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

14
LINES

< > BotCompany Repo | #1032771 // imageChangeOverlay - returns image1 but transparent where both images are identical

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

Libraryless. Click here for Pure Java version (3924L/23K).

// Note: This can probably be optimized if all pixels are direct-grabbed
// and image2 is expendable (then you can use it as output?)
static BufferedImage imageChangeOverlay(BufferedImage image1, BufferedImage image2) {
  assertSameSize(image1, image2);
  int w = image1.getWidth(), h = image1.getHeight(), n = w*h;
  int[] pixels1 = pixelsOfBufferedImage(image1);
  int[] pixels2 = pixelsOfBufferedImage(image2);
  int[] pixelsOut = new[n];
  for i to n: {
    int rgb = pixels1[i];
    pixelsOut[i] = rgb == pixels2[i] ? 0 : rgb;
  }
  ret newBufferedImage(w, h, pixelsOut);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1032771
Snippet name: imageChangeOverlay - returns image1 but transparent where both images are identical
Eternal ID of this version: #1032771/2
Text MD5: b91a91f3ee1e747e25f7300e5473050a
Transpilation MD5: 48a1eb3f9fdd27aa4512bc3c7227b5ff
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-05 23:01:57
Source code size: 591 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 171 / 265
Version history: 1 change(s)
Referenced in: [show references]