Merge with trunk revision 40072

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@40128 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2016-10-05 19:06:59 +00:00
parent bb5773f64e
commit 32c7e9a6a8
5 changed files with 389 additions and 184 deletions

View file

@ -3410,6 +3410,7 @@ typedef enum {
}
else if ([[box fillColor] isEqual:[NSColor clearColor]] == NO)
{
// Testplant-MAL-10052016: keeping branch code...
// This isn't right per docs but Apple does do something like
// this...anyone with a better idea please have at it...
color = [box fillColor];
@ -3457,6 +3458,7 @@ typedef enum {
}
else if ([[box borderColor] isEqual:[NSColor clearColor]] == NO)
{
// Testplant-MAL-10052016: keeping branch code...
// This isn't right per docs but Apple does do something like
// this...anyone with a better idea please have at it...
[[box borderColor] set];

View file

@ -37,7 +37,6 @@
#import <Foundation/NSXMLParser.h>
#import <Foundation/NSXMLDocument.h>
#import <Foundation/NSXMLElement.h>
#import <GNUstepBase/GSMime.h>
#import "AppKit/NSApplication.h"
#import "AppKit/NSNib.h"
@ -1034,7 +1033,7 @@
}
NS_HANDLER
{
NSLog(@"Exception occured while loading model: %@",[localException reason]);
NSLog(@"Exception occurred while loading model: %@",[localException reason]);
// TEST_RELEASE(unarchiver);
}
NS_ENDHANDLER
@ -1275,7 +1274,7 @@
}
NS_HANDLER
{
NSLog(@"Exception occured while parsing Xib: %@",[localException reason]);
NSLog(@"Exception occurred while parsing Xib: %@",[localException reason]);
DESTROY(self);
}
NS_ENDHANDLER
@ -1584,10 +1583,11 @@ didStartElement: (NSString*)elementName
if ([type isEqualToString: @"base64-UTF8"])
{
NSData *d = [new dataUsingEncoding: NSASCIIStringEncoding];
d = [GSMimeDocument decodeBase64: d];
NSData *d = [[NSData alloc] initWithBase64EncodedString: new
options: 0];
new = AUTORELEASE([[NSString alloc] initWithData: d
encoding: NSUTF8StringEncoding]);
RELEASE(d);
}
// empty strings are not nil!
@ -1698,9 +1698,8 @@ didStartElement: (NSString*)elementName
}
else if ([@"bytes" isEqualToString: elementName])
{
id new = [[element value] dataUsingEncoding: NSASCIIStringEncoding
allowLossyConversion: NO];
new = [GSMimeDocument decodeBase64: new];
id new = AUTORELEASE([[NSData alloc] initWithBase64EncodedString: [element value]
options: 0]);
if (objID != nil)
[decoded setObject: new forKey: objID];

View file

@ -74,7 +74,7 @@ struct gs_jpeg_error_mgr
jmp_buf setjmpBuffer;
/* a pointer to the last error message, nil if no
error occured. if present, string is autoreleased. */
error occurred. if present, string is autoreleased. */
NSString *error;
};
typedef struct gs_jpeg_error_mgr *gs_jpeg_error_mgr_ptr;
@ -407,7 +407,7 @@ static void gs_jpeg_memory_dest_destroy (j_compress_ptr cinfo)
// establish return context for error handling
if (setjmp(jerrMgr.setjmpBuffer))
{
/* assign the description of possible occured error to errorMsg */
/* assign the description of possible occurred error to errorMsg */
if (errorMsg)
*errorMsg = (jerrMgr.error ? (id)jerrMgr.error : (id)nil);
gs_jpeg_memory_src_destroy(&cinfo);
@ -564,7 +564,7 @@ static void gs_jpeg_memory_dest_destroy (j_compress_ptr cinfo)
// establish return context for error handling
if (setjmp(jerrMgr.setjmpBuffer))
{
/* assign the description of possible occured error to errorMsg */
/* assign the description of possible occurred error to errorMsg */
if (errorMsg)
*errorMsg = (jerrMgr.error ? (id)jerrMgr.error : (id)nil);
gs_jpeg_memory_dest_destroy(&cinfo);

View file

@ -55,6 +55,7 @@
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#import "AppKit/NSGraphics.h"
#import "NSBitmapImageRepPrivate.h"
#import "NSBitmapImageRep+PNG.h"
@ -320,10 +321,19 @@ static void writer_func(png_structp png_struct, png_bytep data,
NSNumber * gammaNumber = nil;
double gamma = 0.0;
// FIXME: Need to convert to non-pre-multiplied format
if ([self isPlanar]) // don't handle planar yet
// Need to convert to non-pre-multiplied format
if ([self isPlanar] || !(_format & NSAlphaNonpremultipliedBitmapFormat))
{
return nil;
NSBitmapImageRep *converted = [self _convertToFormatBitsPerSample: _bitsPerSample
samplesPerPixel: _numColors
hasAlpha: _hasAlpha
isPlanar: NO
colorSpaceName: _colorSpace
bitmapFormat: _format | NSAlphaNonpremultipliedBitmapFormat
bytesPerRow: _bytesPerRow
bitsPerPixel: _bitsPerPixel];
return [converted _PNGRepresentationWithProperties: properties];
}
// get the image parameters
width = [self pixelsWide];

View file

@ -51,6 +51,7 @@
#import "NSBitmapImageRep+PNG.h"
#import "NSBitmapImageRep+PNM.h"
#import "NSBitmapImageRep+ICNS.h"
#import "NSBitmapImageRepPrivate.h"
#import "GSGuiPrivate.h"
#include "nsimage-tiff.h"
@ -58,25 +59,6 @@
/* Maximum number of planes */
#define MAX_PLANES 5
/* Backend methods (optional) */
@interface NSBitmapImageRep (GSPrivate)
// GNUstep extension
- _initFromTIFFImage: (TIFF *)image number: (int)imageNumber;
// Internal
+ (int) _localFromCompressionType: (NSTIFFCompression)type;
+ (NSTIFFCompression) _compressionTypeFromLocal: (int)type;
- (void) _premultiply;
- (void) _unpremultiply;
- (NSBitmapImageRep *) _convertToFormatBitsPerSample: (NSInteger)bps
samplesPerPixel: (NSInteger)spp
hasAlpha: (BOOL)alpha
isPlanar: (BOOL)isPlanar
colorSpaceName: (NSString*)colorSpaceName
bitmapFormat: (NSBitmapFormat)bitmapFormat
bytesPerRow: (NSInteger)rowBytes
bitsPerPixel: (NSInteger)pixelBits;
@end
/**
<unit>
@ -98,39 +80,36 @@
/** Returns YES if the image stored in data can be read and decoded */
+ (BOOL) canInitWithData: (NSData *)data
{
TIFF *image = NULL;
if (data == nil)
{
return NO;
}
#if HAVE_LIBPNG
if ([self _bitmapIsPNG: data])
return YES;
#endif
if ([self _bitmapIsPNM: data])
return YES;
#if HAVE_LIBJPEG
if ([self _bitmapIsJPEG: data])
return YES;
#endif
#if HAVE_LIBUNGIF || HAVE_LIBGIF
if ([self _bitmapIsGIF: data])
return YES;
#endif
if ([self _bitmapIsICNS: data])
return YES;
image = NSTiffOpenDataRead ((char *)[data bytes], [data length]);
if ([self _bitmapIsTIFF: data])
return YES;
if (image != NULL)
{
NSTiffClose (image);
return YES;
}
else
{
return NO;
}
return NO;
}
/** Returns a list of image filename extensions that are understood by
@ -189,10 +168,6 @@
*/
+ (NSArray*) imageRepsWithData: (NSData *)imageData
{
int i, images;
TIFF *image;
NSMutableArray *array;
if (imageData == nil)
{
NSLog(@"NSBitmapImageRep: nil image data");
@ -259,36 +234,20 @@
return [self _imageRepsWithICNSData: imageData];
}
image = NSTiffOpenDataRead((char *)[imageData bytes], [imageData length]);
if (image == NULL)
if ([self _bitmapIsTIFF: imageData])
{
NSLog(@"NSBitmapImageRep: unable to parse TIFF data");
return [NSArray array];
return [self _imageRepsWithTIFFData: imageData];
}
images = NSTiffGetImageCount(image);
NSDebugLLog(@"NSImage", @"Image contains %d directories", images);
array = [NSMutableArray arrayWithCapacity: images];
for (i = 0; i < images; i++)
{
NSBitmapImageRep* imageRep;
imageRep = [[self alloc] _initFromTIFFImage: image number: i];
if (imageRep)
{
[array addObject: imageRep];
RELEASE(imageRep);
}
}
NSTiffClose(image);
return array;
NSLog(@"NSBitmapImageRep: unable to parse bitmap image data");
return [NSArray array];
}
/** Loads only the default (first) image from the image contained in
data. */
- (id) initWithData: (NSData *)imageData
{
TIFF *image;
Class class;
if (imageData == nil)
{
@ -296,36 +255,30 @@
return nil;
}
if ([object_getClass(self) _bitmapIsPNG: imageData])
class = [self class];
if ([class _bitmapIsPNG: imageData])
return [self _initBitmapFromPNG: imageData];
if ([object_getClass(self) _bitmapIsPNM: imageData])
if ([class _bitmapIsPNM: imageData])
return [self _initBitmapFromPNM: imageData
errorMessage: NULL];
if ([object_getClass(self) _bitmapIsJPEG: imageData])
if ([class _bitmapIsJPEG: imageData])
return [self _initBitmapFromJPEG: imageData
errorMessage: NULL];
if ([object_getClass(self) _bitmapIsGIF: imageData])
if ([class _bitmapIsGIF: imageData])
return [self _initBitmapFromGIF: imageData
errorMessage: NULL];
if ([object_getClass(self) _bitmapIsICNS: imageData])
if ([class _bitmapIsICNS: imageData])
return [self _initBitmapFromICNS: imageData];
image = NSTiffOpenDataRead((char *)[imageData bytes], [imageData length]);
if (image == NULL)
{
RELEASE(self);
NSLog(@"Tiff read invalid TIFF info from data");
return nil;
}
if ([class _bitmapIsTIFF: imageData])
return [self _initBitmapFromTIFF: imageData];
[self _initFromTIFFImage: image number: -1];
NSTiffClose(image);
return self;
DESTROY(self);
return nil;
}
/** Initialize with bitmap data from a rect within the focused view */
@ -1393,48 +1346,115 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
//
/** Produces an NSData object containing a TIFF representation of all
the images stored in anArray. BUGS: Currently this only works if the
images are NSBitmapImageRep objects, and it only creates an TIFF from the
first image in the array. */
images are NSBitmapImageRep objects. */
+ (NSData*) TIFFRepresentationOfImageRepsInArray: (NSArray *)anArray
{
//FIXME: This only outputs one of the ImageReps
NSEnumerator *enumerator = [anArray objectEnumerator];
NSImageRep *rep;
TIFF *image;
NSTiffInfo info;
char *bytes = 0;
long length = 0;
int num = 0;
NSData *data;
image = NSTiffOpenDataWrite(&bytes, &length);
if (image == 0)
{
[NSException raise: NSTIFFException
format: @"Opening data stream for writing"];
}
while ((rep = [enumerator nextObject]) != nil)
{
if ([rep isKindOfClass: self])
{
return [(NSBitmapImageRep*)rep TIFFRepresentation];
}
NSTIFFCompression compression;
float factor;
NSBitmapImageRep *bitmap = (NSBitmapImageRep*)rep;
[bitmap getCompression: &compression
factor: &factor];
[bitmap _fillTIFFInfo: &info
usingCompression: compression
factor: factor];
info.imageNumber = num++;
info.numImages = [anArray count];
info.subfileType = FILETYPE_PAGE;
if (NSTiffWrite(image, &info, [bitmap bitmapData]) != 0)
{
[NSException raise: NSTIFFException format: @"Writing data"];
}
}
}
return nil;
NSTiffClose(image);
data = [NSData dataWithBytesNoCopy: bytes length: length];
if (num > 0)
{
return data;
}
else
{
// FIXME: Not sure wether this is the correct behaviour, at least it was
// the old one of this method.
return nil;
}
}
/** Produces an NSData object containing a TIFF representation of all
the images stored in anArray. The image is compressed according to
the compression type and factor. BUGS: Currently this only works if
the images are NSBitmapImageRep objects, and it only creates an
TIFF from the first image in the array. */
the images are NSBitmapImageRep objects. */
+ (NSData*) TIFFRepresentationOfImageRepsInArray: (NSArray *)anArray
usingCompression: (NSTIFFCompression)type
usingCompression: (NSTIFFCompression)compression
factor: (float)factor
{
//FIXME: This only outputs one of the ImageReps
NSEnumerator *enumerator = [anArray objectEnumerator];
NSImageRep *rep;
NSTiffInfo info;
TIFF *image;
char *bytes = 0;
long length = 0;
int num = 0;
NSData *data;
image = NSTiffOpenDataWrite(&bytes, &length);
if (image == 0)
{
[NSException raise: NSTIFFException
format: @"Opening data stream for writing"];
}
while ((rep = [enumerator nextObject]) != nil)
{
if ([rep isKindOfClass: self])
{
return [(NSBitmapImageRep*)rep TIFFRepresentationUsingCompression: type
[(NSBitmapImageRep*)rep _fillTIFFInfo: &info
usingCompression: compression
factor: factor];
}
info.imageNumber = num++;
info.numImages = [anArray count];
info.subfileType = FILETYPE_PAGE;
if (NSTiffWrite(image, &info, [(NSBitmapImageRep*)rep bitmapData]) != 0)
{
[NSException raise: NSTIFFException format: @"Writing data"];
}
}
}
return nil;
NSTiffClose(image);
data = [NSData dataWithBytesNoCopy: bytes length: length];
if (num > 0)
{
return data;
}
else
{
// FIXME: Not sure wether this is the correct behaviour, at least it was
// the old one of this method.
return nil;
}
}
/** Returns an NSData object containing a TIFF representation of the
@ -1452,7 +1472,7 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
/** Returns an NSData object containing a TIFF representation of the
receiver. The TIFF data is compressed using compresssion type
and factor. */
- (NSData*) TIFFRepresentationUsingCompression: (NSTIFFCompression)type
- (NSData*) TIFFRepresentationUsingCompression: (NSTIFFCompression)compression
factor: (float)factor
{
NSTiffInfo info;
@ -1460,56 +1480,16 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
char *bytes = 0;
long length = 0;
info.imageNumber = 0;
info.subfileType = 255;
info.width = _pixelsWide;
info.height = _pixelsHigh;
info.bitsPerSample = _bitsPerSample;
info.samplesPerPixel = _numColors;
if ([self canBeCompressedUsing: type] == NO)
{
type = NSTIFFCompressionNone;
factor = 0;
}
if (_isPlanar)
info.planarConfig = PLANARCONFIG_SEPARATE;
else
info.planarConfig = PLANARCONFIG_CONTIG;
if ([_colorSpace isEqual: NSDeviceRGBColorSpace]
|| [_colorSpace isEqual: NSCalibratedRGBColorSpace])
info.photoInterp = PHOTOMETRIC_RGB;
else if ([_colorSpace isEqual: NSDeviceWhiteColorSpace]
|| [_colorSpace isEqual: NSCalibratedWhiteColorSpace])
info.photoInterp = PHOTOMETRIC_MINISBLACK;
else if ([_colorSpace isEqual: NSDeviceBlackColorSpace]
|| [_colorSpace isEqual: NSCalibratedBlackColorSpace])
info.photoInterp = PHOTOMETRIC_MINISWHITE;
else
{
NSWarnMLog(@"Unknown colorspace %@.", _colorSpace);
info.photoInterp = PHOTOMETRIC_RGB;
}
info.extraSamples = (_hasAlpha) ? 1 : 0;
info.assocAlpha = (_format & NSAlphaNonpremultipliedBitmapFormat) ? 0 : 1;
info.compression = [NSBitmapImageRep _localFromCompressionType: type];
if (factor < 0)
factor = 0;
if (factor > 1)
factor = 1;
info.quality = factor * 100;
info.numImages = 1;
info.error = 0;
image = NSTiffOpenDataWrite(&bytes, &length);
if (image == 0)
{
[NSException raise: NSTIFFException
format: @"Opening data stream for writting"];
format: @"Opening data stream for writing"];
}
[self _fillTIFFInfo: &info
usingCompression: compression
factor: factor];
if (NSTiffWrite(image, &info, [self bitmapData]) != 0)
{
[NSException raise: NSTIFFException format: @"Writing data"];
@ -1533,13 +1513,35 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
NSEnumerator *enumerator = [imageReps objectEnumerator];
NSImageRep *rep;
while ((rep = [enumerator nextObject]) != nil)
if (storageType == NSTIFFFileType)
{
if ([rep isKindOfClass: self])
NSNumber *comp_property = [properties objectForKey: NSImageCompressionMethod];
NSNumber *factor_property = [properties objectForKey: NSImageCompressionFactor];
if ((comp_property != nil) && (factor_property != nil))
{
return [(NSBitmapImageRep*)rep representationUsingType: storageType
properties: properties];
}
float factor = [factor_property floatValue];
NSTIFFCompression compression = [comp_property unsignedShortValue];
return [self TIFFRepresentationOfImageRepsInArray: imageReps
usingCompression: compression
factor: factor];
}
else
{
return [self TIFFRepresentationOfImageRepsInArray: imageReps];
}
}
else
{
while ((rep = [enumerator nextObject]) != nil)
{
if ([rep isKindOfClass: self])
{
return [(NSBitmapImageRep*)rep representationUsingType: storageType
properties: properties];
}
}
}
return nil;
@ -1761,7 +1763,7 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
copy = (NSBitmapImageRep*)[super copyWithZone: zone];
copy->_properties = [_properties copyWithZone: zone];
copy->_properties = [_properties mutableCopyWithZone: zone];
copy->_imageData = [_imageData mutableCopyWithZone: zone];
copy->_imagePlanes = NSZoneMalloc(zone, sizeof(unsigned char*) * MAX_PLANES);
if (_imageData == nil)
@ -1866,10 +1868,71 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
return NSTIFFCompressionNone;
}
+ (BOOL) _bitmapIsTIFF: (NSData *)data
{
TIFF *image = NSTiffOpenDataRead((char *)[data bytes], [data length]);
if (image != NULL)
{
NSTiffClose(image);
return YES;
}
else
{
return NO;
}
}
+ (NSArray*) _imageRepsWithTIFFData: (NSData *)imageData
{
int i, images;
TIFF *image;
NSMutableArray *array;
image = NSTiffOpenDataRead((char *)[imageData bytes], [imageData length]);
if (image == NULL)
{
NSLog(@"NSBitmapImageRep: unable to parse TIFF data");
return [NSArray array];
}
images = NSTiffGetImageCount(image);
NSDebugLLog(@"NSImage", @"Image contains %d directories", images);
array = [NSMutableArray arrayWithCapacity: images];
for (i = 0; i < images; i++)
{
NSBitmapImageRep* imageRep;
imageRep = [[self alloc] _initFromTIFFImage: image number: i];
if (imageRep)
{
[array addObject: imageRep];
RELEASE(imageRep);
}
}
NSTiffClose(image);
return array;
}
- (NSBitmapImageRep *) _initBitmapFromTIFF: (NSData *)imageData
{
TIFF *image = NSTiffOpenDataRead((char *)[imageData bytes], [imageData length]);
if (image == NULL)
{
RELEASE(self);
NSLog(@"Tiff read invalid TIFF info from data");
return nil;
}
[self _initFromTIFFImage: image number: -1];
NSTiffClose(image);
return self;
}
/* 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
- (NSBitmapImageRep *) _initFromTIFFImage: (TIFF *)image number: (int)imageNumber
{
NSString* space;
NSTiffInfo* info;
@ -1940,6 +2003,56 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
return self;
}
- (void) _fillTIFFInfo: (NSTiffInfo*)info
usingCompression: (NSTIFFCompression)type
factor: (float)factor
{
info->numImages = 1;
info->imageNumber = 0;
info->subfileType = 255;
info->width = _pixelsWide;
info->height = _pixelsHigh;
info->bitsPerSample = _bitsPerSample;
info->samplesPerPixel = _numColors;
if (_isPlanar)
info->planarConfig = PLANARCONFIG_SEPARATE;
else
info->planarConfig = PLANARCONFIG_CONTIG;
if ([_colorSpace isEqual: NSDeviceRGBColorSpace]
|| [_colorSpace isEqual: NSCalibratedRGBColorSpace])
info->photoInterp = PHOTOMETRIC_RGB;
else if ([_colorSpace isEqual: NSDeviceWhiteColorSpace]
|| [_colorSpace isEqual: NSCalibratedWhiteColorSpace])
info->photoInterp = PHOTOMETRIC_MINISBLACK;
else if ([_colorSpace isEqual: NSDeviceBlackColorSpace]
|| [_colorSpace isEqual: NSCalibratedBlackColorSpace])
info->photoInterp = PHOTOMETRIC_MINISWHITE;
else
{
NSWarnMLog(@"Unknown colorspace %@.", _colorSpace);
info->photoInterp = PHOTOMETRIC_RGB;
}
info->extraSamples = (_hasAlpha) ? 1 : 0;
info->assocAlpha = (_format & NSAlphaNonpremultipliedBitmapFormat) ? 0 : 1;
if ([self canBeCompressedUsing: type] == NO)
{
type = NSTIFFCompressionNone;
factor = 0;
}
info->compression = [NSBitmapImageRep _localFromCompressionType: type];
if (factor < 0)
factor = 0;
if (factor > 1)
factor = 1;
info->quality = factor * 100;
info->error = 0;
}
- (void) _premultiply
{
NSInteger x, y;
@ -1968,25 +2081,66 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
if (_bitsPerSample == 8)
{
NSUInteger a;
if (!_isPlanar)
{
// Optimize for the most common case
NSUInteger a;
NSInteger offset;
NSInteger line_offset;
for (y = 0; y < _pixelsHigh; y++)
{
line_offset = _bytesPerRow * y;
for (x = 0; x < _pixelsWide; x++)
{
//[self getPixel: pixelData atX: x y: y];
getP(self, getPSel, pixelData, x, y);
a = pixelData[ai];
if (a != 255)
{
for (i = start; i < end; i++)
offset = (_bitsPerPixel * x) / 8 + line_offset;
a = _imagePlanes[0][offset + ai];
if (a != 255)
{
NSUInteger t = a * pixelData[i] + 0x80;
pixelData[i] = ((t >> 8) + t) >> 8;
if (a == 0)
{
for (i = start; i < end; i++)
{
_imagePlanes[0][offset + i] = 0;
}
}
else
{
for (i = start; i < end; i++)
{
NSUInteger v = _imagePlanes[0][offset + i];
NSUInteger t = a * v + 0x80;
v = ((t >> 8) + t) >> 8;
_imagePlanes[0][offset + i] = v;
}
}
}
}
}
}
else
{
NSUInteger a;
for (y = 0; y < _pixelsHigh; y++)
{
for (x = 0; x < _pixelsWide; x++)
{
//[self getPixel: pixelData atX: x y: y];
getP(self, getPSel, pixelData, x, y);
a = pixelData[ai];
if (a != 255)
{
for (i = start; i < end; i++)
{
NSUInteger t = a * pixelData[i] + 0x80;
pixelData[i] = ((t >> 8) + t) >> 8;
}
//[self setPixel: pixelData atX: x y: y];
setP(self, setPSel, pixelData, x, y);
}
//[self setPixel: pixelData atX: x y: y];
setP(self, setPSel, pixelData, x, y);
}
}
}
@ -2045,33 +2199,73 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
if (_bitsPerSample == 8)
{
NSUInteger a;
if (!_isPlanar)
{
// Optimize for the most common case
NSUInteger a;
NSInteger offset;
NSInteger line_offset;
for (y = 0; y < _pixelsHigh; y++)
{
for (x = 0; x < _pixelsWide; x++)
{
//[self getPixel: pixelData atX: x y: y];
getP(self, getPSel, pixelData, x, y);
a = pixelData[ai];
if ((a != 0) && (a != 255))
line_offset = _bytesPerRow * y;
for (x = 0; x < _pixelsWide; x++)
{
for (i = start; i < end; i++)
{
NSUInteger c;
c = (pixelData[i] * 255) / a;
if (c >= 255)
offset = (_bitsPerPixel * x) / 8 + line_offset;
a = _imagePlanes[0][offset + ai];
if ((a != 0) && (a != 255))
{
pixelData[i] = 255;
}
else
{
pixelData[i] = c;
for (i = start; i < end; i++)
{
NSUInteger v = _imagePlanes[0][offset + i];
NSUInteger c;
c = (v * 255) / a;
if (c >= 255)
{
v = 255;
}
else
{
v = c;
}
_imagePlanes[0][offset + i] = v;
}
}
}
//[self setPixel: pixelData atX: x y: y];
setP(self, setPSel, pixelData, x, y);
}
}
else
{
NSUInteger a;
for (y = 0; y < _pixelsHigh; y++)
{
for (x = 0; x < _pixelsWide; x++)
{
//[self getPixel: pixelData atX: x y: y];
getP(self, getPSel, pixelData, x, y);
a = pixelData[ai];
if ((a != 0) && (a != 255))
{
for (i = start; i < end; i++)
{
NSUInteger c;
c = (pixelData[i] * 255) / a;
if (c >= 255)
{
pixelData[i] = 255;
}
else
{
pixelData[i] = c;
}
}
//[self setPixel: pixelData atX: x y: y];
setP(self, setPSel, pixelData, x, y);
}
}
}
}