Compare commits

...

2 commits

Author SHA1 Message Date
Champlin, Saji 59886a80fd adjust benchmark sample count
All checks were successful
cargo_test_bench / Run Tests (push) Successful in 1m29s
cargo_test_bench / Run Benchmarks (push) Successful in 2m27s
2024-07-31 13:31:44 -05:00
Champlin, Saji 2c34886dc5 rename api context 2024-07-31 13:31:35 -05:00
3 changed files with 9 additions and 6 deletions

View file

@ -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(

View file

@ -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.

View file

@ -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?;