2.5: Render Api
* 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.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -54,3 +54,8 @@ CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
|
||||
# own include
|
||||
|
||||
CPPFLAGS += -I../include
|
||||
|
||||
ifeq ($(WITH_OPENEXR), true)
|
||||
CPPFLAGS += -DWITH_OPENEXR
|
||||
endif
|
||||
|
||||
|
||||
@@ -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] )
|
||||
|
||||
@@ -59,3 +59,7 @@ ifeq ($(WITH_OPENJPEG),true)
|
||||
CPPFLAGS += -DWITH_OPENJPEG
|
||||
endif
|
||||
|
||||
ifeq ($(WITH_OPENEXR), true)
|
||||
CPPFLAGS += -DWITH_OPENEXR
|
||||
endif
|
||||
|
||||
|
||||
@@ -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] )
|
||||
|
||||
@@ -53,3 +53,7 @@ CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
|
||||
|
||||
CPPFLAGS += -I../include
|
||||
|
||||
ifeq ($(WITH_OPENEXR), true)
|
||||
CPPFLAGS += -DWITH_OPENEXR
|
||||
endif
|
||||
|
||||
|
||||
@@ -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] )
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user