1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00
Files
egui/crates/egui_inspection/src/png.rs
lucasmerlin 72389ed5a8 egui_inspection: PNG-encode screenshots on the wire; collapse protocol feature
- FrameScreenshot now carries PNG bytes instead of raw RGBA (PROTOCOL_VERSION 1→2);
  add a shared `encode_png` helper behind a new `png` feature so the live plugin and the
  kittest harness encode frames identically.
- Make the protocol module unconditional: drop the `protocol` feature flag and the
  optional serde/serde_bytes/rmp-serde deps it gated.
- plugin.rs: re-stamp screenshot-bearing frames with the current step (so inspectors
  waiting for step > prev don't reject them) and pump a tail-side repaint while awaiting
  the GPU readback.
2026-05-26 16:20:07 +02:00

22 lines
1015 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Shared screenshot PNG encoder.
//!
//! Both peers — the live [`crate::InspectionPlugin`] and `egui_kittest`'s harness inspector
//! — encode their frames here so they produce identically-encoded
//! [`crate::protocol::FrameScreenshot`]s.
/// Encode tightly-packed RGBA8 pixels (`width * height * 4` bytes) as PNG using `image`'s
/// default settings (`CompressionType::Default` + `FilterType::Adaptive`).
///
/// PNG keeps high-resolution captures off the hot path of socket throughput — a 1550×2114
/// RGBA8 buffer is ~13 MiB raw but typically <1 MiB encoded.
///
/// # Errors
/// When the encoder fails (e.g. the buffer length doesn't match `width * height * 4`).
pub fn encode_png(width: u32, height: u32, rgba: &[u8]) -> Result<Vec<u8>, image::ImageError> {
use image::ImageEncoder as _;
let mut out = std::io::Cursor::new(Vec::new());
image::codecs::png::PngEncoder::new(&mut out)
.write_image(rgba, width, height, image::ExtendedColorType::Rgba8)?;
Ok(out.into_inner())
}