summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2009-05-27 07:44:14 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2009-05-27 09:57:22 (GMT)
commitcfdfdf079c4a2095c588dd8af8403c74d2cfa37a (patch)
treec4297c67413f25bf4e125258467f694e175972d9 /src/gui/image
parent80bc757b56953065fafeffe6c4b8fb6fbca287ac (diff)
downloadQt-cfdfdf079c4a2095c588dd8af8403c74d2cfa37a.zip
Qt-cfdfdf079c4a2095c588dd8af8403c74d2cfa37a.tar.gz
Qt-cfdfdf079c4a2095c588dd8af8403c74d2cfa37a.tar.bz2
Optimized QRasterPixmapData::metric.
Avoid needless DPI calculations when not needed, and simplify the DPI calculations to the point where most of the operations disappear. Also avoid calling QImage::metric() so that we don't need to go through two switch statements and an extra function call just to get the width of a pixmap. Reviewed-by: Trond
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qpixmap_raster.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index b5556cd..29e4f3f 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -322,25 +322,36 @@ extern int qt_defaultDpiY();
int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
{
+ QImageData *d = image.d;
+ if (!d)
+ return 0;
+
// override the image dpi with the screen dpi when rendering to a pixmap
- const int dpmX = qRound(qt_defaultDpiX() * 100 / qreal(2.54));
- const int dpmY = qRound(qt_defaultDpiY() * 100 / qreal(2.54));
switch (metric) {
+ case QPaintDevice::PdmWidth:
+ return d->width;
+ case QPaintDevice::PdmHeight:
+ return d->height;
case QPaintDevice::PdmWidthMM:
- return qRound(image.width() * 1000 / dpmX);
+ return qRound(d->width * 25.4 / qt_defaultDpiX());
case QPaintDevice::PdmHeightMM:
- return qRound(image.height() * 1000 / dpmY);
- case QPaintDevice::PdmDpiX:
- return qRound(dpmX * qreal(0.0254));
- case QPaintDevice::PdmDpiY:
- return qRound(dpmY * qreal(0.0254));
+ return qRound(d->width * 25.4 / qt_defaultDpiY());
+ case QPaintDevice::PdmNumColors:
+ return d->colortable.size();
+ case QPaintDevice::PdmDepth:
+ return d->depth;
+ case QPaintDevice::PdmDpiX: // fall-through
case QPaintDevice::PdmPhysicalDpiX:
- return qRound(dpmX * qreal(0.0254));
+ return qt_defaultDpiX();
+ case QPaintDevice::PdmDpiY: // fall-through
case QPaintDevice::PdmPhysicalDpiY:
- return qRound(dpmY * qreal(0.0254));
+ return qt_defaultDpiY();
default:
- return image.metric(metric);
+ qWarning("QRasterPixmapData::metric(): Unhandled metric type %d", metric);
+ break;
}
+
+ return 0;
}
QImage* QRasterPixmapData::buffer()