MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / validateHeader

Method validateHeader

tools/ktx2check/ktx2check.cpp:1228–1392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1226}
1227
1228void
1229ktxValidator::validateHeader(validationContext& ctx)
1230{
1231 ktx_uint8_t identifier_reference[12] = KTX2_IDENTIFIER_REF;
1232 ktx_uint32_t max_dim;
1233
1234 ctx.inp->read((char *)&ctx.header, sizeof(KTX_header2));
1235 if (ctx.inp->fail())
1236 addIssue(logger::eFatal, IOError.FileRead, strerror(errno));
1237 else if (ctx.inp->eof())
1238 addIssue(logger::eFatal, IOError.UnexpectedEOF);
1239
1240 // Is this a KTX2 file?
1241 if (memcmp(&ctx.header.identifier, identifier_reference, 12) != 0) {
1242 addIssue(logger::eFatal, FileError.NotKTX2);
1243 }
1244
1245 if (isProhibitedFormat((VkFormat)ctx.header.vkFormat))
1246 addIssue(logger::eError, HeaderData.ProhibitedFormat);
1247
1248 if (!isValidFormat((VkFormat)ctx.header.vkFormat)) {
1249 if (ctx.header.vkFormat <= VK_FORMAT_MAX_STANDARD_ENUM || ctx.header.vkFormat > 0x10010000)
1250 addIssue(logger::eError, HeaderData.InvalidFormat, ctx.header.vkFormat);
1251 else
1252 addIssue(logger::eError, HeaderData.UnknownFormat, ctx.header.vkFormat);
1253 }
1254
1255 /* Check texture dimensions. KTX files can store 8 types of textures:
1256 1D, 2D, 3D, cube, and array variants of these. There is currently
1257 no extension for 3D array textures in any 3D API. */
1258 if (ctx.header.pixelWidth == 0)
1259 addIssue(logger::eError, HeaderData.WidthZero);
1260
1261 if (ctx.header.pixelDepth > 0 && ctx.header.pixelHeight == 0)
1262 addIssue(logger::eError, HeaderData.DepthNoHeight);
1263
1264 if (ctx.header.pixelDepth > 0)
1265 {
1266 if (ctx.header.layerCount > 0) {
1267 /* No 3D array textures yet. */
1268 addIssue(logger::eWarning, HeaderData.ThreeDArray);
1269 } else
1270 ctx.dimensionCount = 3;
1271 }
1272 else if (ctx.header.pixelHeight > 0)
1273 {
1274 ctx.dimensionCount = 2;
1275 }
1276 else
1277 {
1278 ctx.dimensionCount = 1;
1279 }
1280
1281 if (ctx.header.faceCount == 6)
1282 {
1283 if (ctx.dimensionCount != 2)
1284 {
1285 /* cube map needs 2D faces */

Callers

nothing calls this directly

Calls 7

isProhibitedFormatFunction · 0.85
isValidFormatFunction · 0.85
vkFormatStringFunction · 0.85
padnFunction · 0.85
createDfd4FormatMethod · 0.80
extractFormatInfoMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected