Compare commits
2 commits
37f67323e1
...
59886a80fd
Author | SHA1 | Date | |
---|---|---|---|
![]() |
59886a80fd | ||
![]() |
2c34886dc5 |
|
@ -3,14 +3,17 @@ use image::{ImageReader, RgbImage};
|
|||
use pi_frame_server::dither::{DitherMethod, DitheredImage, Palette};
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("dithering_benchmark");
|
||||
|
||||
let sample_file = "sample_0.tiff";
|
||||
let image: RgbImage = ImageReader::open(format!("samples/{sample_file}"))
|
||||
.expect("file exists")
|
||||
.decode()
|
||||
.expect("file is valid")
|
||||
.into_rgb8();
|
||||
group.sample_size(20);
|
||||
|
||||
c.bench_with_input(BenchmarkId::new("dither", "sample_0"), &image, |b, i| {
|
||||
group.bench_with_input(BenchmarkId::new("dither", "sample_0"), &image, |b, i| {
|
||||
b.iter(|| {
|
||||
let mut method = DitherMethod::Atkinson.get_ditherer();
|
||||
let mut result = DitheredImage::new(
|
||||
|
|
|
@ -22,12 +22,12 @@ pub enum ApiError {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Context {
|
||||
pub struct AppState {
|
||||
display_channel: Sender<DisplaySetCommand>,
|
||||
display_task: Arc<JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
impl AppState {
|
||||
#[must_use]
|
||||
pub fn new(disp: Box<dyn EInkPanel + Send>) -> Self {
|
||||
let (tx, rx) = mpsc::channel(2);
|
||||
|
@ -86,7 +86,7 @@ pub async fn display_task(
|
|||
/// API routes for axum
|
||||
/// Start with the basics: Send an image, crop it, dither, and upload.
|
||||
/// we defer the upload to a separate task.
|
||||
pub fn router() -> Router<Context> {
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/setimage", post(set_image))
|
||||
.route("/preview", post(preview_image))
|
||||
|
@ -149,7 +149,7 @@ where
|
|||
|
||||
#[instrument(skip(ctx))]
|
||||
async fn set_image(
|
||||
State(ctx): State<Context>,
|
||||
State(ctx): State<AppState>,
|
||||
img_req: ImageRequest,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
// FIXME: resize image to 800x480 to match the eink panel.
|
||||
|
|
|
@ -80,7 +80,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
Command::Serve => {
|
||||
let display = FakeEInk {};
|
||||
|
||||
let ctx = api::Context::new(Box::new(display));
|
||||
let ctx = api::AppState::new(Box::new(display));
|
||||
|
||||
let app = api::router().with_state(ctx);
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
|
||||
|
|
Loading…
Reference in a new issue