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_LATC.h" | 8 #include "SkTextureCompressor_LATC.h" |
9 #include "SkTextureCompressor_Blitter.h" | 9 #include "SkTextureCompressor_Blitter.h" |
10 #include "SkTextureCompressor_Utils.h" | 10 #include "SkTextureCompressor_Utils.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 typedef uint64_t (*A84x4To64BitProc)(const uint8_t block[]); | 80 typedef uint64_t (*A84x4To64BitProc)(const uint8_t block[]); |
81 | 81 |
82 // This function is used by both R11 EAC and LATC to compress 4x4 blocks | 82 // This function is used by both R11 EAC and LATC to compress 4x4 blocks |
83 // of 8-bit alpha into 64-bit values that comprise the compressed data. | 83 // of 8-bit alpha into 64-bit values that comprise the compressed data. |
84 // For both formats, we need to make sure that the dimensions of the | 84 // For both formats, we need to make sure that the dimensions of the |
85 // src pixels are divisible by 4, and copy 4x4 blocks one at a time | 85 // src pixels are divisible by 4, and copy 4x4 blocks one at a time |
86 // for compression. | 86 // for compression. |
87 static bool compress_4x4_a8_to_64bit(uint8_t* dst, const uint8_t* src, | 87 static bool compress_4x4_a8_to_64bit(uint8_t* dst, const uint8_t* src, |
88 int width, int height, int rowBytes, | 88 int width, int height, size_t rowBytes, |
89 A84x4To64BitProc proc) { | 89 A84x4To64BitProc proc) { |
90 // Make sure that our data is well-formed enough to be considered for compre
ssion | 90 // Make sure that our data is well-formed enough to be considered for compre
ssion |
91 if (0 == width || 0 == height || (width % 4) != 0 || (height % 4) != 0) { | 91 if (0 == width || 0 == height || (width % 4) != 0 || (height % 4) != 0) { |
92 return false; | 92 return false; |
93 } | 93 } |
94 | 94 |
95 int blocksX = width >> 2; | 95 int blocksX = width >> 2; |
96 int blocksY = height >> 2; | 96 int blocksY = height >> 2; |
97 | 97 |
98 uint8_t block[16]; | 98 uint8_t block[16]; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // 8 7 6 5 4 3 2 0 --> 9 7 6 5 4 3 2 0 | 343 // 8 7 6 5 4 3 2 0 --> 9 7 6 5 4 3 2 0 |
344 x |= (x >> 3) & 0x01010101; | 344 x |= (x >> 3) & 0x01010101; |
345 | 345 |
346 // Mask out high bits: | 346 // Mask out high bits: |
347 // 9 7 6 5 4 3 2 0 --> 1 7 6 5 4 3 2 0 | 347 // 9 7 6 5 4 3 2 0 --> 1 7 6 5 4 3 2 0 |
348 x &= 0x07070707; | 348 x &= 0x07070707; |
349 | 349 |
350 return pack_index(x); | 350 return pack_index(x); |
351 } | 351 } |
352 | 352 |
353 typedef uint64_t (*PackIndicesProc)(const uint8_t* alpha, int rowBytes); | 353 typedef uint64_t (*PackIndicesProc)(const uint8_t* alpha, size_t rowBytes); |
354 template<PackIndicesProc packIndicesProc> | 354 template<PackIndicesProc packIndicesProc> |
355 static void compress_a8_latc_block(uint8_t** dstPtr, const uint8_t* src, int row
Bytes) { | 355 static void compress_a8_latc_block(uint8_t** dstPtr, const uint8_t* src, size_t
rowBytes) { |
356 *(reinterpret_cast<uint64_t*>(*dstPtr)) = | 356 *(reinterpret_cast<uint64_t*>(*dstPtr)) = |
357 SkEndian_SwapLE64(0xFF | (packIndicesProc(src, rowBytes) << 16)); | 357 SkEndian_SwapLE64(0xFF | (packIndicesProc(src, rowBytes) << 16)); |
358 *dstPtr += 8; | 358 *dstPtr += 8; |
359 } | 359 } |
360 | 360 |
361 inline uint64_t PackRowMajor(const uint8_t *indices, int rowBytes) { | 361 inline uint64_t PackRowMajor(const uint8_t *indices, size_t rowBytes) { |
362 uint64_t result = 0; | 362 uint64_t result = 0; |
363 for (int i = 0; i < 4; ++i) { | 363 for (int i = 0; i < 4; ++i) { |
364 const uint32_t idx = *(reinterpret_cast<const uint32_t*>(indices + i*row
Bytes)); | 364 const uint32_t idx = *(reinterpret_cast<const uint32_t*>(indices + i*row
Bytes)); |
365 result |= static_cast<uint64_t>(convert_index(idx)) << 12*i; | 365 result |= static_cast<uint64_t>(convert_index(idx)) << 12*i; |
366 } | 366 } |
367 return result; | 367 return result; |
368 } | 368 } |
369 | 369 |
370 inline uint64_t PackColumnMajor(const uint8_t *indices, int rowBytes) { | 370 inline uint64_t PackColumnMajor(const uint8_t *indices, size_t rowBytes) { |
371 // !SPEED! Blarg, this is kind of annoying. SSE4 can make this | 371 // !SPEED! Blarg, this is kind of annoying. SSE4 can make this |
372 // a LOT faster. | 372 // a LOT faster. |
373 uint8_t transposed[16]; | 373 uint8_t transposed[16]; |
374 for (int i = 0; i < 4; ++i) { | 374 for (int i = 0; i < 4; ++i) { |
375 for (int j = 0; j < 4; ++j) { | 375 for (int j = 0; j < 4; ++j) { |
376 transposed[j*4+i] = indices[i*rowBytes + j]; | 376 transposed[j*4+i] = indices[i*rowBytes + j]; |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
380 return PackRowMajor(transposed, 4); | 380 return PackRowMajor(transposed, 4); |
381 } | 381 } |
382 | 382 |
383 static bool compress_4x4_a8_latc(uint8_t* dst, const uint8_t* src, | 383 static bool compress_4x4_a8_latc(uint8_t* dst, const uint8_t* src, |
384 int width, int height, int rowBytes) { | 384 int width, int height, size_t rowBytes) { |
385 | 385 |
386 if (width < 0 || ((width % 4) != 0) || height < 0 || ((height % 4) != 0)) { | 386 if (width < 0 || ((width % 4) != 0) || height < 0 || ((height % 4) != 0)) { |
387 return false; | 387 return false; |
388 } | 388 } |
389 | 389 |
390 uint8_t** dstPtr = &dst; | 390 uint8_t** dstPtr = &dst; |
391 for (int y = 0; y < height; y += 4) { | 391 for (int y = 0; y < height; y += 4) { |
392 for (int x = 0; x < width; x += 4) { | 392 for (int x = 0; x < width; x += 4) { |
393 compress_a8_latc_block<PackRowMajor>(dstPtr, src + y*rowBytes + x, r
owBytes); | 393 compress_a8_latc_block<PackRowMajor>(dstPtr, src + y*rowBytes + x, r
owBytes); |
394 } | 394 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 *cmpDst &= ~cmpMask; | 465 *cmpDst &= ~cmpMask; |
466 *cmpDst |= cmpSrc; | 466 *cmpDst |= cmpSrc; |
467 } | 467 } |
468 #endif // PEDANTIC_BLIT_RECT | 468 #endif // PEDANTIC_BLIT_RECT |
469 }; | 469 }; |
470 | 470 |
471 //////////////////////////////////////////////////////////////////////////////// | 471 //////////////////////////////////////////////////////////////////////////////// |
472 | 472 |
473 namespace SkTextureCompressor { | 473 namespace SkTextureCompressor { |
474 | 474 |
475 bool CompressA8ToLATC(uint8_t* dst, const uint8_t* src, int width, int height, i
nt rowBytes) { | 475 bool CompressA8ToLATC(uint8_t* dst, const uint8_t* src, int width, int height, s
ize_t rowBytes) { |
476 #if COMPRESS_LATC_FAST | 476 #if COMPRESS_LATC_FAST |
477 return compress_4x4_a8_latc(dst, src, width, height, rowBytes); | 477 return compress_4x4_a8_latc(dst, src, width, height, rowBytes); |
478 #elif COMPRESS_LATC_SLOW | 478 #elif COMPRESS_LATC_SLOW |
479 return compress_4x4_a8_to_64bit(dst, src, width, height, rowBytes, compress_
latc_block); | 479 return compress_4x4_a8_to_64bit(dst, src, width, height, rowBytes, compress_
latc_block); |
480 #else | 480 #else |
481 #error "Must choose either fast or slow LATC compression" | 481 #error "Must choose either fast or slow LATC compression" |
482 #endif | 482 #endif |
483 } | 483 } |
484 | 484 |
485 SkBlitter* CreateLATCBlitter(int width, int height, void* outputBuffer, | 485 SkBlitter* CreateLATCBlitter(int width, int height, void* outputBuffer, |
(...skipping 24 matching lines...) Expand all Loading... |
510 for (int j = 0; j < height; j += 4) { | 510 for (int j = 0; j < height; j += 4) { |
511 for (int i = 0; i < width; i += 4) { | 511 for (int i = 0; i < width; i += 4) { |
512 decompress_latc_block(dst + i, dstRowBytes, src); | 512 decompress_latc_block(dst + i, dstRowBytes, src); |
513 src += 8; | 513 src += 8; |
514 } | 514 } |
515 dst += 4 * dstRowBytes; | 515 dst += 4 * dstRowBytes; |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 } // SkTextureCompressor | 519 } // SkTextureCompressor |
OLD | NEW |