Mesa (master): util: Factor out the code to shorten a format name.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed Feb 24 15:45:36 UTC 2010


Module: Mesa
Branch: master
Commit: 943314f38f1224d4929b41acc9ef8fde81ef9dbe
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=943314f38f1224d4929b41acc9ef8fde81ef9dbe

Author: José Fonseca <jfonseca at vmware.com>
Date:   Wed Feb 24 15:10:46 2010 +0000

util: Factor out the code to shorten a format name.

---

 src/gallium/auxiliary/util/u_format_access.py |   19 ++++---------------
 src/gallium/auxiliary/util/u_format_parse.py  |   10 ++++++++++
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format_access.py b/src/gallium/auxiliary/util/u_format_access.py
index 83f7a1b..ca0c976 100644
--- a/src/gallium/auxiliary/util/u_format_access.py
+++ b/src/gallium/auxiliary/util/u_format_access.py
@@ -42,17 +42,6 @@ import sys
 from u_format_parse import *
 
 
-def short_name(format):
-    '''Make up a short norm for a format, suitable to be used as suffix in
-    function names.'''
-
-    name = format.name
-    if name.startswith('PIPE_FORMAT_'):
-        name = name[len('PIPE_FORMAT_'):]
-    name = name.lower()
-    return name
-
-
 def is_format_supported(format):
     '''Determines whether we actually have the plumbing necessary to generate the 
     to read/write to/from this format.'''
@@ -262,7 +251,7 @@ def conversion_expr(src_type, dst_type, dst_native_type, value):
 def generate_format_read(format, dst_type, dst_native_type, dst_suffix):
     '''Generate the function to read pixels from a particular format'''
 
-    name = short_name(format)
+    name = format.short_name()
 
     src_native_type = native_type(format)
 
@@ -350,7 +339,7 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix):
 def generate_format_write(format, src_type, src_native_type, src_suffix):
     '''Generate the function to write pixels to a particular format'''
 
-    name = short_name(format)
+    name = format.short_name()
 
     dst_native_type = native_type(format)
 
@@ -427,7 +416,7 @@ def generate_read(formats, dst_type, dst_native_type, dst_suffix):
     for format in formats:
         if is_format_supported(format):
             print '   case %s:' % format.name
-            print '      func = &util_format_%s_read_%s;' % (short_name(format), dst_suffix)
+            print '      func = &util_format_%s_read_%s;' % (format.short_name(), dst_suffix)
             print '      break;'
     print '   default:'
     print '      debug_printf("unsupported format\\n");'
@@ -454,7 +443,7 @@ def generate_write(formats, src_type, src_native_type, src_suffix):
     for format in formats:
         if is_format_supported(format):
             print '   case %s:' % format.name
-            print '      func = &util_format_%s_write_%s;' % (short_name(format), src_suffix)
+            print '      func = &util_format_%s_write_%s;' % (format.short_name(), src_suffix)
             print '      break;'
     print '   default:'
     print '      debug_printf("unsupported format\\n");'
diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py
index 3733602..248a26e 100755
--- a/src/gallium/auxiliary/util/u_format_parse.py
+++ b/src/gallium/auxiliary/util/u_format_parse.py
@@ -77,6 +77,16 @@ class Format:
     def __str__(self):
         return self.name
 
+    def short_name(self):
+        '''Make up a short norm for a format, suitable to be used as suffix in
+        function names.'''
+
+        name = self.name
+        if name.startswith('PIPE_FORMAT_'):
+            name = name[len('PIPE_FORMAT_'):]
+        name = name.lower()
+        return name
+
     def block_size(self):
         size = 0
         for type in self.in_types:




More information about the mesa-commit mailing list