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

Remove the untested and broken NOS stuff

This commit is contained in:
Martin Tůma 2020-11-28 20:34:25 +01:00
parent 2431f432d4
commit 8423fc1230
3 changed files with 19 additions and 36 deletions

View File

@ -11,15 +11,6 @@
#define LINE_LIMIT 1024 #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) static inline bool isEOH(const QByteArray &line)
{ {
return (line.size() >= 2 && line.at(line.size() - 2) == 0x1A 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); return line.right(line.size() - 4);
} }
static bool readHeaderLine(QFile &file, bool mangled, QByteArray &line) static bool readHeaderLine(QFile &file, QByteArray &line)
{ {
char c; char c;
while (getChar(file, mangled, &c) && line.size() < LINE_LIMIT) { while (file.getChar(&c) && line.size() < LINE_LIMIT) {
if (c == '\0') { if (c == '\0') {
line.append(c); line.append(c);
return true; return true;
@ -50,11 +41,11 @@ static bool readHeaderLine(QFile &file, bool mangled, QByteArray &line)
continue; continue;
if (c == '\n') { if (c == '\n') {
if (!getChar(file, mangled, &c)) if (!file.getChar(&c))
return false; return false;
if (c == ' ') { if (c == ' ') {
do { do {
if (!getChar(file, mangled, &c)) if (!file.getChar(&c))
return false; return false;
} while (c == ' '); } while (c == ' ');
line.append(','); line.append(',');
@ -136,11 +127,7 @@ bool BSBMap::parseBSB(const QByteArray &line)
if (sv.size() == 2) { if (sv.size() == 2) {
w = sv.at(0).toUInt(&wok); w = sv.at(0).toUInt(&wok);
h = sv.at(1).toUInt(&hok); 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) { if (!wok || !hok || !w || !h) {
_errorString = "Invalid BSB RA field"; _errorString = "Invalid BSB RA field";
return false; return false;
@ -225,24 +212,23 @@ bool BSBMap::parseRGB(const QByteArray &line)
return false; return false;
} }
bool BSBMap::readHeader(QFile &file, bool mangled) bool BSBMap::readHeader(QFile &file)
{ {
QByteArray line; QByteArray line;
QString datum, proj; QString datum, proj;
double params[9]; double params[9];
QList<ReferencePoint> points; QList<ReferencePoint> points;
while (readHeaderLine(file, mangled, line)) { while (readHeaderLine(file, line)) {
if (isEOH(line)) { if (isEOH(line)) {
if (!_size.isValid() || !_projection.isValid()) { if (!_size.isValid() || !_projection.isValid()) {
_errorString = "Invalid KAP/NOS file header"; _errorString = "Invalid KAP file header";
return false; return false;
} }
return createTransform(points); return createTransform(points);
} }
if ((isType(line, "BSB/") || isType(line, "NOS/")) if (isType(line, "BSB/") && !parseBSB(hdrData(line)))
&& !parseBSB(hdrData(line)))
return false; return false;
else if (isType(line, "KNP/") else if (isType(line, "KNP/")
&& !parseKNP(hdrData(line), datum, proj, params[0])) && !parseKNP(hdrData(line), datum, proj, params[0]))
@ -262,7 +248,7 @@ bool BSBMap::readHeader(QFile &file, bool mangled)
line.clear(); line.clear();
} }
_errorString = "Not a KAP/NOS file"; _errorString = "Not a KAP file";
return false; 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}; static const char mask[] = {0, 63, 31, 15, 7, 3, 1, 0};
do { do {
if (!getChar(file, _mangled, &c)) if (!file.getChar(&c))
return false; return false;
} while ((uchar)c >= 0x80); } while ((uchar)c >= 0x80);
while (true) { while (true) {
if (!getChar(file, _mangled, &c)) if (!file.getChar(&c))
return false; return false;
if (c == '\0') if (c == '\0')
break; break;
@ -338,7 +324,7 @@ bool BSBMap::readRow(QFile &file, char bits, uchar *buf)
multiplier = c & mask[(int)bits]; multiplier = c & mask[(int)bits];
while ((uchar)c >= 0x80) { while ((uchar)c >= 0x80) {
if (!getChar(file, _mangled, &c)) if (!file.getChar(&c))
return false; return false;
multiplier = (multiplier << 7) + (c & 0x7f); multiplier = (multiplier << 7) + (c & 0x7f);
} }
@ -363,7 +349,7 @@ QImage BSBMap::readImage()
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
return QImage(); return QImage();
file.seek(_dataOffset); file.seek(_dataOffset);
if (!getChar(file, _mangled, &bits)) if (!file.getChar(&bits))
return QImage(); return QImage();
QImage img(_size, QImage::Format_Indexed8); 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), : Map(parent), _fileName(fileName), _img(0), _ratio(1.0), _dataOffset(-1),
_valid(false) _valid(false)
{ {
QFileInfo fi(fileName);
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
@ -391,8 +376,7 @@ BSBMap::BSBMap(const QString &fileName, QObject *parent)
} }
_palette.resize(256); _palette.resize(256);
_mangled = !fi.suffix().compare("no1", Qt::CaseInsensitive); if (!readHeader(file))
if (!readHeader(file, _mangled))
return; return;
_dataOffset = file.pos(); _dataOffset = file.pos();

View File

@ -39,7 +39,7 @@ private:
bool parseKNQ(const QByteArray &line, double params[9]); bool parseKNQ(const QByteArray &line, double params[9]);
bool parseREF(const QByteArray &line, QList<ReferencePoint> &points); bool parseREF(const QByteArray &line, QList<ReferencePoint> &points);
bool parseRGB(const QByteArray &line); bool parseRGB(const QByteArray &line);
bool readHeader(QFile &file, bool mangled); bool readHeader(QFile &file);
bool createProjection(const QString &datum, const QString &proj, bool createProjection(const QString &datum, const QString &proj,
double params[9]); double params[9]);
bool createTransform(const QList<ReferencePoint> &points); bool createTransform(const QList<ReferencePoint> &points);
@ -54,7 +54,6 @@ private:
QSize _size; QSize _size;
qreal _ratio; qreal _ratio;
qint64 _dataOffset; qint64 _dataOffset;
bool _mangled;
QVector<QRgb> _palette; QVector<QRgb> _palette;
bool _valid; bool _valid;

View File

@ -46,7 +46,7 @@ Map *MapList::loadFile(const QString &path, QString &errorString,
map = new IMGMap(path); map = new IMGMap(path);
else if (suffix == "map" || suffix == "tar") else if (suffix == "map" || suffix == "tar")
map = new OziMap(path); map = new OziMap(path);
else if (suffix == "kap" || suffix == "no1" || suffix == "nos") else if (suffix == "kap")
map = new BSBMap(path); map = new BSBMap(path);
if (map && map->isValid()) if (map && map->isValid())
@ -109,7 +109,7 @@ QString MapList::formats()
+ qApp->translate("MapList", "Garmin IMG maps") + qApp->translate("MapList", "Garmin IMG maps")
+ " (*.gmap *.gmapi *.img *.xml);;" + " (*.gmap *.gmapi *.img *.xml);;"
+ qApp->translate("MapList", "Garmin JNX maps") + " (*.jnx);;" + 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", "OziExplorer maps") + " (*.map);;"
+ qApp->translate("MapList", "MBTiles maps") + " (*.mbtiles);;" + qApp->translate("MapList", "MBTiles maps") + " (*.mbtiles);;"
+ qApp->translate("MapList", "TrekBuddy maps/atlases") + " (*.tar *.tba);;" + qApp->translate("MapList", "TrekBuddy maps/atlases") + " (*.tar *.tba);;"
@ -122,7 +122,7 @@ QStringList MapList::filter()
{ {
QStringList filter; QStringList filter;
filter << "*.gmap" << "*.gmapi" << "*.img" << "*.jnx" << "*.kap" << "*.map" filter << "*.gmap" << "*.gmapi" << "*.img" << "*.jnx" << "*.kap" << "*.map"
<< "*.mbtiles" << "*.no1" << "*.nos" << "*.rmap" << "*.rtmap" << "*.tar" << "*.mbtiles" << "*.rmap" << "*.rtmap" << "*.tar" << "*.tba" << "*.tif"
<< "*.tba" << "*.tif" << "*.tiff" << "*.xml"; << "*.tiff" << "*.xml";
return filter; return filter;
} }