#include "wx/filefn.h"
#include "wx/wfstream.h"
#include "wx/quantize.h"
+#include "wx/scopeguard.h"
#include "wx/anidecod.h"
// For memcpy
}
-typedef struct
+struct BMPPalette
{
+ static void Free(BMPPalette* pal) { delete [] pal; }
+
unsigned char r, g, b;
-} _cmap;
+};
bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
int bpp, int ncolors, int comp,
wxUint16 aWord;
// allocate space for palette if needed:
- _cmap *cmap;
+ BMPPalette *cmap;
if ( bpp < 16 )
{
- cmap = new _cmap[ncolors];
+ cmap = new BMPPalette[ncolors];
if ( !cmap )
{
if (verbose)
return false;
}
}
- else
+ else // no palette
+ {
cmap = NULL;
+ }
+
+ wxON_BLOCK_EXIT1(&BMPPalette::Free, cmap);
// destroy existing here instead of:
image->Destroy();
{
if ( verbose )
wxLogError( _("BMP: Couldn't allocate memory.") );
- delete[] cmap;
return false;
}
{
if ( verbose )
wxLogError(_("BMP: Couldn't allocate memory."));
- delete[] cmap;
return false;
}
}
}
}
- delete[] cmap;
-
image->SetMask(false);
const wxStreamError err = stream.GetLastError();