Created
October 18, 2016 19:28
-
-
Save vzsg/964a307575fc2c534e90bd294b93ed8d to your computer and use it in GitHub Desktop.
Kingfisher processor that replaces #FFFFFF with transparent color
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
import Foundation | |
import Kingfisher | |
import CoreImage | |
private let colorCubeData: [Float] = [ | |
0, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 0, 1, | |
1, 1, 0, 1, | |
0, 0, 1, 1, | |
1, 0, 1, 1, | |
0, 1, 1, 1, | |
0, 0, 0, 0 | |
] | |
private let cubeData = NSData(bytes: colorCubeData, length: colorCubeData.count * MemoryLayout<Float>.size) | |
struct WhiteToTransparentProcessor: CIImageProcessor { | |
let identifier = "com.ouroboros.WhiteToTransparent" | |
let filter = Filter { input in | |
guard let colorCube = CIFilter(name: "CIColorCube", withInputParameters: [ | |
"inputCubeDimension": 2, | |
"inputCubeData": cubeData, | |
kCIInputImageKey: input]) else { | |
return nil | |
} | |
return colorCube.outputImage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment