<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIKernel",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Image"
    ],
    "preciseIdentifier" : "c:objc(cs)CIKernel"
  },
  "title" : "CIKernel"
}
-->

# CIKernel

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

```
class CIKernel
```

## Overview> Note:
> If your custom filter uses both color and geometry information, but does not require processing both at the same time, you can improve performance by separating your image processing code: use a ``doc://com.apple.coreimage/documentation/CoreImage/CIColorKernel`` object for the color processing step and a ``doc://com.apple.coreimage/documentation/CoreImage/CIWarpKernel`` object for the geometry processing step.

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.

```c
#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:

```c
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](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CIKernelLangRef/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004397) and [Core Image Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_intro/ci_intro.html#//apple_ref/doc/uid/TP30001185) for more details.

## Topics

### Creating a Kernel Using Metal Shading Language

[`init(functionName:fromMetalLibraryData:)`](/documentation/CoreImage/CIKernel/init(functionName:fromMetalLibraryData:))

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

[`init(functionName:fromMetalLibraryData:outputPixelFormat:)`](/documentation/CoreImage/CIKernel/init(functionName:fromMetalLibraryData:outputPixelFormat:))

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

[`kernelNames(fromMetalLibraryData:)`](/documentation/CoreImage/CIKernel/kernelNames(fromMetalLibraryData:))

Return an array of strings containing the names of all of the kernels contained in the Metal library.

[`kernels(withMetalString:)`](/documentation/CoreImage/CIKernel/kernels(withMetalString:))

Load kernels from a Metal language string.

### Getting a Kernel Name

[`name`](/documentation/CoreImage/CIKernel/name)

The name of the kernel routine.

### Identifying the Region of Interest for the Kernel

[`setROISelector(_:)`](/documentation/CoreImage/CIKernel/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

[`apply(extent:roiCallback:arguments:)`](/documentation/CoreImage/CIKernel/apply(extent:roiCallback:arguments:))

Creates a new image using the kernel and specified arguments.

[`CIKernelROICallback`](/documentation/CoreImage/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 [`apply(extent:roiCallback:arguments:)`](/documentation/CoreImage/CIKernel/apply(extent:roiCallback:arguments:)) method.

### Deprecated

[`init(source:)`](/documentation/CoreImage/CIKernel/init(source:))

Creates a single kernel object.

[`makeKernels(source:)`](/documentation/CoreImage/CIKernel/makeKernels(source:))

Creates and returns and array of  `CIKernel` objects.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)