summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2010-02-24 15:41:24 +0000
committerJosé Fonseca <[email protected]>2010-02-24 15:45:28 +0000
commit1dbb5f02aeca89626c4479c53828ea7957989892 (patch)
tree6059cb4b00b5a5046daf891722c632e9fb0e17fe /src
parent3c45c4bc44310c1af4f0c06d29eb0a9d39a38837 (diff)
util: Refactor some code.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/util/u_format_access.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/gallium/auxiliary/util/u_format_access.py b/src/gallium/auxiliary/util/u_format_access.py
index ca0c9765c26..fb85215d205 100644
--- a/src/gallium/auxiliary/util/u_format_access.py
+++ b/src/gallium/auxiliary/util/u_format_access.py
@@ -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'''
@@ -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,18 +372,7 @@ 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 not format.is_array():
@@ -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