Imagination PowerVR SDK Blog

PVRTexTool major flaws

pvrtextool

#1
  1. The PVRTexTool premultiplies alpha into the rgb channels. I’m encoding single channel textures that happen to have an alpha channel of 0. Even though I set -alpha Image0001.png,a to force alpha=1, but apparently the data has already been lost. This is on OSX. I suspect you’re not passing the correct flags to OSX when you decode the image.

  2. rgb*a,a. 100 x 0,0. <- tool is loading and doing premul

  3. rgb*a/a, a. 000, 0. <- lost the data in conversion back from premul

  4. rgb,1 <- -alpha sets a=1 (but really now 000,1 should be 1001)

Also this will result in lower precision than the original image even for RGB and RGBA images. I don’t have -l on the command line (premul option).

  1. When ASTCMxN,UBN,sRGB mode is used, the colors of my PNG are blown out to super bright (they’re RGB color space). The only thing this should do on an image is set the SRGB_ALPHA version of the ASTC constant into the KTX file. This should have no affect on the imported pixels.

These two bugs make the PVRTexTool unusable for any kind of production work. It’s a very useful tool with a lot of great options. I supposed ImageMagick could be used to force the alpha to 1 before it hits PVRTexTool for the 1/2/3 channel case. That won’t fix data loss in the 4 channel case with alpha that are within 0 to 1.

Since -red/…/-alpha apparently set the value after the premul load, you can use the copied image with alpha set to 1 (to get past premul load), and then use -alpha originalImage.png to set the alpha from the original.


#2

Hi,

can you provide a bit more detail about what you are trying to achieve? Are you converting formats?

bests,
Marton


#3

No, I’m just trying to encode png textures with alpha to ASTC.

  1. PVRTexTool appears to be loading the png image with OSX system libraries with the wrong flags and premultiplying the data, and then unpremulyiplying it. So dilated colors in small alpha regions (f.e. 0) are changed/lost.

PNG is an unpremultiplied format, but textures should be encoded as is regardless. There is a flag to premultiply the texture to knock out pixels in low alpha, but I’m not setting that.

  1. PVRTexTool must be passing -srgb to the ref. astcenc. That doesn’t do what people think, and causes an srgb to linear conversion to occur. That is probably why brightening of the resulting image occurs.

#4

Hi Alec,

Thanks for bringing these to our attention.

For the first issue you mentioned, could you provide the command line arguments you were using and the input files? I’ve tried to reproduce this but I can’t see any alpha pre-multiplication happening.

The second issue is a known bug in PVRTexTool. The problem here is that it always assumes images (PNG, BMP, TGA etc.) are linear RGB, so when you specify sRGB in the format for the output, it does a colour space conversion before transcoding the data.

You could specify lRGB to prevent this conversion, but then you’ll have the wrong ASTC constant in your KTX file.

This is a flaw in PVRTexTool and we aim to fix this in the near future.

Thanks
Lawrence


#5

Hi Lawrence,

Are you testing on OSX for the premul issue? I switched to lRGB already, but then the format constant is wrong as you stated.


#6

Hi Alec,

There is no OS specific code within PVRTexTool itself that would trigger the pre-multiplication. My guess is that it’s happening within one of the image libraries we are using.

Is the input image a PNG file? If you can attach an image file that reproduces the issue that would help greatly.

Lawrence


#7

Hi Lawrence,

I think what I was seeing (now that PVRTexTool works) is is that PVRTexToolGUI displays channels unmultiplied (which looks really wrong with all RGB=white, A8). Xcode displays content premultiplied which is more what you’d expect to see. So in the tool you see the channels, and in Xcode the alpha=0 knocks out the channels (but they’re still there). I could see the channels in PVRTexToolGUI. I’m still seeing the sRGB problem in 2008_R1.

There also are command line options for -cube and -array (or both), but nothing for -volume in the tool. The big difference on volume textures is the interpolation between faces. Often times the volume mips are unused with areas like color grading, since volume mips are their own strange beast. Many renderers may not honor ASTC 3D volumes, which is another problem, and expect a 2D array of ASTC encoded textures.