Re: Cocoa, Quartz, Colorspaces and ColorSync
Re: Cocoa, Quartz, Colorspaces and ColorSync
- Subject: Re: Cocoa, Quartz, Colorspaces and ColorSync
- From: Eric Ocean <email@hidden>
- Date: Wed, 29 Sep 2004 09:54:57 -0700
Here's the technote you want (2035): http://developer.apple.com/technotes/tn/tn2035.html. It explains how Quartz and color management work together, and gives some rough definition of the basic concepts.
Second, the Quartz code you want to use is pretty much:
CMProfileRef aProfile;
CMGetDefaultProfileBySpace(cmRGBData, &aProfile);
if ( aProfile == NULL ) return PF_Err_OUT_OF_MEMORY;
colorSpace = CGColorSpaceCreateWithPlatformColorSpace( aProfile );
CMCloseProfile( aProfile );
The CGColorSpaceCreateWithPlatformColorSpace() is how you access ColorSync on the Mac, *not* using the ICC-based functions. It's very confusing. Look up CMGetDefaultProfileBySpace() and you'll see other constants which you can supply. You change these profiles in the ColorSync Utility app.
Also, go to OmniGroup.com and download OmniAppKit. It has some nice ColorSync-relelated code for Cocoa that you can use.
Regards,
Eric Ocean
On Sep 29, 2004, at 8:47 AM, Robert Clair wrote:
Apologies in advance for the multiple post, but the subject spans several areas and information is scarce.
I'm writing a Cocoa graphic arts app and I'm trying to make it at least minimally color managed. (Or, at least, I'm trying to write it so that adding full color management later doesn't require a complete rewrite.)
I've searched the docs, the web and the archives and I haven't found much in the way of information. The docs are outdated - the section of the ColorSync documentation titled "Developing Your ColorSync-Supportive Application" is written in terms of QuickDraw and PICT images. I understand in principle how color management works, it is just the specifics and detailed information on what is really happening that are missing.
For the moment I'm not concerned about reading in files or images with embedded profiles, just with things that I'm creating in Cocoa. I'm not sure what the definition of "device indenpendence" is here. Presently when my app saves a file (in its own file format) the colors are saved by archiving the NSColor objects that were created as "device independent" colors. If I then open the file on a system with a different display is the color on the new screen a ColorSync match for the color on the screen of the first system ? Or should I get the components from the NSColor object, store them and use them to initialize a new NSColor object when opening the file?
The NSColor class method colorWithCalibratedRed:green:blue:alpha: supposedly returns a calibrated or "device independent" color in the NSCalibratedRGBColorSpace. I take this to mean that the "working space" of a Cocoa program using calibrated RGB is NSCalibratedRGBColorSpace. WHAT SPACE IS THIS ???? If it is a real color space, it should have a defined relationship to, say, CIE XYZ. Is it the spaced defined by the profile "Generic RGB Profile" ? (This would be at least consistent, because that's what the Cocoa printing system is putting in the spool pdf.) Is it always the same or does it depend on what is set as the default RGB profile ?
By way of contrast, in CoreGraphics you must first set the colorspace and then the color before you draw. The Quartz function to obtain a Calibrated RGB space, CGColorSpaceCreateCalibratedRGB, requires that you specify a white point, a black point, gammas and a matrix - all the info needed to relate the space to CIE 1931 XYZ. Or
you can use CGColorSpaceCreateICCBased with a specific profile.
My first guess was that code like
NSColor* myCalibratedColor =
[NSColor colorWithCalibratedRed: myRed green: myGreen blue: myBlue alpha: 1.0];
[myCalibratedColor set];
was just sugar coating for something like this:
CGColorspaceRef myColorSpaceRef =
CGColorSpaceCreateCalibratedRGB( myWhitePoint, myBlackPoint, myGammas, myMatrix);
or
CGColorspaceRef myColorSpaceRef =
CGColorSpaceCreateICCBased ( 3, myRangeArray, myProfileProviderRef, myAlternatespaceRef );
followed by
CGContextSetFillColorSpace( myContextRef, myColorSpaceRef );
CGContextSetStrokeColorSpace( myContextRef, myColorSpaceRef );
CGContextSetFillColor( myContextRef, myComponentArray);
CGContextSetStrokeColor( myContextRef, myComponentArray);
for some default data or profile. Then life would be (relatively) simple if someone could tell
me what space the default data corresponds to.
Stepping with the debugger, this seems not to be the case. NSColor is apparently a class cluster and the code creates an instance of a NSCaliabratedRGB color. Since this is internal there is no information available. So, again, the plea: what is happening under the hood here ?
Also: what is ColorSync really doing here when things are drawn to the screen ?? I supply an RGB to to Cocoa via [NSColor colorWithCalibratedRed:green:blue:alpha:], set that color, draw, and some (other) RGB is applied by the graphics card to the inputs of the display. Where and when do the various transformations take place ?
A related question: What exactly is the Digital Color Meter app measuring for RGB ?? It is clearly getting
an RGB somewhere before the display correction is applied - the numbers it reports are the same for a given thing on the screen even when the display profile is changed to wildly different things.
Any information, confirmations or pointers to reliable information would be greatly appreciated.
Bob Clair
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden