Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
SkReadPixelsRec Struct Reference

#include <SkReadPixelsRec.h>

Public Member Functions

 SkReadPixelsRec (const SkImageInfo &info, void *pixels, size_t rowBytes, int x, int y)
 
 SkReadPixelsRec (const SkPixmap &pm, int x, int y)
 
bool trim (int srcWidth, int srcHeight)
 

Public Attributes

void * fPixels
 
size_t fRowBytes
 
SkImageInfo fInfo
 
int fX
 
int fY
 

Detailed Description

Helper class to package and trim the parameters passed to readPixels()

Definition at line 19 of file SkReadPixelsRec.h.

Constructor & Destructor Documentation

◆ SkReadPixelsRec() [1/2]

SkReadPixelsRec::SkReadPixelsRec ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes,
int  x,
int  y 
)
inline

Definition at line 20 of file SkReadPixelsRec.h.

21 : fPixels(pixels)
22 , fRowBytes(rowBytes)
23 , fInfo(info)
24 , fX(x)
25 , fY(y)
26 {}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
double y
double x
SkImageInfo fInfo

◆ SkReadPixelsRec() [2/2]

SkReadPixelsRec::SkReadPixelsRec ( const SkPixmap pm,
int  x,
int  y 
)
inline

Definition at line 28 of file SkReadPixelsRec.h.

30 , fRowBytes(pm.rowBytes())
31 , fInfo(pm.info())
32 , fX(x)
33 , fY(y)
34 {}
size_t rowBytes() const
Definition: SkPixmap.h:145
const SkImageInfo & info() const
Definition: SkPixmap.h:135
void * writable_addr() const
Definition: SkPixmap.h:483

Member Function Documentation

◆ trim()

bool SkReadPixelsRec::trim ( int  srcWidth,
int  srcHeight 
)

Definition at line 11 of file SkReadPixelsRec.cpp.

11 {
12 if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()) {
13 return false;
14 }
15 if (0 >= fInfo.width() || 0 >= fInfo.height()) {
16 return false;
17 }
18
19 int x = fX;
20 int y = fY;
22 if (!srcR.intersect({0, 0, srcWidth, srcHeight})) {
23 return false;
24 }
25
26 // if x or y are negative, then we have to adjust pixels
27 if (x > 0) {
28 x = 0;
29 }
30 if (y > 0) {
31 y = 0;
32 }
33 // here x,y are either 0 or negative
34 // we negate and add them so UBSAN (pointer-overflow) doesn't get confused.
35 fPixels = ((char*)fPixels + -y*fRowBytes + -x*fInfo.bytesPerPixel());
36 // the intersect may have shrunk info's logical size
38 fX = srcR.x();
39 fY = srcR.y();
40
41 return true;
42}
Definition: SkRect.h:32
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
size_t minRowBytes() const
Definition: SkImageInfo.h:517
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454
int bytesPerPixel() const
Definition: SkImageInfo.h:492
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371

Member Data Documentation

◆ fInfo

SkImageInfo SkReadPixelsRec::fInfo

Definition at line 38 of file SkReadPixelsRec.h.

◆ fPixels

void* SkReadPixelsRec::fPixels

Definition at line 36 of file SkReadPixelsRec.h.

◆ fRowBytes

size_t SkReadPixelsRec::fRowBytes

Definition at line 37 of file SkReadPixelsRec.h.

◆ fX

int SkReadPixelsRec::fX

Definition at line 39 of file SkReadPixelsRec.h.

◆ fY

int SkReadPixelsRec::fY

Definition at line 40 of file SkReadPixelsRec.h.


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