API  0.9.6
 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  {
139  case kCGColorSpaceGenericGray: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
140  case kCGColorSpaceGenericRGB: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
141  case kCGColorSpaceGenericCMYK: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelCMYK, 4, NULL);
142  case kCGColorSpaceGenericRGBLinear: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
143  case kCGColorSpaceGenericRGBHDR: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
144  case kCGColorSpaceAdobeRGB1998: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
145  case kCGColorSpaceSRGB: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
146  }
147 
148  return NULL;
149 }
150 
151 // Getting Information About Color Spaces
152 
153 function CGColorSpaceCopyICCProfile(aColorSpace)
154 {
155  return NULL;
156 }
157 
159 {
160  return aColorSpace.count;
161 }
162 
163 function CGColorSpaceGetTypeID(aColorSpace)
164 {
165 }
166 
167 function CGColorSpaceGetModel(aColorSpace)
168 {
169  return aColorSpace.model;
170 }
171 
172 function CGColorSpaceGetBaseColorSpace(aColorSpace)
173 {
174 }
175 
176 function CGColorSpaceGetColorTableCount(aColorSpace)
177 {
178 }
179 
180 function CGColorSpaceGetColorTable(aColorSpace)
181 {
182 }
183 
184 // Retaining and Releasing Color Spaces
185 
186 function CGColorSpaceRelease(aColorSpace)
187 {
188 }
189 
190 function CGColorSpaceRetain(aColorSpace)
191 {
192  return aColorSpace;
193 }
194 
195 // FIXME: We should refer to some default values.
196 #define STANDARDIZE(components, index, minimum, maximum, multiplier) \
197 { \
198  if (index > components.length) \
199  { \
200  components[index] = maximum; \
201  return; \
202  } \
203 \
204  var component = components[index]; \
205  \
206  if (component < minimum) \
207  components[index] = minimum; \
208  else if (component > maximum) \
209  components[index] = maximum; \
210  else \
211  components[index] = ROUND(component * multiplier) / multiplier; \
212 }
213 
214 function CGColorSpaceStandardizeComponents(aColorSpace, components)
215 {
216  var count = aColorSpace.count;
217 
218  // Standardize the alpha value. We allow the alpha value to have a
219  // higher precision than other components since it is not ultimately
220  // bound to 256 bits like RGB.
221  STANDARDIZE(components, count, 0, 1, 1000);
222 
223  if (aColorSpace.base)
224  aColorSpace = aColorSpace.base;
225 
226  switch (aColorSpace.model)
227  {
231  case kCGColorSpaceModelDeviceN: while (count--)
232  STANDARDIZE(components, count, 0, 1, 255);
233  break;
234 
235  // We don't currently support these color spaces.
238  case kCGColorSpaceModelPattern: break;
239  }
240 }