1 // Test whether min[] and extent[] of an ImageParam are correctly passed into
2 // the filter.
3 #include "Halide.h"
4 #include <stdio.h>
5
6 using namespace Halide;
7
main(int argc,char ** argv)8 int main(int argc, char **argv) {
9 Var x("x");
10 Func f("f");
11 ImageParam in(Int(32), 1, "in");
12 Expr factor("factor");
13
14 // Multiply by -10 or +10 for coordinates that fall outside the input
15 // image.
16 factor = select(x < in.left(), -10,
17 select(x > in.right(), 10, 1));
18 f(x) = factor * x;
19
20 // Create input and output buffers. The input pixels are never accessed,
21 // but we initialize them anyway.
22 Buffer<int> input(5);
23 Buffer<int> out(10);
24 input.fill(0);
25 out.fill(0);
26
27 // Change coordinate origin of input and output buffer so that they are
28 // aligned as follows:
29 // input |------|
30 // out |-----------------|
31 const int INOFF = 4;
32 const int OUTOFF = 1;
33 input.set_min(INOFF);
34 out.set_min(OUTOFF);
35 in.set(input);
36 f.realize(out);
37
38 // Check correctness of result
39 int expected[] = {-10, -20, -30, 4, 5, 6, 7, 8, 90, 100};
40 for (int i = 0; i < out.width(); i++) {
41 if (out(i + OUTOFF) != expected[i]) {
42 printf("Unexpected output: %d != %d\n", out(i + OUTOFF), expected[i]);
43 return -1;
44 }
45 }
46
47 printf("Success!\n");
48 return 0;
49 }
50