Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Private Member Functions | Friends | List of all members
SkCodec Class Referenceabstract

#include <SkCodec.h>

Inheritance diagram for SkCodec:
SkNoncopyable SkBmpCodec SkHeifCodec SkIcoCodec SkJpegCodec SkPngCodec SkRawCodec SkScalingCodec SkWbmpCodec

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 }
 

Public Member Functions

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 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 *))
 

Static Public Attributes

static constexpr int kNoFrame = -1
 
static constexpr int kRepetitionCountInfinite = -1
 

Protected Types

using XformFormat = skcms_PixelFormat
 

Protected Member Functions

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 ()
 

Private Member Functions

virtual const SkFrameHoldergetFrameHolder () 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 SkSamplergetSampler (bool)
 

Friends

class DM::CodecSrc
 
class PNGCodecGM
 
class SkSampledCodec
 
class SkIcoCodec
 
class SkAndroidCodec
 
class SkPDFBitmap
 

Detailed Description

Abstraction layer directly on top of an image codec.

Definition at line 58 of file SkCodec.h.

Member Typedef Documentation

◆ XformFormat

Definition at line 790 of file SkCodec.h.

Member Enumeration Documentation

◆ 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.

76 {
77 /**
78 * General return value for success.
79 */
81 /**
82 * The input is incomplete. A partial image was generated.
83 */
85 /**
86 * Like kIncompleteInput, except the input had an error.
87 *
88 * If returned from an incremental decode, decoding cannot continue,
89 * even with more data.
90 */
92 /**
93 * The generator cannot convert to match the request, ignoring
94 * dimensions.
95 */
97 /**
98 * The generator cannot scale to requested size.
99 */
101 /**
102 * Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes
103 * too small, etc.
104 */
106 /**
107 * The input did not contain a valid image.
108 */
110 /**
111 * Fulfilling this request requires rewinding the input, which is not
112 * supported for this input.
113 */
115 /**
116 * An internal error, such as OOM.
117 */
119 /**
120 * This method is not implemented by this codec.
121 * FIXME: Perhaps this should be kUnsupported?
122 */
124 };
@ kInvalidConversion
Definition SkCodec.h:96
@ kInvalidScale
Definition SkCodec.h:100
@ kIncompleteInput
Definition SkCodec.h:84
@ kInvalidInput
Definition SkCodec.h:109
@ kInvalidParameters
Definition SkCodec.h:105
@ kInternalError
Definition SkCodec.h:118
@ kCouldNotRewind
Definition SkCodec.h:114
@ kUnimplemented
Definition SkCodec.h:123
@ kSuccess
Definition SkCodec.h:80
@ kErrorInInput
Definition SkCodec.h:91

◆ SelectionPolicy

enum class SkCodec::SelectionPolicy
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.

136 {
137 /**
138 * If the container format contains both still images and image sequences,
139 * SkCodec should choose one of the still images. This is the default.
140 * Note that kPreferStillImage may prevent use of the animation features
141 * if the input is not rewindable.
142 */
144 /**
145 * If the container format contains both still images and image sequences,
146 * SkCodec should choose one of the image sequences for animation.
147 */
149 };

◆ SkScanlineOrder

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.

575 {
576 /*
577 * By far the most common, this indicates that the image can be decoded
578 * reliably using the scanline decoder, and that rows will be output in
579 * the logical order.
580 */
582
583 /*
584 * This indicates that the scanline decoder reliably outputs rows, but
585 * they will be returned in reverse order. If the scanline format is
586 * kBottomUp, the nextScanline() API can be used to determine the actual
587 * y-coordinate of the next output row, but the client is not forced
588 * to take advantage of this, given that it's not too tough to keep
589 * track independently.
590 *
591 * For full image decodes, it is safe to get all of the scanlines at
592 * once, since the decoder will handle inverting the rows as it
593 * decodes.
594 *
595 * For subset decodes and sampling, it is simplest to get and skip
596 * scanlines one at a time, using the nextScanline() API. It is
597 * possible to ask for larger chunks at a time, but this should be used
598 * with caution. As with full image decodes, the decoder will handle
599 * inverting the requested rows, but rows will still be delivered
600 * starting from the bottom of the image.
601 *
602 * Upside down bmps are an example.
603 */
605 };
@ kBottomUp_SkScanlineOrder
Definition SkCodec.h:604
@ kTopDown_SkScanlineOrder
Definition SkCodec.h:581

◆ ZeroInitialized

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.

303 {
304 /**
305 * The memory passed to getPixels is zero initialized. The SkCodec
306 * may take advantage of this by skipping writing zeroes.
307 */
309 /**
310 * The memory passed to getPixels has not been initialized to zero,
311 * so the SkCodec must write all zeroes to memory.
312 *
313 * This is the default. It will be used if no Options struct is used.
314 */
316 };
@ kYes_ZeroInitialized
Definition SkCodec.h:308
@ kNo_ZeroInitialized
Definition SkCodec.h:315

Constructor & Destructor Documentation

◆ ~SkCodec()

SkCodec::~SkCodec ( )
virtual

Definition at line 261 of file SkCodec.cpp.

261{}

◆ SkCodec()

SkCodec::SkCodec ( SkEncodedInfo &&  info,
XformFormat  srcFormat,
std::unique_ptr< SkStream stream,
SkEncodedOrigin  origin = kTopLeft_SkEncodedOrigin 
)
protected

Definition at line 250 of file SkCodec.cpp.

254 : fEncodedInfo(std::move(info))
255 , fSrcXformFormat(srcFormat)
256 , fStream(std::move(stream))
257 , fOrigin(origin)
258 , fDstInfo()
259 , fOptions() {}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkStream * stream()
Definition SkCodec.h:865

Member Function Documentation

◆ applyColorXform()

void SkCodec::applyColorXform ( void *  dst,
const void *  src,
int  count 
) const
protected

Definition at line 853 of file SkCodec.cpp.

853 {
854 // It is okay for srcProfile to be null. This will use sRGB.
855 const auto* srcProfile = fEncodedInfo.profile();
856 SkAssertResult(skcms_Transform(src, fSrcXformFormat, skcms_AlphaFormat_Unpremul, srcProfile,
857 dst, fDstXformFormat, fDstXformAlphaFormat, &fDstProfile,
858 count));
859}
int count
#define SkAssertResult(cond)
Definition SkAssert.h:123
bool skcms_Transform(const void *src, skcms_PixelFormat srcFmt, skcms_AlphaFormat srcAlpha, const skcms_ICCProfile *srcProfile, void *dst, skcms_PixelFormat dstFmt, skcms_AlphaFormat dstAlpha, const skcms_ICCProfile *dstProfile, size_t nz)
Definition skcms.cc:2494
@ skcms_AlphaFormat_Unpremul
const skcms_ICCProfile * profile() const

◆ bounds()

SkIRect SkCodec::bounds ( ) const
inline

Definition at line 231 of file SkCodec.h.

231 {
232 return SkIRect::MakeWH(fEncodedInfo.width(), fEncodedInfo.height());
233 }
int width() const
int height() const
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56

◆ colorXform()

bool SkCodec::colorXform ( ) const
inlineprotected

Definition at line 906 of file SkCodec.h.

906{ return fXformTime != kNo_XformTime; }

◆ conversionSupported()

bool SkCodec::conversionSupported ( const SkImageInfo dst,
bool  srcIsOpaque,
bool  needsColorXform 
)
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.

286 {
287 if (!valid_alpha(dst.alphaType(), srcIsOpaque)) {
288 return false;
289 }
290
291 switch (dst.colorType()) {
296 return true;
299 return srcIsOpaque;
301 return SkEncodedInfo::kGray_Color == fEncodedInfo.color() && srcIsOpaque;
303 // conceptually we can convert anything into alpha_8, but we haven't actually coded
304 // all of those other conversions yet.
305 return SkEncodedInfo::kXAlpha_Color == fEncodedInfo.color();
306 default:
307 return false;
308 }
309}
static bool valid_alpha(SkAlphaType dstAlpha, bool srcIsOpaque)
Definition SkCodecPriv.h:90
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
Definition SkColorType.h:32
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
Definition SkColorType.h:31
dst
Definition cp.py:12
Color color() const

◆ currScanline()

int SkCodec::currScanline ( ) const
inlineprotected

Returns the number of scanlines that have been decoded so far. This is unaffected by the SkScanlineOrder.

Returns -1 if we have not started a scanline decode.

Definition at line 888 of file SkCodec.h.

888{ return fCurrScanline; }

◆ dimensions()

SkISize SkCodec::dimensions ( ) const
inline

Definition at line 230 of file SkCodec.h.

230{ return {fEncodedInfo.width(), fEncodedInfo.height()}; }

◆ dstInfo()

const SkImageInfo & SkCodec::dstInfo ( ) const
inlineprotected

Definition at line 878 of file SkCodec.h.

878{ return fDstInfo; }

◆ getEncodedData()

std::unique_ptr< SkStream > SkCodec::getEncodedData ( ) const
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.

1046 {
1047 SkASSERT(fStream);
1048 if (!fStream) {
1049 return nullptr;
1050 }
1051 return fStream->duplicate();
1052}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ getEncodedFormat()

SkEncodedImageFormat SkCodec::getEncodedFormat ( ) const
inline

Format of the encoded data.

Definition at line 292 of file SkCodec.h.

292{ return this->onGetEncodedFormat(); }
virtual SkEncodedImageFormat onGetEncodedFormat() const =0

◆ getEncodedInfo()

const SkEncodedInfo & SkCodec::getEncodedInfo ( ) const
inlineprotected

Definition at line 788 of file SkCodec.h.

788{ return fEncodedInfo; }

◆ getFrameCount()

int SkCodec::getFrameCount ( )
inline

Return the number of frames in the image.

May require reading through the stream.

Definition at line 641 of file SkCodec.h.

641 {
642 return this->onGetFrameCount();
643 }
virtual int onGetFrameCount()
Definition SkCodec.h:909

◆ getFrameHolder()

virtual const SkFrameHolder * SkCodec::getFrameHolder ( ) const
inlineprivatevirtual

For multi-framed images, return the object with information about the frames.

Reimplemented in SkAvifCodec, SkHeifCodec, SkJpegxlCodec, SkWebpCodec, and SkWuffsCodec.

Definition at line 968 of file SkCodec.h.

968 {
969 return nullptr;
970 }

◆ getFrameInfo() [1/2]

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.

861 {
862 const int frameCount = this->getFrameCount();
863 SkASSERT(frameCount >= 0);
864 if (frameCount <= 0) {
865 return std::vector<FrameInfo>{};
866 }
867
868 if (frameCount == 1 && !this->onGetFrameInfo(0, nullptr)) {
869 // Not animated.
870 return std::vector<FrameInfo>{};
871 }
872
873 std::vector<FrameInfo> result(frameCount);
874 for (int i = 0; i < frameCount; ++i) {
875 SkAssertResult(this->onGetFrameInfo(i, &result[i]));
876 }
877 return result;
878}
virtual bool onGetFrameInfo(int, FrameInfo *) const
Definition SkCodec.h:913
int getFrameCount()
Definition SkCodec.h:641
GAsyncResult * result

◆ getFrameInfo() [2/2]

bool SkCodec::getFrameInfo ( int  index,
FrameInfo info 
) const
inline

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.

739 {
740 if (index < 0) {
741 return false;
742 }
743 return this->onGetFrameInfo(index, info);
744 }

◆ getICCProfile()

const skcms_ICCProfile * SkCodec::getICCProfile ( ) const
inline

Return the ICC profile of the encoded data.

Definition at line 238 of file SkCodec.h.

238 {
239 return this->getEncodedInfo().profile();
240 }
const SkEncodedInfo & getEncodedInfo() const
Definition SkCodec.h:788

◆ getImage() [1/2]

std::tuple< sk_sp< SkImage >, SkCodec::Result > SkCodec::getImage ( )

Definition at line 565 of file SkCodec.cpp.

565 {
566 // If the codec reports that it is rotated, we need to rotate the image info
567 // it says it is, so the output is what the user wants.
568 SkImageInfo info = this->getInfo();
571 }
572 return this->getImage(info, nullptr);
573}
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
std::tuple< sk_sp< SkImage >, SkCodec::Result > getImage()
Definition SkCodec.cpp:565
SkEncodedOrigin getOrigin() const
Definition SkCodec.h:246
SkImageInfo getInfo() const
Definition SkCodec.h:228
SK_API SkImageInfo SwapWidthHeight(const SkImageInfo &info)

◆ getImage() [2/2]

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.

534 {
535 SkBitmap bm;
536 if (!bm.tryAllocPixels(info)) {
537 return {nullptr, kInternalError};
538 }
539
540 Result result;
541 auto decode = [this, options, &result](const SkPixmap& pm) {
542 result = this->getPixels(pm, options);
543 switch (result) {
547 return true;
548 default:
549 return false;
550 }
551 };
552
553 // If the codec reports this image is rotated, we will decode it into
554 // a temporary buffer, then copy it (rotated) into the pixmap belonging
555 // to bm that we allocated above. If the image is not rotated, we will
556 // decode straight into that allocated pixmap.
557 if (!SkPixmapUtils::Orient(bm.pixmap(), this->getOrigin(), decode)) {
558 return {nullptr, result};
559 }
560 // Setting the bitmap to be immutable saves us from having to copy it.
561 bm.setImmutable();
563}
void setImmutable()
Definition SkBitmap.cpp:400
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:271
Result getPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, const Options *)
Definition SkCodec.cpp:467
const Options & options() const
Definition SkCodec.h:880
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
SK_API bool Orient(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
static DecodeResult decode(std::string path)

◆ getInfo()

SkImageInfo SkCodec::getInfo ( ) const
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.

228{ return fEncodedInfo.makeImageInfo(); }
SkImageInfo makeImageInfo() const

◆ getOrigin()

SkEncodedOrigin SkCodec::getOrigin ( ) const
inline

Returns the image orientation stored in the EXIF data. If there is no EXIF data, or if we cannot read the EXIF data, returns kTopLeft.

Definition at line 246 of file SkCodec.h.

246{ return fOrigin; }

◆ getPixels() [1/3]

Result SkCodec::getPixels ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes 
)
inline

Simplified version of getPixels() that uses the default Options.

Definition at line 412 of file SkCodec.h.

412 {
413 return this->getPixels(info, pixels, rowBytes, nullptr);
414 }

◆ getPixels() [2/3]

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.

Parameters
infoA 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.

Returns
Result kSuccess, or another value explaining the type of failure.

Definition at line 467 of file SkCodec.cpp.

468 {
469 if (kUnknown_SkColorType == info.colorType()) {
470 return kInvalidConversion;
471 }
472 if (nullptr == pixels) {
473 return kInvalidParameters;
474 }
475 if (rowBytes < info.minRowBytes()) {
476 return kInvalidParameters;
477 }
478
479 // Default options.
480 Options optsStorage;
481 if (nullptr == options) {
482 options = &optsStorage;
483 } else {
484 if (options->fSubset) {
485 SkIRect subset(*options->fSubset);
486 if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) {
487 // FIXME: How to differentiate between not supporting subset at all
488 // and not supporting this particular subset?
489 return kUnimplemented;
490 }
491 }
492 }
493
494 const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes,
495 *options);
496 if (frameIndexResult != kSuccess) {
497 return frameIndexResult;
498 }
499
500 // FIXME: Support subsets somehow? Note that this works for SkWebpCodec
501 // because it supports arbitrary scaling/subset combinations.
502 if (!this->dimensionsSupported(info.dimensions())) {
503 return kInvalidScale;
504 }
505
506 fDstInfo = info;
507 fOptions = *options;
508
509 // On an incomplete decode, the subclass will specify the number of scanlines that it decoded
510 // successfully.
511 int rowsDecoded = 0;
512 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, &rowsDecoded);
513
514 // A return value of kIncompleteInput indicates a truncated image stream.
515 // In this case, we will fill any uninitialized memory with a default value.
516 // Some subclasses will take care of filling any uninitialized memory on
517 // their own. They indicate that all of the memory has been filled by
518 // setting rowsDecoded equal to the height.
519 if ((kIncompleteInput == result || kErrorInInput == result) && rowsDecoded != info.height()) {
520 // FIXME: (skbug.com/5772) fillIncompleteImage will fill using the swizzler's width, unless
521 // there is a subset. In that case, it will use the width of the subset. From here, the
522 // subset will only be non-null in the case of SkWebpCodec, but it treats the subset
523 // differenty from the other codecs, and it needs to use the width specified by the info.
524 // Set the subset to null so SkWebpCodec uses the correct width.
525 fOptions.fSubset = nullptr;
526 this->fillIncompleteImage(info, pixels, rowBytes, options->fZeroInitialized, info.height(),
527 rowsDecoded);
528 }
529
530 return result;
531}
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
virtual Result onGetPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, const Options &, int *rowsDecoded)=0
virtual bool onGetValidSubset(SkIRect *) const
Definition SkCodec.h:836
const SkIRect * fSubset
Definition SkCodec.h:347
ZeroInitialized fZeroInitialized
Definition SkCodec.h:329

◆ getPixels() [3/3]

Result SkCodec::getPixels ( const SkPixmap pm,
const Options opts = nullptr 
)
inline

Definition at line 416 of file SkCodec.h.

416 {
417 return this->getPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), opts);
418 }
size_t rowBytes() const
Definition SkPixmap.h:145
const SkImageInfo & info() const
Definition SkPixmap.h:135
void * writable_addr() const
Definition SkPixmap.h:483

◆ getRepetitionCount()

int SkCodec::getRepetitionCount ( )
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.

775 {
776 return this->onGetRepetitionCount();
777 }
virtual int onGetRepetitionCount()
Definition SkCodec.h:917

◆ getSampler()

virtual SkSampler * SkCodec::getSampler ( bool  )
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 SkBmpMaskCodec, SkBmpRLECodec, SkBmpStandardCodec, SkHeifCodec, SkIcoCodec, SkJpegCodec, SkPngCodec, and SkWbmpCodec.

Definition at line 1035 of file SkCodec.h.

1035{ return nullptr; }

◆ getScaledDimensions()

SkISize SkCodec::getScaledDimensions ( float  desiredScale) const
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.

255 {
256 // Negative and zero scales are errors.
257 SkASSERT(desiredScale > 0.0f);
258 if (desiredScale <= 0.0f) {
259 return SkISize::Make(0, 0);
260 }
261
262 // Upscaling is not supported. Return the original size if the client
263 // requests an upscale.
264 if (desiredScale >= 1.0f) {
265 return this->dimensions();
266 }
267 return this->onGetScaledDimensions(desiredScale);
268 }
SkISize dimensions() const
Definition SkCodec.h:230
virtual SkISize onGetScaledDimensions(float) const
Definition SkCodec.h:805
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ getScanlineOrder()

SkScanlineOrder SkCodec::getScanlineOrder ( ) const
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.

613{ return this->onGetScanlineOrder(); }
virtual SkScanlineOrder onGetScanlineOrder() const
Definition SkCodec.h:876

◆ getScanlines()

int SkCodec::getScanlines ( void *  dst,
int  countLines,
size_t  rowBytes 
)

Write the next countLines scanlines into dst.

Not valid to call before calling startScanlineDecode().

Parameters
dstMust be non-null, and large enough to hold countLines scanlines of size rowBytes.
countLinesNumber of lines to write.
rowBytesNumber of bytes per row. Must be large enough to hold a scanline based on the SkImageInfo used to create this object.
Returns
the number of lines successfully decoded. If this value is less than countLines, this will fill the remaining lines with a default value.

Definition at line 694 of file SkCodec.cpp.

694 {
695 if (fCurrScanline < 0) {
696 return 0;
697 }
698
699 SkASSERT(!fDstInfo.isEmpty());
700 if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) {
701 return 0;
702 }
703
704 const int linesDecoded = this->onGetScanlines(dst, countLines, rowBytes);
705 if (linesDecoded < countLines) {
706 this->fillIncompleteImage(this->dstInfo(), dst, rowBytes, this->options().fZeroInitialized,
707 countLines, linesDecoded);
708 }
709 fCurrScanline += countLines;
710 return linesDecoded;
711}
const SkImageInfo & dstInfo() const
Definition SkCodec.h:878
virtual int onGetScanlines(void *, int, size_t)
Definition SkCodec.h:1008
bool isEmpty() const
int height() const

◆ getSrcXformFormat()

XformFormat SkCodec::getSrcXformFormat ( ) const
inlineprotected

Definition at line 799 of file SkCodec.h.

799 {
800 return fSrcXformFormat;
801 }

◆ getValidSubset()

bool SkCodec::getValidSubset ( SkIRect desiredSubset) const
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.

Parameters
desiredSubsetIn/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.
Returns
true if this codec supports decoding desiredSubset (as returned, potentially modified)

Definition at line 285 of file SkCodec.h.

285 {
286 return this->onGetValidSubset(desiredSubset);
287 }

◆ getYUVAPlanes()

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().

Parameters
yuvaPixmapsContains preallocated pixmaps configured according to a successful call to queryYUVAInfo().

Definition at line 276 of file SkCodec.cpp.

276 {
277 if (!yuvaPixmaps.isValid()) {
278 return kInvalidInput;
279 }
280 if (!this->rewindIfNeeded()) {
281 return kCouldNotRewind;
282 }
283 return this->onGetYUVAPlanes(yuvaPixmaps);
284}
bool rewindIfNeeded()
Definition SkCodec.cpp:311
virtual Result onGetYUVAPlanes(const SkYUVAPixmaps &)
Definition SkCodec.h:834
bool isValid() const

◆ incrementalDecode()

Result SkCodec::incrementalDecode ( int rowsDecoded = nullptr)
inline

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.

Parameters
rowsDecodedOptional 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.
Returns
kSuccess if all lines requested in startIncrementalDecode have been completely decoded. kIncompleteInput otherwise.

Definition at line 498 of file SkCodec.h.

498 {
499 if (!fStartedIncrementalDecode) {
500 return kInvalidParameters;
501 }
502 return this->onIncrementalDecode(rowsDecoded);
503 }
virtual Result onIncrementalDecode(int *)
Definition SkCodec.h:1001

◆ MakeFromData() [1/2]

std::unique_ptr< SkCodec > SkCodec::MakeFromData ( sk_sp< SkData data,
SkPngChunkReader reader = nullptr 
)
static

Definition at line 238 of file SkCodec.cpp.

238 {
239 return MakeFromData(std::move(data), SkCodecs::get_decoders(), reader);
240}
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition SkCodec.cpp:241
const std::vector< Decoder > & get_decoders()
Definition SkCodec.cpp:130

◆ MakeFromData() [2/2]

std::unique_ptr< SkCodec > SkCodec::MakeFromData ( sk_sp< SkData data,
SkSpan< const SkCodecs::Decoder >  decoders,
SkPngChunkReader reader = nullptr 
)
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.

243 {
244 if (!data) {
245 return nullptr;
246 }
247 return MakeFromStream(SkMemoryStream::Make(std::move(data)), decoders, nullptr, reader);
248}
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
Definition SkCodec.cpp:163
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
Definition SkStream.cpp:314

◆ MakeFromStream() [1/2]

std::unique_ptr< SkCodec > SkCodec::MakeFromStream ( std::unique_ptr< SkStream stream,
Result outResult = nullptr,
SkPngChunkReader chunkReader = nullptr,
SelectionPolicy  selectionPolicy = SelectionPolicy::kPreferStillImage 
)
static

Definition at line 157 of file SkCodec.cpp.

159 {
160 return MakeFromStream(std::move(stream), SkCodecs::get_decoders(), outResult,
161 chunkReader, selectionPolicy);
162}

◆ MakeFromStream() [2/2]

std::unique_ptr< SkCodec > SkCodec::MakeFromStream ( std::unique_ptr< SkStream stream,
SkSpan< const SkCodecs::Decoder >  decoders,
Result outResult = nullptr,
SkPngChunkReader chunkReader = nullptr,
SelectionPolicy  selectionPolicy = SelectionPolicy::kPreferStillImage 
)
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.

165 {
166 Result resultStorage;
167 if (!outResult) {
168 outResult = &resultStorage;
169 }
170
171 if (!stream) {
172 *outResult = kInvalidInput;
173 return nullptr;
174 }
175
176 if (selectionPolicy != SelectionPolicy::kPreferStillImage
177 && selectionPolicy != SelectionPolicy::kPreferAnimation) {
178 *outResult = kInvalidParameters;
179 return nullptr;
180 }
181
182 constexpr size_t bytesToRead = MinBufferedBytesNeeded();
183
184 char buffer[bytesToRead];
185 size_t bytesRead = stream->peek(buffer, bytesToRead);
186
187 // It is also possible to have a complete image less than bytesToRead bytes
188 // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead.
189 // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter
190 // than bytesToRead, so pass that directly to the decoder.
191 // It also is possible the stream uses too small a buffer for peeking, but
192 // we trust the caller to use a large enough buffer.
193
194 if (0 == bytesRead) {
195 // TODO: After implementing peek in CreateJavaOutputStreamAdaptor.cpp, this
196 // printf could be useful to notice failures.
197 // SkCodecPrintf("Encoded image data failed to peek!\n");
198
199 // It is possible the stream does not support peeking, but does support
200 // rewinding.
201 // Attempt to read() and pass the actual amount read to the decoder.
202 bytesRead = stream->read(buffer, bytesToRead);
203 if (!stream->rewind()) {
204 SkCodecPrintf("Encoded image data could not peek or rewind to determine format!\n");
205 *outResult = kCouldNotRewind;
206 return nullptr;
207 }
208 }
209
210 SkCodecs::MakeFromStreamCallback rawFallback = nullptr;
211 for (const SkCodecs::Decoder& proc : decoders) {
212 if (proc.isFormat(buffer, bytesRead)) {
213 // Some formats are special, since we want to be able to provide an extra parameter.
214 if (proc.id == "png") {
215 return proc.makeFromStream(std::move(stream), outResult, chunkReader);
216 } else if (proc.id == "heif" || proc.id == "gif") {
217 return proc.makeFromStream(std::move(stream), outResult, &selectionPolicy);
218 } else if (proc.id == "raw") {
219 rawFallback = proc.makeFromStream;
220 continue;
221 }
222 return proc.makeFromStream(std::move(stream), outResult, nullptr);
223 }
224 }
225 if (rawFallback != nullptr) {
226 // Fallback to raw.
227 return rawFallback(std::move(stream), outResult, nullptr);
228 }
229
230 if (bytesRead < bytesToRead) {
231 *outResult = kIncompleteInput;
232 } else {
233 *outResult = kUnimplemented;
234 }
235 return nullptr;
236}
#define SkCodecPrintf(...)
Definition SkCodecPriv.h:23
static constexpr size_t MinBufferedBytesNeeded()
Definition SkCodec.h:71
virtual bool rewind()
Definition SkStream.h:100
virtual size_t peek(void *, size_t) const
Definition SkStream.h:68
virtual size_t read(void *buffer, size_t size)=0
static const uint8_t buffer[]

◆ MinBufferedBytesNeeded()

static constexpr size_t SkCodec::MinBufferedBytesNeeded ( )
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.

71{ return 32; }

◆ nextScanline()

int SkCodec::nextScanline ( ) const
inline

Returns the y-coordinate of the next row to be returned by the scanline decoder.

This will equal fCurrScanline, except in the case of strangely encoded image types (bottom-up bmps).

Results are undefined when not in scanline decoding mode.

Definition at line 624 of file SkCodec.h.

624{ return this->outputScanline(fCurrScanline); }
int outputScanline(int inputScanline) const
Definition SkCodec.cpp:731

◆ onDimensionsSupported()

virtual bool SkCodec::onDimensionsSupported ( const SkISize )
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.

815 {
816 return false;
817 }

◆ onGetEncodedFormat()

virtual SkEncodedImageFormat SkCodec::onGetEncodedFormat ( ) const
protectedpure virtual

◆ onGetFrameCount()

virtual int SkCodec::onGetFrameCount ( )
inlineprotectedvirtual

Reimplemented in SkAvifCodec, SkHeifCodec, SkJpegxlCodec, SkWebpCodec, and SkWuffsCodec.

Definition at line 909 of file SkCodec.h.

909 {
910 return 1;
911 }

◆ onGetFrameInfo()

virtual bool SkCodec::onGetFrameInfo ( int  ,
FrameInfo  
) const
inlineprotectedvirtual

Reimplemented in SkAvifCodec, SkHeifCodec, SkJpegxlCodec, SkWebpCodec, and SkWuffsCodec.

Definition at line 913 of file SkCodec.h.

913 {
914 return false;
915 }

◆ onGetGainmapInfo()

virtual bool SkCodec::onGetGainmapInfo ( SkGainmapInfo ,
std::unique_ptr< SkStream > *   
)
inlineprotectedvirtual

Reimplemented in SkJpegCodec.

Definition at line 803 of file SkCodec.h.

803{ return false; }

◆ onGetPixels()

virtual Result SkCodec::onGetPixels ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes,
const Options ,
int rowsDecoded 
)
protectedpure virtual
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.

Implemented in SkPngCodec, SkWbmpCodec, SkWebpCodec, SkWuffsCodec, SkBmpMaskCodec, SkBmpRLECodec, SkBmpStandardCodec, SkIcoCodec, SkJpegCodec, SkRawCodec, SkAvifCodec, SkHeifCodec, and SkJpegxlCodec.

◆ onGetRepetitionCount()

virtual int SkCodec::onGetRepetitionCount ( )
inlineprotectedvirtual

Reimplemented in SkAvifCodec, SkHeifCodec, SkJpegxlCodec, SkWebpCodec, and SkWuffsCodec.

Definition at line 917 of file SkCodec.h.

917 {
918 return 0;
919 }

◆ onGetScaledDimensions()

virtual SkISize SkCodec::onGetScaledDimensions ( float  ) const
inlineprotectedvirtual

Reimplemented in SkIcoCodec, SkJpegCodec, SkRawCodec, and SkScalingCodec.

Definition at line 805 of file SkCodec.h.

805 {
806 // By default, scaling is not supported.
807 return this->dimensions();
808 }

◆ onGetScanlineOrder()

virtual SkScanlineOrder SkCodec::onGetScanlineOrder ( ) const
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.

876{ return kTopDown_SkScanlineOrder; }

◆ onGetScanlines()

virtual int SkCodec::onGetScanlines ( void *  ,
int  ,
size_t   
)
inlineprivatevirtual

Reimplemented in SkWbmpCodec, SkBmpCodec, SkHeifCodec, SkIcoCodec, and SkJpegCodec.

Definition at line 1008 of file SkCodec.h.

1008{ return 0; }

◆ onGetValidSubset()

virtual bool SkCodec::onGetValidSubset ( SkIRect ) const
inlineprotectedvirtual

Reimplemented in SkWebpCodec.

Definition at line 836 of file SkCodec.h.

836 {
837 // By default, subsets are not supported.
838 return false;
839 }

◆ onGetYUVAPlanes()

virtual Result SkCodec::onGetYUVAPlanes ( const SkYUVAPixmaps )
inlineprotectedvirtual

Reimplemented in SkJpegCodec.

Definition at line 834 of file SkCodec.h.

834{ return kUnimplemented; }

◆ onIncrementalDecode()

virtual Result SkCodec::onIncrementalDecode ( int )
inlineprivatevirtual

Reimplemented in SkPngCodec, SkIcoCodec, and SkWuffsCodec.

Definition at line 1001 of file SkCodec.h.

1001 {
1002 return kUnimplemented;
1003 }

◆ onOutputScanline()

int SkCodec::onOutputScanline ( int  inputScanline) const
protectedvirtual

Definition at line 736 of file SkCodec.cpp.

736 {
737 switch (this->getScanlineOrder()) {
739 return inputScanline;
741 return fEncodedInfo.height() - inputScanline - 1;
742 default:
743 // This case indicates an interlaced gif and is implemented by SkGifCodec.
744 SkASSERT(false);
745 return 0;
746 }
747}
SkScanlineOrder getScanlineOrder() const
Definition SkCodec.h:613

◆ onQueryYUVAInfo()

virtual bool SkCodec::onQueryYUVAInfo ( const SkYUVAPixmapInfo::SupportedDataTypes ,
SkYUVAPixmapInfo  
) const
inlineprotectedvirtual

Reimplemented in SkJpegCodec.

Definition at line 831 of file SkCodec.h.

832 { return false; }

◆ onRewind()

virtual bool SkCodec::onRewind ( )
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.

858 {
859 return true;
860 }

◆ onSkipScanlines()

virtual bool SkCodec::onSkipScanlines ( int  )
inlineprivatevirtual

Reimplemented in SkBmpCodec, SkHeifCodec, SkIcoCodec, SkJpegCodec, and SkWbmpCodec.

Definition at line 1006 of file SkCodec.h.

1006{ return false; }

◆ onStartIncrementalDecode()

virtual Result SkCodec::onStartIncrementalDecode ( const SkImageInfo ,
void *  ,
size_t  ,
const Options  
)
inlineprivatevirtual

Reimplemented in SkWuffsCodec, SkIcoCodec, and SkPngCodec.

Definition at line 996 of file SkCodec.h.

997 {
998 return kUnimplemented;
999 }

◆ onStartScanlineDecode()

virtual Result SkCodec::onStartScanlineDecode ( const SkImageInfo ,
const Options  
)
inlineprivatevirtual

Reimplemented in SkHeifCodec, SkJpegCodec, SkWbmpCodec, SkBmpCodec, and SkIcoCodec.

Definition at line 991 of file SkCodec.h.

992 {
993 return kUnimplemented;
994 }

◆ options()

const Options & SkCodec::options ( ) const
inlineprotected

Definition at line 880 of file SkCodec.h.

880{ return fOptions; }

◆ outputScanline()

int SkCodec::outputScanline ( int  inputScanline) const

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.

731 {
732 SkASSERT(0 <= inputScanline && inputScanline < fEncodedInfo.height());
733 return this->onOutputScanline(inputScanline);
734}
virtual int onOutputScanline(int inputScanline) const
Definition SkCodec.cpp:736

◆ queryYUVAInfo()

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.

Parameters
supportedDataTypesIndicates 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.
yuvaPixmapInfoOutput parameter that specifies the planar configuration, subsampling, orientation, chroma siting, plane color types, and row bytes.

Definition at line 267 of file SkCodec.cpp.

268 {
269 if (!yuvaPixmapInfo) {
270 return false;
271 }
272 return this->onQueryYUVAInfo(supportedDataTypes, yuvaPixmapInfo) &&
273 yuvaPixmapInfo->isSupported(supportedDataTypes);
274}
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
Definition SkCodec.h:831
bool isSupported(const SupportedDataTypes &) const

◆ Register()

static void SkCodec::Register ( bool(*)(const void *, size_t)  peek,
std::unique_ptr< SkCodec >(*)(std::unique_ptr< SkStream >, SkCodec::Result *)  make 
)
static

◆ ResultToString()

const char * SkCodec::ResultToString ( Result  result)
static

Readable string representing the error code.

Definition at line 880 of file SkCodec.cpp.

880 {
881 switch (result) {
882 case kSuccess:
883 return "success";
884 case kIncompleteInput:
885 return "incomplete input";
886 case kErrorInInput:
887 return "error in input";
889 return "invalid conversion";
890 case kInvalidScale:
891 return "invalid scale";
893 return "invalid parameters";
894 case kInvalidInput:
895 return "invalid input";
896 case kCouldNotRewind:
897 return "could not rewind";
898 case kInternalError:
899 return "internal error";
900 case kUnimplemented:
901 return "unimplemented";
902 default:
903 SkASSERT(false);
904 return "bogus result value";
905 }
906}

◆ rewindIfNeeded()

bool SkCodec::rewindIfNeeded ( )
protected

If the stream was previously read, attempt to rewind.

If the stream needed to be rewound, call onRewind.

Returns
true if the codec is at the right position and can be used. false if there was a failure to rewind.

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.

311 {
312 // Store the value of fNeedsRewind so we can update it. Next read will
313 // require a rewind.
314 const bool needsRewind = fNeedsRewind;
315 fNeedsRewind = true;
316 if (!needsRewind) {
317 return true;
318 }
319
320 // startScanlineDecode will need to be called before decoding scanlines.
321 fCurrScanline = -1;
322 // startIncrementalDecode will need to be called before incrementalDecode.
323 fStartedIncrementalDecode = false;
324
325 // Some codecs do not have a stream. They may hold onto their own data or another codec.
326 // They must handle rewinding themselves.
327 if (fStream && !fStream->rewind()) {
328 return false;
329 }
330
331 return this->onRewind();
332}
virtual bool onRewind()
Definition SkCodec.h:858

◆ setSrcXformFormat()

void SkCodec::setSrcXformFormat ( XformFormat  pixelFormat)
protected

Definition at line 263 of file SkCodec.cpp.

263 {
264 fSrcXformFormat = pixelFormat;
265}

◆ skipScanlines()

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.

Returns
true if the scanlines were successfully skipped false on failure, possible reasons for failure include: An incomplete input image stream. Calling this function before calling startScanlineDecode(). If countLines is less than zero or so large that it moves the current scanline past the end of the image.

Definition at line 713 of file SkCodec.cpp.

713 {
714 if (fCurrScanline < 0) {
715 return false;
716 }
717
718 SkASSERT(!fDstInfo.isEmpty());
719 if (countLines < 0 || fCurrScanline + countLines > fDstInfo.height()) {
720 // Arguably, we could just skip the scanlines which are remaining,
721 // and return true. We choose to return false so the client
722 // can catch their bug.
723 return false;
724 }
725
726 bool result = this->onSkipScanlines(countLines);
727 fCurrScanline += countLines;
728 return result;
729}
virtual bool onSkipScanlines(int)
Definition SkCodec.h:1006

◆ startIncrementalDecode() [1/2]

Result SkCodec::startIncrementalDecode ( const SkImageInfo dstInfo,
void *  dst,
size_t  rowBytes 
)
inline

Definition at line 471 of file SkCodec.h.

471 {
472 return this->startIncrementalDecode(dstInfo, dst, rowBytes, nullptr);
473 }
Result startIncrementalDecode(const SkImageInfo &dstInfo, void *dst, size_t rowBytes, const Options *)
Definition SkCodec.cpp:575

◆ startIncrementalDecode() [2/2]

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.

Parameters
dstInfoInfo of the destination. If the dimensions do not match those of getInfo, this implies a scale.
dstMemory to write to. Needs to be large enough to hold the subset, if present, or the full image as described in dstInfo.
optionsContains decoding options, including if memory is zero initialized and whether to decode a subset.
Returns
Enum representing success or reason for failure.

Definition at line 575 of file SkCodec.cpp.

576 {
577 fStartedIncrementalDecode = false;
578
579 if (kUnknown_SkColorType == info.colorType()) {
580 return kInvalidConversion;
581 }
582 if (nullptr == pixels) {
583 return kInvalidParameters;
584 }
585
586 // Set options.
587 Options optsStorage;
588 if (nullptr == options) {
589 options = &optsStorage;
590 } else {
591 if (options->fSubset) {
592 SkIRect size = SkIRect::MakeSize(info.dimensions());
593 if (!size.contains(*options->fSubset)) {
594 return kInvalidParameters;
595 }
596
597 const int top = options->fSubset->top();
598 const int bottom = options->fSubset->bottom();
599 if (top < 0 || top >= info.height() || top >= bottom || bottom > info.height()) {
600 return kInvalidParameters;
601 }
602 }
603 }
604
605 const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes,
606 *options);
607 if (frameIndexResult != kSuccess) {
608 return frameIndexResult;
609 }
610
611 if (!this->dimensionsSupported(info.dimensions())) {
612 return kInvalidScale;
613 }
614
615 fDstInfo = info;
616 fOptions = *options;
617
618 const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes, fOptions);
619 if (kSuccess == result) {
620 fStartedIncrementalDecode = true;
621 } else if (kUnimplemented == result) {
622 // FIXME: This is temporarily necessary, until we transition SkCodec
623 // implementations from scanline decoding to incremental decoding.
624 // SkAndroidCodec will first attempt to use incremental decoding, but
625 // will fall back to scanline decoding if incremental returns
626 // kUnimplemented. rewindIfNeeded(), above, set fNeedsRewind to true
627 // (after potentially rewinding), but we do not want the next call to
628 // startScanlineDecode() to do a rewind.
629 fNeedsRewind = false;
630 }
631 return result;
632}
virtual Result onStartIncrementalDecode(const SkImageInfo &, void *, size_t, const Options &)
Definition SkCodec.h:996
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
constexpr int32_t top() const
Definition SkRect.h:120
constexpr int32_t bottom() const
Definition SkRect.h:134
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66

◆ startScanlineDecode() [1/2]

Result SkCodec::startScanlineDecode ( const SkImageInfo dstInfo)
inline

Simplified version of startScanlineDecode() that uses the default Options.

Definition at line 531 of file SkCodec.h.

531 {
532 return this->startScanlineDecode(dstInfo, nullptr);
533 }
Result startScanlineDecode(const SkImageInfo &dstInfo, const Options *options)
Definition SkCodec.cpp:635

◆ startScanlineDecode() [2/2]

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.

Parameters
dstInfoInfo of the destination. If the dimensions do not match those of getInfo, this implies a scale.
optionsContains decoding options, including if memory is zero initialized.
Returns
Enum representing success or reason for failure.

Definition at line 635 of file SkCodec.cpp.

636 {
637 // Reset fCurrScanline in case of failure.
638 fCurrScanline = -1;
639
640 // Set options.
641 Options optsStorage;
642 if (nullptr == options) {
643 options = &optsStorage;
644 } else if (options->fSubset) {
645 SkIRect size = SkIRect::MakeSize(info.dimensions());
646 if (!size.contains(*options->fSubset)) {
647 return kInvalidInput;
648 }
649
650 // We only support subsetting in the x-dimension for scanline decoder.
651 // Subsetting in the y-dimension can be accomplished using skipScanlines().
652 if (options->fSubset->top() != 0 || options->fSubset->height() != info.height()) {
653 return kInvalidInput;
654 }
655 }
656
657 // Scanline decoding only supports decoding the first frame.
658 if (options->fFrameIndex != 0) {
659 return kUnimplemented;
660 }
661
662 // The void* dst and rowbytes in handleFrameIndex or only used for decoding prior
663 // frames, which is not supported here anyway, so it is safe to pass nullptr/0.
664 const Result frameIndexResult = this->handleFrameIndex(info, nullptr, 0, *options);
665 if (frameIndexResult != kSuccess) {
666 return frameIndexResult;
667 }
668
669 // FIXME: Support subsets somehow?
670 if (!this->dimensionsSupported(info.dimensions())) {
671 return kInvalidScale;
672 }
673
674 const Result result = this->onStartScanlineDecode(info, *options);
675 if (result != SkCodec::kSuccess) {
676 return result;
677 }
678
679 // FIXME: See startIncrementalDecode. That method set fNeedsRewind to false
680 // so that when onStartScanlineDecode calls rewindIfNeeded it would not
681 // rewind. But it also relies on that call to rewindIfNeeded to set
682 // fNeedsRewind to true for future decodes. When
683 // fUsingCallbackForHandleFrameIndex is true, that call to rewindIfNeeded is
684 // skipped, so this method sets it back to true.
685 SkASSERT(fUsingCallbackForHandleFrameIndex || fNeedsRewind);
686 fNeedsRewind = true;
687
688 fCurrScanline = 0;
689 fDstInfo = info;
690 fOptions = *options;
691 return kSuccess;
692}
virtual Result onStartScanlineDecode(const SkImageInfo &, const Options &)
Definition SkCodec.h:991
constexpr int32_t height() const
Definition SkRect.h:165

◆ stream()

SkStream * SkCodec::stream ( )
inlineprotected

Get method for the input stream

Definition at line 865 of file SkCodec.h.

865 {
866 return fStream.get();
867 }

◆ usesColorXform()

virtual bool SkCodec::usesColorXform ( ) const
inlineprotectedvirtual

Reimplemented in SkIcoCodec, SkRawCodec, and SkWbmpCodec.

Definition at line 903 of file SkCodec.h.

903{ return true; }

◆ xformOnDecode()

bool SkCodec::xformOnDecode ( ) const
inlineprotected

Definition at line 907 of file SkCodec.h.

907{ return fXformTime == kDecodeRow_XformTime; }

Friends And Related Symbol Documentation

◆ DM::CodecSrc

friend class DM::CodecSrc
friend

Definition at line 1037 of file SkCodec.h.

◆ PNGCodecGM

friend class PNGCodecGM
friend

Definition at line 1038 of file SkCodec.h.

◆ SkAndroidCodec

friend class SkAndroidCodec
friend

Definition at line 1041 of file SkCodec.h.

◆ SkIcoCodec

friend class SkIcoCodec
friend

Definition at line 1040 of file SkCodec.h.

◆ SkPDFBitmap

friend class SkPDFBitmap
friend

Definition at line 1042 of file SkCodec.h.

◆ SkSampledCodec

friend class SkSampledCodec
friend

Definition at line 1039 of file SkCodec.h.

Member Data Documentation

◆ kNoFrame

constexpr int SkCodec::kNoFrame = -1
staticconstexpr

Definition at line 650 of file SkCodec.h.

◆ kRepetitionCountInfinite

constexpr int SkCodec::kRepetitionCountInfinite = -1
staticconstexpr

Definition at line 759 of file SkCodec.h.


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