* @internal * @~English * @brief Check a KTX2 file header. * * As well as checking that the header identifies a KTX 2 file, the function * sanity checks the values and returns information about the texture in a * struct KTX_supplementary_info. * * @param pHeader pointer to the KTX header to check * @param pSuppInfo pointer to a KTX_supplementary_info structure in which to *
| 181 | * @author Mark Callow, HI Corporation |
| 182 | */ |
| 183 | KTX_error_code ktxCheckHeader2_(KTX_header2* pHeader, |
| 184 | KTX_supplemental_info* pSuppInfo) |
| 185 | { |
| 186 | // supp info is compressed, generateMipmaps and num dimensions. Don't need |
| 187 | // compressed as formatSize gives us that. I think the other 2 aren't needed. |
| 188 | ktx_uint8_t identifier_reference[12] = KTX2_IDENTIFIER_REF; |
| 189 | |
| 190 | assert(pHeader != NULL && pSuppInfo != NULL); |
| 191 | ktx_uint32_t max_dim; |
| 192 | |
| 193 | /* Compare identifier, is this a KTX file? */ |
| 194 | if (memcmp(pHeader->identifier, identifier_reference, 12) != 0) |
| 195 | { |
| 196 | return KTX_UNKNOWN_FILE_FORMAT; |
| 197 | } |
| 198 | |
| 199 | /* Check format */ |
| 200 | if (isProhibitedFormat(pHeader->vkFormat)) |
| 201 | { |
| 202 | return KTX_FILE_DATA_ERROR; |
| 203 | } |
| 204 | if (!isValidFormat(pHeader->vkFormat)) |
| 205 | { |
| 206 | return KTX_UNSUPPORTED_FEATURE; |
| 207 | } |
| 208 | if (pHeader->supercompressionScheme == KTX_SS_BASIS_LZ && pHeader->vkFormat != VK_FORMAT_UNDEFINED) |
| 209 | { |
| 210 | return KTX_FILE_DATA_ERROR; |
| 211 | } |
| 212 | |
| 213 | /* Check texture dimensions. KTX files can store 8 types of textures: |
| 214 | 1D, 2D, 3D, cube, and array variants of these. There is currently |
| 215 | no extension for 3D array textures in any 3D API. */ |
| 216 | if ((pHeader->pixelWidth == 0) || |
| 217 | (pHeader->pixelDepth > 0 && pHeader->pixelHeight == 0)) |
| 218 | { |
| 219 | /* texture must have width */ |
| 220 | /* texture must have height if it has depth */ |
| 221 | return KTX_FILE_DATA_ERROR; |
| 222 | } |
| 223 | |
| 224 | if (pHeader->pixelDepth > 0) |
| 225 | { |
| 226 | if (pHeader->layerCount > 0) |
| 227 | { |
| 228 | /* No 3D array textures yet. */ |
| 229 | return KTX_UNSUPPORTED_FEATURE; |
| 230 | } |
| 231 | pSuppInfo->textureDimension = 3; |
| 232 | } |
| 233 | else if (pHeader->pixelHeight > 0) |
| 234 | { |
| 235 | pSuppInfo->textureDimension = 2; |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | pSuppInfo->textureDimension = 1; |
| 240 | } |
no test coverage detected