| 500 | } |
| 501 | |
| 502 | private void FilterPalette8(ByteBuffer palette, int palSize, |
| 503 | ByteBuffer inbuf, ByteBuffer outbuf, |
| 504 | int stride, Rect r) |
| 505 | { |
| 506 | // Indexed color |
| 507 | int x, h = r.height(), w = r.width(), b, pad = stride - w; |
| 508 | ByteBuffer ptr = outbuf.duplicate(); |
| 509 | byte bits; |
| 510 | ByteBuffer srcPtr = inbuf.duplicate(); |
| 511 | if (palSize <= 2) { |
| 512 | // 2-color palette |
| 513 | while (h > 0) { |
| 514 | for (x = 0; x < w / 8; x++) { |
| 515 | bits = srcPtr.get(); |
| 516 | for (b = 7; b >= 0; b--) { |
| 517 | ptr.put(palette.get(bits >> b & 1)); |
| 518 | } |
| 519 | } |
| 520 | if (w % 8 != 0) { |
| 521 | bits = srcPtr.get(); |
| 522 | for (b = 7; b >= 8 - w % 8; b--) { |
| 523 | ptr.put(palette.get(bits >> b & 1)); |
| 524 | } |
| 525 | } |
| 526 | ptr.position(ptr.position() + pad); |
| 527 | h--; |
| 528 | } |
| 529 | } else { |
| 530 | // 256-color palette |
| 531 | while (h > 0) { |
| 532 | int endOfRow = ptr.position() + w; |
| 533 | while (ptr.position() < endOfRow) { |
| 534 | ptr.put(palette.get(srcPtr.get())); |
| 535 | } |
| 536 | ptr.position(ptr.position() + pad); |
| 537 | h--; |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | private void FilterPalette16(ShortBuffer palette, int palSize, |
| 543 | ByteBuffer inbuf, ShortBuffer outbuf, |