blog

James Turrell's The Light Inside by Ed Shipol

A Cocoa Color Mystery

by

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.
https://github.com/jbagley/ColorSpaceTour
 
Photo by Ed Shipol via Flickr. Some rights reserved.

+ more

Accurate Timing

Accurate Timing

In many tasks we need to do something at given intervals of time. The most obvious ways may not give you the best results. Time? Meh. The most basic tasks that don't have what you might call CPU-scale time requirements can be handled with the usual language and...

read more