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 | 43 |
46 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int, int); | 44 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int, int); |
47 | 45 |
48 png_structp png_ptr() { return fPng_ptr; } | 46 png_structp png_ptr() { return fPng_ptr; } |
49 SkSwizzler* swizzler() { return fSwizzler; } | 47 SkSwizzler* swizzler() { return fSwizzler; } |
50 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; } | 48 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; } |
51 int numberPasses() const { return fNumberPasses; } | 49 int numberPasses() const { return fNumberPasses; } |
52 | 50 |
53 enum AlphaState { | 51 enum AlphaState { |
54 // This class has done no decoding, or threw away its knowledge (in | 52 // This class has done no decoding, or threw away its knowledge (in |
(...skipping 12 matching lines...) Expand all Loading... |
67 png_structp fPng_ptr; | 65 png_structp fPng_ptr; |
68 png_infop fInfo_ptr; | 66 png_infop fInfo_ptr; |
69 | 67 |
70 // These are stored here so they can be used both by normal decoding and sca
nline decoding. | 68 // These are stored here so they can be used both by normal decoding and sca
nline decoding. |
71 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. | 69 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |
72 SkAutoTDelete<SkSwizzler> fSwizzler; | 70 SkAutoTDelete<SkSwizzler> fSwizzler; |
73 | 71 |
74 SkSwizzler::SrcConfig fSrcConfig; | 72 SkSwizzler::SrcConfig fSrcConfig; |
75 const int fNumberPasses; | 73 const int fNumberPasses; |
76 int fBitDepth; | 74 int fBitDepth; |
77 | |
78 AlphaState fAlphaState; | 75 AlphaState fAlphaState; |
79 | 76 |
80 bool decodePalette(bool premultiply, int* ctableCount); | 77 bool decodePalette(bool premultiply, int* ctableCount); |
81 void destroyReadStruct(); | 78 void destroyReadStruct(); |
82 | 79 |
83 typedef SkCodec INHERITED; | 80 typedef SkCodec INHERITED; |
84 }; | 81 }; |
OLD | NEW |