Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
SkBmpRLECodec Class Reference

#include <SkBmpRLECodec.h>

Inheritance diagram for SkBmpRLECodec:
SkBmpCodec SkCodec SkNoncopyable

Public Member Functions

 SkBmpRLECodec (SkEncodedInfo &&info, std::unique_ptr< SkStream >, uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor, uint32_t offset, SkCodec::SkScanlineOrder rowOrder)
 
int setSampleX (int)
 
int fillWidth () const
 
- 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 ()
 

Protected Member Functions

Result onGetPixels (const SkImageInfo &dstInfo, void *dst, size_t dstRowBytes, const Options &, int *) override
 
SkCodec::Result onPrepareToDecode (const SkImageInfo &dstInfo, const SkCodec::Options &options) override
 
- Protected Member Functions inherited from SkBmpCodec
 SkBmpCodec (SkEncodedInfo &&info, std::unique_ptr< SkStream >, uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder)
 
SkEncodedImageFormat onGetEncodedFormat () const override
 
bool onRewind () override
 
bool inIco () const
 
virtual bool onInIco () const
 
int32_t getDstRow (int32_t y, int32_t height) const
 
uint16_t bitsPerPixel () const
 
SkScanlineOrder onGetScanlineOrder () const override
 
size_t srcRowBytes () const
 
SkCodec::Result prepareToDecode (const SkImageInfo &dstInfo, const SkCodec::Options &options)
 
uint32_t * xformBuffer () const
 
void resetXformBuffer (int count)
 
- 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 bool onQueryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
 
virtual Result onGetYUVAPlanes (const SkYUVAPixmaps &)
 
virtual bool onGetValidSubset (SkIRect *) const
 
bool rewindIfNeeded ()
 
SkStreamstream ()
 
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

int decodeRows (const SkImageInfo &dstInfo, void *dst, size_t dstRowBytes, const Options &opts) override
 
bool skipRows (int count) override
 
SkSamplergetSampler (bool createIfNecessary) override
 

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 Member Functions inherited from SkBmpCodec
static bool IsBmp (const void *, size_t)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, Result *)
 
static std::unique_ptr< SkCodecMakeFromIco (std::unique_ptr< SkStream >, Result *)
 
- 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 *))
 
- 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
 
- Static Protected Member Functions inherited from SkBmpCodec
static Result ReadHeader (SkStream *, bool inIco, std::unique_ptr< SkCodec > *codecOut)
 
- Static Protected Attributes inherited from SkBmpCodec
static constexpr SkColorType kXformSrcColorType = kBGRA_8888_SkColorType
 
static constexpr auto kXformSrcColorFormat = skcms_PixelFormat_BGRA_8888
 

Detailed Description

Definition at line 29 of file SkBmpRLECodec.h.

Constructor & Destructor Documentation

◆ SkBmpRLECodec()

SkBmpRLECodec::SkBmpRLECodec ( SkEncodedInfo &&  info,
std::unique_ptr< SkStream stream,
uint16_t  bitsPerPixel,
uint32_t  numColors,
uint32_t  bytesPerColor,
uint32_t  offset,
SkCodec::SkScanlineOrder  rowOrder 
)

Definition at line 33 of file SkBmpRLECodec.cpp.

38 : INHERITED(std::move(info), std::move(stream), bitsPerPixel, rowOrder)
39 , fColorTable(nullptr)
40 , fNumColors(numColors)
41 , fBytesPerColor(bytesPerColor)
42 , fOffset(offset)
43 , fBytesBuffered(0)
44 , fCurrRLEByte(0)
45 , fSampleX(1)
46{}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
uint16_t bitsPerPixel() const
Definition SkBmpCodec.h:87
SkStream * stream()
Definition SkCodec.h:865
Point offset

Member Function Documentation

◆ decodeRows()

int SkBmpRLECodec::decodeRows ( const SkImageInfo dstInfo,
void *  dst,
size_t  dstRowBytes,
const Options opts 
)
overrideprivatevirtual

Implements SkBmpCodec.

Definition at line 292 of file SkBmpRLECodec.cpp.

293 {
294 int height = info.height();
295
296 // Account for sampling.
297 SkImageInfo dstInfo = info.makeWH(this->fillWidth(), height);
298
299 // Set the background as transparent. Then, if the RLE code skips pixels,
300 // the skipped pixels will be transparent.
301 if (dst) {
302 SkSampler::Fill(dstInfo, dst, dstRowBytes, opts.fZeroInitialized);
303 }
304
305 // Adjust the height and the dst if the previous call to decodeRows() left us
306 // with lines that need to be skipped.
307 if (height > fLinesToSkip) {
308 height -= fLinesToSkip;
309 if (dst) {
310 dst = SkTAddOffset<void>(dst, fLinesToSkip * dstRowBytes);
311 }
312 fLinesToSkip = 0;
313
315 } else {
316 fLinesToSkip -= height;
317 return height;
318 }
319
320 void* decodeDst = dst;
321 size_t decodeRowBytes = dstRowBytes;
322 SkImageInfo decodeInfo = dstInfo;
323 if (decodeDst) {
324 if (this->colorXform()) {
325 decodeInfo = decodeInfo.makeColorType(kXformSrcColorType);
327 int count = height * dstInfo.width();
328 this->resetXformBuffer(count);
329 sk_bzero(this->xformBuffer(), count * sizeof(uint32_t));
330 decodeDst = this->xformBuffer();
331 decodeRowBytes = dstInfo.width() * sizeof(uint32_t);
332 }
333 }
334 }
335
336 int decodedHeight = this->decodeRLE(decodeInfo, decodeDst, decodeRowBytes);
337 if (this->colorXform() && decodeDst) {
338 for (int y = 0; y < decodedHeight; y++) {
339 this->applyColorXform(dst, decodeDst, dstInfo.width());
340 decodeDst = SkTAddOffset<void>(decodeDst, decodeRowBytes);
341 dst = SkTAddOffset<void>(dst, dstRowBytes);
342 }
343 }
344
345 return decodedHeight;
346}
int count
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
static void sk_bzero(void *buffer, size_t size)
Definition SkMalloc.h:105
void resetXformBuffer(int count)
Definition SkBmpCodec.h:105
uint32_t * xformBuffer() const
Definition SkBmpCodec.h:104
static constexpr SkColorType kXformSrcColorType
Definition SkBmpCodec.h:111
int fillWidth() const
const SkImageInfo & dstInfo() const
Definition SkCodec.h:878
void applyColorXform(void *dst, const void *src, int count) const
Definition SkCodec.cpp:853
bool colorXform() const
Definition SkCodec.h:906
static void Fill(const SkImageInfo &info, void *dst, size_t rowBytes, SkCodec::ZeroInitialized zeroInit)
Definition SkSampler.cpp:20
double y
dst
Definition cp.py:12
int32_t height
SkImageInfo makeWH(int newWidth, int newHeight) const
int width() const
SkColorType colorType() const
SkImageInfo makeColorType(SkColorType newColorType) const

◆ fillWidth()

int SkBmpRLECodec::fillWidth ( ) const

Definition at line 579 of file SkBmpRLECodec.cpp.

579 {
580 return get_scaled_dimension(this->dimensions().width(), fSampleX);
581}
static int get_scaled_dimension(int srcDimension, int sampleSize)
Definition SkCodecPriv.h:44
SkISize dimensions() const
Definition SkCodec.h:230
int32_t width

◆ getSampler()

SkSampler * SkBmpRLECodec::getSampler ( bool  )
overrideprivatevirtual

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 566 of file SkBmpRLECodec.cpp.

566 {
567 if (!fSampler && createIfNecessary) {
568 fSampler = std::make_unique<SkBmpRLESampler>(this);
569 }
570
571 return fSampler.get();
572}

◆ onGetPixels()

SkCodec::Result SkBmpRLECodec::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 51 of file SkBmpRLECodec.cpp.

54 {
55 if (opts.fSubset) {
56 // Subsets are not supported.
57 return kUnimplemented;
58 }
59
60 Result result = this->prepareToDecode(dstInfo, opts);
61 if (kSuccess != result) {
62 return result;
63 }
64
65 // Perform the decode
66 int rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts);
67 if (rows != dstInfo.height()) {
68 // We set rowsDecoded equal to the height because the background has already
69 // been filled. RLE encodings sometimes skip pixels, so we always start by
70 // filling the background.
71 *rowsDecoded = dstInfo.height();
72 return kIncompleteInput;
73 }
74
75 return kSuccess;
76}
SkCodec::Result prepareToDecode(const SkImageInfo &dstInfo, const SkCodec::Options &options)
int decodeRows(const SkImageInfo &dstInfo, void *dst, size_t dstRowBytes, const Options &opts) override
@ kIncompleteInput
Definition SkCodec.h:84
@ kUnimplemented
Definition SkCodec.h:123
@ kSuccess
Definition SkCodec.h:80
GAsyncResult * result
int height() const

◆ onPrepareToDecode()

SkCodec::Result SkBmpRLECodec::onPrepareToDecode ( const SkImageInfo dstInfo,
const SkCodec::Options options 
)
overrideprotectedvirtual

Implements SkBmpCodec.

Definition at line 252 of file SkBmpRLECodec.cpp.

253 {
254 // FIXME: Support subsets for scanline decodes.
255 if (options.fSubset) {
256 // Subsets are not supported.
257 return kUnimplemented;
258 }
259
260 // Reset fSampleX. If it needs to be a value other than 1, it will get modified by
261 // the sampler.
262 fSampleX = 1;
263 fLinesToSkip = 0;
264
265 SkColorType colorTableColorType = dstInfo.colorType();
266 if (this->colorXform()) {
267 // Just set a known colorType for the colorTable. No need to actually transform
268 // the colors in the colorTable.
269 colorTableColorType = kBGRA_8888_SkColorType;
270 }
271
272 // Create the color table if necessary and prepare the stream for decode
273 // Note that if it is non-NULL, inputColorCount will be modified
274 if (!this->createColorTable(colorTableColorType)) {
275 SkCodecPrintf("Error: could not create color table.\n");
277 }
278
279 // Initialize a buffer for encoded RLE data
280 if (!this->initializeStreamBuffer()) {
281 SkCodecPrintf("Error: cannot initialize stream buffer.\n");
283 }
284
285 return SkCodec::kSuccess;
286}
#define SkCodecPrintf(...)
Definition SkCodecPriv.h:23
SkColorType
Definition SkColorType.h:19
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kInvalidInput
Definition SkCodec.h:109
const Options & options() const
Definition SkCodec.h:880
const SkIRect * fSubset
Definition SkCodec.h:347

◆ setSampleX()

int SkBmpRLECodec::setSampleX ( int  sampleX)

Definition at line 574 of file SkBmpRLECodec.cpp.

574 {
575 fSampleX = sampleX;
576 return this->fillWidth();
577}

◆ skipRows()

bool SkBmpRLECodec::skipRows ( int  count)
overrideprivatevirtual

Reimplemented from SkBmpCodec.

Definition at line 536 of file SkBmpRLECodec.cpp.

536 {
537 const SkImageInfo rowInfo = SkImageInfo::Make(this->dimensions().width(), count,
538 kN32_SkColorType, kUnpremul_SkAlphaType);
539 return count == this->decodeRows(rowInfo, nullptr, 0, this->options());
540}
kUnpremul_SkAlphaType
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

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