<div dir="ltr"><br><br>On Wed, Jan 7, 2015 at 11:20 PM, Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>> wrote:<br>> From: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>><br>> Aparently, the packing/unpacking functions for these formats have differed<br>> from the format description in formats.h.  Instead of fixing this, people<br>> simply left a comment saying it was broken.  Let's actually fix it for<br>> real.<br>><br>> Signed-off-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>><br>> v2 by Samuel Iglesias <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>>:<br>> - Keep comment in unpack_R5G6B5_UNORM()<br>> ---<br>>  src/mesa/main/format_pack.c      | 10 ++--------<br>>  src/mesa/main/format_unpack.c    |  7 ++-----<br>>  src/mesa/main/formats.c          | 12 ++++++------<br>>  src/mesa/main/texstore.c         |  2 +-<br>>  src/mesa/swrast/s_texfetch_tmp.h |  8 ++++----<br>>  5 files changed, 15 insertions(+), 24 deletions(-)<br>><br>> diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c<br>> index 31c9f77..20d2b1a 100644<br>> --- a/src/mesa/main/format_pack.c<br>> +++ b/src/mesa/main/format_pack.c<br>> @@ -458,17 +458,11 @@ pack_row_float_B5G6R5_UNORM(GLuint n, const GLfloat src[][4], void *dst)<br>>  }<br>><br>><br>> -/*<br>> - * MESA_FORMAT_R5G6B5_UNORM<br>> - * Warning: these functions do not match the current Mesa definition<br>> - * of MESA_FORMAT_R5G6B5_UNORM.<br>> - */<br>> -<br>>  static void<br>>  pack_ubyte_R5G6B5_UNORM(const GLubyte src[4], void *dst)<br>>  {<br>>     GLushort *d = ((GLushort *) dst);<br>> -   *d = PACK_COLOR_565_REV(src[RCOMP], src[GCOMP], src[BCOMP]);<br>> +   *d = PACK_COLOR_565(src[BCOMP], src[GCOMP], src[RCOMP]);<br>>  }<br>><br>>  static void<br>> @@ -479,7 +473,7 @@ pack_float_R5G6B5_UNORM(const GLfloat src[4], void *dst)<br>>     UNCLAMPED_FLOAT_TO_UBYTE(r, src[RCOMP]);<br>>     UNCLAMPED_FLOAT_TO_UBYTE(g, src[GCOMP]);<br>>     UNCLAMPED_FLOAT_TO_UBYTE(b, src[BCOMP]);<br>> -   *d = PACK_COLOR_565_REV(r, g, b);<br>> +   *d = PACK_COLOR_565(b, g, r);<br>>  }<br>><br>>  static void<br>> diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c<br>> index d5628a9..69c76d3 100644<br>> --- a/src/mesa/main/format_unpack.c<br>> +++ b/src/mesa/main/format_unpack.c<br>> @@ -2764,16 +2764,13 @@ unpack_ubyte_B5G6R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)<br>>  static void<br>>  unpack_ubyte_R5G6B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)<br>>  {<br>> -   /* Warning: this function does not match the current Mesa definition<br>> -    * of MESA_FORMAT_R5G6B5_UNORM.<br>> -    */<br>>     const GLushort *s = ((const GLushort *) src);<br>>     GLuint i;<br>>     for (i = 0; i < n; i++) {<br>>        GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */<br>> -      dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);<br>> +      dst[i][RCOMP] = EXPAND_5_8( t        & 0x1f);<br>>        dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);<br>> -      dst[i][BCOMP] = EXPAND_5_8( t        & 0x1f);<br>> +      dst[i][BCOMP] = EXPAND_5_8((t >> 11) & 0x1f);<br>>        dst[i][ACOMP] = 0xff;<br>>     }<br>>  }<br>> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c<br>> index 58c32e2..1315d36 100644<br>> --- a/src/mesa/main/formats.c<br>> +++ b/src/mesa/main/formats.c<br>> @@ -1462,14 +1462,14 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,<br>>        return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian;<br>><br>>     case MESA_FORMAT_B5G6R5_UNORM:<br>> -      return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 && !swapBytes;<br>> +      return ((format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) ||<br>> +              (format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5_REV)) &&<br>> +              !swapBytes;<br>><br>>     case MESA_FORMAT_R5G6B5_UNORM:<br>> -      /* Some of the 16-bit MESA_FORMATs that would seem to correspond to<br>> -       * GL_UNSIGNED_SHORT_* are byte-swapped instead of channel-reversed,<br>> -       * according to formats.h, so they can't be matched.<br>> -       */<br>> -      return GL_FALSE;<br>> +      return ((format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5) ||<br>> +              (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5_REV)) &&<br>> +              !swapBytes;<br>><br>>     case MESA_FORMAT_B4G4R4A4_UNORM:<br>>        return format == GL_BGRA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV &&<br>> diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c<br>> index 50aa1fd..b9407d2 100644<br>> --- a/src/mesa/main/texstore.c<br>> +++ b/src/mesa/main/texstore.c<br>> @@ -923,7 +923,7 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)<br>>           }<br>>           else {<br>>              for (col = 0; col < srcWidth; col++) {<br>> -               dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );<br>> +               dstUS[col] = PACK_COLOR_565( srcUB[2], srcUB[1], srcUB[0] );<br>>                 srcUB += 3;<br>>              }<br>>           }<br>> diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h<br>> index 7ff30f6..23db48d 100644<br>> --- a/src/mesa/swrast/s_texfetch_tmp.h<br>> +++ b/src/mesa/swrast/s_texfetch_tmp.h<br>> @@ -417,10 +417,10 @@ FETCH(R5G6B5_UNORM)(const struct swrast_texture_image *texImage,<br>>                      GLint i, GLint j, GLint k, GLfloat *texel)<br>>  {<br>>     const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);<br>> -   const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */<br>> -   texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );<br>> -   texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >>  9) & 0x3) );<br>> -   texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >>  2) & 0x7) );<br>> +   const GLushort s = *src;<br>> +   texel[RCOMP] = ((s      ) & 0x1f) * (1.0F / 31.0F);<br>> +   texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);<br>> +   texel[BCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);<br>>     texel[ACOMP] = 1.0F;<br>>  }<br>><br>> --<br>> 1.9.1<br>><br>> _______________________________________________<br>> mesa-dev mailing list<br>> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>Below comment in formats.h also needs a fix to show correct ordering of components:<br><br>    *  examples:                   msb <------ TEXEL BITS -----------> lsb<br>    *  MESA_FORMAT_A8B8G8R8_UNORM, AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR<br>    *  MESA_FORMAT_R5G6B5_UNORM                        RRRR RGGG GGGB BBBB<br>    *  MESA_FORMAT_B4G4R4X4_UNORM                      BBBB GGGG RRRR XXXX<br><br><br>With this comment fixed, this patch is:<br>Reviewed-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>></div>