From 65d03c9893db24ffef947cd1edf722641f5a526a Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 Jun 2015 20:21:50 -0300 Subject: [PATCH] Add support to compile gif_format.cpp with giflib 4 --- src/app/file/gif_format.cpp | 56 +++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/src/app/file/gif_format.cpp b/src/app/file/gif_format.cpp index ae9498273..60bf90edc 100644 --- a/src/app/file/gif_format.cpp +++ b/src/app/file/gif_format.cpp @@ -31,6 +31,10 @@ #include +#if GIFLIB_MAJOR < 5 +#define GifMakeMapObject MakeMapObject +#endif + namespace app { using namespace base; @@ -106,15 +110,23 @@ static int interlaced_jumps[] = { 8, 8, 4, 2 }; struct GifFilePtr { public: +#if GIFLIB_MAJOR >= 5 typedef int (*CloseFunc)(GifFileType*, int*); +#else + typedef int (*CloseFunc)(GifFileType*); +#endif GifFilePtr(GifFileType* ptr, CloseFunc closeFunc) : m_ptr(ptr), m_closeFunc(closeFunc) { } ~GifFilePtr() { +#if GIFLIB_MAJOR >= 5 int errCode; m_closeFunc(m_ptr, &errCode); +#else + m_closeFunc(m_ptr); +#endif } operator GifFileType*() { @@ -132,8 +144,12 @@ private: bool GifFormat::onLoad(FileOp* fop) { - int errCode; - GifFilePtr gif_file(DGifOpenFileHandle(open_file_descriptor_with_exception(fop->filename, "rb"), &errCode), &DGifCloseFile); + int errCode = 0; + GifFilePtr gif_file(DGifOpenFileHandle(open_file_descriptor_with_exception(fop->filename, "rb") +#if GIFLIB_MAJOR >= 5 + , &errCode +#endif + ), &DGifCloseFile); if (!gif_file) { fop_error(fop, "Error loading GIF header.\n"); @@ -244,7 +260,13 @@ bool GifFormat::onLoad(FileOp* fop) for (int y = 0; y < frame_h; ++y) { addr = frame_image->getPixelAddress(0, y); if (DGifGetLine(gif_file, addr, frame_w) == GIF_ERROR) - throw Exception("Invalid image data (%d).\n", gif_file->Error); + throw Exception("Invalid image data (%d).\n" +#if GIFLIB_MAJOR >= 5 + , gif_file->Error +#else + , GifLastError() +#endif + ); } } @@ -522,8 +544,12 @@ void GifFormat::onDestroyData(FileOp* fop) #ifdef ENABLE_SAVE bool GifFormat::onSave(FileOp* fop) { - int errCode; - GifFilePtr gif_file(EGifOpenFileHandle(open_file_descriptor_with_exception(fop->filename, "wb"), &errCode), &EGifCloseFile); + int errCode = 0; + GifFilePtr gif_file(EGifOpenFileHandle(open_file_descriptor_with_exception(fop->filename, "wb") +#if GIFLIB_MAJOR >= 5 + , &errCode +#endif + ), &EGifCloseFile); if (!gif_file) throw Exception("Error creating GIF file.\n"); @@ -682,6 +708,7 @@ bool GifFormat::onSave(FileOp* fop) // Specify loop extension. if (frame_num == 0 && loop >= 0) { +#if GIFLIB_MAJOR >= 5 if (EGifPutExtensionLeader(gif_file, APPLICATION_EXT_FUNC_CODE) == GIF_ERROR) throw Exception("Error writing GIF graphics extension record (header section)."); @@ -698,6 +725,23 @@ bool GifFormat::onSave(FileOp* fop) if (EGifPutExtensionTrailer(gif_file) == GIF_ERROR) throw Exception("Error writing GIF graphics extension record (trailer section)."); + +#else + unsigned char extension_bytes[11]; + + memcpy(extension_bytes, "NETSCAPE2.0", 11); + if (EGifPutExtensionFirst(gif_file, APPLICATION_EXT_FUNC_CODE, 11, extension_bytes) == GIF_ERROR) + throw Exception("Error writing GIF graphics extension record for frame %d.\n", (int)frame_num); + + extension_bytes[0] = 1; + extension_bytes[1] = (loop & 0xff); + extension_bytes[2] = (loop >> 8) & 0xff; + if (EGifPutExtensionNext(gif_file, APPLICATION_EXT_FUNC_CODE, 3, extension_bytes) == GIF_ERROR) + throw Exception("Error writing GIF graphics extension record for frame %d.\n", (int)frame_num); + + if (EGifPutExtensionLast(gif_file, APPLICATION_EXT_FUNC_CODE, 0, NULL) == GIF_ERROR) + throw Exception("Error writing GIF graphics extension record for frame %d.\n", (int)frame_num); +#endif } // Write graphics extension record (to save the duration of the @@ -770,8 +814,8 @@ bool GifFormat::onSave(FileOp* fop) } return true; -} #endif +} base::SharedPtr GifFormat::onGetFormatOptions(FileOp* fop) {