Low-level direct transcoding from an already-open KTX2 handle, using a high-level family string such as: "BC7", "BC3", "BC1", "ETC1", "ETC2", "ASTC", "PVRTC1", "RGBA32", "RGB_HALF", "RGBA_HALF", "RGB_9E5", etc. See choose_transcoder_format().
(
self,
ktx2_handle: KTX2Handle,
family: str,
level=0,
layer=0,
face=0,
decode_flags=0,
channel0=-1,
channel1=-1
)
| 616 | # (data_bytes, chosen_tfmt, block_width, block_height) |
| 617 | # ----------------------------------------------------------------------- |
| 618 | def transcode_handle( |
| 619 | self, |
| 620 | ktx2_handle: KTX2Handle, |
| 621 | family: str, |
| 622 | level=0, |
| 623 | layer=0, |
| 624 | face=0, |
| 625 | decode_flags=0, |
| 626 | channel0=-1, |
| 627 | channel1=-1 |
| 628 | ): |
| 629 | """ |
| 630 | Low-level direct transcoding from an already-open KTX2 handle, |
| 631 | using a high-level family string such as: |
| 632 | "BC7", "BC3", "BC1", "ETC1", "ETC2", "ASTC", "PVRTC1", |
| 633 | "RGBA32", "RGB_HALF", "RGBA_HALF", "RGB_9E5", etc. |
| 634 | See choose_transcoder_format(). |
| 635 | Returns: |
| 636 | (data_bytes, tfmt, block_width, block_height) |
| 637 | """ |
| 638 | |
| 639 | # Decide the exact transcoder format (BC1/BC7/etc.) |
| 640 | tfmt = self.choose_transcoder_format(ktx2_handle, family) |
| 641 | |
| 642 | # Get original dims of the requested slice |
| 643 | ow = self.get_level_orig_width(ktx2_handle, level, layer, face) |
| 644 | oh = self.get_level_orig_height(ktx2_handle, level, layer, face) |
| 645 | |
| 646 | # Compute correct output size for the chosen format |
| 647 | out_size = self.basis_compute_transcoded_image_size_in_bytes(tfmt, ow, oh) |
| 648 | if out_size == 0: |
| 649 | raise RuntimeError( |
| 650 | f"Computed output size is 0 for tfmt={tfmt}, dims={ow}x{oh}" |
| 651 | ) |
| 652 | |
| 653 | # Allocate output buffer |
| 654 | out_ptr = self._alloc(out_size) |
| 655 | |
| 656 | # Ensure transcoding tables are ready |
| 657 | ok = self.ktx2_start_transcoding(ktx2_handle.handle) |
| 658 | if not ok: |
| 659 | self._free(out_ptr) |
| 660 | raise RuntimeError("start_transcoding failed") |
| 661 | |
| 662 | # Perform the transcode |
| 663 | ok = self.ktx2_transcode_image_level( |
| 664 | ktx2_handle.handle, |
| 665 | level, layer, face, |
| 666 | out_ptr, |
| 667 | out_size // self.basis_get_bytes_per_block_or_pixel(tfmt), |
| 668 | tfmt, |
| 669 | decode_flags, |
| 670 | 0, # row_pitch_in_blocks_or_pixels |
| 671 | 0, # rows_in_pixels |
| 672 | channel0, |
| 673 | channel1, |
| 674 | 0 # no thread-local state |
| 675 | ) |
no test coverage detected