Objects of this type contain metadata for a single test image on disk. Attributes: file_path: The path of the file on disk. file_path_out: The path of the output file on disk. test_format: The test format group. file_name: The test file name. color_p
| 48 | |
| 49 | |
| 50 | class TestImage: |
| 51 | ''' |
| 52 | Objects of this type contain metadata for a single test image on disk. |
| 53 | |
| 54 | Attributes: |
| 55 | file_path: The path of the file on disk. |
| 56 | file_path_out: The path of the output file on disk. |
| 57 | test_format: The test format group. |
| 58 | file_name: The test file name. |
| 59 | color_profile: The image compression color profile. |
| 60 | color_format: The image color format. |
| 61 | name: The image human name. |
| 62 | is_3d: True if the image is 3D, else False. |
| 63 | is_alpha_scaled: True if the image wants alpha scaling, else False. |
| 64 | |
| 65 | Class Attributes: |
| 66 | TEST_EXTS: Expected test image extensions. |
| 67 | PROFILES: Tuple of valid color profile values. |
| 68 | FORMATS: Tuple of valid color format values. |
| 69 | FLAGS: Map of valid flags (key) and their meaning (value). |
| 70 | ''' |
| 71 | TEST_EXTS = ('.jpg', '.png', '.tga', '.dds', '.hdr', '.ktx') |
| 72 | |
| 73 | PROFILES = ('ldr', 'ldrs', 'hdr') |
| 74 | |
| 75 | FORMATS = ('l', 'la', 'xy', 'rgb', 'rgba') |
| 76 | |
| 77 | FLAGS = { |
| 78 | '3': '3D image', |
| 79 | 'a': 'Alpha scaled image' |
| 80 | } |
| 81 | |
| 82 | def __init__(self, file_path: Path): |
| 83 | ''' |
| 84 | Create a new image definition, based on a structured file path. |
| 85 | |
| 86 | Args: |
| 87 | file_path: The path of the image on disk. |
| 88 | |
| 89 | Raise: |
| 90 | TestImageException: The image is not found or path is malformed. |
| 91 | ''' |
| 92 | self.file_path = file_path.resolve() |
| 93 | if not self.file_path.exists(): |
| 94 | raise TestImageException(f'Image does not exist ({file_path})') |
| 95 | |
| 96 | self.test_set = file_path.parent.parent.name |
| 97 | self.test_format = file_path.parent.name |
| 98 | self.file_name = file_path.name |
| 99 | |
| 100 | # Decode the mandatory fields |
| 101 | self.color_profile = self._decode_color_profile(file_path.stem) |
| 102 | self.color_format = self._decode_color_format(file_path.stem) |
| 103 | self.name = self._decode_name(file_path.stem) |
| 104 | |
| 105 | # Decode flags |
| 106 | flags = self._decode_flags(file_path.stem) |
| 107 | self.is_3d = '3' in flags |