Change Log

Mon. 20-Nov-2006 Mark Tracy <tracy454 at concentric dot net>
Many changes related to bitmap images

1.  NSBitmapImateRep attribute global strings were not defined
    Fix: add definitions to externs.h, and declarations to NSBitmapImageRep.h
    Comment: Two strings defined in Cocoa were commented out: NSImageColorSyncData
      is proprietary to Apple, and NSImageEXIFData has no support elsewhere in
      GNUstep. I propose adding GSImageICCProfileData if and when color management
      is added to GNUstep.

2.  LZW compression in TIFF was disabled for lack of a test of its availability
    Fix: Implement NSTiffIsCodecConfigured(codec) in tiff.m
    Comment: As of libtiff-3.7.0, there is a function call in the API to test
      availability at runtime. For libtiff-3.6.0 (earlier?) there are macros
      #defined in tiffconf.h. The implementation check the library version at
      compile time, and uses one of the two methods. I have not tested the 
      second method for lack of an installation of an old libtiff.

3.  -canCompressUsing: relied on a static list of capabilities
    Fix: Use the new NSTiffIsCodecConfigured(codec) in NSBitmapImageRep.m
    Comment: The static list could be wrong, as it was on my system. Also
      eliminate the supports_lzw_compression flag.

4.  +getTIFFCompressionTypes:count: relied on a static list of compressors.
    Fix: Use the new NSTiffIsCodecConfigured(codec) in NSBitmapImageRep.m
    Comment: Compares GNUstep supported compressors against actual availability.
      Also change the private instance methods _localFromCompressionType and 
      _compressionTypeFromLocal to private class methods so that they can be used
      in -initWithTIFFImage:number: and -TIFFRepresentationUsingCompression:factor:
      and +getTIFFCompressionTypes:count: This is probably a clumsy implementation
      but it works.

5.  -setProperty:toValue: and -valueForProperty: were not implemented
    Fix: Add a new instance variable NSMutableDictionary * _properties to 
      NSBitmapImageRep.h and implemented accessors in NSBitmapImageRep.m. Patch
      -_initFromTIFFImage to set compression type and factor in _properties.
    Comment: This feature is used to pass options to and from JPEG, PNG, TIFF, and
      GIF in Cocoa, although the docs are kind of vague. In one case the Cocoa docs
      said the properties were set when reading a TIFF, but the implementation
      didn't; I chose to implement the docs. Cocoa does use properties when 
      exporting bitmaps, so I implemented that.

6.  Checked and updated NSBitmapImageFileType in NSBitmapImageRep.h
    Fix: confirmed the enumeration values against Cocoa, and added 
      NSJPEG2000FileType = 5
    Comment: JPEG-2000 is not implemented, just reserved a space for it.

7.  -representationUsingType:properties: was not implemented
    Fix: Implement export of TIFF, JPEG, GIF and PNG in NSBitmapImage.m
    Comment: See the change notes for JPEG, GIF, and PNG for more. BMP and JPEG-2000
      are not implemented; they just log a message to that effect. As apparently
      Cocoa does it this way, if you pass nil for properties, it falls back to 
      the internal _properties, and if that is empty, there are some safe defaults.

8.  +representationfOfImageRepsInArray:UsingType:properties: was not implemented
    Fix: Partially implement in NSBitmapImageRep.m
    Comment: I just stole the incomplete code from
      +TIFFRepresentationOfImageRepsInArray: since I have yet to find an explanation
      of how this really ought to work.

9.  JPEG export didn't handle alpha channel, properties or errors.
    Fix: Add -_JPEGRepresentationWithProperties:errorMessage: to
      NSBitmapImageRep+JPEG.h and greatly rework Nicolas Roard's code in
      NSBitmapImageRep+JPEG.m. Patch -_initBitmapFromJPEG:errorMessage to
      write properties.
    Comment: Major rewrite of Nicolas Roard's JPEG export code. 
    To do: Support for planar bitmaps and support for colorspaces other than
      RGB(A).

10. PNG export not implemented
    Fix: Add -_PNGRepresentationWithProperties: to
      NSBitmapImageRep+PNG.h and implement NSBitmapImageRep+PNG.m
    Comment: No support yet for planar bitmaps. Only supports 
      NS*WhiteColorSpace and NS*RGBColorSpace. Does support alpha. Support for
      reading and writing NSImageGamma is experimental. In keeping with Cocoa,
      the property NSImageGamma ranges from 0.0 to 1.0; representing the range
      of minimum supported gamma to maximum supported gamma, in this case 1.0
      to 2.5. This is in contrast to GNUstep where by convention the property
      would range from 0.0 to 255.0.
    To do: proper error message support

11. GIF export not implemented
    Fix: Add -_GIFRepresentationWithPropterties:errorMessage: to
      NSBitmapImageRep+GIF.h and implement in NSBitmapImageRep+GIF.m
    Comments: Supports only RGB(A) colorspaces, but ignores alpha. Supports
      planar or interleaved bitmaps. Supports properties NSImageRGBColorTable.

12. -_initBitmapFromGIF:errorMessage: did not support transparency
    Fix: Don't ignore control blocks in NSBitmapImageRep+GIF.m; check for
      transparency.
    Comment: If a transparent color is found, it adds an alpha channel to the 
      bitmap. Also, save the color table in properties.

13. -_initBitmapFromGIF:errorMessage: would show the last image in a 
      multi-image GIF file
    Fix: Break the parsing loop after the first image in NSBitmapImageRep+GIF.m
    Comment: Also check for frame duration, and set that property. There is not
      yet any support for animated GIF. This will require some additional 
      infrastructure, and I won't do it unless asked.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24140 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Mark Tracy 2006-11-21 06:36:26 +00:00
parent abfea70cf8
commit 9f633f60f6
11 changed files with 669 additions and 84 deletions

View file

@ -55,19 +55,14 @@
/* Maximum number of planes */
#define MAX_PLANES 5
/* FIXME: By default the libtiff library (v3.5.7 and less at least) do
not support LZW compression, but it's not possible to find out if it
does or not until after we've already written an image :-(. */
static BOOL supports_lzw_compression = NO;
/* Backend methods (optional) */
@interface NSBitmapImageRep (GSPrivate)
// GNUstep extension
- _initFromTIFFImage: (TIFF *)image number: (int)imageNumber;
// Internal
- (int) _localFromCompressionType: (NSTIFFCompression)type;
- (NSTIFFCompression) _compressionTypeFromLocal: (int)type;
+ (int) _localFromCompressionType: (NSTIFFCompression)type;
+ (NSTIFFCompression) _compressionTypeFromLocal: (int)type;
@end
/**
@ -526,6 +521,7 @@ static BOOL supports_lzw_compression = NO;
{
[self setOpaque: YES];
}
_properties = [[NSMutableDictionary alloc] init];
return self;
}
@ -555,6 +551,7 @@ static BOOL supports_lzw_compression = NO;
{
NSZoneFree([self zone],_imagePlanes);
RELEASE(_imageData);
RELEASE(_properties);
[super dealloc];
}
@ -763,7 +760,7 @@ static BOOL supports_lzw_compression = NO;
}
info.extraSamples = (_hasAlpha) ? 1 : 0;
info.compression = [self _localFromCompressionType: type];
info.compression = [NSBitmapImageRep _localFromCompressionType: type];
if (factor < 0)
factor = 0;
if (factor > 255)
@ -790,23 +787,81 @@ static BOOL supports_lzw_compression = NO;
usingType:(NSBitmapImageFileType)storageType
properties:(NSDictionary *)properties
{
// TODO
// Partial implementation only returns data for the first imageRep in the array
// and only works for NSBitmapImageRep or subclasses thereof.
//FIXME: This only outputs one of the ImageReps
NSEnumerator *enumerator = [imageReps objectEnumerator];
NSImageRep *rep;
while ((rep = [enumerator nextObject]) != nil)
{
if ([rep isKindOfClass: self])
{
return [(NSBitmapImageRep*)rep representationUsingType: storageType
properties: properties];
}
}
return nil;
}
- (NSData *)representationUsingType:(NSBitmapImageFileType)storageType
properties:(NSDictionary *)properties
{
// TODO
// if it exists, the passed in properties takes precedence over the internal _properties
NSDictionary * __properties;
__properties = (properties)? properties : (NSDictionary *)_properties;
switch (storageType)
{
case NSTIFFFileType:
{
NSNumber * property;
float factor = _comp_factor;
NSTIFFCompression compression = _compression;
if ((property = [__properties objectForKey: NSImageCompressionMethod]))
compression = [property unsignedShortValue];
if ((property = [__properties objectForKey: NSImageCompressionFactor]))
factor = [property floatValue];
if ([self canBeCompressedUsing: compression] == NO)
{
factor = 0.0;
compression = NSTIFFCompressionNone;
}
return [self TIFFRepresentationUsingCompression: compression factor: factor];
}
case NSBMPFileType:
NSLog(@"BMP representation is not yet implemented");
return nil;
case NSGIFFileType:
return [self _GIFRepresentationWithProperties: __properties
errorMessage: NULL];
case NSJPEGFileType:
return [self _JPEGRepresentationWithProperties: __properties
errorMessage: NULL];
case NSPNGFileType:
return [self _PNGRepresentationWithProperties: __properties];
case NSJPEG2000FileType:
NSLog(@"JPEG2000 representation is not yet implemented");
return nil;
}
return nil;
}
//
// Setting and Checking Compression Types
//
/** Returns a C-array of available TIFF compression types.
*/
+ (void) getTIFFCompressionTypes: (const NSTIFFCompression **)list
count: (int *)numTypes
{
// the GNUstep supported types
static NSTIFFCompression types[] = {
NSTIFFCompressionNone,
NSTIFFCompressionCCITTFAX3,
@ -817,11 +872,22 @@ static BOOL supports_lzw_compression = NO;
NSTIFFCompressionPackBits,
NSTIFFCompressionOldJPEG
};
// check with libtiff to see what is really available
int i, j;
static NSTIFFCompression checkedTypes[8];
for (i = 0, j = 0; i < 8; i++)
{
if (NSTiffIsCodecConfigured([NSBitmapImageRep _localFromCompressionType: types[i]]))
{
checkedTypes[j] = types[i];
j++;
}
}
if (list)
*list = types;
*list = checkedTypes;
if (numTypes)
*numTypes = sizeof(types)/sizeof(*types);
*numTypes = j;
}
+ (NSString*) localizedNameForTIFFCompressionType: (NSTIFFCompression)type
@ -845,30 +911,26 @@ static BOOL supports_lzw_compression = NO;
- (BOOL) canBeCompressedUsing: (NSTIFFCompression)compression
{
BOOL does;
int codecConf =
NSTiffIsCodecConfigured([NSBitmapImageRep _localFromCompressionType: compression]);
switch (compression)
{
case NSTIFFCompressionCCITTFAX3:
case NSTIFFCompressionCCITTFAX4:
if (_numColors == 1 && _bitsPerSample == 1)
if (_numColors == 1 && _bitsPerSample == 1 && codecConf != 0)
does = YES;
else
does = NO;
break;
case NSTIFFCompressionLZW:
does = supports_lzw_compression;
break;
case NSTIFFCompressionNone:
case NSTIFFCompressionJPEG:
case NSTIFFCompressionJPEG: // this is a GNUstep extension; Cocoa does not support
case NSTIFFCompressionPackBits:
case NSTIFFCompressionOldJPEG:
does = YES;
break;
case NSTIFFCompressionNEXT:
default:
does = NO;
does = (codecConf != 0);
}
return does;
}
@ -894,13 +956,19 @@ static BOOL supports_lzw_compression = NO;
- (void)setProperty:(NSString *)property withValue:(id)value
{
// TODO
if (value)
{
[_properties setObject: value forKey: property];
}
else // clear the property
{
[_properties removeObjectForKey: property];
}
}
- (id)valueForProperty:(NSString *)property
{
// TODO
return nil;
return [_properties objectForKey: property];
}
// NSCopying protocol
@ -978,7 +1046,7 @@ static BOOL supports_lzw_compression = NO;
@implementation NSBitmapImageRep (GSPrivate)
- (int) _localFromCompressionType: (NSTIFFCompression)type
+ (int) _localFromCompressionType: (NSTIFFCompression)type
{
switch (type)
{
@ -996,7 +1064,7 @@ static BOOL supports_lzw_compression = NO;
return COMPRESSION_NONE;
}
- (NSTIFFCompression) _compressionTypeFromLocal: (int)type
+ (NSTIFFCompression) _compressionTypeFromLocal: (int)type
{
switch (type)
{
@ -1057,9 +1125,15 @@ static BOOL supports_lzw_compression = NO;
colorSpaceName: space
bytesPerRow: 0
bitsPerPixel: 0];
_compression = [self _compressionTypeFromLocal: info->compression];
_compression = [NSBitmapImageRep _compressionTypeFromLocal: info->compression];
_comp_factor = 255 * (1 - ((float)info->quality)/100.0);
// Note that Cocoa does not do this, even though the docs say it should
[_properties setObject: [NSNumber numberWithUnsignedShort: _compression]
forKey: NSImageCompressionMethod];
[_properties setObject: [NSNumber numberWithFloat: _comp_factor]
forKey: NSImageCompressionFactor];
if (NSTiffRead(image, info, [self bitmapData]))
{
OBJC_FREE(info);