pub fn crop_captured_frame(
frame: &CapturedFrame,
rect_px: Rect,
encode_png: bool,
) -> Result<CapturedFrame, CaptureError>Expand description
Crops a full-window RGBA capture to rect_px (physical pixels).
The rectangle is rounded outward (floor left/top, ceil right/bottom)
and clamped to the frame. The returned format is always RGBA8. PNG data is
regenerated only when encode_png is true; existing source PNG bytes are
never reused.
§Errors
Returns CaptureError::InvalidFrameBuffer unless the source has exactly
four bytes per declared pixel, CaptureError::EmptyCrop after clamp, or
CaptureError::Encode if optional PNG encoding fails.
§Panics
With overflow checks enabled, may panic if declared dimensions overflow
usize RGBA-size arithmetic. Allocation failure follows Rust’s allocator policy.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_render_wgpu::{CapturedFrame, CapturedFrameFormat};
let frame = CapturedFrame { width: 2, height: 1,
format: CapturedFrameFormat::Rgba8,
rgba: vec![1, 2, 3, 255, 4, 5, 6, 255], png_data: None };
let crop = ailloli_ui_winit::crop_captured_frame(
&frame, Rect::new(1.0, 0.0, 1.0, 1.0), false).unwrap();
assert_eq!((crop.width, crop.height, crop.rgba), (1, 1, vec![4, 5, 6, 255]));