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

20
LINES

< > BotCompany Repo | #1033935 // PosterizeBWImage

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

Libraryless. Click here for Pure Java version (14694L/85K).

1  
srecord noeq PosterizeBWImage(int brightnessLevels, BWImage img) is PixelPreservingImageOpResult<BWImage> {
2  
  BWImage result;
3  
  
4  
  run {
5  
    if (brightnessLevels >= 256 || img == null) ret with result = img;
6  
    byte[] pixels = img.getBytes();
7  
    int w = img.getWidth(), h = img.getHeight(), n = pixels.length;
8  
    byte[] pixels2 = new[n];
9  
    var posterizer = cachePosterizer(SinglePixelPosterizer(brightnessLevels));
10  
11  
    for i to n:
12  
      pixels2[i] = (byte) posterizer.get(ubyteToInt(pixels[i]));
13  
  
14  
    result = new BWImage(w, h, pixels2);
15  
  }
16  
  
17  
  public BWImage pixelPreservingSrcImage() { ret img; }
18  
  
19  
  BWImage get() { if (result == null) run(); ret result; }
20  
}

Author comment

Began life as a copy of #1033678

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033935
Snippet name: PosterizeBWImage
Eternal ID of this version: #1033935/9
Text MD5: 93ca3bc00ea2a7c3782b20bcfbcf6db6
Transpilation MD5: 8f8063eb9c0383ea0a5b17353bf3fbaa
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-17 21:48:52
Source code size: 691 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 178 / 347
Version history: 8 change(s)
Referenced in: [show references]