NSTIFFCompressionPackBits not compressing?
NSTIFFCompressionPackBits not compressing?
- Subject: NSTIFFCompressionPackBits not compressing?
- From: Jérôme Laurens <email@hidden>
- Date: Fri, 25 Jul 2003 21:17:21 +0200
I have got a big problem concerning the PackBits TIFF compression: it
expands instead of compressing.
I just create an image view in IB to display the NSApplication icon,
and add the following testCompress: method, hooked to a button.
In the first method, I use the PDF data from dataWithPDFInsideRect: to
create an image on which I apply
TIFFRepresentationUsingCompression:factor:, the size of the output data
is logged. The NSTIFFCompressionPackBits is ridiculous.
In the second method, I use an NSBitmapImageRep with the TIFF
representation of the previously created image. The results are the
same.
In the third method, I use an NSBitmapImageRep directly with the
contents of the view using . No problem here.
So here is my question: WHY this very poor NSTIFFCompressionPackBits
compression rate when using the pdf data?
(on other examples, there is no compression at all...)
Here is the output
USING PDF DATA:
-- NSTIFFCompressionNone: length = 168186
-- NSTIFFCompressionLZW: length = 34302
-- NSTIFFCompressionPackBits: length = 161926
USING TIFF REPRESENTATION:
-- NSTIFFCompressionNone: length = 168186
-- NSTIFFCompressionLZW: length = 34302
can be compressed using NSTIFFCompressionPackBits?: YES
-- NSTIFFCompressionPackBits: length = 161926
USING View:
-- NSTIFFCompressionNone: length = 126174
- NSTIFFCompressionLZW: length = 27426
can be compressed using NSTIFFCompressionPackBits?: YES
-- NSTIFFCompressionPackBits: length = 37430
@implementation NSView(MORE)
- (IBAction) compress: (id) sender
{
NSLog(@"USING PDF
DATA:");
NSData * D = [self dataWithPDFInsideRect: [self bounds]];
NSImage * image = [[[NSImage allocWithZone: [self zone]]
initWithData: D] autorelease];
NSLog(@"-- NSTIFFCompressionNone: length = %i",
[[image TIFFRepresentationUsingCompression:
NSTIFFCompressionNone factor: 0] length]);
NSLog(@"-- NSTIFFCompressionLZW: length = %i",
[[image TIFFRepresentationUsingCompression:
NSTIFFCompressionLZW factor: 0] length]);
NSLog(@"-- NSTIFFCompressionPackBits: length = %i",
[[image TIFFRepresentationUsingCompression:
NSTIFFCompressionPackBits factor: 0] length]);
NSLog(@"USING TIFF REPRESENTATION:");
NSBitmapImageRep * BIR = [[[NSBitmapImageRep allocWithZone: [self
zone]] initWithData: [image TIFFRepresentation]] autorelease];
NSData * D = [BIR representationUsingType: NSTIFFFileType
properties:
[NSDictionary dictionaryWithObject: [NSNumber
numberWithInt: NSTIFFCompressionNone] forKey:
NSImageCompressionMethod]];
NSLog(@"-- NSTIFFCompressionNone: length = %i", [D length]);
D = [BIR representationUsingType: NSTIFFFileType properties:
[NSDictionary dictionaryWithObject: [NSNumber
numberWithInt: NSTIFFCompressionLZW] forKey: NSImageCompressionMethod]];
NSLog(@"-- NSTIFFCompressionLZW: length = %i", [D length]);
NSLog(@"can be compressed using NSTIFFCompressionPackBits?: %@",
([BIR canBeCompressedUsing: NSTIFFCompressionPackBits]?
@"YES": @"NO"));
D = [BIR representationUsingType: NSTIFFFileType properties:
[NSDictionary dictionaryWithObject: [NSNumber
numberWithInt: NSTIFFCompressionPackBits] forKey:
NSImageCompressionMethod]];
NSLog(@"-- NSTIFFCompressionPackBits: length = %i", [D length]);
NSLog(@"USING View:");
[self lockFocus];
BIR = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [self
bounds]] autorelease];
[self unlockFocus];
D = [BIR representationUsingType: NSTIFFFileType properties:
[NSDictionary dictionaryWithObject: [NSNumber
numberWithInt: NSTIFFCompressionNone] forKey:
NSImageCompressionMethod]];
NSLog(@"-- NSTIFFCompressionNone: length = %i", [D length]);
D = [BIR representationUsingType: NSTIFFFileType properties:
[NSDictionary dictionaryWithObject: [NSNumber
numberWithInt: NSTIFFCompressionLZW] forKey: NSImageCompressionMethod]];
NSLog(@"-- NSTIFFCompressionLZW: length = %i", [D length]);
NSLog(@"can be compressed using NSTIFFCompressionPackBits?: %@",
([BIR canBeCompressedUsing: NSTIFFCompressionPackBits]?
@"YES": @"NO"));
D = [BIR representationUsingType: NSTIFFFileType properties:
[NSDictionary dictionaryWithObject: [NSNumber
numberWithInt: NSTIFFCompressionPackBits] forKey:
NSImageCompressionMethod]];
NSLog(@"-- NSTIFFCompressionPackBits: length = %i", [D length]);
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.