diff --git a/src/dgif.hh b/src/dgif.hh index 06b5e73..cebfdf4 100644 --- a/src/dgif.hh +++ b/src/dgif.hh @@ -8,8 +8,9 @@ extern "C" { #include "url.hh" #include "image.hh" +struct DilloGif; -void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version); +DilloGif *a_Gif_new(DilloImage *Image, DilloUrl *url, int version); void a_Gif_callback(int Op, void *data); diff --git a/src/gif.cc b/src/gif.cc index b9c25cc..0789ff3 100644 --- a/src/gif.cc +++ b/src/gif.cc @@ -82,7 +82,9 @@ #define MAX_LWZ_BITS 12 -typedef struct { +struct DilloGif { + ~DilloGif(); + DilloImage *Image; DilloUrl *url; int version; @@ -131,7 +133,7 @@ typedef struct { int num_spill_lines_max; int length[(1 << MAX_LWZ_BITS) + 1]; int code_and_byte[(1 << MAX_LWZ_BITS) + 1]; -} DilloGif; +}; /* Some invariants: * @@ -153,9 +155,9 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *buf, /** * Create a new gif structure for decoding a gif into a RGB buffer */ -void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version) +DilloGif *a_Gif_new(DilloImage *Image, DilloUrl *url, int version) { - DilloGif *gif = reinterpret_cast< DilloGif * >( dMalloc(sizeof(DilloGif)) ); + DilloGif *gif = new DilloGif{}; _MSG("a_Gif_new: gif=%p\n", gif); gif->Image = Image; @@ -180,8 +182,9 @@ void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version) /** * Free the gif-decoding data structure. */ -static void Gif_free(DilloGif *gif) +DilloGif::~DilloGif() { + DilloGif *gif= this; int i; _MSG("Gif_free: gif=%p\n", gif); @@ -192,7 +195,6 @@ static void Gif_free(DilloGif *gif) dFree(gif->spill_lines[i]); dFree(gif->spill_lines); } - dFree(gif); } /** @@ -208,7 +210,7 @@ void a_Gif_callback(int Op, void *data) CacheClient_t *Client = reinterpret_cast< CacheClient_t * >( data ); Gif_close(reinterpret_cast< DilloGif * >( Client->CbData ), Client); } else if (Op == CA_Abort) { - Gif_free(reinterpret_cast< DilloGif * >( data )); + delete reinterpret_cast< DilloGif * >( data ); } } @@ -246,7 +248,7 @@ static void Gif_close(DilloGif *gif, CacheClient_t *Client) { _MSG("Gif_close: destroy gif %p\n", gif); a_Dicache_close(gif->url, gif->version, Client); - Gif_free(gif); + delete gif; } @@ -1023,7 +1025,7 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *ibuf, #else /* ENABLE_GIF */ -void *a_Gif_new() { return 0; } +DilloGif *a_Gif_new() { return 0; } void a_Gif_callback() { return; } #endif /* ENABLE_GIF */