Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkTextureCompressorUtils_DEFINED | |
| 9 #define SkTextureCompressorUtils_DEFINED | |
| 10 | |
| 11 namespace SkTextureCompressor { | |
| 12 | |
| 13 #if 1 | |
|
robertphillips
2014/10/23 12:10:20
Do you intend for these to be static? They're name
pavelk
2014/10/23 16:05:03
Yep. :)
| |
| 14 // Divides each byte in the 32-bit argument by three. | |
| 15 inline uint32_t MultibyteDiv3(uint32_t x) { | |
| 16 const uint32_t a = (x >> 2) & 0x3F3F3F3F; | |
| 17 const uint32_t ar = (x & 0x03030303) << 4; | |
| 18 | |
| 19 const uint32_t b = (x >> 4) & 0x0F0F0F0F; | |
| 20 const uint32_t br = (x & 0x0F0F0F0F) << 2; | |
| 21 | |
| 22 const uint32_t c = (x >> 6) & 0x03030303; | |
| 23 const uint32_t cr = x & 0x3F3F3F3F; | |
| 24 | |
| 25 return a + b + c + (((ar + br + cr) >> 6) & 0x03030303); | |
| 26 } | |
| 27 | |
| 28 // Takes a loaded 32-bit integer of four 8-bit greyscale values and returns their | |
| 29 // quantization into 3-bit values, used by LATC and R11 EAC. Instead of taki ng the | |
| 30 // top three bits, the function computes the best three-bit value such that its | |
| 31 // reconstruction into an eight bit value via bit replication will yield the best | |
| 32 // results. In a 32-bit integer taking the range of values from 0-255 we wou ld add | |
| 33 // 18 and divide by 36 (255 / 36 ~= 7). However, since we are working in con strained | |
| 34 // 8-bit space, our algorithm is the following: | |
| 35 // 1. Shift right by one to give room for overflow | |
| 36 // 2. Add 9 (18/2) | |
| 37 // 3. Divide by 18 (divide by two, then by three twice) | |
| 38 inline uint32_t ConvertToThreeBitIndex(uint32_t x) { | |
| 39 x = (x >> 1) & 0x7F7F7F7F; // 1 | |
| 40 x = x + 0x09090909; // 2 | |
| 41 | |
| 42 // Need to divide by 18... so first divide by two | |
| 43 x = (x >> 1) & 0x7F7F7F7F; | |
| 44 | |
| 45 // Now divide by three twice | |
| 46 x = MultibyteDiv3(x); | |
| 47 x = MultibyteDiv3(x); | |
| 48 return x; | |
| 49 } | |
| 50 #else | |
| 51 // Moves the top three bits of each byte in the 32-bit argument to the least | |
| 52 // significant bits their respective byte. | |
| 53 inline uint32_t ConvertToThreeBitIndex(uint32_t x) { | |
| 54 return (x >> 5) & 0x07070707; | |
| 55 } | |
| 56 #endif | |
| 57 } | |
| 58 | |
| 59 #endif // SkTextureCompressorUtils_DEFINED | |
| OLD | NEW |