NSColor and NSColorPicker Don't Agree

Member
Posts: 64
Joined: 2005.06
Post: #1
Long story short, I'm getting the values of a color taken from an NSColorWell (which uses NSColorPicker), my problem is, NSColor and NSColorPicker don't agree on HSB values.

When I compare the values I get out of NSColor, they are always close, but slightly different from what NSColorPicker displays. If the color is adjusted inside NSColorPicker to reflect the values from NSColor, its a similar but definitely different color or shade.

I'm using the NSCalibratedRGBColorSpace color space, which is what your supposed to use for getting HSB values. Unfortunately, there's just not much information on this sort of problem anywhere on the web or the other MacOS X programming sites.

Add: I should note that the values don't match, only if the values are set using the hsb tab in NSColorPicker, if the colors are set using any other color format and you then switch back to the hsb tab, all the hsb values will match. But the second you touch anything in the hsb tab (even if you don't actually change any values), the values will change and will no longer match.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #2
Err, in the last post, when I said NSColorPicker, I meant NSColorPanel

Anyhow, I've found the problem and "fixed" it to boot. It's good news and bad news, good news is that my code works, the bad news is that Apple's code doesn't.

I started getting really suspicious with the hsb values the NSColorPanel was giving me, they just didn't seem right. So I plugged my values into Photoshop and a few other small graphics programs I have and the results: all the values my code was obtaining was perfectly valid. Plug in the values the NSColorPanel was giving me though, and you get a different color.

That's right, NSColorPanel does not correctly display values for HSB; from what I can see, it looks to be calculating out HSV values and then passing them off as HSB. HSV and HSB while close, are not the same and trying to interchange the numbers will give you weird results. Exactly what I was getting.

Point being, I "fixed" it by removing the HSB Mask from the NSColorPanel. The user can't put in HSB values directly into the NSColorPanel anymore, but even if I let them, they'd just get an incorrect color back. It's no big loss, as my program allows the user to input individual color values in any color format already (and they'll get the RIGHT color back); the NSColorPanel was really just there to make it easier on the user.
Quote this message in a reply
Post Reply