-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
61 lines (56 loc) · 1.62 KB
/
main.cpp
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
#include "util.h"
#include <iostream>
#include <sstream>
#include <string>
#include <filesystem>
#include <thread>
util::Uchar4 Pixel(util::Uint2 inPos, util::Uint2 inRes, float inProgress)
{
unsigned r = unsigned(float(inPos.x) / (inRes.x - 1) * 255);
unsigned g = unsigned(float(inPos.y) / (inRes.y - 1) * 255);
unsigned b = unsigned(inProgress * 255);
return util::Uchar4(r, g, b, 255);
}
void Render(float inProgress, util::ImageRGBA8& outImage)
{
unsigned w = outImage.GetWidth();
unsigned h = outImage.GetHeight();
for (unsigned y = 0; y < h; ++y)
{
for (unsigned x = 0; x < w; ++x)
{
outImage.At(x, y) = Pixel({ x, y }, { w, h }, inProgress);
}
}
}
void Export(int inFrame, const util::ImageRGBA8& inImage)
{
std::stringstream ss;
ss << std::setfill('0') << std::setw(3) << inFrame;
const std::filesystem::path current_path = std::filesystem::current_path();
std::string filename = ss.str() + ".png";
std::string filepath = (current_path / filename).string();
util::SaveImage(filepath, inImage);
std::cout << filename << std::endl;
}
int main(int argc, char** argv)
{
std::cout << "start." << std::endl;
const int cMaxFrameNum = 600;
std::vector<std::thread> threads(cMaxFrameNum);
for (int i = 0; i < cMaxFrameNum; ++i)
{
threads.push_back(std::thread(
[](int inFrame, int inMaxFrameNum)
{
util::ImageRGBA8 image(512, 512);
float progress = float(inFrame) / (cMaxFrameNum - 1);
Render(progress, image);
Export(inFrame, image);
}, i, cMaxFrameNum
));
threads.back().join();
}
std::cout << "done." << std::endl;
return 0;
}