API 0.9.5
AppKit/CoreGraphics/CGColorSpace.j
Go to the documentation of this file.
00001 /*
00002  * CGColorSpace.j
00003  * AppKit
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2008, 280 North, Inc.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 kCGColorSpaceModelUnknown       = -1;
00024 kCGColorSpaceModelMonochrome    = 0;
00025 kCGColorSpaceModelRGB           = 1;
00026 kCGColorSpaceModelCMYK          = 2;
00027 kCGColorSpaceModelLab           = 3;
00028 kCGColorSpaceModelDeviceN       = 4;
00029 kCGColorSpaceModelIndexed       = 5;
00030 kCGColorSpaceModelPattern       = 6;
00031 
00032 /*
00033     @global
00034     @group CGColorSpace
00035 */
00036 kCGColorSpaceGenericGray        = "CGColorSpaceGenericGray";
00037 /*
00038     @global
00039     @group CGColorSpace
00040 */
00041 kCGColorSpaceGenericRGB         = "CGColorSpaceGenericRGB";
00042 /*
00043     @global
00044     @group CGColorSpace
00045 */
00046 kCGColorSpaceGenericCMYK        = "CGColorSpaceGenericCMYK";
00047 /*
00048     @global
00049     @group CGColorSpace
00050 */
00051 kCGColorSpaceGenericRGBLinear   = "CGColorSpaceGenericRGBLinear";
00052 /*
00053     @global
00054     @group CGColorSpace
00055 */
00056 kCGColorSpaceGenericRGBHDR      = "CGColorSpaceGenericRGBHDR";
00057 /*
00058     @global
00059     @group CGColorSpace
00060 */
00061 kCGColorSpaceAdobeRGB1998       = "CGColorSpaceAdobeRGB1998";
00062 /*
00063     @global
00064     @group CGColorSpace
00065 */
00066 kCGColorSpaceSRGB               = "CGColorSpaceSRGB";
00067 
00068 var _CGNamedColorSpaces         = {};
00069 
00070 #define _CGColorSpaceCreateWithModel(aModel, aComponentCount, aBaseColorSpace) \
00071     { model:aModel, count:aComponentCount, base:aBaseColorSpace }
00072 
00073 function CGColorSpaceCreateCalibratedGray(aWhitePoint, aBlackPoint, gamma)
00074 {
00075     return _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
00076 }
00077 
00078 function CGColorSpaceCreateCalibratedRGB(aWhitePoint, aBlackPoint, gamma)
00079 {
00080     return _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 1, NULL);
00081 }
00082 
00083 function CGColorSpaceCreateICCBased(aComponentCount, range, profile, alternate)
00084 {
00085     // FIXME: Do we need to support this?
00086     return NULL;
00087 }
00088 
00089 function CGColorSpaceCreateLab(aWhitePoint, aBlackPoint, aRange)
00090 {
00091     // FIXME: Do we need to support this?
00092     return NULL;
00093 }
00094 
00095 function CGColorSpaceCreateDeviceCMYK()
00096 {
00097     return CGColorSpaceCreateWithName(kCGColorSpaceGenericCMYK);
00098 }
00099 
00100 function CGColorSpaceCreateDeviceGray()
00101 {
00102     return CGColorSpaceCreateWithName(kCGColorSpaceGenericGray);
00103 }
00104 
00105 function CGColorSpaceCreateDeviceRGB()
00106 {
00107     return CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
00108 }
00109 
00110 function CGColorSpaceCreateWithPlatformColorSpace()
00111 {
00112     // FIXME: This for sure we don't need.
00113     return NULL;
00114 }
00115 
00116 function CGColorSpaceCreateIndexed(aBaseColorSpace, lastIndex, colorTable)
00117 {
00118     // FIXME: Do we need to support this?
00119     return NULL;
00120 }
00121 
00122 function CGColorSpaceCreatePattern(aBaseColorSpace)
00123 {
00124     if (aBaseColorSpace)
00125         return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, aBaseColorSpace.count, aBaseColorSpace);
00126 
00127     return _CGColorSpaceCreateWithModel(kCGColorSpaceModelPattern, 0, NULL);
00128 }
00129 
00130 function CGColorSpaceCreateWithName(aName)
00131 {
00132     var colorSpace = _CGNamedColorSpaces[aName];
00133 
00134     if (colorSpace)
00135         return colorSpace;
00136 
00137     switch (aName)
00138     {
00139         case kCGColorSpaceGenericGray:      return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelMonochrome, 1, NULL);
00140         case kCGColorSpaceGenericRGB:       return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
00141         case kCGColorSpaceGenericCMYK:      return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelCMYK, 4, NULL);
00142         case kCGColorSpaceGenericRGBLinear: return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
00143         case kCGColorSpaceGenericRGBHDR:    return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
00144         case kCGColorSpaceAdobeRGB1998:     return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
00145         case kCGColorSpaceSRGB:             return _CGNamedColorSpaces[aName] = _CGColorSpaceCreateWithModel(kCGColorSpaceModelRGB, 3, NULL);
00146     }
00147 
00148     return NULL;
00149 }
00150 
00151 // Getting Information About Color Spaces
00152 
00153 function CGColorSpaceCopyICCProfile(aColorSpace)
00154 {
00155     return NULL;
00156 }
00157 
00158 function CGColorSpaceGetNumberOfComponents(aColorSpace)
00159 {
00160     return aColorSpace.count;
00161 }
00162 
00163 function CGColorSpaceGetTypeID(aColorSpace)
00164 {
00165 }
00166 
00167 function CGColorSpaceGetModel(aColorSpace)
00168 {
00169     return aColorSpace.model;
00170 }
00171 
00172 function CGColorSpaceGetBaseColorSpace(aColorSpace)
00173 {
00174 }
00175 
00176 function CGColorSpaceGetColorTableCount(aColorSpace)
00177 {
00178 }
00179 
00180 function CGColorSpaceGetColorTable(aColorSpace)
00181 {
00182 }
00183 
00184 // Retaining and Releasing Color Spaces
00185 
00186 function CGColorSpaceRelease(aColorSpace)
00187 {
00188 }
00189 
00190 function CGColorSpaceRetain(aColorSpace)
00191 {
00192     return aColorSpace;
00193 }
00194 
00195 // FIXME: We should refer to some default values.
00196 #define STANDARDIZE(components, index, minimum, maximum, multiplier)    \
00197 { \
00198     if (index > components.length) \
00199     { \
00200         components[index] = maximum; \
00201         return; \
00202     } \
00203 \
00204     var component = components[index]; \
00205     \
00206     if (component < minimum) \
00207         components[index] = minimum; \
00208     else if (component > maximum) \
00209         components[index] = maximum; \
00210     else \
00211         components[index] = ROUND(component * multiplier) / multiplier; \
00212 }
00213 
00214 function CGColorSpaceStandardizeComponents(aColorSpace, components)
00215 {
00216     var count = aColorSpace.count;
00217 
00218     // Standardize the alpha value.  We allow the alpha value to have a
00219     // higher precision than other components since it is not ultimately
00220     // bound to 256 bits like RGB.
00221     STANDARDIZE(components, count, 0, 1, 1000);
00222 
00223     if (aColorSpace.base)
00224         aColorSpace = aColorSpace.base;
00225 
00226     switch (aColorSpace.model)
00227     {
00228         case kCGColorSpaceModelMonochrome:
00229         case kCGColorSpaceModelRGB:
00230         case kCGColorSpaceModelCMYK:
00231         case kCGColorSpaceModelDeviceN:     while (count--)
00232                                                 STANDARDIZE(components, count, 0, 1, 255);
00233                                             break;
00234 
00235         // We don't currently support these color spaces.
00236         case kCGColorSpaceModelIndexed:
00237         case kCGColorSpaceModelLab:
00238         case kCGColorSpaceModelPattern:     break;
00239     }
00240 }
 All Classes Files Functions Variables Defines