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 "SkColorSpaceXform.h" |
10 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 voidp(void* ptr) : fPtr(ptr) {} | 32 voidp(void* ptr) : fPtr(ptr) {} |
33 | 33 |
34 template <typename T> | 34 template <typename T> |
35 operator T*() const { return (T*)fPtr; } | 35 operator T*() const { return (T*)fPtr; } |
36 | 36 |
37 explicit operator bool() const { return fPtr != nullptr; } | 37 explicit operator bool() const { return fPtr != nullptr; } |
38 | 38 |
39 void* fPtr; | 39 void* fPtr; |
40 }; | 40 }; |
41 | 41 |
| 42 SkPngCodec(const SkEncodedInfo&, const SkImageInfo&, SkStream*, SkPngChunkRe
ader*, |
| 43 void* png_ptr, void* info_ptr, int bitDepth); |
| 44 |
42 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) | 45 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*, int*) |
43 override; | 46 override; |
44 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } | 47 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF
ormat; } |
45 bool onRewind() override; | 48 bool onRewind() override; |
46 uint64_t onGetFillValue(const SkImageInfo&) const override; | 49 uint64_t onGetFillValue(const SkImageInfo&) const override; |
47 | 50 |
48 // Helper to set up swizzler, color xforms, and color table. Also calls png_
read_update_info. | |
49 bool initializeXforms(const SkImageInfo& dstInfo, const Options&, SkPMColor*
colorPtr, | |
50 int* colorCount); | |
51 void initializeSwizzler(const SkImageInfo& dstInfo, const Options&); | |
52 SkSampler* getSampler(bool createIfNecessary) override; | 51 SkSampler* getSampler(bool createIfNecessary) override; |
53 void allocateStorage(const SkImageInfo& dstInfo); | 52 void applyXformRow(void* dst, const void* src); |
54 void applyXformRow(void* dst, const void* src, SkColorType, SkAlphaType, int
width); | |
55 | 53 |
56 virtual int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
int count, | 54 voidp png_ptr() { return fPng_ptr; } |
57 int startRow) = 0; | 55 voidp info_ptr() { return fInfo_ptr; } |
58 | 56 |
59 SkPngCodec(const SkEncodedInfo&, const SkImageInfo&, SkStream*, SkPngChunkRe
ader*, | 57 SkSwizzler* swizzler() { return fSwizzler; } |
60 void* png_ptr, void* info_ptr, int, int); | 58 |
| 59 // Initialize variables used by applyXformRow. |
| 60 void initializeXformAlphaAndWidth(); |
| 61 |
| 62 /** |
| 63 * Pass available input to libpng to process it. |
| 64 * |
| 65 * libpng will call any relevant callbacks installed. This will continue de
coding |
| 66 * until it reaches the end of the file, or until a callback tells libpng t
o stop. |
| 67 */ |
| 68 void processData(); |
| 69 |
| 70 Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, si
ze_t rowBytes, |
| 71 const SkCodec::Options&, |
| 72 SkPMColor* ctable, int* ctableCount) override; |
| 73 Result onIncrementalDecode(int*) override; |
61 | 74 |
62 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; | 75 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; |
63 voidp fPng_ptr; | 76 voidp fPng_ptr; |
64 voidp fInfo_ptr; | 77 voidp fInfo_ptr; |
65 | 78 |
66 // These are stored here so they can be used both by normal decoding and sca
nline decoding. | 79 // These are stored here so they can be used both by normal decoding and sca
nline decoding. |
67 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. | 80 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |
68 SkAutoTDelete<SkSwizzler> fSwizzler; | 81 SkAutoTDelete<SkSwizzler> fSwizzler; |
69 std::unique_ptr<SkColorSpaceXform> fColorXform; | 82 std::unique_ptr<SkColorSpaceXform> fColorXform; |
70 SkAutoTMalloc<uint8_t> fStorage; | 83 SkAutoTMalloc<uint8_t> fStorage; |
71 uint8_t* fSwizzlerSrcRow; | |
72 uint32_t* fColorXformSrcRow; | 84 uint32_t* fColorXformSrcRow; |
73 size_t fSrcRowBytes; | 85 const int fBitDepth; |
74 | |
75 const int fNumberPasses; | |
76 int fBitDepth; | |
77 | 86 |
78 private: | 87 private: |
79 | 88 |
80 enum XformMode { | 89 enum XformMode { |
81 // Requires only a swizzle pass. | 90 // Requires only a swizzle pass. |
82 kSwizzleOnly_XformMode, | 91 kSwizzleOnly_XformMode, |
83 | 92 |
84 // Requires only a color xform pass. | 93 // Requires only a color xform pass. |
85 kColorOnly_XformMode, | 94 kColorOnly_XformMode, |
86 | 95 |
87 // Requires a swizzle and a color xform. | 96 // Requires a swizzle and a color xform. |
88 kSwizzleColor_XformMode, | 97 kSwizzleColor_XformMode, |
89 }; | 98 }; |
90 | 99 |
91 bool createColorTable(const SkImageInfo& dstInfo, int* ctableCount); | 100 bool createColorTable(const SkImageInfo& dstInfo, int* ctableCount); |
| 101 // Helper to set up swizzler, color xforms, and color table. Also calls png_
read_update_info. |
| 102 bool initializeXforms(const SkImageInfo& dstInfo, const Options&, SkPMColor*
colorPtr, |
| 103 int* colorCount); |
| 104 void initializeSwizzler(const SkImageInfo& dstInfo, const Options&); |
| 105 void allocateStorage(const SkImageInfo& dstInfo); |
92 void destroyReadStruct(); | 106 void destroyReadStruct(); |
93 | 107 |
94 XformMode fXformMode; | 108 virtual Result decodeAllRows(void* dst, size_t rowBytes, int* rowsDecoded) =
0; |
| 109 virtual void setRange(int firstRow, int lastRow, void* dst, size_t rowBytes)
= 0; |
| 110 virtual Result decode(int* rowsDecoded) = 0; |
| 111 |
| 112 XformMode fXformMode; |
| 113 SkAlphaType fXformAlphaType; |
| 114 int fXformWidth; |
95 | 115 |
96 typedef SkCodec INHERITED; | 116 typedef SkCodec INHERITED; |
97 }; | 117 }; |
OLD | NEW |