image icon indicating copy to clipboard operation
image copied to clipboard

Benchmark error: UnsupportedError { format: Exact(Jpeg), kind: Color(Rgba8) }

Open zamazan4ik opened this issue 1 year ago • 7 comments

Hi!

I observed an error during the library benchmarking.

Expected

The benchmark completes successfully with the documented command.

Actual behaviour

The benchmark fails with the following error:

taskset -c 0 cargo +nightly bench --features=benchmarks

<lines are omitted for clarity>
...
encode-jpeg/zero-Rgb8-file/256
                        time:   [1.2626 ms 1.2630 ms 1.2635 ms]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
Benchmarking encode-jpeg/zero-Rgba8-rawvec/64: Warming up for 3.0000 sthread 'main' panicked at benches/encode.rs:132:41:
called `Result::unwrap()` on an `Err` value: Unsupported(UnsupportedError { format: Exact(Jpeg), kind: Color(Rgba8) })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: bench failed, to rerun pass `--bench encode`

Reproduction steps

  1. Run cargo +nightly bench --features=benchmarks
  2. Wait until the encode-jpeg/zero-Rgba8-rawvec/64 the benchmark will start
  3. Get the error

Environment info:

  • OS: Fedora 39
  • Kernel: 6.8.7
  • Rustc version: 1.80.0-nightly
  • image version: main branch, 5013041c830c2f5aa189cccc7f8902ce22e283c7 commit

zamazan4ik avatar May 04 '24 13:05 zamazan4ik

The JPEG format cannot store an alpha channel. See #2211

Looks like the benchmark needs to be updated to strip the alpha channel or skip those images

fintelia avatar May 04 '24 17:05 fintelia

I am also getting this error when upgrading from 0.24.6 to 0.25.2 on the same image file.

marvin-j97 avatar Oct 06 '24 20:10 marvin-j97

PR welcome!

fintelia avatar Oct 06 '24 20:10 fintelia

fn main() {
    let img = image::open("in.jpg").unwrap();
    println!("Loaded");

    let buffer = image::imageops::resize(&img, 500, 500, image::imageops::FilterType::Lanczos3);
    buffer.save("out.jpg").unwrap(); // <- crashes in .save()
}

So this code works with 0.24.6, but crashes with 0.25.2. Not sure if it happens for every image, but I tried a handful and it crashes everytime.

marvin-j97 avatar Oct 06 '24 22:10 marvin-j97

That's annoying but expected. Calling resize on a DynamicImage produces an RgbaImage due to a quirk of how the GenericImageView trait works. Trying to save an RGBA image as JPEG fails because the JPEG file format cannot store an alpha channel

fintelia avatar Oct 06 '24 22:10 fintelia

+1, any update?

thep0y avatar Oct 11 '24 08:10 thep0y

Status is the same as it was five days ago:

PR welcome!

fintelia avatar Oct 11 '24 15:10 fintelia