Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
AutoCleanPng Class Reference
Inheritance diagram for AutoCleanPng:
SkNoncopyable

Public Member Functions

 AutoCleanPng (png_structp png_ptr, SkStream *stream, SkPngChunkReader *reader, SkCodec **codecPtr)
 
 ~AutoCleanPng ()
 
void setInfoPtr (png_infop info_ptr)
 
bool decodeBounds ()
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Detailed Description

Definition at line 88 of file SkPngCodec.cpp.

Constructor & Destructor Documentation

◆ AutoCleanPng()

AutoCleanPng::AutoCleanPng ( png_structp  png_ptr,
SkStream stream,
SkPngChunkReader reader,
SkCodec **  codecPtr 
)
inline

Definition at line 96 of file SkPngCodec.cpp.

98 : fPng_ptr(png_ptr)
99 , fInfo_ptr(nullptr)
100 , fStream(stream)
101 , fChunkReader(reader)
102 , fOutCodec(codecPtr)
103 {}

◆ ~AutoCleanPng()

AutoCleanPng::~AutoCleanPng ( )
inline

Definition at line 105 of file SkPngCodec.cpp.

105 {
106 // fInfo_ptr will never be non-nullptr unless fPng_ptr is.
107 if (fPng_ptr) {
108 png_infopp info_pp = fInfo_ptr ? &fInfo_ptr : nullptr;
109 png_destroy_read_struct(&fPng_ptr, info_pp, nullptr);
110 }
111 }

Member Function Documentation

◆ decodeBounds()

bool AutoCleanPng::decodeBounds ( )

Reads enough of the input stream to decode the bounds.

Returns
false if the stream is not a valid PNG (or too short). true if it read enough of the stream to determine the bounds. In the latter case, the stream may have been read beyond the point to determine the bounds, and the png_ptr will have saved any extra data. Further, if the codecPtr supplied to the constructor was not NULL, it will now point to a new SkCodec, which owns (or refs, in the case of the SkPngChunkReader) the inputs. If codecPtr was NULL, the png_ptr and info_ptr are unowned, and it is up to the caller to destroy them.

Definition at line 165 of file SkPngCodec.cpp.

165 {
166 SkASSERT(fStream);
167 if (setjmp(PNG_JMPBUF(fPng_ptr))) {
168 return false;
169 }
170
171 png_set_progressive_read_fn(fPng_ptr, nullptr, nullptr, nullptr, nullptr);
172
173 // Arbitrary buffer size, though note that it matches (below)
174 // SkPngCodec::processData(). FIXME: Can we better suit this to the size of
175 // the PNG header?
176 constexpr size_t kBufferSize = 4096;
177 char buffer[kBufferSize];
178
179 {
180 // Parse the signature.
181 if (fStream->read(buffer, 8) < 8) {
182 return false;
183 }
184
185 png_process_data(fPng_ptr, fInfo_ptr, (png_bytep) buffer, 8);
186 }
187
188 while (true) {
189 // Parse chunk length and type.
190 if (fStream->read(buffer, 8) < 8) {
191 // We have read to the end of the input without decoding bounds.
192 break;
193 }
194
195 png_byte* chunk = reinterpret_cast<png_byte*>(buffer);
196 const size_t length = png_get_uint_32(chunk);
197
198 if (is_chunk(chunk, "IDAT")) {
199 this->infoCallback(length);
200 return true;
201 }
202
203 png_process_data(fPng_ptr, fInfo_ptr, chunk, 8);
204 // Process the full chunk + CRC.
205 if (!process_data(fPng_ptr, fInfo_ptr, fStream, buffer, kBufferSize, length + 4)) {
206 return false;
207 }
208 }
209
210 return false;
211}
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool process_data(png_structp png_ptr, png_infop info_ptr, SkStream *stream, void *buffer, size_t bufferSize, size_t length)
#define PNG_JMPBUF(x)
static bool is_chunk(const png_byte *chunk, const char *tag)
static const size_t kBufferSize
Definition SkString.cpp:27
virtual size_t read(void *buffer, size_t size)=0
static const uint8_t buffer[]
size_t length

◆ setInfoPtr()

void AutoCleanPng::setInfoPtr ( png_infop  info_ptr)
inline

Definition at line 113 of file SkPngCodec.cpp.

113 {
114 SkASSERT(nullptr == fInfo_ptr);
115 fInfo_ptr = info_ptr;
116 }

The documentation for this class was generated from the following file: