 |
 |
Saving TIFF with no alpha channel
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
What I want to do is save a tiff with no alpha channel. Currently I am doing the following to save my tiff file:
NSImage *theImage;
NSPDFImageRep *myPDF;
[myPDF setCurrentPage:0];
theImage = [[NSImage alloc] init];
[theImage addRepresentation:myPDF];
data = [theImage TIFFRepresentation];
[theImage release];
[data writeToFile:@"/myNewTIFF.tif" atomically:YES];
But it automatically tacks on that alpha channel. I saw setAlpha in NSImageRep, but that sounds like it doesn't actually do what I want. The description says "Informs the receiver whether the image has an alpha component".
Thanks for any help or nudges in the right direction
Ben
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
What happens if you call setAlpha:NO before you write it out to file?
Matt
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
Originally posted by Ghoser777:
What happens if you call setAlpha:NO before you write it out to file?
Matt
Thats part of NSImageRep, so I would need to change my code. My guess, from reading its description, is it wont disable the alpha channel on an existing image, but I will give it a shot.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
It's sort of involved, but you could get an NSBitmapImageRep from your image, create a new NSBitmapImageRep with the same parameters (except three samples per pixel instead of four, and alpha NO), and then copy the data in. As long as you have bitsPerPixel set to 32, it'll just ignore the alpha data.
This is sort of a pain, though - seems like there oughta be an easier way.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
Originally posted by smeger:
It's sort of involved, but you could get an NSBitmapImageRep from your image, create a new NSBitmapImageRep with the same parameters (except three samples per pixel instead of four, and alpha NO), and then copy the data in. As long as you have bitsPerPixel set to 32, it'll just ignore the alpha data.
This is sort of a pain, though - seems like there oughta be an easier way.
Ok, I have some idea, but am not sure where to go from here.
Code:
data = [image1 TIFFRepresentation];
NSBitmapImageRep *srcImageRep = [[NSBitmapImageRep alloc] initWithData:data];
NSBitmapImageRep *destImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:[image1 size].width
pixelsHigh:[image1 size].height
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:NULL
bitsPerPixel:32] autorelease];
image1 contains my loaded image. I am not sure now how to copy the data from srcImageRep into destImageRep. Any more insight would be great.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Originally posted by kupan787:
Ok, I have some idea, but am not sure where to go from here.
Code:
data = [image1 TIFFRepresentation];
NSBitmapImageRep *srcImageRep = [[NSBitmapImageRep alloc] initWithData:data];
NSBitmapImageRep *destImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:[image1 size].width
pixelsHigh:[image1 size].height
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:NULL
bitsPerPixel:32] autorelease];
image1 contains my loaded image. I am not sure now how to copy the data from srcImageRep into destImageRep. Any more insight would be great.
(untested code follows)
Code:
data = [image1 TIFFRepresentation];
NSBitmapImageRep *srcImageRep = [[[NSBitmapImageRep alloc] initWithData:data] autorelease];
NSBitmapImageRep *destImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:[srcImageRep pixelsWide]
pixelsHigh:[srcImageRep pixelsHigh]
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:NULL
bitsPerPixel:32] autorelease];
const int srcBytesPerPlane = [srcImageRep bytesPerPlane];
const int destBytesPerPlane = [destImageRep bytesPerPlane];
NSParameterAssert( srcBytesPerPlane == destBytesPerPlane );
unsigned char *srcBuffer = [srcImageRep bitmapData];
unsigned char *destBuffer = [destImageRep bitmapData];
memmove(destBuffer, srcBuffer, destBytesPerPlane);
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
Originally posted by smeger:
(untested code follows)
Code:
data = [image1 TIFFRepresentation];
NSBitmapImageRep *srcImageRep = [[[NSBitmapImageRep alloc] initWithData:data] autorelease];
NSBitmapImageRep *destImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:[srcImageRep pixelsWide]
pixelsHigh:[srcImageRep pixelsHigh]
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:NULL
bitsPerPixel:32] autorelease];
const int srcBytesPerPlane = [srcImageRep bytesPerPlane];
const int destBytesPerPlane = [destImageRep bytesPerPlane];
NSParameterAssert( srcBytesPerPlane == destBytesPerPlane );
unsigned char *srcBuffer = [srcImageRep bitmapData];
unsigned char *destBuffer = [destImageRep bitmapData];
memmove(destBuffer, srcBuffer, destBytesPerPlane);
Ok using this code, I get an interesting result. The file comes up as a black image (the whole page is black), and when I try and pass the tiff off to something else, I get the following:
/tmp/send/Output.pdf.tif: 0: Bad value for "FillOrder"
So something is not going good...
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|