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 "SkPngChunkReader.h" | |
11 #include "SkEncodedFormat.h" | 10 #include "SkEncodedFormat.h" |
12 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
13 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
14 #include "SkSwizzler.h" | 13 #include "SkSwizzler.h" |
15 | 14 |
16 #include "png.h" | 15 #include "png.h" |
17 | 16 |
18 class SkStream; | 17 class SkStream; |
19 | 18 |
20 class SkPngCodec : public SkCodec { | 19 class SkPngCodec : public SkCodec { |
21 public: | 20 public: |
22 static bool IsPng(SkStream*); | 21 static bool IsPng(SkStream*); |
23 | 22 |
24 // Assume IsPng was called and returned true. | 23 // Assume IsPng was called and returned true. |
25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); | 24 static SkCodec* NewFromStream(SkStream*); |
26 | 25 |
27 virtual ~SkPngCodec(); | 26 virtual ~SkPngCodec(); |
28 | 27 |
29 protected: | 28 protected: |
30 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) | 29 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) |
31 override; | 30 override; |
32 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } | 31 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } |
33 bool onRewind() override; | 32 bool onRewind() override; |
34 uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const
override; | 33 uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const
override; |
35 bool onReallyHasAlpha() const final; | 34 bool onReallyHasAlpha() const final; |
36 | 35 |
37 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. | 36 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. |
38 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, | 37 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, |
39 SkPMColor*, int* ctableCount); | 38 SkPMColor*, int* ctableCount); |
40 SkSampler* getSampler(bool createIfNecessary) override { | 39 SkSampler* getSampler(bool createIfNecessary) override { |
41 SkASSERT(fSwizzler); | 40 SkASSERT(fSwizzler); |
42 return fSwizzler; | 41 return fSwizzler; |
43 } | 42 } |
44 | 43 |
45 SkPngCodec(const SkImageInfo&, SkStream*, SkPngChunkReader*, png_structp, pn
g_infop, int, int); | 44 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int, int); |
46 | 45 |
47 png_structp png_ptr() { return fPng_ptr; } | 46 png_structp png_ptr() { return fPng_ptr; } |
48 SkSwizzler* swizzler() { return fSwizzler; } | 47 SkSwizzler* swizzler() { return fSwizzler; } |
49 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; } | 48 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; } |
50 int numberPasses() const { return fNumberPasses; } | 49 int numberPasses() const { return fNumberPasses; } |
51 | 50 |
52 enum AlphaState { | 51 enum AlphaState { |
53 // 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 |
54 // scanline decodes). | 53 // scanline decodes). |
55 kUnknown_AlphaState, | 54 kUnknown_AlphaState, |
56 // This class found the image (possibly partial, in the case of a | 55 // This class found the image (possibly partial, in the case of a |
57 // scanline decode) to be opaque. | 56 // scanline decode) to be opaque. |
58 kOpaque_AlphaState, | 57 kOpaque_AlphaState, |
59 // Ths class found the image to have alpha. | 58 // Ths class found the image to have alpha. |
60 kHasAlpha_AlphaState, | 59 kHasAlpha_AlphaState, |
61 }; | 60 }; |
62 | 61 |
63 virtual AlphaState alphaInScanlineDecode() const = 0; | 62 virtual AlphaState alphaInScanlineDecode() const = 0; |
64 | 63 |
65 private: | 64 private: |
66 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; | 65 png_structp fPng_ptr; |
67 png_structp fPng_ptr; | 66 png_infop fInfo_ptr; |
68 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 AlphaState fAlphaState; | 75 AlphaState fAlphaState; |
78 | 76 |
79 bool decodePalette(bool premultiply, int* ctableCount); | 77 bool decodePalette(bool premultiply, int* ctableCount); |
80 void destroyReadStruct(); | 78 void destroyReadStruct(); |
81 | 79 |
82 typedef SkCodec INHERITED; | 80 typedef SkCodec INHERITED; |
83 }; | 81 }; |
OLD | NEW |