-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate.cpp
114 lines (88 loc) · 2.94 KB
/
rotate.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// +build ignore
#include <Halide.h>
#include "rotate.hpp"
using namespace Halide;
Func rotate90(Func input, Expr width, Expr height) {
Var x("x"), y("y"), ch("ch");
Expr w = width - 1;
Expr h = height - 1;
Region src_bounds = {{0, w},{0, h},{0, 4}};
Func in = BoundaryConditions::constant_exterior(input, 0, src_bounds);
Func r = Func("rotate90");
r(x, y, ch) = in(y, h - x, ch);
return r;
}
Func rotate180(Func input, Expr width, Expr height) {
Var x("x"), y("y"), ch("ch");
Expr w = width - 1;
Expr h = height - 1;
Region src_bounds = {{0, w},{0, h},{0, 4}};
Func in = BoundaryConditions::constant_exterior(input, 0, src_bounds);
Func r = Func("rotate180");
r(x, y, ch) = in(w - x, h - y, ch);
return r;
}
Func rotate270(Func input, Expr width, Expr height) {
Var x("x"), y("y"), ch("ch");
Expr w = width - 1;
Expr h = height - 1;
Region src_bounds = {{0, w},{0, h},{0, 4}};
Func in = BoundaryConditions::constant_exterior(input, 0, src_bounds);
Func r = Func("rotate270");
r(x, y, ch) = in(w - y, x, ch);
return r;
}
std::tuple<Func, std::vector<Argument>> export_rotate90() {
ImageParam src(UInt(8), 3, "src");
// input data format
src.dim(0).set_stride(4);
src.dim(2).set_stride(1);
src.dim(2).set_bounds(0, 4);
Param<int32_t> width{"width", 1920};
Param<int32_t> height{"height", 1080};
Func fn = rotate90(src.in(), width, height);
// output data format
OutputImageParam out = fn.output_buffer();
out.dim(0).set_stride(4);
out.dim(2).set_stride(1);
out.dim(2).set_bounds(0, 4);
std::vector<Argument> args = {src, width, height};
std::tuple<Func, std::vector<Argument>> tuple = std::make_tuple(fn, args);
return tuple;
}
std::tuple<Func, std::vector<Argument>> export_rotate180() {
ImageParam src(UInt(8), 3, "src");
// input data format
src.dim(0).set_stride(4);
src.dim(2).set_stride(1);
src.dim(2).set_bounds(0, 4);
Param<int32_t> width{"width", 1920};
Param<int32_t> height{"height", 1080};
Func fn = rotate180(src.in(), width, height);
// output data format
OutputImageParam out = fn.output_buffer();
out.dim(0).set_stride(4);
out.dim(2).set_stride(1);
out.dim(2).set_bounds(0, 4);
std::vector<Argument> args = {src, width, height};
std::tuple<Func, std::vector<Argument>> tuple = std::make_tuple(fn, args);
return tuple;
}
std::tuple<Func, std::vector<Argument>> export_rotate270() {
ImageParam src(UInt(8), 3, "src");
// input data format
src.dim(0).set_stride(4);
src.dim(2).set_stride(1);
src.dim(2).set_bounds(0, 4);
Param<int32_t> width{"width", 1920};
Param<int32_t> height{"height", 1080};
Func fn = rotate270(src.in(), width, height);
// output data format
OutputImageParam out = fn.output_buffer();
out.dim(0).set_stride(4);
out.dim(2).set_stride(1);
out.dim(2).set_bounds(0, 4);
std::vector<Argument> args = {src, width, height};
std::tuple<Func, std::vector<Argument>> tuple = std::make_tuple(fn, args);
return tuple;
}