Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPngCodec.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef SkPngCodec_DEFINED
8#define SkPngCodec_DEFINED
9
14
15#include <cstddef>
16#include <cstdint>
17#include <memory>
18
19class SkColorPalette;
21class SkSampler;
22class SkStream;
23class SkSwizzler;
24struct SkEncodedInfo;
25struct SkImageInfo;
26
27class SkPngCodec : public SkCodec {
28public:
29 static bool IsPng(const void*, size_t);
30
31 // Assume IsPng was called and returned true.
32 static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*,
33 SkPngChunkReader* = nullptr);
34
35 // FIXME (scroggo): Temporarily needed by AutoCleanPng.
36 void setIdatLength(size_t len) { fIdatLength = len; }
37
38 ~SkPngCodec() override;
39
40protected:
41 // We hold the png_ptr and info_ptr as voidp to avoid having to include png.h
42 // or forward declare their types here. voidp auto-casts to the real pointer types.
43 struct voidp {
44 voidp(void* ptr) : fPtr(ptr) {}
45
46 template <typename T>
47 operator T*() const { return (T*)fPtr; }
48
49 explicit operator bool() const { return fPtr != nullptr; }
50
51 void* fPtr;
52 };
53
54 SkPngCodec(SkEncodedInfo&&, std::unique_ptr<SkStream>, SkPngChunkReader*,
55 void* png_ptr, void* info_ptr, int bitDepth);
56
57 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, int*)
58 override;
60 bool onRewind() override;
61
62 SkSampler* getSampler(bool createIfNecessary) override;
63 void applyXformRow(void* dst, const void* src);
64
65 voidp png_ptr() { return fPng_ptr; }
66 voidp info_ptr() { return fInfo_ptr; }
67
68 SkSwizzler* swizzler() { return fSwizzler.get(); }
69
70 // Initialize variables used by applyXformRow.
72
73 /**
74 * Pass available input to libpng to process it.
75 *
76 * libpng will call any relevant callbacks installed. This will continue decoding
77 * until it reaches the end of the file, or until a callback tells libpng to stop.
78 */
79 bool processData();
80
81 Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
82 const SkCodec::Options&) override;
83 Result onIncrementalDecode(int*) override;
84
88
89 // These are stored here so they can be used both by normal decoding and scanline decoding.
91 std::unique_ptr<SkSwizzler> fSwizzler;
94 const int fBitDepth;
95
96private:
97
98 enum XformMode {
99 // Requires only a swizzle pass.
100 kSwizzleOnly_XformMode,
101
102 // Requires only a color xform pass.
103 kColorOnly_XformMode,
104
105 // Requires a swizzle and a color xform.
106 kSwizzleColor_XformMode,
107 };
108
109 bool createColorTable(const SkImageInfo& dstInfo);
110 // Helper to set up swizzler, color xforms, and color table. Also calls png_read_update_info.
111 SkCodec::Result initializeXforms(const SkImageInfo& dstInfo, const Options&);
112 void initializeSwizzler(const SkImageInfo& dstInfo, const Options&, bool skipFormatConversion);
113 void allocateStorage(const SkImageInfo& dstInfo);
114 void destroyReadStruct();
115
116 virtual Result decodeAllRows(void* dst, size_t rowBytes, int* rowsDecoded) = 0;
117 virtual void setRange(int firstRow, int lastRow, void* dst, size_t rowBytes) = 0;
118 virtual Result decode(int* rowsDecoded) = 0;
119
120 XformMode fXformMode;
121 int fXformWidth;
122
123 size_t fIdatLength;
124 bool fDecodedIdat;
125
126 using INHERITED = SkCodec;
127};
128#endif // SkPngCodec_DEFINED
SkEncodedImageFormat
const SkImageInfo & dstInfo() const
Definition SkCodec.h:878
void * fColorXformSrcRow
Definition SkPngCodec.h:93
voidp fPng_ptr
Definition SkPngCodec.h:86
void applyXformRow(void *dst, const void *src)
SkSampler * getSampler(bool createIfNecessary) override
skia_private::AutoTMalloc< uint8_t > fStorage
Definition SkPngCodec.h:92
~SkPngCodec() override
voidp fInfo_ptr
Definition SkPngCodec.h:87
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, Result *, SkPngChunkReader *=nullptr)
SkSwizzler * swizzler()
Definition SkPngCodec.h:68
virtual Result decode(int *rowsDecoded)=0
const int fBitDepth
Definition SkPngCodec.h:94
Result onGetPixels(const SkImageInfo &, void *, size_t, const Options &, int *) override
bool onRewind() override
Result onStartIncrementalDecode(const SkImageInfo &dstInfo, void *pixels, size_t rowBytes, const SkCodec::Options &) override
virtual Result decodeAllRows(void *dst, size_t rowBytes, int *rowsDecoded)=0
void initializeXformParams()
voidp info_ptr()
Definition SkPngCodec.h:66
voidp png_ptr()
Definition SkPngCodec.h:65
Result onIncrementalDecode(int *) override
std::unique_ptr< SkSwizzler > fSwizzler
Definition SkPngCodec.h:91
sk_sp< SkPngChunkReader > fPngChunkReader
Definition SkPngCodec.h:85
virtual void setRange(int firstRow, int lastRow, void *dst, size_t rowBytes)=0
bool processData()
sk_sp< SkColorPalette > fColorTable
Definition SkPngCodec.h:90
SkEncodedImageFormat onGetEncodedFormat() const override
Definition SkPngCodec.h:59
static bool IsPng(const void *, size_t)
void setIdatLength(size_t len)
Definition SkPngCodec.h:36
#define T
voidp(void *ptr)
Definition SkPngCodec.h:44