| 16636 | } |
| 16637 | |
| 16638 | bool ktx2_transcoder::init(const void* pData, uint32_t data_size) |
| 16639 | { |
| 16640 | clear(); |
| 16641 | |
| 16642 | if (!pData) |
| 16643 | { |
| 16644 | BASISU_DEVEL_ERROR("ktx2_transcoder::init: pData is nullptr\n"); |
| 16645 | assert(0); |
| 16646 | return false; |
| 16647 | } |
| 16648 | |
| 16649 | if (data_size <= sizeof(ktx2_header)) |
| 16650 | { |
| 16651 | BASISU_DEVEL_ERROR("ktx2_transcoder::init: File is impossibly too small to be a valid KTX2 file\n"); |
| 16652 | return false; |
| 16653 | } |
| 16654 | |
| 16655 | if (memcmp(pData, g_ktx2_file_identifier, sizeof(g_ktx2_file_identifier)) != 0) |
| 16656 | { |
| 16657 | BASISU_DEVEL_ERROR("ktx2_transcoder::init: KTX2 file identifier is not present\n"); |
| 16658 | return false; |
| 16659 | } |
| 16660 | |
| 16661 | m_pData = static_cast<const uint8_t *>(pData); |
| 16662 | m_data_size = data_size; |
| 16663 | |
| 16664 | memcpy((void*)&m_header, pData, sizeof(m_header)); |
| 16665 | |
| 16666 | // We only support UASTC and ETC1S |
| 16667 | if (m_header.m_vk_format != KTX2_VK_FORMAT_UNDEFINED) |
| 16668 | { |
| 16669 | BASISU_DEVEL_ERROR("ktx2_transcoder::init: KTX2 file must be in ETC1S or UASTC format\n"); |
| 16670 | return false; |
| 16671 | } |
| 16672 | |
| 16673 | // 3.3: "When format is VK_FORMAT_UNDEFINED, typeSize must equal 1." |
| 16674 | if (m_header.m_type_size != 1) |
| 16675 | { |
| 16676 | BASISU_DEVEL_ERROR("ktx2_transcoder::init: Invalid type_size\n"); |
| 16677 | return false; |
| 16678 | } |
| 16679 | |
| 16680 | // We only currently support 2D textures (plain, cubemapped, or texture array), which is by far the most common use case. |
| 16681 | // The BasisU library does not support 1D or 3D textures at all. |
| 16682 | if ((m_header.m_pixel_width < 1) || (m_header.m_pixel_height < 1) || (m_header.m_pixel_depth > 0)) |
| 16683 | { |
| 16684 | BASISU_DEVEL_ERROR("ktx2_transcoder::init: Only 2D or cubemap textures are supported\n"); |
| 16685 | return false; |
| 16686 | } |
| 16687 | |
| 16688 | // Face count must be 1 or 6 |
| 16689 | if ((m_header.m_face_count != 1) && (m_header.m_face_count != 6)) |
| 16690 | { |
| 16691 | BASISU_DEVEL_ERROR("ktx2_transcoder::init: Invalid face count, file is corrupted or invalid\n"); |
| 16692 | return false; |
| 16693 | } |
| 16694 | |
| 16695 | if (m_header.m_face_count > 1) |
no test coverage detected