mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 19:00:59 +00:00
Moved code to create the _imageData into
[initWithBitmapDataPlanes:...] and corrected [copyWithZone:] git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10118 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f9d1c47f89
commit
9cd3d8198e
1 changed files with 150 additions and 118 deletions
|
@ -35,6 +35,7 @@
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
#include <Foundation/NSData.h>
|
#include <Foundation/NSData.h>
|
||||||
#include <AppKit/NSGraphics.h>
|
#include <AppKit/NSGraphics.h>
|
||||||
|
#include <AppKit/NSView.h>
|
||||||
#include <AppKit/NSPasteboard.h>
|
#include <AppKit/NSPasteboard.h>
|
||||||
#include <AppKit/NSBitmapImageRep.h>
|
#include <AppKit/NSBitmapImageRep.h>
|
||||||
#include <AppKit/AppKitExceptions.h>
|
#include <AppKit/AppKitExceptions.h>
|
||||||
|
@ -49,63 +50,53 @@
|
||||||
@interface NSBitmapImageRep (Backend)
|
@interface NSBitmapImageRep (Backend)
|
||||||
+ (NSArray *) _wrasterFileTypes;
|
+ (NSArray *) _wrasterFileTypes;
|
||||||
- _initFromWrasterFile: (NSString *)filename number: (int)imageNumber;
|
- _initFromWrasterFile: (NSString *)filename number: (int)imageNumber;
|
||||||
|
|
||||||
|
// GNUstep extension
|
||||||
|
- _initFromTIFFImage: (TIFF *)image number: (int)imageNumber;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSBitmapImageRep
|
@implementation NSBitmapImageRep
|
||||||
|
|
||||||
/* Given a TIFF image (from the libtiff library), load the image information
|
+ (BOOL) canInitWithData: (NSData *)data
|
||||||
into our data structure. Reads the specified image. */
|
|
||||||
- _initFromTIFFImage: (TIFF *)image number: (int)imageNumber
|
|
||||||
{
|
{
|
||||||
NSString* space;
|
TIFF *image = NULL;
|
||||||
NSTiffInfo* info;
|
image = NSTiffOpenDataRead((char *)[data bytes], [data length]);
|
||||||
|
NSTiffClose(image);
|
||||||
|
|
||||||
/* Seek to the correct image and get the dictionary information */
|
return (image) ? YES : NO;
|
||||||
info = NSTiffGetInfo(imageNumber, image);
|
}
|
||||||
if (!info)
|
|
||||||
|
+ (NSArray *) imageUnfilteredFileTypes
|
||||||
|
{
|
||||||
|
static NSArray *types = nil;
|
||||||
|
|
||||||
|
if (types == nil)
|
||||||
{
|
{
|
||||||
RELEASE(self);
|
NSArray *wtypes = [self _wrasterFileTypes];
|
||||||
NSLog(@"Tiff read invalid TIFF info in directory %d", imageNumber);
|
|
||||||
return nil;
|
if (wtypes != nil)
|
||||||
|
{
|
||||||
|
types = [wtypes mutableCopy];
|
||||||
|
[(NSMutableArray *)types addObjectsFromArray:
|
||||||
|
[NSArray arrayWithObjects: @"tiff", @"tif", nil]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
types = [[NSArray alloc] initWithObjects: @"tiff", @"tif", nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 8-bit RGB will be converted to 24-bit by the tiff routines, so account
|
return types;
|
||||||
for this. */
|
}
|
||||||
space = nil;
|
|
||||||
switch(info->photoInterp)
|
+ (NSArray *) imageUnfilteredPasteboardTypes
|
||||||
|
{
|
||||||
|
static NSArray *types = nil;
|
||||||
|
|
||||||
|
if (types == nil)
|
||||||
{
|
{
|
||||||
case PHOTOMETRIC_MINISBLACK: space = NSDeviceWhiteColorSpace; break;
|
types = [[NSArray alloc] initWithObjects: NSTIFFPboardType, nil];
|
||||||
case PHOTOMETRIC_MINISWHITE: space = NSDeviceBlackColorSpace; break;
|
|
||||||
case PHOTOMETRIC_RGB: space = NSDeviceRGBColorSpace; break;
|
|
||||||
case PHOTOMETRIC_PALETTE:
|
|
||||||
space = NSDeviceRGBColorSpace;
|
|
||||||
info->samplesPerPixel = 3;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[self initWithBitmapDataPlanes: NULL
|
return types;
|
||||||
pixelsWide: info->width
|
|
||||||
pixelsHigh: info->height
|
|
||||||
bitsPerSample: info->bitsPerSample
|
|
||||||
samplesPerPixel: info->samplesPerPixel
|
|
||||||
hasAlpha: (info->extraSamples > 0)
|
|
||||||
isPlanar: (info->planarConfig == PLANARCONFIG_SEPARATE)
|
|
||||||
colorSpaceName: space
|
|
||||||
bytesPerRow: 0
|
|
||||||
bitsPerPixel: 0];
|
|
||||||
_compression = info->compression;
|
|
||||||
_comp_factor = 255 * (1 - ((float)info->quality)/100.0);
|
|
||||||
|
|
||||||
if (NSTiffRead(image, info, [self bitmapData]))
|
|
||||||
{
|
|
||||||
RELEASE(self);
|
|
||||||
NSLog(@"Tiff read invalid TIFF image data in directory %d", imageNumber);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id) imageRepWithData: (NSData *)tiffData
|
+ (id) imageRepWithData: (NSData *)tiffData
|
||||||
|
@ -168,7 +159,10 @@
|
||||||
- (id) initWithFocusedViewRect: (NSRect)rect
|
- (id) initWithFocusedViewRect: (NSRect)rect
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
return [self notImplemented: _cmd];
|
[self notImplemented: _cmd];
|
||||||
|
|
||||||
|
RELEASE(self);
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the designated initializer */
|
/* This is the designated initializer */
|
||||||
|
@ -208,15 +202,42 @@
|
||||||
rowBytes = ceil((float)width * _bitsPerPixel / 8);
|
rowBytes = ceil((float)width * _bitsPerPixel / 8);
|
||||||
_bytesPerRow = rowBytes;
|
_bytesPerRow = rowBytes;
|
||||||
|
|
||||||
|
_imagePlanes = NSZoneMalloc([self zone], sizeof(unsigned char*) * MAX_PLANES);
|
||||||
if (planes)
|
if (planes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
OBJC_MALLOC(_imagePlanes, unsigned char*, MAX_PLANES);
|
|
||||||
for (i = 0; i < MAX_PLANES; i++)
|
for (i = 0; i < MAX_PLANES; i++)
|
||||||
_imagePlanes[i] = NULL;
|
_imagePlanes[i] = NULL;
|
||||||
for (i = 0; i < ((_isPlanar) ? _numColors : 1); i++)
|
for (i = 0; i < ((_isPlanar) ? _numColors : 1); i++)
|
||||||
_imagePlanes[i] = planes[i];
|
_imagePlanes[i] = planes[i];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned char* bits;
|
||||||
|
long length;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// No image data was given, allocate it.
|
||||||
|
length = (long)((_isPlanar) ? _numColors : 1) * _bytesPerRow *
|
||||||
|
_pixelsHigh * sizeof(unsigned char);
|
||||||
|
_imageData = [[NSMutableData alloc] initWithLength: length];
|
||||||
|
bits = [_imageData mutableBytes];
|
||||||
|
_imagePlanes[0] = bits;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
for (i= 1; i < MAX_PLANES; i++)
|
||||||
|
_imagePlanes[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (alpha)
|
if (alpha)
|
||||||
{
|
{
|
||||||
unsigned char *bData = (unsigned char*)[self bitmapData];
|
unsigned char *bData = (unsigned char*)[self bitmapData];
|
||||||
|
@ -270,53 +291,11 @@
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
OBJC_FREE(_imagePlanes);
|
NSZoneFree([self zone],_imagePlanes);
|
||||||
RELEASE(_imageData);
|
RELEASE(_imageData);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL) canInitWithData: (NSData *)data
|
|
||||||
{
|
|
||||||
TIFF *image = NULL;
|
|
||||||
image = NSTiffOpenDataRead((char *)[data bytes], [data length]);
|
|
||||||
NSTiffClose(image);
|
|
||||||
|
|
||||||
return (image) ? YES : NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imageUnfilteredFileTypes
|
|
||||||
{
|
|
||||||
static NSArray *types = nil;
|
|
||||||
|
|
||||||
if (types == nil)
|
|
||||||
{
|
|
||||||
NSArray *wtypes = [self _wrasterFileTypes];
|
|
||||||
|
|
||||||
if (wtypes != nil)
|
|
||||||
{
|
|
||||||
types = [wtypes mutableCopy];
|
|
||||||
[(NSMutableArray *)types addObjectsFromArray:
|
|
||||||
[NSArray arrayWithObjects: @"tiff", @"tif", nil]];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
types = [[NSArray alloc] initWithObjects: @"tiff", @"tif", nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *) imageUnfilteredPasteboardTypes
|
|
||||||
{
|
|
||||||
static NSArray *types = nil;
|
|
||||||
|
|
||||||
if (types == nil)
|
|
||||||
{
|
|
||||||
types = [[NSArray alloc] initWithObjects: NSTIFFPboardType, nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Getting Information about the Image
|
// Getting Information about the Image
|
||||||
//
|
//
|
||||||
|
@ -364,32 +343,6 @@
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!_imagePlanes || !_imagePlanes[0])
|
|
||||||
{
|
|
||||||
long length;
|
|
||||||
unsigned char* bits;
|
|
||||||
|
|
||||||
length = (long)_numColors * _bytesPerRow * _pixelsHigh
|
|
||||||
* sizeof(unsigned char);
|
|
||||||
_imageData = RETAIN([NSMutableData dataWithLength: length]);
|
|
||||||
if (!_imagePlanes)
|
|
||||||
OBJC_MALLOC(_imagePlanes, unsigned char*, MAX_PLANES);
|
|
||||||
bits = [_imageData mutableBytes];
|
|
||||||
_imagePlanes[0] = bits;
|
|
||||||
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
|
|
||||||
{
|
|
||||||
for (i= 1; i < MAX_PLANES; i++)
|
|
||||||
_imagePlanes[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (data)
|
if (data)
|
||||||
for (i=0; i < _numColors; i++)
|
for (i=0; i < _numColors; i++)
|
||||||
data[i] = _imagePlanes[i];
|
data[i] = _imagePlanes[i];
|
||||||
|
@ -591,8 +544,32 @@
|
||||||
|
|
||||||
copy = (NSBitmapImageRep*)[super copyWithZone: zone];
|
copy = (NSBitmapImageRep*)[super copyWithZone: zone];
|
||||||
|
|
||||||
copy->_imagePlanes = 0;
|
|
||||||
copy->_imageData = [_imageData copyWithZone: zone];
|
copy->_imageData = [_imageData copyWithZone: zone];
|
||||||
|
copy->_imagePlanes = NSZoneMalloc(zone, sizeof(unsigned char*) * MAX_PLANES);
|
||||||
|
if (_imageData == nil)
|
||||||
|
{
|
||||||
|
memcpy(copy->_imagePlanes, _imagePlanes, sizeof(unsigned char*) * MAX_PLANES);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned char* bits;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
bits = [copy->_imageData mutableBytes];
|
||||||
|
copy->_imagePlanes[0] = bits;
|
||||||
|
if (_isPlanar)
|
||||||
|
{
|
||||||
|
for (i=1; i < _numColors; i++)
|
||||||
|
copy->_imagePlanes[i] = bits + i*_bytesPerRow * _pixelsHigh;
|
||||||
|
for (i= _numColors; i < MAX_PLANES; i++)
|
||||||
|
copy->_imagePlanes[i] = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i= 1; i < MAX_PLANES; i++)
|
||||||
|
copy->_imagePlanes[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
@ -658,6 +635,61 @@
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Given a TIFF image (from the libtiff library), load the image information
|
||||||
|
into our data structure. Reads the specified image. */
|
||||||
|
- _initFromTIFFImage: (TIFF *)image number: (int)imageNumber
|
||||||
|
{
|
||||||
|
NSString* space;
|
||||||
|
NSTiffInfo* info;
|
||||||
|
|
||||||
|
/* Seek to the correct image and get the dictionary information */
|
||||||
|
info = NSTiffGetInfo(imageNumber, image);
|
||||||
|
if (!info)
|
||||||
|
{
|
||||||
|
RELEASE(self);
|
||||||
|
NSLog(@"Tiff read invalid TIFF info in directory %d", imageNumber);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 8-bit RGB will be converted to 24-bit by the tiff routines, so account
|
||||||
|
for this. */
|
||||||
|
space = nil;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
[self initWithBitmapDataPlanes: NULL
|
||||||
|
pixelsWide: info->width
|
||||||
|
pixelsHigh: info->height
|
||||||
|
bitsPerSample: info->bitsPerSample
|
||||||
|
samplesPerPixel: info->samplesPerPixel
|
||||||
|
hasAlpha: (info->extraSamples > 0)
|
||||||
|
isPlanar: (info->planarConfig == PLANARCONFIG_SEPARATE)
|
||||||
|
colorSpaceName: space
|
||||||
|
bytesPerRow: 0
|
||||||
|
bitsPerPixel: 0];
|
||||||
|
_compression = info->compression;
|
||||||
|
_comp_factor = 255 * (1 - ((float)info->quality)/100.0);
|
||||||
|
|
||||||
|
if (NSTiffRead(image, info, [self bitmapData]))
|
||||||
|
{
|
||||||
|
RELEASE(self);
|
||||||
|
NSLog(@"Tiff read invalid TIFF image data in directory %d", imageNumber);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
// This are just placeholders for the implementation in the backend
|
// This are just placeholders for the implementation in the backend
|
||||||
- _initFromWrasterFile: (NSString *)filename number: (int)imageNumber
|
- _initFromWrasterFile: (NSString *)filename number: (int)imageNumber
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue