Re: Fw: NSBitmapImageRep bitmapData and 16 bits per sample
Re: Fw: NSBitmapImageRep bitmapData and 16 bits per sample
- Subject: Re: Fw: NSBitmapImageRep bitmapData and 16 bits per sample
- From: "Geraldine Joffre" <email@hidden>
- Date: Mon, 9 Jun 2003 10:41:02 +0200
Thanks for the idea. I've tried the method you suggested, using the NSData of the image file
directly instead of [NSImage TIFFRepresentation] but it did not change the result because of
this declaration:
unsigned char *destData = [destImageRep bitmapData];
As you correctly pointed out in your first answer, I should not care about the type. If I use
instead
unsigned short *destData = [destImageRep bitmapData];
the compiler issues a warning but then the app produces a "real" 16-bits image.
Thanks for your help. I'm happy I can stick to Cocoa for manipulating 16-bits images.
---------- Original Message -----------
From: Marco Binder <email@hidden>
To: "Geraldine Joffre" <email@hidden>
Sent: Sun, 8 Jun 2003 20:04:02 +0200
Subject: Re: Fw: NSBitmapImageRep bitmapData and 16 bits per sample
>
OK, i c. You must not use an NSImage to deal with 16-bit data. The
>
TIFFRepresentation will always return an 8-bit image! Directly
>
instantiate the NSBitmapImageRep with the data: [[NSBitmapImageRep
>
alloc] initWithData: data]
>
>
It will do the setup for you automatically (like samplesprepixel and
>
stuff). You can query for bitsPerPixel to confirm its 16-bit. The resto
>
of your ocde looks good so far. You already did the cast to (unsigned
>
short*) on the bitmap pointer, so that should be fine too (if short is
>
16-bit!).
>
>
I guess the initialization part was the only hurdle!
>
>
Good luck!
>
>
Marco
>
>
Am Sonntag, 08.06.03, um 19:40 Uhr (Europe/Berlin) schrieb Geraldine
>
Joffre:
>
>
> Hi Marco,
>
>
>
> Thanks for your answer. Below is my code, simplified in order to focus
>
> on the relevant stuff.
>
> I should mention that when I first load the 16-bits source image,
>
> this image does not show
>
> properly in my view. However, the image returned by the code below
>
> shows as it should.
>
>
>
> I will try tomorrow the bitwise operation you are suggesting and will
>
> let you know the result.
>
>
>
> --------------------
>
> - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
>
> {
>
> NSImage * loadedImage = [[NSImage alloc] initWithData:data];
>
> [..]
>
> }
>
>
>
> [..]
>
> NSBitmapImageRep * srcRep = [NSBitmapImageRep imageRepWithData:
>
>
>
> [loadedImage TIFFRepresentation]]];
>
> int bps = [srcRep bitsPerSample];
>
> NSImage *destImage = [[[NSImage alloc]
>
> initWithSize:NSMakeSize(Imax, Jmax)]
>
> autorelease];
>
> NSBitmapImageRep *destImageRep = [[
>
> [NSBitmapImageRep alloc]
>
> initWithBitmapDataPlanes:nil
>
> pixelsWide:Imax
>
> pixelsHigh:Jmax
>
> bitsPerSample:bps
>
> samplesPerPixel:3
>
> hasAlpha:NO
>
> isPlanar:NO
>
> colorSpaceName:NSCalibratedRGBColorSpace
>
> bytesPerRow:NULL
>
> bitsPerPixel:NULL] autorelease];
>
> unsigned char *destData = [destImageRep bitmapData];
>
> unsigned char *p8;
>
> unsigned short *p16;
>
> int i, j, sommeR, sommeG, sommeB;
>
> int t = 0;
>
>
>
> switch (bps) {
>
>
>
> case 16:
>
> for ( j = 0; j < Jmax; j++ ) {
>
> for ( i = 0; i < Imax; i++ ) {
>
> [..]
>
> p16 = (unsigned short*) [srcRep bitmapData];
>
> [..]
>
> sommeR = sommeR + p16[0];
>
> sommeG = sommeG + p16[1];
>
> sommeB = sommeB + p16[2];
>
> }
>
> destData[0] = (unsigned short)rint(sommeR/Kmax);
>
> destData[2] = (unsigned short)rint(sommeG/Kmax);
>
> destData[4] = (unsigned short)rint(sommeB/Kmax);
>
> t = t + 3;
>
> destData = destData + 6;
>
> }
>
> }
>
> [...]
>
> [destImage addRepresentation:destImageRep];
>
> return destImage;
_______________________________________________
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.