# Incorrect KTX file structure when use PVRTexLib

**URL:** <https://forums.imgtec.com/t/incorrect-ktx-file-structure-when-use-pvrtexlib/1488>\
**Category:** PowerVR Insider\
**Tags:** pvrtextool\
**Created:** [August 1, 2012, 9:02am UTC](https://forums.imgtec.com/t/incorrect-ktx-file-structure-when-use-pvrtexlib/1488 "2012-08-01T09:02:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oiram-2](https://avatars.discourse-cdn.com/v4/letter/o/54ee81/32.png) [@oiram-2](https://forums.imgtec.com/u/oiram-2)\
**Post date:** [August 1, 2012, 9:02am UTC](https://forums.imgtec.com/t/incorrect-ktx-file-structure-when-use-pvrtexlib/1488/1 "2012-08-01T09:02:23Z")

</div>

Here is the KTX file structure from&nbsp;[http://www.khronos.org/opengles/sdk/tools/KTX/file\_format\_spec](http://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/)

\<pre =“pseudo-code” style="margin-left: 0em; font-size: medium; page-break-inside: avoid; text-align: left; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: thin; border-right-width: thin; border-bottom-width: thin; border-left-width: thin; border-color: initial; -: initial; -attachment: initial; -origin: initial; -clip: initial; padding-top: 0.5em; padding-right: 1em; padding-bottom: 0.5em; padding-left: 1em; min-width: 45em; border-color: initial; line-height: 20px; -webkit-text-size-adjust: none; "\>Byte[12] identifier  
  
UInt32 endianness  
  
UInt32 glType  
  
UInt32 glTypeSize  
  
UInt32 glFormat  
  
Uint32 glInternalFormat  
  
Uint32 glBaseInternalFormat  
  
UInt32 pixelWidth  
  
UInt32 pixelHeight  
  
UInt32 pixelDepth  
  
UInt32 numberOfArrayElements  
  
UInt32 numberOfFaces  
  
UInt32 numberOfMipmapLevels  
  
UInt32 bytesOfKeyValueData  
  
  
  
for each keyValuePair that fits in bytesOfKeyValueData  
  
UInt32 keyAndValueByteSize  
  
Byte keyAndValue[keyAndValueByteSize]  
  
Byte valuePadding[3 - ((keyAndValueByteSize + 3) % 4)]  
  
end  
  
  
  
for each mipmap\_level in numberOfMipmapLevels  
  
UInt32 imageSize;  
  
for each array\_element in numberOfArrayElements  
  
for each face in numberOfFaces  
  
for each z\_slice in pixelDepth  
  
for each row or row\_of\_blocks in pixelHeight  
  
for each pixel or block\_of\_pixels in pixelWidth  
  
Byte data[format-specific-number-of-bytes]\*\*  
  
end  
  
end  
  
end  
  
Byte cubePadding[0-3]  
  
end  
  
end  
  
Byte mipPadding[3 - ((imageSize + 3) % 4)]  
  
end

I found the PVRTexLib save incorrect KTX file that missed “UInt32 imageSize;” before every MIPMaps level compressed pixel data.

Mali GPU Texture Compression Tool is corrected.

Same issue with&nbsp;PVRTexTool GUI/CL.

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forums.imgtec.com/u/tobias)\
**Post date:** [August 1, 2012, 9:20am UTC](https://forums.imgtec.com/t/incorrect-ktx-file-structure-when-use-pvrtexlib/1488/2 "2012-08-01T09:20:34Z")

</div>

Yikes, good catch!  
  
I’m not 100% why this hasn’t been noticed before but I’ll definitely fix this for the next release.  
  
If this is a blocking issue for you, if you email [DevTech@imgtec.com](mailto:DevTech@imgtec.com) I should be able to provide a version with the fix in. Otherwise the next release should be available within the next month or so.  
  
Thanks,  
  
Tobias

---

<div class="post-metadata">

**Author:** ![oiram-2](https://avatars.discourse-cdn.com/v4/letter/o/54ee81/32.png) [@oiram-2](https://forums.imgtec.com/u/oiram-2)\
**Post date:** [August 2, 2012, 1:51am UTC](https://forums.imgtec.com/t/incorrect-ktx-file-structure-when-use-pvrtexlib/1488/3 "2012-08-02T01:51:34Z")

</div>

I’ve mailed you already.

 ![Smile]( "Smile")
