[Mesa-dev] [PATCH] mesa: adjust usage of swapBytes/littleEndian in format_matches_format_and_type

Marek Olšák maraeo at gmail.com
Thu Jan 31 08:06:45 PST 2013


- swapBytes has no effect on 8-bit single-component formats
- GL_SHORT is in host byte order, so checking for littleEndian is unnecessary,
  I decided to make the change for single-component formats only
- for 8_8 formats, instead of littleEndian && !swapBytes,
  use littleEndian != swapBytes to include big endian hosts

Based on suggestions from Michel Dänzer.
---
This will be applied on top of my previous patch series.


 src/mesa/main/formats.c |   49 +++++++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 29 deletions(-)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 4598d65..78f51c7 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -3006,19 +3006,16 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
    case MESA_FORMAT_A8:
       return format == GL_ALPHA && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_A16:
-      return format == GL_ALPHA && type == GL_UNSIGNED_SHORT &&
-         littleEndian && !swapBytes;
+      return format == GL_ALPHA && type == GL_UNSIGNED_SHORT && !swapBytes;
    case MESA_FORMAT_L8:
    case MESA_FORMAT_SL8:
       return format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_L16:
-      return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT &&
-         littleEndian && !swapBytes;
+      return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT && !swapBytes;
    case MESA_FORMAT_I8:
       return format == GL_INTENSITY && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_I16:
-      return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT &&
-         littleEndian && !swapBytes;
+      return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT && !swapBytes;
 
    case MESA_FORMAT_YCBCR:
       return format == GL_YCBCR_MESA &&
@@ -3037,7 +3034,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return GL_FALSE;
 
    case MESA_FORMAT_R16:
-      return format == GL_RED && type == GL_UNSIGNED_SHORT && littleEndian &&
+      return format == GL_RED && type == GL_UNSIGNED_SHORT &&
          !swapBytes;
    case MESA_FORMAT_GR1616:
       return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian &&
@@ -3125,8 +3122,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return format == GL_RG && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_ALPHA_UINT8:
-      return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_BYTE &&
-             !swapBytes;
+      return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_ALPHA_UINT16:
       return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_SHORT &&
              !swapBytes;
@@ -3134,7 +3130,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_INT &&
              !swapBytes;
    case MESA_FORMAT_ALPHA_INT8:
-      return format == GL_ALPHA_INTEGER && type == GL_BYTE && !swapBytes;
+      return format == GL_ALPHA_INTEGER && type == GL_BYTE;
    case MESA_FORMAT_ALPHA_INT16:
       return format == GL_ALPHA_INTEGER && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_ALPHA_INT32:
@@ -3150,8 +3146,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return GL_FALSE;
 
    case MESA_FORMAT_LUMINANCE_UINT8:
-      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE &&
-             !swapBytes;
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_LUMINANCE_UINT16:
       return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_SHORT &&
              !swapBytes;
@@ -3159,8 +3154,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_INT &&
              !swapBytes;
    case MESA_FORMAT_LUMINANCE_INT8:
-      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_BYTE &&
-             !swapBytes;
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_BYTE;
    case MESA_FORMAT_LUMINANCE_INT16:
       return format == GL_LUMINANCE_INTEGER_EXT && type == GL_SHORT &&
              !swapBytes;
@@ -3187,7 +3181,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
              !swapBytes;
 
    case MESA_FORMAT_R_INT8:
-      return format == GL_RED_INTEGER && type == GL_BYTE && !swapBytes;
+      return format == GL_RED_INTEGER && type == GL_BYTE;
    case MESA_FORMAT_RG_INT8:
       return format == GL_RG_INTEGER && type == GL_BYTE && !swapBytes;
    case MESA_FORMAT_RGB_INT8:
@@ -3212,7 +3206,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return format == GL_RGBA_INTEGER && type == GL_INT && !swapBytes;
 
    case MESA_FORMAT_R_UINT8:
-      return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
+      return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_RG_UINT8:
       return format == GL_RG_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
    case MESA_FORMAT_RGB_UINT8:
@@ -3242,13 +3236,12 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
 
    case MESA_FORMAT_DUDV8:
       return (format == GL_DU8DV8_ATI || format == GL_DUDV_ATI) &&
-             type == GL_BYTE && littleEndian && !swapBytes;
+             type == GL_BYTE && littleEndian != swapBytes;
 
    case MESA_FORMAT_SIGNED_R8:
-      return format == GL_RED && type == GL_BYTE && !swapBytes;
+      return format == GL_RED && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_RG88_REV:
-      return format == GL_RG && type == GL_BYTE && littleEndian &&
-             !swapBytes;
+      return format == GL_RG && type == GL_BYTE && littleEndian != swapBytes;
    case MESA_FORMAT_SIGNED_RGBX8888:
       return GL_FALSE;
 
@@ -3271,7 +3264,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return GL_FALSE;
 
    case MESA_FORMAT_SIGNED_R16:
-      return format == GL_RED && type == GL_SHORT && littleEndian &&
+      return format == GL_RED && type == GL_SHORT &&
              !swapBytes;
    case MESA_FORMAT_SIGNED_GR1616:
       return format == GL_RG && type == GL_SHORT && littleEndian && !swapBytes;
@@ -3309,20 +3302,18 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return GL_FALSE;
 
    case MESA_FORMAT_SIGNED_A8:
-      return format == GL_ALPHA && type == GL_BYTE && !swapBytes;
+      return format == GL_ALPHA && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_L8:
-      return format == GL_LUMINANCE && type == GL_BYTE && !swapBytes;
+      return format == GL_LUMINANCE && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_AL88:
       return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
-             littleEndian && !swapBytes;
+             littleEndian != swapBytes;
    case MESA_FORMAT_SIGNED_I8:
-      return format == GL_INTENSITY && type == GL_BYTE && !swapBytes;
+      return format == GL_INTENSITY && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_A16:
-      return format == GL_ALPHA && type == GL_SHORT && littleEndian &&
-             !swapBytes;
+      return format == GL_ALPHA && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_SIGNED_L16:
-      return format == GL_LUMINANCE && type == GL_SHORT && littleEndian &&
-             !swapBytes;
+      return format == GL_LUMINANCE && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_SIGNED_AL1616:
       return format == GL_LUMINANCE_ALPHA && type == GL_SHORT &&
              littleEndian && !swapBytes;
-- 
1.7.10.4



More information about the mesa-dev mailing list