Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[blender.git] / source / blender / compositor / operations / COM_PreviewOperation.cpp
index aff374cdded54c19a998ef7fe3b7fbd7f6a31d9d..6e58b277f66c7cbfb87d31eb0779e010df6ded17 100644 (file)
@@ -35,16 +35,19 @@ extern "C" {
        #include "MEM_guardedalloc.h"
        #include "IMB_imbuf.h"
        #include "IMB_imbuf_types.h"
+       #include "IMB_colormanagement.h"
 }
 
 
-PreviewOperation::PreviewOperation() : NodeOperation()
+PreviewOperation::PreviewOperation(const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings) : NodeOperation()
 {
        this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
        this->m_outputBuffer = NULL;
        this->m_input = NULL;
        this->m_divider = 1.0f;
        this->m_node = NULL;
+       this->m_viewSettings = viewSettings;
+       this->m_displaySettings = displaySettings;
 }
 
 void PreviewOperation::initExecution()
@@ -82,6 +85,10 @@ void PreviewOperation::executeRegion(rcti *rect, unsigned int tileNumber)
 {
        int offset;
        float color[4];
+       struct ColormanageProcessor *cm_processor;
+
+       cm_processor = IMB_colormanagement_display_processor_new(this->m_viewSettings, this->m_displaySettings);
+
        for (int y = rect->ymin; y < rect->ymax; y++) {
                offset = (y * getWidth() + rect->xmin) * 4;
                for (int x = rect->xmin; x < rect->xmax; x++) {
@@ -93,11 +100,13 @@ void PreviewOperation::executeRegion(rcti *rect, unsigned int tileNumber)
                        color[2] = 0.0f;
                        color[3] = 1.0f;
                        this->m_input->read(color, rx, ry, COM_PS_NEAREST);
-                       linearrgb_to_srgb_v4(color, color);
+                       IMB_colormanagement_processor_apply_v4(cm_processor, color);
                        F4TOCHAR4(color, this->m_outputBuffer + offset);
                        offset += 4;
                }
        }
+
+       IMB_colormanagement_processor_free(cm_processor);
 }
 bool PreviewOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
 {