From 0abb4c2096234cbbde7d9dc442c16010845d1032 Mon Sep 17 00:00:00 2001 From: Ethan Simmons Date: Sun, 5 May 2024 18:34:57 -0500 Subject: [PATCH] Change errors to anyhow, fix improperly oriented tensor --- src/process_point.rs | 8 +++----- src/wayland/app.rs | 9 +++------ src/wayland/builder.rs | 4 +++- src/wayland/draw.rs | 7 +++++-- src/wayland/ui.rs | 5 +++++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/process_point.rs b/src/process_point.rs index 3f83764..620ec2c 100644 --- a/src/process_point.rs +++ b/src/process_point.rs @@ -1,24 +1,22 @@ use std::fs; -use std::error::Error; use std::time::Instant; use rten_tensor::{NdTensor, AsView}; use rten::Model; use ocrs::{OcrEngine, OcrEngineParams}; -pub fn print_words(image: NdTensor) -> Result<(), Box> { +pub fn print_words(image: NdTensor) -> anyhow::Result<()> { let begin = Instant::now(); - println!("{:#?}", begin.elapsed()); - let begin = Instant::now(); ocr(image).unwrap(); + println!("{:#?}", begin.elapsed()); Ok(()) } -fn ocr(data: NdTensor) -> Result<(), Box> { +fn ocr(data: NdTensor) -> anyhow::Result<()> { let detection_model_data = fs::read("text-detection.rten")?; let rec_model_data = fs::read("text-recognition.rten")?; diff --git a/src/wayland/app.rs b/src/wayland/app.rs index 111d8b1..d08ce1a 100644 --- a/src/wayland/app.rs +++ b/src/wayland/app.rs @@ -31,13 +31,10 @@ use wayland_client::{ }; use std::time::Duration; - -use rten_tensor::NdTensor; - -use anyhow::Result; +use anyhow; use crate::wayland::{ - draw::{DrawPath, Draw}, + draw::DrawPath, builder::{TextAreaBuilder, DrawAreaBuilder, ButtonBuilder}, ui::{self, Widget, ButtonType}, Position, @@ -71,7 +68,7 @@ pub(crate) struct SimpleWindow { } impl SimpleWindow { - pub(crate) fn run() -> Result<()> { + pub(crate) fn run() -> anyhow::Result<()> { let conn = Connection::connect_to_env()?; let (globals, event_queue) = registry_queue_init(&conn)?; diff --git a/src/wayland/builder.rs b/src/wayland/builder.rs index 6ab1635..d5e5aa4 100644 --- a/src/wayland/builder.rs +++ b/src/wayland/builder.rs @@ -37,7 +37,7 @@ impl<'a> TextAreaBuilder { self.position = Some(Position::new(x, y)) } - + #[allow(unused)] pub(super) fn colors(&mut self, colors: TextAreaColors) { self.colors = Some(colors); } @@ -88,6 +88,7 @@ impl ButtonBuilder { self.position = Some(Position::new(x as f32, y as f32)) } + #[allow(unused)] pub(super) fn colors(&mut self, colors: ButtonColors) { self.colors = Some(colors) } @@ -156,6 +157,7 @@ impl DrawAreaBuilder { self.position = Some(Position::new(x, y)) } + #[allow(unused)] pub(super) fn colors(&mut self, colors: DrawAreaColors) { self.colors = Some(colors) } diff --git a/src/wayland/draw.rs b/src/wayland/draw.rs index f44bfdc..7c43755 100644 --- a/src/wayland/draw.rs +++ b/src/wayland/draw.rs @@ -2,7 +2,6 @@ use raqote::{DrawTarget, Color, StrokeStyle, PathBuilder, Source, DrawOptions, S use rten_tensor::NdTensor; use crate::wayland::Position; -use crate::process_point::print_words; pub(super) trait Draw { fn render(&self, area: &mut DrawTarget<&mut [u32]>); @@ -35,6 +34,7 @@ impl DrawPath { } } + #[allow(unused)] pub(crate) fn into_iter(self) -> std::vec::IntoIter { self.paths.into_iter() } @@ -43,11 +43,13 @@ impl DrawPath { self.paths.iter() } + #[allow(unused)] pub(crate) fn iter_mut(&mut self) -> std::slice::IterMut { self.paths.iter_mut() } } +#[allow(unused)] pub(super) struct DrawAreaColors { background_color: Color, drawing_color: Color, @@ -83,6 +85,7 @@ impl DrawArea { Source::Solid(self.colors.drawing_color.into()) } + #[allow(unused)] fn border_source(&self) -> Source { Source::Solid(self.colors.border_color.into()) } @@ -161,7 +164,7 @@ impl From<&DrawArea> for NdTensor { image::ImageFormat::Png ).unwrap(); - NdTensor::from_data([1, draw_area.width as usize, draw_area.height as usize], data) + NdTensor::from_data([1, draw_area.height, draw_area.width], data) } } diff --git a/src/wayland/ui.rs b/src/wayland/ui.rs index 374058e..4411ac4 100644 --- a/src/wayland/ui.rs +++ b/src/wayland/ui.rs @@ -5,6 +5,7 @@ use crate::wayland::{ Position, }; +#[allow(unused)] pub(super) struct UIColors { draw_area: Color, button: Color, @@ -87,6 +88,7 @@ impl Window { } +#[allow(unused)] pub(super) struct ButtonColors { background: Color, border: Color, @@ -109,6 +111,7 @@ pub(super) enum ButtonType { Enter, } +#[allow(unused)] pub(super) struct Button { pub(super) button_type: ButtonType, pub(super) width: usize, @@ -141,6 +144,7 @@ impl Draw for Button { } } +#[allow(unused)] pub(super) struct TextAreaColors { pub(super) background: Color, pub(super) text: Color, @@ -164,6 +168,7 @@ pub(super) struct TextArea { } impl TextArea { + #[allow(unused)] pub(super) fn text_source(&self) -> Source { Source::Solid(self.colors.text.into()) }