!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 && !alpha.getPixel(x, y+1)) ++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); if (q == 0x0011) --x; else if (q == 0x1100) ++x; if (q == 0x0101) ++y; else if (q == 0x1010) --y; else if (q == 0x0111) { --x; ++y; } else if (q == 0x1011) { --x; --y; } else fail(q); // TODO path.lineTo(x, y); } // while (x != x1 || y != y1); showImage(alpha); showImage(renderShape(path, w, h)); } 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 && < img.h && img.getPixel(x, y); }