BMPParser.h
1.33 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
#pragma once
#ifdef ERROR
#define ERROR_ ERROR
#undef ERROR
#endif
#include <stdint.h> // node < 7 uses libstdc++ on macOS which lacks complete c++11
#include <string>
namespace BMPParser{
enum Status{
EMPTY,
OK,
ERROR,
};
class Parser{
public:
Parser()=default;
~Parser();
void parse(uint8_t *buf, int bufSize, uint8_t *format=nullptr);
void clearImgd();
int32_t getWidth() const;
int32_t getHeight() const;
uint8_t *getImgd() const;
Status getStatus() const;
std::string getErrMsg() const;
private:
Status status = Status::EMPTY;
uint8_t *data = nullptr;
uint8_t *ptr = nullptr;
int len = 0;
int32_t w = 0;
int32_t h = 0;
uint8_t *imgd = nullptr;
std::string err = "";
std::string op = "";
template <typename T, bool check=true> inline T get();
template <typename T, bool check=true> inline T get(uint8_t* pointer);
std::string getStr(int len, bool reverse=false);
inline void skip(int len);
void calcMaskShift(uint32_t& shift, uint32_t& mask, double& multp);
void setOp(std::string val);
std::string getOp() const;
void setErrUnsupported(std::string msg);
void setErrUnknown(std::string msg);
void setErr(std::string msg);
std::string getErr() const;
};
}
#ifdef ERROR_
#define ERROR ERROR_
#undef ERROR_
#endif