[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50414] branches/soc-2011-tomato/source/ blender: Color Management: sequencer's scopes now works in display space

Sergey Sharybin sergey.vfx at gmail.com
Wed Sep 5 13:42:57 CEST 2012


Revision: 50414
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50414
Author:   nazgul
Date:     2012-09-05 11:42:57 +0000 (Wed, 05 Sep 2012)
Log Message:
-----------
Color Management: sequencer's scopes now works in display space

Added utility function to apply display transformation on image buffer's
float array which is currently only used by sequencer's scopes.

This function is multithreaded, but scopes should be improved further
since currently they're being recalculated from scratch on every draw.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/editors/space_sequencer/sequencer_draw.c
    branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c

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-09-05 11:42:20 UTC (rev 50413)
+++ branches/soc-2011-tomato/source/blender/editors/space_sequencer/sequencer_draw.c	2012-09-05 11:42:57 UTC (rev 50414)
@@ -912,29 +912,37 @@
 
 	if (ibuf->rect == NULL && ibuf->rect_float == NULL)
 		return;
-	
-	switch (sseq->mainb) {
-		case SEQ_DRAW_IMG_IMBUF:
-			if (sseq->zebra != 0) {
-				scope = make_zebra_view_from_ibuf(ibuf, sseq->zebra);
-			}
-			break;
-		case SEQ_DRAW_IMG_WAVEFORM:
-			if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
-				scope = make_sep_waveform_view_from_ibuf(ibuf);
-			}
-			else {
-				scope = make_waveform_view_from_ibuf(ibuf);
-			}
-			break;
-		case SEQ_DRAW_IMG_VECTORSCOPE:
-			scope = make_vectorscope_view_from_ibuf(ibuf);
-			break;
-		case SEQ_DRAW_IMG_HISTOGRAM:
-			scope = make_histogram_view_from_ibuf(ibuf);
-			break;
+
+	if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
+		if (sseq->zebra != 0) {
+			scope = make_zebra_view_from_ibuf(ibuf, sseq->zebra);
+		}
 	}
+	else {
+		ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
 
+		IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings, &scene->display_settings);
+
+		switch (sseq->mainb) {
+			case SEQ_DRAW_IMG_WAVEFORM:
+				if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
+					scope = make_sep_waveform_view_from_ibuf(display_ibuf);
+				}
+				else {
+					scope = make_waveform_view_from_ibuf(display_ibuf);
+				}
+				break;
+			case SEQ_DRAW_IMG_VECTORSCOPE:
+				scope = make_vectorscope_view_from_ibuf(display_ibuf);
+				break;
+			case SEQ_DRAW_IMG_HISTOGRAM:
+				scope = make_histogram_view_from_ibuf(display_ibuf);
+				break;
+		}
+
+		IMB_freeImBuf(display_ibuf);
+	}
+
 	if (scope) {
 		IMB_freeImBuf(ibuf);
 		ibuf = scope;

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-09-05 11:42:20 UTC (rev 50413)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-09-05 11:42:57 UTC (rev 50414)
@@ -50,6 +50,13 @@
 void IMB_colormanagement_init(void);
 void IMB_colormanagement_exit(void);
 
+/* ** Generic functions ** */
+
+void IMB_colormanagement_check_file_config(struct Main *bmain);
+
+void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *display_settings,
+                                           struct ColorManagedViewSettings *view_settings);
+
 /* ** 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);
@@ -60,9 +67,11 @@
 void IMB_colormanagement_imbuf_to_role(struct ImBuf *ibuf, int role);
 void IMB_colormanagement_imbuf_from_role(struct ImBuf *ibuf, int role);
 
-void IMB_colormanagement_imbuf_make_scene_linear(struct ImBuf *ibuf,
-		struct ColorManagedColorspaceSettings *colorspace_settings);
+void IMB_colormanagement_imbuf_make_scene_linear(struct ImBuf *ibuf, struct ColorManagedColorspaceSettings *colorspace_settings);
 
+void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
+                                                  const struct ColorManagedDisplaySettings *display_settings);
+
 /* ** Public display buffers interfaces ** */
 
 void IMB_colormanage_cache_free(struct ImBuf *ibuf);
@@ -81,11 +90,6 @@
 
 void IMB_display_buffer_invalidate(struct ImBuf *ibuf);
 
-void IMB_colormanagement_check_file_config(struct Main *bmain);
-
-void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *display_settings,
-                                           struct ColorManagedViewSettings *view_settings);
-
 /* ** Display funcrions ** */
 int IMB_colormanagement_display_get_named_index(const char *name);
 const char *IMB_colormanagement_display_get_indexed_name(int index);
@@ -104,7 +108,7 @@
 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 */
+/* ** Tile-based buffer management ** */
 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer,
                                        int stride, int offset_x, int offset_y,
                                        int xmin, int ymin, int xmax, int ymax);

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-09-05 11:42:20 UTC (rev 50413)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-09-05 11:42:57 UTC (rev 50414)
@@ -599,8 +599,10 @@
 
 	float *buffer;
 	unsigned char *byte_buffer;
-	unsigned char *display_buffer;
 
+	float *display_buffer;
+	unsigned char *display_buffer_byte;
+
 	int width;
 	int start_line;
 	int tot_line;
@@ -617,7 +619,10 @@
 	void *processor;
 	float *buffer;
 	unsigned char *byte_buffer;
-	unsigned char *display_buffer;
+
+	float *display_buffer;
+	unsigned char *display_buffer_byte;
+
 	int width;
 } DisplayBufferInitData;
 
@@ -643,8 +648,12 @@
 	if (init_data->byte_buffer)
 		handle->byte_buffer = init_data->byte_buffer + offset;
 
-	handle->display_buffer = init_data->display_buffer + offset;
+	if (init_data->display_buffer)
+		handle->display_buffer = init_data->display_buffer + offset;
 
+	if (init_data->display_buffer_byte)
+		handle->display_buffer_byte = init_data->display_buffer_byte + offset;
+
 	handle->width = ibuf->x;
 
 	handle->start_line = start_line;
@@ -658,7 +667,7 @@
 }
 
 static void display_buffer_apply_threaded(ImBuf *ibuf, float *buffer, unsigned char *byte_buffer,
-                                          unsigned char *display_buffer,
+                                          float *display_buffer, unsigned char *display_buffer_byte,
                                           void *processor, void *(do_thread) (void *))
 {
 	DisplayBufferInitData init_data;
@@ -668,6 +677,7 @@
 	init_data.buffer = buffer;
 	init_data.byte_buffer = byte_buffer;
 	init_data.display_buffer = display_buffer;
+	init_data.display_buffer_byte = display_buffer_byte;
 
 	IMB_processor_apply_threaded(ibuf->y, sizeof(DisplayBufferThread), &init_data,
 	                             display_buffer_init_handle, do_thread);
@@ -735,7 +745,8 @@
 	ConstProcessorRcPtr *processor = (ConstProcessorRcPtr *) handle->processor;
 	PackedImageDesc *img;
 	float *buffer = handle->buffer;
-	unsigned char *display_buffer = handle->display_buffer;
+	float *display_buffer = handle->display_buffer;
+	unsigned char *display_buffer_byte = handle->display_buffer_byte;
 	int channels = handle->channels;
 	int width = handle->width;
 	int height = handle->tot_line;
@@ -751,11 +762,17 @@
 
 	OCIO_packedImageDescRelease(img);
 
-	/* do conversion */
-	IMB_buffer_byte_from_float(display_buffer, linear_buffer,
-	                           channels, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
-	                           predivide, width, height, width, width);
+	if (display_buffer_byte) {
+		/* do conversion */
+		IMB_buffer_byte_from_float(display_buffer_byte, linear_buffer,
+		                           channels, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
+		                           predivide, width, height, width, width);
+	}
 
+	if (display_buffer) {
+		memcpy(display_buffer, linear_buffer, width * height * channels * sizeof(float));
+	}
+
 	if (linear_buffer != buffer)
 		MEM_freeN(linear_buffer);
 
@@ -811,9 +828,9 @@
 	return processor;
 }
 
-static void colormanage_display_buffer_process(ImBuf *ibuf, unsigned char *display_buffer,
-                                               const ColorManagedViewSettings *view_settings,
-                                               const ColorManagedDisplaySettings *display_settings)
+static void colormanage_display_buffer_process_ex(ImBuf *ibuf, float *display_buffer, unsigned char *display_buffer_byte,
+                                                  const ColorManagedViewSettings *view_settings,
+                                                  const ColorManagedDisplaySettings *display_settings)
 {
 	ConstProcessorRcPtr *processor;
 	const float gamma = view_settings->gamma;
@@ -825,12 +842,20 @@
 
 	if (processor) {
 		display_buffer_apply_threaded(ibuf, ibuf->rect_float, (unsigned char *) ibuf->rect,
-		                              display_buffer, processor, do_display_buffer_apply_thread);
+		                              display_buffer, display_buffer_byte, processor,
+		                              do_display_buffer_apply_thread);
 	}
 
 	OCIO_processorRelease(processor);
 }
 
+static void colormanage_display_buffer_process(ImBuf *ibuf, unsigned char *display_buffer,
+                                               const ColorManagedViewSettings *view_settings,
+                                               const ColorManagedDisplaySettings *display_settings)
+{
+	colormanage_display_buffer_process_ex(ibuf, NULL, display_buffer, view_settings, display_settings);
+}
+
 /*********************** Threaded color space transform routines *************************/
 
 typedef struct ColorspaceTransformThread {
@@ -1075,7 +1100,31 @@
 #endif
 }
 
+void IMB_colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
+                                                  const ColorManagedDisplaySettings *display_settings)
+{
 #ifdef WITH_OCIO
+	/* OCIO_TODO: byte buffer management is not supported here yet */
+	if (!ibuf->rect_float)
+		return;
+
+	if (global_tot_display == 0 || global_tot_view == 0) {
+		IMB_buffer_float_from_float(ibuf->rect_float, ibuf->rect_float, ibuf->channels, IB_PROFILE_LINEAR_RGB, ibuf->profile,
+		                            ibuf->flags & IB_cm_predivide, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+	}
+	else {
+		colormanage_display_buffer_process_ex(ibuf, ibuf->rect_float, NULL, view_settings, display_settings);
+	}
+#else

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list