A Cocoa Color Mystery

James Turrell's The Light Inside by Ed Shipol

The Problem

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.

A Solution

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.

Lessons Learned

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.

Jason Bagley

Jason Bagley

Jason is a Senior Software Engineer at Art & Logic. He enjoys exploring far and wide in the digital realm.
Jason Bagley

Latest posts by Jason Bagley (see all)


Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.