ScriptBasic
May 22, 2012, 02:32:45 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The ScriptBasic User, Developer and extension module guides are available at the WIKI.
 
   Home   Wiki Help Search Login Register  
Pages: [1]
  Print  
Author Topic: FreeImage  (Read 857 times)
support
Administrator
*****
Posts: 409


« 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.

  • Get FreeImage version number
  • Get FreeImage copyright message
  • Load a jpg image
  • Get the image height and width
  • Rescale the jpg image from 225x225 to 100x100 using bicubic interpolation
  • Save the rescaled image as a png
  • Flip the original jpg image 180 degrees and save it as a png

Code:
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


Rescaled and converted to .png


Flipped 180 degrees


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$

« Last Edit: October 26, 2011, 04:34:39 PM by support » Logged
RONB
Newbie
*
Posts: 35


« Reply #1 on: November 02, 2011, 07:17:45 PM »

I installed freeimage-dev on ubuntu server
Which distribution of GTK did you use for ubuntu
Would you post the ubuntu gtk.so and gtk.bas
Will the same gtk.bas work for windows as well linux

I noticed in the docs that you can feed it with a url and send the result as a html page, so that will be my first SB test of freeimage.

thanks, Ron

Logged
support
Administrator
*****
Posts: 409


« Reply #2 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.

* gtk-server32.zip (47.34 KB - downloaded 34 times.)
« Last Edit: November 02, 2011, 08:56:13 PM by support » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!