python: Expand the texture test suit to cover one YUV and one DXT format.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 16 Jul 2008 05:11:45 +0000 (14:11 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 16 Jul 2008 05:13:10 +0000 (14:13 +0900)
src/gallium/state_trackers/python/tests/base.py
src/gallium/state_trackers/python/tests/data.py
src/gallium/state_trackers/python/tests/texture.py

index d5d6114a45db7c7008a09b2c6ea7c61d83b0729f..d83abdfa7650855fea3e2ee78759486df156e904 100644 (file)
@@ -93,6 +93,9 @@ class Test:
     def __init__(self):
         pass
     
+    def description(self):
+        raise NotImplementedError
+        
     def run(self):
         raise NotImplementedError
 
@@ -111,7 +114,8 @@ class TestSuite(Test):
     
     def run(self):
         for test in self.tests:
-            self.test.run()
+            print "Running %s..." % test.description()
+            test.run()
 
 
 class TextureTemplate:
index 2287884285e8b8837307786440e8038624fcbe99..3c1cda59d744a918ca126ca1e1751edae0d1123d 100644 (file)
@@ -211,7 +211,6 @@ dxt1_rgba = [
 
 
 def generate_data_compressed(surface, blocks):
-    pixels, block = blocks[0]
     
     stride = surface.nblocksx*surface.block.size
     size = surface.nblocksy*stride
@@ -219,19 +218,23 @@ def generate_data_compressed(surface, blocks):
     raw = ByteArray(size)
     rgba = FloatArray(surface.height*surface.width*4)
     
-    for y in range(0, surface.nblocksx):
-        for x in range(0, surface.nblocksy):
+    for yj in range(0, surface.nblocksy):
+        for xj in range(0, surface.nblocksx):
+            pixels, block = blocks[random.randint(0, len(blocks) - 1)]
             
-            offset = (y*surface.nblocksx + x)*surface.block.width
+            offset = (yj*surface.nblocksx + xj)*surface.block.size
             for i in range(0, surface.block.size):
                 raw[offset + i] = block[i]
             
-            for j in range(0, surface.block.width):
-                for i in range(0, surface.block.height):
-                    offset = ((y*surface.block.height + j)*surface.width + x*surface.block.width + i)*4 
-                    pixel = pixels[j*surface.block.width + i]
-                    for ch in range(0, 4):
-                        rgba[offset + ch] = float(pixel[ch])/255.0
+            for yi in range(0, surface.block.height):
+                for xi in range(0, surface.block.width):
+                    y = yj*surface.block.height + yi
+                    x = xj*surface.block.width + xi
+                    if y < surface.height and x < surface.width:
+                        offset = (y*surface.width + x)*4 
+                        pixel = pixels[yi*surface.block.width + xi]
+                        for ch in range(0, 4):
+                            rgba[offset + ch] = float(pixel[ch])/255.0
     
     surface.put_tile_raw(0, 0, surface.width, surface.height, raw, stride)
 
@@ -252,6 +255,14 @@ def generate_data_simple(surface):
     
     surface.get_tile_rgba(0, 0, surface.width, surface.height, rgba)
     
+    if surface.format in (PIPE_FORMAT_YCBCR, PIPE_FORMAT_YCBCR_REV):
+        # normalize
+        for y in range(0, surface.height):
+            for x in range(0, surface.width):
+                for ch in range(4):
+                    offset = (y*surface.width + x)*4 + ch
+                    rgba[offset] = min(max(rgba[offset], 0.0), 1.0)
+    
     return rgba
 
 
index 6a5ffb38b958a6729202b749bad1f0557e2481f5..7812d8aebf50d543ad14807621ddfe1df829bf61 100644 (file)
@@ -33,7 +33,7 @@ from base import *
 from data import generate_data
 
 
-def compare_rgba(width, height, rgba1, rgba2, tol=0.01):
+def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256):
     errors = 0
     for y in range(0, height):
         for x in range(0, width):
@@ -58,22 +58,25 @@ class TextureTest(Test):
         Test.__init__(self)
         self.__dict__.update(kargs)
 
+    def description(self):
+        return "%s %ux%u" % (formats[self.format], self.width, self.height)
+        
     def run(self):
         dev = self.dev
         
-        #format = PIPE_FORMAT_A8R8G8B8_UNORM
-        format = PIPE_FORMAT_DXT1_RGB
+        format = self.format
+        width = self.width
+        height = self.height
         
         if not dev.is_format_supported(format, PIPE_TEXTURE):
-            pass
+            print "SKIP"
+            return
         if not dev.is_format_supported(format, PIPE_SURFACE):
-            pass
+            print "SKIP"
+            return
         
         ctx = dev.context_create()
     
-        width = 64
-        height = 64
-    
         # disabled blending/masking
         blend = Blend()
         blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -169,7 +172,7 @@ class TextureTest(Test):
             0:TEX OUT[0], IN[0], SAMP[0], 2D
             1:END
         ''')
-        fs.dump()
+        #fs.dump()
         ctx.set_fragment_shader(fs)
 
         nverts = 4
@@ -227,15 +230,26 @@ class TextureTest(Test):
 
         cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba)
 
-        compare_rgba(width, height, rgba, expected_rgba)
+        if compare_rgba(width, height, rgba, expected_rgba):
+            print "OK"
+        else:
+            print "FAIL"
         
-        show_image(width, height, Result=rgba, Expected=expected_rgba)
+            show_image(width, height, Result=rgba, Expected=expected_rgba)
+            #save_image(width, height, rgba, "result.png")
+            #save_image(width, height, expected_rgba, "expected.png")
+            sys.exit(0)
 
 
 def main():
     dev = Device()
-    test = TextureTest(dev = dev)
-    test.run()
+    suite = TestSuite()
+    formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_DXT1_RGB]
+    sizes = [64, 32, 16, 8, 4, 2]
+    for format in formats:
+        for size in sizes:
+            suite.add_test(TextureTest(dev=dev, format=format, width=size, height=size))
+    suite.run()
 
 
 if __name__ == '__main__':