Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Saving TIFF with no alpha channel

Saving TIFF with no alpha channel
Thread Tools
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Nov 7, 2002, 06:06 PM
 
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
Reply With Quote
Nov 7, 2002, 06:15 PM
 
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
Reply With Quote
Nov 8, 2002, 12:22 AM
 
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
Reply With Quote
Nov 8, 2002, 06:36 PM
 
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
Reply With Quote
Nov 9, 2002, 04:33 PM
 
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
Reply With Quote
Nov 9, 2002, 06:53 PM
 
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
Reply With Quote
Nov 9, 2002, 07:34 PM
 
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...
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2