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

30
LINES

< > BotCompany Repo | #1035868 // sumOfBinaryImages

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10980L/63K).

1  
// images must have same size
2  
static int[] sumOfBinaryImages(L<? extends IBinaryImage> images) {
3  
  int n = l(images);
4  
  if (n == 0) null;
5  
  var it = iterator(images);
6  
  var img = it.next();
7  
  int w = img.getWidth(), h = img.getHeight();
8  
  int[] pixels = new[w*h];
9  
  int nBytes = (w*h+7)/8;
10  
  var pingSource = pingSource();
11  
  
12  
  while (true) {
13  
    ping(pingSource);
14  
    Image2B realizedImage = img.toImage2B();
15  
    byte[] imgPixels = realizedImage.pixels;
16  
    int j = 0;
17  
    for i to nBytes: {
18  
      int b = imgPixels[i];
19  
      for bit to 8: {
20  
        pixels[j++] += b & 1;
21  
        b >>= 1;
22  
      }
23  
    }
24  
    
25  
    if (!it.hasNext()) break;
26  
    img = it.next();
27  
  }
28  
  
29  
  ret pixels;
30  
}

Author comment

Began life as a copy of #1035846

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1035868
Snippet name: sumOfBinaryImages
Eternal ID of this version: #1035868/3
Text MD5: 3e57dc6d90434e17f64969f501b98fa2
Transpilation MD5: 39e98947d2dfb1d739b74d5aea0f36ed
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-05 15:40:55
Source code size: 711 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 116 / 167
Version history: 2 change(s)
Referenced in: [show references]