0

I'm in the unenviable position of working with a huge established codebase for an application that needs to work on both Windows and OSX. A section that I'm currently working on contains some legacy code for an eyedropper/color picker tool. Unfortunately I don't have a lot of experience developing for the Mac, so I'm hoping someone can shed some light on my problem.

The eyedropper colors are slightly wrong in some cases, and I traced the problem to a difference between the expected CGColorSpaceRef which is set by a call to CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) and the actual color space set by the primary display profile. Setting the OS display profile to generic RGB removes the discrepancy, but I want the eyedropper to get a consistent color no matter what the display profile is.

Would retrieving the primary monitor display profile and using that instead of the generic RGB one ensure that the eyedropper tool gets a consistent value? I found the CGColorSpaceCreateWithPlatformColorSpace(...) function, but according to the documentation it has been deprecated since OSX 10.6. What would be the current way to handle this in Quartz?

I feel a little constricted on this, since I have neither the authority or expertise to make major changes such as adding dependencies on additional frameworks.

Ben
  • 163
  • 1
  • 7
  • It seems like the existing call to CGColorSpaceCreateWithName(...) may have been the problem. I replaced it with a call to CGColorSpaceCreateDeviceRGB(), and it seems to get a color space that matches the display profile and doesn't cause incorrect eyedropper colors. There may be risks associated with this change, but if there are I'm not aware of them. – Ben Apr 04 '13 at 20:17

1 Answers1

0

NSColor has this function:

-(void)getRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha

Which will return RGB components converted from device-dependent colorspaces.

Example taken from Radiant Color Picker

CGFloat red, green, blue, a;
NSColor *colorAsRGB = [_color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
[colorAsRGB getRed:&red green:&green blue:&blue alpha:&a];

Relevant links:

NSColor

Working With Colorspaces

SG1
  • 545
  • 3
  • 5
  • Is there a way to do this in C/C++? I only have a cursory knowledge of Objective-C, and the application only uses C/C++. – Ben Apr 04 '13 at 19:15
  • This thread might be what you are looking for: http://stackoverflow.com/questions/4700168/get-rgb-value-from-uicolor-presets – SG1 Apr 04 '13 at 19:27
  • and change the line CGContextSetFillColorWithColor(context, [color CGColor]); to use the function void CGContextSetFillColor ( CGContextRef c, const CGFloat components[] ); instead – SG1 Apr 04 '13 at 19:29
  • I appreciate the time you spent looking at this issue, but I think those links address a somewhat different issue from mine. Fortunately, I found a solution that seems to work and is a smaller change than I expected. – Ben Apr 04 '13 at 20:20