<div class="gmail_quote">On Fri, Nov 6, 2009 at 10:27 AM, Boudewijn Rempt <span dir="ltr"><<a href="mailto:boud@valdyas.org">boud@valdyas.org</a>></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>
> Here are two patches to fix DPI in krita for jpeg and png. I would<br>
> especially need someone to check units. Currently krita is consistant with<br>
> itself... Would be nice also, if we had the unit of resolution in the UI.<br>
> (and why do I have to divide by 72 ?)<br>
><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 &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->setValue(72.0 * resolution);<br>
doubleResolution->setDecimals(0);<br>
<br clear="all"></blockquote></div><br><br>I wouldn't say it is right to say that "internal resolution" 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'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's define a KisImage point as "ipx" (image pixel)</font> (n<font face="arial,helvetica,sans-serif">ote that this "ipx" are not equivalent to a pixel of viewport)</font><br>
<font face="arial,helvetica,sans-serif"></font></font><br>Let's define a viewport pixel as "vpx" 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 "vpx"es per one pt.<br>
<br>The number of "ipx"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 "ipx"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'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's resolution from pt'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>