blit: pass 'flags' to bcm_accel_blit()
[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 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 SWIG_IGNORE(gPixmap);
111 class gPixmap: public iObject
112 {
113         DECLARE_REF(gPixmap);
114 public:
115 #ifndef SWIG
116         enum
117         {
118                 blitAlphaTest=1,
119                 blitAlphaBlend=2,
120                 blitScale=4
121         };
122
123         gPixmap(gSurface *surface);
124         gPixmap(eSize, int bpp, int accel = 0);
125
126         gSurface *surface;
127         
128         eLock contentlock;
129         int final;
130         
131         gPixmap *lock();
132         void unlock();
133         inline bool needClut() const { return surface && surface->bpp <= 8; }
134 #endif
135         virtual ~gPixmap();
136         eSize size() const { return eSize(surface->x, surface->y); }
137 private:
138         bool must_delete_surface;
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, const eRect &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 #ifdef SWIG
148         gPixmap();
149 #endif
150 };
151 SWIG_TEMPLATE_TYPEDEF(ePtr<gPixmap>, gPixmapPtr);
152
153 #endif