Revision: 56065
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56065
Author:   nazgul
Date:     2013-04-15 15:41:53 +0000 (Mon, 15 Apr 2013)
Log Message:
-----------
Fix #34967: Display transform makes byte image with alpha=0 black

Skip premultiplication/de-premultiplication when acquiring display
buffer for a byte image. Will make conversion a bit faster also :)

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/colormanagement.c

Modified: trunk/blender/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/colormanagement.c 2013-04-15 
15:16:11 UTC (rev 56064)
+++ trunk/blender/source/blender/imbuf/intern/colormanagement.c 2013-04-15 
15:41:53 UTC (rev 56065)
@@ -1213,7 +1213,7 @@
        handle->float_colorspace = init_data->float_colorspace;
 }
 
-static void *display_buffer_apply_get_linear_buffer(DisplayBufferThread 
*handle)
+static float *display_buffer_apply_get_linear_buffer(DisplayBufferThread 
*handle, bool *is_straight_alpha)
 {
        float *linear_buffer = NULL;
 
@@ -1248,7 +1248,6 @@
                        }
                        else if (channels == 4) {
                                rgba_uchar_to_float(fp, cp);
-                               straight_to_premul_v4(fp);
                        }
                        else {
                                BLI_assert(!"Buffers of 3 or 4 channels are 
only supported here");
@@ -1258,8 +1257,10 @@
                if (!is_data && !is_data_display) {
                        /* convert float buffer to scene linear space */
                        IMB_colormanagement_transform(linear_buffer, width, 
height, channels,
-                                                     from_colorspace, 
to_colorspace, TRUE);
+                                                     from_colorspace, 
to_colorspace, FALSE);
                }
+
+               *is_straight_alpha = true;
        }
        else if (handle->float_colorspace) {
                /* currently float is non-linear only in sequencer, which is 
working
@@ -1275,6 +1276,8 @@
 
                IMB_colormanagement_transform(linear_buffer, width, height, 
channels,
                                              from_colorspace, to_colorspace, 
TRUE);
+
+               *is_straight_alpha = false;
        }
        else {
                /* some processors would want to modify float original buffer
@@ -1287,6 +1290,8 @@
                 */
 
                memcpy(linear_buffer, handle->buffer, buffer_size * 
sizeof(float));
+
+               *is_straight_alpha = false;
        }
 
        return linear_buffer;
@@ -1316,7 +1321,9 @@
                }
        }
        else {
-               float *linear_buffer = 
display_buffer_apply_get_linear_buffer(handle);
+               bool is_straight_alpha;
+               float *linear_buffer = 
display_buffer_apply_get_linear_buffer(handle, &is_straight_alpha);
+               bool predivide = is_straight_alpha == false;
 
                if (is_data) {
                        /* special case for data buffers - no color space 
conversions,
@@ -1325,7 +1332,8 @@
                }
                else {
                        /* apply processor */
-                       IMB_colormanagement_processor_apply(cm_processor, 
linear_buffer, width, height, channels, TRUE);
+                       IMB_colormanagement_processor_apply(cm_processor, 
linear_buffer, width, height, channels,
+                                                           predivide);
                }
 
                /* copy result to output buffers */
@@ -1333,12 +1341,25 @@
                        /* do conversion */
                        IMB_buffer_byte_from_float(display_buffer_byte, 
linear_buffer,
                                                   channels, dither, 
IB_PROFILE_SRGB, IB_PROFILE_SRGB,
-                                                  TRUE, width, height, width, 
width);
+                                                  predivide, width, height, 
width, width);
                }
 
-               if (display_buffer)
+               if (display_buffer) {
                        memcpy(display_buffer, linear_buffer, width * height * 
channels * sizeof(float));
 
+                       if (is_straight_alpha && channels == 4) {
+                               int i;
+                               float *fp;
+
+                               for (i = 0, fp = display_buffer;
+                                    i < width * height;
+                                    i++, fp += channels)
+                               {
+                                       straight_to_premul_v4(fp);
+                               }
+                       }
+               }
+
                MEM_freeN(linear_buffer);
        }
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to