use std::io::Write;
use crate::{FrameView, PixelFormat, Result};
pub fn render_sixel<W: Write>(frame: FrameView<'_>, output: &mut W) -> Result<()> {
let mut rgba = Vec::with_capacity(frame.width() * frame.height() * 4);
for y in 0..frame.height() {
for x in 0..frame.width() {
let pixel = frame.pixel(x, y).expect("validated frame coordinate");
match frame.format() {
PixelFormat::Rgb8 => rgba.extend_from_slice(&[pixel[0], pixel[1], pixel[2], 255]),
PixelFormat::Rgba8 => rgba.extend_from_slice(pixel),
}
}
}
let image = icy_sixel::SixelImage::from_rgba(rgba, frame.width(), frame.height());
let encoded = image
.encode()
.map_err(|error| crate::Error::Unsupported(error.to_string()))?;
output.write_all(encoded.as_bytes())?;
Ok(())
}