Skip to content

Commit

Permalink
Update metrics stderr messages and add metrics to command create enco…
Browse files Browse the repository at this point in the history
…de astc method
  • Loading branch information
wasimabbas-arm committed Nov 20, 2024
1 parent a0405a0 commit 15ba0e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 11 additions & 4 deletions tools/ktx/command_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,15 +874,17 @@ void CommandCreate::processOptions(cxxopts::Options& opts, cxxopts::ParseResult&
}
}

const auto canCompare = options.codec == BasisCodec::BasisLZ || options.codec == BasisCodec::UASTC;
const auto basisCodec = options.codec == BasisCodec::BasisLZ || options.codec == BasisCodec::UASTC;
const auto astcCodec = isFormatAstc(options.vkFormat);
const auto canCompare = basisCodec || astcCodec;

if (canCompare)
if (basisCodec)
fillOptionsCodecBasis<decltype(options)>(options);

if (options.compare_ssim && !canCompare)
fatal_usage("--compare-ssim can only be used with BasisLZ or UASTC encoding.");
fatal_usage("--compare-ssim can only be used with BasisLZ, UASTC or ASTC encoding.");
if (options.compare_psnr && !canCompare)
fatal_usage("--compare-psnr can only be used with BasisLZ or UASTC encoding.");
fatal_usage("--compare-psnr can only be used with BasisLZ, UASTC or ASTC encoding.");

if (isFormatAstc(options.vkFormat) && !options.raw) {
options.encodeASTC = true;
Expand Down Expand Up @@ -1226,11 +1228,16 @@ void CommandCreate::encodeBasis(KTXTexture2& texture, OptionsEncodeBasis<false>&
}

void CommandCreate::encodeASTC(KTXTexture2& texture, OptionsEncodeASTC& opts) {
MetricsCalculator metrics;
metrics.saveReferenceImages(texture, options, *this);

if (opts.encodeASTC) {
const auto ret = ktxTexture2_CompressAstcEx(texture, &opts);
if (ret != KTX_SUCCESS)
fatal(rc::KTX_FAILURE, "Failed to encode KTX2 file with codec ASTC. KTX Error: {}", ktxErrorString(ret));
}

metrics.decodeAndCalculateMetrics(texture, options, *this);
}

void CommandCreate::compress(KTXTexture2& texture, const OptionsDeflate& opts) {
Expand Down
9 changes: 6 additions & 3 deletions tools/ktx/command_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,14 @@ void CommandEncode::processOptions(cxxopts::Options& opts, cxxopts::ParseResult&
fatal_usage("Cannot encode to BasisLZ and supercompress with ZLIB.");
}

const auto canCompare = options.codec == BasisCodec::BasisLZ || options.codec == BasisCodec::UASTC;
const auto basisCodec = options.codec == BasisCodec::BasisLZ || options.codec == BasisCodec::UASTC;
const auto astcCodec = isFormatAstc(options.vkFormat);
const auto canCompare = basisCodec || astcCodec;

if (options.compare_ssim && !canCompare)
fatal_usage("--compare-ssim can only be used with BasisLZ or UASTC encoding.");
fatal_usage("--compare-ssim can only be used with BasisLZ, UASTC or ASTC encoding.");
if (options.compare_psnr && !canCompare)
fatal_usage("--compare-psnr can only be used with BasisLZ or UASTC encoding.");
fatal_usage("--compare-psnr can only be used with BasisLZ, UASTC or ASTC encoding.");
}

void CommandEncode::executeEncode() {
Expand Down

0 comments on commit 15ba0e6

Please sign in to comment.