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 |
19 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
20 | 34 |
21 namespace SkTextureCompressor { | 35 namespace SkTextureCompressor { |
22 | 36 |
23 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { | 37 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { |
24 if (NULL == dimX || NULL == dimY) { | 38 if (NULL == dimX || NULL == dimY) { |
25 return; | 39 return; |
26 } | 40 } |
27 | 41 |
28 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { | 42 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { |
29 return; | 43 return; |
30 } | 44 } |
31 | 45 |
32 // 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. |
33 switch(format) { | 47 switch(format) { |
34 // These formats are 64 bits per 4x4 block. | 48 // These formats are 64 bits per 4x4 block. |
35 default: | 49 default: |
36 SkDEBUGFAIL("Unknown compression format!"); | 50 SkDEBUGFAIL("Unknown compression format!"); |
37 // fall through | 51 // fall through |
| 52 case kLATC_Format: |
38 case kR11_EAC_Format: | 53 case kR11_EAC_Format: |
39 case kLATC_Format: | 54 case kETC1_Format: |
40 *dimX = 4; | 55 *dimX = 4; |
41 *dimY = 4; | 56 *dimY = 4; |
42 break; | 57 break; |
43 | 58 |
44 // This format is 12x12 blocks to 128 bits. | 59 // This format is 12x12 blocks to 128 bits. |
45 case kASTC_12x12_Format: | 60 case kASTC_12x12_Format: |
46 *dimX = 12; | 61 *dimX = 12; |
47 *dimY = 12; | 62 *dimY = 12; |
48 break; | 63 break; |
49 } | 64 } |
50 } | 65 } |
51 | 66 |
52 int GetCompressedDataSize(Format fmt, int width, int height) { | 67 int GetCompressedDataSize(Format fmt, int width, int height) { |
53 int dimX, dimY; | 68 int dimX, dimY; |
54 GetBlockDimensions(fmt, &dimX, &dimY, true); | 69 GetBlockDimensions(fmt, &dimX, &dimY, true); |
55 | 70 |
56 int encodedBlockSize = 0; | 71 int encodedBlockSize = 0; |
57 | 72 |
58 switch (fmt) { | 73 switch (fmt) { |
59 // These formats are 64 bits per 4x4 block. | 74 // These formats are 64 bits per 4x4 block. |
| 75 case kLATC_Format: |
60 case kR11_EAC_Format: | 76 case kR11_EAC_Format: |
61 case kLATC_Format: | 77 case kETC1_Format: |
62 encodedBlockSize = 8; | 78 encodedBlockSize = 8; |
63 break; | 79 break; |
64 | 80 |
65 // This format is 12x12 blocks to 128 bits. | 81 // This format is 12x12 blocks to 128 bits. |
66 case kASTC_12x12_Format: | 82 case kASTC_12x12_Format: |
67 encodedBlockSize = 16; | 83 encodedBlockSize = 16; |
68 break; | 84 break; |
69 | 85 |
70 default: | 86 default: |
71 SkFAIL("Unknown compressed format!"); | 87 SkFAIL("Unknown compressed format!"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 case kASTC_12x12_Format: | 119 case kASTC_12x12_Format: |
104 proc = CompressA8To12x12ASTC; | 120 proc = CompressA8To12x12ASTC; |
105 break; | 121 break; |
106 default: | 122 default: |
107 // Do nothing... | 123 // Do nothing... |
108 break; | 124 break; |
109 } | 125 } |
110 } | 126 } |
111 break; | 127 break; |
112 | 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; |
| 138 } |
| 139 } |
| 140 break; |
| 141 |
113 default: | 142 default: |
114 // Do nothing... | 143 // Do nothing... |
115 break; | 144 break; |
116 } | 145 } |
117 } | 146 } |
118 | 147 |
119 if (NULL != proc) { | 148 if (NULL != proc) { |
120 return proc(dst, src, width, height, rowBytes); | 149 return proc(dst, src, width, height, rowBytes); |
121 } | 150 } |
122 | 151 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 201 |
173 switch(format) { | 202 switch(format) { |
174 case kLATC_Format: | 203 case kLATC_Format: |
175 DecompressLATC(dst, dstRowBytes, src, width, height); | 204 DecompressLATC(dst, dstRowBytes, src, width, height); |
176 return true; | 205 return true; |
177 | 206 |
178 case kR11_EAC_Format: | 207 case kR11_EAC_Format: |
179 DecompressR11EAC(dst, dstRowBytes, src, width, height); | 208 DecompressR11EAC(dst, dstRowBytes, src, width, height); |
180 return true; | 209 return true; |
181 | 210 |
| 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 |
182 case kASTC_12x12_Format: | 215 case kASTC_12x12_Format: |
183 // TODO(krajcevski) .. right now just fall through and return false. | 216 // TODO(krajcevski) .. right now just fall through and return false. |
184 return false; | 217 return false; |
| 218 |
| 219 default: |
| 220 // Do nothing... |
| 221 break; |
185 } | 222 } |
186 | 223 |
187 return false; | 224 return false; |
188 } | 225 } |
189 | 226 |
190 } // namespace SkTextureCompressor | 227 } // namespace SkTextureCompressor |
OLD | NEW |