pub mod det;
pub mod device;
pub mod formula;
pub mod formula_enc;
mod gpu_run;
pub mod layout;
pub mod lcnet;
pub mod math;
pub mod models;
pub mod pdf;
pub mod pipeline;
pub mod rec;
mod script;
pub use device::{Device, DeviceStatus, ModelChoice, Quality, select_models};
pub use gpu_run::GpuStats;
#[derive(Debug, Clone)]
pub struct Image {
pub width: usize,
pub height: usize,
pub channels: usize,
pub data: Vec<u8>,
}
impl Image {
#[inline]
pub fn at(&self, x: usize, y: usize, c: usize) -> u8 {
let c = if self.channels == 1 { 0 } else { c };
self.data[(y * self.width + x) * self.channels + c]
}
}
pub type Quad = [(f32, f32); 4];
#[derive(Debug, Clone)]
pub struct Line {
pub quad: Quad,
pub text: String,
pub score: f32,
pub formula: bool,
}
pub(crate) fn read_json(dir: &std::path::Path, name: &str) -> Result<serde_json::Value, String> {
let p = dir.join(name);
let s = std::fs::read(&p).map_err(|e| format!("reading {}: {e}", p.display()))?;
serde_json::from_slice(&s).map_err(|e| format!("{} is not valid JSON: {e}", p.display()))
}
pub(crate) fn read_weights(dir: &std::path::Path) -> Result<pagesift_infer::Weights, String> {
let p = dir.join("model.safetensors");
let b = std::fs::read(&p).map_err(|e| format!("reading {}: {e}", p.display()))?;
pagesift_infer::Weights::from_bytes(&b)
}