37 const Displacement LOOKUP_DIRECTION[2][2][2][2] = {
39 { { { { 0, 0 }, { 1, 0 } }, { { 0, +1 }, { +1, 0 } } }, { { { 0, -1 }, { 0, -1 } }, { { 9, 9 }, { 0, -1 } } } },
41 { { { { -1, 0 }, { 9, 9 } }, { { 0, 1 }, { +1, 0 } } }, { { { -1, 0 }, { -1, 0 } }, { { 0, 1 }, { 0, 0 } } } }
44 const Displacement LOOKUP_INTERNAL_PIXEL[3][3] = {
45 { { 0, 0 }, { 0, -1 }, { 0, 0 } },
46 { { -1, -1 }, { 9, 0 }, { 0, 0 } },
47 { { 0, 0 }, { -1, 0 }, { 0, 0 } }
50 const int W = in.getWidth(), H = in.getHeight();
51 const float LEVEL = level * in.MAX_VALUE;
56 for (
auto seed : border) {
68 if (
x < W &&
y < H && in().mean() > LEVEL) ++ctr;
69 if (
x > 0 &&
y < H && in(
x - 1,
y).mean() > LEVEL) ++ctr;
70 if (x < W && y > 0 && in(
x,
y - 1).mean() > LEVEL) ++ctr;
71 if (
x > 0 &&
y > 0 && in(
x - 1,
y - 1).mean() > LEVEL) ++ctr;
77 Displacement prev = { 0, 0 };
79 boundary.push_back(contour);
85 rb =
x < W &&
y < H && in().mean() > LEVEL,
86 lb =
x > 0 &&
y < H && in(
x - 1,
y).mean() > LEVEL,
87 rt = x < W && y > 0 && in(
x,
y - 1).mean() > LEVEL,
88 lt =
x > 0 &&
y > 0 && in(
x - 1,
y - 1).mean() > LEVEL;
91 if ((rb && lb && rt && lt) || !(rb || lb || rt || lt))
98 Displacement d = LOOKUP_DIRECTION[lt][rt][lb][rb];
100 if (prev.x == 0 && prev.y == 0)
107 Displacement ip = LOOKUP_INTERNAL_PIXEL[d.y + 1][d.x + 1];
108 int ipx =
x + ip.x, ipy =
y + ip.y;
109 if (ipx >= 0 && ipy >= 0 && ipx < W && ipy < H) {
110 testedPixels.
goTo(ipx, ipy);
122 }
while (seed.
x !=
x || seed.
y !=
y);
A sequence of integer-valued 2D points.
void addPoint(int x, int y)
Adds a new point to the end of the contour.
unsigned char getValue() const
Returns 0..MAX_UNNORM_VALUE value at current position.
void goTo(int x, int y)
Changes current position.
void putValue(unsigned char x)
Puts a properly scaled (0..MAX_UNNORM_VALUE) value at the current position.
jobject jlong jint jint y
Beatmup::InternalBitmap * bitmap