| 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.h" | 8 #include "SkCodec.h" |
| 9 #include "SkColorTable.h" | 9 #include "SkColorTable.h" |
| 10 #include "SkEncodedFormat.h" | 10 #include "SkEncodedFormat.h" |
| 11 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
| 12 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
| 13 #include "SkSwizzler.h" | 13 #include "SkSwizzler.h" |
| 14 | 14 |
| 15 #ifdef SKIA_PNG_PREFIXED | 15 #ifdef SKIA_PNG_PREFIXED |
| 16 // this must proceed png.h | 16 // this must proceed png.h |
| 17 #include "pngprefix.h" | 17 #include "pngprefix.h" |
| 18 #endif | 18 #endif |
| 19 #include "png.h" | 19 #include "png.h" |
| 20 | 20 |
| 21 class SkScanlineDecoder; | 21 class SkScanlineDecoder; |
| 22 class SkStream; | 22 class SkStream; |
| 23 | 23 |
| 24 class SkPngCodec : public SkCodec { | 24 class SkPngCodec : public SkCodec { |
| 25 public: | 25 public: |
| 26 // Assumes IsPng was called and returned true. | 26 // Assumes IsPng was called and returned true. |
| 27 static SkCodec* NewFromStream(SkStream*); | 27 static SkCodec* NewFromStream(SkStream*); |
| 28 static bool IsPng(SkStream*); | 28 static bool IsPng(SkStream*); |
| 29 |
| 30 virtual ~SkPngCodec(); |
| 31 |
| 29 protected: | 32 protected: |
| 30 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) | 33 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) |
| 31 override; | 34 override; |
| 32 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } | 35 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } |
| 33 SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo, const Op
tions& options, | 36 SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo, const Op
tions& options, |
| 34 SkPMColor ctable[], int* ctableCount
) override; | 37 SkPMColor ctable[], int* ctableCount
) override; |
| 35 bool onReallyHasAlpha() const override { return fReallyHasAlpha; } | 38 bool onReallyHasAlpha() const override { return fReallyHasAlpha; } |
| 36 private: | 39 private: |
| 37 png_structp fPng_ptr; | 40 png_structp fPng_ptr; |
| 38 png_infop fInfo_ptr; | 41 png_infop fInfo_ptr; |
| 39 | 42 |
| 40 // These are stored here so they can be used both by normal decoding and sca
nline decoding. | 43 // These are stored here so they can be used both by normal decoding and sca
nline decoding. |
| 41 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. | 44 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |
| 42 SkAutoTDelete<SkSwizzler> fSwizzler; | 45 SkAutoTDelete<SkSwizzler> fSwizzler; |
| 43 | 46 |
| 44 SkSwizzler::SrcConfig fSrcConfig; | 47 SkSwizzler::SrcConfig fSrcConfig; |
| 45 int fNumberPasses; | 48 int fNumberPasses; |
| 46 bool fReallyHasAlpha; | 49 bool fReallyHasAlpha; |
| 47 int fBitDepth; | 50 int fBitDepth; |
| 48 | 51 |
| 49 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int); | 52 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int); |
| 50 ~SkPngCodec(); | |
| 51 | 53 |
| 52 | 54 |
| 53 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. | 55 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. |
| 54 Result initializeSwizzler(const SkImageInfo& requestedInfo, void* dst, | 56 Result initializeSwizzler(const SkImageInfo& requestedInfo, void* dst, |
| 55 size_t rowBytes, const Options&, SkPMColor*, int*
ctableCount); | 57 size_t rowBytes, const Options&, SkPMColor*, int*
ctableCount); |
| 56 | 58 |
| 57 // Calls rewindIfNeeded and returns true if the decoder can continue. | 59 // Calls rewindIfNeeded and returns true if the decoder can continue. |
| 58 bool handleRewind(); | 60 bool handleRewind(); |
| 59 bool decodePalette(bool premultiply, int bitDepth, int* ctableCount); | 61 bool decodePalette(bool premultiply, int* ctableCount); |
| 60 void finish(); | 62 void finish(); |
| 61 void destroyReadStruct(); | 63 void destroyReadStruct(); |
| 62 | 64 |
| 63 friend class SkPngScanlineDecoder; | 65 friend class SkPngScanlineDecoder; |
| 64 friend class SkPngInterlacedScanlineDecoder; | 66 friend class SkPngInterlacedScanlineDecoder; |
| 65 | 67 |
| 66 typedef SkCodec INHERITED; | 68 typedef SkCodec INHERITED; |
| 67 }; | 69 }; |
| OLD | NEW |