Skip to content

Commit

Permalink
Save extra aovs
Browse files Browse the repository at this point in the history
  • Loading branch information
oktomus committed Feb 27, 2018
1 parent 1c80288 commit e5463a4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ namespace
{
if (m_params.m_diagnostics)
{
m_variation_aov_index = frame.create_extra_aov_image("variation");
m_samples_aov_index = frame.create_extra_aov_image("samples");
m_variation_aov_index = frame.create_extra_aov_image("variation", PixelFormatHalf);
m_samples_aov_index = frame.create_extra_aov_image("samples", PixelFormatHalf);

if ((thread_index == 0) && (m_variation_aov_index == size_t(~0) || m_samples_aov_index == size_t(~0)))
{
Expand Down
58 changes: 55 additions & 3 deletions src/appleseed/renderer/modeling/frame/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,13 @@ const AOVContainer& Frame::internal_aovs() const
return impl->m_internal_aovs;
}

size_t Frame::create_extra_aov_image(const char* name) const
size_t Frame::create_extra_aov_image(
const char* name,
const PixelFormat pixel_format) const
{
const size_t index = aov_images().get_index(name);
if (index == size_t(~0) && aov_images().size() < MaxAOVCount)
return aov_images().append(name, 4, PixelFormatFloat);
return aov_images().append(name, 4, pixel_format);

return index;
}
Expand Down Expand Up @@ -646,6 +648,16 @@ namespace
}
else if (extension == ".png")
{
// Test if the image contains appropriate data
if (image.properties().m_pixel_format != PixelFormatHalf &&
image.properties().m_channel_count != 4)
{
RENDERER_LOG_ERROR(
"failed to write image file %s: data images can only be saved as exr.",
file_path);
return false;
}

write_png_image(
bf_file_path,
image,
Expand Down Expand Up @@ -720,7 +732,7 @@ bool Frame::write_aov_images(const char* file_path) const

bool success = true;

if (!aovs().empty())
if (!aovs().empty() || !aov_images().empty())
{
const bf::path boost_file_path(file_path);
const bf::path directory = boost_file_path.parent_path();
Expand All @@ -741,6 +753,22 @@ bool Frame::write_aov_images(const char* file_path) const
if (!write_image(aov_file_path.c_str(), aov->get_image(), aov))
success = false;
}

// Extra AOVs
for (size_t i = 0, e = aov_images().size(); i < e; ++i)
{
const Image & image = aov_images().get_image(i);

// Compute AOV image file path.
const string aov_name = aov_images().get_name(i);
const string safe_aov_name = make_safe_filename(aov_name);
const string aov_file_name = base_file_name + "." + safe_aov_name + extension;
const string aov_file_path = (directory / aov_file_name).string();

// Write AOV image.
if (!write_image(aov_file_path.c_str(), image))
success = false;
}
}

return success;
Expand Down Expand Up @@ -776,6 +804,30 @@ bool Frame::write_main_and_aov_images() const
}
}

if (!aov_images().empty())
{
const bf::path boost_file_path(filepath);
const bf::path directory = boost_file_path.parent_path();
const string base_file_name = boost_file_path.stem().string();
const string extension = boost_file_path.extension().string();

// Extra AOVs
for (size_t i = 0, e = aov_images().size(); i < e; ++i)
{
const Image & image = aov_images().get_image(i);

// Compute AOV image file path.
const string aov_name = aov_images().get_name(i);
const string safe_aov_name = make_safe_filename(aov_name);
const string aov_file_name = base_file_name + "." + safe_aov_name + extension;
const string aov_file_path = (directory / aov_file_name).string();

// Write AOV image.
if (!write_image(aov_file_path.c_str(), image))
success = false;
}
}

return success;
}

Expand Down
5 changes: 4 additions & 1 deletion src/appleseed/renderer/modeling/frame/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// appleseed.foundation headers.
#include "foundation/image/canvasproperties.h"
#include "foundation/image/colorspace.h"
#include "foundation/image/pixel.h"
#include "foundation/math/aabb.h"
#include "foundation/math/filter.h"
#include "foundation/math/vector.h"
Expand Down Expand Up @@ -101,7 +102,9 @@ class APPLESEED_DLLSYMBOL Frame
const AOVContainer& aovs() const;

// Create an extra AOV image if it does not exist.
size_t create_extra_aov_image(const char* name) const;
size_t create_extra_aov_image(
const char* name,
const foundation::PixelFormat pixel_format = foundation::PixelFormatFloat) const;

// Return the reconstruction filter used by the main image and the AOV images.
const foundation::Filter2f& get_filter() const;
Expand Down

0 comments on commit e5463a4

Please sign in to comment.