[Bf-blender-cvs] [09c6b31] multiview: New Stereo Image Output options (work in progress)

Dalai Felinto noreply at git.blender.org
Thu Aug 7 20:19:01 CEST 2014


Commit: 09c6b31395e59f5a1fd741262beac54883a95711
Author: Dalai Felinto
Date:   Thu Aug 7 20:14:58 2014 +0200
Branches: multiview
https://developer.blender.org/rB09c6b31395e59f5a1fd741262beac54883a95711

New Stereo Image Output options (work in progress)

Now there is a new menu to let the user pick whether to export the image as Individual images, or as Stereo 3D.
The only mode currently working is Anaglyph (and it goes better with RGBA output).

It includes a big refactor of my original approach to save_image_doit

I'm wait to decide the best design with Sergey before implementing the other modes (and finishing anaglyph to handle all cases, spaces).

===================================================================

M	release/scripts/startup/bl_ui/properties_render.py
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/space_image/image_buttons.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/imbuf/CMakeLists.txt
M	source/blender/imbuf/IMB_imbuf.h
A	source/blender/imbuf/intern/stereoimbuf.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/makesrna/intern/rna_ui_api.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index 9ffd244..39f7c7a 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -404,6 +404,8 @@ class RENDER_PT_output(RenderButtonsPanel, Panel):
         col.prop(rd, "use_render_cache")
 
         layout.template_image_settings(image_settings, color_management=False)
+        if rd.use_multiple_views:
+            layout.template_image_views(image_settings)
 
         if file_format == 'QUICKTIME':
             quicktime = rd.quicktime
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 139e243..72b3280 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -860,6 +860,7 @@ void uiTemplateGameStates(uiLayout *layout, struct PointerRNA *ptr, const char *
                       PointerRNA *used_ptr, const char *used_propname, int active_state);
 void uiTemplateImage(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *userptr, int compact);
 void uiTemplateImageSettings(uiLayout *layout, struct PointerRNA *imfptr, int color_management);
+void uiTemplateImageViews(uiLayout *layout, struct PointerRNA *imfptr);
 void uiTemplateImageLayers(uiLayout *layout, struct bContext *C, struct Image *ima, struct ImageUser *iuser);
 void uiTemplateRunningJobs(uiLayout *layout, struct bContext *C);
 void uiOperatorSearch_But(uiBut *but);
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 8fa7e72..cab326c 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -973,6 +973,53 @@ void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, int color_man
 	}
 }
 
+void uiTemplateImageViews(uiLayout *layout, PointerRNA *imfptr)
+{
+	ImageFormatData *imf = imfptr->data;
+	PropertyRNA *prop;
+	PointerRNA stereo_output_ptr;
+	StereoDisplay *stereo_output = &imf->stereo_output;
+
+	uiLayout *col, *box;
+
+	/* OpenEXR multiview is only to save multiview exr */
+	if (imf->imtype == R_IMF_IMTYPE_MULTIVIEW)
+		return;
+
+	col = uiLayoutColumn(layout, false);
+
+	uiItemL(col, IFACE_("Views Output:"), ICON_NONE);
+	uiItemR(uiLayoutRow(col, false), imfptr, "views_output", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
+
+	prop = RNA_struct_find_property(imfptr, "stereo_output");
+	stereo_output_ptr = RNA_property_pointer_get(imfptr, prop);
+
+	box = uiLayoutBox(col);
+	uiLayoutSetActive(box, imf->views_output == R_IMF_VIEWS_STEREO_3D);
+	col = uiLayoutColumn(box, false);
+
+	uiItemR(col, &stereo_output_ptr, "stereo_mode", 0, NULL, ICON_NONE);
+
+	switch (stereo_output->display_mode) {
+		case S3D_DISPLAY_ANAGLYPH:
+		{
+			uiItemR(col, &stereo_output_ptr, "anaglyph_type", 0, NULL, ICON_NONE);
+			break;
+		}
+		case S3D_DISPLAY_INTERLACE:
+		{
+			uiItemR(col, &stereo_output_ptr, "interlace_type", 0, NULL, ICON_NONE);
+			uiItemR(col, &stereo_output_ptr, "use_interlace_swap", 0, NULL, ICON_NONE);
+			break;
+		}
+		case S3D_DISPLAY_SIDEBYSIDE:
+		{
+			uiItemR(col, &stereo_output_ptr, "use_sidebyside_crosseyed", 0, NULL, ICON_NONE);
+			break;
+		}
+	}
+}
+
 void uiTemplateImageLayers(uiLayout *layout, bContext *C, Image *ima, ImageUser *iuser)
 {
 	Scene *scene = CTX_data_scene(C);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 9692561..71c396e 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1530,6 +1530,52 @@ static void save_image_post(wmOperator *op, ImBuf *ibuf, Image *ima, int ok, int
 	}
 }
 
+static void save_imbuf_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf)
+{
+	if (colormanaged_ibuf != ibuf) {
+		/* This guys might be modified by image buffer write functions,
+		 * need to copy them back from color managed image buffer to an
+		 * original one, so file type of image is being properly updated.
+		 */
+		ibuf->ftype = colormanaged_ibuf->ftype;
+		ibuf->planes = colormanaged_ibuf->planes;
+
+		IMB_freeImBuf(colormanaged_ibuf);
+	}
+}
+
+static void save_image_get_view_filepath(Scene *scene, const char *filepath, RenderView *rv,
+                                         char *r_filepath, char *r_view)
+{
+	SceneRenderView *srv;
+	char suffix[FILE_MAX];
+
+	srv = BLI_findstring(&scene->r.views, rv->name, offsetof(SceneRenderView, name));
+
+	if (srv) {
+		if (r_filepath) {
+			BLI_strncpy(suffix, srv->suffix, sizeof(suffix));
+			BLI_strncpy(r_filepath, filepath, FILE_MAX);
+			BLI_path_view(r_filepath, suffix);
+		}
+
+		if (r_view) {
+			BLI_strncpy(r_view, srv->name, FILE_MAX);
+		}
+	}
+	else {
+		if (r_filepath) {
+			BLI_strncpy(suffix, rv->name, sizeof(suffix));
+			BLI_strncpy(r_filepath, filepath, FILE_MAX);
+			BLI_path_view(r_filepath, suffix);
+		}
+
+		if (r_view) {
+			BLI_strncpy(r_view, rv->name, FILE_MAX);
+		}
+	}
+}
+
 /**
  * \return success.
  * \note ``ima->name`` and ``ibuf->name`` should end up the same.
@@ -1544,6 +1590,8 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
 	RenderResult *rr;
 	bool ok = false;
 
+	WM_cursor_wait(1);
+
 	if (ibuf) {
 		ImBuf *colormanaged_ibuf = NULL;
 		const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id);
@@ -1552,11 +1600,12 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
 		const bool save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") && RNA_boolean_get(op->ptr, "save_as_render"));
 		ImageFormatData *imf = &simopts->im_format;
 
+		const bool is_multilayer = imf->imtype == R_IMF_IMTYPE_MULTILAYER;
+		bool is_mono;
+
 		/* old global to ensure a 2nd save goes to same dir */
 		BLI_strncpy(G.ima, simopts->filepath, sizeof(G.ima));
 
-		WM_cursor_wait(1);
-
 		if (ima->type == IMA_TYPE_R_RESULT) {
 			/* enforce user setting for RGB or RGBA, but skip BW */
 			if (simopts->im_format.planes == R_IMF_PLANES_RGBA) {
@@ -1577,132 +1626,181 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
 		/* we need renderresult for exr and multiview */
 		scene = CTX_data_scene(C);
 		rr = BKE_image_acquire_renderresult(scene, ima);
+		is_mono = rr ? BLI_countlist(&rr->views) < 2 : false;
 
-		if (simopts->im_format.imtype == R_IMF_IMTYPE_MULTIVIEW) {
-			ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, simopts->im_format.exr_codec, true, "");
-
-			save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath);
-			ED_space_image_release_buffer(sima, ibuf, lock);
-		}
+		/* error handling */
+		if (!rr) {
+			if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
+				BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image");
+				goto cleanup;
+			}
 
-		else if (simopts->im_format.imtype == R_IMF_IMTYPE_MULTILAYER) {
-			if (rr) {
-				int numviews = BLI_countlist(&rr->views);
+			else if (is_multilayer) {
+				BKE_report(op->reports, RPT_ERROR, "Did not write, no Multiview Image");
+				goto cleanup;
+			}
 
-				/* monoview */
-				if (numviews < 2) {
-					ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, simopts->im_format.exr_codec, false, "");
+			else if (!is_mono) {
+				BKE_report(op->reports, RPT_ERROR, "Did not write, the image doesn't have multiple views");
+				goto cleanup;
+			}
 
-					save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath);
-					ED_space_image_release_buffer(sima, ibuf, lock);
+			else {
+				BKE_image_release_renderresult(scene, ima);
+			}
+		}
+		else {
+			if (imf->imtype != R_IMF_IMTYPE_MULTIVIEW && imf->views_output == R_IMF_VIEWS_STEREO_3D) {
+				if ((ima->flag & IMA_IS_STEREO) == 0) {
+					BKE_reportf(op->reports, RPT_ERROR, "Did not write, the image doesn't have a \"%s\" and \"%s\" views",
+					           STEREO_LEFT_NAME, STEREO_RIGHT_NAME);
+					goto cleanup;
 				}
 
-				/* multiview - individual images */
-				else {
-					char filepath[FILE_MAX];
-					SceneRenderView *srv;
-					RenderView *rv;
-					char view[FILE_MAX];
-					char suffix[FILE_MAX];
-
-					for (rv = (RenderView *) rr->views.first; rv; rv = rv->next) {
-						srv = BLI_findstring(&scene->r.views, rv->name, offsetof(SceneRenderView, name));
+				/* it shouldn't ever happen*/
+				if ((BLI_findstring(&rr->views, STEREO_LEFT_NAME, offsetof(RenderView, name)) == NULL) ||
+				    (BLI_findstring(&rr->views, STEREO_RIGHT_NAME, offsetof(RenderView, name)) == NULL)) {
+					BKE_reportf(op->reports, RPT_ERROR, "Did not write, the image doesn't have a \"%s\" and \"%s\" views",
+					           STEREO_LEFT_NAME, STEREO_RIGHT_NAME);
+					goto cleanup;
+				}
 
-						BLI_strncpy(view, srv->name, sizeof(view));
-						BLI_strncpy(suffix, srv->suffix, sizeof(suffix));
+			}
+		}
 
-						BLI_strncpy(filepath, simopts->filepath, sizeof(filepath));
-						BLI_path_view(filepath, suffix);
+		/* fancy multiview OpenEXR */
+		if (imf->imtype == R_IMF_IMTYPE_MULTIVIEW) {
+			ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf->exr_codec, true, "");
+			save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath);
+			ED_space_image_release_buffer(sima, ibuf, lock);
+		}
 
-						ok &= RE_WriteRenderResult(op->reports, rr, filepath, simopts->im_format.exr_codec, false, view);
-						save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, filepath);
-					}
-					ED_space_image_release_buffer(sima, ibuf, lock);
-				}
+		/* mono, legacy code */
+		else if(is_mono) {
+			if (is_multilayer) {
+				ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf->exr_codec, false, "");
 			}
 			else {
-				BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image");
+				colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf);
+				ok = BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, imf, save_copy);
+				save_imbuf_post(ibuf, col

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list