| 540 | } |
| 541 | |
| 542 | private void FilterPalette16(ShortBuffer palette, int palSize, |
| 543 | ByteBuffer inbuf, ShortBuffer outbuf, |
| 544 | int stride, Rect r) |
| 545 | { |
| 546 | // Indexed color |
| 547 | int x, h = r.height(), w = r.width(), b, pad = stride - w; |
| 548 | ShortBuffer ptr = outbuf.duplicate(); |
| 549 | byte bits; |
| 550 | ByteBuffer srcPtr = inbuf.duplicate(); |
| 551 | if (palSize <= 2) { |
| 552 | // 2-color palette |
| 553 | while (h > 0) { |
| 554 | for (x = 0; x < w / 8; x++) { |
| 555 | bits = srcPtr.get(); |
| 556 | for (b = 7; b >= 0; b--) { |
| 557 | ptr.put(palette.get(bits >> b & 1)); |
| 558 | } |
| 559 | } |
| 560 | if (w % 8 != 0) { |
| 561 | bits = srcPtr.get(); |
| 562 | for (b = 7; b >= 8 - w % 8; b--) { |
| 563 | ptr.put(palette.get(bits >> b & 1)); |
| 564 | } |
| 565 | } |
| 566 | ptr.position(ptr.position() + pad); |
| 567 | h--; |
| 568 | } |
| 569 | } else { |
| 570 | // 256-color palette |
| 571 | while (h > 0) { |
| 572 | int endOfRow = ptr.position() + w; |
| 573 | while (ptr.position() < endOfRow) { |
| 574 | ptr.put(palette.get(srcPtr.get())); |
| 575 | } |
| 576 | ptr.position(ptr.position() + pad); |
| 577 | h--; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | private void FilterPalette32(IntBuffer palette, int palSize, |
| 583 | ByteBuffer inbuf, IntBuffer outbuf, |