Warning: session_start(): open(/var/lib/php/sessions/sess_cf4k2kmns9legs6rp8ihgv7i6i, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
import java.awt.geom.*;
p {
BufferedImage img = loadBufferedImage(#1006973);
BWImage bw = getAlphaChannel(img);
Image2B alpha = new Image2B(bw);
int w = alpha.w(), h = alpha.h();
Path2D.Float path = new Path2D.Float();
int x = w/2;
int y = -1;
while (y < h && !isInteresting(getQuadrant(alpha, x, y)) ++y;
int x1 = x, y1 = y;
path.moveTo(x, y);
new HashSet seen;
while (seen.add(new Pt(x, y))) {
int q = getQuadrant(alpha, x, y);
Pt next = null;
for (Pt p : neighborhood(x, y))
if (!seen.contains(p) && isInteresting(getQuadrant(alpha, p.x, p.y))) {
next = p;
break;
}
if (next == null) break;
x = next.x;
y = next.y;
path.lineTo(x, y);
}
showImage(alpha);
showImage(renderShape(path, w, h));
}
sbool isInteresting(int q) {
ret q != 0 && q != 0x1111;
}
static int getQuadrant(Image2B img, int x, int y) {
ret (getQuadrant_getPixel(img, x, y) ? 0x1000 : 0) +
(getQuadrant_getPixel(img, x+1, y) ? 0x0100 : 0) +
(getQuadrant_getPixel(img, x, y+1) ? 0x0010 : 0) +
(getQuadrant_getPixel(img, x+1, y+1) ? 0x0001 : 0);
}
static bool getQuadrant_getPixel(Image2B img, int x, int y) {
ret x >= 0 && x < img.w && y >= 0 && y < img.h && img.getPixel(x, y);
}
static L neighborhood(int x, int y) {
ret ll(new Pt(x-1, y-1), new Pt(x, y-1), new Pt(x+1, y-1),
new Pt(x-1, y), new Pt(x+1, y),
new Pt(x-1, y+1), new Pt(x, y+1), new Pt(x+1, y+1));
}