Libraryless. Click here for Pure Java version (7277L/41K).
1 | srecord noeq ImageDiffAsPNG(Rect r, byte[] pngData) is G2Drawable { |
2 | public void drawOn(Graphics2D g) { |
3 | var image = diffImage(); |
4 | if (image != null) |
5 | g.drawImage(image, r.x, r.y, null); |
6 | } |
7 | |
8 | BufferedImage diffImage() { |
9 | ret imageFromBytes(pngData); |
10 | } |
11 | |
12 | *(BufferedImage img1, BufferedImage img2) { |
13 | this(ImageDifferenceAsTransparentOverlay(img1, img2)); |
14 | } |
15 | |
16 | *(ImageDifferenceAsTransparentOverlay diff) { |
17 | r = diff.changedBounds(); |
18 | if (!empty(r)) |
19 | pngData = toPNG(clipBufferedImage(diff!, r)); |
20 | } |
21 | |
22 | bool isEmpty() { ret main empty(r); } |
23 | |
24 | toString { |
25 | ret isEmpty() ? "No change" |
26 | : "Changed area: " + r + ", png bytes: " + n2(l(pngData)) |
27 | + ", bits/pixel: " + formatDouble(bitsPerPixel(), 1); |
28 | } |
29 | |
30 | double bitsPerPixel() { |
31 | ret doubleRatio(l(pngData)*8L, area(r)); |
32 | } |
33 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034397 |
Snippet name: | ImageDiffAsPNG |
Eternal ID of this version: | #1034397/10 |
Text MD5: | 81d4282ba8ade86ba6e4f8d2ad990ffa |
Transpilation MD5: | 5cf1fa55c3ce506dc327c0219b3745f2 |
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:43:48 |
Source code size: | 871 bytes / 33 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 190 / 303 |
Version history: | 9 change(s) |
Referenced in: | [show references] |