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" | |
13 #include "SkStream.h" | 12 #include "SkStream.h" |
14 #include "SkCodec_wbmp.h" | 13 #include "SkCodec_wbmp.h" |
15 | 14 |
16 // Each bit represents a pixel, so width is actually a number of bits. | 15 // Each bit represents a pixel, so width is actually a number of bits. |
17 // A row will always be stored in bytes, so we round width up to the | 16 // A row will always be stored in bytes, so we round width up to the |
18 // nearest multiple of 8 to get the number of bits actually in the row. | 17 // nearest multiple of 8 to get the number of bits actually in the row. |
19 // We then divide by 8 to convert to bytes. | 18 // We then divide by 8 to convert to bytes. |
20 static inline size_t get_src_row_bytes(int width) { | 19 static inline size_t get_src_row_bytes(int width) { |
21 return SkAlign8(width) >> 3; | 20 return SkAlign8(width) >> 3; |
22 } | 21 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 71 } |
73 | 72 |
74 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, | 73 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, |
75 const SkPMColor* ctable, const Options& opts) { | 74 const SkPMColor* ctable, const Options& opts) { |
76 // Create the swizzler based on the desired color type | 75 // Create the swizzler based on the desired color type |
77 switch (info.colorType()) { | 76 switch (info.colorType()) { |
78 case kIndex_8_SkColorType: | 77 case kIndex_8_SkColorType: |
79 case kN32_SkColorType: | 78 case kN32_SkColorType: |
80 case kRGB_565_SkColorType: | 79 case kRGB_565_SkColorType: |
81 case kGray_8_SkColorType: | 80 case kGray_8_SkColorType: |
82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op
ts.fZeroInitialized, | 81 break; |
83 this->getInfo()); | |
84 default: | 82 default: |
85 return nullptr; | 83 return nullptr; |
86 } | 84 } |
| 85 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, |
| 86 opts.fZeroInitialized); |
87 } | 87 } |
88 | 88 |
89 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { | 89 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { |
90 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { | 90 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { |
91 return kIncompleteInput; | 91 return kIncompleteInput; |
92 } | 92 } |
93 return kSuccess; | 93 return kSuccess; |
94 } | 94 } |
95 | 95 |
96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) | 96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 174 } |
175 return kSuccess; | 175 return kSuccess; |
176 } | 176 } |
177 | 177 |
178 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 178 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
179 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { | 179 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { |
180 if (options.fSubset) { | 180 if (options.fSubset) { |
181 // Subsets are not supported. | 181 // Subsets are not supported. |
182 return kUnimplemented; | 182 return kUnimplemented; |
183 } | 183 } |
184 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | |
185 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI
nfo)) { | |
186 return kInvalidScale; | |
187 } | |
188 } | |
189 | 184 |
190 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 185 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
191 return kInvalidConversion; | 186 return kInvalidConversion; |
192 } | 187 } |
193 | 188 |
194 // Fill in the color table | 189 // Fill in the color table |
195 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); | 190 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); |
196 | 191 |
197 // Copy the color table to a pointer that can be owned by the scanline decod
er | 192 // Copy the color table to a pointer that can be owned by the scanline decod
er |
198 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 193 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
199 fColorTable.reset(new SkColorTable(inputColorTable, 2)); | 194 fColorTable.reset(new SkColorTable(inputColorTable, 2)); |
200 } | 195 } |
201 | 196 |
202 // Initialize the swizzler | 197 // Initialize the swizzler |
203 fSwizzler.reset(this->initializeSwizzler(dstInfo, | 198 fSwizzler.reset(this->initializeSwizzler(dstInfo, |
204 get_color_ptr(fColorTable.get()), options)); | 199 get_color_ptr(fColorTable.get()), options)); |
205 if (nullptr == fSwizzler.get()) { | 200 if (nullptr == fSwizzler.get()) { |
206 return kInvalidConversion; | 201 return kInvalidConversion; |
207 } | 202 } |
208 | 203 |
209 fSrcBuffer.reset(fSrcRowBytes); | 204 fSrcBuffer.reset(fSrcRowBytes); |
210 | 205 |
211 return kSuccess; | 206 return kSuccess; |
212 } | 207 } |
213 | 208 |
OLD | NEW |