Browse Source

Enable bmp format

Jerome Wu 6 years ago
parent
commit
07b45ec0b5
  1. 2
      examples/file-input/demo.html
  2. 38
      package-lock.json
  3. 13
      src/common/worker.js
  4. BIN
      tests/assets/testocr.bmp

2
examples/file-input/demo.html

@ -127,7 +127,7 @@ function recognizeFile(file){ @@ -127,7 +127,7 @@ function recognizeFile(file){
<option value='vie' > Vietnamese </option>
</select>
<button onclick="recognizeFile('http://localhost:3000/examples/node/cosmic.png')">Sample Image</button>
<button onclick="recognizeFile('../node/testocr.bmp')">Sample Image</button>
<input type="file" onchange="recognizeFile(window.lastFile=this.files[0])">
<div id="log"></div>

38
package-lock.json generated

@ -2152,14 +2152,12 @@ @@ -2152,14 +2152,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -2174,20 +2172,17 @@ @@ -2174,20 +2172,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -2304,8 +2299,7 @@ @@ -2304,8 +2299,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -2317,7 +2311,6 @@ @@ -2317,7 +2311,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -2332,7 +2325,6 @@ @@ -2332,7 +2325,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -2340,14 +2332,12 @@ @@ -2340,14 +2332,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@ -2366,7 +2356,6 @@ @@ -2366,7 +2356,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -2447,8 +2436,7 @@ @@ -2447,8 +2436,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -2460,7 +2448,6 @@ @@ -2460,7 +2448,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -2582,7 +2569,6 @@ @@ -2582,7 +2569,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -5166,11 +5152,6 @@ @@ -5166,11 +5152,6 @@
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz",
"integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA=="
},
"whatwg-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz",
"integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q=="
}
}
},
@ -6287,6 +6268,11 @@ @@ -6287,6 +6268,11 @@
}
}
},
"whatwg-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz",
"integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q=="
},
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",

13
src/common/worker.js

@ -35,9 +35,15 @@ const handleInit = (req, res) => { @@ -35,9 +35,15 @@ const handleInit = (req, res) => {
};
const setImage = (image) => {
const { w, h, data } = readImage(Module, Array.from(image));
base.SetImage(data);
const {
w, h, bytesPerPixel, data, pix,
} = readImage(Module, Array.from(image));
if (data === null) {
base.SetImage(pix);
} else {
base.SetImage(data, w, h, bytesPerPixel, w * bytesPerPixel);
}
base.SetRectangle(0, 0, w, h);
return data;
};
@ -48,7 +54,6 @@ const loadLanguage = (req, res, cb) => { @@ -48,7 +54,6 @@ const loadLanguage = (req, res, cb) => {
langs: lang,
tessModule: Module,
langURI: langPath,
cache: true,
}).then(cb);
};

BIN
tests/assets/testocr.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Loading…
Cancel
Save