Re: Compositing a CIImage to NSBitmapImage planar problems
Re: Compositing a CIImage to NSBitmapImage planar problems
- Subject: Re: Compositing a CIImage to NSBitmapImage planar problems
- From: Heinrich Giesen <email@hidden>
- Date: Mon, 16 Oct 2006 16:11:04 +0200
Hello,
On 16.10.2006, at 11:15, Jeremy Faller wrote:
bitmapImageRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:outputBitmapSize.width
pixelsHigh:outputBitmapSize.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:YES
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0
bitsPerPixel:0];
The code runs much more quickly, but the [bitmapData] is empty. Any
pointers on what's going on here would be appreciated.
From the docs for graphicsContextWithBitmapImageRep:
(NSGraphicsContext)
This method accepts only single plane NSBitmapImageRep instances.
i.e. planar imageReps with more than one plane cannot be created this
way.
Look at the system console. You should have seen error messages with
something
like: "CGContextSaveGState: invalid context" and
"CGContextDrawImage: invalid context"
and some more messages.
If you have a *meshed* sourceRep with 8 bit per sample and 4 samples
per pixel
and need a *planar* destRep with also 8 bit per sample and 4 samples
per pixel
and if pixelsWide and pixelsHigh are the same it is not difficult to
convert
from meshed to planar. It can be made in a few lines of code.
Here a code snippet without errorchecking or optimizing
(say:pseudocode).
Precondition: You have a valid sourceRep and an empty (but valid)
destRep:
destIndex = 0;
for( row=0; row<[sourceRep pixelsHigh]; row++ ){
buffer = [sourceRep bitmapData] + row*[sourceRep bytesPerRow];
for( pix=0; pix<[sourceRep pixelsWide ]; pix++ ){
destPlane[0][destIndex] = buffer[4*pix]; // red
destPlane[1][destIndex] = buffer[4*pix+1]; // green
destPlane[2][destIndex] = buffer[4*pix+2]; // blue
destPlane[3][destIndex] = buffer[4*pix+3]; // alpha
destIndex+=4;
}
}
Good luck
Heinrich Giesen
--
Heinrich Giesen
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden