NSColorSpace Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.4 and later.
Companion guide
Declared in
NSColorSpace.h
Related sample code

Overview

The NSColorSpace class enables the creation of objects representing custom color spaces. You can make custom color spaces from ColorSync profiles or from ICC profiles. NSColorSpace also has factory methods that return objects representing the system color spaces.

You can use the colorWithColorSpace:components:count: method of the NSColor class to create color objects using custom NSColorSpace objects. You can also send the colorUsingColorSpace: message to an NSColor object to convert it between two color spaces, either of which may be a custom color space.

Tasks

Getting a Named NSColorSpace Object

Getting the Color Spaces Available On the System

Initializing a Custom NSColorSpace Object

Accessing Color-Space Data and Attributes

Class Methods

adobeRGB1998ColorSpace

Returns an NSColorSpace object representing an Adobe RGB (1998) color space.

+ (NSColorSpace *)adobeRGB1998ColorSpace
Return Value

The NSColorSpace object. This color-additive color space has red, green, blue, and alpha components.

Discussion

The Adobe RGB (1998) color space was designed to encompass most of the colors achievable on CMYK color printers, but by using RGB primary colors on a device such as the computer display. For more information on this color space, go to http://www.adobe.com/digitalimag/adobergb.html.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSColorSpace.h

availableColorSpacesWithModel:

Returns the list of color spaces available on the system that are displayed in the color panel, in the order they are displayed in the color panel.

+ (NSArray *)availableColorSpacesWithModel:(NSColorSpaceModel)model
Parameters
model

The model to return the color spaces for.

Return Value

The list of color spaces, or an empty array if no color spaces are available for the specified model.

Discussion

This method doesn’t return color spaces created on the fly or spaces without user-displayable names. Pass NSUnknownColorSpaceModel as model to get all available color spaces.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSColorSpace.h

deviceCMYKColorSpace

Returns an NSColorSpace object representing a calibrated or device-dependent CMYK color space.

+ (NSColorSpace *)deviceCMYKColorSpace
Return Value

The NSColorSpace object. This color space has cyan, magenta, yellow, black, and alpha components. Typical devices that use the color-subtractive CMYK color space are color printers. This object corresponds to the Cocoa color space name NSDeviceCMYKColorSpace.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

deviceGrayColorSpace

Returns an NSColorSpace object representing a calibrated or device-dependent gray color space.

+ (NSColorSpace *)deviceGrayColorSpace
Return Value

The NSColorSpace object. The color space also includes an alpha component. Typical devices that use this color space are grayscale printers and displays. This object corresponds to the Cocoa color space name NSDeviceWhiteColorSpace.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

deviceRGBColorSpace

Returns an NSColorSpace object representing a calibrated or device-dependent RGB color space.

+ (NSColorSpace *)deviceRGBColorSpace
Return Value

The NSColorSpace object. This color space has red, green, blue, and alpha components. Typical devices that use the color-additive RGB color space are displays and scanners. This object corresponds to the Cocoa color space name NSDeviceRGBColorSpace.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

genericCMYKColorSpace

Returns an NSColorSpace object representing a device-independent CMYK color space.

+ (NSColorSpace *)genericCMYKColorSpace
Return Value

The NSColorSpace object. This color space has cyan, magenta, yellow, black and alpha component.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

genericGamma22GrayColorSpace

Returns an NSColorSpace object representing a gray color space with a gamma value of 2.2.

+ (NSColorSpace *)genericGamma22GrayColorSpace
Return Value

The NSColorSpace object.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSColorSpace.h

genericGrayColorSpace

Returns an NSColorSpace object representing a device-independent gray color space.

+ (NSColorSpace *)genericGrayColorSpace
Return Value

The NSColorSpace object. The color space also includes an alpha component. This object corresponds to the Cocoa color space name NSCalibratedWhiteColorSpace.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

genericRGBColorSpace

Returns an NSColorSpace object representing a device-independent RGB color space.

+ (NSColorSpace *)genericRGBColorSpace
Return Value

The NSColorSpace object. This color-additive color space has red, green, blue, and alpha components. This object corresponds to the Cocoa color space name NSCalibratedRGBColorSpace.

Availability
  • Available in OS X v10.4 and later.
Related Sample Code
Declared In
NSColorSpace.h

sRGBColorSpace

Returns an NSColorSpace object representing an sRGB color space.

+ (NSColorSpace *)sRGBColorSpace
Return Value

The NSColorSpace object. This color-additive color space has red, green, blue, and alpha components.

Discussion

The sRGB color space is a standard color space for use on monitors, printers, and the Internet. For further information on sRGB, see http://www.color.org/srgb.html.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSColorSpace.h

Instance Methods

CGColorSpace

Returns a Core Graphics color-space object that represents a color space equivalent to the receiver’s.

- (CGColorSpaceRef)CGColorSpace
Return Value

A reference to an Core Graphics color-space object (CGColorSpaceRef) or NULL if the type of color space represented by the receiver cannot be represented by a CGColorSpace object.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSColorSpace.h

colorSpaceModel

Returns the model on which the color space of the receiver is based.

- (NSColorSpaceModel)colorSpaceModel
Return Value

A constant specifying the color space model of the receiver. See Color Space Models for a list of valid NSColorSpaceModel constants.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

colorSyncProfile

Returns the ColorSync profile from which the receiver was created.

- (void *)colorSyncProfile
Return Value

The ColorSync profile on which the receiver is based. You need to cast this value to an object of opaque type CMProfileRef. Returns NULL if the receiver was created from a ICC-profile data instead. See ColorSync Manager Reference for further information on CMProfileRef.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

ICCProfileData

Returns the ICC profile data from which the receiver was created.

- (NSData *)ICCProfileData
Return Value

The ICC profile from which the receiver was created. This method attempts to compute the profile data from a CMProfileRef object and returns nil if it is unable to.

For information on ICC profiles, see the latest ICC specification at the International Color Consortium website.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

initWithCGColorSpace:

Initializes and returns an NSColorSpace object initialized from a Core Graphics color-space object.

- (id)initWithCGColorSpace:(CGColorSpaceRef)cgColorSpace
Parameters
cgColorSpace

A reference to a Core Graphics color-space object (CGColorSpaceRef).

Return Value

The initialized NSColorSpace object or nil if initialization was not successful, which might happen if the color space represented by the CGColorSpace object is not supported by NSColorSpace.

Discussion

Because NSColorSpace might retain or copy the CGColorSpace object depending on circumstances, you should not assume pointer equality of the provided object with that returned by CGColorSpace. And even if the pointer equality is preserved during runtime, it may not be after the NSColorSpace object is archived and unarchived.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSColorSpace.h

initWithColorSyncProfile:

Initializes and returns an NSColorSpace object given a ColorSync profile.

- (id)initWithColorSyncProfile:(void *)prof
Parameters
prof

The ColorSync profile to use when initializing the NSColorSpace object. This should be an object of opaque type CMProfileRef. See ColorSync Manager Reference for further information on CMProfileRef.

Return Value

The initialized NSColorSpace object or nil if initialization was not successful.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

initWithICCProfileData:

Initializes and returns an NSColorSpace object given an ICC profile.

- (id)initWithICCProfileData:(NSData *)iccData
Parameters
iccData

The ICC profile to use when initializing the NSColorSpace object. For information on ICC profiles, see the latest ICC specification at the International Color Consortium website.

Return Value

The initialized NSColorSpace object or nil if initialization was not successful.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

localizedName

Returns the localized name of the receiver.

- (NSString *)localizedName
Return Value

The name of the color space as a localized string or nil if no localized name exists.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

numberOfColorComponents

Returns the number of components supported by the receiver.

- (NSInteger)numberOfColorComponents
Return Value

The number of components (excluding alpha) the receiver supports or zero if the receiver is not based on float components.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

Constants

NSColorSpaceModel

The type of the color-space mode constants listed in “Color Space Models.”

typedef NSInteger NSColorSpaceModel;
Availability
  • Available in OS X v10.4 and later.
Declared In
NSColorSpace.h

Color Space Models

Identify the abstract model on which an NSColorSpace object is based.

typedef enum {
   NSUnknownColorSpaceModel = -1,
   NSGrayColorSpaceModel,
   NSRGBColorSpaceModel,
   NSCMYKColorSpaceModel,
   NSLABColorSpaceModel,
   NSDeviceNColorSpaceModel,
   NSIndexedColorSpaceModel,
   NSPatternColorSpaceModel
};
Constants
NSUnknownColorSpaceModel

This model is not known to NSColorSpace.

Available in OS X v10.4 and later.

Declared in NSColorSpace.h.

NSGrayColorSpaceModel

The grayscale color-space model. Can refer to both device-dependent and generic color space variants.

Available in OS X v10.4 and later.

Declared in NSColorSpace.h.

NSRGBColorSpaceModel

The RGB (red green blue) color-space model. Can refer to both device-dependent and generic color space variants.

Available in OS X v10.4 and later.

Declared in NSColorSpace.h.

NSCMYKColorSpaceModel

The CYMK (cyan, yellow, magenta, black) color-space model. Can refer to both device-dependent and generic color space variants.

Available in OS X v10.4 and later.

Declared in NSColorSpace.h.

NSLABColorSpaceModel

The L*a*b* device-independent color-space model, which represents colors relative to a reference white point.

Available in OS X v10.4 and later.

Declared in NSColorSpace.h.

NSDeviceNColorSpaceModel

DeviceN is a color-space model from Adobe Systems, Inc. used in PostScript and PDF color specification.

Available in OS X v10.4 and later.

Declared in NSColorSpace.h.

NSIndexedColorSpaceModel

An indexed color space, which identifies specified discrete colors in a color list by index number. An indexed color value (a color specification in indexed color space) consists of an index value that refers to a color in a color list.

Available in OS X v10.5 and later.

Declared in NSColorSpace.h.

NSPatternColorSpaceModel

Identifies a pattern color space, which is simply an image that is repeated over and over again in a tiled pattern.

Available in OS X v10.5 and later.

Declared in NSColorSpace.h.

Discussion

These constants are returned from colorSpaceModel and are derived from the profile data encapsulated by the object.

Declared In
NSColorSpace.h