[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50506] branches/soc-2011-tomato/source/ blender: Color Management: add View as Render to image datablocks

Sergey Sharybin sergey.vfx at gmail.com
Mon Sep 10 16:47:48 CEST 2012


Revision: 50506
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50506
Author:   nazgul
Date:     2012-09-10 14:47:47 +0000 (Mon, 10 Sep 2012)
Log Message:
-----------
Color Management: add View as Render to image datablocks

This is need since some images (like normal maps, textures and so) would
want to be viewed without any tone map applied on them. On the same time
it's possible that some images would want to be affected by tone maps,
and renders would always want to be affected by tone maps.

After long discussion with Brecht we decided less painful and most clear
way would be to simply add "View as Render" option to image datablocks.

If this option is enabled for image, both settings from Display and
Render blocks of color management settings would be applied on display.

If this option is disabled, only display transform with default view and
no exposure/gamma/curves would be applied.

Render result and compositor viewers would always have "View as Render"
enabled.

There's separated setting when image is saving which says whether saved
image should be affected by render part of color management settings.

This option is enabled by default for render result/node viewer and
disabled by default for all the rest images. This option wouldn't have
affect when saving to float formats such as EXR.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/editors/include/ED_image.h
    branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c
    branches/soc-2011-tomato/source/blender/editors/space_image/image_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c
    branches/soc-2011-tomato/source/blender/editors/space_node/node_view.c
    branches/soc-2011-tomato/source/blender/editors/space_sequencer/sequencer_view.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_image_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_image.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-09-10 14:00:05 UTC (rev 50505)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-09-10 14:47:47 UTC (rev 50506)
@@ -246,6 +246,9 @@
 		ima->source = source;
 		ima->type = type;
 
+		if (source == IMA_SRC_VIEWER)
+			ima->flag |= IMA_VIEW_AS_RENDER;
+
 		BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
 	}
 	return ima;

Modified: branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2012-09-10 14:00:05 UTC (rev 50505)
+++ branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2012-09-10 14:47:47 UTC (rev 50506)
@@ -7926,6 +7926,7 @@
 	/* color management pipeline changes compatibility code */
 	{
 		Scene *scene;
+		Image *ima;
 
 		for (scene = main->scene.first; scene; scene = scene->id.next) {
 			if ((scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) == 0) {
@@ -7936,6 +7937,11 @@
 				}
 			}
 		}
+
+		for (ima = main->image.first; ima; ima = ima->id.next) {
+			if (ima->source == IMA_SRC_VIEWER)
+				ima->flag |= IMA_VIEW_AS_RENDER;
+		}
 	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: branches/soc-2011-tomato/source/blender/editors/include/ED_image.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/include/ED_image.h	2012-09-10 14:00:05 UTC (rev 50505)
+++ branches/soc-2011-tomato/source/blender/editors/include/ED_image.h	2012-09-10 14:47:47 UTC (rev 50506)
@@ -80,7 +80,7 @@
 /* UI level image (texture) updating... render calls own stuff (too) */
 void ED_image_update_frame(const struct Main *mainp, int cfra);
 
-void ED_image_draw_info(struct Scene *scene, struct ARegion *ar, int color_manage, int channels, int x, int y,
+void ED_image_draw_info(struct Scene *scene, struct ARegion *ar, int color_manage, int use_default_view, int channels, int x, int y,
                         const unsigned char cp[4], const float fp[4], int *zp, float *zpf);
 
 #endif /* __ED_IMAGE_H__ */

Modified: branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c	2012-09-10 14:00:05 UTC (rev 50505)
+++ branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c	2012-09-10 14:47:47 UTC (rev 50506)
@@ -692,6 +692,7 @@
 
 			col = uiLayoutColumn(layout, FALSE);
 			uiTemplateColorspaceSettings(col, &imaptr, "colorspace_settings");
+			uiItemR(col, &imaptr, "view_as_render", 0, NULL, ICON_NONE);
 
 			if (ima->source != IMA_SRC_GENERATED) {
 				if (compact == 0) { /* background image view doesnt need these */

Modified: branches/soc-2011-tomato/source/blender/editors/space_image/image_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_image/image_draw.c	2012-09-10 14:00:05 UTC (rev 50505)
+++ branches/soc-2011-tomato/source/blender/editors/space_image/image_draw.c	2012-09-10 14:47:47 UTC (rev 50506)
@@ -94,7 +94,7 @@
 }
 
 /* used by node view too */
-void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int channels, int x, int y,
+void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_default_view, int channels, int x, int y,
                         const unsigned char cp[4], const float fp[4], int *zp, float *zpf)
 {
 	char str[256];
@@ -195,7 +195,10 @@
 		if (color_manage && channels == 4) {
 			float pixel[4];
 
-			IMB_colormanagement_pixel_to_display_space_v4(pixel, fp,  &scene->view_settings, &scene->display_settings);
+			if (use_default_view)
+				IMB_colormanagement_pixel_to_display_space_v4(pixel, fp,  NULL, &scene->display_settings);
+			else
+				IMB_colormanagement_pixel_to_display_space_v4(pixel, fp,  &scene->view_settings, &scene->display_settings);
 
 			BLI_snprintf(str, sizeof(str), "  |  CM  R:%-.4f  G:%-.4f  B:%-.4f", pixel[0], pixel[1], pixel[2]);
 			BLF_position(blf_mono_font, dx, 6, 0);
@@ -245,7 +248,10 @@
 	}
 
 	if (color_manage) {
-		IMB_colormanagement_pixel_to_display_space_v4(finalcol, col,  &scene->view_settings, &scene->display_settings);
+		if (use_default_view)
+			IMB_colormanagement_pixel_to_display_space_v4(finalcol, col,  NULL, &scene->display_settings);
+		else
+			IMB_colormanagement_pixel_to_display_space_v4(finalcol, col,  &scene->view_settings, &scene->display_settings);
 	}
 	else {
 		copy_v4_v4(finalcol, col);
@@ -491,7 +497,8 @@
 
 static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene, Image *ima, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
 {
-	unsigned int *display_buffer, *rect;
+	unsigned char *display_buffer;
+	unsigned int *rect;
 	int dx, dy, sx, sy, x, y;
 	void *cache_handle;
 
@@ -499,8 +506,10 @@
 	if (ima->xrep < 1) return;
 	if (ima->yrep < 1) return;
 
-	display_buffer = (unsigned int *) IMB_display_buffer_acquire(ibuf, &scene->view_settings,
-			&scene->display_settings, &cache_handle);
+	if (ima->flag & IMA_VIEW_AS_RENDER)
+		display_buffer = IMB_display_buffer_acquire(ibuf, &scene->view_settings, &scene->display_settings, &cache_handle);
+	else
+		display_buffer = IMB_display_buffer_acquire(ibuf, NULL, &scene->display_settings, &cache_handle);
 
 	if (!display_buffer)
 		return;
@@ -515,7 +524,7 @@
 	dy = ibuf->y / ima->yrep;
 	sx = (sima->curtile % ima->xrep) * dx;
 	sy = (sima->curtile / ima->xrep) * dy;
-	rect = get_part_from_buffer(display_buffer, ibuf->x, sx, sy, sx + dx, sy + dy);
+	rect = get_part_from_buffer((unsigned int*)display_buffer, ibuf->x, sx, sy, sx + dx, sy + dy);
 	
 	/* draw repeated */
 	for (sy = 0; sy + dy <= ibuf->y; sy += dy) {

Modified: branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c	2012-09-10 14:00:05 UTC (rev 50505)
+++ branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c	2012-09-10 14:47:47 UTC (rev 50506)
@@ -1183,6 +1183,8 @@
 static void save_image_options_from_op(SaveImageOptions *simopts, wmOperator *op)
 {
 	if (op->customdata) {
+		BKE_color_managed_view_settings_free(&simopts->im_format.view_settings);
+
 		simopts->im_format = *(ImageFormatData *)op->customdata;
 	}
 
@@ -1195,13 +1197,15 @@
 static void save_image_options_to_op(SaveImageOptions *simopts, wmOperator *op)
 {
 	if (op->customdata) {
+		BKE_color_managed_view_settings_free(&((ImageFormatData *)op->customdata)->view_settings);
+
 		*(ImageFormatData *)op->customdata = simopts->im_format;
 	}
 
 	RNA_string_set(op->ptr, "filepath", simopts->filepath);
 }
 
-static ImBuf *save_image_colormanaged_imbuf_acquire(ImBuf *ibuf, SaveImageOptions *simopts, void **cache_handle)
+static ImBuf *save_image_colormanaged_imbuf_acquire(ImBuf *ibuf, SaveImageOptions *simopts, int save_as_render, void **cache_handle)
 {
 	ImageFormatData *imf = &simopts->im_format;
 	ImBuf *colormanaged_ibuf;
@@ -1211,9 +1215,13 @@
 	do_colormanagement = !BKE_imtype_supports_float(imf->imtype);
 
 	if (do_colormanagement) {
-		unsigned char *display_buffer =
-			IMB_display_buffer_acquire(ibuf, &imf->view_settings, &imf->display_settings, cache_handle);
+		unsigned char *display_buffer;
 
+		if (save_as_render)
+			display_buffer = IMB_display_buffer_acquire(ibuf, &imf->view_settings, &imf->display_settings, cache_handle);
+		else
+			display_buffer = IMB_display_buffer_acquire(ibuf, NULL, &imf->display_settings, cache_handle);
+
 		if (*cache_handle) {
 			colormanaged_ibuf = IMB_allocImBuf(ibuf->x, ibuf->y, ibuf->planes, 0);
 			colormanaged_ibuf->rect = (unsigned int *) display_buffer;
@@ -1247,6 +1255,7 @@
 		const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id);
 		const short relative = (RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path"));
 		const short save_copy = (RNA_struct_find_property(op->ptr, "copy") && RNA_boolean_get(op->ptr, "copy"));
+		const short save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") && RNA_boolean_get(op->ptr, "save_as_render"));
 		short ok = FALSE;
 
 		/* old global to ensure a 2nd save goes to same dir */
@@ -1271,7 +1280,7 @@
 			}
 		}
 
-		colormanaged_ibuf = save_image_colormanaged_imbuf_acquire(ibuf, simopts, &cache_handle);
+		colormanaged_ibuf = save_image_colormanaged_imbuf_acquire(ibuf, simopts, save_as_render, &cache_handle);
 
 		if (simopts->im_format.imtype == R_IMF_IMTYPE_MULTILAYER) {
 			Scene *scene = CTX_data_scene(C);
@@ -1350,6 +1359,9 @@
 static void image_save_as_free(wmOperator *op)
 {
 	if (op->customdata) {
+		ImageFormatData *im_format = (ImageFormatData *)op->customdata;
+		BKE_color_managed_view_settings_free(&im_format->view_settings);
+
 		MEM_freeN(op->customdata);
 		op->customdata = NULL;
 	}
@@ -1402,6 +1414,11 @@
 		RNA_boolean_set(op->ptr, "copy", TRUE);
 	}
 
+	if (ima->source == IMA_SRC_VIEWER)
+		RNA_boolean_set(op->ptr, "save_as_render", TRUE);
+	else
+		RNA_boolean_set(op->ptr, "save_as_render", FALSE);
+
 	op->customdata = MEM_mallocN(sizeof(simopts.im_format), __func__);
 	memcpy(op->customdata, &simopts.im_format, sizeof(simopts.im_format));
 
@@ -1437,7 +1454,7 @@
 
 	/* image template */
 	RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &ptr);
-	uiTemplateImageSettings(layout, &ptr, TRUE);
+	uiTemplateImageSettings(layout, &ptr, FALSE);
 
 	/* main draw call */
 	RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
@@ -1465,6 +1482,7 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
 	/* properties */
+	RNA_def_boolean(ot->srna, "save_as_render", 0, "Save As Render", "Apply render part of display transform when saving byte image");
 	RNA_def_boolean(ot->srna, "copy", 0, "Copy", "Create a new image file without modifying the current image in blender");
 
 	WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_SAVE,
@@ -1989,6 +2007,7 @@
 
 	int draw;
 	int color_manage;
+	int use_default_view;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list