Re: How to handle planar raw images ?
Re: How to handle planar raw images ?
- Subject: Re: How to handle planar raw images ?
- From: "Dennis C. De Mars" <email@hidden>
- Date: Sat, 18 Aug 2001 10:37:56 -0700
on 8/18/01 5:11 AM, Bertrand Mansion at email@hidden wrote:
>
Hello,
>
>
I have asked this before but did not formulate my question right because I
>
was confused about the problem. I am trying to import data from a raw image
>
file into an NSBitmapImageRep object.
>
>
When the image is non-planar (RGB,RGB,RGB...) it works just fine.
>
When the image is planar (RRRR...,GGGG...,BBBB...), it does not work.
>
Instead, I see nine small pictures in my NSView.
>
>
I get all the data from the raw image file using NSData's
>
initWithContentsOfFile method.
>
>
What I would like to know, is what I am supposed to do with it after, in
>
order to pass it to NSBitmapImageRep's initWithBitmapDataPlanes: ?
>
>
What argument am I supposed to pass for planes when I have a planar raw
>
image file, RGB, no alpha, 24bits ?
You need to know the address of the beginning of each plane. Then you put
these pointers into an array and pass the array to initWithBitmapDataPlanes:
So, with your described format it would be something like:
unsigned char* planes[3] = {addressOfRedPlane, addressOfGreenPlane,
addressOfBluePlane};
NSBitmapImageRep* bitmapRep;
bitmapRep = [NSBitmapImageRep initWithBitmapDataPlanes: planes
pixelsWide: width
pixelsHigh: height
bitsPerSample: 8
samplesPerPixel: 3
hasAlpha: NO
isPlanar: YES
colorSpaceName: @"NSDeviceRGBColorSpace"
bytesPerRow: 0 /* let Cocoa figure it out */
bitsPerPixel: 0 /* let Cocoa figure it out */
];
If there is any "dead space" at the end of a row in a plane for alignment
purposes, you'll have to specify something for bytesPerRow.
>
How do I structure my variable or my pointer to make it a valid argument ?
>
>
How do I process the NSData bytes in order to put them into a buffer ? (This
>
is especially not clear as I don't know yet the relations between C
>
variables and Objective-C objects).
NSData already buffers the data, so you don't have to do it yourself as long
as the NSData object sticks around (that is, it isn't released). You can use
the -bytes method to return a pointer to the buffer. If you want to copy the
data into a separate buffer you can use -getBytes to do the copy.
If your raw bitmap data is really the three planes and nothing else, then
the address of the first plane is just the address of the buffer. You'll
have to calculate the other two. If the data consists of exactly the three
planes, then you could do the following (assume your NSData object is called
theData):
unsigned char* redPlane, *greenPlane, *bluePlane;
unsigned int dataLength;
dataLength = [theData length];
redPlane = (unsigned char*)[theData - bytes];
greenPlane = redPlane + (dataLength/3);
bluePlane = greenPlane + (dataLength/3);
planes[0] = redPlane;
planes[1] = greenPlane;
planes[2] = bluePlane;
...and then make your "initWithBitmapDataPlanes" call as outlined above.
>
If someone could help me it would really be great as I have been struggling
>
with that two days now. It looks like everybody uses non-planar images and I
>
am stuck with bloody planar images !!! Thanks
I've only done non-planar images with this myself, so I'm not absolutely
sure the above will work, but it should be pretty close.
- Dennis D.