Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #159 from gemini-testing/fix/calib-crop
Browse files Browse the repository at this point in the history
Calibrator only looks for left side marker
  • Loading branch information
scf2k committed Apr 29, 2015
2 parents 9dce719 + 90da220 commit 14ad755
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
1 change: 0 additions & 1 deletion lib/browser/client-scripts/gemini.calibrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@
bodyStyle.width = '100%';
bodyStyle.height = '100%';
createRedStripe('left');
createRedStripe('right');
}(window));
4 changes: 2 additions & 2 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down
24 changes: 9 additions & 15 deletions lib/calibrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,31 +54,25 @@ 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++) {
outer: for (var y = 0; y < height; 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);
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'
));
}

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;
Expand Down
2 changes: 1 addition & 1 deletion test/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/calibrator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 14ad755

Please sign in to comment.