PlatformImage

The Android form, wrapping a Bitmap.

The bitmap belongs to this object. Nothing else may hold it after close.

The Apple form, wrapping a CGImage.

Swift callers read pixels through toNSData and take a Core Image handle through toCIImage. The CGImage itself is not exposed.

A decoded frame, owned by the caller.

The pixels stay in whatever the platform decoded them into. Call close when you are done with the frame, from Kotlin or from Swift. Nothing else releases it for you.

Use toRgba8888 from Kotlin. Swift callers should use toNSData() on the Apple form of this class instead, which reads the same pixels without a per-byte bridged call.

The JVM form, wrapping a BufferedImage.

The image belongs to this object. Nothing else may hold it after close. There is no native buffer to free here, so close only drops the reference.

The browser form, holding an RGBA snapshot rather than a live frame.

This is the one place the browser cannot honour the common contract. VideoFrame.copyTo returns a Promise and there is no synchronous path to a frame's pixels, so the copy the common KDoc calls "always a copy" is paid before the image is constructed rather than inside toRgba8888. The signature holds. The sentence about pixels staying in whatever the platform decoded them into does not.

A PlatformImage costs widthPx * heightPx * 4 bytes of wasm heap for as long as it is open, so close it promptly and do not hold a strip of them.

Properties

Link copied to clipboard
actual val heightPx: Int

Frame height in pixels.

actual val heightPx: Int

Frame height in pixels.

expect val heightPx: Int

Frame height in pixels.

actual val heightPx: Int

Frame height in pixels.

actual val heightPx: Int

Frame height in pixels.

Link copied to clipboard
actual val widthPx: Int

Frame width in pixels.

actual val widthPx: Int

Frame width in pixels.

expect val widthPx: Int

Frame width in pixels.

actual val widthPx: Int

Frame width in pixels.

actual val widthPx: Int

Frame width in pixels.

Functions

Link copied to clipboard

The underlying bitmap, still owned by this object.

Link copied to clipboard

The underlying image, still owned by this object.

Link copied to clipboard
actual open override fun close()

Releases the underlying pixels. Idempotent, and using the image afterwards is a programming error.

actual open override fun close()

Releases the underlying pixels. Idempotent, and using the image afterwards is a programming error.

expect open override fun close()

Releases the underlying pixels. Idempotent, and using the image afterwards is a programming error.

actual open override fun close()

Releases the underlying pixels. Idempotent, and using the image afterwards is a programming error.

actual open override fun close()

Releases the underlying pixels. Idempotent, and using the image afterwards is a programming error.

Link copied to clipboard
suspend fun PlatformImage.encodeStill(spec: StillSpec = StillSpec()): StillBytes

Encodes this frame as a still image.

Link copied to clipboard
fun toCIImage(): CIImage?

The frame as a CIImage, for further Core Image work without a round trip through bytes.

Link copied to clipboard
fun toNSData(): NSData

The pixels as tightly packed RGBA_8888 in an NSData, which Swift sees as Data.

Link copied to clipboard
actual fun toRgba8888(): ByteArray

Copies the pixels out as tightly packed RGBA_8888, row-major, with no row padding.

actual fun toRgba8888(): ByteArray

The pixels are read in the frame's own color space wherever Core Graphics will take one. Naming a device space instead converts the frame on its way out, and a frame rendered for Rec.709 then stops matching the file the same pipeline encodes. A device space is the fallback for an image Core Graphics will not open a matching context for, such as a monochrome or CMYK one.

expect fun toRgba8888(): ByteArray

Copies the pixels out as tightly packed RGBA_8888, row-major, with no row padding.

actual fun toRgba8888(): ByteArray

Copies the pixels out as tightly packed RGBA_8888, row-major, with no row padding.

actual fun toRgba8888(): ByteArray

Copies the pixels out as tightly packed RGBA_8888, row-major, with no row padding.