Inherits from | |
Conforms to | |
Framework | Library/Frameworks/QuartzCore.framework |
Availability | Mac OS X v10.4 and later |
Declared in | CIContext.h |
Companion guides | |
Related sample code |
The CIContext
class provides an evaluation context for rendering a CIImage
object through Quartz 2D or OpenGL. You use CIContext
objects in conjunction with other Core Image classes, such as CIFilter
, CIImage
, and CIColor
, to take advantage of the built-in Core Image filters when processing images.
– createCGImage:fromRect:
– createCGImage:fromRect:format:colorSpace:
– createCGLayerWithSize:info:
– drawImage:atPoint:fromRect:
– drawImage:inRect:fromRect:
– render:toBitmap:rowBytes:bounds:format:colorSpace:
Creates a Core Image context from a Quartz context, using the specified options.
+ (CIContext *)contextWithCGContext:(CGContextRef)ctx options:(NSDictionary *)dict
A Quartz graphics context (CGContextRef
object) either obtained from the system or created using a Quartz function such as CGBitmapContextCreate
. See Quartz 2D Programming Guide for information on creating Quartz graphics contexts.
A dictionary that contains color space information. You can provide the keys kCIContextOutputColorSpace
or kCIContextWorkingColorSpace
along with a CGColorSpaceRef
object for each color space.
After calling this method, Core Image draws content to the specified Quartz graphics context.
When you create a CIContext
object using a Quartz graphics context, any transformations that are already set on the Quartz graphics context affect drawing to that context.
CIContext.h
Creates a Core Image context from a CGL context, using the specified options and pixel format object.
+ (CIContext *)contextWithCGLContext:(CGLContextObj)ctx pixelFormat:(CGLPixelFormatObj)pf options:(NSDictionary *)dict
A CGL context (CGLContextObj
object) obtain by calling the CGL function CGLCreateContext
.
A CGL pixel format object (CGLPixelFormatObj
object) created by calling the CGL function CGLChoosePixelFormat
. This argument must be the same pixel format object used to create the CGL context. The pixel format object must be valid for the lifetime of the Core Image context. Don’t release the pixel format object until after you release the Core Image context.
A dictionary that contains color space information. You can provide the keys kCIContextOutputColorSpace
or kCIContextWorkingColorSpace
along with a CGColorSpaceRef
object for each color space.
After calling this method, Core Image draws content into the surface (drawable object) attached to the CGL context. A CGL context is an Mac OS X OpenGL context. For more information, see OpenGL Programming Guide for Mac OS X.
When you create a CIContext
object using a CGL context, all OpenGL states set for the CGL context affect rendering to that context. That means that coordinate and viewport transformations set on the CGL context as well as the vertex color.
For best results, follow these guidelines when you use Core Image to render into an OpenGL context:
Ensure that the a single unit in the coordinate space of the OpenGL context represents a single pixel in the output device.
The Core Image coordinate space has the origin in the bottom left corner of the screen. You should configure the OpenGL context in the same way.
The OpenGL context blending state is respected by Core Image. If the image you want to render contains translucent pixels, it’s best to enable blending using a blend function with the parameters GL_ONE, GL_ONE_MINUS_SRC_ALPHA
, as shown in the following code example.
Some typical initialization code for a view with width W
and height H
is:
glViewport (0, 0, W, H); |
glMatrixMode (GL_PROJECTION); |
glLoadIdentity (); |
glOrtho (0, W, 0, H, -1, 1); |
glMatrixMode (GL_MODELVIEW); |
glLoadIdentity (); |
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
glEnable (GL_BLEND); |
CIContext.h
Frees any cached data, such as temporary images, associated with the context and runs the garbage collector.
- (void)clearCaches
You can use this method to remove textures from the texture cache that reference deleted images.
CIContext.h
Creates a Quartz 2D image from a region of a CIImage
object.
- (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r
A CIImage
object.
The region of the image to render.
A Quartz 2D (CGImageRef
) image. You are responsible for releasing the returned image when you no longer need it.
Renders a region of an image into a temporary buffer using the context, then creates and returns a Quartz 2D image with the results.
CIContext.h
Creates a Quartz 2D image from a region of a CIImage
object.
- (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs
A CIImage
object.
The region of the image to render.
The format of the image.
The color space of the image.
A Quartz 2D (CGImageRef
) image. You are responsible for releasing the returned image when you no longer need it.
Renders a region of an image into a temporary buffer using the context, then creates and returns a Quartz 2D image with the results.
CIContext.h
Creates a CGLayer object from the provided parameters.
- (CGLayerRef)createCGLayerWithSize:(CGSize)size info:(CFDictionaryRef)d
The size, in default user space units, of the layer relative to the graphics context.
A dictionary, which is passed to CGLayerCreateWithContext
as the auxiliaryInfo
parameter. Pass NULL
as this parameter is reserved for future use.
A CGLayer (CGLayerRef
) object.
After calling this method, Core Image draws content into the CGLayer object. Core Image creates a CGLayer object by calling the Quartz 2D function CGLayerCreateWithContext
, whose prototype is:
CGLayerRef CGLayerCreateWithContext ( |
CGContextRef context, |
CGSize size, |
CFDictionaryRef auxiliaryInfo |
); |
Core Image passes the CIContext
object as the context
parameter, the size as the size
parameter, and the dictionary as the auxiliaryInfo
parameter. For more information on CGLayer objects, see Quartz 2D Programming Guide and CGLayer Reference.
CIContext.h
Renders a region of an image to a point in the context destination.
- (void)drawImage:(CIImage *)im atPoint:(CGPoint)p fromRect:(CGRect)src
A CIImage
object.
The point in the context destination to draw to.
The region of the image to draw.
You can call this method to force evaluation of the result after you apply a filter using one of the methods of the CIFilter
class, such as apply:
, apply:arguments:options:
, and apply:k, . . .
.
CIContext.h
Renders a region of an image to a rectangle in the context destination.
- (void)drawImage:(CIImage *)im inRect:(CGRect)dest fromRect:(CGRect)src
A CIImage
object.
The rectangle in the context destination to draw into.
The subregion of the image that you want to draw into the context, with the origin and target size defined by the dest
parameter.
You can call this method to force evaluation of the result after you you apply a filter using one of the methods of the CIFilter
class, such as apply:
, apply:arguments:options:
, and apply:k, . . .
.
CIContext.h
Runs the garbage collector to reclaim any resources that the context no longer requires.
- (void)reclaimResources
The system calls this method automatically after every rendering operation. You can use this method to remove textures from the texture cache that reference deleted images.
CIContext.h
Renders to the given bitmap.
- (void)render:(CIImage *)im toBitmap:(void *)data rowBytes:(ptrdiff_t)rb bounds:(CGRect)r format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs
A CIImage
object.
Storage for the bitmap data.
The bytes per row.
The bounds of the bitmap data.
The format of the bitmap data.
The color space for the data. Pass NULL
if you want to use the output color space of the context.
CIContext.h
Keys in the options dictionary for a CIContext
object.
extern NSString *kCIContextOutputColorSpace; extern NSString *kCIContextWorkingColorSpace; extern NSString *kCIContextUseSoftwareRenderer;
kCIContextOutputColorSpace
A key for the color space to use for images before they are rendered to the context. By default, Core Image uses the GenericRGB color space, which leaves color matching to the system. You can specify a different output color space by providing a Quartz 2D CGColorSpace
object (CGColorSpaceRef
). (See Quartz 2D Programming Guide for information on creating and using CGColorSpace
objects.)
kCIContextWorkingColorSpace
A key for the color space to use for image operations. By default, Core Image assumes that processing nodes are 128 bits-per-pixel, linear light, premultiplied RGBA floating-point values that use the GenericRGB color space. You can specify a different working color space by providing a Quartz 2D CGColorSpace
object (CGColorSpaceRef
). Note that the working color space must be RGB-based. If you have YUV data as input (or other data that is not RGB-based), you can use ColorSync functions to convert to the working color space. (See Quartz 2D Programming Guide for information on creating and using CGColorSpace
objects.)
kCIContextUseSoftwareRenderer
A key for enabling software renderer use. If the associated NSNumber
object is YES
, then the software renderer is required.
CIContext.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-03-16)