
#import "ColorAsRGBADictionary.h"

@implementation NSColor (ColorAsRGBADictionary)

+ (NSColor *)colorFromRGBADictionary:(NSDictionary *)dict
{
    float red, green, blue, alpha;
    
    alpha = [[dict objectForKey:@"Alpha"] floatValue];
    red   = [[dict objectForKey:@"Red"] floatValue];
    green = [[dict objectForKey:@"Green"] floatValue];
    blue  = [[dict objectForKey:@"Blue"] floatValue];

    return
	[NSColor colorWithCalibratedRed:red 
		 green:green
		 blue:blue
		 alpha:alpha];
}

- (NSDictionary *)colorToRGBADictionary
{
    float red, green, blue, alpha;
    [[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace]
	getRed:&red green:&green blue:&blue alpha:&alpha];

    return
	[NSDictionary 
	    dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:alpha], @"Alpha",
	    [NSNumber numberWithFloat:red], @"Red",
	    [NSNumber numberWithFloat:green], @"Green",
	    [NSNumber numberWithFloat:blue], @"Blue", nil];
}


@end
