render api utility function to initialize a render layer from an image rather then loading through python.

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.
This commit is contained in:
Campbell Barton 2009-07-27 18:50:10 +00:00
parent 324187b61a
commit eb40d8ef0f
4 changed files with 58 additions and 1 deletions

@ -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)

@ -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);

@ -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);

@ -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;