| 10331 | } |
| 10332 | |
| 10333 | bool basisu_transcoder::start_transcoding(const void* pData, uint32_t data_size) |
| 10334 | { |
| 10335 | if (!validate_header_quick(pData, data_size)) |
| 10336 | { |
| 10337 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: header validation failed\n"); |
| 10338 | return false; |
| 10339 | } |
| 10340 | |
| 10341 | const basis_file_header* pHeader = reinterpret_cast<const basis_file_header*>(pData); |
| 10342 | const uint8_t* pDataU8 = static_cast<const uint8_t*>(pData); |
| 10343 | |
| 10344 | if (pHeader->m_tex_format == (int)basis_tex_format::cETC1S) |
| 10345 | { |
| 10346 | if (m_lowlevel_etc1s_decoder.m_local_endpoints.size()) |
| 10347 | { |
| 10348 | m_lowlevel_etc1s_decoder.clear(); |
| 10349 | } |
| 10350 | |
| 10351 | if (pHeader->m_flags & cBASISHeaderFlagUsesGlobalCodebook) |
| 10352 | { |
| 10353 | if (!m_lowlevel_etc1s_decoder.get_global_codebooks()) |
| 10354 | { |
| 10355 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: File uses global codebooks, but set_global_codebooks() has not been called\n"); |
| 10356 | return false; |
| 10357 | } |
| 10358 | if (!m_lowlevel_etc1s_decoder.get_global_codebooks()->get_endpoints().size()) |
| 10359 | { |
| 10360 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: Global codebooks must be unpacked first by calling start_transcoding()\n"); |
| 10361 | return false; |
| 10362 | } |
| 10363 | if ((m_lowlevel_etc1s_decoder.get_global_codebooks()->get_endpoints().size() != pHeader->m_total_endpoints) || |
| 10364 | (m_lowlevel_etc1s_decoder.get_global_codebooks()->get_selectors().size() != pHeader->m_total_selectors)) |
| 10365 | { |
| 10366 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: Global codebook size mismatch (wrong codebooks for file).\n"); |
| 10367 | return false; |
| 10368 | } |
| 10369 | if (!pHeader->m_tables_file_size) |
| 10370 | { |
| 10371 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: file is corrupted (2)\n"); |
| 10372 | return false; |
| 10373 | } |
| 10374 | if (pHeader->m_tables_file_ofs > data_size) |
| 10375 | { |
| 10376 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: file is corrupted or passed in buffer too small (4)\n"); |
| 10377 | return false; |
| 10378 | } |
| 10379 | if (pHeader->m_tables_file_size > (data_size - pHeader->m_tables_file_ofs)) |
| 10380 | { |
| 10381 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: file is corrupted or passed in buffer too small (5)\n"); |
| 10382 | return false; |
| 10383 | } |
| 10384 | } |
| 10385 | else |
| 10386 | { |
| 10387 | if (!pHeader->m_endpoint_cb_file_size || !pHeader->m_selector_cb_file_size || !pHeader->m_tables_file_size) |
| 10388 | { |
| 10389 | BASISU_DEVEL_ERROR("basisu_transcoder::start_transcoding: file is corrupted (0)\n"); |
| 10390 | return false; |
no test coverage detected