FROM : Jens Bauer
DATE : Sat Nov 02 20:44:29 2002
Hi all,
Solved this problem.
I did 2 things wrong.
1: The alpha channel...
[offscreen orPlotX:x y:y with:0x00400000];
...should be...
[offscreen orPlotX:x y:y with:0x004000ff];
2: in the init method, I added...
[self setCacheMode:NSImageCacheNever];
...so now it looks something like this:
[self addRepresentation:bitmapImageRep];
[self setSize:imageSize];
[self setFlipped:YES];
[self setCacheMode:NSImageCacheNever];
}
I hope this will help someone else. =)
Friday 1. Nov 2002 kl. 22:00 skrev Jens Bauer:
> 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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Sat Nov 02 20:44:29 2002
Hi all,
Solved this problem.
I did 2 things wrong.
1: The alpha channel...
[offscreen orPlotX:x y:y with:0x00400000];
...should be...
[offscreen orPlotX:x y:y with:0x004000ff];
2: in the init method, I added...
[self setCacheMode:NSImageCacheNever];
...so now it looks something like this:
[self addRepresentation:bitmapImageRep];
[self setSize:imageSize];
[self setFlipped:YES];
[self setCacheMode:NSImageCacheNever];
}
I hope this will help someone else. =)
Friday 1. Nov 2002 kl. 22:00 skrev Jens Bauer:
> 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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Jens Bauer | Nov 1, 22:00 | |
| Jens Bauer | Nov 2, 20:44 |






Cocoa mail archive

