PhotoEditRenderer
@objcMembers
@objc(PESDKPhotoEditRenderer)
open class PhotoEditRenderer : NSObject
extension PhotoEditRenderer: PhotoEditModelSettable
A PhotoEditRenderer
takes a CIImage
and a PhotoEditModel
as input and takes care of
applying all necessary effects and filters to the image. The output image can then be rendered
into an EAGLContext
or converted into a CGImage
instance.
-
Creates a new
PhotoEditRenderer
object.Declaration
Swift
public required init(productType: LicenseProduct)
Parameters
productType
The product this renderer is used in.
-
Creates a new
PhotoEditRenderer
object.Note
This initializer should only be used with Objective-C.Declaration
Swift
@objc(initWithProductType:) public convenience init(_objCProductType: _ObjCLicenseProduct)
Parameters
_objCProductType
The product this renderer is used in.
-
The input image.
Declaration
Swift
open var originalImage: CIImage? { get set }
-
The current time of the untrimmed input video that should be rendered.
Declaration
Swift
open var currentTime: CMTime? { get }
-
The photo edit model that describes all effects that should be applied to the input image.
Declaration
Swift
open var photoEditModel: PhotoEditModel { get set }
-
The render mode describes which effects should be applied to the input image.
Declaration
Swift
open var renderMode: PESDKRenderMode { get set }
-
The asset manager that is associated with this renderer. It is used to fetch the resources for sprites like stickers, brush and frames.
Declaration
Swift
open var assetManager: AssetManager?
-
The asset catalog that is associated with this renderer.
Declaration
Swift
public var assetCatalog: AssetCatalog { get set }
-
The queue on which rendering is perfomed.
Declaration
Swift
public private(set) lazy var renderingQueue: DispatchQueue { get set }
-
A
CIImage
instance with all effects and filters applied to it.Declaration
Swift
open var outputImage: CIImage { get }
-
The size of the output image.
Declaration
Swift
open var outputImageSize: CGSize { get }
-
Invalidates the cache. You can call this prior to rendering to force a complete rerender.
Declaration
Swift
open func invalidateCache()
-
The
CIContext
that is used to generate images.Declaration
Swift
public var generatingCIContext: CIContext { get }
-
Applies all necessary filters and effects to the input image and converts it to an instance of
CGImage
.Declaration
Swift
open func newOutputImage() -> CGImage
Return Value
A newly created instance of
CGImage
. -
Renders the final output image into a pixel buffer.
Declaration
Swift
open func renderOutputImage(into pixelBuffer: CVPixelBuffer)
Parameters
pixelBuffer
The pixel buffer to render the output image into.
-
Same as
newOutputImage()
but asynchronously.Declaration
Swift
@objc(createOutputImageWithCompletion:) open func createOutputImage(with completion: @escaping (_ outputImage: CGImage) -> Void)
Parameters
completion
A completion handler that receives the newly created instance of
CGImage
once rendering is complete.
-
Draws the output image into the given
EAGLContext
.Declaration
Swift
@discardableResult @objc(drawOutputImageInContext:toRect:) open func drawOutputImage(in context: EAGLContext, to rect: CGRect) -> CIImage
Parameters
context
An instance of
EAGLContext
to draw into.rect
The
CGRect
in which the output image should be drawn. It is identical to the OpenGL viewport parameters of the framebuffer.Return Value
The final rendered
CIImage
. -
Draws the output image into the given
EAGLContext
.Declaration
Swift
open func drawOutputImage(in context: EAGLContext, to rect: CGRect, targetSize: CGSize? = nil, transform: CGAffineTransform = CGAffineTransform.identity, backgroundColor: UIColor? = nil, backgroundImage: CIImage? = nil, nearest: Bool = false, forceCropHack: Bool = false) -> CIImage
Parameters
context
An instance of
EAGLContext
to draw into.rect
The
CGRect
in which the output image should be drawn. It is identical to the OpenGL viewport parameters of the framebuffer.targetSize
The target size of the image that should be rendered. It is used to scale the image appropriately. If this value is nil the size of the
rect
parameter is used instead.transform
An optional affine transformation that should be applied to the image before rendering.
backgroundColor
An optional background color with infinite extents.
backgroundImage
An optional background image which will be cropped to the output image extents and it will be visible in transparent areas of the output image.
nearest
If true nearest-neighbor sampling is applied to the image before
transform
is applied. The default value is false.forceCropHack
If true a workaround for a Core Image bug is enabled where the resulting image is cropped to a slightly smaller extent. Otherwise cropping is not applied and the result looks always as if
clampedToExtent
is enabled. The default value is false.Return Value
The final rendered
CIImage
. -
A class containing the created
See moreMTLCommandBuffer
and the targetCGColorSpace
that were used to draw the image with a Metal context.Declaration
Swift
@objcMembers @objc(PESDKDrawReturnValue) open class DrawReturnValue : NSObject
-
Draws the output image into the given
CAMetalDrawable
.Declaration
Swift
@discardableResult open func drawOutputImage(for device: MTLDevice, in drawable: CAMetalDrawable, to rect: CGRect, commandQueue: MTLCommandQueue) -> DrawReturnValue?
Parameters
device
The
MTLDevice
to use.drawable
The drawable to draw into.
rect
The rectangle to draw into.
commandQueue
The
MTLCommandQueue
to use.Return Value
A tuple containing the created
MTLCommandBuffer
and the targetCGColorSpace
that was used to render the image. -
drawOutputImage(for:
in: to: commandQueue: targetSize: transform: backgroundColor: backgroundImage: nearest: presentAndCommit: label: ) Draws the output image into the given
CAMetalDrawable
.Declaration
Swift
@discardableResult open func drawOutputImage(for device: MTLDevice, in drawable: CAMetalDrawable, to rect: CGRect, commandQueue: MTLCommandQueue, targetSize: CGSize? = nil, transform: CGAffineTransform = CGAffineTransform.identity, backgroundColor: UIColor? = nil, backgroundImage: CIImage? = nil, nearest: Bool = false, presentAndCommit: Bool = true, label: String? = nil) -> DrawReturnValue?
Parameters
device
The
MTLDevice
to use.drawable
The drawable to draw into.
rect
The rectangle to draw into.
commandQueue
The
MTLCommandQueue
to use.targetSize
The target size of the image that should be rendered. It is used to scale the image appropriately. If this value is nil the size of the
rect
parameter is used instead.transform
An optional affine transformation that should be applied to the image before rendering.
backgroundColor
An optional background color with infinite extents.
backgroundImage
An optional background image which will be cropped to the output image extents and it will be visible in transparent areas of the output image.
nearest
If true nearest-neighbor sampling is applied to the image before
transform
is applied. The default value is false.presentAndCommit
If true the presentation is handled by this method otherwise the created
MTLCommandBuffer
is not committed and not scheduled for presentation. The default value is true.label
An optional label to tag the created Metal resources.
Return Value
A tuple containing the created
MTLCommandBuffer
and the targetCGColorSpace
that was used to render the image. -
This is a boxed property which exposes a Swift struct to Objective-C. This property should only be used if you are using Objective-C.
Every invocation of the getter will return a new (temporary) object wrapping the underlying Swift struct. Boxed properties cannot be chained with the dot syntax for mutable access of nested properties in place. Use the setter with the assignment operator instead to modify boxed properties, e.g.:
PESDKPhotoEditModel *photoEditModel = [[PESDKPhotoEditModel alloc] init]; // CORRECT: // get boxed `AdjustmentModel` PESDKAdjustmentModel *adjustmentModel = photoEditModel.adjustmentModel; // modify boxed `AdjustmentModel` adjustmentModel.brightness = 0.5; // set modified boxed `AdjustmentModel` photoEditModel.adjustmentModel = adjustmentModel; // WRONG: photoEditModel.adjustmentModel.brightness = 0.5;
Declaration
Swift
var boxedPhotoEditModel: _ObjCPhotoEditModel { get set }
-
Applies all necessary filters and effects to the input image and converts it to a
Data
object containing the specified image file format and the given compressoin quality (if applicable).Declaration
Swift
@objc(generateOutputImageDataWithFormat:compressionQuality:metadataSourcePhoto:completionHandler:) open func generateOutputImageData(withFormat imageFormat: ImageFileFormat, compressionQuality: CGFloat, metadataSourcePhoto: Photo?, completionHandler: @escaping (_ outputImageData: Data?, _ imageWidth: CGFloat, _ imageHeight: CGFloat) -> Void)
Parameters
imageFormat
The image file format to generate.
compressionQuality
The compression quality to apply. This will only be used for lossy image formats.
metadataSourcePhoto
The photo of which the metadata should be copied to the new image. If
nil
it uses the metadata of the original image, if available.completionHandler
A completion handler that receives the newly created instance of
Data
once rendering is complete.