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; | |
22 class SkStream; | 21 class SkStream; |
23 | 22 |
24 class SkPngCodec : public SkCodec { | 23 class SkPngCodec : public SkCodec { |
25 public: | 24 public: |
26 static bool IsPng(SkStream*); | 25 static bool IsPng(SkStream*); |
27 | 26 |
28 // Assume IsPng was called and returned true. | 27 // Assume IsPng was called and returned true. |
29 static SkCodec* NewFromStream(SkStream*); | 28 static SkCodec* NewFromStream(SkStream*); |
30 static SkScanlineDecoder* NewSDFromStream(SkStream*); | |
31 | 29 |
32 virtual ~SkPngCodec(); | 30 virtual ~SkPngCodec(); |
33 | 31 |
34 protected: | 32 protected: |
35 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) | 33 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) |
36 override; | 34 override; |
37 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } | 35 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } |
38 bool onRewind() override; | 36 bool onRewind() override; |
39 uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const
override; | 37 uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const
override; |
40 bool onReallyHasAlpha() const final; | 38 bool onReallyHasAlpha() const final; |
41 | 39 |
42 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. | 40 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. |
43 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, | 41 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, |
44 SkPMColor*, int* ctableCount); | 42 SkPMColor*, int* ctableCount, int subsetLeft, int
subsetWidth); |
45 SkSampler* getSampler(bool createIfNecessary) override { return fSwizzler; } | 43 SkSampler* getSampler(bool createIfNecessary) override { return fSwizzler; } |
46 | 44 |
47 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int, int); | 45 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int, int); |
48 | 46 |
49 png_structp png_ptr() { return fPng_ptr; } | 47 png_structp png_ptr() { return fPng_ptr; } |
50 SkSwizzler* swizzler() { return fSwizzler; } | 48 SkSwizzler* swizzler() { return fSwizzler; } |
51 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; } | 49 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; } |
52 int numberPasses() const { return fNumberPasses; } | 50 int numberPasses() const { return fNumberPasses; } |
53 | 51 |
54 enum AlphaState { | 52 enum AlphaState { |
(...skipping 13 matching lines...) Expand all Loading... |
68 png_structp fPng_ptr; | 66 png_structp fPng_ptr; |
69 png_infop fInfo_ptr; | 67 png_infop fInfo_ptr; |
70 | 68 |
71 // These are stored here so they can be used both by normal decoding and sca
nline decoding. | 69 // These are stored here so they can be used both by normal decoding and sca
nline decoding. |
72 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. | 70 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |
73 SkAutoTDelete<SkSwizzler> fSwizzler; | 71 SkAutoTDelete<SkSwizzler> fSwizzler; |
74 | 72 |
75 SkSwizzler::SrcConfig fSrcConfig; | 73 SkSwizzler::SrcConfig fSrcConfig; |
76 const int fNumberPasses; | 74 const int fNumberPasses; |
77 int fBitDepth; | 75 int fBitDepth; |
78 | |
79 AlphaState fAlphaState; | 76 AlphaState fAlphaState; |
80 | 77 |
81 bool decodePalette(bool premultiply, int* ctableCount); | 78 bool decodePalette(bool premultiply, int* ctableCount); |
82 void destroyReadStruct(); | 79 void destroyReadStruct(); |
83 | 80 |
84 typedef SkCodec INHERITED; | 81 typedef SkCodec INHERITED; |
85 }; | 82 }; |
OLD | NEW |