KTX to PNG is not working

Hi, I’m trying to convert a KTX image to the PNG format with the PVRTexTool. When I use the GUI tool, open up the KTX file, and click save as image, the image is converted perfectly. However, this is too slow. I have thousands of KTX images to convert to PNG and so I turned to the PVRTexToolCLI. Except, it seems as though the CLI doesn’t work for some KTXs.

For example when I run this command,
PVRTexToolCLI -i input.ktx -d output.png -f r8g8b8a8
I get the error
Error: Unable to save texture as requested format, please check the format being used is supported.

Am I doing this wrong somehow? Is this a new bug?

Hi ktxtopng,

Could you please indicate what PVRTexTool version are you using and attach a .ktx file generating the error?

Best regards,

Sure. I’m using:

PVRTexToolCL version 4.24
SDK Version: 20.1@5740574
PVRTexLib 4.24 | JpegLib version 8`10CPVRJpegIO |  libpng version 1.6.37 - April 14, 2019

and here’s a sample KTX.


I’ve tried the same command with the attached .ktx file with the same PVRTexToolCLI version (v4.24.0 Build 20.1@5740574) but it works fine for me.

Could you specify what OS are you on? It might be an OS dependant issue.

In case you’re on Windows, I can give you the latest internal PVRTexTool version. I tried and works fine as well, it might be a bug already fixed. I’d give you this version through support (I can see you also submitted a ticket in https://pvrsupport.imgtec.com).

Best regards,

I’m on macOS 10.15.6 (19G73). I’ll try to reinstall and see if anything changes. Do you have a macOS version of the internal version?

I reinstalled the package and it’s finally outputting the PNG. Except, the PNG has black where alpha should be. The PNG outputted from the GUI doesn’t have this problem though. Did you have this issue when decompressing my KTX?

Hi ktxtopng,

I had the same issue you’re describing.

The Tools team verified this issue is fixed in the internal version. I already answered the ticket you sent through our support web (https://pvrsupport.imgtec.com) with instructions for downloading the lastest MacOS internal version.

Please let me know if you experience any other issues.

Best regards,

It works perfectly now, thank you for all the help.

Actually, I spoke too soon. It looks like the color is still off. Here’s the intended PNG generated by the old version of the GUI and here’s the PNG generated by the internal version of the CLI. The GUI PNG also looks like the KTX when viewed by the Preview default application on macOS.

Hi ktxtopng,

After reviewing with the Tools Team, this issue is due to linear and sRGB color space differences. PVRTexTool 4.24 shows images without any gamma correction as the Preview default application on MacOS does. The Internal Version CLI applies gamma correction to the results, and also the Internal Version GUI now applies gamma correction to preview images, giving place to a brighter preview. Apologies for all the confusion.

Best regards,

I figured that might be the situation. In that case, I think I have found another bug for you. I can’t seem to change the format to lRGB with the Internal CLI. For example, this command produces the same sRGB PNG as before.
PVRTexToolCLI -i input.ktx -d output.png -f r8g8b8a8,UBN,lRGB

Hi ktxtopng,

After consulting with the Tools Team, in the command “-i input.ktx -d output.png -f FRMT”:

  • The “-d” part of the command means decompress and implies saving the texture to an image file like PNG, JPG or BMP, which generally expect RGBA8888 and sRGB colour space.

  • The “-f FRMT” part transcodes the input to format FRMT before being saved.

However image files like PNG are always transcoded to RGBA8888 sRGB before being saved (you’d need a different container like .pvr or .ktx to store the texture in its native format). This means that -f r8g8b8a8, -f r8g8b8a8,UBN,lRGB and -f r8g8b8a8,UBN,sRGB produce the same PNG file.

You can use the -ics “input color space” parameter available for the Internal Version. It will force CLI to treat input texture as sRGB. Combined with the format option, no colour space conversion will be done when saving to PNG, producing the results you expect: PVRTexToolCLI -i input.ktx -ics sRGB -d linear.png -f r8g8b8a8,UBN,sRGB

Best regards,

having the same problem with the black alpha layer using PVRTexToolCL version 4.24 / SDK Version: 20.1@5740574 on linux

But i also noticed that:

  1. my output files never have a dot. output is like wantednamepng
  2. the wanted output format is not respected and instead always saved as BMP

I am using it like this: PVRTexToolCLI -i test.ktx -d demo.png -f r8g8b8a8

and getting a BMP named demopng

are theses problems known with this version and fixed in the next?

Hi grain,

Yes, those problems are known and were fixed some time ago in our internal version.

Please raise a ticket in our customer’s support area (https://pvrsupport.imgtec.com/) so I can provide you with a internal version.

Best regards,

© Imagination Technologies Limited. All rights reserved.
Privacy PolicyTerms & ConditionsTrademarksCookies