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