-
Notifications
You must be signed in to change notification settings - Fork 1
/
unufo_types.h
150 lines (113 loc) · 3.12 KB
/
unufo_types.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef ESYNTH_TYPES_H
#define ESYNTH_TYPES_H
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include <inttypes.h>
typedef struct Coordinates
{
int x, y;
Coordinates(int _x,int _y): x(_x), y(_y) { }
Coordinates(): x(0), y(0) { }
bool operator< (const Coordinates& other) const {
return y*y+x*x < (other.y*other.y+other.x*other.x);
}
Coordinates operator+ (const Coordinates& a) const {
return Coordinates(x+a.x,y+a.y);
}
Coordinates operator- (const Coordinates& a) const {
return Coordinates(x-a.x,y-a.y);
}
} Coordinates;
struct Parameters
{
bool invent_gradients;
bool equal_adjustment;
bool use_ref_layer;
gint32 corpus_id;
gint32 neighbours, tries;
gint32 comp_size, transfer_size;
gint32 max_adjustment;
};
//Bitmap class with three dimensions (width, height, number of channels)
template<class T>
struct Bitmap
{
int width, height, depth;
T *data;
explicit Bitmap() {
data = 0;
}
~Bitmap() {
delete[] data;
}
void resize(int w,int h,int d) {
width = w;
height = h;
depth = d;
delete[] data;
data = new T[w*h*4];
memset(data, 0, w*h*4);
}
T *at(int x,int y) const {
return data + (y*width+x)*4;
}
T *at(const Coordinates position) const {
return at(position.x,position.y);
}
void to_drawable(GimpDrawable *drawable, int x1,int y1, int src_layer) {
int i,j;
GimpPixelRgn region;
guchar *img;
gimp_pixel_rgn_init(®ion, drawable, x1,y1,width,height, TRUE,TRUE);
img = new guchar[width*height*depth];
for(i=0;i<width*height;i++)
for(j=0;j<int(drawable->bpp);j++)
img[i*drawable->bpp+j] = data[i*4+src_layer+j];
gimp_pixel_rgn_set_rect(®ion, img, x1,y1,width,height);
delete[] img;
}
void from_drawable(GimpDrawable *drawable,
int x1,int y1, int dest_layer) {
int i,j;
GimpPixelRgn region;
guchar *img;
gimp_pixel_rgn_init(®ion, drawable, x1,y1,width,height, FALSE,FALSE);
img = new guchar[width*height*depth];
gimp_pixel_rgn_get_rect(®ion, img, x1,y1,width,height);
for(i=0;i<width*height;i++)
for(j=0;j<(int)(drawable->bpp);j++)
data[i*4+dest_layer+j] = img[i*drawable->bpp+j];
delete[] img;
}
private:
Bitmap(const Bitmap&);
Bitmap& operator=(const Bitmap&);
};
template<class T>
struct Matrix
{
int width, height;
T *data;
explicit Matrix(): data(NULL) {}
~Matrix() {
delete[] data;
}
void resize(int w, int h) {
width = w;
height = h;
delete[] data;
data = new T[w*h*sizeof(T)];
memset(data, 0, w*h*sizeof(T));
}
T *at(int x,int y) const {
return &data[y*width+x];
}
T *at(const Coordinates& position) const {
return at(position.x, position.y);
}
private:
/* don't copy me plz */
Matrix(const Matrix<T>&);
const Matrix& operator=(const Matrix<T>&);
};
#endif // ESYNTH_TYPES_H