| 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 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // clamp[0, 2047](base_cw * 8 + 4 + mod_val*mul*8) | 305 // clamp[0, 2047](base_cw * 8 + 4 + mod_val*mul*8) |
| 306 // | 306 // |
| 307 // mod_val is chosen from a palette of values based on the index of the | 307 // mod_val is chosen from a palette of values based on the index of the |
| 308 // given pixel. The palette is chosen by the value stored in mod. | 308 // given pixel. The palette is chosen by the value stored in mod. |
| 309 // This formula returns a value between 0 and 2047, which is converted | 309 // This formula returns a value between 0 and 2047, which is converted |
| 310 // to a float from 0 to 1 in OpenGL. | 310 // to a float from 0 to 1 in OpenGL. |
| 311 // | 311 // |
| 312 // If mul is zero, then we set mul = 1/8, so that the formula becomes | 312 // If mul is zero, then we set mul = 1/8, so that the formula becomes |
| 313 // clamp[0, 2047](base_cw * 8 + 4 + mod_val) | 313 // clamp[0, 2047](base_cw * 8 + 4 + mod_val) |
| 314 | 314 |
| 315 #if COMPRESS_R11_EAC_SLOW |
| 316 |
| 315 static const int kNumR11EACPalettes = 16; | 317 static const int kNumR11EACPalettes = 16; |
| 316 static const int kR11EACPaletteSize = 8; | 318 static const int kR11EACPaletteSize = 8; |
| 317 static const int kR11EACModifierPalettes[kNumR11EACPalettes][kR11EACPaletteSize]
= { | 319 static const int kR11EACModifierPalettes[kNumR11EACPalettes][kR11EACPaletteSize]
= { |
| 318 {-3, -6, -9, -15, 2, 5, 8, 14}, | 320 {-3, -6, -9, -15, 2, 5, 8, 14}, |
| 319 {-3, -7, -10, -13, 2, 6, 9, 12}, | 321 {-3, -7, -10, -13, 2, 6, 9, 12}, |
| 320 {-2, -5, -8, -13, 1, 4, 7, 12}, | 322 {-2, -5, -8, -13, 1, 4, 7, 12}, |
| 321 {-2, -4, -6, -13, 1, 3, 5, 12}, | 323 {-2, -4, -6, -13, 1, 3, 5, 12}, |
| 322 {-3, -6, -8, -12, 2, 5, 7, 11}, | 324 {-3, -6, -8, -12, 2, 5, 7, 11}, |
| 323 {-3, -7, -9, -11, 2, 6, 8, 10}, | 325 {-3, -7, -9, -11, 2, 6, 8, 10}, |
| 324 {-4, -7, -8, -11, 3, 6, 7, 10}, | 326 {-4, -7, -8, -11, 3, 6, 7, 10}, |
| 325 {-3, -5, -8, -11, 2, 4, 7, 10}, | 327 {-3, -5, -8, -11, 2, 4, 7, 10}, |
| 326 {-2, -6, -8, -10, 1, 5, 7, 9}, | 328 {-2, -6, -8, -10, 1, 5, 7, 9}, |
| 327 {-2, -5, -8, -10, 1, 4, 7, 9}, | 329 {-2, -5, -8, -10, 1, 4, 7, 9}, |
| 328 {-2, -4, -8, -10, 1, 3, 7, 9}, | 330 {-2, -4, -8, -10, 1, 3, 7, 9}, |
| 329 {-2, -5, -7, -10, 1, 4, 6, 9}, | 331 {-2, -5, -7, -10, 1, 4, 6, 9}, |
| 330 {-3, -4, -7, -10, 2, 3, 6, 9}, | 332 {-3, -4, -7, -10, 2, 3, 6, 9}, |
| 331 {-1, -2, -3, -10, 0, 1, 2, 9}, | 333 {-1, -2, -3, -10, 0, 1, 2, 9}, |
| 332 {-4, -6, -8, -9, 3, 5, 7, 8}, | 334 {-4, -6, -8, -9, 3, 5, 7, 8}, |
| 333 {-3, -5, -7, -9, 2, 4, 6, 8} | 335 {-3, -5, -7, -9, 2, 4, 6, 8} |
| 334 }; | 336 }; |
| 335 | 337 |
| 336 #if COMPRESS_R11_EAC_SLOW | |
| 337 // Pack the base codeword, palette, and multiplier into the 64 bits necessary | 338 // Pack the base codeword, palette, and multiplier into the 64 bits necessary |
| 338 // to decode it. | 339 // to decode it. |
| 339 static uint64_t pack_r11eac_block(uint16_t base_cw, uint16_t palette, uint16_t m
ultiplier, | 340 static uint64_t pack_r11eac_block(uint16_t base_cw, uint16_t palette, uint16_t m
ultiplier, |
| 340 uint64_t indices) { | 341 uint64_t indices) { |
| 341 SkASSERT(palette < 16); | 342 SkASSERT(palette < 16); |
| 342 SkASSERT(multiplier < 16); | 343 SkASSERT(multiplier < 16); |
| 343 SkASSERT(indices < (static_cast<uint64_t>(1) << 48)); | 344 SkASSERT(indices < (static_cast<uint64_t>(1) << 48)); |
| 344 | 345 |
| 345 const uint64_t b = static_cast<uint64_t>(base_cw) << 56; | 346 const uint64_t b = static_cast<uint64_t>(base_cw) << 56; |
| 346 const uint64_t m = static_cast<uint64_t>(multiplier) << 52; | 347 const uint64_t m = static_cast<uint64_t>(multiplier) << 52; |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 if (CompressBufferToFormat(dst, src, bitmap.colorType(), bitmap.width(), bit
map.height(), | 814 if (CompressBufferToFormat(dst, src, bitmap.colorType(), bitmap.width(), bit
map.height(), |
| 814 bitmap.rowBytes(), format)) { | 815 bitmap.rowBytes(), format)) { |
| 815 return SkData::NewFromMalloc(dst, compressedDataSize); | 816 return SkData::NewFromMalloc(dst, compressedDataSize); |
| 816 } | 817 } |
| 817 | 818 |
| 818 sk_free(dst); | 819 sk_free(dst); |
| 819 return NULL; | 820 return NULL; |
| 820 } | 821 } |
| 821 | 822 |
| 822 } // namespace SkTextureCompressor | 823 } // namespace SkTextureCompressor |
| OLD | NEW |