FreeImage Update for HMG

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

FreeImage Update for HMG

Post by AUGE_OHR »

hi,

i found FreeImage_MakeThumbnail() using FreeImage.
but this Method is not include in
c:\hmg.3.4.4\HARBOUR\contrib\hbfimage\hbfimage.hbx
c:\hmg.3.4.4\HARBOUR\include\hbfimage.hbx
now i have found c:\MiniGUI\SOURCE\hbfimage\

i made a copy and try it with HMG this Way

Code: Select all

..\build hbfimage.hbp
and got

Code: Select all

c:\hmg.3.4.4\HARBOUR\lib\libhbfimage.a 
which is much bigger than

Code: Select all

C:\hmg.3.4.4\HARBOUR\lib\win\mingw\libhbfimage.a
now my Question is how can i use it without override original HMG / MinGW LIB :idea:
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: FreeImage Update for HMG

Post by AUGE_OHR »

hi,

i have work on Freeimage for HMG and create a new LIB
it also include FreeImage_MakeThumbnail()

Sample is "Original" FreeImage Sample from MiniGUI Extendet Version which compile/link with HMG and run without Error. some Option are not include while not avaiable under HMG like DEFINE IMAGELIST

i include LIB but not FreeImage.DLL which is need else App will not start when link LIB
FREEVIEW.ZIP
(163.03 KiB) Downloaded 190 times
---

this is my working Code for Thumbs using FreeImage

Code: Select all

   fname := cPath + aDir[ nCount ] [ 1 ]
   FI_hBitmap1_aux := FREE_Load( FREE_GetFileType( fname, 0 ), fname, 0 )

   IF !EMPTY( FI_hBitmap1_aux )
      clone := FREE_Clone( FI_hBitmap1_aux )
      FREE_Unload( FI_hBitmap1_aux )

      * FI_hBitmap1 := FREE_Rescale( clone, 128, 128, FILTER_BICUBIC )
      FI_hBitmap1 := Free_MakeThumbnail( clone, 128, TRUE )
      FREE_Unload( clone )

      cSaveFile := GetTempFolder() + cFileNoExt( fname ) + ".bmp"
      FREE_Save( FIF_BMP, FI_hBitmap1, cSaveFile, BMP_DEFAULT )
      SetProperty( "THUMBSWIN", cImage, "PICTURE", cSaveFile )
it does "save" Thumbs and "load" it again.

but it is still 2 x faster than BT Function
BT 84,12 / 84,06
FI 41,30 / 40,93
i do save/load to RAMdisk. when use NVM or SSD it is slower but still much faster than BT
i guess, if i can use hBitmap "direct" it will speedup to create Thumbs "on-fly"

---

i was told that FI_hBitmap1 is NOT a hBitmap so i try

Code: Select all

   hBitmap := FREE_WINCONVTODIB(FI_hBitmap1)
   SetProperty( "THUMBSWIN", cImage, "HBITMAP", hBitmap )
and

Code: Select all

   SetProperty( "THUMBSWIN", cImage, "PICTURE", hBitmap )
and

Code: Select all

   Hwnd := GetControlHandle( cImage, "THUMBSWIN" )
   SendMessage(Hwnd, STM_SETIMAGE, IMAGE_BITMAP, hBitmap)
   ReDrawWindow(Hwnd)
which is like

Code: Select all

   BT_HMGSetImage( "THUMBSWIN", cImage, hBitmap )
but still does not show Image :(

need other Idea ... :idea:
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: FreeImage Update for HMG

Post by AUGE_OHR »

hi,

found a Way to "Cache" Thumbs

Code: Select all

   fname := cPath + aDir[ nCount ] [ 1 ]
   cSaveFile := GetTempFolder() + "FI_" +cFileNoExt( fname ) + ".bmp"

   IF FILE(cSaveFile)
      SetProperty( "THUMBSWIN", cImage, "PICTURE", cSaveFile )
   ELSE
      IF SP_lFreeImage() = .T.
         FI_hBitmap1_aux := FREE_Load( FREE_GetFileType( fname, 0 ), fname, 0 )
         clone := FREE_Clone( FI_hBitmap1_aux )
         FREE_Unload( FI_hBitmap1_aux ) 

         FI_hBitmap1 := Free_MakeThumbnail( clone, 128, TRUE )
         FREE_Unload( clone )

         FREE_Save( FIF_BMP, FI_hBitmap1, cSaveFile, BMP_DEFAULT )
         SetProperty( "THUMBSWIN", cImage, "PICTURE", cSaveFile )
         FREE_Unload( FI_hBitmap1 )
       * FERASE( cSaveFile )
i do not delete temporary "FI_" Thumb file so i can use it next time :D
while Thumbs files are only 128x128 it load < 3 Sec where need before > 40 Sec. with FreeImage ( BT > 80 Sec )

---


using FreeImage now is my fastes Way ... but it need FreeImage.DLL else harbour App does not start :o
under Xbase++ i don´t have a (Import) LIB, just call FreeImage.DLL.

Code: Select all

   IF FILE("FREEIMAGE.DLL")
      // use API function
   ELSE
      // use Xbase++ function
   ENDIF
under harbour i have DLL Call in CODE.C where i have use to build a (Import?) LIB

hbfimage.hbp start in HMG Folder

Code: Select all

-hblib
-inc

-o../../harbour/lib/hbfimage

-I.

-hbx=../../include/hbfimage.hbx

-w3 -es2

# For FreeImage headers
-c=gnu90

core.c 
i also need to include CODE.C into my HB_FUNC to call FreeImage API Function ... hm :?

when now start without FreeImage.DLL i get a Error that FreeImage.DLL is missing and hole App quit. :shock:
missing_FreeImage.jpg
missing_FreeImage.jpg (28.15 KiB) Viewed 3736 times
i don`t find Error Message while Debugger does not start (MAIN 1st line ALTD() ) before Error Message ... :evil:
i know that Code like ErrorSys is load before MAIN ... what is load under harbour / HMG :?:

how is the right Way to implement FreeImage when have NO FreeImage.DLL :idea:
i don´t want work 3-PP DLL when it might stop hole App
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: FreeImage Update for HMG

Post by AUGE_OHR »

hi,

i want to use FreeImage.dll without "Import" LIB.

under Xbase++ using ot4xb i have

Code: Select all

//proto freeimage.dll
#define OT4XB_ASSERT_ALL
#include "ot4xb.ch"
#include "freeimage.ch"
#PRAGMA LIBRARY( "ot4xb.LIB" )

//DLL_API void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE));
 DLL FreeImage IMPORT VOID FreeImage_Initialise( BOOL bLocalPOnly ) SYMBOL "_FreeImage_Initialise@4"

//DLL_API void DLL_CALLCONV FreeImage_DeInitialise(void);
  DLL FreeImage IMPORT VOID FreeImage_DeInitialize( ) SYMBOL  "_FreeImage_DeInitialise@0"

//DLL_API const char *DLL_CALLCONV FreeImage_GetVersion(void);
  DLL FreeImage IMPORT ZSTRING  FreeImage_GetVersion() SYMBOL  "_FreeImage_GetVersion@0"

Code: Select all

PROCEDURE MAIN

 ? "Initialise"

FreeImage_Initialise(.t.)

 ? "Version          :", freeImage_GetVersion()
 ? "Copyright        :", freeImage_GetCopyrightMessage()
 ? "File type        :", freeImage_GetFileType( "proglogo.jpg" )

 nDll := freeImage_Load( FREE_IMAGE_FORMAT.FIF_JPEG, "proglogo.jpg", JPEG_DEFAULT )
here Xbase++ Source
Profreeimage.zip
(13.68 KiB) Downloaded 180 times
---
under harbour i have CORE.C (rename to FREECORE.C )

Code: Select all

[code]
HB_FUNC( FREE_INITIALISE )
{
	FreeImage_Initialise( hb_fi_parl( 1 ) /* load_local_plugins_only */ );
}

HB_FUNC( FREE_DEINITIALISE )
{
	FreeImage_DeInitialise();
}

HB_FUNC( FREE_GETVERSION )
{
	hb_retc( FreeImage_GetVersion() );
}
HB_FUNC seems me same but how to use it without "Import" LIB :idea:
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: FreeImage Update for HMG

Post by AUGE_OHR »

hi,

Fivewin CLASS TImage use FreeImage

Code: Select all

DLL32 FUNCTION FISAVE( nFormat AS LONG, hDib AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS BOOL ;
      PASCAL FROM If( IsExe64(), "FreeImage_Save", "_FreeImage_Save@16" ) LIB hLib

---

DLL32 FUNCTION Shell_NotifyIcon( nMsg AS LONG, pNID AS LPSTR ) AS BOOL PASCAL ;
                                 FROM "Shell_NotifyIconA" LIB "shell32.dll"

//------------------------------------------------------------------------//

DLL32 FUNCTION CopyFile( cExFile AS LPSTR, cNewFile AS LPSTR, lFailIfEx AS LONG );
   AS BOOL PASCAL FROM "CopyFileA" LIB "Kernel32.dll"

//------------------------------------------------------------------------//

DLL32 FUNCTION OutputDebugString( cOutputStr AS LPSTR ) AS VOID PASCAL ;
      FROM "OutputDebugStringA" Lib "kernel32.dll"
how to convert Syntax to HMG_CallDLL() :idea:
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: FreeImage Update for HMG

Post by AUGE_OHR »

hi,

still try to load freeimage.dll direct but have Problem to understand how go on

Code: Select all

STATIC hDLL := 0
FUNCTION FREE_INITIALISE()
   hDLL := HMG_CallDLL( "Kernel32.dll", DLL_OSAPI, "LoadLibrary", "FreeImage.dll")
   nStart := HMG_CallDLL( "Kernel32.dll", DLL_OSAPI, "GetProcAddress", hDLL, "_FreeImage_Initialise@4")
   /// next ???   
i can "LoadLibrary" FreeImage.dll and "GetProcAddress" but what next

other Sample

Code: Select all

FUNCTION FREE_GetVersion()
LOCAL nRet , nStart, cBuffer := SPACE(32)
   nStart := HMG_CallDLL( "Kernel32.dll", DLL_OSAPI, "GetProcAddress", hDLL, "_FreeImage_GetVersion@0")
   // next ??    
   nRet := HMG_CallDLL( hDLL,, nStart, @cBuffer )
   nRet := HMG_CallDLL( nStart,,hDLL, @cBuffer )   
it does not work :(
need some help please
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: FreeImage Update for HMG

Post by danielmaximiliano »

Hola Jimmy: la mayoría de los amigos que estamos en HMG no somos programadores hábiles/no sabemos "C" .
Por este motivo casi no obtienes repuestas a tus publicsciones.
Hace un tiempo tuve problemas con una dll la cual tuve que exportar sus funciones a una lib.a para poder usarla, en ese tiempo leí este link para empaparme sobre loadlibrary.

Hi Jimmy:
Most of us friends at HMG are not skilled programmers / we don't know "C".
For this reason, you hardly get responses to your advertisements.
A while ago I had problems with a dll which I had to export its functions to a lib.a to be able to use it, at that time I read this link to get soaked about loadlibrary


https://docs.microsoft.com/en-us/cpp/bu ... ew=vs-2019
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: FreeImage Update for HMG

Post by danielmaximiliano »

AUGE_OHR wrote: Thu Jul 02, 2020 10:47 pm
i want to use FreeImage.dll without "Import" LIB.
Hola Jimmy : descargue Freeimage source y Freeimage.dll desde https://freeimage.sourceforge.io/download.html
compile y ejecute su demo sin ningun inconveniente.

Hi Jimmy: Download Freeimage source and Freeimage.dll from https://freeimage.sourceforge.io/download.html
compile and run your demo without any hassle.
2020-07-05 20_42_34-Window.png
2020-07-05 20_42_34-Window.png (17.44 KiB) Viewed 3307 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: FreeImage Update for HMG

Post by AUGE_OHR »

hi,

i do have FreeImage running so that is not the Problem.

i have to build Import"-LIB" LibFreeImage.a from Core.C
i need FreeImage.DLL else APP does not start.

---

under Xbase++ i can "load" FreeImage.DLL "on-fly"
when missing FreeImage.DLL my APP still run

thats why i try to "load" FreeImage.DLL, get ProcAdress and use

Code: Select all

   FpQCall( {"freeimage","_FreeImage_GetPalette@4"},qt,ndib )
FpQCall() is like DllCall ( HMG_CallDLL() ) but i can´t figure out how it work with harbour / HMG :(
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: FreeImage Update for HMG

Post by AUGE_OHR »

from Petzold "Windows-Programming"

this will work when include "Import-LIB" GDI32.LIB

Code: Select all

   Rectangle(hdc,xLeft,yTop,xRight,yBottom) ;
---

this is how to use without LIB just DLL

Code: Select all

typedef BOOL ) WINAPI * PFNRECT) (HDC,int,int,int,int) ;

HANDLE hLibrary ;
PRNRECT pfnRectangle ;

   hLibrary = Loadlibrary(TEXT("GDI32.DLL"))
   pfnRectangle = (PFNRECT) GetProcAdress( hLibrary, TEXT("Rectangle"))
now this Code should work

Code: Select all

   pfnRectangle(hdc,xLeft,yTop,xRight,yBottom) ;
   FreeLibrary(hLibrary) ;
so i have to re-write FreeImage Code.C ... hm :roll:
have fun
Jimmy
Post Reply