Instance Methodswift-png 4.4.5PNG
unpack(as:deindexer:)
Unpacks this image to a scalar pixel array, using a custom deindexing function.
PNG.Image.swift:902func unpack<T>(as _: T.Type, deindexer: ([(r: UInt8, g: UInt8, b: UInt8, a: UInt8)]) -> (Int) -> UInt8) -> [T] where T : FixedWidthInteger, T : UnsignedInteger
Parameters
- _
A scalar color target type.
- deindexer
A function which uses the palette entries in the color
format
to generate a dereferencing function. This function will only be invoked iflayout.format
is an indexed format.See the indexed color tutorial for more about the semantics of this function.
Returns
A scalar 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. Its length is equal to size.x
multiplied by size.y
.
For an image with a grayscale-alpha color format
, this function selects the v component from pixels of the form (v, a)
For an image with an RGB color format
, this function selects the r component from pixels of the form (r, g, b).
For an image with an RGBA color format
, this function selects the r component from pixels of the form (r, g, b, a).
For an image with a BGR color format
, this function selects the r component from pixels of the form (b, g, r).
For an image with a BGRA color format
, this function selects the r component from pixels of the form (b, g, r, a).
This function ignores chroma keys, as its scalar color target is not capable of representing transparency. The unpacked components are scaled to fill the range of T
, according to the color depth computed from the color format
.
Other members in extension
Type members
init<Color>(packing: [Color], size: (x: Int, y: Int), layout: PNG.Layout, metadata: PNG.Metadata
) Creates an image from a pixel array.
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.