This file is part of MXE. See index.html for further information. From a0c0640eb7e98db4a9cbe5104abef8425d975712 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 4 Jul 2012 10:05:33 +0200 Subject: [PATCH 1/2] giflib compatibility Taken from http://trac.osgeo.org/gdal/changeset/24491?format=diff&new=24491 --- frmts/gif/gifdataset.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/frmts/gif/gifdataset.cpp b/frmts/gif/gifdataset.cpp index c89f34c..1947edd 100644 --- a/frmts/gif/gifdataset.cpp +++ b/frmts/gif/gifdataset.cpp @@ -470,6 +470,28 @@ GDALDataset *GIFDataset::Open( GDALOpenInfo * poOpenInfo ) } /************************************************************************/ +/* GDALPrintGifError() */ +/************************************************************************/ + +static void GDALPrintGifError(const char* pszMsg) +{ +/* GIFLIB_MAJOR is only defined in libgif >= 4.2.0 */ +/* libgif 4.2.0 has retired PrintGifError() and added GifErrorString() */ +#if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && \ + ((GIFLIB_MAJOR == 4 && GIFLIB_MINOR >= 2) || GIFLIB_MAJOR > 4) + /* Static string actually, hence the const char* cast */ + const char* pszGIFLIBError = (const char*) GifErrorString(); + if (pszGIFLIBError == NULL) + pszGIFLIBError = "Unknown error"; + CPLError( CE_Failure, CPLE_AppDefined, + "%s. GIFLib Error : %s", pszMsg, pszGIFLIBError ); +#else + PrintGifError(); + CPLError( CE_Failure, CPLE_AppDefined, "%s", pszMsg ); +#endif +} + +/************************************************************************/ /* CreateCopy() */ /************************************************************************/ @@ -596,9 +618,7 @@ GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, psGifCT->ColorCount, 255, psGifCT) == GIF_ERROR) { FreeMapObject(psGifCT); - PrintGifError(); - CPLError( CE_Failure, CPLE_AppDefined, - "Error writing gif file." ); + GDALPrintGifError("Error writing gif file."); EGifCloseFile(hGifFile); VSIFCloseL( fp ); return NULL; @@ -622,9 +642,7 @@ GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, if (EGifPutImageDesc(hGifFile, 0, 0, nXSize, nYSize, bInterlace, NULL) == GIF_ERROR ) { - PrintGifError(); - CPLError( CE_Failure, CPLE_AppDefined, - "Error writing gif file." ); + GDALPrintGifError("Error writing gif file."); EGifCloseFile(hGifFile); VSIFCloseL( fp ); return NULL; -- 1.7.10.4 From 7411f59dd769a72a79838e932d1a0988b04dc4d5 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 4 Jul 2012 10:42:33 +0200 Subject: [PATCH 2/2] giflib 5 compatibility taken from http://trac.osgeo.org/gdal/changeset/24627 --- frmts/gif/biggifdataset.cpp | 5 +++++ frmts/gif/gifdataset.cpp | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/frmts/gif/biggifdataset.cpp b/frmts/gif/biggifdataset.cpp index e3029e5..6bed0dc 100644 --- a/frmts/gif/biggifdataset.cpp +++ b/frmts/gif/biggifdataset.cpp @@ -371,7 +371,12 @@ CPLErr BIGGIFDataset::ReOpen() VSIFSeekL( fp, 0, SEEK_SET ); nLastLineRead = -1; +#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 + int nError; + hGifFile = DGifOpen( fp, VSIGIFReadFunc, &nError ); +#else hGifFile = DGifOpen( fp, VSIGIFReadFunc ); +#endif if( hGifFile == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, diff --git a/frmts/gif/gifdataset.cpp b/frmts/gif/gifdataset.cpp index 1947edd..0b99158 100644 --- a/frmts/gif/gifdataset.cpp +++ b/frmts/gif/gifdataset.cpp @@ -36,8 +36,17 @@ CPL_CVSID("$Id: gifdataset.cpp 23621 2011-12-20 23:26:56Z rouault $"); CPL_C_START void GDALRegister_GIF(void); +#if !(defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5) + // This prototype seems to have been messed up! GifFileType * EGifOpen(void* userData, OutputFunc writeFunc); + +// Define alias compatible with giflib >= 5.0.0 +#define GifMakeMapObject MakeMapObject +#define GifFreeMapObject FreeMapObject + +#endif // defined(GIFLIB_MAJOR) && GIFLIB_MAJOR < 5 + CPL_C_END static const int InterlacedOffset[] = { 0, 4, 2, 1 }; @@ -322,7 +331,12 @@ GDALDataset *GIFDataset::Open( GDALOpenInfo * poOpenInfo ) if( fp == NULL ) return NULL; +#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 + int nError; + hGifFile = DGifOpen( fp, VSIGIFReadFunc, &nError ); +#else hGifFile = DGifOpen( fp, VSIGIFReadFunc ); +#endif if( hGifFile == NULL ) { VSIFCloseL( fp ); @@ -380,7 +394,12 @@ GDALDataset *GIFDataset::Open( GDALOpenInfo * poOpenInfo ) DGifCloseFile( hGifFile ); VSIFSeekL( fp, 0, SEEK_SET); + +#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 + hGifFile = DGifOpen( fp, VSIGIFReadFunc, &nError ); +#else hGifFile = DGifOpen( fp, VSIGIFReadFunc ); +#endif if( hGifFile == NULL ) { VSIFCloseL( fp ); @@ -473,14 +492,19 @@ GDALDataset *GIFDataset::Open( GDALOpenInfo * poOpenInfo ) /* GDALPrintGifError() */ /************************************************************************/ -static void GDALPrintGifError(const char* pszMsg) +static void GDALPrintGifError(GifFileType *hGifFile, const char* pszMsg) { /* GIFLIB_MAJOR is only defined in libgif >= 4.2.0 */ /* libgif 4.2.0 has retired PrintGifError() and added GifErrorString() */ #if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && \ ((GIFLIB_MAJOR == 4 && GIFLIB_MINOR >= 2) || GIFLIB_MAJOR > 4) /* Static string actually, hence the const char* cast */ + +#if GIFLIB_MAJOR >= 5 + const char* pszGIFLIBError = (const char*) GifErrorString(hGifFile->Error); +#else const char* pszGIFLIBError = (const char*) GifErrorString(); +#endif if (pszGIFLIBError == NULL) pszGIFLIBError = "Unknown error"; CPLError( CE_Failure, CPLE_AppDefined, @@ -557,7 +581,12 @@ GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, return NULL; } +#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 + int nError; + hGifFile = EGifOpen( fp, VSIGIFWriteFunc, &nError ); +#else hGifFile = EGifOpen( fp, VSIGIFWriteFunc ); +#endif if( hGifFile == NULL ) { VSIFCloseL( fp ); @@ -577,7 +606,7 @@ GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, if( poBand->GetColorTable() == NULL ) { - psGifCT = MakeMapObject( 256, NULL ); + psGifCT = GifMakeMapObject( 256, NULL ); for( iColor = 0; iColor < 256; iColor++ ) { psGifCT->Colors[iColor].Red = (GifByteType) iColor; @@ -593,7 +622,7 @@ GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, while( nFullCount < poCT->GetColorEntryCount() ) nFullCount = nFullCount * 2; - psGifCT = MakeMapObject( nFullCount, NULL ); + psGifCT = GifMakeMapObject( nFullCount, NULL ); for( iColor = 0; iColor < poCT->GetColorEntryCount(); iColor++ ) { GDALColorEntry sEntry; @@ -617,14 +646,14 @@ GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, if (EGifPutScreenDesc(hGifFile, nXSize, nYSize, psGifCT->ColorCount, 255, psGifCT) == GIF_ERROR) { - FreeMapObject(psGifCT); - GDALPrintGifError("Error writing gif file."); + GifFreeMapObject(psGifCT); + GDALPrintGifError(hGifFile, "Error writing gif file."); EGifCloseFile(hGifFile); VSIFCloseL( fp ); return NULL; } - FreeMapObject(psGifCT); + GifFreeMapObject(psGifCT); psGifCT = NULL; /* Support for transparency */ @@ -642,7 +671,7 @@ GIFDataset::CreateCopy( const char * pszFilename, GDALDataset *poSrcDS, if (EGifPutImageDesc(hGifFile, 0, 0, nXSize, nYSize, bInterlace, NULL) == GIF_ERROR ) { - GDALPrintGifError("Error writing gif file."); + GDALPrintGifError(hGifFile, "Error writing gif file."); EGifCloseFile(hGifFile); VSIFCloseL( fp ); return NULL; -- 1.7.10.4