1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-25 10:48:04 +02:00

Added support for Geotagged JPEG files

This commit is contained in:
2019-03-13 00:25:46 +01:00
parent 78d07cc166
commit bf845a4a65
8 changed files with 285 additions and 45 deletions

View File

@ -1,12 +1,8 @@
#include "common/tifffile.h"
#include "pcs.h"
#include "tifffile.h"
#include "geotiff.h"
#define TIFF_DOUBLE 12
#define TIFF_SHORT 3
#define TIFF_LONG 4
#define ModelPixelScaleTag 33550
#define ModelTiepointTag 33922
#define ModelTransformationTag 34264
@ -126,7 +122,7 @@ bool GeoTIFF::readEntry(TIFFFile &file, Ctx &ctx) const
return true;
}
bool GeoTIFF::readIFD(TIFFFile &file, quint32 &offset, Ctx &ctx) const
bool GeoTIFF::readIFD(TIFFFile &file, quint32 offset, Ctx &ctx) const
{
quint16 count;
@ -139,9 +135,6 @@ bool GeoTIFF::readIFD(TIFFFile &file, quint32 &offset, Ctx &ctx) const
if (!readEntry(file, ctx))
return false;
if (!file.readValue(offset))
return false;
return true;
}
@ -475,27 +468,26 @@ bool GeoTIFF::geographicModel(QMap<quint16, Value> &kv)
GeoTIFF::GeoTIFF(const QString &path)
{
quint32 ifd;
QList<ReferencePoint> points;
PointD scale;
QMap<quint16, Value> kv;
Ctx ctx;
TIFFFile file;
file.setFileName(path);
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
_errorString = QString("Error opening TIFF file: %1")
.arg(file.errorString());
return;
}
if (!file.readHeader(ifd)) {
_errorString = "Invalid TIFF header";
_errorString = file.errorString();
return;
}
while (ifd) {
if (!readIFD(file, ifd, ctx)) {
TIFFFile tiff(&file);
if (!tiff.isValid()) {
_errorString = "Not a TIFF file";
return;
}
for (quint32 ifd = tiff.ifd(); ifd; ) {
if (!readIFD(tiff, ifd, ctx) || !tiff.readValue(ifd)) {
_errorString = "Invalid IFD";
return;
}
@ -507,19 +499,19 @@ GeoTIFF::GeoTIFF(const QString &path)
}
if (ctx.scale) {
if (!readScale(file, ctx.scale, scale)) {
if (!readScale(tiff, ctx.scale, scale)) {
_errorString = "Error reading model pixel scale";
return;
}
}
if (ctx.tiepoints) {
if (!readTiepoints(file, ctx.tiepoints, ctx.tiepointCount, points)) {
if (!readTiepoints(tiff, ctx.tiepoints, ctx.tiepointCount, points)) {
_errorString = "Error reading raster->model tiepoint pairs";
return;
}
}
if (!readKeys(file, ctx, kv)) {
if (!readKeys(tiff, ctx, kv)) {
_errorString = "Error reading Geo key/value";
return;
}
@ -547,7 +539,7 @@ GeoTIFF::GeoTIFF(const QString &path)
_transform = Transform(points);
else if (ctx.matrix) {
double matrix[16];
if (!readMatrix(file, ctx.matrix, matrix)) {
if (!readMatrix(tiff, ctx.matrix, matrix)) {
_errorString = "Error reading transformation matrix";
return;
}

View File

@ -39,7 +39,7 @@ private:
};
bool readEntry(TIFFFile &file, Ctx &ctx) const;
bool readIFD(TIFFFile &file, quint32 &offset, Ctx &ctx) const;
bool readIFD(TIFFFile &file, quint32 offset, Ctx &ctx) const;
bool readScale(TIFFFile &file, quint32 offset, PointD &scale) const;
bool readTiepoints(TIFFFile &file, quint32 offset, quint32 count,
QList<ReferencePoint> &points) const;

View File

@ -1,28 +0,0 @@
#include "tifffile.h"
#define TIFF_II 0x4949
#define TIFF_MM 0x4D4D
#define TIFF_MAGIC 42
bool TIFFFile::readHeader(quint32 &ifd)
{
quint16 endian, magic;
if (QFile::read((char*)&endian, sizeof(endian)) < (qint64)sizeof(endian))
return false;
if (endian == TIFF_II)
_be = false;
else if (endian == TIFF_MM)
_be = true;
else
return false;
if (!readValue(magic))
return false;
if (magic != TIFF_MAGIC)
return false;
if (!readValue(ifd))
return false;
return true;
}

View File

@ -1,43 +0,0 @@
#ifndef TIFFFILE_H
#define TIFFFILE_H
#include <QFile>
#include <QtEndian>
class TIFFFile : public QFile
{
public:
TIFFFile() : _be(false) {}
TIFFFile(const QString &path) : QFile(path), _be(false) {}
bool readHeader(quint32 &ifd);
template<class T> bool readValue(T &val)
{
T data;
if (QFile::read((char*)&data, sizeof(T)) < (qint64)sizeof(T))
return false;
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
if (_be)
val = data;
else {
for (size_t i = 0; i < sizeof(T); i++)
*((char *)&val + i) = *((char*)&data + sizeof(T) - 1 - i);
}
#else
if (_be) {
for (size_t i = 0; i < sizeof(T); i++)
*((char *)&val + i) = *((char*)&data + sizeof(T) - 1 - i);
} else
val = data;
#endif
return true;
}
private:
bool _be;
};
#endif // TIFFFILE_H