Optimization
[GPXSee.git] / src / map / geotiffmap.cpp
blob6d139f0dbce5c268eadda1ba816d0928dfc700d9
1 #include <QPainter>
2 #include <QImageReader>
3 #include "common/util.h"
4 #include "geotiff.h"
5 #include "image.h"
6 #include "geotiffmap.h"
9 GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
10 : Map(fileName, parent), _img(0), _ratio(1.0), _valid(false)
12 QImageReader ir(fileName);
13 if (!ir.canRead()) {
14 _errorString = "Unsupported/invalid image file";
15 return;
17 _size = ir.size();
19 GeoTIFF gt(fileName);
20 if (!gt.isValid()) {
21 _errorString = gt.errorString();
22 return;
23 } else {
24 _projection = gt.projection();
25 _transform = gt.transform();
28 _valid = true;
31 GeoTIFFMap::~GeoTIFFMap()
33 delete _img;
36 QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
38 return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
41 Coordinates GeoTIFFMap::xy2ll(const QPointF &p)
43 return _projection.xy2ll(_transform.img2proj(p * _ratio));
46 QRectF GeoTIFFMap::bounds()
48 return QRectF(QPointF(0, 0), _size / _ratio);
51 void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
53 if (_img)
54 _img->draw(painter, rect, flags);
57 void GeoTIFFMap::load(const Projection &in, const Projection &out,
58 qreal deviceRatio, bool hidpi)
60 Q_UNUSED(in);
61 Q_UNUSED(out);
63 _ratio = hidpi ? deviceRatio : 1.0;
65 _img = new Image(path());
66 if (_img)
67 _img->setDevicePixelRatio(_ratio);
70 void GeoTIFFMap::unload()
72 delete _img;
73 _img = 0;
76 Map *GeoTIFFMap::create(const QString &path, bool *isDir)
78 if (isDir)
79 *isDir = false;
81 return new GeoTIFFMap(path);