Re: I need float resolution bitmap data from a JPG using CIImage or similar helper
Re: I need float resolution bitmap data from a JPG using CIImage or similar helper
- Subject: Re: I need float resolution bitmap data from a JPG using CIImage or similar helper
- From: Robert Lorentz <email@hidden>
- Date: Tue, 1 Jun 2010 16:04:44 -0400
On Jun 1, 2010, at 2:16 PM, David Duncan wrote:
> On May 31, 2010, at 5:40 PM, Robert Lorentz wrote:
>
>> 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.
>
> You can use ImageIO to do this, just ask for Floating point precision from your images. This is something that you set with the image source options. Something like this (error checking and mem management missing):
> CGImageSourceRef src = CGImageSourceCreateWithURL(urlToFile, (CFDictionaryRef)[NSDictionary dictionaryWithObject:[NSNumber numberWithBOOL:YES] forKey:(id)kCGImageSourceShouldAllowFloat]);
> CGImageRef img = CGImageSourceCreateAtIndex(src, 0);
>
OK This looks more along the lines of what I want to be doing, as opposed to having to create contexts and draw in to them to get the data, which is awkward and seems very backwards. I follow you as far as creating the CGImageRef -- yes, I see how I pull in an image file and dictate to read data in as float as opposed to byte-length integers....
However, what do I do with img?? I don't see anything in any of the CG* documentation for me getting an array of floats "out of" a CGImageRef. What would the next step be for me to access this data? Or are you simply suggesting this is another way that I can get a JPG in to a data type to then write out to a context?
I'm sorry if I didn't mention this before but, while I've read as deeply as I can in the docs, I am completely new to cocoa and even more new to CG/CI/Quartz/etc
>> // 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);
>
> Are you sure the context was actually created? Specifically for float contexts, you need the kCGImageAlpha[Premultilied | None]Last flag as well.
I guess it's being created; CGBitmapContextCreate documentation states for return value I either get a bitmap context or NULL if it can't be created... I do get a valid pointer returned that I'm able to use. When using KCGImageAlphaPremultipliedLast I get better results .. maybe? Also I'm now using the NSGraphicsContext code suggested by Jens
00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00
^^ is repeated for my entire block of memory, after I draw my image on to the context. Definitely not the data I'm expecting.
..My code now looks like:
[.. load up and display CIImage myImage so I can verify it's correct]
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGBitmapFloatComponents | kCGImageAlphaPremultipliedLast );
NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped: NO];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext: nsContext];
// Should be, and certainly seems to be, drawing to the context created above, with data stored in rawData
[myImage drawInRect:[self bounds] fromRect:[self bounds] operation:NSCompositeSourceIn fraction:1.0];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden