feat: make Flutgrid implement image
This commit is contained in:
parent
3b835b4609
commit
386a5fd5ec
3 changed files with 891 additions and 2 deletions
869
Cargo.lock
generated
869
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,5 +5,6 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { version = "0.7.5" }
|
axum = { version = "0.7.5" }
|
||||||
|
image = "0.25.1"
|
||||||
tokio = { version = "1.38", features = ["full"] }
|
tokio = { version = "1.38", features = ["full"] }
|
||||||
tokio-test = "*"
|
tokio-test = "*"
|
||||||
|
|
|
||||||
23
src/main.rs
23
src/main.rs
|
|
@ -3,12 +3,13 @@
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cell::SyncUnsafeCell,
|
cell::SyncUnsafeCell,
|
||||||
io::{self, Error, ErrorKind},
|
io::{self, Cursor, Error, ErrorKind},
|
||||||
iter::once,
|
iter::once,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use axum::{http::StatusCode, routing::get, Router};
|
use axum::{http::StatusCode, routing::get, Router};
|
||||||
|
use image::{GenericImage, GenericImageView, Rgba};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter},
|
io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter},
|
||||||
net::TcpListener,
|
net::TcpListener,
|
||||||
|
|
@ -52,6 +53,21 @@ impl<T> FlutGrid<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GenericImageView for FlutGrid<u32> {
|
||||||
|
type Pixel = Rgba<u8>;
|
||||||
|
|
||||||
|
fn dimensions(&self) -> (u32, u32) {
|
||||||
|
return (self.size_x as u32, self.size_y as u32);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel {
|
||||||
|
match self.get(x as u16, y as u16) {
|
||||||
|
None => todo!("out of bounds for images not supported"),
|
||||||
|
Some(color) => return Rgba(color.to_be_bytes()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Grid<u16, T> for FlutGrid<T> {
|
impl<T> Grid<u16, T> for FlutGrid<T> {
|
||||||
fn get(&self, x: u16, y: u16) -> Option<&T> {
|
fn get(&self, x: u16, y: u16) -> Option<&T> {
|
||||||
match self.index(x, y) {
|
match self.index(x, y) {
|
||||||
|
|
@ -266,6 +282,11 @@ async fn main() -> io::Result<()> {
|
||||||
let web_listener = TcpListener::bind("0.0.0.0:7792").await?;
|
let web_listener = TcpListener::bind("0.0.0.0:7792").await?;
|
||||||
println!("bound web listener");
|
println!("bound web listener");
|
||||||
|
|
||||||
|
let img_asuc = asuc.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let img_grids = unsafe { img_asuc.get().as_ref().unwrap() };
|
||||||
|
});
|
||||||
|
|
||||||
let app = Router::new().route("/", get(root));
|
let app = Router::new().route("/", get(root));
|
||||||
tokio::spawn(async move { axum::serve(web_listener, app).await });
|
tokio::spawn(async move { axum::serve(web_listener, app).await });
|
||||||
println!("web server started");
|
println!("web server started");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue