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 ?
![Smile :-)](./images/smilies/icon_smile.gif)