Created
October 19, 2010 00:08
-
-
Save kylesluder/633335 to your computer and use it in GitHub Desktop.
Version of OQColorGetComponents that goes through a linear RGB color space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OQLinearRGBA OQGetColorComponents(NSColor *c) | |
{ | |
static dispatch_once_t once; | |
static NSColorSpace *linearRGBColorSpace; | |
dispatch_once(&once, ^{ | |
CGColorSpaceRef cgColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear); | |
linearRGBColorSpace = [[NSColorSpace alloc] initWithCGColorSpace:cgColorSpace]; | |
CGColorSpaceRelease(cgColorSpace); | |
OBASSERT_NOTNULL(linearRGBColorSpace); | |
OBASSERT([linearRGBColorSpace colorSpaceModel] == NSRGBColorSpaceModel); | |
OBASSERT([linearRGBColorSpace numberOfColorComponents] == 3); | |
}); | |
OQLinearRGBA l; | |
if (c) { | |
CGFloat components[3]; | |
[[c colorUsingColorSpace:linearRGBColorSpace] getComponents:components]; | |
l.r = components[0]; | |
l.g = components[1]; | |
l.b = components[2]; | |
l.a = [c alphaComponent]; | |
} else | |
memset(&l, 0, sizeof(l)); // Treat nil as clear. | |
return l; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment