commit before doing some hefty shapekey change, will break compilation
[blender-staging.git] / source / blender / nodes / intern / CMP_nodes / CMP_image.c
index be5a1d7241bf675c51580cf8db15541aa1faaad0..89a3072ac8dfd5628c35cec0689b55c395e863c9 100644 (file)
@@ -65,9 +65,32 @@ static CompBuf *node_composit_get_image(RenderData *rd, Image *ima, ImageUser *i
        if(ibuf==NULL)
                return NULL;
        
-       if(ibuf->rect_float==NULL)
-               IMB_float_from_rect(ibuf);
+       if (rd->color_mgt_flag & R_COLOR_MANAGEMENT) {
+               if (ibuf->profile == IB_PROFILE_NONE) {
+                       /* if float buffer already exists = already linear */
+                       /* else ... */
+                       if (ibuf->rect_float == NULL) {
+                               imb_freerectfloatImBuf(ibuf);
+                               ibuf->profile = IB_PROFILE_SRGB;
+                               IMB_float_from_rect(ibuf);
+                       } else {
+                               ibuf->profile = IB_PROFILE_LINEAR_RGB;
+                       }
+               }
+       } else {
+               if (ibuf->profile == IB_PROFILE_SRGB) {
+                       if (ibuf->rect_float != NULL) {
+                               imb_freerectfloatImBuf(ibuf);
+                       }
+                       ibuf->profile = IB_PROFILE_NONE;
+                       IMB_float_from_rect(ibuf);
+               }
+       }
        
+       if (ibuf->rect_float == NULL) {
+               IMB_float_from_rect(ibuf);
+       }
+
        type= ibuf->channels;
        
        if(rd->scemode & R_COMP_CROP) {
@@ -235,7 +258,7 @@ static void node_composit_exec_image(void *data, bNode *node, bNodeStack **in, b
                        if(out[1]->hasoutput)
                                out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);
 
-                       generate_preview(node, stackbuf);
+                       generate_preview(data, node, stackbuf);
                }
        }       
 };
@@ -330,11 +353,13 @@ void node_composit_rlayers_out(RenderData *rd, RenderLayer *rl, bNodeStack **out
 
 static void node_composit_exec_rlayers(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 {
-   Scene *sce= node->id?(Scene *)node->id:G.scene; /* G.scene is WEAK! */
+   Scene *sce= (Scene *)node->id;
+   Render *re= (sce)? RE_GetRender(sce->id.name): NULL;
    RenderData *rd= data;
-   RenderResult *rr;
+   RenderResult *rr= NULL;
 
-   rr= RE_GetResult(RE_GetRender(sce->id.name));
+   if(re)
+          rr= RE_AcquireResultRead(re);
 
    if(rr) {
       SceneRenderLayer *srl= BLI_findlink(&sce->r.layers, node->custom1);
@@ -365,11 +390,14 @@ static void node_composit_exec_rlayers(void *data, bNode *node, bNodeStack **in,
 
                node_composit_rlayers_out(rd, rl, out, rr->rectx, rr->recty);
 
-               generate_preview(node, stackbuf);
+               generate_preview(data, node, stackbuf);
             }
          }
       }
-   }   
+   }
+
+   if(re)
+          RE_ReleaseResult(re);
 };