Re: exporting image files to disk using CGImageDestination
Re: exporting image files to disk using CGImageDestination
- Subject: Re: exporting image files to disk using CGImageDestination
- From: Kevin Meaney <email@hidden>
- Date: Tue, 25 Feb 2014 13:25:02 +0000
On 24 Feb 2014, at 18:59, Kevin Meaney <email@hidden> wrote:
> On 24 Feb 2014, at 18:40, David Duncan <email@hidden> wrote:
>>
>> How are you generating these images? Specifically, the CGImageRef you pass to CGImageDestination and the pixels backing it.
>>
>> PNG does not store premultiplied image data, so the pixels will be un-multiplied for storage if necessary. TIFF does not seem to have a position on which form the data takes, but decoders may expect pre-multiplied since thats what Photoshop writes.
>>
>> If your starting image is not pre-multiplied alpha, then the TIFF may be written the same way but decoded with a pre-multiplied assumption, which would make the image look horrible.
>
> The image is created from a CGContext RGBA, 8 bits per component. sRGB profile with a bitmap info option of kCGImageAlphaPremultipliedLast. As far as I can tell you can't create a CGContext with an alpha channel that isn't pre-multiplied. I tried creating as few different types with no success.
>
> In my coreimage filter, I unpremultiply the color values before calculating the new alpha values which will then be multiplied against the old alpha and then I pre-multiply again before the coreimage kernel filter returns.
I've looked for alternatives with this a little more. I was hoping I might be able to create a CIContext from a vImage buffer so that I could provide a buffer that didn't hint it was pre-multiplied. But there is no option to do that.
I took the generated tiff file and saved it as a png file. The rendering of the png file was considerably better than that for the tiff file where alpha was neither 0.0 or 1.0. Rendering was better but it was also clear that something had gone wrong with the (pre)multiply calculations going via the generation of the tiff file. Since the areas of the image where alpha was somewhere between 0 and 1, but not at either end the image which had been created from the tiff file was brighter in those areas.
It is almost like when creating the tiff file there is a unpremul step (which from what's been implied on this thread is correct), but when coming to render the image from the tiff file it is assumed the image has been pre-multiplied. I'm only using Preview to view the images, and I'm wondering if I need another app to view the images in. But at the same time I'd like images I generate to look good in Preview.
Kevin
_______________________________________________
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