X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3af706cc3164bacc24899e0fc827c28e7ea812b6..0cdd04ad993f86710bc5c9d9c8c12ec25a34ac71:/src/common/imagtga.cpp diff --git a/src/common/imagtga.cpp b/src/common/imagtga.cpp index bf99b1af4c..6d65dd7889 100644 --- a/src/common/imagtga.cpp +++ b/src/common/imagtga.cpp @@ -30,6 +30,7 @@ #include "wx/imagtga.h" #include "wx/log.h" +#include "wx/scopeguard.h" // ---------------------------------------------------------------------------- // constants @@ -187,6 +188,8 @@ int ReadTGA(wxImage* image, wxInputStream& stream) return wxTGA_MEMERR; } + wxON_BLOCK_EXIT1(free, imageData); + unsigned char *dst = image->GetData(); unsigned char* alpha = NULL; @@ -218,13 +221,10 @@ int ReadTGA(wxImage* image, wxInputStream& stream) b[i] = buf[0]; } - #if wxUSE_PALETTE - +#if wxUSE_PALETTE // Set the palette of the image. - image->SetPalette(wxPalette(paletteLength, r, g, b)); - - #endif // wxUSE_PALETTE +#endif // wxUSE_PALETTE delete[] r; delete[] g; @@ -235,6 +235,7 @@ int ReadTGA(wxImage* image, wxInputStream& stream) switch (imageType) { +#if wxUSE_PALETTE // Raw indexed. case 1: @@ -296,6 +297,7 @@ int ReadTGA(wxImage* image, wxInputStream& stream) } } break; +#endif // wxUSE_PALETTE // Raw RGB. @@ -428,6 +430,7 @@ int ReadTGA(wxImage* image, wxInputStream& stream) } break; +#if wxUSE_PALETTE // RLE indexed. case 9: @@ -489,6 +492,7 @@ int ReadTGA(wxImage* image, wxInputStream& stream) } } break; +#endif // wxUSE_PALETTE // RLE RGB. @@ -625,8 +629,6 @@ int ReadTGA(wxImage* image, wxInputStream& stream) return wxTGA_INVFORMAT; } - free(imageData); - return wxTGA_OK; }