init(packing:size:layout:metadata:indexer:)

    Creates an image from a scalar pixel array, using a custom indexing function.

    PNG.Image.swift:985
    init<T>(packing pixels: [T], size: (x: Int, y: Int), layout: PNG.Layout, metadata: PNG.Metadata = .init(), indexer: ([(r: UInt8, g: UInt8, b: UInt8, a: UInt8)]) -> (UInt8) -> Int) where T : FixedWidthInteger, T : UnsignedInteger

    Parameters

    pixels

    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.

    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.

    indexer

    A function which uses the palette entries in the color format to generate a referencing function. This function will only be invoked if the image color format is an indexed format.

    For an image with a grayscale-alpha color format, this function assigns the gray channel to the given scalars, and sets the alpha channel to T.max.

    For an image with an RGB or BGR color format, this function assigns all channels to the given scalars, replicating each scalar three times.

    For an image with an RGBA or BGRA color format, this function assigns all opaque channels to the given scalars, replicating each scalar three times, and sets the alpha channel to T.max.

    The scalar values are assumed to fill the entire range of T.

    See the indexed color tutorial for more about the semantics of this function.

    Other members in extension

    Type members

    Instance members