#ifndef _GRAPHIC_HELPER_H_ #define _GRAPHIC_HELPER_H_ #ifdef __ANDROID__ #undef _U #undef _L #undef _N #undef _S #undef _P #undef _C #undef _X #undef _B #endif #include #include struct PLGH_Color_RGBA { uint8_t R; uint8_t G; uint8_t B; uint8_t A; PLGH_Color_RGBA(uint8_t _R = 0, uint8_t _G = 0, uint8_t _B = 0, uint8_t _A = 0) : R(_R), G(_G), B(_B), A(_A) {} uint8_t toY() const { return 0.299 * R + 0.587 * G + 0.114 * B; } uint8_t toU() const { return -0.1687 * R - 0.3313 * G + 0.5 * B + 128; } uint8_t toV() const { return 0.5 * R - 0.4187 * G - 0.0813 * B + 128; } uint16_t toUV() const { const uint8_t U = toU(); const uint8_t V = toV(); const uint16_t UV = (V << 8 | U); return UV; } uint16_t toRGB565() const { return (((unsigned(R) << 8) & 0xF800) | ((unsigned(G) << 3) & 0x7E0) | ((unsigned(B) >> 3))); } }; struct PLGH_Color_YUV { uint8_t Y; uint8_t U; uint8_t V; PLGH_Color_YUV(uint8_t _Y = 0, uint8_t _U = 0, uint8_t _V = 0) : Y(_Y), U(_U), V(_V) {} uint8_t toR() const; uint8_t toG() const; uint8_t toB() const; }; struct PLGH_Pen { uint8_t type; uint8_t width; PLGH_Pen(uint8_t _type, uint8_t _width) : type(_type), width(_width) {} PLGH_Pen(int _type, int _width) : type((uint8_t)_type), width((uint8_t)_width) {} }; struct PLGH_Point { int X; int Y; PLGH_Point(int _X = 0, int _Y = 0) : X(_X), Y(_Y) { } }; struct PLGH_Rect { PLGH_Point leftTop; PLGH_Point rightBottom; PLGH_Rect() : leftTop(), rightBottom() { } PLGH_Rect(const PLGH_Point& _leftTop, const PLGH_Point& _rightBottom) : leftTop(_leftTop), rightBottom(_rightBottom) { } int width() const { return rightBottom.X - leftTop.X; } int height() const { return rightBottom.Y - leftTop.Y; } PLGH_Point center() const { return PLGH_Point(int(leftTop.X + (rightBottom.X - leftTop.X) / 2.0), int(leftTop.Y + (rightBottom.Y - leftTop.Y) / 2.0)); } int area() const { return width() * height(); } }; struct PLGH_Path { int type; std::vector points; PLGH_Path() : type(0), points() { } }; #endif