| 418 | } |
| 419 | |
| 420 | static unsigned |
| 421 | interlace_incr(unsigned y, unsigned height) |
| 422 | { |
| 423 | static const unsigned char incr[] = { 8, 2, 4, 2 }; |
| 424 | |
| 425 | /* The lower three bits indicate the current pass */ |
| 426 | |
| 427 | /* Advance to the next row of the current pass */ |
| 428 | y += incr[y & 0x3]; |
| 429 | |
| 430 | /* Go to the next pass if y exceeds height */ |
| 431 | /* Might not be the immediately following pass if height is small */ |
| 432 | if (y >= height && (y & 0x7) == 0) { |
| 433 | /* Pass 1 -> Pass 2 */ |
| 434 | y = 4; |
| 435 | } |
| 436 | if (y >= height && (y & 0x7) == 4) { |
| 437 | /* Pass 2 -> Pass 3 */ |
| 438 | y = 2; |
| 439 | } |
| 440 | if (y >= height && (y & 0x3) == 2) { |
| 441 | /* Pass 3 -> Pass 4 */ |
| 442 | y = 1; |
| 443 | } |
| 444 | |
| 445 | return y; |
| 446 | } |
| 447 | |
| 448 | /* Decode an unsigned 16 bit quantity */ |
| 449 | static unsigned short |