1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-26 04:35:54 +01:00
GPXSee/src/common/tifffile.h

59 lines
1.1 KiB
C
Raw Normal View History

2018-01-08 23:47:45 +01:00
#ifndef TIFFFILE_H
#define TIFFFILE_H
2019-03-13 00:25:46 +01:00
#include <QIODevice>
2018-01-08 23:47:45 +01:00
#include <QtEndian>
2019-03-13 00:25:46 +01:00
#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
2018-01-08 23:47:45 +01:00
{
public:
2019-03-13 00:25:46 +01:00
TIFFFile(QIODevice *device);
bool isValid() const {return _ifd != 0;}
quint32 ifd() const {return _ifd;}
2018-01-08 23:47:45 +01:00
bool seek(qint64 pos) {return _device->seek(_offset + pos);}
qint64 pos() const {return _offset + _device->pos();}
QByteArray read(qint64 maxSize) {return _device->read(maxSize);}
2018-01-08 23:47:45 +01:00
template<class T> bool readValue(T &val)
{
T data;
2019-03-13 00:25:46 +01:00
if (_device->read((char*)&data, sizeof(T)) < (qint64)sizeof(T))
2018-01-08 23:47:45 +01:00
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
2018-03-21 18:52:57 +01:00
return true;
}
2018-01-08 23:47:45 +01:00
private:
2019-03-13 00:25:46 +01:00
QIODevice *_device;
2018-01-08 23:47:45 +01:00
bool _be;
2019-03-13 00:25:46 +01:00
quint32 _ifd;
qint64 _offset;
2018-01-08 23:47:45 +01:00
};
#endif // TIFFFILE_H