<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShaders",
  "identifier" : "/documentation/MetalPerformanceShaders/MPSImageHistogramSpecification/encodeTransform(to:sourceTexture:sourceHistogram:sourceHistogramOffset:desiredHistogram:desiredHistogramOffset:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSImageHistogramSpecification(im)encodeTransformToCommandBuffer:sourceTexture:sourceHistogram:sourceHistogramOffset:desiredHistogram:desiredHistogramOffset:"
  },
  "title" : "encodeTransform(to:sourceTexture:sourceHistogram:sourceHistogramOffset:desiredHistogram:desiredHistogramOffset:)"
}
-->

# encodeTransform(to:sourceTexture:sourceHistogram:sourceHistogramOffset:desiredHistogram:desiredHistogramOffset:)

Encodes the transform function to a command buffer using a compute command encoder. The transform function computes the equalization lookup table.

```
func encodeTransform(to commandBuffer: any MTLCommandBuffer, sourceTexture source: any MTLTexture, sourceHistogram: any MTLBuffer, sourceHistogramOffset: Int, desiredHistogram: any MTLBuffer, desiredHistogramOffset: Int)
```

## Parameters

`commandBuffer`

A valid command buffer.

`source`

A valid texture containing the source image for the filter.

`sourceHistogram`

A valid buffer containing the histogram results for the source image. This filter will use these histogram results to generate the cumulative histogram for equalizing the image.  The histogram results per channel are stored together. The number of channels for which histogram results are stored is determined by the number of channels in the image. If the `histogramForAlpha` value of the [`histogramInfo`](/documentation/MetalPerformanceShaders/MPSImageHistogramSpecification/histogramInfo) property is <doc://com.apple.documentation/documentation/Swift/false> and the source image is RGBA, then only histogram results for RGB channels are stored.

`sourceHistogramOffset`

The byte offset into the source histogram buffer where the histogram starts. Must conform to alignment requirements for the `offset` parameter of the <doc://com.apple.documentation/documentation/Metal/MTLComputeCommandEncoder/setBuffer(_:offset:index:)> method.

`desiredHistogram`

A valid buffer containing the desired histogram results for the source image. The histogram results per channel are stored together. The number of channels for which histogram results are stored is determined by the number of channels in the image. If the `histogramForAlpha` value of the [`histogramInfo`](/documentation/MetalPerformanceShaders/MPSImageHistogramSpecification/histogramInfo) property is <doc://com.apple.documentation/documentation/Swift/false> and the source image is RGBA, then only histogram results for RGB channels are stored.

`desiredHistogramOffset`

The byte offset into the desired histogram buffer where the histogram starts. Must conform to alignment requirements for the `offset` parameter of the <doc://com.apple.documentation/documentation/Metal/MTLComputeCommandEncoder/setBuffer(_:offset:index:)> method.

## Discussion

The transform function will not begin to execute until after the command buffer has been enqueued and committed. This step will need to be repeated with the new [`MPSKernel`](/documentation/MetalPerformanceShaders/MPSKernel) object if the [`copy(with:device:)`](/documentation/MetalPerformanceShaders/MPSKernel/copy(with:device:)) or <doc://com.apple.documentation/documentation/Foundation/NSCopying/copy(with:)> method is called.

## See Also

  <doc://com.apple.documentation/documentation/Metal/MTLComputeCommandEncoder/setBufferOffset(_:index:)>

  <doc://com.apple.documentation/documentation/Metal/MTLComputeCommandEncoder/setBuffer(_:offset:index:)>



---

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)