Imagination PowerVR SDK Blog

BUG: PowerVR Texture Tool KTX Export Error


#1

Dear PowerVR,

your texture tool is amazing, but i have found a bug. When u export a KTX file, in certain cases, it has wrong imageSize. The export image bytes are correct, but the imageSize parameter is not. This is a serious problem, couz my ktx loader implementation relie on this parameter (also severel others like PicoPixel). But good news, it is easy to fix.

KTX File Format Specification says:

imageSize is the number of bytes of pixel data in the current LOD level. This includes all z slices, all faces, all rows (or rows of blocks) and all pixels (or blocks) in each row for the mipmap level
also says:
Uncompressed texture data matches a GL_UNPACK_ALIGNMENT of 4
.

So let count together: I have an 2x2 GL_RGB GL_UNSIGNED_BYTE image (mipmap level). Your implementation returns 12 for imageSize. This is wrong! U have to include the padding on scanline. Becouse the first row of byte are (RGBRGB) 6bytes long, but u shold round that up to 8 bytes (UNPACK_ALIGNMENT). Correct way to calculate imageSize is (SOLUTION):



uint bpp=8; //the size of the pixel in bits;

uint width=2; //the width of the image (or mipmap level)

uint height=2; //the height of the image (or mipmap level)

uint scanlineSize=bppwidth/8; //its 6

scanlineSize+=3-(scanlineSize+3)%4; //round up to 4 byte boundary! so its 8

uint imageSize=scanlineSize
height;



Plz fix your code, i woud like to avoid crashes and recalculation of this parameter. (Even picopixel crashes)

Thank You:

collerblade

#2

Forget to mention: The image bytes are correct! So there is no need to change that! Only the imageSize parameter is wrong!


#3

Thank you for your feedback, I’ve filed a bug report on our internal tracker (BRN52842).



Look out for the BRN number in future release notes.



Thanks,

Paul.


#4

Thank You!



A minor modification:

Bpp is actually 24bit i was mistaken.



uint bpp=24; //the size of the pixel in bits;

uint width=2; //the width of the image (or mipmap level)

uint height=2; //the height of the image (or mipmap level)

uint scanlineSize=bppwidth/8; //its 6

scanlineSize+=3-(scanlineSize+3)%4; //round up to 4 byte boundary! so its 8

uint imageSize=scanlineSize
height;




Also the editor crashes, while tries to open the “rgb-mipmap-reference.ktx” file. This file is a reference ktx file.



Collerblade


#5

Thank you again for your feedback.



I’ve filed a bug report for the KTX reference file open failure on our internal tracker (BRN52880).



Thanks,

Paul.