diff options
Diffstat (limited to 'source/blender/compositor/operations')
9 files changed, 63 insertions, 53 deletions
diff --git a/source/blender/compositor/operations/COM_ImageOperation.cpp b/source/blender/compositor/operations/COM_ImageOperation.cpp index 4ec5643c0bb..fb3efbb67ed 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.cpp +++ b/source/blender/compositor/operations/COM_ImageOperation.cpp @@ -33,6 +33,7 @@ extern "C" { #include "RE_render_ext.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" + #include "IMB_colormanagement.h" } BaseImageOperation::BaseImageOperation() : NodeOperation() diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cpp b/source/blender/compositor/operations/COM_OutputFileOperation.cpp index b72875ab2f9..21ecfdb5272 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.cpp +++ b/source/blender/compositor/operations/COM_OutputFileOperation.cpp @@ -31,9 +31,12 @@ #include "BKE_global.h" #include "BKE_main.h" +#include "DNA_color_types.h" + extern "C" { #include "MEM_guardedalloc.h" #include "IMB_imbuf.h" + #include "IMB_colormanagement.h" #include "IMB_imbuf_types.h" } @@ -91,7 +94,8 @@ static void write_buffer_rect(rcti *rect, const bNodeTree *tree, OutputSingleLayerOperation::OutputSingleLayerOperation( - const RenderData *rd, const bNodeTree *tree, DataType datatype, ImageFormatData *format, const char *path) + const RenderData *rd, const bNodeTree *tree, DataType datatype, ImageFormatData *format, const char *path, + const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings) { this->m_rd = rd; this->m_tree = tree; @@ -104,6 +108,9 @@ OutputSingleLayerOperation::OutputSingleLayerOperation( this->m_format = format; BLI_strncpy(this->m_path, path, sizeof(this->m_path)); + + this->m_viewSettings = viewSettings; + this->m_displaySettings = displaySettings; } void OutputSingleLayerOperation::initExecution() @@ -131,8 +138,7 @@ void OutputSingleLayerOperation::deinitExecution() ibuf->mall |= IB_rectfloat; ibuf->dither = this->m_rd->dither_intensity; - if (this->m_rd->color_mgt_flag & R_COLOR_MANAGEMENT) - ibuf->profile = IB_PROFILE_LINEAR_RGB; + IMB_display_buffer_to_imbuf_rect(ibuf, m_viewSettings, m_displaySettings); BKE_makepicstring(filename, this->m_path, bmain->name, this->m_rd->cfra, this->m_format->imtype, (this->m_rd->scemode & R_EXTENSION), true); diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 532242c97ce..69d1ad48ced 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -28,6 +28,8 @@ #include "BLI_rect.h" #include "BLI_path_util.h" +#include "DNA_color_types.h" + #include "intern/openexr/openexr_multi.h" /* Writes the image to a single-layer file. */ @@ -43,8 +45,11 @@ private: DataType m_datatype; SocketReader *m_imageInput; + const ColorManagedViewSettings *m_viewSettings; + const ColorManagedDisplaySettings *m_displaySettings; public: - OutputSingleLayerOperation(const RenderData *rd, const bNodeTree *tree, DataType datatype, ImageFormatData *format, const char *path); + OutputSingleLayerOperation(const RenderData *rd, const bNodeTree *tree, DataType datatype, ImageFormatData *format, const char *path, + const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings); void executeRegion(rcti *rect, unsigned int tileNumber); bool isOutputOperation(bool rendering) const { return true; } diff --git a/source/blender/compositor/operations/COM_PreviewOperation.cpp b/source/blender/compositor/operations/COM_PreviewOperation.cpp index aff374cdded..6e58b277f66 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.cpp +++ b/source/blender/compositor/operations/COM_PreviewOperation.cpp @@ -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) { diff --git a/source/blender/compositor/operations/COM_PreviewOperation.h b/source/blender/compositor/operations/COM_PreviewOperation.h index ffd80ff27af..9e774d0e41b 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.h +++ b/source/blender/compositor/operations/COM_PreviewOperation.h @@ -24,6 +24,7 @@ #define _COM_PreviewOperation_h #include "COM_NodeOperation.h" #include "DNA_image_types.h" +#include "DNA_color_types.h" #include "BLI_rect.h" class PreviewOperation : public NodeOperation { @@ -37,8 +38,10 @@ protected: SocketReader *m_input; float m_divider; + const ColorManagedViewSettings *m_viewSettings; + const ColorManagedDisplaySettings *m_displaySettings; public: - PreviewOperation(); + PreviewOperation(const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings); bool isOutputOperation(bool rendering) const { return true; } void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_SplitViewerOperation.cpp b/source/blender/compositor/operations/COM_SplitViewerOperation.cpp index d59d1f9f10d..7325e32a863 100644 --- a/source/blender/compositor/operations/COM_SplitViewerOperation.cpp +++ b/source/blender/compositor/operations/COM_SplitViewerOperation.cpp @@ -62,7 +62,6 @@ void SplitViewerOperation::deinitExecution() void SplitViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber) { float *buffer = this->m_outputBuffer; - unsigned char *bufferDisplay = this->m_outputBufferDisplay; if (!buffer) return; int x1 = rect->xmin; @@ -76,7 +75,6 @@ void SplitViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber) for (y = y1; y < y2; y++) { for (x = x1; x < x2; x++) { bool image1; - float srgb[4]; image1 = this->m_xSplit ? x > perc : y > perc; if (image1) { this->m_image1Input->read(&(buffer[offset]), x, y, COM_PS_NEAREST); @@ -84,21 +82,7 @@ void SplitViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber) else { this->m_image2Input->read(&(buffer[offset]), x, y, COM_PS_NEAREST); } - /// @todo: linear conversion only when scene color management is selected, also check predivide. - if (this->m_doColorManagement) { - if (this->m_doColorPredivide) { - linearrgb_to_srgb_predivide_v4(srgb, buffer + offset); - } - else { - linearrgb_to_srgb_v4(srgb, buffer + offset); - } - } - else { - copy_v4_v4(srgb, buffer + offset); - } - - rgba_float_to_uchar(bufferDisplay + offset, srgb); - + offset += 4; } offset += (this->getWidth() - (x2 - x1)) * 4; diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp index f443c33cd54..d9ca131721f 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp @@ -34,6 +34,7 @@ extern "C" { #include "MEM_guardedalloc.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" + #include "IMB_colormanagement.h" } @@ -43,10 +44,10 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation() this->setImageUser(NULL); this->m_outputBuffer = NULL; this->m_depthBuffer = NULL; - this->m_outputBufferDisplay = NULL; this->m_active = false; - this->m_doColorManagement = true; this->m_doDepthBuffer = false; + this->m_viewSettings = NULL; + this->m_displaySettings = NULL; } void ViewerBaseOperation::initExecution() @@ -60,7 +61,7 @@ void ViewerBaseOperation::initImage() { Image *anImage = this->m_image; ImBuf *ibuf = BKE_image_acquire_ibuf(anImage, this->m_imageUser, &this->m_lock); - + if (!ibuf) return; BLI_lock_thread(LOCK_DRAW_IMAGE); if (ibuf->x != (int)getWidth() || ibuf->y != (int)getHeight()) { @@ -70,30 +71,44 @@ void ViewerBaseOperation::initImage() IMB_freezbuffloatImBuf(ibuf); ibuf->x = getWidth(); ibuf->y = getHeight(); - imb_addrectImBuf(ibuf); imb_addrectfloatImBuf(ibuf); anImage->ok = IMA_OK_LOADED; + ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; + + BLI_unlock_thread(LOCK_DRAW_IMAGE); } + if (m_doDepthBuffer) { addzbuffloatImBuf(ibuf); } BLI_unlock_thread(LOCK_DRAW_IMAGE); - - + /* now we combine the input with ibuf */ this->m_outputBuffer = ibuf->rect_float; - this->m_outputBufferDisplay = (unsigned char *)ibuf->rect; + + /* needed for display buffer update + * + * no need to lock / reference the image buffer because it's seems + * to be the single place which changes buffers of viewer image + * which is this node + */ + this->m_ibuf = ibuf; + if (m_doDepthBuffer) { this->m_depthBuffer = ibuf->zbuf_float; } - + BKE_image_release_ibuf(this->m_image, this->m_lock); } void ViewerBaseOperation:: updateImage(rcti *rect) { + IMB_partial_display_buffer_update(this->m_ibuf, this->m_outputBuffer, NULL, getWidth(), 0, 0, + this->m_viewSettings, this->m_displaySettings, + rect->xmin, rect->ymin, rect->xmax, rect->ymax); + WM_main_add_notifier(NC_WINDOW | ND_DRAW, NULL); } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.h b/source/blender/compositor/operations/COM_ViewerBaseOperation.h index d90eb343f6c..f7d479eb3b8 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.h +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.h @@ -30,7 +30,6 @@ class ViewerBaseOperation : public NodeOperation { protected: float *m_outputBuffer; float *m_depthBuffer; - unsigned char *m_outputBufferDisplay; Image *m_image; ImageUser *m_imageUser; void *m_lock; @@ -38,9 +37,11 @@ protected: float m_centerX; float m_centerY; OrderOfChunks m_chunkOrder; - bool m_doColorManagement; - bool m_doColorPredivide; bool m_doDepthBuffer; + ImBuf *m_ibuf; + + const ColorManagedViewSettings *m_viewSettings; + const ColorManagedDisplaySettings *m_displaySettings; public: bool isOutputOperation(bool rendering) const { return isActiveViewerOutput(); } @@ -57,10 +58,10 @@ public: float getCenterY() { return this->m_centerY; } OrderOfChunks getChunkOrder() { return this->m_chunkOrder; } const CompositorPriority getRenderPriority() const; - void setColorManagement(bool doColorManagement) { this->m_doColorManagement = doColorManagement; } - void setColorPredivide(bool doColorPredivide) { this->m_doColorPredivide = doColorPredivide; } bool isViewerOperation() { return true; } - + + void setViewSettings(const ColorManagedViewSettings *viewSettings) { this->m_viewSettings = viewSettings; } + void setDisplaySettings(const ColorManagedDisplaySettings *displaySettings) { this->m_displaySettings = displaySettings; } protected: ViewerBaseOperation(); void updateImage(rcti *rect); diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cpp b/source/blender/compositor/operations/COM_ViewerOperation.cpp index b85b86bddc3..576d5da4d74 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerOperation.cpp @@ -72,7 +72,6 @@ void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber) { float *buffer = this->m_outputBuffer; float *depthbuffer = this->m_depthBuffer; - unsigned char *bufferDisplay = this->m_outputBufferDisplay; if (!buffer) return; const int x1 = rect->xmin; const int y1 = rect->ymin; @@ -82,7 +81,7 @@ void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber) const int offsetadd4 = offsetadd * 4; int offset = (y1 * this->getWidth() + x1); int offset4 = offset * 4; - float alpha[4], srgb[4], depth[4]; + float alpha[4], depth[4]; int x; int y; bool breaked = false; @@ -98,19 +97,6 @@ void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber) this->m_depthInput->read(depth, x, y, COM_PS_NEAREST); depthbuffer[offset] = depth[0]; } - if (this->m_doColorManagement) { - if (this->m_doColorPredivide) { - linearrgb_to_srgb_predivide_v4(srgb, buffer + offset4); - } - else { - linearrgb_to_srgb_v4(srgb, buffer + offset4); - } - } - else { - copy_v4_v4(srgb, buffer + offset4); - } - - rgba_float_to_uchar(bufferDisplay + offset4, srgb); offset ++; offset4 += 4; |