// Path: code/jipsg/common/src/main/java/org/github/jipsg/common/image/BufferedImageFactory.java
// public class BufferedImageFactory {
// 
//     public static BufferedImage create(Object source) throws Exception {
// 
//         BufferedImage result;
// 
//         if (source instanceof File) {
//             File sourceFile = (File) source;
//             result = ImageIO.read(sourceFile);
//         } else if (source instanceof String) {
//             File sourceFile = new File(source.toString());
//             result = ImageIO.read(sourceFile);
//         } else {
//             throw new IllegalArgumentException("Don't know how to handle : " + source.getClass().getName());
//         }
// 
//         return result;
//     }
// 
//     public static boolean writeBufferedImage(BufferedImage bufferedImage, String formatName, File file) throws Exception {
//         System.out.println("Saving " + file.getPath());
//         return ImageIO.write(bufferedImage, formatName, file);
//     }
// }
// 
// Path: code/jipsg/imageio/src/main/java/org/github/jipsg/imageio/BaseImageIoTest.java
// public class BaseImageIoTest extends AbstractImageTest {
// 
//     @Override
//     public void setup() {
//         super.setModuleName("imageio");
//         super.setup();
//     }
// 
//     @Override
//     public BufferedImage createBufferedImage(File file) throws IOException {
//         return ImageIO.read(file);
//     }
// 
//     @Override
//     public void writeBufferedImage(BufferedImage bufferedImage, String formatName, File targetFile) throws Exception {
//         System.out.println("Saving " + targetFile.getPath());
//         ImageIO.write(bufferedImage, formatName, targetFile);
//     }
// 
//     @Override
//     public void writeBufferedImage(BufferedImage bufferedImage, float quality, int dpi, String formatName, File targetFile) throws Exception {
// 
//         System.out.println("Saving " + targetFile.getPath());
// 
//         if (formatName.equalsIgnoreCase("jpg") || formatName.equalsIgnoreCase("jpeg")) {
//             JPEGImageWriter imageWriter = (JPEGImageWriter) ImageIO.getImageWritersBySuffix(formatName).next();
//             ImageWriteParam writeParam = imageWriter.getDefaultWriteParam();
//             ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
//             IIOMetadata metadata = imageWriter.getDefaultImageMetadata(typeSpecifier, writeParam);
// 
//             if (formatName.equalsIgnoreCase("jpg") || formatName.equalsIgnoreCase("jpeg")) {
//                 Element tree = (Element) metadata.getAsTree("javax_imageio_jpeg_image_1.0");
//                 Element jfif = (Element) tree.getElementsByTagName("app0JFIF").item(0);
//                 jfif.setAttribute("Xdensity", Integer.toString(dpi));
//                 jfif.setAttribute("Ydensity", Integer.toString(dpi));
//                 jfif.setAttribute("resUnits", "1");
//                 metadata.setFromTree("javax_imageio_jpeg_image_1.0", tree);
//             }
// 
//             if (quality >= 0 && quality <= 1f) {
//                 JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam();
//                 jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
//                 jpegParams.setCompressionQuality(quality);
//             }
// 
//             FileOutputStream os = new FileOutputStream(targetFile);
//             final ImageOutputStream stream = ImageIO.createImageOutputStream(os);
// 
//             try {
//                 imageWriter.setOutput(stream);
//                 imageWriter.write(metadata, new IIOImage(bufferedImage, null, metadata), writeParam);
//             } finally {
//                 stream.close();
//             }
//         } else {
//             writeBufferedImage(bufferedImage, formatName, targetFile);
//         }
//     }
// 
//     /**
//      * Some quick and dirty image scaling - please note that for best performance
//      * and quality you should use image rescaling libraries.
//      */
//     @Override
//     public BufferedImage resample(BufferedImage bufferedImage, int width, int height) {
//         Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
//         Dimension boundaryDimension = new Dimension(width, height);
//         Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension);
// 
//         double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth();
//         double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight();
// 
//         AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
//         AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
// 
//         return biLinearScaleOp.filter(
//                 bufferedImage,
//                 new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType()));
//     }
// }


import org.github.jipsg.common.image.BufferedImageFactory;
import org.github.jipsg.imageio.BaseImageIoTest;
import org.junit.Test;
import java.awt.image.BufferedImage;
import java.io.File;
import static org.junit.Assert.assertNull;
package org.github.jipsg.image.comparison;




/**
 * Created by sgoeschl on 18/11/14.
 */
public class IdenticalImageComparatorTest extends BaseImageIoTest {


    @Override
    public void setup() {
        super.setModuleName("image-processing");
        super.setup();
    }

    @Test
    public void testIdenticalImage() throws Exception {

        final BufferedImage bufferedImage1 = BufferedImageFactory.create("../../images/samples/open-office-01.pdf.300.0.png");
        final BufferedImage bufferedImage2 = BufferedImageFactory.create("../../images/samples/open-office-01.pdf.300.0.png");
        final IdenticalImageComparator identicalImageComparator = new IdenticalImageComparator();
        assertNull(identicalImageComparator.diffImages(bufferedImage1, bufferedImage2));
    }

    @Test
    public void testModifiedImage() throws Exception {

        final BufferedImage bufferedImage1 = BufferedImageFactory.create("../../images/samples/open-office-01.pdf.300.0.png");
        final BufferedImage bufferedImage2 = BufferedImageFactory.create("../../images/samples/open-office-02.pdf.300.0.png");
// Path: code/jipsg/common/src/main/java/org/github/jipsg/common/image/BufferedImageFactory.java
// public class BufferedImageFactory {
// 
//     public static BufferedImage create(Object source) throws Exception {
// 
//         BufferedImage result;
// 
//         if (source instanceof File) {
//             File sourceFile = (File) source;
//             result = ImageIO.read(sourceFile);
//         } else if (source instanceof String) {
//             File sourceFile = new File(source.toString());
//             result = ImageIO.read(sourceFile);
//         } else {
//             throw new IllegalArgumentException("Don't know how to handle : " + source.getClass().getName());
//         }
// 
//         return result;
//     }
// 
//     public static boolean writeBufferedImage(BufferedImage bufferedImage, String formatName, File file) throws Exception {
//         System.out.println("Saving " + file.getPath());
//         return ImageIO.write(bufferedImage, formatName, file);
//     }
// }
// 
// Path: code/jipsg/imageio/src/main/java/org/github/jipsg/imageio/BaseImageIoTest.java
// public class BaseImageIoTest extends AbstractImageTest {
// 
//     @Override
//     public void setup() {
//         super.setModuleName("imageio");
//         super.setup();
//     }
// 
//     @Override
//     public BufferedImage createBufferedImage(File file) throws IOException {
//         return ImageIO.read(file);
//     }
// 
//     @Override
//     public void writeBufferedImage(BufferedImage bufferedImage, String formatName, File targetFile) throws Exception {
//         System.out.println("Saving " + targetFile.getPath());
//         ImageIO.write(bufferedImage, formatName, targetFile);
//     }
// 
//     @Override
//     public void writeBufferedImage(BufferedImage bufferedImage, float quality, int dpi, String formatName, File targetFile) throws Exception {
// 
//         System.out.println("Saving " + targetFile.getPath());
// 
//         if (formatName.equalsIgnoreCase("jpg") || formatName.equalsIgnoreCase("jpeg")) {
//             JPEGImageWriter imageWriter = (JPEGImageWriter) ImageIO.getImageWritersBySuffix(formatName).next();
//             ImageWriteParam writeParam = imageWriter.getDefaultWriteParam();
//             ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
//             IIOMetadata metadata = imageWriter.getDefaultImageMetadata(typeSpecifier, writeParam);
// 
//             if (formatName.equalsIgnoreCase("jpg") || formatName.equalsIgnoreCase("jpeg")) {
//                 Element tree = (Element) metadata.getAsTree("javax_imageio_jpeg_image_1.0");
//                 Element jfif = (Element) tree.getElementsByTagName("app0JFIF").item(0);
//                 jfif.setAttribute("Xdensity", Integer.toString(dpi));
//                 jfif.setAttribute("Ydensity", Integer.toString(dpi));
//                 jfif.setAttribute("resUnits", "1");
//                 metadata.setFromTree("javax_imageio_jpeg_image_1.0", tree);
//             }
// 
//             if (quality >= 0 && quality <= 1f) {
//                 JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam();
//                 jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
//                 jpegParams.setCompressionQuality(quality);
//             }
// 
//             FileOutputStream os = new FileOutputStream(targetFile);
//             final ImageOutputStream stream = ImageIO.createImageOutputStream(os);
// 
//             try {
//                 imageWriter.setOutput(stream);
//                 imageWriter.write(metadata, new IIOImage(bufferedImage, null, metadata), writeParam);
//             } finally {
//                 stream.close();
//             }
//         } else {
//             writeBufferedImage(bufferedImage, formatName, targetFile);
//         }
//     }
// 
//     /**
//      * Some quick and dirty image scaling - please note that for best performance
//      * and quality you should use image rescaling libraries.
//      */
//     @Override
//     public BufferedImage resample(BufferedImage bufferedImage, int width, int height) {
//         Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
//         Dimension boundaryDimension = new Dimension(width, height);
//         Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension);
// 
//         double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth();
//         double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight();
// 
//         AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
//         AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
// 
//         return biLinearScaleOp.filter(
//                 bufferedImage,
//                 new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType()));
//     }
// }


// Path: code/jipsg/image-manipulation/src/test/java/org/github/jipsg/image/comparison/IdenticalImageComparatorTest.java
import org.github.jipsg.common.image.BufferedImageFactory;
import org.github.jipsg.imageio.BaseImageIoTest;
import org.junit.Test;
import java.awt.image.BufferedImage;
import java.io.File;
import static org.junit.Assert.assertNull;

package org.github.jipsg.image.comparison;




/**
 * Created by sgoeschl on 18/11/14.
 */
public class IdenticalImageComparatorTest extends BaseImageIoTest {


    @Override
    public void setup() {
        super.setModuleName("image-processing");
        super.setup();
    }

    @Test
    public void testIdenticalImage() throws Exception {

        final BufferedImage bufferedImage1 = BufferedImageFactory.create("../../images/samples/open-office-01.pdf.300.0.png");
        final BufferedImage bufferedImage2 = BufferedImageFactory.create("../../images/samples/open-office-01.pdf.300.0.png");
        final IdenticalImageComparator identicalImageComparator = new IdenticalImageComparator();
        assertNull(identicalImageComparator.diffImages(bufferedImage1, bufferedImage2));
    }

    @Test
    public void testModifiedImage() throws Exception {

        final BufferedImage bufferedImage1 = BufferedImageFactory.create("../../images/samples/open-office-01.pdf.300.0.png");
        final BufferedImage bufferedImage2 = BufferedImageFactory.create("../../images/samples/open-office-02.pdf.300.0.png");
        final IdenticalImageComparator identicalImageComparator = new IdenticalImageComparator();