-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpngdiff.h
More file actions
74 lines (54 loc) · 1.87 KB
/
pngdiff.h
File metadata and controls
74 lines (54 loc) · 1.87 KB
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
/*
This is a comment, I love comments
*/
#ifndef IMG_PNGDIFF__HPP
#define IMG_PNGDIFF__HPP
#include "png.h"
#include <QImageIOPlugin>
#include <QMap>
#define PNGDIFF_SIGNATURE_SIZE 7
#define PNGDIFF_SIGNATURE "pngdiff"
#define PNGDIFF_FORMAT_KEY "pngdiff"
// I want to reduce the refactoring as much as possible
#define PNGDIFF_READER_ARGS uint32_t, QByteArray
#define PNGDIFF_LABEL(label) static constexpr char * label = (char *) #label; \
bool label ## Reader(PNGDIFF_READER_ARGS);
#define PNGDIFF_INSERT_LABEL(label) \
map.insert(QByteArray(PNGDIFF::label), &PNGDIFF::label ## Reader)
#define PNGDIFF_COMPRESSION_TYPE_IGNORE 0x00
#define PNGDIFF_COMPRESSION_TYPE_SIMPLE 0x01
#define PNGDIFF_COMPRESSION_TYPE_CONTINUED 0x02
class PNGDIFFHandler : public QImageIOHandler
{
public:
PNGDIFFHandler();
bool canRead() const override;
bool read(QImage *outImage) override;
static bool canRead(QIODevice *device);
};
class PNGDIFFPlugin : public QImageIOPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "pngdiff.json")
public:
Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
};
class PNGDIFF
{
typedef bool (PNGDIFF::*chunk_reader)(PNGDIFF_READER_ARGS);
public:
PNGDIFF_LABEL(path) // path
PNGDIFF_LABEL(itra) // image transforms
PNGDIFF_LABEL(styp) // scanline compression type
PNGDIFF_LABEL(idat) // image data
PNGDIFF_LABEL(IEND) // image data
QMap<QByteArray, chunk_reader> chunkmap;
QByteArray original_image_data;
PNG original_image;
QByteArray scanline_compression_types;
PNGDIFF();
QMap<QByteArray, chunk_reader> initChunkMap();
bool process(QByteArray data);
};
#endif // PNGDIFF__HPP