Flutter Engine
The Flutter Engine
|
#include <SkCodec.h>
Classes | |
struct | FrameInfo |
struct | Options |
Public Types | |
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 Member Functions | |
static constexpr size_t | MinBufferedBytesNeeded () |
static const char * | ResultToString (Result) |
static std::unique_ptr< SkCodec > | MakeFromStream (std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage) |
static std::unique_ptr< SkCodec > | MakeFromStream (std::unique_ptr< SkStream >, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage) |
static std::unique_ptr< SkCodec > | MakeFromData (sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr) |
static std::unique_ptr< SkCodec > | MakeFromData (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 *)) |
Static Public Attributes | |
static constexpr int | kNoFrame = -1 |
static constexpr int | kRepetitionCountInfinite = -1 |
Protected Types | |
using | XformFormat = skcms_PixelFormat |
Private Member Functions | |
virtual const SkFrameHolder * | getFrameHolder () const |
virtual Result | onStartScanlineDecode (const SkImageInfo &, const Options &) |
virtual Result | onStartIncrementalDecode (const SkImageInfo &, void *, size_t, const Options &) |
virtual Result | onIncrementalDecode (int *) |
virtual bool | onSkipScanlines (int) |
virtual int | onGetScanlines (void *, int, size_t) |
virtual SkSampler * | getSampler (bool) |
Friends | |
class | DM::CodecSrc |
class | PNGCodecGM |
class | SkSampledCodec |
class | SkIcoCodec |
class | SkAndroidCodec |
class | SkPDFBitmap |
|
protected |
enum SkCodec::Result |
Error codes for various SkCodec methods.
Enumerator | |
---|---|
kSuccess | General return value for success. |
kIncompleteInput | The input is incomplete. A partial image was generated. |
kErrorInInput | Like kIncompleteInput, except the input had an error. If returned from an incremental decode, decoding cannot continue, even with more data. |
kInvalidConversion | The generator cannot convert to match the request, ignoring dimensions. |
kInvalidScale | The generator cannot scale to requested size. |
kInvalidParameters | Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes too small, etc. |
kInvalidInput | The input did not contain a valid image. |
kCouldNotRewind | Fulfilling this request requires rewinding the input, which is not supported for this input. |
kInternalError | An internal error, such as OOM. |
kUnimplemented | This method is not implemented by this codec. FIXME: Perhaps this should be kUnsupported? |
Definition at line 76 of file SkCodec.h.
|
strong |
For container formats that contain both still images and image sequences, instruct the decoder how the output should be selected. (Refer to comments for each value for more details.)
Enumerator | |
---|---|
kPreferStillImage | If the container format contains both still images and image sequences, SkCodec should choose one of the still images. This is the default. Note that kPreferStillImage may prevent use of the animation features if the input is not rewindable. |
kPreferAnimation | If the container format contains both still images and image sequences, SkCodec should choose one of the image sequences for animation. |
Definition at line 136 of file SkCodec.h.
The order in which rows are output from the scanline decoder is not the same for all variations of all image types. This explains the possible output row orderings.
Enumerator | |
---|---|
kTopDown_SkScanlineOrder | |
kBottomUp_SkScanlineOrder |
Definition at line 575 of file SkCodec.h.
Whether or not the memory passed to getPixels is zero initialized.
Enumerator | |
---|---|
kYes_ZeroInitialized | The memory passed to getPixels is zero initialized. The SkCodec may take advantage of this by skipping writing zeroes. |
kNo_ZeroInitialized | The memory passed to getPixels has not been initialized to zero, so the SkCodec must write all zeroes to memory. This is the default. It will be used if no Options struct is used. |
Definition at line 303 of file SkCodec.h.
|
virtual |
Definition at line 261 of file SkCodec.cpp.
|
protected |
Definition at line 250 of file SkCodec.cpp.
|
protected |
Definition at line 853 of file SkCodec.cpp.
|
inlineprotected |
|
protectedvirtual |
Return whether we can convert to dst.
Will be called for the appropriate frame, prior to initializing the colorXform.
Reimplemented in SkHeifCodec, SkIcoCodec, SkJpegCodec, SkJpegxlCodec, and SkWbmpCodec.
Definition at line 286 of file SkCodec.cpp.
|
inlineprotected |
|
inline |
|
inlineprotected |
|
virtual |
Return the underlying encoded data stream. This may be nullptr if the original stream could not be duplicated.
Reimplemented in SkWuffsCodec.
Definition at line 1046 of file SkCodec.cpp.
|
inline |
|
inlineprotected |
|
inline |
|
inlineprivatevirtual |
For multi-framed images, return the object with information about the frames.
Reimplemented in SkAvifCodec, SkHeifCodec, and SkWebpCodec.
Definition at line 968 of file SkCodec.h.
std::vector< SkCodec::FrameInfo > SkCodec::getFrameInfo | ( | ) |
Return info about all the frames in the image.
May require reading through the stream to determine info about the frames (including the count).
As such, future decoding calls may require a rewind.
This may return an empty vector for non-animated codecs. See the getFrameInfo(int, FrameInfo*) comment.
Definition at line 861 of file SkCodec.cpp.
Return info about a single frame.
Does not read through the stream, so it should be called after getFrameCount() to parse any frames that have not already been parsed.
Only supported by animated (multi-frame) codecs. Note that this is a property of the codec (the SkCodec subclass), not the image.
To elaborate, some codecs support animation (e.g. GIF). Others do not (e.g. BMP). Animated codecs can still represent single frame images. Calling getFrameInfo(0, etc) will return true for a single frame GIF even if the overall image is not animated (in that the pixels on screen do not change over time). When incrementally decoding a GIF image, we might only know that there's a single frame so far.
For non-animated SkCodec subclasses, it's sufficient but not necessary for this method to always return false.
Definition at line 739 of file SkCodec.h.
|
inline |
std::tuple< sk_sp< SkImage >, SkCodec::Result > SkCodec::getImage | ( | ) |
Definition at line 565 of file SkCodec.cpp.
std::tuple< sk_sp< SkImage >, SkCodec::Result > SkCodec::getImage | ( | const SkImageInfo & | info, |
const Options * | opts = nullptr |
||
) |
Return an image containing the pixels. If the codec's origin is not "upper left", This will rotate the output image accordingly.
Definition at line 533 of file SkCodec.cpp.
|
inline |
Return a reasonable SkImageInfo to decode into.
If the image has an ICC profile that does not map to an SkColorSpace, the returned SkImageInfo will use SRGB.
Definition at line 228 of file SkCodec.h.
|
inline |
|
inline |
Simplified version of getPixels() that uses the default Options.
SkCodec::Result SkCodec::getPixels | ( | const SkImageInfo & | info, |
void * | pixels, | ||
size_t | rowBytes, | ||
const Options * | options | ||
) |
Decode into the given pixels, a block of memory of size at least (info.fHeight - 1) * rowBytes + (info.fWidth * bytesPerPixel)
Repeated calls to this function should give the same results, allowing the PixelRef to be immutable.
info | A description of the format (config, size) expected by the caller. This can simply be identical to the info returned by getInfo(). |
This contract also allows the caller to specify different output-configs, which the implementation can decide to support or not.
A size that does not match getInfo() implies a request to scale. If the generator cannot perform this scale, it will return kInvalidScale.
If the info contains a non-null SkColorSpace, the codec will perform the appropriate color space transformation.
If the caller passes in the SkColorSpace that maps to the ICC profile reported by getICCProfile(), the color space transformation is a no-op.
If the caller passes a null SkColorSpace, no color space transformation will be done.
If a scanline decode is in progress, scanline mode will end, requiring the client to call startScanlineDecode() in order to return to decoding scanlines.
Definition at line 467 of file SkCodec.cpp.
|
inline |
Return the number of times to repeat, if this image is animated. This number does not include the first play through of each frame. For example, a repetition count of 4 means that each frame is played 5 times and then the animation stops.
It can return kRepetitionCountInfinite, a negative number, meaning that the animation should loop forever.
May require reading the stream to find the repetition count.
As such, future decoding calls may require a rewind.
For still (non-animated) image codecs, this will return 0.
Definition at line 775 of file SkCodec.h.
|
inlineprivatevirtual |
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 in SkBmpStandardCodec, and SkPngCodec.
Definition at line 1035 of file SkCodec.h.
|
inline |
Return a size that approximately supports the desired scale factor. The codec may not be able to scale efficiently to the exact scale factor requested, so return a size that approximates that scale. The returned value is the codec's suggestion for the closest valid scale that it can natively support
Definition at line 255 of file SkCodec.h.
|
inline |
An enum representing the order in which scanlines will be returned by the scanline decoder.
This is undefined before startScanlineDecode() is called.
Definition at line 613 of file SkCodec.h.
Write the next countLines scanlines into dst.
Not valid to call before calling startScanlineDecode().
dst | Must be non-null, and large enough to hold countLines scanlines of size rowBytes. |
countLines | Number of lines to write. |
rowBytes | Number of bytes per row. Must be large enough to hold a scanline based on the SkImageInfo used to create this object. |
Definition at line 694 of file SkCodec.cpp.
|
inlineprotected |
|
inline |
Return (via desiredSubset) a subset which can decoded from this codec, or false if this codec cannot decode subsets or anything similar to desiredSubset.
desiredSubset | In/out parameter. As input, a desired subset of the original bounds (as specified by getInfo). If true is returned, desiredSubset may have been modified to a subset which is supported. Although a particular change may have been made to desiredSubset to create something supported, it is possible other changes could result in a valid subset. If false is returned, desiredSubset's value is undefined. |
SkCodec::Result SkCodec::getYUVAPlanes | ( | const SkYUVAPixmaps & | yuvaPixmaps | ) |
Returns kSuccess, or another value explaining the type of failure. This always attempts to perform a full decode. To get the planar configuration without decoding use queryYUVAInfo().
yuvaPixmaps | Contains preallocated pixmaps configured according to a successful call to queryYUVAInfo(). |
Definition at line 276 of file SkCodec.cpp.
Start/continue the incremental decode.
Not valid to call before a call to startIncrementalDecode() returns kSuccess.
If kIncompleteInput is returned, may be called again after more data has been provided to the source SkStream.
Unlike getPixels and getScanlines, this does not do any filling. This is left up to the caller, since they may be skipping lines or continuing the decode later. In the latter case, they may choose to initialize all lines first, or only initialize the remaining lines after the first call.
rowsDecoded | Optional output variable returning the total number of lines initialized. Only meaningful if this method returns kIncompleteInput. Otherwise the implementation may not set it. Note that some implementations may have initialized this many rows, but not necessarily finished those rows (e.g. interlaced PNG). This may be useful for determining what rows the client needs to initialize. |
Definition at line 498 of file SkCodec.h.
|
static |
Definition at line 238 of file SkCodec.cpp.
|
static |
If this data represents an encoded image that we know how to decode, return an SkCodec that can decode it. Otherwise return NULL.
If the SkPngChunkReader is not NULL then: If the image is not a PNG, the SkPngChunkReader will be ignored. If the image is a PNG, the SkPngChunkReader will be reffed. If the PNG has unknown chunks, the SkPngChunkReader will be used to handle these chunks. SkPngChunkReader will be called to read any unknown chunk at any point during the creation of the codec or the decode. Note that if SkPngChunkReader fails to read a chunk, this could result in a failure to create the codec or a failure to decode the image. If the PNG does not contain unknown chunks, the SkPngChunkReader will not be used or modified.
Definition at line 241 of file SkCodec.cpp.
|
static |
Definition at line 157 of file SkCodec.cpp.
|
static |
If this stream represents an encoded image that we know how to decode, return an SkCodec that can decode it. Otherwise return NULL.
As stated above, this call must be able to peek or read MinBufferedBytesNeeded to determine the correct format, and then start reading from the beginning. First it will attempt to peek, and it assumes that if less than MinBufferedBytesNeeded bytes (but more than zero) are returned, this is because the stream is shorter than this, so falling back to reading would not provide more data. If peek() returns zero bytes, this call will instead attempt to read(). This will require that the stream can be rewind()ed.
If Result is not NULL, it will be set to either kSuccess if an SkCodec is returned or a reason for the failure if NULL is returned.
If SkPngChunkReader is not NULL, take a ref and pass it to libpng if the image is a png.
If the SkPngChunkReader is not NULL then: If the image is not a PNG, the SkPngChunkReader will be ignored. If the image is a PNG, the SkPngChunkReader will be reffed. If the PNG has unknown chunks, the SkPngChunkReader will be used to handle these chunks. SkPngChunkReader will be called to read any unknown chunk at any point during the creation of the codec or the decode. Note that if SkPngChunkReader fails to read a chunk, this could result in a failure to create the codec or a failure to decode the image. If the PNG does not contain unknown chunks, the SkPngChunkReader will not be used or modified.
If NULL is returned, the stream is deleted immediately. Otherwise, the SkCodec takes ownership of it, and will delete it when done with it.
Definition at line 163 of file SkCodec.cpp.
|
inlinestaticconstexpr |
Minimum number of bytes that must be buffered in SkStream input.
An SkStream passed to NewFromStream must be able to use this many bytes to determine the image type. Then the same SkStream must be passed to the correct decoder to read from the beginning.
This can be accomplished by implementing peek() to support peeking this many bytes, or by implementing rewind() to be able to rewind() after reading this many bytes.
Definition at line 71 of file SkCodec.h.
|
inline |
|
inlineprotectedvirtual |
Subclasses should override if they support dimensions other than the srcInfo's.
Reimplemented in SkIcoCodec, SkJpegCodec, SkRawCodec, and SkScalingCodec.
Definition at line 815 of file SkCodec.h.
|
protectedpure virtual |
Implemented in SkAvifCodec, SkBmpCodec, SkHeifCodec, SkIcoCodec, SkJpegCodec, SkJpegxlCodec, SkPngCodec, SkRawCodec, SkWbmpCodec, and SkWebpCodec.
|
inlineprotectedvirtual |
Reimplemented in SkAvifCodec, SkHeifCodec, SkJpegxlCodec, and SkWebpCodec.
Definition at line 909 of file SkCodec.h.
Reimplemented in SkAvifCodec, SkHeifCodec, SkJpegxlCodec, and SkWebpCodec.
Definition at line 913 of file SkCodec.h.
|
inlineprotectedvirtual |
|
protectedpure virtual |
rowsDecoded | When 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. |
Implemented in SkPngCodec, SkWbmpCodec, SkWebpCodec, SkBmpMaskCodec, SkBmpRLECodec, SkBmpStandardCodec, SkIcoCodec, SkJpegCodec, SkRawCodec, SkAvifCodec, SkHeifCodec, and SkJpegxlCodec.
|
inlineprotectedvirtual |
Reimplemented in SkAvifCodec, SkHeifCodec, SkJpegxlCodec, and SkWebpCodec.
Definition at line 917 of file SkCodec.h.
|
inlineprotectedvirtual |
Reimplemented in SkIcoCodec, SkJpegCodec, SkRawCodec, and SkScalingCodec.
|
inlineprotectedvirtual |
The remaining functions revolve around decoding scanlines. Most images types will be kTopDown and will not need to override this function.
Reimplemented in SkBmpCodec, and SkIcoCodec.
Definition at line 876 of file SkCodec.h.
|
inlineprotectedvirtual |
Reimplemented in SkWebpCodec.
Definition at line 836 of file SkCodec.h.
|
inlineprotectedvirtual |
Reimplemented in SkPngCodec.
Definition at line 736 of file SkCodec.cpp.
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
Called by rewindIfNeeded, if the stream needed to be rewound.
Subclasses should do any set up needed after a rewind.
Reimplemented in SkBmpCodec, SkHeifCodec, SkJpegCodec, SkJpegxlCodec, SkPngCodec, and SkWbmpCodec.
Definition at line 858 of file SkCodec.h.
|
inlineprivatevirtual |
|
inlineprivatevirtual |
Reimplemented in SkPngCodec.
|
inlineprivatevirtual |
|
inlineprotected |
Returns the output y-coordinate of the row that corresponds to an input y-coordinate. The input y-coordinate represents where the scanline is located in the encoded data.
This will equal inputScanline, except in the case of strangely encoded image types (bottom-up bmps, interlaced gifs).
Definition at line 731 of file SkCodec.cpp.
bool SkCodec::queryYUVAInfo | ( | const SkYUVAPixmapInfo::SupportedDataTypes & | supportedDataTypes, |
SkYUVAPixmapInfo * | yuvaPixmapInfo | ||
) | const |
If decoding to YUV is supported, this returns true. Otherwise, this returns false and the caller will ignore output parameter yuvaPixmapInfo.
supportedDataTypes | Indicates the data type/planar config combinations that are supported by the caller. If the generator supports decoding to YUV(A), but not as a type in supportedDataTypes, this method returns false. |
yuvaPixmapInfo | Output parameter that specifies the planar configuration, subsampling, orientation, chroma siting, plane color types, and row bytes. |
Definition at line 267 of file SkCodec.cpp.
|
static |
|
static |
Readable string representing the error code.
Definition at line 880 of file SkCodec.cpp.
|
protected |
If the stream was previously read, attempt to rewind.
If the stream needed to be rewound, call onRewind.
This is called by getPixels(), getYUV8Planes(), startIncrementalDecode() and startScanlineDecode(). Subclasses may call if they need to rewind at another time.
Definition at line 311 of file SkCodec.cpp.
|
protected |
Definition at line 263 of file SkCodec.cpp.
bool SkCodec::skipScanlines | ( | int | countLines | ) |
Skip count scanlines.
Not valid to call before calling startScanlineDecode().
The default version just calls onGetScanlines and discards the dst. NOTE: If skipped lines are the only lines with alpha, this default will make reallyHasAlpha return true, when it could have returned false.
Definition at line 713 of file SkCodec.cpp.
|
inline |
Definition at line 471 of file SkCodec.h.
SkCodec::Result SkCodec::startIncrementalDecode | ( | const SkImageInfo & | dstInfo, |
void * | dst, | ||
size_t | rowBytes, | ||
const Options * | options | ||
) |
Prepare for an incremental decode with the specified options.
This may require a rewind.
If kIncompleteInput is returned, may be called again after more data has been provided to the source SkStream.
dstInfo | Info of the destination. If the dimensions do not match those of getInfo, this implies a scale. |
dst | Memory to write to. Needs to be large enough to hold the subset, if present, or the full image as described in dstInfo. |
options | Contains decoding options, including if memory is zero initialized and whether to decode a subset. |
Definition at line 575 of file SkCodec.cpp.
|
inline |
Simplified version of startScanlineDecode() that uses the default Options.
Definition at line 531 of file SkCodec.h.
SkCodec::Result SkCodec::startScanlineDecode | ( | const SkImageInfo & | dstInfo, |
const Options * | options | ||
) |
The remaining functions revolve around decoding scanlines. Prepare for a scanline decode with the specified options.
After this call, this class will be ready to decode the first scanline.
This must be called in order to call getScanlines or skipScanlines.
This may require rewinding the stream.
Not all SkCodecs support this.
dstInfo | Info of the destination. If the dimensions do not match those of getInfo, this implies a scale. |
options | Contains decoding options, including if memory is zero initialized. |
Definition at line 635 of file SkCodec.cpp.
|
inlineprotected |
|
inlineprotectedvirtual |
Reimplemented in SkIcoCodec, SkRawCodec, and SkWbmpCodec.
Definition at line 903 of file SkCodec.h.
|
inlineprotected |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
staticconstexpr |