Skip to content

Commit

Permalink
Removed hazeRemovalFilter because CIKernel is deprecated in ios 12.
Browse files Browse the repository at this point in the history
  • Loading branch information
NikKovIos committed Jan 6, 2022
1 parent eb9e000 commit e7648fb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
1 change: 0 additions & 1 deletion Source/Configuration/YPImagePickerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public struct YPImagePickerConfiguration {
YPFilter(name: "Toaster", applier: YPFilter.toasterFilter),
YPFilter(name: "1977", applier: YPFilter.apply1977Filter),
YPFilter(name: "Clarendon", applier: YPFilter.clarendonFilter),
YPFilter(name: "HazeRemoval", applier: YPFilter.hazeRemovalFilter),
YPFilter(name: "Chrome", coreImageFilterName: "CIPhotoEffectChrome"),
YPFilter(name: "Fade", coreImageFilterName: "CIPhotoEffectFade"),
YPFilter(name: "Instant", coreImageFilterName: "CIPhotoEffectInstant"),
Expand Down
87 changes: 0 additions & 87 deletions Source/Filters/Photo/YPFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ extension YPFilter {
])
}

public static func hazeRemovalFilter(image: CIImage) -> CIImage? {
let filter = HazeRemovalFilter()
filter.inputImage = image
return filter.outputImage
}

private static func getColor(red: Int, green: Int, blue: Int, alpha: Int = 255) -> CIColor {
return CIColor(red: CGFloat(Double(red) / 255.0),
green: CGFloat(Double(green) / 255.0),
Expand All @@ -141,84 +135,3 @@ extension YPFilter {
return CIImage(color: color).cropped(to: rect)
}
}

class HazeRemovalFilter: CIFilter {
var inputImage: CIImage!
var inputColor: CIColor! = CIColor(red: 0.7, green: 0.9, blue: 1.0)
var inputDistance: Float! = 0.2
var inputSlope: Float! = 0.0
var hazeRemovalKernel: CIKernel!

override init() {
// check kernel has been already initialized
let code: String = """
kernel vec4 myHazeRemovalKernel(
sampler src,
__color color,
float distance,
float slope)
{
vec4 t;
float d;
d = destCoord().y * slope + distance;
t = unpremultiply(sample(src, samplerCoord(src)));
t = (t - d * color) / (1.0 - d);
return premultiply(t);
}
"""
self.hazeRemovalKernel = CIKernel(source: code)
super.init()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override var outputImage: CIImage? {
guard let inputImage = self.inputImage,
let hazeRemovalKernel = self.hazeRemovalKernel,
let inputColor = self.inputColor,
let inputDistance = self.inputDistance,
let inputSlope = self.inputSlope
else {
return nil
}
let src: CISampler = CISampler(image: inputImage)
return hazeRemovalKernel.apply(extent: inputImage.extent,
roiCallback: { (_, rect) -> CGRect in
return rect
}, arguments: [
src,
inputColor,
inputDistance,
inputSlope
])
}

override var attributes: [String: Any] {
return [
kCIAttributeFilterDisplayName: "Haze Removal Filter",
"inputDistance": [
kCIAttributeMin: 0.0,
kCIAttributeMax: 1.0,
kCIAttributeSliderMin: 0.0,
kCIAttributeSliderMax: 0.7,
kCIAttributeDefault: 0.2,
kCIAttributeIdentity: 0.0,
kCIAttributeType: kCIAttributeTypeScalar
],
"inputSlope": [
kCIAttributeSliderMin: -0.01,
kCIAttributeSliderMax: 0.01,
kCIAttributeDefault: 0.00,
kCIAttributeIdentity: 0.00,
kCIAttributeType: kCIAttributeTypeScalar
],
kCIInputColorKey: [
kCIAttributeDefault: CIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
]
]
}
}

0 comments on commit e7648fb

Please sign in to comment.