mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Initial implementation of NSImage* classes based upon Adam Feodor's work.
Changes to utilize the TIFF library. Uncomment some code now that NSException and NSNotification* classes exist. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@1654 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
fed5dc1dfb
commit
72a5816ea0
21 changed files with 2235 additions and 668 deletions
30
ChangeLog
30
ChangeLog
|
@ -1,3 +1,33 @@
|
|||
Mon Aug 12 14:16:12 1996 GNUstep Development <gnustep@duncan.ocbi.com>
|
||||
|
||||
* Headers/gnustep/gui/NSBitmapImageRep.h: Initial implementation
|
||||
based upon Adam's Feodor work.
|
||||
* Headers/gnustep/gui/NSCachedImageRep.h: Likewise.
|
||||
* Headers/gnustep/gui/NSCustomImageRep.h: Likewise.
|
||||
* Headers/gnustep/gui/NSEPSImageRep.h: Likewise.
|
||||
* Headers/gnustep/gui/NSImage.h: Likewise.
|
||||
* Headers/gnustep/gui/NSImageRep.h: Likewise.
|
||||
* Source/NSBitmapImageRep.m: Likewise.
|
||||
* Source/NSCachedImageRep.m: Likewise.
|
||||
* Source/NSCustomImageRep.m: Likewise.
|
||||
* Source/NSEPSImageRep.m: Likewise.
|
||||
* Source/NSImage.m: Likewise.
|
||||
* Source/NSImageRep.m: Likewise.
|
||||
|
||||
* Headers/gnustep/gui/NSApplication.h (-reportException:): Uncomment
|
||||
method now that NSExceptions are implemented.
|
||||
* Source/NSApplication.m (-reportException:): Likewise.
|
||||
* Headers/gnustep/gui/NSText.h: Include NSNotification header file
|
||||
now that class is implemented.
|
||||
* Headers/gnustep/gui/config.h.in: Don't define NSNotification and
|
||||
NSNotificationCenter to void as classes are now implemented.
|
||||
* Headers/gnustep/gui/NSWindow.h: Uncomment methods now that NSScreen
|
||||
class has been implemented.
|
||||
* Source/NSWindow.m: Likewise.
|
||||
* Source/Makefile.in: Changes to use TIFF library.
|
||||
* Source/tiff.c: New file.
|
||||
* Headers/gnustep/gui/nsimage-tiff.h: New file.
|
||||
|
||||
Wed Jul 10 17:11:53 1996 Scott Christley <scottc@net-community.com>
|
||||
|
||||
* Source/NSView.m: Use NSDebugLog instead of NSLog.
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include <AppKit/stdappkit.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <AppKit/NSEvent.h>
|
||||
#include <AppKit/NSResponder.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
|
@ -202,7 +203,7 @@
|
|||
//
|
||||
// Reporting an exception
|
||||
//
|
||||
//- (void)reportException:(NSException *)anException
|
||||
- (void)reportException:(NSException *)anException;
|
||||
|
||||
//
|
||||
// Terminating the application
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -39,6 +39,14 @@
|
|||
|
||||
{
|
||||
// Attributes
|
||||
unsigned int bytesPerRow;
|
||||
unsigned int numColors;
|
||||
unsigned int bitsPerPixel;
|
||||
unsigned short compression;
|
||||
BOOL isPlanar;
|
||||
BOOL freePlanes;
|
||||
unsigned char** imagePlanes;
|
||||
NSMutableData* imageData;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -50,14 +58,14 @@
|
|||
- (id)initWithFocusedViewRect:(NSRect)rect;
|
||||
- (id)initWithBitmapDataPlanes:(unsigned char **)planes
|
||||
pixelsWide:(int)width
|
||||
pixelsHigh:(int)height
|
||||
bitsPerSample:(int)bps
|
||||
samplesPerPixel:(int)spp
|
||||
hasAlpha:(BOOL)alpha
|
||||
isPlanar:(BOOL)config
|
||||
colorSpaceName:(NSString *)colorSpaceName
|
||||
bytesPerRow:(int)rowBytes
|
||||
bitsPerPixel:(int)pixelBits;
|
||||
pixelsHigh:(int)height
|
||||
bitsPerSample:(int)bps
|
||||
samplesPerPixel:(int)spp
|
||||
hasAlpha:(BOOL)alpha
|
||||
isPlanar:(BOOL)config
|
||||
colorSpaceName:(NSString *)colorSpaceName
|
||||
bytesPerRow:(int)rowBytes
|
||||
bitsPerPixel:(int)pixelBits;
|
||||
|
||||
//
|
||||
// Getting Information about the Image
|
||||
|
@ -81,7 +89,7 @@ bytesPerRow:(int)rowBytes
|
|||
+ (NSData *)TIFFRepresentationOfImageRepsInArray:(NSArray *)anArray;
|
||||
+ (NSData *)TIFFRepresentationOfImageRepsInArray:(NSArray *)anArray
|
||||
usingCompression:(NSTIFFCompression)compressionType
|
||||
factor:(float)factor;
|
||||
factor:(float)factor;
|
||||
- (NSData *)TIFFRepresentation;
|
||||
- (NSData *)TIFFRepresentationUsingCompression:(NSTIFFCompression)compressionType
|
||||
factor:(float)factor;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
NSCachedImageRep.h
|
||||
|
||||
Description...
|
||||
Cached image representation.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -40,6 +40,9 @@
|
|||
|
||||
{
|
||||
// Attributes
|
||||
NSRect _rect;
|
||||
NSWindow* _window;
|
||||
void* _cache;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -47,7 +50,7 @@
|
|||
//
|
||||
- (id)initWithSize:(NSSize)aSize
|
||||
depth:(NSWindowDepth)aDepth
|
||||
separate:(BOOL)separate
|
||||
separate:(BOOL)separate
|
||||
alpha:(BOOL)alpha;
|
||||
- (id)initWithWindow:(NSWindow *)aWindow
|
||||
rect:(NSRect)aRect;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
NSCustomImageRep.h
|
||||
|
||||
Description...
|
||||
Custom image representation.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -39,6 +39,8 @@
|
|||
|
||||
{
|
||||
// Attributes
|
||||
id delegate;
|
||||
SEL selector;
|
||||
}
|
||||
|
||||
- (id)initWithDrawSelector:(SEL)aSelector
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
NSEPSImageRep.h
|
||||
|
||||
Description...
|
||||
EPS image representation.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
NSImage.h
|
||||
|
||||
Description...
|
||||
Load, manipulate and display images
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -33,15 +33,43 @@
|
|||
|
||||
#include <AppKit/stdappkit.h>
|
||||
#include <DPSClient/TypesandConstants.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSImageRep.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
|
||||
@class NSPasteboard;
|
||||
@class NSMutableArray;
|
||||
@class NSImageRep;
|
||||
@class NSColor;
|
||||
@class NSView;
|
||||
|
||||
@interface NSImage : NSObject <NSCoding>
|
||||
|
||||
{
|
||||
// Attributes
|
||||
NSSize image_size;
|
||||
NSString* name;
|
||||
NSSize _size;
|
||||
struct __imageFlags {
|
||||
unsigned int scalable:1;
|
||||
unsigned int dataRetained:1;
|
||||
unsigned int flipDraw:1;
|
||||
unsigned int uniqueWindow:1;
|
||||
unsigned int uniqueWasExplicitlySet:1;
|
||||
unsigned int sizeWasExplicitlySet:1;
|
||||
unsigned int builtIn:1;
|
||||
unsigned int needsToExpand:1;
|
||||
unsigned int useEPSOnResolutionMismatch:1;
|
||||
unsigned int colorMatchPreferred:1;
|
||||
unsigned int multipleResolutionMatching:1;
|
||||
unsigned int subImage:1;
|
||||
unsigned int aSynch:1;
|
||||
unsigned int archiveByName:1;
|
||||
unsigned int cacheSeparately:1;
|
||||
unsigned int unboundedCacheDepth:1;
|
||||
} _flags;
|
||||
NSMutableArray* _reps;
|
||||
NSMutableArray* _repList;
|
||||
NSColor* _color;
|
||||
BOOL _syncLoad;
|
||||
NSView* _lockedView;
|
||||
id delegate;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -82,12 +110,12 @@
|
|||
operation:(NSCompositingOperation)op;
|
||||
- (void)compositeToPoint:(NSPoint)aPoint
|
||||
fromRect:(NSRect)aRect
|
||||
operation:(NSCompositingOperation)op;
|
||||
operation:(NSCompositingOperation)op;
|
||||
- (void)dissolveToPoint:(NSPoint)aPoint
|
||||
fraction:(float)aFloat;
|
||||
- (void)dissolveToPoint:(NSPoint)aPoint
|
||||
fromRect:(NSRect)aRect
|
||||
fraction:(float)aFloat;
|
||||
fraction:(float)aFloat;
|
||||
|
||||
//
|
||||
// Choosing Which Image Representation to Use
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
NSImageRep.h
|
||||
|
||||
Description...
|
||||
Abstract representation of an image.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -39,6 +39,13 @@
|
|||
|
||||
{
|
||||
// Attributes
|
||||
NSString* colorSpace;
|
||||
NSSize size;
|
||||
BOOL hasAlpha;
|
||||
BOOL isOpaque;
|
||||
int bitsPerSample;
|
||||
int _pixelsWide;
|
||||
int _pixelsHigh;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
|
||||
@interface NSText : NSView <NSCoding>
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSText.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <AppKit/NSScreen.h>
|
||||
|
||||
@interface NSWindow : NSResponder <NSCoding>
|
||||
|
||||
|
@ -223,14 +224,14 @@ screen:aScreen;
|
|||
//
|
||||
// Screens and window depths
|
||||
//
|
||||
//+ (NSWindowDepth)defaultDepthLimit
|
||||
//- (BOOL)canStoreColor;
|
||||
//- (NSScreen *)deepestScreen;
|
||||
//- (NSWindowDepth)depthLimit;
|
||||
//- (BOOL)hasDynamicDepthLimit;
|
||||
//- (NSScreen *)screen;
|
||||
//- (void)setDepthLimit:(NSWindowDepth)limit;
|
||||
//- (void)setDynamicDepthLimit:(BOOL)flag;
|
||||
+ (NSWindowDepth)defaultDepthLimit;
|
||||
- (BOOL)canStoreColor;
|
||||
- (NSScreen *)deepestScreen;
|
||||
- (NSWindowDepth)depthLimit;
|
||||
- (BOOL)hasDynamicDepthLimit;
|
||||
- (NSScreen *)screen;
|
||||
- (void)setDepthLimit:(NSWindowDepth)limit;
|
||||
- (void)setDynamicDepthLimit:(BOOL)flag;
|
||||
|
||||
//
|
||||
// Cursor management
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
#include <Foundation/NSGeometry.h>
|
||||
|
||||
// Until they have been added to libobjects
|
||||
#define NSNotification void
|
||||
#define NSNotificationCenter void
|
||||
//#define NSNotification void
|
||||
//#define NSNotificationCenter void
|
||||
|
||||
@config_include@
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ includedir = $(prefix)/include
|
|||
|
||||
MAKEDEFINES =
|
||||
|
||||
CC = @CC@ -g
|
||||
CC = @CC@ -g -DHAVE_LIBTIFF
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CFLAGS = -c $(GCCFLAGS) -I../Headers $(CPPFLAGS)
|
||||
|
||||
|
@ -150,7 +150,8 @@ gui/NSWorkspace.h \
|
|||
gui/TrackingRectangle.h \
|
||||
gui/TypesandConstants.h \
|
||||
gui/config.h \
|
||||
gui/stdappkit.h
|
||||
gui/stdappkit.h \
|
||||
gui/nsimage-tiff.h
|
||||
|
||||
GNUSTEP_DPS_HEADERS = dps/NSDPSContext.h \
|
||||
dps/DPSOperators.h \
|
||||
|
@ -221,13 +222,16 @@ NSWindow$(oext) \
|
|||
NSWorkspace$(oext) \
|
||||
Functions$(oext) \
|
||||
TrackingRectangle$(oext) \
|
||||
LogFile$(oext)
|
||||
LogFile$(oext) \
|
||||
tiff$(oext)
|
||||
|
||||
OBJS = $(OBJS_WITHOUT_INIT)
|
||||
|
||||
.SUFFIXES: .m
|
||||
.m$(oext):
|
||||
$(CC) $(CFLAGS) $<
|
||||
.c$(oext):
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
#
|
||||
# libraries
|
||||
|
|
|
@ -813,7 +813,8 @@ NSString *NSApplicationWillUpdateNotification;
|
|||
}
|
||||
|
||||
// Reporting an exception
|
||||
//- (void)reportException:(NSException *)anException
|
||||
- (void)reportException:(NSException *)anException
|
||||
{}
|
||||
|
||||
//
|
||||
// Terminating the application
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
NSBitmapImageRep.m
|
||||
|
||||
Bitmap image representations
|
||||
Bitmap image representation.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -19,188 +19,395 @@
|
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
|
||||
If you are interested in a warranty or support for this source code,
|
||||
contact Scott Christley <scottc@net-community.com> for more information.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/NSBitmapImageRep.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <AppKit/NSBitmapImageRep.h>
|
||||
#include <AppKit/nsimage-tiff.h>
|
||||
|
||||
@implementation NSBitmapImageRep
|
||||
/* Maximum number of planes */
|
||||
#define MAX_PLANES 5
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
/* Backend protocol - methods that must be implemented by the backend to
|
||||
complete the class */
|
||||
@protocol NXBitmapImageRepBackend
|
||||
- (BOOL) draw;
|
||||
@end
|
||||
|
||||
@implementation NSBitmapImageRep
|
||||
|
||||
/* Given a TIFF image (from the libtiff library), load the image information
|
||||
into our data structure. Reads the specified image. */
|
||||
- _initFromImage: (TIFF *)image number: (int)imageNumber
|
||||
{
|
||||
if (self == [NSBitmapImageRep class])
|
||||
NSString* space;
|
||||
NSTiffInfo* info;
|
||||
|
||||
info = NSTiffGetInfo(imageNumber, image);
|
||||
if (!info)
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
[NSException raise:NSTIFFException format: @"Read invalid TIFF info"];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Allocating and Initializing a New NSBitmapImageRep Object
|
||||
//
|
||||
+ (id)imageRepWithData:(NSData *)tiffData
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
/* 8-bit RGB will be converted to 24-bit by the tiff routines, so account
|
||||
for this. */
|
||||
space = nil;
|
||||
#ifdef HAVE_LIBTIFF
|
||||
switch(info->photoInterp)
|
||||
{
|
||||
case PHOTOMETRIC_MINISBLACK: space = NSDeviceWhiteColorSpace; break;
|
||||
case PHOTOMETRIC_MINISWHITE: space = NSDeviceBlackColorSpace; break;
|
||||
case PHOTOMETRIC_RGB: space = NSDeviceRGBColorSpace; break;
|
||||
case PHOTOMETRIC_PALETTE:
|
||||
space = NSDeviceRGBColorSpace;
|
||||
info->samplesPerPixel = 3;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
+ (NSArray *)imageRepsWithData:(NSData *)tiffData
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
[self initWithBitmapDataPlanes: NULL
|
||||
pixelsWide: info->width
|
||||
pixelsHigh: info->height
|
||||
bitsPerSample: info->bitsPerSample
|
||||
samplesPerPixel: info->samplesPerPixel
|
||||
hasAlpha: (info->samplesPerPixel > 3)
|
||||
isPlanar: (info->planarConfig == PLANARCONFIG_SEPARATE)
|
||||
colorSpaceName: space
|
||||
bytesPerRow: 0
|
||||
bitsPerPixel: 0];
|
||||
compression = info->compression;
|
||||
|
||||
//
|
||||
// Producing a TIFF Representation of the Image
|
||||
//
|
||||
+ (NSData *)TIFFRepresentationOfImageRepsInArray:(NSArray *)anArray
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSData *)TIFFRepresentationOfImageRepsInArray:(NSArray *)anArray
|
||||
usingCompression:(NSTIFFCompression)compressionType
|
||||
factor:(float)factor
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting and Checking Compression Types
|
||||
//
|
||||
+ (void)getTIFFCompressionTypes:(const NSTIFFCompression **)list
|
||||
count:(int *)numTypes
|
||||
{}
|
||||
|
||||
+ (NSString *)localizedNameForTIFFCompressionType:(NSTIFFCompression)compression
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
//
|
||||
// Allocating and Initializing a New NSBitmapImageRep Object
|
||||
//
|
||||
- (id)initWithData:(NSData *)tiffData
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)initWithFocusedViewRect:(NSRect)rect
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)initWithBitmapDataPlanes:(unsigned char **)planes
|
||||
pixelsWide:(int)width
|
||||
pixelsHigh:(int)height
|
||||
bitsPerSample:(int)bps
|
||||
samplesPerPixel:(int)spp
|
||||
hasAlpha:(BOOL)alpha
|
||||
isPlanar:(BOOL)config
|
||||
colorSpaceName:(NSString *)colorSpaceName
|
||||
bytesPerRow:(int)rowBytes
|
||||
bitsPerPixel:(int)pixelBits
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Getting Information about the Image
|
||||
//
|
||||
- (int)bitsPerPixel
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (int)samplesPerPixel
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (BOOL)isPlanar
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (int)numberOfPlanes
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (int)bytesPerPlane
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (int)bytesPerRow
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Getting Image Data
|
||||
//
|
||||
- (unsigned char *)bitmapData
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (void)getBitmapDataPlanes:(unsigned char **)data
|
||||
{}
|
||||
|
||||
//
|
||||
// Producing a TIFF Representation of the Image
|
||||
//
|
||||
- (NSData *)TIFFRepresentation
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSData *)TIFFRepresentationUsingCompression:(NSTIFFCompression)compressionType
|
||||
factor:(float)factor
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting and Checking Compression Types
|
||||
//
|
||||
- (BOOL)canBeCompressedUsing:(NSTIFFCompression)compression
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)getCompression:(NSTIFFCompression *)compression
|
||||
factor:(float *)factor
|
||||
{}
|
||||
|
||||
- (void)setCompression:(NSTIFFCompression)compression
|
||||
factor:(float)factor
|
||||
{}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
}
|
||||
|
||||
- initWithCoder:aDecoder
|
||||
{
|
||||
[super initWithCoder:aDecoder];
|
||||
if (NSTiffRead(imageNumber, image, NULL, [self bitmapData]))
|
||||
{
|
||||
[NSException raise:NSTIFFException format: @"Read invalid TIFF image"];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (id) imageRepWithData: (NSData *)tiffData
|
||||
{
|
||||
NSArray* array;
|
||||
|
||||
array = [self imageRepsWithData: tiffData];
|
||||
if ([array count])
|
||||
return [array objectAtIndex: 0];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *) imageRepsWithData: (NSData *)tiffData
|
||||
{
|
||||
int images;
|
||||
TIFF* image;
|
||||
NSTiffInfo* info;
|
||||
NSMutableArray* array;
|
||||
|
||||
image = NSTiffOpenData((char *)[tiffData bytes], [tiffData length],
|
||||
"r", NULL);
|
||||
if (!image)
|
||||
{
|
||||
[NSException raise:NSTIFFException format: @"Read invalid TIFF data"];
|
||||
}
|
||||
|
||||
array = [NSMutableArray arrayWithCapacity:1];
|
||||
images = 0;
|
||||
while ((info = NSTiffGetInfo(images, image)))
|
||||
{
|
||||
NSBitmapImageRep* imageRep;
|
||||
|
||||
OBJC_FREE(info);
|
||||
imageRep = [[[[self class] alloc]
|
||||
_initFromImage: image number: images] autorelease];
|
||||
[array addObject: imageRep];
|
||||
images++;
|
||||
}
|
||||
NSTiffClose(image);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/* Loads only the default (first) image from the TIFF image contained in
|
||||
data. */
|
||||
- (id) initWithData: (NSData *)tiffData
|
||||
{
|
||||
TIFF *image;
|
||||
|
||||
image = NSTiffOpenData((char *)[tiffData bytes], [tiffData length],
|
||||
"r", NULL);
|
||||
if (!image)
|
||||
{
|
||||
[NSException raise:NSTIFFException format: @"Read invalid TIFF data"];
|
||||
}
|
||||
|
||||
[self _initFromImage:image number: -1];
|
||||
NSTiffClose(image);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithFocusedViewRect: (NSRect)rect
|
||||
{
|
||||
return [self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* This is the designated initializer */
|
||||
/* Note: It's unclear whether or not we own the data that is passed
|
||||
to us here. Since the data is not of type "const", one could assume
|
||||
that we do own it and that it should not be copied. I'm also assuming
|
||||
we own the data that "planes" points to. This is all a very hazardous
|
||||
assumption. It's also harder to deal with. */
|
||||
- (id) initWithBitmapDataPlanes: (unsigned char **)planes
|
||||
pixelsWide: (int)width
|
||||
pixelsHigh: (int)height
|
||||
bitsPerSample: (int)bps
|
||||
samplesPerPixel: (int)spp
|
||||
hasAlpha: (BOOL)alpha
|
||||
isPlanar: (BOOL)config
|
||||
colorSpaceName: (NSString *)colorSpaceName
|
||||
bytesPerRow: (int)rowBytes
|
||||
bitsPerPixel: (int)pixelBits;
|
||||
{
|
||||
if (!bps || !spp || !width || !height)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Required arguments not specified creating NSBitmapImageRep"];
|
||||
}
|
||||
|
||||
_pixelsWide = width;
|
||||
_pixelsHigh = height;
|
||||
size.width = width;
|
||||
size.height = height;
|
||||
bitsPerSample = bps;
|
||||
numColors = spp;
|
||||
hasAlpha = alpha;
|
||||
isPlanar = isPlanar;
|
||||
colorSpace = [colorSpaceName retain];
|
||||
if (!pixelBits)
|
||||
pixelBits = bps * ((isPlanar) ? 1 : spp);
|
||||
bitsPerPixel = pixelBits;
|
||||
if (!rowBytes)
|
||||
rowBytes = ceil((float)width * bitsPerPixel / 8);
|
||||
bytesPerRow = rowBytes;
|
||||
|
||||
if (planes)
|
||||
{
|
||||
freePlanes = YES;
|
||||
imagePlanes = planes;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (imagePlanes && freePlanes)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_PLANES; i++)
|
||||
if (imagePlanes[i])
|
||||
OBJC_FREE(imagePlanes[i]);
|
||||
}
|
||||
OBJC_FREE(imagePlanes);
|
||||
[imageData release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
+ (BOOL) canInitWithData: (NSData *)data
|
||||
{
|
||||
TIFF *image = NULL;
|
||||
image = NSTiffOpenData((char *)[data bytes], [data length], "r", NULL);
|
||||
NSTiffClose(image);
|
||||
|
||||
return (image) ? YES : NO;
|
||||
}
|
||||
|
||||
+ (BOOL) canInitWithPasteboard: (NSPasteboard *)pasteboard
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSArray *) imageFileTypes
|
||||
{
|
||||
return [self imageUnfilteredFileTypes];
|
||||
}
|
||||
|
||||
+ (NSArray *) imagePasteboardTypes
|
||||
{
|
||||
return [self imageUnfilteredPasteboardTypes];
|
||||
}
|
||||
|
||||
+ (NSArray *) imageUnfilteredFileTypes
|
||||
{
|
||||
return [NSArray arrayWithObjects: @"tiff", @"tif", nil];
|
||||
}
|
||||
|
||||
+ (NSArray *) imageUnfilteredPasteboardTypes
|
||||
{
|
||||
return [NSArray arrayWithObjects: NSTIFFPboardType, nil];
|
||||
}
|
||||
|
||||
// Getting Information about the Image
|
||||
- (int) bitsPerPixel
|
||||
{
|
||||
return bitsPerPixel;
|
||||
}
|
||||
|
||||
- (int) samplesPerPixel
|
||||
{
|
||||
return numColors;
|
||||
}
|
||||
|
||||
- (BOOL) isPlanar
|
||||
{
|
||||
return isPlanar;
|
||||
}
|
||||
|
||||
- (int) numberOfPlanes
|
||||
{
|
||||
return (isPlanar) ? numColors : 1;
|
||||
}
|
||||
|
||||
- (int) bytesPerPlane
|
||||
{
|
||||
return bytesPerRow*_pixelsHigh;
|
||||
}
|
||||
|
||||
- (int) bytesPerRow
|
||||
{
|
||||
return bytesPerRow;
|
||||
}
|
||||
|
||||
// Getting Image Data
|
||||
- (unsigned char *) bitmapData
|
||||
{
|
||||
unsigned char *planes[MAX_PLANES];
|
||||
[self getBitmapDataPlanes: planes];
|
||||
return (unsigned char *)[imageData mutableBytes];
|
||||
// return planes[0];
|
||||
}
|
||||
|
||||
- (void) getBitmapDataPlanes: (unsigned char **)data
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!imagePlanes)
|
||||
{
|
||||
long length;
|
||||
unsigned char* bits;
|
||||
|
||||
length = numColors * bytesPerRow * _pixelsHigh * sizeof(unsigned char);
|
||||
imageData = [NSMutableData dataWithCapacity: length];
|
||||
OBJC_MALLOC(imagePlanes, unsigned char*, MAX_PLANES);
|
||||
bits = [imageData mutableBytes];
|
||||
if (isPlanar)
|
||||
{
|
||||
for (i=1; i < numColors; i++)
|
||||
imagePlanes[i] = bits + i*bytesPerRow * _pixelsHigh;
|
||||
for (i= numColors; i < MAX_PLANES; i++)
|
||||
imagePlanes[i] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
imagePlanes[1] = bits;
|
||||
for (i= 1; i < MAX_PLANES; i++)
|
||||
imagePlanes[i] = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
if (data)
|
||||
for (i=0; i < numColors; i++)
|
||||
data[i] = imagePlanes[i];
|
||||
}
|
||||
|
||||
- (BOOL) draw
|
||||
{
|
||||
[self bitmapData];
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Producing a TIFF Representation of the Image
|
||||
+ (NSData *) TIFFRepresentationOfImageRepsInArray: (NSArray *)anArray
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSData *) TIFFRepresentationOfImageRepsInArray: (NSArray *)anArray
|
||||
usingCompression: (NSTIFFCompression)compressionType
|
||||
factor: (float)factor
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSData *) TIFFRepresentation
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSData *) TIFFRepresentationUsingCompression: (NSTIFFCompression)compressionType
|
||||
factor: (float)factor
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
// Setting and Checking Compression Types
|
||||
+ (void) getTIFFCompressionTypes: (const NSTIFFCompression **)list
|
||||
count: (int *)numTypes
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
+ (NSString *) localizedNameForTIFFCompressionType: (NSTIFFCompression)compression
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL) canBeCompressedUsing: (NSTIFFCompression)compression
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) getCompression: (NSTIFFCompression *)compression
|
||||
factor: (float *)factor
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) setCompression: (NSTIFFCompression)compression
|
||||
factor: (float)factor
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
// NSCoding protocol
|
||||
- (void) encodeWithCoder: aCoder
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- initWithCoder: aDecoder
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
/*
|
||||
NSCachedImageRep.m
|
||||
|
||||
Description...
|
||||
Cached image representation.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -19,74 +19,101 @@
|
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
|
||||
If you are interested in a warranty or support for this source code,
|
||||
contact Scott Christley <scottc@net-community.com> for more information.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
*/
|
||||
/*
|
||||
Keeps a representation of an image in an off-screen window. If the
|
||||
message initFromWindow:rect: is sent with a nil window, one is created
|
||||
using the rect information.
|
||||
*/
|
||||
#include <Foundation/NSException.h>
|
||||
#include <AppKit/NSCachedImageRep.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
|
||||
#include <gnustep/gui/NSCachedImageRep.h>
|
||||
/* Backend protocol - methods that must be implemented by the backend to
|
||||
complete the class */
|
||||
@protocol NXCachedImageRepBackend
|
||||
- (BOOL) draw;
|
||||
@end
|
||||
|
||||
@implementation NSCachedImageRep
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [NSCachedImageRep class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Initializing an NSCachedImageRep
|
||||
//
|
||||
- (id)initWithSize:(NSSize)aSize
|
||||
depth:(NSWindowDepth)aDepth
|
||||
separate:(BOOL)separate
|
||||
alpha:(BOOL)alpha
|
||||
- (id) initWithSize: (NSSize)aSize
|
||||
depth: (NSWindowDepth)aDepth
|
||||
separate: (BOOL)separate
|
||||
alpha: (BOOL)alpha
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)initWithWindow:(NSWindow *)aWindow
|
||||
rect:(NSRect)aRect
|
||||
- initWithWindow: (NSWindow *)win rect: (NSRect)rect
|
||||
{
|
||||
return nil;
|
||||
int style = NSClosableWindowMask;
|
||||
|
||||
[super init];
|
||||
|
||||
_window = win;
|
||||
_rect = rect;
|
||||
|
||||
/* Either win or rect must be non-NULL. If rect is empty, we get the
|
||||
frame info from the window. If win is nil we create it from the
|
||||
rect information. */
|
||||
if (NSIsEmptyRect(_rect))
|
||||
{
|
||||
if (!_window)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Must specify either window or rect when creating NSCachedImageRep"];
|
||||
}
|
||||
|
||||
_rect = [_window frame];
|
||||
}
|
||||
if (!_window)
|
||||
_window = [[NSWindow alloc] initWithContentRect: _rect
|
||||
styleMask: style
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[_window release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
//
|
||||
// Getting the Representation
|
||||
//
|
||||
- (NSRect)rect
|
||||
- (NSRect) rect
|
||||
{
|
||||
return NSZeroRect;
|
||||
return _rect;
|
||||
}
|
||||
|
||||
- (NSWindow *)window
|
||||
- (NSWindow *) window
|
||||
{
|
||||
return nil;
|
||||
return _window;
|
||||
}
|
||||
|
||||
- (BOOL)draw
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder
|
||||
- (void) encodeWithCoder: aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
}
|
||||
|
||||
- initWithCoder:aDecoder
|
||||
- initWithCoder: aDecoder
|
||||
{
|
||||
[super initWithCoder:aDecoder];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
/*
|
||||
NSCustomImageRep.m
|
||||
|
||||
Description...
|
||||
Custom image representation.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Mar 1996
|
||||
|
||||
This file is part of the GNUstep Application Kit Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
|
@ -19,66 +19,68 @@
|
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
|
||||
If you are interested in a warranty or support for this source code,
|
||||
contact Scott Christley <scottc@net-community.com> for more information.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/NSCustomImageRep.h>
|
||||
#include <AppKit/NSCustomImageRep.h>
|
||||
|
||||
@implementation NSCustomImageRep
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
- (id) initWithDrawSelector: (SEL)aSelector
|
||||
delegate: (id)anObject
|
||||
{
|
||||
if (self == [NSCustomImageRep class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
}
|
||||
[super init];
|
||||
|
||||
/* WARNING: Retaining the delegate may or may not create a cyclic graph */
|
||||
delegate = [anObject retain];
|
||||
selector = aSelector;
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
|
||||
- (id)initWithDrawSelector:(SEL)aSelector
|
||||
delegate:(id)anObject
|
||||
- (void) dealloc
|
||||
{
|
||||
return nil;
|
||||
[delegate release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
//
|
||||
// Identifying the Object
|
||||
//
|
||||
- (id)delegate
|
||||
- (id) delegate
|
||||
{
|
||||
return nil;
|
||||
return delegate;
|
||||
}
|
||||
|
||||
- (SEL)drawSelector
|
||||
- (SEL) drawSelector
|
||||
{
|
||||
return NULL;
|
||||
return selector;
|
||||
}
|
||||
|
||||
- (BOOL) draw
|
||||
{
|
||||
[delegate perform: selector];
|
||||
return YES;
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder
|
||||
- (void) encodeWithCoder: aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
[super encodeWithCoder: aCoder];
|
||||
|
||||
[aCoder encodeObject: delegate];
|
||||
// FIXME: [aCoder encodeSelector: selector];
|
||||
}
|
||||
|
||||
- initWithCoder:aDecoder
|
||||
- initWithCoder: aDecoder
|
||||
{
|
||||
[super initWithCoder:aDecoder];
|
||||
self = [super initWithCoder: aDecoder];
|
||||
|
||||
delegate = [[aDecoder decodeObject] retain];
|
||||
// FIXME: selector = [aDecoder decodeSelector];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
/*
|
||||
NSEPSImageRep.m
|
||||
|
||||
Description...
|
||||
EPS image representation.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep Application Kit Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
|
@ -19,82 +19,63 @@
|
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
|
||||
If you are interested in a warranty or support for this source code,
|
||||
contact Scott Christley <scottc@net-community.com> for more information.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/NSEPSImageRep.h>
|
||||
#include <AppKit/NSEPSImageRep.h>
|
||||
|
||||
@implementation NSEPSImageRep
|
||||
@implementation NSEPSImageRep
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [NSEPSImageRep class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Initializing a New Instance
|
||||
//
|
||||
+ (id)imageRepWithData:(NSData *)epsData
|
||||
+ (id) imageRepWithData: (NSData *)epsData
|
||||
{
|
||||
return nil;
|
||||
[self notImplemented: _cmd];
|
||||
return self;
|
||||
}
|
||||
- (id) initWithData: (NSData *)epsData
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
//
|
||||
// Initializing a New Instance
|
||||
//
|
||||
- (id)initWithData:(NSData *)epsData
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Getting Image Data
|
||||
//
|
||||
- (NSRect)boundingBox
|
||||
- (NSRect) boundingBox
|
||||
{
|
||||
return NSZeroRect;
|
||||
NSRect rect;
|
||||
[self notImplemented: _cmd];
|
||||
return rect;
|
||||
}
|
||||
|
||||
- (NSData *)EPSRepresentation
|
||||
- (NSData *) EPSRepresentation
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Drawing the Image
|
||||
//
|
||||
- (void)prepareGState
|
||||
{}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder
|
||||
- (void) prepareGState
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- initWithCoder:aDecoder
|
||||
// NSCoding protocol
|
||||
- (void) encodeWithCoder: aCoder
|
||||
{
|
||||
[super initWithCoder:aDecoder];
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- initWithCoder: aDecoder
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
1003
Source/NSImage.m
1003
Source/NSImage.m
File diff suppressed because it is too large
Load diff
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
NSImageRep.m
|
||||
|
||||
Description...
|
||||
Abstract representation of an image.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep Application Kit Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
|
@ -19,7 +19,7 @@
|
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
|
||||
If you are interested in a warranty or support for this source code,
|
||||
contact Scott Christley <scottc@net-community.com> for more information.
|
||||
|
||||
|
@ -28,206 +28,369 @@
|
|||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/NSImageRep.h>
|
||||
#include <string.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <AppKit/NSImageRep.h>
|
||||
#include <AppKit/NSBitmapImageRep.h>
|
||||
#include <AppKit/NSEPSImageRep.h>
|
||||
|
||||
// NSImageRep notifications
|
||||
NSString *NSImageRepRegistryChangedNotification;
|
||||
|
||||
/* Backend protocol - methods that must be implemented by the backend to
|
||||
complete the class */
|
||||
@protocol NXImageRepBackend
|
||||
- (BOOL) drawAtPoint: (NSPoint)aPoint;
|
||||
- (BOOL) drawInRect: (NSRect)aRect;
|
||||
@end
|
||||
|
||||
static NSMutableArray* imageReps = NULL;
|
||||
|
||||
/* Get the extension from a name */
|
||||
static NSString *
|
||||
extension(NSString *name)
|
||||
{
|
||||
/* Waiting for NSString to be complete */
|
||||
#if 0
|
||||
return [name pathExtension];
|
||||
#else
|
||||
char *s;
|
||||
|
||||
s = strrchr([name cString], '.');
|
||||
if (s > strrchr([name cString], '/'))
|
||||
return [NSString stringWithCString:s+1];
|
||||
else
|
||||
return nil;
|
||||
#endif
|
||||
}
|
||||
|
||||
@implementation NSImageRep
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSImageRep class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
}
|
||||
/* While there are four imageRep subclasses, in practice, only two of
|
||||
them can load in data from an external source. */
|
||||
imageReps = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||
[imageReps addObject: [NSBitmapImageRep class]];
|
||||
[imageReps addObject: [NSEPSImageRep class]];
|
||||
}
|
||||
|
||||
//
|
||||
// Creating an NSImageRep
|
||||
//
|
||||
+ (id)imageRepWithContentsOfFile:(NSString *)filename
|
||||
+ (id) imageRepWithContentsOfFile: (NSString *)filename
|
||||
{
|
||||
NSArray* array;
|
||||
|
||||
array = [self imageRepsWithContentsOfFile: filename];
|
||||
if ([array count])
|
||||
return [array objectAtIndex: 0];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *)imageRepsWithContentsOfFile:(NSString *)filename
|
||||
+ (NSArray *) imageRepsWithContentsOfFile: (NSString *)filename
|
||||
{
|
||||
int i, count;
|
||||
NSString* ext;
|
||||
NSMutableArray* array;
|
||||
|
||||
ext = extension(filename);
|
||||
// FIXME: Should this be an exception? Should we even check this?
|
||||
if (!ext)
|
||||
return nil;
|
||||
array = [NSMutableArray arrayWithCapacity:1];
|
||||
|
||||
count = [imageReps count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
Class rep = [imageReps objectAtIndex: i];
|
||||
if ([[rep imageFileTypes] indexOfObject: ext] != NSNotFound)
|
||||
{
|
||||
NSData* data = [NSData dataWithContentsOfFile: filename];
|
||||
if ([rep class] == [NSBitmapImageRep class])
|
||||
[array addObject: [rep imageRepWithData: data]];
|
||||
}
|
||||
#if 0
|
||||
if ([rep respondsToSelector: @selector(imageFileTypes)]
|
||||
&& [[rep imageFileTypes] indexOfObject: ext] != NSNotFound)
|
||||
{
|
||||
NSData* data = [NSData dataWithContentsOfFile: filename];
|
||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
||||
[array addObjectsFromArray: [rep imageRepsWithData: data]];
|
||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||
[array addObject: [rep imageRepWithData: data]];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return (NSArray *)array;
|
||||
}
|
||||
|
||||
+ (id) imageRepWithPasteboard: (NSPasteboard *)pasteboard
|
||||
{
|
||||
NSArray* array;
|
||||
|
||||
array = [self imageRepsWithPasteboard: pasteboard];
|
||||
if ([array count])
|
||||
return [array objectAtIndex: 0];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (id)imageRepWithPasteboard:(NSPasteboard *)pasteboard
|
||||
+ (NSArray *) imageRepsWithPasteboard: (NSPasteboard *)pasteboard
|
||||
{
|
||||
return nil;
|
||||
int i, count;
|
||||
NSMutableArray* array;
|
||||
|
||||
array = [NSMutableArray arrayWithCapacity:1];
|
||||
|
||||
count = [imageReps count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
NSString* ptype;
|
||||
Class rep = [imageReps objectAtIndex: i];
|
||||
if ([rep respondsToSelector: @selector(imagePasteboardTypes)]
|
||||
&& (ptype =
|
||||
[pasteboard availableTypeFromArray:[rep imagePasteboardTypes]]))
|
||||
{
|
||||
NSData* data = [pasteboard dataForType: ptype];
|
||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
||||
[array addObjectsFromArray: [rep imageRepsWithData: data]];
|
||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||
[array addObject: [rep imageRepWithData: data]];
|
||||
}
|
||||
}
|
||||
return (NSArray *)array;
|
||||
}
|
||||
|
||||
+ (NSArray *)imageRepsWithPasteboard:(NSPasteboard *)pasteboard
|
||||
- (void) dealloc
|
||||
{
|
||||
return nil;
|
||||
[colorSpace release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Data Types
|
||||
//
|
||||
+ (BOOL)canInitWithData:(NSData *)data
|
||||
+ (BOOL) canInitWithData: (NSData *)data
|
||||
{
|
||||
/* Subclass responsibility */
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL)canInitWithPasteboard:(NSPasteboard *)pasteboard
|
||||
+ (BOOL) canInitWithPasteboard: (NSPasteboard *)pasteboard
|
||||
{
|
||||
/* Subclass responsibility */
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSArray *)imageFileTypes
|
||||
+ (NSArray *) imageFileTypes
|
||||
{
|
||||
/* Subclass responsibility */
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *)imagePasteboardTypes
|
||||
+ (NSArray *) imagePasteboardTypes
|
||||
{
|
||||
/* Subclass responsibility */
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *)imageUnfilteredFileTypes
|
||||
+ (NSArray *) imageUnfilteredFileTypes
|
||||
{
|
||||
/* Subclass responsibility */
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *)imageUnfilteredPasteboardTypes
|
||||
+ (NSArray *) imageUnfilteredPasteboardTypes
|
||||
{
|
||||
/* Subclass responsibility */
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Managing NSImageRep Subclasses
|
||||
//
|
||||
+ (Class)imageRepClassForData:(NSData *)data
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+ (Class)imageRepClassForFileType:(NSString *)type
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+ (Class)imageRepClassForPasteboardType:(NSString *)type
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+ (void)registerImageRepClass:(Class)imageRepClass
|
||||
{}
|
||||
|
||||
+ (NSArray *)registeredImageRepClasses
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (void)unregisterImageRepClass:(Class)imageRepClass
|
||||
{}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
//
|
||||
// Setting the Size of the Image
|
||||
//
|
||||
- (void)setSize:(NSSize)aSize
|
||||
{}
|
||||
|
||||
- (NSSize)size
|
||||
- (void) setSize: (NSSize)aSize
|
||||
{
|
||||
return NSZeroSize;
|
||||
size = aSize;
|
||||
}
|
||||
|
||||
- (NSSize) size
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
//
|
||||
// Specifying Information about the Representation
|
||||
//
|
||||
- (int)bitsPerSample
|
||||
- (int) bitsPerSample
|
||||
{
|
||||
return 0;
|
||||
return bitsPerSample;
|
||||
}
|
||||
|
||||
- (NSString *)colorSpaceName
|
||||
- (NSString *) colorSpaceName
|
||||
{
|
||||
return nil;
|
||||
return colorSpace;
|
||||
}
|
||||
|
||||
- (BOOL)hasAlpha
|
||||
- (BOOL) hasAlpha
|
||||
{
|
||||
return NO;
|
||||
return hasAlpha;
|
||||
}
|
||||
|
||||
- (BOOL)isOpaque
|
||||
- (BOOL) isOpaque
|
||||
{
|
||||
return NO;
|
||||
return isOpaque;
|
||||
}
|
||||
|
||||
- (int)pixelsHigh
|
||||
- (int) pixelsWide
|
||||
{
|
||||
return 0;
|
||||
return _pixelsWide;
|
||||
}
|
||||
|
||||
- (int)pixelsWide
|
||||
- (int) pixelsHigh
|
||||
{
|
||||
return 0;
|
||||
return _pixelsHigh;
|
||||
}
|
||||
|
||||
- (void)setAlpha:(BOOL)flag
|
||||
{}
|
||||
- (void) setAlpha: (BOOL)flag
|
||||
{
|
||||
hasAlpha = flag;
|
||||
}
|
||||
|
||||
- (void)setBitsPerSample:(int)anInt
|
||||
{}
|
||||
- (void) setBitsPerSample: (int)anInt
|
||||
{
|
||||
bitsPerSample = anInt;
|
||||
}
|
||||
|
||||
- (void)setColorSpaceName:(NSString *)aString
|
||||
{}
|
||||
- (void) setColorSpaceName: (NSString *)aString
|
||||
{
|
||||
[colorSpace autorelease];
|
||||
colorSpace = [aString retain];
|
||||
}
|
||||
|
||||
- (void)setOpaque:(BOOL)flag
|
||||
{}
|
||||
- (void) setOpaque: (BOOL)flag
|
||||
{
|
||||
isOpaque = flag;
|
||||
}
|
||||
|
||||
- (void)setPixelsHigh:(int)anInt
|
||||
{}
|
||||
- (void) setPixelsWide: (int)anInt
|
||||
{
|
||||
_pixelsWide = anInt;
|
||||
}
|
||||
|
||||
- (void)setPixelsWide:(int)anInt
|
||||
{}
|
||||
- (void) setPixelsHigh: (int)anInt
|
||||
{
|
||||
_pixelsHigh = anInt;
|
||||
}
|
||||
|
||||
//
|
||||
// Drawing the Image
|
||||
//
|
||||
- (BOOL)draw
|
||||
- (BOOL) draw
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) drawAtPoint: (NSPoint)aPoint
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)drawAtPoint:(NSPoint)aPoint
|
||||
- (BOOL) drawInRect: (NSRect)aRect
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)drawInRect:(NSRect)aRect
|
||||
// Managing NSImageRep Subclasses
|
||||
+ (Class) imageRepClassForData: (NSData *)data
|
||||
{
|
||||
return NO;
|
||||
int i, count;
|
||||
|
||||
count = [imageReps count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
Class rep = [imageReps objectAtIndex: i];
|
||||
if ([rep canInitWithData: data])
|
||||
return rep;
|
||||
}
|
||||
return Nil;
|
||||
}
|
||||
|
||||
+ (Class) imageRepClassForFileType: (NSString *)type
|
||||
{
|
||||
int i, count;
|
||||
|
||||
count = [imageReps count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
Class rep = [imageReps objectAtIndex: i];
|
||||
if ([rep respondsToSelector: @selector(imageFileTypes)]
|
||||
&& [[rep imageFileTypes] indexOfObject: type] != NSNotFound)
|
||||
{
|
||||
return rep;
|
||||
}
|
||||
}
|
||||
return Nil;
|
||||
}
|
||||
|
||||
+ (Class) imageRepClassForPasteboardType: (NSString *)type
|
||||
{
|
||||
int i, count;
|
||||
|
||||
count = [imageReps count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
Class rep = [imageReps objectAtIndex: i];
|
||||
if ([rep respondsToSelector: @selector(imagePasteboardTypes)]
|
||||
&& ([[rep imagePasteboardTypes] indexOfObject: type] != NSNotFound))
|
||||
{
|
||||
return rep;
|
||||
}
|
||||
}
|
||||
return Nil;
|
||||
}
|
||||
|
||||
+ (void) registerImageRepClass: (Class)imageRepClass
|
||||
{
|
||||
[imageReps addObject: imageRepClass];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSImageRepRegistryChangedNotification
|
||||
object: self];
|
||||
}
|
||||
|
||||
+ (NSArray *) registeredImageRepClasses
|
||||
{
|
||||
return (NSArray *)imageReps;
|
||||
}
|
||||
|
||||
+ (void) unregisterImageRepClass: (Class)imageRepClass
|
||||
{
|
||||
[imageReps removeObject: imageRepClass];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSImageRepRegistryChangedNotification
|
||||
object: self];
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder
|
||||
- (void) encodeWithCoder: aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
[super encodeWithCoder: aCoder];
|
||||
|
||||
[aCoder encodeObject: colorSpace];
|
||||
[aCoder encodeSize: size];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &hasAlpha];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &isOpaque];
|
||||
[aCoder encodeValueOfObjCType: @encode(int) at: &bitsPerSample];
|
||||
[aCoder encodeValueOfObjCType: @encode(int) at: &_pixelsWide];
|
||||
[aCoder encodeValueOfObjCType: @encode(int) at: &_pixelsHigh];
|
||||
}
|
||||
|
||||
- initWithCoder:aDecoder
|
||||
- initWithCoder: aDecoder
|
||||
{
|
||||
[super initWithCoder:aDecoder];
|
||||
self = [super initWithCoder: aDecoder];
|
||||
|
||||
colorSpace = [[aDecoder decodeObject] retain];
|
||||
size = [aDecoder decodeSize];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &hasAlpha];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &isOpaque];
|
||||
[aDecoder decodeValueOfObjCType: @encode(int) at: &bitsPerSample];
|
||||
[aDecoder decodeValueOfObjCType: @encode(int) at: &_pixelsWide];
|
||||
[aDecoder decodeValueOfObjCType: @encode(int) at: &_pixelsHigh];
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -101,7 +101,10 @@ NSString *NSWindowWillMoveNotification;
|
|||
}
|
||||
|
||||
// Screens and window depths
|
||||
//+ (NSWindowDepth)defaultDepthLimit
|
||||
+ (NSWindowDepth)defaultDepthLimit
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
|
@ -630,13 +633,36 @@ NSString *NSWindowWillMoveNotification;
|
|||
}
|
||||
|
||||
// Screens and window depths
|
||||
//- (BOOL)canStoreColor;
|
||||
//- (NSScreen *)deepestScreen;
|
||||
//- (NSWindowDepth)depthLimit;
|
||||
//- (BOOL)hasDynamicDepthLimit;
|
||||
//- (NSScreen *)screen;
|
||||
//- (void)setDepthLimit:(NSWindowDepth)limit;
|
||||
//- (void)setDynamicDepthLimit:(BOOL)flag;
|
||||
- (BOOL)canStoreColor
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSScreen *)deepestScreen
|
||||
{
|
||||
return [NSScreen deepestScreen];
|
||||
}
|
||||
|
||||
- (NSWindowDepth)depthLimit
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (BOOL)hasDynamicDepthLimit
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSScreen *)screen
|
||||
{
|
||||
return [NSScreen mainScreen];
|
||||
}
|
||||
|
||||
- (void)setDepthLimit:(NSWindowDepth)limit
|
||||
{}
|
||||
|
||||
- (void)setDynamicDepthLimit:(BOOL)flag
|
||||
{}
|
||||
|
||||
//
|
||||
// Cursor management
|
||||
|
|
474
Source/tiff.c
Normal file
474
Source/tiff.c
Normal file
|
@ -0,0 +1,474 @@
|
|||
/* tiff - Functions for dealing with tiff images
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@colorado.edu>
|
||||
Date: Feb 1996
|
||||
|
||||
This file is part of the GNUstep Application Kit Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/* Code in NSTiffRead, NSTiffGetInfo, and NSTiffGetColormap
|
||||
is derived from tif_getimage, by Sam Leffler. See the copyright below.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1991, 1992, 1993, 1994 Sam Leffler
|
||||
* Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h> /* for L_SET, etc definitions */
|
||||
#include <gnustep/base/objc-malloc.h>
|
||||
#include <AppKit/nsimage-tiff.h>
|
||||
|
||||
typedef struct {
|
||||
char* data;
|
||||
long size;
|
||||
long position;
|
||||
const char* mode;
|
||||
realloc_data_callback* realloc_data;
|
||||
} chandle_t;
|
||||
|
||||
#ifdef HAVE_LIBTIFF
|
||||
|
||||
/* Client functions that provide reading/writing of data for libtiff */
|
||||
static tsize_t
|
||||
TiffHandleRead(thandle_t handle, tdata_t buf, toff_t count)
|
||||
{
|
||||
chandle_t* chand = (chandle_t *)handle;
|
||||
printf("TiffHandleRead\n");
|
||||
if (chand->position >= chand->size)
|
||||
return 0;
|
||||
if (chand->position + count > chand->size)
|
||||
count = chand->size - chand->position;
|
||||
memcpy(buf, chand->data + chand->position, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static tsize_t
|
||||
TiffHandleWrite(thandle_t handle, tdata_t buf, toff_t count)
|
||||
{
|
||||
chandle_t* chand = (chandle_t *)handle;
|
||||
printf("TiffHandleWrite\n");
|
||||
if (chand->mode == "r")
|
||||
return 0;
|
||||
if (chand->position + count > chand->size)
|
||||
{
|
||||
if (chand->realloc_data == NULL)
|
||||
return 0;
|
||||
chand->size = chand->position + count + 1;
|
||||
chand->data = chand->realloc_data(chand->data, chand->size);
|
||||
if (chand->data == NULL)
|
||||
return 0;
|
||||
}
|
||||
memcpy(chand->data + chand->position, buf, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static toff_t
|
||||
TiffHandleSeek(thandle_t handle, toff_t offset, int mode)
|
||||
{
|
||||
chandle_t* chand = (chandle_t *)handle;
|
||||
printf("TiffHandleSeek\n");
|
||||
switch(mode)
|
||||
{
|
||||
case SEEK_SET: chand->position = offset; break;
|
||||
case SEEK_CUR: chand->position += offset; break;
|
||||
case SEEK_END:
|
||||
if (offset > 0 && chand->mode == "r")
|
||||
return 0;
|
||||
chand->position += offset; break;
|
||||
break;
|
||||
}
|
||||
return chand->position;
|
||||
}
|
||||
|
||||
static int
|
||||
TiffHandleClose(thandle_t handle)
|
||||
{
|
||||
chandle_t* chand = (chandle_t *)handle;
|
||||
|
||||
printf("TiffHandleClose\n");
|
||||
/* Presumably, we don't need the handle anymore */
|
||||
OBJC_FREE(chand);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static toff_t
|
||||
TiffHandleSize(thandle_t handle)
|
||||
{
|
||||
chandle_t* chand = (chandle_t *)handle;
|
||||
printf("TiffHandleSize\n");
|
||||
return chand->size;
|
||||
}
|
||||
|
||||
static int
|
||||
TiffHandleMap(thandle_t handle, tdata_t* data, toff_t* size)
|
||||
{
|
||||
chandle_t* chand = (chandle_t *)handle;
|
||||
|
||||
printf("TiffHandleMap\n");
|
||||
*data = chand->data;
|
||||
*size = chand->size;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
TiffHandleUnmap(thandle_t handle, tdata_t data, toff_t size)
|
||||
{
|
||||
printf("TiffHandleUnmap\n");
|
||||
/* Nothing to unmap. */
|
||||
}
|
||||
|
||||
/* Open a tiff from a stream. Returns NULL if can't read tiff information. */
|
||||
TIFF*
|
||||
NSTiffOpenData(char* data, long size, const char* mode,
|
||||
realloc_data_callback* realloc_data)
|
||||
{
|
||||
chandle_t* handle;
|
||||
printf("NSTiffOpenData\n");
|
||||
OBJC_MALLOC(handle, chandle_t, 1);
|
||||
handle->data = data;
|
||||
handle->position = 0;
|
||||
handle->size = size;
|
||||
handle->mode = mode;
|
||||
handle->realloc_data = realloc_data;
|
||||
return TIFFClientOpen("NSData", mode,
|
||||
(thandle_t)handle,
|
||||
TiffHandleRead, TiffHandleWrite,
|
||||
TiffHandleSeek, TiffHandleClose,
|
||||
TiffHandleSize,
|
||||
TiffHandleMap, TiffHandleUnmap);
|
||||
}
|
||||
|
||||
int
|
||||
NSTiffClose(TIFF* image)
|
||||
{
|
||||
TIFFClose(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read some information about the image. Note that currently we don't
|
||||
determine numImages. */
|
||||
NSTiffInfo *
|
||||
NSTiffGetInfo(int imageNumber, TIFF* image)
|
||||
{
|
||||
NSTiffInfo* info;
|
||||
|
||||
if (imageNumber >= 0 && !TIFFSetDirectory(image, imageNumber))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OBJC_MALLOC(info, NSTiffInfo, 1);
|
||||
memset(info, 0, sizeof(NSTiffInfo));
|
||||
if (imageNumber >= 0)
|
||||
info->imageNumber = imageNumber;
|
||||
|
||||
TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &info->width);
|
||||
TIFFGetField(image, TIFFTAG_IMAGELENGTH, &info->height);
|
||||
TIFFGetField(image, TIFFTAG_COMPRESSION, &info->compression);
|
||||
TIFFGetField(image, TIFFTAG_SUBFILETYPE, &info->subfileType);
|
||||
|
||||
/* If the following tags aren't present then use the TIFF defaults. */
|
||||
TIFFGetFieldDefaulted(image, TIFFTAG_BITSPERSAMPLE, &info->bitsPerSample);
|
||||
TIFFGetFieldDefaulted(image, TIFFTAG_SAMPLESPERPIXEL,
|
||||
&info->samplesPerPixel);
|
||||
TIFFGetFieldDefaulted(image, TIFFTAG_PLANARCONFIG,
|
||||
&info->planarConfig);
|
||||
|
||||
/* If TIFFTAG_PHOTOMETRIC is not present then assign a reasonable default.
|
||||
The TIFF 5.0 specification doesn't give a default. */
|
||||
if (!TIFFGetField(image, TIFFTAG_PHOTOMETRIC, &info->photoInterp))
|
||||
{
|
||||
switch (info->samplesPerPixel)
|
||||
{
|
||||
case 1:
|
||||
info->photoInterp = PHOTOMETRIC_MINISBLACK;
|
||||
break;
|
||||
case 3: case 4:
|
||||
info->photoInterp = PHOTOMETRIC_RGB;
|
||||
break;
|
||||
default:
|
||||
TIFFError(TIFFFileName(image),
|
||||
"Missing needed \"PhotometricInterpretation\" tag");
|
||||
return (0);
|
||||
}
|
||||
TIFFError(TIFFFileName(image),
|
||||
"No \"PhotometricInterpretation\" tag, assuming %s\n",
|
||||
info->photoInterp == PHOTOMETRIC_RGB ? "RGB" : "min-is-black");
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
#define READ_SCANLINE(sample) \
|
||||
if ( TIFFReadScanline( image, buf, row, sample ) < 0 ) { \
|
||||
fprintf(stderr, "tiff: bad data read on line %d\n", row ); \
|
||||
error = 1; \
|
||||
break; \
|
||||
} \
|
||||
inP = buf;
|
||||
|
||||
/* Read an image into a data array. The data array is assumed to have been
|
||||
already allocated to the correct size.
|
||||
|
||||
Note that palette images are implicitly coverted to 24-bit contig
|
||||
direct color images. Thus the data array should be large
|
||||
enough to hold this information. */
|
||||
int
|
||||
NSTiffRead(int imageNumber, TIFF* image, NSTiffInfo* info, char* data)
|
||||
{
|
||||
int i;
|
||||
int row, col;
|
||||
int maxval;
|
||||
int size;
|
||||
int line;
|
||||
int error = 0;
|
||||
u_char* inP;
|
||||
u_char* outP;
|
||||
u_char* buf;
|
||||
u_char* raster;
|
||||
NSTiffInfo* newinfo;
|
||||
NSTiffColormap* map;
|
||||
int scan_line_size;
|
||||
|
||||
if (data == NULL)
|
||||
return -1;
|
||||
|
||||
/* Make sure we're at the right image */
|
||||
if ((newinfo = NSTiffGetInfo(imageNumber, image)) == NULL)
|
||||
return -1;
|
||||
|
||||
if (info)
|
||||
memcpy(info, newinfo, sizeof(NSTiffInfo));
|
||||
|
||||
map = NULL;
|
||||
if ( newinfo->photoInterp == PHOTOMETRIC_PALETTE)
|
||||
{
|
||||
map = NSTiffGetColormap(image);
|
||||
if (!map)
|
||||
return -1;
|
||||
}
|
||||
|
||||
maxval = ( 1 << newinfo->bitsPerSample ) - 1;
|
||||
line = ceil((float)newinfo->width * newinfo->bitsPerSample / 8.0);
|
||||
size = ceil((float)line * newinfo->height * newinfo->samplesPerPixel );
|
||||
scan_line_size = TIFFScanlineSize(image);
|
||||
OBJC_MALLOC(buf, u_char, TIFFScanlineSize(image));
|
||||
|
||||
raster = (u_char *)data;
|
||||
outP = raster;
|
||||
switch ( newinfo->photoInterp )
|
||||
{
|
||||
case PHOTOMETRIC_MINISBLACK:
|
||||
case PHOTOMETRIC_MINISWHITE:
|
||||
if (newinfo->planarConfig == PLANARCONFIG_CONTIG)
|
||||
{
|
||||
for ( row = 0; row < newinfo->height; ++row )
|
||||
{
|
||||
READ_SCANLINE(0)
|
||||
for ( col = 0; col < line*newinfo->samplesPerPixel; col++)
|
||||
*outP++ = *inP++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < newinfo->samplesPerPixel; i++)
|
||||
for ( row = 0; row < newinfo->height; ++row )
|
||||
{
|
||||
READ_SCANLINE(i)
|
||||
for ( col = 0; col < line; col++)
|
||||
*outP++ = *inP++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PHOTOMETRIC_PALETTE:
|
||||
{
|
||||
for ( row = 0; row < newinfo->height; ++row )
|
||||
{
|
||||
READ_SCANLINE(0)
|
||||
for ( col = 0; col < newinfo->width; col++)
|
||||
{
|
||||
*outP++ = map->red[*inP] / 256;
|
||||
*outP++ = map->green[*inP] / 256;
|
||||
*outP++ = map->blue[*inP] / 256;
|
||||
inP++;
|
||||
}
|
||||
}
|
||||
free(map->red);
|
||||
free(map->green);
|
||||
free(map->blue);
|
||||
free(map);
|
||||
}
|
||||
break;
|
||||
case PHOTOMETRIC_RGB:
|
||||
if (newinfo->planarConfig == PLANARCONFIG_CONTIG)
|
||||
{
|
||||
for ( row = 0; row < newinfo->height; ++row )
|
||||
{
|
||||
READ_SCANLINE(0)
|
||||
for ( col = 0; col < newinfo->width; col++)
|
||||
for (i = 0; i < newinfo->samplesPerPixel; i++)
|
||||
*outP++ = *inP++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < newinfo->samplesPerPixel; i++)
|
||||
for ( row = 0; row < newinfo->height; ++row )
|
||||
{
|
||||
READ_SCANLINE(i)
|
||||
for ( col = 0; col < newinfo->width; col++)
|
||||
*outP++ = *inP++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
TIFFError(TIFFFileName(image),
|
||||
"Can't read photometric %d", newinfo->photoInterp);
|
||||
break;
|
||||
}
|
||||
|
||||
OBJC_FREE(newinfo);
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
NSWriteTiff(TIFF* image, NSTiffInfo* info, char* data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
/* Many programs get TIFF colormaps wrong. They use 8-bit colormaps
|
||||
instead of 16-bit colormaps. This function is a heuristic to
|
||||
detect and correct this. */
|
||||
static int
|
||||
CheckAndCorrectColormap(NSTiffColormap* map)
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < map->size; i++)
|
||||
if ((map->red[i] > 255)||(map->green[i] > 255)||(map->blue[i] > 255))
|
||||
return 16;
|
||||
|
||||
#define CVT(x) (((x) * 255) / ((1L<<16)-1))
|
||||
for (i = 0; i < map->size; i++)
|
||||
{
|
||||
map->red[i] = CVT(map->red[i]);
|
||||
map->green[i] = CVT(map->green[i]);
|
||||
map->blue[i] = CVT(map->blue[i]);
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
|
||||
/* Gets the colormap for the image if there is one. Returns a
|
||||
NSTiffColormap if one was found.
|
||||
*/
|
||||
NSTiffColormap *
|
||||
NSTiffGetColormap(TIFF* image)
|
||||
{
|
||||
NSTiffInfo* info;
|
||||
NSTiffColormap* map;
|
||||
|
||||
/* Re-read the tiff information. We pass -1 as the image number which
|
||||
means just read the current image. */
|
||||
info = NSTiffGetInfo(-1, image);
|
||||
if (info->photoInterp != PHOTOMETRIC_PALETTE)
|
||||
return NULL;
|
||||
|
||||
OBJC_MALLOC(map, NSTiffColormap, 1);
|
||||
map->size = 1 << info->bitsPerSample;
|
||||
|
||||
if (!TIFFGetField(image, TIFFTAG_COLORMAP,
|
||||
&map->red, &map->green, &map->blue))
|
||||
{
|
||||
TIFFError(TIFFFileName(image), "Missing required \"Colormap\" tag");
|
||||
OBJC_FREE(map);
|
||||
return NULL;
|
||||
}
|
||||
if (CheckAndCorrectColormap(map) == 8)
|
||||
TIFFWarning(TIFFFileName(image), "Assuming 8-bit colormap");
|
||||
|
||||
free(info);
|
||||
return map;
|
||||
}
|
||||
|
||||
#else /* HAVE_LIBTIFF */
|
||||
|
||||
TIFF*
|
||||
NSTiffOpenData(char* data, long size, const char* mode,
|
||||
realloc_data_callback* realloc_data)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
NSTiffClose(TIFF* image)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSTiffInfo *
|
||||
NSTiffGetInfo(int imageNumber, TIFF* image)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
NSTiffRead(int imageNumber, TIFF* image, NSTiffInfo* info, char* data)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
NSTiffWrite(TIFF* image, NSTiffInfo* info, char* data)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
NSTiffColormap *
|
||||
NSTiffGetColormap(TIFF* image)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* not HAVE_LIBTIFF */
|
Loading…
Reference in a new issue