Qt6 reading JPEG encoded as Progressive using more memory (sometimes till out-of-memory) than Baseline
-
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 = memory (MB)
- calculation for above image :-
7360 * 4912 * 3 * 1 = 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 = 1.7MB
- so expect it to maximum consume 1.7MB and not 103MB
- may be i am wrong about it but this is just little knowledge of how i have it
- From my understanding that memory used during decompression (using IDCT shrink-on-load from libjpeg (link)) should be :-
- 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
- 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 ?
-
Please provide a small jpeg and create a bug report. I can only think that libjpeg does either something wrong here or the Qt plugin does not handle a specific combination of parameters correctly.
-
- I added the links to the image in the description above but adding under again :-
- yeah sure i added that as a bug to be checked by the Qt Team :-