9dd170ac49be822a6936b07dbd895bb68720277c
[enigma2.git] / lib / gdi / gpixmap.h
1 #ifndef __gpixmap_h
2 #define __gpixmap_h
3
4 #include <pthread.h>
5 #include <string>
6 #include <lib/base/object.h>
7 #include <lib/base/elock.h>
8 #include <lib/gdi/erect.h>
9 #include <lib/gdi/fb.h>
10
11 struct gColor
12 {
13         int color;
14         gColor(int color): color(color)
15         {
16         }
17         gColor(): color(0)
18         {
19         }
20         operator int() const { return color; }
21         bool operator==(const gColor &o) const { return o.color==color; }
22 };
23
24 struct gRGB
25 {
26         unsigned char b, g, r, a;
27         gRGB(int r, int g, int b, int a=0): b(b), g(g), r(r), a(a)
28         {
29         }
30         gRGB(unsigned long val): b(val&0xFF), g((val>>8)&0xFF), r((val>>16)&0xFF), a((val>>24)&0xFF)            // ARGB
31         {
32         }
33         gRGB(): b(0), g(0), r(0), a(0)
34         {
35         }
36         void operator=(unsigned long val)
37         {
38                 b = val&0xFF;
39                 g = (val>>8)&0xFF;
40                 r = (val>>16)&0xFF;
41                 a = (val>>24)&0xFF;
42         }
43         bool operator < (const gRGB &c) const
44         {
45                 if (b < c.b)
46                         return 1;
47                 if (b == c.b)
48                 {
49                         if (g < c.g)
50                                 return 1;
51                         if (g == c.g)
52                         {
53                                 if (r < c.r)
54                                         return 1;
55                                 if (r == c.r)
56                                         return a < c.a;
57                         }
58                 }
59                 return 0;
60         }
61         bool operator==(const gRGB &c) const
62         {
63                 return (b == c.b) && (g == c.g) && (r == c.r) && (a == c.a);
64         }
65 };
66
67 struct gPalette
68 {
69         int start, colors;
70         gRGB *data;
71         gColor findColor(const gRGB &rgb) const;
72 };
73
74 struct gLookup
75 {
76         int size;
77         gColor *lookup;
78         gLookup(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
79         gLookup();
80         ~gLookup() { delete [] lookup; }
81         void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
82 };
83
84 /**
85  * \brief A softreference to a font.
86  *
87  * The font is specified by a name and a size.
88  * \c gFont is part of the \ref gdi.
89  */
90 class gFont: public iObject
91 {
92 DECLARE_REF;
93 public:
94
95         std::string family;
96         int pointSize;
97         
98         /**
99          * \brief Constructs a font with the given name and size.
100          * \param family The name of the font, for example "NimbusSansL-Regular Sans L Regular".
101          * \param pointSize the size of the font in PIXELS.
102          */
103         gFont(const std::string &family, int pointSize):
104                         family(family), pointSize(pointSize)
105         {
106         }
107         
108         virtual ~gFont()
109         {
110         }
111         
112         gFont()
113                 :pointSize(0)
114         {
115         }
116 };
117
118 struct gSurface
119 {
120         int type;
121         int x, y, bpp, bypp, stride;
122         gPalette clut;
123         
124         void *data;
125         virtual ~gSurface();
126 };
127
128 struct gSurfaceSystem: gSurface
129 {
130         gSurfaceSystem(eSize size, int bpp);
131         ~gSurfaceSystem();
132 };
133
134 struct gPixmap: public iObject
135 {
136 DECLARE_REF;
137 private:
138         friend class gDC;
139         void fill(const gRegion &clip, const gColor &color);
140         
141         enum
142         {
143                 blitAlphaTest=1
144         };
145         void blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flags=0);
146         
147         void mergePalette(const gPixmap &target);
148         void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
149 public:
150         gSurface *surface;
151         
152         eLock contentlock;
153         int final;
154         
155         gPixmap *lock();
156         void unlock();
157         
158         eSize getSize() const { return eSize(surface->x, surface->y); }
159         
160         gPixmap(gSurface *surface);
161         gPixmap(eSize, int bpp);
162         virtual ~gPixmap();
163 };
164
165 #endif