Commit: 937130a294cf474aa733e585c576b78cbf618874
Author: howetuft
Date:   Mon Nov 14 17:55:26 2022 +0100
Branches: master
https://developer.blender.org/rB937130a294cf474aa733e585c576b78cbf618874

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

===================================================================

M       intern/cycles/app/oiio_output_driver.cpp

===================================================================

diff --git a/intern/cycles/app/oiio_output_driver.cpp 
b/intern/cycles/app/oiio_output_driver.cpp
index 477465c880b..d7677276981 100644
--- a/intern/cycles/app/oiio_output_driver.cpp
+++ b/intern/cycles/app/oiio_output_driver.cpp
@@ -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();
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to