Skip to main content

Module cg

Module cg 

Source
Expand description

CoreGraphics — turning a CGImage into bytes, and bytes into a PNG.

AppKit’s NSBitmapImageRep does both of these on the Mac, and the macOS capture paths still use it: those renders are compared byte-for-byte against a Swift reference, and swapping the pixel plumbing underneath them would invalidate that. CoreGraphics and ImageIO are the same API on every Apple platform, so this is what the iOS paths use instead.

The two are not interchangeable — a bitmap context cannot hold non-premultiplied alpha — but that does not matter: each platform is only ever compared against a reference rendered the same way it was.

Functions§

capture_layer⚠
Rasterise a CALayer into a tightly packed RGBA8 buffer.
cgimage_to_rgba⚠
Draw a CGImage into a tightly packed RGBA8 buffer.
rgba_to_cgimage⚠
Build a CGImage from tightly packed RGBA8 bytes. Caller owns the result.
write_png
Write RGBA8 bytes to a PNG file.