API  0.9.7
 All Classes Files Functions Variables Macros Groups Pages
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 
31 
32 /*
33  @global
34  @group CGColorSpace
35 */
36 kCGColorSpaceGenericGray = "CGColorSpaceGenericGray";
37 /*
38  @global
39  @group CGColorSpace
40 */
41 kCGColorSpaceGenericRGB = "CGColorSpaceGenericRGB";
42 /*
43  @global
44  @group CGColorSpace
45 */
46 kCGColorSpaceGenericCMYK = "CGColorSpaceGenericCMYK";
47 /*
48  @global
49  @group CGColorSpace
50 */
51 kCGColorSpaceGenericRGBLinear = "CGColorSpaceGenericRGBLinear";
52 /*
53  @global
54  @group CGColorSpace
55 */
56 kCGColorSpaceGenericRGBHDR = "CGColorSpaceGenericRGBHDR";
57 /*
58  @global
59  @group CGColorSpace
60 */
61 kCGColorSpaceAdobeRGB1998 = "CGColorSpaceAdobeRGB1998";
62 /*
63  @global
64  @group CGColorSpace
65 */
66 kCGColorSpaceSRGB = "CGColorSpaceSRGB";
67 
68 var _CGNamedColorSpaces = {};
69 
70 #define _CGColorSpaceCreateWithModel(aModel, aComponentCount, aBaseColorSpace) \
71  { model:aModel, count:aComponentCount, base:aBaseColorSpace }
72 
73 function CGColorSpaceCreateCalibratedGray(aWhitePoint, aBlackPoint, gamma)
74 {
75  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
76 }
77 
78 function CGColorSpaceCreateCalibratedRGB(aWhitePoint, aBlackPoint, gamma)
79 {
80  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 1, NULL);
81 }
82 
83 function CGColorSpaceCreateICCBased(aComponentCount, range, profile, alternate)
84 {
85  // FIXME: Do we need to support this?
86  return NULL;
87 }
88 
89 function CGColorSpaceCreateLab(aWhitePoint, aBlackPoint, aRange)
90 {
91  // FIXME: Do we need to support this?
92  return NULL;
93 }
94 
96 {
98 }
99 
101 {
103 }
104 
106 {
108 }
109 
111 {
112  // FIXME: This for sure we don't need.
113  return NULL;
114 }
115 
116 function CGColorSpaceCreateIndexed(aBaseColorSpace, lastIndex, colorTable)
117 {
118  // FIXME: Do we need to support this?
119  return NULL;
120 }
121 
122 function CGColorSpaceCreatePattern(aBaseColorSpace)
123 {
124  if (aBaseColorSpace)
125  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, aBaseColorSpace.count, aBaseColorSpace);
126 
127  return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, 0, NULL);
128 }
129 
131 {
132  var colorSpace = _CGNamedColorSpaces[aName];
133 
134  if (colorSpace)
135  return colorSpace;
136 
137  switch (aName)
138  {
140  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
141 
143  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
144 
146  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelCMYK, 4, NULL);
147 
149  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
150 
152  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
153 
155  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
156 
157  case kCGColorSpaceSRGB:
158  return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
159  }
160 
161  return NULL;
162 }
163 
164 // Getting Information About Color Spaces
165 
166 function CGColorSpaceCopyICCProfile(aColorSpace)
167 {
168  return NULL;
169 }
170 
172 {
173  return aColorSpace.count;
174 }
175 
176 function CGColorSpaceGetTypeID(aColorSpace)
177 {
178 }
179 
180 function CGColorSpaceGetModel(aColorSpace)
181 {
182  return aColorSpace.model;
183 }
184 
185 function CGColorSpaceGetBaseColorSpace(aColorSpace)
186 {
187 }
188 
189 function CGColorSpaceGetColorTableCount(aColorSpace)
190 {
191 }
192 
193 function CGColorSpaceGetColorTable(aColorSpace)
194 {
195 }
196 
197 // Retaining and Releasing Color Spaces
198 
199 function CGColorSpaceRelease(aColorSpace)
200 {
201 }
202 
203 function CGColorSpaceRetain(aColorSpace)
204 {
205  return aColorSpace;
206 }
207 
208 // FIXME: We should refer to some default values.
209 #define STANDARDIZE(components, index, minimum, maximum, multiplier) \
210 { \
211  if (index > components.length) \
212  { \
213  components[index] = maximum; \
214  return; \
215  } \
216 \
217  var component = components[index]; \
218  \
219  if (component < minimum) \
220  components[index] = minimum; \
221  else if (component > maximum) \
222  components[index] = maximum; \
223  else \
224  components[index] = ROUND(component * multiplier) / multiplier; \
225 }
226 
227 function CGColorSpaceStandardizeComponents(aColorSpace, components)
228 {
229  var count = aColorSpace.count;
230 
231  // Standardize the alpha value. We allow the alpha value to have a
232  // higher precision than other components since it is not ultimately
233  // bound to 256 bits like RGB.
234  STANDARDIZE(components, count, 0, 1, 1000);
235 
236  if (aColorSpace.base)
237  aColorSpace = aColorSpace.base;
238 
239  switch (aColorSpace.model)
240  {
245  while (count--)
246  STANDARDIZE(components, count, 0, 1, 255);
247  break;
248 
249  // We don't currently support these color spaces.
253  break;
254  }
255 }