MCPcopy Create free account
hub / github.com/defold/defold / transcode_image_level

Method transcode_image_level

engine/dlib/src/basis/transcoder/basisu_transcoder.cpp:10685–10834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10683 }
10684
10685 bool basisu_transcoder::transcode_image_level(
10686 const void* pData, uint32_t data_size,
10687 uint32_t image_index, uint32_t level_index,
10688 void* pOutput_blocks, uint32_t output_blocks_buf_size_in_blocks_or_pixels,
10689 transcoder_texture_format fmt,
10690 uint32_t decode_flags, uint32_t output_row_pitch_in_blocks_or_pixels, basisu_transcoder_state *pState, uint32_t output_rows_in_pixels) const
10691 {
10692 const uint32_t bytes_per_block_or_pixel = basis_get_bytes_per_block_or_pixel(fmt);
10693
10694 if (!m_ready_to_transcode)
10695 {
10696 BASISU_DEVEL_ERROR("basisu_transcoder::transcode_image_level: must call start_transcoding() first\n");
10697 return false;
10698 }
10699
10700 //const bool transcode_alpha_data_to_opaque_formats = (decode_flags & cDecodeFlagsTranscodeAlphaDataToOpaqueFormats) != 0;
10701
10702 if (decode_flags & cDecodeFlagsPVRTCDecodeToNextPow2)
10703 {
10704 BASISU_DEVEL_ERROR("basisu_transcoder::transcode_image_level: cDecodeFlagsPVRTCDecodeToNextPow2 currently unsupported\n");
10705 // TODO: Not yet supported
10706 return false;
10707 }
10708
10709 if (!validate_header_quick(pData, data_size))
10710 {
10711 BASISU_DEVEL_ERROR("basisu_transcoder::transcode_image_level: header validation failed\n");
10712 return false;
10713 }
10714
10715 const basis_file_header* pHeader = reinterpret_cast<const basis_file_header*>(pData);
10716
10717 const uint8_t* pDataU8 = static_cast<const uint8_t*>(pData);
10718
10719 const basis_slice_desc* pSlice_descs = reinterpret_cast<const basis_slice_desc*>(pDataU8 + pHeader->m_slice_desc_file_ofs);
10720
10721 const bool basis_file_has_alpha_slices = (pHeader->m_flags & cBASISHeaderFlagHasAlphaSlices) != 0;
10722
10723 int slice_index = find_first_slice_index(pData, data_size, image_index, level_index);
10724 if (slice_index < 0)
10725 {
10726 BASISU_DEVEL_ERROR("basisu_transcoder::transcode_image_level: failed finding slice index\n");
10727 // Unable to find the requested image/level
10728 return false;
10729 }
10730
10731 if ((fmt == transcoder_texture_format::cTFPVRTC1_4_RGBA) && (!basis_file_has_alpha_slices))
10732 {
10733 // Switch to PVRTC1 RGB if the input doesn't have alpha.
10734 fmt = transcoder_texture_format::cTFPVRTC1_4_RGB;
10735 }
10736
10737 if (pHeader->m_tex_format == (int)basis_tex_format::cETC1S)
10738 {
10739 if (pSlice_descs[slice_index].m_flags & cSliceDescFlagsHasAlpha)
10740 {
10741 BASISU_DEVEL_ERROR("basisu_transcoder::transcode_image_level: alpha basis file has out of order alpha slice\n");
10742

Callers 1

TranscodeLevelFunction · 0.80

Calls 6

transcode_imageMethod · 0.80
assertFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected