mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 09:40:50 +00:00
Merge Source/NSBimapImageRep,GIF,JPEG,PNG files
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@38662 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
630073e694
commit
6315d5f4b0
4 changed files with 59 additions and 29 deletions
|
@ -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 <stefan@wms-network.de>
|
||||
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 <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 @@ 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)
|
||||
|
|
|
@ -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 <stefan@wms-network.de>
|
||||
Date: Nov 2003
|
||||
|
@ -54,11 +54,6 @@ typedef int jpeg_boolean;
|
|||
#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 @@ 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
|
||||
|
|
|
@ -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;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
|
||||
|
|
|
@ -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 <fedor@gnu.org>
|
||||
Date: Feb 1996
|
||||
|
@ -834,8 +834,8 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
|
|||
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 @@ _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,
|
|||
<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 @@ _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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue