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 "SkBmpStandardCodec.h" | 8 #include "SkBmpStandardCodec.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (stream()->skip(fOffset - colorBytes) != fOffset - colorBytes) { | 145 if (stream()->skip(fOffset - colorBytes) != fOffset - colorBytes) { |
146 SkCodecPrintf("Error: unable to skip to image data.\n"); | 146 SkCodecPrintf("Error: unable to skip to image data.\n"); |
147 return false; | 147 return false; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 // Return true on success | 151 // Return true on success |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 bool SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op
tions& opts) { | 155 void SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op
tions& opts) { |
156 // Get swizzler configuration | 156 // Get swizzler configuration |
157 SkSwizzler::SrcConfig config; | 157 SkSwizzler::SrcConfig config = SkSwizzler::kUnknown; |
158 switch (this->bitsPerPixel()) { | 158 switch (this->bitsPerPixel()) { |
159 case 1: | 159 case 1: |
160 config = SkSwizzler::kIndex1; | 160 config = SkSwizzler::kIndex1; |
161 break; | 161 break; |
162 case 2: | 162 case 2: |
163 config = SkSwizzler::kIndex2; | 163 config = SkSwizzler::kIndex2; |
164 break; | 164 break; |
165 case 4: | 165 case 4: |
166 config = SkSwizzler::kIndex4; | 166 config = SkSwizzler::kIndex4; |
167 break; | 167 break; |
168 case 8: | 168 case 8: |
169 config = SkSwizzler::kIndex; | 169 config = SkSwizzler::kIndex; |
170 break; | 170 break; |
171 case 24: | 171 case 24: |
172 config = SkSwizzler::kBGR; | 172 config = SkSwizzler::kBGR; |
173 break; | 173 break; |
174 case 32: | 174 case 32: |
175 if (fIsOpaque) { | 175 if (fIsOpaque) { |
176 config = SkSwizzler::kBGRX; | 176 config = SkSwizzler::kBGRX; |
177 } else { | 177 } else { |
178 config = SkSwizzler::kBGRA; | 178 config = SkSwizzler::kBGRA; |
179 } | 179 } |
180 break; | 180 break; |
181 default: | 181 default: |
182 SkASSERT(false); | 182 SkASSERT(false); |
183 return false; | |
184 } | 183 } |
185 | 184 |
186 // Get a pointer to the color table if it exists | 185 // Get a pointer to the color table if it exists |
187 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); | 186 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); |
188 | 187 |
189 // Create swizzler | 188 // Create swizzler |
190 fSwizzler.reset(SkSwizzler::CreateSwizzler(config, colorPtr, dstInfo, opts))
; | 189 fSwizzler.reset(SkSwizzler::CreateSwizzler(config, colorPtr, dstInfo, opts))
; |
191 | 190 SkASSERT(fSwizzler); |
192 if (nullptr == fSwizzler.get()) { | |
193 return false; | |
194 } | |
195 return true; | |
196 } | 191 } |
197 | 192 |
198 SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo, | 193 SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo, |
199 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { | 194 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { |
200 // Create the color table if necessary and prepare the stream for decode | 195 // Create the color table if necessary and prepare the stream for decode |
201 // Note that if it is non-NULL, inputColorCount will be modified | 196 // Note that if it is non-NULL, inputColorCount will be modified |
202 if (!this->createColorTable(dstInfo.alphaType(), inputColorCount)) { | 197 if (!this->createColorTable(dstInfo.alphaType(), inputColorCount)) { |
203 SkCodecPrintf("Error: could not create color table.\n"); | 198 SkCodecPrintf("Error: could not create color table.\n"); |
204 return SkCodec::kInvalidInput; | 199 return SkCodec::kInvalidInput; |
205 } | 200 } |
206 | 201 |
207 // Copy the color table to the client if necessary | 202 // Copy the color table to the client if necessary |
208 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount)
; | 203 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount)
; |
209 | 204 |
210 // Initialize a swizzler if necessary | 205 // Initialize a swizzler |
211 if (!this->initializeSwizzler(dstInfo, options)) { | 206 this->initializeSwizzler(dstInfo, options); |
212 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | |
213 return SkCodec::kInvalidConversion; | |
214 } | |
215 return SkCodec::kSuccess; | 207 return SkCodec::kSuccess; |
216 } | 208 } |
217 | 209 |
218 /* | 210 /* |
219 * Performs the bitmap decoding for standard input format | 211 * Performs the bitmap decoding for standard input format |
220 */ | 212 */ |
221 int SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t
dstRowBytes, | 213 int SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t
dstRowBytes, |
222 const Options& opts) { | 214 const Options& opts) { |
223 // Iterate over rows of the image | 215 // Iterate over rows of the image |
224 const int height = dstInfo.height(); | 216 const int height = dstInfo.height(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 319 } |
328 } | 320 } |
329 | 321 |
330 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const { | 322 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const { |
331 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); | 323 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); |
332 if (colorPtr) { | 324 if (colorPtr) { |
333 return get_color_table_fill_value(colorType, colorPtr, 0); | 325 return get_color_table_fill_value(colorType, colorPtr, 0); |
334 } | 326 } |
335 return INHERITED::onGetFillValue(colorType); | 327 return INHERITED::onGetFillValue(colorType); |
336 } | 328 } |
OLD | NEW |