"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/gifcodec.c" between
libgdiplus-3.12.tar.gz and libgdiplus-4.2.tar.gz

About: libgdiplus is an Open Source implementation of the GDI+ API (part of the Mono project).

gifcodec.c  (libgdiplus-3.12):gifcodec.c  (libgdiplus-4.2)
skipping to change at line 42 skipping to change at line 42
#include "gdiplus-private.h" #include "gdiplus-private.h"
GUID gdip_gif_image_format_guid = {0xb96b3cb0U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0 x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e}}; GUID gdip_gif_image_format_guid = {0xb96b3cb0U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0 x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e}};
#ifdef HAVE_LIBGIF #ifdef HAVE_LIBGIF
#include <gif_lib.h> #include <gif_lib.h>
#include "gifcodec.h" #include "gifcodec.h"
#ifdef EgifOpen
/* giflib declares this incorrectly as EgifOpen */
extern GifFileType *EGifOpen(void *userData, OutputFunc writeFunc);
#endif
/* Data structure used for callback */ /* Data structure used for callback */
typedef struct typedef struct
{ {
GetBytesDelegate getBytesFunc; GetBytesDelegate getBytesFunc;
SeekDelegate seekFunc; SeekDelegate seekFunc;
} gif_callback_data; } gif_callback_data;
/* Codecinfo related data*/ /* Codecinfo related data*/
static ImageCodecInfo gif_codec; static ImageCodecInfo gif_codec;
skipping to change at line 109 skipping to change at line 104
return read; return read;
} }
/* /*
This is the DGifSlurp and AddExtensionBlock code courtesy of giflib, This is the DGifSlurp and AddExtensionBlock code courtesy of giflib,
It's modified to not dump comments after the image block, since those It's modified to not dump comments after the image block, since those
are still valid are still valid
*/ */
static int static int
AddExtensionBlockMono(SavedImage *New, int Len, BYTE ExtData[]) AddExtensionBlockMono(SavedImage *New, int Function, int Len, BYTE ExtData[])
{ {
ExtensionBlock *ep; ExtensionBlock *ep;
if (New->ExtensionBlocks == NULL) { if (New->ExtensionBlocks == NULL) {
New->ExtensionBlocks=(ExtensionBlock *)GdipAlloc(sizeof(Extension Block)); New->ExtensionBlocks=(ExtensionBlock *)GdipAlloc(sizeof(Extension Block));
} else { } else {
New->ExtensionBlocks = (ExtensionBlock*) gdip_realloc (New->Exten sionBlocks, sizeof(ExtensionBlock) * (New->ExtensionBlockCount + 1)); New->ExtensionBlocks = (ExtensionBlock*) gdip_realloc (New->Exten sionBlocks, sizeof(ExtensionBlock) * (New->ExtensionBlockCount + 1));
} }
if (New->ExtensionBlocks == NULL) { if (New->ExtensionBlocks == NULL) {
return (GIF_ERROR); return (GIF_ERROR);
} }
ep = &New->ExtensionBlocks[New->ExtensionBlockCount++]; ep = &New->ExtensionBlocks[New->ExtensionBlockCount++];
ep->Function = Function;
ep->ByteCount=Len; ep->ByteCount=Len;
ep->Bytes = (char *)GdipAlloc(ep->ByteCount); ep->Bytes = (GifByteType *)GdipAlloc(ep->ByteCount);
if (ep->Bytes == NULL) { if (ep->Bytes == NULL) {
return (GIF_ERROR); return (GIF_ERROR);
} }
if (ExtData) { if (ExtData) {
memcpy(ep->Bytes, ExtData, Len); memcpy(ep->Bytes, ExtData, Len);
ep->Function = New->Function;
} }
return (GIF_OK); return (GIF_OK);
} }
static void static void
FreeExtensionMono(SavedImage *Image) FreeExtensionMono(SavedImage *Image)
{ {
ExtensionBlock *ep; ExtensionBlock *ep;
skipping to change at line 170 skipping to change at line 165
if (DGifGetLine(GifFile, &sp->RasterBits[index], sp->ImageDesc.Wi dth) == GIF_ERROR) if (DGifGetLine(GifFile, &sp->RasterBits[index], sp->ImageDesc.Wi dth) == GIF_ERROR)
return GIF_ERROR; return GIF_ERROR;
} }
return GIF_OK; return GIF_OK;
} }
static int static int
DGifSlurpMono(GifFileType * GifFile, SavedImage *TrailingExtensions) DGifSlurpMono(GifFileType * GifFile, SavedImage *TrailingExtensions)
{ {
int ImageSize; int ImageSize;
int Function;
GifRecordType RecordType; GifRecordType RecordType;
SavedImage *sp; SavedImage *sp;
GifByteType *ExtData; GifByteType *ExtData;
SavedImage temp_save; SavedImage temp_save;
temp_save.ExtensionBlocks = NULL; temp_save.ExtensionBlocks = NULL;
temp_save.ExtensionBlockCount = 0; temp_save.ExtensionBlockCount = 0;
if (TrailingExtensions != NULL) { if (TrailingExtensions != NULL) {
TrailingExtensions->ExtensionBlocks = NULL; TrailingExtensions->ExtensionBlocks = NULL;
skipping to change at line 236 skipping to change at line 232
sp->ExtensionBlocks = temp_save.Extension Blocks; sp->ExtensionBlocks = temp_save.Extension Blocks;
sp->ExtensionBlockCount = temp_save.Exten sionBlockCount; sp->ExtensionBlockCount = temp_save.Exten sionBlockCount;
temp_save.ExtensionBlocks = NULL; temp_save.ExtensionBlocks = NULL;
temp_save.ExtensionBlockCount = 0; temp_save.ExtensionBlockCount = 0;
} }
break; break;
} }
case EXTENSION_RECORD_TYPE: { case EXTENSION_RECORD_TYPE: {
if (DGifGetExtension(GifFile, &temp_save.Function , &ExtData) == GIF_ERROR) { if (DGifGetExtension(GifFile, &Function, &ExtData ) == GIF_ERROR) {
return (GIF_ERROR); return (GIF_ERROR);
} }
while (ExtData != NULL) { while (ExtData != NULL) {
/* Create an extension block with our dat a */ /* Create an extension block with our dat a */
if (AddExtensionBlockMono(&temp_save, Ext Data[0], &ExtData[1]) == GIF_ERROR) { if (AddExtensionBlockMono(&temp_save, Fun ction, ExtData[0], &ExtData[1]) == GIF_ERROR) {
return (GIF_ERROR); return (GIF_ERROR);
} }
if (DGifGetExtensionNext(GifFile, &ExtDat a) == GIF_ERROR) { if (DGifGetExtensionNext(GifFile, &ExtDat a) == GIF_ERROR) {
return (GIF_ERROR); return (GIF_ERROR);
} }
temp_save.Function = 0;
} }
break; break;
} }
case TERMINATE_RECORD_TYPE: { case TERMINATE_RECORD_TYPE: {
break; break;
} }
default: { /* Should be trapped by DGifGetRecordType */ default: { /* Should be trapped by DGifGetRecordType */
break; break;
skipping to change at line 307 skipping to change at line 302
GifImageDesc *img_desc; GifImageDesc *img_desc;
disposal = 0; disposal = 0;
last_disposal = 0; last_disposal = 0;
loop_value = 0; loop_value = 0;
global_palette = NULL; global_palette = NULL;
result = NULL; result = NULL;
loop_counter = FALSE; loop_counter = FALSE;
if (from_file) { if (from_file) {
#if GIFLIB_MAJOR >= 5
gif = DGifOpen(stream, &gdip_gif_fileinputfunc, NULL);
#else
gif = DGifOpen(stream, &gdip_gif_fileinputfunc); gif = DGifOpen(stream, &gdip_gif_fileinputfunc);
#endif
} else { } else {
#if GIFLIB_MAJOR >= 5
gif = DGifOpen (stream, &gdip_gif_inputfunc, NULL);
#else
gif = DGifOpen (stream, &gdip_gif_inputfunc); gif = DGifOpen (stream, &gdip_gif_inputfunc);
#endif
} }
if (gif == NULL) { if (gif == NULL) {
goto error; goto error;
} }
/* Read the image */ /* Read the image */
if (DGifSlurpMono(gif, &global_extensions) != GIF_OK) { if (DGifSlurpMono(gif, &global_extensions) != GIF_OK) {
goto error; goto error;
} }
skipping to change at line 584 skipping to change at line 587
disposal = 0; disposal = 0;
} }
gdip_bitmap_setactive(result, dimension, 0); gdip_bitmap_setactive(result, dimension, 0);
if (global_palette != NULL) { if (global_palette != NULL) {
GdipFree(global_palette); GdipFree(global_palette);
} }
FreeExtensionMono(&global_extensions); FreeExtensionMono(&global_extensions);
#if (GIFLIB_MAJOR > 5) || ((GIFLIB_MAJOR == 5) && (GIFLIB_MINOR >= 1))
DGifCloseFile (gif, NULL);
#else
DGifCloseFile (gif); DGifCloseFile (gif);
#endif
*image = result; *image = result;
return Ok; return Ok;
error: error:
if (global_palette != NULL) { if (global_palette != NULL) {
GdipFree(global_palette); GdipFree(global_palette);
} }
if (result != NULL) { if (result != NULL) {
gdip_bitmap_dispose (result); gdip_bitmap_dispose (result);
} }
if (gif != NULL) { if (gif != NULL) {
FreeExtensionMono (&global_extensions); FreeExtensionMono (&global_extensions);
#if (GIFLIB_MAJOR > 5) || ((GIFLIB_MAJOR == 5) && (GIFLIB_MINOR >= 1))
DGifCloseFile (gif, NULL);
#else
DGifCloseFile (gif); DGifCloseFile (gif);
#endif
} }
*image = NULL; *image = NULL;
return InvalidParameter; return InvalidParameter;
} }
GpStatus GpStatus
gdip_load_gif_image_from_file (FILE *fp, GpImage **image) gdip_load_gif_image_from_file (FILE *fp, GpImage **image)
{ {
return gdip_load_gif_image (fp, image, TRUE); return gdip_load_gif_image (fp, image, TRUE);
skipping to change at line 664 skipping to change at line 674
BOOL animated; BOOL animated;
int frame; int frame;
BitmapData *bitmap_data; BitmapData *bitmap_data;
int pixbuf_size; int pixbuf_size;
if (!stream) { if (!stream) {
return InvalidParameter; return InvalidParameter;
} }
if (from_file) { if (from_file) {
#if GIFLIB_MAJOR >= 5
fp = EGifOpenFileName (stream, 0, NULL);
#else
fp = EGifOpenFileName (stream, 0); fp = EGifOpenFileName (stream, 0);
#endif
} else { } else {
#if GIFLIB_MAJOR >= 5
fp = EGifOpen (stream, gdip_gif_outputfunc, NULL);
#else
fp = EGifOpen (stream, gdip_gif_outputfunc); fp = EGifOpen (stream, gdip_gif_outputfunc);
#endif
} }
if (!fp) { if (!fp) {
return FileNotFound; return FileNotFound;
} }
red = NULL; red = NULL;
green = NULL; green = NULL;
blue = NULL; blue = NULL;
pixbuf_org = NULL; pixbuf_org = NULL;
skipping to change at line 705 skipping to change at line 723
case PixelFormat4bppIndexed: case PixelFormat4bppIndexed:
cmap_size = 16; cmap_size = 16;
break; break;
case PixelFormat8bppIndexed: case PixelFormat8bppIndexed:
cmap_size = 256; cmap_size = 256;
break; break;
default: default:
goto error; goto error;
} }
#if GIFLIB_MAJOR >= 5
cmap = GifMakeMapObject(cmap_size, 0);
#else
cmap = MakeMapObject(cmap_size, 0); cmap = MakeMapObject(cmap_size, 0);
#endif
pixbuf = GdipAlloc(pixbuf_size); pixbuf = GdipAlloc(pixbuf_size);
if (pixbuf == NULL) { if (pixbuf == NULL) {
goto error; goto error;
} }
pixbuf_org = pixbuf; pixbuf_org = pixbuf;
for (c = 0; (c < cmap_size) && (c < bitmap_data-> palette->Count); c++) { for (c = 0; (c < cmap_size) && (c < bitmap_data-> palette->Count); c++) {
v = (BYTE*)&bitmap_data->palette->Entries [c]; v = (BYTE*)&bitmap_data->palette->Entries [c];
skipping to change at line 796 skipping to change at line 817
bitmap_data->scan0 + y * bitmap_data->stride, bitmap_data->scan0 + y * bitmap_data->stride,
bitmap_data->width ); bitmap_data->width );
} }
break; break;
} }
} }
/* Restore pointer, 1bpp and 4bpp above alter it */ /* Restore pointer, 1bpp and 4bpp above alter it */
pixbuf = pixbuf_org; pixbuf = pixbuf_org;
} else { } else {
cmap_size = 256; cmap_size = 256;
#if GIFLIB_MAJOR >= 5
cmap = GifMakeMapObject (cmap_size, 0);
#else
cmap = MakeMapObject (cmap_size, 0); cmap = MakeMapObject (cmap_size, 0);
#endif
red = GdipAlloc(pixbuf_size); red = GdipAlloc(pixbuf_size);
green = GdipAlloc(pixbuf_size); green = GdipAlloc(pixbuf_size);
blue = GdipAlloc(pixbuf_size); blue = GdipAlloc(pixbuf_size);
pixbuf = GdipAlloc(pixbuf_size); pixbuf = GdipAlloc(pixbuf_size);
if ((red == NULL) || (green == NULL) || (blue == NULL) || (pixbuf == NULL)) { if ((red == NULL) || (green == NULL) || (blue == NULL) || (pixbuf == NULL)) {
goto error; goto error;
} }
pixbuf_org = pixbuf; pixbuf_org = pixbuf;
red_ptr = red; red_ptr = red;
skipping to change at line 827 skipping to change at line 851
*blue_ptr++ = v[3]; *blue_ptr++ = v[3];
#else #else
*red_ptr++ = v[2]; *red_ptr++ = v[2];
*green_ptr++ = v[1]; *green_ptr++ = v[1];
*blue_ptr++ = v[0]; *blue_ptr++ = v[0];
#endif #endif
v += 4; v += 4;
} }
} }
if (QuantizeBuffer(bitmap_data->width, bitmap_dat if (
a->height, &cmap_size, #if GIFLIB_MAJOR >= 5
GifQuantizeBuffer(
#else
QuantizeBuffer(
#endif
bitmap_data->width, bitmap_data->
height, &cmap_size,
red, green, blue, pixbuf, cmap-> Colors) == GIF_ERROR) { red, green, blue, pixbuf, cmap-> Colors) == GIF_ERROR) {
goto error; goto error;
} }
} }
#if GIFLIB_MAJOR >= 5
cmap->BitsPerPixel = GifBitSize (cmap_size);
#else
cmap->BitsPerPixel = BitSize (cmap_size); cmap->BitsPerPixel = BitSize (cmap_size);
#endif
cmap->ColorCount = 1 << cmap->BitsPerPixel; cmap->ColorCount = 1 << cmap->BitsPerPixel;
if ((frame == 0) && (k == 0)) { if ((frame == 0) && (k == 0)) {
/* First Image defines the global colormap */ /* First Image defines the global colormap */
if (EGifPutScreenDesc (fp, bitmap_data->width, bi tmap_data->height, cmap->BitsPerPixel, 0, cmap) == GIF_ERROR) { if (EGifPutScreenDesc (fp, bitmap_data->width, bi tmap_data->height, cmap->BitsPerPixel, 0, cmap) == GIF_ERROR) {
goto error; goto error;
} }
/* An animated image must have the application ex tension */ /* An animated image must have the application ex tension */
if (animated) { if (animated) {
/* Store the LoopCount extension */ /* Store the LoopCount extension */
if (gdip_bitmapdata_property_find_id(bitm ap_data, PropertyTagLoopCount, &index) == Ok) { if (gdip_bitmapdata_property_find_id(bitm ap_data, PropertyTagLoopCount, &index) == Ok) {
BYTE Buffer[3]; BYTE Buffer[3];
BYTE *ptr = bitmap_data->property [index].value; BYTE *ptr = bitmap_data->property [index].value;
Buffer[0] = 1; Buffer[0] = 1;
Buffer[1] = ptr[0]; Buffer[1] = ptr[0];
Buffer[2] = ptr[1]; Buffer[2] = ptr[1];
#if GIFLIB_MAJOR >= 5
EGifPutExtensionLeader(fp, APPLIC
ATION_EXT_FUNC_CODE);
EGifPutExtensionBlock(fp, 11, "NE
TSCAPE2.0");
EGifPutExtensionBlock(fp, 3, Buff
er);
EGifPutExtensionTrailer(fp);
#else
EGifPutExtensionFirst(fp, APPLICA TION_EXT_FUNC_CODE, 11, "NETSCAPE2.0"); EGifPutExtensionFirst(fp, APPLICA TION_EXT_FUNC_CODE, 11, "NETSCAPE2.0");
EGifPutExtensionLast(fp, APPLICAT ION_EXT_FUNC_CODE, 3, Buffer); EGifPutExtensionLast(fp, APPLICAT ION_EXT_FUNC_CODE, 3, Buffer);
#endif
} }
} }
if (gdip_bitmapdata_property_find_id(bitmap_data, PropertyTagExifUserComment, &index) == Ok) { if (gdip_bitmapdata_property_find_id(bitmap_data, PropertyTagExifUserComment, &index) == Ok) {
EGifPutComment(fp, (const char *)bitmap_d ata->property[index].value); EGifPutComment(fp, (const char *)bitmap_d ata->property[index].value);
} }
} }
/* Every image has a control extension specifying the tim e delay */ /* Every image has a control extension specifying the tim e delay */
if (animated || bitmap_data->transparent < 0) { if (animated || bitmap_data->transparent < 0) {
skipping to change at line 904 skipping to change at line 945
goto error; goto error;
} }
for (i = 0; i < bitmap_data->height; ++i) { for (i = 0; i < bitmap_data->height; ++i) {
if (EGifPutLine (fp, pixbuf, bitmap_data->width) == GIF_ERROR) { if (EGifPutLine (fp, pixbuf, bitmap_data->width) == GIF_ERROR) {
goto error; goto error;
} }
pixbuf += bitmap_data->width; pixbuf += bitmap_data->width;
} }
#if GIFLIB_MAJOR >= 5
GifFreeMapObject (cmap);
#else
FreeMapObject (cmap); FreeMapObject (cmap);
#endif
if (red != NULL) { if (red != NULL) {
GdipFree (red); GdipFree (red);
} }
if (green != NULL) { if (green != NULL) {
GdipFree (green); GdipFree (green);
} }
if (blue != NULL) { if (blue != NULL) {
GdipFree (blue); GdipFree (blue);
} }
skipping to change at line 926 skipping to change at line 971
GdipFree (pixbuf_org); GdipFree (pixbuf_org);
} }
red = NULL; red = NULL;
green = NULL; green = NULL;
blue = NULL; blue = NULL;
pixbuf_org = NULL; pixbuf_org = NULL;
} }
} }
#if (GIFLIB_MAJOR > 5) || ((GIFLIB_MAJOR == 5) && (GIFLIB_MINOR >= 1))
EGifCloseFile (fp, NULL);
#else
EGifCloseFile (fp); EGifCloseFile (fp);
#endif
return Ok; return Ok;
error: error:
if (cmap != NULL) { if (cmap != NULL) {
#if GIFLIB_MAJOR >= 5
GifFreeMapObject (cmap);
#else
FreeMapObject (cmap); FreeMapObject (cmap);
#endif
} }
if (red != NULL) { if (red != NULL) {
GdipFree (red); GdipFree (red);
} }
if (green != NULL) { if (green != NULL) {
GdipFree (green); GdipFree (green);
} }
 End of changes. 36 change blocks. 
16 lines changed or deleted 72 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS