I need float resolution bitmap data from a JPG using CIImage or similar helper
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:content-type:subject :date:message-id:to:mime-version:x-mailer; bh=uwEc8AKfZBmGvT/hA7G612rt11Y7SpqKz+c5UcILjBo=; b=Dhay5dGQyhaPyZbWuTVOPds03R71F6ytuPIluPXpGHANEqjqGEHFygOqzylnkrQAzU zxktw0ugKNLbGCdrrxpBpqzsKyfeg45wpI3+lPknuf1abAMeTwnWPM+vsoR1lMDDfYG1 WciDbMX5YkBxcEnfrjxxsdMNFOSXzX0hTCPPY= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:content-type:subject:date:message-id:to:mime-version:x-mailer; b=JBqLDZKu5tUKECUzkfEX0M1lxqJObrYadBlRdWyK5kq6XSAFx2uOCznWY0BAmaKITf Yv22dqFEIXRCHOKjK6XyTT5V5kRoGg/twjvwDR4KlS0XIbAcfzcJTaFtqv70VBgMwSky yDVPa9Q15tVKyTHB9GuCppeq4i/7sNu3/+1fg= 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/site_archiver%40lists.apple... This email sent to site_archiver@lists.apple.com
participants (1)
-
Robert Lorentz