@@ -360,7 +360,7 @@ astcSwizzle(const ktxAstcParams ¶ms) {
360
360
361
361
static void
362
362
astcBlockDimensions (ktx_uint32_t block_size,
363
- uint32_t & block_x, uint32_t & block_y, uint32_t & block_z) {
363
+ uint32_t & block_x, uint32_t & block_y, uint32_t & block_z) {
364
364
switch (block_size) {
365
365
case KTX_PACK_ASTC_BLOCK_DIMENSION_4x4 : block_x = 4 ; block_y = 4 ; block_z = 1 ; break ;
366
366
case KTX_PACK_ASTC_BLOCK_DIMENSION_5x4 : block_x = 5 ; block_y = 4 ; block_z = 1 ; break ;
@@ -393,7 +393,7 @@ astcBlockDimensions(ktx_uint32_t block_size,
393
393
394
394
static void
395
395
astcBlockDimensions (VkFormat format,
396
- uint32_t &x, uint32_t &y, uint32_t &z) noexcept {
396
+ uint32_t &x, uint32_t &y, uint32_t &z) noexcept {
397
397
switch (format) {
398
398
case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: x = 4 ; y = 4 ; z = 0 ; break ;
399
399
case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: x = 4 ; y = 4 ; z = 0 ; break ;
@@ -887,12 +887,12 @@ ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality) {
887
887
888
888
struct decompression_workload
889
889
{
890
- astcenc_context* context;
891
- uint8_t * data;
892
- size_t data_len;
893
- astcenc_image* image_out;
894
- astcenc_swizzle swizzle;
895
- astcenc_error error;
890
+ astcenc_context* context;
891
+ uint8_t * data;
892
+ size_t data_len;
893
+ astcenc_image* image_out;
894
+ astcenc_swizzle swizzle;
895
+ astcenc_error error;
896
896
};
897
897
898
898
/* *
@@ -903,17 +903,17 @@ struct decompression_workload
903
903
* @param payload The parameters for this thread.
904
904
*/
905
905
static void decompression_workload_runner (int thread_count, int thread_id, void * payload) {
906
- (void )thread_count;
907
-
908
- decompression_workload* work = static_cast <decompression_workload*>(payload);
909
- astcenc_error error = astcenc_decompress_image (work->context , work->data , work->data_len ,
910
- work->image_out , &work->swizzle , thread_id);
911
- // This is a racy update, so which error gets returned is a random, but it
912
- // will reliably report an error if an error occurs
913
- if (error != ASTCENC_SUCCESS)
914
- {
915
- work->error = error;
916
- }
906
+ (void )thread_count;
907
+
908
+ decompression_workload* work = static_cast <decompression_workload*>(payload);
909
+ astcenc_error error = astcenc_decompress_image (work->context , work->data , work->data_len ,
910
+ work->image_out , &work->swizzle , thread_id);
911
+ // This is a racy update, so which error gets returned is a random, but it
912
+ // will reliably report an error if an error occurs
913
+ if (error != ASTCENC_SUCCESS)
914
+ {
915
+ work->error = error;
916
+ }
917
917
}
918
918
919
919
/* *
@@ -925,7 +925,7 @@ static void decompression_workload_runner(int thread_count, int thread_id, void*
925
925
// will update "This" with the uncompressed copy
926
926
KTX_API KTX_error_code KTX_APIENTRY
927
927
ktxTexture2_DecodeAstc (ktxTexture2 *This, ktx_uint32_t vkformat) {
928
- // Decompress This using astc-encoder
928
+ // Decompress This using astc-encoder
929
929
uint32_t * BDB = This->pDfd + 1 ;
930
930
khr_df_model_e colorModel = (khr_df_model_e)KHR_DFDVAL (BDB, MODEL);
931
931
if (colorModel != KHR_DF_MODEL_ASTC && This->supercompressionScheme != KTX_SS_NONE) // No supercompression supported yet
@@ -935,12 +935,12 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) {
935
935
936
936
DECLARE_PRIVATE (priv, This);
937
937
938
- uint32_t channelId = KHR_DFDSVAL (BDB, 0 , CHANNELID);
939
- if (channelId == KHR_DF_CHANNEL_ASTC_DATA) {
940
- // Found astc data
941
- }
942
- else
943
- return KTX_FILE_DATA_ERROR;
938
+ uint32_t channelId = KHR_DFDSVAL (BDB, 0 , CHANNELID);
939
+ if (channelId == KHR_DF_CHANNEL_ASTC_DATA) {
940
+ // Found astc data
941
+ }
942
+ else
943
+ return KTX_FILE_DATA_ERROR;
944
944
945
945
// Create a prototype texture to use for calculating sizes in the target
946
946
// format and, as useful side effects, provide us with a properly sized
@@ -984,7 +984,7 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) {
984
984
}
985
985
}
986
986
987
- // This is where I do the decompression from "This" to prototype target
987
+ // This is where I do the decompression from "This" to prototype target
988
988
astcenc_profile profile{ASTCENC_PRF_LDR_SRGB};
989
989
astcenc_swizzle swizzle{ASTCENC_SWZ_R, ASTCENC_SWZ_G, ASTCENC_SWZ_B, ASTCENC_SWZ_A};
990
990
@@ -994,15 +994,15 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) {
994
994
float quality{ASTCENC_PRE_MEDIUM};
995
995
uint32_t flags{0 }; // TODO: Use normals mode to reconstruct normals params->normalMap ? ASTCENC_FLG_MAP_NORMAL : 0};
996
996
997
- astcBlockDimensions ((VkFormat)vkformat , block_size_x, block_size_y, block_size_z);
997
+ astcBlockDimensions ((VkFormat)This-> vkFormat , block_size_x, block_size_y, block_size_z);
998
998
999
999
// quality = astcQuality(params->qualityLevel);
1000
1000
// profile = astcEncoderAction(*params, BDB);
1001
1001
// swizzle = astcSwizzle(*params);
1002
1002
1003
1003
// if(params->perceptual) flags |= ASTCENC_FLG_USE_PERCEPTUAL;
1004
1004
1005
- uint32_t threadCount{1 }; // Decompression isn't the bottlneck and only used when checking for psnr and ssim
1005
+ uint32_t threadCount{1 }; // Decompression isn't the bottlneck and only used when checking for psnr and ssim
1006
1006
astcenc_config astc_config;
1007
1007
astcenc_context *astc_context;
1008
1008
astcenc_error astc_error = astcenc_config_init (profile,
@@ -1018,69 +1018,69 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) {
1018
1018
if (astc_error != ASTCENC_SUCCESS)
1019
1019
return KTX_INVALID_OPERATION;
1020
1020
1021
- decompression_workload work;
1022
- work.context = astc_context;
1023
- work.swizzle = swizzle;
1024
- work.error = ASTCENC_SUCCESS;
1025
-
1026
- for (uint32_t levelIndex = 0 ; levelIndex < This->numLevels ; ++levelIndex) {
1027
- const uint32_t imageWidth = std::max (This->baseWidth >> levelIndex, 1u );
1028
- const uint32_t imageHeight = std::max (This->baseHeight >> levelIndex, 1u );
1029
- const uint32_t imageDepths = std::max (This->baseDepth >> levelIndex, 1u );
1030
-
1031
- for (uint32_t layerIndex = 0 ; layerIndex < This->numLayers ; ++layerIndex) {
1032
- for (uint32_t faceIndex = 0 ; faceIndex < This->numFaces ; ++faceIndex) {
1033
- for (uint32_t depthSliceIndex = 0 ; depthSliceIndex < imageDepths; ++depthSliceIndex) {
1034
-
1035
- ktx_size_t levelImageSizeIn = ktxTexture_calcImageSize (ktxTexture (This), levelIndex, KTX_FORMAT_VERSION_TWO);
1036
-
1037
- ktx_size_t imageOffsetIn;
1038
- ktx_size_t imageOffsetOut;
1039
-
1040
- ktxTexture2_GetImageOffset (This, levelIndex, layerIndex, faceIndex + depthSliceIndex, &imageOffsetIn);
1041
- ktxTexture2_GetImageOffset (prototype, levelIndex, layerIndex, faceIndex + depthSliceIndex, &imageOffsetOut);
1042
-
1043
- auto * imageDataIn = This->pData + imageOffsetIn;
1044
- auto * imageDataOut = prototype->pData + imageOffsetOut;
1045
-
1046
- astcenc_image imageOut;
1047
- imageOut.dim_x = imageWidth;
1048
- imageOut.dim_y = imageHeight;
1049
- imageOut.dim_z = imageDepths;
1050
- imageOut.data_type = ASTCENC_TYPE_U8; // TODO: Fix for HDR types
1051
- imageOut.data = (void **)&imageDataOut; // TODO: Fix for HDR types
1052
-
1053
- work.data = imageDataIn;
1054
- work.data_len = levelImageSizeIn;
1055
- work.image_out = &imageOut;
1056
-
1057
- // Only launch worker threads for multi-threaded use - it makes basic
1058
- // single-threaded profiling and debugging a little less convoluted
1059
- if (threadCount > 1 ) {
1060
- launchThreads (threadCount, decompression_workload_runner, &work);
1061
- } else {
1062
- work.error = astcenc_decompress_image (work.context , work.data , work.data_len ,
1063
- work.image_out , &work.swizzle , 0 );
1064
- }
1065
-
1066
- // Reset ASTC context for next image
1067
- astcenc_decompress_reset (astc_context);
1068
-
1069
- if (work.error != ASTCENC_SUCCESS) {
1070
- std::cout << " ASTC decompressor failed\n " << astcenc_get_error_string (work.error ) << std::endl;
1071
-
1072
- astcenc_context_free (astc_context);
1073
- return KTX_INVALID_OPERATION;
1074
- }
1075
- }
1076
- }
1077
- }
1078
- }
1021
+ decompression_workload work;
1022
+ work.context = astc_context;
1023
+ work.swizzle = swizzle;
1024
+ work.error = ASTCENC_SUCCESS;
1025
+
1026
+ for (uint32_t levelIndex = 0 ; levelIndex < This->numLevels ; ++levelIndex) {
1027
+ const uint32_t imageWidth = std::max (This->baseWidth >> levelIndex, 1u );
1028
+ const uint32_t imageHeight = std::max (This->baseHeight >> levelIndex, 1u );
1029
+ const uint32_t imageDepths = std::max (This->baseDepth >> levelIndex, 1u );
1030
+
1031
+ for (uint32_t layerIndex = 0 ; layerIndex < This->numLayers ; ++layerIndex) {
1032
+ for (uint32_t faceIndex = 0 ; faceIndex < This->numFaces ; ++faceIndex) {
1033
+ for (uint32_t depthSliceIndex = 0 ; depthSliceIndex < imageDepths; ++depthSliceIndex) {
1034
+
1035
+ ktx_size_t levelImageSizeIn = ktxTexture_calcImageSize (ktxTexture (This), levelIndex, KTX_FORMAT_VERSION_TWO);
1036
+
1037
+ ktx_size_t imageOffsetIn;
1038
+ ktx_size_t imageOffsetOut;
1039
+
1040
+ ktxTexture2_GetImageOffset (This, levelIndex, layerIndex, faceIndex + depthSliceIndex, &imageOffsetIn);
1041
+ ktxTexture2_GetImageOffset (prototype, levelIndex, layerIndex, faceIndex + depthSliceIndex, &imageOffsetOut);
1042
+
1043
+ auto * imageDataIn = This->pData + imageOffsetIn;
1044
+ auto * imageDataOut = prototype->pData + imageOffsetOut;
1045
+
1046
+ astcenc_image imageOut;
1047
+ imageOut.dim_x = imageWidth;
1048
+ imageOut.dim_y = imageHeight;
1049
+ imageOut.dim_z = imageDepths;
1050
+ imageOut.data_type = ASTCENC_TYPE_U8; // TODO: Fix for HDR types
1051
+ imageOut.data = (void **)&imageDataOut; // TODO: Fix for HDR types
1052
+
1053
+ work.data = imageDataIn;
1054
+ work.data_len = levelImageSizeIn;
1055
+ work.image_out = &imageOut;
1056
+
1057
+ // Only launch worker threads for multi-threaded use - it makes basic
1058
+ // single-threaded profiling and debugging a little less convoluted
1059
+ if (threadCount > 1 ) {
1060
+ launchThreads (threadCount, decompression_workload_runner, &work);
1061
+ } else {
1062
+ work.error = astcenc_decompress_image (work.context , work.data , work.data_len ,
1063
+ work.image_out , &work.swizzle , 0 );
1064
+ }
1065
+
1066
+ // Reset ASTC context for next image
1067
+ astcenc_decompress_reset (astc_context);
1068
+
1069
+ if (work.error != ASTCENC_SUCCESS) {
1070
+ std::cout << " ASTC decompressor failed\n " << astcenc_get_error_string (work.error ) << std::endl;
1071
+
1072
+ astcenc_context_free (astc_context);
1073
+ return KTX_INVALID_OPERATION;
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
1079
1080
- // We are done with astcencoder
1080
+ // We are done with astcdecoder
1081
1081
astcenc_context_free (astc_context);
1082
1082
1083
- if (result == KTX_SUCCESS) {
1083
+ if (result == KTX_SUCCESS) {
1084
1084
// Fix up the current texture
1085
1085
DECLARE_PROTECTED (thisPrtctd, This);
1086
1086
DECLARE_PRIVATE (protoPriv, prototype);
0 commit comments