// シームレス画像作成テスト /* @pjs preload="taj_orig.jpg"; */ PImage img, dstImg; void setup() { size(512, 512); img = loadImage("taj_orig.jpg"); dstImg = makeSeamless(img); } void draw() { background(128); // マウスボタンを押していたら元画像を表示 if ( mousePressed == true) { image(img, 0, 0); } else { image(dstImg, 0, 0); } } // マウスボタンクリック時 void mouseClicked() { if (mouseButton != RIGHT) return; // 右ボタンが押されたら画像保存 dstImg.save("dst.png"); } PImage makeSeamless(PImage img) { color src0, src1; float dstr, dstg, dstb; int adrs0, adrs1; int w = img.width; int h = img.height; PImage dstImg = createImage(w, h, ARGB); img.loadPixels(); dstImg.loadPixels(); int hw = w / 2; int hh = h / 2; float sz = (hw - 1) * (hh - 1); for (float y=0; y < h; y++) { for (float x=0; x < w; x++) { float vx = ((x < hw)? x : (w - x - 1)) / (hw - 1); float vy = ((y < hh)? y : (h - y - 1)) / (hh - 1); float d0 = (1 - vx * vy); float d1 = (1 - d0); adrs0 = int((y + hh) % h * w + (x + hw) % w); adrs1 = int(y * w + x); src0 = img.pixels[adrs0]; src1 = img.pixels[adrs1]; dstr = red(src0) * d0 + red(src1) * d1; dstg = green(src0) * d0 + green(src1) * d1; dstb = blue(src0) * d0 + blue(src1) * d1; dstImg.pixels[adrs0] = color(dstr, dstg, dstb); } } dstImg.updatePixels(); return dstImg; }