* Source/NSBitmapImageRep+PNG.m: Better cleanup on error.

* Source/NSBitmapImageRep.m (_set_bit_value): Correct error in
bit operation. This should allow the code to work with 16 bit images.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37267 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2013-10-20 20:41:52 +00:00
parent 5c7627d474
commit 35b547f964
3 changed files with 33 additions and 19 deletions

View file

@ -1,3 +1,9 @@
2013-10-20 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSBitmapImageRep+PNG.m: Better cleanup on error.
* Source/NSBitmapImageRep.m (_set_bit_value): Correct error in bit
operation. This should allow the code to work with 16 bit images.
2013-10-17 Eric Wasylishen <ewasylishen@gmail.com>
* Images/common_SliderHoriz.tiff:

View file

@ -98,7 +98,7 @@ static void reader_func(png_structp png_struct, png_bytep data,
png_infop png_info, png_end_info;
int width,height;
unsigned char *buf;
unsigned char *buf = NULL;
int bytes_per_row;
int type,channels,depth;
@ -108,7 +108,6 @@ static void reader_func(png_structp png_struct, png_bytep data,
reader_struct_t reader;
if (!(self = [super init]))
return nil;
@ -137,7 +136,12 @@ static void reader_func(png_structp png_struct, png_bytep data,
if (setjmp(png_jmpbuf(png_struct)))
{
// We get here when an error happens during image loading
png_destroy_read_struct(&png_struct, &png_info, &png_end_info);
if (buf != NULL)
{
NSZoneFree([self zone], buf);
}
RELEASE(self);
return nil;
}
@ -212,25 +216,29 @@ static void reader_func(png_structp png_struct, png_bytep data,
buf = NSZoneMalloc([self zone], bytes_per_row * height);
{
unsigned char *row_pointers[height];
png_bytep row_pointers[height];
int i;
for (i=0;i<height;i++)
row_pointers[i]=buf+i*bytes_per_row;
for (i = 0; i < height; i++)
{
row_pointers[i] = buf + i * bytes_per_row;
}
png_read_image(png_struct, row_pointers);
}
[self initWithBitmapDataPlanes: &buf
pixelsWide: width
pixelsHigh: height
bitsPerSample: depth
samplesPerPixel: channels
hasAlpha: alpha
isPlanar: NO
colorSpaceName: colorspace
bitmapFormat: NSAlphaNonpremultipliedBitmapFormat
bytesPerRow: bytes_per_row
bitsPerPixel: bpp];
self = [self initWithBitmapDataPlanes: &buf
pixelsWide: width
pixelsHigh: height
bitsPerSample: depth
samplesPerPixel: channels
hasAlpha: alpha
isPlanar: NO
colorSpaceName: colorspace
bitmapFormat: NSAlphaNonpremultipliedBitmapFormat
bytesPerRow: bytes_per_row
bitsPerPixel: bpp];
_imageData = [[NSData alloc]
initWithBytesNoCopy: buf
length: bytes_per_row * height];

View file

@ -834,8 +834,8 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
all = ((1<<bit_width)-1) << shift;
if (byte1 != byte2)
base[byte1] = (value >> 8) | (base[byte1] ^ (all >> 8));
base[byte2] = (value & 255) | (base[byte2] ^ (all & 255));
base[byte1] = (value >> 8) | (base[byte1] & ~(all >> 8));
base[byte2] = (value & 255) | (base[byte2] & ~(all & 255));
}
/**