<div class="gmail_quote">On Fri, Nov 6, 2009 at 10:27 AM, Boudewijn Rempt <span dir="ltr">&lt;<a href="mailto:boud@valdyas.org">boud@valdyas.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">On Thursday 05 November 2009, Cyrille Berger wrote:<br>
&gt; Here are two patches to fix DPI in krita for jpeg and png. I would<br>
&gt;  especially need someone to check units. Currently krita is consistant with<br>
&gt;  itself... Would be nice also, if we had the unit of resolution in the UI.<br>
&gt;  (and why do I have to divide by 72 ?)<br>
&gt;<br>
<br>
</div></div>It looks like internally, resolution is expressed as a factor of the KOffice<br>
document resolution, which is 72 dpi. For instance:<br>
<br>
QPointF KisImage::documentToPixel(const QPointF &amp;documentCoord) const<br>
{<br>
    return QPointF(documentCoord.x() * xRes(), documentCoord.y() * yRes());<br>
}<br>
<br>
And in the dialogs, we show pixels per inch:<br>
<br>
KisCustomImageWidget:<br>
<br>
    doubleResolution-&gt;setValue(72.0 * resolution);<br>
    doubleResolution-&gt;setDecimals(0);<br>
<br clear="all"></blockquote></div><br><br>I wouldn&#39;t say it is  right to say that &quot;internal resolution&quot; is X dpi due to unit difference.<br><br>Krita works with special points those are neither pixels of the viewport nor pts. One pixel of KisImage has a size. This size is measured in pt&#39;s, (pt is a universal units equal to 1/72 inch).<br>
<br><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">Let&#39;s define a KisImage  point as  &quot;ipx&quot; (image pixel)</font> (n<font face="arial,helvetica,sans-serif">ote that this &quot;ipx&quot; are not equivalent to a pixel of viewport)</font><br>

<font face="arial,helvetica,sans-serif"></font></font><br>Let&#39;s define a viewport pixel as &quot;vpx&quot; that depends on the size of your display (it is calculated using KoDpi in KoZoomHandler)<br><br>KoZoomHandler::m_resolution[XY] stores the number of &quot;vpx&quot;es per one pt.<br>
<br>The number of &quot;ipx&quot;es per one pt is defined by the user and depends on the value of KisImage<br><br>KisImage::[xy]Res stores the number of a &quot;ipx&quot;es per pt.<br><br><font style="font-family: courier new,monospace;" face="courier new,monospace"><br>
                          ipx per inch<br>[</font><font style="font-family: courier new,monospace;" face="courier new,monospace">KisImage::xRes()] =-------------------------<br>                     pt per inch =const=72<br>
<br><br></font> <font style="font-family: courier new,monospace;" face="courier new,monospace">                                   vpx per inch<br>
[</font>KoZoomHandler::m_resolution[XY]<font style="font-family: courier new,monospace;" face="courier new,monospace">] = -------------------------<br>
                               pt per inch =const=72</font><br><br><br><br><br>
JPEG stores it&#39;s resolution in DPIs.<br>
<font face="courier new,monospace">       <br>[dpi]= ipx per inch<br><br></font><font face="courier new,monospace"><font face="arial,helvetica,sans-serif"><br></font> <br><font face="arial,helvetica,sans-serif">This means that you have to translate a unit in the denominator of KisImage&#39;s resolution from pt&#39;s to inches. As this value stands in denominator, you have to do a backward operation:<br>
<br>DPI = INCHES_TO_POINT(</font></font><font style="font-family: courier new,monospace;" face="courier new,monospace">KisImage::xRes());</font><br><font face="courier new,monospace"><br><br><font face="arial,helvetica,sans-serif">You can take a look at how it works in:<br>
<br>krita/ui/canvas/kis_prescaled_projection.cc<br>libs/flake/KoZoomHandler.cc<br>libs/kobase/KoUnit.h</font></font><br><br>More than that, you can activate dbgRender kDegug-messages and KisPrescaledProjection will report you all the interesting information about dpis.<br>
<br><br><br><br>-- <br>Dmitry Kazakov<br>