render api utility function to initialize a render layer from an image rather then...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jul 2009 18:50:10 +0000 (18:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jul 2009 18:50:10 +0000 (18:50 +0000)
lay = result.layers[0]
lay.rect_from_file("somefile.png", part.x, part.y)

If the source image is bigger then the render layer x/y offsets can be used to choose the part of the image use.

release/ui/space_view3d_toolbar.py
source/blender/makesrna/intern/rna_render.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/pipeline.c

index 0a9b1090f9e789abd3299692f3076dc5c9d22152..7fd8d75209fbfd1227091a48a6ec322db66d56d4 100644 (file)
@@ -27,7 +27,8 @@ class VIEW3D_PT_tools_objectmode(View3DPanel):
                col.itemO("object.duplicate")
                col.itemO("object.delete")
                
-               if context.active_object.type == 'MESH':
+               active_object= context.active_object
+               if active_object and active_object.type == 'MESH':
                        layout.itemL(text="Shading:")
                
                        col = layout.column(align=True)
index 89c4823035737829c5f7b9838b30ae7dce642274..7268d560282a1c2ddeb65271da7a8411acfc157c 100644 (file)
@@ -297,10 +297,21 @@ static void rna_def_render_layer(BlenderRNA *brna)
 {
        StructRNA *srna;
        PropertyRNA *prop;
+       FunctionRNA *func;
        
        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");
+       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);
 
        rna_def_render_layer_common(srna, 0);
index d96054f5a766b35c4a5096eb3a1463144f08191d..2df3a0a4f8b35bca5b0f8c1e8479c44be324396e 100644 (file)
@@ -39,6 +39,7 @@ struct bNodeTree;
 struct Image;
 struct NodeBlurData;
 struct Object;
+struct ReportList;
 struct RenderData;
 struct RenderEngine;
 struct RenderEngineType;
@@ -265,6 +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);
+
 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);
 void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result);
index 3e50ea92846e25cb68a370e6de1df6fa9cf81533..4a84b1e78b6ca910fff233d54b02a1c51ad92198 100644 (file)
@@ -45,6 +45,7 @@
 #include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_object.h"
+#include "BKE_report.h"
 #include "BKE_scene.h"
 #include "BKE_writeavi.h"      /* <------ should be replaced once with generic movie module */
 #include "BKE_pointcache.h"
@@ -2876,6 +2877,47 @@ void RE_engine_update_stats(RenderEngine *engine, char *stats, char *info)
        re->i.statstr= NULL;
 }
 
+/* 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)
+{
+       ImBuf *ibuf = IMB_loadiffname(filename, IB_rect);
+
+       if(ibuf  && (ibuf->rect || ibuf->rect_float)) {
+               if (ibuf->x == layer->rectx && ibuf->y == layer->recty) {
+                       if(ibuf->rect_float==NULL)
+                               IMB_float_from_rect(ibuf);
+
+                       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)) {
+                               ImBuf *ibuf_clip;
+
+                               if(ibuf->rect_float==NULL)
+                                       IMB_float_from_rect(ibuf);
+
+                               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);
+
+                                       memcpy(layer->rectf, ibuf_clip->rect_float, sizeof(float)*4*layer->rectx*layer->recty);
+                                       IMB_freeImBuf(ibuf_clip);
+                               }
+                               else {
+                                       BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to allocate clip buffer '%s'\n", filename);
+                               }
+                       }
+                       else {
+                               BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: incorrect dimensions for partial copy '%s'\n", filename);
+                       }
+               }
+
+               IMB_freeImBuf(ibuf);
+       }
+       else {
+               BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
+       }
+}
 static void external_render_3d(Render *re, RenderEngineType *type)
 {
        RenderEngine engine;