mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-26 07:50:58 +00:00
Image improvements.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6481 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a51fd0ad14
commit
b9de76dad5
5 changed files with 103 additions and 16 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2000-04-18 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Hooks for using backend libraries to read images.
|
||||
* Source/NSBitmapImageRep.m (-_initFromWrasterFile:number:): New stub
|
||||
for backends.
|
||||
(+imageRepsWithFile:): New method.
|
||||
(+_wrasterFileTypes): New stub for backend.
|
||||
(+imageFileTypes): Include wraster file types.
|
||||
* Source/NSImageRep.m (+imageRepsWithContentsOfFile:): Check/use if
|
||||
rep implements +imageRepsWithFile.
|
||||
|
||||
* Headers/gnustep/gui/nsimage-tiff.h: Add field for associated alpha.
|
||||
* Source/tiff.m: Set it.
|
||||
|
||||
2000-04-17 Jonathan Gapen <jagapen@whitewater.chem.wisc.edu>
|
||||
|
||||
* Headers/gnustep/gui/NSColorPanel.h: New ivars for panel objects.
|
||||
|
|
|
@ -49,6 +49,7 @@ typedef struct {
|
|||
u_short photoInterp; /* photometric interpretation of bitmap data, */
|
||||
u_short compression;
|
||||
u_short extraSamples; /* Alpha */
|
||||
int assocAlpha;
|
||||
int quality; /* compression quality (for jpeg) 1 to 255 */
|
||||
int numImages; /* number of images in tiff */
|
||||
int error;
|
||||
|
|
|
@ -45,17 +45,17 @@
|
|||
/* Maximum number of planes */
|
||||
#define MAX_PLANES 5
|
||||
|
||||
/* Backend protocol - methods that must be implemented by the backend to
|
||||
complete the class */
|
||||
@protocol NXBitmapImageRepBackend
|
||||
- (BOOL) draw;
|
||||
/* Backend methods (optional) */
|
||||
@interface NSBitmapImageRep (Backend)
|
||||
+ (NSArray *) _wrasterFileTypes;
|
||||
- _initFromWrasterFile: (NSString *)filename number: (int)imageNumber;
|
||||
@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
|
||||
- _initFromTIFFImage: (TIFF *)image number: (int)imageNumber
|
||||
{
|
||||
NSString* space;
|
||||
NSTiffInfo* info;
|
||||
|
@ -64,6 +64,7 @@
|
|||
info = NSTiffGetInfo(imageNumber, image);
|
||||
if (!info)
|
||||
{
|
||||
RELEASE(self);
|
||||
NSLog(@"Tiff read invalid TIFF info in directory %d", imageNumber);
|
||||
return nil;
|
||||
}
|
||||
|
@ -99,6 +100,7 @@
|
|||
|
||||
if (NSTiffRead(image, info, [self bitmapData]))
|
||||
{
|
||||
RELEASE(self);
|
||||
NSLog(@"Tiff read invalid TIFF image data in directory %d", imageNumber);
|
||||
return nil;
|
||||
}
|
||||
|
@ -106,6 +108,11 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- _initFromWrasterFile: (NSString *)filename number: (int)imageNumber
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (id) imageRepWithData: (NSData *)tiffData
|
||||
{
|
||||
NSArray* array;
|
||||
|
@ -135,7 +142,7 @@
|
|||
for (i = 0; i < images; i++)
|
||||
{
|
||||
NSBitmapImageRep* imageRep;
|
||||
imageRep = [[[self class] alloc] _initFromImage: image number: i];
|
||||
imageRep = [[[self class] alloc] _initFromTIFFImage: image number: i];
|
||||
if (imageRep)
|
||||
[array addObject: AUTORELEASE(imageRep)];
|
||||
}
|
||||
|
@ -144,6 +151,43 @@
|
|||
return array;
|
||||
}
|
||||
|
||||
/* A special method used mostly when we have the wraster library in the
|
||||
backend, which can read several more image formats */
|
||||
+ (NSArray*) imageRepsWithFile: (NSString *)filename
|
||||
{
|
||||
NSString *ext;
|
||||
int images;
|
||||
NSMutableArray *array;
|
||||
NSBitmapImageRep* imageRep;
|
||||
|
||||
/* Don't use this for TIFF images, use the regular ...Data methods */
|
||||
ext = [filename pathExtension];
|
||||
if (!ext)
|
||||
{
|
||||
NSLog(@"Extension missing from filename - '%@'", filename);
|
||||
return nil;
|
||||
}
|
||||
if ([[self imageUnfilteredFileTypes] indexOfObject: ext] != NSNotFound)
|
||||
{
|
||||
NSData* data = [NSData dataWithContentsOfFile: filename];
|
||||
return [self imageRepsWithData: data];
|
||||
}
|
||||
|
||||
array = [NSMutableArray arrayWithCapacity: 2];
|
||||
images = 0;
|
||||
do
|
||||
{
|
||||
imageRep = [[[self class] alloc] _initFromWrasterFile: filename
|
||||
number: images];
|
||||
if (imageRep)
|
||||
[array addObject: AUTORELEASE(imageRep)];
|
||||
images++;
|
||||
}
|
||||
while (imageRep);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/* Loads only the default (first) image from the TIFF image contained in
|
||||
data. */
|
||||
- (id) initWithData: (NSData *)tiffData
|
||||
|
@ -153,10 +197,12 @@
|
|||
image = NSTiffOpenDataRead((char *)[tiffData bytes], [tiffData length]);
|
||||
if (image == 0)
|
||||
{
|
||||
[NSException raise:NSTIFFException format: @"Read invalid TIFF data"];
|
||||
RELEASE(self);
|
||||
NSLog(@"Tiff read invalid TIFF info from data");
|
||||
return nil;
|
||||
}
|
||||
|
||||
[self _initFromImage:image number: -1];
|
||||
[self _initFromTIFFImage:image number: -1];
|
||||
NSTiffClose(image);
|
||||
return self;
|
||||
}
|
||||
|
@ -280,9 +326,23 @@
|
|||
return [[pasteboard types] containsObject: NSTIFFPboardType];
|
||||
}
|
||||
|
||||
+ (NSArray *) _wrasterFileTypes
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *) imageFileTypes
|
||||
{
|
||||
return [self imageUnfilteredFileTypes];
|
||||
NSArray *wtypes = [self _wrasterFileTypes];
|
||||
if (wtypes)
|
||||
{
|
||||
wtypes = AUTORELEASE([wtypes mutableCopy]);
|
||||
[(NSMutableArray *)wtypes addObjectsFromArray:
|
||||
[self imageUnfilteredFileTypes]];
|
||||
}
|
||||
else
|
||||
wtypes = [self imageUnfilteredFileTypes];
|
||||
return wtypes;
|
||||
}
|
||||
|
||||
+ (NSArray *) imagePasteboardTypes
|
||||
|
|
|
@ -82,23 +82,32 @@ static NSMutableArray* imageReps = NULL;
|
|||
// FIXME: Should this be an exception? Should we even check this?
|
||||
if (!ext)
|
||||
{
|
||||
NSLog(@"extension missing from filename - '%@'", filename);
|
||||
NSLog(@"Extension missing from filename - '%@'", filename);
|
||||
return nil;
|
||||
}
|
||||
array = [NSMutableArray arrayWithCapacity: 1];
|
||||
|
||||
array = nil;
|
||||
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];
|
||||
NSData* data;
|
||||
|
||||
|
||||
if ([rep respondsToSelector: @selector(imageRepsWithFile:)])
|
||||
array = [rep imageRepsWithFile: filename];
|
||||
if ([array count] > 0)
|
||||
break;
|
||||
|
||||
data = [NSData dataWithContentsOfFile: filename];
|
||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
||||
[array addObjectsFromArray: [rep imageRepsWithData: data]];
|
||||
array = [rep imageRepsWithData: data];
|
||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||
[array addObject: [rep imageRepWithData: data]];
|
||||
array = [rep imageRepWithData: data];
|
||||
if ([array count] > 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (NSArray *)array;
|
||||
|
|
|
@ -285,8 +285,11 @@ NSTiffGetInfo(int imageNumber, TIFF* image)
|
|||
TIFFGetField(image, TIFFTAG_JPEGQUALITY, &info->quality);
|
||||
TIFFGetField(image, TIFFTAG_SUBFILETYPE, &info->subfileType);
|
||||
TIFFGetField(image, TIFFTAG_EXTRASAMPLES, &info->extraSamples, &sample_info);
|
||||
if (info->extraSamples == EXTRASAMPLE_ASSOCALPHA && sample_info)
|
||||
info->extraSamples = sample_info[0];
|
||||
info->extraSamples = (info->extraSamples == 1
|
||||
&& ((sample_info[0] == EXTRASAMPLE_ASSOCALPHA)
|
||||
|| (sample_info[0] == EXTRASAMPLE_UNASSALPHA)));
|
||||
info->assocAlpha = (info->extraSamples == 1
|
||||
&& sample_info[0] == EXTRASAMPLE_ASSOCALPHA);
|
||||
|
||||
/* If the following tags aren't present then use the TIFF defaults. */
|
||||
TIFFGetFieldDefaulted(image, TIFFTAG_BITSPERSAMPLE, &info->bitsPerSample);
|
||||
|
|
Loading…
Reference in a new issue