[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48841] branches/soc-2011-tomato: Color management support for sequencer

Sergey Sharybin sergey.vfx at gmail.com
Wed Jul 11 21:39:43 CEST 2012


Revision: 48841
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48841
Author:   nazgul
Date:     2012-07-11 19:39:43 +0000 (Wed, 11 Jul 2012)
Log Message:
-----------
Color management support for sequencer

This adds color management controls to the sequencer space,
which are applying on the displaying image.

Currently used the same UI approach as was used for other
areas, but this would probably be cleaned up in the nearest
future.

This required a bit of hackish stuff to be done, Namely color
management for the sequencer requires one extra step in the
conversion chain to convert sRGB float buffer to linear space.
This was made by setting special flag in ImBuf. Later this
could be done using input color space for the ImBuf probably.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_sequencer.py
    branches/soc-2011-tomato/source/blender/editors/space_sequencer/sequencer_draw.c
    branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_sequencer.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_sequencer.py	2012-07-11 19:32:32 UTC (rev 48840)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_sequencer.py	2012-07-11 19:39:43 UTC (rev 48841)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 import bpy
 from bpy.types import Header, Menu, Panel
+from bl_ui.properties_color_management import ColorManagedViewSettingsPanel
 
 
 def act_strip(context):
@@ -860,5 +861,8 @@
             col.prop(st, "show_separate_color")
         col.prop(st, "proxy_render_size")
 
+class SEQUENCER_PT_display_properties(SequencerButtonsPanel_Output, Panel, ColorManagedViewSettingsPanel):
+    bl_label = "Display Properties"
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)

Modified: branches/soc-2011-tomato/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_sequencer/sequencer_draw.c	2012-07-11 19:32:32 UTC (rev 48840)
+++ branches/soc-2011-tomato/source/blender/editors/space_sequencer/sequencer_draw.c	2012-07-11 19:39:43 UTC (rev 48841)
@@ -52,6 +52,7 @@
 
 #include "BKE_sound.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 
 #include "BIF_gl.h"
@@ -68,6 +69,9 @@
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
 /* own include */
 #include "sequencer_intern.h"
 
@@ -812,6 +816,8 @@
 	GLuint texid;
 	GLuint last_texid;
 	SeqRenderData context;
+	unsigned char *display_buffer;
+	void *cache_handle = NULL;
 
 	render_size = sseq->render_size;
 	if (render_size == 0) {
@@ -892,12 +898,23 @@
 	if (scope) {
 		IMB_freeImBuf(ibuf);
 		ibuf = scope;
+
+		if (ibuf->rect_float && ibuf->rect == NULL) {
+			IMB_rect_from_float(ibuf);
+		}
+
+		display_buffer = (unsigned char *)ibuf->rect;
 	}
+	else {
+		const ColorManagedViewSettings *view_settings;
+		wmWindow *win = CTX_wm_window(C);
 
-	if (ibuf->rect_float && ibuf->rect == NULL) {
-		IMB_rect_from_float(ibuf);	
+		ibuf->colormanagement_flags |= IMB_COLORMANAGEMENT_SRGB_SOURCE;
+
+		view_settings = IMB_view_settings_get_effective(win, &sseq->view_settings);
+		display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, &win->display_settings, &cache_handle);
 	}
-	
+
 	/* setting up the view - actual drawing starts here */
 	UI_view2d_view_ortho(v2d);
 
@@ -910,7 +927,7 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
 	glBegin(GL_QUADS);
 
 	if (frame_ofs) {
@@ -1042,6 +1059,8 @@
 		}
 	}
 
+	if (cache_handle)
+		IMB_display_buffer_release(cache_handle);
 }
 
 #if 0

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h	2012-07-11 19:32:32 UTC (rev 48840)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h	2012-07-11 19:39:43 UTC (rev 48841)
@@ -128,6 +128,7 @@
 	unsigned int   encodedbuffersize; /* Size of encodedbuffer */
 
 	/* color management */
+	unsigned int colormanagement_flags;  /* flags filed used by color management rutines */
 	unsigned int *display_buffer_flags;  /* array of per-display display buffers dirty flags */
 	struct ColormanageCache *colormanage_cache;  /* cache used by color management */
 
@@ -256,4 +257,12 @@
 extern const char *imb_ext_movie[];
 extern const char *imb_ext_audio[];
 
+/* imbuf->colormanagement_flags */
+
+/* special flag used for color management of compositor results,
+ * which are in sRGB space and requires extra step in color conversions
+ * could be replaced with something more general in the future
+ */
+#define IMB_COLORMANAGEMENT_SRGB_SOURCE    (1 << 0)
+
 #endif

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-11 19:32:32 UTC (rev 48840)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-11 19:39:43 UTC (rev 48841)
@@ -625,6 +625,8 @@
 	int channels;
 	int dither;
 	int predivide;
+
+	int buffer_in_srgb;
 } DisplayBufferThread;
 
 static void display_buffer_apply_threaded(ImBuf *ibuf, float *buffer, unsigned char *display_buffer,
@@ -637,8 +639,16 @@
 	int i, tot_thread = BLI_system_thread_count();
 	int start_line, tot_line;
 
-	if (tot_thread > 1)
+	if (tot_thread > 1) {
+		/* XXX: IMB_buffer_byte_from_float_tonecurve isn't thread-safe because of
+		 *      possible non-initialized sRGB conversion stuff. Make sure it's properly
+		 *      initialized before starting threads, but likely this stuff should be
+		 *      initialized somewhere before to avoid possible issues in other issues.
+		 */
+		BLI_init_srgb_conversion();
+
 		BLI_init_threads(&threads, do_thread, tot_thread);
+	}
 
 	start_line = 0;
 	tot_line = ((float)(ibuf->y / tot_thread)) + 0.5f;
@@ -664,6 +674,7 @@
 		handles[i].channels = ibuf->channels;
 		handles[i].dither = ibuf->dither;
 		handles[i].predivide = predivide;
+		handles[i].buffer_in_srgb = ibuf->colormanagement_flags & IMB_COLORMANAGEMENT_SRGB_SOURCE;
 
 		if (tot_thread > 1)
 			BLI_insert_thread(&threads, &handles[i]);
@@ -677,6 +688,30 @@
 		do_thread(&handles[0]);
 }
 
+static void *display_buffer_apply_get_linear_buffer(DisplayBufferThread *handle)
+{
+	float *linear_buffer = handle->buffer;
+
+	if (handle->buffer_in_srgb) {
+		float *buffer = handle->buffer;
+
+		int channels = handle->channels;
+		int width = handle->width;
+		int height = handle->tot_line;
+		int predivide = handle->predivide;
+
+		int buffer_size = 4 * channels * width * height;
+
+		linear_buffer = MEM_callocN(buffer_size * sizeof(float), "color conversion linear buffer");
+
+		IMB_buffer_float_from_float(linear_buffer, buffer, channels,
+		                            IB_PROFILE_LINEAR_RGB, IB_PROFILE_SRGB,
+		                            predivide, width, height, width, width);
+	}
+
+	return linear_buffer;
+}
+
 static void *do_display_buffer_apply_tonemap_thread(void *handle_v)
 {
 	DisplayBufferThread *handle = (DisplayBufferThread *) handle_v;
@@ -691,24 +726,22 @@
 	int dither = handle->dither;
 	int predivide = handle->predivide;
 
-	IMB_buffer_byte_from_float_tonecurve(display_buffer, buffer, channels, dither,
+	float *linear_buffer = display_buffer_apply_get_linear_buffer(handle);
+
+	IMB_buffer_byte_from_float_tonecurve(display_buffer, linear_buffer, channels, dither,
 	                                     IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB,
 	                                     predivide, width, height, width, width,
 	                                     tonecurve_func);
 
+	if (linear_buffer != buffer)
+		MEM_freeN(linear_buffer);
+
 	return NULL;
 }
 
 static void display_buffer_apply_tonemap(ImBuf *ibuf, unsigned char *display_buffer,
                                          imb_tonecurveCb tonecurve_func)
 {
-	/* XXX: IMB_buffer_byte_from_float_tonecurve isn't thread-safe because of
-	 *      possible non-initialized sRGB conversion stuff. Make sure it's properly
-	 *      initialized before starting threads, but likely this stuff should be
-	 *      initialized somewhere before to avoid possible issues in other issues.
-	 */
-	BLI_init_srgb_conversion();
-
 	display_buffer_apply_threaded(ibuf, ibuf->rect_float, display_buffer, tonecurve_func,
 	                              do_display_buffer_apply_tonemap_thread);
 }
@@ -726,7 +759,9 @@
 	int dither = handle->dither;
 	int predivide = handle->predivide;
 
-	img = OCIO_createPackedImageDesc(buffer, width, height, channels, sizeof(float),
+	float *linear_buffer = display_buffer_apply_get_linear_buffer(handle);
+
+	img = OCIO_createPackedImageDesc(linear_buffer, width, height, channels, sizeof(float),
 	                                 channels * sizeof(float), channels * sizeof(float) * width);
 
 	OCIO_processorApply(processor, img);
@@ -734,10 +769,13 @@
 	OCIO_packedImageDescRelease(img);
 
 	/* do conversion */
-	IMB_buffer_byte_from_float(display_buffer, buffer,
+	IMB_buffer_byte_from_float(display_buffer, linear_buffer,
 	                           channels, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
 	                           predivide, width, height, width, width);
 
+	if (linear_buffer != buffer)
+		MEM_freeN(linear_buffer);
+
 	return NULL;
 }
 
@@ -1103,6 +1141,11 @@
 
 					colormanage_check_view_settings(&sclip->view_settings, "clip editor", default_view);
 				}
+				else if (sl->spacetype == SPACE_SEQ) {
+					SpaceSeq *sseq = (SpaceSeq *) sl;
+
+					colormanage_check_view_settings(&sseq->view_settings, "sequencer editor", default_view);
+				}
 			}
 		}
 	}

Modified: branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h	2012-07-11 19:32:32 UTC (rev 48840)
+++ branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h	2012-07-11 19:39:43 UTC (rev 48841)
@@ -473,6 +473,9 @@
 	int pad;
 
 	struct bGPdata *gpd;        /* grease-pencil data */
+
+	/* **** color management **** */
+	ColorManagedViewSettings view_settings;
 } SpaceSeq;
 
 
@@ -690,6 +693,7 @@
 	char dt_uvstretch;
 	char around;
 
+	/* **** color management **** */
 	ColorManagedViewSettings view_settings;
 } SpaceImage;
 
@@ -874,6 +878,7 @@
 	
 	struct bGPdata *gpd;        /* grease-pencil data */
 
+	/* **** color management **** */
 	ColorManagedViewSettings view_settings;
 } SpaceNode;
 

Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c
===================================================================
--- branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c	2012-07-11 19:32:32 UTC (rev 48840)
+++ branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c	2012-07-11 19:39:43 UTC (rev 48841)
@@ -2143,6 +2143,11 @@

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list