Initializerswift-png 4.4.5PNG
init(packing:size:layout:metadata:)
Creates an image from a pixel array.
PNG.Image.swift:1034init<Color>(packing pixels: [Color], size: (x: Int, y: Int), layout: PNG.Layout, metadata: PNG.Metadata = .init()) where Color : PNG.Color
Parameters
- pixels
A pixel array. Its elements are arranged in row-major order. The first pixel in this array corresponds to the top-left corner of the image. The
Color
type provides thepack(_:as:)
implementation used to pack the image data.The length of this array must match
size.x * size.y
. Passing an array of the wrong length will result in a precondition failure.- size
The size of the image. Both dimensions must be greater than zero. Passing an invalid image size will result in a precondition failure.
- layout
An image layout.
- metadata
A metadata structure. The default value is an empty metadata structure.
Other members in extension
Type members
init<T>(packing: [T], size: (x: Int, y: Int), layout: PNG.Layout, metadata: PNG.Metadata
) Creates an image from a scalar pixel array.
init<Color>(packing: [Color], size: (x: Int, y: Int), layout: PNG.Layout, metadata: PNG.Metadata, indexer: ([(r: UInt8, g: UInt8, b: UInt8, a: UInt8)]) -> (Color.Aggregate) -> Int
) Creates an image from a pixel array, using a custom indexing function.
init<T>(packing: [T], size: (x: Int, y: Int), layout: PNG.Layout, metadata: PNG.Metadata, indexer: ([(r: UInt8, g: UInt8, b: UInt8, a: UInt8)]) -> (UInt8) -> Int
) Creates an image from a scalar pixel array, using a custom indexing function.
static func decompress(path: String
) throws -> `Self`? Decompresses and decodes a PNG from a file at the given file path.
static func decompress<Source>(stream: inout Source
) throws -> PNG.Image Decompresses and decodes a PNG from the given bytestream.
Instance members
let layout: PNG.Layout
The layout of this image.
var metadata: PNG.Metadata
The metadata in this image.
let size: (x: Int, y: Int)
The size of this image, measured in pixels.
var storage: [UInt8]
The raw backing storage of the image content.
func bindStorage(to: PNG.Layout
) -> PNG.Image Rebinds this image to a compatible layout.
func compress(path: String, level: Int, hint: Int
) throws -> Void? Encodes and compresses a PNG to a file at the given file path.
func compress<Destination>(stream: inout Destination, level: Int, hint: Int
) throws Encodes and compresses a PNG to the given bytestream.
func unpack<Color>(as: Color.Type
) -> [Color] Unpacks this image to a pixel array.
func unpack<T>(as: T.Type
) -> [T] Unpacks this image to a scalar pixel array.
func unpack<Color>(as: Color.Type, deindexer: ([(r: UInt8, g: UInt8, b: UInt8, a: UInt8)]) -> (Int) -> Color.Aggregate
) -> [Color] Unpacks this image to a pixel array, using a custom deindexing function.
func unpack<T>(as: T.Type, deindexer: ([(r: UInt8, g: UInt8, b: UInt8, a: UInt8)]) -> (Int) -> UInt8
) -> [T] Unpacks this image to a scalar pixel array, using a custom deindexing function.