API  0.9.10
CGColorSpace.j
Go to the documentation of this file.
1 /*
2  * CGColorSpace.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 @typedef CGColorSpace
24 
33 
34 /*
35  @global
36  @group CGColorSpace
37 */
38 kCGColorSpaceGenericGray = "CGColorSpaceGenericGray";
39 /*
40  @global
41  @group CGColorSpace
42 */
43 kCGColorSpaceGenericRGB = "CGColorSpaceGenericRGB";
44 /*
45  @global
46  @group CGColorSpace
47 */
48 kCGColorSpaceGenericCMYK = "CGColorSpaceGenericCMYK";
49 /*
50  @global
51  @group CGColorSpace
52 */
53 kCGColorSpaceGenericRGBLinear = "CGColorSpaceGenericRGBLinear";
54 /*
55  @global
56  @group CGColorSpace
57 */
58 kCGColorSpaceGenericRGBHDR = "CGColorSpaceGenericRGBHDR";
59 /*
60  @global
61  @group CGColorSpace
62 */
63 kCGColorSpaceAdobeRGB1998 = "CGColorSpaceAdobeRGB1998";
64 /*
65  @global
66  @group CGColorSpace
67 */
68 kCGColorSpaceSRGB = "CGColorSpaceSRGB";
69 
70 var _CGNamedColorSpaces = {};
71 
72 #define _CGColorSpaceCreateWithModel(aModel, aComponentCount, aBaseColorSpace) \
73  { model:aModel, count:aComponentCount, base:aBaseColorSpace }
74 
75 function CGColorSpaceCreateCalibratedGray(aWhitePoint, aBlackPoint, gamma)
76 {
77  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
78 }
79 
80 function CGColorSpaceCreateCalibratedRGB(aWhitePoint, aBlackPoint, gamma)
81 {
82  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 1, NULL);
83 }
84 
85 function CGColorSpaceCreateICCBased(aComponentCount, range, profile, alternate)
86 {
87  // FIXME: Do we need to support this?
88  return NULL;
89 }
90 
91 function CGColorSpaceCreateLab(aWhitePoint, aBlackPoint, aRange)
92 {
93  // FIXME: Do we need to support this?
94  return NULL;
95 }
96 
98 {
100 }
101 
103 {
105 }
106 
108 {
110 }
111 
113 {
114  // FIXME: This for sure we don't need.
115  return NULL;
116 }
117 
118 function CGColorSpaceCreateIndexed(aBaseColorSpace, lastIndex, colorTable)
119 {
120  // FIXME: Do we need to support this?
121  return NULL;
122 }
123 
124 function CGColorSpaceCreatePattern(aBaseColorSpace)
125 {
126  if (aBaseColorSpace)
127  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, aBaseColorSpace.count, aBaseColorSpace);
128 
129  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, 0, NULL);
130 }
131 
133 {
134  var colorSpace = _CGNamedColorSpaces[aName];
135 
136  if (colorSpace)
137  return colorSpace;
138 
139  switch (aName)
140  {
142  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
143 
145  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
146 
148  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelCMYK, 4, NULL);
149 
151  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
152 
154  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
155 
157  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
158 
159  case kCGColorSpaceSRGB:
160  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
161  }
162 
163  return NULL;
164 }
165 
166 // Getting Information About Color Spaces
167 
168 function CGColorSpaceCopyICCProfile(aColorSpace)
169 {
170  return NULL;
171 }
172 
174 {
175  return aColorSpace.count;
176 }
177 
178 function CGColorSpaceGetTypeID(aColorSpace)
179 {
180 }
181 
182 function CGColorSpaceGetModel(aColorSpace)
183 {
184  return aColorSpace.model;
185 }
186 
187 function CGColorSpaceGetBaseColorSpace(aColorSpace)
188 {
189 }
190 
191 function CGColorSpaceGetColorTableCount(aColorSpace)
192 {
193 }
194 
195 function CGColorSpaceGetColorTable(aColorSpace)
196 {
197 }
198 
199 // Retaining and Releasing Color Spaces
200 
201 function CGColorSpaceRelease(aColorSpace)
202 {
203 }
204 
205 function CGColorSpaceRetain(aColorSpace)
206 {
207  return aColorSpace;
208 }
209 
210 // FIXME: We should refer to some default values.
211 #define STANDARDIZE(components, index, minimum, maximum, multiplier) \
212 { \
213  if (index > components.length) \
214  { \
215  components[index] = maximum; \
216  return; \
217  } \
218 \
219  var component = components[index]; \
220  \
221  if (component < minimum) \
222  components[index] = minimum; \
223  else if (component > maximum) \
224  components[index] = maximum; \
225  else \
226  components[index] = ROUND(component * multiplier) / multiplier; \
227 }
228 
229 function CGColorSpaceStandardizeComponents(aColorSpace, components)
230 {
231  var count = aColorSpace.count;
232 
233  // Standardize the alpha value. We allow the alpha value to have a
234  // higher precision than other components since it is not ultimately
235  // bound to 256 bits like RGB.
236  STANDARDIZE(components, count, 0, 1, 1000);
237 
238  if (aColorSpace.base)
239  aColorSpace = aColorSpace.base;
240 
241  switch (aColorSpace.model)
242  {
247  while (count--)
248  STANDARDIZE(components, count, 0, 1, 255);
249  break;
250 
251  // We don't currently support these color spaces.
255  break;
256  }
257 }
function CGColorSpaceGetColorTable(aColorSpace)
Definition: CGColorSpace.j:195
function CGColorSpaceCopyICCProfile(aColorSpace)
Definition: CGColorSpace.j:168
function CGColorSpaceCreateDeviceRGB()
Definition: CGColorSpace.j:107
kCGColorSpaceGenericRGBHDR
Definition: CGColorSpace.j:58
kCGColorSpaceModelIndexed
Definition: CGColorSpace.j:31
function CGColorSpaceCreateCalibratedGray(aWhitePoint, aBlackPoint, gamma)
Definition: CGColorSpace.j:75
function CGColorSpaceStandardizeComponents(aColorSpace, components)
Definition: CGColorSpace.j:229
kCGColorSpaceModelCMYK
Definition: CGColorSpace.j:28
function CGColorSpaceGetColorTableCount(aColorSpace)
Definition: CGColorSpace.j:191
#define STANDARDIZE(components, index, minimum, maximum, multiplier)
Definition: CGColorSpace.j:211
kCGColorSpaceGenericRGBLinear
Definition: CGColorSpace.j:53
function CGColorSpaceCreateWithName(aName)
Definition: CGColorSpace.j:132
function CGColorSpaceCreatePattern(aBaseColorSpace)
Definition: CGColorSpace.j:124
function CGColorSpaceCreateLab(aWhitePoint, aBlackPoint, aRange)
Definition: CGColorSpace.j:91
kCGColorSpaceGenericCMYK
Definition: CGColorSpace.j:48
kCGColorSpaceModelRGB
Definition: CGColorSpace.j:27
function CGColorSpaceCreateDeviceGray()
Definition: CGColorSpace.j:102
kCGColorSpaceModelPattern
Definition: CGColorSpace.j:32
function CGColorSpaceGetModel(aColorSpace)
Definition: CGColorSpace.j:182
function CGColorSpaceRelease(aColorSpace)
Definition: CGColorSpace.j:201
function CGColorSpaceGetNumberOfComponents(aColorSpace)
Definition: CGColorSpace.j:173
function CGColorSpaceCreateDeviceCMYK()
Definition: CGColorSpace.j:97
kCGColorSpaceModelLab
Definition: CGColorSpace.j:29
kCGColorSpaceModelDeviceN
Definition: CGColorSpace.j:30
function CGColorSpaceCreateICCBased(aComponentCount, range, profile, alternate)
Definition: CGColorSpace.j:85
kCGColorSpaceGenericRGB
Definition: CGColorSpace.j:43
kCGColorSpaceGenericGray
Definition: CGColorSpace.j:38
kCGColorSpaceSRGB
Definition: CGColorSpace.j:68
function CGColorSpaceCreateIndexed(aBaseColorSpace, lastIndex, colorTable)
Definition: CGColorSpace.j:118
function CGColorSpaceGetTypeID(aColorSpace)
Definition: CGColorSpace.j:178
kCGColorSpaceModelMonochrome
Definition: CGColorSpace.j:26
function CGColorSpaceCreateCalibratedRGB(aWhitePoint, aBlackPoint, gamma)
Definition: CGColorSpace.j:80
function CGColorSpaceGetBaseColorSpace(aColorSpace)
Definition: CGColorSpace.j:187
kCGColorSpaceAdobeRGB1998
Definition: CGColorSpace.j:63
function CGColorSpaceCreateWithPlatformColorSpace()
Definition: CGColorSpace.j:112
CGColorSpace kCGColorSpaceModelUnknown
Definition: CGColorSpace.j:25
function CGColorSpaceRetain(aColorSpace)
Definition: CGColorSpace.j:205