Last active
August 18, 2017 06:23
-
-
Save HarshilShah/ca0e18db01ce250fd308ab5acc99a9d0 to your computer and use it in GitHub Desktop.
CIEdgePreserveUpsampleFilter usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CIEdgePreserveUpsampleFilter.swift | |
// | |
// Created by Harshil Shah on 18/08/17. | |
// Copyright © 2017 Harshil Shah. All rights reserved. | |
// | |
import CoreImage | |
extension CIImage { | |
/// Method to upsample a `CIImage` while preserving the edges as shown | |
/// in a guide image | |
/// | |
/// - Parameter guideImage: The guide image with respect to which the image | |
/// should be upsampled | |
/// - Returns: The upsampled image. Returns nil if the filter doesn't exist | |
/// on the target platform (`CIEdgePreserveUpsampleFilter` is available on | |
/// iOS 10, tvOS 10, and higher) | |
func upsampled(withGuideImage guideImage: CIImage) -> CIImage? { | |
guard let upsampleFilter = CIFilter(name: "CIEdgePreserveUpsampleFilter") else { | |
return nil | |
} | |
upsampleFilter.setValue(self, forKey: "inputSmallImage") | |
upsampleFilter.setValue(guideImage, forKey: kCIInputImageKey) | |
return upsampleFilter.outputImage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment