Getting float bitmap data to and from CIImage
Getting float bitmap data to and from CIImage
- Subject: Getting float bitmap data to and from CIImage
- From: Rodney Kennedy <email@hidden>
- Date: Wed, 22 Mar 2006 19:55:38 +1100
I'm having a problem with exchanging between float bitmap data
(kCIFormatRGBAf) and CIImage. I've poured over the previous related
posts and my problem remains. My code does convert in both
directions but there appears to be a subtle nonlinear gamma like
distortion introduced and there is quantization which reduces the
dynamic range of the images. There appears to be no problem with
doing the same with 8 bit data.
More Details:
In my application I can take any image and use it to define a CIImage
(yes I know it is a recipe and not an image) and put it through a
CIFilter pipeline. When the pipeline does nothing (e.g., a blur of
zero radius) the output CIImage when displayed in a NSImageView looks
perfect, i.e., looks like the original as say Preview would display
it. When exported to an 8bit TIFF is is also perfect. When I try to
export to a 16bit TIFF is where I notice a problem. First I export
to a float bitmap and from there I easily generate 16bit samples to
preserve precision. It is in the float bitmap I notice there is a
problem. The rendered float data shows a mild distortion consistent
with a non-unity gamma plus the values appear to be quantized which
suggests that perhaps the precision is limited to 8 bits somewhere.
When displayed the image is mildly more contrasty the the original.
I assume this may be a color space problem.
Can anyone see what the problem might be in the following code?
Rod
- (NSBitmapImageRep *)RGBAFloatBitmapImageRepWithCImage:(CIImage *)
ciImage;
- (CIImage *)cIImageWithRGBAFloatBitmapImageRep:(NSBitmapImageRep *)rep;
- (NSBitmapImageRep *)RGBAFloatBitmapImageRepWithCImage:(CIImage *)
ciImage
{
int pWide = [ciImage extent].size.width;
int pHigh = [ciImage extent].size.height;
int bitmapBytesPerRow = (pWide * sizeof(float) * 4); ///// float RGBA
///// prepare RGBFloatBitmapImageRep
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil pixelsWide:pWide pixelsHigh:pHigh
bitsPerSample:8 * sizeof(float) samplesPerPixel:4 hasAlpha:YES
isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:NSFloatingPointSamplesBitmapFormat
bytesPerRow:bitmapBytesPerRow bitsPerPixel:0];
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName
( kCGColorSpaceGenericRGB );
CGContextRef context = CGBitmapContextCreate( [rep bitmapData],
pWide, pHigh, 8 * sizeof(float), bitmapBytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents );
CIContext *ciContext = [CIContext contextWithCGContext:context
options:nil];
[ciContext drawImage:ciImage atPoint:CGPointZero fromRect:[ciImage
extent]];
CGContextRelease( context );
CGColorSpaceRelease( colorSpace );
return [rep autorelease];
}
- (CIImage *)cIImageWithRGBAFloatBitmapImageRep:(NSBitmapImageRep *)rep
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName
( kCGColorSpaceGenericRGB );
NSData *bitmapData = [NSData dataWithBytes:[rep bitmapData] length:
[rep bytesPerRow] * [rep pixelsHigh]];
CIImage *ciImage = [CIImage imageWithBitmapData:bitmapData
bytesPerRow:[rep bytesPerRow] size:CGSizeMake( [rep pixelsWide], [rep
pixelsHigh] ) format:kCIFormatRGBAf colorSpace:colorSpace];
CGColorSpaceRelease( colorSpace );
return ciImage;
}
_______________________________________________
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