Too large ktx file is generated

Hi. I’m trying to create a ktx file with a cube map.
I have 6 jpg images, each one is 2048x2048 pixels. Their total size is less than 5 megabytes.
I create the ktx file using toktx tool:
toktx.exe --cubemap cubemap.ktx posx.jpg negx.jpg posy.jpg negy.jpg posz.jpg negz.jpg
However, I get a cubemap.ktx file that is 72 megabytes in size.
What goes wrong?

ktxinfo.exe output:

Header

identifier: «KTX 11»\r\n\x1A\n
endianness: 0x4030201
glType: 0x1401
glTypeSize: 1
glFormat: 0x1907
glInternalformat: 0x8c41
glBaseInternalformat: 0x1907
pixelWidth: 2048
pixelHeight: 2048
pixelDepth: 0
numberOfArrayElements: 0
numberOfFaces: 6
numberOfMipLevels: 1
bytesOfKeyValueData: 28

Key/Value Data

KTXorientation: S=r,T=d

Data Sizes (bytes)
------------------
Level 0: 75497472

Total: 75497472

Number of pixels at 3 bytes per pixel: 2048 * 2048 * 6 * 3 = 25165824 * 3 = 75497472, so that looks like the expected size for uncompressed image data.
JPEG is of course a lossy compressed file format, so it is not surprising that the input files are smaller. You could use a compressed texture format (depends on which ones are supported by your graphics hardware) and -encode command line option for toktx.

1 Like

If you switch to KTX v2.0, you can use one of the universal formats: ETC1S/BasisLZ or UASTC. These are transcodable to whatever format your hardware supports. If you choose UASTC you can use the --uastc_rdo_l and --zcmp options to reduce the size still further. --uastc_rdo_l causes a small loss in quality but improves the effect of the lossless --zcmp step. (RDO means rate-distortion optimization). You can use --zcmp on images in any format including uncompressed images. Note though that it only affects the file/transmission size. The images have to be inflated to their pre-zcmp size before uploading to a graphics API.