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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: src/utils/SkTextureCompressor_R11EAC.cpp
diff --git a/src/utils/SkTextureCompressor_R11EAC.cpp b/src/utils/SkTextureCompressor_R11EAC.cpp
index 982fb012ef3cf9b3b6249b96eb1a6cb788789958..2826fc58217bb4ff39b65e3bb0e17c3d2d232b1d 100644
--- a/src/utils/SkTextureCompressor_R11EAC.cpp
+++ b/src/utils/SkTextureCompressor_R11EAC.cpp
@@ -29,8 +29,6 @@
// If mul is zero, then we set mul = 1/8, so that the formula becomes
// clamp[0, 2047](base_cw * 8 + 4 + mod_val)
-#if COMPRESS_R11_EAC_SLOW
-
static const int kNumR11EACPalettes = 16;
static const int kR11EACPaletteSize = 8;
static const int kR11EACModifierPalettes[kNumR11EACPalettes][kR11EACPaletteSize] = {
@@ -52,6 +50,8 @@ static const int kR11EACModifierPalettes[kNumR11EACPalettes][kR11EACPaletteSize]
{-3, -5, -7, -9, 2, 4, 6, 8}
};
+#if COMPRESS_R11_EAC_SLOW
+
// Pack the base codeword, palette, and multiplier into the 64 bits necessary
// to decode it.
static uint64_t pack_r11eac_block(uint16_t base_cw, uint16_t palette, uint16_t multiplier,
@@ -557,6 +557,39 @@ inline void compress_block_vertical(uint8_t* dstPtr, const uint8_t *block) {
static_cast<uint64_t>(packedIndexColumn3));
}
+static inline int get_r11_eac_index(uint64_t block, int x, int y) {
+ SkASSERT(x >= 0 && x < 4);
+ SkASSERT(y >= 0 && y < 4);
+ const int idx = x*4 + y;
+ return (block >> ((15-idx)*3)) & 0x7;
+}
+
+static void decompress_r11_eac_block(uint8_t* dst, int dstRowBytes, const uint8_t* src) {
+ const uint64_t block = SkEndian_SwapBE64(*(reinterpret_cast<const uint64_t *>(src)));
+
+ const int base_cw = (block >> 56) & 0xFF;
+ const int mod = (block >> 52) & 0xF;
+ const int palette_idx = (block >> 48) & 0xF;
+
+ const int* palette = kR11EACModifierPalettes[palette_idx];
+
+ for (int j = 0; j < 4; ++j) {
+ for (int i = 0; i < 4; ++i) {
+ const int idx = get_r11_eac_index(block, i, j);
+ const int val = base_cw*8 + 4 + palette[idx]*mod*8;
+ if (val < 0) {
+ dst[i] = 0;
+ } else if (val > 2047) {
+ dst[i] = 0xFF;
+ } else {
+ dst[i] = (val >> 3) & 0xFF;
+ }
+ }
+ dst += dstRowBytes;
+ }
robertphillips 2014/07/31 15:01:02 extra line ?
krajcevski 2014/07/31 15:12:18 Done.
+
+}
+
////////////////////////////////////////////////////////////////////////////////
namespace SkTextureCompressor {
@@ -582,4 +615,14 @@ SkBlitter* CreateR11EACBlitter(int width, int height, void* outputBuffer) {
(width, height, outputBuffer);
}
+void DecompressR11EAC(uint8_t* dst, int dstRowBytes, const uint8_t* src, int width, int height) {
+ for (int j = 0; j < height; j += 4) {
+ for (int i = 0; i < width; i += 4) {
+ decompress_r11_eac_block(dst + i, dstRowBytes, src);
+ src += 8;
+ }
+ dst += 4 * dstRowBytes;
+ }
+}
+
} // namespace SkTextureCompressor

Powered by Google App Engine
This is Rietveld 408576698