@@ -0,0 +1,2232 @@
+package asdff;%0A%0Aimport com.google.common.base.Function;%0A%0Aimport java.awt.image.BufferedImage;%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.util.UUID;%0A%0Aimport javax.imageio.ImageIO;%0A%0Apublic class ImageDiffWriter %7B%0A  private static final int DIFF_COLOR = 0x00FF3E96;%0A%0A  private final String diffPath;%0A%0A  public ImageDiffWriter(String diffPath) %7B%0A    this.diffPath = diffPath;%0A  %7D%0A%0A  public Function%3CScreenshotDiff, ScreenshotDiff%3E doWork() %7B%0A    return new Function%3CScreenshotDiff, ScreenshotDiff%3E() %7B%0A      public ScreenshotDiff apply(ScreenshotDiff input) %7B%0A        try %7B%0A          File diffFile = new File(diffPath, UUID.randomUUID().toString() + %22.png%22);%0A          System.out.println(%0A              %22Found difference! Creating diff image: %22 + diffFile.toPath().toString());%0A          BufferedImage oldImage = ImageIO.read(new ByteArrayInputStream(input.getOldData()));%0A          BufferedImage newImage = ImageIO.read(new ByteArrayInputStream(input.getNewData()));%0A%0A          BufferedImage diffImage = produceDiffImage(oldImage, newImage);%0A%0A          ImageIO.write(diffImage, %22png%22, diffFile);%0A        %7D catch (IOException e) %7B%0A          e.printStackTrace();%0A        %7D%0A%0A        return null;%0A      %7D%0A    %7D;%0A  %7D%0A%0A  private static BufferedImage produceDiffImage(BufferedImage oldImage, BufferedImage newImage) %7B%0A    BufferedImage img1 = oldImage;%0A    BufferedImage img2 = newImage;%0A%0A    int width1 = img1.getWidth(null);%0A    int width2 = img2.getWidth(null);%0A    int height1 = img1.getHeight(null);%0A    int height2 = img2.getHeight(null);%0A%0A    assert ((width1 != width2) %7C%7C (height1 != height2));%0A%0A    if ((width1 != width2) %7C%7C (height1 != height2)) %7B%0A      System.err.println(%22Error: Images dimensions mismatch%22);%0A      System.exit(1);%0A    %7D%0A%0A    BufferedImage diffImage = new BufferedImage(width1, height1, BufferedImage.TYPE_INT_RGB);%0A%0A    for (int i = 0; i %3C height1; i++) %7B%0A      for (int j = 0; j %3C width1; j++) %7B%0A        int rgb1 = img1.getRGB(j, i);%0A        int rgb2 = img2.getRGB(j, i);%0A%0A        if (rgb1 == rgb2) %7B%0A          diffImage.setRGB(j, i, rgb1);%0A        %7D else %7B%0A          diffImage.setRGB(j, i, DIFF_COLOR);%0A        %7D%0A      %7D%0A    %7D%0A%0A    return diffImage;%0A  %7D%0A%7D%0A

Create ImageDiffWriter.java