Skip to content

Commit

Permalink
Return bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
edi9999 committed Mar 28, 2017
1 parent d7953ce commit c84476b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 39 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Changelog
Changelog
=========

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.0 - 2016-12-14
1.0.0 [unreleased]
------------------

### Changed

* Update api to be error-first ([#30](https://github.com/edi9999/jsqrcode/pull/30))
- Update api to return result and bounding box : https://github.com/edi9999/jsqrcode/issues/35
- Update api to be error-first ([#30](https://github.com/edi9999/jsqrcode/pull/30)\)

## 0.x
0.x
---

* Initial release
- Initial release
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ var data = context.getImageData(0, 0, width, height);
qr.decode(data);
```

Decode from canvas with "qr-canvas" ID:

```
qr.decode()
```

Building it yourself
====================

If you want, you can build the script yourself.
Expand Down Expand Up @@ -97,6 +90,6 @@ You will have access to the global variable `QrCode` if you do the following in
See [examples/browser-upload/index.html](examples/browser-upload/index.html) for a very basic example using a file upload.

Changelog
===========================
=========

See [`CHANGELOG.md`](CHANGELOG.md).
See [`CHANGELOG.md`](CHANGELOG.md)\.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
},
"homepage": "https://github.com/edi9999/jsqrcode",
"devDependencies": {
"chai": "^1.9.1",
"chai": "^3.5.0",
"eslint": "^2.13.1",
"mocha": "^2.4.5",
"image-parser": "^1.2.4",
"mocha": "^3.2.0",
"rollup": "^0.34.13",
"uglify-js": "^2.7.3"
}
Expand Down
16 changes: 2 additions & 14 deletions src/qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,8 @@ QrCode.prototype.decode = function(src, data) {

}).bind(this);

if (src == undefined) {
/* decode from canvas #qr-canvas */

var canvas_qr = document.getElementById("qr-canvas");
var context = canvas_qr.getContext('2d');

this.width = canvas_qr.width;
this.height = canvas_qr.height;
this.imagedata = context.getImageData(0, 0, this.width, this.height);

decode();
} else if (src.width != undefined) {
if (src != undefined && src.width != undefined) {
/* decode from canvas canvas.context.getImageData */

this.width = src.width;
this.height = src.height;
this.imagedata = {"data": data || src.data};
Expand Down Expand Up @@ -153,7 +141,7 @@ QrCode.prototype.process = function(imageData) {
console.log('QR Code processing time (ms): ' + time);
}

return this.decode_utf8(str);
return {result: this.decode_utf8(str), points: qRCodeMatrix.points};
};

QrCode.prototype.getPixel = function(imageData, x, y) {
Expand Down
62 changes: 53 additions & 9 deletions test/qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var fs = require('fs');
var QrCode = require('../dist/index.js');
var ImageParser = require("image-parser");

function copy(input) {
return JSON.parse(JSON.stringify(input));
}

it('should work with basic image', function(done) {
var c = fs.readFileSync(__dirname + '/image.png');
var img = new ImageParser(c);
Expand All @@ -13,9 +17,31 @@ it('should work with basic image', function(done) {
var qr = new QrCode();
qr.callback = function(error, result) {
if (error) {
done(error);
return done(error);
}
expect(result).to.equal('Test');
expect(copy(result)).to.deep.equal({
"result": 'Test',
"points": [
{
"count": 2,
"estimatedModuleSize": 8,
"x": 36,
"y": 148,
},
{
"count": 2,
"estimatedModuleSize": 8,
"x": 36,
"y": 36,
},
{
"count": 2,
"estimatedModuleSize": 8,
"x": 148,
"y": 36,
}
]
});
done();
};
qr.decode({width: img.width(), height: img.height()}, img._imgBuffer);
Expand All @@ -32,15 +58,33 @@ it('should work with imageData format', function(done) {
var qr = new QrCode();
qr.callback = function(error, result) {
if (error) {
done(error);
return done(error);
}
expect(result).to.equal('Test');
expect(copy(result)).to.deep.equal({
"result": 'Test',
"points": [
{
"count": 2,
"estimatedModuleSize": 8,
"x": 36,
"y": 148,
},
{
"count": 2,
"estimatedModuleSize": 8,
"x": 36,
"y": 36,
},
{
"count": 2,
"estimatedModuleSize": 8,
"x": 148,
"y": 36,
}
]
});
done();
};
qr.decode({
height: img.height(),
width: img.width(),
data: img._imgBuffer
});
qr.decode({height: img.height(), width: img.width(), data: img._imgBuffer});
});
});

0 comments on commit c84476b

Please sign in to comment.