-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (62 loc) · 1.89 KB
/
main.cpp
File metadata and controls
71 lines (62 loc) · 1.89 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
#include <string>
#include "CLI11.hpp"
#include "config.h"
#include "utils/base.h"
#include "utils/stopwatch.hpp"
#include "impl_simple.h"
#include "impl_simd.h"
#include "impl_mmx.h"
#include "impl_sse2.h"
#include "impl_avx.h"
using std::string;
void do_work(Impl &impl, YUV420 *yuv_src, YUV420 *yuv_dst, RGB *rgb,
uint8_t alpha){
impl.YUV2RGB(yuv_src, rgb);
impl.AlphaBlend(rgb, alpha);
impl.RGB2YUV(rgb, yuv_dst);
}
int main(int argc, char *argv[]){
CLI::App app("Convert YUV420 file to RGB");
std::string fileName = "default";
bool should_dump = false;
app.add_option("-f", fileName, "Input YUV420 file")
-> required();
app.add_option("-s", should_dump, "Whether to dump the output");
CLI11_PARSE(app, argc, argv);
YUV420 yuv_src = YUV420(kWidth, kHeight);
YUV420 yuv_dst = YUV420(kWidth, kHeight);
RGB rgb = RGB(kHeight, kWidth);
DEFER({ yuv_src.Free();});
DEFER({yuv_dst.Free();});
DEFER({rgb.Free();});
yuv_src.ReadFromYUVFile(fileName);
ImplSimple simple_isa;
ImplSimd<SimdMMX> mmx;
ImplSimd<SimdSSE2> sse2;
ImplSimd<SimdAVX> avx;
#define LIST_OF_IMPL \
X(simple_isa) \
X(mmx) \
X(sse2) \
X(avx)
#define X(name) try{ \
stopwatch::Stopwatch stopwatch; \
stopwatch.start(); \
for (size_t alpha = 0; alpha < 255; alpha += 1) { \
do_work(name, &yuv_src, &yuv_dst, &rgb, alpha); \
if (should_dump){ \
string nameString = string(#name); \
string outFile = nameString + "_output_" + std::to_string(alpha) + ".yuv"; \
yuv_dst.WriteToYUVFile(outFile); \
} \
} \
std::cout << std::left << std::setw(10) << #name << ": " << std::setw(8) \
<< std::right << stopwatch.elapsed<stopwatch::ms>() << "ms" << std::endl; \
}catch (const std::exception& e) { \
std::cerr << #name << ": " << e.what() << std::endl; \
}
LIST_OF_IMPL
#undef X
#undef LIST_OF_IMPL
return 0;
}