Transform 0..255 compression factor to 0..1 quality to match Cocoa specs

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37898 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Riccardo Mottola 2014-05-21 14:52:09 +00:00
parent 94c5228058
commit 44500d28e6
3 changed files with 18 additions and 11 deletions

View file

@ -1,3 +1,9 @@
2014-05-21 Riccardo Mottola <rm@gnu.org>
* Source/NSBitmapImageRep+JPEG.m
* Source/NSBitmapImageRep.m
Transform 0..255 compression factor to 0..1 quality to match Cocoa specs.
2014-05-04 Ivan Vucica <ivan@vucica.net>
* Tests/GNUmakefile: Don't fail if 'gnustep-tests --clean' fails.

View file

@ -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
@ -600,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

View file

@ -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
@ -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.
@ -1911,7 +1911,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]