24 #ifndef SkMatrix_DEFINED 25 #define SkMatrix_DEFINED 118 static Matrix MakeAll(
float scaleX,
float skewX,
float transX,
float skewY,
float scaleY,
float transY,
float pers0,
119 float pers1,
float pers2) {
121 m.
setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2);
131 kTranslate_Mask = 0x01,
134 kPerspective_Mask = 0x08,
146 if (fTypeMask & kUnknown_Mask) {
147 fTypeMask = this->computeTypeMask();
162 return this->getType() == 0;
175 return !(this->getType() & ~(kScale_Mask | kTranslate_Mask));
187 return !(this->getType() & ~(kTranslate_Mask));
212 if (fTypeMask & kUnknown_Mask) {
213 fTypeMask = this->computeTypeMask();
215 return (fTypeMask & kRectStaysRect_Mask) != 0;
240 return this->rectStaysRect();
246 static constexpr
int kMScaleX = 0;
247 static constexpr
int kMSkewX = 1;
248 static constexpr
int kMTransX = 2;
249 static constexpr
int kMSkewY = 3;
250 static constexpr
int kMScaleY = 4;
251 static constexpr
int kMTransY = 5;
252 static constexpr
int kMPersp0 = 6;
253 static constexpr
int kMPersp1 = 7;
254 static constexpr
int kMPersp2 = 8;
259 static constexpr
int kAScaleX = 0;
260 static constexpr
int kASkewY = 1;
261 static constexpr
int kASkewX = 2;
262 static constexpr
int kAScaleY = 3;
263 static constexpr
int kATransX = 4;
264 static constexpr
int kATransY = 5;
285 float get(
int index)
const {
296 return fMat[kMScaleX];
305 return fMat[kMScaleY];
315 return fMat[kMSkewY];
325 return fMat[kMSkewX];
334 return fMat[kMTransX];
343 return fMat[kMTransY];
351 return fMat[kMPersp0];
359 return fMat[kMPersp1];
374 this->setTypeMask(kUnknown_Mask);
385 void set(
int index,
float value) {
388 this->setTypeMask(kUnknown_Mask);
396 this->set(kMScaleX, v);
404 this->set(kMScaleY, v);
412 this->set(kMSkewY, v);
420 this->set(kMSkewX, v);
428 this->set(kMTransX, v);
436 this->set(kMTransY, v);
445 this->set(kMPersp0, v);
454 this->set(kMPersp1, v);
473 void setAll(
float scaleX,
float skewX,
float transX,
float skewY,
float scaleY,
float transY,
float persp0,
474 float persp1,
float persp2) {
475 fMat[kMScaleX] = scaleX;
476 fMat[kMSkewX] = skewX;
477 fMat[kMTransX] = transX;
478 fMat[kMSkewY] = skewY;
479 fMat[kMScaleY] = scaleY;
480 fMat[kMTransY] = transY;
481 fMat[kMPersp0] = persp0;
482 fMat[kMPersp1] = persp1;
483 fMat[kMPersp2] = persp2;
484 this->setTypeMask(kUnknown_Mask);
493 void get9(
float buffer[9])
const {
494 memcpy(buffer, fMat, 9 *
sizeof(
float));
513 void set9(
const float buffer[9]);
544 void setTranslate(
float dx,
float dy);
554 void setScale(
float sx,
float sy,
float px,
float py);
561 void setScale(
float sx,
float sy);
572 void setRotate(
float degrees,
float px,
float py);
579 void setRotate(
float degrees);
592 void setSinCos(
float sinValue,
float cosValue,
float px,
float py);
602 void setSinCos(
float sinValue,
float cosValue);
612 void setSkew(
float kx,
float ky,
float px,
float py);
619 void setSkew(
float kx,
float ky);
658 void preTranslate(
float dx,
float dy);
686 void preScale(
float sx,
float sy,
float px,
float py);
707 void preScale(
float sx,
float sy);
738 void preRotate(
float degrees,
float px,
float py);
765 void preRotate(
float degrees);
793 void preSkew(
float kx,
float ky,
float px,
float py);
814 void preSkew(
float kx,
float ky);
833 void preConcat(
const Matrix& other);
853 void postTranslate(
float dx,
float dy);
881 void postScale(
float sx,
float sy,
float px,
float py);
902 void postScale(
float sx,
float sy);
930 bool postIDiv(
int divx,
int divy);
961 void postRotate(
float degrees,
float px,
float py);
988 void postRotate(
float degrees);
1016 void postSkew(
float kx,
float ky,
float px,
float py);
1037 void postSkew(
float kx,
float ky);
1056 void postConcat(
const Matrix& other);
1086 bool setRectToRect(
const Rect& src,
const Rect& dst, ScaleToFit stf);
1122 bool setPolyToPoly(
const Point src[],
const Point dst[],
int count);
1134 if (this->isIdentity()) {
1140 return this->invertNonIdentity(inverse);
1153 static void SetAffineIdentity(
float affine[6]);
1165 bool asAffine(
float affine[6])
const;
1181 void setAffine(
const float affine[6]);
1210 MNN_ASSERT((dst && src && count > 0) || 0 == count);
1212 MNN_ASSERT(src == dst || &dst[count] <= &src[0] || &src[count] <= &dst[0]);
1213 this->getMapPtsProc()(*
this, dst, src, count);
1240 this->mapPoints(pts, pts, count);
1260 this->getMapXYProc()(*
this, x, y, result);
1281 this->getMapXYProc()(*
this, x, y, &result);
1294 bool mapRect(
Rect* dst,
const Rect& src)
const;
1305 return this->mapRect(rect, *rect);
1315 (void)this->mapRect(&dst, src);
1326 void mapRectScaleTranslate(
Rect* dst,
const Rect& src)
const;
1342 return 0 == memcmp(fMat, m.fMat,
sizeof(fMat));
1379 float getMinScale()
const;
1387 float getMaxScale()
const;
1399 bool getMinMaxScales(
float scaleFactors[2])
const;
1409 static const Matrix& I();
1420 static const Matrix& InvalidMatrix();
1450 this->setTypeMask(kUnknown_Mask);
1465 fMat[kMScaleX] = sx;
1467 fMat[kMTransX] = tx;
1470 fMat[kMScaleY] = sy;
1471 fMat[kMTransY] = ty;
1478 if (sx != 1 || sy != 1) {
1479 mask |= kScale_Mask;
1482 mask |= kTranslate_Mask;
1484 this->setTypeMask(mask | kRectStaysRect_Mask);
1500 static constexpr
int kRectStaysRect_Mask = 0x10;
1505 static constexpr
int kOnlyPerspectiveValid_Mask = 0x40;
1507 static constexpr
int kUnknown_Mask = 0x80;
1509 static constexpr
int kORableMasks = kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask;
1511 static constexpr
int kAllMasks =
1512 kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask | kRectStaysRect_Mask;
1515 mutable uint32_t fTypeMask;
1517 static void ComputeInv(
float dst[9],
const float src[9],
double invDet,
bool isPersp);
1519 uint8_t computeTypeMask()
const;
1520 uint8_t computePerspectiveTypeMask()
const;
1522 void setTypeMask(
int mask) {
1524 MNN_ASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask ||
1525 ((kUnknown_Mask | kOnlyPerspectiveValid_Mask) & mask) ==
1526 (kUnknown_Mask | kOnlyPerspectiveValid_Mask));
1527 fTypeMask = (uint8_t)(mask);
1530 void orTypeMask(
int mask) {
1532 fTypeMask = (uint8_t)(fTypeMask | mask);
1535 void clearTypeMask(
int mask) {
1538 fTypeMask = fTypeMask & ~mask;
1541 TypeMask getPerspectiveTypeMaskOnly()
const {
1542 if ((fTypeMask & kUnknown_Mask) && !(fTypeMask & kOnlyPerspectiveValid_Mask)) {
1543 fTypeMask = this->computePerspectiveTypeMask();
1545 return (TypeMask)(fTypeMask & 0xF);
1551 bool isTriviallyIdentity()
const {
1552 if (fTypeMask & kUnknown_Mask) {
1555 return ((fTypeMask & 0xF) == 0);
1558 inline void updateTranslateMask() {
1559 if ((fMat[kMTransX] != 0) | (fMat[kMTransY] != 0)) {
1560 fTypeMask |= kTranslate_Mask;
1562 fTypeMask &= ~kTranslate_Mask;
1566 typedef void (*MapXYProc)(
const Matrix& mat,
float x,
float y, Point* result);
1568 static MapXYProc GetMapXYProc(TypeMask mask) {
1570 return gMapXYProcs[mask & kAllMasks];
1573 MapXYProc getMapXYProc()
const {
1574 return GetMapXYProc(this->getType());
1577 typedef void (*MapPtsProc)(
const Matrix& mat, Point dst[],
const Point src[],
int count);
1579 static MapPtsProc GetMapPtsProc(TypeMask mask) {
1581 return gMapPtsProcs[mask & kAllMasks];
1584 MapPtsProc getMapPtsProc()
const {
1585 return GetMapPtsProc(this->getType());
1588 bool invertNonIdentity(Matrix* inverse)
const;
1590 static void Identity_xy(
const Matrix&,
float,
float, Point*);
1591 static void Trans_xy(
const Matrix&,
float,
float, Point*);
1592 static void Scale_xy(
const Matrix&,
float,
float, Point*);
1593 static void ScaleTrans_xy(
const Matrix&,
float,
float, Point*);
1594 static void Rot_xy(
const Matrix&,
float,
float, Point*);
1595 static void RotTrans_xy(
const Matrix&,
float,
float, Point*);
1596 static void Persp_xy(
const Matrix&,
float,
float, Point*);
1598 static const MapXYProc gMapXYProcs[];
1600 static void Identity_pts(
const Matrix&, Point[],
const Point[],
int);
1601 static void Trans_pts(
const Matrix&, Point dst[],
const Point[],
int);
1602 static void Scale_pts(
const Matrix&, Point dst[],
const Point[],
int);
1603 static void ScaleTrans_pts(
const Matrix&, Point dst[],
const Point[],
int count);
1604 static void Persp_pts(
const Matrix&, Point dst[],
const Point[],
int);
1606 static void Affine_vpts(
const Matrix&, Point dst[],
const Point[],
int);
1608 static const MapPtsProc gMapPtsProcs[];
float get(int index) const
Definition: Matrix.h:285
float & operator[](int index)
Definition: Matrix.h:372
void setIdentity()
Definition: Matrix.h:535
float getScaleX() const
Definition: Matrix.h:295
ScaleToFit
Definition: Matrix.h:1064
Point mapXY(float x, float y) const
Definition: Matrix.h:1279
static Matrix MakeTrans(float dx, float dy)
Definition: Matrix.h:95
float getTranslateX() const
Definition: Matrix.h:333
bool isIdentity() const
Definition: Matrix.h:161
void setScaleTranslate(float sx, float sy, float tx, float ty)
Definition: Matrix.h:1464
bool isScaleTranslate() const
Definition: Matrix.h:174
#define MNN_ASSERT(x)
Definition: MNNDefine.h:41
void setTranslateX(float v)
Definition: Matrix.h:427
float getSkewX() const
Definition: Matrix.h:324
void setScaleX(float v)
Definition: Matrix.h:395
void setSkewX(float v)
Definition: Matrix.h:419
void setPerspY(float v)
Definition: Matrix.h:453
float getSkewY() const
Definition: Matrix.h:314
TypeMask getType() const
Definition: Matrix.h:145
scales in x and y to fill destination Rect
Definition: Matrix.h:1065
static Matrix MakeRectToRect(const Rect &src, const Rect &dst, ScaleToFit stf)
Definition: Matrix.h:1103
void setTranslateY(float v)
Definition: Matrix.h:435
static Matrix MakeScale(float scale)
Definition: Matrix.h:79
void mapXY(float x, float y, Point *result) const
Definition: Matrix.h:1259
scales and aligns to center
Definition: Matrix.h:1067
void setSkewY(float v)
Definition: Matrix.h:411
bool isTranslate() const
Definition: Matrix.h:186
float getPerspX() const
Definition: Matrix.h:350
void dirtyMatrixTypeCache()
Definition: Matrix.h:1449
float operator[](int index) const
Definition: Matrix.h:273
scales and aligns to right and bottom
Definition: Matrix.h:1068
bool invert(Matrix *inverse) const
Definition: Matrix.h:1132
Matrix()
Definition: Matrix.h:50
bool mapRect(Rect *rect) const
Definition: Matrix.h:1304
void setTranslate(float dx, float dy)
#define MNN_PUBLIC
Definition: MNNDefine.h:53
void setPerspX(float v)
Definition: Matrix.h:444
static Matrix MakeScale(float sx, float sy)
Definition: Matrix.h:64
Rect mapRect(const Rect &src) const
Definition: Matrix.h:1313
void set(int index, float value)
Definition: Matrix.h:385
static Matrix MakeAll(float scaleX, float skewX, float transX, float skewY, float scaleY, float transY, float pers0, float pers1, float pers2)
Definition: Matrix.h:118
float getTranslateY() const
Definition: Matrix.h:342
Definition: AutoTime.hpp:16
bool setRectToRect(const Rect &src, const Rect &dst, ScaleToFit stf)
void setConcat(const Matrix &a, const Matrix &b)
float getScaleY() const
Definition: Matrix.h:304
void mapPoints(Point dst[], const Point src[], int count) const
Definition: Matrix.h:1209
void mapPoints(Point pts[], int count) const
Definition: Matrix.h:1239
void setAll(float scaleX, float skewX, float transX, float skewY, float scaleY, float transY, float persp0, float persp1, float persp2)
Definition: Matrix.h:473
bool rectStaysRect() const
Definition: Matrix.h:211
void setScale(float sx, float sy, float px, float py)
bool preservesAxisAlignment() const
Definition: Matrix.h:239
scales and aligns to left and top
Definition: Matrix.h:1066
static Matrix Concat(const Matrix &a, const Matrix &b)
Definition: Matrix.h:1440
void setScaleY(float v)
Definition: Matrix.h:403
bool cheapEqualTo(const Matrix &m) const
Definition: Matrix.h:1341
void get9(float buffer[9]) const
Definition: Matrix.h:493
TypeMask
Definition: Matrix.h:129
friend MNN_PUBLIC bool operator!=(const Matrix &a, const Matrix &b)
Definition: Matrix.h:1363
float getPerspY() const
Definition: Matrix.h:358