From 0a87c06b0d9cda20f2e361d65de865ec13304b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 19 Mar 2021 08:42:20 +0100 Subject: [PATCH] Optimization --- src/map/IMG/lblfile.cpp | 14 +++++++++----- src/map/IMG/lblfile.h | 4 ++-- src/map/IMG/rastertile.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/map/IMG/lblfile.cpp b/src/map/IMG/lblfile.cpp index af93efcc..b4147afa 100644 --- a/src/map/IMG/lblfile.cpp +++ b/src/map/IMG/lblfile.cpp @@ -340,17 +340,21 @@ bool LBLFile::loadRasterTable(Handle &hdl, quint32 offset, quint32 size, return true; } -QImage LBLFile::readImage(Handle &hdl, quint32 id) const +QPixmap LBLFile::image(Handle &hdl, quint32 id) const { + QPixmap pm; + if (id >= _imgCount) - return QImage(); + return pm; if (!seek(hdl, _imgOffset + _rasters[id].offset)) - return QImage(); + return pm; QByteArray ba; ba.resize(_rasters[id].size); if (!read(hdl, ba.data(), _rasters[id].size)) - return QImage(); + return pm; - return QImage::fromData(ba); + pm.loadFromData(ba, "jpeg"); + + return pm; } diff --git a/src/map/IMG/lblfile.h b/src/map/IMG/lblfile.h index b7ed9353..6a41c55b 100644 --- a/src/map/IMG/lblfile.h +++ b/src/map/IMG/lblfile.h @@ -1,7 +1,7 @@ #ifndef LBLFILE_H #define LBLFILE_H -#include +#include #include "common/textcodec.h" #include "subfile.h" #include "label.h" @@ -33,7 +33,7 @@ public: bool capitalize = true) const; quint8 imageIdSize() const {return _imgOffsetIdSize;} - QImage readImage(Handle &hdl, quint32 id) const; + QPixmap image(Handle &hdl, quint32 id) const; private: struct Image { diff --git a/src/map/IMG/rastertile.cpp b/src/map/IMG/rastertile.cpp index 8a984882..2f3e0d41 100644 --- a/src/map/IMG/rastertile.cpp +++ b/src/map/IMG/rastertile.cpp @@ -226,13 +226,13 @@ void RasterTile::drawPolygons(QPainter *painter) QSize size(QRectF(tl, br).toRect().size()); SubFile::Handle hdl(poly.raster.lbl()); - QImage img(poly.raster.lbl()->readImage(hdl, poly.raster.id())); - qreal sx = (qreal)size.width() / (qreal)img.width(); - qreal sy = (qreal)size.height() / (qreal)img.height(); + QPixmap pm(poly.raster.lbl()->image(hdl, poly.raster.id())); + qreal sx = (qreal)size.width() / (qreal)pm.width(); + qreal sy = (qreal)size.height() / (qreal)pm.height(); painter->save(); painter->scale(sx, sy); - painter->drawImage(QPointF(tl.x() / sx, tl.y() / sy), img); + painter->drawPixmap(QPointF(tl.x() / sx, tl.y() / sy), pm); painter->restore(); //painter->setPen(Qt::blue);