Warning: session_start(): open(/var/lib/php/sessions/sess_cn0mqno7vbta79i6tj9a0t3pea, 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
// fills transparent pixels in the image with
// the color of the (roughly) closest non-transparent neighbor pixel
sclass ImageInfiller {
settable BufferedImage inputImage;
int w, h;
int[] pixels;
PtBuffer queue;
PtBuffer nextQueue;
BufferedImage outputImage;
gettable int rounds;
gettable int filledPixels;
*() {}
*(BufferedImage *inputImage) {}
run {
prepare();
do
oneRound();
while (!done());
}
bool done() {
ret nextQueue != null && nextQueue.isEmpty();
}
BufferedImage get() {
ret pixelsToBufferedImage(pixels, w);
}
void prepare {
pixels = pixelsFromBufferedImage(inputImage);
w = inputImage.getWidth();
h = inputImage.getHeight();
}
void oneRound {
++rounds;
queue = nextQueue;
nextQueue = new PtBuffer;
for (p : queue == null ? pixelsInImageIterator(w, h) : queue) {
int x = p.x, y = p.y;
int rgba = pixels[y*w+x];
if (!isTransparent(rgba)) continue;
//new IntBuffer colors; // surrounding colors
new MultiSet surroundingColors;
for (int y2 = max(0, y-1); y2 < min(h, y+2); y2++)
for (int x2 = max(0, x-1); x2 < min(w, x+2); x2++) {
rgba = pixels[y2*w+x2];
if (!isTransparent(rgba)) surroundingColors.add(rgba);
}
if (!surroundingColors.isEmpty()) {
// Surrounding color found, fill pixel
pixels[y*w+x] = surroundingColors.mostPopular();
filledPixels++;
// Schedule surrounding transparent pixels
for (int y2 = max(0, y-1); y2 < min(h, y+2); y2++)
for (int x2 = max(0, x-1); x2 < min(w, x+2); x2++)
nextQueue.add(x2, y2);
} else
// No surrounding colors found, reschedule this pixel
nextQueue.add(p);
}
print("Round " + rounds + " pixels filled: " + n2(filledPixels));
}
}