-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.h
More file actions
74 lines (61 loc) · 1.25 KB
/
Copy pathimage.h
File metadata and controls
74 lines (61 loc) · 1.25 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
#ifndef IMAGE_H
#define IMAGE_H
#include <fstream>
struct Color {
union {
struct {
unsigned char r, g, b, a;
};
unsigned char raw[4];
unsigned int val;
};
int bytespp;
Color() : val(0), bytespp(1) {
}
Color(unsigned char R, unsigned char G, unsigned char B, unsigned char A) : r(R), g(G), b(B), a(A), bytespp(4) {
}
Color(int v, int bpp) : val(v), bytespp(bpp) {
}
Color(const Color &c) : val(c.val), bytespp(c.bytespp) {
}
Color(const unsigned char *p, int bpp) : val(0), bytespp(bpp) {
for (int i=0; i<bpp; i++) {
raw[i] = p[i];
}
}
Color & operator =(const Color &c) {
if (this != &c) {
bytespp = c.bytespp;
val = c.val;
}
return *this;
}
};
class Image {
protected:
unsigned char* data;
int width;
int height;
int bytespp;
public:
enum Format {
GRAYSCALE=1, RGB=3, RGBA=4
};
Image();
Image(int w, int h, int bpp);
Image(const char *filename);
Image(const Image &img);
void read_file(const char *filename);
void write_png_file(const char *filename);
Color get(int x, int y);
bool set(int x, int y, Color c);
~Image();
int get_width();
int get_height();
int get_bytespp();
unsigned char *buffer();
void clear();
bool flip_horizontally();
bool flip_vertically();
};
#endif //__IMAGE_H__