static BWImage clusterImages(L<BWImage> images) { if (empty(images)) null; int n = l(images); int w = (int) sqrt(n), h = (n+w-1)/w; int cw = 0, ch = 0; for (BWImage i : images) { cw = max(cw, i.getWidth()); ch = max(ch, i.getHeight()); } // TODO: check if there are too many full black rows/cols in images int iw = 1+w*(cw+1), ih = 1+h*(ch+1); // light gray background to distinguish between image and spacing BWImage img = new BWImage(iw, ih, 0.95f); for (int x = 0; x < iw; x += cw+1) for y to ih: img.setPixel(x, y, 0f); for (int y = 0; y < ih; y += ch+1) for x to iw: img.setPixel(x, y, 0f); for i to n: { int x = i % w, y = i / w; BWImage im = images.get(i); copyBWImage(im, 0, 0, img, 1+x*(cw+1)+(cw-im.getWidth())/2, 1+y*(ch+1)+(ch-im.getHeight())/2); } ret img; }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1004632 |
| Snippet name: | clusterImages |
| Eternal ID of this version: | #1004632/1 |
| Text MD5: | f7b3990b01587a13f8ff1c25edad505d |
| Author: | stefan |
| Category: | javax / images |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-08-24 19:22:58 |
| Source code size: | 888 bytes / 30 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 871 / 849 |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |