| 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 #include "SkTextureCompressor_Utils.h" | 10 #include "SkTextureCompressor_Utils.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // Fully transparent? We know the encoding... | 228 // Fully transparent? We know the encoding... |
| 229 case 0: | 229 case 0: |
| 230 // (0x0020 << 48) produces the following: | 230 // (0x0020 << 48) produces the following: |
| 231 // basw_cw: 0 | 231 // basw_cw: 0 |
| 232 // mod: 0, palette: {-3, -6, -9, -15, 2, 5, 8, 14} | 232 // mod: 0, palette: {-3, -6, -9, -15, 2, 5, 8, 14} |
| 233 // multiplier: 2 | 233 // multiplier: 2 |
| 234 // mod_val: -3 | 234 // mod_val: -3 |
| 235 // | 235 // |
| 236 // this gives the following formula: | 236 // this gives the following formula: |
| 237 // clamp[0, 2047](0*8+4+(-3)*2*8) = 0 | 237 // clamp[0, 2047](0*8+4+(-3)*2*8) = 0 |
| 238 // | 238 // |
| 239 // Furthermore, it is impervious to endianness: | 239 // Furthermore, it is impervious to endianness: |
| 240 // 0x0020000000002000ULL | 240 // 0x0020000000002000ULL |
| 241 // Will produce one pixel with index 2, which gives: | 241 // Will produce one pixel with index 2, which gives: |
| 242 // clamp[0, 2047](0*8+4+(-9)*2*8) = 0 | 242 // clamp[0, 2047](0*8+4+(-9)*2*8) = 0 |
| 243 return 0x0020000000002000ULL; | 243 return 0x0020000000002000ULL; |
| 244 | 244 |
| 245 // Fully opaque? We know this encoding too... | 245 // Fully opaque? We know this encoding too... |
| 246 case 255: | 246 case 255: |
| 247 | 247 |
| 248 // -1 produces the following: | 248 // -1 produces the following: |
| 249 // basw_cw: 255 | 249 // basw_cw: 255 |
| 250 // mod: 15, palette: {-3, -5, -7, -9, 2, 4, 6, 8} | 250 // mod: 15, palette: {-3, -5, -7, -9, 2, 4, 6, 8} |
| 251 // mod_val: 8 | 251 // mod_val: 8 |
| 252 // | 252 // |
| 253 // this gives the following formula: | 253 // this gives the following formula: |
| 254 // clamp[0, 2047](255*8+4+8*8*8) = clamp[0, 2047](2556) = 2047 | 254 // clamp[0, 2047](255*8+4+8*8*8) = clamp[0, 2047](2556) = 2047 |
| 255 return 0xFFFFFFFFFFFFFFFFULL; | 255 return 0xFFFFFFFFFFFFFFFFULL; |
| 256 | 256 |
| 257 default: | 257 default: |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 403 |
| 404 x = swap_shift<12>(x, 0xFFF000000ULL); | 404 x = swap_shift<12>(x, 0xFFF000000ULL); |
| 405 #else | 405 #else |
| 406 // If our CPU is little endian, then the above logic will | 406 // If our CPU is little endian, then the above logic will |
| 407 // produce the following indices: | 407 // produce the following indices: |
| 408 // x: 00 00 00 00 00 00 00 00 c g i m d h l p b f j n a e k o | 408 // x: 00 00 00 00 00 00 00 00 c g i m d h l p b f j n a e k o |
| 409 | 409 |
| 410 x = swap_shift<36>(x, 0xFC0ULL); | 410 x = swap_shift<36>(x, 0xFC0ULL); |
| 411 | 411 |
| 412 // x: 00 00 00 00 00 00 00 00 a e i m d h l p b f j n c g k o | 412 // x: 00 00 00 00 00 00 00 00 a e i m d h l p b f j n c g k o |
| 413 | 413 |
| 414 x = (x & (0xFFFULL << 36)) | ((x & 0xFFFFFFULL) << 12) | ((x >> 24) & 0xFFFU
LL); | 414 x = (x & (0xFFFULL << 36)) | ((x & 0xFFFFFFULL) << 12) | ((x >> 24) & 0xFFFU
LL); |
| 415 #endif | 415 #endif |
| 416 | 416 |
| 417 // x: 00 00 00 00 00 00 00 00 a e i m b f j n c g k o d h l p | 417 // x: 00 00 00 00 00 00 00 00 a e i m b f j n c g k o d h l p |
| 418 return x; | 418 return x; |
| 419 } | 419 } |
| 420 | 420 |
| 421 // This function follows the same basic procedure as compress_heterogeneous_r11e
ac_block | 421 // This function follows the same basic procedure as compress_heterogeneous_r11e
ac_block |
| 422 // above when COMPRESS_R11_EAC_FAST is defined, but it avoids a few loads/stores
and | 422 // above when COMPRESS_R11_EAC_FAST is defined, but it avoids a few loads/stores
and |
| 423 // tries to optimize where it can using SIMD. | 423 // tries to optimize where it can using SIMD. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 //////////////////////////////////////////////////////////////////////////////// | 491 //////////////////////////////////////////////////////////////////////////////// |
| 492 | 492 |
| 493 // The R11 EAC format expects that indices are given in column-major order. Sinc
e | 493 // The R11 EAC format expects that indices are given in column-major order. Sinc
e |
| 494 // we receive alpha values in raster order, this usually means that we have to u
se | 494 // we receive alpha values in raster order, this usually means that we have to u
se |
| 495 // pack6 above to properly pack our indices. However, if our indices come from t
he | 495 // pack6 above to properly pack our indices. However, if our indices come from t
he |
| 496 // blitter, then each integer will be a column of indices, and hence can be effi
ciently | 496 // blitter, then each integer will be a column of indices, and hence can be effi
ciently |
| 497 // packed. This function takes the bottom three bits of each byte and places the
m in | 497 // packed. This function takes the bottom three bits of each byte and places the
m in |
| 498 // the least significant 12 bits of the resulting integer. | 498 // the least significant 12 bits of the resulting integer. |
| 499 static inline uint32_t pack_indices_vertical(uint32_t x) { | 499 static inline uint32_t pack_indices_vertical(uint32_t x) { |
| 500 #if defined (SK_CPU_BENDIAN) | 500 #if defined (SK_CPU_BENDIAN) |
| 501 return | 501 return |
| 502 (x & 7) | | 502 (x & 7) | |
| 503 ((x >> 5) & (7 << 3)) | | 503 ((x >> 5) & (7 << 3)) | |
| 504 ((x >> 10) & (7 << 6)) | | 504 ((x >> 10) & (7 << 6)) | |
| 505 ((x >> 15) & (7 << 9)); | 505 ((x >> 15) & (7 << 9)); |
| 506 #else | 506 #else |
| 507 return | 507 return |
| 508 ((x >> 24) & 7) | | 508 ((x >> 24) & 7) | |
| 509 ((x >> 13) & (7 << 3)) | | 509 ((x >> 13) & (7 << 3)) | |
| 510 ((x >> 2) & (7 << 6)) | | 510 ((x >> 2) & (7 << 6)) | |
| 511 ((x << 9) & (7 << 9)); | 511 ((x << 9) & (7 << 9)); |
| 512 #endif | 512 #endif |
| 513 } | 513 } |
| 514 | 514 |
| 515 // This function returns the compressed format of a block given as four columns
of | 515 // This function returns the compressed format of a block given as four columns
of |
| 516 // alpha values. Each column is assumed to be loaded from top to bottom, and hen
ce | 516 // alpha values. Each column is assumed to be loaded from top to bottom, and hen
ce |
| 517 // must first be converted to indices and then packed into the resulting 64-bit | 517 // must first be converted to indices and then packed into the resulting 64-bit |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 (width, height, outputBuffer); | 657 (width, height, outputBuffer); |
| 658 } | 658 } |
| 659 | 659 |
| 660 void DecompressR11EAC(uint8_t* dst, int dstRowBytes, const uint8_t* src, int wid
th, int height) { | 660 void DecompressR11EAC(uint8_t* dst, int dstRowBytes, const uint8_t* src, int wid
th, int height) { |
| 661 for (int j = 0; j < height; j += 4) { | 661 for (int j = 0; j < height; j += 4) { |
| 662 for (int i = 0; i < width; i += 4) { | 662 for (int i = 0; i < width; i += 4) { |
| 663 decompress_r11_eac_block(dst + i, dstRowBytes, src); | 663 decompress_r11_eac_block(dst + i, dstRowBytes, src); |
| 664 src += 8; | 664 src += 8; |
| 665 } | 665 } |
| 666 dst += 4 * dstRowBytes; | 666 dst += 4 * dstRowBytes; |
| 667 } | 667 } |
| 668 } | 668 } |
| 669 | 669 |
| 670 } // namespace SkTextureCompressor | 670 } // namespace SkTextureCompressor |
| OLD | NEW |