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 "SkColorSpaceXform.h" |
9 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
10 #include "SkPngChunkReader.h" | 11 #include "SkPngChunkReader.h" |
11 #include "SkEncodedFormat.h" | 12 #include "SkEncodedFormat.h" |
12 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
13 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
14 #include "SkSwizzler.h" | 15 #include "SkSwizzler.h" |
15 | 16 |
16 #include "png.h" | 17 #include "png.h" |
17 | 18 |
18 class SkStream; | 19 class SkStream; |
19 | 20 |
20 class SkPngCodec : public SkCodec { | 21 class SkPngCodec : public SkCodec { |
21 public: | 22 public: |
22 static bool IsPng(const char*, size_t); | 23 static bool IsPng(const char*, size_t); |
23 | 24 |
24 // Assume IsPng was called and returned true. | 25 // Assume IsPng was called and returned true. |
25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); | 26 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); |
26 | 27 |
27 virtual ~SkPngCodec(); | 28 virtual ~SkPngCodec(); |
28 | 29 |
29 protected: | 30 protected: |
30 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) | 31 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) |
31 override; | 32 override; |
32 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } | 33 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } |
33 bool onRewind() override; | 34 bool onRewind() override; |
34 uint32_t onGetFillValue(SkColorType) const override; | 35 uint32_t onGetFillValue(SkColorType) const override; |
35 | 36 |
36 // Helper to set up swizzler and color table. Also calls png_read_update_inf
o. | 37 // Helper to set up swizzler, color xforms, and color table. Also calls png_
read_update_info. |
37 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, | 38 bool initializeXforms(const SkImageInfo& requestedInfo, const Options&, SkPM
Color* colorPtr, |
38 SkPMColor*, int* ctableCount); | 39 int* colorCount); |
39 SkSampler* getSampler(bool createIfNecessary) override { | 40 SkSampler* getSampler(bool createIfNecessary) override { |
40 SkASSERT(fSwizzler); | 41 SkASSERT(fSwizzler); |
41 return fSwizzler; | 42 return fSwizzler; |
42 } | 43 } |
| 44 void allocateStorage(const SkImageInfo& dstInfo); |
| 45 |
| 46 virtual int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
int count, |
| 47 int startRow) = 0; |
43 | 48 |
44 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun
kReader*, | 49 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun
kReader*, |
45 png_structp, png_infop, int, int, sk_sp<SkColorSpace>); | 50 png_structp, png_infop, int, int, sk_sp<SkColorSpace>); |
46 | 51 |
47 png_structp png_ptr() { return fPng_ptr; } | 52 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; |
48 SkSwizzler* swizzler() { return fSwizzler; } | 53 png_structp fPng_ptr; |
49 int numberPasses() const { return fNumberPasses; } | 54 png_infop fInfo_ptr; |
| 55 |
| 56 // These are stored here so they can be used both by normal decoding and sca
nline decoding. |
| 57 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |
| 58 SkAutoTDelete<SkSwizzler> fSwizzler; |
| 59 std::unique_ptr<SkColorSpaceXform> fColorXform; |
| 60 SkAutoTMalloc<uint8_t> fStorage; |
| 61 uint8_t* fSwizzlerSrcRow; |
| 62 uint32_t* fColorXformSrcRow; |
| 63 size_t fSrcRowBytes; |
| 64 |
| 65 const int fNumberPasses; |
| 66 int fBitDepth; |
50 | 67 |
51 private: | 68 private: |
52 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; | |
53 png_structp fPng_ptr; | |
54 png_infop fInfo_ptr; | |
55 | |
56 // These are stored here so they can be used both by normal decoding and sca
nline decoding. | |
57 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. | |
58 SkAutoTDelete<SkSwizzler> fSwizzler; | |
59 | |
60 const int fNumberPasses; | |
61 int fBitDepth; | |
62 | |
63 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl
eCount); | 69 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl
eCount); |
64 void destroyReadStruct(); | 70 void destroyReadStruct(); |
65 | 71 |
66 typedef SkCodec INHERITED; | 72 typedef SkCodec INHERITED; |
67 }; | 73 }; |
OLD | NEW |