commit before doing some hefty shapekey change, will break compilation
[blender-staging.git] / source / blender / nodes / intern / CMP_nodes / CMP_image.c
index 06c3b90e8289f9f3486bb7f03375c8559736f767..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) {
@@ -201,33 +224,33 @@ static void node_composit_exec_image(void *data, bNode *node, bNodeStack **in, b
                }
                else {
                        stackbuf= node_composit_get_image(rd, ima, iuser);
+
+                       if (stackbuf) {
+                               /*respect image premul option*/
+                               if (stackbuf->type==CB_RGBA && ima->flag & IMA_DO_PREMUL) {
+                                       int i;
+                                       float *pixel;
                        
-                       /*respect image premul option*/
-                       if (stackbuf->type==CB_RGBA && ima->flag & IMA_DO_PREMUL) {
-                               int i;
-                               float *pixel;
-                       
-                               /*first duplicate stackbuf->rect, since it's just a pointer
-                                 to the source imbuf, and we don't want to change that.*/
-                               stackbuf->rect = MEM_dupallocN(stackbuf->rect);
+                                       /*first duplicate stackbuf->rect, since it's just a pointer
+                                         to the source imbuf, and we don't want to change that.*/
+                                       stackbuf->rect = MEM_dupallocN(stackbuf->rect);
                                
-                               /*flag that we can free the buffer.*/
-                               stackbuf->malloc = 1;
+                                       /*premul the image*/
                                
-                               /*premul the image*/                            
-                               pixel = stackbuf->rect;
-                               for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) {
-                                       pixel[0] *= pixel[3];
-                                       pixel[1] *= pixel[3];
-                                       pixel[2] *= pixel[3];
+                                       pixel = stackbuf->rect;
+                                       for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) {
+                                               pixel[0] *= pixel[3];
+                                               pixel[1] *= pixel[3];
+                                               pixel[2] *= pixel[3];
+                                       }
                                }
-                       }
                        
-                       /* put image on stack */        
-                       out[0]->data= stackbuf;
+                               /* put image on stack */        
+                               out[0]->data= stackbuf;
                        
-                       if(out[2]->hasoutput)
-                               out[2]->data= node_composit_get_zimage(node, rd);
+                               if(out[2]->hasoutput)
+                                       out[2]->data= node_composit_get_zimage(node, rd);
+                       }
                }
                
                /* alpha and preview for both types */
@@ -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);
                }
        }       
 };
@@ -244,6 +267,7 @@ static void node_composit_init_image(bNode* node)
 {
    ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
    node->storage= iuser;
+   iuser->frames= 1;
    iuser->sfra= 1;
    iuser->fie_ima= 2;
    iuser->ok= 1;
@@ -329,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);
@@ -364,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);
 };