-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathimg_output.cpp
More file actions
55 lines (43 loc) · 1.46 KB
/
img_output.cpp
File metadata and controls
55 lines (43 loc) · 1.46 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
#include <Halide.h>
#include "halide_complexfunc.h"
#include "signal.h"
#include "util.h"
using namespace Halide;
using namespace Halide::Tools;
class ImgOutputToDBGenerator : public Halide::Generator<ImgOutputToDBGenerator> {
public:
GeneratorParam<int32_t> vectorsize {"vectorsize", 4};
GeneratorParam<int32_t> blocksize {"blocksize", 64};
Input<Buffer<double>> img {"img", 3}; // complex input
Output<Buffer<double>> out{"out", 2};
void generate() {
Func img_func("cimg");
img_func = img;
ComplexFunc cimg(c, img_func);
RDom r(0, img.dim(1).extent(), 0, img.dim(2).extent(), "r");
m() = maximum(abs(cimg(r.x, r.y)));
out(x, y) = Expr(10) * log10(abs(cimg(x, y)) / m());
}
void schedule() {
m.compute_root();
out.compute_root()
.vectorize(x, vectorsize)
.parallel(y, blocksize);
}
private:
Var x{"x"}, y{"y"}, c{"c"};
Func m{"m"};
};
class ImgOutputU8Generator : public Halide::Generator<ImgOutputU8Generator> {
public:
Input<Buffer<double>> dB {"dB", 2};
Input<double> dB_min {"dB_min"};
Input<double> dB_max {"dB_max"};
Output<Buffer<uint8_t>> out{"out", 2};
void generate() {
Var x{"x"}, y{"y"};
out(x, y) = ConciseCasts::u8(dB_scale(dB(x, y), dB_min, dB_max, UInt(8)));
}
};
HALIDE_REGISTER_GENERATOR(ImgOutputToDBGenerator, img_output_to_dB)
HALIDE_REGISTER_GENERATOR(ImgOutputU8Generator, img_output_u8)