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

54
LINES

< > BotCompany Repo | #1033934 // gazelle22_borderImage

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

Libraryless. Click here for Pure Java version (6977L/40K).

static BWImage gazelle22_borderImage(BWImage posterizedWithMeta) {
  PosterizeBWImage op = cast getMetaSrc(posterizedWithMeta);
  ret gazelle22_borderImage(op.img, posterizedWithMeta, op.brightnessLevels);
}

static BWImage gazelle22_borderImage(BWImage unposterized, BWImage posterized, int brightnessLevels) {
  assertSameSize(unposterized, posterized);
  int w = posterized.getWidth(), h = posterized.getHeight();
  BWImage out = new(w*2+1, h*2+1);
  int singleStep = iceil(doubleRatio(255, brightnessLevels-1));
  
  for y to h:
    for x to w: {
      if (x < w-1) {
        // check border with right neighbor
        
        int posterizedContrast = absDiff(posterized.getInt(x, y),
          posterized.getInt(x+1, y));
          
        float result;
        if (posterizedContrast != 0) {
          if (posterizedContrast > singleStep) result = 1f;
          else {
            int realContrast = absDiff(unposterized.getInt(x, y),
              unposterized.getInt(x+1, y));
            result = floatRatio(realContrast, singleStep);
          }
          out.setPixel(x*2+1, y*2,   result);
          out.setPixel(x*2+1, y*2+1, result);
        }
      }
      
      if (y < h-1) {
        // check border with bottom neighbor
        
        int posterizedContrast = absDiff(posterized.getInt(x, y),
          posterized.getInt(x, y+1));
          
        float result;
        if (posterizedContrast != 0) {
          if (posterizedContrast > singleStep) result = 1f;
          else {
            int realContrast = absDiff(unposterized.getInt(x, y),
              unposterized.getInt(x+1, y));
            result = floatRatio(realContrast, singleStep);
          }
          out.setPixel(x*2,   y*2+1, result);
          out.setPixel(x*2+1, y*2+1, result);
        }
      }
    }
    
  ret out;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033934
Snippet name: gazelle22_borderImage
Eternal ID of this version: #1033934/5
Text MD5: 87534d412515d1c89f5c993b21ee75ce
Transpilation MD5: c23e8bc06316ec906d0851c27af1551e
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-14 01:14:36
Source code size: 1871 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 138 / 215
Version history: 4 change(s)
Referenced in: [show references]