mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 11:39:16 +02:00
Added support for Geotagged JPEG files
This commit is contained in:
26
src/common/tifffile.cpp
Normal file
26
src/common/tifffile.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "tifffile.h"
|
||||
|
||||
#define TIFF_II 0x4949
|
||||
#define TIFF_MM 0x4D4D
|
||||
#define TIFF_MAGIC 42
|
||||
|
||||
TIFFFile::TIFFFile(QIODevice *device) : _device(device), _ifd(0)
|
||||
{
|
||||
quint16 endian, magic;
|
||||
|
||||
if (_device->read((char*)&endian, sizeof(endian)) < (qint64)sizeof(endian))
|
||||
return;
|
||||
if (endian == TIFF_II)
|
||||
_be = false;
|
||||
else if (endian == TIFF_MM)
|
||||
_be = true;
|
||||
else
|
||||
return;
|
||||
|
||||
if (!readValue(magic))
|
||||
return;
|
||||
if (magic != TIFF_MAGIC)
|
||||
return;
|
||||
if (!readValue(_ifd))
|
||||
return;
|
||||
}
|
55
src/common/tifffile.h
Normal file
55
src/common/tifffile.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef TIFFFILE_H
|
||||
#define TIFFFILE_H
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QtEndian>
|
||||
|
||||
#define TIFF_BYTE 1
|
||||
#define TIFF_ASCII 2
|
||||
#define TIFF_SHORT 3
|
||||
#define TIFF_LONG 4
|
||||
#define TIFF_RATIONAL 5
|
||||
#define TIFF_DOUBLE 12
|
||||
|
||||
class TIFFFile
|
||||
{
|
||||
public:
|
||||
TIFFFile(QIODevice *device);
|
||||
|
||||
bool isValid() const {return _ifd != 0;}
|
||||
quint32 ifd() const {return _ifd;}
|
||||
|
||||
bool seek(qint64 pos) {return _device->seek(pos);}
|
||||
qint64 pos() const {return _device->pos();}
|
||||
template<class T> bool readValue(T &val)
|
||||
{
|
||||
T data;
|
||||
|
||||
if (_device->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:
|
||||
QIODevice *_device;
|
||||
bool _be;
|
||||
quint32 _ifd;
|
||||
};
|
||||
|
||||
#endif // TIFFFILE_H
|
Reference in New Issue
Block a user