Only in gnustep-gui-0.11.0-bitmap/Headers/Additions/GNUstepGUI: GSVersion.h
diff -ru gnustep-gui-0.11.0/Headers/AppKit/NSBitmapImageRep.h gnustep-gui-0.11.0-bitmap/Headers/AppKit/NSBitmapImageRep.h
--- gnustep-gui-0.11.0/Headers/AppKit/NSBitmapImageRep.h	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Headers/AppKit/NSBitmapImageRep.h	2006-10-30 09:06:26.000000000 -0800
@@ -30,6 +30,7 @@
 #define _GNUstep_H_NSBitmapImageRep
 
 #include <AppKit/NSImageRep.h>
+#include <Foundation/NSDictionary.h>
 
 @class NSArray;
 @class NSString;
@@ -42,21 +43,37 @@
   NSTIFFCompressionCCITTFAX3,
   NSTIFFCompressionCCITTFAX4,
   NSTIFFCompressionLZW,
+  NSTIFFCompressionOldJPEG,
   NSTIFFCompressionJPEG,
   NSTIFFCompressionNEXT,
-  NSTIFFCompressionPackBits,
-  NSTIFFCompressionOldJPEG
+  NSTIFFCompressionPackBits
 } NSTIFFCompression;
 
 #ifndef STRICT_OPENSTEP
-// FIXME: This is probably wrong
 typedef enum _NSBitmapImageFileType {
     NSTIFFFileType = 0,
     NSBMPFileType = 1,
     NSGIFFileType = 2,
     NSJPEGFileType = 3,
-    NSPNGFileType = 4
+    NSPNGFileType = 4,
+    NSJPEG2000FileType = 5  // available in Mac OS X v10.4
 } NSBitmapImageFileType;
+
+APPKIT_EXPORT NSString *NSImageCompressionMethod;  // NSNumber; only for TIFF files
+APPKIT_EXPORT NSString *NSImageCompressionFactor;  // NSNumber 0.0 to 255.0; only for JPEG files (GNUstep extension: JPEG-compressed TIFFs too)
+APPKIT_EXPORT NSString *NSImageDitherTranparency;  // NSNumber boolean; only for writing GIF files
+APPKIT_EXPORT NSString *NSImageRGBColorTable;  // NSData; only for reading & writing GIF files
+APPKIT_EXPORT NSString *NSImageInterlaced;  // NSNumber boolean; only for writing PNG files
+//APPKIT_EXPORT NSString *NSImageColorSyncProfileData; // Mac OX X only
+//APPKIT_EXPORT NSString *GSImageICCProfileData;  // if & when color management comes to GNUstep
+APPKIT_EXPORT NSString *NSImageFrameCount;  // NSNumber integer; only for reading animated GIF files
+APPKIT_EXPORT NSString *NSImageCurrentFrame; // NSNumber integer; only for animated GIF files
+APPKIT_EXPORT NSString *NSImageCurrentFrameDuration;  // NSNumber float; only for reading animated GIF files
+APPKIT_EXPORT NSString *NSImageLoopCount; // NSNumber integer; only for reading animated GIF files
+APPKIT_EXPORT NSString *NSImageGamma; // NSNumber 0.0 to 1.0; only for reading & writing PNG files
+APPKIT_EXPORT NSString *NSImageProgressive; // NSNumber boolean; only for reading & writing JPEG files
+//APPKIT_EXPORT NSString *NSImageEXIFData; // No GNUstep support yet; for reading & writing JPEG
+
 #endif
 
 @interface NSBitmapImageRep : NSImageRep
@@ -65,8 +82,9 @@
   unsigned int		_bytesPerRow;
   unsigned int		_numColors;
   unsigned int		_bitsPerPixel;   
-  unsigned short	_compression;
+  unsigned short  	_compression;
   float			_comp_factor;
+  NSMutableDictionary   *_properties;
   BOOL			_isPlanar;
   unsigned char		**_imagePlanes;
   NSMutableData		*_imageData;
Only in gnustep-gui-0.11.0-bitmap/Headers/AppKit: NSBitmapImageRep.h~
diff -ru gnustep-gui-0.11.0/Source/externs.m gnustep-gui-0.11.0-bitmap/Source/externs.m
--- gnustep-gui-0.11.0/Source/externs.m	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/externs.m	2006-10-30 08:56:47.000000000 -0800
@@ -96,6 +96,22 @@
 NSString *NSApplicationWillUnhideNotification = @"ApplicationWillUnhide";
 NSString *NSApplicationWillUpdateNotification = @"ApplicationWillUpdate";
 
+// NSBitmapImageRep Global strings
+NSString *NSImageCompressionMethod = @"NSImageCompressionMethod";
+NSString *NSImageCompressionFactor = @"NSImageCompressionFactor";
+NSString *NSImageDitherTransparency = @"NSImageDitherTransparency";
+NSString *NSImageRGBColorTable = @"NSImageRGBColorTable";
+NSString *NSImageInterlaced = @"NSImageInterlaced";
+//NSString *NSImageColorSyncProfileData = @"NSImageColorSyncProfileData";  // Mac OS X only
+//NSString *GSImageICCProfileData = @"GSImageICCProfileData";  // if & when GNUstep supports color management
+NSString *NSImageFrameCount = @"NSImageFrameCount";
+NSString *NSImageCurrentFrame = @"NSImageCurrentFrame";
+NSString *NSImageCurrentFrameDuration = @"NSImageCurrentFrameDuration";
+NSString *NSImageLoopCount = @"NSImageLoopCount";
+NSString *NSImageGamma = @"NSImageGamma";
+NSString *NSImageProgressive = @"NSImageProgressive";
+//NSString *NSImageEXIFData = @"NSImageEXIFData";  // No support yet in GNUstep
+
 // NSColor Global strings
 NSString *NSCalibratedWhiteColorSpace = @"NSCalibratedWhiteColorSpace";
 NSString *NSCalibratedBlackColorSpace = @"NSCalibratedBlackColorSpace";
Only in gnustep-gui-0.11.0-bitmap/Source: Info-gnustep.plist
Only in gnustep-gui-0.11.0/Source: libgnustep-gui.def
diff -ru gnustep-gui-0.11.0/Source/NSBitmapImageRep+GIF.h gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+GIF.h
--- gnustep-gui-0.11.0/Source/NSBitmapImageRep+GIF.h	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+GIF.h	2006-10-24 04:32:22.000000000 -0700
@@ -35,6 +35,7 @@
 + (BOOL) _bitmapIsGIF: (NSData *)imageData;
 - (id) _initBitmapFromGIF: (NSData *)imageData
              errorMessage: (NSString **)errorMsg;
+- (NSData *) _GIFRepresentationWithProperties: (NSDictionary *) properties;
 
 @end
 
diff -ru gnustep-gui-0.11.0/Source/NSBitmapImageRep+GIF.m gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+GIF.m
--- gnustep-gui-0.11.0/Source/NSBitmapImageRep+GIF.m	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+GIF.m	2006-10-24 04:32:09.000000000 -0700
@@ -334,6 +334,12 @@
   return self;
 }
 
+- (NSData *) _GIFRepresentationWithProperties: (NSDictionary *) properties
+{
+  NSLog(@"GIF representation is not yet implemented");
+  return nil;
+}
+
 @end
 
 #else /* !HAVE_LIBUNGIF || !HAVE_LIBGIF */
@@ -349,6 +355,12 @@
   RELEASE(self);
   return nil;
 }
+
+- (NSData *) _GIFRepresentationWithProperties: (NSDictionary *) properties
+{
+  return nil;
+}
+
 @end
 
 #endif /* !HAVE_LIBUNGIF || !HAVE_LIBGIF */
diff -ru gnustep-gui-0.11.0/Source/NSBitmapImageRep+JPEG.h gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+JPEG.h
--- gnustep-gui-0.11.0/Source/NSBitmapImageRep+JPEG.h	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+JPEG.h	2006-10-24 04:28:53.000000000 -0700
@@ -36,7 +36,7 @@
 + (BOOL) _bitmapIsJPEG: (NSData *)imageData;
 - (id) _initBitmapFromJPEG: (NSData *)imageData
 	      errorMessage: (NSString **)errorMsg;
-
+- (NSData *) _JPEGRepresentationWithProperties: (NSDictionary *) properties;
 @end
 
 #endif // _NSBitmapImageRep_JPEG_H_include
diff -ru gnustep-gui-0.11.0/Source/NSBitmapImageRep+JPEG.m gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+JPEG.m
--- gnustep-gui-0.11.0/Source/NSBitmapImageRep+JPEG.m	2006-07-04 14:31:49.000000000 -0700
+++ gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+JPEG.m	2006-10-30 09:32:16.000000000 -0800
@@ -362,6 +362,12 @@
   return self;
 }
 
+- (NSData *) _JPEGRepresentationWithProperties: (NSDictionary *) properties
+{
+  NSLog(@"JPEG representation is not yet implemented");
+  return nil;
+}
+
 @end
 
 #else /* !HAVE_LIBJPEG */
@@ -377,6 +383,10 @@
   RELEASE(self);
   return nil;
 }
+- (NSData *) _JPEGRepresentationWithProperties: (NSDictionary *) properties
+{
+  return nil;
+}
 @end
 
 #endif /* !HAVE_LIBJPEG */
diff -ru gnustep-gui-0.11.0/Source/NSBitmapImageRep.m gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep.m
--- gnustep-gui-0.11.0/Source/NSBitmapImageRep.m	2006-08-08 18:37:32.000000000 -0700
+++ gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep.m	2006-10-30 14:26:37.000000000 -0800
@@ -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 @@
     {
       [self setOpaque: YES];
     }
+  _properties = [[NSMutableDictionary alloc] init];
   return self;
 }
 
@@ -555,6 +551,7 @@
 {
   NSZoneFree([self zone],_imagePlanes);
   RELEASE(_imageData);
+  RELEASE(_properties);
   [super dealloc];
 }
 
@@ -763,7 +760,7 @@
     }
 
   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,78 @@
 				   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];
+
+    case NSJPEGFileType:
+      return [self _JPEGRepresentationWithProperties: __properties];
+
+    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 +869,22 @@
     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 +908,26 @@
 - (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 +953,19 @@
 
 - (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 +1043,7 @@
 
 @implementation NSBitmapImageRep (GSPrivate)
 
-- (int) _localFromCompressionType: (NSTIFFCompression)type
++ (int) _localFromCompressionType: (NSTIFFCompression)type
 {
   switch (type)
     {
@@ -996,7 +1061,7 @@
   return COMPRESSION_NONE;
 }
 
-- (NSTIFFCompression) _compressionTypeFromLocal: (int)type
++ (NSTIFFCompression) _compressionTypeFromLocal: (int)type
 {
   switch (type)
     {
@@ -1057,9 +1122,15 @@
 		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);
diff -ru gnustep-gui-0.11.0/Source/NSBitmapImageRep+PNG.h gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+PNG.h
--- gnustep-gui-0.11.0/Source/NSBitmapImageRep+PNG.h	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+PNG.h	2006-10-24 04:21:04.000000000 -0700
@@ -34,6 +34,7 @@
 @interface NSBitmapImageRep (PNG)
 + (BOOL) _bitmapIsPNG: (NSData *)imageData;
 - (id) _initBitmapFromPNG: (NSData *)imageData;
+- (NSData *) _PNGRepresentationWithProperties: (NSDictionary *) properties;
 @end
 
 #endif
diff -ru gnustep-gui-0.11.0/Source/NSBitmapImageRep+PNG.m gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+PNG.m
--- gnustep-gui-0.11.0/Source/NSBitmapImageRep+PNG.m	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/NSBitmapImageRep+PNG.m	2006-10-30 11:41:01.000000000 -0800
@@ -217,6 +217,11 @@
   return self;
 }
 
+- (NSData *) _PNGRepresentationWithProperties: (NSDictionary *) properties
+{
+  NSLog(@"PNG representation is not yet implemented");
+  return nil;
+}
 @end
 
 #else /* !HAVE_LIBPNG */
@@ -231,6 +236,10 @@
   RELEASE(self);
   return nil;
 }
+- (NSData *) _PNGRepresentationWithProperties: (NSDictionary *) properties
+{
+  return nil;
+}
 @end
 
 #endif /* !HAVE_LIBPNG */
diff -ru gnustep-gui-0.11.0/Source/nsimage-tiff.h gnustep-gui-0.11.0-bitmap/Source/nsimage-tiff.h
--- gnustep-gui-0.11.0/Source/nsimage-tiff.h	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/nsimage-tiff.h	2006-10-25 18:25:43.000000000 -0700
@@ -75,5 +75,7 @@
 
 extern NSTiffColormap* NSTiffGetColormap(TIFF* image);
 
+extern int NSTiffIsCodecConfigured(unsigned int codec);
+
 #endif // _GNUstep_H_tiff
 
diff -ru gnustep-gui-0.11.0/Source/tiff.m gnustep-gui-0.11.0-bitmap/Source/tiff.m
--- gnustep-gui-0.11.0/Source/tiff.m	2006-02-21 22:43:48.000000000 -0800
+++ gnustep-gui-0.11.0-bitmap/Source/tiff.m	2006-10-30 10:35:49.000000000 -0800
@@ -585,4 +585,60 @@
   return map;
 }
 
+int NSTiffIsCodecConfigured(unsigned int codec)
+{
+#if (TIFFLIB_VERSION >= 20041016)
+  // starting with version 3.7.0 we can ask libtiff what it is configured to do
+  return TIFFIsCODECConfigured(codec);
+#else
+  // we check the tiffconf.h
+#include <tiffconf.h>
+#ifndef CCITT_SUPPORT
+#  define CCITT_SUPPORT 0
+#else
+#  define CCITT_SUPPORT 1
+#endif
+#ifndef PACKBITS_SUPPORT
+#  define PACKBITS_SUPPORT 0
+#else
+#  define PACKBITS_SUPPORT 1
+#endif
+#ifndef OJPEG_SUPPORT
+#  define OJPEG_SUPPORT 0
+#else
+#  define OJPEG_SUPPORT 1
+#endif
+#ifndef LZW_SUPPORT
+#  define LZW_SUPPORT 0
+#else
+#  define LZW_SUPPORT 1
+#endif
+#ifndef NEXT_SUPPORT
+#  define NEXT_SUPPORT 0
+#else
+#  define NEXT_SUPPORT 1
+#endif
+#ifndef JPEG_SUPPORT
+#  define JPEG_SUPPORT 0
+#else
+#  define JPEG_SUPPORT 1
+#endif
+/* If this fails, your libtiff is obsolete! Come to think of it
+ * if you even are compiling this part your libtiff is obsolete. */
+  switch (codec)
+  {
+    case COMPRESSION_NONE: return 1;
+    case COMPRESSION_CCITTFAX3: return CCITT_SUPPORT;
+    case COMPRESSION_CCITTFAX4: return CCITT_SUPPORT;
+    case COMPRESSION_JPEG: return JPEG_SUPPORT;
+    case COMPRESSION_PACKBITS: return PACKBITS_SUPPORT;
+    case COMPRESSION_OJPEG: return OJPEG_SUPPORT;
+    case COMPRESSION_LZW: return LZW_SUPPORT;
+    case COMPRESSION_NEXT: return NEXT_SUPPORT;
+    default:
+      return 0;
+  }
+#endif
+}
+
 
