1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Compare commits

..

No commits in common. "947d2d62b377939d81a786a7c5ade43602303043" and "6ef66442601b4cf986db95a8a5f6b5d9044fce16" have entirely different histories.

13 changed files with 56 additions and 188 deletions

View File

@ -139,7 +139,6 @@ HEADERS += src/common/config.h \
src/map/encjob.h \ src/map/encjob.h \
src/map/encmap.h \ src/map/encmap.h \
src/map/ENC/iso8211.h \ src/map/ENC/iso8211.h \
src/map/filter.h \
src/map/gemfmap.h \ src/map/gemfmap.h \
src/map/gmifile.h \ src/map/gmifile.h \
src/map/oruxmap.h \ src/map/oruxmap.h \
@ -357,7 +356,6 @@ SOURCES += src/main.cpp \
src/map/encatlas.cpp \ src/map/encatlas.cpp \
src/map/encmap.cpp \ src/map/encmap.cpp \
src/map/ENC/iso8211.cpp \ src/map/ENC/iso8211.cpp \
src/map/filter.cpp \
src/map/gemfmap.cpp \ src/map/gemfmap.cpp \
src/map/gmifile.cpp \ src/map/gmifile.cpp \
src/map/oruxmap.cpp \ src/map/oruxmap.cpp \

View File

@ -138,11 +138,16 @@ QList<const DEMTile*> DEMFile::tiles(const RectC &rect, int level) const
int DEMFile::level(const Zoom &zoom) const int DEMFile::level(const Zoom &zoom) const
{ {
/*
for (int i = 0; i < _levels.size(); i++) for (int i = 0; i < _levels.size(); i++)
if (_levels.at(i).level >= zoom.level()) if (_levels.at(i).level >= zoom.level())
return i; return i;
return _levels.size() - 1; return _levels.size() - 1;
*/
Q_UNUSED(zoom);
return 0;
} }
MapData::Elevation *DEMFile::elevations(Handle &hdl, int level, MapData::Elevation *DEMFile::elevations(Handle &hdl, int level,
@ -165,7 +170,7 @@ MapData::Elevation *DEMFile::elevations(Handle &hdl, int level,
quint16 lim = limit(tile, l.factor); quint16 lim = limit(tile, l.factor);
Matrix<qint16> m(tile->h(), tile->w()); Matrix<qint16> m(tile->h(), tile->w());
JLS jls(tile->diff(), l.factor); JLS jls(tile->diff(), l.factor, tile->w());
if (jls.decode(this, hdl, m)) { if (jls.decode(this, hdl, m)) {
for (int i = 0; i < m.size(); i++) { for (int i = 0; i < m.size(); i++) {
if (m.at(i) >= lim) if (m.at(i) >= lim)

View File

@ -21,8 +21,10 @@ static const int J[] = {
4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15
}; };
JLS::JLS(quint16 diff, quint16 factor) JLS::JLS(quint16 diff, quint16 factor, quint16 cols)
: _data((cols + 3) * 2)
{ {
_w = cols;
_maxval = diff; _maxval = diff;
_near = factor; _near = factor;
@ -31,6 +33,21 @@ JLS::JLS(quint16 diff, quint16 factor)
quint8 bpp = max(2, ceil(log2(_maxval + 1))); quint8 bpp = max(2, ceil(log2(_maxval + 1)));
quint8 LIMIT = 2 * (bpp + max(8, bpp)); quint8 LIMIT = 2 * (bpp + max(8, bpp));
_limit = LIMIT - _qbpp - 1; _limit = LIMIT - _qbpp - 1;
_runIndex = 0;
_rk = 0;
_rg = 1;
_lrk = 0;
quint16 A = max(2, (_range + 32) / 64);
for (int i = 0; i < 4; i++) {
_a[i] = A;
_b[i] = 0;
_n[i] = 1;
}
_last = _data.data();
_current = _data.data() + (cols + 3);
} }
bool JLS::processRunMode(BitStream &bs, quint16 col, quint16 &samples) bool JLS::processRunMode(BitStream &bs, quint16 col, quint16 &samples)
@ -291,28 +308,11 @@ bool JLS::decode(const SubFile *file, SubFile::Handle &hdl, Matrix<qint16> &img)
if (!bs.init()) if (!bs.init())
return false; return false;
_w = img.w();
_data = QVector<quint16>((_w + 3) * 2);
_last = _data.data();
_current = _data.data() + (_w + 3);
_runIndex = 0;
_rk = 0;
_rg = 1;
_lrk = 0;
quint16 A = max(2, (_range + 32) / 64);
for (int i = 0; i < 4; i++) {
_a[i] = A;
_b[i] = 0;
_n[i] = 1;
}
for (int i = 0; i < img.h(); i++) { for (int i = 0; i < img.h(); i++) {
if (!readLine(bs)) if (!readLine(bs))
return false; return false;
memcpy(&img.at(i, 0), _current + 1, _w * sizeof(quint16)); memcpy(&img.at(i, 0), _current + 1, img.w() * sizeof(quint16));
quint16 *tmp = _last; quint16 *tmp = _last;
_last = _current; _last = _current;

View File

@ -10,7 +10,7 @@ namespace IMG {
class JLS class JLS
{ {
public: public:
JLS(quint16 diff, quint16 factor); JLS(quint16 diff, quint16 factor, quint16 cols);
bool decode(const SubFile *file, SubFile::Handle &hdl, Matrix<qint16> &img); bool decode(const SubFile *file, SubFile::Handle &hdl, Matrix<qint16> &img);
@ -36,7 +36,7 @@ private:
_value <<= bits; _value <<= bits;
_shift += bits; _shift += bits;
while (-1 < (qint8)_shift) { while (-1 < (char)_shift) {
if (!_file->readByte(_hdl, &data)) if (!_file->readByte(_hdl, &data))
return false; return false;
@ -60,8 +60,10 @@ private:
bool processRunMode(BitStream &bs, quint16 col, quint16 &samples); bool processRunMode(BitStream &bs, quint16 col, quint16 &samples);
bool decodeError(BitStream &bs, quint8 limit, quint8 k, uint &MErrval); bool decodeError(BitStream &bs, quint8 limit, quint8 k, uint &MErrval);
quint16 _w;
quint16 _maxval; quint16 _maxval;
quint16 _near; quint16 _near;
quint16 _range; quint16 _range;
quint8 _qbpp; quint8 _qbpp;
quint8 _limit; quint8 _limit;
@ -74,7 +76,6 @@ private:
qint16 _b[4]; qint16 _b[4];
quint8 _lrk; quint8 _lrk;
quint16 _w;
QVector<quint16> _data; QVector<quint16> _data;
quint16 *_current; quint16 *_current;
quint16 *_last; quint16 *_last;

View File

@ -7,7 +7,6 @@
#include "map/bitmapline.h" #include "map/bitmapline.h"
#include "map/rectd.h" #include "map/rectd.h"
#include "map/hillshading.h" #include "map/hillshading.h"
#include "map/filter.h"
#include "style.h" #include "style.h"
#include "lblfile.h" #include "lblfile.h"
#include "dem.h" #include "dem.h"
@ -29,7 +28,6 @@ using namespace IMG;
#define ROAD 0 #define ROAD 0
#define WATER 1 #define WATER 1
#define BLUR_RADIUS 3
#define DELTA 0.05 /* DEM3 resolution in degrees */ #define DELTA 0.05 /* DEM3 resolution in degrees */
static const QColor textColor(Qt::black); static const QColor textColor(Qt::black);
@ -455,15 +453,15 @@ void RasterTile::fetchData(QList<MapData::Poly> &polygons,
_data->points(pointRectD.toRectC(_proj, 20), _zoom, &points); _data->points(pointRectD.toRectC(_proj, 20), _zoom, &points);
} }
MatrixD RasterTile::elevation(int extend) const MatrixD RasterTile::elevation() const
{ {
MatrixD m(_rect.height() + 2 * extend, _rect.width() + 2 * extend); MatrixD m(_rect.height() + 2, _rect.width() + 2);
QVector<Coordinates> ll; QVector<Coordinates> ll;
int left = _rect.left() - extend; int left = _rect.left() - 1;
int right = _rect.right() + extend; int right = _rect.right() + 1;
int top = _rect.top() - extend; int top = _rect.top() - 1;
int bottom = _rect.bottom() + extend; int bottom = _rect.bottom() + 1;
ll.reserve(m.w() * m.h()); ll.reserve(m.w() * m.h());
for (int y = top; y <= bottom; y++) for (int y = top; y <= bottom; y++)
@ -498,11 +496,9 @@ MatrixD RasterTile::elevation(int extend) const
void RasterTile::drawHillShading(QPainter *painter) const void RasterTile::drawHillShading(QPainter *painter) const
{ {
if (_hillShading && _zoom >= 18 && _zoom <= 24) { if (_hillShading && _zoom >= 18 && _zoom <= 24)
MatrixD dem(Filter::blur(elevation(BLUR_RADIUS), BLUR_RADIUS)); painter->drawImage(_rect.x(), _rect.y(),
QImage img(HillShading::render(dem, BLUR_RADIUS)); HillShading::render(elevation()));
painter->drawImage(_rect.x(), _rect.y(), img);
}
} }
void RasterTile::render() void RasterTile::render()

View File

@ -75,7 +75,7 @@ private:
const QFont *poiFont(Style::FontSize size = Style::Normal, const QFont *poiFont(Style::FontSize size = Style::Normal,
int zoom = -1, bool extended = false) const; int zoom = -1, bool extended = false) const;
MatrixD elevation(int extend) const; MatrixD elevation() const;
Projection _proj; Projection _proj;
Transform _transform; Transform _transform;

View File

@ -1,114 +0,0 @@
#include <cmath>
#include "filter.h"
static QVector<int> boxesForGauss(double sigma, int n)
{
double wIdeal = sqrt((12 * sigma * sigma / n) + 1);
int wl = floor(wIdeal);
if (wl % 2 == 0)
wl--;
int wu = wl + 2;
double mIdeal = (12 * sigma*sigma - n * wl * wl - 4 * n * wl - 3 * n)
/ (-4 * wl - 4);
int m = round(mIdeal);
QVector<int> sizes(n);
for (int i = 0; i < n; i++)
sizes[i] = i < m ? wl : wu;
return sizes;
}
static void boxBlurH4(const MatrixD &src, MatrixD &dst, int r)
{
double iarr = 1.0 / (r + r + 1);
for (int i = 0; i < src.h(); i++) {
int ti = i * src.w(), li = ti, ri = ti + r;
double fv = src.at(ti);
double lv = src.at(ti + src.w() - 1);
double val = (r + 1) * fv;
for (int j = 0; j < r; j++)
val += src.at(ti + j);
for (int j = 0; j <= r; j++) {
val += src.at(ri++) - fv;
dst.at(ti++) = val * iarr;
}
for (int j = r + 1; j < src.w() - r; j++) {
val += src.at(ri++) - src.at(li++);
dst.at(ti++) = val * iarr;
}
for (int j = src.w() - r; j < src.w(); j++) {
val += lv - src.at(li++);
dst.at(ti++) = val * iarr;
}
}
}
static void boxBlurT4(const MatrixD &src, MatrixD &dst, int r)
{
double iarr = 1.0 / (r + r + 1);
for (int i = 0; i < src.w(); i++) {
int ti = i, li = ti, ri = ti + r * src.w();
double fv = src.at(ti);
double lv = src.at(ti + src.w() * (src.h() - 1));
double val = (r + 1) * fv;
for (int j = 0; j < r; j++)
val += src.at(ti + j * src.w());
for (int j = 0; j <= r; j++) {
val += src.at(ri) - fv;
dst.at(ti) = val * iarr;
ri += src.w(); ti += src.w();
}
for (int j = r + 1; j < src.h() - r; j++) {
val += src.at(ri) - src.at(li);
dst.at(ti) = val * iarr;
li += src.w(); ri += src.w(); ti += src.w();
}
for (int j = src.h() - r; j < src.h(); j++) {
val += lv - src.at(li);
dst.at(ti) = val * iarr;
li += src.w(); ti += src.w();
}
}
}
static void boxBlur4(MatrixD &src, MatrixD &dst, int r)
{
for (int i = 0; i < src.size(); i++)
dst.at(i) = src.at(i);
boxBlurH4(dst, src, r);
boxBlurT4(src, dst, r);
}
static void gaussBlur4(MatrixD &src, MatrixD &dst, int r)
{
QVector<int> bxs(boxesForGauss(r, 3));
boxBlur4(src, dst, (bxs.at(0) - 1) / 2);
boxBlur4(dst, src, (bxs.at(1) - 1) / 2);
boxBlur4(src, dst, (bxs.at(2) - 1) / 2);
}
MatrixD Filter::blur(const MatrixD &m, int radius)
{
MatrixD src(m);
MatrixD dst(m.h(), m.w());
for (int i = 0; i < m.size(); i++)
if (std::isnan(m.at(i)))
src.at(i) = -500;
gaussBlur4(src, dst, radius);
for (int i = 0; i < dst.size(); i++)
if (std::isnan(m.at(i)))
dst.at(i) = NAN;
return dst;
}

View File

@ -1,11 +0,0 @@
#ifndef FILTER_H
#define FILTER_H
#include "matrix.h"
namespace Filter
{
MatrixD blur(const MatrixD &m, int radius);
}
#endif // FILTER_H

View File

@ -59,11 +59,10 @@ static void getSubmatrix(int x, int y, const MatrixD &m, SubMatrix &sm)
sm.z9 = m.at(bottom, right); sm.z9 = m.at(bottom, right);
} }
QImage HillShading::render(const MatrixD &m, int extend, quint8 alpha, double z, QImage HillShading::render(const MatrixD &m, quint8 alpha, double z,
double azimuth, double elevation) double azimuth, double elevation)
{ {
QImage img(m.w() - 2 * extend, m.h() - 2 * extend, QImage img(m.w() - 2, m.h() - 2, QImage::Format_ARGB32_Premultiplied);
QImage::Format_ARGB32_Premultiplied);
uchar *bits = img.bits(); uchar *bits = img.bits();
int bpl = img.bytesPerLine(); int bpl = img.bytesPerLine();
@ -73,8 +72,8 @@ QImage HillShading::render(const MatrixD &m, int extend, quint8 alpha, double z,
getConstants(azimuth, elevation, c); getConstants(azimuth, elevation, c);
for (int y = extend; y < m.h() - extend; y++) { for (int y = 1; y < m.h() - 1; y++) {
for (int x = extend; x < m.w() - extend; x++) { for (int x = 1; x < m.w() - 1; x++) {
getSubmatrix(x, y, m, sm); getSubmatrix(x, y, m, sm);
getDerivativesHorn(sm, z, d); getDerivativesHorn(sm, z, d);
@ -90,7 +89,7 @@ QImage HillShading::render(const MatrixD &m, int extend, quint8 alpha, double z,
pixel = (alpha - val)<<24; pixel = (alpha - val)<<24;
} }
*(quint32*)(bits + (y - extend) * bpl + (x - extend) * 4) = pixel; *(quint32*)(bits + (y - 1) * bpl + (x - 1) * 4) = pixel;
} }
} }

View File

@ -7,8 +7,8 @@
class HillShading class HillShading
{ {
public: public:
static QImage render(const MatrixD &m, int extend, quint8 alpha = 96, static QImage render(const MatrixD &m, quint8 alpha = 96, double z = 0.3,
double z = 0.3, double azimuth = 315, double elevation = 25); double azimuth = 315, double elevation = 25);
}; };
#endif // HILLSHADING_H #endif // HILLSHADING_H

View File

@ -4,7 +4,6 @@
#include "common/dem.h" #include "common/dem.h"
#include "map/rectd.h" #include "map/rectd.h"
#include "map/hillshading.h" #include "map/hillshading.h"
#include "map/filter.h"
#include "rastertile.h" #include "rastertile.h"
using namespace Mapsforge; using namespace Mapsforge;
@ -13,8 +12,6 @@ using namespace Mapsforge;
#define PATHS_EXTENT 20 #define PATHS_EXTENT 20
#define SEARCH_EXTENT -0.5 #define SEARCH_EXTENT -0.5
#define BLUR_RADIUS 3
static double LIMIT = cos(deg2rad(170)); static double LIMIT = cos(deg2rad(170));
static qreal area(const QPainterPath &polygon) static qreal area(const QPainterPath &polygon)
@ -441,11 +438,9 @@ void RasterTile::drawPaths(QPainter *painter, const QList<MapData::Path> &paths,
painter->setBrush(ri->brush()); painter->setBrush(ri->brush());
painter->drawEllipse(ll2xy(point->coordinates), radius, radius); painter->drawEllipse(ll2xy(point->coordinates), radius, radius);
} else { } else {
if (_hillShading) { if (_hillShading)
MatrixD dem(Filter::blur(elevation(BLUR_RADIUS), BLUR_RADIUS)); painter->drawImage(_rect.x(), _rect.y(),
QImage img(HillShading::render(dem, BLUR_RADIUS)); HillShading::render(elevation()));
painter->drawImage(_rect.x(), _rect.y(), img);
}
} }
} }
} }
@ -476,14 +471,14 @@ void RasterTile::fetchData(QList<MapData::Path> &paths,
_data->points(pointRectD.toRectC(_proj, 20), _zoom, &points); _data->points(pointRectD.toRectC(_proj, 20), _zoom, &points);
} }
MatrixD RasterTile::elevation(int extend) const MatrixD RasterTile::elevation() const
{ {
MatrixD m(_rect.height() + 2 * extend, _rect.width() + 2 * extend); MatrixD m(_rect.height() + 2, _rect.width() + 2);
int left = _rect.left() - extend; int left = _rect.left() - 1;
int right = _rect.right() + extend; int right = _rect.right() + 1;
int top = _rect.top() - extend; int top = _rect.top() - 1;
int bottom = _rect.bottom() + extend; int bottom = _rect.bottom() + 1;
QVector<Coordinates> ll; QVector<Coordinates> ll;
ll.reserve(m.w() * m.h()); ll.reserve(m.w() * m.h());

View File

@ -215,7 +215,7 @@ private:
void drawPaths(QPainter *painter, const QList<MapData::Path> &paths, void drawPaths(QPainter *painter, const QList<MapData::Path> &paths,
const QList<MapData::Point> &points, QVector<PainterPath> &painterPaths); const QList<MapData::Point> &points, QVector<PainterPath> &painterPaths);
MatrixD elevation(int extend) const; MatrixD elevation() const;
Projection _proj; Projection _proj;
Transform _transform; Transform _transform;

View File

@ -15,7 +15,6 @@ public:
int h() const {return _h;} int h() const {return _h;}
int w() const {return _w;} int w() const {return _w;}
const T &at(int n) const {return _m.at(n);}
T &at(int n) {return _m[n];} T &at(int n) {return _m[n];}
T &at(int i, int j) {return _m[_w * i + j];} T &at(int i, int j) {return _m[_w * i + j];}
T const &at(int i, int j) const {return _m.at(_w * i + j);} T const &at(int i, int j) const {return _m.at(_w * i + j);}