views:

99

answers:

1

I am a Mac guy,

How to get the PackBits compression using sips?

Below one for LZW works fine.

sips -s formatOptions lzw /DefaultGroup.tif

But this fails:

sips -s formatOptions packbits /DefaultGroup.tif

Any idea why?

A: 

The code below works. But still I could not find the actual answer to my query.

 int compression = NSTIFFCompressionPackBits;

CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)dataToWrite, NULL);

CGImageRef imageRef =  CGImageSourceCreateImageAtIndex(source, 0, NULL);

CFMutableDictionaryRef saveMetaAndOpts = CFDictionaryCreateMutable(nil,0,&kCFTypeDictionaryKeyCallBacks,  &kCFTypeDictionaryValueCallBacks);

CFMutableDictionaryRef tiffProfsMut = CFDictionaryCreateMutable(nil, 0,
&kCFTypeDictionaryKeyCallBacks,  &kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(tiffProfsMut, kCGImagePropertyTIFFCompression, CFNumberCreate(NULL, kCFNumberIntType, &compression));  
CFDictionarySetValue(saveMetaAndOpts, kCGImagePropertyTIFFDictionary, tiffProfsMut);

NSURL *outURL = [[NSURL alloc] initFileURLWithPath:filename];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL ((CFURLRef)outURL, (CFStringRef)@"public.tiff" , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, saveMetaAndOpts);
CGImageDestinationFinalize(dr);

CFRelease(dr);
[outURL release];
CFRelease(tiffProfsMut);
CFRelease(saveMetaAndOpts);
CFRelease(imageRef);

CFRelease(source);
Dhanaraj