MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / init

Method init

external/basisu/transcoder/basisu_transcoder.cpp:16638–16917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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)

Callers 3

decode_palettesMethod · 0.45
decode_tablesMethod · 0.45
transcode_sliceMethod · 0.45

Calls 7

clearFunction · 0.85
assertFunction · 0.85
read_le_dwordFunction · 0.85
maximumFunction · 0.70
try_resizeMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected