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 |
| 236 case kASTC_4x4_Format: |
| 237 case kASTC_5x4_Format: |
| 238 case kASTC_5x5_Format: |
| 239 case kASTC_6x5_Format: |
| 240 case kASTC_6x6_Format: |
| 241 case kASTC_8x5_Format: |
| 242 case kASTC_8x6_Format: |
| 243 case kASTC_8x8_Format: |
| 244 case kASTC_10x5_Format: |
| 245 case kASTC_10x6_Format: |
| 246 case kASTC_10x8_Format: |
| 247 case kASTC_10x10_Format: |
| 248 case kASTC_12x10_Format: |
215 case kASTC_12x12_Format: | 249 case kASTC_12x12_Format: |
216 // TODO(krajcevski) .. right now just fall through and return false. | 250 DecompressASTC(dst, dstRowBytes, src, width, height, dimX, dimY); |
217 return false; | 251 return true; |
218 | 252 |
219 default: | 253 default: |
220 // Do nothing... | 254 // Do nothing... |
221 break; | 255 break; |
222 } | 256 } |
223 | 257 |
224 return false; | 258 return false; |
225 } | 259 } |
226 | 260 |
227 } // namespace SkTextureCompressor | 261 } // namespace SkTextureCompressor |
OLD | NEW |