Re: render to 128x128 image
Re: render to 128x128 image
- Subject: Re: render to 128x128 image
- From: Jake <email@hidden>
- Date: Mon, 12 Nov 2001 00:27:12 -0500 (EST)
>
> Trying to render some stuff into an Icon with the following code:
>
>
>
> const int width = 128;
>
> const int height = 128;
>
> int i;
>
>
>
> NSImage *buf;
>
> NSBitmapImageRep *bufrep;
>
> unsigned char *d[5];
>
>
Why are you declaring d as an array of five pointers?
According to doc:
- (void)getBitmapDataPlanes:(unsigned char **)
data Provides access to bitmap data for the receiver separated into
planes. data should be an array of five character pointers. If the bitmap
data is in planar configuration, each pointer will be initialized to point
to one of the data planes. If there are less than five planes, the
remaining pointers will be set to NULL. If the bitmap data is in meshed
configuration, only the first pointer will be initialized; the others will
be NULL. Color components in planar configuration are arranged in the
expected order-for example, red before green before blue for RGB color.
All color planes precede the coverage plane.
so, it should return in my situation, 4 arrays, one per channel,
containing the values of that channel for the pixels. sort looks like
d[0] = rrrrrrrrrrrrrrrrrrrrr....
d[1] = ggggggggggggggggggggg....
d[2] = bbbbbbbbbbbbbbbbbbbbb....
d[3] = aaaaaaaaaaaaaaaaaaaaa....
d[4] = NULL
no?
>
>
>
>
> buf = [[NSImage allocWithZone:[self zone]]
>
> initWithSize:NSMakeSize(width, height)];
>
> [buf retain];
>
>
>
> bufrep = [[NSBitmapImageRep alloc]
>
> initWithBitmapDataPlanes:NULL
>
> pixelsWide: width
>
> pixelsHigh: height
>
> bitsPerSample: 8
>
> samplesPerPixel: 4
>
> hasAlpha: YES
>
> isPlanar: YES
>
> colorSpaceName: NSDeviceRGBColorSpace
>
>
You probably want NSCalibratedRGBColorSpace..
>
>
> bytesPerRow: 0
>
> bitsPerPixel: 32];
>
>
>
> [bufrep retain];
>
>
I'm not going to dig through your pointer math, but I was wondering why
>
you're making your bitmap planar?
-- cut from doc ---
planes is an array of character pointers, each of which points to a buffer
containing raw image data. If the data is in planar configuration, each
buffer holds one component-one plane-of the data. Color planes are
arranged in the standard order-for example, red before green before blue
for RGB color. All color planes precede the coverage plane.
If the data is in meshed configuration (isPlanar is NO), only the first
buffer is read.
If planes is NULL or an array of NULL pointers, this method allocates
enough memory to hold the image described by the other arguments. You can
then obtain pointers to this memory (with the getBitmapDataPlanes: or
bitmapData method) and fill in the image data. In this case, the allocated
memory will belong to the object and will be freed when it's freed.
-- end cut from doc ---
So here, i passed NULL in the init and had the call allocate space for me.
There is no pointer math here really. By making the bitmap planar(as the
illustration above) prepares it for the vector code. *grin* that shall
come later. at any rate. given the above allocation, one should be able to
fill the entire 128x128 image red by
for (i = 0; i < 128x128; i++)
{
d[0][i] = 255;
d[1][i] = 0;
d[2][i] = 0;
d[3][i] = 255;
}
no? however, it seem i would need
for (i = 0; i < 256 * 256; i++)
{
d[0][i] = 255;
d[1][i] = 0;
d[2][i] = 0;
d[3][i] = 255;
}
instead. please straighten me out.
thank you.
Jake