Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: src/utils/SkTextureCompressor_R11EAC.cpp

Issue 432503002: Add initial pipeline for decompressors (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 11 matching lines...) Expand all
22 // clamp[0, 2047](base_cw * 8 + 4 + mod_val*mul*8) 22 // clamp[0, 2047](base_cw * 8 + 4 + mod_val*mul*8)
23 // 23 //
24 // mod_val is chosen from a palette of values based on the index of the 24 // mod_val is chosen from a palette of values based on the index of the
25 // given pixel. The palette is chosen by the value stored in mod. 25 // given pixel. The palette is chosen by the value stored in mod.
26 // This formula returns a value between 0 and 2047, which is converted 26 // This formula returns a value between 0 and 2047, which is converted
27 // to a float from 0 to 1 in OpenGL. 27 // to a float from 0 to 1 in OpenGL.
28 // 28 //
29 // If mul is zero, then we set mul = 1/8, so that the formula becomes 29 // If mul is zero, then we set mul = 1/8, so that the formula becomes
30 // clamp[0, 2047](base_cw * 8 + 4 + mod_val) 30 // clamp[0, 2047](base_cw * 8 + 4 + mod_val)
31 31
32 #if COMPRESS_R11_EAC_SLOW
33
34 static const int kNumR11EACPalettes = 16; 32 static const int kNumR11EACPalettes = 16;
35 static const int kR11EACPaletteSize = 8; 33 static const int kR11EACPaletteSize = 8;
36 static const int kR11EACModifierPalettes[kNumR11EACPalettes][kR11EACPaletteSize] = { 34 static const int kR11EACModifierPalettes[kNumR11EACPalettes][kR11EACPaletteSize] = {
37 {-3, -6, -9, -15, 2, 5, 8, 14}, 35 {-3, -6, -9, -15, 2, 5, 8, 14},
38 {-3, -7, -10, -13, 2, 6, 9, 12}, 36 {-3, -7, -10, -13, 2, 6, 9, 12},
39 {-2, -5, -8, -13, 1, 4, 7, 12}, 37 {-2, -5, -8, -13, 1, 4, 7, 12},
40 {-2, -4, -6, -13, 1, 3, 5, 12}, 38 {-2, -4, -6, -13, 1, 3, 5, 12},
41 {-3, -6, -8, -12, 2, 5, 7, 11}, 39 {-3, -6, -8, -12, 2, 5, 7, 11},
42 {-3, -7, -9, -11, 2, 6, 8, 10}, 40 {-3, -7, -9, -11, 2, 6, 8, 10},
43 {-4, -7, -8, -11, 3, 6, 7, 10}, 41 {-4, -7, -8, -11, 3, 6, 7, 10},
44 {-3, -5, -8, -11, 2, 4, 7, 10}, 42 {-3, -5, -8, -11, 2, 4, 7, 10},
45 {-2, -6, -8, -10, 1, 5, 7, 9}, 43 {-2, -6, -8, -10, 1, 5, 7, 9},
46 {-2, -5, -8, -10, 1, 4, 7, 9}, 44 {-2, -5, -8, -10, 1, 4, 7, 9},
47 {-2, -4, -8, -10, 1, 3, 7, 9}, 45 {-2, -4, -8, -10, 1, 3, 7, 9},
48 {-2, -5, -7, -10, 1, 4, 6, 9}, 46 {-2, -5, -7, -10, 1, 4, 6, 9},
49 {-3, -4, -7, -10, 2, 3, 6, 9}, 47 {-3, -4, -7, -10, 2, 3, 6, 9},
50 {-1, -2, -3, -10, 0, 1, 2, 9}, 48 {-1, -2, -3, -10, 0, 1, 2, 9},
51 {-4, -6, -8, -9, 3, 5, 7, 8}, 49 {-4, -6, -8, -9, 3, 5, 7, 8},
52 {-3, -5, -7, -9, 2, 4, 6, 8} 50 {-3, -5, -7, -9, 2, 4, 6, 8}
53 }; 51 };
54 52
53 #if COMPRESS_R11_EAC_SLOW
54
55 // Pack the base codeword, palette, and multiplier into the 64 bits necessary 55 // Pack the base codeword, palette, and multiplier into the 64 bits necessary
56 // to decode it. 56 // to decode it.
57 static uint64_t pack_r11eac_block(uint16_t base_cw, uint16_t palette, uint16_t m ultiplier, 57 static uint64_t pack_r11eac_block(uint16_t base_cw, uint16_t palette, uint16_t m ultiplier,
58 uint64_t indices) { 58 uint64_t indices) {
59 SkASSERT(palette < 16); 59 SkASSERT(palette < 16);
60 SkASSERT(multiplier < 16); 60 SkASSERT(multiplier < 16);
61 SkASSERT(indices < (static_cast<uint64_t>(1) << 48)); 61 SkASSERT(indices < (static_cast<uint64_t>(1) << 48));
62 62
63 const uint64_t b = static_cast<uint64_t>(base_cw) << 56; 63 const uint64_t b = static_cast<uint64_t>(base_cw) << 56;
64 const uint64_t m = static_cast<uint64_t>(multiplier) << 52; 64 const uint64_t m = static_cast<uint64_t>(multiplier) << 52;
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 const uint32_t packedIndexColumn2 = pack_indices_vertical(indexColumn2); 550 const uint32_t packedIndexColumn2 = pack_indices_vertical(indexColumn2);
551 const uint32_t packedIndexColumn3 = pack_indices_vertical(indexColumn3); 551 const uint32_t packedIndexColumn3 = pack_indices_vertical(indexColumn3);
552 552
553 *dst = SkEndian_SwapBE64(0x8490000000000000ULL | 553 *dst = SkEndian_SwapBE64(0x8490000000000000ULL |
554 (static_cast<uint64_t>(packedIndexColumn0) << 36) | 554 (static_cast<uint64_t>(packedIndexColumn0) << 36) |
555 (static_cast<uint64_t>(packedIndexColumn1) << 24) | 555 (static_cast<uint64_t>(packedIndexColumn1) << 24) |
556 static_cast<uint64_t>(packedIndexColumn2 << 12) | 556 static_cast<uint64_t>(packedIndexColumn2 << 12) |
557 static_cast<uint64_t>(packedIndexColumn3)); 557 static_cast<uint64_t>(packedIndexColumn3));
558 } 558 }
559 559
560 static inline int get_r11_eac_index(uint64_t block, int x, int y) {
561 SkASSERT(x >= 0 && x < 4);
562 SkASSERT(y >= 0 && y < 4);
563 const int idx = x*4 + y;
564 return (block >> ((15-idx)*3)) & 0x7;
565 }
566
567 static void decompress_r11_eac_block(uint8_t* dst, int dstRowBytes, const uint8_ t* src) {
568 const uint64_t block = SkEndian_SwapBE64(*(reinterpret_cast<const uint64_t * >(src)));
569
570 const int base_cw = (block >> 56) & 0xFF;
571 const int mod = (block >> 52) & 0xF;
572 const int palette_idx = (block >> 48) & 0xF;
573
574 const int* palette = kR11EACModifierPalettes[palette_idx];
575
576 for (int j = 0; j < 4; ++j) {
577 for (int i = 0; i < 4; ++i) {
578 const int idx = get_r11_eac_index(block, i, j);
579 const int val = base_cw*8 + 4 + palette[idx]*mod*8;
580 if (val < 0) {
581 dst[i] = 0;
582 } else if (val > 2047) {
583 dst[i] = 0xFF;
584 } else {
585 dst[i] = (val >> 3) & 0xFF;
586 }
587 }
588 dst += dstRowBytes;
589 }
robertphillips 2014/07/31 15:01:02 extra line ?
krajcevski 2014/07/31 15:12:18 Done.
590
591 }
592
560 //////////////////////////////////////////////////////////////////////////////// 593 ////////////////////////////////////////////////////////////////////////////////
561 594
562 namespace SkTextureCompressor { 595 namespace SkTextureCompressor {
563 596
564 bool CompressA8ToR11EAC(uint8_t* dst, const uint8_t* src, int width, int height, int rowBytes) { 597 bool CompressA8ToR11EAC(uint8_t* dst, const uint8_t* src, int width, int height, int rowBytes) {
565 598
566 #if (COMPRESS_R11_EAC_SLOW) || (COMPRESS_R11_EAC_FAST) 599 #if (COMPRESS_R11_EAC_SLOW) || (COMPRESS_R11_EAC_FAST)
567 600
568 return compress_4x4_a8_to_64bit(dst, src, width, height, rowBytes, compress_ r11eac_block); 601 return compress_4x4_a8_to_64bit(dst, src, width, height, rowBytes, compress_ r11eac_block);
569 602
570 #elif COMPRESS_R11_EAC_FASTEST 603 #elif COMPRESS_R11_EAC_FASTEST
571 604
572 return compress_a8_to_r11eac_fast(dst, src, width, height, rowBytes); 605 return compress_a8_to_r11eac_fast(dst, src, width, height, rowBytes);
573 606
574 #else 607 #else
575 #error "Must choose R11 EAC algorithm" 608 #error "Must choose R11 EAC algorithm"
576 #endif 609 #endif
577 } 610 }
578 611
579 SkBlitter* CreateR11EACBlitter(int width, int height, void* outputBuffer) { 612 SkBlitter* CreateR11EACBlitter(int width, int height, void* outputBuffer) {
580 return new 613 return new
581 SkTCompressedAlphaBlitter<4, 8, compress_block_vertical> 614 SkTCompressedAlphaBlitter<4, 8, compress_block_vertical>
582 (width, height, outputBuffer); 615 (width, height, outputBuffer);
583 } 616 }
584 617
618 void DecompressR11EAC(uint8_t* dst, int dstRowBytes, const uint8_t* src, int wid th, int height) {
619 for (int j = 0; j < height; j += 4) {
620 for (int i = 0; i < width; i += 4) {
621 decompress_r11_eac_block(dst + i, dstRowBytes, src);
622 src += 8;
623 }
624 dst += 4 * dstRowBytes;
625 }
626 }
627
585 } // namespace SkTextureCompressor 628 } // namespace SkTextureCompressor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698