diff --git a/lib/browser/client-scripts/gemini.calibrate.js b/lib/browser/client-scripts/gemini.calibrate.js index ec0bfc1db..8521979cd 100644 --- a/lib/browser/client-scripts/gemini.calibrate.js +++ b/lib/browser/client-scripts/gemini.calibrate.js @@ -35,5 +35,4 @@ bodyStyle.width = '100%'; bodyStyle.height = '100%'; createRedStripe('left'); - createRedStripe('right'); }(window)); diff --git a/lib/browser/index.js b/lib/browser/index.js index 0745e3c00..e3c04e830 100644 --- a/lib/browser/index.js +++ b/lib/browser/index.js @@ -242,8 +242,8 @@ module.exports = inherit({ image = image.crop({ left: _this._calibration.left, top: _this._calibration.top, - width: image.getSize().width - _this._calibration.right - _this._calibration.left, - height: image.getSize().height - _this._calibration.bottom - _this._calibration.top + width: image.getSize().width - _this._calibration.left, + height: image.getSize().height - _this._calibration.top }); } diff --git a/lib/calibrator.js b/lib/calibrator.js index 28553061f..0be122db7 100644 --- a/lib/calibrator.js +++ b/lib/calibrator.js @@ -38,12 +38,12 @@ Calibrator.prototype.calibrate = function(browser) { * Compare pixel with given x,y to given pixel in the pattern * @param {Object} coords * @param {Object} positionData position data - * @param [Boolean] reverse should be true when traversing x from right to left */ - function checkPattern(coords, positionData, reverse) { + function checkPattern(coords, positionData) { if (Image.RGBToString(image.getRGBA(coords.x, coords.y)) === find[positionData.u]) { if (++positionData.u === find.length) { - positionData.pos = {x: coords.x - (reverse? -1 : 1) * (find.length - 1), y: coords.y}; + positionData.pos = {x: coords.x - (find.length - 1), y: coords.y}; + return positionData.pos; } return; @@ -54,21 +54,17 @@ Calibrator.prototype.calibrate = function(browser) { var width = image.getSize().width, height = image.getSize().height, - start = {u: 0}, - end = {u: 0}; + start = {u: 0}; - for (var y = 0; y < height && (!start.pos || !end.pos); y++) { - for (var x = 0; x < width; x++) { - if (!start.pos) { - checkPattern({x: x, y: y}, start); - } - if (!end.pos) { - checkPattern({x: width - x - 1, y: height - y - 1}, end, true); + outer: for (var y = 0; y < height && !start.pos; y++) { + for (var x = 0; x < width && !start.pos; x++) { + if (checkPattern({x: x, y: y}, start)) { + break outer; } } } - if (!start.pos || !end.pos) { + if (!start.pos) { return q.reject(new GeminiError( 'Could not calibrate. This could be due to calibration page has failed to open properly' )); @@ -76,9 +72,7 @@ Calibrator.prototype.calibrate = function(browser) { var calibration = { top: start.pos.y, - left: start.pos.x, - right: width - 1 - end.pos.x, - bottom: height - 1 - end.pos.y + left: start.pos.x }; _this._cache[browser.id] = calibration; diff --git a/test/browser.test.js b/test/browser.test.js index eae3c09dd..560390c5e 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -252,7 +252,7 @@ describe('browser', function() { return image.getSize(); }); - return assert.eventually.deepEqual(size, {width: 572, height: 311}); + return assert.eventually.deepEqual(size, {width: 574, height: 311}); }); }); diff --git a/test/calibrator.test.js b/test/calibrator.test.js index a16f82798..1186ecabb 100644 --- a/test/calibrator.test.js +++ b/test/calibrator.test.js @@ -37,7 +37,7 @@ describe('calibrator', function() { it('should calculate correct crop area', function() { setScreenshot('calibrate.png'); var result = calibrator.calibrate(browser); - return assert.eventually.deepEqual(result, {top: 24, left: 6, right: 2, bottom: 0}); + return assert.eventually.deepEqual(result, {top: 24, left: 6}); }); it('should not perform the calibration process two times', function() { @@ -59,7 +59,7 @@ describe('calibrator', function() { .then(function() { return calibrator.calibrate(browser); }); - return assert.eventually.deepEqual(result, {top: 24, left: 6, right: 2, bottom: 0}); + return assert.eventually.deepEqual(result, {top: 24, left: 6}); }); it('should fail on broken calibration page', function() {