• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Final round with NSTIFFCompressionCCITTFAX3
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Final round with NSTIFFCompressionCCITTFAX3


  • Subject: Final round with NSTIFFCompressionCCITTFAX3
  • From: Ben Mackin <email@hidden>
  • Date: Wed, 11 Sep 2002 15:49:39 -0700

I was told awhile back that in order to use NSTIFFCompressionCCITTFAX3 I
couldn't give it a full color tiff (didn't make sense to me, but if that is
how it works, so be it). I finally got some code working that converts the
image to a greyscale tiff, and then I try and convert it to
NSTIFFCompressionCCITTFAX3 type, but no luck.

I really need this to work (so I can stop using ghostscript to convert my
files), so I will lay out my new code one more time, in hopes that someone
can figure this out. The compression type is supported (I don't get an error
like if I try and use the JPEG one), so it should work.

- (IBAction)convert:(id)sender
{
NSImage *theImage, *bwImage;
NSData *theData, *myData;
NSString *path=[pathTextField stringValue];
NSBitmapImageRep *myTIFFasBitMap;
NSDictionary *myDict;

path=[path stringByExpandingTildeInPath];
NSLog(@"converting file at: %@", path);

theImage=[[NSImage alloc] initWithContentsOfFile: path];

if (theImage) {
NSLog(@"file loaded.");
bwImage=[self filterImage: theImage];

myData = [bwImage TIFFRepresentation];
myDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"NSTIFFCompressionCCITTFAX3", @"NSImageCompressionMethod",nil];

myTIFFasBitMap = [[NSBitmapImageRep alloc] initWithData:myData];
theData = [myTIFFasBitMap representationUsingType:NSTIFFFileType
properties:myDict];

if ([theData writeToFile:@"/Users/kupan787/Desktop/output.tiff"
atomically:YES])
{
NSLog(@"file written out as TIFF");
} else {
NSLog(@"file write failed.");
}
} else {
NSLog(@"could not open file.");
}
[theImage release];
}


- (NSImage *)filterImage:(NSImage *)srcImage
{
NSBitmapImageRep *srcImageRep = [NSBitmapImageRep
imageRepWithData:[srcImage TIFFRepresentation]];

int w = [srcImageRep pixelsWide];
int h = [srcImageRep pixelsHigh];
int x, y;
int ao = [srcImageRep hasAlpha] ? 1 : 0;

NSImage *destImage = [[NSImage alloc] initWithSize:NSMakeSize(w,h)];

NSBitmapImageRep *destImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:w
pixelsHigh:h
bitsPerSample:8
samplesPerPixel:1
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedBlackColorSpace
bytesPerRow:NULL
bitsPerPixel:NULL] autorelease];

unsigned char *srcData = [srcImageRep bitmapData];
unsigned char *destData = [destImageRep bitmapData];
unsigned char *p1, *p2;
int n = [srcImageRep bitsPerPixel] / 8;

for ( y = 0; y < h; y++ ) {
for ( x = 0; x < w; x++ ) {
p1 = srcData + n * (y * w + x);
p2 = destData + y * w + x;

*p2 = (char)rint((*(p1 + ao) + *(p1 + 1 + ao) + *(p1 + 2 + ao))
/ 3);
}
}

[destImage addRepresentation:destImageRep];
return destImage;
}

Thanks,
Ben
_______________________________________________
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.

  • Follow-Ups:
    • Re: Final round with NSTIFFCompressionCCITTFAX3
      • From: Cameron Hayne <email@hidden>
References: 
 >Re: iso-8859-1 over UTF8 (was: Re: cString deprecated!) (From: "Clark S. Cox III" <email@hidden>)

  • Prev by Date: Re: real authority on what needs to be released
  • Next by Date: Re: Mail API
  • Previous by thread: Re: iso-8859-1 over UTF8 (was: Re: cString deprecated!)
  • Next by thread: Re: Final round with NSTIFFCompressionCCITTFAX3
  • Index(es):
    • Date
    • Thread