# MPMask

    final class MPMask: Sendable, Equatable

Single-channel MediaPipe segmentation mask supporting conversion between `0...255` and `0.0...1.0` representations.
- `
  ### [init(float32Data:width:height:)](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC11float32Data5width6heightACSPySfG_S2itcfc)

  ` Creates a `.float32` mask by copying `width * height` elements from `float32Data`.

  #### Declaration

  Swift

      convenience init(float32Data: UnsafePointer<Float>, width: Int, height: Int)

- `
  ### [init(uint8Data:width:height:)](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC9uint8Data5width6heightACSPys5UInt8VG_S2itcfc)

  ` Creates a `.uInt8` mask by copying `width * height` elements from `uint8Data`.

  #### Declaration

  Swift

      convenience init(uint8Data: UnsafePointer<UInt8>, width: Int, height: Int)

- `
  ### [dataType](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC8dataTypeAA08MaskDataG0Ovp)

  ` Primary native data type of the segmentation mask.

  #### Declaration

  Swift

      final let dataType: MaskDataType

- `
  ### [float32Elements](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC15float32ElementsSaySfGvp)

  ` Mask values in `0.0...1.0`.

  When `dataType` is `.uInt8`, each element is scaled by `1.0 / 255.0`.

  #### Declaration

  Swift

      final var float32Elements: [Float] { get }

- `
  ### [height](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC6heightSivp)

  ` Height of the segmentation mask in pixels.

  #### Declaration

  Swift

      final let height: Int

- `
  ### [pixelCount](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC10pixelCountSivp)

  ` Total number of pixels in the mask (`width * height`).

  #### Declaration

  Swift

      final let pixelCount: Int

- `
  ### [uint8Elements](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC13uint8ElementsSays5UInt8VGvp)

  ` Mask values in `0...255`.

  When `dataType` is `.float32`, each element is clamped to `0.0...1.0` (mapping `NaN` to `0`) and scaled by `255.0`.

  #### Declaration

  Swift

      final var uint8Elements: [UInt8] { get }

- `
  ### [width](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC5widthSivp)

  ` Width of the segmentation mask in pixels.

  #### Declaration

  Swift

      final let width: Int

- `
  ### [withUnsafeFloat32BufferPointer(_:)](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC30withUnsafeFloat32BufferPointeryxxSRySfGKXEKlF)

  ` Invokes `body` with an `UnsafeBufferPointer<Float>` covering all `width * height` pixels.

  #### Declaration

  Swift

      final func withUnsafeFloat32BufferPointer<Result>(_ body: (UnsafeBufferPointer<Float>) throws -> Result) rethrows -> Result

- `
  ### [withUnsafeUInt8BufferPointer(_:)](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/MPMask.md.txt#/s:20MediaPipeTasksCommon6MPMaskC28withUnsafeUInt8BufferPointeryxxSRys0H0VGKXEKlF)

  ` Invokes `body` with an `UnsafeBufferPointer<UInt8>` covering all `width * height` pixels.

  #### Declaration

  Swift

      final func withUnsafeUInt8BufferPointer<Result>(_ body: (UnsafeBufferPointer<UInt8>) throws -> Result) rethrows -> Result