<!--
{
  "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/MPSImageHistogram/histogramSize(forSourceFormat:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSImageHistogram(im)histogramSizeForSourceFormat:"
  },
  "title" : "histogramSize(forSourceFormat:)"
}
-->

# histogramSize(forSourceFormat:)

The amount of space the histogram will take up in the output buffer.

```
func histogramSize(forSourceFormat sourceFormat: MTLPixelFormat) -> Int
```

## Parameters

`sourceFormat`

The pixel format of the source image, corresponding to the `sourceTexture` object of the [`encode(to:sourceTexture:histogram:histogramOffset:)`](/documentation/MetalPerformanceShaders/MPSImageHistogram/encode(to:sourceTexture:histogram:histogramOffset:)) method.

## Return Value

The number of bytes needed to store the histogram results.

## Discussion

This convenience function calculates the minimum amount of space needed in the output histogram for the results. The buffer should be at least this length and longer if the `histogramOffset` value in the [`encode(to:sourceTexture:histogram:histogramOffset:)`](/documentation/MetalPerformanceShaders/MPSImageHistogram/encode(to:sourceTexture:histogram:histogramOffset:)) method is non-zero.

---

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)