Re: NSImage from Palm Bitmap?
Re: NSImage from Palm Bitmap?
- Subject: Re: NSImage from Palm Bitmap?
- From: Dave Riggle <email@hidden>
- Date: Wed, 3 Sep 2003 14:43:31 -0700
Thanks for everybody's help. Apparently NSBitmapImageRep doesn't do
pixel swizzling. Below is the working code for converting an RGB565
bitmap to an RGBA8888 bitmap.
Dave
-----
// swizzle pixels from RGB565 to RGBA8888
#define SRC_PIXEL UInt16
#define DST_PIXEL UInt32
#define RED(x) (((x) << 16) & 0xF8000000)
#define GREEN(x) (((x) << 13) & 0x00FC0000)
#define BLUE(x) (((x) << 11) & 0x0000F800)
#define ALPHA(x) 0x000000FF
NSImage *PalmBitmapToNSImage(PalmBitmapTypeV2_16 *bmp)
{
register SRC_PIXEL *src;
register DST_PIXEL *dest;
NSImage* image;
NSBitmapImageRep *bitmap;
int row, col, dstRowBytes;
bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: nil
pixelsWide: bmp->width pixelsHigh: bmp->height
bitsPerSample: 8 samplesPerPixel: 4
hasAlpha: YES isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: 0 bitsPerPixel: 32];
src = (SRC_PIXEL *) ((unsigned char *) bmp +
sizeof(PalmBitmapTypeV2_16));
dest = (DST_PIXEL *) [bitmap bitmapData];
dstRowBytes = [bitmap bytesPerRow];
for (row = bmp->height; row > 0; row--)
{
for (col = bmp->width; col > 0; col--)
{
register DST_PIXEL pixel = *src++;
*dest++ = RED(pixel) | GREEN(pixel) | BLUE(pixel) |
ALPHA(pixel);
}
dest = (DST_PIXEL*) ((unsigned char*)dest + dstRowBytes -
bmp->width*sizeof(DST_PIXEL));
}
image = [[NSImage alloc] initWithSize:NSMakeSize(bmp->width,
bmp->height)];
[image addRepresentation:bitmap];
[bitmap release];
return image;
}
_______________________________________________
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.