Turns a single mask component into a bitfield. Returns 0 if the bitmask was * invalid, or nonzero if it's ok. Span of 0 means the bitmask was absent. */
| 330 | * invalid, or nonzero if it's ok. Span of 0 means the bitmask was absent. |
| 331 | */ |
| 332 | static int ParseBitfield(bitfield * field, uint32_t mask) |
| 333 | { |
| 334 | uint32_t bit; |
| 335 | for(bit = 0; bit < 32 && !(mask & (UINT32_C(1) << bit)); bit++) |
| 336 | ; |
| 337 | |
| 338 | if(bit >= 32) |
| 339 | { |
| 340 | /* Absent bitmasks are valid. */ |
| 341 | field->start = field->span = 0; |
| 342 | return 1; |
| 343 | } |
| 344 | |
| 345 | field->start = bit; |
| 346 | for(; bit < 32 && (mask & (UINT32_C(1) << bit)); bit++) |
| 347 | ; |
| 348 | field->span = bit - field->start; |
| 349 | |
| 350 | /* If there are more set bits, there was a gap, which is invalid. */ |
| 351 | if(bit < 32 && (mask & ~((UINT32_C(1) << bit) - 1))) return 0; |
| 352 | |
| 353 | return 1; |
| 354 | } |
| 355 | |
| 356 | /* A single color entry in the palette, in file order (BGR + one unused byte). |
| 357 | */ |