tayloraswift / swift-png

decode, inspect, edit, and encode png images in pure swift

Home Page:https://swiftinit.org/docs/swift-png

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

provide single-stage conversion API

tayloraswift opened this issue · comments

the library should provide a convenience function that takes any format of PNG and normalizes it to a user-provided format in a single function call. (right now we don’t do this because some checks are unnecessary if certain things are known about the PNGs beforehand. however these are all per-image, nor per-pixel checks so it really wouldn’t be that much less efficient)

API should look like

func convert<Component>(_ path:String, to format:PixelFormat) throws 
    -> ([Component], Int, Int) where Component:BinaryInteger

let (data, width, height):([UInt16], Int, Int) = try convert("example.png", to: .rgba) 
// .rgba, .grayscale, .planar