NSBitmapImageRep - draws in 32bit, but not in 16bit depth
NSBitmapImageRep - draws in 32bit, but not in 16bit depth
- Subject: NSBitmapImageRep - draws in 32bit, but not in 16bit depth
- From: Jens Bauer <email@hidden>
- Date: Fri, 1 Nov 2002 22:00:10 +0100
Hi all,
Got some code, which allocates a NSBitmapImageRep and draws into this
newly allocated image.
I subclass NSImage and add a few methods for drawing the picture.
I've included 2 methods, the init and an example drawing method:
---8<-----8<-----8<-----
- (id)initWithWidth:(int)width andHeight:(int)height
{
NSSize imageSize;
enum
{
kBitsPerSample = 8,
kSamplesPerPixel = 4,
kBytesPerPixel = 4,
kBitsPerPixel = kBytesPerPixel * 8,
kHasAlpha = YES,
kIsPlanar = NO
};
self = [super init];
if(self)
{
imageSize.width = (float) width;
imageSize.height = (float) height;
bitmapImageRep = [NSBitmapImageRep alloc];
[bitmapImageRep
initWithBitmapDataPlanes:NULL
pixelsWide:width
pixelsHigh:height
bitsPerSample:kBitsPerSample
samplesPerPixel:kSamplesPerPixel
hasAlpha:kHasAlpha
isPlanar:kIsPlanar
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:kBitsPerPixel];
[self addRepresentation:bitmapImageRep];
[self setSize:imageSize];
[self setFlipped:YES];
}
return(self);
}
- (void)orPlotX:(long)xPos y:(long)yPos with:(long)pixel
{
register long x;
register long y;
register long width;
x = xPos;
y = yPos;
if(x >= 0 && y >= 0)
{
width = (int) [self size].width;
if(x < width)
{
if(y < (int) [self size].height)
{
((long *) [bitmapImageRep bitmapData])[y * width + x] |= pixel;
}
}
}
}
--->8----->8----->8-----
Now, I use this line...
[offscreen compositeToPoint:NSZeroPoint fromRect:[self subImageRect]
operation:NSCompositeCopy];
...to place it in the window.
This all works very well if I set my screen depth to 32bit.
If I switch to 16bit *after* the allocation or 8bit for that matter, it
*still* works.
Now... If I start the application in 16bit mode and switch to 32bit
mode, nothing shows up.
I've tried turning alpha on/off, and it seems there's no difference
there.
If I dump the NSBitmapImageRep info after the allocation, I get...
bitsPerPixel:32
bytesPerRow:404
samplesPerPixel:4
bytesPerPlane:32724
isPlanar:0
pixelsWide:101.000000
pixelsHigh:81.000000
which looks right in my eyes.
Can anyone see what I'm doing wrong ?
-Why does the image show up as black in 16bit color depth, when it's
correct in 32bit color depth ?
Love,
Jens
_______________________________________________
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.