this repo has no description
at main 37 lines 939 B view raw
1use anyhow::{Context, Result}; 2use base64::Engine; 3 4#[derive(Debug, Clone)] 5pub struct RgbFrame { 6 pub width: u32, 7 pub height: u32, 8 pub data: Vec<u8>, 9} 10 11pub fn decode_screencast_frame( 12 encoded_data: &str, 13 target_width: u32, 14 target_height: u32, 15) -> Result<RgbFrame> { 16 let bytes = base64::engine::general_purpose::STANDARD 17 .decode(encoded_data) 18 .context("failed to decode CDP frame payload")?; 19 20 let img = image::load_from_memory(&bytes).context("failed to decode image bytes")?; 21 let normalized = if img.width() == target_width && img.height() == target_height { 22 img 23 } else { 24 img.resize_exact( 25 target_width, 26 target_height, 27 image::imageops::FilterType::Triangle, 28 ) 29 }; 30 31 let rgb = normalized.to_rgb8(); 32 Ok(RgbFrame { 33 width: target_width, 34 height: target_height, 35 data: rgb.into_raw(), 36 }) 37}