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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 { 1, 7, 9, 3, 8, 9, 4, 9, 9, 2, 10, 9, 2, 7, 10, 6, 8, 10, 9, 9, 10, 4, | 127 { 1, 7, 9, 3, 8, 9, 4, 9, 9, 2, 10, 9, 2, 7, 10, 6, 8, 10, 9, 9, 10, 4, |
128 10, 10, 3, 7, 11, 10, 8, 11, 15, 9, 11, 7, 10, 11, -1, 0, 0, -1, 0, 0, -1, 0, | 128 10, 10, 3, 7, 11, 10, 8, 11, 15, 9, 11, 7, 10, 11, -1, 0, 0, -1, 0, 0, -1, 0, |
129 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0}, // n = 20 | 129 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0}, // n = 20 |
130 { 2, 10, 9, 4, 11, 9, 1, 9, 10, 6, 10, 10, 10, 11, 10, 1, 9, 11, 9, 10, 11, 16, | 130 { 2, 10, 9, 4, 11, 9, 1, 9, 10, 6, 10, 10, 10, 11, 10, 1, 9, 11, 9, 10, 11, 16, |
131 11, 11, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, | 131 11, 11, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, |
132 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0} // n = 20 | 132 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0} // n = 20 |
133 }; | 133 }; |
134 | 134 |
135 // Returns the alpha value of a texel at position (x, y) from src. | 135 // Returns the alpha value of a texel at position (x, y) from src. |
136 // (x, y) are assumed to be in the range [0, 12). | 136 // (x, y) are assumed to be in the range [0, 12). |
137 inline uint8_t GetAlpha(const uint8_t *src, int rowBytes, int x, int y) { | 137 inline uint8_t GetAlpha(const uint8_t *src, size_t rowBytes, int x, int y) { |
138 SkASSERT(x >= 0 && x < 12); | 138 SkASSERT(x >= 0 && x < 12); |
139 SkASSERT(y >= 0 && y < 12); | 139 SkASSERT(y >= 0 && y < 12); |
140 SkASSERT(rowBytes >= 12); | 140 SkASSERT(rowBytes >= 12); |
141 return *(src + y*rowBytes + x); | 141 return *(src + y*rowBytes + x); |
142 } | 142 } |
143 | 143 |
144 inline uint8_t GetAlphaTranspose(const uint8_t *src, int rowBytes, int x, int y)
{ | 144 inline uint8_t GetAlphaTranspose(const uint8_t *src, size_t rowBytes, int x, int
y) { |
145 return GetAlpha(src, rowBytes, y, x); | 145 return GetAlpha(src, rowBytes, y, x); |
146 } | 146 } |
147 | 147 |
148 // Output the 16 bytes stored in top and bottom and advance the pointer. The byt
es | 148 // Output the 16 bytes stored in top and bottom and advance the pointer. The byt
es |
149 // are stored as the integers are represented in memory, so they should be swapp
ed | 149 // are stored as the integers are represented in memory, so they should be swapp
ed |
150 // if necessary. | 150 // if necessary. |
151 static inline void send_packing(uint8_t** dst, const uint64_t top, const uint64_
t bottom) { | 151 static inline void send_packing(uint8_t** dst, const uint64_t top, const uint64_
t bottom) { |
152 uint64_t* dst64 = reinterpret_cast<uint64_t*>(*dst); | 152 uint64_t* dst64 = reinterpret_cast<uint64_t*>(*dst); |
153 dst64[0] = top; | 153 dst64[0] = top; |
154 dst64[1] = bottom; | 154 dst64[1] = bottom; |
155 *dst += 16; | 155 *dst += 16; |
156 } | 156 } |
157 | 157 |
158 // Compresses an ASTC block, by looking up the proper contributions from | 158 // Compresses an ASTC block, by looking up the proper contributions from |
159 // k6x5To12x12Table and computing an index from the associated values. | 159 // k6x5To12x12Table and computing an index from the associated values. |
160 typedef uint8_t (*GetAlphaProc)(const uint8_t* src, int rowBytes, int x, int y); | 160 typedef uint8_t (*GetAlphaProc)(const uint8_t* src, size_t rowBytes, int x, int
y); |
161 | 161 |
162 template<GetAlphaProc getAlphaProc> | 162 template<GetAlphaProc getAlphaProc> |
163 static void compress_a8_astc_block(uint8_t** dst, const uint8_t* src, int rowByt
es) { | 163 static void compress_a8_astc_block(uint8_t** dst, const uint8_t* src, size_t row
Bytes) { |
164 // Check for single color | 164 // Check for single color |
165 bool constant = true; | 165 bool constant = true; |
166 const uint32_t firstInt = *(reinterpret_cast<const uint32_t*>(src)); | 166 const uint32_t firstInt = *(reinterpret_cast<const uint32_t*>(src)); |
167 for (int i = 0; i < 12; ++i) { | 167 for (int i = 0; i < 12; ++i) { |
168 const uint32_t *rowInt = reinterpret_cast<const uint32_t *>(src + i*rowB
ytes); | 168 const uint32_t *rowInt = reinterpret_cast<const uint32_t *>(src + i*rowB
ytes); |
169 constant = constant && (rowInt[0] == firstInt); | 169 constant = constant && (rowInt[0] == firstInt); |
170 constant = constant && (rowInt[1] == firstInt); | 170 constant = constant && (rowInt[1] == firstInt); |
171 constant = constant && (rowInt[2] == firstInt); | 171 constant = constant && (rowInt[2] == firstInt); |
172 } | 172 } |
173 | 173 |
(...skipping 1858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2032 SkFAIL("Implement me!"); | 2032 SkFAIL("Implement me!"); |
2033 } | 2033 } |
2034 #endif | 2034 #endif |
2035 }; | 2035 }; |
2036 | 2036 |
2037 //////////////////////////////////////////////////////////////////////////////// | 2037 //////////////////////////////////////////////////////////////////////////////// |
2038 | 2038 |
2039 namespace SkTextureCompressor { | 2039 namespace SkTextureCompressor { |
2040 | 2040 |
2041 bool CompressA8To12x12ASTC(uint8_t* dst, const uint8_t* src, | 2041 bool CompressA8To12x12ASTC(uint8_t* dst, const uint8_t* src, |
2042 int width, int height, int rowBytes) { | 2042 int width, int height, size_t rowBytes) { |
2043 if (width < 0 || ((width % 12) != 0) || height < 0 || ((height % 12) != 0))
{ | 2043 if (width < 0 || ((width % 12) != 0) || height < 0 || ((height % 12) != 0))
{ |
2044 return false; | 2044 return false; |
2045 } | 2045 } |
2046 | 2046 |
2047 uint8_t** dstPtr = &dst; | 2047 uint8_t** dstPtr = &dst; |
2048 for (int y = 0; y < height; y += 12) { | 2048 for (int y = 0; y < height; y += 12) { |
2049 for (int x = 0; x < width; x += 12) { | 2049 for (int x = 0; x < width; x += 12) { |
2050 compress_a8_astc_block<GetAlpha>(dstPtr, src + y*rowBytes + x, rowBy
tes); | 2050 compress_a8_astc_block<GetAlpha>(dstPtr, src + y*rowBytes + x, rowBy
tes); |
2051 } | 2051 } |
2052 } | 2052 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 read_astc_block(&data, src); | 2092 read_astc_block(&data, src); |
2093 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR
owBytes, data); | 2093 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR
owBytes, data); |
2094 | 2094 |
2095 // ASTC encoded blocks are 16 bytes (128 bits) large. | 2095 // ASTC encoded blocks are 16 bytes (128 bits) large. |
2096 src += 16; | 2096 src += 16; |
2097 } | 2097 } |
2098 } | 2098 } |
2099 } | 2099 } |
2100 | 2100 |
2101 } // SkTextureCompressor | 2101 } // SkTextureCompressor |
OLD | NEW |