A project for an image processing Cocoa app last year ran into some difficulty when images produced had small color differences compared to the results of previous versions. We had changed most of the infrastructure as we ported this former Photoshop plug-in. We had to consider many systems as possible culprits. Did the colors shift on loading? During format conversion? During processing? Converting for display? Or when saved to disk? Did the format of the image file matter? Did Photoshop do something Cocoa wasn’t doing? It was a slog, but that last one proved to be the right question.
We finally looked at color spaces. The app did not create its result images with the same color space as the originals causing the small color shifts seen. It also discarded the original color space when transforming to an intermediate format used for processing. This is something which Photoshop would take care of in the earlier versions of this app, so well that we didn’t immediately think of it. We just needed to grab the color space when loading the original and apply it to the result and any intermediate versions of the image which might wind up as the final result.
Cocoa and Quartz have some quirks when handling color spaces, but they are fully supported. It just requires a little diligence, and, ultimately, is pretty simple. I created a Playground to demonstrate some of the ways of interacting with an image’s color space. Let me know if you have better ways.
Photo by Ed Shipol via Flickr. Some rights reserved.
Spot the Vulnerability: Loops and Terminating Conditions In memory-unsafe languages like C, special care must be taken when copying untrusted data, particularly when copying it to another buffer. In this post, we\'ll spot and mitigate a past vulnerability in Linux\'s...