From 8423fc1230380e6bb39b863faa1c7fbdce448198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 28 Nov 2020 20:34:25 +0100 Subject: [PATCH] Remove the untested and broken NOS stuff --- src/map/bsbmap.cpp | 44 ++++++++++++++------------------------------ src/map/bsbmap.h | 3 +-- src/map/maplist.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/map/bsbmap.cpp b/src/map/bsbmap.cpp index b4b88760..b262a96e 100644 --- a/src/map/bsbmap.cpp +++ b/src/map/bsbmap.cpp @@ -11,15 +11,6 @@ #define LINE_LIMIT 1024 -static inline bool getChar(QFile &file, bool mangled, char *c) -{ - if (!file.getChar(c)) - return false; - if (mangled) - *c = (char)((int)(*c - 9) & 0xFF); - return true; -} - static inline bool isEOH(const QByteArray &line) { return (line.size() >= 2 && line.at(line.size() - 2) == 0x1A @@ -36,11 +27,11 @@ static inline QByteArray hdrData(const QByteArray &line) return line.right(line.size() - 4); } -static bool readHeaderLine(QFile &file, bool mangled, QByteArray &line) +static bool readHeaderLine(QFile &file, QByteArray &line) { char c; - while (getChar(file, mangled, &c) && line.size() < LINE_LIMIT) { + while (file.getChar(&c) && line.size() < LINE_LIMIT) { if (c == '\0') { line.append(c); return true; @@ -50,11 +41,11 @@ static bool readHeaderLine(QFile &file, bool mangled, QByteArray &line) continue; if (c == '\n') { - if (!getChar(file, mangled, &c)) + if (!file.getChar(&c)) return false; if (c == ' ') { do { - if (!getChar(file, mangled, &c)) + if (!file.getChar(&c)) return false; } while (c == ' '); line.append(','); @@ -136,11 +127,7 @@ bool BSBMap::parseBSB(const QByteArray &line) if (sv.size() == 2) { w = sv.at(0).toUInt(&wok); h = sv.at(1).toUInt(&hok); - } else if (sv.size() == 4) { - w = sv.at(2).toUInt(&wok); - h = sv.at(3).toUInt(&hok); } - if (!wok || !hok || !w || !h) { _errorString = "Invalid BSB RA field"; return false; @@ -225,24 +212,23 @@ bool BSBMap::parseRGB(const QByteArray &line) return false; } -bool BSBMap::readHeader(QFile &file, bool mangled) +bool BSBMap::readHeader(QFile &file) { QByteArray line; QString datum, proj; double params[9]; QList points; - while (readHeaderLine(file, mangled, line)) { + while (readHeaderLine(file, line)) { if (isEOH(line)) { if (!_size.isValid() || !_projection.isValid()) { - _errorString = "Invalid KAP/NOS file header"; + _errorString = "Invalid KAP file header"; return false; } return createTransform(points); } - if ((isType(line, "BSB/") || isType(line, "NOS/")) - && !parseBSB(hdrData(line))) + if (isType(line, "BSB/") && !parseBSB(hdrData(line))) return false; else if (isType(line, "KNP/") && !parseKNP(hdrData(line), datum, proj, params[0])) @@ -262,7 +248,7 @@ bool BSBMap::readHeader(QFile &file, bool mangled) line.clear(); } - _errorString = "Not a KAP/NOS file"; + _errorString = "Not a KAP file"; return false; } @@ -324,12 +310,12 @@ bool BSBMap::readRow(QFile &file, char bits, uchar *buf) static const char mask[] = {0, 63, 31, 15, 7, 3, 1, 0}; do { - if (!getChar(file, _mangled, &c)) + if (!file.getChar(&c)) return false; } while ((uchar)c >= 0x80); while (true) { - if (!getChar(file, _mangled, &c)) + if (!file.getChar(&c)) return false; if (c == '\0') break; @@ -338,7 +324,7 @@ bool BSBMap::readRow(QFile &file, char bits, uchar *buf) multiplier = c & mask[(int)bits]; while ((uchar)c >= 0x80) { - if (!getChar(file, _mangled, &c)) + if (!file.getChar(&c)) return false; multiplier = (multiplier << 7) + (c & 0x7f); } @@ -363,7 +349,7 @@ QImage BSBMap::readImage() if (!file.open(QIODevice::ReadOnly)) return QImage(); file.seek(_dataOffset); - if (!getChar(file, _mangled, &bits)) + if (!file.getChar(&bits)) return QImage(); QImage img(_size, QImage::Format_Indexed8); @@ -382,7 +368,6 @@ BSBMap::BSBMap(const QString &fileName, QObject *parent) : Map(parent), _fileName(fileName), _img(0), _ratio(1.0), _dataOffset(-1), _valid(false) { - QFileInfo fi(fileName); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { @@ -391,8 +376,7 @@ BSBMap::BSBMap(const QString &fileName, QObject *parent) } _palette.resize(256); - _mangled = !fi.suffix().compare("no1", Qt::CaseInsensitive); - if (!readHeader(file, _mangled)) + if (!readHeader(file)) return; _dataOffset = file.pos(); diff --git a/src/map/bsbmap.h b/src/map/bsbmap.h index 933d53c5..f27820de 100644 --- a/src/map/bsbmap.h +++ b/src/map/bsbmap.h @@ -39,7 +39,7 @@ private: bool parseKNQ(const QByteArray &line, double params[9]); bool parseREF(const QByteArray &line, QList &points); bool parseRGB(const QByteArray &line); - bool readHeader(QFile &file, bool mangled); + bool readHeader(QFile &file); bool createProjection(const QString &datum, const QString &proj, double params[9]); bool createTransform(const QList &points); @@ -54,7 +54,6 @@ private: QSize _size; qreal _ratio; qint64 _dataOffset; - bool _mangled; QVector _palette; bool _valid; diff --git a/src/map/maplist.cpp b/src/map/maplist.cpp index cdd25a62..451e8c00 100644 --- a/src/map/maplist.cpp +++ b/src/map/maplist.cpp @@ -46,7 +46,7 @@ Map *MapList::loadFile(const QString &path, QString &errorString, map = new IMGMap(path); else if (suffix == "map" || suffix == "tar") map = new OziMap(path); - else if (suffix == "kap" || suffix == "no1" || suffix == "nos") + else if (suffix == "kap") map = new BSBMap(path); if (map && map->isValid()) @@ -109,7 +109,7 @@ QString MapList::formats() + qApp->translate("MapList", "Garmin IMG maps") + " (*.gmap *.gmapi *.img *.xml);;" + qApp->translate("MapList", "Garmin JNX maps") + " (*.jnx);;" - + qApp->translate("MapList", "BSB nautical charts") + " (*.kap *.no1 *.nos);;" + + qApp->translate("MapList", "BSB nautical charts") + " (*.kap);;" + qApp->translate("MapList", "OziExplorer maps") + " (*.map);;" + qApp->translate("MapList", "MBTiles maps") + " (*.mbtiles);;" + qApp->translate("MapList", "TrekBuddy maps/atlases") + " (*.tar *.tba);;" @@ -122,7 +122,7 @@ QStringList MapList::filter() { QStringList filter; filter << "*.gmap" << "*.gmapi" << "*.img" << "*.jnx" << "*.kap" << "*.map" - << "*.mbtiles" << "*.no1" << "*.nos" << "*.rmap" << "*.rtmap" << "*.tar" - << "*.tba" << "*.tif" << "*.tiff" << "*.xml"; + << "*.mbtiles" << "*.rmap" << "*.rtmap" << "*.tar" << "*.tba" << "*.tif" + << "*.tiff" << "*.xml"; return filter; }