All checks were successful
Build and test / Tests (pull_request) Successful in 1m12s
Checking yaml / Run yamllint (pull_request) Successful in 4s
Build and test / Build AMD64 (pull_request) Successful in 1m3s
Build and test / Generate Documentation (pull_request) Successful in 58s
Checking Renovate configuration / validate (pull_request) Successful in 1m50s
Build and test / Clippy (pull_request) Successful in 1m2s
30 lines
1 KiB
Rust
30 lines
1 KiB
Rust
use anyhow::Result;
|
|
use std::path::Path;
|
|
|
|
use crate::model::Document;
|
|
|
|
// Shared reader logic for CBx (CBZ/CBR) formats
|
|
pub trait CbxReader: Send + Sync {
|
|
// Implementors should return a list of (file_name, jpeg_bytes)
|
|
fn extract_images(&self, input: &Path) -> Result<Vec<(String, Vec<u8>)>>;
|
|
|
|
// Build a Document from extracted JPEG bytes
|
|
fn read_cbx(&self, input: &Path) -> Result<Document> {
|
|
let files = self.extract_images(input)?;
|
|
let mut pages: Vec<crate::model::ImagePage> = Vec::new();
|
|
{
|
|
use rayon::prelude::*;
|
|
files
|
|
.par_iter()
|
|
.map(|(name, data)| crate::model::ImagePage {
|
|
name: name.clone(),
|
|
image: image::load_from_memory(data).expect("Failed to decode image"),
|
|
jpeg_dct: Some(data.clone()),
|
|
})
|
|
.collect_into_vec(&mut pages);
|
|
|
|
pages.par_sort_by_key(|p| p.name.clone());
|
|
}
|
|
Ok(Document::new(pages))
|
|
}
|
|
}
|