summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
dda522b)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45159
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#include <stdlib.h>
#include <string.h>
#include "wx/gifdecod.h"
#include <stdlib.h>
#include <string.h>
#include "wx/gifdecod.h"
+#include "wx/ptr_scpd.h"
+#include "wx/scopeguard.h"
DECLARE_NO_COPY_CLASS(GIFImage)
};
DECLARE_NO_COPY_CLASS(GIFImage)
};
+wxDECLARE_SCOPED_PTR(GIFImage, GIFImagePtr)
+wxDEFINE_SCOPED_PTR(GIFImage, GIFImagePtr)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
if (type == 0x2C)
{
// allocate memory for IMAGEN struct
if (type == 0x2C)
{
// allocate memory for IMAGEN struct
- GIFImage *pimg = new GIFImage();
+ GIFImagePtr pimg(new GIFImage());
- if (pimg == NULL)
- {
- Destroy();
+ wxScopeGuard guardDestroy = wxMakeObjGuard(*this, &wxGIFDecoder::Destroy);
+
+ if ( !pimg.get() )
// fill in the data
static const unsigned int idbSize = (2 + 2 + 2 + 2 + 1);
stream.Read(buf, idbSize);
if (stream.LastRead() != idbSize)
// fill in the data
static const unsigned int idbSize = (2 + 2 + 2 + 2 + 1);
stream.Read(buf, idbSize);
if (stream.LastRead() != idbSize)
pimg->left = buf[0] + 256 * buf[1];
pimg->top = buf[2] + 256 * buf[3];
pimg->left = buf[0] + 256 * buf[1];
pimg->top = buf[2] + 256 * buf[3];
pimg->w = buf[4] + 256 * buf[5];
pimg->h = buf[6] + 256 * buf[7];
pimg->w = buf[4] + 256 * buf[5];
pimg->h = buf[6] + 256 * buf[7];
- if (anim && ((pimg->w == 0) || (pimg->w > (unsigned int)m_szAnimation.GetWidth()) ||
- (pimg->h == 0) || (pimg->h > (unsigned int)m_szAnimation.GetHeight())))
- {
- Destroy();
+ if ( anim && ((pimg->w == 0) || (pimg->w > (unsigned int)m_szAnimation.GetWidth()) ||
+ (pimg->h == 0) || (pimg->h > (unsigned int)m_szAnimation.GetHeight())) )
interl = ((buf[8] & 0x40)? 1 : 0);
size = pimg->w * pimg->h;
interl = ((buf[8] & 0x40)? 1 : 0);
size = pimg->w * pimg->h;
pimg->pal = (unsigned char *) malloc(768);
if ((!pimg->p) || (!pimg->pal))
pimg->pal = (unsigned char *) malloc(768);
if ((!pimg->p) || (!pimg->pal))
// load local color map if available, else use global map
if ((buf[8] & 0x80) == 0x80)
// load local color map if available, else use global map
if ((buf[8] & 0x80) == 0x80)
stream.Read(pimg->pal, numBytes);
pimg->ncolours = local_ncolors;
if (stream.LastRead() != numBytes)
stream.Read(pimg->pal, numBytes);
pimg->ncolours = local_ncolors;
if (stream.LastRead() != numBytes)
// get initial code size from first byte in raster data
bits = (unsigned char)stream.GetC();
if (bits == 0)
// get initial code size from first byte in raster data
bits = (unsigned char)stream.GetC();
if (bits == 0)
- wxGIFErrorCode result = dgif(stream, pimg, interl, bits);
+ wxGIFErrorCode result = dgif(stream, pimg.get(), interl, bits);
+
+ guardDestroy.Dismiss();
// add the image to our frame array
// add the image to our frame array
- m_frames.Add((void*)pimg);
+ m_frames.Add(pimg.release());
m_nFrames++;
// if this is not an animated GIF, exit after first image
m_nFrames++;
// if this is not an animated GIF, exit after first image