<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qt6 reading JPEG encoded as Progressive using more memory (sometimes till out-of-memory) than Baseline]]></title><description><![CDATA[<p dir="auto">Hey all,</p>
<ul>
<li>We are using Qt6 on an embedded device (ARM64 imx8) with limited RAM (total about 400MB).</li>
<li>While loading JPEG image (<a href="https://gist.github.com/wahabshah/a36cd8524e098a58e3909cc5c3592436#jpeg-progressive" target="_blank" rel="noopener noreferrer nofollow ugc">Iink</a>) which is encoded as progressive in an Qt Widget application :-<pre><code>bailey.jpg: JPEG image data, JFIF standard 1.02, resolution (DPI), density 72x72, segment length 16, progressive, precision 8, 7360x4912, frames 3
</code></pre>
</li>
<li>using <strong>QImageReader::read</strong> to read image scaled to <em>30px x 30px</em> instead of <em>7360px x4912px</em> :-<pre><code> // Reader for JPEG
 QImageReader reader("bailey.jpg");
 reader.setScaledSize(QSize(30, 30)); // directly decode at 30x30

 QImage image30x30;
 if (!reader.read(&amp;image30x30)) {
     qWarning() &lt;&lt; "Failed to load:" &lt;&lt; reader.errorString();
     return -1;
 }

</code></pre>
</li>
<li>Even though a scaled down version of image e.g <em>30px x 30px</em> is asked
<ul>
<li>From my understanding that memory used during decompression (using IDCT  shrink-on-load from libjpeg (<a href="https://libjpeg-turbo.org/About/SmartScale" target="_blank" rel="noopener noreferrer nofollow ugc">link</a>)) should be :-<pre><code class="language-bash">width × height × channels × bytes per channel = memory (MB)
</code></pre>
</li>
<li>calculation for above image  :-<pre><code class="language-bash">7360 * 4912 * 3 * 1  = 103MB
</code></pre>
</li>
<li>But since we are asking for a scaled version so libjpeg would scale to 1/8 as its theoratical limit<pre><code class="language-bash">(7360 / 8 ) * (614 / 8) * 3 * 1 = 1.7MB
</code></pre>
</li>
<li>so expect it to maximum consume 1.7MB and not 103MB</li>
<li>may be i am wrong about it but this is just little knowledge of how i have it</li>
</ul>
</li>
<li>During the read, it seems like it is loading whole image that it causes out-of-memory for kernel to kill the application eventually.</li>
<li>The default QJpegPlugin linked is libjpeg :-<pre><code>$ ldd /usr/lib/plugins/imageformats/libqjpeg.so 
...
libjpeg.so.62 =&gt; /usr/lib/libjpeg.so.62 (0x0000ffffbd350000)
</code></pre>
</li>
<li>But when same image was converted from progressive to baseline  (<a href="https://gist.github.com/wahabshah/a36cd8524e098a58e3909cc5c3592436#jpeg-baseline" target="_blank" rel="noopener noreferrer nofollow ugc">Iink</a>)  then it did use some memory but not till out-of-memory<pre><code>bailey.jpg: JPEG image data, JFIF standard 1.02, resolution (DPI), density 72x72, segment length 16, baseline, precision 8, 7360x4912, components 3
</code></pre>
</li>
<li>Therefore the question is :-
<ul>
<li>does QJpegPlugin and eventually libjpeg can they handle progressive images efficiently or is it a bug or limitation of library itself?</li>
<li>or should we convert JPEG to baselines as it seems to respect the downscaling and not load whole image into memory ?</li>
</ul>
</li>
</ul>
]]></description><link>https://forum.qt.io/topic/163221/qt6-reading-jpeg-encoded-as-progressive-using-more-memory-sometimes-till-out-of-memory-than-baseline</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 23:02:57 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163221.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 12 Sep 2025 08:07:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Qt6 reading JPEG encoded as Progressive using more memory (sometimes till out-of-memory) than Baseline on Fri, 12 Sep 2025 08:59:10 GMT]]></title><description><![CDATA[<ul>
<li>I added the links to the image in the description above but adding under again  :-
<ul>
<li><a href="https://gist.github.com/wahabshah/a36cd8524e098a58e3909cc5c3592436#jpeg-progressive" target="_blank" rel="noopener noreferrer nofollow ugc">https://gist.github.com/wahabshah/a36cd8524e098a58e3909cc5c3592436#jpeg-progressive</a></li>
<li><a href="https://gist.github.com/wahabshah/a36cd8524e098a58e3909cc5c3592436#jpeg-baseline" target="_blank" rel="noopener noreferrer nofollow ugc">https://gist.github.com/wahabshah/a36cd8524e098a58e3909cc5c3592436#jpeg-baseline</a></li>
</ul>
</li>
<li>yeah sure i added that as a bug to be checked by the Qt Team :-
<ul>
<li><a href="https://bugreports.qt.io/browse/QTBUG-140124" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-140124</a></li>
</ul>
</li>
</ul>
]]></description><link>https://forum.qt.io/post/831504</link><guid isPermaLink="true">https://forum.qt.io/post/831504</guid><dc:creator><![CDATA[wahabshah]]></dc:creator><pubDate>Fri, 12 Sep 2025 08:59:10 GMT</pubDate></item><item><title><![CDATA[Reply to Qt6 reading JPEG encoded as Progressive using more memory (sometimes till out-of-memory) than Baseline on Fri, 12 Sep 2025 08:12:45 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
]]></description><link>https://forum.qt.io/post/831503</link><guid isPermaLink="true">https://forum.qt.io/post/831503</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 12 Sep 2025 08:12:45 GMT</pubDate></item></channel></rss>