From 23787756df77e980bf6407a64f318f8422a5bc73 Mon Sep 17 00:00:00 2001 From: Linus Date: Wed, 9 Feb 2022 00:06:20 +0100 Subject: [PATCH] Include gamma correction added to screenshot in #96 --- examples/live.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/live.rs b/examples/live.rs index 7d641dd..c132a19 100644 --- a/examples/live.rs +++ b/examples/live.rs @@ -7,6 +7,7 @@ use libremarkable::framebuffer::common::{DISPLAYHEIGHT, DISPLAYWIDTH}; use libremarkable::framebuffer::core::Framebuffer; use libremarkable::framebuffer::FramebufferIO; use libremarkable::image; +use rgb565::Rgb565; use std::io::Cursor; use tiny_http::{Header, Response, Server, StatusCode}; @@ -31,21 +32,23 @@ fn main() { continue; } - let rgb565 = fb + let width = DISPLAYWIDTH as u32; + let height = DISPLAYHEIGHT as u32; + let contents = fb .dump_region(framebuffer::common::mxcfb_rect { top: 0, left: 0, - width: DISPLAYWIDTH.into(), - height: DISPLAYHEIGHT.into(), + width, + height, }) - .unwrap(); + .expect("dumping image buffer with known dimensions should succeed") + .chunks_exact(2) + .flat_map(|c| Rgb565::from_rgb565_le([c[0], c[1]]).to_srgb888_components()) + .collect::>(); + + let rgb888 = image::RgbImage::from_raw(width, height, contents) + .expect("unable to construct the rgb image"); - let rgb888 = framebuffer::storage::rgbimage_from_u8_slice( - DISPLAYWIDTH.into(), - DISPLAYHEIGHT.into(), - &rgb565, - ) - .unwrap(); let url_lc = request.url().to_lowercase(); let (data, mime) = if url_lc.ends_with("jpg") || url_lc.ends_with("jpeg") { (encode(&*&rgb888, ImageFormat::Jpeg), "image/jpeg")