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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 if (!conversion_possible(dstInfo, this->getInfo())) { | 52 if (!conversion_possible(dstInfo, this->getInfo())) { |
53 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | 53 SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
54 return kInvalidConversion; | 54 return kInvalidConversion; |
55 } | 55 } |
56 | 56 |
57 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol
orCount); | 57 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol
orCount); |
58 if (kSuccess != result) { | 58 if (kSuccess != result) { |
59 return result; | 59 return result; |
60 } | 60 } |
61 result = this->decodeRows(dstInfo, dst, dstRowBytes, opts); | 61 uint32_t rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts); |
62 if (kSuccess != result) { | 62 if (rows != dstInfo.height()) { |
63 return result; | 63 this->setIncompleteScanlines(dstInfo.height() - rows); |
| 64 return kIncompleteInput; |
64 } | 65 } |
65 if (fInIco) { | 66 if (fInIco) { |
66 return this->decodeIcoMask(dstInfo, dst, dstRowBytes); | 67 return this->decodeIcoMask(dstInfo, dst, dstRowBytes); |
67 } | 68 } |
68 return kSuccess; | 69 return kSuccess; |
69 } | 70 } |
70 | 71 |
71 /* | 72 /* |
72 * Process the color table for the bmp input | 73 * Process the color table for the bmp input |
73 */ | 74 */ |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 if (!this->initializeSwizzler(dstInfo, options)) { | 225 if (!this->initializeSwizzler(dstInfo, options)) { |
225 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | 226 SkCodecPrintf("Error: cannot initialize swizzler.\n"); |
226 return SkCodec::kInvalidConversion; | 227 return SkCodec::kInvalidConversion; |
227 } | 228 } |
228 return SkCodec::kSuccess; | 229 return SkCodec::kSuccess; |
229 } | 230 } |
230 | 231 |
231 /* | 232 /* |
232 * Performs the bitmap decoding for standard input format | 233 * Performs the bitmap decoding for standard input format |
233 */ | 234 */ |
234 SkCodec::Result SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, | 235 uint32_t SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, |
235 void* dst, size_t dstRowBytes, | 236 void* dst, size_t dstRowBytes, |
236 const Options& opts) { | 237 const Options& opts) { |
237 // Iterate over rows of the image | 238 // Iterate over rows of the image |
238 const int height = dstInfo.height(); | 239 const int height = dstInfo.height(); |
239 for (int y = 0; y < height; y++) { | 240 for (int y = 0; y < height; y++) { |
240 // Read a row of the input | 241 // Read a row of the input |
241 if (this->stream()->read(fSrcBuffer.get(), fSrcRowBytes) != fSrcRowBytes
) { | 242 if (this->stream()->read(fSrcBuffer.get(), fSrcRowBytes) != fSrcRowBytes
) { |
242 SkCodecPrintf("Warning: incomplete input stream.\n"); | 243 SkCodecPrintf("Warning: incomplete input stream.\n"); |
243 // Fill the destination image on failure | 244 return y; |
244 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y); | |
245 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); | |
246 uint32_t fillColorOrIndex = get_fill_color_or_index(dstInfo.alphaTyp
e()); | |
247 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height() -
y, | |
248 fillColorOrIndex, colorPtr, opts.fZeroInitialized); | |
249 return kIncompleteInput; | |
250 } | 245 } |
251 | 246 |
252 // Decode the row in destination format | 247 // Decode the row in destination format |
253 uint32_t row = this->getDstRow(y, dstInfo.height()); | 248 uint32_t row = this->getDstRow(y, dstInfo.height()); |
254 | 249 |
255 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); | 250 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); |
256 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 251 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
257 } | 252 } |
258 | 253 |
259 // Finished decoding the entire image | 254 // Finished decoding the entire image |
260 return kSuccess; | 255 return height; |
261 } | 256 } |
262 | 257 |
263 // TODO (msarett): This function will need to be modified in order to perform ro
w by row decodes | 258 // TODO (msarett): This function will need to be modified in order to perform ro
w by row decodes |
264 // when the Ico scanline decoder is implemented. | 259 // when the Ico scanline decoder is implemented. |
265 SkCodec::Result SkBmpStandardCodec::decodeIcoMask(const SkImageInfo& dstInfo, | 260 SkCodec::Result SkBmpStandardCodec::decodeIcoMask(const SkImageInfo& dstInfo, |
266 void* dst, size_t dstRowBytes) { | 261 void* dst, size_t dstRowBytes) { |
267 // BMP in ICO have transparency, so this cannot be 565, and this mask | 262 // BMP in ICO have transparency, so this cannot be 565, and this mask |
268 // prevents us from using kIndex8. The below code depends on the output | 263 // prevents us from using kIndex8. The below code depends on the output |
269 // being an SkPMColor. | 264 // being an SkPMColor. |
270 SkASSERT(dstInfo.colorType() == kN32_SkColorType); | 265 SkASSERT(dstInfo.colorType() == kN32_SkColorType); |
(...skipping 20 matching lines...) Expand all Loading... |
291 int modulus; | 286 int modulus; |
292 SkTDivMod(x, 8, "ient, &modulus); | 287 SkTDivMod(x, 8, "ient, &modulus); |
293 uint32_t shift = 7 - modulus; | 288 uint32_t shift = 7 - modulus; |
294 uint32_t alphaBit = | 289 uint32_t alphaBit = |
295 (fSrcBuffer.get()[quotient] >> shift) & 0x1; | 290 (fSrcBuffer.get()[quotient] >> shift) & 0x1; |
296 dstRow[x] &= alphaBit - 1; | 291 dstRow[x] &= alphaBit - 1; |
297 } | 292 } |
298 } | 293 } |
299 return kSuccess; | 294 return kSuccess; |
300 } | 295 } |
| 296 |
| 297 uint32_t SkBmpStandardCodec::onGetFillValue(const SkImageInfo& dstInfo) const { |
| 298 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); |
| 299 if (colorPtr) { |
| 300 return get_color_table_fill_value(dstInfo.colorType(), colorPtr, 0); |
| 301 } |
| 302 return INHERITED::onGetFillValue(dstInfo); |
| 303 } |
OLD | NEW |