Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions tests/ktxdiff/ktxdiff_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ int EXIT_CODE_MISMATCH = 1;
int EXIT_CODE_MATCH = 0;

template <typename... Args>
void error(int return_code, Args&&... args) {
fmt::print(std::cerr, std::forward<Args>(args)...);
void error(int return_code, fmt::format_string<Args...> fmt, Args&&... args) {
fmt::print(std::cerr, fmt, std::forward<Args>(args)...);
std::exit(return_code);
}

Expand Down Expand Up @@ -354,9 +354,9 @@ bool compare(Texture& lhs, Texture& rhs, float tolerance) {
const bool isFormatSFloat32 = isSigned && isFloat && is32Bit && vkFormat != VK_FORMAT_D32_SFLOAT_S8_UINT;
const bool isFormatUNORM8 = !isSigned && !isFloat && is8Bit && isNormalized;

const auto mismatch = [&](auto&&... args) {
const auto mismatch = [&](const auto& fmt, auto&&... args) {
fmt::print("ktxdiff: ");
fmt::print(std::forward<decltype(args)>(args)...);
fmt::print(fmt::runtime(fmt), std::forward<decltype(args)>(args)...);
fmt::print(" between\n");
fmt::print(" Expected: {} and\n", lhs.filepath);
fmt::print(" Received: {}\n", rhs.filepath);
Expand Down
16 changes: 8 additions & 8 deletions tools/ktx/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,31 @@ struct Reporter {
std::string commandDescription;

template <typename... Args>
void warning(Args&&... args) {
void warning(fmt::format_string<Args...> fmt, Args&&... args) {
fmt::print(std::cerr, "{} warning: ", commandName);
fmt::print(std::cerr, std::forward<Args>(args)...);
fmt::print(std::cerr, fmt, std::forward<Args>(args)...);
fmt::print(std::cerr, "\n");
}

template <typename... Args>
void error(Args&&... args) {
void error(fmt::format_string<Args...> fmt, Args&&... args) {
fmt::print(std::cerr, "{} error: ", commandName);
fmt::print(std::cerr, std::forward<Args>(args)...);
fmt::print(std::cerr, fmt, std::forward<Args>(args)...);
fmt::print(std::cerr, "\n");
}

template <typename... Args>
void fatal(ReturnCode return_code, Args&&... args) {
void fatal(ReturnCode return_code, fmt::format_string<Args...> fmt, Args&&... args) {
fmt::print(std::cerr, "{} fatal: ", commandName);
fmt::print(std::cerr, std::forward<Args>(args)...);
fmt::print(std::cerr, fmt, std::forward<Args>(args)...);
fmt::print(std::cerr, "\n");
throw FatalError(return_code);
}

template <typename... Args>
void fatal_usage(Args&&... args) {
void fatal_usage(fmt::format_string<Args...> fmt, Args&&... args) {
fmt::print(std::cerr, "{} fatal: ", commandName);
fmt::print(std::cerr, std::forward<Args>(args)...);
fmt::print(std::cerr, fmt, std::forward<Args>(args)...);
fmt::print(std::cerr, " See '{} --help'.\n", commandName);
throw FatalError(rc::INVALID_ARGUMENTS);
}
Expand Down
8 changes: 4 additions & 4 deletions tools/ktx/command_compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct DiffHexFixedWidth : public DiffBase<T> {

virtual std::string value(std::size_t index, OutputFormat format) const override {
if (format == OutputFormat::text) {
return fmt::format(fmt::format("0x{{:0{}x}}", sizeof(T) << 1), DiffBase<T>::rawValue(index));
return fmt::format("0x{1:0{0}x}", sizeof(T) << 1, DiffBase<T>::rawValue(index));
} else {
return fmt::format("{}", DiffBase<T>::rawValue(index));
}
Expand Down Expand Up @@ -499,7 +499,7 @@ class PrintDiff {
if (!std::exchange(firstContext, false))
printIndent(0, "\n");
for (const auto& ctx : context)
printIndent(0, ctx);
printIndent(0, fmt::runtime(ctx));
context.clear();
}
}
Expand Down Expand Up @@ -650,9 +650,9 @@ class PrintDiff {

auto formatOptionalFileOffset = [](const std::optional<std::size_t>& fileOffset, std::size_t imageOffset, bool json) {
if (fileOffset.has_value())
return fmt::format(json ? "{}" : "0x{:x}", *fileOffset + imageOffset);
return fmt::format(fmt::runtime(json ? "{}" : "0x{:x}"), *fileOffset + imageOffset);
else
return fmt::format(json ? "null" : "N/A");
return fmt::format(fmt::runtime(json ? "null" : "N/A"));
};

auto formatPacked = [=](const ImageSpan::TexelBlockPtr<>& texelBlock, bool json) {
Expand Down
26 changes: 13 additions & 13 deletions tools/ktx/command_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ struct OptionsCreate {

if (args[kSwizzle].count()) {
swizzle = to_lower_copy(args[kSwizzle].as<std::string>());
const auto errorFmt = "Invalid --swizzle value: \"{}\". The value must match the \"[rgba01]{{4}}\" regex.";
constexpr auto errorFmt = "Invalid --swizzle value: \"{}\". The value must match the \"[rgba01]{{4}}\" regex.";
if (swizzle->size() != 4)
report.fatal_usage(errorFmt, *swizzle);
for (const auto c : *swizzle)
Expand All @@ -516,7 +516,7 @@ struct OptionsCreate {
}
if (args[kInputSwizzle].count()) {
swizzleInput = to_lower_copy(args[kInputSwizzle].as<std::string>());
const auto errorFmt = "Invalid --input-swizzle value: \"{}\". The value must match the \"[rgba01]{{4}}\" regex.";
constexpr auto errorFmt = "Invalid --input-swizzle value: \"{}\". The value must match the \"[rgba01]{{4}}\" regex.";
if (swizzleInput->size() != 4)
report.fatal_usage(errorFmt, *swizzleInput);
for (const auto c : *swizzleInput)
Expand Down Expand Up @@ -766,7 +766,7 @@ struct OptionsCreate {
}

if (formatDesc.transfer() == KHR_DF_TRANSFER_SRGB) {
const auto error_message = "Invalid value \"{}\" to --{} for format \"{}\". Transfer function must be sRGB for sRGB formats.";
constexpr auto error_message = "Invalid value \"{}\" to --{} for format \"{}\". Transfer function must be sRGB for sRGB formats.";
if (!convertTF.has_value() && assignTF.has_value()) {
switch (assignTF.value()) {
case KHR_DF_TRANSFER_UNSPECIFIED:
Expand All @@ -787,7 +787,7 @@ struct OptionsCreate {
report.fatal_usage("Option --{} cannot be used with sRGB formats.", kNormalize);

if (isFormatNotSRGBButHasSRGBVariant(vkFormat)) {
const auto error_message = "Invalid value \"{}\" to --{} for format \"{}\". Transfer function must not be sRGB for a non-sRGB VkFormat with sRGB variant.";
constexpr auto error_message = "Invalid value \"{}\" to --{} for format \"{}\". Transfer function must not be sRGB for a non-sRGB VkFormat with sRGB variant.";
if (!convertTF.has_value() && assignTF.has_value() && assignTF == KHR_DF_TRANSFER_SRGB) {
report.fatal_usage(error_message, args[kAssignTf].count() ? args[kAssignTf].as<std::string>() : args[kAssignOetf].as<std::string>(),
kAssignTf, args[kFormat].as<std::string>());
Expand Down Expand Up @@ -1514,7 +1514,7 @@ std::string CommandCreate::readRawFile(const std::filesystem::path& filepath) {
}

void CommandCreate::executeCreate() {
const auto warningFn = [this](const std::string& w) { this->warning(w); };
const auto warningFn = [this](const std::string& w) { this->warning(fmt::runtime(w)); };

KTXTexture2 texture{nullptr};
targetChannelCount = options.formatDesc.channelCount();
Expand Down Expand Up @@ -1609,7 +1609,7 @@ void CommandCreate::executeCreate() {
const auto maxDimension = std::max(target.width(), std::max(target.height(), baseDepth));
maxLevels = log2(maxDimension) + 1;
if (options.levels.value_or(1) > maxLevels) {
auto errorFmt = "Requested {} levels is too many. With {} {}x{} and depth {} the texture can only have {} levels at most.";
constexpr auto errorFmt = "Requested {} levels is too many. With {} {}x{} and depth {} the texture can only have {} levels at most.";
std::string baseExpl;
if (options.width.has_value() || options.height.has_value()) {
baseExpl = "a requested base image size of";
Expand Down Expand Up @@ -1651,7 +1651,7 @@ void CommandCreate::executeCreate() {
const uint32_t targetImageHeight = std::max(target.height() >> levelIndex, 1u);

if (inputImageFile->spec().width() != expectedImageWidth || inputImageFile->spec().height() != expectedImageHeight) {
const auto errorFmt = "Input image \"{}\" with size {}x{} does not match expected size {}x{} for level {}.";
constexpr auto errorFmt = "Input image \"{}\" with size {}x{} does not match expected size {}x{} for level {}.";
fatal(rc::INVALID_FILE, errorFmt, fmtInFile(inputFilepath),
inputImageFile->spec().width(),
inputImageFile->spec().height(),
Expand All @@ -1669,7 +1669,7 @@ void CommandCreate::executeCreate() {
assert((target.format().primaries() == colorSpaceInfo.src.usedPrimaries
|| colorSpaceInfo.src.usedPrimaries != KHR_DF_PRIMARIES_UNSPECIFIED)
&& "determineSourceColorSpace failed to check for UNSPECIFIED.");
const auto errorFmt = "Colorspace conversion requires unsupported {} {} {}.";
constexpr auto errorFmt = "Colorspace conversion requires unsupported {} {} {}.";
if (colorSpaceInfo.src.transferFunction == nullptr) {
std::string source;
if (options.assignTF.has_value()) {
Expand All @@ -1686,7 +1686,7 @@ void CommandCreate::executeCreate() {
" --{}, with or without --{}, to specify handling.",
options.kAssignTf, options.kConvertTf);
}
fatal(rc::NOT_SUPPORTED, errorMsg);
fatal(rc::NOT_SUPPORTED, fmt::runtime(errorMsg));
}
if (colorSpaceInfo.dst.transferFunction == nullptr) {
// If we get here it is because (a) a transfer supported for decode but not
Expand All @@ -1705,7 +1705,7 @@ void CommandCreate::executeCreate() {
" required to convert primaries to {}.",
toString(target.format().primaries()));
}
fatal(rc::NOT_SUPPORTED, errorMsg);
fatal(rc::NOT_SUPPORTED, fmt::runtime(errorMsg));
}
if (!options.noWarnOnColorConversions) {
if (target.format().model() == KHR_DF_MODEL_RGBSDA
Expand Down Expand Up @@ -1817,7 +1817,7 @@ void CommandCreate::executeCreate() {
//const auto input_error_message = "Input file \"{}\" The transfer function to be applied to the created texture is neither linear nor none. Normalize is only available for these transfer functions.";
//const auto inputTransfer = inputImageFile->spec().format().transfer();
//bool is_file_error = (inputTransfer != KHR_DF_TRANSFER_UNSPECIFIED && inputTransfer != KHR_DF_TRANSFER_LINEAR);
const auto option_error_message = "--{} value is {}. Normalize can only be used if the transfer function is linear or none.";
constexpr auto option_error_message = "--{} value is {}. Normalize can only be used if the transfer function is linear or none.";
if (options.convertTF.has_value()) {
fatal_usage(option_error_message, OptionsCreate::kConvertTf,
toString(options.convertTF.value()));
Expand All @@ -1835,7 +1835,7 @@ void CommandCreate::executeCreate() {

if (options.premultiplyAlpha) {
if(image->getComponentCount() < 4) {
const auto option_error_message = "PremultiplyAlpha can only be used if the input image has alpha channels.";
constexpr auto option_error_message = "PremultiplyAlpha can only be used if the input image has alpha channels.";
fatal_usage(option_error_message, OptionsCreate::kPremultiplyAlpha);
}
image->premultiplyAlpha();
Expand Down Expand Up @@ -2747,7 +2747,7 @@ void CommandCreate::determineSourceColorSpace(const ImageInput& in, SrcColorSpac
} else {
fatal(rc::INVALID_FILE,
"Input file \"{}\" has gamma 0.0f. Use --{} to specify transfer function.",
options.kAssignTf);
in.filename(), options.kAssignTf);
}
} else {
if (!options.convertTF.has_value()) {
Expand Down
6 changes: 3 additions & 3 deletions tools/ktx/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ struct PrintIndent {
int indentWidth = 4;

public:
template <typename Fmt, typename... Args>
inline void operator()(int depth, Fmt&& fmt, Args&&... args) {
template <typename... Args>
inline void operator()(int depth, fmt::format_string<Args...> fmt, Args&&... args) {
fmt::print(os, "{:{}}", "", indentWidth * (indentBase + depth));
fmt::print(os, std::forward<Fmt>(fmt), std::forward<Args>(args)...);
fmt::print(os, fmt, std::forward<Args>(args)...);
}
};

Expand Down
8 changes: 4 additions & 4 deletions tools/ktx/validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,25 @@ struct ValidationContext {
++numWarning;
if (treatWarningsAsError) {
returnCode = +rc::INVALID_FILE;
callback(ValidationReport{IssueType::error, issue.id, std::string{issue.message}, fmt::format(issue.detailsFmt, std::forward<Args>(args)...)});
callback(ValidationReport{IssueType::error, issue.id, std::string{issue.message}, fmt::format(fmt::runtime(issue.detailsFmt), std::forward<Args>(args)...)});

} else {
callback(ValidationReport{issue.type, issue.id, std::string{issue.message}, fmt::format(issue.detailsFmt, std::forward<Args>(args)...)});
callback(ValidationReport{issue.type, issue.id, std::string{issue.message}, fmt::format(fmt::runtime(issue.detailsFmt), std::forward<Args>(args)...)});
}
}

template <typename... Args>
void error(const IssueError& issue, Args&&... args) {
++numError;
returnCode = +rc::INVALID_FILE;
callback(ValidationReport{issue.type, issue.id, std::string{issue.message}, fmt::format(issue.detailsFmt, std::forward<Args>(args)...)});
callback(ValidationReport{issue.type, issue.id, std::string{issue.message}, fmt::format(fmt::runtime(issue.detailsFmt), std::forward<Args>(args)...)});
}

template <typename... Args>
void fatal(const IssueFatal& issue, Args&&... args) {
++numError;
returnCode = +rc::INVALID_FILE;
const auto report = ValidationReport{issue.type, issue.id, std::string{issue.message}, fmt::format(issue.detailsFmt, std::forward<Args>(args)...)};
const auto report = ValidationReport{issue.type, issue.id, std::string{issue.message}, fmt::format(fmt::runtime(issue.detailsFmt), std::forward<Args>(args)...)};
callback(report);

throw FatalValidationError(report);
Expand Down