quicktex/tests/test_BC1.py

68 lines
3.1 KiB
Python
Raw Normal View History

2021-03-10 11:42:31 +00:00
import rgbcx
2021-03-07 06:41:42 +00:00
import unittest
2021-03-10 09:15:04 +00:00
import nose
2021-03-10 11:42:31 +00:00
from parameterized import parameterized_class
from s3tc import BC1Block
2021-03-09 09:25:20 +00:00
from images import Blocks
2021-03-07 06:41:42 +00:00
2021-03-10 11:42:31 +00:00
def get_class_name(cls, num, params_dict):
2021-03-10 09:15:04 +00:00
# By default the generated class named includes either the "name"
# parameter (if present), or the first string value. This example shows
# multiple parameters being included in the generated class name:
return "%s%s" % (
cls.__name__,
params_dict['suffix'],
)
2021-03-10 11:42:31 +00:00
@parameterized_class([
2021-03-10 09:15:04 +00:00
{"use_3color": False, "use_3color_black": False, "suffix": "4Color"},
{"use_3color": True, "use_3color_black": False, "suffix": "3Color"},
{"use_3color": True, "use_3color_black": True, "suffix": "3ColorBlack"},
2021-03-10 11:42:31 +00:00
], class_name_func=get_class_name)
2021-03-10 09:15:04 +00:00
class TestBC1EncoderBlocks(unittest.TestCase):
2021-03-08 10:23:04 +00:00
"""Test BC1 encoder with a variety of inputs with 3 color blocks disabled."""
2021-03-07 06:41:42 +00:00
def setUp(self):
2021-03-10 09:15:04 +00:00
self.bc1_encoder = rgbcx.BC1Encoder(rgbcx.InterpolatorType.Ideal, 5, self.use_3color, self.use_3color_black)
2021-03-07 06:41:42 +00:00
def test_block_size(self):
2021-03-08 10:23:04 +00:00
"""Ensure encoded block size is 8 bytes."""
2021-03-09 09:25:20 +00:00
out = self.bc1_encoder.encode_image(Blocks.greyscale, 4, 4)
2021-03-07 09:39:51 +00:00
self.assertEqual(self.bc1_encoder.block_width, 4, 'incorrect reported block width')
self.assertEqual(self.bc1_encoder.block_height, 4, 'incorrect reported block height')
2021-03-07 06:41:42 +00:00
self.assertEqual(self.bc1_encoder.block_size, 8, 'incorrect reported block size')
self.assertEqual(len(out), 8, 'incorrect returned block size')
2021-03-08 10:23:04 +00:00
def test_block_4color(self):
2021-03-10 09:15:04 +00:00
"""Test encoder output with 4 color greyscale testblock."""
2021-03-10 11:42:31 +00:00
out = BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.greyscale, 4, 4))
2021-03-10 09:15:04 +00:00
selectors = [[0, 2, 3, 1]] * 4
2021-03-08 10:23:04 +00:00
2021-03-10 09:15:04 +00:00
self.assertFalse(out.is_3color(), "returned block color mode for greyscale test block")
self.assertEqual(selectors, out.selectors, "block has incorrect selectors for greyscale test block")
2021-03-08 00:15:26 +00:00
def test_block_3color(self):
2021-03-10 09:15:04 +00:00
"""Test encoder output with 3 color test block."""
2021-03-10 11:42:31 +00:00
out = BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color, 4, 4))
2021-03-10 09:15:04 +00:00
selectors = [[1, 2, 2, 0]] * 4
2021-03-08 00:15:26 +00:00
2021-03-10 09:15:04 +00:00
self.assertEqual(out.is_3color(), self.use_3color, "returned incorrect block color mode for 3 color test block")
if self.use_3color: # we only care about the selectors if we are in 3 color mode
self.assertEqual(selectors, out.selectors, "block has incorrect selectors for 3 color test block")
2021-03-08 00:15:26 +00:00
def test_block_3color_black(self):
2021-03-10 09:15:04 +00:00
"""Test encoder output with 3 color test block with black pixels."""
2021-03-10 11:42:31 +00:00
out = BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color_black, 4, 4))
2021-03-10 09:15:04 +00:00
selectors = [[3, 1, 2, 0]] * 4
2021-03-08 10:23:04 +00:00
2021-03-10 09:15:04 +00:00
self.assertEqual(out.is_3color_black(), self.use_3color_black, "returned incorrect block color mode for 3 color with black test block")
if self.use_3color_black: # we only care about the selectors if we are in 3 color black mode
self.assertEqual(selectors, out.selectors, "block has incorrect selectors for 3 color with black test block")
2021-03-08 10:23:04 +00:00
2021-03-07 06:41:42 +00:00
if __name__ == '__main__':
2021-03-10 09:15:04 +00:00
nose.main()