QuickTime Visual Context - Setting the kQTVisualContextOutputColorSpaceKey Attribute

Q: How do I set the output color space attribute when creating a QuickTime OpenGL Texture Visual Context?

A: Both QuickTime Visual Context creation APIs, QTOpenGLTextureContextCreate and QTPixelBufferContextCreate take a dictionary of key-value paired attributes that influence aspects of the created context. Single attributes may also be set after creation by calling QTVisualContextSetAttribute. A full list of visual context attributes can be found in ImageCompression.h.

Two of these attributes are the working color space (kQTVisualContextWorkingColorSpaceKey) and the output color space (kQTVisualContextOutputColorSpaceKey). Setting one or both of these color space attributes allows developers to influence how QuickTime interprets color information during rendering.

Key: kQTVisualContextWorkingColorSpaceKey

Value: CGColorSpaceRef


The color space in which QuickTime will perform image processing. If this attribute is not set, images will be
processed in the output color space.
Key: kQTVisualContextOutputColorSpaceKey

Value: CGColorSpaceRef


The color space of images produced by this visual context. If this attribute is not set, images may be in any
color space.

Note: Color and color space management is a complex topic. Before using the visual context color space attributes mentioned above be aware of how they may affect the output image. See the references section for links to further documentation.

To set the output color space attribute, first create an attributes dictionary containing a CGColorSpaceRef paired with the kQTVisualContextOutputColorSpaceKey key, then pass this attributes dictionary to QTOpenGLTextureContextCreate as shown in listing 1. Listing 2 demonstrates how to create a CGColorSpaceRef from the display profile.

Listing 1: Visual Context creation with attributes.

QTVisualContextRef  theVisualContext;


NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                         [self displayColorSpace], kQTVisualContextOutputColorSpaceKey, nil];

error = QTOpenGLTextureContextCreate(kCFAllocatorDefault, (CGLContextObj)[[self openGLContext] CGLContextObj],
                                    (CGLPixelFormatObj)[[self pixelFormat] CGLPixelFormatObj],
if (noErr == error) {
    [self setVisualContext:theVisualContext];
} ...


Listing 2: Creating a display color space.


// return currently set display color space
- (CGColorSpaceRef)displayColorSpace
    return mDisplayColorSpace;

// set the display color space, this function in null safe
- (void)setDisplayColorSpace:(CGColorSpaceRef)inDisplayColorSpace

    mDisplayColorSpace = inDisplayColorSpace;

// update the display color space
- (void)updateDisplayColorSpace:(CGDirectDisplayID)inDisplayID
    CMProfileRef profile;

    if (noErr == CMGetProfileByAVID((CMDisplayIDType)inDisplayID, &profile)) {
        CGColorSpaceRef theDisplayColorSpace = CGColorSpaceCreateWithPlatformColorSpace(profile);

        [self setDisplayColorSpace:theDisplayColorSpace];


    } else {
        [self setDisplayColorSpace:NULL];

    if (NULL != [self visualContext]) {
                                    [self displayColorSpace]);



Back to Top 

Document Revision History

2007-09-28First Version

Posted: 2007-09-28

Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.