Skip to content

Commit

Permalink
core/options: Add option for the png decoder to strip 16 bit images i…
Browse files Browse the repository at this point in the history
…nto 8 bit images

Signed-off-by: caleb <[email protected]>
  • Loading branch information
etemesi254 committed Oct 15, 2023
1 parent 2a79ae2 commit 5a60b9b
Showing 1 changed file with 47 additions and 25 deletions.
72 changes: 47 additions & 25 deletions zune-core/src/options/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ fn decoder_strict_mode() -> DecoderFlags {
png_confirm_crc: true,
jpg_error_on_non_conformance: true,

zune_use_unsafe: true,
zune_use_neon: true,
zune_use_avx: true,
zune_use_avx2: true,
zune_use_sse2: true,
zune_use_sse3: true,
zune_use_sse41: true,
png_add_alpha_channel: false
zune_use_unsafe: true,
zune_use_neon: true,
zune_use_avx: true,
zune_use_avx2: true,
zune_use_sse2: true,
zune_use_sse3: true,
zune_use_sse41: true,
png_add_alpha_channel: false,
png_strip_16_bit_to_8_bit: false
}
}

Expand All @@ -40,14 +41,16 @@ fn fast_options() -> DecoderFlags {
png_confirm_crc: false,
jpg_error_on_non_conformance: false,

zune_use_unsafe: true,
zune_use_neon: true,
zune_use_avx: true,
zune_use_avx2: true,
zune_use_sse2: true,
zune_use_sse3: true,
zune_use_sse41: true,
png_add_alpha_channel: false
zune_use_unsafe: true,
zune_use_neon: true,
zune_use_avx: true,
zune_use_avx2: true,
zune_use_sse2: true,
zune_use_sse3: true,
zune_use_sse41: true,

png_add_alpha_channel: false,
png_strip_16_bit_to_8_bit: false
}
}

Expand All @@ -63,14 +66,16 @@ fn cmd_options() -> DecoderFlags {
png_confirm_crc: false,
jpg_error_on_non_conformance: false,

zune_use_unsafe: true,
zune_use_neon: true,
zune_use_avx: true,
zune_use_avx2: true,
zune_use_sse2: true,
zune_use_sse3: true,
zune_use_sse41: true,
png_add_alpha_channel: false
zune_use_unsafe: true,
zune_use_neon: true,
zune_use_avx: true,
zune_use_avx2: true,
zune_use_sse2: true,
zune_use_sse3: true,
zune_use_sse41: true,

png_add_alpha_channel: false,
png_strip_16_bit_to_8_bit: false
}
}

Expand Down Expand Up @@ -106,7 +111,9 @@ pub struct DecoderFlags {
/// Whether the png decoder should add alpha channel where possible.
png_add_alpha_channel: bool,
/// Whether we should use neon instructions where possible.
zune_use_neon: bool
zune_use_neon: bool,
/// Whether the png decoder should strip 16 bit to 8 bit
png_strip_16_bit_to_8_bit: bool
}

/// Decoder options
Expand Down Expand Up @@ -364,6 +371,21 @@ impl DecoderOptions {
pub const fn png_get_add_alpha_channel(&self) -> bool {
self.flags.png_add_alpha_channel
}

/// Whether the png decoder should reduce 16 bit images to 8 bit
/// images implicitly.
///
/// Equivalent to [png::Transformations::STRIP_16](https://docs.rs/png/latest/png/struct.Transformations.html#associatedconstant.STRIP_16)
pub fn png_set_strip_to_8bit(mut self, yes: bool) -> Self {
self.flags.png_strip_16_bit_to_8_bit = yes;
self
}

/// Return a boolean indicating whether the png decoder should reduce
/// 16 bit images to 8 bit images implicitly
pub const fn png_get_strip_to_8bit(&self) -> bool {
self.flags.png_strip_16_bit_to_8_bit
}
}

/// JPEG specific options
Expand Down

0 comments on commit 5a60b9b

Please sign in to comment.