[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48959] branches/soc-2011-tomato: Color management: support of configurable input color space

Sergey Sharybin sergey.vfx at gmail.com
Mon Jul 16 12:50:53 CEST 2012


Revision: 48959
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48959
Author:   nazgul
Date:     2012-07-16 10:50:53 +0000 (Mon, 16 Jul 2012)
Log Message:
-----------
Color management: support of configurable input color space

This adds a user-defined input color space name for image and
movie clip data blocks. Support for this thing for other data
blocks is still a TODO.

Input color space is being used on loading file to convert
loaded image buffer from this space to scene linear space,
later this space is never used in a pipeline.

Color space name was wrapped into own structure like it's
done for display and view settings. This helps keep code
de-duplicated in RNA and it'll help when likely more options
are added into input color space settings (i.e. flag whether
image could be color managed or it's a non-color data).

This implied quite of internal refactoring:

- Made routines around threaded display buffer calculation
  more general, so any kind of color transform could be
  performed using the same technique.

- Added function to convert given float buffer from given
  input color space to output color space. This is a public
  function which could be used in such a things as compositor
  node.

- Added function to convert ImBuf's content to scene linear
  space. Currently used only for images and clips. Should be
  added to any image/movie-related data blocks such as
  sequencer strips, but that a bit more long-term plan.

- If input color space is set to NONE then no buffer transform
  would be performed on image loading. It'll behave in the same
  way as using scene linear as input space.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_buttons.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
    branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c
    branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/IMB_colormanagement_intern.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_image_types.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_movieclip_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_color.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_image.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_movieclip.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2012-07-16 10:50:53 UTC (rev 48959)
@@ -1037,6 +1037,7 @@
 
         col = layout.column()
         col.template_movieclip(sc, "clip", compact=True)
+        col.separator()
         col.prop(clip, "start_frame")
         col.prop(clip, "frame_offset")
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-07-16 10:50:53 UTC (rev 48959)
@@ -47,6 +47,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
@@ -2189,6 +2190,9 @@
 /* common stuff to do with images after loading */
 static void image_initialize_after_load(Image *ima, ImBuf *ibuf)
 {
+	/* make float buffer stored in ImBuf scene linear space */
+	IMB_colormanagement_imbuf_make_scene_linear(ibuf, &ima->colorspace_settings);
+
 	/* preview is NULL when it has never been used as an icon before */
 	if (G.background == 0 && ima->preview == NULL)
 		BKE_icon_changed(BKE_icon_getid(&ima->id));

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-07-16 10:50:53 UTC (rev 48959)
@@ -74,6 +74,7 @@
 #include "BKE_image.h"  /* openanim */
 #include "BKE_tracking.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 #include "IMB_moviecache.h"
@@ -777,6 +778,11 @@
 			ibuf = movieclip_load_movie_file(clip, user, framenr, flag);
 		}
 
+		if (ibuf) {
+			/* make float buffer stored in ImBuf scene linear space */
+			IMB_colormanagement_imbuf_make_scene_linear(ibuf, &clip->colorspace_settings);
+		}
+
 		if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0)
 			put_imbuf_cache(clip, user, ibuf, flag);
 	}

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_buttons.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_buttons.c	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_buttons.c	2012-07-16 10:50:53 UTC (rev 48959)
@@ -118,6 +118,9 @@
 		uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
 
 	if (clip) {
+		uiLayout *col;
+		PointerRNA colorspace_settings_ptr;
+
 		row = uiLayoutRow(layout, FALSE);
 		block = uiLayoutGetBlock(row);
 		uiDefBut(block, LABEL, 0, "File Path:", 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
@@ -128,6 +131,14 @@
 
 		uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
 		uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
+
+		/* OCIO_TODO: de-duplicate this with image space and other areas */
+		prop = RNA_struct_find_property(&clipptr, "colorspace_settings");
+		colorspace_settings_ptr = RNA_property_pointer_get(&clipptr, prop);
+
+		col = uiLayoutColumn(layout, FALSE);
+		uiItemL(col, "Color Space:", ICON_NONE);
+		uiItemR(col, &colorspace_settings_ptr, "name", 0, "", ICON_NONE);
 	}
 }
 

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c	2012-07-16 10:50:53 UTC (rev 48959)
@@ -540,6 +540,8 @@
 	/* fields to check if cache is still valid */
 	int framenr, start_frame, frame_offset;
 	short render_size, render_flag;
+
+	char colorspace[64];
 } SpaceClipDrawContext;
 
 int ED_space_clip_texture_buffer_supported(SpaceClip *sc)
@@ -583,6 +585,15 @@
 	need_rebind |= context->start_frame != clip->start_frame;
 	need_rebind |= context->frame_offset != clip->frame_offset;
 
+	if (!need_rebind) {
+		/* OCIO_TODO: not entirely nice, but currently it seems to be easiest way
+		 *            to deal with changing input color space settings
+		 *            pointer-based check could fail due to new buffers could be
+		 *            be allocated on on old memory
+		 */
+		need_rebind = strcmp(context->colorspace, clip->colorspace_settings.name) != 0;
+	}
+
 	if (need_rebind) {
 		int width = ibuf->x, height = ibuf->y;
 		int need_recreate = 0;
@@ -636,6 +647,8 @@
 		context->render_flag = sc->user.render_flag;
 		context->start_frame = clip->start_frame;
 		context->frame_offset = clip->frame_offset;
+
+		strcpy(context->colorspace, clip->colorspace_settings.name);
 	}
 	else {
 		/* displaying exactly the same image which was loaded t oa texture,

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-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/editors/space_image/image_buttons.c	2012-07-16 10:50:53 UTC (rev 48959)
@@ -613,6 +613,7 @@
 	uiLayout *row, *split, *col;
 	uiBlock *block;
 	char str[128];
+
 	void *lock;
 
 	if (!ptr->data)
@@ -728,8 +729,18 @@
 					uiItemL(layout, str, ICON_NONE);
 				}
 			}
-			
+
 			if (ima->source != IMA_SRC_GENERATED) {
+				PointerRNA colorspace_settings_ptr;
+
+				/* OCIO_TODO: de-duplicate this with clip space and other areas */
+				prop = RNA_struct_find_property(&imaptr, "colorspace_settings");
+				colorspace_settings_ptr = RNA_property_pointer_get(&imaptr, prop);
+
+				col = uiLayoutColumn(layout, FALSE);
+				uiItemL(col, "Color Space:", ICON_NONE);
+				uiItemR(col, &colorspace_settings_ptr, "name", 0, "", ICON_NONE);
+
 				if (compact == 0) { /* background image view doesnt need these */
 					uiItemS(layout);
 

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-16 10:50:53 UTC (rev 48959)
@@ -33,6 +33,7 @@
 
 #define BCM_CONFIG_FILE "config.ocio"
 
+struct ColorManagedColorspaceSettings;
 struct ColorManagedDisplaySettings;
 struct ColorManagedViewSettings;
 struct EnumPropertyItem;
@@ -47,6 +48,13 @@
 void IMB_colormanagement_init(void);
 void IMB_colormanagement_exit(void);
 
+/* ** Color space transformation functions ** */
+void IMB_colormanagement_colorspace_transform(float *buffer, int width, int height, int channels,
+                                              const char *from_colorspace, const char *to_colorspace);
+
+void IMB_colormanagement_imbuf_make_scene_linear(struct ImBuf *ibuf,
+		struct ColorManagedColorspaceSettings *colorspace_settings);
+
 /* ** Public display buffers interfaces ** */
 
 void IMB_colormanage_cache_free(struct ImBuf *ibuf);
@@ -74,9 +82,14 @@
 int IMB_colormanagement_view_get_named_index(const char *name);
 const char *IMB_colormanagement_view_get_indexed_name(int index);
 
+/* ** Color space functions ** */
+int IMB_colormanagement_colorspace_get_named_index(const char *name);
+const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
+
 /* ** RNA helper functions ** */
 void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem);
 void IMB_colormanagement_view_items_add(struct EnumPropertyItem **items, int *totitem, const char *display_name);
+void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
 
 /* Tile-based buffer management */
 struct PartialBufferUpdateContext *IMB_partial_buffer_update_context_new(struct ImBuf *ibuf);

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/IMB_colormanagement_intern.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/IMB_colormanagement_intern.h	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/IMB_colormanagement_intern.h	2012-07-16 10:50:53 UTC (rev 48959)
@@ -64,4 +64,8 @@
 struct ColorManagedView *colormanage_view_get_indexed(int index);
 struct ColorManagedView *colormanage_view_get_named(const char *name);
 
+struct ColorSpace *colormanage_colorspace_add(const char *name);
+struct ColorSpace *colormanage_colorspace_get_named(const char *name);
+struct ColorSpace *colormanage_colorspace_get_indexed(int index);
+
 #endif // IMB_COLORMANAGEMENT_INTERN_H

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-16 10:50:38 UTC (rev 48958)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-16 10:50:53 UTC (rev 48959)
@@ -35,6 +35,8 @@
 #include <math.h>
 
 #include "DNA_color_types.h"
+#include "DNA_image_types.h"
+#include "DNA_movieclip_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
@@ -70,17 +72,16 @@
 
 /* ** list of all supported color spaces, displays and views */
 #ifdef WITH_OCIO
-static ListBase global_colorspaces = {NULL};
-
 static char global_role_scene_linear[64];
 static char global_role_color_picking[64];
 static char global_role_texture_painting[64];
-
 #endif
 
+static ListBase global_colorspaces = {NULL};
 static ListBase global_displays = {NULL};
 static ListBase global_views = {NULL};
 
+static int global_tot_colorspace = 0;
 static int global_tot_display = 0;
 static int global_tot_view = 0;
 
@@ -229,7 +230,8 @@
 	if (!ibuf->colormanage_cache->moviecache) {
 		struct MovieCache *moviecache;
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list