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

18
LINES

< > BotCompany Repo | #1033302 // scaledBufferedImageFromBWIntegralImage

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

Libraryless. Click here for Pure Java version (11530L/67K).

static BufferedImage scaledBufferedImageFromBWIntegralImage(int w, BWIntegralImage img) {
  ret scaledBufferedImageFromBWIntegralImage(img, w);
}

static BufferedImage scaledBufferedImageFromBWIntegralImage(BWIntegralImage img, int w, int h default heightForWidth(img.w, img.h, w)) {
  int w1 = img.w, h1 = img.h;
  int[] pixels = new[w*h];
  int i = 0;
  for y to h:
    for x to w: {
      // TODO: optimize
      int x1 = x*w1/w, x2 = max(x1+1, (x+1)*w1/w);
      int y1 = y*h1/h, y2 = max(y1+1, (y+1)*h1/h);
      int pixel = iround(img.getPixelAverage(x1, y1, x2, y2));
      pixels[i++] = brightnessToRGBA(pixel);
    }
  ret bufferedImage(w, h, pixels);
}

Author comment

Began life as a copy of #1019597

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1033302
Snippet name: scaledBufferedImageFromBWIntegralImage
Eternal ID of this version: #1033302/9
Text MD5: 5c728efb2105c4e8a978330c77e2c443
Transpilation MD5: 2f3a6f5340b06690ee4d52d437aa7922
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-27 15:36:41
Source code size: 679 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 207 / 301
Version history: 8 change(s)
Referenced in: [show references]