Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error in decoding Code 128 barcodes #79

Merged
merged 1 commit into from
Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
quaggaJS
========

- [Changelog](#changelog) (2015-11-15)
- [Changelog](#changelog) (2015-11-22)

## What is QuaggaJS?

Expand Down Expand Up @@ -434,6 +434,12 @@ on the ``singleChannel`` flag in the configuration when using ``decodeSingle``.

## <a name="changelog">Changelog</a>

### 2015-11-22

- Fixes
- Fixed inconsistencies for Code 128 decoding (See
[\#76](https://github.com/serratus/quaggaJS/issues/76))

### 2015-11-15

- Fixes
Expand Down
48 changes: 31 additions & 17 deletions dist/quagga.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/quagga.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/static_images.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h3>Working with static images</h3>
&copy; Copyright by Christoph Oberhofer
</p>
</footer>
<script src="../src/vendor/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="vendor/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="../dist/quagga.js" type="text/javascript"></script>
<script src="static_images.js" type="text/javascript"></script>
</body>
Expand Down
48 changes: 31 additions & 17 deletions lib/quagga.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quagga",
"version": "0.8.1",
"version": "0.8.2",
"description": "An advanced barcode-scanner written in JavaScript",
"main": "lib/quagga.js",
"browser": "dist/quagga.min.js",
Expand Down
47 changes: 31 additions & 16 deletions src/code_128_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ Code128Reader.prototype._decode = function() {
rawResult = [],
decodedCodes = [],
shiftNext = false,
unshift;
unshift,
removeLastCharacter = true;

if (startInfo === null) {
return null;
Expand Down Expand Up @@ -278,6 +279,10 @@ Code128Reader.prototype._decode = function() {
shiftNext = false;
code = self._decodeCode(code.end);
if (code !== null) {
if (code.code !== self.STOP_CODE) {
removeLastCharacter = true;
}

if (code.code !== self.STOP_CODE) {
rawResult.push(code.code);
multiplier++;
Expand All @@ -292,6 +297,9 @@ Code128Reader.prototype._decode = function() {
} else if (code.code < 96) {
result.push(String.fromCharCode(code.code - 64));
} else {
if (code.code !== self.STOP_CODE) {
removeLastCharacter = false;
}
switch (code.code) {
case self.CODE_SHIFT:
shiftNext = true;
Expand All @@ -313,6 +321,9 @@ Code128Reader.prototype._decode = function() {
if (code.code < 96) {
result.push(String.fromCharCode(32 + code.code));
} else {
if (code.code !== self.STOP_CODE) {
removeLastCharacter = false;
}
switch (code.code) {
case self.CODE_SHIFT:
shiftNext = true;
Expand All @@ -333,17 +344,21 @@ Code128Reader.prototype._decode = function() {
case self.CODE_C:
if (code.code < 100) {
result.push(code.code < 10 ? "0" + code.code : code.code);
}
switch (code.code) {
case self.CODE_A:
codeset = self.CODE_A;
break;
case self.CODE_B:
codeset = self.CODE_B;
break;
case self.STOP_CODE:
done = true;
break;
} else {
if (code.code !== self.STOP_CODE) {
removeLastCharacter = false;
}
switch (code.code) {
case self.CODE_A:
codeset = self.CODE_A;
break;
case self.CODE_B:
codeset = self.CODE_B;
break;
case self.STOP_CODE:
done = true;
break;
}
}
break;
}
Expand All @@ -359,14 +374,11 @@ Code128Reader.prototype._decode = function() {
return null;
}

// find end bar
code.end = self._nextUnset(self._row, code.end);
if (!self._verifyTrailingWhitespace(code)){
return null;
}

// checksum
// Does not work correctly yet!!! startcode - endcode?
checksum -= multiplier * rawResult[rawResult.length - 1];
if (checksum % 103 !== rawResult[rawResult.length - 1]) {
return null;
Expand All @@ -377,7 +389,10 @@ Code128Reader.prototype._decode = function() {
}

// remove last code from result (checksum)
result.splice(result.length - 1, 1);
if (removeLastCharacter) {
result.splice(result.length - 1, 1);
}


return {
code: result.join(""),
Expand Down
2 changes: 1 addition & 1 deletion test/integration/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('decodeSingle', function () {
{"name": "image-005.jpg", "result": "419055603900009001012999"},
{"name": "image-006.jpg", "result": "419055603900009001012999"},
{"name": "image-007.jpg", "result": "T 000003552345"},
{"name": "image-008.jpg", "result": "FANAVF1461710"},
{"name": "image-008.jpg", "result": "FANAVF14617104"},
{"name": "image-009.jpg", "result": "0001285112001000040801"},
{"name": "image-010.jpg", "result": "673023"}
];
Expand Down