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 27 matching lines...) Expand all Loading... | |
38 default: | 38 default: |
39 return false; | 39 return false; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 /* | 43 /* |
44 * Creates an instance of the decoder | 44 * Creates an instance of the decoder |
45 * Called only by NewFromStream | 45 * Called only by NewFromStream |
46 */ | 46 */ |
47 SkBmpStandardCodec::SkBmpStandardCodec(const SkImageInfo& info, SkStream* stream , | 47 SkBmpStandardCodec::SkBmpStandardCodec(const SkImageInfo& info, SkStream* stream , |
48 SkBmpCodec::BmpInputFormat inputFormat, | |
48 uint16_t bitsPerPixel, uint32_t numColors , | 49 uint16_t bitsPerPixel, uint32_t numColors , |
49 uint32_t bytesPerColor, uint32_t offset, | 50 uint32_t bytesPerColor, uint32_t offset, |
50 SkBmpCodec::RowOrder rowOrder, bool inIco ) | 51 SkBmpCodec::RowOrder rowOrder, bool inIco ) |
51 : INHERITED(info, stream, bitsPerPixel, rowOrder) | 52 : INHERITED(info, stream, inputFormat, bitsPerPixel, rowOrder) |
52 , fColorTable(NULL) | 53 , fColorTable(NULL) |
53 , fNumColors(this->computeNumColors(numColors)) | 54 , fNumColors(this->computeNumColors(numColors)) |
54 , fBytesPerColor(bytesPerColor) | 55 , fBytesPerColor(bytesPerColor) |
55 , fOffset(offset) | 56 , fOffset(offset) |
56 , fSwizzler(NULL) | 57 , fSwizzler(NULL) |
57 , fSrcBuffer(NULL) | 58 , fSrcBuffer(NULL) |
58 , fInIco(inIco) | 59 , fInIco(inIco) |
59 {} | 60 {} |
60 | 61 |
61 /* | 62 /* |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 SkASSERT(false); | 274 SkASSERT(false); |
274 return 0; | 275 return 0; |
275 } | 276 } |
276 return fillColorOrIndex; | 277 return fillColorOrIndex; |
277 } | 278 } |
278 | 279 |
279 /* | 280 /* |
280 * Performs the bitmap decoding for standard input format | 281 * Performs the bitmap decoding for standard input format |
281 */ | 282 */ |
282 SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo, | 283 SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo, |
283 void* dst, size_t dstRowBytes, | 284 void* dst, size_t dstRowBytes, |
284 const Options& opts) { | 285 const Options& opts) { |
285 // Set constant values | 286 // Set constant values |
286 const int width = dstInfo.width(); | 287 const int width = dstInfo.width(); |
287 const int height = dstInfo.height(); | 288 const int height = dstInfo.height(); |
288 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel ())); | 289 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel ())); |
289 | 290 |
290 // Iterate over rows of the image | 291 // Iterate over rows of the image |
291 for (int y = 0; y < height; y++) { | 292 for (int y = 0; y < height; y++) { |
292 // Read a row of the input | 293 // Read a row of the input |
293 if (this->stream()->read(fSrcBuffer.get(), rowBytes) != rowBytes) { | 294 if (this->stream()->read(fSrcBuffer.get(), rowBytes) != rowBytes) { |
294 SkCodecPrintf("Warning: incomplete input stream.\n"); | 295 SkCodecPrintf("Warning: incomplete input stream.\n"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 uint32_t alphaBit = | 353 uint32_t alphaBit = |
353 (fSrcBuffer.get()[quotient] >> shift) & 0x1; | 354 (fSrcBuffer.get()[quotient] >> shift) & 0x1; |
354 dstRow[x] &= alphaBit - 1; | 355 dstRow[x] &= alphaBit - 1; |
355 } | 356 } |
356 } | 357 } |
357 } | 358 } |
358 | 359 |
359 // Finished decoding the entire image | 360 // Finished decoding the entire image |
360 return kSuccess; | 361 return kSuccess; |
361 } | 362 } |
363 | |
364 SkBmpStandardScanlineDecoder::SkBmpStandardScanlineDecoder(SkBmpStandardCodec* c odec) | |
365 : INHERITED(codec->getInfo()) | |
366 , fCodec(codec) | |
367 {} | |
368 | |
369 SkCodec::Result SkBmpStandardScanlineDecoder::onStart(const SkImageInfo& dstInfo , | |
scroggo
2015/08/13 21:25:36
Here's how I see these. Let me know if I'm wrong:
msarett
2015/08/14 15:44:48
This is clever!
| |
370 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) { | |
371 // Rewind the stream if needed | |
372 if (!fCodec->rewindIfNeeded()) { | |
373 return SkCodec::kCouldNotRewind; | |
374 } | |
375 | |
376 if (options.fSubset) { | |
377 // Subsets are not supported. | |
378 return SkCodec::kUnimplemented; | |
379 } | |
380 if (dstInfo.dimensions() != fCodec->getInfo().dimensions()) { | |
381 SkCodecPrintf("Error: scaling not supported.\n"); | |
382 return SkCodec::kInvalidScale; | |
383 } | |
384 if (!conversion_possible(dstInfo, fCodec->getInfo())) { | |
385 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | |
386 return SkCodec::kInvalidConversion; | |
387 } | |
388 | |
389 // Create the color table if necessary and prepare the stream for decode | |
390 // Note that if it is non-NULL, inputColorCount will be modified | |
391 if (!fCodec->createColorTable(dstInfo.alphaType(), inputColorCount)) { | |
392 SkCodecPrintf("Error: could not create color table.\n"); | |
393 return SkCodec::kInvalidInput; | |
394 } | |
395 | |
396 // Copy the color table to the client if necessary | |
397 copy_color_table(dstInfo, fCodec->fColorTable, inputColorPtr, inputColorCoun t); | |
398 | |
399 // Initialize a swizzler if necessary | |
400 if (!fCodec->initializeSwizzler(dstInfo, options)) { | |
401 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | |
402 return SkCodec::kInvalidConversion; | |
403 } | |
404 | |
405 fDstInfo = dstInfo; | |
406 fOpts = options; | |
407 | |
408 return SkCodec::kSuccess; | |
409 } | |
410 | |
411 SkCodec::Result SkBmpStandardScanlineDecoder::onGetScanlines(void* dst, | |
412 int count, size_t rowBytes) { | |
413 // Create a new image info representing the portion of the image to decode | |
414 SkImageInfo rowInfo = fDstInfo.makeWH(dstInfo().width(), count); | |
415 | |
416 // Decode the requested rows | |
417 SkCodec::Result r = fCodec->decode(rowInfo, dst, rowBytes, fOpts); | |
scroggo
2015/08/13 21:25:36
This needs to be returned. (probably true for the
msarett
2015/08/14 15:44:48
Hmm yes. Thanks for being a better error checker
scroggo
2015/08/14 21:53:00
I just filed skbug.com/4208, where I proposed doin
| |
418 } | |
OLD | NEW |