20 #include "../bitmap/abstract_bitmap.h"
21 #include "../geometry.h"
31 template<
typename in_t,
typename out_t>
class FillRegion {
50 std::vector<IntPoint>& border,
57 W = in.getWidth() - 1, H = in.getHeight() - 1,
58 MW =
out.getWidth() - 1, MH =
out.getHeight() - 1;
60 std::queue<IntPoint> queue;
62 in.goTo(seed.
x, seed.
y);
64 const typename in_t::pixtype ref = in();
65 const int range =
out.MAX_UNNORM_VALUE;
68 unsigned char newval, oldval;
71 while (!queue.empty()) {
76 mx =
p.
x - maskOffset.
x,
77 my =
p.
y - maskOffset.
y;
80 bool onBorder =
false;
82 if (
p.
x > 0 && mx > 0 && (diff = (in(
p.
x - 1,
p.
y) - ref).abs().max()) <=
tolerance) {
85 oldval =
out.getValue();
86 if (oldval < newval) {
93 if (
p.
y > 0 && my > 0 && (diff = (in(
p.
x,
p.
y - 1) - ref).abs().max()) <=
tolerance) {
96 oldval =
out.getValue();
97 if (oldval < newval) {
102 else onBorder =
true;
104 if (
p.
x < W && mx < MW && (diff = (in(
p.
x + 1,
p.
y) - ref).abs().max()) <=
tolerance) {
106 out.goTo(mx + 1, my);
107 oldval =
out.getValue();
108 if (oldval < newval) {
109 out.putValue(newval);
113 else onBorder =
true;
115 if (
p.
y < H && my < MH && (diff = (in(
p.
x,
p.
y + 1) - ref).abs().max()) <=
tolerance) {
117 out.goTo(mx, my + 1);
118 oldval =
out.getValue();
119 if (oldval < newval) {
120 out.putValue(newval);
124 else onBorder =
true;
158 const int morphoSize = (int)ceilf(holdRad + releaseRad);
159 const float morphoReleaseRing = releaseRad - holdRad;
161 for (
auto p : pointSet) {
169 for (
int y =
y1;
y <=
y2; ++
y) {
171 for (
int x =
x1;
x <=
x2; ++
x, mask++) {
174 if (d2 <
sqr(holdRad))
176 else if (d2 <
sqr(releaseRad)) {
178 int c = (int)roundf((
float)
val * (1.0f - (sqrtf((
float)d2) - holdRad) / morphoReleaseRing));
204 const int morphoSize = (int)ceilf(holdRad + releaseRad);
205 const float morphoReleaseRing = releaseRad - holdRad;
207 for (
auto p : pointSet) {
215 for (
int y =
y1;
y <=
y2; ++
y) {
217 for (
int x =
x1;
x <=
x2; ++
x, mask++) {
220 if (d2 <
sqr(holdRad))
222 else if (d2 <
sqr(releaseRad)) {
224 int c = (int)roundf((
float)
val * (sqrtf((
float)d2) - holdRad) / morphoReleaseRing);
A very basic class for any image.
Circular dilatation kernel for flood fill contours postprocessing.
static void process(AbstractBitmap &bitmap, std::vector< IntPoint > &pointSet, int val, float holdRad, float releaseRad)
Circular dilatation of a mask at given points.
Circular erosion kernel for flood fill contours postprocessing.
static void process(AbstractBitmap &bitmap, std::vector< IntPoint > &pointSet, int val, float holdRad, float releaseRad)
Circular erosion of a mask at given points.
Region filling kernel implementing flood fill starting from a given seed.
in_t::pixtype::operating_type inpixvaltype
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.
CustomPoint< int > IntPoint
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
JNIEnv jlong jint jint jint jint y2
JNIEnv jlong jint jint jint x2
JNIEnv jlong jint jint jint y1
jobject jlong jint jint y
return(jlong) new Beatmup jlong jstring jint val
Beatmup::InternalBitmap * bitmap
Beatmup::IntPoint p((int) x,(int) y)