Image.FromString() and Picture.FromString() are two new methods that load an image from the contents of a string.
[GB.GTK] * NEW: Image.FromString() and Picture.FromString() are two new methods that load an image from the contents of a string. [GB.GTK3] * NEW: Image.FromString() and Picture.FromString() are two new methods that load an image from the contents of a string. [GB.IMAGE.IO] * NEW: Image.FromString() and Picture.FromString() are two new methods that load an image from the contents of a string. [GB.QT4] * NEW: Image.FromString() and Picture.FromString() are two new methods that load an image from the contents of a string. [GB.QT5] * NEW: Image.FromString() and Picture.FromString() are two new methods that load an image from the contents of a string.
This commit is contained in:
parent
02a28a22ab
commit
066c25c7aa
@ -1,23 +1,23 @@
|
||||
/***************************************************************************
|
||||
|
||||
CImage.cpp
|
||||
CImage.cpp
|
||||
|
||||
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
|
||||
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
@ -79,19 +79,19 @@ static void take_image(CIMAGE *_object, gPicture *image)
|
||||
CIMAGE *CIMAGE_create(gPicture *image)
|
||||
{
|
||||
CIMAGE *img;
|
||||
static GB_CLASS class_id = 0;
|
||||
static GB_CLASS class_id = 0;
|
||||
|
||||
if (!class_id)
|
||||
class_id = GB.FindClass("Image");
|
||||
if (!class_id)
|
||||
class_id = GB.FindClass("Image");
|
||||
|
||||
img = (CIMAGE *)GB.New(class_id, NULL, NULL);
|
||||
|
||||
if (image)
|
||||
take_image(img, image);
|
||||
else
|
||||
take_image(img, new gPicture());
|
||||
img = (CIMAGE *)GB.New(class_id, NULL, NULL);
|
||||
|
||||
return img;
|
||||
if (image)
|
||||
take_image(img, image);
|
||||
else
|
||||
take_image(img, new gPicture());
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
/*CIMAGE *CIMAGE_create(gPicture *picture)
|
||||
@ -109,23 +109,23 @@ CIMAGE *CIMAGE_create(gPicture *image)
|
||||
|
||||
void* GTK_GetImage(GdkPixbuf *buf)
|
||||
{
|
||||
CIMAGE *pic = CIMAGE_create(new gPicture(buf));
|
||||
CIMAGE *pic = CIMAGE_create(new gPicture(buf));
|
||||
g_object_ref(buf);
|
||||
return (void*)pic;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
||||
Image
|
||||
Image
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#if 0
|
||||
BEGIN_METHOD(CIMAGE_new, GB_INTEGER w; GB_INTEGER h; GB_BOOLEAN trans)
|
||||
|
||||
int w = VARGOPT(w, 0);
|
||||
int h = VARGOPT(h, 0);
|
||||
bool trans = VARGOPT(trans, false);
|
||||
int w = VARGOPT(w, 0);
|
||||
int h = VARGOPT(h, 0);
|
||||
bool trans = VARGOPT(trans, false);
|
||||
|
||||
IMAGE = new gPicture(gPicture::MEMORY, w, h, trans);
|
||||
PICTURE->setTag(new gGambasTag((void *)THIS));
|
||||
@ -178,6 +178,25 @@ BEGIN_METHOD(Image_Load, GB_STRING path)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(Image_FromString, GB_STRING data)
|
||||
|
||||
CIMAGE *image;
|
||||
|
||||
gPicture *pic = gPicture::fromMemory(STRING(data), LENGTH(data));
|
||||
|
||||
if (pic)
|
||||
{
|
||||
image = CIMAGE_create(pic);
|
||||
pic->getPixbuf();
|
||||
GB.ReturnObject(image);
|
||||
return;
|
||||
}
|
||||
|
||||
GB.Error("Unable to load image");
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(Image_Save, GB_STRING path; GB_INTEGER quality)
|
||||
|
||||
check_image(THIS);
|
||||
@ -197,7 +216,7 @@ BEGIN_METHOD(Image_Stretch, GB_INTEGER width; GB_INTEGER height)
|
||||
CIMAGE *img;
|
||||
|
||||
check_image(THIS);
|
||||
img = CIMAGE_create(PICTURE->stretch(VARG(width), VARG(height), true));
|
||||
img = CIMAGE_create(PICTURE->stretch(VARG(width), VARG(height), true));
|
||||
GB.ReturnObject((void*)img);
|
||||
|
||||
END_METHOD
|
||||
@ -208,7 +227,7 @@ BEGIN_METHOD(Image_Rotate, GB_FLOAT angle)
|
||||
CIMAGE *img;
|
||||
|
||||
check_image(THIS);
|
||||
img = CIMAGE_create(PICTURE->rotate(VARG(angle)));
|
||||
img = CIMAGE_create(PICTURE->rotate(VARG(angle)));
|
||||
GB.ReturnObject((void*)img);
|
||||
|
||||
END_METHOD
|
||||
@ -216,27 +235,27 @@ END_METHOD
|
||||
|
||||
BEGIN_METHOD(Image_PaintImage, GB_OBJECT img; GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h; GB_INTEGER sx; GB_INTEGER sy; GB_INTEGER sw; GB_INTEGER sh)
|
||||
|
||||
int x, y, w, h, sx, sy, sw, sh;
|
||||
CIMAGE *image = (CIMAGE *)VARG(img);
|
||||
int x, y, w, h, sx, sy, sw, sh;
|
||||
CIMAGE *image = (CIMAGE *)VARG(img);
|
||||
gPicture *src;
|
||||
|
||||
if (GB.CheckObject(image))
|
||||
return;
|
||||
if (GB.CheckObject(image))
|
||||
return;
|
||||
|
||||
src = check_image(image);
|
||||
check_image(THIS);
|
||||
|
||||
x = VARGOPT(x, 0);
|
||||
y = VARGOPT(y, 0);
|
||||
w = VARGOPT(w, -1);
|
||||
h = VARGOPT(h, -1);
|
||||
x = VARGOPT(x, 0);
|
||||
y = VARGOPT(y, 0);
|
||||
w = VARGOPT(w, -1);
|
||||
h = VARGOPT(h, -1);
|
||||
|
||||
sx = VARGOPT(sx, 0);
|
||||
sy = VARGOPT(sy, 0);
|
||||
sw = VARGOPT(sw, -1);
|
||||
sh = VARGOPT(sh, -1);
|
||||
sx = VARGOPT(sx, 0);
|
||||
sy = VARGOPT(sy, 0);
|
||||
sw = VARGOPT(sw, -1);
|
||||
sh = VARGOPT(sh, -1);
|
||||
|
||||
//DRAW_NORMALIZE(x, y, w, h, sx, sy, sw, sh, pic->width(), pic->height());
|
||||
//DRAW_NORMALIZE(x, y, w, h, sx, sy, sw, sh, pic->width(), pic->height());
|
||||
|
||||
PICTURE->draw(src, x, y, w, h, sx, sy, sw, sh);
|
||||
|
||||
@ -245,21 +264,22 @@ END_METHOD
|
||||
|
||||
GB_DESC CImageDesc[] =
|
||||
{
|
||||
GB_DECLARE("Image", sizeof(CIMAGE)),
|
||||
GB_DECLARE("Image", sizeof(CIMAGE)),
|
||||
|
||||
GB_STATIC_METHOD("Load", "Image", Image_Load, "(Path)s"),
|
||||
GB_METHOD("Save", 0, Image_Save, "(Path)s[(Quality)i]"),
|
||||
GB_STATIC_METHOD("Load", "Image", Image_Load, "(Path)s"),
|
||||
GB_STATIC_METHOD("FromString", "Image", Image_FromString, "(Data)s"),
|
||||
GB_METHOD("Save", 0, Image_Save, "(Path)s[(Quality)i]"),
|
||||
|
||||
GB_METHOD("Stretch", "Image", Image_Stretch, "(Width)i(Height)i"),
|
||||
GB_METHOD("Rotate", "Image", Image_Rotate, "(Angle)f"),
|
||||
GB_METHOD("Stretch", "Image", Image_Stretch, "(Width)i(Height)i"),
|
||||
GB_METHOD("Rotate", "Image", Image_Rotate, "(Angle)f"),
|
||||
|
||||
GB_METHOD("PaintImage", 0, Image_PaintImage, "(Image)Image;(X)i(Y)i[(Width)i(Height)i(SrcX)i(SrcY)i(SrcWidth)i(SrcHeight)i]"),
|
||||
GB_METHOD("PaintImage", 0, Image_PaintImage, "(Image)Image;(X)i(Y)i[(Width)i(Height)i(SrcX)i(SrcY)i(SrcWidth)i(SrcHeight)i]"),
|
||||
|
||||
GB_PROPERTY_READ("Picture", "Picture", Image_Picture),
|
||||
GB_PROPERTY_READ("Picture", "Picture", Image_Picture),
|
||||
|
||||
GB_INTERFACE("Paint", &PAINT_Interface),
|
||||
GB_INTERFACE("PaintMatrix", &PAINT_MATRIX_Interface),
|
||||
GB_INTERFACE("Paint", &PAINT_Interface),
|
||||
GB_INTERFACE("PaintMatrix", &PAINT_MATRIX_Interface),
|
||||
|
||||
GB_END_DECLARE
|
||||
GB_END_DECLARE
|
||||
};
|
||||
|
||||
|
@ -75,7 +75,7 @@ bool CPICTURE_load_image(gPicture **p, const char *path, int lenp)
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
BEGIN_METHOD(CPICTURE_new, GB_INTEGER w; GB_INTEGER h; GB_BOOLEAN trans)
|
||||
BEGIN_METHOD(Picture_new, GB_INTEGER w; GB_INTEGER h; GB_BOOLEAN trans)
|
||||
|
||||
int w = VARGOPT(w, 0);
|
||||
int h = VARGOPT(h, 0);
|
||||
@ -91,42 +91,42 @@ BEGIN_METHOD(CPICTURE_new, GB_INTEGER w; GB_INTEGER h; GB_BOOLEAN trans)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CPICTURE_free)
|
||||
BEGIN_METHOD_VOID(Picture_free)
|
||||
|
||||
if (PICTURE) PICTURE->unref();
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_resize, GB_INTEGER width; GB_INTEGER height)
|
||||
BEGIN_METHOD(Picture_Resize, GB_INTEGER width; GB_INTEGER height)
|
||||
|
||||
PICTURE->resize(VARG(width),VARG(height));
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_width)
|
||||
BEGIN_PROPERTY(Picture_Width)
|
||||
|
||||
GB.ReturnInteger(PICTURE->width());
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_height)
|
||||
BEGIN_PROPERTY(Picture_Height)
|
||||
|
||||
GB.ReturnInteger(PICTURE->height());
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_depth)
|
||||
BEGIN_PROPERTY(Picture_Depth)
|
||||
|
||||
GB.ReturnInteger(PICTURE->depth());
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_load, GB_STRING path)
|
||||
BEGIN_METHOD(Picture_Load, GB_STRING path)
|
||||
|
||||
CPICTURE *picture;
|
||||
char *addr;
|
||||
@ -149,6 +149,23 @@ BEGIN_METHOD(CPICTURE_load, GB_STRING path)
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD(Picture_FromString, GB_STRING data)
|
||||
|
||||
CPICTURE *picture;
|
||||
|
||||
gPicture *pic = gPicture::fromMemory(STRING(data), LENGTH(data));
|
||||
|
||||
if (pic)
|
||||
{
|
||||
picture = CPICTURE_create(pic);
|
||||
GB.ReturnObject(picture);
|
||||
return;
|
||||
}
|
||||
|
||||
GB.Error("Unable to load picture");
|
||||
|
||||
END_METHOD
|
||||
|
||||
/*
|
||||
BEGIN_METHOD(CPICTURE_fromMemory,GB_STRING data;)
|
||||
|
||||
@ -164,7 +181,7 @@ BEGIN_METHOD(CPICTURE_fromMemory,GB_STRING data;)
|
||||
END_METHOD
|
||||
*/
|
||||
|
||||
BEGIN_METHOD(CPICTURE_save, GB_STRING path; GB_INTEGER quality)
|
||||
BEGIN_METHOD(Picture_Save, GB_STRING path; GB_INTEGER quality)
|
||||
|
||||
switch (PICTURE->save(GB.FileName(STRING(path), LENGTH(path)), VARGOPT(quality, -1)))
|
||||
{
|
||||
@ -176,21 +193,21 @@ BEGIN_METHOD(CPICTURE_save, GB_STRING path; GB_INTEGER quality)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CPICTURE_clear)
|
||||
BEGIN_METHOD_VOID(Picture_Clear)
|
||||
|
||||
PICTURE->clear();
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_fill, GB_INTEGER col)
|
||||
BEGIN_METHOD(Picture_Fill, GB_INTEGER col)
|
||||
|
||||
PICTURE->fill(VARG(col));
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_copy, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h)
|
||||
BEGIN_METHOD(Picture_Copy, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h)
|
||||
|
||||
CPICTURE *pic=NULL;
|
||||
int x=0;
|
||||
@ -209,7 +226,7 @@ BEGIN_METHOD(CPICTURE_copy, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_image)
|
||||
BEGIN_PROPERTY(Picture_Image)
|
||||
|
||||
CIMAGE *img = CIMAGE_create(PICTURE->copy());
|
||||
//CIMAGE_get(img)->getPixbuf();
|
||||
@ -217,7 +234,7 @@ BEGIN_PROPERTY(CPICTURE_image)
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_transparent)
|
||||
BEGIN_PROPERTY(Picture_Transparent)
|
||||
|
||||
if (READ_PROPERTY) { GB.ReturnBoolean(PICTURE->isTransparent()); return; }
|
||||
PICTURE->setTransparent(VPROP(GB_BOOLEAN));
|
||||
@ -231,25 +248,26 @@ GB_DESC CPictureDesc[] =
|
||||
|
||||
//GB_STATIC_METHOD("_exit", NULL, CPICTURE_flush, NULL),
|
||||
|
||||
GB_METHOD("_new", NULL, CPICTURE_new, "[(Width)i(Height)i(Transparent)b]"),
|
||||
GB_METHOD("_free", NULL, CPICTURE_free, NULL),
|
||||
GB_METHOD("_new", NULL, Picture_new, "[(Width)i(Height)i(Transparent)b]"),
|
||||
GB_METHOD("_free", NULL, Picture_free, NULL),
|
||||
|
||||
GB_PROPERTY_READ("Width", "i", CPICTURE_width),
|
||||
GB_PROPERTY_READ("Height", "i", CPICTURE_height),
|
||||
GB_PROPERTY_READ("W", "i", CPICTURE_width),
|
||||
GB_PROPERTY_READ("H", "i", CPICTURE_height),
|
||||
GB_PROPERTY_READ("Depth", "i", CPICTURE_depth),
|
||||
GB_PROPERTY("Transparent", "b", CPICTURE_transparent),
|
||||
GB_PROPERTY_READ("Width", "i", Picture_Width),
|
||||
GB_PROPERTY_READ("Height", "i", Picture_Height),
|
||||
GB_PROPERTY_READ("W", "i", Picture_Width),
|
||||
GB_PROPERTY_READ("H", "i", Picture_Height),
|
||||
GB_PROPERTY_READ("Depth", "i", Picture_Depth),
|
||||
GB_PROPERTY("Transparent", "b", Picture_Transparent),
|
||||
|
||||
GB_STATIC_METHOD("Load", "Picture", CPICTURE_load, "(Path)s"),
|
||||
GB_METHOD("Save", 0, CPICTURE_save, "(Path)s[(Quality)i]"),
|
||||
GB_METHOD("Resize", 0, CPICTURE_resize, "(Width)i(Height)i"),
|
||||
GB_STATIC_METHOD("Load", "Picture", Picture_Load, "(Path)s"),
|
||||
GB_STATIC_METHOD("FromString", "Picture", Picture_FromString, "(Data)s"),
|
||||
GB_METHOD("Save", NULL, Picture_Save, "(Path)s[(Quality)i]"),
|
||||
GB_METHOD("Resize", NULL, Picture_Resize, "(Width)i(Height)i"),
|
||||
|
||||
GB_METHOD("Clear", 0, CPICTURE_clear, 0),
|
||||
GB_METHOD("Fill", 0, CPICTURE_fill, "(Color)i"),
|
||||
GB_METHOD("Clear", NULL, Picture_Clear, NULL),
|
||||
GB_METHOD("Fill", NULL, Picture_Fill, "(Color)i"),
|
||||
|
||||
GB_METHOD("Copy", "Picture", CPICTURE_copy, "[(X)i(Y)i(Width)i(Height)i]"),
|
||||
GB_PROPERTY_READ("Image", "Image", CPICTURE_image),
|
||||
GB_METHOD("Copy", "Picture", Picture_Copy, "[(X)i(Y)i(Width)i(Height)i]"),
|
||||
GB_PROPERTY_READ("Image", "Image", Picture_Image),
|
||||
|
||||
GB_INTERFACE("Paint", &PAINT_Interface),
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
/***************************************************************************
|
||||
|
||||
c_image.c
|
||||
c_image.c
|
||||
|
||||
(c) 2000-2017 Benoît Minisini <gambas@users.sourceforge.net>
|
||||
(c) 2000-2017 Benoît Minisini <gambas@users.sourceforge.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
@ -27,71 +27,52 @@
|
||||
|
||||
#define LOAD_INC 65536L
|
||||
|
||||
BEGIN_METHOD(CIMAGE_load, GB_STRING path)
|
||||
|
||||
static void load_image(const char *addr, int len)
|
||||
{
|
||||
GdkPixbuf *img = NULL;
|
||||
char *addr, *laddr;
|
||||
int len, llen;
|
||||
const char *laddr;
|
||||
int llen;
|
||||
GdkPixbufLoader* loader = NULL;
|
||||
GError *error = NULL;
|
||||
int size;
|
||||
int format;
|
||||
GB_IMG *image;
|
||||
|
||||
/*if (LENGTH(path) && *STRING(path) == '/')
|
||||
loader = gdk_pixbuf_loader_new();
|
||||
|
||||
laddr = addr;
|
||||
llen = len;
|
||||
while (llen > 0)
|
||||
{
|
||||
img = gdk_pixbuf_new_from_file(GB.ToZeroString(ARG(path)), &error);
|
||||
if (error)
|
||||
size = llen > LOAD_INC ? LOAD_INC : llen;
|
||||
if (!gdk_pixbuf_loader_write(loader, (guchar*)laddr, (gsize)size, &error))
|
||||
{
|
||||
fprintf(stderr, "gb.image.io: error: cannot load %d image bytes\n", size);
|
||||
GB.Error(error->message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{*/
|
||||
if (GB.LoadFile(STRING(path), LENGTH(path), &addr, &len))
|
||||
{
|
||||
GB.Error("Unable to load image");
|
||||
return;
|
||||
}
|
||||
|
||||
loader = gdk_pixbuf_loader_new();
|
||||
|
||||
laddr = addr;
|
||||
llen = len;
|
||||
while (llen > 0)
|
||||
{
|
||||
size = llen > LOAD_INC ? LOAD_INC : llen;
|
||||
if (!gdk_pixbuf_loader_write(loader, (guchar*)laddr, (gsize)size, &error))
|
||||
{
|
||||
fprintf(stderr, "gb.image.io: error: cannot load %d image bytes\n", size);
|
||||
GB.Error(error->message);
|
||||
goto __END;
|
||||
}
|
||||
laddr += size;
|
||||
llen -= size;
|
||||
}
|
||||
|
||||
gdk_pixbuf_loader_close(loader, NULL);
|
||||
|
||||
img = gdk_pixbuf_loader_get_pixbuf(loader);
|
||||
if (!img)
|
||||
{
|
||||
GB.Error("Unable to load image");
|
||||
goto __END;
|
||||
}
|
||||
laddr += size;
|
||||
llen -= size;
|
||||
}
|
||||
|
||||
g_object_ref(G_OBJECT(img));
|
||||
gdk_pixbuf_loader_close(loader, NULL);
|
||||
|
||||
img = gdk_pixbuf_loader_get_pixbuf(loader);
|
||||
if (!img)
|
||||
{
|
||||
GB.Error("Unable to load image");
|
||||
goto __END;
|
||||
}
|
||||
|
||||
g_object_ref(G_OBJECT(img));
|
||||
|
||||
//}
|
||||
|
||||
// Rowstride breaks gb.image (it is rounded up so that a line is always a four bytes multiple).
|
||||
if (gdk_pixbuf_get_n_channels(img) == 3)
|
||||
{
|
||||
GdkPixbuf *aimg;
|
||||
aimg = gdk_pixbuf_add_alpha(img, FALSE, 0, 0, 0);
|
||||
g_object_unref(G_OBJECT(img));
|
||||
img = aimg;
|
||||
img = aimg;
|
||||
}
|
||||
|
||||
//fprintf(stderr, "nchannels = %d size = %d x %d rowstride = %d\n", gdk_pixbuf_get_n_channels(img), gdk_pixbuf_get_width(img), gdk_pixbuf_get_height(img), gdk_pixbuf_get_rowstride(img));
|
||||
@ -115,29 +96,51 @@ BEGIN_METHOD(CIMAGE_load, GB_STRING path)
|
||||
__END:
|
||||
|
||||
if (loader)
|
||||
{
|
||||
g_object_unref(G_OBJECT(loader));
|
||||
GB.ReleaseFile(addr, len);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_METHOD(Image_Load, GB_STRING path)
|
||||
|
||||
char *addr;
|
||||
int len;
|
||||
|
||||
if (GB.LoadFile(STRING(path), LENGTH(path), &addr, &len))
|
||||
{
|
||||
GB.Error("Unable to load image");
|
||||
return;
|
||||
}
|
||||
|
||||
load_image(addr, len);
|
||||
|
||||
GB.ReleaseFile(addr, len);
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(Image_FromString, GB_STRING data)
|
||||
|
||||
load_image(STRING(data), LENGTH(data));
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
static const char *FILE_get_ext(const char *path)
|
||||
{
|
||||
const char *p;
|
||||
const char *p;
|
||||
|
||||
p = rindex(path, '/');
|
||||
if (p)
|
||||
path = &p[1];
|
||||
p = rindex(path, '/');
|
||||
if (p)
|
||||
path = &p[1];
|
||||
|
||||
p = rindex(path, '.');
|
||||
if (p == NULL)
|
||||
return &path[strlen(path)];
|
||||
else
|
||||
return p + 1;
|
||||
p = rindex(path, '.');
|
||||
if (p == NULL)
|
||||
return &path[strlen(path)];
|
||||
else
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
BEGIN_METHOD(CIMAGE_save, GB_STRING path; GB_INTEGER quality)
|
||||
BEGIN_METHOD(Image_Save, GB_STRING path; GB_INTEGER quality)
|
||||
|
||||
char *path = GB.FileName(STRING(path), LENGTH(path));
|
||||
const char *ext = NULL;
|
||||
@ -296,12 +299,13 @@ END_METHOD
|
||||
|
||||
GB_DESC CImageDesc[] =
|
||||
{
|
||||
GB_DECLARE("Image", sizeof(CIMAGE)),
|
||||
GB_DECLARE("Image", sizeof(CIMAGE)),
|
||||
|
||||
GB_STATIC_METHOD("Load", "Image", CIMAGE_load, "(Path)s"),
|
||||
GB_METHOD("Save", NULL, CIMAGE_save, "(Path)s[(Quality)i]"),
|
||||
GB_METHOD("Stretch", "Image", Image_Stretch, "(Width)i(Height)i"),
|
||||
GB_STATIC_METHOD("Load", "Image", Image_Load, "(Path)s"),
|
||||
GB_STATIC_METHOD("FromString", "Image", Image_FromString, "(Data)s"),
|
||||
GB_METHOD("Save", NULL, Image_Save, "(Path)s[(Quality)i]"),
|
||||
GB_METHOD("Stretch", "Image", Image_Stretch, "(Width)i(Height)i"),
|
||||
|
||||
GB_END_DECLARE
|
||||
GB_END_DECLARE
|
||||
};
|
||||
|
||||
|
@ -145,7 +145,7 @@ CIMAGE *CIMAGE_create(QImage *image)
|
||||
return img;
|
||||
}
|
||||
|
||||
BEGIN_PROPERTY(IMAGE_Picture)
|
||||
BEGIN_PROPERTY(Image_Picture)
|
||||
|
||||
CPICTURE *pict;
|
||||
QImage img;
|
||||
@ -164,7 +164,7 @@ BEGIN_PROPERTY(IMAGE_Picture)
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_METHOD(IMAGE_Load, GB_STRING path)
|
||||
BEGIN_METHOD(Image_Load, GB_STRING path)
|
||||
|
||||
QImage *p;
|
||||
CIMAGE *img;
|
||||
@ -180,8 +180,23 @@ BEGIN_METHOD(IMAGE_Load, GB_STRING path)
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD(Image_FromString, GB_STRING data)
|
||||
|
||||
BEGIN_METHOD(IMAGE_Save, GB_STRING path; GB_INTEGER quality)
|
||||
QImage *p;
|
||||
CIMAGE *img;
|
||||
|
||||
if (CPICTURE_from_string(&p, STRING(data), LENGTH(data)))
|
||||
{
|
||||
//p->convertToFormat(QImage::Format_ARGB32);
|
||||
img = CIMAGE_create(p);
|
||||
GB.ReturnObject(img);
|
||||
}
|
||||
else
|
||||
GB.Error("Unable to load image");
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD(Image_Save, GB_STRING path; GB_INTEGER quality)
|
||||
|
||||
QString path = TO_QSTRING(GB.FileName(STRING(path), LENGTH(path)));
|
||||
bool ok = false;
|
||||
@ -202,7 +217,7 @@ BEGIN_METHOD(IMAGE_Save, GB_STRING path; GB_INTEGER quality)
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD(IMAGE_Stretch, GB_INTEGER width; GB_INTEGER height)
|
||||
BEGIN_METHOD(Image_Stretch, GB_INTEGER width; GB_INTEGER height)
|
||||
|
||||
//static int count = 0;
|
||||
QImage *stretch;
|
||||
@ -234,7 +249,7 @@ BEGIN_METHOD(IMAGE_Stretch, GB_INTEGER width; GB_INTEGER height)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(IMAGE_Rotate, GB_FLOAT angle)
|
||||
BEGIN_METHOD(Image_Rotate, GB_FLOAT angle)
|
||||
|
||||
QImage *rotate = new QImage();
|
||||
double angle = VARG(angle);
|
||||
@ -255,7 +270,7 @@ BEGIN_METHOD(IMAGE_Rotate, GB_FLOAT angle)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(IMAGE_PaintImage, GB_OBJECT img; GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h; GB_INTEGER sx; GB_INTEGER sy; GB_INTEGER sw; GB_INTEGER sh)
|
||||
BEGIN_METHOD(Image_PaintImage, GB_OBJECT img; GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h; GB_INTEGER sx; GB_INTEGER sy; GB_INTEGER sw; GB_INTEGER sh)
|
||||
|
||||
int x, y, w, h, sx, sy, sw, sh;
|
||||
CIMAGE *image = (CIMAGE *)VARG(img);
|
||||
@ -310,15 +325,16 @@ GB_DESC CImageDesc[] =
|
||||
{
|
||||
GB_DECLARE("Image", sizeof(CIMAGE)),
|
||||
|
||||
GB_STATIC_METHOD("Load", "Image", IMAGE_Load, "(Path)s"),
|
||||
GB_METHOD("Save", NULL, IMAGE_Save, "(Path)s[(Quality)i]"),
|
||||
GB_STATIC_METHOD("Load", "Image", Image_Load, "(Path)s"),
|
||||
GB_STATIC_METHOD("FromString", "Image", Image_FromString, "(Data)s"),
|
||||
GB_METHOD("Save", NULL, Image_Save, "(Path)s[(Quality)i]"),
|
||||
|
||||
GB_METHOD("Stretch", "Image", IMAGE_Stretch, "(Width)i(Height)i"),
|
||||
GB_METHOD("Rotate", "Image", IMAGE_Rotate, "(Angle)f"),
|
||||
GB_METHOD("Stretch", "Image", Image_Stretch, "(Width)i(Height)i"),
|
||||
GB_METHOD("Rotate", "Image", Image_Rotate, "(Angle)f"),
|
||||
|
||||
GB_METHOD("PaintImage", NULL, IMAGE_PaintImage, "(Image)Image;(X)i(Y)i[(Width)i(Height)i(SrcX)i(SrcY)i(SrcWidth)i(SrcHeight)i]"),
|
||||
GB_METHOD("PaintImage", NULL, Image_PaintImage, "(Image)Image;(X)i(Y)i[(Width)i(Height)i(SrcX)i(SrcY)i(SrcWidth)i(SrcHeight)i]"),
|
||||
|
||||
GB_PROPERTY_READ("Picture", "Picture", IMAGE_Picture),
|
||||
GB_PROPERTY_READ("Picture", "Picture", Image_Picture),
|
||||
|
||||
GB_INTERFACE("Paint", &PAINT_Interface),
|
||||
GB_INTERFACE("PaintMatrix", &PAINT_MATRIX_Interface),
|
||||
|
@ -78,6 +78,16 @@ static CPICTURE *create()
|
||||
}
|
||||
|
||||
|
||||
bool CPICTURE_from_string(QImage **p, const char *addr, int len)
|
||||
{
|
||||
bool ok;
|
||||
|
||||
*p = 0;
|
||||
CREATE_IMAGE_FROM_MEMORY(*p, addr, len, ok)
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool CPICTURE_load_image(QImage **p, const char *path, int lenp)
|
||||
{
|
||||
char *addr;
|
||||
@ -92,14 +102,12 @@ bool CPICTURE_load_image(QImage **p, const char *path, int lenp)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CREATE_IMAGE_FROM_MEMORY(*p, addr, len, ok)
|
||||
ok = CPICTURE_from_string(p, addr, len);
|
||||
|
||||
GB.ReleaseFile(addr, len);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CPICTURE *CPICTURE_grab(QWidget *wid, int screen, int x, int y, int w, int h)
|
||||
{
|
||||
CPICTURE *pict;
|
||||
@ -152,7 +160,7 @@ CPICTURE *CPICTURE_create(const QPixmap *pixmap)
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_new, GB_INTEGER w; GB_INTEGER h; GB_BOOLEAN trans)
|
||||
BEGIN_METHOD(Picture_new, GB_INTEGER w; GB_INTEGER h; GB_BOOLEAN trans)
|
||||
|
||||
int w, h;
|
||||
|
||||
@ -181,7 +189,7 @@ BEGIN_METHOD(CPICTURE_new, GB_INTEGER w; GB_INTEGER h; GB_BOOLEAN trans)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CPICTURE_free)
|
||||
BEGIN_METHOD_VOID(Picture_free)
|
||||
|
||||
delete THIS->pixmap;
|
||||
THIS->pixmap = 0;
|
||||
@ -189,7 +197,7 @@ BEGIN_METHOD_VOID(CPICTURE_free)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_resize, GB_INTEGER width; GB_INTEGER height)
|
||||
BEGIN_METHOD(Picture_Resize, GB_INTEGER width; GB_INTEGER height)
|
||||
|
||||
QPixmap *pixmap = new QPixmap(VARG(width), VARG(height));
|
||||
|
||||
@ -203,28 +211,28 @@ BEGIN_METHOD(CPICTURE_resize, GB_INTEGER width; GB_INTEGER height)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_width)
|
||||
BEGIN_PROPERTY(Picture_Width)
|
||||
|
||||
GB.ReturnInteger(THIS->pixmap->width());
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_height)
|
||||
BEGIN_PROPERTY(Picture_Height)
|
||||
|
||||
GB.ReturnInteger(THIS->pixmap->height());
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_depth)
|
||||
BEGIN_PROPERTY(Picture_Depth)
|
||||
|
||||
GB.ReturnInteger(THIS->pixmap->depth());
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_load, GB_STRING path)
|
||||
BEGIN_METHOD(Picture_Load, GB_STRING path)
|
||||
|
||||
CPICTURE *pict;
|
||||
QImage *img;
|
||||
@ -241,8 +249,24 @@ BEGIN_METHOD(CPICTURE_load, GB_STRING path)
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD(Picture_FromString, GB_STRING data)
|
||||
|
||||
BEGIN_METHOD(CPICTURE_save, GB_STRING path; GB_INTEGER quality)
|
||||
CPICTURE *pict;
|
||||
QImage *img;
|
||||
|
||||
if (!CPICTURE_from_string(&img, STRING(data), LENGTH(data)))
|
||||
{
|
||||
GB.Error("Unable to load picture");
|
||||
return;
|
||||
}
|
||||
|
||||
CREATE_PICTURE_FROM_IMAGE(pict, img);
|
||||
DELETE_IMAGE(img);
|
||||
GB.ReturnObject(pict);
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD(Picture_Save, GB_STRING path; GB_INTEGER quality)
|
||||
|
||||
QString path = TO_QSTRING(GB.FileName(STRING(path), LENGTH(path)));
|
||||
bool ok = false;
|
||||
@ -262,7 +286,7 @@ BEGIN_METHOD(CPICTURE_save, GB_STRING path; GB_INTEGER quality)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CPICTURE_clear)
|
||||
BEGIN_METHOD_VOID(Picture_Clear)
|
||||
|
||||
delete THIS->pixmap;
|
||||
THIS->pixmap = new QPixmap;
|
||||
@ -270,7 +294,7 @@ BEGIN_METHOD_VOID(CPICTURE_clear)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_fill, GB_INTEGER col)
|
||||
BEGIN_METHOD(Picture_Fill, GB_INTEGER col)
|
||||
|
||||
int col = VARG(col);
|
||||
QBitmap mask;
|
||||
@ -280,7 +304,7 @@ BEGIN_METHOD(CPICTURE_fill, GB_INTEGER col)
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(CPICTURE_copy, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h)
|
||||
BEGIN_METHOD(Picture_Copy, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h)
|
||||
|
||||
CPICTURE *pict;
|
||||
int x = VARGOPT(x, 0);
|
||||
@ -301,7 +325,7 @@ BEGIN_METHOD(CPICTURE_copy, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_image)
|
||||
BEGIN_PROPERTY(Picture_Image)
|
||||
|
||||
QImage *image = new QImage();
|
||||
|
||||
@ -313,7 +337,7 @@ BEGIN_PROPERTY(CPICTURE_image)
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CPICTURE_transparent)
|
||||
BEGIN_PROPERTY(Picture_Transparent)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
GB.ReturnBoolean(THIS->pixmap->hasAlpha());
|
||||
@ -337,27 +361,28 @@ GB_DESC CPictureDesc[] =
|
||||
{
|
||||
GB_DECLARE("Picture", sizeof(CPICTURE)),
|
||||
|
||||
GB_METHOD("_new", NULL, CPICTURE_new, "[(Width)i(Height)i(Transparent)b]"),
|
||||
GB_METHOD("_free", NULL, CPICTURE_free, NULL),
|
||||
GB_METHOD("_new", NULL, Picture_new, "[(Width)i(Height)i(Transparent)b]"),
|
||||
GB_METHOD("_free", NULL, Picture_free, NULL),
|
||||
|
||||
GB_PROPERTY_READ("W", "i", CPICTURE_width),
|
||||
GB_PROPERTY_READ("Width", "i", CPICTURE_width),
|
||||
GB_PROPERTY_READ("H", "i", CPICTURE_height),
|
||||
GB_PROPERTY_READ("Height", "i", CPICTURE_height),
|
||||
GB_PROPERTY_READ("Depth", "i", CPICTURE_depth),
|
||||
GB_PROPERTY_READ("W", "i", Picture_Width),
|
||||
GB_PROPERTY_READ("Width", "i", Picture_Width),
|
||||
GB_PROPERTY_READ("H", "i", Picture_Height),
|
||||
GB_PROPERTY_READ("Height", "i", Picture_Height),
|
||||
GB_PROPERTY_READ("Depth", "i", Picture_Depth),
|
||||
|
||||
GB_STATIC_METHOD("Load", "Picture", CPICTURE_load, "(Path)s"),
|
||||
GB_METHOD("Save", NULL, CPICTURE_save, "(Path)s[(Quality)i]"),
|
||||
GB_METHOD("Resize", NULL, CPICTURE_resize, "(Width)i(Height)i"),
|
||||
GB_STATIC_METHOD("Load", "Picture", Picture_Load, "(Path)s"),
|
||||
GB_STATIC_METHOD("FromString", "Picture", Picture_FromString, "(Data)s"),
|
||||
GB_METHOD("Save", NULL, Picture_Save, "(Path)s[(Quality)i]"),
|
||||
GB_METHOD("Resize", NULL, Picture_Resize, "(Width)i(Height)i"),
|
||||
|
||||
GB_METHOD("Clear", NULL, CPICTURE_clear, NULL),
|
||||
GB_METHOD("Fill", NULL, CPICTURE_fill, "(Color)i"),
|
||||
GB_METHOD("Clear", NULL, Picture_Clear, NULL),
|
||||
GB_METHOD("Fill", NULL, Picture_Fill, "(Color)i"),
|
||||
//GB_METHOD("Mask", NULL, CPICTURE_mask, "[(Color)i]"),
|
||||
|
||||
GB_PROPERTY("Transparent", "b", CPICTURE_transparent),
|
||||
GB_PROPERTY("Transparent", "b", Picture_Transparent),
|
||||
|
||||
GB_METHOD("Copy", "Picture", CPICTURE_copy, "[(X)i(Y)i(Width)i(Height)i]"),
|
||||
GB_PROPERTY_READ("Image", "Image", CPICTURE_image),
|
||||
GB_METHOD("Copy", "Picture", Picture_Copy, "[(X)i(Y)i(Width)i(Height)i]"),
|
||||
GB_PROPERTY_READ("Image", "Image", Picture_Image),
|
||||
|
||||
//GB_INTERFACE("Draw", &DRAW_Interface),
|
||||
GB_INTERFACE("Paint", &PAINT_Interface),
|
||||
|
@ -72,6 +72,7 @@ extern GB_DESC CPictureDesc[];
|
||||
CPICTURE *CPICTURE_grab(QWidget *wid, int screen = -1, int x = 0, int y = 0, int w = -1, int h = -1);
|
||||
CPICTURE *CPICTURE_get_picture(const char *path);
|
||||
bool CPICTURE_load_image(QImage **p, const char *path, int lenp);
|
||||
bool CPICTURE_from_string(QImage **p, const char *addr, int len);
|
||||
CPICTURE *CPICTURE_create(const QPixmap *pixmap);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user