Issue #323, added LZW support to TIFF reader

This commit is contained in:
Christopher Lloyd 2009-07-28 18:38:06 +00:00
parent 12c4ae2846
commit 839ae31766
13 changed files with 526 additions and 67 deletions

View File

@ -2742,6 +2742,14 @@
FEBF5A160DCD450700CE5A1C /* KGPaint_radialGradient.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5A0A0DCD450700CE5A1C /* KGPaint_radialGradient.m */; };
FEBF5A170DCD450700CE5A1C /* KGPaint_ramp.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5A0B0DCD450700CE5A1C /* KGPaint_ramp.h */; };
FEBF5A180DCD450700CE5A1C /* KGPaint_ramp.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5A0C0DCD450700CE5A1C /* KGPaint_ramp.m */; };
FEBF5B77100D851500F64C71 /* O2LZW.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5B75100D851500F64C71 /* O2LZW.h */; };
FEBF5B78100D851500F64C71 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5B76100D851500F64C71 /* O2LZW.m */; };
FEBF5B79100D851500F64C71 /* O2LZW.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5B75100D851500F64C71 /* O2LZW.h */; };
FEBF5B7A100D851500F64C71 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5B76100D851500F64C71 /* O2LZW.m */; };
FEBF5B7B100D851500F64C71 /* O2LZW.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5B75100D851500F64C71 /* O2LZW.h */; };
FEBF5B7C100D851500F64C71 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5B76100D851500F64C71 /* O2LZW.m */; };
FEBF5B7D100D851500F64C71 /* O2LZW.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5B75100D851500F64C71 /* O2LZW.h */; };
FEBF5B7E100D851500F64C71 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5B76100D851500F64C71 /* O2LZW.m */; };
FEC0C7810F146AF800903F6D /* KGImageSource_GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = FEC0C77F0F146AF800903F6D /* KGImageSource_GIF.h */; };
FEC0C7820F146AF800903F6D /* KGImageSource_GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = FEC0C7800F146AF800903F6D /* KGImageSource_GIF.m */; };
FEC0C7830F146AF800903F6D /* KGImageSource_GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = FEC0C77F0F146AF800903F6D /* KGImageSource_GIF.h */; };
@ -3653,6 +3661,8 @@
FEBF5A0A0DCD450700CE5A1C /* KGPaint_radialGradient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGPaint_radialGradient.m; sourceTree = "<group>"; };
FEBF5A0B0DCD450700CE5A1C /* KGPaint_ramp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGPaint_ramp.h; sourceTree = "<group>"; };
FEBF5A0C0DCD450700CE5A1C /* KGPaint_ramp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGPaint_ramp.m; sourceTree = "<group>"; };
FEBF5B75100D851500F64C71 /* O2LZW.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = O2LZW.h; sourceTree = "<group>"; };
FEBF5B76100D851500F64C71 /* O2LZW.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = O2LZW.m; sourceTree = "<group>"; };
FEC0C77F0F146AF800903F6D /* KGImageSource_GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGImageSource_GIF.h; sourceTree = "<group>"; };
FEC0C7800F146AF800903F6D /* KGImageSource_GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGImageSource_GIF.m; sourceTree = "<group>"; };
FECAF4C80DB710EE00BA2A8E /* ApplicationServices.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ApplicationServices.xcodeproj; path = ../ApplicationServices/ApplicationServices.xcodeproj; sourceTree = SOURCE_ROOT; };
@ -4678,6 +4688,8 @@
FE267E7F0B8BCB660000DDC0 /* ImageIO */ = {
isa = PBXGroup;
children = (
FEBF5B75100D851500F64C71 /* O2LZW.h */,
FEBF5B76100D851500F64C71 /* O2LZW.m */,
FE66F0050E513AE8006C5796 /* CGImageProperties.m */,
FE669C8C0F12B1A600534F46 /* gif_lib.h */,
FE669C840F12B1A600534F46 /* gif_lib.m */,
@ -5199,6 +5211,7 @@
FE9DB3D60FD6BD5A00A1CE17 /* NSRangeEntries.h in Headers */,
FEAED7A00FD6C96E0043F915 /* KGDataConsumer.h in Headers */,
FE2C7F560FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
FEBF5B79100D851500F64C71 /* O2LZW.h in Headers */,
A1CC701D100534AB00DB9974 /* NSCachingBinder.h in Headers */,
A1CC70441005371100DB9974 /* NSTextBinder.h in Headers */,
FE6D918E101381F600BA6BAD /* NSCellUndoManager.h in Headers */,
@ -5563,6 +5576,7 @@
FE9DB3D70FD6BD5B00A1CE17 /* NSRangeEntries.h in Headers */,
FEAED79E0FD6C96E0043F915 /* KGDataConsumer.h in Headers */,
FE2C7F550FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
FEBF5B7B100D851500F64C71 /* O2LZW.h in Headers */,
A1CC701F100534AB00DB9974 /* NSCachingBinder.h in Headers */,
A1CC70421005371100DB9974 /* NSTextBinder.h in Headers */,
FE6D9190101381F600BA6BAD /* NSCellUndoManager.h in Headers */,
@ -5922,6 +5936,7 @@
FEAED7A20FD6C96E0043F915 /* KGDataConsumer.h in Headers */,
FE2C7F570FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
FEA661230FF5C6F200E2C03B /* KGFont_gdi.h in Headers */,
FEBF5B77100D851500F64C71 /* O2LZW.h in Headers */,
A1CC7019100534AB00DB9974 /* NSCachingBinder.h in Headers */,
A1CC70481005371100DB9974 /* NSTextBinder.h in Headers */,
FE6D918C101381F600BA6BAD /* NSCellUndoManager.h in Headers */,
@ -6209,6 +6224,7 @@
FEA317C50FD5893300F480D4 /* NSRaise.h in Headers */,
FEA3182B0FD5961100F480D4 /* NSRangeEntries.h in Headers */,
FE2C7F580FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
FEBF5B7D100D851500F64C71 /* O2LZW.h in Headers */,
A1CC701B100534AB00DB9974 /* NSCachingBinder.h in Headers */,
A1CC70461005371100DB9974 /* NSTextBinder.h in Headers */,
FE6D9192101381F600BA6BAD /* NSCellUndoManager.h in Headers */,
@ -6969,6 +6985,7 @@
FEAED7A10FD6C96E0043F915 /* KGDataConsumer.m in Sources */,
FEAED7A60FD6C9820043F915 /* CGPDFContext.m in Sources */,
FEB07FA10FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
FEBF5B7A100D851500F64C71 /* O2LZW.m in Sources */,
A1CC701E100534AB00DB9974 /* NSCachingBinder.m in Sources */,
A1CC70451005371100DB9974 /* NSTextBinder.m in Sources */,
FE6D918F101381F600BA6BAD /* NSCellUndoManager.m in Sources */,
@ -7301,6 +7318,7 @@
FEAED79F0FD6C96E0043F915 /* KGDataConsumer.m in Sources */,
FEAED7A50FD6C9820043F915 /* CGPDFContext.m in Sources */,
FEB07FA20FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
FEBF5B7C100D851500F64C71 /* O2LZW.m in Sources */,
A1CC7020100534AB00DB9974 /* NSCachingBinder.m in Sources */,
A1CC70431005371100DB9974 /* NSTextBinder.m in Sources */,
FE6D9191101381F600BA6BAD /* NSCellUndoManager.m in Sources */,
@ -7667,6 +7685,7 @@
FEAED7A70FD6C9820043F915 /* CGPDFContext.m in Sources */,
FEA661240FF5C6F300E2C03B /* KGFont_gdi.m in Sources */,
FEB07FA00FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
FEBF5B78100D851500F64C71 /* O2LZW.m in Sources */,
A1CC701A100534AB00DB9974 /* NSCachingBinder.m in Sources */,
A1CC70491005371100DB9974 /* NSTextBinder.m in Sources */,
FE6D918D101381F600BA6BAD /* NSCellUndoManager.m in Sources */,
@ -7904,6 +7923,7 @@
FEA3161A0FD5667D00F480D4 /* NSControllerMarker.m in Sources */,
FEA3182C0FD5961100F480D4 /* NSRangeEntries.m in Sources */,
FEB07FA30FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
FEBF5B7E100D851500F64C71 /* O2LZW.m in Sources */,
A1CC701C100534AB00DB9974 /* NSCachingBinder.m in Sources */,
A1CC70471005371100DB9974 /* NSTextBinder.m in Sources */,
FE6D9193101381F600BA6BAD /* NSCellUndoManager.m in Sources */,

View File

@ -369,6 +369,12 @@
FEAED71F0FD6C4460043F915 /* CGPDFContext.m in Sources */ = {isa = PBXBuildFile; fileRef = FEAED71B0FD6C4460043F915 /* CGPDFContext.m */; };
FEAED7200FD6C4460043F915 /* CGPDFContext.h in Headers */ = {isa = PBXBuildFile; fileRef = FEAED71A0FD6C4460043F915 /* CGPDFContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
FEAED7210FD6C4460043F915 /* CGPDFContext.m in Sources */ = {isa = PBXBuildFile; fileRef = FEAED71B0FD6C4460043F915 /* CGPDFContext.m */; };
FEBF5BCF100D8B2C00F64C71 /* O2LZW.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5BCD100D8B2C00F64C71 /* O2LZW.h */; };
FEBF5BD0100D8B2C00F64C71 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5BCE100D8B2C00F64C71 /* O2LZW.m */; };
FEBF5BD1100D8B2C00F64C71 /* O2LZW.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5BCD100D8B2C00F64C71 /* O2LZW.h */; };
FEBF5BD2100D8B2C00F64C71 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5BCE100D8B2C00F64C71 /* O2LZW.m */; };
FEBF5BD3100D8B2C00F64C71 /* O2LZW.h in Headers */ = {isa = PBXBuildFile; fileRef = FEBF5BCD100D8B2C00F64C71 /* O2LZW.h */; };
FEBF5BD4100D8B2C00F64C71 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF5BCE100D8B2C00F64C71 /* O2LZW.m */; };
FEC11AE80FD4B4D600082282 /* CGAffineTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = FEC11A380FD4B4D600082282 /* CGAffineTransform.h */; settings = {ATTRIBUTES = (Public, ); }; };
FEC11AE90FD4B4D600082282 /* CGAffineTransform.m in Sources */ = {isa = PBXBuildFile; fileRef = FEC11A390FD4B4D600082282 /* CGAffineTransform.m */; };
FEC11AEA0FD4B4D600082282 /* CGBitmapContext.h in Headers */ = {isa = PBXBuildFile; fileRef = FEC11A3A0FD4B4D600082282 /* CGBitmapContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -657,6 +663,8 @@
FEAED70F0FD6C40E0043F915 /* KGDataConsumer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGDataConsumer.m; sourceTree = "<group>"; };
FEAED71A0FD6C4460043F915 /* CGPDFContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGPDFContext.h; sourceTree = "<group>"; };
FEAED71B0FD6C4460043F915 /* CGPDFContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGPDFContext.m; sourceTree = "<group>"; };
FEBF5BCD100D8B2C00F64C71 /* O2LZW.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = O2LZW.h; sourceTree = "<group>"; };
FEBF5BCE100D8B2C00F64C71 /* O2LZW.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = O2LZW.m; sourceTree = "<group>"; };
FEC11A380FD4B4D600082282 /* CGAffineTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGAffineTransform.h; sourceTree = "<group>"; };
FEC11A390FD4B4D600082282 /* CGAffineTransform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGAffineTransform.m; sourceTree = "<group>"; };
FEC11A3A0FD4B4D600082282 /* CGBitmapContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGBitmapContext.h; sourceTree = "<group>"; };
@ -872,6 +880,8 @@
0867D691FE84028FC02AAC07 /* CoreGraphics */ = {
isa = PBXGroup;
children = (
FEBF5BCD100D8B2C00F64C71 /* O2LZW.h */,
FEBF5BCE100D8B2C00F64C71 /* O2LZW.m */,
FEAED71A0FD6C4460043F915 /* CGPDFContext.h */,
FEAED71B0FD6C4460043F915 /* CGPDFContext.m */,
FEC11A380FD4B4D600082282 /* CGAffineTransform.h */,
@ -1201,6 +1211,7 @@
FE9DB4610FD6C38300A1CE17 /* CGDataConsumer.h in Headers */,
FEAED7100FD6C40E0043F915 /* KGDataConsumer.h in Headers */,
FEAED71C0FD6C4460043F915 /* CGPDFContext.h in Headers */,
FEBF5BCF100D8B2C00F64C71 /* O2LZW.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1299,6 +1310,7 @@
FE9DB4630FD6C38300A1CE17 /* CGDataConsumer.h in Headers */,
FEAED7120FD6C40E0043F915 /* KGDataConsumer.h in Headers */,
FEAED71E0FD6C4460043F915 /* CGPDFContext.h in Headers */,
FEBF5BD1100D8B2C00F64C71 /* O2LZW.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1397,6 +1409,7 @@
FE9DB4650FD6C38300A1CE17 /* CGDataConsumer.h in Headers */,
FEAED7140FD6C40E0043F915 /* KGDataConsumer.h in Headers */,
FEAED7200FD6C4460043F915 /* CGPDFContext.h in Headers */,
FEBF5BD3100D8B2C00F64C71 /* O2LZW.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1659,6 +1672,7 @@
FE9DB4620FD6C38300A1CE17 /* CGDataConsumer.m in Sources */,
FEAED7110FD6C40E0043F915 /* KGDataConsumer.m in Sources */,
FEAED71D0FD6C4460043F915 /* CGPDFContext.m in Sources */,
FEBF5BD0100D8B2C00F64C71 /* O2LZW.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1752,6 +1766,7 @@
FE9DB4640FD6C38300A1CE17 /* CGDataConsumer.m in Sources */,
FEAED7130FD6C40E0043F915 /* KGDataConsumer.m in Sources */,
FEAED71F0FD6C4460043F915 /* CGPDFContext.m in Sources */,
FEBF5BD2100D8B2C00F64C71 /* O2LZW.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1845,6 +1860,7 @@
FE9DB4660FD6C38300A1CE17 /* CGDataConsumer.m in Sources */,
FEAED7150FD6C40E0043F915 /* KGDataConsumer.m in Sources */,
FEAED7210FD6C4460043F915 /* CGPDFContext.m in Sources */,
FEBF5BD4100D8B2C00F64C71 /* O2LZW.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -11,6 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@class KGFont;
typedef KGFont *O2FontRef;
@class NSData;
@interface KGFont : NSObject {
NSString *_name;
int _unitsPerEm;

View File

@ -66,6 +66,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
double _xResolution;
double _yPosition;
double _yResolution;
unsigned _predictor;
}
-initWithTIFFReader:(NSTIFFReader *)reader;

View File

@ -9,6 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import "NSTIFFImageFileDirectory.h"
#import "NSTIFFReader.h"
#import <CoreGraphics/CoreGraphics.h>
#import "O2LZW.h"
@implementation NSTIFFImageFileDirectory
@ -198,6 +199,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
_yResolution=[reader expectRational];
break;
case NSTIFFTagPredictor:
_predictor=[reader expectUnsigned16];
break;
case NSTIFFTagPhotoshopPrivate1:
case NSTIFFTagPhotoshopPrivate2:
// ignore
@ -310,11 +315,49 @@ static void decode_R8_G8_B8_Afill(const unsigned char *stripBytes,unsigned byteC
*pixelBytesRowp=pixelBytesRow;
}
NSData *LZWDecode(NSData *data,unsigned stripLength){
NSMutableData *result=[NSMutableData dataWithLength:stripLength];
LZWFileType lzwStream;
// FIXME: look into crash because not open stream, stream bug?
lzwStream.inputStream=[NSInputStream inputStreamWithData:data];
[lzwStream.inputStream open];
lzwStream.PixelCount=stripLength;
DLZWSetupDecompress(&lzwStream);
int error;
if((error=DLZWDecompressLine(&lzwStream,[result mutableBytes],stripLength))==0)
NSLog(@"error=%d",error);
return result;
}
void depredict_R8G8B8A8(uint8_t *pixelBytes,unsigned bytesPerRow,unsigned height){
int y;
for(y=0;y<height;y++){
int i;
for(i=4;i<bytesPerRow;){
pixelBytes[i]+=pixelBytes[i-4];
i++;
pixelBytes[i]+=pixelBytes[i-4];
i++;
pixelBytes[i]+=pixelBytes[i-4];
i++;
pixelBytes[i]+=pixelBytes[i-4];
i++;
}
pixelBytes+=bytesPerRow;
}
}
-(BOOL)getRGBAImageBytes:(unsigned char *)pixelBytes data:(NSData *)data {
const unsigned char *bytes=[data bytes];
unsigned length=[data length];
unsigned strip,i;
int bitsPerPixel,bytesPerRow,pixelBytesRow,pixelBytesCol;
int bitsPerPixel,bytesPerRow,pixelBytesRow;
// general checks
if(_imageLength==0){
@ -339,7 +382,7 @@ static void decode_R8_G8_B8_Afill(const unsigned char *stripBytes,unsigned byteC
// specific checks for unimplemented features
if(_compression!=NSTIFFCompression_none/* && _compression!=NSTIFFCompression_LZW*/){
if(_compression!=NSTIFFCompression_none && _compression!=NSTIFFCompression_LZW){
NSLog(@"TIFF unsupported, compression %d",_compression);
return NO;
}
@ -365,10 +408,8 @@ static void decode_R8_G8_B8_Afill(const unsigned char *stripBytes,unsigned byteC
return NO;
}
}
bytesPerRow=_imageWidth*4;
bytesPerRow=_imageWidth*(bitsPerPixel/8);
pixelBytesRow=0;
pixelBytesCol=0;
if(_compression==NSTIFFCompression_LZW){
@ -382,12 +423,19 @@ static void decode_R8_G8_B8_Afill(const unsigned char *stripBytes,unsigned byteC
}
NSData *data=[NSData dataWithBytes:bytes+offset length:byteCount];
// LZWDecode_data not present anyway
// data=[KGPDFFilter LZWDecode_data:data parameters:nil];
int stripLength=_rowsPerStrip;
if(pixelBytesRow+stripLength>_imageLength)
stripLength=_imageLength-pixelBytesRow;
stripLength*=bytesPerRow;
data=LZWDecode(data,stripLength);
if(_samplesPerPixel==4)
decode_R8_G8_B8_A8([data bytes],[data length],pixelBytes,bytesPerRow,&pixelBytesRow,_imageLength);
decode_R8_G8_B8_A8([data bytes],stripLength,pixelBytes,_imageWidth*4,&pixelBytesRow,_imageLength);
else
decode_R8_G8_B8_Afill([data bytes],[data length],pixelBytes,bytesPerRow,&pixelBytesRow,_imageLength);
decode_R8_G8_B8_Afill([data bytes],stripLength,pixelBytes,_imageWidth*4,&pixelBytesRow,_imageLength);
}
}
@ -401,12 +449,28 @@ static void decode_R8_G8_B8_Afill(const unsigned char *stripBytes,unsigned byteC
return NO;
}
if(_samplesPerPixel==4)
decode_R8_G8_B8_A8(bytes+offset,byteCount,pixelBytes,bytesPerRow,&pixelBytesRow,_imageLength);
decode_R8_G8_B8_A8(bytes+offset,byteCount,pixelBytes,_imageWidth*4,&pixelBytesRow,_imageLength);
else
decode_R8_G8_B8_Afill(bytes+offset,byteCount,pixelBytes,bytesPerRow,&pixelBytesRow,_imageLength);
decode_R8_G8_B8_Afill(bytes+offset,byteCount,pixelBytes,_imageWidth*4,&pixelBytesRow,_imageLength);
}
}
switch(_predictor){
case NSTIFFTagPredictor_none:
break;
case NSTIFFTagPredictor_horizontal:
if(_samplesPerPixel==4)
depredict_R8G8B8A8(pixelBytes,bytesPerRow,_imageLength);
else
NSLog(@"TIFF predictor error, horizontal unsupported for samples per pixel=%d");
break;
case NSTIFFTagPredictor_floatingPoint:
NSLog(@"TIFF predictor error, floating point unsupported");
break;
}
return YES;
}

View File

@ -61,7 +61,8 @@ enum {
NSTIFFTagXResolution=282,
NSTIFFTagYPosition=287,
NSTIFFTagYResolution=283,
NSTIFFTagPredictor=317,
NSTIFFTagPhotoshopPrivate1=34377,
NSTIFFTagPhotoshopPrivate2=37724,
NSTIFFTagExifIFD=34665,
@ -88,6 +89,10 @@ enum {
NSTIFFSampleFormat_VOID=4,
NSTIFFSampleFormat_COMPLEXINT=5,
NSTIFFSampleFormat_COMPLEXIEEEFP=6,
NSTIFFTagPredictor_none=1,
NSTIFFTagPredictor_horizontal=2,
NSTIFFTagPredictor_floatingPoint=3,
};
@interface NSTIFFReader : NSObject {

57
CoreGraphics/O2LZW.h Normal file
View File

@ -0,0 +1,57 @@
#import <Foundation/Foundation.h>
/*
Gif-Lib by Gershon Elber,Eric S. Raymond,Toshio Kuratomi
The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
typedef int LZWWord;
typedef unsigned int LZWPrefixType;
typedef unsigned char LZWPixelType;
typedef struct LZWFileType {
int LZWError;
LZWWord
BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */
ClearCode, /* The CLEAR LZ code. */
EOFCode, /* The EOF LZ code. */
RunningCode, /* The next code algorithm can generate. */
RunningBits, /* The number of bits required to represent RunningCode. */
MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits. */
LastCode, /* The code before the current code. */
CrntCode, /* Current algorithm code. */
StackPtr, /* For character stack (see below). */
CrntShiftState; /* Number of bits in CrntShiftDWord. */
unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */
unsigned long PixelCount; /* Number of pixels in image. */
NSInputStream *inputStream;
uint8_t Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
uint8_t Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */
LZWPrefixType Prefix[LZ_MAX_CODE + 1];
} LZWFileType;
int DLZWSetupDecompress(LZWFileType * LZWFile);
int DLZWDecompressLine(LZWFileType * LZWFile,LZWPixelType * Line,int LineLen);

274
CoreGraphics/O2LZW.m Normal file
View File

@ -0,0 +1,274 @@
/*
Gif-Lib by Gershon Elber,Eric S. Raymond,Toshio Kuratomi
The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#import "O2LZW.h"
#define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
#define LZ_BITS 12
#define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */
#define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */
#define GIF_ERROR 0
#define GIF_OK 1
#define D_GIF_ERR_READ_FAILED 102
#define D_GIF_ERR_DATA_TOO_BIG 108
#define D_GIF_ERR_NOT_READABLE 111
#define D_GIF_ERR_IMAGE_DEFECT 112
#define D_GIF_ERR_EOF_TOO_SOON 113
static inline int READ(LZWFileType * _gif,uint8_t *_buf,int _len){
return [(_gif)->inputStream read:_buf maxLength:_len];
}
/******************************************************************************
* Setup the LZ decompression for this image:
*****************************************************************************/
int DLZWSetupDecompress(LZWFileType * LZWFile) {
int i, BitsPerPixel;
LZWPrefixType *Prefix;
BitsPerPixel = 8;
LZWFile->BitsPerPixel = BitsPerPixel;
LZWFile->ClearCode = (1 << BitsPerPixel);
LZWFile->EOFCode = LZWFile->ClearCode + 1;
LZWFile->RunningCode = LZWFile->EOFCode + 1;
LZWFile->RunningBits = BitsPerPixel + 1; /* Number of bits per code. */
LZWFile->MaxCode1 = 1 << LZWFile->RunningBits; /* Max. code + 1. */
LZWFile->StackPtr = 0; /* No pixels on the pixel stack. */
LZWFile->LastCode = NO_SUCH_CODE;
LZWFile->CrntShiftState = 0; /* No information in CrntShiftDWord. */
LZWFile->CrntShiftDWord = 0;
Prefix = LZWFile->Prefix;
for (i = 0; i <= LZ_MAX_CODE; i++)
Prefix[i] = NO_SUCH_CODE;
return GIF_OK;
}
/******************************************************************************
* This routines read one gif data block at a time and buffers it internally
* so that the decompression routine could access it.
* The routine returns the next byte from its internal buffer (or read next
* block in if buffer empty) and returns GIF_OK if succesful.
*****************************************************************************/
static int DLZWBufferedInput(LZWFileType * LZWFile,
uint8_t * NextByte) {
if(READ(LZWFile, NextByte, 1)==-1)
return GIF_ERROR;
return GIF_OK;
}
/******************************************************************************
* The LZ decompression input routine:
* This routine is responsable for the decompression of the bit stream from
* 8 bits (bytes) packets, into the real codes.
* Returns GIF_OK if read succesfully.
*****************************************************************************/
static int DLZWDecompressInput(LZWFileType * LZWFile,int *Code) {
uint8_t NextByte;
static unsigned short CodeMasks[] = {
0x0000, 0x0001, 0x0003, 0x0007,
0x000f, 0x001f, 0x003f, 0x007f,
0x00ff, 0x01ff, 0x03ff, 0x07ff,
0x0fff
};
/* The image can't contain more than LZ_BITS per code. */
if (LZWFile->RunningBits > LZ_BITS) {
LZWFile->LZWError = D_GIF_ERR_IMAGE_DEFECT;
return GIF_ERROR;
}
while (LZWFile->CrntShiftState < LZWFile->RunningBits) {
/* Needs to get more bytes from input stream for next code: */
if (DLZWBufferedInput(LZWFile, &NextByte) == GIF_ERROR) {
return GIF_ERROR;
}
LZWFile->CrntShiftDWord<<=8;
LZWFile->CrntShiftDWord|=(unsigned)NextByte;
LZWFile->CrntShiftState += 8;
}
*Code = (LZWFile->CrntShiftDWord>>(LZWFile->CrntShiftState-LZWFile->RunningBits)) & CodeMasks[LZWFile->RunningBits];
// LZWFile->CrntShiftDWord >>= LZWFile->RunningBits;
LZWFile->CrntShiftState -= LZWFile->RunningBits;
/* If code cannot fit into RunningBits bits, must raise its size. Note
* however that codes above 4095 are used for special signaling.
* If we're using LZ_BITS bits already and we're at the max code, just
* keep using the table as it is, don't increment LZWFile->RunningCode.
*/
if (LZWFile->RunningCode < LZ_MAX_CODE + 2){
LZWFile->RunningCode++;
if(LZWFile->RunningCode >=LZWFile->MaxCode1 && LZWFile->RunningBits < LZ_BITS) {
LZWFile->MaxCode1 <<= 1;
LZWFile->RunningBits++;
}
}
return GIF_OK;
}
/******************************************************************************
* Routine to trace the Prefixes linked list until we get a prefix which is
* not code, but a pixel value (less than ClearCode). Returns that pixel value.
* If image is defective, we might loop here forever, so we limit the loops to
* the maximum possible if image O.k. - LZ_MAX_CODE times.
*****************************************************************************/
static int DLZWGetPrefixChar(LZWPrefixType *Prefix,int Code,int ClearCode) {
int i = 0;
while (Code > ClearCode && i++ <= LZ_MAX_CODE) {
if (Code > LZ_MAX_CODE) {
return NO_SUCH_CODE;
}
Code = Prefix[Code];
}
return Code;
}
int DLZWDecompressLine(LZWFileType * LZWFile,LZWPixelType * Line,int LineLen) {
int i = 0;
int j, CrntCode, EOFCode, ClearCode, CrntPrefix, LastCode, StackPtr;
uint8_t *Stack, *Suffix;
LZWPrefixType *Prefix;
StackPtr = LZWFile->StackPtr;
Prefix = LZWFile->Prefix;
Suffix = LZWFile->Suffix;
Stack = LZWFile->Stack;
EOFCode = LZWFile->EOFCode;
ClearCode = LZWFile->ClearCode;
LastCode = LZWFile->LastCode;
while (i < LineLen) { /* Decode LineLen items. */
if (DLZWDecompressInput(LZWFile, &CrntCode) == GIF_ERROR){
NSLog(@"error at %s %d",__FILE__,__LINE__);
return GIF_ERROR;
}
if (CrntCode == EOFCode) {
/* Note however that usually we will not be here as we will stop
* decoding as soon as we got all the pixel, or EOF code will
* not be read at all, and DLZWGetLine/Pixel clean everything. */
if (i != LineLen - 1 || LZWFile->PixelCount != 0) {
NSLog(@"error at %s %d",__FILE__,__LINE__);
LZWFile->LZWError = D_GIF_ERR_EOF_TOO_SOON;
return GIF_ERROR;
}
i++;
} else if (CrntCode == ClearCode) {
/* We need to start over again: */
for (j = 0; j <= LZ_MAX_CODE; j++)
Prefix[j] = NO_SUCH_CODE;
LZWFile->RunningCode = LZWFile->EOFCode + 1;
LZWFile->RunningBits = LZWFile->BitsPerPixel + 1;
LZWFile->MaxCode1 = 1 << LZWFile->RunningBits;
LastCode = LZWFile->LastCode = NO_SUCH_CODE;
LastCode = CrntCode;
} else {
if (CrntCode < ClearCode) {
/* This is simple - its pixel scalar, so add it to output: */
Line[i] = CrntCode;
i++;
} else
#define RUNNING_CODE_MINUS 2
{
/* Its a code to needed to be traced: trace the linked list
* until the prefix is a pixel, while pushing the suffix
* pixels on our stack. If we done, pop the stack in reverse
* (thats what stack is good for!) order to output. */
if (Prefix[CrntCode] == NO_SUCH_CODE) {
/* Only allowed if CrntCode is exactly the running code:
* In that case CrntCode = XXXCode, CrntCode or the
* prefix code is last code and the suffix char is
* exactly the prefix of last code! */
if (CrntCode == LZWFile->RunningCode - RUNNING_CODE_MINUS) {
CrntPrefix = LastCode;
Suffix[LZWFile->RunningCode - RUNNING_CODE_MINUS] =
Stack[StackPtr++] = DLZWGetPrefixChar(Prefix,
LastCode,
ClearCode);
} else {
LZWFile->LZWError = D_GIF_ERR_IMAGE_DEFECT;
NSLog(@"error at %s %d",__FILE__,__LINE__);
return GIF_ERROR;
}
} else
CrntPrefix = CrntCode;
/* Now (if image is O.K.) we should not get an NO_SUCH_CODE
* During the trace. As we might loop forever, in case of
* defective image, we count the number of loops we trace
* and stop if we got LZ_MAX_CODE. obviously we can not
* loop more than that. */
j = 0;
while (j++ <= LZ_MAX_CODE && CrntPrefix > ClearCode && CrntPrefix <= LZ_MAX_CODE) {
Stack[StackPtr++] = Suffix[CrntPrefix];
CrntPrefix = Prefix[CrntPrefix];
}
if (j >= LZ_MAX_CODE || CrntPrefix > LZ_MAX_CODE) {
LZWFile->LZWError = D_GIF_ERR_IMAGE_DEFECT;
NSLog(@"error at %s %d",__FILE__,__LINE__);
return GIF_ERROR;
}
/* Push the last character on stack: */
Stack[StackPtr++] = CrntPrefix;
/* Now lets pop all the stack into output: */
while (StackPtr != 0 && i < LineLen){
Line[i] = Stack[--StackPtr];
i++;
}
}
if (LastCode != NO_SUCH_CODE) {
Prefix[LZWFile->RunningCode - RUNNING_CODE_MINUS] = LastCode;
if (CrntCode == LZWFile->RunningCode - RUNNING_CODE_MINUS) {
/* Only allowed if CrntCode is exactly the running code:
* In that case CrntCode = XXXCode, CrntCode or the
* prefix code is last code and the suffix char is
* exactly the prefix of last code! */
Suffix[LZWFile->RunningCode - RUNNING_CODE_MINUS] =DLZWGetPrefixChar(Prefix, LastCode, ClearCode);
} else {
Suffix[LZWFile->RunningCode - RUNNING_CODE_MINUS] =DLZWGetPrefixChar(Prefix, CrntCode, ClearCode);
}
}
LastCode = CrntCode;
}
}
LZWFile->LastCode = LastCode;
LZWFile->StackPtr = StackPtr;
return GIF_OK;
}

View File

@ -69,12 +69,11 @@ typedef struct GifHashTableType {
#define IS_WRITEABLE(Private) (GifFile->FileState & FILE_STATE_WRITE)
typedef unsigned char GifPixelType;
typedef unsigned char GifByteType;
typedef unsigned int GifPrefixType;
typedef int GifWord;
typedef struct GifColorType {
GifByteType Red, Green, Blue;
uint8_t Red, Green, Blue;
} GifColorType;
typedef struct ColorMapObject {
@ -135,9 +134,9 @@ typedef struct GifFileType {
unsigned long PixelCount; /* Number of pixels in image. */
NSInputStream *inputStream;
NSOutputStream *outputStream;
GifByteType Buf[256]; /* Compressed input is buffered here. */
GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
GifByteType Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */
uint8_t Buf[256]; /* Compressed input is buffered here. */
uint8_t Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
uint8_t Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */
GifPrefixType Prefix[LZ_MAX_CODE + 1];
GifHashTableType *HashTable;
} GifFileType;
@ -173,8 +172,8 @@ int EGifPutExtensionFirst(GifFileType * GifFile, int GifExtCode,int GifExtLen, c
int EGifPutExtensionNext(GifFileType * GifFile, int GifExtCode,int GifExtLen, const void * GifExtension);
int EGifPutExtensionLast(GifFileType * GifFile, int GifExtCode,int GifExtLen, const void * GifExtension);
int EGifPutExtension(GifFileType * GifFile, int GifExtCode, int GifExtLen,const void * GifExtension);
int EGifPutCode(GifFileType * GifFile, int GifCodeSize,const GifByteType * GifCodeBlock);
int EGifPutCodeNext(GifFileType * GifFile,const GifByteType * GifCodeBlock);
int EGifPutCode(GifFileType * GifFile, int GifCodeSize,const uint8_t * GifCodeBlock);
int EGifPutCodeNext(GifFileType * GifFile,const uint8_t * GifCodeBlock);
int EGifCloseFile(GifFileType * GifFile);
#define E_GIF_ERR_OPEN_FAILED 1
@ -199,10 +198,10 @@ int DGifGetRecordType(GifFileType * GifFile, GifRecordType * GifType);
int DGifGetImageDesc(GifFileType * GifFile);
int DGifGetLine(GifFileType * GifFile, GifPixelType * GifLine, int GifLineLen);
int DGifGetComment(GifFileType * GifFile, char *GifComment);
int DGifGetExtension(GifFileType * GifFile, int *GifExtCode,GifByteType ** GifExtension);
int DGifGetExtensionNext(GifFileType * GifFile, GifByteType ** GifExtension);
int DGifGetCode(GifFileType * GifFile, int *GifCodeSize,GifByteType ** GifCodeBlock);
int DGifGetCodeNext(GifFileType * GifFile, GifByteType ** GifCodeBlock);
int DGifGetExtension(GifFileType * GifFile, int *GifExtCode,uint8_t ** GifExtension);
int DGifGetExtensionNext(GifFileType * GifFile, uint8_t ** GifExtension);
int DGifGetCode(GifFileType * GifFile, int *GifCodeSize,uint8_t ** GifCodeBlock);
int DGifGetCodeNext(GifFileType * GifFile, uint8_t ** GifCodeBlock);
int DGifCloseFile(GifFileType * GifFile);
#define D_GIF_ERR_OPEN_FAILED 101
@ -219,7 +218,7 @@ int DGifCloseFile(GifFileType * GifFile);
#define D_GIF_ERR_IMAGE_DEFECT 112
#define D_GIF_ERR_EOF_TOO_SOON 113
int QuantizeBuffer(unsigned int Width, unsigned int Height,int *ColorMapSize, GifByteType * RedInput,GifByteType * GreenInput, GifByteType * BlueInput,GifByteType * OutputBuffer,GifColorType * OutputColorMap);
int QuantizeBuffer(unsigned int Width, unsigned int Height,int *ColorMapSize, uint8_t * RedInput,uint8_t * GreenInput, uint8_t * BlueInput,uint8_t * OutputBuffer,GifColorType * OutputColorMap);
extern int GifLastError(GifFileType *);

View File

@ -34,14 +34,14 @@ static int EGifPutWord(int Word, GifFileType * GifFile);
static int EGifSetupCompress(GifFileType * GifFile);
static int EGifCompressLine(GifFileType * GifFile, GifPixelType * Line,int LineLen);
static int EGifCompressOutput(GifFileType * GifFile, int Code);
static int EGifBufferedOutput(GifFileType * GifFile, GifByteType * Buf,int c);
static int EGifBufferedOutput(GifFileType * GifFile, uint8_t * Buf,int c);
static int DGifGetWord(GifFileType *GifFile, GifWord *Word);
static int DGifSetupDecompress(GifFileType *GifFile);
static int DGifDecompressLine(GifFileType *GifFile, GifPixelType *Line,int LineLen);
static int DGifGetPrefixChar(GifPrefixType *Prefix, int Code, int ClearCode);
static int DGifDecompressInput(GifFileType *GifFile, int *Code);
static int DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf,GifByteType *NextByte);
static int DGifBufferedInput(GifFileType *GifFile, uint8_t *Buf,uint8_t *NextByte);
/* The colors are stripped to 5 bits per primary color if non MSDOS system
* or to 4 (not enough memory...) if MSDOS as first step.
@ -51,14 +51,14 @@ static int DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf,GifByteType
#define MAX_PRIM_COLOR 0x1f
typedef struct QuantizedColorType {
GifByteType RGB[3];
GifByteType NewColorIndex;
uint8_t RGB[3];
uint8_t NewColorIndex;
long Count;
struct QuantizedColorType *Pnext;
} QuantizedColorType;
typedef struct NewColorMapType {
GifByteType RGBMin[3], RGBWidth[3];
uint8_t RGBMin[3], RGBWidth[3];
unsigned int NumEntries; /* # of QuantizedColorType in linked list below */
unsigned long Count; /* Total number of pixels in all the entries */
QuantizedColorType *QuantizedColors;
@ -121,7 +121,7 @@ GifFileType *DGifOpen(NSInputStream *stream) {
int DGifGetScreenDesc(GifFileType * GifFile) {
int i, BitsPerPixel;
GifByteType Buf[3];
uint8_t Buf[3];
if (!IS_READABLE(GifFile)) {
/* This file was NOT open for reading: */
@ -173,7 +173,7 @@ int DGifGetScreenDesc(GifFileType * GifFile) {
*****************************************************************************/
int DGifGetRecordType(GifFileType * GifFile,GifRecordType * Type) {
GifByteType Buf;
uint8_t Buf;
if (!IS_READABLE(GifFile)) {
/* This file was NOT open for reading: */
@ -212,7 +212,7 @@ int DGifGetRecordType(GifFileType * GifFile,GifRecordType * Type) {
int DGifGetImageDesc(GifFileType * GifFile) {
int i, BitsPerPixel;
GifByteType Buf[3];
uint8_t Buf[3];
SavedImage *sp;
if (!IS_READABLE(GifFile)) {
@ -306,7 +306,7 @@ int DGifGetImageDesc(GifFileType * GifFile) {
*****************************************************************************/
int DGifGetLine(GifFileType * GifFile,GifPixelType * Line,int LineLen) {
GifByteType *Dummy;
uint8_t *Dummy;
if (!IS_READABLE(GifFile)) {
/* This file was NOT open for reading: */
@ -345,9 +345,9 @@ int DGifGetLine(GifFileType * GifFile,GifPixelType * Line,int LineLen) {
* The Extension should NOT be freed by the user (not dynamically allocated).
* Note it is assumed the Extension desc. header ('!') has been read.
*****************************************************************************/
int DGifGetExtension(GifFileType * GifFile,int *ExtCode,GifByteType ** Extension) {
int DGifGetExtension(GifFileType * GifFile,int *ExtCode,uint8_t ** Extension) {
GifByteType Buf;
uint8_t Buf;
if (!IS_READABLE(GifFile)) {
/* This file was NOT open for reading: */
@ -369,9 +369,9 @@ int DGifGetExtension(GifFileType * GifFile,int *ExtCode,GifByteType ** Extension
* routine should be called until NULL Extension is returned.
* The Extension should NOT be freed by the user (not dynamically allocated).
*****************************************************************************/
int DGifGetExtensionNext(GifFileType * GifFile,GifByteType ** Extension) {
int DGifGetExtensionNext(GifFileType * GifFile,uint8_t ** Extension) {
GifByteType Buf;
uint8_t Buf;
if (READ(GifFile, &Buf, 1) != 1) {
GifFile->GifError = D_GIF_ERR_READ_FAILED;
@ -448,7 +448,7 @@ static int DGifGetWord(GifFileType * GifFile,GifWord *Word) {
* to DGifGetCodeNext, until NULL block is returned.
* The block should NOT be freed by the user (not dynamically allocated).
*****************************************************************************/
int DGifGetCode(GifFileType * GifFile,int *CodeSize,GifByteType ** CodeBlock) {
int DGifGetCode(GifFileType * GifFile,int *CodeSize,uint8_t ** CodeBlock) {
if (!IS_READABLE(GifFile)) {
/* This file was NOT open for reading: */
@ -467,9 +467,9 @@ int DGifGetCode(GifFileType * GifFile,int *CodeSize,GifByteType ** CodeBlock) {
* The block should NOT be freed by the user (not dynamically allocated).
*****************************************************************************/
int DGifGetCodeNext(GifFileType * GifFile,
GifByteType ** CodeBlock) {
uint8_t ** CodeBlock) {
GifByteType Buf;
uint8_t Buf;
if (READ(GifFile, &Buf, 1) != 1) {
GifFile->GifError = D_GIF_ERR_READ_FAILED;
@ -498,7 +498,7 @@ int DGifGetCodeNext(GifFileType * GifFile,
static int DGifSetupDecompress(GifFileType * GifFile) {
int i, BitsPerPixel;
GifByteType CodeSize;
uint8_t CodeSize;
GifPrefixType *Prefix;
READ(GifFile, &CodeSize, 1); /* Read Code size from file. */
@ -535,7 +535,7 @@ static int DGifDecompressLine(GifFileType * GifFile,
int i = 0;
int j, CrntCode, EOFCode, ClearCode, CrntPrefix, LastCode, StackPtr;
GifByteType *Stack, *Suffix;
uint8_t *Stack, *Suffix;
GifPrefixType *Prefix;
StackPtr = GifFile->StackPtr;
@ -681,7 +681,7 @@ static int DGifGetPrefixChar(GifPrefixType *Prefix,int Code,int ClearCode) {
*****************************************************************************/
static int DGifDecompressInput(GifFileType * GifFile,int *Code) {
GifByteType NextByte;
uint8_t NextByte;
static unsigned short CodeMasks[] = {
0x0000, 0x0001, 0x0003, 0x0007,
0x000f, 0x001f, 0x003f, 0x007f,
@ -729,8 +729,8 @@ static int DGifDecompressInput(GifFileType * GifFile,int *Code) {
* block in if buffer empty) and returns GIF_OK if succesful.
*****************************************************************************/
static int DGifBufferedInput(GifFileType * GifFile,
GifByteType * Buf,
GifByteType * NextByte) {
uint8_t * Buf,
uint8_t * NextByte) {
if (Buf[0] == 0) {
/* Needs to read the next buffer - this one is empty: */
@ -771,7 +771,7 @@ int DGifSlurp(GifFileType * GifFile) {
int ImageSize;
GifRecordType RecordType;
SavedImage *sp;
GifByteType *ExtData;
uint8_t *ExtData;
SavedImage temp_save;
int Function=0;
@ -961,7 +961,7 @@ int EGifPutScreenDesc(GifFileType * GifFile,
const ColorMapObject * ColorMap) {
int i;
GifByteType Buf[3];
uint8_t Buf[3];
if (GifFile->FileState & FILE_STATE_SCREEN) {
/* If already has screen descriptor - something is wrong! */
@ -1046,7 +1046,7 @@ int EGifPutImageDesc(GifFileType * GifFile,
const ColorMapObject * ColorMap) {
int i;
GifByteType Buf[3];
uint8_t Buf[3];
if (GifFile->FileState & FILE_STATE_IMAGE &&
GifFile->PixelCount > 0xffff0000UL) {
@ -1226,7 +1226,7 @@ int EGifPutExtensionFirst(GifFileType * GifFile,
int ExtLen,
const void * Extension) {
GifByteType Buf[3];
uint8_t Buf[3];
if (!IS_WRITEABLE(GifFile)) {
/* This file was NOT open for writing: */
@ -1235,7 +1235,7 @@ int EGifPutExtensionFirst(GifFileType * GifFile,
}
if (ExtCode == 0) {
WRITE(GifFile, (GifByteType *)&ExtLen, 1);
WRITE(GifFile, (uint8_t *)&ExtLen, 1);
} else {
Buf[0] = '!';
Buf[1] = ExtCode;
@ -1256,7 +1256,7 @@ int EGifPutExtensionNext(GifFileType * GifFile,
int ExtLen,
const void * Extension) {
GifByteType Buf;
uint8_t Buf;
if (!IS_WRITEABLE(GifFile)) {
/* This file was NOT open for writing: */
@ -1279,7 +1279,7 @@ int EGifPutExtensionLast(GifFileType * GifFile,
int ExtLen,
const void * Extension) {
GifByteType Buf;
uint8_t Buf;
if (!IS_WRITEABLE(GifFile)) {
/* This file was NOT open for writing: */
@ -1312,7 +1312,7 @@ int EGifPutExtension(GifFileType * GifFile,
int ExtLen,
const void * Extension) {
GifByteType Buf[3];
uint8_t Buf[3];
if (!IS_WRITEABLE(GifFile)) {
/* This file was NOT open for writing: */
@ -1321,7 +1321,7 @@ int EGifPutExtension(GifFileType * GifFile,
}
if (ExtCode == 0)
WRITE(GifFile, (GifByteType *)&ExtLen, 1);
WRITE(GifFile, (uint8_t *)&ExtLen, 1);
else {
Buf[0] = '!'; /* Extension Introducer 0x21 */
Buf[1] = ExtCode; /* Extension Label */
@ -1344,7 +1344,7 @@ int EGifPutExtension(GifFileType * GifFile,
*****************************************************************************/
int EGifPutCode(GifFileType * GifFile,
int CodeSize,
const GifByteType * CodeBlock) {
const uint8_t * CodeBlock) {
if (!IS_WRITEABLE(GifFile)) {
/* This file was NOT open for writing: */
@ -1370,9 +1370,9 @@ int EGifPutCode(GifFileType * GifFile,
* given buffer pointer is NULL, empty block is written to mark end of code.
*****************************************************************************/
int EGifPutCodeNext(GifFileType * GifFile,
const GifByteType * CodeBlock) {
const uint8_t * CodeBlock) {
GifByteType Buf;
uint8_t Buf;
if (CodeBlock != NULL) {
if (WRITE(GifFile, CodeBlock, CodeBlock[0] + 1)
@ -1397,7 +1397,7 @@ int EGifPutCodeNext(GifFileType * GifFile,
*****************************************************************************/
int EGifCloseFile(GifFileType * GifFile) {
GifByteType Buf;
uint8_t Buf;
if (GifFile == NULL)
return GIF_ERROR;
@ -1449,7 +1449,7 @@ static int EGifPutWord(int Word,
static int EGifSetupCompress(GifFileType * GifFile) {
int BitsPerPixel;
GifByteType Buf;
uint8_t Buf;
/* Test and see what color map to use, and from it # bits per pixel: */
if (GifFile->Image.ColorMap)
@ -1625,7 +1625,7 @@ static int EGifCompressOutput(GifFileType * GifFile,
* Returns GIF_OK if written succesfully.
*****************************************************************************/
static int EGifBufferedOutput(GifFileType * GifFile,
GifByteType * Buf,
uint8_t * Buf,
int c) {
if (c == FLUSH_OUTPUT) {
@ -2366,7 +2366,7 @@ static int SubdivColorMap(NewColorMapType * NewColorSubdiv,unsigned int ColorMap
* Also non of the parameter are allocated by this routine.
* This function returns GIF_OK if succesfull, GIF_ERROR otherwise.
******************************************************************************/
int QuantizeBuffer(unsigned int Width,unsigned int Height,int *ColorMapSize,GifByteType * RedInput,GifByteType * GreenInput,GifByteType * BlueInput,GifByteType * OutputBuffer,GifColorType * OutputColorMap) {
int QuantizeBuffer(unsigned int Width,unsigned int Height,int *ColorMapSize,uint8_t * RedInput,uint8_t * GreenInput,uint8_t * BlueInput,uint8_t * OutputBuffer,GifColorType * OutputColorMap) {
unsigned int Index, NumOfEntries;
int i, j, MaxRGBError[3];

View File

@ -80,9 +80,14 @@ static CGColorRef cgColorFromColor(NSColor *color){
_dashLengths=NSZoneMalloc([self zone],sizeof(float)*4);
NSString *path=[[NSBundle bundleForClass:[self class]] pathForResource:@"overlay" ofType:@"png"];
// NSString *path=[[NSBundle bundleForClass:[self class]] pathForResource:@"redLZWSquare" ofType:@"tif"];
NSData *data=[NSData dataWithContentsOfFile:path];
CGImageSourceRef source=CGImageSourceCreateWithData((CFDataRef)data,nil);
_resamplingImage=CGImageSourceCreateImageAtIndex(source,0,nil);
#if 0
if(![_resamplingImage isKindOfClass:NSClassFromString(@"KGImage")])
NSLog(@"IMAGE data=%@",CGDataProviderCopyData(CGImageGetDataProvider(_resamplingImage)));
#endif
if(_resamplingImage==nil)
NSLog(@"no image! path=%@ %d",path,[data length]);
[(id)source release];

View File

@ -12,13 +12,14 @@
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
FE0997430D87095000033630 /* overlay.png in Resources */ = {isa = PBXBuildFile; fileRef = FE0997420D87095000033630 /* overlay.png */; };
FE1364030FE80F4900DE15FA /* KTFont.m in Sources */ = {isa = PBXBuildFile; fileRef = FEA084D40EF5FDE6001E8260 /* KTFont.m */; };
FE1364050FE80F4F00DE15FA /* KTFont+PDF.m in Sources */ = {isa = PBXBuildFile; fileRef = FEA084D20EF5FDE6001E8260 /* KTFont+PDF.m */; };
FE14EC4B0DBD9BF00070928C /* DemoCGContext.m in Sources */ = {isa = PBXBuildFile; fileRef = FE14EC490DBD9BF00070928C /* DemoCGContext.m */; };
FE14EC4C0DBD9BF00070928C /* DemoKGContext.m in Sources */ = {isa = PBXBuildFile; fileRef = FE14EC4A0DBD9BF00070928C /* DemoKGContext.m */; };
FE14EC960DBDA5420070928C /* DemoContext.m in Sources */ = {isa = PBXBuildFile; fileRef = FE14EC950DBDA5420070928C /* DemoContext.m */; };
FE1F93630D7EF19900969491 /* KGImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = FE1F93620D7EF19900969491 /* KGImageView.m */; };
FE1F937A0D7EF1F800969491 /* KGRenderController.m in Sources */ = {isa = PBXBuildFile; fileRef = FE1F93790D7EF1F800969491 /* KGRenderController.m */; };
FE452BCE101F412D00585DFE /* KGImageSource_GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = FE452BCD101F412D00585DFE /* KGImageSource_GIF.m */; };
FE452BD1101F414700585DFE /* gif_lib.m in Sources */ = {isa = PBXBuildFile; fileRef = FE452BD0101F414700585DFE /* gif_lib.m */; };
FE45ED3D0DC2374E00F49290 /* KGImageSource.m in Sources */ = {isa = PBXBuildFile; fileRef = FE45ED340DC2374E00F49290 /* KGImageSource.m */; };
FE45ED3E0DC2374E00F49290 /* KGImageSource_BMP.m in Sources */ = {isa = PBXBuildFile; fileRef = FE45ED360DC2374E00F49290 /* KGImageSource_BMP.m */; };
FE45ED3F0DC2374E00F49290 /* KGImageSource_JPEG.m in Sources */ = {isa = PBXBuildFile; fileRef = FE45ED380DC2374E00F49290 /* KGImageSource_JPEG.m */; };
@ -72,8 +73,10 @@
FE6EDD400DB78EA1005503A1 /* KGPDFxrefEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = FE6EDD260DB78EA1005503A1 /* KGPDFxrefEntry.m */; };
FE6EDD410DB78EA1005503A1 /* KGzlib.m in Sources */ = {isa = PBXBuildFile; fileRef = FE6EDD280DB78EA1005503A1 /* KGzlib.m */; };
FE6EE00B0DB7CE0B005503A1 /* KGContext_builtin.m in Sources */ = {isa = PBXBuildFile; fileRef = FE6EE00A0DB7CE0B005503A1 /* KGContext_builtin.m */; };
FE8CA8ED10181DD500F78535 /* O2LZW.m in Sources */ = {isa = PBXBuildFile; fileRef = FE8CA8EC10181DD500F78535 /* O2LZW.m */; };
FE9552810D77CA67009B765B /* KGSurface.m in Sources */ = {isa = PBXBuildFile; fileRef = FE9552780D77CA67009B765B /* KGSurface.m */; };
FE9552830D77CA67009B765B /* VGPath.m in Sources */ = {isa = PBXBuildFile; fileRef = FE95527C0D77CA67009B765B /* VGPath.m */; };
FEA47EC2101E44CD005820F3 /* redLZWSquare.tif in Resources */ = {isa = PBXBuildFile; fileRef = FEA47EC1101E44CD005820F3 /* redLZWSquare.tif */; };
FEBF55B90DCA0DE500CE5A1C /* KGPaint.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF55B80DCA0DE500CE5A1C /* KGPaint.m */; };
FEBF575B0DCA60CD00CE5A1C /* KGPaint_image.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF575A0DCA60CD00CE5A1C /* KGPaint_image.m */; };
FEBF59190DCC063400CE5A1C /* KGPaint_pattern.m in Sources */ = {isa = PBXBuildFile; fileRef = FEBF59050DCC063400CE5A1C /* KGPaint_pattern.m */; };
@ -116,6 +119,10 @@
FE1F93790D7EF1F800969491 /* KGRenderController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGRenderController.m; sourceTree = "<group>"; };
FE3396000DBA8CF7009AB3E0 /* CoreGraphics_KG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreGraphics_KG.h; sourceTree = "<group>"; };
FE33964B0DBAE733009AB3E0 /* DemosTemplate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemosTemplate.m; sourceTree = "<group>"; };
FE452BCC101F412D00585DFE /* KGImageSource_GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGImageSource_GIF.h; sourceTree = "<group>"; };
FE452BCD101F412D00585DFE /* KGImageSource_GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGImageSource_GIF.m; sourceTree = "<group>"; };
FE452BCF101F414700585DFE /* gif_lib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gif_lib.h; sourceTree = "<group>"; };
FE452BD0101F414700585DFE /* gif_lib.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = gif_lib.m; sourceTree = "<group>"; };
FE45ED330DC2374E00F49290 /* KGImageSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGImageSource.h; sourceTree = "<group>"; };
FE45ED340DC2374E00F49290 /* KGImageSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGImageSource.m; sourceTree = "<group>"; };
FE45ED350DC2374E00F49290 /* KGImageSource_BMP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGImageSource_BMP.h; sourceTree = "<group>"; };
@ -222,6 +229,8 @@
FE6EDE380DB797FA005503A1 /* KGExceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGExceptions.h; sourceTree = "<group>"; };
FE6EE0090DB7CE0B005503A1 /* KGContext_builtin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGContext_builtin.h; sourceTree = "<group>"; };
FE6EE00A0DB7CE0B005503A1 /* KGContext_builtin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGContext_builtin.m; sourceTree = "<group>"; };
FE8CA8EB10181DD500F78535 /* O2LZW.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = O2LZW.h; sourceTree = "<group>"; };
FE8CA8EC10181DD500F78535 /* O2LZW.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = O2LZW.m; sourceTree = "<group>"; };
FE9552770D77CA67009B765B /* KGSurface.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = KGSurface.h; sourceTree = "<group>"; };
FE9552780D77CA67009B765B /* KGSurface.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = KGSurface.m; sourceTree = "<group>"; };
FE9552790D77CA67009B765B /* VGmath.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = VGmath.h; sourceTree = "<group>"; };
@ -229,8 +238,7 @@
FE95527C0D77CA67009B765B /* VGPath.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = VGPath.m; sourceTree = "<group>"; };
FEA084D10EF5FDE6001E8260 /* KTFont+PDF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KTFont+PDF.h"; sourceTree = "<group>"; };
FEA084D20EF5FDE6001E8260 /* KTFont+PDF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KTFont+PDF.m"; sourceTree = "<group>"; };
FEA084D30EF5FDE6001E8260 /* KTFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KTFont.h; sourceTree = "<group>"; };
FEA084D40EF5FDE6001E8260 /* KTFont.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KTFont.m; sourceTree = "<group>"; };
FEA47EC1101E44CD005820F3 /* redLZWSquare.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = redLZWSquare.tif; sourceTree = "<group>"; };
FEBF55B70DCA0DE500CE5A1C /* KGPaint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGPaint.h; sourceTree = "<group>"; };
FEBF55B80DCA0DE500CE5A1C /* KGPaint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGPaint.m; sourceTree = "<group>"; };
FEBF57590DCA60CD00CE5A1C /* KGPaint_image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGPaint_image.h; sourceTree = "<group>"; };
@ -319,6 +327,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
FEA47EC1101E44CD005820F3 /* redLZWSquare.tif */,
FE45EE640DC254C700F49290 /* overlay.jpg */,
FE0997420D87095000033630 /* overlay.png */,
8D1107310486CEB800E47090 /* Info.plist */,
@ -340,6 +349,12 @@
FE21384A0DC2303100CEDC65 /* CoreGraphics */ = {
isa = PBXGroup;
children = (
FE452BCF101F414700585DFE /* gif_lib.h */,
FE452BD0101F414700585DFE /* gif_lib.m */,
FE452BCC101F412D00585DFE /* KGImageSource_GIF.h */,
FE452BCD101F412D00585DFE /* KGImageSource_GIF.m */,
FE8CA8EB10181DD500F78535 /* O2LZW.h */,
FE8CA8EC10181DD500F78535 /* O2LZW.m */,
FE45ED420DC2376700F49290 /* NSTIFFImageFileDirectory.h */,
FE45ED430DC2376700F49290 /* NSTIFFImageFileDirectory.m */,
FE45ED440DC2376700F49290 /* NSTIFFReader.h */,
@ -364,8 +379,6 @@
children = (
FEA084D10EF5FDE6001E8260 /* KTFont+PDF.h */,
FEA084D20EF5FDE6001E8260 /* KTFont+PDF.m */,
FEA084D30EF5FDE6001E8260 /* KTFont.h */,
FEA084D40EF5FDE6001E8260 /* KTFont.m */,
FE4F4CB70E10397000A5A5F8 /* KGColorSpace+PDF.h */,
FE4F4CB80E10397000A5A5F8 /* KGColorSpace+PDF.m */,
FE4F4CBB0E10397000A5A5F8 /* KGFunction+PDF.h */,
@ -530,6 +543,7 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
FE0997430D87095000033630 /* overlay.png in Resources */,
FE45EE650DC254C700F49290 /* overlay.jpg in Resources */,
FEA47EC2101E44CD005820F3 /* redLZWSquare.tif in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -607,8 +621,10 @@
FE4F4CC30E10397000A5A5F8 /* KGFunction+PDF.m in Sources */,
FE4F4CC40E10397000A5A5F8 /* KGImage+PDF.m in Sources */,
FE4F4CC50E10397000A5A5F8 /* KGShading+PDF.m in Sources */,
FE1364030FE80F4900DE15FA /* KTFont.m in Sources */,
FE1364050FE80F4F00DE15FA /* KTFont+PDF.m in Sources */,
FE8CA8ED10181DD500F78535 /* O2LZW.m in Sources */,
FE452BCE101F412D00585DFE /* KGImageSource_GIF.m in Sources */,
FE452BD1101F414700585DFE /* gif_lib.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

Binary file not shown.