Cycles: apply basic gamma correction in stadalone OpenImageIO output driver
For file formats like PNG, JPEG and TIFF. Eventually this should use the OpenColorIO view transform, but this at least makes the image closer to what it should be in most cases. Differential Revision: https://developer.blender.org/D16482
This commit is contained in:
parent
ec04870091
commit
937130a294
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include "app/oiio_output_driver.h"
|
||||
|
||||
#include "scene/colorspace.h"
|
||||
|
||||
#include <OpenImageIO/imagebuf.h>
|
||||
#include <OpenImageIO/imagebufalgo.h>
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
OIIOOutputDriver::OIIOOutputDriver(const string_view filepath,
|
||||
|
@ -47,11 +52,23 @@ void OIIOOutputDriver::write_render_tile(const Tile &tile)
|
|||
}
|
||||
|
||||
/* Manipulate offset and stride to convert from bottom-up to top-down convention. */
|
||||
image_output->write_image(TypeDesc::FLOAT,
|
||||
pixels.data() + (height - 1) * width * 4,
|
||||
AutoStride,
|
||||
-width * 4 * sizeof(float),
|
||||
AutoStride);
|
||||
ImageBuf image_buffer(spec,
|
||||
pixels.data() + (height - 1) * width * 4,
|
||||
AutoStride,
|
||||
-width * 4 * sizeof(float),
|
||||
AutoStride);
|
||||
|
||||
/* Apply gamma correction for (some) non-linear file formats.
|
||||
* TODO: use OpenColorIO view transform if available. */
|
||||
if (ColorSpaceManager::detect_known_colorspace(
|
||||
u_colorspace_auto, "", image_output->format_name(), true) == u_colorspace_srgb) {
|
||||
const float g = 1.0f / 2.2f;
|
||||
ImageBufAlgo::pow(image_buffer, image_buffer, {g, g, g, 1.0f});
|
||||
}
|
||||
|
||||
/* Write to disk and close */
|
||||
image_buffer.set_write_format(TypeDesc::FLOAT);
|
||||
image_buffer.write(image_output.get());
|
||||
image_output->close();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue