openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
gpixmap.h
Go to the documentation of this file.
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 <byteswap.h>
12 
13 struct gRGB
14 {
15  union {
16 #if BYTE_ORDER == LITTLE_ENDIAN
17  struct {
18  unsigned char b, g, r, a;
19  };
20 #else
21  struct {
22  unsigned char a, r, g, b;
23  };
24 #endif
25  uint32_t value;
26  };
27  gRGB(int r, int g, int b, int a=0): b(b), g(g), r(r), a(a)
28  {
29  }
30  gRGB(uint32_t val): value(val)
31  {
32  }
33  gRGB(const gRGB& other): value(other.value)
34  {
35  }
36  gRGB(const char *colorstring)
37  {
38  uint32_t val = 0;
39 
40  if (colorstring)
41  {
42  for (int i = 0; i < 8; i++)
43  {
44  char c = colorstring[i];
45  if (!c) break;
46  val <<= 4;
47  if (c >= '0' && c <= '9')
48  val |= c - '0';
49  else if(c >= 'a' && c <= 'f')
50  val |= c - 'a' + 10;
51  else if(c >= 'A' && c <= 'F')
52  val |= c - 'A' + 10;
53  else if(c >= ':' && c <= '?') // Backwards compatibility for old style color strings
54  val |= c & 0x0f;
55  }
56  }
57  value = val;
58  }
59  gRGB(): value(0)
60  {
61  }
62 
63  uint32_t argb() const
64  {
65  return value;
66  }
67 
68  void set(uint32_t val)
69  {
70  value = val;
71  }
72 
73  void operator=(uint32_t val)
74  {
75  value = val;
76  }
77  bool operator < (const gRGB &c) const
78  {
79  if (b < c.b)
80  return true;
81  if (b == c.b)
82  {
83  if (g < c.g)
84  return true;
85  if (g == c.g)
86  {
87  if (r < c.r)
88  return true;
89  if (r == c.r)
90  return a < c.a;
91  }
92  }
93  return false;
94  }
95  bool operator==(const gRGB &c) const
96  {
97  return c.value == value;
98  }
99  bool operator != (const gRGB &c) const
100  {
101  return c.value != value;
102  }
103  operator const std::string () const
104  {
105  uint32_t val = value;
106  std::string escapecolor = "\\c";
107  escapecolor.resize(10);
108  for (int i = 9; i >= 2; i--)
109  {
110  int hexbits = val & 0xf;
111  escapecolor[i] = hexbits < 10 ? '0' + hexbits
112  : 'a' - 10 + hexbits;
113  val >>= 4;
114  }
115  return escapecolor;
116  }
117  void alpha_blend(const gRGB other)
118  {
119 #define BLEND(x, y, a) (y + (((x-y) * a)>>8))
120  b = BLEND(other.b, b, other.a);
121  g = BLEND(other.g, g, other.a);
122  r = BLEND(other.r, r, other.a);
123  a = BLEND(0xFF, a, other.a);
124 #undef BLEND
125  }
126 };
127 
128 #ifndef SWIG
129 struct gColor
130 {
131  int color;
133  {
134  }
135  gColor(): color(0)
136  {
137  }
138  operator int() const { return color; }
139  bool operator==(const gColor &o) const { return o.color==color; }
140 };
141 
142 struct gPalette
143 {
144  int start, colors;
146  uint32_t data_phys;
147 
148  gColor findColor(const gRGB rgb) const;
149  gPalette(): start(0), colors(0), data(0), data_phys(0) {}
150 };
151 
152 struct gLookup
153 {
154  int size;
156  gLookup(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
157  gLookup();
158  ~gLookup() { delete [] lookup; }
159  void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
160 };
161 
163 {
164  int x, y, bpp, bypp, stride;
166  void *data;
168 
170  gUnmanagedSurface(int width, int height, int bpp);
171 };
172 
174 {
176  gSurface(int width, int height, int bpp, int accel);
177  ~gSurface();
178 private:
179  gSurface(const gSurface&); /* Copying managed gSurface is not allowed */
180  gSurface& operator =(const gSurface&);
181 };
182 #endif
183 
184 class gRegion;
185 
187 class gPixmap: public iObject
188 {
189  DECLARE_REF(gPixmap);
190 public:
191 #ifdef SWIG
192  gPixmap();
193 #else
194  enum
195  {
203  blitVAlignBottom = 128
204  };
205 
206  enum {
210  };
211 
212  typedef void (*gPixmapDisposeCallback)(gPixmap* pixmap);
213 
215  gPixmap(eSize, int bpp, int accel = 0);
216  gPixmap(int width, int height, int bpp, gPixmapDisposeCallback on_dispose, int accel = accelAuto);
217 
219 
220  inline bool needClut() const { return surface && surface->bpp <= 8; }
221 #endif
222  virtual ~gPixmap();
223  eSize size() const { return eSize(surface->x, surface->y); }
224 
225 private:
226  gPixmapDisposeCallback on_dispose;
227 
228  friend class gDC;
229  void fill(const gRegion &clip, const gColor &color);
230  void fill(const gRegion &clip, const gRGB &color);
231 
232  void blit(const gPixmap &src, const eRect &pos, const gRegion &clip, int flags=0);
233 
234  void mergePalette(const gPixmap &target);
235  void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
236  void line(const gRegion &clip, ePoint start, ePoint end, gRGB color);
237  void line(const gRegion &clip, ePoint start, ePoint end, unsigned int color);
238 };
240 
241 #endif
Definition: epoint.h:9
Definition: erect.h:11
Definition: esize.h:8
Definition: grc.h:330
Definition: gpixmap.h:188
@ accelNever
Definition: gpixmap.h:207
@ accelAuto
Definition: gpixmap.h:208
@ accelAlways
Definition: gpixmap.h:209
gPixmap(gUnmanagedSurface *surface)
Definition: gpixmap.cpp:1258
eSize size() const
Definition: gpixmap.h:223
virtual ~gPixmap()
Definition: gpixmap.cpp:1245
gUnmanagedSurface * surface
Definition: gpixmap.h:218
bool needClut() const
Definition: gpixmap.h:220
void(* gPixmapDisposeCallback)(gPixmap *pixmap)
Definition: gpixmap.h:212
@ blitKeepAspectRatio
Definition: gpixmap.h:199
@ blitAlphaTest
Definition: gpixmap.h:196
@ blitAlphaBlend
Definition: gpixmap.h:197
@ blitScale
Definition: gpixmap.h:198
@ blitHAlignRight
Definition: gpixmap.h:201
@ blitHAlignCenter
Definition: gpixmap.h:200
@ blitVAlignCenter
Definition: gpixmap.h:202
@ blitVAlignBottom
Definition: gpixmap.h:203
Definition: region.h:9
Definition: object.h:15
const char int accel
Definition: epng.h:36
const char int int int height
Definition: epng.h:39
const char int int width
Definition: epng.h:39
#define BLEND(x, y, a)
SWIG_TEMPLATE_TYPEDEF(ePtr< gPixmap >, gPixmapPtr)
SWIG_IGNORE(gPixmap)
line
Definition: newplugin.py:87
target
Definition: newplugin.py:59
def clip(val, min, max)
Definition: PiPSetup.py:17
val
Definition: UnitConversions.py:88
pos
Definition: enigma_py_patcher.py:16
Definition: picload.cpp:163
Definition: gpixmap.h:130
int color
Definition: gpixmap.h:131
bool operator==(const gColor &o) const
Definition: gpixmap.h:139
gColor(int color)
Definition: gpixmap.h:132
gColor()
Definition: gpixmap.h:135
Definition: gpixmap.h:153
gLookup()
Definition: gpixmap.cpp:91
void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end)
Definition: gpixmap.cpp:102
int size
Definition: gpixmap.h:154
gColor * lookup
Definition: gpixmap.h:155
~gLookup()
Definition: gpixmap.h:158
Definition: gpixmap.h:143
gColor findColor(const gRGB rgb) const
Definition: gpixmap.cpp:1202
uint32_t data_phys
Definition: gpixmap.h:146
gRGB * data
Definition: gpixmap.h:145
gPalette()
Definition: gpixmap.h:149
int colors
Definition: gpixmap.h:144
int start
Definition: gpixmap.h:144
Definition: gpixmap.h:14
unsigned char r
Definition: gpixmap.h:18
gRGB(int r, int g, int b, int a=0)
Definition: gpixmap.h:27
unsigned char a
Definition: gpixmap.h:18
unsigned char b
Definition: gpixmap.h:18
void operator=(uint32_t val)
Definition: gpixmap.h:73
void alpha_blend(const gRGB other)
Definition: gpixmap.h:117
gRGB()
Definition: gpixmap.h:59
bool operator<(const gRGB &c) const
Definition: gpixmap.h:77
bool operator!=(const gRGB &c) const
Definition: gpixmap.h:99
uint32_t argb() const
Definition: gpixmap.h:63
gRGB(const char *colorstring)
Definition: gpixmap.h:36
void set(uint32_t val)
Definition: gpixmap.h:68
unsigned char g
Definition: gpixmap.h:18
bool operator==(const gRGB &c) const
Definition: gpixmap.h:95
gRGB(const gRGB &other)
Definition: gpixmap.h:33
uint32_t value
Definition: gpixmap.h:25
gRGB(uint32_t val)
Definition: gpixmap.h:30
Definition: gpixmap.h:174
gSurface()
Definition: gpixmap.h:175
~gSurface()
Definition: gpixmap.cpp:227
Definition: gpixmap.h:163
int bypp
Definition: gpixmap.h:164
int bpp
Definition: gpixmap.h:164
gPalette clut
Definition: gpixmap.h:165
void * data
Definition: gpixmap.h:166
int data_phys
Definition: gpixmap.h:167
int x
Definition: gpixmap.h:164
int stride
Definition: gpixmap.h:164
gUnmanagedSurface()
Definition: gpixmap.cpp:138
int y
Definition: gpixmap.h:164