def generate_data_compressed(surface, blocks):
- pixels, block = blocks[0]
stride = surface.nblocksx*surface.block.size
size = surface.nblocksy*stride
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)
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
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):
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
0:TEX OUT[0], IN[0], SAMP[0], 2D
1:END
''')
- fs.dump()
+ #fs.dump()
ctx.set_fragment_shader(fs)
nverts = 4
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__':