Stamp refactoring:
Write those on render result during rendering, so we can cleanly write a render result image after rendering.
This commit is contained in:
@@ -46,6 +46,7 @@ struct ImageFormatData;
|
||||
struct ImagePool;
|
||||
struct Main;
|
||||
struct ReportList;
|
||||
struct RenderResult;
|
||||
|
||||
#define IMA_MAX_SPACE 64
|
||||
|
||||
@@ -58,10 +59,11 @@ void BKE_image_free_buffers(struct Image *image);
|
||||
/* call from library */
|
||||
void BKE_image_free(struct Image *image);
|
||||
|
||||
void BKE_imbuf_stamp_info(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf);
|
||||
void BKE_render_result_stamp_info(struct Scene *scene, struct Object *camera, struct RenderResult *rr);
|
||||
void BKE_imbuf_stamp_info(struct RenderResult *rr, struct ImBuf *ibuf);
|
||||
void BKE_image_stamp_buf(struct Scene *scene, struct Object *camera, unsigned char *rect, float *rectf, int width, int height, int channels);
|
||||
bool BKE_imbuf_alpha_test(struct ImBuf *ibuf);
|
||||
int BKE_imbuf_write_stamp(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf);
|
||||
int BKE_imbuf_write_stamp(struct Scene *scene, struct RenderResult *rr, struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf);
|
||||
void BKE_imbuf_write_prepare(struct ImBuf *ibuf, struct ImageFormatData *imf);
|
||||
int BKE_imbuf_write(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf);
|
||||
int BKE_imbuf_write_as(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf, const bool is_copy);
|
||||
|
||||
@@ -2028,26 +2028,45 @@ void BKE_image_stamp_buf(
|
||||
#undef BUFF_MARGIN_Y
|
||||
}
|
||||
|
||||
void BKE_imbuf_stamp_info(Scene *scene, Object *camera, struct ImBuf *ibuf)
|
||||
void BKE_render_result_stamp_info(Scene *scene, Object *camera, struct RenderResult *rr)
|
||||
{
|
||||
struct StampData stamp_data;
|
||||
struct StampData *stamp_data;
|
||||
|
||||
if (!ibuf) return;
|
||||
if (!(scene && scene->r.stamp & R_STAMP_ALL))
|
||||
return;
|
||||
|
||||
/* fill all the data values, no prefix */
|
||||
stampdata(scene, camera, &stamp_data, 0);
|
||||
if (!rr->stamp_data) {
|
||||
stamp_data = MEM_callocN(sizeof(StampData), "RenderResult.stamp_data");
|
||||
}
|
||||
else {
|
||||
stamp_data = rr->stamp_data;
|
||||
}
|
||||
|
||||
if (stamp_data.file[0]) IMB_metadata_change_field(ibuf, "File", stamp_data.file);
|
||||
if (stamp_data.note[0]) IMB_metadata_change_field(ibuf, "Note", stamp_data.note);
|
||||
if (stamp_data.date[0]) IMB_metadata_change_field(ibuf, "Date", stamp_data.date);
|
||||
if (stamp_data.marker[0]) IMB_metadata_change_field(ibuf, "Marker", stamp_data.marker);
|
||||
if (stamp_data.time[0]) IMB_metadata_change_field(ibuf, "Time", stamp_data.time);
|
||||
if (stamp_data.frame[0]) IMB_metadata_change_field(ibuf, "Frame", stamp_data.frame);
|
||||
if (stamp_data.camera[0]) IMB_metadata_change_field(ibuf, "Camera", stamp_data.camera);
|
||||
if (stamp_data.cameralens[0]) IMB_metadata_change_field(ibuf, "Lens", stamp_data.cameralens);
|
||||
if (stamp_data.scene[0]) IMB_metadata_change_field(ibuf, "Scene", stamp_data.scene);
|
||||
if (stamp_data.strip[0]) IMB_metadata_change_field(ibuf, "Strip", stamp_data.strip);
|
||||
if (stamp_data.rendertime[0]) IMB_metadata_change_field(ibuf, "RenderTime", stamp_data.rendertime);
|
||||
stampdata(scene, camera, stamp_data, 0);
|
||||
|
||||
if (!rr->stamp_data) {
|
||||
rr->stamp_data = stamp_data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BKE_imbuf_stamp_info(RenderResult *rr, struct ImBuf *ibuf)
|
||||
{
|
||||
struct StampData *stamp_data = rr->stamp_data;
|
||||
|
||||
if (!ibuf || !stamp_data) return;
|
||||
|
||||
if (stamp_data->file[0]) IMB_metadata_change_field(ibuf, "File", stamp_data->file);
|
||||
if (stamp_data->note[0]) IMB_metadata_change_field(ibuf, "Note", stamp_data->note);
|
||||
if (stamp_data->date[0]) IMB_metadata_change_field(ibuf, "Date", stamp_data->date);
|
||||
if (stamp_data->marker[0]) IMB_metadata_change_field(ibuf, "Marker", stamp_data->marker);
|
||||
if (stamp_data->time[0]) IMB_metadata_change_field(ibuf, "Time", stamp_data->time);
|
||||
if (stamp_data->frame[0]) IMB_metadata_change_field(ibuf, "Frame", stamp_data->frame);
|
||||
if (stamp_data->camera[0]) IMB_metadata_change_field(ibuf, "Camera", stamp_data->camera);
|
||||
if (stamp_data->cameralens[0]) IMB_metadata_change_field(ibuf, "Lens", stamp_data->cameralens);
|
||||
if (stamp_data->scene[0]) IMB_metadata_change_field(ibuf, "Scene", stamp_data->scene);
|
||||
if (stamp_data->strip[0]) IMB_metadata_change_field(ibuf, "Strip", stamp_data->strip);
|
||||
if (stamp_data->rendertime[0]) IMB_metadata_change_field(ibuf, "RenderTime", stamp_data->rendertime);
|
||||
}
|
||||
|
||||
bool BKE_imbuf_alpha_test(ImBuf *ibuf)
|
||||
@@ -2242,15 +2261,14 @@ int BKE_imbuf_write_as(ImBuf *ibuf, const char *name, ImageFormatData *imf,
|
||||
return ok;
|
||||
}
|
||||
|
||||
int BKE_imbuf_write_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const char *name, struct ImageFormatData *imf)
|
||||
int BKE_imbuf_write_stamp(Scene *scene, struct RenderResult *rr, ImBuf *ibuf, const char *name, struct ImageFormatData *imf)
|
||||
{
|
||||
if (scene && scene->r.stamp & R_STAMP_ALL)
|
||||
BKE_imbuf_stamp_info(scene, camera, ibuf);
|
||||
BKE_imbuf_stamp_info(rr, ibuf);
|
||||
|
||||
return BKE_imbuf_write(ibuf, name, imf);
|
||||
}
|
||||
|
||||
|
||||
static void do_makepicstring(
|
||||
char *string, const char *base, const char *relbase, int frame, const char imtype,
|
||||
const ImageFormatData *im_format, const short use_ext, const short use_frames,
|
||||
|
||||
@@ -478,12 +478,14 @@ static void screen_opengl_render_write(OGLRender *oglrender)
|
||||
|
||||
rr = RE_AcquireResultRead(oglrender->re);
|
||||
|
||||
BKE_render_result_stamp_info(scene, camera, rr);
|
||||
|
||||
BKE_image_path_from_imformat(
|
||||
name, scene->r.pic, oglrender->bmain->name, scene->r.cfra,
|
||||
&scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, false, NULL);
|
||||
|
||||
/* write images as individual images or stereo */
|
||||
ok = RE_WriteRenderViewsImage(oglrender->reports, rr, scene, camera, false, name);
|
||||
ok = RE_WriteRenderViewsImage(oglrender->reports, rr, scene, false, name);
|
||||
|
||||
RE_ReleaseResultImage(oglrender->re);
|
||||
|
||||
@@ -805,7 +807,7 @@ static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op)
|
||||
}
|
||||
}
|
||||
else {
|
||||
ok = RE_WriteRenderViewsImage(op->reports, rr, scene, scene->camera, true, name);
|
||||
ok = RE_WriteRenderViewsImage(op->reports, rr, scene, true, name);
|
||||
if (ok) {
|
||||
printf("Saved: %s", name);
|
||||
BKE_reportf(op->reports, RPT_INFO, "Saved file: %s", name);
|
||||
|
||||
@@ -1672,12 +1672,7 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
if (1) {
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
if (scene && scene->camera) {
|
||||
BKE_imbuf_stamp_info(scene, scene->camera, ibuf);
|
||||
}
|
||||
}
|
||||
BKE_imbuf_stamp_info(rr, ibuf);
|
||||
}
|
||||
|
||||
/* fancy multiview OpenEXR */
|
||||
|
||||
@@ -49,6 +49,7 @@ struct Scene;
|
||||
struct SceneRenderLayer;
|
||||
struct EnvMap;
|
||||
struct RenderResult;
|
||||
struct StampData;
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
||||
/* this include is what is exposed of render to outside world */
|
||||
@@ -171,6 +172,8 @@ typedef struct RenderResult {
|
||||
/* render info text */
|
||||
char *text;
|
||||
char *error;
|
||||
|
||||
struct StampData *stamp_data;
|
||||
} RenderResult;
|
||||
|
||||
|
||||
@@ -261,7 +264,7 @@ void RE_init_threadcount(Render *re);
|
||||
/* the main processor, assumes all was set OK! */
|
||||
void RE_TileProcessor(struct Render *re);
|
||||
|
||||
bool RE_WriteRenderViewsImage(struct ReportList *reports, struct RenderResult *rr, struct Scene *scene, struct Object *camera, const bool stamp, char *name);
|
||||
bool RE_WriteRenderViewsImage(struct ReportList *reports, struct RenderResult *rr, struct Scene *scene, const bool stamp, char *name);
|
||||
bool RE_WriteRenderViewsMovie(struct ReportList *reports, struct RenderResult *rr, struct Scene *scene, struct RenderData *rd,
|
||||
struct bMovieHandle *mh, const size_t width, const size_t height, void **movie_ctx_arr,
|
||||
const size_t totvideos, bool preview);
|
||||
|
||||
@@ -363,6 +363,7 @@ void RE_AcquireResultImageViews(Render *re, RenderResult *rr)
|
||||
rr->layers = re->result->layers;
|
||||
rr->xof = re->disprect.xmin;
|
||||
rr->yof = re->disprect.ymin;
|
||||
rr->stamp_data = re->result->stamp_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3026,12 +3027,17 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr
|
||||
scene->r.cfra = frame;
|
||||
|
||||
if (render_initialize_from_main(re, &scene->r, bmain, scene, srl, camera_override, lay_override, 0, 0)) {
|
||||
Object *camera;
|
||||
MEM_reset_peak_memory();
|
||||
|
||||
BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_PRE);
|
||||
|
||||
do_render_all_options(re);
|
||||
|
||||
/* save render result stamp if needed */
|
||||
camera = RE_GetCamera(re);
|
||||
BKE_render_result_stamp_info(scene, camera, re->result);
|
||||
|
||||
if (write_still && !G.is_break) {
|
||||
if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
|
||||
/* operator checks this but in case its called from elsewhere */
|
||||
@@ -3082,7 +3088,7 @@ void RE_RenderFreestyleExternal(Render *re)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scene, struct Object *camera, const bool stamp, char *name)
|
||||
bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scene, const bool stamp, char *name)
|
||||
{
|
||||
bool is_mono;
|
||||
bool ok = true;
|
||||
@@ -3125,8 +3131,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
|
||||
|
||||
if (stamp) {
|
||||
/* writes the name of the individual cameras */
|
||||
Object *view_camera = BKE_camera_multiview_render(scene, camera, rv->name);
|
||||
ok = BKE_imbuf_write_stamp(scene, view_camera, ibuf, name, &rd->im_format);
|
||||
ok = BKE_imbuf_write_stamp(scene, rr, ibuf, name, &rd->im_format);
|
||||
}
|
||||
else {
|
||||
ok = BKE_imbuf_write(ibuf, name, &rd->im_format);
|
||||
@@ -3152,8 +3157,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
|
||||
|
||||
if (stamp) {
|
||||
/* writes the name of the individual cameras */
|
||||
Object *view_camera = BKE_camera_multiview_render(scene, camera, rv->name);
|
||||
ok = BKE_imbuf_write_stamp(scene, view_camera, ibuf, name, &rd->im_format);
|
||||
ok = BKE_imbuf_write_stamp(scene, rr, ibuf, name, &rd->im_format);
|
||||
}
|
||||
else {
|
||||
ok = BKE_imbuf_write(ibuf, name, &rd->im_format);
|
||||
@@ -3188,7 +3192,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
|
||||
ibuf_arr[2] = IMB_stereo3d_ImBuf(&scene->r.im_format, ibuf_arr[0], ibuf_arr[1]);
|
||||
|
||||
if (stamp)
|
||||
ok = BKE_imbuf_write_stamp(scene, camera, ibuf_arr[2], name, &rd->im_format);
|
||||
ok = BKE_imbuf_write_stamp(scene, rr, ibuf_arr[2], name, &rd->im_format);
|
||||
else
|
||||
ok = BKE_imbuf_write(ibuf_arr[2], name, &rd->im_format);
|
||||
|
||||
@@ -3214,7 +3218,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
|
||||
&scene->display_settings, &imf);
|
||||
|
||||
if (stamp)
|
||||
ok = BKE_imbuf_write_stamp(scene, camera, ibuf_arr[2], name, &rd->im_format);
|
||||
ok = BKE_imbuf_write_stamp(scene, rr, ibuf_arr[2], name, &rd->im_format);
|
||||
else
|
||||
ok = BKE_imbuf_write(ibuf_arr[2], name, &imf);
|
||||
|
||||
@@ -3324,7 +3328,6 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie
|
||||
RenderResult rres;
|
||||
double render_time;
|
||||
bool ok = true;
|
||||
Object *camera = RE_GetCamera(re);
|
||||
|
||||
RE_AcquireResultImageViews(re, &rres);
|
||||
|
||||
@@ -3341,7 +3344,7 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie
|
||||
&scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, true, NULL);
|
||||
|
||||
/* write images as individual images or stereo */
|
||||
ok = RE_WriteRenderViewsImage(re->reports, &rres, scene, camera, true, name);
|
||||
ok = RE_WriteRenderViewsImage(re->reports, &rres, scene, true, name);
|
||||
}
|
||||
|
||||
RE_ReleaseResultImageViews(re, &rres);
|
||||
@@ -3469,6 +3472,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
|
||||
}
|
||||
else {
|
||||
for (nfra = sfra, scene->r.cfra = sfra; scene->r.cfra <= efra; scene->r.cfra++) {
|
||||
Object *camera;
|
||||
char name[FILE_MAX];
|
||||
|
||||
/* only border now, todo: camera lens. (ton) */
|
||||
@@ -3567,6 +3571,10 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
|
||||
do_render_all_options(re);
|
||||
totrendered++;
|
||||
|
||||
/* save render result stamp if needed */
|
||||
camera = RE_GetCamera(re);
|
||||
BKE_render_result_stamp_info(scene, camera, re->result);
|
||||
|
||||
if (re->test_break(re->tbh) == 0) {
|
||||
if (!G.is_break)
|
||||
if (!do_write_image_or_movie(re, bmain, scene, mh, totvideos, NULL))
|
||||
|
||||
@@ -115,7 +115,9 @@ void render_result_free(RenderResult *res)
|
||||
MEM_freeN(res->text);
|
||||
if (res->error)
|
||||
MEM_freeN(res->error);
|
||||
|
||||
if (res->stamp_data)
|
||||
MEM_freeN(res->stamp_data);
|
||||
|
||||
MEM_freeN(res);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user