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 "SkChunkReader.h" |
10 #include "SkEncodedFormat.h" | 11 #include "SkEncodedFormat.h" |
11 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
12 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
13 #include "SkSwizzler.h" | 14 #include "SkSwizzler.h" |
14 | 15 |
15 extern "C" { | 16 extern "C" { |
16 #include "png.h" | 17 #include "png.h" |
17 } | 18 } |
18 | 19 |
19 class SkScanlineDecoder; | 20 class SkScanlineDecoder; |
20 class SkStream; | 21 class SkStream; |
21 | 22 |
22 class SkPngCodec : public SkCodec { | 23 class SkPngCodec : public SkCodec { |
23 public: | 24 public: |
24 // Assumes IsPng was called and returned true. | 25 // Assumes IsPng was called and returned true. |
25 static SkCodec* NewFromStream(SkStream*); | 26 static SkCodec* NewFromStream(SkStream*, SkChunkReader* = NULL); |
26 static bool IsPng(SkStream*); | 27 static bool IsPng(SkStream*); |
27 protected: | 28 protected: |
28 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) | 29 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) |
29 override; | 30 override; |
30 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } | 31 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } |
31 SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo) override
; | 32 SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo) override
; |
32 bool onReallyHasAlpha() const override { return fReallyHasAlpha; } | 33 bool onReallyHasAlpha() const override { return fReallyHasAlpha; } |
33 private: | 34 private: |
| 35 SkAutoTUnref<SkChunkReader> fChunkReader; |
34 png_structp fPng_ptr; | 36 png_structp fPng_ptr; |
35 png_infop fInfo_ptr; | 37 png_infop fInfo_ptr; |
36 | 38 |
37 // These are stored here so they can be used both by normal decoding and sca
nline decoding. | 39 // These are stored here so they can be used both by normal decoding and sca
nline decoding. |
38 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. | 40 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |
39 SkAutoTDelete<SkSwizzler> fSwizzler; | 41 SkAutoTDelete<SkSwizzler> fSwizzler; |
40 | 42 |
41 SkSwizzler::SrcConfig fSrcConfig; | 43 SkSwizzler::SrcConfig fSrcConfig; |
42 int fNumberPasses; | 44 int fNumberPasses; |
43 bool fReallyHasAlpha; | 45 bool fReallyHasAlpha; |
44 | 46 |
45 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop); | 47 SkPngCodec(const SkImageInfo&, SkStream*, SkChunkReader*, png_structp, png_i
nfop); |
46 ~SkPngCodec(); | 48 ~SkPngCodec(); |
47 | 49 |
48 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. | 50 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. |
49 Result initializeSwizzler(const SkImageInfo& requestedInfo, void* dst, | 51 Result initializeSwizzler(const SkImageInfo& requestedInfo, void* dst, |
50 size_t rowBytes, const Options&); | 52 size_t rowBytes, const Options&); |
51 bool decodePalette(bool premultiply); | 53 bool decodePalette(bool premultiply); |
52 void finish(); | 54 void finish(); |
53 | 55 |
54 friend class SkPngScanlineDecoder; | 56 friend class SkPngScanlineDecoder; |
55 | 57 |
56 typedef SkCodec INHERITED; | 58 typedef SkCodec INHERITED; |
57 }; | 59 }; |
OLD | NEW |