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 1972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1983 // stored in the block. | 1983 // stored in the block. |
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 |
robertphillips
2014/08/07 17:53:15
Add a comment like the following for all three ins
krajcevski
2014/08/07 18:00:41
Done.
| |
1994 struct CompressorASTC { | |
1995 static inline void CompressA8Vertical(uint8_t* dst, const uint8_t* src) { | |
1996 compress_a8_astc_block<GetAlphaTranspose>(&dst, src, 12); | |
1997 } | |
1998 | |
1999 static inline void CompressA8Horizontal(uint8_t* dst, const uint8_t* src, | |
2000 int srcRowBytes) { | |
2001 compress_a8_astc_block<GetAlpha>(&dst, src, srcRowBytes); | |
2002 } | |
2003 | |
2004 static inline void UpdateBlock(uint8_t* dst, const uint8_t* src) { | |
2005 } | |
2006 }; | |
2007 | |
1994 //////////////////////////////////////////////////////////////////////////////// | 2008 //////////////////////////////////////////////////////////////////////////////// |
1995 | 2009 |
1996 namespace SkTextureCompressor { | 2010 namespace SkTextureCompressor { |
1997 | 2011 |
1998 bool CompressA8To12x12ASTC(uint8_t* dst, const uint8_t* src, | 2012 bool CompressA8To12x12ASTC(uint8_t* dst, const uint8_t* src, |
1999 int width, int height, int rowBytes) { | 2013 int width, int height, int rowBytes) { |
2000 if (width < 0 || ((width % 12) != 0) || height < 0 || ((height % 12) != 0)) { | 2014 if (width < 0 || ((width % 12) != 0) || height < 0 || ((height % 12) != 0)) { |
2001 return false; | 2015 return false; |
2002 } | 2016 } |
2003 | 2017 |
(...skipping 19 matching lines...) Expand all Loading... | |
2023 // In the case of ASTC, if everything index is zero, then the interpolated v alue | 2037 // 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 | 2038 // will decode to zero provided we have the right header. We use the encodin g |
2025 // from recognizing all zero blocks from above. | 2039 // from recognizing all zero blocks from above. |
2026 const int nBlocks = (width * height / 144); | 2040 const int nBlocks = (width * height / 144); |
2027 uint8_t *dst = reinterpret_cast<uint8_t *>(outputBuffer); | 2041 uint8_t *dst = reinterpret_cast<uint8_t *>(outputBuffer); |
2028 for (int i = 0; i < nBlocks; ++i) { | 2042 for (int i = 0; i < nBlocks; ++i) { |
2029 send_packing(&dst, SkTEndian_SwapLE64(0x0000000001FE000173ULL), 0); | 2043 send_packing(&dst, SkTEndian_SwapLE64(0x0000000001FE000173ULL), 0); |
2030 } | 2044 } |
2031 | 2045 |
2032 return allocator->createT< | 2046 return allocator->createT< |
2033 SkTCompressedAlphaBlitter<12, 16, CompressA8ASTCBlockVertical>, int, int , void* > | 2047 SkTCompressedAlphaBlitter<12, 16, CompressorASTC>, int, int, void* > |
2034 (width, height, outputBuffer); | 2048 (width, height, outputBuffer); |
2035 } | 2049 } |
2036 | 2050 |
2037 void DecompressASTC(uint8_t* dst, int dstRowBytes, const uint8_t* src, | 2051 void DecompressASTC(uint8_t* dst, int dstRowBytes, const uint8_t* src, |
2038 int width, int height, int blockDimX, int blockDimY) { | 2052 int width, int height, int blockDimX, int blockDimY) { |
2039 // ASTC is encoded in what they call "raster order", so that the first | 2053 // 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 | 2054 // block is the bottom-left block in the image, and the first pixel |
2041 // is the bottom-left pixel of the image | 2055 // is the bottom-left pixel of the image |
2042 dst += height * dstRowBytes; | 2056 dst += height * dstRowBytes; |
2043 | 2057 |
2044 ASTCDecompressionData data(blockDimX, blockDimY); | 2058 ASTCDecompressionData data(blockDimX, blockDimY); |
2045 for (int y = 0; y < height; y += blockDimY) { | 2059 for (int y = 0; y < height; y += blockDimY) { |
2046 dst -= blockDimY * dstRowBytes; | 2060 dst -= blockDimY * dstRowBytes; |
2047 SkColor *colorPtr = reinterpret_cast<SkColor*>(dst); | 2061 SkColor *colorPtr = reinterpret_cast<SkColor*>(dst); |
2048 for (int x = 0; x < width; x += blockDimX) { | 2062 for (int x = 0; x < width; x += blockDimX) { |
2049 read_astc_block(&data, src); | 2063 read_astc_block(&data, src); |
2050 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR owBytes, data); | 2064 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR owBytes, data); |
2051 | 2065 |
2052 // ASTC encoded blocks are 16 bytes (128 bits) large. | 2066 // ASTC encoded blocks are 16 bytes (128 bits) large. |
2053 src += 16; | 2067 src += 16; |
2054 } | 2068 } |
2055 } | 2069 } |
2056 } | 2070 } |
2057 | 2071 |
2058 } // SkTextureCompressor | 2072 } // SkTextureCompressor |
OLD | NEW |