fastpack_compress/compressor.rs
1use fastpack_core::types::config::PackMode;
2use image::DynamicImage;
3
4use crate::error::CompressError;
5
6/// Input to a compression backend.
7pub struct CompressInput<'a> {
8 /// The composited atlas image to encode.
9 pub image: &'a DynamicImage,
10
11 /// Controls the compression effort level.
12 pub pack_mode: PackMode,
13
14 /// Quality for lossy codecs (0–100). Ignored by lossless encoders (PNG).
15 pub quality: u8,
16}
17
18/// Raw encoded bytes returned by a compression backend.
19pub struct CompressOutput {
20 /// The encoded file bytes ready to write to disk.
21 pub data: Vec<u8>,
22}
23
24/// Common interface for all image compression backends.
25pub trait Compressor: Send + Sync {
26 /// Encode the atlas image and return the file bytes.
27 fn compress(&self, input: &CompressInput<'_>) -> Result<CompressOutput, CompressError>;
28
29 /// Short identifier matching `OutputConfig::texture_format` (e.g. `"png"`).
30 fn format_id(&self) -> &'static str;
31
32 /// File extension for the texture output, without leading dot (e.g. `"png"`).
33 fn file_extension(&self) -> &'static str;
34}