From 5a60b9bddef2363814e087507a97466f8fa2fb67 Mon Sep 17 00:00:00 2001 From: caleb Date: Sun, 15 Oct 2023 13:59:47 +0300 Subject: [PATCH] core/options: Add option for the png decoder to strip 16 bit images into 8 bit images Signed-off-by: caleb --- zune-core/src/options/decoder.rs | 72 +++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/zune-core/src/options/decoder.rs b/zune-core/src/options/decoder.rs index f1e666c5..e1191ab5 100644 --- a/zune-core/src/options/decoder.rs +++ b/zune-core/src/options/decoder.rs @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 @@ -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