[Mesa-dev] [PATCH 4/8] main: Fix A1R5G5B5 packing/unpacking

Jason Ekstrand jason at jlekstrand.net
Sat Aug 23 15:23:14 PDT 2014


As with B5G6R5, these have been left broken with comments saying they are.

Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com>
---
 src/mesa/main/format_pack.c      |  8 +-------
 src/mesa/main/format_unpack.c    | 11 ++++-------
 src/mesa/main/formats.c          |  2 ++
 src/mesa/swrast/s_texfetch_tmp.h |  8 ++++----
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 9d68fc7..00b90b3 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -584,17 +584,11 @@ pack_float_B5G5R5A1_UNORM(const GLfloat src[4], void *dst)
    pack_ubyte_B5G5R5A1_UNORM(v, dst);
 }
 
-
-/* MESA_FORMAT_A1R5G5B5_UNORM
- * Warning: these functions do not match the current Mesa definition
- * of MESA_FORMAT_A1R5G5B5_UNORM.
- */
-
 static void
 pack_ubyte_A1R5G5B5_UNORM(const GLubyte src[4], void *dst)
 {
    GLushort *d = ((GLushort *) dst), tmp;
-   tmp = PACK_COLOR_1555(src[ACOMP], src[RCOMP], src[GCOMP], src[BCOMP]);
+   tmp = PACK_COLOR_5551(src[BCOMP], src[GCOMP], src[RCOMP], src[ACOMP]);
    *d = (tmp >> 8) | (tmp << 8);
 }
 
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index 58d89e1..ae62456 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -2756,17 +2756,14 @@ unpack_ubyte_B5G5R5A1_UNORM(const void *src, GLubyte dst[][4], GLuint n)
 static void
 unpack_ubyte_A1R5G5B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
 {
-   /* Warning: this function does not match the current Mesa definition
-    * of MESA_FORMAT_A1R5G5B5_UNORM.
-    */
    const GLushort *s = ((const GLushort *) src);
    GLuint i;
    for (i = 0; i < n; i++) {
       GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
-      dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
-      dst[i][GCOMP] = EXPAND_5_8((tmp >>  5) & 0x1f);
-      dst[i][BCOMP] = EXPAND_5_8((tmp >>  0) & 0x1f);
-      dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
+      dst[i][RCOMP] = EXPAND_5_8((tmp >>  1) & 0x1f);
+      dst[i][GCOMP] = EXPAND_5_8((tmp >>  6) & 0x1f);
+      dst[i][BCOMP] = EXPAND_5_8((tmp >> 11) & 0x1f);
+      dst[i][ACOMP] = EXPAND_1_8((tmp      ) & 0x01);
    }
 }
 
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 2ce64de..aac7d37 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1467,6 +1467,8 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
          !swapBytes;
 
    case MESA_FORMAT_A1R5G5B5_UNORM:
+      return format == GL_BGRA && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
+         !swapBytes;
       return GL_FALSE;
 
    case MESA_FORMAT_L4A4_UNORM:
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index 1a688e1..2207c75 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -482,10 +482,10 @@ FETCH(A1R5G5B5_UNORM)(const struct swrast_texture_image *texImage,
 {
    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
    const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
-   texel[RCOMP] = UBYTE_TO_FLOAT( ((s >>  7) & 0xf8) | ((s >> 12) & 0x7) );
-   texel[GCOMP] = UBYTE_TO_FLOAT( ((s >>  2) & 0xf8) | ((s >>  7) & 0x7) );
-   texel[BCOMP] = UBYTE_TO_FLOAT( ((s <<  3) & 0xf8) | ((s >>  2) & 0x7) );
-   texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
+   texel[RCOMP] = ((s >>  1) & 0x1f) * (1.0F / 31.0F);
+   texel[GCOMP] = ((s >>  6) & 0x1f) * (1.0F / 31.0F);
+   texel[BCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+   texel[ACOMP] = ((s      ) & 0x01) * 1.0F;
 }
 
 
-- 
2.1.0



More information about the mesa-dev mailing list