I've been struggling with this issue for a long time, and have not found any 
working/good example on the net or in any chat.. 

What I REALLY want to achieve (this can be poor performance): take a JPG (or 
PNG is great too) file on disk, result with a float *bytes; array holding the 
floating point precision data from the JPG as R G B A format. Anything that 
achieves that is a solution here - my current route is to use CIImage just 
because loading up JPG is so easy with it.

What I've been trying: Get the image in to CIImage because it's so convenient.. 
creating a CGContext, because I should be able to pull the bytes from a 
CGContext easily since I define data for it, then trying to draw the CIImage in 
to it.

Here's my example code (uninterested in memory leaks at this point):

// successfully gets my image
CIImage *image = [CIImage alloc initWithContentsOfURL:NSURL 
fileURLWithPath:in_jpg1];

// I'm working with 512 x 512 exclusively at the moment, I can fix this later
NSUInteger width = 512;
NSUInteger height = 512;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

// this is the data where I want my bytes to reside at the end. I create the 
CGContext with it
// * 16 because *4bytes per component, *4 components rgba
float *rawData = malloc(height * width * 16);
// same as what I said above really
NSUInteger bytesPerPixel = 16;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 32;

// create a CG context, using my float array to hold it's data. Therefore, IF I 
draw to it
// correctly, I should get rawData filled with the bitmap float data of my 
CIImage
CGContextRef context = CGBitmapContextCreate(rawData, width, height, 
bitsPerComponent, bytesPerRow, colorSpace, kCGBitmapFloatComponents);

CGColorSpaceRelease(colorSpace);

// draw the CIImage to the 'context'... this is probably the line that's wrong
[image drawInRect:NSMakeRect(0, 0, width, height) fromRect:[self bounds] 
operation:NSCompositeSourceIn fraction 1.0];


The result of this code, if I watch rawData in a memory dump, is that I malloc 
the array and it becomes all 0's. At no point after that do any of the bytes 
become non-zero.. the JPG is a red to white gradient so I would of course 
expect to see components ranging from like ffffffff 0 0 ffffffff, to ffffffff 
ffffffff fffffff ffffffff

Any help is greatly appreciated. This seems to be a huge stumbling block for 
people.. 

Robert_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to