Wire progressive JPEG, AVIF speed, and custom per-format quality to encoder
- Add EncoderOptions struct with progressive_jpeg and avif_speed fields - Pass encoder options through ProcessingJob to PipelineExecutor - mozjpeg set_progressive_mode() called when progressive JPEG enabled - AVIF encoder speed now configurable (was hardcoded to 6) - run_processing uses CompressConfig::Custom when user overrides preset defaults - Executor properly handles AVIF quality and PNG level in Custom mode
This commit is contained in:
@@ -4,11 +4,28 @@ use std::path::Path;
|
||||
use crate::error::{PixstripError, Result};
|
||||
use crate::types::{ImageFormat, QualityPreset};
|
||||
|
||||
pub struct OutputEncoder;
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct EncoderOptions {
|
||||
pub progressive_jpeg: bool,
|
||||
pub avif_speed: u8,
|
||||
}
|
||||
|
||||
pub struct OutputEncoder {
|
||||
pub options: EncoderOptions,
|
||||
}
|
||||
|
||||
impl OutputEncoder {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
Self {
|
||||
options: EncoderOptions {
|
||||
progressive_jpeg: false,
|
||||
avif_speed: 6,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_options(options: EncoderOptions) -> Self {
|
||||
Self { options }
|
||||
}
|
||||
|
||||
pub fn encode(
|
||||
@@ -60,6 +77,9 @@ impl OutputEncoder {
|
||||
let mut comp = mozjpeg::Compress::new(mozjpeg::ColorSpace::JCS_RGB);
|
||||
comp.set_size(width, height);
|
||||
comp.set_quality(quality as f32);
|
||||
if self.options.progressive_jpeg {
|
||||
comp.set_progressive_mode();
|
||||
}
|
||||
|
||||
let mut output = Vec::new();
|
||||
let mut started = comp.start_compress(&mut output).map_err(|e| PixstripError::Processing {
|
||||
@@ -121,9 +141,10 @@ impl OutputEncoder {
|
||||
let mut buf = Vec::new();
|
||||
let cursor = Cursor::new(&mut buf);
|
||||
let rgba = img.to_rgba8();
|
||||
let speed = self.options.avif_speed.clamp(1, 10);
|
||||
let encoder = image::codecs::avif::AvifEncoder::new_with_speed_quality(
|
||||
cursor,
|
||||
6,
|
||||
speed,
|
||||
quality,
|
||||
);
|
||||
image::ImageEncoder::write_image(
|
||||
|
||||
Reference in New Issue
Block a user