delete surface when created from gpixmap
[enigma2.git] / lib / gdi / gpixmap.cpp
index dbf53838087fa3dc81b836dd6ceeecc33fb0c773..1ecb83d3f18a9359cc42d0feb846fcf12c20c4b8 100644 (file)
@@ -175,6 +175,38 @@ void gPixmap::fill(const gRegion &region, const gColor &color)
        }
 }
 
+void gPixmap::fill(const gRegion &region, const gRGB &color)
+{
+       unsigned int i;
+       for (i=0; i<region.rects.size(); ++i)
+       {
+               const eRect &area = region.rects[i];
+               if ((area.height()<=0) || (area.width()<=0))
+                       continue;
+
+               if (surface->bpp == 32)
+               {
+                       __u32 col;
+
+                       col = color.argb();
+                       col^=0xFF000000;
+
+                       if (surface->data_phys && gAccel::getInstance())
+                               if (!gAccel::getInstance()->fill(surface,  area, col))
+                                       continue;
+
+                       for (int y=area.top(); y<area.bottom(); y++)
+                       {
+                               __u32 *dst=(__u32*)(((__u8*)surface->data)+y*surface->stride+area.left()*surface->bypp);
+                               int x=area.width();
+                               while (x--)
+                                       *dst++=col;
+                       }
+               }       else
+                       eWarning("couldn't rgbfill %d bpp", surface->bpp);
+       }
+}
+
 void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag)
 {
        for (unsigned int i=0; i<clip.rects.size(); ++i)
@@ -182,6 +214,7 @@ void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag
                eRect area=eRect(pos, src.size());
                area&=clip.rects[i];
                area&=eRect(ePoint(0, 0), size());
+
                if ((area.width()<0) || (area.height()<0))
                        continue;
 
@@ -309,7 +342,7 @@ void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag
                                                // use duff's device here!
                                        while (width--)
                                        {
-                                               if (!*src)
+                                               if (!(pal[*src]&0x80000000))
                                                {
                                                        src++;
                                                        dst++;
@@ -378,7 +411,7 @@ void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color)
        if (clip.rects.empty())
                return;
                
-       __u32 col;
+       __u32 col = 0;
        if (surface->bpp == 8)
        {
                srf8 = (__u8*)surface->data;
@@ -437,7 +470,7 @@ void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color)
                        do
                        {
                                ++a;
-                               if (a == clip.rects.size())
+                               if ((unsigned int)a == clip.rects.size())
                                        a = 0;
                                if (a == lasthit)
                                {
@@ -469,6 +502,10 @@ fail:
 
 gColor gPalette::findColor(const gRGB &rgb) const
 {
+               /* grayscale? */
+       if (!data)
+               return (rgb.r + rgb.g + rgb.b) / 3;
+       
        int difference=1<<30, best_choice=0;
        for (int t=0; t<colors; t++)
        {
@@ -501,13 +538,17 @@ DEFINE_REF(gPixmap);
 
 gPixmap::~gPixmap()
 {
+       if (must_delete_surface)
+               delete surface;
 }
 
-gPixmap::gPixmap(gSurface *surface): surface(surface)
+gPixmap::gPixmap(gSurface *surface)
+       :surface(surface), must_delete_surface(false)
 {
 }
 
 gPixmap::gPixmap(eSize size, int bpp, int accel)
+       :must_delete_surface(true)
 {
        surface = new gSurface(size, bpp, accel);
 }