d717ec6ff5d39c01d1c22b14f0a24c2673d942a5
[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(): b(0), g(0), r(0), a(0)
22         {
23         }
24
25         unsigned long argb() const
26         {
27                 return (a<<24)|(r<<16)|(g<<8)|b;
28         }
29
30         void operator=(unsigned long val)
31         {
32                 b = val&0xFF;
33                 g = (val>>8)&0xFF;
34                 r = (val>>16)&0xFF;
35                 a = (val>>24)&0xFF;
36         }
37         bool operator < (const gRGB &c) const
38         {
39                 if (b < c.b)
40                         return 1;
41                 if (b == c.b)
42                 {
43                         if (g < c.g)
44                                 return 1;
45                         if (g == c.g)
46                         {
47                                 if (r < c.r)
48                                         return 1;
49                                 if (r == c.r)
50                                         return a < c.a;
51                         }
52                 }
53                 return 0;
54         }
55         bool operator==(const gRGB &c) const
56         {
57                 return (b == c.b) && (g == c.g) && (r == c.r) && (a == c.a);
58         }
59 };
60
61 #ifndef SWIG
62 struct gColor
63 {
64         int color;
65         gColor(int color): color(color)
66         {
67         }
68         gColor(): color(0)
69         {
70         }
71         operator int() const { return color; }
72         bool operator==(const gColor &o) const { return o.color==color; }
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 #endif
107
108 class gRegion;
109
110 class gPixmap: public iObject
111 {
112         DECLARE_REF(gPixmap);
113 public:
114         enum
115         {
116                 blitAlphaTest=1,
117                 blitAlphaBlend=2
118         };
119
120 #ifndef SWIG
121         gPixmap(gSurface *surface);
122         gPixmap(eSize, int bpp, int accel = 0);
123
124         gSurface *surface;
125         
126         eLock contentlock;
127         int final;
128         
129         gPixmap *lock();
130         void unlock();
131 #endif
132         virtual ~gPixmap();
133         
134         eSize size() const { return eSize(surface->x, surface->y); }
135         inline bool needClut() const { return surface && surface->bpp <= 8; }
136 private:
137         bool must_delete_surface;
138 #ifndef SWIG
139         friend class gDC;
140         void fill(const gRegion &clip, const gColor &color);
141         void fill(const gRegion &clip, const gRGB &color);
142         
143         void blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flags=0);
144         
145         void mergePalette(const gPixmap &target);
146         void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
147 #else
148         gPixmap();
149 #endif
150
151 };
152
153 TEMPLATE_TYPEDEF(ePtr<gPixmap>, gPixmapPtr);
154
155 #endif