Re: Save tiff with no alpha
Re: Save tiff with no alpha
- Subject: Re: Save tiff with no alpha
- From: Marco Binder <email@hidden>
- Date: Mon, 11 Nov 2002 13:00:43 +0100
Well, as fas as I can see, your problem is the following: you
srcImageRep is at 4 samples per pixel (RGB+alpha), your destImageRep
only 3 SPP ! So you cannot simply use scrBuffer as destBuffer! You d
have to manually put the R, G and B data into the proper positions in
destBuffer, ignoring the alpha samples in srcBuffer. Not trivial for
bitsPerPixel != 8.
Your NSAssertion is ok, but if you asked for ([scrImageRep
samplesPerPixel] == [destImageRep samplesPerPixel]) it would have told
you, its not possible.
Have you tried to add your destImageRep to an new NSImage, then call
lockFocusOnRepresentation: on your image and simply draw your other
image or imageRep into that one? Havent tried, but might work, I guess.
marco
Am Montag, 11.11.02 um 03:52 Uhr schrieb Ben Mackin:
What I want to do is save a tiff with no alpha channel. I was told the
following:
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.
So I did the following:
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). That is not what I want, so
something
is not going good.
Is this the correct way of doing this? Is there an easier way?
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.
--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.