[GB.GTK]
* BUG: Fix memory leak when loading images without alpha channel. git-svn-id: svn://localhost/gambas/trunk@6071 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
ce4ac176ef
commit
e28bd14ae3
3 changed files with 27 additions and 14 deletions
|
@ -531,6 +531,7 @@ static void style_panel(int x, int y, int w, int h, int border, int state)
|
||||||
}
|
}
|
||||||
|
|
||||||
gt_draw_border(_cr, style, get_state(state), border, col, x, y, w, h);
|
gt_draw_border(_cr, style, get_state(state), border, col, x, y, w, h);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
GtkShadowType shadow;
|
GtkShadowType shadow;
|
||||||
GtkStateType st = get_state(state);
|
GtkStateType st = get_state(state);
|
||||||
|
|
|
@ -35,13 +35,14 @@ gPicture
|
||||||
|
|
||||||
#define LOAD_INC 65536L
|
#define LOAD_INC 65536L
|
||||||
|
|
||||||
static bool pixbufFromMemory(GdkPixbuf **pixbuf, char *addr, unsigned int len, bool *trans)
|
static bool pixbufFromMemory(GdkPixbuf **ppixbuf, char *addr, unsigned int len, bool *trans)
|
||||||
{
|
{
|
||||||
GdkPixbufLoader* loader;
|
GdkPixbufLoader *loader;
|
||||||
|
GdkPixbuf *pixbuf;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gsize size;
|
gsize size;
|
||||||
|
|
||||||
*pixbuf = 0;
|
*ppixbuf = 0;
|
||||||
|
|
||||||
loader = gdk_pixbuf_loader_new();
|
loader = gdk_pixbuf_loader_new();
|
||||||
|
|
||||||
|
@ -63,23 +64,24 @@ static bool pixbufFromMemory(GdkPixbuf **pixbuf, char *addr, unsigned int len, b
|
||||||
goto __ERROR;
|
goto __ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*pixbuf) = gdk_pixbuf_loader_get_pixbuf(loader);
|
pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
|
||||||
g_object_ref(G_OBJECT(*pixbuf));
|
g_object_ref(pixbuf);
|
||||||
|
|
||||||
if (gdk_pixbuf_get_n_channels(*pixbuf) == 3)
|
if (gdk_pixbuf_get_n_channels(pixbuf) == 3)
|
||||||
{
|
{
|
||||||
// Rowstride breaks gb.image (it is rounded up so that a line is always a four bytes multiple).
|
// Rowstride breaks gb.image (it is rounded up so that a line is always a four bytes multiple).
|
||||||
GdkPixbuf *aimg;
|
GdkPixbuf *aimg;
|
||||||
aimg = gdk_pixbuf_add_alpha(*pixbuf, FALSE, 0, 0, 0);
|
aimg = gdk_pixbuf_add_alpha(pixbuf, FALSE, 0, 0, 0);
|
||||||
g_object_unref(G_OBJECT(*pixbuf));
|
g_object_unref(pixbuf);
|
||||||
g_object_ref(G_OBJECT(aimg));
|
pixbuf = aimg;
|
||||||
*pixbuf = aimg;
|
|
||||||
*trans = false;
|
*trans = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*trans = true;
|
*trans = true;
|
||||||
|
|
||||||
g_object_unref(G_OBJECT(loader));
|
g_object_unref(G_OBJECT(loader));
|
||||||
|
|
||||||
|
*ppixbuf = pixbuf;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
__ERROR:
|
__ERROR:
|
||||||
|
@ -104,6 +106,7 @@ void gPicture::initialize()
|
||||||
|
|
||||||
gPicture::gPicture() : gShare()
|
gPicture::gPicture() : gShare()
|
||||||
{
|
{
|
||||||
|
//fprintf(stderr, "gPicture(): %p\n", this);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +154,7 @@ void gPicture::createMask(bool opaque)
|
||||||
|
|
||||||
gPicture::gPicture(gPictureType type, int w, int h, bool trans) : gShare()
|
gPicture::gPicture(gPictureType type, int w, int h, bool trans) : gShare()
|
||||||
{
|
{
|
||||||
|
//fprintf(stderr, "gPicture(): %p: %d %d %d %d\n", this, type, w, h, trans);
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
_transparent = trans;
|
_transparent = trans;
|
||||||
|
@ -188,6 +192,7 @@ gPicture::gPicture(gPictureType type, int w, int h, bool trans) : gShare()
|
||||||
|
|
||||||
gPicture::gPicture(GdkPixbuf *image, bool trans) : gShare()
|
gPicture::gPicture(GdkPixbuf *image, bool trans) : gShare()
|
||||||
{
|
{
|
||||||
|
//fprintf(stderr, "gPicture(image): %p: %p %d\n", this, image, trans);
|
||||||
initialize();
|
initialize();
|
||||||
if (!image)
|
if (!image)
|
||||||
return;
|
return;
|
||||||
|
@ -241,6 +246,7 @@ gPicture::gPicture(GdkPixmap *pix) : gShare()
|
||||||
|
|
||||||
gPicture::~gPicture()
|
gPicture::~gPicture()
|
||||||
{
|
{
|
||||||
|
//fprintf(stderr, "~gPicture: %p\n", this);
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,9 +371,11 @@ GdkPixmap *gPicture::getPixmap()
|
||||||
if (_type != PIXBUF)
|
if (_type != PIXBUF)
|
||||||
getPixbuf();
|
getPixbuf();
|
||||||
|
|
||||||
|
if (pixmap)
|
||||||
|
g_object_unref(G_OBJECT(pixmap));
|
||||||
if (mask)
|
if (mask)
|
||||||
g_object_unref(G_OBJECT(mask));
|
g_object_unref(G_OBJECT(mask));
|
||||||
|
|
||||||
gt_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &mask, 128);
|
gt_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &mask, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +399,10 @@ gPicture *gPicture::fromMemory(char *addr, unsigned int len)
|
||||||
if (!pixbufFromMemory(&pixbuf, addr, len, &trans))
|
if (!pixbufFromMemory(&pixbuf, addr, len, &trans))
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return new gPicture(pixbuf);
|
{
|
||||||
|
gPicture *pic = new gPicture(pixbuf);
|
||||||
|
return pic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gPicture *gPicture::fromData(const char *data, int width, int height)
|
gPicture *gPicture::fromData(const char *data, int width, int height)
|
||||||
|
@ -627,6 +638,7 @@ gPicture* gPicture::fromNamedIcon(const char *name, int len)
|
||||||
void gPicture::clear()
|
void gPicture::clear()
|
||||||
{
|
{
|
||||||
//fprintf(stderr, "gPicture::clear: %p (%d %d) pixmap = %p pixbuf = %p\n", this, _width, _height, pixmap, pixbuf);
|
//fprintf(stderr, "gPicture::clear: %p (%d %d) pixmap = %p pixbuf = %p\n", this, _width, _height, pixmap, pixbuf);
|
||||||
|
|
||||||
_width = 0;
|
_width = 0;
|
||||||
_height = 0;
|
_height = 0;
|
||||||
_type = VOID;
|
_type = VOID;
|
||||||
|
|
|
@ -26,9 +26,9 @@
|
||||||
|
|
||||||
#include "gtag.h"
|
#include "gtag.h"
|
||||||
|
|
||||||
//#define DEBUG_ME
|
//#define DEBUG_SHARE 1
|
||||||
|
|
||||||
#ifdef DEBUG_ME
|
#ifdef DEBUG_SHARE
|
||||||
|
|
||||||
class gShare
|
class gShare
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue