Page 1 of 1

GIF animado

PostPosted: Sat Sep 20, 2008 2:26 am
by Armando Picon
Amigos

En un ejemplo que colocó Antonio indicaba que para hacer que funcionara un GIF animado se ejecutaba una función llamada CreateGIF(). Alguién tiene ese código para compartir?

Gracias por adelantado.

Armando

Re: GIF animado

PostPosted: Sat Sep 20, 2008 3:38 am
by FranciscoA
Armando Picon wrote:Amigos

En un ejemplo que colocó Antonio indicaba que para hacer que funcionara un GIF animado se ejecutaba una función llamada CreateGIF(). Alguién tiene ese código para compartir?

Gracias por adelantado.

Armando



Armando, ¿ya revisaste Win32.prg en samples?

Saludos.
FranciscoA.

PostPosted: Sat Sep 20, 2008 9:12 am
by Antonio Linares
Armando,

Este es el código que usamos como punto de partida:

https://xbmc.svn.sourceforge.net/svnroo ... tedGif.cpp

PostPosted: Sat Sep 20, 2008 2:13 pm
by Rossine
Antonio,

Ao compilar o exemplo \fwh\samples\testgif.prg me é gerado o erro abaixo:

Code: Select all  Expand view
xLINK: error: Unresolved external symbol '_HB_FUN_CREATEGIF'.
xLINK: error: Unresolved external symbol '_HB_FUN_GIFHWND'.
xLINK: fatal error: 2 unresolved external(s).


Qual arquivo devo incluir na compilação para corrgir estes erros ?

Obrigado,

Rossine.

PostPosted: Sat Sep 20, 2008 3:17 pm
by Antonio Linares
Rossine,

The current code (C++) that we are using only compiles fine with Borland.

We have to modify it to get compiled with Microsoft and gcc. It fails with those compilers.

Our plan is to convert it into standard C code.

PostPosted: Sat Sep 20, 2008 4:27 pm
by Armando Picon
Antonio Linares wrote:Armando,

Este es el código que usamos como punto de partida:

https://xbmc.svn.sourceforge.net/svnroo ... tedGif.cpp


Bajé el codigo y lo estoy revisando... aunque una primera mirada no indica la presencia de CreateGIF(). De todas maneras se agradece...

PostPosted: Sun Sep 21, 2008 8:32 am
by Antonio Linares
Armando,

El problema es que ese código está en C++ y no es compatible con todos los compiladores de C++ ni con distintas versiones.

Lo mejor que podemos hacer es pasarlo de C++ a C y asi lo compatibilizamos para cualquier compilador C.

La forma de hacerlo es fácil, ya que un objeto en C++ no es sino un conjunto de datos que tiene unos comportamientos asociados, por lo que podemos pasar de Class a struct y manejar la estructura con una serie de funciones. Asi es como funcionan los RDDs de Clipper/[x]Harbour ó el sistema GT de gestión de pantalla.

En el siguiente mensaje pongo un ejemplo de como hacerlo. Finalmente añadiremos la función CreateGif(), etc.

PostPosted: Sun Sep 21, 2008 9:17 am
by Antonio Linares
En anigif.h se declaran tres classes: C_Image, C_ImageSet y C_AnimationWindow.

Pasemos la primera de C++ a C. Aqui está la definición de la clase:
Code: Select all  Expand view
class C_Image {
public:
   // standard members:
   int Width, Height;         // Dimensions in pixels
   int BPP;               // Bits Per Pixel   
   char * Raster;            // Bits of Raster Data (Byte Aligned)
   COLOR * Palette;         // Color Map
   int BytesPerRow;         // Width (in bytes) including alignment!
   int Transparent;         // Index of Transparent color (-1 for none)
   // Extra members for animations:
   int xPos, yPos;            // Relative Position
   int Delay;               // Delay after image in 1/1000 seconds.
   int Transparency;         // Animation Transparency.
   // Windows GDI specific:
   BITMAPINFO * pbmi;         // BITMAPINFO structure

   // constructor and destructor:
   C_Image() { Raster=0; Palette=0; pbmi=0; }
   ~C_Image() { delete[]pbmi; delete[]Raster; }

   // operator= (object copy)
   C_Image& operator= (C_Image& rhs);

   // Image initializer (allocates space for raster and palette):
   void Init (int iWidth, int iHeight, int iBPP);

   inline char& Pixel (const int& x, const int& y)
      {return Raster[y*BytesPerRow+x];}

   // Windows GDI Specific function to paint the image on a DC:
   int GDIPaint (HDC hdc, int xDest, int yDest);

   // File Formats:
   int LoadBMP (char* szFile);
   int SaveBMP (char* szFile);
};

Ahora la pasamos a una estructura:
Code: Select all  Expand view
typedef struct
{
   int Width, Height;         // Dimensions in pixels
   int BPP;               // Bits Per Pixel   
   char * Raster;            // Bits of Raster Data (Byte Aligned)
   COLOR * Palette;         // Color Map
   int BytesPerRow;         // Width (in bytes) including alignment!
   int Transparent;         // Index of Transparent color (-1 for none)
   // Extra members for animations:
   int xPos, yPos;            // Relative Position
   int Delay;               // Delay after image in 1/1000 seconds.
   int Transparency;         // Animation Transparency.
   // Windows GDI specific:
   BITMAPINFO * pbmi;         // BITMAPINFO structure
} CIMAGE, * PCIMAGE;

Y sus métodos los convertimos en funciones:
Code: Select all  Expand view
PCIMAGE CImageNew( void )
{
   PCIMAGE pCImage = ( PCIMAGE ) hb_xgrab( sizeof( CIMAGE ) );

   pCImage->Raster = 0;
   pCImage->Palette = 0;
   pCImage->pbmi    = 0;

   return pCImage;
}

Code: Select all  Expand view
void CImageDestroy( PCIMAGE pCImage )
{
   if( pCImage->pbmi )
   {
      hb_xfree( ( void * ) pCImage->pbmi );   
      pCImage->pbmi = 0;
   }

   if( pCImage->Raster )
   {
      hb_xfree( ( void * ) pCImage->Raster );   
      pCImage->Raster = 0;
   }
}

Code: Select all  Expand view
void CImageAssign( PCIMAGE pCImage, PCIMAGE pCAnotherImage )
{
   memcpy( ( void * ) pCImage, ( void * ) pCAnotherImage, sizeof( CIMAGE ) );
}

Code: Select all  Expand view
char CImagePixel( PCIMAGE pCImage, int x, int y )
{
   return PCImage->Raster[ y * pCImage->BytesPerRow + x ];
}

Estos son los métodos que estan definidos en la propia cabecera de la clase, ahora faltan los que estan en el fichero cpp.

Alguien se anima y asi practica su programación en C ? :-)

PostPosted: Sun Sep 21, 2008 9:36 am
by Antonio Linares
Los juntamos en un fichero anigif.c y probamos a compilarlo con distintos compiladores de C y compilan bien todos :-)

c:\mingw\bin\gcc -c -Ic:\mingw\include -Ic:\harbour\include anigif.c

c:\bcc55\bin\bcc32 -c -Ic:\bcc55\include -Ic:\harbour\include anigif.c

c:\vc98\bin\cl.exe -c -Ic:\vc98\include -Ic:\harbour\harbour anigif.c

Es solo el comienzo. Alguien se anima ? Venga! :-)

anigif.c
Code: Select all  Expand view
#include <hbapi.h>
#include <windows.h>

typedef struct
{
   unsigned char b, g, r, x;
} COLOR;

typedef struct
{
   int Width, Height;       // Dimensions in pixels
   int BPP;                 // Bits Per Pixel   
   char * Raster;           // Bits of Raster Data (Byte Aligned)
   COLOR * Palette;         // Color Map
   int BytesPerRow;         // Width (in bytes) including alignment!
   int Transparent;         // Index of Transparent color (-1 for none)
   // Extra members for animations:
   int xPos, yPos;          // Relative Position
   int Delay;               // Delay after image in 1/1000 seconds.
   int Transparency;        // Animation Transparency.
   // Windows GDI specific:
   BITMAPINFO * pbmi;       // BITMAPINFO structure
} CIMAGE, * PCIMAGE;

PCIMAGE CImageNew( void )
{
   PCIMAGE pCImage = ( PCIMAGE ) hb_xgrab( sizeof( CIMAGE ) );

   pCImage->Raster = 0;
   pCImage->Palette = 0;
   pCImage->pbmi    = 0;

   return pCImage;
}

void CImageDestroy( PCIMAGE pCImage )
{
   if( pCImage->pbmi )
   {
      hb_xfree( ( void * ) pCImage->pbmi );   
      pCImage->pbmi = 0;
   }

   if( pCImage->Raster )
   {
      hb_xfree( ( void * ) pCImage->Raster );   
      pCImage->Raster = 0;
   }
}

void CImageAssign( PCIMAGE pCImage, PCIMAGE pCAnotherImage )
{
   memcpy( ( void * ) pCImage, ( void * ) pCAnotherImage, sizeof( CIMAGE ) );
}

char CImagePixel( PCIMAGE pCImage, int x, int y )
{
   return pCImage->Raster[ y * pCImage->BytesPerRow + x ];
}

PostPosted: Sun Sep 21, 2008 12:43 pm
by Ruben D. Fernandez
Antonio:

Solo para informacion:
Este código tambien compila bien con BS2006

Saludos

Ruben Fernandez

PostPosted: Sun Sep 21, 2008 10:13 pm
by Armando Picon
Gracias Antonio...

Con el Codigo que indicaste estuve haciendo algunas pruebas para MinGW, sin éxito. Ahora con tu ejemplo voy a probar si puedo construirlo utilizando el Visual MinGW.

Gracias nuevamente

Armando