Support turbo2.
[vuplus_dvbapp] / 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 gRGB
13 {
14         unsigned char b, g, r, a;
15         gRGB(int r, int g, int b, int a=0): b(b), g(g), r(r), a(a)
16         {
17         }
18         gRGB(unsigned long val): b(val&0xFF), g((val>>8)&0xFF), r((val>>16)&0xFF), a((val>>24)&0xFF)            // ARGB
19         {
20         }
21         gRGB(const char *colorstring)
22         {
23                 unsigned long val = 0;
24                 if (colorstring)
25                 {
26                         for (int i = 0; i < 8; i++)
27                         {
28                                 if (i) val <<= 4;
29                                 if (!colorstring[i]) break;
30                                 val |= (colorstring[i]) & 0x0f;
31                         }
32                 }
33                 b = val&0xFF;
34                 g = (val>>8)&0xFF;
35                 r = (val>>16)&0xFF;
36                 a = (val>>24)&0xFF;
37         }
38         gRGB(): b(0), g(0), r(0), a(0)
39         {
40         }
41
42         unsigned long argb() const
43         {
44                 return (a<<24)|(r<<16)|(g<<8)|b;
45         }
46
47         void operator=(unsigned long val)
48         {
49                 b = val&0xFF;
50                 g = (val>>8)&0xFF;
51                 r = (val>>16)&0xFF;
52                 a = (val>>24)&0xFF;
53         }
54         bool operator < (const gRGB &c) const
55         {
56                 if (b < c.b)
57                         return 1;
58                 if (b == c.b)
59                 {
60                         if (g < c.g)
61                                 return 1;
62                         if (g == c.g)
63                         {
64                                 if (r < c.r)
65                                         return 1;
66                                 if (r == c.r)
67                                         return a < c.a;
68                         }
69                 }
70                 return 0;
71         }
72         bool operator==(const gRGB &c) const
73         {
74                 return (b == c.b) && (g == c.g) && (r == c.r) && (a == c.a);
75         }
76         bool operator != (const gRGB &c) const
77         {
78                 return (b != c.b) || (g != c.g) || (r != c.r) || (a != c.a);
79         }
80         operator const std::string () const
81         {
82                 unsigned long val = (a<<24)|(r<<16)|(g<<8)|b;
83                 std::string escapecolor = "\\c";
84                 escapecolor.resize(10);
85                 for (int i = 9; i >= 2; i--)
86                 {
87                         escapecolor[i] = 0x40 | (val & 0xf);
88                         val >>= 4;
89                 }
90                 return escapecolor;
91         }
92 };
93
94 #ifndef SWIG
95 struct gColor
96 {
97         int color;
98         gColor(int color): color(color)
99         {
100         }
101         gColor(): color(0)
102         {
103         }
104         operator int() const { return color; }
105         bool operator==(const gColor &o) const { return o.color==color; }
106 };
107
108 struct gPalette
109 {
110         int start, colors;
111         gRGB *data;
112         gColor findColor(const gRGB &rgb) const;
113 };
114
115 struct gLookup
116 {
117         int size;
118         gColor *lookup;
119         gLookup(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
120         gLookup();
121         ~gLookup() { delete [] lookup; }
122         void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
123 };
124
125 struct gSurface
126 {
127         int type;
128         int x, y, bpp, bypp, stride;
129         gPalette clut;
130         
131         void *data;
132         int data_phys;
133         int offset; // only for backbuffers
134
135         gSurface();
136         gSurface(eSize size, int bpp, int accel);
137         ~gSurface();
138 };
139 #endif
140
141 class gRegion;
142
143 SWIG_IGNORE(gPixmap);
144 class gPixmap: public iObject
145 {
146         DECLARE_REF(gPixmap);
147 public:
148 #ifndef SWIG
149         enum
150         {
151                 blitAlphaTest=1,
152                 blitAlphaBlend=2,
153                 blitScale=4
154         };
155
156         gPixmap(gSurface *surface);
157         gPixmap(eSize, int bpp, int accel = 0);
158
159         gSurface *surface;
160         
161         eLock contentlock;
162         int final;
163         
164         gPixmap *lock();
165         void unlock();
166         inline bool needClut() const { return surface && surface->bpp <= 8; }
167 #endif
168         virtual ~gPixmap();
169         eSize size() const { return eSize(surface->x, surface->y); }
170 private:
171         bool must_delete_surface;
172         friend class gDC;
173         void fill(const gRegion &clip, const gColor &color);
174         void fill(const gRegion &clip, const gRGB &color);
175         
176         void blit(const gPixmap &src, const eRect &pos, const gRegion &clip, int flags=0);
177         
178         void mergePalette(const gPixmap &target);
179         void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
180 #ifdef SWIG
181         gPixmap();
182 #endif
183 };
184 SWIG_TEMPLATE_TYPEDEF(ePtr<gPixmap>, gPixmapPtr);
185
186 #endif