-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
process.cpp
97 lines (81 loc) · 3.36 KB
/
process.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
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
#include "fcam/Demosaic.h"
#include "fcam/Demosaic_ARM.h"
#include "benchmark.h"
#include "curved.h"
#include "HalideImage.h"
#include "halide_image_io.h"
#include "halide_malloc_trace.h"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace Halide;
int main(int argc, char **argv) {
if (argc < 7) {
printf("Usage: ./process raw.png color_temp gamma contrast timing_iterations output.png\n"
"e.g. ./process raw.png 3200 2 50 5 output.png");
return 0;
}
#ifdef HL_MEMINFO
halide_enable_malloc_trace();
#endif
fprintf(stderr, "input: %s\n", argv[1]);
Image<uint16_t> input = load_image(argv[1]);
fprintf(stderr, " %d %d\n", input.width(), input.height());
Image<uint8_t> output(((input.width() - 32)/32)*32, ((input.height() - 24)/32)*32, 3);
#ifdef HL_MEMINFO
info(input, "input");
stats(input, "input");
// dump(input, "input");
#endif
// These color matrices are for the sensor in the Nokia N900 and are
// taken from the FCam source.
float _matrix_3200[][4] = {{ 1.6697f, -0.2693f, -0.4004f, -42.4346f},
{-0.3576f, 1.0615f, 1.5949f, -37.1158f},
{-0.2175f, -1.8751f, 6.9640f, -26.6970f}};
float _matrix_7000[][4] = {{ 2.2997f, -0.4478f, 0.1706f, -39.0923f},
{-0.3826f, 1.5906f, -0.2080f, -25.4311f},
{-0.0888f, -0.7344f, 2.2832f, -20.0826f}};
Image<float> matrix_3200(4, 3), matrix_7000(4, 3);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
matrix_3200(j, i) = _matrix_3200[i][j];
matrix_7000(j, i) = _matrix_7000[i][j];
}
}
float color_temp = atof(argv[2]);
float gamma = atof(argv[3]);
float contrast = atof(argv[4]);
int timing_iterations = atoi(argv[5]);
int blackLevel = 25;
int whiteLevel = 1023;
double best;
best = benchmark(timing_iterations, 1, [&]() {
curved(color_temp, gamma, contrast, blackLevel, whiteLevel,
input, matrix_3200, matrix_7000,
output);
});
fprintf(stderr, "Halide:\t%gus\n", best * 1e6);
fprintf(stderr, "output: %s\n", argv[6]);
save_image(output, argv[6]);
fprintf(stderr, " %d %d\n", output.width(), output.height());
Image<uint8_t> output_c(output.width(), output.height(), output.channels());
best = benchmark(timing_iterations, 1, [&]() {
FCam::demosaic(input, output_c, color_temp, contrast, true, blackLevel, whiteLevel, gamma);
});
fprintf(stderr, "C++:\t%gus\n", best * 1e6);
fprintf(stderr, "output_c: fcam_c.png\n");
save_image(output_c, "fcam_c.png");
fprintf(stderr, " %d %d\n", output_c.width(), output_c.height());
Image<uint8_t> output_asm(output.width(), output.height(), output.channels());
best = benchmark(timing_iterations, 1, [&]() {
FCam::demosaic_ARM(input, output_asm, color_temp, contrast, true, blackLevel, whiteLevel, gamma);
});
fprintf(stderr, "ASM:\t%gus\n", best * 1e6);
fprintf(stderr, "output_asm: fcam_arm.png\n");
save_image(output_asm, "fcam_arm.png");
fprintf(stderr, " %d %d\n", output_asm.width(), output_asm.height());
// Timings on N900 as of SIGGRAPH 2012 camera ready are (best of 10)
// Halide: 722ms, FCam: 741ms
return 0;
}