2.5: Render Api
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 16 Aug 2009 22:53:15 +0000 (22:53 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 16 Aug 2009 22:53:15 +0000 (22:53 +0000)
* Add RenderResult.load_from_file to load whole multilayer exr's at once.
* Removed x/y offset from RenderLayer.load_from_file, better to encourage
  using offset in begin_result() to minimize memory usage.
* Added WITH_OPENEXR in some screen/file/image module for scons/make, exr
  was not working in some places there.

release/io/engine_render_pov.py
source/blender/editors/screen/Makefile
source/blender/editors/screen/SConscript
source/blender/editors/space_file/Makefile
source/blender/editors/space_file/SConscript
source/blender/editors/space_image/Makefile
source/blender/editors/space_image/SConscript
source/blender/makesrna/intern/rna_render.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/pipeline.c

index ea419bb0ace6ac66a35dcb55f00c37371f597157..ba9e7377535217be891bca3bcfd224308c08621a 100644 (file)
@@ -727,7 +727,7 @@ class PovrayRender(bpy.types.RenderEngine):
                                result = self.begin_result(0, 0, x, y)
                                lay = result.layers[0]
                                # possible the image wont load early on.
-                               try:            lay.rect_from_file(self.temp_file_out, 0, 0)
+                               try:            lay.load_from_file(self.temp_file_out)
                                except: pass
                                self.end_result(result)
                        
index 923a020afcfdedec5aa0078b81653a41567fe0de..00698917be5f66b851ca33c0bb3a6783b93771da 100644 (file)
@@ -54,3 +54,8 @@ CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
 # own include 
 
 CPPFLAGS += -I../include 
+
+ifeq ($(WITH_OPENEXR), true)
+    CPPFLAGS += -DWITH_OPENEXR
+endif
+
index 3972efd8eedd8b7a31d823921ca9d637a296b781..a4f73cfea7e2286108e43704bca9871fd62a5f99 100644 (file)
@@ -12,5 +12,7 @@ defs = ''
 
 if not env['WITH_BF_PYTHON']:
     defs += 'DISABLE_PYTHON'
+if env['WITH_BF_OPENEXR']:
+       defs += ' WITH_OPENEXR'
 
 env.BlenderLib ( 'bf_editors_screen', sources, Split(incs), Split(defs), libtype=['core'], priority=[105] )
index 2f4180448e5a29b5a5ca5c9b8d3727fe21d54cee..43b2f09ed2d401aa1490a70e57a6a20d99e78946 100644 (file)
@@ -59,3 +59,7 @@ ifeq ($(WITH_OPENJPEG),true)
        CPPFLAGS += -DWITH_OPENJPEG
 endif
 
+ifeq ($(WITH_OPENEXR), true)
+    CPPFLAGS += -DWITH_OPENEXR
+endif
+
index 36e042bdaa6adaabe097fe5583b23cd0222ac91e..e6fba38fb8fbdaad6d055c5378cc34692d0d5564 100644 (file)
@@ -12,5 +12,7 @@ defs = []
 
 if env['WITH_BF_OPENJPEG']:
     defs.append('WITH_OPENJPEG')
+if env['WITH_BF_OPENEXR']:
+       defs.append('WITH_OPENEXR')
 
 env.BlenderLib ( 'bf_editors_space_file', sources, Split(incs), defs, libtype=['core'], priority=[115] )
index e7e9a9b5665854137dacd0f78f4ed58719171697..af15b1d9724434d1d6adb27f53314d0636a512a9 100644 (file)
@@ -53,3 +53,7 @@ CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
 
 CPPFLAGS += -I../include 
 
+ifeq ($(WITH_OPENEXR), true)
+    CPPFLAGS += -DWITH_OPENEXR
+endif
+
index e7041ef045861b4d9562d9be00457b350a1b86f2..874549e6949f08dba0e7bb06b4350a24696e5bb2 100644 (file)
@@ -11,5 +11,7 @@ defs = []
 
 if env['WITH_BF_LCMS']:
        defs.append('WITH_LCMS')
+if env['WITH_BF_OPENEXR']:
+       defs.append('WITH_OPENEXR')
 
 env.BlenderLib ( 'bf_editors_space_image', sources, Split(incs), defs, libtype=['core'], priority=[40] )
index eaea62d36ae59a204aaf4e068ddd778f2dba4ce7..a219bd5aefa83a4ab30fff95dca70c2b4e25393d 100644 (file)
@@ -273,10 +273,17 @@ static void rna_def_render_result(BlenderRNA *brna)
 {
        StructRNA *srna;
        PropertyRNA *prop;
+       FunctionRNA *func;
        
        srna= RNA_def_struct(brna, "RenderResult", NULL);
        RNA_def_struct_ui_text(srna, "Render Result", "Result of rendering, including all layers and passes.");
 
+       func= RNA_def_function(srna, "load_from_file", "RE_result_load_from_file");
+       RNA_def_function_ui_description(func, "Copies the pixels of this render result from an image file.");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       prop= RNA_def_string(func, "filename", "", 0, "Filename", "Filename to load into this render tile, must be no smaller then the render result");
+       RNA_def_property_flag(prop, PROP_REQUIRED);
+
        RNA_define_verify_sdna(0);
 
        prop= RNA_def_property(srna, "resolution_x", PROP_INT, PROP_NONE);
@@ -303,15 +310,11 @@ static void rna_def_render_layer(BlenderRNA *brna)
        srna= RNA_def_struct(brna, "RenderLayer", NULL);
        RNA_def_struct_ui_text(srna, "Render Layer", "");
 
-       func= RNA_def_function(srna, "rect_from_file", "RE_layer_rect_from_file");
+       func= RNA_def_function(srna, "load_from_file", "RE_layer_load_from_file");
        RNA_def_function_ui_description(func, "Copies the pixels of this renderlayer from an image file.");
        RNA_def_function_flag(func, FUNC_USE_REPORTS);
        prop= RNA_def_string(func, "filename", "", 0, "Filename", "Filename to load into this render tile, must be no smaller then the renderlayer");
        RNA_def_property_flag(prop, PROP_REQUIRED);
-       prop= RNA_def_int(func, "x", 0, 0, INT_MAX, "Offset X", "Offset the position to copy from if the image is larger then the render layer", 0, INT_MAX);
-       RNA_def_property_flag(prop, PROP_REQUIRED);
-       prop= RNA_def_int(func, "y", 0, 0, INT_MAX, "Offset Y", "Offset the position to copy from if the image is larger then the render layer", 0, INT_MAX);
-       RNA_def_property_flag(prop, PROP_REQUIRED);
        
        RNA_define_verify_sdna(0);
 
index 2df3a0a4f8b35bca5b0f8c1e8479c44be324396e..bf02af6ac36873576bb63c34f60e010309264e1c 100644 (file)
@@ -266,7 +266,8 @@ typedef struct RenderEngine {
        ListBase fullresult;
 } RenderEngine;
 
-void RE_layer_rect_from_file(RenderLayer *layer, struct ReportList *reports, char *filename, int x, int y);
+void RE_layer_load_from_file(RenderLayer *layer, struct ReportList *reports, char *filename);
+void RE_result_load_from_file(RenderResult *result, struct ReportList *reports, char *filename);
 
 struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h);
 void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result);
index e38f2416ca8af39e7d22bb62f42bd7142e9f6fda..a6b089c60291500fcc14d6b2913fe0c78ea8bc8f 100644 (file)
@@ -868,33 +868,26 @@ static void renderresult_add_names(RenderResult *rr)
                        strcpy(rpass->name, get_pass_name(rpass->passtype, -1));
 }
 
-
-/* only for temp buffer files, makes exact copy of render result */
-static void read_render_result(Render *re, int sample)
+/* called for reading temp files, and for external engines */
+static int read_render_result_from_file(char *filename, RenderResult *rr)
 {
        RenderLayer *rl;
        RenderPass *rpass;
        void *exrhandle= IMB_exr_get_handle();
        int rectx, recty;
-       char str[FILE_MAX];
-       
-       RE_FreeRenderResult(re->result);
-       re->result= new_render_result(re, &re->disprect, 0, RR_USEMEM);
 
-       render_unique_exr_name(re, str, sample);
-       if(IMB_exr_begin_read(exrhandle, str, &rectx, &recty)==0) {
+       if(IMB_exr_begin_read(exrhandle, filename, &rectx, &recty)==0) {
                IMB_exr_close(exrhandle);
-               printf("cannot read: %s\n", str);
-               return;
+               return 0;
        }
        
-       printf("read exr tmp file: %s\n", str);
-       
-       if(re->result == NULL || rectx!=re->result->rectx || recty!=re->result->recty) {
+       if(rr == NULL || rectx!=rr->rectx || recty!=rr->recty) {
                printf("error in reading render result\n");
+               IMB_exr_close(exrhandle);
+               return 0;
        }
        else {
-               for(rl= re->result->layers.first; rl; rl= rl->next) {
+               for(rl= rr->layers.first; rl; rl= rl->next) {
                        
                        /* combined */
                        if(rl->rectf) {
@@ -914,10 +907,27 @@ static void read_render_result(Render *re, int sample)
                        
                }
                IMB_exr_read_channels(exrhandle);
-               renderresult_add_names(re->result);
+               renderresult_add_names(rr);
        }
        
        IMB_exr_close(exrhandle);
+
+       return 1;
+}
+
+/* only for temp buffer files, makes exact copy of render result */
+static void read_render_result(Render *re, int sample)
+{
+       char str[FILE_MAX];
+
+       RE_FreeRenderResult(re->result);
+       re->result= new_render_result(re, &re->disprect, 0, RR_USEMEM);
+
+       render_unique_exr_name(re, str, sample);
+       printf("read exr tmp file: %s\n", str);
+
+       if(!read_render_result_from_file(str, re->result))
+               printf("cannot read: %s\n", str);
 }
 
 /* *************************************************** */
@@ -2944,7 +2954,7 @@ void RE_engine_update_stats(RenderEngine *engine, char *stats, char *info)
 
 /* loads in image into a result, size must match
  * x/y offsets are only used on a partial copy when dimensions dont match */
-void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *filename, int x, int y)
+void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, char *filename)
 {
        ImBuf *ibuf = IMB_loadiffname(filename, IB_rect);
 
@@ -2955,7 +2965,7 @@ void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *file
 
                        memcpy(layer->rectf, ibuf->rect_float, sizeof(float)*4*layer->rectx*layer->recty);
                } else {
-                       if ((ibuf->x - x >= layer->rectx) && (ibuf->y - y >= layer->recty)) {
+                       if ((ibuf->x >= layer->rectx) && (ibuf->y >= layer->recty)) {
                                ImBuf *ibuf_clip;
 
                                if(ibuf->rect_float==NULL)
@@ -2963,7 +2973,7 @@ void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *file
 
                                ibuf_clip = IMB_allocImBuf(layer->rectx, layer->recty, 32, IB_rectfloat, 0);
                                if(ibuf_clip) {
-                                       IMB_rectcpy(ibuf_clip, ibuf, 0,0, x,y, layer->rectx, layer->recty);
+                                       IMB_rectcpy(ibuf_clip, ibuf, 0,0, 0,0, layer->rectx, layer->recty);
 
                                        memcpy(layer->rectf, ibuf_clip->rect_float, sizeof(float)*4*layer->rectx*layer->recty);
                                        IMB_freeImBuf(ibuf_clip);
@@ -2983,6 +2993,15 @@ void RE_layer_rect_from_file(RenderLayer *layer, ReportList *reports, char *file
                BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
        }
 }
+
+void RE_result_load_from_file(RenderResult *result, ReportList *reports, char *filename)
+{
+       if(!read_render_result_from_file(filename, result)) {
+               BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
+               return;
+       }
+}
+
 static void external_render_3d(Render *re, RenderEngineType *type)
 {
        RenderEngine engine;