33- (void) setRed:(
float)r green:(
float)g blue:(
float)b alpha:(
float)a
33- (void) setRed:(
float)r green:(
float)g blue:(
float)b alpha:(
float)a {
…}
42- (void) setHue:(
float)h saturation:(
float)s brightness:(
float)b alpha:(
float)a
53 if (h < 0.0) h += 360.0f;
59 q = b * (1.0f - (s * f));
60 t = b * (1.0f - (s * (1.0f - f)));
42- (void) setHue:(
float)h saturation:(
float)s brightness:(
float)b alpha:(
float)a {
…}
80- (id) copyWithZone:(NSZone *)zone
80- (id) copyWithZone:(NSZone *)zone {
…}
87+ (
OOColor *) colorWithHue:(
float)hue saturation:(
float)saturation brightness:(
float)brightness alpha:(
float)alpha
91 return [
result autorelease];
87+ (
OOColor *) colorWithHue:(
float)hue saturation:(
float)saturation brightness:(
float)brightness alpha:(
float)alpha {
…}
95+ (
OOColor *) colorWithRed:(
float)red green:(
float)green blue:(
float)blue alpha:(
float)alpha
99 return [
result autorelease];
95+ (
OOColor *) colorWithRed:(
float)red green:(
float)green blue:(
float)blue alpha:(
float)alpha {
…}
103+ (
OOColor *) colorWithWhite:(
float)white alpha:(
float)alpha
103+ (
OOColor *) colorWithWhite:(
float)white alpha:(
float)alpha {
…}
127+ (
OOColor *) colorWithDescription:(
id)description
127+ (
OOColor *) colorWithDescription:(
id)description {
…}
133+ (
OOColor *) colorWithDescription:(
id)description saturationFactor:(
float)factor
135 NSDictionary *dict =
nil;
138 if (description ==
nil)
return nil;
140 if ([description isKindOfClass:[
OOColor class]])
142 result = [[description copy] autorelease];
144 else if ([description isKindOfClass:[NSString
class]])
146 if ([description hasSuffix:
@"Color"])
149 SEL selector = NSSelectorFromString(description);
150 if ([
self respondsToSelector:selector]) result = [
self performSelector:selector];
158 else if ([description isKindOfClass:[NSArray
class]])
160 result = [
self colorFromString:[description componentsJoinedByString:@" "]];
162 else if ([description isKindOfClass:[NSDictionary
class]])
166 if ([dict objectForKey:
@"hue"] !=
nil)
169 float h = [
dict oo_floatForKey:@"hue"];
170 float s = [
dict oo_floatForKey:@"saturation" defaultValue:1.0f];
171 float b = [
dict oo_floatForKey:@"brightness" defaultValue:-1.0f];
172 if (b < 0.0f) b = [
dict oo_floatForKey:@"value" defaultValue:1.0f];
173 float a = [
dict oo_floatForKey:@"alpha" defaultValue:-1.0f];
174 if (a < 0.0f) a = [
dict oo_floatForKey:@"opacity" defaultValue:1.0f];
182 float r = [
dict oo_floatForKey:@"red"];
183 float g = [
dict oo_floatForKey:@"green"];
184 float b = [
dict oo_floatForKey:@"blue"];
185 float a = [
dict oo_floatForKey:@"alpha" defaultValue:-1.0f];
186 if (a < 0.0f) a = [
dict oo_floatForKey:@"opacity" defaultValue:1.0f];
192 if (factor != 1.0f && result !=
nil)
133+ (
OOColor *) colorWithDescription:(
id)description saturationFactor:(
float)factor {
…}
205+ (
OOColor *) brightColorWithDescription:(
id)description
205+ (
OOColor *) brightColorWithDescription:(
id)description {
…}
214+ (
OOColor *) colorFromString:(NSString*) colorFloatString
216 float rgbaValue[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
217 NSScanner *scanner = [
NSScanner scannerWithString:colorFloatString];
221 for (i = 0; i != 4; ++i)
223 if (![scanner scanFloat:&rgbaValue[i]])
226 if (i < 3)
return nil;
229 rgbaValue[3] /= factor;
231 if (1.0f < rgbaValue[i]) factor = 1.0f / 255.0f;
214+ (
OOColor *) colorFromString:(NSString*) colorFloatString {
…}
335 green:OOLerp(rgba[1], rgba1[1], fraction)
336 blue:OOLerp(rgba[2], rgba1[2], fraction)
337 alpha:OOLerp(rgba[3], rgba1[3], fraction)];
339 return [
result autorelease];
345 return [
NSString stringWithFormat:@"%g, %g, %g, %g", rgba[0], rgba[1], rgba[2], rgba[3]];
368- (void) getRed:(
float *)red green:(
float *)green blue:(
float *)blue alpha:(
float *)alpha
370 NSParameterAssert(red != NULL && green != NULL && blue != NULL && alpha != NULL);
368- (void) getRed:(
float *)red green:(
float *)green blue:(
float *)blue alpha:(
float *)alpha {
…}
388 return rgba[0] == 0.0f &&
rgba[1] == 0.0f &&
rgba[2] == 0.0f;
394 return rgba[0] == 1.0f &&
rgba[1] == 1.0f &&
rgba[2] == 1.0f &&
rgba[3] == 1.0f;
403 float delta = maxrgb - minrgb + 0.0001f;
404 float fRed =
rgba[0], fGreen =
rgba[1], fBlue =
rgba[2];
406 if (maxrgb == fRed && fGreen >= fBlue)
408 hue = 60.0f * (fGreen - fBlue) / delta;
410 else if (maxrgb == fRed && fGreen < fBlue)
412 hue = 60.0f * (fGreen - fBlue) / delta + 360.0f;
414 else if (maxrgb == fGreen)
416 hue = 60.0f * (fBlue - fRed) / delta + 120.0f;
418 else if (maxrgb == fBlue)
420 hue = 60.0f * (fRed - fGreen) / delta + 240.0f;
429 return maxrgb == 0.0f ? 0.0f : (1.0f - (minrgb / maxrgb));
438- (void) getHue:(
float *)hue saturation:(
float *)saturation brightness:(
float *)brightness alpha:(
float *)alpha
440 NSParameterAssert(hue != NULL && saturation != NULL && brightness != NULL && alpha != NULL);
444 float fRed =
rgba[0], fGreen =
rgba[1], fBlue =
rgba[2];
445 float maxrgb = fmax(fRed, fmax(fGreen, fBlue));
446 float minrgb = fmin(fRed, fmin(fGreen, fBlue));
447 float delta = maxrgb - minrgb + 0.0001f;
449 if (maxrgb == fRed && fGreen >= fBlue)
451 h = 60.0f * (fGreen - fBlue) / delta;
453 else if (maxrgb == fRed && fGreen < fBlue)
455 h = 60.0f * (fGreen - fBlue) / delta + 360.0f;
457 else if (maxrgb == fGreen)
459 h = 60.0f * (fBlue - fRed) / delta + 120.0f;
461 else if (maxrgb == fBlue)
463 h = 60.0f * (fRed - fGreen) / delta + 240.0f;
466 float s = (maxrgb == 0.0f) ? 0.0f : (1.0f - (minrgb / maxrgb));
470 *brightness = maxrgb;
438- (void) getHue:(
float *)hue saturation:(
float *)saturation brightness:(
float *)brightness alpha:(
float *)alpha {
…}
494 if (
rgba[3] == 1.0f)
return [[
self retain] autorelease];
496 green:rgba[1] * rgba[3]
497 blue:rgba[2] * rgba[3]
502- (
OOColor *) colorWithBrightnessFactor:(
float)factor
505 green:OOClamp_0_1_f(rgba[1] * factor)
506 blue:OOClamp_0_1_f(rgba[2] * factor)
502- (
OOColor *) colorWithBrightnessFactor:(
float)factor {
…}
515 return [
NSArray arrayWithObjects:
540 return [NSString stringWithFormat:@"{%.3g, %.3g, %.3g, %.3g}", components.r, components.g, components.b, components.a];
546 return [NSString stringWithFormat:@"{%i, %.3g, %.3g, %.3g}", (int)components.h, components.s, components.b, components.a];
NSString * OORGBAComponentsDescription(OORGBAComponents components)
NSString * OOHSBAComponentsDescription(OOHSBAComponents components)
NSString * OORGBAComponentsDescription(OORGBAComponents components)
NSString * OOHSBAComponentsDescription(OOHSBAComponents components)
void getHue:saturation:brightness:alpha:(float *hue,[saturation] float *saturation,[brightness] float *brightness,[alpha] float *alpha)
NSString * descriptionComponents()
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
OOColor * colorWithWhite:alpha:(float white,[alpha] float alpha)
void setHue:saturation:brightness:alpha:(float h, [saturation] float s, [brightness] float b, [alpha] float a)
OOColor * darkGrayColor()
NSString * rgbaDescription()
float saturationComponent()
OOColor * colorFromString:(NSString *colorFloatString)
OOColor * colorWithDescription:(id description)
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
NSArray * normalizedArray()
OOColor * colorWithHue:saturation:brightness:alpha:(float hue,[saturation] float saturation,[brightness] float brightness,[alpha] float alpha)
void setRed:green:blue:alpha:(float r, [green] float g, [blue] float b, [alpha] float a)
OOColor * premultipliedColor()
NSString * hsbaDescription()
OOHSBAComponents hsbaComponents()
OOColor * lightGrayColor()
OORGBAComponents rgbaComponents()
float brightnessComponent()
OOColor * colorWithDescription:saturationFactor:(id description,[saturationFactor] float factor)