adding new bouquets added to the context menu of the bouquet list
[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/smartptr.h>
8 #include <lib/base/elock.h>
9 #include <lib/gdi/erect.h>
10 #include <lib/gdi/fb.h>
11 #include <lib/gdi/region.h>
12
13 struct gColor
14 {
15         int color;
16         gColor(int color): color(color)
17         {
18         }
19         gColor(): color(0)
20         {
21         }
22         operator int() const { return color; }
23         bool operator==(const gColor &o) const { return o.color==color; }
24 };
25
26 struct gRGB
27 {
28         unsigned char b, g, r, a;
29         gRGB(int r, int g, int b, int a=0): b(b), g(g), r(r), a(a)
30         {
31         }
32         gRGB(unsigned long val): b(val&0xFF), g((val>>8)&0xFF), r((val>>16)&0xFF), a((val>>24)&0xFF)            // ARGB
33         {
34         }
35         gRGB(): b(0), g(0), r(0), a(0)
36         {
37         }
38         void operator=(unsigned long val)
39         {
40                 b = val&0xFF;
41                 g = (val>>8)&0xFF;
42                 r = (val>>16)&0xFF;
43                 a = (val>>24)&0xFF;
44         }
45         bool operator < (const gRGB &c) const
46         {
47                 if (b < c.b)
48                         return 1;
49                 if (b == c.b)
50                 {
51                         if (g < c.g)
52                                 return 1;
53                         if (g == c.g)
54                         {
55                                 if (r < c.r)
56                                         return 1;
57                                 if (r == c.r)
58                                         return a < c.a;
59                         }
60                 }
61                 return 0;
62         }
63         bool operator==(const gRGB &c) const
64         {
65                 return (b == c.b) && (g == c.g) && (r == c.r) && (a == c.a);
66         }
67 };
68
69 struct gPalette
70 {
71         int start, colors;
72         gRGB *data;
73         gColor findColor(const gRGB &rgb) const;
74 };
75
76 struct gLookup
77 {
78         int size;
79         gColor *lookup;
80         gLookup(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
81         gLookup();
82         ~gLookup() { delete [] lookup; }
83         void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
84 };
85
86 struct gSurface
87 {
88         int type;
89         int x, y, bpp, bypp, stride;
90         gPalette clut;
91         
92         void *data;
93         int data_phys;
94         int offset; // only for backbuffers
95
96         gSurface();
97         gSurface(eSize size, int bpp, int accel);
98         ~gSurface();
99 };
100
101 class gPixmap: public iObject
102 {
103         DECLARE_REF(gPixmap);
104 public:
105         enum
106         {
107                 blitAlphaTest=1,
108                 blitAlphaBlend=2
109         };
110
111 #ifndef SWIG
112         gPixmap(gSurface *surface);
113         gPixmap(eSize, int bpp, int accel = 0);
114
115         gSurface *surface;
116         
117         eLock contentlock;
118         int final;
119         
120         gPixmap *lock();
121         void unlock();
122 #endif
123         virtual ~gPixmap();
124         
125         eSize size() const { return eSize(surface->x, surface->y); }
126         
127 private:
128 #ifndef SWIG
129         friend class gDC;
130         void fill(const gRegion &clip, const gColor &color);
131         
132         void blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flags=0);
133         
134         void mergePalette(const gPixmap &target);
135         void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
136 #else
137         gPixmap();
138 #endif
139
140 };
141
142 TEMPLATE_TYPEDEF(ePtr<gPixmap>, gPixmapPtr);
143
144 #endif