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_libpng.h" | 8 #include "SkCodec_libpng.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (bitDepth < 8) { | 280 if (bitDepth < 8) { |
281 png_set_packing(png_ptr); | 281 png_set_packing(png_ptr); |
282 } | 282 } |
283 #endif | 283 #endif |
284 // Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel. | 284 // Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel. |
285 if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) { | 285 if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) { |
286 png_set_expand_gray_1_2_4_to_8(png_ptr); | 286 png_set_expand_gray_1_2_4_to_8(png_ptr); |
287 } | 287 } |
288 | 288 |
289 // Now determine the default SkColorType and SkAlphaType and set required tr
ansforms | 289 // Now determine the default SkColorType and SkAlphaType and set required tr
ansforms |
290 SkColorType skColorType; | 290 SkColorType skColorType = kUnknown_SkColorType; |
291 SkAlphaType skAlphaType; | 291 SkAlphaType skAlphaType = kUnknown_SkAlphaType; |
292 switch (colorType) { | 292 switch (colorType) { |
293 case PNG_COLOR_TYPE_PALETTE: | 293 case PNG_COLOR_TYPE_PALETTE: |
294 skColorType = kIndex_8_SkColorType; | 294 skColorType = kIndex_8_SkColorType; |
295 skAlphaType = has_transparency_in_tRNS(png_ptr, info_ptr) ? | 295 skAlphaType = has_transparency_in_tRNS(png_ptr, info_ptr) ? |
296 kUnpremul_SkAlphaType : kOpaque_SkAlphaType; | 296 kUnpremul_SkAlphaType : kOpaque_SkAlphaType; |
297 break; | 297 break; |
298 case PNG_COLOR_TYPE_RGB: | 298 case PNG_COLOR_TYPE_RGB: |
299 if (has_transparency_in_tRNS(png_ptr, info_ptr)) { | 299 if (has_transparency_in_tRNS(png_ptr, info_ptr)) { |
300 //convert to RGBA with tranparency information in tRNS chunk if
it exists | 300 //convert to RGBA with tranparency information in tRNS chunk if
it exists |
301 png_set_tRNS_to_alpha(png_ptr); | 301 png_set_tRNS_to_alpha(png_ptr); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 SkASSERT(false); | 598 SkASSERT(false); |
599 return true; | 599 return true; |
600 } | 600 } |
601 | 601 |
602 // Subclass of SkPngCodec which supports scanline decoding | 602 // Subclass of SkPngCodec which supports scanline decoding |
603 class SkPngScanlineDecoder : public SkPngCodec { | 603 class SkPngScanlineDecoder : public SkPngCodec { |
604 public: | 604 public: |
605 SkPngScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, | 605 SkPngScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, |
606 png_structp png_ptr, png_infop info_ptr, int bitDepth) | 606 png_structp png_ptr, png_infop info_ptr, int bitDepth) |
607 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, 1) | 607 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, 1) |
| 608 , fAlphaState(kUnknown_AlphaState) |
608 , fSrcRow(nullptr) | 609 , fSrcRow(nullptr) |
609 , fAlphaState(kUnknown_AlphaState) | |
610 {} | 610 {} |
611 | 611 |
612 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, | 612 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, |
613 SkPMColor ctable[], int* ctableCount) override { | 613 SkPMColor ctable[], int* ctableCount) override { |
614 if (!conversion_possible(dstInfo, this->getInfo())) { | 614 if (!conversion_possible(dstInfo, this->getInfo())) { |
615 return kInvalidConversion; | 615 return kInvalidConversion; |
616 } | 616 } |
617 | 617 |
618 const Result result = this->initializeSwizzler(dstInfo, options, ctable, | 618 const Result result = this->initializeSwizzler(dstInfo, options, ctable, |
619 ctableCount); | 619 ctableCount); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 } | 836 } |
837 | 837 |
838 if (1 == numberPasses) { | 838 if (1 == numberPasses) { |
839 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), png_p
tr, info_ptr, | 839 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), png_p
tr, info_ptr, |
840 bitDepth); | 840 bitDepth); |
841 } | 841 } |
842 | 842 |
843 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
png_ptr, | 843 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
png_ptr, |
844 info_ptr, bitDepth, numberPasses); | 844 info_ptr, bitDepth, numberPasses); |
845 } | 845 } |
846 | |
OLD | NEW |