Flutter Engine
The Flutter Engine
Functions
SkPixmapUtils Namespace Reference

Functions

SK_API bool Orient (const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
 
SK_API SkImageInfo SwapWidthHeight (const SkImageInfo &info)
 
template<typename Fn >
bool Orient (const SkPixmap &dst, SkEncodedOrigin origin, Fn &&decode)
 

Function Documentation

◆ Orient() [1/2]

bool SkPixmapUtils::Orient ( const SkPixmap dst,
const SkPixmap src,
SkEncodedOrigin  origin 
)

Copy the pixels in src into dst, applying the orientation transformations specified by origin. If the inputs are invalid, this returns false and no copy is made.

Definition at line 44 of file SkPixmapUtils.cpp.

44 {
45 if (src.colorType() != dst.colorType()) {
46 return false;
47 }
48 // note: we just ignore alphaType and colorSpace for this transformation
49
50 int w = src.width();
51 int h = src.height();
53 using std::swap;
54 swap(w, h);
55 }
56 if (dst.width() != w || dst.height() != h) {
57 return false;
58 }
59 if (w == 0 || h == 0) {
60 return true;
61 }
62
63 // check for aliasing to self
64 if (src.addr() == dst.addr()) {
65 return kTopLeft_SkEncodedOrigin == origin;
66 }
67 return draw_orientation(dst, src, origin);
68}
@ kTopLeft_SkEncodedOrigin
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
static bool draw_orientation(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
dst
Definition: cp.py:12
SkScalar w
SkScalar h

◆ Orient() [2/2]

template<typename Fn >
bool SkPixmapUtils::Orient ( const SkPixmap dst,
SkEncodedOrigin  origin,
Fn &&  decode 
)

Decode an image and then copy into dst, applying origin.

Parameters
dstSkPixmap to write the final image, after applying the origin.
originSkEncodedOrigin to apply to the raw pixels.
decodeFunction for decoding into a pixmap without applying the origin.

Definition at line 30 of file SkPixmapUtilsPriv.h.

30 {
31 SkAutoPixmapStorage storage;
32 const SkPixmap* tmp = &dst;
33 if (origin != kTopLeft_SkEncodedOrigin) {
34 auto info = dst.info();
37 }
38 if (!storage.tryAlloc(info)) {
39 return false;
40 }
41 tmp = &storage;
42 }
43 if (!decode(*tmp)) {
44 return false;
45 }
46 if (tmp != &dst) {
47 return Orient(dst, *tmp, origin);
48 }
49 return true;
50}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
bool tryAlloc(const SkImageInfo &)
bool Orient(const SkPixmap &dst, SkEncodedOrigin origin, Fn &&decode)
SK_API SkImageInfo SwapWidthHeight(const SkImageInfo &info)
static DecodeResult decode(std::string path)
Definition: png_codec.cpp:124

◆ SwapWidthHeight()

SkImageInfo SkPixmapUtils::SwapWidthHeight ( const SkImageInfo info)

Return a copy of the provided ImageInfo with the width and height swapped.

Definition at line 70 of file SkPixmapUtils.cpp.

70 {
71 return info.makeWH(info.height(), info.width());
72}