MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / decodeASTC

Function decodeASTC

tests/ktxdiff/ktxdiff_main.cpp:274–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274auto decodeASTC(const char* compressedData, std::size_t compressedSize, uint32_t width, uint32_t height,
275 const std::string& filepath, bool isFormatSRGB, uint32_t blockSizeX, uint32_t blockSizeY, uint32_t blockSizeZ) {
276
277 const auto threadCount = 1u;
278 static constexpr astcenc_swizzle swizzle{ASTCENC_SWZ_R, ASTCENC_SWZ_G, ASTCENC_SWZ_B, ASTCENC_SWZ_A};
279
280 astcenc_error ec = ASTCENC_SUCCESS;
281
282 const astcenc_profile profile = isFormatSRGB ? ASTCENC_PRF_LDR_SRGB : ASTCENC_PRF_LDR;
283 astcenc_config config{};
284 ec = astcenc_config_init(profile, blockSizeX, blockSizeY, blockSizeZ, ASTCENC_PRE_MEDIUM, ASTCENC_FLG_DECOMPRESS_ONLY, &config);
285 if (ec != ASTCENC_SUCCESS)
286 error(EXIT_CODE_ERROR, "ktxdiff error \"{}\": astcenc_config_init: {}\n", filepath, astcenc_get_error_string(ec));
287
288 struct ASTCencStruct {
289 astcenc_context* context = nullptr;
290 ~ASTCencStruct() {
291 astcenc_context_free(context);
292 }
293 } astcenc;
294 astcenc_context*& context = astcenc.context;
295
296 ec = astcenc_context_alloc(&config, threadCount, &context);
297 if (ec != ASTCENC_SUCCESS)
298 error(EXIT_CODE_ERROR, "ktxdiff error \"{}\": astcenc_context_alloc: {}\n", filepath, astcenc_get_error_string(ec));
299
300 astcenc_image image{};
301 image.dim_x = width;
302 image.dim_y = height;
303 image.dim_z = 1; // 3D ASTC formats are currently not supported
304 const auto uncompressedSize = width * height * 4 * sizeof(uint8_t);
305 auto uncompressedBuffer = std::make_unique<uint8_t[]>(uncompressedSize);
306 auto* bufferPtr = uncompressedBuffer.get();
307 image.data = reinterpret_cast<void**>(&bufferPtr);
308 image.data_type = ASTCENC_TYPE_U8;
309
310 ec = astcenc_decompress_image(context, reinterpret_cast<const uint8_t*>(compressedData), compressedSize, &image, &swizzle, 0);
311 if (ec != ASTCENC_SUCCESS)
312 error(EXIT_CODE_ERROR, "ktxdiff error \"{}\": astcenc_decompress_image: {}\n", filepath, astcenc_get_error_string(ec));
313
314 astcenc_decompress_reset(context);
315
316 struct Result {
317 std::unique_ptr<uint8_t[]> data;
318 std::size_t size;
319 };
320 return Result{std::move(uncompressedBuffer), uncompressedSize};
321}
322
323CompareResult compareAstc(const char* lhs, const char* rhs, std::size_t size, uint32_t width, uint32_t height,
324 const std::string& filepathLhs, const std::string& filepathRhs,

Callers 1

compareAstcFunction · 0.85

Calls 7

astcenc_config_initFunction · 0.85
errorFunction · 0.85
astcenc_get_error_stringFunction · 0.85
astcenc_context_allocFunction · 0.85
astcenc_decompress_imageFunction · 0.85
astcenc_decompress_resetFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected