Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

30
LINES

< > BotCompany Repo | #1004632 // clusterImages

JavaX fragment (include)

1  
static BWImage clusterImages(L<BWImage> images) {
2  
  if (empty(images)) null;
3  
  int n = l(images);
4  
  int w = (int) sqrt(n), h = (n+w-1)/w;
5  
  int cw = 0, ch = 0;
6  
  for (BWImage i : images) {
7  
    cw = max(cw, i.getWidth());
8  
    ch = max(ch, i.getHeight());
9  
  }
10  
  // TODO: check if there are too many full black rows/cols in images
11  
  int iw = 1+w*(cw+1), ih = 1+h*(ch+1);
12  
  
13  
  // light gray background to distinguish between image and spacing
14  
  BWImage img = new BWImage(iw, ih, 0.95f);
15  
  
16  
  for (int x = 0; x < iw; x += cw+1)
17  
    for y to ih:
18  
      img.setPixel(x, y, 0f);
19  
  for (int y = 0; y < ih; y += ch+1)
20  
    for x to iw:
21  
      img.setPixel(x, y, 0f);
22  
  for i to n: {
23  
    int x = i % w, y = i / w;
24  
    BWImage im = images.get(i);
25  
    copyBWImage(im, 0, 0, img,
26  
      1+x*(cw+1)+(cw-im.getWidth())/2,
27  
      1+y*(ch+1)+(ch-im.getHeight())/2);
28  
  }
29  
  ret img;
30  
}

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: 526 / 519
Referenced in: [show references]