'use strict';

/**
 * compare images
 */

var resemble = require('node-resemble-js');

module.exports = function() {

    /**
     * need to find done function because gm doesn't have node like callbacks (err,res)
     */
    var done = arguments[arguments.length - 1];

    /**
     * if there is no need for image comparison or no images gets saved on fs, just continue
     */
    if(!this.isComparable || !this.self.saveImages) {
        return done();
    }

    // This feature makes the output nearly worthless and impossible to read.
    // Set it high enought that we never hit it.
    resemble.outputOptions({largeImageThreshold:1000000000})

    /**
     * compare images
     */
    var diff = resemble(this.baselinePath).compareTo(this.regressionPath);

    /**
     * map 'ignore' configuration to resemble options
     */
    var ignore = this.currentArgs.ignore || "";
    if (ignore.indexOf("color") === 0) {
        diff.ignoreColors();
    } else if (ignore.indexOf("antialias") === 0) {
        diff.ignoreAntialiasing();
    }

    /**
     * execute the comparison
     */
    diff.onComplete(done.bind(null,null));
};

@@ -546,48 +546,19 @@
  // 
-Set it high enought that we never hit it
+Turn it off
 .%0A  
@@ -607,17 +607,8 @@
 old:
-100000000
 0%7D)%0A

disable explicitly