Re: Setting up an image's alpha using a 256 grayscale image
Re: Setting up an image's alpha using a 256 grayscale image
- Subject: Re: Setting up an image's alpha using a 256 grayscale image
- From: Yojimbo <email@hidden>
- Date: Tue, 4 Mar 2003 21:31:02 -0800
Thanks Jason! I'll give it a shot.
Jim
On Tuesday, Mar 4, 2003, at 19:50 US/Pacific, Jason Harris wrote:
Hi Yojimbo!
You can do something like the following (untested & unoptimized) code
int imagePixelCount; // number of pixels in your image
char *opaqueImageData; // pointer to opaque xRGB data bytes
char *maskImageData; // pointer to mask grayscale data bytes
char *destinationImageData; // pointer to destination ARGB data bytes
int i;
for (i = 0; i < imagePixelCount; ++i) {
long *opaquePixel = &((long *)opaqueImageData)[i];
long *maskPixel = &maskImageData[i];
long *destinationPixel = &((long *)destinationImageData)[i];
*destinationPixel = (*opaquePixel & 0x00FFFFFF) |
((long)*maskPixel <<
24);
}
You'll probably want to premultiply at the same time. The destination
image
is in ARGB format. Convert each channel of each pixel to a float
ranged
between 0 & 1 and multiply the R, G, & B channels by the A channel.
If the original opaque image had an alpha channel, you will also need
to
unpremultiply it before inserting the new alpha and re-premultiplying
it.
Good luck!
Jason Harris
Geekspiff
Yojimbo Tried to Tell Me:
Thanks Jason,
It's the "bitbang 'em into place" part that I'm struggling with. This
is my first attempt at manually premutiplying images based on pixel
values so any details you can share would be very helpful.
I was also pointed to the Transformed Image example project from Apple
as well which I'll go over tonight.
Thanks again,
Jim
On Tuesday, Mar 4, 2003, at 17:36 US/Pacific, Jason Harris wrote:
Basically, get an NSBitmapImageRep for both images, then create a new
NSBitmapImageRep for the destination image. Get the source bytes
using
[NSBitmapImageRep bitmapData] and bitbang 'em into place. You'll
need to
manually premultiply the destination.
If you have no idea what I'm talking about, respond and I'll go into
more
detail.
Jason Harris
Geekspiff
Yojimbo Tried to Tell Me:
Sorry to ask this of the whole list, but does anyone happen to know
of
a good way to go about configuring the alpha channel of an image
using
another 256 greyscale or B&W bitmap image? I can't seem to find
many
pointers except some QuickDraw references. Is there an easier way?
Thanks in advance,
Jim
_______________________________________________
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.