Skip to content

Commit

Permalink
Compression belongs to Options
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Dec 20, 2024
1 parent eed8ce1 commit 38afa36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ pub struct Info<'a> {

pub frame_control: Option<FrameControl>,
pub animation_control: Option<AnimationControl>,
pub compression: Compression,
/// Gamma of the source system.
/// Set by both `gAMA` as well as to a replacement by `sRGB` chunk.
pub source_gamma: Option<ScaledFloat>,
Expand Down Expand Up @@ -643,9 +642,6 @@ impl Default for Info<'_> {
pixel_dims: None,
frame_control: None,
animation_control: None,
// Default to `deflate::Compression::Fast` and `filter::FilterType::Sub`
// to maintain backward compatible output.
compression: Compression::Fast,
source_gamma: None,
source_chromaticities: None,
srgb: None,
Expand Down
11 changes: 5 additions & 6 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ struct Options {
adaptive_filter: AdaptiveFilterType,
sep_def_img: bool,
validate_sequence: bool,
compression: Compression,
}

impl<'a, W: Write> Encoder<'a, W> {
Expand Down Expand Up @@ -313,7 +314,7 @@ impl<'a, W: Write> Encoder<'a, W> {
/// Accepts a `Compression` or any type that can transform into a `Compression`. Notably `deflate::Compression` and
/// `deflate::CompressionOptions` which "just work".
pub fn set_compression(&mut self, compression: Compression) {
self.info.compression = compression;
self.options.compression = compression;
}

/// Set the used filter type.
Expand Down Expand Up @@ -495,7 +496,6 @@ struct PartialInfo {
color_type: ColorType,
frame_control: Option<FrameControl>,
animation_control: Option<AnimationControl>,
compression: Compression,
has_palette: bool,
}

Expand All @@ -508,7 +508,6 @@ impl PartialInfo {
color_type: info.color_type,
frame_control: info.frame_control,
animation_control: info.animation_control,
compression: info.compression,
has_palette: info.palette.is_some(),
}
}
Expand Down Expand Up @@ -787,7 +786,7 @@ impl<W: Write> Writer<W> {
let filter_method = self.options.filter;
let adaptive_method = self.options.adaptive_filter;

let zlib_encoded = match self.info.compression {
let zlib_encoded = match self.options.compression {
Compression::Fast => {
let mut compressor = fdeflate::Compressor::new(std::io::Cursor::new(Vec::new()))?;

Expand Down Expand Up @@ -832,7 +831,7 @@ impl<W: Write> Writer<W> {
_ => {
let mut current = vec![0; in_len];

let mut zlib = ZlibEncoder::new(Vec::new(), self.info.compression.to_options());
let mut zlib = ZlibEncoder::new(Vec::new(), self.options.compression.to_options());
for line in data.chunks(in_len) {
let filter_type = filter(
filter_method,
Expand Down Expand Up @@ -1417,13 +1416,13 @@ impl<'a, W: Write> StreamWriter<'a, W> {
width,
height,
frame_control: fctl,
compression,
..
} = writer.info;

let bpp = writer.info.bpp_in_prediction();
let in_len = writer.info.raw_row_length() - 1;
let filter = writer.options.filter;
let compression = writer.options.compression;
let adaptive_filter = writer.options.adaptive_filter;
let prev_buf = vec![0; in_len];
let curr_buf = vec![0; in_len];
Expand Down

0 comments on commit 38afa36

Please sign in to comment.