OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkCodec.h" | 8 #include "SkCodec.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
| 12 #include "SkScaledCodec.h" |
12 #include "SkStream.h" | 13 #include "SkStream.h" |
13 #include "SkCodec_wbmp.h" | 14 #include "SkCodec_wbmp.h" |
14 | 15 |
15 // Each bit represents a pixel, so width is actually a number of bits. | 16 // Each bit represents a pixel, so width is actually a number of bits. |
16 // A row will always be stored in bytes, so we round width up to the | 17 // A row will always be stored in bytes, so we round width up to the |
17 // nearest multiple of 8 to get the number of bits actually in the row. | 18 // nearest multiple of 8 to get the number of bits actually in the row. |
18 // We then divide by 8 to convert to bytes. | 19 // We then divide by 8 to convert to bytes. |
19 static inline size_t get_src_row_bytes(int width) { | 20 static inline size_t get_src_row_bytes(int width) { |
20 return SkAlign8(width) >> 3; | 21 return SkAlign8(width) >> 3; |
21 } | 22 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, | 74 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, |
74 const SkPMColor* ctable, const Options& opts) { | 75 const SkPMColor* ctable, const Options& opts) { |
75 // TODO (msarett): Reenable support for 565 if it is desired | 76 // TODO (msarett): Reenable support for 565 if it is desired |
76 // skbug.com/3683 | 77 // skbug.com/3683 |
77 | 78 |
78 // Create the swizzler based on the desired color type | 79 // Create the swizzler based on the desired color type |
79 switch (info.colorType()) { | 80 switch (info.colorType()) { |
80 case kIndex_8_SkColorType: | 81 case kIndex_8_SkColorType: |
81 case kN32_SkColorType: | 82 case kN32_SkColorType: |
82 case kGray_8_SkColorType: | 83 case kGray_8_SkColorType: |
83 return SkSwizzler::CreateSwizzler( | 84 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op
ts.fZeroInitialized, |
84 SkSwizzler::kBit, ctable, info, opts.fZeroInitialized); | 85 this->getInfo()); |
85 default: | 86 default: |
86 return NULL; | 87 return NULL; |
87 } | 88 } |
88 } | 89 } |
89 | 90 |
90 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { | 91 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { |
91 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { | 92 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { |
92 return kIncompleteInput; | 93 return kIncompleteInput; |
93 } | 94 } |
94 return kSuccess; | 95 return kSuccess; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 const SkCodec::Options& options, SkPMColor inputColorTable[], | 195 const SkCodec::Options& options, SkPMColor inputColorTable[], |
195 int* inputColorCount) { | 196 int* inputColorCount) { |
196 if (!fCodec->rewindIfNeeded()) { | 197 if (!fCodec->rewindIfNeeded()) { |
197 return SkCodec::kCouldNotRewind; | 198 return SkCodec::kCouldNotRewind; |
198 } | 199 } |
199 if (options.fSubset) { | 200 if (options.fSubset) { |
200 // Subsets are not supported. | 201 // Subsets are not supported. |
201 return SkCodec::kUnimplemented; | 202 return SkCodec::kUnimplemented; |
202 } | 203 } |
203 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 204 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
204 return SkCodec::kInvalidScale; | 205 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(),
dstInfo)) { |
| 206 return SkCodec::kInvalidScale; |
| 207 } |
205 } | 208 } |
206 | 209 |
207 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 210 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
208 return SkCodec::kInvalidConversion; | 211 return SkCodec::kInvalidConversion; |
209 } | 212 } |
210 | 213 |
211 // Fill in the color table | 214 // Fill in the color table |
212 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount)
; | 215 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount)
; |
213 | 216 |
214 // Copy the color table to a pointer that can be owned by the scanline d
ecoder | 217 // Copy the color table to a pointer that can be owned by the scanline d
ecoder |
215 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 218 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
216 fColorTable.reset(SkNEW_ARGS(SkColorTable, (inputColorTable, 2))); | 219 fColorTable.reset(SkNEW_ARGS(SkColorTable, (inputColorTable, 2))); |
217 } | 220 } |
218 | 221 |
219 // Initialize the swizzler | 222 // Initialize the swizzler |
220 fSwizzler.reset(fCodec->initializeSwizzler(dstInfo, | 223 fSwizzler.reset(fCodec->initializeSwizzler(dstInfo, |
221 get_color_ptr(fColorTable.get()), options)); | 224 get_color_ptr(fColorTable.get()), options)); |
222 if (NULL == fSwizzler.get()) { | 225 if (NULL == fSwizzler.get()) { |
223 return SkCodec::kInvalidInput; | 226 return SkCodec::kInvalidConversion; |
224 } | 227 } |
225 | 228 |
226 return SkCodec::kSuccess; | 229 return SkCodec::kSuccess; |
227 } | 230 } |
228 | 231 |
| 232 SkEncodedFormat onGetEncodedFormat() const { |
| 233 return kWBMP_SkEncodedFormat; |
| 234 } |
| 235 |
229 private: | 236 private: |
230 SkAutoTDelete<SkWbmpCodec> fCodec; | 237 SkAutoTDelete<SkWbmpCodec> fCodec; |
231 SkAutoTUnref<SkColorTable> fColorTable; | 238 SkAutoTUnref<SkColorTable> fColorTable; |
232 SkAutoTDelete<SkSwizzler> fSwizzler; | 239 SkAutoTDelete<SkSwizzler> fSwizzler; |
233 SkAutoTMalloc<uint8_t> fSrcBuffer; | 240 SkAutoTMalloc<uint8_t> fSrcBuffer; |
234 | 241 |
235 typedef SkScanlineDecoder INHERITED; | 242 typedef SkScanlineDecoder INHERITED; |
236 }; | 243 }; |
237 | 244 |
238 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { | 245 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { |
239 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( | 246 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( |
240 SkWbmpCodec::NewFromStream(stream))); | 247 SkWbmpCodec::NewFromStream(stream))); |
241 if (!codec) { | 248 if (!codec) { |
242 return NULL; | 249 return NULL; |
243 } | 250 } |
244 | 251 |
245 // Return the new scanline decoder | 252 // Return the new scanline decoder |
246 return SkNEW_ARGS(SkWbmpScanlineDecoder, (codec.detach())); | 253 return SkNEW_ARGS(SkWbmpScanlineDecoder, (codec.detach())); |
247 } | 254 } |
OLD | NEW |