etc1_bool etc1_pkm_is_valid(const etc1_byte* pHeader) { if (memcmp(pHeader, kMagic, sizeof(kMagic))) { return false; } etc1_uint32 format = readBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET); etc1_uint32 encodedWidth = readBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET); etc1_uint32 encodedHeight = readBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET); etc1_uint32 width = readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET); etc1_uint32 height = readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET); return format == ETC1_RGB_NO_MIPMAPS && encodedWidth >= width && encodedWidth - width < 4 && encodedHeight >= height && encodedHeight - height < 4; }
static int etc1_pkm_is_valid(const unsigned char* pHeader, unsigned* pencodedWidth, unsigned* pencodedHeight) { if (memcmp(pHeader, kMagic, sizeof(kMagic))) { return 0; } unsigned format = readBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET); unsigned encodedWidth = readBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET); unsigned encodedHeight = readBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET); unsigned width = readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET); unsigned height = readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET); *pencodedWidth = encodedWidth; *pencodedHeight = encodedHeight; return format == ETC1_RGB_NO_MIPMAPS && encodedWidth >= width && encodedWidth - width < 4 && encodedHeight >= height && encodedHeight - height < 4; }
etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader) { return readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET); }
etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader) { return readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET); }