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 "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
9 #include "SkBmpMaskCodec.h" | 9 #include "SkBmpMaskCodec.h" |
10 #include "SkBmpRLECodec.h" | 10 #include "SkBmpRLECodec.h" |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 // We can do this here because there is no color table to read | 465 // We can do this here because there is no color table to read |
466 // in bit mask mode. | 466 // in bit mask mode. |
467 if (!inIco && kBitMask_BmpInputFormat == inputFormat) { | 467 if (!inIco && kBitMask_BmpInputFormat == inputFormat) { |
468 if (stream->skip(offset - bytesRead) != offset - bytesRead) { | 468 if (stream->skip(offset - bytesRead) != offset - bytesRead) { |
469 SkCodecPrintf("Error: unable to skip to image data.\n"); | 469 SkCodecPrintf("Error: unable to skip to image data.\n"); |
470 return false; | 470 return false; |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 if (codecOut) { | 474 if (codecOut) { |
| 475 // BMPs-in-ICOs contain an alpha mask after the image which means we |
| 476 // cannot guarantee that an image is opaque, even if the bmp thinks |
| 477 // it is. |
| 478 bool isOpaque = kOpaque_SkAlphaType == alphaType; |
| 479 if (inIco) { |
| 480 alphaType = kUnpremul_SkAlphaType; |
| 481 } |
| 482 |
475 // Set the image info | 483 // Set the image info |
476 const SkImageInfo& imageInfo = SkImageInfo::Make(width, height, | 484 const SkImageInfo& imageInfo = SkImageInfo::Make(width, height, |
477 colorType, alphaType); | 485 colorType, alphaType); |
478 | 486 |
479 // Return the codec | 487 // Return the codec |
480 switch (inputFormat) { | 488 switch (inputFormat) { |
481 case kStandard_BmpInputFormat: | 489 case kStandard_BmpInputFormat: |
482 // We require streams to have a memory base for Bmp-in-Ico decod
es. | 490 // We require streams to have a memory base for Bmp-in-Ico decod
es. |
483 SkASSERT(!inIco || nullptr != stream->getMemoryBase()); | 491 SkASSERT(!inIco || nullptr != stream->getMemoryBase()); |
484 *codecOut = new SkBmpStandardCodec(imageInfo, stream, bitsPerPix
el, numColors, | 492 *codecOut = new SkBmpStandardCodec(imageInfo, stream, bitsPerPix
el, numColors, |
485 bytesPerColor, offset - bytesRead, rowOrder, inIco); | 493 bytesPerColor, offset - bytesRead, rowOrder, isOpaque, i
nIco); |
486 return true; | 494 return true; |
487 case kBitMask_BmpInputFormat: | 495 case kBitMask_BmpInputFormat: |
488 // Bmp-in-Ico must be standard mode | 496 // Bmp-in-Ico must be standard mode |
489 if (inIco) { | 497 if (inIco) { |
490 SkCodecPrintf("Error: Icos may not use bit mask format.\n"); | 498 SkCodecPrintf("Error: Icos may not use bit mask format.\n"); |
491 return false; | 499 return false; |
492 } | 500 } |
493 | 501 |
494 *codecOut = new SkBmpMaskCodec(imageInfo, stream, bitsPerPixel,
masks.detach(), | 502 *codecOut = new SkBmpMaskCodec(imageInfo, stream, bitsPerPixel,
masks.detach(), |
495 rowOrder); | 503 rowOrder); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 return prepareToDecode(dstInfo, options, inputColorPtr, inputColorCount); | 566 return prepareToDecode(dstInfo, options, inputColorPtr, inputColorCount); |
559 } | 567 } |
560 | 568 |
561 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { | 569 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
562 // Create a new image info representing the portion of the image to decode | 570 // Create a new image info representing the portion of the image to decode |
563 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count)
; | 571 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count)
; |
564 | 572 |
565 // Decode the requested rows | 573 // Decode the requested rows |
566 return this->decodeRows(rowInfo, dst, rowBytes, this->options()); | 574 return this->decodeRows(rowInfo, dst, rowBytes, this->options()); |
567 } | 575 } |
OLD | NEW |