swift-image icon indicating copy to clipboard operation
swift-image copied to clipboard

enhancement - filters Dither Atkinson, Floyd Steinberg, Burkes, Sierra, Sierra Two Row, Sierra Lite, Stucki, Jarvis Judice Ninke, Binary, Grayscale, Tint, Shading, Solarize, Invert, Gamma, Brightness, Contrast, Sepia

Open johndpope opened this issue 6 years ago • 3 comments

I came across this code base FilterPlay from @AfricanSwift which applies various filters to nsimage. It maybe nice to some to incorporate some of these into this library. https://github.com/AfricanSwift/FilterPlay

It maybe something where community can pitch in and add / extend

johndpope avatar Aug 08 '18 17:08 johndpope

related https://github.com/BradLarson/GPUImage2/tree/master/examples/Mac/FilterShowcase/FilterShowcase

johndpope avatar Aug 17 '18 00:08 johndpope

filters - https://github.com/johndpope/LightRoom/blob/master/LightRoom/Classes/ColorEffect.swift

also worth checking out https://github.com/muukii/Pixel

johndpope avatar Oct 29 '18 19:10 johndpope

Sorry for leaving this issue non-replied for a long time.

SwiftImage is designed to handle images as a data structure with value semantics rather than a convenient library with various filters.

SwiftImage provides some APIs to collaborate with other libraries/frameworks. For example, it is possible to collaborate with Core Image or Core Graphics like the code below.

// with Core Image
let image = Image<RGB<UInt8>>(uiImage: inputImage)
let outputImage: UIImage = image.withCGImage { cgImage in
    let ciImage = CIImage(cgImage: cgImage)
    
    let filter = CIFilter(name: "CILanczosScaleTransform")!
    filter.setValue(ciImage, forKey: kCIInputImageKey)
    let scale = NSNumber(value: 2736.0 / Double(cropped.width))
    filter.setValue(scale, forKey: kCIInputScaleKey)
    filter.setValue(NSNumber(value: 1.0 as Float), forKey: kCIInputAspectRatioKey)
    let output = filter.value(forKey: kCIOutputImageKey) as! CIImage
    let context = CIContext(options: [.useSoftwareRenderer: false])
    return UIImage(cgImage: context.createCGImage(output, from: output.extent)!)
}
// with Core Graphics
var image = Image<PremultipliedRGBA<UInt8>>(uiImage: imageView.image!)
image.withCGContext { context in
    context.setLineWidth(1)
    context.setStrokeColor(UIColor.red.cgColor)
    context.move(to: CGPoint(x: -1, y: -1))
    context.addLine(to: CGPoint(x: 640, y: 480))
    context.strokePath()
}
imageView.image = image.uiImage

Also you can access to raw buffers using the withUnsafeBufferPointer or withUnsafeMutableBufferPointer methods.

image.withUnsafeBufferPointer { pointer in
    ...
}

It would make it possible to collaborate with various libraries/frameworks.

koher avatar Jul 05 '20 01:07 koher