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_ASTC.h" | 8 #include "SkTextureCompressor_ASTC.h" |
9 #include "SkTextureCompressor_Blitter.h" | 9 #include "SkTextureCompressor_Blitter.h" |
10 | 10 |
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1984 dst += data.fDimY * dstRowBytes; | 1984 dst += data.fDimY * dstRowBytes; |
1985 for (int y = 0; y < data.fDimY; ++y) { | 1985 for (int y = 0; y < data.fDimY; ++y) { |
1986 dst -= dstRowBytes; | 1986 dst -= dstRowBytes; |
1987 SkColor* colorPtr = reinterpret_cast<SkColor*>(dst); | 1987 SkColor* colorPtr = reinterpret_cast<SkColor*>(dst); |
1988 for (int x = 0; x < data.fDimX; ++x) { | 1988 for (int x = 0; x < data.fDimX; ++x) { |
1989 colorPtr[x] = data.getTexel(endpoints, texelWeights, x, y); | 1989 colorPtr[x] = data.getTexel(endpoints, texelWeights, x, y); |
1990 } | 1990 } |
1991 } | 1991 } |
1992 } | 1992 } |
1993 | 1993 |
| 1994 // This is the type passed as the CompressorType argument of the compressed |
| 1995 // blitter for the ASTC format. The static functions required to be in this |
| 1996 // struct are documented in SkTextureCompressor_Blitter.h |
| 1997 struct CompressorASTC { |
| 1998 static inline void CompressA8Vertical(uint8_t* dst, const uint8_t* src) { |
| 1999 compress_a8_astc_block<GetAlphaTranspose>(&dst, src, 12); |
| 2000 } |
| 2001 |
| 2002 static inline void CompressA8Horizontal(uint8_t* dst, const uint8_t* src, |
| 2003 int srcRowBytes) { |
| 2004 compress_a8_astc_block<GetAlpha>(&dst, src, srcRowBytes); |
| 2005 } |
| 2006 |
| 2007 static inline void UpdateBlock(uint8_t* dst, const uint8_t* src) { |
| 2008 } |
| 2009 }; |
| 2010 |
1994 //////////////////////////////////////////////////////////////////////////////// | 2011 //////////////////////////////////////////////////////////////////////////////// |
1995 | 2012 |
1996 namespace SkTextureCompressor { | 2013 namespace SkTextureCompressor { |
1997 | 2014 |
1998 bool CompressA8To12x12ASTC(uint8_t* dst, const uint8_t* src, | 2015 bool CompressA8To12x12ASTC(uint8_t* dst, const uint8_t* src, |
1999 int width, int height, int rowBytes) { | 2016 int width, int height, int rowBytes) { |
2000 if (width < 0 || ((width % 12) != 0) || height < 0 || ((height % 12) != 0))
{ | 2017 if (width < 0 || ((width % 12) != 0) || height < 0 || ((height % 12) != 0))
{ |
2001 return false; | 2018 return false; |
2002 } | 2019 } |
2003 | 2020 |
(...skipping 19 matching lines...) Expand all Loading... |
2023 // In the case of ASTC, if everything index is zero, then the interpolated v
alue | 2040 // In the case of ASTC, if everything index is zero, then the interpolated v
alue |
2024 // will decode to zero provided we have the right header. We use the encodin
g | 2041 // will decode to zero provided we have the right header. We use the encodin
g |
2025 // from recognizing all zero blocks from above. | 2042 // from recognizing all zero blocks from above. |
2026 const int nBlocks = (width * height / 144); | 2043 const int nBlocks = (width * height / 144); |
2027 uint8_t *dst = reinterpret_cast<uint8_t *>(outputBuffer); | 2044 uint8_t *dst = reinterpret_cast<uint8_t *>(outputBuffer); |
2028 for (int i = 0; i < nBlocks; ++i) { | 2045 for (int i = 0; i < nBlocks; ++i) { |
2029 send_packing(&dst, SkTEndian_SwapLE64(0x0000000001FE000173ULL), 0); | 2046 send_packing(&dst, SkTEndian_SwapLE64(0x0000000001FE000173ULL), 0); |
2030 } | 2047 } |
2031 | 2048 |
2032 return allocator->createT< | 2049 return allocator->createT< |
2033 SkTCompressedAlphaBlitter<12, 16, CompressA8ASTCBlockVertical>, int, int
, void* > | 2050 SkTCompressedAlphaBlitter<12, 16, CompressorASTC>, int, int, void* > |
2034 (width, height, outputBuffer); | 2051 (width, height, outputBuffer); |
2035 } | 2052 } |
2036 | 2053 |
2037 void DecompressASTC(uint8_t* dst, int dstRowBytes, const uint8_t* src, | 2054 void DecompressASTC(uint8_t* dst, int dstRowBytes, const uint8_t* src, |
2038 int width, int height, int blockDimX, int blockDimY) { | 2055 int width, int height, int blockDimX, int blockDimY) { |
2039 // ASTC is encoded in what they call "raster order", so that the first | 2056 // ASTC is encoded in what they call "raster order", so that the first |
2040 // block is the bottom-left block in the image, and the first pixel | 2057 // block is the bottom-left block in the image, and the first pixel |
2041 // is the bottom-left pixel of the image | 2058 // is the bottom-left pixel of the image |
2042 dst += height * dstRowBytes; | 2059 dst += height * dstRowBytes; |
2043 | 2060 |
2044 ASTCDecompressionData data(blockDimX, blockDimY); | 2061 ASTCDecompressionData data(blockDimX, blockDimY); |
2045 for (int y = 0; y < height; y += blockDimY) { | 2062 for (int y = 0; y < height; y += blockDimY) { |
2046 dst -= blockDimY * dstRowBytes; | 2063 dst -= blockDimY * dstRowBytes; |
2047 SkColor *colorPtr = reinterpret_cast<SkColor*>(dst); | 2064 SkColor *colorPtr = reinterpret_cast<SkColor*>(dst); |
2048 for (int x = 0; x < width; x += blockDimX) { | 2065 for (int x = 0; x < width; x += blockDimX) { |
2049 read_astc_block(&data, src); | 2066 read_astc_block(&data, src); |
2050 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR
owBytes, data); | 2067 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR
owBytes, data); |
2051 | 2068 |
2052 // ASTC encoded blocks are 16 bytes (128 bits) large. | 2069 // ASTC encoded blocks are 16 bytes (128 bits) large. |
2053 src += 16; | 2070 src += 16; |
2054 } | 2071 } |
2055 } | 2072 } |
2056 } | 2073 } |
2057 | 2074 |
2058 } // SkTextureCompressor | 2075 } // SkTextureCompressor |
OLD | NEW |