-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
185 lines (149 loc) · 5.68 KB
/
main.cpp
File metadata and controls
185 lines (149 loc) · 5.68 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "main.h"
bool goodFun(Function * fun, unsigned width, unsigned height){
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(0,1024);
unsigned e1 = fun->evaluate(dist(rng),dist(rng),width,height);
unsigned e2 = fun->evaluate(dist(rng),dist(rng),width,height);
unsigned e3 = fun->evaluate(dist(rng),dist(rng),width,height);
return (e1 != e2) || (e1 != e3) || (e2 != e3);
}
int main() {
ConfigParser p;
p.load("ImageGenerator.cfg");
FunctionGenerator funGen = FunctionGenerator();
unsigned arraySize = getArraySize(p.recursions);
Function *red[arraySize];
Function *green[arraySize];
Function *blue[arraySize];
std::cout << "Generating Image(s)..." << std::endl<<std::endl;
auto start = std::chrono::high_resolution_clock::now();
auto x = std::chrono::time_point_cast<std::chrono::nanoseconds>(start);
std::string res = std::to_string(x.time_since_epoch().count());
for(int i = 0;i<p.count;i++){
std::cout << "Generating Random Image..." << std::endl;
ucVec imageRnd;
std::string tmp = "rndImage#" + res+ "#i="+std::to_string(i)+".png";
const char *filename0 =tmp.c_str();
imageRnd.resize(p.width * p.height * 4);
unsigned int * redp = p.getRedStartParams();
unsigned int * greenp = p.getGreenStartParams();
unsigned int * bluep = p.getBlueStartParams();
for( int s = 0;s<arraySize;s++){
red[s] = funGen.generateFunction(redp[0],redp[1],redp[2],redp[3]);
green[s] = funGen.generateFunction(greenp[0],greenp[1],greenp[2],greenp[3]);
blue[s] = funGen.generateFunction(bluep[0],bluep[1],bluep[2],bluep[3]);
while(!goodFun(red[s],p.width,p.height)){
red[s] = funGen.generateFunction(redp[0],redp[1],redp[2],redp[3]);
}
while(!goodFun(green[s],p.width,p.height)){
green[s] = funGen.generateFunction(greenp[0],greenp[1],greenp[2],greenp[3]);
}
while(!goodFun(blue[s],p.width,p.height)){
blue[s] = funGen.generateFunction(bluep[0],bluep[1],bluep[2],bluep[3]);
}
}
/*
std::string redFunc = red->print();
std::string greenFunc = green->print();
std::string blueFunc = blue->print();
std::cout << "Red Fun:" << redFunc << std::endl;
std::cout << "Green Fun:" << greenFunc << std::endl;
std::cout << "Blue Fun:" << blueFunc << std::endl;
*/
genBasedOnFunctions(imageRnd, p.width, p.height, red, green, blue,arraySize);
encodeOneStep(filename0, imageRnd, p.width, p.height);
std::cout << "Generating Random Image - Finished!" << std::endl<<std::endl;
}
auto finish = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count() << "ns\n";
//generate some default images Comment this in, if you want some default examples
unsigned width = p.width;
unsigned height = p.height;
/*
//img1
ucVec image;
const char *filename = "image1.png";
image.resize(width * height * 4);
gen1(image, width, height);
encodeOneStep(filename, image, width, height);
//img2
ucVec image2;
const char *filename2 = "image2.png";
image2.resize(width * height * 4);
gen2(image2, width, height);
encodeOneStep(filename2, image2, width, height);
*//*
//img3
ucVec image3;
const char *filename3 = "image3.png";
image3.resize(width * height * 4);
gen3(image3, width, height);
encodeOneStep(filename3, image3, width, height);
*//*
width = 1024;
height = 1024;
//img4
ucVec image4;
const char *filename4 = "image4.png";
image4.resize(width * height * 4);
gen4(image4, width, height);
encodeOneStep(filename4, image4, width, height);
width = 512;
height = 512;
//img5
ucVec image5;
const char *filename5 = "image5.png";
image5.resize(width * height * 4);
gen5(image5, width, height);
encodeOneStep(filename5, image5, width, height);
width = 512;
height = 512;
//img6
ucVec image6;
const char *filename6 = "image6.png";
image6.resize(width * height * 4);
gen6(image6, width, height);
encodeOneStep(filename6, image6, width, height);
width = 1024;
height = 1024;
//img7
ucVec image7;
const char *filename7 = "image7.png";
image7.resize(width * height * 4);
gen7(image7, width, height);
encodeOneStep(filename7, image7, width, height);
width = 512;
height = 512;
//img8
ucVec image8;
const char *filename8 = "image8.png";
image8.resize(width * height * 4);
gen8(image8, width, height);
encodeOneStep(filename8, image8, width, height);
width = 1024;
height = 1024;
//img9
ucVec image9;
const char *filename9 = "image9.png";
image9.resize(width * height * 4);
gen9(image9, width, height);
encodeOneStep(filename9, image9, width, height);
*/
std::cout << "Generating Image(s) - Finished!" << std::endl;
}
//Encode from raw pixels to disk with a single function call
//The image argument has width * height RGBA pixels or width * height * 4 bytes
void encodeOneStep(const char *filename, ucVec &image, unsigned width, unsigned height) {
//Encode the image
unsigned error = lodepng::encode(filename, image, width, height);
//if there's an error, display it
if (error) std::cout << "encoder error " << error << ": " << lodepng_error_text(error) << std::endl;
}
unsigned getArraySize(unsigned e){
if(e == 0){
return 1;
}else {
return 2*getArraySize(e -1) + 1;
}
}