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