Skip to content

Commit ae46489

Browse files
Add more comprehensive fatal error message for normalise option
1 parent 3e36822 commit ae46489

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tools/ktx/command_create.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,10 +1352,21 @@ void CommandCreate::executeCreate() {
13521352

13531353
if (options.normalize) {
13541354
if (target.format().transfer() != KHR_DF_TRANSFER_UNSPECIFIED && target.format().transfer() != KHR_DF_TRANSFER_LINEAR) {
1355-
fatal(rc::INVALID_FILE,
1356-
"Input file \"{}\" The transfer function to be applied to the created texture is neither linear nor none. Normalize is only available for linear images. "
1357-
"Use or modify \"{}\" or \"{}\" settings to assign the transfer function or convert the input image to linear, if required.",
1358-
fmtInFile(inputFilepath), OptionsCreate::kAssignOetf, OptionsCreate::kConvertOetf);
1355+
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.";
1356+
const auto assign_error_message = "Input file \"{}\" Use \"{}\" to assign the linear transfer function to the input image, if required.";
1357+
const auto convert_error_message = "Input file \"{}\" Modify \"{}\" settings to convert the input image to linear transfer function, if required.";
1358+
const auto inputTransfer = inputImageFile->spec().format().transfer();
1359+
bool is_file_error = (inputTransfer != KHR_DF_TRANSFER_UNSPECIFIED && inputTransfer != KHR_DF_TRANSFER_LINEAR);
1360+
bool is_assign_error = !options.assignOETF.has_value();
1361+
bool is_convert_error = !options.convertOETF.has_value();
1362+
if (is_assign_error)
1363+
fatal(rc::INVALID_FILE, assign_error_message, fmtInFile(inputFilepath), OptionsCreate::kAssignOetf);
1364+
else if (is_convert_error)
1365+
fatal(rc::INVALID_FILE, convert_error_message, fmtInFile(inputFilepath), OptionsCreate::kConvertOetf);
1366+
else {
1367+
assert(is_file_error && "In this branch it must be the input file that has the transfre function issue"); (void)is_file_error;
1368+
fatal(rc::INVALID_FILE, input_error_message, fmtInFile(inputFilepath));
1369+
}
13591370
}
13601371
image->normalize();
13611372
}

0 commit comments

Comments
 (0)