OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTextureCompressor.h" | 8 #include "SkTextureCompressor.h" |
9 #include "SkTextureCompressor_Blitter.h" | 9 #include "SkTextureCompressor_Blitter.h" |
10 | 10 |
| 11 #include "SkBlitter.h" |
11 #include "SkEndian.h" | 12 #include "SkEndian.h" |
12 | 13 |
13 // #define COMPRESS_R11_EAC_SLOW 1 | 14 // #define COMPRESS_R11_EAC_SLOW 1 |
14 // #define COMPRESS_R11_EAC_FAST 1 | 15 // #define COMPRESS_R11_EAC_FAST 1 |
15 #define COMPRESS_R11_EAC_FASTEST 1 | 16 #define COMPRESS_R11_EAC_FASTEST 1 |
16 | 17 |
17 // Blocks compressed into R11 EAC are represented as follows: | 18 // Blocks compressed into R11 EAC are represented as follows: |
18 // 0000000000000000000000000000000000000000000000000000000000000000 | 19 // 0000000000000000000000000000000000000000000000000000000000000000 |
19 // |base_cw|mod|mul| ----------------- indices ------------------- | 20 // |base_cw|mod|mul| ----------------- indices ------------------- |
20 // | 21 // |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 602 |
602 #elif COMPRESS_R11_EAC_FASTEST | 603 #elif COMPRESS_R11_EAC_FASTEST |
603 | 604 |
604 return compress_a8_to_r11eac_fast(dst, src, width, height, rowBytes); | 605 return compress_a8_to_r11eac_fast(dst, src, width, height, rowBytes); |
605 | 606 |
606 #else | 607 #else |
607 #error "Must choose R11 EAC algorithm" | 608 #error "Must choose R11 EAC algorithm" |
608 #endif | 609 #endif |
609 } | 610 } |
610 | 611 |
611 SkBlitter* CreateR11EACBlitter(int width, int height, void* outputBuffer) { | 612 SkBlitter* CreateR11EACBlitter(int width, int height, void* outputBuffer, |
612 return new | 613 SkTBlitterAllocator* allocator) { |
613 SkTCompressedAlphaBlitter<4, 8, compress_block_vertical> | 614 |
| 615 if ((width % 4) != 0 || (height % 4) != 0) { |
| 616 return NULL; |
| 617 } |
| 618 |
| 619 // Memset the output buffer to an encoding that decodes to zero. We must do
this |
| 620 // in order to avoid having uninitialized values in the buffer if the blitte
r |
| 621 // decides not to write certain scanlines (and skip entire rows of blocks). |
| 622 // In the case of R11, we use the encoding from recognizing all zero pixels
from above. |
| 623 const int nBlocks = (width * height / 16); // 4x4 pixel blocks. |
| 624 uint64_t *dst = reinterpret_cast<uint64_t *>(outputBuffer); |
| 625 for (int i = 0; i < nBlocks; ++i) { |
| 626 *dst = 0x0020000000002000ULL; |
| 627 ++dst; |
| 628 } |
| 629 |
| 630 return allocator->createT< |
| 631 SkTCompressedAlphaBlitter<4, 8, compress_block_vertical>, int, int, void
*> |
614 (width, height, outputBuffer); | 632 (width, height, outputBuffer); |
615 } | 633 } |
616 | 634 |
617 void DecompressR11EAC(uint8_t* dst, int dstRowBytes, const uint8_t* src, int wid
th, int height) { | 635 void DecompressR11EAC(uint8_t* dst, int dstRowBytes, const uint8_t* src, int wid
th, int height) { |
618 for (int j = 0; j < height; j += 4) { | 636 for (int j = 0; j < height; j += 4) { |
619 for (int i = 0; i < width; i += 4) { | 637 for (int i = 0; i < width; i += 4) { |
620 decompress_r11_eac_block(dst + i, dstRowBytes, src); | 638 decompress_r11_eac_block(dst + i, dstRowBytes, src); |
621 src += 8; | 639 src += 8; |
622 } | 640 } |
623 dst += 4 * dstRowBytes; | 641 dst += 4 * dstRowBytes; |
624 } | 642 } |
625 } | 643 } |
626 | 644 |
627 } // namespace SkTextureCompressor | 645 } // namespace SkTextureCompressor |
OLD | NEW |