1 /* 2 NSBitmapImageRep.h 3 4 Bitmap image representations 5 6 Copyright (C) 1996 Free Software Foundation, Inc. 7 8 Written by: Adam Fedor <fedor@colorado.edu> 9 Date: Feb 1996 10 11 This file is part of the GNUstep GUI Library. 12 13 This library is free software; you can redistribute it and/or 14 modify it under the terms of the GNU Lesser General Public 15 License as published by the Free Software Foundation; either 16 version 2 of the License, or (at your option) any later version. 17 18 This library is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 Lesser General Public License for more details. 22 23 You should have received a copy of the GNU Lesser General Public 24 License along with this library; see the file COPYING.LIB. 25 If not, see <http://www.gnu.org/licenses/> or write to the 26 Free Software Foundation, 51 Franklin Street, Fifth Floor, 27 Boston, MA 02110-1301, USA. 28 */ 29 30 #ifndef _GNUstep_H_NSBitmapImageRep 31 #define _GNUstep_H_NSBitmapImageRep 32 #import <GNUstepBase/GSVersionMacros.h> 33 34 #import <AppKit/NSImageRep.h> 35 36 @class NSArray; 37 @class NSString; 38 @class NSData; 39 @class NSDictionary; 40 @class NSMutableData; 41 @class NSMutableDictionary; 42 @class NSColor; 43 44 /** Describes the type of compression used on an image. Possible compressions: 45 <list> 46 <item> NSTIFFCompressionNone; </item> 47 <item> NSTIFFCompressionCCITTFAX3; </item> 48 <item> NSTIFFCompressionCCITFAX4; </item> 49 <item> NSTIFFCompressionLZW; </item> 50 <item> NSTIFFCompressionJPEG; </item> 51 <item> NSTIFFCompressionNEXT; </item> 52 <item> NSTIFFCompressionPackBits. </item> 53 <item> NSTIFFCompressionOldJPEG; </item> 54 </list> 55 */ 56 typedef enum _NSTIFFCompression { 57 NSTIFFCompressionNone = 1, 58 NSTIFFCompressionCCITTFAX3 = 3, 59 NSTIFFCompressionCCITTFAX4 = 4, 60 NSTIFFCompressionLZW = 5, 61 NSTIFFCompressionJPEG = 6, 62 NSTIFFCompressionNEXT = 32766, 63 NSTIFFCompressionPackBits = 32773, 64 NSTIFFCompressionOldJPEG = 32865 65 } NSTIFFCompression; 66 67 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) 68 /** Type of image 69 <list> 70 <item> NSTIFFFileType; </item> 71 <item> NSBMPFileType; Not implemented </item> 72 <item> NSGIFFileType; </item> 73 <item> NSJPEGFileType; </item> 74 <item> NSPNGFileType; </item> 75 <item> NSJPEG2000FileType. Not implemented </item> 76 </list> 77 */ 78 typedef enum _NSBitmapImageFileType { 79 NSTIFFFileType, 80 NSBMPFileType, 81 NSGIFFileType, 82 NSJPEGFileType, 83 NSPNGFileType, 84 NSJPEG2000FileType // available in Mac OS X v10.4 85 } NSBitmapImageFileType; 86 87 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) 88 89 typedef enum _NSBitmapFormat 90 { 91 NSAlphaFirstBitmapFormat = 1, 92 NSAlphaNonpremultipliedBitmapFormat = 2, 93 NSFloatingPointSamplesBitmapFormat = 4 94 } NSBitmapFormat; 95 96 typedef enum _NSImageRepLoadStatus 97 { 98 NSImageRepLoadStatusUnknownType = -1, 99 NSImageRepLoadStatusReadingHeader = -2, 100 NSImageRepLoadStatusWillNeedAllData = -3, 101 NSImageRepLoadStatusInvalidData = -4, 102 NSImageRepLoadStatusUnexpectedEOF = -5, 103 NSImageRepLoadStatusCompleted = -6 104 } NSImageRepLoadStatus; 105 106 #endif 107 108 APPKIT_EXPORT NSString *NSImageCompressionMethod; // NSNumber; only for TIFF files 109 APPKIT_EXPORT NSString *NSImageCompressionFactor; // NSNumber 0.0 to 255.0; only for JPEG files (GNUstep extension: JPEG-compressed TIFFs too) 110 APPKIT_EXPORT NSString *NSImageDitherTranparency; // NSNumber boolean; only for writing GIF files 111 APPKIT_EXPORT NSString *NSImageRGBColorTable; // NSData; only for reading & writing GIF files 112 APPKIT_EXPORT NSString *NSImageInterlaced; // NSNumber boolean; only for writing PNG files 113 APPKIT_EXPORT NSString *NSImageColorSyncProfileData; // Mac OX X only 114 //APPKIT_EXPORT NSString *GSImageICCProfileData; // if & when color management comes to GNUstep 115 APPKIT_EXPORT NSString *NSImageFrameCount; // NSNumber integer; only for reading animated GIF files 116 APPKIT_EXPORT NSString *NSImageCurrentFrame; // NSNumber integer; only for animated GIF files 117 APPKIT_EXPORT NSString *NSImageCurrentFrameDuration; // NSNumber float; only for reading animated GIF files 118 APPKIT_EXPORT NSString *NSImageLoopCount; // NSNumber integer; only for reading animated GIF files 119 APPKIT_EXPORT NSString *NSImageGamma; // NSNumber 0.0 to 1.0; only for reading & writing PNG files 120 APPKIT_EXPORT NSString *NSImageProgressive; // NSNumber boolean; only for reading & writing JPEG files 121 APPKIT_EXPORT NSString *NSImageEXIFData; // No GNUstep support yet; for reading & writing JPEG 122 123 #endif 124 125 @interface NSBitmapImageRep : NSImageRep 126 { 127 // Attributes 128 NSInteger _bytesPerRow; 129 NSInteger _numColors; 130 NSInteger _bitsPerPixel; 131 unsigned short _compression; 132 float _comp_factor; 133 NSMutableDictionary *_properties; 134 BOOL _isPlanar; 135 unsigned char **_imagePlanes; 136 NSData *_imageData; 137 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) 138 NSBitmapFormat _format; 139 #else 140 unsigned int _format; 141 #endif 142 } 143 144 // 145 // Allocating and Initializing a New NSBitmapImageRep Object 146 // 147 + (id) imageRepWithData: (NSData*)imageData; 148 + (NSArray*) imageRepsWithData: (NSData*)imageData; 149 - (id) initWithData: (NSData*)imageData; 150 - (id) initWithFocusedViewRect: (NSRect)rect; 151 - (id) initWithBitmapDataPlanes: (unsigned char**)planes 152 pixelsWide: (NSInteger)width 153 pixelsHigh: (NSInteger)height 154 bitsPerSample: (NSInteger)bitsPerSample 155 samplesPerPixel: (NSInteger)samplesPerPixel 156 hasAlpha: (BOOL)alpha 157 isPlanar: (BOOL)isPlanar 158 colorSpaceName: (NSString*)colorSpaceName 159 bytesPerRow: (NSInteger)rowBytes 160 bitsPerPixel: (NSInteger)pixelBits; 161 162 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) 163 - (void)colorizeByMappingGray:(CGFloat)midPoint 164 toColor:(NSColor *)midPointColor 165 blackMapping:(NSColor *)shadowColor 166 whiteMapping:(NSColor *)lightColor; 167 - (id)initWithBitmapHandle:(void *)bitmap; 168 - (id)initWithIconHandle:(void *)icon; 169 #endif 170 171 #if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST) 172 - (NSInteger) incrementalLoadFromData: (NSData *)data complete: (BOOL)complete; 173 - (id) initForIncrementalLoad; 174 #endif 175 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) 176 - (id) initWithBitmapDataPlanes: (unsigned char**)planes 177 pixelsWide: (NSInteger)width 178 pixelsHigh: (NSInteger)height 179 bitsPerSample: (NSInteger)bps 180 samplesPerPixel: (NSInteger)spp 181 hasAlpha: (BOOL)alpha 182 isPlanar: (BOOL)isPlanar 183 colorSpaceName: (NSString*)colorSpaceName 184 bitmapFormat: (NSBitmapFormat)bitmapFormat 185 bytesPerRow: (NSInteger)rowBytes 186 bitsPerPixel: (NSInteger)pixelBits; 187 #endif 188 189 // 190 // Getting Information about the Image 191 // 192 - (NSInteger) bitsPerPixel; 193 - (NSInteger) samplesPerPixel; 194 - (BOOL) isPlanar; 195 - (NSInteger) numberOfPlanes; 196 - (NSInteger) bytesPerPlane; 197 - (NSInteger) bytesPerRow; 198 199 // 200 // Getting Image Data 201 // 202 - (unsigned char*) bitmapData; 203 - (void) getBitmapDataPlanes: (unsigned char**)data; 204 205 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) 206 - (NSBitmapFormat) bitmapFormat; 207 - (void) getPixel: (NSUInteger[])pixelData atX: (NSInteger)x y: (NSInteger)y; 208 - (void) setPixel: (NSUInteger[])pixelData atX: (NSInteger)x y: (NSInteger)y; 209 - (NSColor*) colorAtX: (NSInteger)x y: (NSInteger)y; 210 - (void) setColor: (NSColor*)color atX: (NSInteger)x y: (NSInteger)y; 211 #endif 212 213 // 214 // Producing a TIFF Representation of the Image 215 // 216 + (NSData*) TIFFRepresentationOfImageRepsInArray: (NSArray*)anArray; 217 + (NSData*) TIFFRepresentationOfImageRepsInArray: (NSArray*)anArray 218 usingCompression: (NSTIFFCompression)type 219 factor: (float)factor; 220 - (NSData*) TIFFRepresentation; 221 - (NSData*) TIFFRepresentationUsingCompression: (NSTIFFCompression)type 222 factor: (float)factor; 223 224 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) 225 + (NSData *)representationOfImageRepsInArray:(NSArray *)imageReps 226 usingType:(NSBitmapImageFileType)storageType 227 properties:(NSDictionary *)properties; 228 - (NSData *)representationUsingType:(NSBitmapImageFileType)storageType 229 properties:(NSDictionary *)properties; 230 #endif 231 232 // 233 // Setting and Checking Compression Types 234 // 235 + (void) getTIFFCompressionTypes: (const NSTIFFCompression**)list 236 count: (NSInteger*)numTypes; 237 + (NSString*) localizedNameForTIFFCompressionType: (NSTIFFCompression)type; 238 - (BOOL) canBeCompressedUsing: (NSTIFFCompression)compression; 239 - (void) getCompression: (NSTIFFCompression*)compression 240 factor: (float*)factor; 241 - (void) setCompression: (NSTIFFCompression)compression 242 factor: (float)factor; 243 244 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) 245 - (void)setProperty:(NSString *)property withValue:(id)value; 246 - (id)valueForProperty:(NSString *)property; 247 #endif 248 249 @end 250 251 @interface NSBitmapImageRep (GNUstepExtension) 252 + (NSArray*) imageRepsWithFile: (NSString *)filename; 253 @end 254 255 #endif // _GNUstep_H_NSBitmapImageRep 256