Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f557966
Abstract encode common options
wasimabbas-arm Dec 9, 2023
db37f0d
Removes OptionsCodec because these are all just basis options
wasimabbas-arm Dec 9, 2023
4dc1223
Rename EncodeCodec to BasisCodec in preparation for separating encode…
wasimabbas-arm Dec 9, 2023
f77c969
Finally rename the utils file to basis_utils.h
wasimabbas-arm Dec 9, 2023
ca5113d
Updae cts tests part of rebase
wasimabbas-arm Apr 19, 2024
ac7446a
Rename compress_utils.h to deflate_utils.h
wasimabbas-arm Apr 19, 2024
5a43fdf
Rename OptionsCodec to OptionsBasis
wasimabbas-arm Apr 19, 2024
870f2f9
Fix bug, now the program will use ktxBasisParam's noSSE directly
wasimabbas-arm Apr 19, 2024
844705e
Update cts tests
wasimabbas-arm Apr 22, 2024
5de36e7
Rename encode_utils.h to basis_utils.h in doxygen
wasimabbas-arm Apr 23, 2024
f616910
Put noSSE back into common options
wasimabbas-arm Apr 24, 2024
8475985
Fill codec common options separately for astc and basis in create
wasimabbas-arm Apr 25, 2024
dd12a5e
Further changes related to compress to deflate
wasimabbas-arm Apr 26, 2024
b33f540
Move astc options into astc_encode.h
wasimabbas-arm Apr 29, 2024
4595078
Change options_codec to options_codec_basis after changing it in the …
wasimabbas-arm Apr 29, 2024
3691222
Refactor Option names
wasimabbas-arm Apr 29, 2024
8c6cb1d
Fix build issues
wasimabbas-arm Apr 29, 2024
3bc9bfd
Merge branch 'main' into refactor_common_options
wasimabbas-arm Apr 30, 2024
93f6d1f
Rename validateEncodeCodec to validateBasisCodec
wasimabbas-arm Apr 30, 2024
1018e31
Rename captureCodeOption to captureCommonOption
wasimabbas-arm Apr 30, 2024
cf0617e
Documentation adition for no-sse
wasimabbas-arm May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/ktx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ add_executable(ktxtools
command_info.cpp
command_transcode.cpp
command_validate.cpp
compress_utils.h
encode_utils.h
deflate_utils.h
basis_utils.h
format_descriptor.h
formats.h
fragment_uri.h
Expand Down
140 changes: 140 additions & 0 deletions tools/ktx/astc_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2022-2023 The Khronos Group Inc.
// Copyright 2022-2023 RasterGrid Kft.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "command.h"
#include "utility.h"

#include <thread>

// -------------------------------------------------------------------------------------------------

namespace ktx {

/**
//! [command options_astc_codec]
<dl>
<dt>
ASTC:
</dt>
<dd>
Encode the image data with ASTC compression.
</dd>

<dl>
<dt>\--astc-quality &lt;level&gt;</dt>
<dd>The quality level configures the quality-performance
tradeoff for the compressor; more complete searches of the
search space improve image quality at the expense of
compression time. Default is 'medium'. The quality level can be
set between fastest (0) and exhaustive (100) via the
following fixed quality presets:
<table>
<tr><th>Level </th> <th> Quality </th></tr>
<tr><td>fastest </td> <td>(equivalent to quality = 0) </td></tr>
<tr><td>fast </td> <td>(equivalent to quality = 10) </td></tr>
<tr><td>medium </td> <td>(equivalent to quality = 60) </td></tr>
<tr><td>thorough </td> <td>(equivalent to quality = 98) </td></tr>
<tr><td>exhaustive </td> <td>(equivalent to quality = 100) </td></tr>
/table>
</dd>
<dt>\--astc-perceptual</dt>
<dd>The codec should optimize for perceptual error, instead of
direct RMS error. This aims to improve perceived image quality,
but typically lowers the measured PSNR score. Perceptual
methods are currently only available for normal maps and RGB
color data.</dd>
</dl>

@snippet{doc} ktx/encode_utils_common.h command options_codec_common

</dl>
//! [command options_codec_astc]
*/

struct OptionsASTC : public ktxAstcParams {
inline static const char* kAstcQuality = "astc-quality";
inline static const char* kAstcPerceptual = "astc-perceptual";

inline static const char* kAstcOptions[] = {
kAstcQuality,
kAstcPerceptual
};

std::string astcOptions{};
bool encodeASTC = false;
ClampedOption<ktx_uint32_t> qualityLevel{ktxAstcParams::qualityLevel, 0, KTX_PACK_ASTC_QUALITY_LEVEL_MAX};

OptionsASTC() : ktxAstcParams() {
threadCount = std::thread::hardware_concurrency();
if (threadCount == 0)
threadCount = 1;
structSize = sizeof(ktxAstcParams);
normalMap = false;
for (int i = 0; i < 4; i++)
inputSwizzle[i] = 0;
qualityLevel.clear();
}

void init(cxxopts::Options& opts) {
opts.add_options("Encode ASTC")
(kAstcQuality,
"The quality level configures the quality-performance tradeoff for "
"the compressor; more complete searches of the search space "
"improve image quality at the expense of compression time. Default "
"is 'medium'. The quality level can be set between fastest (0) and "
"exhaustive (100) via the following fixed quality presets:\n\n"
" Level | Quality\n"
" ---------- | -----------------------------\n"
" fastest | (equivalent to quality = 0)\n"
" fast | (equivalent to quality = 10)\n"
" medium | (equivalent to quality = 60)\n"
" thorough | (equivalent to quality = 98)\n"
" exhaustive | (equivalent to quality = 100)",
cxxopts::value<std::string>(), "<level>")
(kAstcPerceptual,
"The codec should optimize for perceptual error, instead of direct "
"RMS error. This aims to improve perceived image quality, but "
"typically lowers the measured PSNR score. Perceptual methods are "
"currently only available for normal maps and RGB color data.");
}

void captureASTCOption(const char* name) {
astcOptions += fmt::format(" --{}", name);
}

template <typename T>
T captureASTCOption(cxxopts::ParseResult& args, const char* name) {
const T value = args[name].as<T>();
astcOptions += fmt::format(" --{} {}", name, value);
return value;
}

void process(cxxopts::Options&, cxxopts::ParseResult& args, Reporter& report) {
if (args[kAstcQuality].count()) {
static std::unordered_map<std::string, ktx_pack_astc_quality_levels_e> astc_quality_mapping{
{"fastest", KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST},
{"fast", KTX_PACK_ASTC_QUALITY_LEVEL_FAST},
{"medium", KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM},
{"thorough", KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH},
{"exhaustive", KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE}
};
const auto qualityLevelStr = to_lower_copy(captureASTCOption<std::string>(args, kAstcQuality));
const auto it = astc_quality_mapping.find(qualityLevelStr);
if (it == astc_quality_mapping.end())
report.fatal_usage("Invalid astc-quality: \"{}\"", qualityLevelStr);
qualityLevel = it->second;
} else {
qualityLevel = KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM;
}

if (args[kAstcPerceptual].count()) {
captureASTCOption(kAstcPerceptual);
perceptual = KTX_TRUE;
}
}
};

} // namespace ktx
Loading