First, remember that three numbers do not describe color, three numbers along with color space. RGB is not a color space, it is what is called a color model. There are many color spaces with the RGB model. So ((1,0,0), sRGB) is different from color ((1,0,0), Adobe RGB). Do you know how string encodings work, where a bunch of bytes is not a string in itself? It is very similar. It also looks like you're asking for problems when you want to look at the values ββof the components, because this is an opportunity to ruin the color space processing.
Sorry, I can not help myself. Anyway, I will answer the question as if your original color was ((1,0,0), Generic RGB).
NSColor *color = [NSColor colorWithCalibratedRed:1 green:0 blue:0 alpha:1]; NSLog(@"hue! %g saturation! %g brightness! %g, [color hueComponent], [color saturationComponent], [color brightnessComponent]);
and on the other hand
NSColor *color = [NSColor colorWithCalibratedHue:h saturation:s brightness:b alpha:1]; NSLog(@"red! %g green! %g blue! %g, [color redComponent], [color greenComponent], [color blueComponent]);
These fooComponent methods do not work with all colors, but only in two specific color spaces, see docs. You already know that you are good if you yourself created the colors using the methods above. If you have a color of unknown origin, you can (try) convert it to a color space in which you can use these component methods with the help of -[NSColor colorUsingColorspaceName:] .
Ken
source share