instad of using NSBitmapFormat use individual flags

This commit is contained in:
Riccardo Mottola 2024-05-08 10:28:49 +02:00
parent 7c833cb5a6
commit 55b75b9e33
3 changed files with 39 additions and 21 deletions

View file

@ -39,7 +39,6 @@
#import <Foundation/NSException.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSByteOrder.h>
#import "AppKit/AppKitExceptions.h"
#import "AppKit/NSGraphics.h"
#import "AppKit/NSGraphicsContext.h"
@ -2078,6 +2077,9 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
info->height = _pixelsHigh;
info->bitsPerSample = _bitsPerSample;
info->samplesPerPixel = _numColors;
info->isBigEndian = NO;
info->is16Bit = NO;
info->is32Bit = NO;
// resolution/density
info->xdpi = 0;
@ -2128,7 +2130,26 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
info->quality = factor * 100;
info->error = 0;
info->bitmapFormat = (uint16_t)_format;
if ((_format & NSBitmapFormatSixteenBitBigEndian) != 0)
{
info->isBigEndian = YES;
info->is16Bit = YES;
}
else if ((_format & NSBitmapFormatSixteenBitLittleEndian) != 0)
{
info->isBigEndian = NO;
info->is16Bit = YES;
}
else if ((_format & NSBitmapFormatThirtyTwoBitBigEndian) != 0)
{
info->isBigEndian = YES;
info->is32Bit = YES;
}
else if ((_format & NSBitmapFormatThirtyTwoBitLittleEndian) != 0)
{
info->isBigEndian = NO;
info->is32Bit = YES;
}
}
- (void) _premultiply

View file

@ -57,7 +57,9 @@ typedef struct {
int error;
float xdpi;
float ydpi;
uint16_t bitmapFormat; /* NSBitmapFormat*/
short isBigEndian;
short is16Bit;
short is32Bit;
} NSTiffInfo;
typedef struct {

View file

@ -501,8 +501,7 @@ NSTiffWrite(TIFF *image, NSTiffInfo *info, unsigned char *data)
unsigned int row;
int error = 0;
tmsize_t scan_line_size;
BOOL swap16 = NO;
BOOL swap32 = NO;
BOOL swapByteOrder = NO;
if (info->numImages > 1)
{
@ -537,16 +536,12 @@ NSTiffWrite(TIFF *image, NSTiffInfo *info, unsigned char *data)
scan_line_size = TIFFScanlineSize(image);
// check if image endianness is different from Host
if (((info->bitmapFormat & NSBitmapFormatSixteenBitBigEndian) != 0) != (NSHostByteOrder() == NS_BigEndian))
if ((info->isBigEndian != 0) != (NSHostByteOrder() == NS_BigEndian))
{
swap16 = YES;
}
else if (((info->bitmapFormat & NSBitmapFormatThirtyTwoBitBigEndian) != 0) != (NSHostByteOrder() == NS_BigEndian))
{
swap32 = YES;
swapByteOrder = YES;
}
if (swap16 || swap32)
if (swapByteOrder)
{
bufSwap = malloc(scan_line_size); // sizeof(unsigned char)
}
@ -559,11 +554,11 @@ NSTiffWrite(TIFF *image, NSTiffInfo *info, unsigned char *data)
{
for (row = 0; row < info->height; ++row)
{
if (swap16)
if (swapByteOrder && info->is16Bit)
{
SWAP16
}
else if (swap32)
else if (swapByteOrder && info->is32Bit)
{
SWAP32
}
@ -581,11 +576,11 @@ NSTiffWrite(TIFF *image, NSTiffInfo *info, unsigned char *data)
{
for (row = 0; row < info->height; ++row)
{
if (swap16)
if (swapByteOrder && info->is16Bit)
{
SWAP16
}
else if (swap32)
else if (swapByteOrder && info->is32Bit)
{
SWAP32
}
@ -605,11 +600,11 @@ NSTiffWrite(TIFF *image, NSTiffInfo *info, unsigned char *data)
{
for (row = 0; row < info->height; ++row)
{
if (swap16)
if (swapByteOrder && info->is16Bit)
{
SWAP16
}
else if (swap32)
else if (swapByteOrder && info->is32Bit)
{
SWAP32
}
@ -627,11 +622,11 @@ NSTiffWrite(TIFF *image, NSTiffInfo *info, unsigned char *data)
{
for (row = 0; row < info->height; ++row)
{
if (swap16)
if (swapByteOrder && info->is16Bit)
{
SWAP16
}
else if (swap32)
else if (swapByteOrder && info->is32Bit)
{
SWAP32
}
@ -656,7 +651,7 @@ NSTiffWrite(TIFF *image, NSTiffInfo *info, unsigned char *data)
// Write out the directory as there may be more images comming
TIFFWriteDirectory(image);
TIFFFlush(image);
if (swap16 || swap32)
if (swapByteOrder)
{
free(bufSwap);
}