Repository: image-rs/image (language: rust)

Issue:
Disable strict mode on JPEG decoder
I would like to be able to decode JPEG images using HDR functionality to embed "multiple images" without errors.

My specific use case for this functionality is decoding images captured from Instagram for resizing.

This is more generally applicable to JPEG decoding. See https://github.com/etemesi254/zune-image/issues/167.

## Draft

The default JPEG decoder settings should not be strict (in this regard).


Discussion / hints:
Could you make a PR? This wasn't an intentional choice when switching to zune-jpeg, there was just a lot of code movement leading up to `0.25` and it got overlooked. In general, we try to default to accepting images with errors within reason/when other decoders do. 
Of course, thanks for the quick response! Will follow up soon.

Fix patch:
diff --git a/src/codecs/jpeg/decoder.rs b/src/codecs/jpeg/decoder.rs
index 895b471e91..adb6751d88 100644
--- a/src/codecs/jpeg/decoder.rs
+++ b/src/codecs/jpeg/decoder.rs
@@ -29,6 +29,7 @@ impl<R: BufRead + Seek> JpegDecoder<R> {
         let mut r = r;
         r.read_to_end(&mut input)?;
         let options = zune_core::options::DecoderOptions::default()
+            .set_strict_mode(false)
             .set_max_width(usize::MAX)
             .set_max_height(usize::MAX);
         let mut decoder = zune_jpeg::JpegDecoder::new_with_options(input.as_slice(), options);
@@ -133,8 +134,9 @@ fn new_zune_decoder(
     limits: Limits,
 ) -> zune_jpeg::JpegDecoder<&[u8]> {
     let target_color_space = to_supported_color_space(orig_color_space);
-    let mut options =
-        zune_core::options::DecoderOptions::default().jpeg_set_out_colorspace(target_color_space);
+    let mut options = zune_core::options::DecoderOptions::default()
+        .jpeg_set_out_colorspace(target_color_space)
+        .set_strict_mode(false);
     options = options.set_max_width(match limits.max_image_width {
         Some(max_width) => max_width as usize, // u32 to usize never truncates
         None => usize::MAX,


Test patch: