diff --git a/Source/NSBitmapImageRep+GIF.m b/Source/NSBitmapImageRep+GIF.m index a4eaa2c93..bafb98679 100644 --- a/Source/NSBitmapImageRep+GIF.m +++ b/Source/NSBitmapImageRep+GIF.m @@ -2,7 +2,7 @@ Methods for reading GIF images - Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2003-2014 Free Software Foundation, Inc. Written by: Stefan Kleine Stegemann Date: Nov 2003 @@ -41,6 +41,7 @@ #if HAVE_LIBUNGIF || HAVE_LIBGIF + /* gif_lib.h (4.1.0b1, possibly other versions) uses Object as the name of an argument to a function. This causes a conflict with Object declared by the @@ -50,6 +51,23 @@ objective-c headers. #include #undef Object +// GIF 5.0 no longer has this define +#ifndef FALSE +#define FALSE 0 +#endif /* FALSE */ + +// GIF > 5.0 +#if GIFLIB_MAJOR >= 5 + #define DGifOpen(s, i) DGifOpen(s, i, NULL) + #define EGifOpen(s, i) EGifOpen(s, i, NULL) +#endif + +// GIF> 5.1 +#if GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1 + #define DGifCloseFile(f) DGifCloseFile(f, NULL) + #define EGifCloseFile(f) EGifCloseFile(f, NULL) +#endif + /* ----------------------------------------------------------- The following types and functions are for interacting with the gif library. @@ -110,7 +128,7 @@ static void gs_gif_init_input_source(gs_gif_input_src *src, NSData *data) src->pos = 0; } -#if HAVE_QUANTIZEBUFFER +#if HAVE_QUANTIZEBUFFER || HAVE_GIFQUANTIZEBUFFER /* Function to write GIF to buffer */ static int gs_gif_output(GifFileType *file, const GifByteType *buffer, int len) { @@ -142,11 +160,7 @@ static int gs_gif_output(GifFileType *file, const GifByteType *buffer, int len) } gs_gif_init_input_source(&src, imageData); -#if GIFLIB_MAJOR >= 5 - file = DGifOpen(&src, gs_gif_input, NULL); -#else file = DGifOpen(&src, gs_gif_input); -#endif if (file == NULL) { /* we do not use giferror here because it doesn't @@ -390,7 +404,7 @@ static int gs_gif_output(GifFileType *file, const GifByteType *buffer, int len) - (NSData *) _GIFRepresentationWithProperties: (NSDictionary *) properties errorMessage: (NSString **)errorMsg { -#if HAVE_QUANTIZEBUFFER +#if HAVE_QUANTIZEBUFFER || HAVE_GIFQUANTIZEBUFFER NSMutableData * GIFRep = nil; // our return value GifFileType * GIFFile = NULL; GifByteType * rgbPlanes = NULL; // giflib needs planar RGB @@ -464,7 +478,11 @@ static int gs_gif_output(GifFileType *file, const GifByteType *buffer, int len) // If you have a color table, you must be certain that it is GIF format colorTable = [self valueForProperty: NSImageRGBColorTable]; // nil is OK colorMapSize = (colorTable)? [colorTable length]/sizeof(GifColorType) : 256; +#if GIFLIB_MAJOR >= 5 + GIFColorMap = GifMakeMapObject(colorMapSize, [colorTable bytes]); +#else GIFColorMap = MakeMapObject(colorMapSize, [colorTable bytes]); +#endif if (!GIFColorMap) { SET_ERROR_MSG(@"GIFRepresentation (giflib): MakeMapObject() failed."); @@ -478,9 +496,15 @@ static int gs_gif_output(GifFileType *file, const GifByteType *buffer, int len) SET_ERROR_MSG(@"GIFRepresentation: malloc out of memory."); free(rgbPlanes); } +#if GIFLIB_MAJOR >= 5 + status = GifQuantizeBuffer(width, height, &colorMapSize, + redPlane, greenPlane, bluePlane, + GIFImage, GIFColorMap->Colors); +#else status = QuantizeBuffer(width, height, &colorMapSize, redPlane, greenPlane, bluePlane, GIFImage, GIFColorMap->Colors); +#endif if (status == GIF_ERROR) { free(GIFImage); @@ -506,6 +530,7 @@ static int gs_gif_output(GifFileType *file, const GifByteType *buffer, int len) free(GIFImage); return nil; } + GIFFile = EGifOpen(GIFRep, gs_gif_output); status = EGifPutScreenDesc(GIFFile, width, height, 8, 0, NULL); if (status == GIF_ERROR) diff --git a/Source/NSBitmapImageRep+JPEG.m b/Source/NSBitmapImageRep+JPEG.m index 0a4e1b74a..d727c08e9 100644 --- a/Source/NSBitmapImageRep+JPEG.m +++ b/Source/NSBitmapImageRep+JPEG.m @@ -2,7 +2,7 @@ Methods for reading jpeg images - Copyright (C) 2003-2010 Free Software Foundation, Inc. + Copyright (C) 2003-2014 Free Software Foundation, Inc. Written by: Stefan Kleine Stegemann Date: Nov 2003 @@ -54,11 +54,6 @@ typedef int jpeg_boolean; #endif #endif // __MINGW32__ #include -#if defined(__CYGWIN__) -/* Cygwin uses a patched jpeg */ -#define GSTEP_PROGRESSIVE_CODEC -#endif - #include @@ -605,11 +600,12 @@ static void gs_jpeg_memory_dest_destroy (j_compress_ptr cinfo) jpeg_set_defaults (&cinfo); // set quality + // we expect a value between 0..1, 0 being lowest, 1 highest quality qualityNumber = [properties objectForKey: NSImageCompressionFactor]; if (qualityNumber != nil) { - quality = (int) ((1-[qualityNumber floatValue] / 255.0) * 100.0); + quality = (int) ([qualityNumber floatValue] * 100.0); } // set progressive mode diff --git a/Source/NSBitmapImageRep+PNG.m b/Source/NSBitmapImageRep+PNG.m index a194ec37b..0e0dc10ac 100644 --- a/Source/NSBitmapImageRep+PNG.m +++ b/Source/NSBitmapImageRep+PNG.m @@ -98,7 +98,7 @@ static void reader_func(png_structp png_struct, png_bytep data, png_infop png_info, png_end_info; int width,height; - unsigned char *buf; + unsigned char *buf = NULL; int bytes_per_row; int type,channels,depth; @@ -108,7 +108,6 @@ static void reader_func(png_structp png_struct, png_bytep data, reader_struct_t reader; - if (!(self = [super init])) return nil; @@ -137,7 +136,12 @@ static void reader_func(png_structp png_struct, png_bytep data, if (setjmp(png_jmpbuf(png_struct))) { + // We get here when an error happens during image loading png_destroy_read_struct(&png_struct, &png_info, &png_end_info); + if (buf != NULL) + { + NSZoneFree([self zone], buf); + } RELEASE(self); return nil; } @@ -212,14 +216,18 @@ static void reader_func(png_structp png_struct, png_bytep data, buf = NSZoneMalloc([self zone], bytes_per_row * height); { - unsigned char *row_pointers[height]; + png_bytep row_pointers[height]; int i; + for (i=0;iBitmap image representation. - Copyright (C) 1996, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1996-2014 Free Software Foundation, Inc. Author: Adam Fedor Date: Feb 1996 @@ -834,8 +834,8 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width, all = ((1<> 8) | (base[byte1] ^ (all >> 8)); - base[byte2] = (value & 255) | (base[byte2] ^ (all & 255)); + base[byte1] = (value >> 8) | (base[byte1] & ~(all >> 8)); + base[byte2] = (value & 255) | (base[byte2] & ~(all & 255)); } /** @@ -1498,9 +1498,9 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width, info.compression = [NSBitmapImageRep _localFromCompressionType: type]; if (factor < 0) factor = 0; - if (factor > 255) - factor = 255; - info.quality = (1 - ((float)factor)/255.0) * 100; + if (factor > 1) + factor = 1; + info.quality = factor * 100; info.numImages = 1; info.error = 0; @@ -1685,8 +1685,8 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width, /** Returns the receivers compression and compression factor, which is set either when the image is read in or by -setCompression:factor:. Factor is ignored in many compression schemes. For JPEG compression, - factor can be any value from 0 to 255, with 255 being the maximum - compression. */ + factor can be any value from 0 to 1, with 1 being the maximum + quality. */ - (void) getCompression: (NSTIFFCompression*)compression factor: (float*)factor { @@ -1712,7 +1712,7 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width, NSImageCompressionMethod NSNumber; automatically set when reading TIFF data; writing TIFF data NSImageCompressionFactor - NSNumber 0.0 to 255.0; writing JPEG data + NSNumber 0.0 to 1.0; writing JPEG data (GNUstep extension: JPEG-compressed TIFFs too) NSImageProgressive NSNumber boolean; automatically set when reading JPEG data; writing JPEG data. @@ -1761,7 +1761,8 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width, copy = (NSBitmapImageRep*)[super copyWithZone: zone]; - copy->_imageData = [_imageData copyWithZone: zone]; + copy->_properties = [_properties copyWithZone: zone]; + copy->_imageData = [_imageData mutableCopyWithZone: zone]; copy->_imagePlanes = NSZoneMalloc(zone, sizeof(unsigned char*) * MAX_PLANES); if (_imageData == nil) { @@ -1911,7 +1912,7 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width, bytesPerRow: 0 bitsPerPixel: 0]; _compression = [NSBitmapImageRep _compressionTypeFromLocal: info->compression]; - _comp_factor = 255 * (1 - ((float)info->quality)/100.0); + _comp_factor = (((float)info->quality)/100.0); // Note that Cocoa does not do this, even though the docs say it should [_properties setObject: [NSNumber numberWithUnsignedShort: _compression]