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 "SkBitmap.h" |
8 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
9 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkColorSpace.h" |
10 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
11 #include "SkBitmap.h" | |
12 #include "SkMath.h" | 13 #include "SkMath.h" |
13 #include "SkOpts.h" | 14 #include "SkOpts.h" |
14 #include "SkPngCodec.h" | 15 #include "SkPngCodec.h" |
15 #include "SkSize.h" | 16 #include "SkSize.h" |
16 #include "SkStream.h" | 17 #include "SkStream.h" |
17 #include "SkSwizzler.h" | 18 #include "SkSwizzler.h" |
18 #include "SkTemplates.h" | 19 #include "SkTemplates.h" |
19 #include "SkUtils.h" | 20 #include "SkUtils.h" |
20 | 21 |
21 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // We multiply by the same factor that libpng used to convert | 170 // We multiply by the same factor that libpng used to convert |
170 // fixed point -> double. Since we want floats, we choose to | 171 // fixed point -> double. Since we want floats, we choose to |
171 // do the conversion ourselves rather than convert | 172 // do the conversion ourselves rather than convert |
172 // fixed point -> double -> float. | 173 // fixed point -> double -> float. |
173 return ((float) x) * 0.00001f; | 174 return ((float) x) * 0.00001f; |
174 } | 175 } |
175 | 176 |
176 // Returns a colorSpace object that represents any color space information in | 177 // Returns a colorSpace object that represents any color space information in |
177 // the encoded data. If the encoded data contains no color space, this will | 178 // the encoded data. If the encoded data contains no color space, this will |
178 // return NULL. | 179 // return NULL. |
179 SkColorSpace* read_color_space(png_structp png_ptr, png_infop info_ptr) { | 180 sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) { |
180 | 181 |
181 // First check for an ICC profile | 182 // First check for an ICC profile |
182 png_bytep profile; | 183 png_bytep profile; |
183 png_uint_32 length; | 184 png_uint_32 length; |
184 // The below variables are unused, however, we need to pass them in anyway o
r | 185 // The below variables are unused, however, we need to pass them in anyway o
r |
185 // png_get_iCCP() will return nothing. | 186 // png_get_iCCP() will return nothing. |
186 // Could knowing the |name| of the profile ever be interesting? Maybe for d
ebugging? | 187 // Could knowing the |name| of the profile ever be interesting? Maybe for d
ebugging? |
187 png_charp name; | 188 png_charp name; |
188 // The |compression| is uninteresting since: | 189 // The |compression| is uninteresting since: |
189 // (1) libpng has already decompressed the profile for us. | 190 // (1) libpng has already decompressed the profile for us. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 416 } |
416 if (info_ptrp) { | 417 if (info_ptrp) { |
417 *info_ptrp = info_ptr; | 418 *info_ptrp = info_ptr; |
418 } | 419 } |
419 | 420 |
420 return true; | 421 return true; |
421 } | 422 } |
422 | 423 |
423 SkPngCodec::SkPngCodec(const SkImageInfo& info, SkStream* stream, SkPngChunkRead
er* chunkReader, | 424 SkPngCodec::SkPngCodec(const SkImageInfo& info, SkStream* stream, SkPngChunkRead
er* chunkReader, |
424 png_structp png_ptr, png_infop info_ptr, int bitDepth, in
t numberPasses, | 425 png_structp png_ptr, png_infop info_ptr, int bitDepth, in
t numberPasses, |
425 SkColorSpace* colorSpace) | 426 sk_sp<SkColorSpace> colorSpace) |
426 : INHERITED(info, stream, colorSpace) | 427 : INHERITED(info, stream, colorSpace) |
427 , fPngChunkReader(SkSafeRef(chunkReader)) | 428 , fPngChunkReader(SkSafeRef(chunkReader)) |
428 , fPng_ptr(png_ptr) | 429 , fPng_ptr(png_ptr) |
429 , fInfo_ptr(info_ptr) | 430 , fInfo_ptr(info_ptr) |
430 , fSrcConfig(SkSwizzler::kUnknown) | 431 , fSrcConfig(SkSwizzler::kUnknown) |
431 , fNumberPasses(numberPasses) | 432 , fNumberPasses(numberPasses) |
432 , fBitDepth(bitDepth) | 433 , fBitDepth(bitDepth) |
433 {} | 434 {} |
434 | 435 |
435 SkPngCodec::~SkPngCodec() { | 436 SkPngCodec::~SkPngCodec() { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 return get_color_table_fill_value(colorType, colorPtr, 0); | 628 return get_color_table_fill_value(colorType, colorPtr, 0); |
628 } | 629 } |
629 return INHERITED::onGetFillValue(colorType); | 630 return INHERITED::onGetFillValue(colorType); |
630 } | 631 } |
631 | 632 |
632 // Subclass of SkPngCodec which supports scanline decoding | 633 // Subclass of SkPngCodec which supports scanline decoding |
633 class SkPngScanlineDecoder : public SkPngCodec { | 634 class SkPngScanlineDecoder : public SkPngCodec { |
634 public: | 635 public: |
635 SkPngScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, | 636 SkPngScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, |
636 SkPngChunkReader* chunkReader, png_structp png_ptr, png_infop info_p
tr, int bitDepth, | 637 SkPngChunkReader* chunkReader, png_structp png_ptr, png_infop info_p
tr, int bitDepth, |
637 SkColorSpace* colorSpace) | 638 sk_sp<SkColorSpace> colorSpace) |
638 : INHERITED(srcInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth, 1
, colorSpace) | 639 : INHERITED(srcInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth, 1
, colorSpace) |
639 , fSrcRow(nullptr) | 640 , fSrcRow(nullptr) |
640 {} | 641 {} |
641 | 642 |
642 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, | 643 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, |
643 SkPMColor ctable[], int* ctableCount) override { | 644 SkPMColor ctable[], int* ctableCount) override { |
644 if (!conversion_possible(dstInfo, this->getInfo())) { | 645 if (!conversion_possible(dstInfo, this->getInfo())) { |
645 return kInvalidConversion; | 646 return kInvalidConversion; |
646 } | 647 } |
647 | 648 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 uint8_t* fSrcRow; | 694 uint8_t* fSrcRow; |
694 | 695 |
695 typedef SkPngCodec INHERITED; | 696 typedef SkPngCodec INHERITED; |
696 }; | 697 }; |
697 | 698 |
698 | 699 |
699 class SkPngInterlacedScanlineDecoder : public SkPngCodec { | 700 class SkPngInterlacedScanlineDecoder : public SkPngCodec { |
700 public: | 701 public: |
701 SkPngInterlacedScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, | 702 SkPngInterlacedScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, |
702 SkPngChunkReader* chunkReader, png_structp png_ptr, png_infop info_p
tr, | 703 SkPngChunkReader* chunkReader, png_structp png_ptr, png_infop info_p
tr, |
703 int bitDepth, int numberPasses, SkColorSpace* colorSpace) | 704 int bitDepth, int numberPasses, sk_sp<SkColorSpace> colorSpace) |
704 : INHERITED(srcInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth, n
umberPasses, | 705 : INHERITED(srcInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth, n
umberPasses, |
705 colorSpace) | 706 colorSpace) |
706 , fHeight(-1) | 707 , fHeight(-1) |
707 , fCanSkipRewind(false) | 708 , fCanSkipRewind(false) |
708 { | 709 { |
709 SkASSERT(numberPasses != 1); | 710 SkASSERT(numberPasses != 1); |
710 } | 711 } |
711 | 712 |
712 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, | 713 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, |
713 SkPMColor ctable[], int* ctableCount) override { | 714 SkPMColor ctable[], int* ctableCount) override { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 png_infop info_ptr; | 827 png_infop info_ptr; |
827 SkImageInfo imageInfo; | 828 SkImageInfo imageInfo; |
828 int bitDepth; | 829 int bitDepth; |
829 int numberPasses; | 830 int numberPasses; |
830 | 831 |
831 if (!read_header(stream, chunkReader, &png_ptr, &info_ptr, &imageInfo, &bitD
epth, | 832 if (!read_header(stream, chunkReader, &png_ptr, &info_ptr, &imageInfo, &bitD
epth, |
832 &numberPasses)) { | 833 &numberPasses)) { |
833 return nullptr; | 834 return nullptr; |
834 } | 835 } |
835 | 836 |
836 SkAutoTUnref<SkColorSpace> colorSpace(read_color_space(png_ptr, info_ptr)); | 837 auto colorSpace = read_color_space(png_ptr, info_ptr); |
837 | 838 |
838 if (1 == numberPasses) { | 839 if (1 == numberPasses) { |
839 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk
Reader, | 840 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk
Reader, |
840 png_ptr, info_ptr, bitDepth, colorSpace)
; | 841 png_ptr, info_ptr, bitDepth, colorSpace)
; |
841 } | 842 } |
842 | 843 |
843 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
chunkReader, | 844 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
chunkReader, |
844 png_ptr, info_ptr, bitDepth, numbe
rPasses, | 845 png_ptr, info_ptr, bitDepth, numbe
rPasses, |
845 colorSpace); | 846 colorSpace); |
846 } | 847 } |
OLD | NEW |