-
Notifications
You must be signed in to change notification settings - Fork 333
/
CGColorSpace.j
240 lines (204 loc) · 6.66 KB
/
CGColorSpace.j
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* CGColorSpace.j
* AppKit
*
* Created by Francisco Tolmasky.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
kCGColorSpaceModelUnknown = -1;
kCGColorSpaceModelMonochrome = 0;
kCGColorSpaceModelRGB = 1;
kCGColorSpaceModelCMYK = 2;
kCGColorSpaceModelLab = 3;
kCGColorSpaceModelDeviceN = 4;
kCGColorSpaceModelIndexed = 5;
kCGColorSpaceModelPattern = 6;
/*
@global
@group CGColorSpace
*/
kCGColorSpaceGenericGray = "CGColorSpaceGenericGray";
/*
@global
@group CGColorSpace
*/
kCGColorSpaceGenericRGB = "CGColorSpaceGenericRGB";
/*
@global
@group CGColorSpace
*/
kCGColorSpaceGenericCMYK = "CGColorSpaceGenericCMYK";
/*
@global
@group CGColorSpace
*/
kCGColorSpaceGenericRGBLinear = "CGColorSpaceGenericRGBLinear";
/*
@global
@group CGColorSpace
*/
kCGColorSpaceGenericRGBHDR = "CGColorSpaceGenericRGBHDR";
/*
@global
@group CGColorSpace
*/
kCGColorSpaceAdobeRGB1998 = "CGColorSpaceAdobeRGB1998";
/*
@global
@group CGColorSpace
*/
kCGColorSpaceSRGB = "CGColorSpaceSRGB";
var _CGNamedColorSpaces = {};
#define _CGColorSpaceCreateWithModel(aModel, aComponentCount, aBaseColorSpace) \
{ model:aModel, count:aComponentCount, base:aBaseColorSpace }
function CGColorSpaceCreateCalibratedGray(aWhitePoint, aBlackPoint, gamma)
{
return _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
}
function CGColorSpaceCreateCalibratedRGB(aWhitePoint, aBlackPoint, gamma)
{
return _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 1, NULL);
}
function CGColorSpaceCreateICCBased(aComponentCount, range, profile, alternate)
{
// FIXME: Do we need to support this?
return NULL;
}
function CGColorSpaceCreateLab(aWhitePoint, aBlackPoint, aRange)
{
// FIXME: Do we need to support this?
return NULL;
}
function CGColorSpaceCreateDeviceCMYK()
{
return CGColorSpaceCreateWithName(kCGColorSpaceGenericCMYK);
}
function CGColorSpaceCreateDeviceGray()
{
return CGColorSpaceCreateWithName(kCGColorSpaceGenericGray);
}
function CGColorSpaceCreateDeviceRGB()
{
return CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
}
function CGColorSpaceCreateWithPlatformColorSpace()
{
// FIXME: This for sure we don't need.
return NULL;
}
function CGColorSpaceCreateIndexed(aBaseColorSpace, lastIndex, colorTable)
{
// FIXME: Do we need to support this?
return NULL;
}
function CGColorSpaceCreatePattern(aBaseColorSpace)
{
if (aBaseColorSpace)
return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, aBaseColorSpace.count, aBaseColorSpace);
return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, 0, NULL);
}
function CGColorSpaceCreateWithName(aName)
{
var colorSpace = _CGNamedColorSpaces[aName];
if (colorSpace)
return colorSpace;
switch (aName)
{
case kCGColorSpaceGenericGray: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
case kCGColorSpaceGenericRGB: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
case kCGColorSpaceGenericCMYK: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelCMYK, 4, NULL);
case kCGColorSpaceGenericRGBLinear: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
case kCGColorSpaceGenericRGBHDR: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
case kCGColorSpaceAdobeRGB1998: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
case kCGColorSpaceSRGB: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
}
return NULL;
}
// Getting Information About Color Spaces
function CGColorSpaceCopyICCProfile(aColorSpace)
{
return NULL;
}
function CGColorSpaceGetNumberOfComponents(aColorSpace)
{
return aColorSpace.count;
}
function CGColorSpaceGetTypeID(aColorSpace)
{
}
function CGColorSpaceGetModel(aColorSpace)
{
return aColorSpace.model;
}
function CGColorSpaceGetBaseColorSpace(aColorSpace)
{
}
function CGColorSpaceGetColorTableCount(aColorSpace)
{
}
function CGColorSpaceGetColorTable(aColorSpace)
{
}
// Retaining and Releasing Color Spaces
function CGColorSpaceRelease(aColorSpace)
{
}
function CGColorSpaceRetain(aColorSpace)
{
return aColorSpace;
}
// FIXME: We should refer to some default values.
#define STANDARDIZE(components, index, minimum, maximum, multiplier) \
{ \
if (index > components.length) \
{ \
components[index] = maximum; \
return; \
} \
\
var component = components[index]; \
\
if (component < minimum) \
components[index] = minimum; \
else if (component > maximum) \
components[index] = maximum; \
else \
components[index] = ROUND(component * multiplier) / multiplier; \
}
function CGColorSpaceStandardizeComponents(aColorSpace, components)
{
var count = aColorSpace.count;
// Standardize the alpha value. We allow the alpha value to have a
// higher precision than other components since it is not ultimately
// bound to 256 bits like RGB.
STANDARDIZE(components, count, 0, 1, 1000);
if (aColorSpace.base)
aColorSpace = aColorSpace.base;
switch (aColorSpace.model)
{
case kCGColorSpaceModelMonochrome:
case kCGColorSpaceModelRGB:
case kCGColorSpaceModelCMYK:
case kCGColorSpaceModelDeviceN: while (count--)
STANDARDIZE(components, count, 0, 1, 255);
break;
// We don't currently support these color spaces.
case kCGColorSpaceModelIndexed:
case kCGColorSpaceModelLab:
case kCGColorSpaceModelPattern: break;
}
}