Here for backwards compat, prefer transcodeImageWithFlags(). get_alpha_for_opaque_formats defaults to false channel0/channel1 default to -1 format is transcoder_texture_format
| 1241 | // channel0/channel1 default to -1 |
| 1242 | // format is transcoder_texture_format |
| 1243 | uint32_t transcodeImage(const emscripten::val& dst, uint32_t level_index, uint32_t layer_index, uint32_t face_index, uint32_t format, uint32_t get_alpha_for_opaque_formats, int channel0, int channel1) |
| 1244 | { |
| 1245 | assert(m_magic == KTX2_MAGIC); |
| 1246 | if (m_magic != KTX2_MAGIC) |
| 1247 | return 0; |
| 1248 | |
| 1249 | if (format >= (int)transcoder_texture_format::cTFTotalTextureFormats) |
| 1250 | return 0; |
| 1251 | |
| 1252 | const transcoder_texture_format transcoder_format = static_cast<transcoder_texture_format>(format); |
| 1253 | |
| 1254 | const uint32_t dst_block_width = basis_get_block_width(transcoder_format); |
| 1255 | const uint32_t dst_block_height = basis_get_block_height(transcoder_format); |
| 1256 | |
| 1257 | ktx2_image_level_info info; |
| 1258 | if (!m_transcoder.get_image_level_info(info, level_index, layer_index, face_index)) |
| 1259 | return 0; |
| 1260 | |
| 1261 | uint32_t orig_width = info.m_orig_width, orig_height = info.m_orig_height, total_src_blocks = info.m_total_blocks; |
| 1262 | |
| 1263 | basisu::vector<uint8_t> dst_data; |
| 1264 | |
| 1265 | uint32_t flags = get_alpha_for_opaque_formats ? cDecodeFlagsTranscodeAlphaDataToOpaqueFormats : 0; |
| 1266 | |
| 1267 | const uint32_t transcoded_size_in_bytes = getImageTranscodedSizeInBytes(level_index, layer_index, face_index, format); |
| 1268 | |
| 1269 | if (!dst_data.try_resize(transcoded_size_in_bytes)) |
| 1270 | return 0; |
| 1271 | |
| 1272 | uint32_t status; |
| 1273 | |
| 1274 | if (basis_transcoder_format_is_uncompressed(transcoder_format)) |
| 1275 | { |
| 1276 | status = m_transcoder.transcode_image_level( |
| 1277 | level_index, layer_index, face_index, |
| 1278 | dst_data.data(), orig_width * orig_height, |
| 1279 | transcoder_format, |
| 1280 | flags, |
| 1281 | orig_width, |
| 1282 | orig_height, |
| 1283 | channel0, channel1, |
| 1284 | nullptr); |
| 1285 | } |
| 1286 | else |
| 1287 | { |
| 1288 | const uint32_t bytes_per_block = basis_get_bytes_per_block_or_pixel(transcoder_format); |
| 1289 | |
| 1290 | status = m_transcoder.transcode_image_level( |
| 1291 | level_index, layer_index, face_index, |
| 1292 | dst_data.data(), dst_data.size() / bytes_per_block, |
| 1293 | static_cast<basist::transcoder_texture_format>(format), |
| 1294 | flags, |
| 1295 | 0, |
| 1296 | 0, |
| 1297 | channel0, channel1, |
| 1298 | nullptr); |
| 1299 | } |
| 1300 |
no test coverage detected