[cogl/cogl-1.8] texture: Handle premult conversions when getting texture data



commit 52d331a3cc63bc9cffba0af8694b673e961ee9fa
Author: Neil Roberts <neil linux intel com>
Date:   Thu Feb 23 18:32:59 2012 +0000

    texture: Handle premult conversions when getting texture data
    
    cogl_texture_get_data uses find_best_gl_get_data_format from the
    texture driver which returns the closest format to use for retrieving
    pixel data given an intended format. However this function doesn't
    know about the texture we are reading data from so it doesn't know
    that the data we will actually receive will have the same premult
    status as the texture's format. With the GL driver, this function ends
    up returning exactly the same format as passed in which means it will
    never do a premult conversion. Under GLES it always returns
    COGL_PIXEL_FORMAT_RGBA_8888 so it will always make the data unpremult
    even if the final requested format is premultiplied.
    
    This patch fixes it so that it copies the premult status of the
    closest_format from the format of the underlying texture. That way it
    will later convert or not depending on the requested target format.
    
    Note this patch breaks test-sub-texture with the GL driver because
    that is incorrectly trying to read the texture data back as RGBA_8888
    even though it depends on it not doing a premult conversion. The test
    was already broken with GLES2 and remains broken.
    
    Reviewed-by: Robert Bragg <robert linux intel com>
    
    (cherry picked from commit 39c6bf59cbb571538acbda51714375f0d65098b9)
    
    Conflicts:
    
    	cogl/cogl-texture.c

 cogl/cogl-texture.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 10912f3..d816119 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -1377,6 +1377,7 @@ cogl_texture_get_data (CoglHandle       handle,
   int              y;
   int              tex_width;
   int              tex_height;
+  CoglPixelFormat  texture_format;
 
   CoglTextureGetData tg_data;
 
@@ -1387,9 +1388,11 @@ cogl_texture_get_data (CoglHandle       handle,
 
   tex = COGL_TEXTURE (handle);
 
+  texture_format = cogl_texture_get_format (tex);
+
   /* Default to internal format if none specified */
   if (format == COGL_PIXEL_FORMAT_ANY)
-    format = cogl_texture_get_format (handle);
+    format = texture_format;
 
   tex_width = cogl_texture_get_width (handle);
   tex_height = cogl_texture_get_height (handle);
@@ -1410,6 +1413,12 @@ cogl_texture_get_data (CoglHandle       handle,
                                                        &closest_gl_type);
   closest_bpp = _cogl_get_format_bpp (closest_format);
 
+  /* We can assume that whatever data GL gives us will have the
+     premult status of the original texture */
+  if ((closest_format & COGL_A_BIT))
+    closest_format = ((closest_format & ~COGL_PREMULT_BIT) |
+                      (texture_format & COGL_PREMULT_BIT));
+
   /* Is the requested format supported? */
   if (closest_format == format)
     /* Target user data directly */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]