Fixed [ 1561693 ] wxGIFDecoder creates incorrect wxPalette

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41406 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-09-24 10:54:12 +00:00
parent df816ad92f
commit 57b5c44a4f
2 changed files with 15 additions and 9 deletions

View File

@@ -72,6 +72,7 @@ public:
long delay; /* delay in ms (-1 = unused) */
unsigned char *p; /* bitmap */
unsigned char *pal; /* palette */
unsigned int ncolours; /* number of colours */
GIFImage *next; /* next image */
GIFImage *prev; /* prev image */
@@ -114,6 +115,7 @@ public:
int GetFrameIndex() const;
unsigned char* GetData() const;
unsigned char* GetPalette() const;
unsigned int GetNcolours() const;
unsigned int GetWidth() const;
unsigned int GetHeight() const;
unsigned int GetLeft() const;

View File

@@ -40,6 +40,7 @@ GIFImage::GIFImage()
delay = -1;
p = (unsigned char *) NULL;
pal = (unsigned char *) NULL;
ncolours = 0;
next = (GIFImage *) NULL;
prev = (GIFImage *) NULL;
}
@@ -121,7 +122,7 @@ bool wxGIFDecoder::ConvertToImage(wxImage *image) const
/* set transparent colour mask */
if (transparent != -1)
{
for (i = 0; i < 256; i++)
for (i = 0; i < GetNcolours(); i++)
{
if ((pal[3 * i + 0] == 255) &&
(pal[3 * i + 1] == 0) &&
@@ -152,7 +153,7 @@ bool wxGIFDecoder::ConvertToImage(wxImage *image) const
b[i] = pal[3*i + 2];
}
image->SetPalette(wxPalette(256, r, g, b));
image->SetPalette(wxPalette(GetNcolours(), r, g, b));
#endif // wxUSE_PALETTE
/* copy image data */
@@ -176,6 +177,7 @@ bool wxGIFDecoder::ConvertToImage(wxImage *image) const
int wxGIFDecoder::GetFrameIndex() const { return m_image; }
unsigned char* wxGIFDecoder::GetData() const { return (m_pimage->p); }
unsigned char* wxGIFDecoder::GetPalette() const { return (m_pimage->pal); }
unsigned int wxGIFDecoder::GetNcolours() const { return (m_pimage->ncolours); }
unsigned int wxGIFDecoder::GetWidth() const { return (m_pimage->w); }
unsigned int wxGIFDecoder::GetHeight() const { return (m_pimage->h); }
unsigned int wxGIFDecoder::GetTop() const { return (m_pimage->top); }
@@ -651,7 +653,7 @@ bool wxGIFDecoder::CanRead()
//
int wxGIFDecoder::ReadGIF()
{
unsigned int ncolors;
unsigned int global_ncolors = 0;
int bits, interl, transparent, disposal, i;
long size;
long delay;
@@ -700,8 +702,8 @@ int wxGIFDecoder::ReadGIF()
{
m_background = buf[5];
ncolors = 2 << (buf[4] & 0x07);
size_t numBytes = 3 * ncolors;
global_ncolors = 2 << (buf[4] & 0x07);
size_t numBytes = 3 * global_ncolors;
m_f->Read(pal, numBytes);
if (m_f->LastRead() != numBytes)
{
@@ -847,9 +849,10 @@ int wxGIFDecoder::ReadGIF()
/* load local color map if available, else use global map */
if ((buf[8] & 0x80) == 0x80)
{
ncolors = 2 << (buf[8] & 0x07);
size_t numBytes = 3 * ncolors;
unsigned int local_ncolors = 2 << (buf[8] & 0x07);
size_t numBytes = 3 * local_ncolors;
m_f->Read(pimg->pal, numBytes);
pimg->ncolours = local_ncolors;
if (m_f->LastRead() != numBytes)
{
Destroy();
@@ -859,6 +862,7 @@ int wxGIFDecoder::ReadGIF()
else
{
memcpy(pimg->pal, pal, 768);
pimg->ncolours = global_ncolors;
}
/* get initial code size from first byte in raster data */
@@ -928,9 +932,9 @@ int wxGIFDecoder::ReadGIF()
/* local color map */
if ((buf[8] & 0x80) == 0x80)
{
ncolors = 2 << (buf[8] & 0x07);
unsigned int local_ncolors = 2 << (buf[8] & 0x07);
wxFileOffset pos = m_f->TellI();
wxFileOffset numBytes = 3 * ncolors;
wxFileOffset numBytes = 3 * local_ncolors;
m_f->SeekI(numBytes, wxFromCurrent);
if (m_f->TellI() != (pos + numBytes))
{