Libraryless. Click here for Pure Java version (6941L/39K).
1 | // drawing the resulting image on img1 gives img2 |
2 | srecord noeq ImageDifferenceAsTransparentOverlay(BufferedImage img1, BufferedImage img2) { |
3 | int w, h; |
4 | int[] pixels; |
5 | int x1, y1, x2, y2; // changed area (inclusive) |
6 | |
7 | GrabbableIntPixels gp1, gp2; |
8 | |
9 | run { |
10 | if (pixels != null) ret; |
11 | int w = this.w = img1.getWidth(), h = this.h = img1.getHeight(); |
12 | assertSameSize(img1, img2); |
13 | int[] pixels = this.pixels = new int[w*h]; |
14 | |
15 | gp1 = grabbableIntPixels_fastOrSlow(img1); |
16 | gp2 = grabbableIntPixels_fastOrSlow(img2); |
17 | |
18 | int iPixels1 = gp1.offset, iPixels2 = gp2.offset; |
19 | int[] pixels1 = gp1.data, pixels2 = gp2.data; |
20 | int iPixels = 0; |
21 | x1 = w; y1 = h; x2 = 0; y2 = 0; |
22 | |
23 | for y to h: { |
24 | for x to w: { |
25 | int pix; |
26 | if ((pixels1[iPixels1+x] & 0xFFFFFF) |
27 | != (pix = pixels2[iPixels2+x] & 0xFFFFFF)) { |
28 | pixels[iPixels] = pix | 0xFF000000; |
29 | if (x < x1) x1 = x; |
30 | if (x > x2) x2 = x; |
31 | if (y < y1) y1 = y; |
32 | if (y > y2) y2 = y; |
33 | } |
34 | |
35 | iPixels++; |
36 | } |
37 | |
38 | iPixels1 += gp1.scanlineStride; |
39 | iPixels2 += gp2.scanlineStride; |
40 | } |
41 | } |
42 | |
43 | BufferedImage get() { |
44 | run(); |
45 | ret newBufferedImageWithAlpha(w, h, pixels); |
46 | } |
47 | |
48 | Rect changedBounds() { |
49 | run(); |
50 | ret rectFromPointsInclusive(x1, y1, x2, y2); |
51 | } |
52 | } |
Began life as a copy of #1034393
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034396 |
Snippet name: | ImageDifferenceAsTransparentOverlay |
Eternal ID of this version: | #1034396/7 |
Text MD5: | cf60b0b2c4a73dc64a51f114fa434cdd |
Transpilation MD5: | 7f7e65838a3c12bab6ea0841c129bc1e |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-05 03:35:47 |
Source code size: | 1400 bytes / 52 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 183 / 260 |
Version history: | 6 change(s) |
Referenced in: | [show references] |