1pub mod det;
10pub mod device;
11pub mod formula;
12pub mod formula_enc;
13mod gpu_run;
14pub mod layout;
15pub mod lcnet;
16pub mod math;
17pub mod models;
18pub mod pdf;
19pub mod pipeline;
20pub mod rec;
21mod script;
22
23pub use device::{Device, DeviceStatus, ModelChoice, Quality, select_models};
24pub use gpu_run::GpuStats;
25
26#[derive(Debug, Clone)]
28pub struct Image {
29 pub width: usize,
30 pub height: usize,
31 pub channels: usize,
32 pub data: Vec<u8>,
33}
34
35impl Image {
36 #[inline]
38 pub fn at(&self, x: usize, y: usize, c: usize) -> u8 {
39 let c = if self.channels == 1 { 0 } else { c };
40 self.data[(y * self.width + x) * self.channels + c]
41 }
42}
43
44pub type Quad = [(f32, f32); 4];
46
47#[derive(Debug, Clone)]
49pub struct Line {
50 pub quad: Quad,
51 pub text: String,
52 pub score: f32,
54 pub formula: bool,
56}
57
58pub(crate) fn read_json(dir: &std::path::Path, name: &str) -> Result<serde_json::Value, String> {
60 let p = dir.join(name);
61 let s = std::fs::read(&p).map_err(|e| format!("reading {}: {e}", p.display()))?;
62 serde_json::from_slice(&s).map_err(|e| format!("{} is not valid JSON: {e}", p.display()))
63}
64
65pub(crate) fn read_weights(dir: &std::path::Path) -> Result<pagesift_infer::Weights, String> {
67 let p = dir.join("model.safetensors");
68 let b = std::fs::read(&p).map_err(|e| format!("reading {}: {e}", p.display()))?;
69 pagesift_infer::Weights::from_bytes(&b)
70}