Pixmap

public final class Pixmap

Undocumented

  • Creates an empty Pixmap without pixels, with .unknown ColorType, with .unknown AlphaType, and with a width and height of zero. Use reset() to associate pixels, ColorType, AlphaType, width, and height after Pixmap has been created.

    Declaration

    Swift

    public init()
  • Creates Pixmap from info width, height, AlphaType, and ColorType. addr points to pixels, or nil. This computes the bytes per row from the info parameter.

    No parameter checking is performed; it is up to the caller to ensure that addr and rowBytes agree with info.

    The memory lifetime of pixels is managed by the caller. When Pixmap goes out of scope, addr is unaffected. Pixmap may be later modified by reset() to change its size, pixel type, or storage.

    Declaration

    Swift

    public init(info: ImageInfo, addr: UnsafeMutableRawPointer)

    Parameters

    info

    width, height, AlphaType, ColorType of ImageInfo

    addr

    pointer to pixels allocated by caller; may be nil

    Return Value

    initialized Pixmap

  • Creates Pixmap from info width, height, AlphaType, and ColorType. addr points to pixels, or nil. rowBytes should be info.width times info.bytesPerPixel, or larger. No parameter checking is performed; it is up to the caller to ensure that addr and rowBytes agree with info. The memory lifetime of pixels is managed by the caller. When Pixmap goes out of scope, addr is unaffected. Pixmap may be later modified by reset() to change its size, pixel type, or storage.

    Declaration

    Swift

    public init(info: ImageInfo, addr: UnsafeMutableRawPointer, rowBytes: Int)

    Parameters

    info

    width, height, AlphaType, ColorType of ImageInfo

    addr

    pointer to pixels allocated by caller; may be nil

    rowBytes

    size of one row of addr; width times pixel size, or larger

    Return Value

    initialized Pixmap

  • Sets width, height, row bytes to zero; pixel address to nil; ColorType to .unknown; and AlphaType to .unknown The prior pixels are unaffected; it is up to the caller to release pixels memory if desired.

    Declaration

    Swift

    public func reset()
  • Sets width, height, AlphaType, and ColorType from info. Sets pixel address from addr, which may be nil. Sets row bytes from rowBytes, which should be info.width times info.bytesPerPixel, or larger. Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is too small to hold one row of pixels. The memory lifetime pixels are managed by the caller. When Pixmap goes out of scope, addr is unaffected.

    Declaration

    Swift

    public func reset(info: ImageInfo, addr: UnsafeMutableRawPointer, rowBytes: Int)

    Parameters

    info

    width, height, AlphaType, ColorType of ImageInfo

    addr

    pointer to pixels allocated by caller; may be nil

    rowBytes

    size of one row of addr; width times pixel size, or larger

  • Returns width, height, AlphaType, ColorType, and ColorSpace.

    Declaration

    Swift

    public var info: ImageInfo { get }
  • Returns pixel count in each pixel row. Should be equal or less than: rowBytes / info.bytesPerPixel

    Declaration

    Swift

    public var width: Int32 { get }
  • Returns pixel row count.

    Declaration

    Swift

    public var height: Int32 { get }
  • Return the dimensions of the pixmap (from its ImageInfo)

    Declaration

    Swift

    public var rect: IRect { get }
  • Returns the ColorType for this pixmap

    Declaration

    Swift

    public var colorType: ColorType { get }
  • Returns the AlphaType for this pixmap

    Declaration

    Swift

    public var alphaType: AlphaType { get }
  • Returns SkColorSpace, the range of colors, associated with ImageInfo. The reference count of SkColorSpace is unchanged. The returned SkColorSpace is immutable.

    Declaration

    Swift

    public var colorSpace: ColorSpace? { get }
  • Returns row bytes, the interval from one pixel row to the next. Row bytes is at least as large as: width * info.bytesPerPixel. Returns zero if colorType .unknown It is up to the Bitmap creator to ensure that row bytes is a useful value.

    Declaration

    Swift

    public var rowBytes: Int { get }
  • Returns true if SkAlphaType is kOpaque_SkAlphaType. Does not check if SkColorType allows alpha, or if any pixel value has transparency.

    Declaration

    Swift

    public var isOpaque: Bool { get }
  • Returns pixel address, the base address corresponding to the pixel origin.

    Declaration

    Swift

    public var pixels: UnsafeMutableRawPointer { get }
  • Undocumented

    Declaration

    Swift

    public func getPixels(x: Int32, y: Int32) -> UnsafeRawPointer
  • Undocumented

    Declaration

    Swift

    public func getPixel(x: Int32, y: Int32) -> Color
  • Undocumented

    Declaration

    Swift

    public func scalePixels(destination: Pixmap, quality: FilterQuality)
  • Copies a rectangle of pixels to dstPixels. Copy starts at (srcX, srcY), and does not exceed Pixmap (width, height). dstInfo specifies width, height, ColorType, AlphaType, and ColorSpace of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if dstInfo address equals nil, or dstRowBytes is less than dstInfo.minRowBytes(

    Pixels are copied only if pixel conversion is possible. If Pixmap colorType is .gray8, or .alpha8; dstInfo.colorType must match. If Pixmap colorType is .gray8, dstInfo.colorSpace must match. If PixmapalphaType is .opaque, dstInfo.alphaType must match. If Pixmap colorSpace is nil, dstInfo.colorSpace must match. srcX and srcY may be negative to copy only top or left of source. Returns false if Pixmap width or height is zero or negative.

    Declaration

    Swift

    public func readPixels(dstInfo: ImageInfo, dstPixels: UnsafeMutableRawPointer, dstRowBytes: Int, srcX: Int32 = 0, srcY: Int32 = 0, behavior: TransferFunctionBehavior = .respect) -> Bool

    Parameters

    dstInfo

    destination width, height, ColorType, AlphaType, ColorSpace

    dstPixels

    destination pixel storage

    dstRowBytes

    destination row length

    srcX

    column index whose absolute value is less than width()

    srcY

    row index whose absolute value is less than height()

    Return Value

    true if pixels are copied to dstPixels, or false if the pixel convesion is not possible, or if width/height is zero or negative, or abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().

  • Copies a rectangle of pixels to dst. Copy starts at (srcX, srcY), and does not exceed Pixmap (width, height). dst specifies width, height, ColorType, AlphaType, and ColorSpace of destination. Returns true if pixels are copied. Returns false if dst address equals nil, or dst.rowBytes is less than dst ImageInfo.minRowBytes. Pixels are copied only if pixel conversion is possible. If Pixmap colorType is .gray8, or .alpha8; dstInfo.colorType must match. If Pixmap colorType is .gray8, dstInfo.colorSpace must match. If PixmapalphaType is .opaque, dstInfo.alphaType must match. If Pixmap colorSpace is nil, dstInfo.colorSpace must match. srcX and srcY may be negative to copy only top or left of source. Returns false if Pixmap width or height is zero or negative.

    Declaration

    Swift

    public func readPixels(into: Pixmap, srcX: Int32 = 0, srcY: Int32 = 0) -> Bool

    Parameters

    dst

    ImageInfo and pixel address to write to

    srcX

    column index whose absolute value is less than width()

    srcY

    row index whose absolute value is less than height()

    Return Value

    true if pixels are copied to dst, or false if the pixel convesion is not possible, or if width/height is zero or negative, or abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().

  • Encodes the bitmap using the specified format.

    Declaration

    Swift

    public static func encode(dest: SKWStream, src: Bitmap, encoder: EncodedImageFormat, quality: Int32) -> Bool

    Parameters

    dest

    the stream to write the encoded bitmap into

    src

    the source bitmap to encode

    encoder

    the format to use to encode the bitmap

    Return Value

    true on success, false on failure

  • Encodes the pixmap using the specified format.

    Declaration

    Swift

    public static func encode(dest: SKWStream, src: Pixmap, encoder: EncodedImageFormat, quality: Int32) -> Bool

    Parameters

    dest

    the stream to write the encoded pixmap into

    src

    the source pixmap to encode

    encoder

    the format to use to encode the pixmap

    Return Value

    true on success, false on failure

  • Encodes the pixmap using the specified format.

    Declaration

    Swift

    public func encode(encoder: EncodedImageFormat, quality: Int32) -> SKData?

    Parameters

    encoder

    the format to use to encode the pixmap

    Return Value

    nil on error, or Data containing the image in the specified format with the specified quality on success

  • Undocumented

    Declaration

    Swift

    public func extract(subset: IRect) -> Pixmap?
  • Undocumented

    Declaration

    Swift

    public func extract(into: Pixmap, subset: IRect) -> Bool
  • Undocumented

    Declaration

    Swift

    public func erase(_ color: Color)
  • Undocumented

    Declaration

    Swift

    public func erase(_ color: Color, _ rect: IRect)
  • Undocumented

    Declaration

    Swift

    public func withColorType(_ colorType: ColorType) -> Pixmap
  • Undocumented

    Declaration

    Swift

    public func withColorSpace(_ colorSpace: ColorSpace) -> Pixmap
  • Undocumented

    Declaration

    Swift

    public func withAlphaType(_ alphaType: AlphaType) -> Pixmap