Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Problem with more than 8-bit images with CGBitmapContextCreate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with more than 8-bit images with CGBitmapContextCreate



Hi,

Basically I need to put an image in a floating point format for
processing. So I use the CGImageSource facility, but a subtle
posterization effect in the shadows made me make deeper research where
it seems that the pixels get into an 8-bit pipeline in some way.

Also I saw the recent discussion about this on this list. I use
kCGImageSourceShouldAllowFloat, so the problem seems different.

In the following snippet of code, I do what I think is the simple to
test : the image color space of the bitmap context is set to the one
from the image to prevent any mapping of values. It is drawn in one
time on a big buffer. The file on input is a RAW file from a 350D (12
bits color). I've also tested with the 16-bit TIFF file coming from
the "ImproveYourImage" dmg from apple, to the same problem. The file
from apple gives 235, 235, 233. The console does not report any error.

I've also tested the following other ways :
- feeding CGImageCreate with a data provider url, which works, the
bits per component shows 32 in that case, but the final set of values
is still exactly the same.
- using the Quicktime graphic importer, but it seems to fail to handle raw files

I'm on MacOS X.4.8 PPC.

So I'm stuck, I must be missing something really obvious... but what ?

Many thanks in advance for any advice on this.

Raphael



CFURLRef url_ref = get_file ();

CGDataProviderRef data_provider_ref = CGDataProviderCreateWithURL (url_ref);
CGImageSourceRef image_source_ref =
CGImageSourceCreateWithDataProvider (data_provider_ref, 0);

CFTypeRef keys [] = {kCGImageSourceShouldAllowFloat};
CFTypeRef values [] = {kCFBooleanTrue};

CFDictionaryRef dict_ref = CFDictionaryCreate (0, keys, values, 1, 0, 0);

CGImageRef image_ref = CGImageSourceCreateImageAtIndex
(image_source_ref, 0, dict_ref);

int width = CGImageGetWidth (image_ref);
int height = CGImageGetHeight (image_ref);

// it says 16
printf ("bits per component = %d\n", CGImageGetBitsPerComponent (image_ref));

std::vector <float> buffer (width * height * 4);

CGContextRef context_ref = CGBitmapContextCreate (
	&buffer [0],
	width,
	height,
	32,
	width * 16,
	CGImageGetColorSpace (image_ref),
	kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents|kCGBitmapByteOrder32Host
);

CGRect dest_rect = CGRectMake (0, 0, width, height);
CGContextDrawImage (context_ref, dest_rect, image_ref);

std::set <float> red_float_set;
std::set <float> green_float_set;
std::set <float> blue_float_set;

for (int i = 0 ; i < buffer.size () / 4 ; ++i)
{
	float red = buffer [i * 4];
	float green = buffer [i * 4 + 1];
	float blue = buffer [i * 4 + 2];

	red_float_set.insert (red);
	green_float_set.insert (green);
	blue_float_set.insert (blue);
}

// will always be less than 256
printf ("red nbr = %d\n", red_float_set.size ());
printf ("green nbr = %d\n", green_float_set.size ());
printf ("blue nbr = %d\n", blue_float_set.size ());

<<<
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.