Newsgroup: it.comp.lang.vo-clipper
Titolo: FreeImage

Salve a tutti.
Sto cercando di estendere una classe che ho scaricato da internet tempo fa
per effetture la rotazione di una bitmap. La classe si basa sulla libreria
open source freeimage.
Non riesco a far funzionare in nessun modo il metodo rotate potreste darmi
un aiuto?
Vi allego il codice
------------------------------------------------------------------
#include "FiveWin.ch"
#include "Constant.ch"
#include "Inkey.ch"
#define GW_CHILD       5
#define GW_HWNDNEXT    2
#define RT_BITMAP      2
#define CBM_INIT       4
#define DIB_RGB_COLORS 0
#define MB_ICONEXCLAMATION 48
#ifdef __XPP__
   #define New        _New
   #define Super      ::TBitmap
#endif
STATIC hLib
//----------------------------------------------------------------------------//
CLASS TImageEx FROM TBitmap
   DATA nProgress
   DATA hDib
   CLASSDATA lRegistered AS LOGICAL
   METHOD New( nTop, nLeft, nWidth, nHeight, cResName, cBmpFile,
lNoBorder,;
               oWnd, bLClicked, bRClicked, lScroll, lStretch, oCursor,;
               cMsg, lUpdate, bWhen, lPixel, bValid, lDesign ) CONSTRUCTOR
   METHOD Define( cResName, cBmpFile, oWnd ) CONSTRUCTOR
   METHOD LoadImage( cResName, cBmpFile )
   METHOD Progress( lProgress )
   METHOD ROTATE( Angle )
ENDCLASS
METHOD New( nTop, nLeft, nWidth, nHeight, cResName, cBmpFile, lNoBorder,;
            oWnd, bLClicked, bRClicked, lScroll, lStretch, oCursor,;
            cMsg, lUpdate, bWhen, lPixel, bValid, lDesign ) CLASS TImageEx
   #ifdef __XPP__
      ::lRegistered = .f.
   #endif
   ::nProgress = 1
   Super:New( nTop, nLeft, nWidth, nHeight, cResName, cBmpFile, lNoBorder,
;
              oWnd, bLClicked, bRClicked, lScroll, lStretch, oCursor,     
;
              cMsg, lUpdate, bWhen, lPixel, bValid, lDesign )
return Self
//----------------------------------------------------------------------------//
// This method does not create a control, it just creates a bitmap object
to
// be used somewhere else.
METHOD Rotate( Angle ) CLASS TImageEx
   local hrotate, ncolori, hInfoH, hInfo, hBits, hDC
   local hOldBmp  := ::hBitmap
   local hOldPal  := ::hPalette
   ncolori:=FIGETBPP(::HDib)
   hrotate := firotate(::hdib,Angle)
   fiunload(::hdib)
   ::hDib:=hrotate
   hInfoH  := fiGetInfoHeader(::hDib )
   hInfo   := fiGetInfo(::hDib )
   hBits   := fiGetBits(::hDib )
   hDC     := GetDC32( 0 )
   /*oWnd:GetDC()*/
   ::hBitmap :=CreateDIBitmap( hDC, hInfoH, CBM_INIT, hBits, hInfo,
DIB_RGB_COLORS )
   ReleaseDC32( 0, hDC )
   // oWnd:releaseDC()
   if ! Empty( hOldBmp )
      PalBmpFree( hOldBmp, hOldPal )
   endif
   PalBmpNew( ::hWnd, ::hBitmap, ::hPalette )
RETURN self
METHOD Define( cResName, cBmpFile, oWnd ) CLASS TImageEx
   local aBmpPal, nFormat, hInfoH, hInfo, hBits, hDC
   DEFAULT oWnd := GetWndDefault()
   ::oWnd     = oWnd
   ::nZoom    = 1
   ::hWnd     = 0
   ::hBitmap  = 0
   ::hPalette = 0
   hLib := LoadLibrary( "freeimage.dll" )
   if hLib <= 32
      MsgStop( "Cannot load Freeimage.dll" )
      return 0
   endif
   if ! Empty( cResName )
      aBmpPal    = PalBmpLoad( cResName )
      ::hBitmap  = aBmpPal[ 1 ]
      ::hPalette = aBmpPal[ 2 ]
      cBmpFile  = nil
   endif
   if ! Empty( cBmpFile ) .and. File( cBmpFile )
      ::cBmpFile = cBmpFile
      nFormat := fiGetFileType( ::cBmpFile, 0 )
      ::hDib    := fiLoad( nFormat, ::cBmpFile, 0 )
      hInfoH  := fiGetInfoHeader(::hDib )
      hInfo   := fiGetInfo(::hDib )
      hBits   := fiGetBits(::hDib )
      hDC     := GetDC32( 0 )
      /*oWnd:GetDC()*/
      ::hBitmap :=CreateDIBitmap( hDC, hInfoH, CBM_INIT, hBits, hInfo,
DIB_RGB_COLORS )
      ReleaseDC32( 0, hDC )
      // oWnd:releaseDC()
   endif
   if ::hBitmap != 0
      PalBmpNew( 0, ::hBitmap, ::hPalette )
   endif
return Self
//----------------------------------------------------------------------------//
METHOD LoadImage( cResName, cBmpFile ) CLASS TImageEx
   local lChanged := .f.
   local hOldBmp  := ::hBitmap
   local hOldPal  := ::hPalette
   local aBmpPal, nFormat, hInfoH, hInfo, hBits, hWnd, hDC
   DEFAULT cResName := ::cResName, cBmpFile := ::cBmpFile
   if ! Empty( cResName )
      aBmpPal    = PalBmpLoad( cResName )
      ::hBitmap  = aBmpPal[ 1 ]
      ::hPalette = aBmpPal[ 2 ]
      lChanged   = .t.
      cBmpFile   = nil
   elseif File( cBmpFile )
      ::cBmpFile = cBmpFile
      nFormat := fiGetFileType( ::cBmpFile, 0 )
      ::hDib    := fiLoad( nFormat, ::cBmpFile, 0 )
      hInfoH  := fiGetInfoHeader(::hDib )
      hInfo   := fiGetInfo(::hDib )
      hBits   := fiGetBits(::hDib )
      hDC     := GetDC32( 0 )
      /*oWnd:GetDC()*/
      ::hBitmap :=CreateDIBitmap( hDC, hInfoH, CBM_INIT, hBits, hInfo,
DIB_RGB_COLORS )
      ReleaseDC32( 0, hDC )
      // oWnd:releaseDC()
      lChanged  := .t.
      cResName  := nil
   endif
   if lChanged
      ::cResName = cResName
      ::cBmpFile = cBmpFile
      if ! Empty( hOldBmp )
         PalBmpFree( hOldBmp, hOldPal )
      endif
      PalBmpNew( ::hWnd, ::hBitmap, ::hPalette )
   endif
return lChanged
//----------------------------------------------------------------------------//
METHOD Progress( lProgress ) CLASS TImageEx
   if ValType( lProgress ) == "L"
      if lProgress
         ::nProgress = 1
      else
         ::nProgress = 0
      endif
   endif
return nil
//----------------------------------------------------------------------------//
DLL32 STATIC FUNCTION FIGETFILETYPE( cFileName AS LPSTR, nSize AS LONG )AS
LONG;
PASCAL FROM "_FreeImage_GetFileType@8" LIB hLib
DLL32 STATIC FUNCTION FILOAD( nFormat AS LONG, cFileName AS LPSTR,nFlags
AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_Load@12" LIB hLib
DLL32 STATIC FUNCTION FIGETBPP( hDib AS LONG ) AS _INT;
PASCAL FROM "_FreeImage_GetBPP@4" LIB hLib
DLL32 STATIC FUNCTION FIUNLOAD( hDib AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_Unload@4" LIB hLib
DLL32 STATIC FUNCTION FIGETINFOHEADER( hDib AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_GetInfoHeader@4" LIB hLib
DLL32 STATIC FUNCTION FIGETINFO( hDib AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_GetInfo@4" LIB hLib
DLL32 STATIC FUNCTION FIGETBITS( hDib AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_GetBits@4" LIB hLib
DLL32 STATIC FUNCTION FIGETWIDTH( hDib AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_GetWidth@4" LIB hLib
DLL32 STATIC FUNCTION FIGETHEIGHT( hDib AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_GetHeight@4" LIB hLib
DLL32 STATIC FUNCTION FISAVE( nFormat AS LONG, hDib AS LONG, cFileName AS
LPSTR, nFlags AS LONG ) AS BOOL;
PASCAL FROM "_FreeImage_Save@16" LIB hLib
DLL32 STATIC FUNCTION FIROTATE( hDib AS LONG, ANGLE AS LONG ) AS LONG;
PASCAL FROM "_FreeImage_RotateClassic@12" LIB hLib
DLL32 STATIC FUNCTION FIROTATEEX( hDib AS LONG, ANGLE AS LONG, X_SHIFT AS
LONG, Y_SHIFT AS LONG, XR AS LONG, YR AS LONG, MASK AS BOOL ) AS LONG;
PASCAL FROM "_FreeImage_RotateEx@48" LIB hLib
DLL32 STATIC FUNCTION GETDSKTP32( hWnd AS LONG ) AS LONG;
PASCAL FROM "GetDesktopWindow" LIB "user32.dll"
DLL32 STATIC FUNCTION GETDC32( hWnd AS LONG ) AS LONG;
PASCAL FROM "GetDC" LIB "user32.dll"
DLL32 STATIC FUNCTION RELEASEDC32( hWnd AS LONG ) AS LONG;
PASCAL FROM "ReleaseDC" LIB "user32.dll"
DLL32 STATIC FUNCTION CREATEDIBITMAP( hDC AS LONG, hInfoH AS LONG,nFlags
AS LONG, hBits AS LONG, hInfo AS LONG, nUsage AS LONG ) AS LONG;
PASCAL FROM "CreateDIBitmap" LIB "gdi32.dll"
-------------------------------------------------------
Messaggio inviato da 
http://www.sandlab.org/newsgroup/
Accesso gratuito via web ai Newsgroup

 un aiuto?
Questo č un esempio funzionante:
#include "Fivewin.ch"
STATIC hLib
FUNCTION MAIN()
    LOCAL oWnd, hBmp
    DEFINE WINDOW oWnd
    hBmp = FILOADIMG( "SFONDO.JPG", 90 )
    ACTIVATE WINDOW oWnd;
             ON PAINT SFONDO( oWnd, hDC, hBmp );
             MAXIMIZED
    IF hBmp != 0; DELETEOBJECT( hBmp ); ENDIF
    RETURN NIL
STATIC FUNCTION SFONDO( oWnd, hDC, hBmp )
    LOCAL nTop    := ( oWnd:nHeight() - NBMPHEIGHT( hBmp ) ) / 2
    LOCAL nLeft   := ( oWnd:nWidth() - NBMPWIDTH( hBmp ) ) / 2
    LOCAL nWidth  := NBMPWIDTH( hBmp )
    LOCAL nHeight := NBMPHEIGHT( hBmp )
    IF hBmp = 0; RETURN NIL; ENDIF
    PALBMPDRAW( hDC, nTop, nLeft, hBmp, , nWidth, nHeight )
    RETURN NIL
#define CBM_INIT 4
#define DIB_RGB_COLORS 0
FUNCTION FILOADIMG( cFile, nAngle )
    LOCAL nFormat, hDib, hDibR, hInfoH, hInfo, hBits, hWnd, hDC, hBmp
    DEFAULT nAngle := 0
    IF UPPER( CFILEEXT( cFile ) ) = "BMP"
        RETURN READBITMAP( 0, cFile )
    ENDIF
#ifdef __CLIPPER__
    hLib = LOADLIB32( "freeimage.dll" )
#else
    hLib = LOADLIBRARY( "freeimage.dll" )
#endif
    if hLib <= 32
        MsgStop( "Cannot load FreeImage.dll" )
        return 0
    endif
    nFormat = FIGETFILETYPE( cFile, 0 )
    hDib    = FILOAD( nFormat, cFile, 0 )
    hDibR   = FIROTATE( hDib, nAngle )
    hInfoH  = FIGETINFOHEADER( hDibR )
    hInfo   = FIGETINFO( hDibR )
    hBits   = FIGETBITS( hDibR )
    hWnd    = GETDESKTOPWINDOW()
#ifdef __CLIPPER__
    hDC = GETDC32( hWnd )
#else
    hDC = GETDC( hWnd )
#endif
    hBmp = CREATEDIBITMAP( hDC, hInfoH, CBM_INIT, hBits, hInfo, 
DIB_RGB_COLORS )
#ifdef __CLIPPER__
    RELEASEDC32( hWnd, hDC )
#else
    RELEASEDC( hWnd, hDC )
#endif
    FIUNLOAD( hDib )
    FIUNLOAD( hDibR )
#ifdef __CLIPPER__
    FREELIB32( hLib )
#else
    FREELIBRARY( hLib )
#endif
#ifdef __CLIPPER__
    hBmp = NLOWORD( WOWHANDLE16( hBmp, 8 ) )
#endif
    RETURN hBmp
DLL32 STATIC FUNCTION FIGETFILETYPE( cFileName AS LPSTR, nSize AS LONG ) AS 
LONG;
      PASCAL FROM "_FreeImage_GetFileType@8" LIB hLib
DLL32 STATIC FUNCTION FILOAD( nFormat AS LONG, cFileName AS LPSTR, nFlags AS 
LONG ) AS LONG;
      PASCAL FROM "_FreeImage_Load@12" LIB hLib
DLL32 STATIC FUNCTION FIUNLOAD( hDib AS LONG ) AS VOID;
      PASCAL FROM "_FreeImage_Unload@4" LIB hLib
DLL32 STATIC FUNCTION FIGETINFOHEADER( hDib AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_GetInfoHeader@4" LIB hLib
DLL32 STATIC FUNCTION FIGETINFO( hDib AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_GetInfo@4" LIB hLib
DLL32 STATIC FUNCTION FIGETBITS( hDib AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_GetBits@4" LIB hLib
DLL32 STATIC FUNCTION FIROTATE( hDib AS LONG, nAngle AS _DOUBLE ) AS LONG;
      PASCAL FROM "_FreeImage_RotateClassic@12" LIB hLib
DLL32 STATIC FUNCTION GETDC32( hWnd AS LONG ) AS LONG;
      PASCAL FROM "GetDC" LIB "user32.dll"
DLL32 STATIC FUNCTION RELEASEDC32( hWnd AS LONG ) AS LONG;
      PASCAL FROM "ReleaseDC" LIB "user32.dll"
DLL32 STATIC FUNCTION CREATEDIBITMAP( hDC AS LONG, hInfoH AS LONG, nFlags AS 
LONG, hBits AS LONG, hInfo AS LONG, nUsage AS LONG ) AS LONG;
      PASCAL FROM "CreateDIBitmap" LIB "gdi32.dll"
DLL32 FUNCTION WOWHANDLE16( nHandle AS LONG, nHandleType AS LONG ) AS LONG;
      PASCAL FROM "WOWHandle16" LIB "wow32.dll"
EMG
--
EMAG Software Homepage:     
http://www.emagsoftware.it
The EMG's ZX-Spectrum Page: 
http://www.emagsoftware.it/spectrum
The Best of Spectrum Games: 
http://www.emagsoftware.it/tbosg
The EMG Music page:         
http://www.emagsoftware.it/emgmusic
 

 EMG

Grazie, Enrico Maria Giordano ho colto l'occasione anche per dare
un'occhiata ai tuoi link e ne hai fatta di roba!. Il tuo esempio funziona
alla grande e soprattutto mi ha dato modo di risolvere il problema
passando alla funzione freeimage rotate il parametro <Angle> non come
LONG, da me erroneamente utilizzato, bensě come _DOUBLE come dal tuo
esempio. Adesso sicuramente avro' problemi con la funzione Rescale sempre
della freeimage con il parametro FREE_IMAGE_FILTER di tipo filter. Sai
dirmi qualcosa a riguardo!, grazie.
Alla prossima.
Emanuele Gammone


 dirmi qualcosa a riguardo!, grazie.
E' un parametro numerico che indica il tipo di filtro utilizzato. Dalla 
documentazione:
Public Enum FREE_IMAGE_FILTER
   FILTER_BOX = 0            ' Box, pulse, Fourier window, 1st order 
(constant) b-spline
   FILTER_BICUBIC = 1        ' Mitchell & Netravali's two-param cubic filter
   FILTER_BILINEAR = 2       ' Bilinear filter
   FILTER_BSPLINE = 3        ' 4th order (cubic) b-spline
   FILTER_CATMULLROM = 4     ' Catmull-Rom spline, Overhauser spline
   FILTER_LANCZOS3 = 5       ' Lanczos3 filter
End Enum


 EMG
OK anche questa č fatta. Il parametro in effetti č di tipo numerico e
funziona benissimo (fra l'altro accetta qualsiasi formato numerico, _INT
ovviamente mi sembra il piů appropriato).
Grazie EG


 Grazie EG
Di niente. Sono contento che hai risolto.
