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" |
11 #include "SkTextureCompressor_R11EAC.h" | 11 #include "SkTextureCompressor_R11EAC.h" |
12 | 12 |
13 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
14 #include "SkData.h" | 14 #include "SkData.h" |
15 #include "SkEndian.h" | 15 #include "SkEndian.h" |
16 | 16 |
17 #include "SkTextureCompression_opts.h" | 17 #include "SkTextureCompression_opts.h" |
18 | 18 |
19 #ifndef SK_IGNORE_ETC1_SUPPORT | |
20 # include "etc1.h" | |
21 #endif | |
22 | |
23 // Convert ETC1 functions to our function signatures | |
24 static bool compress_etc1_565(uint8_t* dst, const uint8_t* src, | |
25 int width, int height, int rowBytes) { | |
26 #ifndef SK_IGNORE_ETC1_SUPPORT | |
27 return 0 == etc1_encode_image(src, width, height, 2, rowBytes, dst); | |
28 #else | |
29 return false; | |
30 #endif | |
31 } | |
32 | |
33 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
34 | 20 |
35 namespace SkTextureCompressor { | 21 namespace SkTextureCompressor { |
36 | 22 |
37 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { | 23 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { |
38 if (NULL == dimX || NULL == dimY) { | 24 if (NULL == dimX || NULL == dimY) { |
39 return; | 25 return; |
40 } | 26 } |
41 | 27 |
42 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { | 28 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { |
43 return; | 29 return; |
44 } | 30 } |
45 | 31 |
46 // No specialized arguments, return the dimensions as they are in the spec. | 32 // No specialized arguments, return the dimensions as they are in the spec. |
47 switch(format) { | 33 switch(format) { |
48 // These formats are 64 bits per 4x4 block. | 34 // These formats are 64 bits per 4x4 block. |
49 default: | 35 default: |
50 SkDEBUGFAIL("Unknown compression format!"); | 36 SkDEBUGFAIL("Unknown compression format!"); |
51 // fall through | 37 // fall through |
| 38 case kR11_EAC_Format: |
52 case kLATC_Format: | 39 case kLATC_Format: |
53 case kR11_EAC_Format: | |
54 case kETC1_Format: | |
55 *dimX = 4; | 40 *dimX = 4; |
56 *dimY = 4; | 41 *dimY = 4; |
57 break; | 42 break; |
58 | 43 |
59 // This format is 12x12 blocks to 128 bits. | 44 // This format is 12x12 blocks to 128 bits. |
60 case kASTC_12x12_Format: | 45 case kASTC_12x12_Format: |
61 *dimX = 12; | 46 *dimX = 12; |
62 *dimY = 12; | 47 *dimY = 12; |
63 break; | 48 break; |
64 } | 49 } |
65 } | 50 } |
66 | 51 |
67 int GetCompressedDataSize(Format fmt, int width, int height) { | 52 int GetCompressedDataSize(Format fmt, int width, int height) { |
68 int dimX, dimY; | 53 int dimX, dimY; |
69 GetBlockDimensions(fmt, &dimX, &dimY, true); | 54 GetBlockDimensions(fmt, &dimX, &dimY, true); |
70 | 55 |
71 int encodedBlockSize = 0; | 56 int encodedBlockSize = 0; |
72 | 57 |
73 switch (fmt) { | 58 switch (fmt) { |
74 // These formats are 64 bits per 4x4 block. | 59 // These formats are 64 bits per 4x4 block. |
| 60 case kR11_EAC_Format: |
75 case kLATC_Format: | 61 case kLATC_Format: |
76 case kR11_EAC_Format: | |
77 case kETC1_Format: | |
78 encodedBlockSize = 8; | 62 encodedBlockSize = 8; |
79 break; | 63 break; |
80 | 64 |
81 // This format is 12x12 blocks to 128 bits. | 65 // This format is 12x12 blocks to 128 bits. |
82 case kASTC_12x12_Format: | 66 case kASTC_12x12_Format: |
83 encodedBlockSize = 16; | 67 encodedBlockSize = 16; |
84 break; | 68 break; |
85 | 69 |
86 default: | 70 default: |
87 SkFAIL("Unknown compressed format!"); | 71 SkFAIL("Unknown compressed format!"); |
(...skipping 26 matching lines...) Expand all Loading... |
114 proc = CompressA8ToLATC; | 98 proc = CompressA8ToLATC; |
115 break; | 99 break; |
116 case kR11_EAC_Format: | 100 case kR11_EAC_Format: |
117 proc = CompressA8ToR11EAC; | 101 proc = CompressA8ToR11EAC; |
118 break; | 102 break; |
119 case kASTC_12x12_Format: | 103 case kASTC_12x12_Format: |
120 proc = CompressA8To12x12ASTC; | 104 proc = CompressA8To12x12ASTC; |
121 break; | 105 break; |
122 default: | 106 default: |
123 // Do nothing... | 107 // Do nothing... |
124 break; | |
125 } | |
126 } | |
127 break; | |
128 | |
129 case kRGB_565_SkColorType: | |
130 { | |
131 switch (format) { | |
132 case kETC1_Format: | |
133 proc = compress_etc1_565; | |
134 break; | |
135 default: | |
136 // Do nothing... | |
137 break; | 108 break; |
138 } | 109 } |
139 } | 110 } |
140 break; | 111 break; |
141 | 112 |
142 default: | 113 default: |
143 // Do nothing... | 114 // Do nothing... |
144 break; | 115 break; |
145 } | 116 } |
146 } | 117 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 172 |
202 switch(format) { | 173 switch(format) { |
203 case kLATC_Format: | 174 case kLATC_Format: |
204 DecompressLATC(dst, dstRowBytes, src, width, height); | 175 DecompressLATC(dst, dstRowBytes, src, width, height); |
205 return true; | 176 return true; |
206 | 177 |
207 case kR11_EAC_Format: | 178 case kR11_EAC_Format: |
208 DecompressR11EAC(dst, dstRowBytes, src, width, height); | 179 DecompressR11EAC(dst, dstRowBytes, src, width, height); |
209 return true; | 180 return true; |
210 | 181 |
211 #ifndef SK_IGNORE_ETC1_SUPPORT | |
212 case kETC1_Format: | |
213 return 0 == etc1_decode_image(src, dst, width, height, 3, dstRowByte
s); | |
214 #endif | |
215 case kASTC_12x12_Format: | 182 case kASTC_12x12_Format: |
216 // TODO(krajcevski) .. right now just fall through and return false. | 183 // TODO(krajcevski) .. right now just fall through and return false. |
217 return false; | 184 return false; |
218 } | 185 } |
219 | 186 |
220 return false; | 187 return false; |
221 } | 188 } |
222 | 189 |
223 } // namespace SkTextureCompressor | 190 } // namespace SkTextureCompressor |
OLD | NEW |