forked from core-plot/core-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPTColorSpace.m
More file actions
126 lines (98 loc) · 2.64 KB
/
Copy pathCPTColorSpace.m
File metadata and controls
126 lines (98 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#import "CPTColorSpace.h"
#import "NSCoderExtensions.h"
/// @cond
@interface CPTColorSpace()
@property (nonatomic, readwrite, assign) CGColorSpaceRef cgColorSpace;
@end
/// @endcond
#pragma mark -
/** @brief An immutable color space.
*
* An immutable object wrapper class around @ref CGColorSpaceRef.
**/
@implementation CPTColorSpace
/** @property CGColorSpaceRef cgColorSpace
* @brief The @ref CGColorSpaceRef to wrap around.
**/
@synthesize cgColorSpace;
#pragma mark -
#pragma mark Class methods
/** @brief Returns a shared instance of CPTColorSpace initialized with the standard RGB space.
*
* The standard RGB space is created by the
* @if MacOnly @ref CGColorSpaceCreateWithName ( @ref kCGColorSpaceGenericRGB ) function. @endif
* @if iOSOnly @ref CGColorSpaceCreateDeviceRGB() function. @endif
*
* @return A shared CPTColorSpace object initialized with the standard RGB colorspace.
**/
+(CPTColorSpace *)genericRGBSpace
{
static CPTColorSpace *space = nil;
if ( nil == space ) {
CGColorSpaceRef cgSpace = NULL;
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
cgSpace = CGColorSpaceCreateDeviceRGB();
#else
cgSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
#endif
space = [[CPTColorSpace alloc] initWithCGColorSpace:cgSpace];
CGColorSpaceRelease(cgSpace);
}
return space;
}
#pragma mark -
#pragma mark Init/Dealloc
/** @brief Initializes a newly allocated colorspace object with the specified color space.
* This is the designated initializer.
*
* @param colorSpace The color space.
* @return The initialized CPTColorSpace object.
**/
-(id)initWithCGColorSpace:(CGColorSpaceRef)colorSpace
{
if ( (self = [super init]) ) {
CGColorSpaceRetain(colorSpace);
cgColorSpace = colorSpace;
}
return self;
}
/// @cond
-(void)dealloc
{
CGColorSpaceRelease(cgColorSpace);
[super dealloc];
}
-(void)finalize
{
CGColorSpaceRelease(cgColorSpace);
[super finalize];
}
/// @endcond
#pragma mark -
#pragma mark NSCoding Methods
/// @cond
-(void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeCGColorSpace:self.cgColorSpace forKey:@"CPTColorSpace.cgColorSpace"];
}
-(id)initWithCoder:(NSCoder *)coder
{
if ( (self = [super init]) ) {
cgColorSpace = [coder newCGColorSpaceDecodeForKey:@"CPTColorSpace.cgColorSpace"];
}
return self;
}
/// @endcond
#pragma mark -
#pragma mark Accessors
/// @cond
-(void)setCGColorSpace:(CGColorSpaceRef)newSpace
{
if ( newSpace != cgColorSpace ) {
CGColorSpaceRelease(cgColorSpace);
CGColorSpaceRetain(newSpace);
cgColorSpace = newSpace;
}
}
/// @endcond
@end