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

33
LINES

< > BotCompany Repo | #1034397 // ImageDiffAsPNG

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

Libraryless. Click here for Pure Java version (7277L/41K).

srecord noeq ImageDiffAsPNG(Rect r, byte[] pngData) is G2Drawable {
  public void drawOn(Graphics2D g) {
    var image = diffImage();
    if (image != null)
      g.drawImage(image, r.x, r.y, null);
  }
  
  BufferedImage diffImage() {
    ret imageFromBytes(pngData);
  }
  
  *(BufferedImage img1, BufferedImage img2) {
    this(ImageDifferenceAsTransparentOverlay(img1, img2));
  }
  
  *(ImageDifferenceAsTransparentOverlay diff) {
    r = diff.changedBounds();
    if (!empty(r))
      pngData = toPNG(clipBufferedImage(diff!, r));
  }
  
  bool isEmpty() { ret main empty(r); }
  
  toString {
    ret isEmpty() ? "No change"
      : "Changed area: " + r + ", png bytes: " + n2(l(pngData))
      + ", bits/pixel: " + formatDouble(bitsPerPixel(), 1);
  }
  
  double bitsPerPixel() {
    ret doubleRatio(l(pngData)*8L, area(r));
  }
}

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: 191 / 303
Version history: 9 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)