PhotoEditRenderer

@available(iOS 9.0, *)
@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.

Initializers

  • Creates a new PhotoEditRenderer object.

    Declaration

    Swift

    public required init(productType: LicenseProduct)

    Parameters

    productType

    The product this renderer is used in.

Properties

  • The input image.

    Declaration

    Swift

    open var originalImage: CIImage? { get set }
  • 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: <<error type>> { 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 }

CIImage Generation

  • A CIImage instance with all effects and filters applied to it.

    Declaration

    Swift

    open var outputImage: CIImage { get }

Sizing

  • The size of the output image.

    Declaration

    Swift

    open var outputImageSize: CGSize { get }

Helpers

  • Invalidates the cache. You can call this prior to rendering to force a complete rerender.

    Declaration

    Swift

    open func invalidateCache()

CGImage Generation

  • 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.

Framebuffer Rendering

  • 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 MTLCommandBuffer and the target CGColorSpace that were used to draw the image with a Metal context.

    See more

    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 target CGColorSpace that was used to render the image.

  • 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 target CGColorSpace 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 }