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

25
LINES

< > BotCompany Repo | #1035818 // RegionToImage2B - also works for IPixelSet

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

Transpiled version (11449L) is out of date.

1  
// result image is as large as the region's bounds
2  
// with black pixels inside and white pixels outside the region
3  
srecord noeq RegionToImage2B(IPixelSet region) {
4  
  settable Rect bounds;
5  
  Image2B image;
6  
  
7  
  run {
8  
    bounds if null = region.bounds();
9  
    int x1 = bounds.x, y1 = bounds.y, w = bounds.w, h = bounds.h, i = 0;
10  
    byte[] pixels = new[(w*h+7)/8];
11  
    for y to h:
12  
      for x to w: {
13  
        if (!region.contains(x1+x, y1+y))
14  
          pixels[i/8] |= 1 << (i & 7);
15  
        i++;
16  
      }
17  
      
18  
    image = new Image2B(w, h, pixels);
19  
  }
20  
  
21  
  Image2B get() {
22  
    if (image == null) run();
23  
    ret image;
24  
  }
25  
}

Author comment

Began life as a copy of #1034574

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1035818
Snippet name: RegionToImage2B - also works for IPixelSet
Eternal ID of this version: #1035818/5
Text MD5: 6c7672dff4cf985befd3ea47bcbf33b4
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-15 20:26:55
Source code size: 646 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 79 / 132
Version history: 4 change(s)
Referenced in: [show references]