source clean-up
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4895 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
036bc7d9e1
commit
e4b8154a65
@ -23,8 +23,38 @@
|
||||
#include "wx/image.h"
|
||||
|
||||
|
||||
typedef struct _IMAGEN
|
||||
// --------------------------------------------------------------------------
|
||||
// constants
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// disposal method
|
||||
enum
|
||||
{
|
||||
wxGIF_D_UNSPECIFIED = -1, /* not specified */
|
||||
wxGIF_D_DONOTDISPOSE = 0, /* do not dispose */
|
||||
wxGIF_D_TOBACKGROUND = 1, /* restore to background colour */
|
||||
wxGIF_D_TOPREVIOUS = 2 /* restore to previous image */
|
||||
};
|
||||
|
||||
// error codes
|
||||
enum
|
||||
{
|
||||
wxGIF_OK = 0, /* everything was OK */
|
||||
wxGIF_INVFORMAT = 1, /* error in gif header */
|
||||
wxGIF_MEMERR = 2 /* error allocating memory */
|
||||
};
|
||||
|
||||
#define MAX_BLOCK_SIZE 256 /* max. block size */
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxGIFDecoder class
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// internal class for storing GIF image data
|
||||
class GIFImage
|
||||
{
|
||||
public:
|
||||
unsigned int w; /* width */
|
||||
unsigned int h; /* height */
|
||||
unsigned int left; /* x coord (in logical screen) */
|
||||
@ -34,64 +64,42 @@ typedef struct _IMAGEN
|
||||
long delay; /* delay in ms (-1 = unused) */
|
||||
unsigned char *p; /* bitmap */
|
||||
unsigned char *pal; /* palette */
|
||||
struct _IMAGEN *next; /* next image */
|
||||
struct _IMAGEN *prev; /* prev image */
|
||||
} IMAGEN;
|
||||
GIFImage *next; /* next image */
|
||||
GIFImage *prev; /* prev image */
|
||||
};
|
||||
|
||||
|
||||
/* disposal method */
|
||||
#define D_UNSPECIFIED -1 /* not specified */
|
||||
#define D_DONOTDISPOSE 0 /* do not dispose */
|
||||
#define D_TOBACKGROUND 1 /* restore to background colour */
|
||||
#define D_TOPREVIOUS 2 /* restore to previous image */
|
||||
|
||||
/* error codes */
|
||||
#define E_OK 0 /* everything was OK */
|
||||
#define E_FORMATO 1 /* error in gif header */
|
||||
#define E_MEMORIA 2 /* error allocating memory */
|
||||
|
||||
#define MAX_BLOCK_SIZE 256 /* max. block size */
|
||||
|
||||
class WXDLLEXPORT wxGIFDecoder
|
||||
{
|
||||
private:
|
||||
/* logical screen */
|
||||
// logical screen
|
||||
unsigned int m_screenw; /* logical screen width */
|
||||
unsigned int m_screenh; /* logical screen height */
|
||||
int m_background; /* background color (-1 = none) */
|
||||
|
||||
/* image data */
|
||||
// image data
|
||||
bool m_anim; /* animated GIF */
|
||||
int m_nimages; /* number of images */
|
||||
int m_image; /* current image */
|
||||
IMAGEN *m_pimage; /* pointer to current image */
|
||||
IMAGEN *m_pfirst; /* pointer to first image */
|
||||
IMAGEN *m_plast; /* pointer to last image */
|
||||
GIFImage *m_pimage; /* pointer to current image */
|
||||
GIFImage *m_pfirst; /* pointer to first image */
|
||||
GIFImage *m_plast; /* pointer to last image */
|
||||
|
||||
/* decoder state vars */
|
||||
// decoder state vars
|
||||
int m_restbits; /* remaining valid bits */
|
||||
unsigned int m_restbyte; /* remaining bytes in this block */
|
||||
unsigned int m_lastbyte; /* last byte read */
|
||||
unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */
|
||||
unsigned char *m_bufp; /* pointer to next byte in buffer */
|
||||
|
||||
wxInputStream *m_f; /* input file */
|
||||
// input stream
|
||||
wxInputStream *m_f; /* input stream */
|
||||
|
||||
private:
|
||||
int getcode(int bits, int abfin);
|
||||
int dgif(IMAGEN *img, int interl, int bits);
|
||||
|
||||
public:
|
||||
// constructor, destructor, etc.
|
||||
wxGIFDecoder(wxInputStream *s, bool anim = FALSE);
|
||||
~wxGIFDecoder();
|
||||
bool CanRead();
|
||||
int ReadGIF();
|
||||
void Destroy();
|
||||
|
||||
// convert current frame to wxImage
|
||||
bool ConvertToImage(wxImage *image) const;
|
||||
int dgif(GIFImage *img, int interl, int bits);
|
||||
|
||||
protected:
|
||||
// get data of current frame
|
||||
int GetFrameIndex() const;
|
||||
unsigned char* GetData() const;
|
||||
@ -117,6 +125,17 @@ public:
|
||||
bool GoNextFrame(bool cyclic = FALSE);
|
||||
bool GoPrevFrame(bool cyclic = FALSE);
|
||||
bool GoFrame(int which);
|
||||
|
||||
public:
|
||||
// constructor, destructor, etc.
|
||||
wxGIFDecoder(wxInputStream *s, bool anim = FALSE);
|
||||
~wxGIFDecoder();
|
||||
bool CanRead();
|
||||
int ReadGIF();
|
||||
void Destroy();
|
||||
|
||||
// convert current frame to wxImage
|
||||
bool ConvertToImage(wxImage *image) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ wxGIFDecoder::~wxGIFDecoder()
|
||||
|
||||
void wxGIFDecoder::Destroy()
|
||||
{
|
||||
IMAGEN *pimg, *paux;
|
||||
GIFImage *pimg, *paux;
|
||||
|
||||
pimg = m_pfirst;
|
||||
|
||||
@ -66,7 +66,7 @@ void wxGIFDecoder::Destroy()
|
||||
paux = pimg->next;
|
||||
free(pimg->p);
|
||||
free(pimg->pal);
|
||||
free(pimg);
|
||||
delete pimg;
|
||||
pimg = paux;
|
||||
}
|
||||
}
|
||||
@ -309,7 +309,7 @@ int wxGIFDecoder::getcode(int bits, int ab_fin)
|
||||
// GIF decoding function. The initial code size (aka root size)
|
||||
// is 'bits'. Supports interlaced images (interl == 1).
|
||||
//
|
||||
int wxGIFDecoder::dgif(IMAGEN *img, int interl, int bits)
|
||||
int wxGIFDecoder::dgif(GIFImage *img, int interl, int bits)
|
||||
{
|
||||
int ab_prefix[4096]; /* alphabet (prefixes) */
|
||||
int ab_tail[4096]; /* alphabet (tails) */
|
||||
@ -461,9 +461,9 @@ bool wxGIFDecoder::CanRead()
|
||||
// animated GIF support is enabled. Can read GIFs with any bit
|
||||
// size (color depth), but the output images are always expanded
|
||||
// to 8 bits per pixel. Also, the image palettes always contain
|
||||
// 256 colors, although some of them may be unused. Returns E_OK
|
||||
// (== 0) on success, or an error code if something fails. Error
|
||||
// codes are E_ARCHIVO, E_FORMATO, E_MEMORIA (see header file).
|
||||
// 256 colors, although some of them may be unused. Returns GIF_OK
|
||||
// (== 0) on success, or an error code if something fails (see
|
||||
// header file for details)
|
||||
//
|
||||
int wxGIFDecoder::ReadGIF()
|
||||
{
|
||||
@ -473,11 +473,11 @@ int wxGIFDecoder::ReadGIF()
|
||||
unsigned char type;
|
||||
unsigned char pal[768];
|
||||
unsigned char buf[16];
|
||||
IMAGEN **ppimg, *pimg, *pprev;
|
||||
GIFImage **ppimg, *pimg, *pprev;
|
||||
|
||||
/* check GIF signature */
|
||||
if (!CanRead())
|
||||
return E_FORMATO;
|
||||
return wxGIF_INVFORMAT;
|
||||
|
||||
/* check for and animated GIF support (ver. >= 89a) */
|
||||
m_f->Read(buf, 6);
|
||||
@ -562,12 +562,12 @@ int wxGIFDecoder::ReadGIF()
|
||||
if (type == 0x2C)
|
||||
{
|
||||
/* allocate memory for IMAGEN struct */
|
||||
pimg = (*ppimg) = (IMAGEN *) malloc(sizeof(IMAGEN));
|
||||
pimg = (*ppimg) = new GIFImage();
|
||||
|
||||
if (pimg == NULL)
|
||||
{
|
||||
Destroy();
|
||||
return E_MEMORIA;
|
||||
return wxGIF_MEMERR;
|
||||
}
|
||||
|
||||
/* fill in the data */
|
||||
@ -594,7 +594,7 @@ int wxGIFDecoder::ReadGIF()
|
||||
if ((!pimg->p) || (!pimg->pal))
|
||||
{
|
||||
Destroy();
|
||||
return E_MEMORIA;
|
||||
return wxGIF_MEMERR;
|
||||
}
|
||||
|
||||
/* load local color map if available, else use global map */
|
||||
@ -628,7 +628,7 @@ int wxGIFDecoder::ReadGIF()
|
||||
m_pimage = m_pfirst;
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
return wxGIF_OK;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS && wxUSE_GIF
|
||||
|
@ -49,15 +49,15 @@ bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
|
||||
|
||||
decod = new wxGIFDecoder(&stream, TRUE);
|
||||
|
||||
if ((error = decod->ReadGIF()) != E_OK)
|
||||
if ((error = decod->ReadGIF()) != wxGIF_OK)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case E_FORMATO: wxLogError(_("GIF: Error in image format.")); break;
|
||||
case E_MEMORIA: wxLogError(_("GIF: Couldn't allocate memory.")); break;
|
||||
default: wxLogError(_("GIF: Unknown error."));
|
||||
case wxGIF_INVFORMAT: wxLogError(_("wxGIFHandler: error in GIF image format")); break;
|
||||
case wxGIF_MEMERR: wxLogError(_("wxGIFHandler: couldn't allocate enough memory")); break;
|
||||
default: wxLogError(_("wxGIFHandler: unknown error !!!"));
|
||||
}
|
||||
}
|
||||
delete decod;
|
||||
|
@ -86,21 +86,24 @@ void RLEdecode(unsigned char *p, unsigned int size, wxInputStream& s)
|
||||
#define HDR_NPLANES 65
|
||||
#define HDR_BYTESPERLINE 66
|
||||
|
||||
/* image formats */
|
||||
#define IMAGE_8BIT 0 // 8 bpp, 1 plane (8 bit)
|
||||
#define IMAGE_24BIT 1 // 8 bpp, 3 planes (24 bit)
|
||||
|
||||
/* error codes */
|
||||
#define E_OK 0 // everything was OK
|
||||
#define E_FORMATO 1 // error in pcx file format
|
||||
#define E_MEMORIA 2 // error allocating memory
|
||||
#define E_VERSION 3 // error in pcx version number
|
||||
// image formats
|
||||
enum {
|
||||
wxPCX_8BIT, // 8 bpp, 1 plane (8 bit)
|
||||
wxPCX_24BIT // 8 bpp, 3 planes (24 bit)
|
||||
};
|
||||
|
||||
// error codes
|
||||
enum {
|
||||
wxPCX_OK = 0, // everything was OK
|
||||
wxPCX_INVFORMAT = 1, // error in pcx file format
|
||||
wxPCX_MEMERR = 2, // error allocating memory
|
||||
wxPCX_VERERR = 3 // error in pcx version number
|
||||
};
|
||||
|
||||
// ReadPCX:
|
||||
// Loads a PCX file into the wxImage object pointed by image.
|
||||
// Returns E_OK on success, or an error code otherwise (see
|
||||
// above for error codes)
|
||||
// Returns wxPCX_OK on success, or an error code otherwise
|
||||
// (see above for error codes)
|
||||
//
|
||||
int ReadPCX(wxImage *image, wxInputStream& stream)
|
||||
{
|
||||
@ -122,7 +125,7 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
|
||||
//
|
||||
stream.Read(hdr, 128);
|
||||
|
||||
if (hdr[HDR_VERSION] < 5) return E_VERSION;
|
||||
if (hdr[HDR_VERSION] < 5) return wxPCX_VERERR;
|
||||
|
||||
// Extract all image info from the PCX header.
|
||||
//
|
||||
@ -139,23 +142,23 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
|
||||
// 8 bits (8 bpp, 1 plane) and 24 bits (8 bpp, 3 planes).
|
||||
//
|
||||
if ((nplanes == 3) && (bitsperpixel == 8))
|
||||
format = IMAGE_24BIT;
|
||||
format = wxPCX_24BIT;
|
||||
else if ((nplanes == 1) && (bitsperpixel == 8))
|
||||
format = IMAGE_8BIT;
|
||||
format = wxPCX_8BIT;
|
||||
else
|
||||
return E_FORMATO;
|
||||
return wxPCX_INVFORMAT;
|
||||
|
||||
// If the image is of type IMAGE_8BIT, then there is a
|
||||
// If the image is of type wxPCX_8BIT, then there is a
|
||||
// palette at the end of the file. Read it now before
|
||||
// proceeding.
|
||||
//
|
||||
if (format == IMAGE_8BIT)
|
||||
if (format == wxPCX_8BIT)
|
||||
{
|
||||
pos = stream.TellI();
|
||||
stream.SeekI(-769, wxFromEnd);
|
||||
|
||||
if (stream.GetC() != 12)
|
||||
return E_FORMATO;
|
||||
return wxPCX_INVFORMAT;
|
||||
|
||||
stream.Read(pal, 768);
|
||||
stream.SeekI(pos, wxFromStart);
|
||||
@ -166,10 +169,10 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
|
||||
image->Create(width, height);
|
||||
|
||||
if (!image->Ok())
|
||||
return E_MEMORIA;
|
||||
return wxPCX_MEMERR;
|
||||
|
||||
if ((p = (unsigned char *) malloc(bytesperline * nplanes)) == NULL)
|
||||
return E_MEMORIA;
|
||||
return wxPCX_MEMERR;
|
||||
|
||||
// Now start reading the file, line by line, and store
|
||||
// the data in the format required by wxImage.
|
||||
@ -185,7 +188,7 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case IMAGE_8BIT:
|
||||
case wxPCX_8BIT:
|
||||
{
|
||||
for (i = 0; i < width; i++)
|
||||
{
|
||||
@ -195,7 +198,7 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IMAGE_24BIT:
|
||||
case wxPCX_24BIT:
|
||||
{
|
||||
for (i = 0; i < width; i++)
|
||||
{
|
||||
@ -210,7 +213,7 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
|
||||
|
||||
free(p);
|
||||
|
||||
return E_OK;
|
||||
return wxPCX_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -236,16 +239,16 @@ bool wxPCXHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
|
||||
|
||||
image->Destroy();
|
||||
|
||||
if ((error = ReadPCX(image, stream)) != E_OK)
|
||||
if ((error = ReadPCX(image, stream)) != wxPCX_OK)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case E_FORMATO: wxLogError(_("PCX: Image format unsupported.")); break;
|
||||
case E_MEMORIA: wxLogError(_("PCX: Couldn't allocate memory.")); break;
|
||||
case E_VERSION: wxLogError(_("PCX: Wrong version number.")); break;
|
||||
default: wxLogError(_("PCX: Unknown error."));
|
||||
case wxPCX_INVFORMAT: wxLogError(_("wxPCXHandler: image format unsupported")); break;
|
||||
case wxPCX_MEMERR: wxLogError(_("wxPCXHandler: couldn't allocate memory")); break;
|
||||
case wxPCX_VERERR: wxLogError(_("wxPCXHandler: version number too low")); break;
|
||||
default: wxLogError(_("wxPCXHandler: unknown error !!!"));
|
||||
}
|
||||
}
|
||||
image->Destroy();
|
||||
|
Loading…
Reference in New Issue
Block a user