Plushie.Automation.Screenshot (Plushie v0.6.0)

Copy Markdown View Source

Pixel screenshot for automation and renderer inspection.

Captures pixel-level rendering data for visual regression testing. The :windowed backend uses GPU rendering via iced/wgpu and captures real RGBA pixel data through iced::window::screenshot(). The :headless backend uses tiny-skia software rendering to produce real RGBA pixel data without a display server. The wire protocol uses native msgpack binary for pixel data (no base64 overhead) or base64 for JSON mode. The :mock backend returns empty stubs (hash "", no pixel data) because mock mode has no real renderer.

Note that headless screenshots use software rendering (tiny-skia), so pixels will not match GPU-rendered output (:windowed backend) exactly. Use headless screenshots for catching layout regressions and verifying rendering pipeline correctness; use full screenshots for pixel-perfect visual regression against GPU output.

save_png/2 writes raw RGBA data as a minimal valid PNG file using pure Elixir (:zlib for deflate, :erlang.crc32 for chunk CRCs).

Summary

Functions

Builds a screenshot from a renderer screenshot_response message.

Save the screenshot as a PNG file.

Types

t()

@type t() :: %Plushie.Automation.Screenshot{
  backend: Plushie.Automation.backend_mode() | nil,
  hash: String.t(),
  name: String.t(),
  rgba_data: binary() | nil,
  size: {non_neg_integer(), non_neg_integer()}
}

Functions

from_response(msg, format \\ :msgpack, backend \\ nil)

@spec from_response(
  msg :: map(),
  format :: Plushie.Protocol.format(),
  backend :: Plushie.Automation.backend_mode() | nil
) :: t()

Builds a screenshot from a renderer screenshot_response message.

save_png(screenshot, path)

@spec save_png(screenshot :: t(), path :: String.t()) :: :ok

Save the screenshot as a PNG file.

Writes a minimal but valid PNG with 8-bit RGBA color. Returns :ok. No-op when rgba_data is nil (mock backend stubs).