Settings - read - JPEG - add Jpegli decoder

Ideas for improvements and requests for new features in XnView MP

Moderator: xnview

User avatar
user0
XnThusiast
Posts: 3042
Joined: Sat May 09, 2015 9:37 am

Settings - read - JPEG - add Jpegli decoder

Post by user0 »

XnViewMP 1.11.2
Windows11 (25H2), display resolution 3840x2160, dpi scale 150%


Settings - Formats - Read
request to add Jpegli decoder by WinnieW deserves more attention

Jpegli decodes standard JPEG files with slightly better visual quality than traditional decoders by prioritizing mathematical accuracy and psychovisual fidelity over sheer processing speed. By processing the image data using 32-bit floating-point precision, it minimizes rounding errors, which subtly smooths gradients, sharpens edges, and reduces chroma artifacts in areas like skin tones and saturated colors (especially in low-quality JPEGs).

However, while this high-fidelity reconstruction reduces banding and ringing, the decoder remains fully JPEG-compatible and cannot magically restore permanently lost details or completely eliminate heavy compression blocks.
https://github.com/google/jpegli#decoder-improvements wrote:Decoder improvements
  • Support for 16-bit unsigned and 32-bit floating point output buffers.
  • Non-zero DCT coefficients are dequantized to the expectation value of their respective quantization intervals assuming a Laplacian distribution of the original unquantized DCT coefficients.
  • After dequantization, inverse DCT, chroma upsampling and color space conversions are all done in floating point precision, the conversion to integer samples happens only in the final output phase (unless output to floating point was requested).


Suggestion
  • add Jpegli decoder
    - add 'Use Jpegli' checkbox in Settings>Formats>Read>JPEG (like in Write>JPEG)
    - maybe with bitdepth (per channel) combobox [8, 16]



Test
  • Test image
    testorig.jpg (4:2:0) from jpegsr10.zip (ijg.org)
  • Decoders
    • libjpeg-turbo
      • commands

        Code: Select all

        djpeg.exe -png -outfile testorig_djpeg_dct-int.png testorig.jpg
        djpeg.exe -dct float -png -outfile testorig_djpeg_dct-float.png testorig.jpg
        
      • switches (usage.txt)
        There are few decode switches available, but only one can potentially improve default decode quality: dct

        Code: Select all

                -dct int        Use accurate integer DCT method (default).
                -dct fast       Use less accurate integer DCT method [legacy feature].
                                When the Independent JPEG Group's software was first
                                released in 1991, the decompression time for a
                                1-megapixel JPEG image on a mainstream PC was measured
                                in minutes.  Thus, the fast integer DCT algorithm
                                provided noticeable performance benefits.  On modern
                                CPUs running libjpeg-turbo, however, the decompression
                                time for a 1-megapixel JPEG image is measured in
                                milliseconds, and thus the performance benefits of the
                                fast algorithm are much less noticeable.  On modern
                                x86/x86-64 CPUs that support AVX2 instructions, the
                                fast and int methods have similar performance.  On
                                other types of CPUs, the fast method is generally about
                                5-15% faster than the int method.
        
                                If the JPEG image was compressed using a quality level
                                of 85 or below, then there should be little or no
                                perceptible quality difference between the two
                                algorithms.  When decompressing images that were
                                compressed using quality levels above 85, however, the
                                difference between the fast and int methods becomes
                                more pronounced.  With images compressed using
                                quality=97, for instance, the fast method incurs
                                generally about a 4-6 dB loss in PSNR relative to the
                                int method, but this can be larger for some images.  If
                                you can avoid it, do not use the fast method when
                                decompressing images that were compressed using quality
                                levels above 97.  The algorithm often degenerates for
                                such images and can actually produce a more lossy
                                output image than if the JPEG image had been compressed
                                using lower quality levels.
                -dct float      Use floating-point DCT method [legacy feature].
                                The float method does not produce significantly more
                                accurate results than the int method, and it is much
                                slower.  The float method may also give different
                                results on different machines due to varying roundoff
                                behavior, whereas the integer methods should give the
                                same results on all machines.
        
    • jpegli* (libjxl)
      *project migrated to separate repo, but binaries available only in the parent repo so far
      • commands

        Code: Select all

        djpegli.exe testorig.jpg testorig_djpegli_bitdepth8.png
        djpegli.exe testorig.jpg testorig_djpegli_bitdepth16.png --bitdepth=16
        
      • switches (help from binary)
        There is only one switch available that can potentially improve default decode quality: bitdepth

        Code: Select all

        Usage: D:\jpegli\bin\djpegli.exe INPUT OUTPUT [OPTIONS...]
         INPUT
            The JPEG input file.
         OUTPUT
            The output can be PPM, PNM, PFM, PAM, PGX, PNG, APNG, JPEG
         --disable_output
            No output file will be written (for benchmarking)
         --bitdepth=8|16
            Sets the output bitdepth for integer based formats, can be 8 (default) or 16. Has no impact on PFM output.
         --num_reps=N
            Sets the number of times to decompress the image. Used for benchmarking, the default is 1.
         --quiet
            Silence output (except for errors).
        
         -h, --help
            Prints this help message. All options are shown above.
        
  • Comparison
    • djpeg -dct int|float
      difference is marginal, so default '-dct int' is used
    • djpeg vs djpegli
      difference is visible, jpegli looks better
    • djpegli --bitdepth=8|16
      there is diff, but it is not visually noticeable in the test image
    comparison_jpeg_vs_jpegli.png
    test_jpeg_vs_jpegli.zip






Related
You do not have the required permissions to view the files attached to this post.
Kadet
Posts: 272
Joined: Thu Oct 20, 2022 7:23 pm

Re: Settings - read - JPEG - add Jpegli decoder

Post by Kadet »

+1 🙏
WinnieW
Posts: 55
Joined: Thu Jan 17, 2013 2:28 pm

Re: Settings - read - JPEG - add Jpegli decoder

Post by WinnieW »

I think I'd be wise to implement JPEGLi decoding when it's finalized.
Right now jpegli is still under development and not final, and remaining bugs are likely.