* @brief Validate flags. * * @param profile The profile to check. * @param flags The flags to check. * * @return Return @c ASTCENC_SUCCESS if validated, otherwise an error on failure. */
| 291 | * @return Return @c ASTCENC_SUCCESS if validated, otherwise an error on failure. |
| 292 | */ |
| 293 | static astcenc_error validate_flags( |
| 294 | astcenc_profile profile, |
| 295 | unsigned int flags |
| 296 | ) { |
| 297 | // Flags field must not contain any unknown flag bits |
| 298 | unsigned int exMask = ~ASTCENC_ALL_FLAGS; |
| 299 | if (popcount(flags & exMask) != 0) |
| 300 | { |
| 301 | return ASTCENC_ERR_BAD_FLAGS; |
| 302 | } |
| 303 | |
| 304 | // Flags field must only contain at most a single map type |
| 305 | exMask = ASTCENC_FLG_MAP_NORMAL |
| 306 | | ASTCENC_FLG_MAP_RGBM; |
| 307 | if (popcount(flags & exMask) > 1) |
| 308 | { |
| 309 | return ASTCENC_ERR_BAD_FLAGS; |
| 310 | } |
| 311 | |
| 312 | // Decode_unorm8 must only be used with an LDR profile |
| 313 | bool is_unorm8 = flags & ASTCENC_FLG_USE_DECODE_UNORM8; |
| 314 | bool is_hdr = (profile == ASTCENC_PRF_HDR) || (profile == ASTCENC_PRF_HDR_RGB_LDR_A); |
| 315 | if (is_unorm8 && is_hdr) |
| 316 | { |
| 317 | return ASTCENC_ERR_BAD_DECODE_MODE; |
| 318 | } |
| 319 | |
| 320 | return ASTCENC_SUCCESS; |
| 321 | } |
| 322 | |
| 323 | #if !defined(ASTCENC_DECOMPRESS_ONLY) |
| 324 |
no test coverage detected