Blink API
blurAndGainExampleKernels.h
1 
2 // Source string for the Gain kernel.
3 static const char* const GainKernel = "\
4 kernel GainKernel : ImageComputationKernel<eComponentWise>\n\
5 {\n\
6  Image<eReadWrite> dst;\n\
7 \n\
8  param:\n\
9  float multiply;\n\
10 \n\
11  void define() {\n\
12  defineParam(multiply, \"Gain\", 1.0f);\n\
13  }\n\
14 \n\
15  void process() {\n\
16  dst() *= multiply;\n\
17  }\n\
18 };\n\
19 ";
20 
21 // Source string for the Blur kernel.
22 static const char* const BlurKernel = "\
23 kernel BlurKernel : ImageComputationKernel<eComponentWise>\n\
24 {\n\
25  Image<eRead, eAccessRanged1D, eEdgeClamped> src; //the input image\n\
26  Image<eWrite> dst; //the output image\n\
27 \n\
28  param:\n\
29  int radius;\n\
30  bool horizontal;\n\
31 \n\
32  //In define(), parameters can be given labels and default values.\n\
33  void define() {\n\
34  defineParam(radius, \"Radius\", 10);\
35  defineParam(horizontal, \"Horizontal\", true);\
36  }\n\
37 \n\
38  //The init() function is run before any calls to kernel().\n\
39  void init() {\n\
40  Axis axis = horizontal ? eX : eY;\n\
41  src.setAxis(axis);\n\
42  src.setRange(-radius, radius);\n\
43  }\n\
44 \n\
45  //The kernel function is run at every pixel to produce the output.\n\
46  void process() {\n\
47  ValueType(dst) value = 0;\n\
48  for(int x = -radius; x <= radius; ++x) {\n\
49  value += src(x);\n\
50  }\n\
51  dst() = value / (2 * radius + 1);\n \
52  }\n\
53 };\n\
54 ";


©2019 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.thefoundry.co.uk