Re: Interleaved (interwoven) raw images
Re: Interleaved (interwoven) raw images
- Subject: Re: Interleaved (interwoven) raw images
- From: Raphael Sebbe <email@hidden>
- Date: Thu, 16 Aug 2001 21:28:55 +0200
On Thursday, August 16, 2001, at 08:40 PM, Bertrand Mansion wrote:
>
Thank you Raphael but it didn't work.
>
>
> unsigned char *bd = /* points to the first 24 bits pixel */;
>
>
What do you mean by 'points to the first 24 bits pixel' ?
>
I have declared bd like this :
>
>
unsigned char *bd;
>
bd = (void*)calloc(pixWide * pixHigh * pixelBytes,
>
sizeof(unsigned char));
>
>
Seems fine to me. pixelBytes is 3, correct ?
>
Then, I fill an NSData object (imageData) with a file content like this:
>
>
imageData = [NSData dataWithContentsOfFile:pathTosource];
>
[imageData getBytes:bd];
>
This will work, but you allocated twice the required memory (NSData and
malloc). You could do it with :
bd = [imageData bytes];
But, in this case, do not forget to retain imageData, as it is
autoreleased.
>
>
> _tiedRep = rep = [[NSBitmapImageRep alloc]
>
> initWithBitmapDataPlanes:&bd
>
> pixelsWide:width pixelsHigh:height bitsPerSample:8
>
> samplesPerPixel:3
>
> hasAlpha:NO isPlanar:NO
>
> colorSpaceName:NSCalibratedRGBColorSpace
>
> bytesPerRow:width*3 bitsPerPixel:24];
>
>
What is _tiedRep compared to rep ?
Never mind, I just copied and pasted some code of mine... It is an ivar
(instance variable) of one of my classes.
>
Other than that, I use exactly the same arguments for this method in my
>
own
>
code and it still displays 9 small grey images instead of a big colored
>
one.
>
When I use a non-interwoven image instead, it works just fine.
>
According to
>
me, NSBitmapImageRep can handle planar data if we provide it the good
>
data
>
in &db. Which I don't think I am doing...
>
I understand from this it is working for you for non-planar
(interleaved) images. If you still need planar, you should set up 3 char
pointers, one for each plane, and pass it as an array to the
NSBitmapImageRep initializer method :
unsigned char *planes[3]; // an array of 3 unsigned char pointers
plane[0] = (unsigned char*)malloc(pixWide * pixHigh); // red
plane[1] = (unsigned char*)malloc(pixWide * pixHigh); // green
plane[2] = (unsigned char*)malloc(pixWide * pixHigh); // blue
then
rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:plane
pixelsWide:width pixelsHigh:height bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO isPlanar:YES
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:width bitsPerPixel:8];
>
> Remark : be careful with the first arg -> it is a char **, so that it
>
> can handle planar data... For non-planar data, pass it the *address* of
>
> the pointer to the first pixel.
>
>
Excuse my ignorance but what is a 'char **' ?
>
A pointer to a char * (or an array of char *, in this case), and char *
is a pointer to a char. I would suggest that you have a look at a C
book, this will make it easier for you to master ObjC/Cocoa.
Good luck,
Raphael