houxiao
2017-07-19 d4838060870f637fd1b627dda0117f31390423c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef _GRAPHIC_HELPER_H_
#define _GRAPHIC_HELPER_H_
 
#include <stdint.h>
#include <vector>
#include "GraphicHelper.h"
 
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<PLGH_Point> points;
 
    PLGH_Path() : type(0), points() { }
};
 
#endif