Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
SkPngCodec Class Referenceabstract

#include <SkPngCodec.h>

Inheritance diagram for SkPngCodec:
SkCodec SkNoncopyable SkPngInterlacedDecoder SkPngNormalDecoder

Classes

struct  voidp
 

Public Member Functions

void setIdatLength (size_t len)
 
 ~SkPngCodec () override
 
- Public Member Functions inherited from SkCodec
virtual ~SkCodec ()
 
SkImageInfo getInfo () const
 
SkISize dimensions () const
 
SkIRect bounds () const
 
const skcms_ICCProfilegetICCProfile () const
 
SkEncodedOrigin getOrigin () const
 
SkISize getScaledDimensions (float desiredScale) const
 
bool getValidSubset (SkIRect *desiredSubset) const
 
SkEncodedImageFormat getEncodedFormat () const
 
virtual std::unique_ptr< SkStreamgetEncodedData () const
 
Result getPixels (const SkImageInfo &info, void *pixels, size_t rowBytes, const Options *)
 
Result getPixels (const SkImageInfo &info, void *pixels, size_t rowBytes)
 
Result getPixels (const SkPixmap &pm, const Options *opts=nullptr)
 
std::tuple< sk_sp< SkImage >, SkCodec::ResultgetImage (const SkImageInfo &info, const Options *opts=nullptr)
 
std::tuple< sk_sp< SkImage >, SkCodec::ResultgetImage ()
 
bool queryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
 
Result getYUVAPlanes (const SkYUVAPixmaps &yuvaPixmaps)
 
Result startIncrementalDecode (const SkImageInfo &dstInfo, void *dst, size_t rowBytes, const Options *)
 
Result startIncrementalDecode (const SkImageInfo &dstInfo, void *dst, size_t rowBytes)
 
Result incrementalDecode (int *rowsDecoded=nullptr)
 
Result startScanlineDecode (const SkImageInfo &dstInfo, const Options *options)
 
Result startScanlineDecode (const SkImageInfo &dstInfo)
 
int getScanlines (void *dst, int countLines, size_t rowBytes)
 
bool skipScanlines (int countLines)
 
SkScanlineOrder getScanlineOrder () const
 
int nextScanline () const
 
int outputScanline (int inputScanline) const
 
int getFrameCount ()
 
bool getFrameInfo (int index, FrameInfo *info) const
 
std::vector< FrameInfogetFrameInfo ()
 
int getRepetitionCount ()
 

Static Public Member Functions

static bool IsPng (const void *, size_t)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, Result *, SkPngChunkReader *=nullptr)
 
- Static Public Member Functions inherited from SkCodec
static constexpr size_t MinBufferedBytesNeeded ()
 
static const char * ResultToString (Result)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
 
static std::unique_ptr< SkCodecMakeFromData (sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
 
static std::unique_ptr< SkCodecMakeFromData (sk_sp< SkData >, SkPngChunkReader *=nullptr)
 
static void Register (bool(*peek)(const void *, size_t), std::unique_ptr< SkCodec >(*make)(std::unique_ptr< SkStream >, SkCodec::Result *))
 

Protected Member Functions

 SkPngCodec (SkEncodedInfo &&, std::unique_ptr< SkStream >, SkPngChunkReader *, void *png_ptr, void *info_ptr, int bitDepth)
 
Result onGetPixels (const SkImageInfo &, void *, size_t, const Options &, int *) override
 
SkEncodedImageFormat onGetEncodedFormat () const override
 
bool onRewind () override
 
SkSamplergetSampler (bool createIfNecessary) override
 
void applyXformRow (void *dst, const void *src)
 
voidp png_ptr ()
 
voidp info_ptr ()
 
SkSwizzlerswizzler ()
 
void initializeXformParams ()
 
bool processData ()
 
Result onStartIncrementalDecode (const SkImageInfo &dstInfo, void *pixels, size_t rowBytes, const SkCodec::Options &) override
 
Result onIncrementalDecode (int *) override
 
- Protected Member Functions inherited from SkCodec
const SkEncodedInfogetEncodedInfo () const
 
 SkCodec (SkEncodedInfo &&, XformFormat srcFormat, std::unique_ptr< SkStream >, SkEncodedOrigin=kTopLeft_SkEncodedOrigin)
 
void setSrcXformFormat (XformFormat pixelFormat)
 
XformFormat getSrcXformFormat () const
 
virtual bool onGetGainmapInfo (SkGainmapInfo *, std::unique_ptr< SkStream > *)
 
virtual SkISize onGetScaledDimensions (float) const
 
virtual bool onDimensionsSupported (const SkISize &)
 
virtual SkEncodedImageFormat onGetEncodedFormat () const =0
 
virtual Result onGetPixels (const SkImageInfo &info, void *pixels, size_t rowBytes, const Options &, int *rowsDecoded)=0
 
virtual bool onQueryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
 
virtual Result onGetYUVAPlanes (const SkYUVAPixmaps &)
 
virtual bool onGetValidSubset (SkIRect *) const
 
bool rewindIfNeeded ()
 
virtual bool onRewind ()
 
SkStreamstream ()
 
virtual SkScanlineOrder onGetScanlineOrder () const
 
const SkImageInfodstInfo () const
 
const Optionsoptions () const
 
int currScanline () const
 
virtual int onOutputScanline (int inputScanline) const
 
virtual bool conversionSupported (const SkImageInfo &dst, bool srcIsOpaque, bool needsColorXform)
 
virtual bool usesColorXform () const
 
void applyColorXform (void *dst, const void *src, int count) const
 
bool colorXform () const
 
bool xformOnDecode () const
 
virtual int onGetFrameCount ()
 
virtual bool onGetFrameInfo (int, FrameInfo *) const
 
virtual int onGetRepetitionCount ()
 

Protected Attributes

sk_sp< SkPngChunkReaderfPngChunkReader
 
voidp fPng_ptr
 
voidp fInfo_ptr
 
sk_sp< SkColorPalettefColorTable
 
std::unique_ptr< SkSwizzlerfSwizzler
 
skia_private::AutoTMalloc< uint8_t > fStorage
 
void * fColorXformSrcRow
 
const int fBitDepth
 

Private Member Functions

virtual Result decodeAllRows (void *dst, size_t rowBytes, int *rowsDecoded)=0
 
virtual void setRange (int firstRow, int lastRow, void *dst, size_t rowBytes)=0
 
virtual Result decode (int *rowsDecoded)=0
 

Additional Inherited Members

- Public Types inherited from SkCodec
enum  Result {
  kSuccess , kIncompleteInput , kErrorInInput , kInvalidConversion ,
  kInvalidScale , kInvalidParameters , kInvalidInput , kCouldNotRewind ,
  kInternalError , kUnimplemented
}
 
enum class  SelectionPolicy { kPreferStillImage , kPreferAnimation }
 
enum  ZeroInitialized { kYes_ZeroInitialized , kNo_ZeroInitialized }
 
enum  SkScanlineOrder { kTopDown_SkScanlineOrder , kBottomUp_SkScanlineOrder }
 
- Static Public Attributes inherited from SkCodec
static constexpr int kNoFrame = -1
 
static constexpr int kRepetitionCountInfinite = -1
 
- Protected Types inherited from SkCodec
using XformFormat = skcms_PixelFormat
 

Detailed Description

Definition at line 27 of file SkPngCodec.h.

Constructor & Destructor Documentation

◆ ~SkPngCodec()

SkPngCodec::~SkPngCodec ( )
override

Definition at line 1017 of file SkPngCodec.cpp.

1017 {
1018 this->destroyReadStruct();
1019}

◆ SkPngCodec()

SkPngCodec::SkPngCodec ( SkEncodedInfo &&  encodedInfo,
std::unique_ptr< SkStream stream,
SkPngChunkReader chunkReader,
void *  png_ptr,
void *  info_ptr,
int  bitDepth 
)
protected

Definition at line 1005 of file SkPngCodec.cpp.

1007 : INHERITED(std::move(encodedInfo), png_select_xform_format(encodedInfo), std::move(stream))
1008 , fPngChunkReader(SkSafeRef(chunkReader))
1009 , fPng_ptr(png_ptr)
1011 , fColorXformSrcRow(nullptr)
1012 , fBitDepth(bitDepth)
1013 , fIdatLength(0)
1014 , fDecodedIdat(false)
1015{}
static skcms_PixelFormat png_select_xform_format(const SkEncodedInfo &info)
Definition: SkPngCodec.cpp:471
static T * SkSafeRef(T *obj)
Definition: SkRefCnt.h:140
SkStream * stream()
Definition: SkCodec.h:865
void * fColorXformSrcRow
Definition: SkPngCodec.h:93
voidp fPng_ptr
Definition: SkPngCodec.h:86
voidp fInfo_ptr
Definition: SkPngCodec.h:87
const int fBitDepth
Definition: SkPngCodec.h:94
voidp info_ptr()
Definition: SkPngCodec.h:66
voidp png_ptr()
Definition: SkPngCodec.h:65
sk_sp< SkPngChunkReader > fPngChunkReader
Definition: SkPngCodec.h:85

Member Function Documentation

◆ applyXformRow()

void SkPngCodec::applyXformRow ( void *  dst,
const void *  src 
)
protected

Definition at line 486 of file SkPngCodec.cpp.

486 {
487 switch (fXformMode) {
488 case kSwizzleOnly_XformMode:
489 fSwizzler->swizzle(dst, (const uint8_t*) src);
490 break;
491 case kColorOnly_XformMode:
492 this->applyColorXform(dst, src, fXformWidth);
493 break;
494 case kSwizzleColor_XformMode:
495 fSwizzler->swizzle(fColorXformSrcRow, (const uint8_t*) src);
496 this->applyColorXform(dst, fColorXformSrcRow, fXformWidth);
497 break;
498 }
499}
void applyColorXform(void *dst, const void *src, int count) const
Definition: SkCodec.cpp:853
std::unique_ptr< SkSwizzler > fSwizzler
Definition: SkPngCodec.h:91
dst
Definition: cp.py:12

◆ decode()

virtual Result SkPngCodec::decode ( int rowsDecoded)
privatepure virtual

◆ decodeAllRows()

virtual Result SkPngCodec::decodeAllRows ( void *  dst,
size_t  rowBytes,
int rowsDecoded 
)
privatepure virtual

◆ getSampler()

SkSampler * SkPngCodec::getSampler ( bool  )
overrideprotectedvirtual

Return an object which will allow forcing scanline decodes to sample in X.

May create a sampler, if one is not currently being used. Otherwise, does not affect ownership.

Only valid during scanline decoding or incremental decoding.

Reimplemented from SkCodec.

Definition at line 1141 of file SkPngCodec.cpp.

1141 {
1142 if (fSwizzler || !createIfNecessary) {
1143 return fSwizzler.get();
1144 }
1145
1146 this->initializeSwizzler(this->dstInfo(), this->options(), true);
1147 return fSwizzler.get();
1148}
const SkImageInfo & dstInfo() const
Definition: SkCodec.h:878
const Options & options() const
Definition: SkCodec.h:880

◆ info_ptr()

voidp SkPngCodec::info_ptr ( )
inlineprotected

Definition at line 66 of file SkPngCodec.h.

66{ return fInfo_ptr; }

◆ initializeXformParams()

void SkPngCodec::initializeXformParams ( )
protected

Definition at line 1077 of file SkPngCodec.cpp.

1077 {
1078 switch (fXformMode) {
1079 case kColorOnly_XformMode:
1080 fXformWidth = this->dstInfo().width();
1081 break;
1082 case kSwizzleColor_XformMode:
1083 fXformWidth = this->swizzler()->swizzleWidth();
1084 break;
1085 default:
1086 break;
1087 }
1088}
SkSwizzler * swizzler()
Definition: SkPngCodec.h:68
int swizzleWidth() const
Definition: SkSwizzler.h:90
int width() const
Definition: SkImageInfo.h:365

◆ IsPng()

bool SkPngCodec::IsPng ( const void *  buf,
size_t  bytesRead 
)
static

Definition at line 344 of file SkPngCodec.cpp.

344 {
345 return !png_sig_cmp((png_const_bytep) buf, (png_size_t)0, bytesRead);
346}

◆ MakeFromStream()

std::unique_ptr< SkCodec > SkPngCodec::MakeFromStream ( std::unique_ptr< SkStream stream,
Result result,
SkPngChunkReader chunkReader = nullptr 
)
static

Definition at line 1216 of file SkPngCodec.cpp.

1217 {
1219 if (!stream) {
1221 return nullptr;
1222 }
1223 SkCodec* outCodec = nullptr;
1224 *result = read_header(stream.get(), chunkReader, &outCodec, nullptr, nullptr);
1225 if (kSuccess == *result) {
1226 // Codec has taken ownership of the stream.
1227 SkASSERT(outCodec);
1228 stream.release();
1229 }
1230 return std::unique_ptr<SkCodec>(outCodec);
1231}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkCodec::Result read_header(SkStream *stream, SkPngChunkReader *chunkReader, SkCodec **outCodec, png_structp *png_ptrp, png_infop *info_ptrp)
Definition: SkPngCodec.cpp:795
@ kInvalidInput
Definition: SkCodec.h:109
@ kSuccess
Definition: SkCodec.h:80
GAsyncResult * result

◆ onGetEncodedFormat()

SkEncodedImageFormat SkPngCodec::onGetEncodedFormat ( ) const
inlineoverrideprotectedvirtual

Implements SkCodec.

Definition at line 59 of file SkPngCodec.h.

◆ onGetPixels()

SkCodec::Result SkPngCodec::onGetPixels ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes,
const Options ,
int rowsDecoded 
)
overrideprotectedvirtual
Parameters
rowsDecodedWhen the encoded image stream is incomplete, this function will return kIncompleteInput and rowsDecoded will be set to the number of scanlines that were successfully decoded. This will allow getPixels() to fill the uninitialized memory.

Implements SkCodec.

Definition at line 1171 of file SkPngCodec.cpp.

1173 {
1174 Result result = this->initializeXforms(dstInfo, options);
1175 if (kSuccess != result) {
1176 return result;
1177 }
1178
1179 if (options.fSubset) {
1180 return kUnimplemented;
1181 }
1182
1183 this->allocateStorage(dstInfo);
1184 this->initializeXformParams();
1185 return this->decodeAllRows(dst, rowBytes, rowsDecoded);
1186}
Result
Definition: SkCodec.h:76
@ kUnimplemented
Definition: SkCodec.h:123
virtual Result decodeAllRows(void *dst, size_t rowBytes, int *rowsDecoded)=0
void initializeXformParams()
const SkIRect * fSubset
Definition: SkCodec.h:347

◆ onIncrementalDecode()

SkCodec::Result SkPngCodec::onIncrementalDecode ( int rowsDecoded)
overrideprotectedvirtual

Reimplemented from SkCodec.

Definition at line 1209 of file SkPngCodec.cpp.

1209 {
1210 // FIXME: Only necessary on the first call.
1211 this->initializeXformParams();
1212
1213 return this->decode(rowsDecoded);
1214}
virtual Result decode(int *rowsDecoded)=0

◆ onRewind()

bool SkPngCodec::onRewind ( )
overrideprotectedvirtual

Called by rewindIfNeeded, if the stream needed to be rewound.

Subclasses should do any set up needed after a rewind.

Reimplemented from SkCodec.

Definition at line 1150 of file SkPngCodec.cpp.

1150 {
1151 // This sets fPng_ptr and fInfo_ptr to nullptr. If read_header
1152 // succeeds, they will be repopulated, and if it fails, they will
1153 // remain nullptr. Any future accesses to fPng_ptr and fInfo_ptr will
1154 // come through this function which will rewind and again attempt
1155 // to reinitialize them.
1156 this->destroyReadStruct();
1157
1158 png_structp png_ptr;
1159 png_infop info_ptr;
1160 if (kSuccess != read_header(this->stream(), fPngChunkReader.get(), nullptr,
1161 &png_ptr, &info_ptr)) {
1162 return false;
1163 }
1164
1165 fPng_ptr = png_ptr;
1167 fDecodedIdat = false;
1168 return true;
1169}
T * get() const
Definition: SkRefCnt.h:303

◆ onStartIncrementalDecode()

SkCodec::Result SkPngCodec::onStartIncrementalDecode ( const SkImageInfo dstInfo,
void *  pixels,
size_t  rowBytes,
const SkCodec::Options options 
)
overrideprotectedvirtual

Reimplemented from SkCodec.

Definition at line 1188 of file SkPngCodec.cpp.

1189 {
1190 Result result = this->initializeXforms(dstInfo, options);
1191 if (kSuccess != result) {
1192 return result;
1193 }
1194
1195 this->allocateStorage(dstInfo);
1196
1197 int firstRow, lastRow;
1198 if (options.fSubset) {
1199 firstRow = options.fSubset->top();
1200 lastRow = options.fSubset->bottom() - 1;
1201 } else {
1202 firstRow = 0;
1203 lastRow = dstInfo.height() - 1;
1204 }
1205 this->setRange(firstRow, lastRow, dst, rowBytes);
1206 return kSuccess;
1207}
virtual void setRange(int firstRow, int lastRow, void *dst, size_t rowBytes)=0
constexpr int32_t top() const
Definition: SkRect.h:120
constexpr int32_t bottom() const
Definition: SkRect.h:134
int height() const
Definition: SkImageInfo.h:371

◆ png_ptr()

voidp SkPngCodec::png_ptr ( )
inlineprotected

Definition at line 65 of file SkPngCodec.h.

65{ return fPng_ptr; }

◆ processData()

bool SkPngCodec::processData ( )
protected

Pass available input to libpng to process it.

libpng will call any relevant callbacks installed. This will continue decoding until it reaches the end of the file, or until a callback tells libpng to stop.

Definition at line 213 of file SkPngCodec.cpp.

213 {
214 switch (setjmp(PNG_JMPBUF(fPng_ptr))) {
215 case kPngError:
216 // There was an error. Stop processing data.
217 // FIXME: Do we need to discard png_ptr?
218 return false;
219 case kStopDecoding:
220 // We decoded all the lines we want.
221 return true;
222 case kSetJmpOkay:
223 // Everything is okay.
224 break;
225 default:
226 // No other values should be passed to longjmp.
227 SkASSERT(false);
228 }
229
230 // Arbitrary buffer size
231 constexpr size_t kBufferSize = 4096;
232 char buffer[kBufferSize];
233
234 bool iend = false;
235 while (true) {
236 size_t length;
237 if (fDecodedIdat) {
238 // Parse chunk length and type.
239 if (this->stream()->read(buffer, 8) < 8) {
240 break;
241 }
242
243 png_byte* chunk = reinterpret_cast<png_byte*>(buffer);
244 png_process_data(fPng_ptr, fInfo_ptr, chunk, 8);
245 if (is_chunk(chunk, "IEND")) {
246 iend = true;
247 }
248
249 length = png_get_uint_32(chunk);
250 } else {
251 length = fIdatLength;
252 png_byte idat[] = {0, 0, 0, 0, 'I', 'D', 'A', 'T'};
253 png_save_uint_32(idat, length);
254 png_process_data(fPng_ptr, fInfo_ptr, idat, 8);
255 fDecodedIdat = true;
256 }
257
258 // Process the full chunk + CRC.
259 if (!process_data(fPng_ptr, fInfo_ptr, this->stream(), buffer, kBufferSize, length + 4)
260 || iend) {
261 break;
262 }
263 }
264
265 return true;
266}
static bool read(SkStream *stream, void *buffer, size_t amount)
static bool process_data(png_structp png_ptr, png_infop info_ptr, SkStream *stream, void *buffer, size_t bufferSize, size_t length)
Definition: SkPngCodec.cpp:151
constexpr int kSetJmpOkay
Definition: SkPngCodec.cpp:61
constexpr int kStopDecoding
Definition: SkPngCodec.cpp:65
#define PNG_JMPBUF(x)
Definition: SkPngCodec.cpp:54
constexpr int kPngError
Definition: SkPngCodec.cpp:63
static bool is_chunk(const png_byte *chunk, const char *tag)
Definition: SkPngCodec.cpp:147
static const size_t kBufferSize
Definition: SkString.cpp:27
size_t length
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ setIdatLength()

void SkPngCodec::setIdatLength ( size_t  len)
inline

Definition at line 36 of file SkPngCodec.h.

36{ fIdatLength = len; }

◆ setRange()

virtual void SkPngCodec::setRange ( int  firstRow,
int  lastRow,
void *  dst,
size_t  rowBytes 
)
privatepure virtual

◆ swizzler()

SkSwizzler * SkPngCodec::swizzler ( )
inlineprotected

Definition at line 68 of file SkPngCodec.h.

68{ return fSwizzler.get(); }

Member Data Documentation

◆ fBitDepth

const int SkPngCodec::fBitDepth
protected

Definition at line 94 of file SkPngCodec.h.

◆ fColorTable

sk_sp<SkColorPalette> SkPngCodec::fColorTable
protected

Definition at line 90 of file SkPngCodec.h.

◆ fColorXformSrcRow

void* SkPngCodec::fColorXformSrcRow
protected

Definition at line 93 of file SkPngCodec.h.

◆ fInfo_ptr

voidp SkPngCodec::fInfo_ptr
protected

Definition at line 87 of file SkPngCodec.h.

◆ fPng_ptr

voidp SkPngCodec::fPng_ptr
protected

Definition at line 86 of file SkPngCodec.h.

◆ fPngChunkReader

sk_sp<SkPngChunkReader> SkPngCodec::fPngChunkReader
protected

Definition at line 85 of file SkPngCodec.h.

◆ fStorage

skia_private::AutoTMalloc<uint8_t> SkPngCodec::fStorage
protected

Definition at line 92 of file SkPngCodec.h.

◆ fSwizzler

std::unique_ptr<SkSwizzler> SkPngCodec::fSwizzler
protected

Definition at line 91 of file SkPngCodec.h.


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