-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibf.h
80 lines (69 loc) · 3.67 KB
/
ibf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef IBF_H
#define IBF_H
#include <QMainWindow>
#include <QMatrix4x4>
QT_BEGIN_NAMESPACE
class QString;
class QByteArray;
QT_END_NAMESPACE
/*
A very simple and limited image file format.
Specification:
+--------------+-------------+--------------------------+---------------------------------+
| offset | length | description | hardcoded values for version 1 |
+--------------+-------------+--------------------------+---------------------------------+
| 0 | 3 | Magic id: 'IBF' | |
+--------------+-------------+--------------------------+---------------------------------+
| 3 | 1 | Version | 0x1 |
+--------------+-------------+--------------------------+---------------------------------+
| 4 | 4 | header length (L) | 89+N |
+--------------+-------------+--------------------------+---------------------------------+
| 8 | 4 | name length (N) | |
+--------------+-------------+--------------------------+---------------------------------+
| 12 | N | name (unicode) | |
+--------------+-------------+--------------------------+---------------------------------+
| 12+N | 1 | format id: | 0x1 |
| | | 0x0: 8 graylevel bits | |
| | | 0x1: R8G8B8A8 | |
| | | ... | |
+--------------+-------------+--------------------------+---------------------------------+
| 13+N | 4 | image width (pixels) | |
+--------------+-------------+--------------------------+---------------------------------+
| 17+N | 4 | image height (pixels) | |
+--------------+-------------+--------------------------+---------------------------------+
| 21+N | 64 | Transformation matrix | using only basic 3x3 because 3D |
| | | (4x4 floats) | transforms aren't supported |
+--------------+-------------+--------------------------+---------------------------------+
| 85+N | 4 | pixel data length (M) | W*H*4 |
+--------------+-------------+--------------------------+---------------------------------+
| 89+N | L-(89+N) | reserved | |
+--------------+-------------+--------------------------+---------------------------------+
| L | M | pixel data | |
+--------------+-------------+--------------------------+---------------------------------+
*/
class IBF
{
public:
IBF(const QString& IBFFilename); // load an ibf from disk
IBF(const QImage& image, const QString& name, const QMatrix4x4& xform); // encode an ibf
~IBF();
bool save(const QString& targetFilename) const;
const QString& name() const { return _name; }
bool ToPixmap(QPixmap* pixmap) const;
const QMatrix4x4& Transform() const { return _xform; }
private:
bool load(const QString& IBFFilename);
private:
unsigned char _version;
QString _name;
enum format {
GRAY8 = 0,
R8G8B8A8 = 1
};
enum format _format;
int _width;
int _height;
QMatrix4x4 _xform;
QByteArray _data;
};
#endif // IBF_H