---
title: "init(copying:cvImageFormat:cgImageFormat:pixelFormat:)"
framework: accelerate
role: symbol
role_heading: Initializer
path: "accelerate/vimage/pixelbuffer/init(copying:cvimageformat:cgimageformat:pixelformat:)"
---

# init(copying:cvImageFormat:cgImageFormat:pixelFormat:)

Initializes a pixel buffer by copying the data from a Core Video pixel buffer.

## Declaration

```swift
init(copying cvPixelBuffer: CVPixelBuffer, cvImageFormat: vImageCVImageFormat, cgImageFormat: inout vImage_CGImageFormat, pixelFormat: Format.Type = Format.self) throws
```

## Parameters

- `cvPixelBuffer`: The source Core Video pixel buffer.
- `cvImageFormat`: The image format of the Core Video pixel buffer.
- `cgImageFormat`: The Core Graphics image format that specifies the image output.
- `pixelFormat`: The pixel format of the initialized buffer.

## Discussion

Discussion The following code shows how to incorporate a vImage pixel buffer into a CIImageProcessorKernel instance. The code calls init(copying:cvImageFormat:cgImageFormat:pixelFormat:) to initialize a pixel buffer from the processor kernel’s input. class ContrastStretchImageProcessorKernel: CIImageProcessorKernel {          static var cgImageFormat = vImage_CGImageFormat(         bitsPerComponent: 8,         bitsPerPixel: 32,         colorSpace: CGColorSpaceCreateDeviceRGB(),         bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipLast.rawValue),         renderingIntent: .defaultIntent)!          static let cvImageFormat = vImageCVImageFormat.make(         format: .format32BGRA,         colorSpace: CGColorSpaceCreateDeviceRGB(),         alphaIsOpaqueHint: true)!

override class var outputFormat: CIFormat {         return CIFormat.BGRA8     }          override class func formatForInput(at input: Int32) -> CIFormat {         return CIFormat.BGRA8     }          override class func process(with inputs: [CIImageProcessorInput]?,                                 arguments: [String: Any]?,                                 output: CIImageProcessorOutput) throws {                  guard             let input = inputs?.first,             let inputPixelBuffer = input.pixelBuffer,             let outputPixelBuffer = output.pixelBuffer else {                 return             }             let buffer = try vImage.PixelBuffer(copying: inputPixelBuffer,                                             cvImageFormat: cvImageFormat,                                             cgImageFormat: &cgImageFormat,                                             pixelFormat: vImage.Interleaved8x4.self)                  buffer.contrastStretch(destination: buffer)                  try buffer.copy(to: outputPixelBuffer,                         cvImageFormat: cvImageFormat,                         cgImageFormat: cgImageFormat)     } }

## See Also

### Related Documentation

- [vImageBuffer_InitWithCVPixelBuffer(_:_:_:_:_:_:)](accelerate/vimagebuffer_initwithcvpixelbuffer(_:_:_:_:_:_:).md)

### Creating a pixel buffer from a Core Video buffer

- [init(referencing:converter:destinationPixelFormat:)](accelerate/vimage/pixelbuffer/init(referencing:converter:destinationpixelformat:).md)
- [init(referencing:planeIndex:overrideSize:pixelFormat:)](accelerate/vimage/pixelbuffer/init(referencing:planeindex:overridesize:pixelformat:).md)
