This class wraps the latest astcenc interface, supported from the 2.0 release or later, which broke argument compatibility with the earlier 1.x series.
| 259 | |
| 260 | |
| 261 | class Encoder2x(EncoderBase): |
| 262 | ''' |
| 263 | This class wraps the latest astcenc interface, supported from the 2.0 |
| 264 | release or later, which broke argument compatibility with the earlier |
| 265 | 1.x series. |
| 266 | ''' |
| 267 | version = 'main' |
| 268 | |
| 269 | remap_color_switches = { |
| 270 | 'ldr': '-tl', |
| 271 | 'ldrs': '-ts', |
| 272 | 'hdr': '-th', |
| 273 | 'hdra': '-tH' |
| 274 | } |
| 275 | |
| 276 | remap_output_types = { |
| 277 | 'ldr': '.png', |
| 278 | 'ldrs': '.png', |
| 279 | 'hdr': '.exr', |
| 280 | 'hdra': '.exr' |
| 281 | } |
| 282 | |
| 283 | def __init__(self, variant: str, binary_path: Optional[Path] = None): |
| 284 | name = f'astcenc-{variant}-{self.version}' |
| 285 | |
| 286 | if binary_path is None: |
| 287 | binary = 'astcenc' |
| 288 | post = f'-{variant}' if variant != 'universal' else '' |
| 289 | ext = '.exe' if os.name == 'nt' else '' |
| 290 | binary_path = Path('./') / 'bin' / f'{binary}{post}{ext}' |
| 291 | |
| 292 | super().__init__(name, variant, binary_path) |
| 293 | |
| 294 | def build_cli(self, image, block_size='6x6', preset='-thorough', |
| 295 | keep_output=True, threads=None): |
| 296 | operation = self.remap_color_switches[image.color_profile] |
| 297 | |
| 298 | src_path = image.file_path |
| 299 | |
| 300 | if keep_output: |
| 301 | extension = self.remap_output_types[image.color_profile] |
| 302 | |
| 303 | dst_file = f'{image.file_path_out.stem}{extension}' |
| 304 | |
| 305 | dst_dir = image.file_path_out.parent |
| 306 | dst_dir = dst_dir / self.name / preset[1:] / block_size |
| 307 | dst_dir.mkdir(parents=True, exist_ok=True) |
| 308 | |
| 309 | dst_path = str(dst_dir / dst_file) |
| 310 | |
| 311 | else: |
| 312 | if sys.platform == 'win32': |
| 313 | dst_path = 'nul' |
| 314 | else: |
| 315 | dst_path = '/dev/null' |
| 316 | |
| 317 | command = [ |
| 318 | str(self.binary_path), operation, str(src_path), str(dst_path), |
nothing calls this directly
no outgoing calls
no test coverage detected