-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
141 lines (106 loc) · 4.53 KB
/
main.cpp
File metadata and controls
141 lines (106 loc) · 4.53 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
#define _CRT_SECURE_NO_WARNINGS
#define THRESHOLD_SAMPLES() 11 // the number of samples for threshold testing.
#include <vector>
#include <stdint.h>
#include <direct.h>
#include "convert.h"
#include "histogram.h"
#include "image.h"
#include "scoped_timer.h"
#include "generatebn_void_cluster.h"
#include "dft.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb/stb_image_write.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb/stb_image.h"
void TestMask(const std::vector<uint8_t>& noise, size_t noiseSize, const char* baseFileName)
{
std::vector<uint8_t> thresholdImage(noise.size());
for (size_t testIndex = 0; testIndex < THRESHOLD_SAMPLES(); ++testIndex)
{
float percent = float(testIndex) / float(THRESHOLD_SAMPLES() - 1);
uint8_t thresholdValue = FromFloat<uint8_t>(percent);
if (thresholdValue == 0)
thresholdValue = 1;
else if (thresholdValue == 255)
thresholdValue = 254;
for (size_t pixelIndex = 0, pixelCount = noise.size(); pixelIndex < pixelCount; ++pixelIndex)
thresholdImage[pixelIndex] = noise[pixelIndex] > thresholdValue ? 255 : 0;
std::vector<uint8_t> thresholdImageDFT;
DFT(thresholdImage, thresholdImageDFT, noiseSize);
std::vector<uint8_t> noiseAndDFT;
size_t noiseAndDFT_width = 0;
size_t noiseAndDFT_height = 0;
AppendImageHorizontal(thresholdImage, noiseSize, noiseSize, thresholdImageDFT, noiseSize, noiseSize, noiseAndDFT, noiseAndDFT_width, noiseAndDFT_height);
char fileName[256];
sprintf(fileName, "%s_%u.png", baseFileName, thresholdValue);
stbi_write_png(fileName, int(noiseAndDFT_width), int(noiseAndDFT_height), 1, noiseAndDFT.data(), 0);
}
}
void TestNoise(const std::vector<uint8_t>& noise8, const std::vector<uint8_t>& noise16, size_t noiseSize, const char* baseFileName)
{
char fileName[256];
sprintf(fileName, "%s.noise.png", baseFileName);
stbi_write_png(fileName, int(noiseSize), int(noiseSize), 1, noise8.data(), 0);
sprintf(fileName, "%s.noise.16b.png", baseFileName);
stbi_write_png(fileName, int(noiseSize), int(noiseSize), 2, noise16.data(), 0);
sprintf(fileName, "%s.histogram.csv", baseFileName);
WriteHistogram(noise8, fileName);
std::vector<uint8_t> noiseDFT;
DFT(noise8, noiseDFT, noiseSize);
std::vector<uint8_t> noiseAndDFT;
size_t noiseAndDFT_width = 0;
size_t noiseAndDFT_height = 0;
AppendImageHorizontal(noise8, noiseSize, noiseSize, noiseDFT, noiseSize, noiseSize, noiseAndDFT, noiseAndDFT_width, noiseAndDFT_height);
sprintf(fileName, "%s.png", baseFileName);
stbi_write_png(fileName, int(noiseAndDFT_width), int(noiseAndDFT_height), 1, noiseAndDFT.data(), 0);
TestMask(noise8, noiseSize, baseFileName);
}
int main(int argc, char** argv)
{
_mkdir("out");
_mkdir("debug");
// generate blue noise using void and cluster
{
static const size_t c_width = 256;
static const float c_sigma = 1.9f;
static const InitialPointSetModes c_mode = InitialPointSetModes::MBC;
char baseFileName[1024];
sprintf(baseFileName, "out/VNC_%i_%i_%s", (int)c_width, int(c_sigma * 10.0f), ToString(c_mode));
std::vector<uint8_t> noise8;
std::vector<uint8_t> noise16;
{
ScopedTimer timer("Blue noise by void and cluster");
GenerateBN_Void_Cluster(noise8, noise16, c_width, c_sigma, c_mode, baseFileName);
}
TestNoise(noise8, noise16, c_width, baseFileName);
}
/*
// generate blue noise using void and cluster but using mitchell's best candidate instead of initial binary pattern and phase 1
{
static size_t c_width = 256;
std::vector<uint8_t> noise;
{
ScopedTimer timer("Blue noise by void and cluster with Mitchells best candidate");
GenerateBN_Void_Cluster(noise, c_width, true, "out/blueVC_1M");
}
TestNoise(noise, c_width, "out/blueVC_1M");
}
// load a blue noise texture
{
int width, height, channels;
std::vector<uint8_t> noise;
{
ScopedTimer timer("Blue noise by void and cluster from loading the texture");
uint8_t* image = stbi_load("bluenoise256.png", &width, &height, &channels, 0);
noise.reserve(width*height);
for (int i = 0; i < width*height; ++i)
noise.push_back(image[i*channels]);
stbi_image_free(image);
}
TestNoise(noise, width, "out/blueVC_2");
}
*/
system("pause");
return 0;
}