If I'm writing drawing code in Core Graphics on Mac OS X or iPhone OS, I can set the active fill color to red by calling:
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0); // RGB(1,0,0)
If I want 50% gray, I could call:
CGContextSetRGBFillColor(context, 0.5, 0.5, 0.5, 1.0); // RGB(0.5,0.5,0.5)
But for shades of gray it's tempting to make a shorter line and call:
CGContextSetGrayFillColor(context, 0.5, 1.0);
However, this function is NOT simply calling the RGB method with the intensity value copied three times; instead it is changing the context's color space from DeviceRGB to DeviceGray. The next call to an RGB method will switch it back.
I'm curious to know:
- What's the penalty for switching color spaces?
- Is there a penalty for drawing when your context's color space doesn't match your device's native color space? (i.e., drawing in DeviceGray versus DeviceRGB)
I'm asking out of technical curiosity, not a desire to prematurely optimize, so please keep your admonitions to a minimum, please.