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