Class: CIContext

Inherits:
NSObject show all

Overview

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.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (CIContext) contextWithEAGLContext(eaglContext)

Creates a Core Image context from an EAGL context. The OpenGL ES context must support OpenGL ES 2.0. All drawing performed using the drawImage:atPoint:fromRect: method or the drawImage:inRect:fromRect: method is rendered directly into the context.

Parameters:

  • eaglContext (EAGLContext)

    The EAGL context to render to.

Returns:

  • (CIContext)

    A Core Image context that targets OpenGL ES.

+ (CIContext) contextWithEAGLContext(eaglContext, options:dict)

Creates a Core Image context from an EAGL context using the specified options. The OpenGL ES context must support OpenGL ES 2.0. All drawing performed using the drawImage:atPoint:fromRect: method or the drawImage:inRect:fromRect: method is rendered directly into the context.You should use this method if you want to get real-time performance on a device. One of the advantages of using an EAGL context is that the rendered image stays on the GPU and does not get copied to CPU memory.

Parameters:

  • eaglContext (EAGLContext)

    The EAGL context to render to.

  • options (Hash)

    A dictionary that contains options for creating a CIContext object. You can pass any of the keys defined in “Context Options” along with the appropriate value.

Returns:

  • (CIContext)

    A Core Image context that targets OpenGL ES.

+ (CIContext) contextWithOptions(dict)

Creates a CPU-based Core Image context using the specified options. You can create a CPU-based context by providing the key kCIContextUseSoftwareRenderer. A CPU-based context supports larger input and output images than a GPU-based context. It also allows your app to perform processing in the background, such as when saving the rendered output to the Photo Library.GPU rendering is faster than CPU rendering, but the resulting image is not displayed on the device until after is it copied to CPU memory and converted to another image type, such as a UIImage object.

Parameters:

  • dict (Hash)

    A dictionary that contains options for the context. You can pass any of the keys defined in “Context Options” along with the appropriate value.

Returns:

Instance Method Details

- (CGImageRef) createCGImage(im, fromRect:r)

Creates a Quartz 2D image from a region of a Core Image image object. Renders a region of an image into a temporary buffer using the context, then creates and returns a Quartz 2D image with the results.

Parameters:

  • im (CIImage)

    A Core Image image object.

  • r (CGRect)

    The region of the image to render.

Returns:

  • (CGImageRef)

    A Quartz 2D image. You are responsible for releasing the returned image when you no longer need it.

- (CGImageRef) createCGImage(im, fromRect:r, format:f, colorSpace:cs)

Creates a Quartz 2D image from a region of a Core Image image object. Renders a region of an image into a temporary buffer using the context, then creates and returns a Quartz 2D image with the results.

Parameters:

  • im (CIImage)

    A Core Image image object.

  • r (CGRect)

    The region of the image to render.

  • f (CIFormat)

    The format of the image.

  • cs (CGColorSpaceRef)

    The color space of the image.

Returns:

  • (CGImageRef)

    A Quartz 2D image. You are responsible for releasing the returned image when you no longer need it.

- (Object) drawImage(im, inRect:dest, fromRect:src)

Renders a region of an image to a rectangle in the context destination. On iOS, this method draws the CIImage object into a renderbuffer for the OpenGL ES context. Use this method only if the CIContext object is created with contextWithEAGLContext: and if you are rendering to a CAEAGLayer.On OS X, you need to be aware of whether the CIContext object is created with a CGContextRef or a CGLContext object. If you create the CIContext object with a CGContextRef, the dimensions of the destination rectangle are in points. If you create the CIContext object with a CGLContext object, the dimensions are in pixels.On iOS 5, this method is synchronous. On iOS 6, this method is asynchronous. For apps linked on iOS 5, this method will continue to be synchronous.

Parameters:

  • im (CIImage)

    A CIImage object.

  • dest (CGRect)

    The rectangle in the context destination to draw into. The image is scaled to fill the destination rectangle.

  • src (CGRect)

    The subregion of the image that you want to draw into the context, with the origin and target size defined by the dest parameter. This rectangle is always in pixel dimensions.

Returns:

- (CGSize) inputImageMaximumSize

Returns the maximum size allowed for any image rendered into the context. Some contexts limit the maximum size of an image that can be rendered into them. For example, the maximum size might reflect a limitation in the underlying graphics hardware.

Returns:

- (CGSize) outputImageMaximumSize

Returns the maximum size allowed for any image created by the context. Some contexts limit the maximum size of an image that can be created by them. For example, the maximum size might reflect a limitation in the underlying graphics hardware.

Returns:

- (Object) render(im, toBitmap:data, rowBytes:rb, bounds:r, format:f, colorSpace:cs)

Renders to the given bitmap.

Parameters:

  • im (CIImage)

    A Core Image image object.

  • data (Object)

    Storage for the bitmap data.

  • rb (ptrdiff_t)

    The bytes per row.

  • r (CGRect)

    The bounds of the bitmap data.

  • f (CIFormat)

    The format of the bitmap data.

  • cs (CGColorSpaceRef)

    The color space for the data. Pass NULL if you want to use the output color space of the context.

Returns:

- (Object) render(image, toCVPixelBuffer:buffer)

Renders an image into a pixel buffer.

Parameters:

  • image (CIImage)

    A Core Image image object.

  • buffer (CVPixelBufferRef)

    The destination pixel buffer.

Returns:

- (Object) render(image, toCVPixelBuffer:buffer, bounds:r, colorSpace:cs)

Renders a region of an image into a pixel buffer.

Parameters:

  • image (CIImage)

    A Core Image image object.

  • buffer (CVPixelBufferRef)

    The destination pixel buffer.

  • r (CGRect)

    The rectangle in the destination pixel buffer to draw into.

  • cs (CGColorSpaceRef)

    The color space of the destination pixel buffer.

Returns: