util: Kill array vs arith layouts. Revamp UTIL_FORMAT_LAYOUT_xxx.
[mesa.git] / src / gallium / auxiliary / util / u_format_access.py
index ca0c9765c26068ed5aa7c8454bc2d91c21a96a79..f7a92f62a8ca91476b3108e90f3651bbac4fda10 100644 (file)
@@ -52,7 +52,7 @@ def is_format_supported(format):
     if format.colorspace not in ('rgb', 'zs'):
         return False
 
-    if format.layout not in (ARITH, ARRAY):
+    if format.layout != PLAIN:
         return False
 
     for i in range(4):
@@ -70,7 +70,7 @@ def is_format_supported(format):
 def native_type(format):
     '''Get the native appropriate for a format.'''
 
-    if format.layout in (ARITH, ARRAY):
+    if format.layout == PLAIN:
         if not format.is_array():
             # For arithmetic pixel formats return the integer type that matches the whole pixel
             return 'uint%u_t' % format.block_size()
@@ -248,6 +248,24 @@ def conversion_expr(src_type, dst_type, dst_native_type, value):
     assert False
 
 
+def compute_inverse_swizzle(format):
+    '''Return an array[4] of inverse swizzle terms'''
+    inv_swizzle = [None]*4
+    if format.colorspace == 'rgb':
+        for i in range(4):
+            swizzle = format.out_swizzle[i]
+            if swizzle < 4:
+                inv_swizzle[swizzle] = i
+    elif format.colorspace == 'zs':
+        swizzle = format.out_swizzle[0]
+        if swizzle < 4:
+            inv_swizzle[swizzle] = 0
+    else:
+        assert False
+
+    return inv_swizzle
+
+
 def generate_format_read(format, dst_type, dst_native_type, dst_suffix):
     '''Generate the function to read pixels from a particular format'''
 
@@ -281,7 +299,7 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix):
     else:
         assert False
 
-    if format.layout in (ARITH, ARRAY):
+    if format.layout == PLAIN:
         if not format.is_array():
             print '         %s pixel = *src_pixel++;' % src_native_type
             shift = 0;
@@ -330,7 +348,7 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix):
 
     print '      }'
     print '      src_row += src_stride;'
-    print '      dst_row += dst_stride/sizeof(%s);' % dst_native_type
+    print '      dst_row += dst_stride/sizeof(*dst_row);'
     print '   }'
     print '}'
     print
@@ -354,20 +372,9 @@ def generate_format_write(format, src_type, src_native_type, src_suffix):
     print '      const %s *src_pixel = src_row;' %src_native_type
     print '      for (x = 0; x < w; ++x) {'
 
-    inv_swizzle = [None]*4
-    if format.colorspace == 'rgb':
-        for i in range(4):
-            swizzle = format.out_swizzle[i]
-            if swizzle < 4:
-                inv_swizzle[swizzle] = i
-    elif format.colorspace == 'zs':
-        swizzle = format.out_swizzle[0]
-        if swizzle < 4:
-            inv_swizzle[swizzle] = 0
-    else:
-        assert False
+    inv_swizzle = compute_inverse_swizzle(format)
 
-    if format.layout in (ARITH, ARRAY):
+    if format.layout == PLAIN:
         if not format.is_array():
             print '         %s pixel = 0;' % dst_native_type
             shift = 0;
@@ -395,7 +402,7 @@ def generate_format_write(format, src_type, src_native_type, src_suffix):
 
     print '      }'
     print '      dst_row += dst_stride;'
-    print '      src_row += src_stride/sizeof(%s);' % src_native_type
+    print '      src_row += src_stride/sizeof(*src_row);'
     print '   }'
     print '}'
     print