Beatmup
Kernels::FillRegion< in_t, out_t > Class Template Reference

Region filling kernel implementing flood fill starting from a given seed. More...

#include <region_filling.h>

Public Types

typedef in_t::pixtype::operating_type inpixvaltype
 

Static Public Member Functions

static void process (AbstractBitmap &input, AbstractBitmap &output, IntPoint maskOffset, IntPoint seed, inpixvaltype tolerance, std::vector< IntPoint > &border, IntRectangle &bounds)
 Fills a region in an output bitmap starting from a given position in an input bitmap. More...
 

Detailed Description

template<typename in_t, typename out_t>
class Kernels::FillRegion< in_t, out_t >

Region filling kernel implementing flood fill starting from a given seed.

Definition at line 31 of file region_filling.h.

Member Typedef Documentation

◆ inpixvaltype

template<typename in_t , typename out_t >
typedef in_t::pixtype::operating_type Kernels::FillRegion< in_t, out_t >::inpixvaltype

Definition at line 33 of file region_filling.h.

Member Function Documentation

◆ process()

template<typename in_t , typename out_t >
static void Kernels::FillRegion< in_t, out_t >::process ( AbstractBitmap input,
AbstractBitmap output,
IntPoint  maskOffset,
IntPoint  seed,
inpixvaltype  tolerance,
std::vector< IntPoint > &  border,
IntRectangle bounds 
)
inlinestatic

Fills a region in an output bitmap starting from a given position in an input bitmap.

Parameters
inputInput bitmap reader
outputOutput mask writer
maskOffsetMask position in the bitmap
seedEntry point
toleranceTolerance level: how much a pixel has to be different from seed to not to be filled
borderA vector to put border points to for further processing
boundsBounding box of the filled region; the input value is updated but not reset

Definition at line 44 of file region_filling.h.

52  {
53  in_t in(input);
54  out_t out(output);
55 
56  const int
57  W = in.getWidth() - 1, H = in.getHeight() - 1,
58  MW = out.getWidth() - 1, MH = out.getHeight() - 1;
59 
60  std::queue<IntPoint> queue;
61  queue.push(IntPoint(seed.x, seed.y));
62  in.goTo(seed.x, seed.y);
63 
64  const typename in_t::pixtype ref = in(); // reference input value
65  const int range = out.MAX_UNNORM_VALUE;
66 
67  inpixvaltype diff;
68  unsigned char newval, oldval;
69 
70  // performance critical cycle
71  while (!queue.empty()) {
72  // popping from queue front
73  IntPoint p = queue.front();
74  queue.pop();
75  int
76  mx = p.x - maskOffset.x,
77  my = p.y - maskOffset.y;
78 
79  // checking neighbor pixels
80  bool onBorder = false;
81 
82  if (p.x > 0 && mx > 0 && (diff = (in(p.x - 1, p.y) - ref).abs().max()) <= tolerance) {
83  newval = (tolerance > 0 && diff > 0) ? (range * (tolerance - diff) / tolerance + 1) : out.MAX_UNNORM_VALUE;
84  out.goTo(mx - 1, my);
85  oldval = out.getValue();
86  if (oldval < newval) {
87  out.putValue(newval);
88  queue.push(IntPoint(p.x - 1, p.y));
89  }
90  }
91  else onBorder = true;
92 
93  if (p.y > 0 && my > 0 && (diff = (in(p.x, p.y - 1) - ref).abs().max()) <= tolerance) {
94  newval = (tolerance > 0 && diff > 0) ? (range * (tolerance - diff) / tolerance + 1) : out.MAX_UNNORM_VALUE;
95  out.goTo(mx, my - 1);
96  oldval = out.getValue();
97  if (oldval < newval) {
98  out.putValue(newval);
99  queue.push(IntPoint(p.x, p.y - 1));
100  }
101  }
102  else onBorder = true;
103 
104  if (p.x < W && mx < MW && (diff = (in(p.x + 1, p.y) - ref).abs().max()) <= tolerance) {
105  newval = (tolerance > 0 && diff > 0) ? (range * (tolerance - diff) / tolerance + 1) : out.MAX_UNNORM_VALUE;
106  out.goTo(mx + 1, my);
107  oldval = out.getValue();
108  if (oldval < newval) {
109  out.putValue(newval);
110  queue.push(IntPoint(p.x + 1, p.y));
111  }
112  }
113  else onBorder = true;
114 
115  if (p.y < H && my < MH && (diff = (in(p.x, p.y + 1) - ref).abs().max()) <= tolerance) {
116  newval = (tolerance > 0 && diff > 0) ? (range * (tolerance - diff) / tolerance + 1) : out.MAX_UNNORM_VALUE;
117  out.goTo(mx, my + 1);
118  oldval = out.getValue();
119  if (oldval < newval) {
120  out.putValue(newval);
121  queue.push(IntPoint(p.x, p.y + 1));
122  }
123  }
124  else onBorder = true;
125 
126  if (onBorder) {
127  border.push_back(IntPoint(mx, my));
128 
129  if (mx < bounds.a.x)
130  bounds.a.x = mx;
131  if (mx > bounds.b.x)
132  bounds.b.x = mx;
133  if (my < bounds.a.y)
134  bounds.a.y = my;
135  if (my > bounds.b.y)
136  bounds.b.y = my;
137  }
138  }
139  }
CustomPoint< numeric > b
Definition: geometry.h:131
CustomPoint< numeric > a
Definition: geometry.h:131
in_t::pixtype::operating_type inpixvaltype
CustomPoint< int > IntPoint
Definition: geometry.h:629
JNIEnv jlong jint out
Beatmup::IntPoint p((int) x,(int) y)
jlong jfloat tolerance

The documentation for this class was generated from the following file: