ScriptBasic

ScriptBasic => Tutorials => Topic started by: Support on October 26, 2011, 09:29:28 AM

Title: FreeImage
Post by: Support on October 26, 2011, 09:29:28 AM
Here is an example of scripting the FreeImage library under Linux. FreeImage is also available for Windows.


Code: [Select]
DECLARE SUB DLL ALIAS "_idll" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"
DECLARE SUB REQUIRE ALIAS "_idll_require" LIB "gtk-server"
DECLARE SUB DEFINE ALIAS "_idll_define" LIB "gtk-server"

REQUIRE "libfreeimage.so"

DEFINE "FreeImage_GetVersion NONE STRING 0"
DEFINE "FreeImage_GetCopyrightMessage NONE STRING 0"
DEFINE "FreeImage_Load NONE LONG 3 INT STRING INT"
DEFINE "FreeImage_GetWidth NONE INT 1 LONG"
DEFINE "FreeImage_GetHeight NONE INT 1 LONG"
DEFINE "FreeImage_Rescale NONE LONG 4 LONG INT INT INT"
DEFINE "FreeImage_Save NONE BOOL 4 INT LONG STRING INT"
DEFINE "FreeImage_Rotate NONE LONG 3 LONG DOUBLE NULL"

CONST FIF_BMP  =  0
CONST FIF_JPEG =  2
CONST FIF_PNG  = 13
CONST FIF_GIF  = 25

CONST FILTER_BICUBIC = 1

PRINT DLL("FreeImage_GetVersion"),"\n"
PRINT DLL("FreeImage_GetCopyrightMessage"),"\n"
fbmp = DLL("FreeImage_Load " & FIF_JPEG & " \"world.jpg\" 0")
PRINT "Width: ",DLL("FreeImage_GetWidth " & fbmp),"\n"
PRINT "Height: ",DLL("FreeImage_GetHeight " & fbmp),"\n"
fbmps = DLL("FreeImage_Rescale " & fbmp & " 100 100 " & FILTER_BICUBIC)
DLL("FreeImage_Save " & FIF_PNG & " " & fbmps & " \"world_small.png\" 0")
fbmpr = DLL("FreeImage_Rotate " & fbmp & " 180 0")
DLL("FreeImage_Save " & FIF_PNG & " " & fbmpr & " \"world_flip.png\" 0")

Original .jpg image
(http://files.allbasic.info/ScriptBasic/world.jpg)

Rescaled and converted to .png
(http://files.allbasic.info/ScriptBasic/world_small.png)

Flipped 180 degrees
(http://files.allbasic.info/ScriptBasic/world_flip.png)

jrs@laptop:~/sb/FreeImage$ scriba fi.sb
3.13.1
This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
Width: 225
Height: 225
jrs@laptop:~/sb/FreeImage$

Title: Re: FreeImage
Post by: Support on November 02, 2011, 08:14:11 PM
If you define the library in your program like I did in the FreeImage example and use my version of the GTK-Server extension module, you don't need the gtk.bas include. (SB module) Attached is the 32 bit version of gtk-server.so for Ubuntu.

Quote
Will the same gtk.bas work for windows as well linux

I have some recent Windows/Linux Gtk-Server examples HERE (http://www.allbasic.info/forum/index.php?topic=144.0).