| 9990 | } |
| 9991 | |
| 9992 | bool basisu_transcoder::get_image_info(const void* pData, uint32_t data_size, basisu_image_info& image_info, uint32_t image_index) const |
| 9993 | { |
| 9994 | if (!validate_header_quick(pData, data_size)) |
| 9995 | { |
| 9996 | BASISU_DEVEL_ERROR("basisu_transcoder::get_image_info: header validation failed\n"); |
| 9997 | return false; |
| 9998 | } |
| 9999 | |
| 10000 | int slice_index = find_first_slice_index(pData, data_size, image_index, 0); |
| 10001 | if (slice_index < 0) |
| 10002 | { |
| 10003 | BASISU_DEVEL_ERROR("basisu_transcoder::get_image_info: invalid slice index\n"); |
| 10004 | return false; |
| 10005 | } |
| 10006 | |
| 10007 | const basis_file_header* pHeader = static_cast<const basis_file_header*>(pData); |
| 10008 | |
| 10009 | if (image_index >= pHeader->m_total_images) |
| 10010 | { |
| 10011 | BASISU_DEVEL_ERROR("basisu_transcoder::get_image_info: invalid image_index\n"); |
| 10012 | return false; |
| 10013 | } |
| 10014 | |
| 10015 | const basis_slice_desc* pSlice_descs = reinterpret_cast<const basis_slice_desc*>(static_cast<const uint8_t*>(pData) + pHeader->m_slice_desc_file_ofs); |
| 10016 | |
| 10017 | uint32_t total_levels = 1; |
| 10018 | for (uint32_t i = slice_index + 1; i < pHeader->m_total_slices; i++) |
| 10019 | if (pSlice_descs[i].m_image_index == image_index) |
| 10020 | total_levels = basisu::maximum<uint32_t>(total_levels, pSlice_descs[i].m_level_index + 1); |
| 10021 | else |
| 10022 | break; |
| 10023 | |
| 10024 | if (total_levels > 16) |
| 10025 | { |
| 10026 | BASISU_DEVEL_ERROR("basisu_transcoder::get_image_info: invalid image_index\n"); |
| 10027 | return false; |
| 10028 | } |
| 10029 | |
| 10030 | const basis_slice_desc& slice_desc = pSlice_descs[slice_index]; |
| 10031 | |
| 10032 | image_info.m_image_index = image_index; |
| 10033 | image_info.m_total_levels = total_levels; |
| 10034 | |
| 10035 | image_info.m_alpha_flag = false; |
| 10036 | |
| 10037 | // For ETC1S, if anything has alpha all images have alpha. For UASTC, we only report alpha when the image actually has alpha. |
| 10038 | if (pHeader->m_tex_format == (int)basis_tex_format::cETC1S) |
| 10039 | image_info.m_alpha_flag = (pHeader->m_flags & cBASISHeaderFlagHasAlphaSlices) != 0; |
| 10040 | else |
| 10041 | image_info.m_alpha_flag = (slice_desc.m_flags & cSliceDescFlagsHasAlpha) != 0; |
| 10042 | |
| 10043 | image_info.m_iframe_flag = (slice_desc.m_flags & cSliceDescFlagsFrameIsIFrame) != 0; |
| 10044 | |
| 10045 | image_info.m_width = slice_desc.m_num_blocks_x * 4; |
| 10046 | image_info.m_height = slice_desc.m_num_blocks_y * 4; |
| 10047 | image_info.m_orig_width = slice_desc.m_orig_width; |
| 10048 | image_info.m_orig_height = slice_desc.m_orig_height; |
| 10049 | image_info.m_num_blocks_x = slice_desc.m_num_blocks_x; |
no outgoing calls
no test coverage detected