Author: mlytwyn
Date: Sat Jun 20 18:37:34 2015
New Revision: 38662
URL: http://svn.gna.org/viewcvs/gnustep?rev=38662&view=rev
Log:
Merge Source/NSBimapImageRep,GIF,JPEG,PNG files
Modified:
libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+GIF.m
libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+JPEG.m
libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+PNG.m
libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep.m
Modified:
libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+GIF.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep%2BGIF.m?rev=38662&r1=38661&r2=38662&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+GIF.m
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+GIF.m
Sat Jun 20 18:37:34 2015
@@ -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 <[email protected]>
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 @@
#include <gif_lib.h>
#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 @@
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 @@
}
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 @@
- (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 @@
// 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 @@
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 @@
free(GIFImage);
return nil;
}
+
GIFFile = EGifOpen(GIFRep, gs_gif_output);
status = EGifPutScreenDesc(GIFFile, width, height, 8, 0, NULL);
if (status == GIF_ERROR)
Modified:
libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+JPEG.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep%2BJPEG.m?rev=38662&r1=38661&r2=38662&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+JPEG.m
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+JPEG.m
Sat Jun 20 18:37:34 2015
@@ -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 <[email protected]>
Date: Nov 2003
@@ -54,11 +54,6 @@
#endif
#endif // __MINGW32__
#include <jpeglib.h>
-#if defined(__CYGWIN__)
-/* Cygwin uses a patched jpeg */
-#define GSTEP_PROGRESSIVE_CODEC
-#endif
-
#include <setjmp.h>
@@ -605,11 +600,12 @@
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
Modified:
libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+PNG.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep%2BPNG.m?rev=38662&r1=38661&r2=38662&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+PNG.m
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep+PNG.m
Sat Jun 20 18:37:34 2015
@@ -98,7 +98,7 @@
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 @@
reader_struct_t reader;
-
if (!(self = [super init]))
return nil;
@@ -137,7 +136,12 @@
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 @@
buf = NSZoneMalloc([self zone], bytes_per_row * height);
{
- unsigned char *row_pointers[height];
+ png_bytep row_pointers[height];
int i;
+
for (i=0;i<height;i++)
+ {
row_pointers[i]=buf+i*bytes_per_row;
+ }
+
png_read_image(png_struct, row_pointers);
}
- [self initWithBitmapDataPlanes: &buf
+ self = [self initWithBitmapDataPlanes: &buf
pixelsWide: width
pixelsHigh: height
bitsPerSample: depth
Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep.m?rev=38662&r1=38661&r2=38662&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep.m
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSBitmapImageRep.m
Sat Jun 20 18:37:34 2015
@@ -2,7 +2,7 @@
<abstract>Bitmap image representation.</abstract>
- Copyright (C) 1996, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1996-2014 Free Software Foundation, Inc.
Author: Adam Fedor <[email protected]>
Date: Feb 1996
@@ -834,8 +834,8 @@
all = ((1<<bit_width)-1) << shift;
if (byte1 != byte2)
- base[byte1] = (value >> 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 @@
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 @@
/** 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 @@
<term> NSImageCompressionMethod </term>
<desc> NSNumber; automatically set when reading TIFF data; writing TIFF
data </desc>
<term> NSImageCompressionFactor </term>
- <desc> NSNumber 0.0 to 255.0; writing JPEG data
+ <desc> NSNumber 0.0 to 1.0; writing JPEG data
(GNUstep extension: JPEG-compressed TIFFs too) </desc>
<term> NSImageProgressive </term>
<desc> NSNumber boolean; automatically set when reading JPEG data; writing
JPEG data.
@@ -1761,7 +1761,8 @@
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 @@
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]
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs