[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48499] branches/soc-2011-tomato/source/ blender: Color management: added support of color applying color transform on save

Sergey Sharybin sergey.vfx at gmail.com
Mon Jul 2 18:38:08 CEST 2012


Revision: 48499
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48499
Author:   nazgul
Date:     2012-07-02 16:38:06 +0000 (Mon, 02 Jul 2012)
Log Message:
-----------
Color management: added support of color applying color transform on save

This applies to files when saving from image editor and when saving
render result.

Currently only works for images which has got float buffer and saving
happens to byte formats (such as PNG, JPEG). Also supports applying
color management for preview jpegs when main buffer is saving into
OpenEXR file.

As default transform when saving from image editor would be the same
settings as image editor uses itself.

Defaults for color correction of rendered images would be default
display name, no view transform and default values for gamma and
exposure.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/colortools.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
    branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c
    branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c
    branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_color_types.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_windowmanager_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_scene.c
    branches/soc-2011-tomato/source/blender/render/intern/source/pipeline.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h	2012-07-02 16:37:40 UTC (rev 48498)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h	2012-07-02 16:38:06 UTC (rev 48499)
@@ -64,6 +64,7 @@
 int     BKE_imtype_supports_zbuf(const char imtype);
 int     BKE_imtype_supports_compress(const char imtype);
 int     BKE_imtype_supports_quality(const char imtype);
+int     BKE_imtype_supports_float(const char imtype);
 char    BKE_imtype_valid_channels(const char imtype);
 char    BKE_imtype_valid_depths(const char imtype);
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/colortools.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/colortools.c	2012-07-02 16:37:40 UTC (rev 48498)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/colortools.c	2012-07-02 16:38:06 UTC (rev 48499)
@@ -1237,7 +1237,7 @@
 void BKE_color_managed_view_settings_copy(ColorManagedViewSettings *new_settings,
                                           const ColorManagedViewSettings *settings)
 {
-	BLI_strncpy(new_settings->view_transform, new_settings->view_transform, sizeof(new_settings->view_transform));
+	BLI_strncpy(new_settings->view_transform, settings->view_transform, sizeof(new_settings->view_transform));
 
 	new_settings->exposure = settings->exposure;
 	new_settings->gamma = settings->gamma;

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-07-02 16:37:40 UTC (rev 48498)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-07-02 16:38:06 UTC (rev 48499)
@@ -1011,6 +1011,20 @@
 	return 0;
 }
 
+int BKE_imtype_supports_float(const char imtype)
+{
+	switch (imtype) {
+		case R_IMF_IMTYPE_CINEON:
+		case R_IMF_IMTYPE_DPX:
+		case R_IMF_IMTYPE_RADHDR:
+		case R_IMF_IMTYPE_OPENEXR:
+		case R_IMF_IMTYPE_MULTILAYER:
+		case R_IMF_IMTYPE_JP2:
+			return TRUE;
+	}
+	return 0;
+}
+
 char BKE_imtype_valid_channels(const char imtype)
 {
 	char chan_flag = IMA_CHAN_FLAG_RGB; /* assume all support rgb */

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-07-02 16:37:40 UTC (rev 48498)
+++ branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c	2012-07-02 16:38:06 UTC (rev 48499)
@@ -798,11 +798,14 @@
 {
 	ImageFormatData *imf = imfptr->data;
 	ID *id = imfptr->id.data;
+	PointerRNA display_settings_ptr, view_settings_ptr;
+	PropertyRNA *prop;
 	const int depth_ok = BKE_imtype_valid_depths(imf->imtype);
 	/* some settings depend on this being a scene thats rendered */
 	const short is_render_out = (id && GS(id->name) == ID_SCE);
 
 	uiLayout *col, *row, *split, *sub;
+	int show_preview = FALSE;
 
 	col = uiLayoutColumn(layout, FALSE);
 
@@ -843,6 +846,7 @@
 	}
 
 	if (is_render_out && (imf->imtype == R_IMF_IMTYPE_OPENEXR)) {
+		show_preview = TRUE;
 		uiItemR(row, imfptr, "use_preview", 0, NULL, ICON_NONE);
 	}
 
@@ -864,6 +868,26 @@
 		uiItemR(col, imfptr, "cineon_gamma", 0, NULL, ICON_NONE);
 #endif
 	}
+
+	/* color management */
+	if (!BKE_imtype_supports_float(imf->imtype) ||
+	    (show_preview && imf->flag & R_IMF_FLAG_PREVIEW_JPG))
+	{
+		prop = RNA_struct_find_property(imfptr, "display_settings");
+		display_settings_ptr = RNA_property_pointer_get(imfptr, prop);
+
+		prop = RNA_struct_find_property(imfptr, "view_settings");
+		view_settings_ptr = RNA_property_pointer_get(imfptr, prop);
+
+		col = uiLayoutColumn(layout, FALSE);
+		uiItemL(col, IFACE_("Color Management"), ICON_NONE);
+
+		uiItemR(col, &display_settings_ptr, "display_device", 0, NULL, ICON_NONE);
+
+		uiItemR(col, &view_settings_ptr, "view_transform", 0, NULL, ICON_NONE);
+		uiItemR(col, &view_settings_ptr, "exposure", 0, NULL, ICON_NONE);
+		uiItemR(col, &view_settings_ptr, "gamma", 0, NULL, ICON_NONE);
+	}
 }
 
 void uiTemplateImageLayers(uiLayout *layout, bContext *C, Image *ima, ImageUser *iuser)

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-07-02 16:37:40 UTC (rev 48498)
+++ branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c	2012-07-02 16:38:06 UTC (rev 48499)
@@ -55,6 +55,7 @@
 #include "BKE_report.h"
 #include "BKE_screen.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
@@ -1082,12 +1083,14 @@
 	}
 }
 
-static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima, Scene *scene, const short guess_path)
+static int save_image_options_init(bContext *C, SaveImageOptions *simopts, SpaceImage *sima, Scene *scene, const short guess_path)
 {
 	void *lock;
 	ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
 
 	if (ibuf) {
+		wmWindow *win = CTX_wm_window(C);
+		const ColorManagedViewSettings *view_settings;
 		Image *ima = sima->image;
 		short is_depth_set = FALSE;
 
@@ -1136,6 +1139,12 @@
 			}
 			BLI_path_abs(simopts->filepath, G.main->name);
 		}
+
+		/* color management */
+		view_settings = IMB_view_settings_get_effective(win, &sima->view_settings);
+
+		BKE_color_managed_display_settings_copy(&simopts->im_format.display_settings, &win->display_settings);
+		BKE_color_managed_view_settings_copy(&simopts->im_format.view_settings, view_settings);
 	}
 
 	ED_space_image_release_buffer(sima, lock);
@@ -1164,6 +1173,29 @@
 	RNA_string_set(op->ptr, "filepath", simopts->filepath);
 }
 
+static ImBuf *save_image_colormanaged_imbuf_acquire(ImBuf *ibuf, SaveImageOptions *simopts, void **cache_handle)
+{
+	ImageFormatData *imf = &simopts->im_format;
+	ImBuf *colormanaged_ibuf;
+	int do_colormanagement;
+
+	*cache_handle = NULL;
+	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);
+
+		colormanaged_ibuf = IMB_allocImBuf(ibuf->x, ibuf->y, ibuf->planes, 0);
+		colormanaged_ibuf->rect = (unsigned int *) display_buffer;
+	}
+	else {
+		colormanaged_ibuf = ibuf;
+	}
+
+	return colormanaged_ibuf;
+}
+
 /* assumes name is FILE_MAX */
 /* ima->name and ibuf->name should end up the same */
 static void save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveImageOptions *simopts, int do_newpath)
@@ -1173,6 +1205,8 @@
 	ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
 
 	if (ibuf) {
+		void *cache_handle;
+		ImBuf *colormanaged_ibuf;
 		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"));
@@ -1199,7 +1233,9 @@
 				ibuf->planes = BKE_imbuf_alpha_test(ibuf) ? 32 : 24;
 			}
 		}
-		
+
+		colormanaged_ibuf = save_image_colormanaged_imbuf_acquire(ibuf, simopts, &cache_handle);
+
 		if (simopts->im_format.imtype == R_IMF_IMTYPE_MULTILAYER) {
 			Scene *scene = CTX_data_scene(C);
 			RenderResult *rr = BKE_image_acquire_renderresult(scene, ima);
@@ -1213,7 +1249,7 @@
 			BKE_image_release_renderresult(scene, ima);
 		}
 		else {
-			if (BKE_imbuf_write_as(ibuf, simopts->filepath, &simopts->im_format, save_copy)) {
+			if (BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, &simopts->im_format, save_copy)) {
 				ok = TRUE;
 			}
 		}
@@ -1262,6 +1298,13 @@
 		WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
 
 		WM_cursor_wait(0);
+
+		if (cache_handle) {
+			colormanaged_ibuf->rect = NULL;
+			IMB_freeImBuf(colormanaged_ibuf);
+
+			IMB_display_buffer_release(cache_handle);
+		}
 	}
 
 	ED_space_image_release_buffer(sima, lock);
@@ -1284,7 +1327,7 @@
 
 	/* just in case to initialize values,
 	 * these should be set on invoke or by the caller. */
-	save_image_options_init(&simopts, sima, CTX_data_scene(C), 0);
+	save_image_options_init(C, &simopts, sima, CTX_data_scene(C), 0);
 
 	save_image_options_from_op(&simopts, op);
 
@@ -1313,7 +1356,7 @@
 
 	save_image_options_defaults(&simopts);
 
-	if (save_image_options_init(&simopts, sima, scene, TRUE) == 0)
+	if (save_image_options_init(C, &simopts, sima, scene, TRUE) == 0)
 		return OPERATOR_CANCELLED;
 	save_image_options_to_op(&simopts, op);
 
@@ -1398,7 +1441,7 @@
 	Scene *scene = CTX_data_scene(C);
 	SaveImageOptions simopts;
 
-	if (save_image_options_init(&simopts, sima, scene, FALSE) == 0)
+	if (save_image_options_init(C, &simopts, sima, scene, FALSE) == 0)
 		return OPERATOR_CANCELLED;
 	save_image_options_from_op(&simopts, op);
 

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-02 16:37:40 UTC (rev 48498)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-02 16:38:06 UTC (rev 48499)
@@ -56,6 +56,9 @@
 
 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
+void IMB_display_buffer_to_imbuf_rect(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
+                                      const struct ColorManagedDisplaySettings *display_settings);
+
 void IMB_display_buffer_release(void *cache_handle);
 
 void IMB_display_buffer_invalidate(struct ImBuf *ibuf);

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-02 16:37:40 UTC (rev 48498)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-02 16:38:06 UTC (rev 48499)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list