| 50 | */ |
| 51 | |
| 52 | KTX_error_code ktxCheckHeader1_(KTX_header* pHeader, |
| 53 | KTX_supplemental_info* pSuppInfo) |
| 54 | { |
| 55 | ktx_uint8_t identifier_reference[12] = KTX_IDENTIFIER_REF; |
| 56 | ktx_uint32_t max_dim; |
| 57 | |
| 58 | assert(pHeader != NULL && pSuppInfo != NULL); |
| 59 | |
| 60 | /* Compare identifier, is this a KTX file? */ |
| 61 | if (memcmp(pHeader->identifier, identifier_reference, 12) != 0) |
| 62 | { |
| 63 | return KTX_UNKNOWN_FILE_FORMAT; |
| 64 | } |
| 65 | |
| 66 | if (pHeader->endianness == KTX_ENDIAN_REF_REV) |
| 67 | { |
| 68 | /* Convert endianness of pHeader fields. */ |
| 69 | _ktxSwapEndian32(&pHeader->glType, 12); |
| 70 | |
| 71 | if (pHeader->glTypeSize != 1 && |
| 72 | pHeader->glTypeSize != 2 && |
| 73 | pHeader->glTypeSize != 4) |
| 74 | { |
| 75 | /* Only 8-, 16-, and 32-bit types supported so far. */ |
| 76 | return KTX_FILE_DATA_ERROR; |
| 77 | } |
| 78 | } |
| 79 | else if (pHeader->endianness != KTX_ENDIAN_REF) |
| 80 | { |
| 81 | return KTX_FILE_DATA_ERROR; |
| 82 | } |
| 83 | |
| 84 | /* Check glType and glFormat */ |
| 85 | pSuppInfo->compressed = 0; |
| 86 | if (pHeader->glType == 0 || pHeader->glFormat == 0) |
| 87 | { |
| 88 | if (pHeader->glType + pHeader->glFormat != 0) |
| 89 | { |
| 90 | /* either both or none of glType, glFormat must be zero */ |
| 91 | return KTX_FILE_DATA_ERROR; |
| 92 | } |
| 93 | pSuppInfo->compressed = 1; |
| 94 | } |
| 95 | |
| 96 | if (pHeader->glFormat == pHeader->glInternalformat) { |
| 97 | // glInternalFormat is either unsized (which is no longer and should |
| 98 | // never have been supported by libktx) or glFormat is sized. |
| 99 | return KTX_FILE_DATA_ERROR; |
| 100 | } |
| 101 | |
| 102 | /* Check texture dimensions. KTX files can store 8 types of textures: |
| 103 | 1D, 2D, 3D, cube, and array variants of these. There is currently |
| 104 | no GL extension for 3D array textures. */ |
| 105 | if ((pHeader->pixelWidth == 0) || |
| 106 | (pHeader->pixelDepth > 0 && pHeader->pixelHeight == 0)) |
| 107 | { |
| 108 | /* texture must have width */ |
| 109 | /* texture must have height if it has depth */ |