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" | 10 #include "SkPngChunkReader.h" |
11 #include "SkEncodedFormat.h" | 11 #include "SkEncodedFormat.h" |
12 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
14 #include "SkSwizzler.h" | 14 #include "SkSwizzler.h" |
15 | 15 |
16 #include "png.h" | 16 #include "png.h" |
17 | 17 |
18 class SkStream; | 18 class SkStream; |
19 | 19 |
20 class SkPngCodec : public SkCodec { | 20 class SkPngCodec : public SkCodec { |
21 public: | 21 public: |
22 static bool IsPng(const char*, size_t); | 22 static bool IsPng(const char*, size_t); |
23 | 23 |
24 // Assume IsPng was called and returned true. | 24 // Assume IsPng was called and returned true. |
25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); | 25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); |
26 | 26 |
27 virtual ~SkPngCodec(); | 27 virtual ~SkPngCodec(); |
28 | 28 |
29 protected: | 29 protected: |
30 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun
kReader*, | |
31 png_structp, png_infop, int bitDepth, sk_sp<SkColorSpace>); | |
32 | |
33 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) | 30 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) |
34 override; | 31 override; |
35 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } | 32 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } |
36 bool onRewind() override; | 33 bool onRewind() override; |
37 uint32_t onGetFillValue(SkColorType) const override; | 34 uint32_t onGetFillValue(SkColorType) const override; |
38 | 35 |
39 // 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. |
40 bool initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, | 37 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, |
41 SkPMColor*, int* ctableCount); | 38 SkPMColor*, int* ctableCount); |
42 SkSampler* getSampler(bool createIfNecessary) override { | 39 SkSampler* getSampler(bool createIfNecessary) override { |
43 SkASSERT(fSwizzler); | 40 SkASSERT(fSwizzler); |
44 return fSwizzler; | 41 return fSwizzler; |
45 } | 42 } |
46 | 43 |
| 44 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun
kReader*, |
| 45 png_structp, png_infop, int, int, sk_sp<SkColorSpace>); |
| 46 |
47 png_structp png_ptr() { return fPng_ptr; } | 47 png_structp png_ptr() { return fPng_ptr; } |
48 png_infop info_ptr() { return fInfo_ptr; } | |
49 SkSwizzler* swizzler() { return fSwizzler; } | 48 SkSwizzler* swizzler() { return fSwizzler; } |
50 | 49 int numberPasses() const { return fNumberPasses; } |
51 /** | |
52 * Pass available input to libpng to process it. | |
53 * | |
54 * libpng will call any relevant callbacks installed. This will continue de
coding | |
55 * until it reaches the end of the file, or until a callback tells libpng t
o stop. | |
56 */ | |
57 void processData(); | |
58 | |
59 Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, si
ze_t rowBytes, | |
60 const SkCodec::Options&, | |
61 SkPMColor* ctable, int* ctableCount) override; | |
62 Result onIncrementalDecode(int*) override; | |
63 | 50 |
64 private: | 51 private: |
65 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; | 52 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; |
66 png_structp fPng_ptr; | 53 png_structp fPng_ptr; |
67 png_infop fInfo_ptr; | 54 png_infop fInfo_ptr; |
68 | 55 |
| 56 // These are stored here so they can be used both by normal decoding and sca
nline decoding. |
69 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. | 57 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |
70 SkAutoTDelete<SkSwizzler> fSwizzler; | 58 SkAutoTDelete<SkSwizzler> fSwizzler; |
71 | 59 |
72 const int fBitDepth; | 60 const int fNumberPasses; |
| 61 int fBitDepth; |
73 | 62 |
74 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl
eCount); | 63 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl
eCount); |
75 void destroyReadStruct(); | 64 void destroyReadStruct(); |
76 | 65 |
77 virtual Result decodeAllRows(void* dst, size_t rowBytes, int* rowsDecoded) =
0; | |
78 virtual void setRange(int firstRow, int lastRow, void* dst, size_t rowBytes)
= 0; | |
79 virtual Result decode(int* rowsDecoded) = 0; | |
80 | |
81 typedef SkCodec INHERITED; | 66 typedef SkCodec INHERITED; |
82 }; | 67 }; |
OLD | NEW |