Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with the usage of the --format parameter (v4.3.0-alpha3) #734

Closed
Yason83 opened this issue Jul 10, 2023 · 2 comments
Closed

Issue with the usage of the --format parameter (v4.3.0-alpha3) #734

Yason83 opened this issue Jul 10, 2023 · 2 comments

Comments

@Yason83
Copy link

Yason83 commented Jul 10, 2023

Dear Sir/Madam,

I hope this message finds you well. I am currently facing a challenge regarding the streaming conversion of files to the KTX2 format.

The issue I am encountering is that the input files have different extensions, such as JPG or PNG, and they may or may not have an alpha channel. Additionally, the input files can have either 8-bit or 16-bit depth. In some cases, the files may even be grayscale or grayscale with an alpha channel. Unfortunately, I do not have explicit information about the channels for each file.

When I use the following command for file compression, it works fine for most of my files:
ktx create --format R8G8B8A8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file>

However, other files return an error and fail to convert because the format specified in the command does not match their characteristics.

Is there a way to automatically detect the channels in the files or omit specifying them entirely using the --format parameter? I am aiming to achieve maximum file compression with minimal loss of quality and reduced memory footprint for KTX2 conversion.

I apologize if I have overlooked this information in the documentation. I kindly request your assistance in helping me understand how to address this issue.

Thank you for your support, and I look forward to your response.

Best regards,

@Yason83 Yason83 changed the title Issue with the usage of the --format parameter Issue with the usage of the --format parameter (v4.3.0-alpha3) Jul 10, 2023
@Yason83
Copy link
Author

Yason83 commented Jul 10, 2023

I stumbled upon #726 by accident and thought of a possible workaround for my problem.

Instead of using a single command line, I can write four separate lines like this:

ktx create --format R8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file>
ktx create --format R8G8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file>
ktx create --format R8G8B8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file>
ktx create --format R8G8B8A8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file>

If the number of channels exceeds the expected count, the program will terminate, and I will obtain the desired file as a result.

This solution may appear quite hacky and not very elegant. (-:

@MarkCallow
Copy link
Collaborator

The legacy toktx command automatically chooses the format from the input files. It also supports JPG input. However the heuristic doesn't suit everyone's needs. It gets more difficult to implement and understand with the addition of HDR input from EXR files. For these reasons the new tool requires the user to explicitly specify the desired format.

I'm glad you found a solution. Sorry it is not elegant.

If the number of channels exceeds the expected count, the program will terminate, and I will obtain the desired file as a result.

I don't understand this sentence. ktx create silently discards unused channels so the R8_SRGB command will succeed regardless of the number of channels in the input file. You might want to reverse the order and separate the commands with || so the pipeline will exit when a .ktx2 file is successfully created.

ktx create --format R8G8B8A8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file> || \
ktx create --format R8G8B8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file> || \
ktx create --format R8G8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file> || \
ktx create --format R8_SRGB --encode basis-lz --clevel 5 --qlevel 255 <input file> <output_ktx2 file>

If the input has less than 4 channels, the first command will fail and the second command will be tried, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants