Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-140124

Qt6 reading JPEG encoded as Progressive using more memory (sometimes till out-of-memory) than Baseline

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: P2: Important P2: Important
    • None
    • 6.8.2
    • Image formats
    • None
    • Yocto arm64 imx8
    • Linux/Yocto

      Hey all,

      • We are using Qt6 on an embedded device (ARM64 imx8) with limited RAM (total about 400MB).
      • While loading JPEG image Iink which is encoded as progressive in an Qt Widget application :-
          bailey.jpg: JPEG image data, JFIF standard 1.02, resolution (DPI), density 72x72, segment length 16, progressive, precision 8, 7360x4912, frames 3
           
      • using QImageReader::read to read image scaled to 30px x 30px instead of 7360px x4912px :-
        // Reader for JPEG
        QImageReader reader("bailey.jpg");
        reader.setScaledSize(QSize(30, 30)); // directly decode at 30x30
        
        QImage image30x30;
        if (!reader.read(&image30x30))
        
        { qWarning() << "Failed to load:" << reader.errorString(); return -1; }
            
      • Even though a scaled down version of image e.g 30px x 30px is asked
        • From my understanding that memory used during decompression (using IDCT shrink-on-load from libjpeg (link) should be :-
          (width × height × channels × bytes per channel) / (1024 * 1024) = memory (MB)
              
        • calculation for above image :-
          7360 * 4912 * 3 * 1 / (1024*1024) = 103MB
              
        • But since we are asking for a scaled version so libjpeg would scale to 1/8 as its theoratical limit
          (7360 / 8 ) * (614 / 8) * 3 * 1  / (1024* 1024) = 1.7MB
              
        • so expect it to maximum consume 1.7MB and not 103MB
        • then using some resampling algorithm like Lanczos filter from 920px * 614px, it is converted to 30px * 30px
        • may be i am wrong about it but this is just little knowledge of how i have it
      • During the read, it seems like it is loading whole image that it causes out-of-memory for kernel to kill the application eventually.
      • The default QJpegPlugin linked is libjpeg :-
        $ ldd /usr/lib/plugins/imageformats/libqjpeg.so 
            ...
        libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x0000ffffbd350000)
            
      • But when same image was converted from progressive to baseline (Iink)) then it did use some memory but not till out-of-memory
        bailey.jpg: JPEG image data, JFIF standard 1.02, resolution (DPI), density 72x72, segment length 16, baseline, precision 8, 7360x4912, components 3
            
      • May be not directly related to Magickimage also had some issue with libjpeg :- link
      • Therefore the question is :-
        • does QJpegPlugin and eventually libjpeg can they handle progressive images efficiently or is it a bug or limitation of library itself?
        • or should we convert JPEG to baselines as it seems to respect the downscaling and not load whole image into memory ?

        1. bailey.jpg
          bailey.jpg
          4.75 MB
        2. bailey_baseline.jpg
          bailey_baseline.jpg
          4.91 MB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            vgt Eirik Aavitsland
            wahabshah Wahab Shah
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes