Returns whether a non-negative integer is a power of 2. */
| 494 | /* Returns whether a non-negative integer is a power of 2. |
| 495 | */ |
| 496 | static int IsPowerOf2(uint32_t x) |
| 497 | { |
| 498 | while(x) |
| 499 | { |
| 500 | /* When we find a bit, return whether no other bits are set. */ |
| 501 | if(x & 1) |
| 502 | return !(x & ~UINT32_C(1)); |
| 503 | x = x >> 1; |
| 504 | } |
| 505 | |
| 506 | /* 0, the only value for x which lands us here, isn't a power of 2. */ |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | /* Returns the byte length of a scan line padded as necessary to be divisible |
| 511 | * by four. For example, 3 pixels wide at 24 bpp would yield 12 (3 pixels * 3 |