diff --git a/Cargo.lock b/Cargo.lock index 04f1e0817..caf4b4e41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1949,7 +1949,6 @@ name = "modals" version = "0.1.0" dependencies = [ "bit_field 0.9.0", - "dither", "fast_image_resize", "gam", "image", diff --git a/services/gam/Cargo.toml b/services/gam/Cargo.toml index 4a54ff958..a3e0e9a5a 100644 --- a/services/gam/Cargo.toml +++ b/services/gam/Cargo.toml @@ -37,7 +37,7 @@ qrcode = { version = "0.12", default-features = false } #dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28 dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true } # note: image version is matched to version used by dither -image = { version = "0.23", default-features = false, features = ["jpeg", "png"], optional = true } +image = { version = "0.23", default-features = false, features = ["png"], optional = true } [target.'cfg(not(any(windows,unix)))'.dependencies] utralib = {path = "../../utralib"} diff --git a/services/graphics-server/src/api/tile.rs b/services/graphics-server/src/api/tile.rs index 7d1f5a448..6182ab52f 100644 --- a/services/graphics-server/src/api/tile.rs +++ b/services/graphics-server/src/api/tile.rs @@ -65,7 +65,7 @@ impl Tile { pub fn get_word(&self, point: Point) -> Word { self.words[self.word_index(point)] } - + pub fn set_word(&mut self, point: Point, word: Word) { self.words[self.word_index(point)] = word; } diff --git a/services/modals/Cargo.toml b/services/modals/Cargo.toml index 7b42e4939..f45c62e48 100644 --- a/services/modals/Cargo.toml +++ b/services/modals/Cargo.toml @@ -23,9 +23,9 @@ locales = {path = "../../locales"} bit_field = "0.9.0" #dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28 -dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true } +#dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true } # note: image version is matched to version used by dither -image = { version = "0.23", default-features = false, features = ["jpeg", "png"], optional = true } +image = { version = "0.23", default-features = false, features = ["png"], optional = true } fast_image_resize = {version = "0.9.2", optional = true} [target.'cfg(not(any(windows,unix)))'.dependencies] @@ -33,5 +33,5 @@ utralib = { path = "../../utralib"} [features] tts = [] -ditherpunk = ["image", "dither", "fast_image_resize"] +ditherpunk = ["image", "fast_image_resize"] default = [] diff --git a/services/modals/src/main.rs b/services/modals/src/main.rs index 138f62248..d536b3a72 100644 --- a/services/modals/src/main.rs +++ b/services/modals/src/main.rs @@ -449,7 +449,7 @@ fn xmain() -> ! { let mut image = gam::modal::Image::new( renderer_cid, Opcode::ImageReturn.to_u32().unwrap(), - ); + ); image.set_bitmap(Some(Bitmap::from(config.tiles))); renderer_modal.modify( Some(ActionType::Image(image)), diff --git a/services/shellchat/src/cmds/net_cmd.rs b/services/shellchat/src/cmds/net_cmd.rs index 1097754d0..d53d28a35 100644 --- a/services/shellchat/src/cmds/net_cmd.rs +++ b/services/shellchat/src/cmds/net_cmd.rs @@ -283,6 +283,63 @@ impl<'a> ShellCmdApi<'a> for NetCmd { } } } + #[cfg(feature="ditherpunk")] + "image" => { + const MAX_IMAGE_LEN: usize = 256 * 1024; // includes HTTP headers + if let Some(url) = tokens.next() { + match url.split_once('/') { + Some((host, path)) => { + match TcpStream::connect((host, 80)) { + Ok(mut stream) => { + let mut heap_image = match xous::syscall::map_memory( + None, + None, + MAX_IMAGE_LEN, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) { + Ok(d) => d, + Err(e) => { + log::error!("couldn't allocate data for image, aborting"); + write!(ret, "Couldn't allocate memory for image, aborting: {:?}", e).unwrap(); + return Ok(Some(ret)); + } + }; + stream.set_read_timeout(Some(Duration::from_millis(10_000))).unwrap(); + stream.set_write_timeout(Some(Duration::from_millis(10_000))).unwrap(); + match write!(stream, "GET /{} HTTP/1.1\r\n", path) { + Ok(_) => log::trace!("sent GET"), + Err(e) => { + log::error!("GET err {:?}", e); + write!(ret, "Error sending GET: {:?}", e).unwrap(); + } + } + write!(stream, "Host: {}\r\nAccept: */*\r\nUser-Agent: Precursor/0.9.6\r\n", host).expect("stream error"); + write!(stream, "Connection: close\r\n").expect("stream error"); + write!(stream, "\r\n").expect("stream error"); + log::info!("fetching response...."); + match stream.read(heap_image.as_slice_mut()) { + Ok(len) => { + log::info!("fetched {} bytes of http data", len); + } + Err(e) => write!(ret, "Didn't get response from host: {:?}", e).unwrap(), + } + if let Some(start) = find_subsequence( + heap_image.as_slice::(), + &[0x0d, 0x0a, 0x0d, 0x0a], // this is \r\n\r\n, which indicates end of header. + ) { + log::info!("image data is {} bytes long", heap_image.len() - start); + } + xous::syscall::unmap_memory(heap_image).expect("couldn't de-allocate image memory"); + } + Err(e) => write!(ret, "Couldn't connect to {}:80: {:?}", host, e).unwrap(), + } + } + _ => write!(ret, "Usage: image bunniefoo.com/bunnie/bunny.png").unwrap(), + } + } else { + write!(ret, "Usage: image bunniefoo.com/bunnie/bunny.png").unwrap(); + } + } "tls" => { write!(ret, "Work in progress. Please check back later!").unwrap(); } @@ -417,6 +474,12 @@ impl<'a> ShellCmdApi<'a> for NetCmd { } } +// yep. this is from stackoverflow copypasta +#[cfg(feature="ditherpunk")] +fn find_subsequence(haystack: &[u8], needle: &[u8]) -> Option { + haystack.windows(needle.len()).position(|window| window == needle) +} + enum Responses { Uptime, NotFound,