Cycles: svn merge -r41182:41205 ^/trunk/blender
[blender-staging.git] / source / blender / render / intern / source / pipeline.c
index bbe32765443f81ee85fb4a3ed426cd181decd8d5..6e61c930fd096f2911c750d819768672b836729b 100644 (file)
@@ -889,18 +889,39 @@ static void *ml_addlayer_cb(void *base, char *str)
 {
        RenderResult *rr= base;
        RenderLayer *rl;
+
+       /* don't add if layer already exists */
+       for(rl=rr->layers.first; rl; rl=rl->next)
+               if(strcmp(rl->name, str) == 0)
+                       return rl;
        
+       /* add render layer */
        rl= MEM_callocN(sizeof(RenderLayer), "new render layer");
        BLI_addtail(&rr->layers, rl);
        
        BLI_strncpy(rl->name, str, EXR_LAY_MAXNAME);
+       rl->rectx = rr->rectx;
+       rl->recty = rr->recty;
+
        return rl;
 }
-static void ml_addpass_cb(void *UNUSED(base), void *lay, char *str, float *rect, int totchan, char *chan_id)
+static void ml_addpass_cb(void *base, void *lay, char *str, float *rect, int totchan, char *chan_id)
 {
+       RenderResult *rr= base;
        RenderLayer *rl= lay;   
-       RenderPass *rpass= MEM_callocN(sizeof(RenderPass), "loaded pass");
+       RenderPass *rpass;
        int a;
+
+       /* don't add if pass already exists */
+       for(rpass=rl->passes.first; rpass; rpass=rpass->next) {
+               if(strcmp(rpass->name, str) == 0) {
+                       MEM_freeN(rect);
+                       return;
+               }
+       }
+       
+       /* add render pass */
+       rpass = MEM_callocN(sizeof(RenderPass), "loaded pass");
        
        BLI_addtail(&rl->passes, rpass);
        rpass->channels= totchan;
@@ -914,6 +935,8 @@ static void ml_addpass_cb(void *UNUSED(base), void *lay, char *str, float *rect,
        for(a=0; a<totchan; a++)
                rpass->chan_id[a]= chan_id[a];
        
+       rpass->rectx = rr->rectx;
+       rpass->recty = rr->recty;
        rpass->rect= rect;
 }
 
@@ -921,24 +944,12 @@ static void ml_addpass_cb(void *UNUSED(base), void *lay, char *str, float *rect,
 RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty)
 {
        RenderResult *rr= MEM_callocN(sizeof(RenderResult), "loaded render result");
-       RenderLayer *rl;
-       RenderPass *rpass;
        
        rr->rectx= rectx;
        rr->recty= recty;
        
        IMB_exr_multilayer_convert(exrhandle, rr, ml_addlayer_cb, ml_addpass_cb);
 
-       for(rl=rr->layers.first; rl; rl=rl->next) {
-               rl->rectx= rectx;
-               rl->recty= recty;
-
-               for(rpass=rl->passes.first; rpass; rpass=rpass->next) {
-                       rpass->rectx= rectx;
-                       rpass->recty= recty;
-               }
-       }
-       
        return rr;
 }
 
@@ -3321,10 +3332,22 @@ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char
 
 void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filename)
 {
-       if(!read_render_result_from_file(filename, result)) {
+       /* optionally also add layers/passes that were in the file but not setup
+          for rendering, useful for external render engines or network render */
+       void *exrhandle= IMB_exr_get_handle();
+       int rectx, recty;
+
+       if(IMB_exr_begin_read(exrhandle, filename, &rectx, &recty))
+               IMB_exr_multilayer_convert(exrhandle, result, ml_addlayer_cb, ml_addpass_cb);
+
+       IMB_exr_close(exrhandle);
+       
+#if 0
+       if(!read_render_result_from_file(filename, result, 1)) {
                BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
                return;
        }
+#endif
 }
 
 const float default_envmap_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 };