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