[GB.IMAGE.IO]

* NEW: Image.Stretch() is a new method that allows to stretch an image 
  without having to use a full GUI component.


git-svn-id: svn://localhost/gambas/trunk@5764 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2013-07-26 22:14:10 +00:00
parent 8ba257cf9b
commit 1c34bd7bd5
5 changed files with 71 additions and 8 deletions

View file

@ -1,9 +1,9 @@
# Gambas Project File 3.0
# Compiled with Gambas 3.2.90
# Compiled with Gambas 3.4.90
Title=Gambas web site generator
Startup=MMain
Icon=html.png
Version=3.2.90
Version=3.4.90
VersionFile=1
Component=gb.image
Component=gb.gui

View file

@ -2,7 +2,7 @@ MMain
Gambas web site generator
0
0
3.2.90
3.4.90
gb.image
gb.gui

View file

@ -45,11 +45,11 @@ Public Sub GetFileSize(iSize As Long) As String
If iSize < 1000 Then
Return Subst(("&1 B"), CStr(iSize))
Else If iSize < 1000000 Then
Return Subst(("&1 KiB"), Format(iSize / 1024, "#.#"))
Return Subst(("&1 KiB"), Format(iSize / 1024, "0.#"))
Else If iSize < 1000000000 Then
Return Subst(("&1 MiB"), Format(iSize / 1048576, "#.#"))
Return Subst(("&1 MiB"), Format(iSize / 1048576, "0.#"))
Else
Return Subst(("&1 GiB"), Format(iSize / 1073741824, "#.#"))
Return Subst(("&1 GiB"), Format(iSize / 1073741824, "0.#"))
Endif
End

View file

@ -25,7 +25,7 @@
Background = &HDFEFFF&
Expand = True
{ FileChooser1 FileChooser
MoveScaled(0,2,85,56)
MoveScaled(4,4,85,56)
Background = &HF7DFFF&
Expand = True
}

View file

@ -213,13 +213,76 @@ __END:
END_METHOD
static GdkPixbuf *stretch_pixbuf(GdkPixbuf *img, int w, int h)
{
GdkPixbuf *image = NULL;
int wimg, himg;
int ws, hs;
if (w <= 0 && h <= 0)
goto __RETURN;
wimg = gdk_pixbuf_get_width(img);
himg = gdk_pixbuf_get_height(img);
if (w < 0)
w = wimg * h / himg;
else if (h < 0)
h = himg * w / wimg;
if (w <= 0 || h <= 0)
goto __RETURN;
ws = w;
hs = h;
if (ws < (wimg / 4))
ws = w * 4;
if (hs < (himg / 4))
hs = h * 4;
if (ws != w || hs != h)
{
image = gdk_pixbuf_scale_simple(img, ws, hs, GDK_INTERP_NEAREST);
g_object_unref(G_OBJECT(img));
img = image;
}
image = gdk_pixbuf_scale_simple(img, w, h, GDK_INTERP_BILINEAR);
__RETURN:
g_object_unref(G_OBJECT(img));
return image;
}
BEGIN_METHOD(Image_Stretch, GB_INTEGER width; GB_INTEGER height)
GdkPixbuf *img;
GB_IMG *image;
SYNCHRONIZE_IMAGE(THIS);
IMAGE.Convert(THIS, GB_IMAGE_RGBA);
img = gdk_pixbuf_new_from_data((const guchar *)THIS->data, GDK_COLORSPACE_RGB, TRUE, 8, THIS->width, THIS->height, THIS->width * sizeof(uint), NULL, NULL);
img = stretch_pixbuf(img, VARG(width), VARG(height));
image = IMAGE.Create(gdk_pixbuf_get_width(img), gdk_pixbuf_get_height(img), GB_IMAGE_RGBA, gdk_pixbuf_get_pixels(img));
IMAGE.Convert(image, IMAGE.GetDefaultFormat());
GB.ReturnObject(image);
g_object_unref(G_OBJECT(img));
END_METHOD
GB_DESC CImageDesc[] =
{
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_END_DECLARE
};