|
|
|
@ -16,10 +16,10 @@ class TestBC1Block(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_size(self):
|
|
|
|
|
"""Test the size and dimensions of BC1Block"""
|
|
|
|
|
self.assertEqual(BC1Block.size, 8, 'incorrect block size')
|
|
|
|
|
self.assertEqual(BC1Block.nbytes, 8, 'incorrect block size')
|
|
|
|
|
self.assertEqual(BC1Block.width, 4, 'incorrect block width')
|
|
|
|
|
self.assertEqual(BC1Block.height, 4, 'incorrect block width')
|
|
|
|
|
self.assertEqual(BC1Block.dimensions, (4, 4), 'incorrect block dimensions')
|
|
|
|
|
self.assertEqual(BC1Block.size, (4, 4), 'incorrect block dimensions')
|
|
|
|
|
|
|
|
|
|
def test_buffer(self):
|
|
|
|
|
"""Test the buffer protocol of BC1Block"""
|
|
|
|
@ -29,7 +29,7 @@ class TestBC1Block(unittest.TestCase):
|
|
|
|
|
self.assertFalse(mv.readonly, 'buffer is readonly')
|
|
|
|
|
self.assertTrue(mv.c_contiguous, 'buffer is not contiguous')
|
|
|
|
|
self.assertEqual(mv.ndim, 1, 'buffer is multidimensional')
|
|
|
|
|
self.assertEqual(mv.nbytes, BC1Block.size, 'buffer is the wrong size')
|
|
|
|
|
self.assertEqual(mv.nbytes, BC1Block.nbytes, 'buffer is the wrong size')
|
|
|
|
|
self.assertEqual(mv.format, 'B', 'buffer has the wrong format')
|
|
|
|
|
|
|
|
|
|
mv[:] = block_bytes
|
|
|
|
@ -68,24 +68,24 @@ class TestBC1Block(unittest.TestCase):
|
|
|
|
|
class TestBC1Texture(unittest.TestCase):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.tex = BC1Texture(self.w, self.h)
|
|
|
|
|
self.size = self.wb * self.hb * BC1Block.size
|
|
|
|
|
self.nbytes = self.wb * self.hb * BC1Block.nbytes
|
|
|
|
|
|
|
|
|
|
def test_size(self):
|
|
|
|
|
"""Test size of BC1Texture in bytes"""
|
|
|
|
|
self.assertEqual(self.tex.size, self.size, 'incorrect texture size')
|
|
|
|
|
self.assertEqual(len(self.tex.tobytes()), self.size, 'incorrect texture size from tobytes')
|
|
|
|
|
self.assertEqual(self.tex.nbytes, self.nbytes, 'incorrect texture size')
|
|
|
|
|
self.assertEqual(len(self.tex.tobytes()), self.nbytes, 'incorrect texture size from tobytes')
|
|
|
|
|
|
|
|
|
|
def test_dimensions(self):
|
|
|
|
|
"""Test dimensions of BC1Texture in pixels"""
|
|
|
|
|
self.assertEqual(self.tex.width, self.w, 'incorrect texture width')
|
|
|
|
|
self.assertEqual(self.tex.height, self.h, 'incorrect texture height')
|
|
|
|
|
self.assertEqual(self.tex.dimensions, (self.w, self.h), 'incorrect texture dimensions')
|
|
|
|
|
self.assertEqual(self.tex.size, (self.w, self.h), 'incorrect texture dimensions')
|
|
|
|
|
|
|
|
|
|
def test_dimensions_blocks(self):
|
|
|
|
|
"""Test dimensions of BC1Texture in blocks"""
|
|
|
|
|
self.assertEqual(self.tex.width_blocks, self.wb, 'incorrect texture width_blocks')
|
|
|
|
|
self.assertEqual(self.tex.height_blocks, self.hb, 'incorrect texture width_blocks')
|
|
|
|
|
self.assertEqual(self.tex.dimensions_blocks, (self.wb, self.hb), 'incorrect texture dimensions_blocks')
|
|
|
|
|
self.assertEqual(self.tex.size_blocks, (self.wb, self.hb), 'incorrect texture dimensions_blocks')
|
|
|
|
|
|
|
|
|
|
def test_blocks(self):
|
|
|
|
|
"""Test getting and setting blocks to BC1Texture"""
|
|
|
|
@ -97,9 +97,9 @@ class TestBC1Texture(unittest.TestCase):
|
|
|
|
|
b = self.tex.tobytes()
|
|
|
|
|
for x in range(self.wb):
|
|
|
|
|
for y in range(self.hb):
|
|
|
|
|
index = (x + (y * self.wb)) * BC1Block.size
|
|
|
|
|
index = (x + (y * self.wb)) * BC1Block.nbytes
|
|
|
|
|
tb = self.tex[x, y]
|
|
|
|
|
fb = BC1Block.frombytes(b[index:index + BC1Block.size])
|
|
|
|
|
fb = BC1Block.frombytes(b[index:index + BC1Block.nbytes])
|
|
|
|
|
self.assertEqual(tb, blocks[y][x], 'incorrect block read from texture')
|
|
|
|
|
self.assertEqual(fb, blocks[y][x], 'incorrect block read from texture bytes')
|
|
|
|
|
|
|
|
|
@ -116,7 +116,7 @@ class TestBC1Texture(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
self.assertFalse(mv.readonly, 'buffer is readonly')
|
|
|
|
|
self.assertTrue(mv.c_contiguous, 'buffer is not contiguous')
|
|
|
|
|
self.assertEqual(mv.nbytes, self.size, 'buffer is the wrong size')
|
|
|
|
|
self.assertEqual(mv.nbytes, self.nbytes, 'buffer is the wrong size')
|
|
|
|
|
self.assertEqual(mv.format, 'B', 'buffer has the wrong format')
|
|
|
|
|
|
|
|
|
|
data = block_bytes * self.wb * self.hb
|
|
|
|
@ -141,7 +141,7 @@ class TestBC1Encoder(unittest.TestCase):
|
|
|
|
|
"""Test encoder output with 4 color greyscale test block"""
|
|
|
|
|
out_tex = self.bc1_encoder.encode(BC1Blocks.greyscale.texture)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(out_tex.dimensions_blocks, (1, 1), 'encoded texture has multiple blocks')
|
|
|
|
|
self.assertEqual(out_tex.size_blocks, (1, 1), 'encoded texture has multiple blocks')
|
|
|
|
|
|
|
|
|
|
out_block = out_tex[0, 0]
|
|
|
|
|
|
|
|
|
@ -152,7 +152,7 @@ class TestBC1Encoder(unittest.TestCase):
|
|
|
|
|
"""Test encoder output with 3 color test block"""
|
|
|
|
|
out_tex = self.bc1_encoder.encode(BC1Blocks.three_color.texture)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(out_tex.dimensions_blocks, (1, 1), 'encoded texture has multiple blocks')
|
|
|
|
|
self.assertEqual(out_tex.size_blocks, (1, 1), 'encoded texture has multiple blocks')
|
|
|
|
|
|
|
|
|
|
out_block = out_tex[0, 0]
|
|
|
|
|
|
|
|
|
@ -166,7 +166,7 @@ class TestBC1Encoder(unittest.TestCase):
|
|
|
|
|
"""Test encoder output with 3 color test block with black pixels"""
|
|
|
|
|
out_tex = self.bc1_encoder.encode(BC1Blocks.three_color_black.texture)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(out_tex.dimensions_blocks, (1, 1), 'encoded texture has multiple blocks')
|
|
|
|
|
self.assertEqual(out_tex.size_blocks, (1, 1), 'encoded texture has multiple blocks')
|
|
|
|
|
|
|
|
|
|
out_block = out_tex[0, 0]
|
|
|
|
|
has_black = 3 in [j for row in out_block.selectors for j in row]
|
|
|
|
@ -199,7 +199,7 @@ class TestBC1Decoder(unittest.TestCase):
|
|
|
|
|
in_tex[0, 0] = block
|
|
|
|
|
out_tex = self.bc1_decoder.decode(in_tex)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(out_tex.dimensions, (4, 4), 'decoded texture has incorrect dimensions')
|
|
|
|
|
self.assertEqual(out_tex.size, (4, 4), 'decoded texture has incorrect dimensions')
|
|
|
|
|
|
|
|
|
|
out_img = Image.frombytes('RGBA', (4, 4), out_tex.tobytes())
|
|
|
|
|
img_diff = ImageChops.difference(out_img, image).convert('L')
|
|
|
|
|