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_ASTC.h" | 9 #include "SkTextureCompressor_ASTC.h" |
10 #include "SkTextureCompressor_LATC.h" | 10 #include "SkTextureCompressor_LATC.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { | 37 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { |
38 if (NULL == dimX || NULL == dimY) { | 38 if (NULL == dimX || NULL == dimY) { |
39 return; | 39 return; |
40 } | 40 } |
41 | 41 |
42 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { | 42 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 // No specialized arguments, return the dimensions as they are in the spec. | 46 // No specialized arguments, return the dimensions as they are in the spec. |
47 switch(format) { | 47 static const struct FormatDimensions { |
48 // These formats are 64 bits per 4x4 block. | 48 const int fBlockSizeX; |
49 default: | 49 const int fBlockSizeY; |
50 SkDEBUGFAIL("Unknown compression format!"); | 50 } kFormatDimensions[kFormatCnt] = { |
51 // fall through | 51 { 4, 4 }, // kLATC_Format |
52 case kLATC_Format: | 52 { 4, 4 }, // kR11_EAC_Format |
53 case kR11_EAC_Format: | 53 { 4, 4 }, // kETC1_Format |
54 case kETC1_Format: | 54 { 4, 4 }, // kASTC_4x4_Format |
55 *dimX = 4; | 55 { 5, 4 }, // kASTC_5x4_Format |
56 *dimY = 4; | 56 { 5, 5 }, // kASTC_5x5_Format |
57 break; | 57 { 6, 5 }, // kASTC_6x5_Format |
58 { 6, 6 }, // kASTC_6x6_Format | |
59 { 8, 5 }, // kASTC_8x5_Format | |
60 { 8, 6 }, // kASTC_8x6_Format | |
61 { 8, 8 }, // kASTC_8x8_Format | |
62 { 10, 5 }, // kASTC_10x5_Format | |
63 { 10, 6 }, // kASTC_10x6_Format | |
64 { 10, 8 }, // kASTC_10x8_Format | |
65 { 10, 10 }, // kASTC_10x10_Format | |
66 { 12, 10 }, // kASTC_12x10_Format | |
67 { 12, 12 }, // kASTC_12x12_Format | |
68 }; | |
58 | 69 |
59 // This format is 12x12 blocks to 128 bits. | 70 *dimX = kFormatDimensions[format].fBlockSizeX; |
60 case kASTC_12x12_Format: | 71 *dimY = kFormatDimensions[format].fBlockSizeY; |
61 *dimX = 12; | |
62 *dimY = 12; | |
63 break; | |
64 } | |
65 } | 72 } |
66 | 73 |
67 int GetCompressedDataSize(Format fmt, int width, int height) { | 74 int GetCompressedDataSize(Format fmt, int width, int height) { |
68 int dimX, dimY; | 75 int dimX, dimY; |
69 GetBlockDimensions(fmt, &dimX, &dimY, true); | 76 GetBlockDimensions(fmt, &dimX, &dimY, true); |
70 | 77 |
71 int encodedBlockSize = 0; | 78 int encodedBlockSize = 0; |
72 | 79 |
73 switch (fmt) { | 80 switch (fmt) { |
74 // These formats are 64 bits per 4x4 block. | 81 // These formats are 64 bits per 4x4 block. |
75 case kLATC_Format: | 82 case kLATC_Format: |
76 case kR11_EAC_Format: | 83 case kR11_EAC_Format: |
77 case kETC1_Format: | 84 case kETC1_Format: |
78 encodedBlockSize = 8; | 85 encodedBlockSize = 8; |
79 break; | 86 break; |
80 | 87 |
81 // This format is 12x12 blocks to 128 bits. | 88 // This format is 128 bits. |
89 case kASTC_4x4_Format: | |
90 case kASTC_5x4_Format: | |
91 case kASTC_5x5_Format: | |
92 case kASTC_6x5_Format: | |
93 case kASTC_6x6_Format: | |
94 case kASTC_8x5_Format: | |
95 case kASTC_8x6_Format: | |
96 case kASTC_8x8_Format: | |
97 case kASTC_10x5_Format: | |
98 case kASTC_10x6_Format: | |
99 case kASTC_10x8_Format: | |
100 case kASTC_10x10_Format: | |
101 case kASTC_12x10_Format: | |
82 case kASTC_12x12_Format: | 102 case kASTC_12x12_Format: |
83 encodedBlockSize = 16; | 103 encodedBlockSize = 16; |
84 break; | 104 break; |
85 | 105 |
86 default: | 106 default: |
87 SkFAIL("Unknown compressed format!"); | 107 SkFAIL("Unknown compressed format!"); |
88 return -1; | 108 return -1; |
89 } | 109 } |
90 | 110 |
91 if(((width % dimX) == 0) && ((height % dimY) == 0)) { | 111 if(((width % dimX) == 0) && ((height % dimY) == 0)) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 return true; | 225 return true; |
206 | 226 |
207 case kR11_EAC_Format: | 227 case kR11_EAC_Format: |
208 DecompressR11EAC(dst, dstRowBytes, src, width, height); | 228 DecompressR11EAC(dst, dstRowBytes, src, width, height); |
209 return true; | 229 return true; |
210 | 230 |
211 #ifndef SK_IGNORE_ETC1_SUPPORT | 231 #ifndef SK_IGNORE_ETC1_SUPPORT |
212 case kETC1_Format: | 232 case kETC1_Format: |
213 return 0 == etc1_decode_image(src, dst, width, height, 3, dstRowByte s); | 233 return 0 == etc1_decode_image(src, dst, width, height, 3, dstRowByte s); |
214 #endif | 234 #endif |
235 | |
robertphillips
2014/08/06 21:13:15
Can we not have all these fall through and call Ge
krajcevski
2014/08/06 22:31:00
Can't believe I didn't think of that.
| |
236 case kASTC_4x4_Format: | |
237 DecompressASTC(dst, dstRowBytes, src, width, height, 4, 4); | |
238 return true; | |
239 | |
240 case kASTC_5x4_Format: | |
241 DecompressASTC(dst, dstRowBytes, src, width, height, 5, 4); | |
242 return true; | |
243 | |
244 case kASTC_5x5_Format: | |
245 DecompressASTC(dst, dstRowBytes, src, width, height, 5, 5); | |
246 return true; | |
247 | |
248 case kASTC_6x5_Format: | |
249 DecompressASTC(dst, dstRowBytes, src, width, height, 6, 5); | |
250 return true; | |
251 | |
252 case kASTC_6x6_Format: | |
253 DecompressASTC(dst, dstRowBytes, src, width, height, 6, 6); | |
254 return true; | |
255 | |
256 case kASTC_8x5_Format: | |
257 DecompressASTC(dst, dstRowBytes, src, width, height, 8, 5); | |
258 return true; | |
259 | |
260 case kASTC_8x6_Format: | |
261 DecompressASTC(dst, dstRowBytes, src, width, height, 8, 6); | |
262 return true; | |
263 | |
264 case kASTC_8x8_Format: | |
265 DecompressASTC(dst, dstRowBytes, src, width, height, 8, 8); | |
266 return true; | |
267 | |
268 case kASTC_10x5_Format: | |
269 DecompressASTC(dst, dstRowBytes, src, width, height, 10, 5); | |
270 return true; | |
271 | |
272 case kASTC_10x6_Format: | |
273 DecompressASTC(dst, dstRowBytes, src, width, height, 10, 6); | |
274 return true; | |
275 | |
276 case kASTC_10x8_Format: | |
277 DecompressASTC(dst, dstRowBytes, src, width, height, 10, 8); | |
278 return true; | |
279 | |
280 case kASTC_10x10_Format: | |
281 DecompressASTC(dst, dstRowBytes, src, width, height, 10, 10); | |
282 return true; | |
283 | |
284 case kASTC_12x10_Format: | |
285 DecompressASTC(dst, dstRowBytes, src, width, height, 12, 10); | |
286 return true; | |
287 | |
215 case kASTC_12x12_Format: | 288 case kASTC_12x12_Format: |
216 // TODO(krajcevski) .. right now just fall through and return false. | 289 DecompressASTC(dst, dstRowBytes, src, width, height, 12, 12); |
217 return false; | 290 return true; |
218 | 291 |
219 default: | 292 default: |
220 // Do nothing... | 293 // Do nothing... |
221 break; | 294 break; |
222 } | 295 } |
223 | 296 |
224 return false; | 297 return false; |
225 } | 298 } |
226 | 299 |
227 } // namespace SkTextureCompressor | 300 } // namespace SkTextureCompressor |
OLD | NEW |