Class

CIKernel

A GPU-based image processing routine used to create custom Core Image filters.

Declaration

@interface CIKernel : NSObject

Overview

The kernel language routine for a general-purpose filter kernel has the following characteristics:

  • Its return type is vec4 (Core Image Kernel Language) or float4 (Metal Shading Language); that is, it returns a pixel color for the output image.

  • It may use zero or more input images. Each input image is represented by a parameter of type sampler.

A kernel routine typically produces its output by calculating source image coordinates (using the destCoord and samplerTransform functions or the samplerTransform function), samples from the source images (using the sample function), and computes a final pixel color (output using the return keyword). For example, the Metal Shading Language source below implements a filter that passes through its input image unchanged.

#include <CoreImage/CoreImage.h>
 
extern "C" {
    namespace coreimage {
        float4 do_nothing(sampler src) {
            return src.sample(src.coord());
        }
    }
}

The equivalent code in Core Image Kernel Language is:

kernel vec4 do_nothing(sampler image) {
    vec2 dc = destCoord();
    return sample(image, samplerTransform(image, dc));
}

The Core Image Kernel Language is a dialect of the OpenGL Shading Language. See Core Image Kernel Language Reference and Core Image Programming Guide for more details.

Topics

Creating a Kernel Using Core Image Kernel Language

+ kernelWithString:

Creates a single kernel object.

Deprecated
+ kernelsWithString:

Creates and returns and array of CIKernel objects.

Deprecated

Creating a Kernel Using Metal Shading Language

+ kernelWithFunctionName:fromMetalLibraryData:error:

Creates a single kernel object using a Metal Shading Language (MSL) kernel function.

+ kernelWithFunctionName:fromMetalLibraryData:outputPixelFormat:error:

Creates a single kernel object using a Metal Shading Language kernel function with optional pixel format.

Getting a Kernel Name

name

The name of the kernel routine.

Identifying the Region of Interest for the Kernel

- setROISelector:

Sets the selector Core Image uses to query the region of interest for image processing with the kernel.

Applying a Kernel to Filter an Image

- applyWithExtent:roiCallback:arguments:

Creates a new image using the kernel and specified arguments.

CIKernelROICallback

The signature for a block that computes the region of interest (ROI) for a given area of destination image pixels. Core Image calls this block when applying the kernel. You specify this block when using the applyWithExtent:roiCallback:arguments: method.

Relationships

Inherits From

See Also

Custom Filters

Writing Custom Kernels

Write your own custom kernels in either the Core Image Kernel Language or the Metal Shading Language.

CIColorKernel

A GPU-based image processing routine that processes only the color information in images, used to create custom Core Image filters.

CIWarpKernel

A GPU-based image processing routine that processes only the geometry information in an image, used to create custom Core Image filters.

CIBlendKernel

A GPU-based image processing routine that is optimized for blending two images.

CISampler

An object that retrieves pixel samples for processing by a filter kernel.