CGColorSpace Reference
| Derived from | |
| Framework | ApplicationServices/ApplicationServices.h |
| Declared in | CGColorSpace.h |
| Companion guides |
Overview
The CGColorSpaceRef opaque type encapsulates color space information that is used to specify how Quartz interprets color information. A color space specifies how color values are interpreted. A color space is multi-dimensional, and each dimension represents a specific color component. For example, the colors in an RGB color space have three dimensions or components—red, green, and blue. The intensity of each component is represented by floating point values—their range and meaning depends on the color space in question.
Different types of devices (scanners, monitors, printers) operate within different color spaces (RGB, CMYK, grayscale). Additionally, two devices of the same type (for example, color displays from different manufacturers) may operate within the same kind of color space, yet still produce a different range of colors, or gamut. Color spaces that are correctly specified ensure that an image has a consistent appearance regardless of the output device.
Quartz supports several kinds of color spaces:
Calibrated color spaces ensure that colors appear the same when displayed on different devices. The visual appearance of the color is preserved, as far as the capabilities of the device allow.
Device-dependent color spaces are tied to the system of color representation of a particular device. Device color spaces are not recommended when high-fidelity color preservation is important.
Special color spaces—indexed and pattern. An indexed color space contains a color table with up to 256 entries and a base color space to which the color table entries are mapped. Each entry in the color table specifies one color in the base color space. A pattern color space is used when stroking or filling with a pattern. Pattern color spaces are supported in OS X version 10.1 and later.
Functions by Task
Creating Device-Independent Color Spaces
-
CGColorSpaceCreateCalibratedGray -
CGColorSpaceCreateCalibratedRGB -
CGColorSpaceCreateICCBased -
CGColorSpaceCreateWithICCProfile -
CGColorSpaceCreateLab
Creating Generic or Device-Dependent Color Spaces
In OS X v10.4 and later, the color space returned by each of these functions is no longer device-dependent and is replaced by a generic counterpart.
Creating Special Color Spaces
Getting Information About Color Spaces
-
CGColorSpaceGetNumberOfComponents -
CGColorSpaceGetTypeID -
CGColorSpaceGetModel -
CGColorSpaceGetBaseColorSpace -
CGColorSpaceGetColorTableCount -
CGColorSpaceGetColorTable
Retaining and Releasing Color Spaces
Functions
CGColorSpaceCreateCalibratedGray
Creates a calibrated grayscale color space.
CGColorSpaceRef CGColorSpaceCreateCalibratedGray( const CGFloat whitePoint[3], const CGFloat blackPoint[3], CGFloat gamma );
Parameters
- whitePoint
An array of 3 numbers specifying the tristimulus value, in the CIE 1931 XYZ-space, of the diffuse white point.
- blackPoint
An array of 3 numbers specifying the tristimulus value, in CIE 1931 XYZ-space, of the diffuse black point.
- gamma
The gamma value appropriate for the imaging device.
Return Value
A new calibrated gray color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
Creates a device-independent grayscale color space that represents colors relative to a reference white point. This white point is based on the whitest light that can be generated by the output device. Colors in a device-independent color space should appear the same when displayed on different devices, to the extent that the capabilities of the device allow.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreateCalibratedRGB
Creates a calibrated RGB color space.
CGColorSpaceRef CGColorSpaceCreateCalibratedRGB( const CGFloat whitePoint[3], const CGFloat blackPoint[3], const CGFloat gamma[3], const CGFloat matrix[9] );
Parameters
- whitePoint
An array of 3 numbers specifying the tristimulus value, in the CIE 1931 XYZ-space, of the diffuse white point.
- blackPoint
An array of 3 numbers specifying the tristimulus value, in CIE 1931 XYZ-space, of the diffuse black point.
- gamma
An array of 3 numbers specifying the gamma for the red, green, and blue components of the color space.
- matrix
An array of 9 numbers specifying the linear interpretation of the gamma-modified RGB values of the color space with respect to the final XYZ representation.
Return Value
A new calibrated RGB color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
Creates a device-independent RGB color space that represents colors relative to a reference white point. This white point is based on the whitest light that can be generated by the output device. Colors in a device-independent color space should appear the same when displayed on different devices, to the extent that the capabilities of the device allow.
For color spaces that require a detailed gamma, such as the piecewise transfer function used in sRGB or ITU-R BT.709, you may want to use the function CGColorSpaceCreateICCBased instead, because it can accurately represent these gamma curves.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreateDeviceCMYK
Creates a device-dependent CMYK color space.
CGColorSpaceRef CGColorSpaceCreateDeviceCMYK( void );
Return Value
A device-dependent CMYK color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
In OS X v10.4 and later, this color space is no longer device-dependent and is replaced by the generic counterpart—kCGColorSpaceGenericCMYK—described in “Color Space Names”. If you use this function in OS X v10.4 and later, colors are mapped to the generic color spaces. If you want to bypass color matching, use the color space of the destination context.
Colors in a device-dependent color space are not transformed or otherwise modified when displayed on an output device—that is, there is no attempt to maintain the visual appearance of a color. As a consequence, colors in a device color space often appear different when displayed on different output devices. For this reason, device color spaces are not recommended when color preservation is important.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreateDeviceGray
Creates a device-dependent grayscale color space.
CGColorSpaceRef CGColorSpaceCreateDeviceGray( void );
Return Value
A device-dependent gray color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
In OS X v10.4 and later, this color space is no longer device-dependent and is replaced by the generic counterpart—kCGColorSpaceGenericGray—described in “Color Space Names”. If you use this function in OS X v10.4 and later, colors are mapped to the generic color spaces. If you want to bypass color matching, use the color space of the destination context.
Colors in a device-dependent color space are not transformed or otherwise modified when displayed on an output device—that is, there is no attempt to maintain the visual appearance of a color. As a consequence, colors in a device color space often appear different when displayed on different output devices. For this reason, device color spaces are not recommended when color preservation is important.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreateDeviceRGB
Creates a device-dependent RGB color space.
CGColorSpaceRef CGColorSpaceCreateDeviceRGB( void );
Return Value
A device-dependent RGB color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
In OS X v10.4 and later, this color space is no longer device-dependent and is replaced by the generic counterpart—kCGColorSpaceGenericRGB—described in “Color Space Names”. If you use this function in OS X v10.4 and later, colors are mapped to the generic color spaces. If you want to bypass color matching, use the color space of the destination context.
Colors in a device-dependent color space are not transformed or otherwise modified when displayed on an output device—that is, there is no attempt to maintain the visual appearance of a color. As a consequence, colors in a device color space often appear different when displayed on different output devices. For this reason, device color spaces are not recommended when color preservation is important.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreateICCBased
Creates a device-independent color space that is defined according to the ICC color profile specification.
CGColorSpaceRef CGColorSpaceCreateICCBased( size_t nComponents, const CGFloat *range, CGDataProviderRef profile, CGColorSpaceRef alternate );
Parameters
- nComponents
The number of color components in the color space defined by the ICC profile data. This must match the number of components actually in the ICC profile and must equal 1, 3, or 4.
- range
An array of numbers that specify the minimum and maximum valid values of the corresponding color components. The size of the array is two times the number of components. If
c[k]is thekth color component, the valid range is range[2*k] ≤ c[k] ≤range[2*k+1].- profile
A data provider that supplies the ICC profile.
- alternateSpace
An alternate color space to use in case the ICC profile is not supported. The alternate color space must have
nComponentscolor components. You must supply an alternate color space. If this parameter isNULL, then the function returnsNULL.
Return Value
A new ICC-based color space object. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
This function creates an ICC-based color space from an ICC color profile, as defined by the International Color Consortium. ICC profiles define the reproducible color gamut (the range of colors supported by a device) and other characteristics of a particular output device, providing a way to accurately transform the color space of one device to the color space of another. The ICC profile is usually provided by the manufacturer of the device. Additionally, some color monitors and printers contain electronically embedded ICC profile information, as do some bitmap formats such as TIFF. Colors in a device-independent color space should appear the same when displayed on different devices, to the extent that the capabilities of the device allow.
You may want to use this function for a color space that requires a detailed gamma, such as the piecewise transfer function used in sRGB or ITU-R BT.709, because this function can accurately represent these gamma curves.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
CGColorSpace.hCGColorSpaceCreateIndexed
Creates an indexed color space, consisting of colors specified by a color lookup table.
CGColorSpaceRef CGColorSpaceCreateIndexed( CGColorSpaceRef baseSpace, size_t lastIndex, const unsigned char *colorTable );
Parameters
- baseSpace
The color space on which the color table is based.
- lastIndex
The maximum valid index value for the color table. The value must be less than or equal to 255.
- colorTable
An array of
m*(lastIndex+1)bytes, wheremis the number of color components in the base color space. Each byte is an unsigned integer in the range0to255that is scaled to the range of the corresponding color component in the base color space.
Return Value
A new indexed color space object. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
An indexed color space contains a color table with up to 255 entries, and a base color space to which the color table entries are mapped. Each entry in the color table specifies one color in the base color space. A value in an indexed color space is treated as an index into the color table of the color space. The data in the table is in meshed format. (For example, for an RGB color space the values are R, G, B, R, G, B, and so on.)
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreateLab
Creates a device-independent color space that is relative to human color perception, according to the CIE L*a*b* standard.
CGColorSpaceRef CGColorSpaceCreateLab( const CGFloat whitePoint[3], const CGFloat blackPoint[3], const CGFloat range[4] );
Parameters
- whitePoint
An array of 3 numbers that specify the tristimulus value, in the CIE 1931 XYZ-space, of the diffuse white point.
- blackPoint
An array of 3 numbers that specify the tristimulus value, in CIE 1931 XYZ-space, of the diffuse black point.
- range
An array of 4 numbers that specify the range of valid values for the a* and b* components of the color space. The a* component represents values running from green to red, and the b* component represents values running from blue to yellow.
Return Value
A new L*a*b* color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
The CIE L*a*b* space is a nonlinear transformation of the Munsell color notation system (a system which specifies colors by hue, value, and saturation—or “chroma”—values), designed to match perceived color difference with quantitative distance in color space. The L* component represents the lightness value, the a* component represents values running from green to red, and the b* component represents values running from blue to yellow. This roughly corresponds to the way the human brain is thought to decode colors. Colors in a device-independent color space should appear the same when displayed on different devices, to the extent that the capabilities of the device allow.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreatePattern
Creates a pattern color space.
CGColorSpaceRef CGColorSpaceCreatePattern( CGColorSpaceRef baseSpace );
Parameters
- baseSpace
For masking patterns, the underlying color space that specifies the colors to be painted through the mask. For colored patterns, you should pass
NULL.
Return Value
A new pattern color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
For information on creating and using patterns, see Quartz 2D Programming Guide and CGPattern Reference. Quartz retains the color space you pass in. Upon return, you may safely release it by calling CGColorSpaceRelease.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceCreateWithICCProfile
Creates an ICC-based color space using the ICC profile contained in the specified data.
CGColorSpaceRef CGColorSpaceCreateWithICCProfile( CFDataRef data );
Parameters
- data
The data containing the ICC profile to set for the new color space.
Return Value
A new color space based on the specified profile.
Availability
- Available in iOS 4.0 and later.
See Also
Declared In
CGColorSpace.hCGColorSpaceCreateWithName
Creates a specified type of Quartz color space.
CGColorSpaceRef CGColorSpaceCreateWithName( CFStringRef name );
Parameters
- name
A color space name. See
“Color Space Names”for a list of the valid Quartz-defined names.
Return Value
A new generic color space. You are responsible for releasing this object by calling CGColorSpaceRelease. If unsuccessful, returns NULL.
Discussion
You can use this function to create a generic color space. For more information, see “Color Space Names”.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceGetBaseColorSpace
Returns the base color space of a pattern or indexed color space.
CGColorSpace CGColorSpaceGetBaseColorSpace( CGColorSpaceRef space );
Parameters
- space
A color space object for a pattern or indexed color space.
Return Value
The base color space if the space parameter is a pattern or indexed color space; otherwise, NULL.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceGetColorTable
Copies the entries in the color table of an indexed color space.
void CGColorSpaceGetColorTable( CGColorSpaceRef space, uint8_t *table); );
Parameters
- space
A color space object for an indexed color space.
- table
The array pointed to by table should be at least as large as the number of entries in the color table. On output, the array contains the table data in the same format as that passed to
CGColorSpaceCreateIndexed.
Discussion
This function does nothing if the color space is not an indexed color space. To determine whether a color space is an indexed color space, call the function CGColorSpaceGetModel.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
CGColorSpace.hCGColorSpaceGetColorTableCount
Returns the number of entries in the color table of an indexed color space.
size_t CGColorSpaceGetColorTableCount( CGColorSpaceRef space );
Parameters
- space
A color space object for an indexed color space.
Return Value
The number of entries in the color table of the space parameter if the color space is an indexed color space; otherwise, returns 0.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
CGColorSpace.hCGColorSpaceGetModel
Returns the color space model of the provided color space.
CGColorSpaceModel CGColorSpaceGetModel( CGColorSpaceRef space );
Parameters
- space
A color space object.
Return Value
One of the constants described in “Color Space Models”.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceGetNumberOfComponents
Returns the number of color components in a color space.
size_t CGColorSpaceGetNumberOfComponents( CGColorSpaceRef cs );
Parameters
- cs
The Quartz color space to examine.
Return Value
The number of color components in the specified color space, not including the alpha value. For example, for an RGB color space, CGColorSpaceGetNumberOfComponents returns a value of 3.
Discussion
A color space defines an n-dimensional space whose dimensions (or components) represent intensity values. For example, you specify colors in RGB space as three intensity values: red, green, and blue. You can use the CGColorSpaceGetNumberOfComponents function to obtain the number of components in a given color space.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceGetTypeID
Returns the Core Foundation type identifier for Quartz color spaces.
CFTypeID CGColorSpaceGetTypeID( void );
Return Value
The identifier for the opaque type CGColorSpaceRef.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceRelease
Decrements the retain count of a color space.
void CGColorSpaceRelease( CGColorSpaceRef cs );
Parameters
- cs
The Quartz color space to release.
Discussion
This function is equivalent to CFRelease, except that it does not cause an error if the cs parameter is NULL.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hCGColorSpaceRetain
Increments the retain count of a color space.
CGColorSpaceRef CGColorSpaceRetain( CGColorSpaceRef cs );
Parameters
- cs
The Quartz color space to retain.
Return Value
The same color space you passed in as the cs parameter.
Discussion
This function is equivalent to CFRetain, except that it does not cause an error if the cs parameter is NULL.
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hData Types
CGColorSpaceRef
An opaque type that encapsulates color space information.
typedef struct CGColorSpace *CGColorSpaceRef;
Availability
- Available in iOS 2.0 and later.
Declared In
CGColorSpace.hConstants
Color Space Models
Models for color spaces.
enum CGColorSpaceModel {
kCGColorSpaceModelUnknown = -1,
kCGColorSpaceModelMonochrome,
kCGColorSpaceModelRGB,
kCGColorSpaceModelCMYK,
kCGColorSpaceModelLab,
kCGColorSpaceModelDeviceN,
kCGColorSpaceModelIndexed,
kCGColorSpaceModelPattern
};
typedef int32_t CGColorSpaceModel;
Constants
kCGColorSpaceModelUnknownAn unknown color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGColorSpaceModelMonochromeA monochrome color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGColorSpaceModelRGBAn RGB color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGColorSpaceModelCMYKA CMYK color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGColorSpaceModelLabA Lab color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGColorSpaceModelDeviceNA DeviceN color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGColorSpaceModelIndexedAn indexed color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGColorSpaceModelPatternA pattern color space model.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.
Color Rendering Intents
Handling options for colors that are not located within the destination color space of a graphics context.
enum CGColorRenderingIntent {
kCGRenderingIntentDefault,
kCGRenderingIntentAbsoluteColorimetric,
kCGRenderingIntentRelativeColorimetric,
kCGRenderingIntentPerceptual,
kCGRenderingIntentSaturation
};
typedef enum CGColorRenderingIntent CGColorRenderingIntent;
Constants
kCGRenderingIntentDefaultThe default rendering intent for the graphics context.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGRenderingIntentAbsoluteColorimetricMap colors outside of the gamut of the output device to the closest possible match inside the gamut of the output device. This can produce a clipping effect, where two different color values in the gamut of the graphics context are mapped to the same color value in the output device’s gamut. Unlike the relative colorimetric, absolute colorimetric does not modify colors inside the gamut of the output device.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGRenderingIntentRelativeColorimetricMap colors outside of the gamut of the output device to the closest possible match inside the gamut of the output device. This can produce a clipping effect, where two different color values in the gamut of the graphics context are mapped to the same color value in the output device’s gamut. The relative colorimetric shifts all colors (including those within the gamut) to account for the difference between the white point of the graphics context and the white point of the output device.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGRenderingIntentPerceptualPreserve the visual relationship between colors by compressing the gamut of the graphics context to fit inside the gamut of the output device. Perceptual intent is good for photographs and other complex, detailed images.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.kCGRenderingIntentSaturationPreserve the relative saturation value of the colors when converting into the gamut of the output device. The result is an image with bright, saturated colors. Saturation intent is good for reproducing images with low detail, such as presentation charts and graphs.
Available in iOS 2.0 and later.
Declared in
CGColorSpace.h.
Discussion
The rendering intent specifies how Quartz should handle colors that are not located within the gamut of the destination color space of a graphics context. It determines the exact method used to map colors from one color space to another. If you do not explicitly set the rendering intent by calling the function CGContextSetRenderingIntent, the graphics context uses the relative colorimetric rendering intent, except when drawing sampled images.
© 2003, 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-03-24)