Author Topic: FreeImage Fun  (Read 4274 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
FreeImage Fun
« on: March 12, 2013, 12:07:04 PM »
I converted one of my old FreeImage SB examples using GTK-Server to DLLC. I have attached a new DLLC that handles the weird FreeImage function names. (direct access without going through a wrapper)

Code: OxygenBasic
  1. ' FreeImage Example
  2.  
  3. DECLARE SUB DLLC_File ALIAS "dllfile" LIB "DLLC"
  4. DECLARE SUB DLLC_Proc ALIAS "dllproc" LIB "DLLC"
  5. DECLARE SUB DLLC_Call ALIAS "dllcall" LIB "DLLC"
  6.  
  7. fih = DLLC_File("FreeImage.dll")
  8.  
  9. Version = DLLC_Proc(fih,"_FreeImage_GetVersion@0 z = ( )")
  10. Copyright = DLLC_Proc(fih,"_FreeImage_GetCopyrightMessage@0 z = ( )")
  11. LoadImage  = DLLC_Proc(fih,"_FreeImage_Load@12 i = (i fif, z filename, i flag)")
  12. Width = DLLC_Proc(fih,"_FreeImage_GetWidth@4 i = (i dib)")
  13. Height = DLLC_Proc(fih,"_FreeImage_GetHeight@4 i = (i dib)")
  14. Rescale = DLLC_Proc(fih,"_FreeImage_Rescale@16 i = (i dib, i dst_width, i dst_height, i filter)")
  15. Rotate = DLLC_Proc(fih,"_FreeImage_Rotate@16 i = (i dib, d angle, p bkcolor)")
  16. Save = DLLC_Proc(fih,"_FreeImage_Save@16 b = (i fif, i dib, z fname, i flage)")
  17.  
  18. CONST FIF_BMP  =  0
  19. CONST FIF_JPEG =  2
  20. CONST FIF_PNG  = 13
  21. CONST FIF_GIF  = 25
  22. CONST FILTER_BICUBIC = 1
  23.  
  24. PRINT DLLC_Call(Version),"\n"
  25. PRINT DLLC_Call(Copyright),"\n"
  26. fbmp = DLLC_Call(LoadImage, FIF_JPEG, "world.jpg", 0)
  27. PRINT "Width: ",DLLC_Call(Width, fbmp),"\n"
  28. PRINT "Height: ",DLLC_Call(Height, fbmp),"\n"
  29. fbmps = DLLC_Call(Rescale, fbmp, 100, 100, FILTER_BICUBIC)
  30. DLLC_Call(Save, FIF_PNG, fbmps, "world_small.png", 0)
  31. fbmpr = DLLC_Call(Rotate, fbmp, 180, 0)
  32. DLLC_Call(Save, FIF_PNG, fbmpr, "world_flip.png", 0)
  33.  

C:\SB22\test>scriba testfi.sb
3.15.4
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
C:\SB22\test>

Original .jpg image


Rescaled and converted to .png


Flipped 180 degrees



X
« Last Edit: March 12, 2013, 09:14:04 PM by JRS »

Charles Pegge

  • Guest
Re: FreeImage Fun
« Reply #1 on: March 12, 2013, 12:34:55 PM »
Easier to use than GDIplus, but rather large for distribution. Do most Linuxes already have it on-board John?

JRS

  • Guest
Re: FreeImage Fun
« Reply #2 on: March 12, 2013, 12:56:27 PM »
Quote
Easier to use than GDIplus, but rather large for distribution. Do most Linuxes already have it on-board John?

Not standard issue but a simple install via Synaptic. The Linux version doesn't have all the wrapper and cryptic function name crap that the Windows version has. It's the typical Windows trick. Getting all animals to drink out of the same trough.

The reason it's huge (2.7 MB) is the Windows version has all the open source image plug-ins static linked into the FreeImage.dll. (only one DLL to distribute) Works for me as I just declare what I want to use at runtime and I'm done. Isn't that what scripting is suppose to be all about?


« Last Edit: March 12, 2013, 01:42:13 PM by JRS »

Peter

  • Guest
Re: FreeImage Fun
« Reply #3 on: March 12, 2013, 01:04:27 PM »
Code: [Select]
include "sw.inc"
Window 640,480,1

p1 = LoadBmp "bmp/earth.bmp",1
single a

while Key(27)=0
  Cls RGB(200,200,248)
  DrawBmp p1,100,100,228,228,0
  DrawBmp p1,100,300,200,200,0
  DrawBmp p1,300,340,128,128,0
  DrawBmp p1,428,372, 64, 64,0
  RotateBmp p1,320,100,a
  SetText 220,16,"Some Blue Planets",RGB(0,0,250)
  Sync()
  a +=9
  if a >360 then a= -360
wend
Quit

X
« Last Edit: March 12, 2013, 01:09:47 PM by peter »

JRS

  • Guest
Re: FreeImage Fun
« Reply #4 on: March 12, 2013, 07:20:49 PM »
My plan at the moment is to create the first DLLC based scripted extension module for ScriptBasic using the FreeImage DLL. (ScriptBasic will be the wrapper)

Code: [Select]
IMPORT FI

PRINT FI::GetVersion(),"\n"
...

I dumped the FreeImage.dll exported function list and group them by the trailing @ value and than alphabetically.

Code: [Select]
[ 0 ]
_FreeImage_CreateTag@0
_FreeImage_DeInitialise@0
_FreeImage_GetCopyrightMessage@0
_FreeImage_GetFIFCount@0
_FreeImage_GetVersion@0
_FreeImage_IsLittleEndian@0

[ 4 ]
_FreeImage_Clone@4
_FreeImage_CloneTag@4
_FreeImage_CloseMemory@4
_FreeImage_ConvertTo16Bits555@4
_FreeImage_ConvertTo16Bits565@4
_FreeImage_ConvertTo24Bits@4
_FreeImage_ConvertTo32Bits@4
_FreeImage_ConvertTo4Bits@4
_FreeImage_ConvertTo8Bits@4
_FreeImage_ConvertToFloat@4
_FreeImage_ConvertToGreyscale@4
_FreeImage_ConvertToRGB16@4
_FreeImage_ConvertToRGBF@4
_FreeImage_ConvertToUINT16@4
_FreeImage_DeleteTag@4
_FreeImage_DestroyICCProfile@4
_FreeImage_FIFSupportsICCProfiles@4
_FreeImage_FIFSupportsNoPixels@4
_FreeImage_FIFSupportsReading@4
_FreeImage_FIFSupportsWriting@4
_FreeImage_FindCloseMetadata@4
_FreeImage_FlipHorizontal@4
_FreeImage_FlipVertical@4
_FreeImage_GetBits@4
_FreeImage_GetBlueMask@4
_FreeImage_GetBPP@4
_FreeImage_GetColorsUsed@4
_FreeImage_GetColorType@4
_FreeImage_GetDIBSize@4
_FreeImage_GetDotsPerMeterX@4
_FreeImage_GetDotsPerMeterY@4
_FreeImage_GetFIFDescription@4
_FreeImage_GetFIFExtensionList@4
_FreeImage_GetFIFFromFilename@4
_FreeImage_GetFIFFromFilenameU@4
_FreeImage_GetFIFFromFormat@4
_FreeImage_GetFIFFromMime@4
_FreeImage_GetFIFMimeType@4
_FreeImage_GetFIFRegExpr@4
_FreeImage_GetFormatFromFIF@4
_FreeImage_GetGreenMask@4
_FreeImage_GetHeight@4
_FreeImage_GetICCProfile@4
_FreeImage_GetImageType@4
_FreeImage_GetInfo@4
_FreeImage_GetInfoHeader@4
_FreeImage_GetLine@4
_FreeImage_GetPageCount@4
_FreeImage_GetPalette@4
_FreeImage_GetPitch@4
_FreeImage_GetRedMask@4
_FreeImage_GetTagCount@4
_FreeImage_GetTagDescription@4
_FreeImage_GetTagID@4
_FreeImage_GetTagKey@4
_FreeImage_GetTagLength@4
_FreeImage_GetTagType@4
_FreeImage_GetTagValue@4
_FreeImage_GetThumbnail@4
_FreeImage_GetTransparencyCount@4
_FreeImage_GetTransparencyTable@4
_FreeImage_GetTransparentIndex@4
_FreeImage_GetWidth@4
_FreeImage_HasBackgroundColor@4
_FreeImage_HasPixels@4
_FreeImage_HasRGBMasks@4
_FreeImage_Initialise@4
_FreeImage_Invert@4
_FreeImage_IsPluginEnabled@4
_FreeImage_IsTransparent@4
_FreeImage_PreMultiplyWithAlpha@4
_FreeImage_SetOutputMessage@4
_FreeImage_SetOutputMessageStdCall@4
_FreeImage_TellMemory@4
_FreeImage_Unload@4

[ 8 ]
_FreeImage_AppendPage@8
_FreeImage_CloneMetadata@8
_FreeImage_CloseMultiBitmap@8
_FreeImage_ColorQuantize@8
_FreeImage_ConvertToStandardType@8
_FreeImage_DeletePage@8
_FreeImage_Dither@8
_FreeImage_FIFSupportsExportBPP@8
_FreeImage_FIFSupportsExportType@8
_FreeImage_FindNextMetadata@8
_FreeImage_GetBackgroundColor@8
_FreeImage_GetChannel@8
_FreeImage_GetComplexChannel@8
_FreeImage_GetFileType@8
_FreeImage_GetFileTypeFromMemory@8
_FreeImage_GetFileTypeU@8
_FreeImage_GetMetadataCount@8
_FreeImage_GetScanLine@8
_FreeImage_LockPage@8
_FreeImage_MultigridPoissonSolver@8
_FreeImage_OpenMemory@8
_FreeImage_SetBackgroundColor@8
_FreeImage_SetDotsPerMeterX@8
_FreeImage_SetDotsPerMeterY@8
_FreeImage_SetPluginEnabled@8
_FreeImage_SetTagCount@8
_FreeImage_SetTagDescription@8
_FreeImage_SetTagID@8
_FreeImage_SetTagKey@8
_FreeImage_SetTagLength@8
_FreeImage_SetTagType@8
_FreeImage_SetTagValue@8
_FreeImage_SetThumbnail@8
_FreeImage_SetTransparent@8
_FreeImage_SetTransparentIndex@8
_FreeImage_Threshold@8

[ 12 ]
_FreeImage_AcquireMemory@12
_FreeImage_AdjustBrightness@12
_FreeImage_AdjustContrast@12
_FreeImage_AdjustCurve@12
_FreeImage_AdjustGamma@12
_FreeImage_ConvertLine16_555_To16_565@12
_FreeImage_ConvertLine16_565_To16_555@12
_FreeImage_ConvertLine16To24_555@12
_FreeImage_ConvertLine16To24_565@12
_FreeImage_ConvertLine16To32_555@12
_FreeImage_ConvertLine16To32_565@12
_FreeImage_ConvertLine16To4_555@12
_FreeImage_ConvertLine16To4_565@12
_FreeImage_ConvertLine16To8_555@12
_FreeImage_ConvertLine16To8_565@12
_FreeImage_ConvertLine1To4@12
_FreeImage_ConvertLine1To8@12
_FreeImage_ConvertLine24To16_555@12
_FreeImage_ConvertLine24To16_565@12
_FreeImage_ConvertLine24To32@12
_FreeImage_ConvertLine24To4@12
_FreeImage_ConvertLine24To8@12
_FreeImage_ConvertLine32To16_555@12
_FreeImage_ConvertLine32To16_565@12
_FreeImage_ConvertLine32To24@12
_FreeImage_ConvertLine32To4@12
_FreeImage_ConvertLine32To8@12
_FreeImage_ConvertLine4To8@12
_FreeImage_ConvertToType@12
_FreeImage_CreateICCProfile@12
_FreeImage_FillBackground@12
_FreeImage_FindFirstMetadata@12
_FreeImage_GetFileTypeFromHandle@12
_FreeImage_GetHistogram@12
_FreeImage_GetLockedPageNumbers@12
_FreeImage_InsertPage@12
_FreeImage_Load@12
_FreeImage_LoadFromMemory@12
_FreeImage_LoadMultiBitmapFromMemory@12
_FreeImage_LoadU@12
_FreeImage_MakeThumbnail@12
_FreeImage_MovePage@12
_FreeImage_RotateClassic@12
_FreeImage_SeekMemory@12
_FreeImage_SetChannel@12
_FreeImage_SetComplexChannel@12
_FreeImage_SetTransparencyTable@12
_FreeImage_SwapPaletteIndices@12
_FreeImage_TagToString@12
_FreeImage_UnlockPage@12
_FreeImage_ZLibCRC32@12

[ 16 ]
_FreeImage_Composite@16
_FreeImage_ConvertLine1To16_555@16
_FreeImage_ConvertLine1To16_565@16
_FreeImage_ConvertLine1To24@16
_FreeImage_ConvertLine1To32@16
_FreeImage_ConvertLine4To16_555@16
_FreeImage_ConvertLine4To16_565@16
_FreeImage_ConvertLine4To24@16
_FreeImage_ConvertLine4To32@16
_FreeImage_ConvertLine8To16_555@16
_FreeImage_ConvertLine8To16_565@16
_FreeImage_ConvertLine8To24@16
_FreeImage_ConvertLine8To32@16
_FreeImage_ConvertLine8To4@16
_FreeImage_GetMetadata@16
_FreeImage_GetPixelColor@16
_FreeImage_GetPixelIndex@16
_FreeImage_JPEGTransform@16
_FreeImage_JPEGTransformU@16
_FreeImage_LoadFromHandle@16
_FreeImage_LookupSVGColor@16
_FreeImage_LookupX11Color@16
_FreeImage_OpenMultiBitmapFromHandle@16
_FreeImage_ReadMemory@16
_FreeImage_Rescale@16
_FreeImage_Rotate@16
_FreeImage_Save@16
_FreeImage_SaveMultiBitmapToMemory@16
_FreeImage_SaveToMemory@16
_FreeImage_SaveU@16
_FreeImage_SetMetadata@16
_FreeImage_SetPixelColor@16
_FreeImage_SetPixelIndex@16
_FreeImage_SwapColors@16
_FreeImage_WriteMemory@16
_FreeImage_ZLibCompress@16
_FreeImage_ZLibGUnzip@16
_FreeImage_ZLibGZip@16
_FreeImage_ZLibUncompress@16

[ 20 ]
_FreeImage_ApplyPaletteIndexMapping@20
_FreeImage_ColorQuantizeEx@20
_FreeImage_Copy@20
_FreeImage_Paste@20
_FreeImage_RegisterExternalPlugin@20
_FreeImage_RegisterLocalPlugin@20
_FreeImage_SaveMultiBitmapToHandle@20
_FreeImage_SaveToHandle@20
_FreeImage_TmoDrago03@20
_FreeImage_TmoFattal02@20
_FreeImage_TmoReinhard05@20

[ 24 ]
_FreeImage_Allocate@24
_FreeImage_ApplyColorMapping@24
_FreeImage_JPEGCrop@24
_FreeImage_JPEGCropU@24
_FreeImage_OpenMultiBitmap@24
_FreeImage_ToneMapping@24

[ 28 ]
_FreeImage_AllocateHeader@28
_FreeImage_AllocateT@28
_FreeImage_EnlargeCanvas@28

[ 32 ]
_FreeImage_AdjustColors@32
_FreeImage_AllocateHeaderT@32
_FreeImage_ConvertToRawBits@32
_FreeImage_GetAdjustColorsLookupTable@32

[ 36 ]
_FreeImage_AllocateEx@36
_FreeImage_ConvertFromRawBits@36
_FreeImage_TmoReinhard05Ex@36

[ 40 ]
_FreeImage_AllocateExT@40

[ 48 ]
_FreeImage_RotateEx@48

FreeImage_OutputMessageProc

X
« Last Edit: March 12, 2013, 09:44:17 PM by JRS »

Charles Pegge

  • Guest
Re: FreeImage Fun
« Reply #5 on: March 12, 2013, 10:44:17 PM »
Thanks John,

I have ported this api to Oxygen.

It has to be the laziest API port ever  ;D. This version of Oxygen will derive an unmangled name from an alias like so:

! alias _FreeImage_GetCopyrightMessage@0() as char*

invoked with:

FreeImage_GetCopyrightMessage

PS: see latest Oxygen

X
« Last Edit: March 14, 2013, 06:05:07 AM by Charles Pegge »

JRS

  • Guest
Re: FreeImage Fun
« Reply #6 on: March 13, 2013, 07:28:07 AM »
Charles,

Is this a FreeImage DLL only type feature? If I pass any unique part of the function name, will ALIAS find it?


Code: OxygenBasic
  1. include "Freeimage.inc"
  2. sys img,imr,lx,ly,tx,ty,r
  3. img = FreeImage_Load FIF_JPEG,"world.jpg",0
  4. lx  = FreeImage_GetWidth img
  5. ly  = FreeImage_GetHeight img
  6. tx  = lx/2
  7. ty  = ly/2
  8. imr = FreeImage_Rescale img,tx,ty,0
  9. r   = FreeImage_Save FIF_JPEG,imr,"t.jpg",0
  10. print tx " x " ty "  ok"
  11.  

SA (Simple Alias)  8)
« Last Edit: March 13, 2013, 08:26:03 AM by JRS »

Charles Pegge

  • Guest
Re: FreeImage Fun
« Reply #7 on: March 13, 2013, 09:20:53 AM »
I think that is standard gcc/ms name mangling. Easy to add new rules for demangling, if we encounter other species.

PS: 'alias' is currently lowercase, but this will go in the next release and 'Alias' / 'ALIAS' will also work.


JRS

  • Guest
Re: FreeImage Fun
« Reply #8 on: March 13, 2013, 04:57:55 PM »
The DLLC interface is for those only needing a small slice of what FreeImage is capable of. If your going to write a full blown image management application, O2 is the language to do it in. My goal with the DLLC project was to add functionality by scripting APIs.
« Last Edit: March 13, 2013, 06:12:28 PM by JRS »