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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, | 82 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, |
82 const SkPMColor* ctable, const Options& opts) { | 83 const SkPMColor* ctable, const Options& opts) { |
83 // TODO (msarett): Reenable support for 565 if it is desired | 84 // TODO (msarett): Reenable support for 565 if it is desired |
84 // skbug.com/3683 | 85 // skbug.com/3683 |
85 | 86 |
86 // Create the swizzler based on the desired color type | 87 // Create the swizzler based on the desired color type |
87 switch (info.colorType()) { | 88 switch (info.colorType()) { |
88 case kIndex_8_SkColorType: | 89 case kIndex_8_SkColorType: |
89 case kN32_SkColorType: | 90 case kN32_SkColorType: |
90 case kGray_8_SkColorType: | 91 case kGray_8_SkColorType: |
91 return SkSwizzler::CreateSwizzler( | 92 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op
ts.fZeroInitialized, |
92 SkSwizzler::kBit, ctable, info, opts.fZeroInitialized); | 93 this->getInfo().width()); |
93 default: | 94 default: |
94 return NULL; | 95 return NULL; |
95 } | 96 } |
96 } | 97 } |
97 | 98 |
98 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { | 99 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { |
99 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { | 100 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { |
100 return kIncompleteInput; | 101 return kIncompleteInput; |
101 } | 102 } |
102 return kSuccess; | 103 return kSuccess; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 const SkCodec::Options& options, SkPMColor inputColorTable[], | 199 const SkCodec::Options& options, SkPMColor inputColorTable[], |
199 int* inputColorCount) { | 200 int* inputColorCount) { |
200 if (!fCodec->handleRewind()) { | 201 if (!fCodec->handleRewind()) { |
201 return SkCodec::kCouldNotRewind; | 202 return SkCodec::kCouldNotRewind; |
202 } | 203 } |
203 if (options.fSubset) { | 204 if (options.fSubset) { |
204 // Subsets are not supported. | 205 // Subsets are not supported. |
205 return SkCodec::kUnimplemented; | 206 return SkCodec::kUnimplemented; |
206 } | 207 } |
207 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 208 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
208 return SkCodec::kInvalidScale; | 209 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(),
dstInfo)) { |
| 210 return SkCodec::kInvalidScale; |
| 211 } |
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::kInvalidInput; |
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 |