├── .gitignore ├── LICENSE.md ├── README.md ├── sample ├── favicon.ico ├── index.html ├── js │ ├── index.js │ ├── jquery-3.3.1.min.js │ └── ocr.js ├── qr.html └── style │ ├── common-style.css │ └── index.css └── src ├── bcr.analyze.js ├── bcr.cities.js ├── bcr.cleaning.js ├── bcr.job.js ├── bcr.js ├── bcr.names.js ├── bcr.streets.js ├── bcr.utility.js ├── data ├── dan.traineddata.gz ├── deu.traineddata.gz ├── eng.traineddata.gz ├── fra.traineddata.gz ├── ita.traineddata.gz ├── spa.traineddata.gz └── swe.traineddata.gz ├── lang ├── dan.js ├── deu.js ├── eng.js ├── fra.js ├── ita.js ├── spa.js └── swe.js ├── qr ├── alignpat.js ├── bitmat.js ├── bmparser.js ├── datablock.js ├── databr.js ├── datamask.js ├── decoder.js ├── detector.js ├── errorlevel.js ├── findpat.js ├── formatinf.js ├── gf256.js ├── gf256poly.js ├── grid.js ├── qrcode.js ├── rsdecoder.js └── version.js └── tesseract ├── tesseract-core.js ├── tesseract.min.js └── worker.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | dev/ 7 | 8 | # User-specific stuff 9 | .idea 10 | .idea/ 11 | .idea/**/workspace.xml 12 | .idea/**/tasks.xml 13 | .idea/**/dictionaries 14 | .idea/**/shelf 15 | 16 | # Sensitive or high-churn files 17 | .idea/**/dataSources/ 18 | .idea/**/dataSources.ids 19 | .idea/**/dataSources.local.xml 20 | .idea/**/sqlDataSources.xml 21 | .idea/**/dynamic.xml 22 | .idea/**/uiDesigner.xml 23 | 24 | # Gradle 25 | .idea/**/gradle.xml 26 | .idea/**/libraries 27 | 28 | # CMake 29 | cmake-build-debug/ 30 | cmake-build-release/ 31 | 32 | # Mongo Explorer plugin 33 | .idea/**/mongoSettings.xml 34 | 35 | # File-based project format 36 | *.iws 37 | 38 | # IntelliJ 39 | out/ 40 | 41 | # mpeltonen/sbt-idea plugin 42 | .idea_modules/ 43 | 44 | # JIRA plugin 45 | atlassian-ide-plugin.xml 46 | 47 | # Cursive Clojure plugin 48 | .idea/replstate.xml 49 | 50 | # Crashlytics plugin (for Android Studio and IntelliJ) 51 | com_crashlytics_export_strings.xml 52 | crashlytics.properties 53 | crashlytics-build.properties 54 | fabric.properties 55 | 56 | # Editor-based Rest Client 57 | .idea/httpRequests 58 | ### VisualStudioCode template 59 | .vscode/* 60 | !.vscode/settings.json 61 | !.vscode/tasks.json 62 | !.vscode/launch.json 63 | !.vscode/extensions.json 64 | ### Windows template 65 | # Windows thumbnail cache files 66 | Thumbs.db 67 | ehthumbs.db 68 | ehthumbs_vista.db 69 | 70 | # Dump file 71 | *.stackdump 72 | 73 | # Folder config file 74 | [Dd]esktop.ini 75 | 76 | # Recycle Bin used on file shares 77 | $RECYCLE.BIN/ 78 | 79 | # Windows Installer files 80 | *.cab 81 | *.msi 82 | *.msix 83 | *.msm 84 | *.msp 85 | 86 | # Windows shortcuts 87 | *.lnk 88 | /.vs 89 | /sample/dataset 90 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Javascript BCR Library](https://github.com/syneo-tools-gmbh/Javascript-BCR-Library) 1.0.12 2 | ## Authors: Gaspare Ferraro, Renzo Sala, Simone Ponte, Paolo Macco 3 | 4 | BCR Library is a javascript library, using the OCR engine Tesseract.JS, that extracts name, company name, job, address, phone numbers, email and web address out of a business card picture. 5 | 6 | The library is written in Javascript and can be used in any Javascript project (included in projects using frameworks for hybrid mobile applications, like Apache Cordova, Phonegap or Ionic). 7 | 8 | The library can be used offline, no online dependencies are required. 9 | 10 | # Installation 11 | Copy the content of the repository and reference bcr via `script` tag in your HTML project: 12 | 13 | ```html 14 | 15 | ``` 16 | 17 | # Sample 18 | The sample application in the repository must be executed on a web server. 19 | 20 | If you have python it's enough to run `python -m http.server 8000` in the project folder. 21 | 22 | If you use cordova, you can add the `browser` platform and run it (it works on other platforms like Android or iOS too). 23 | 24 | # Reference 25 | 26 | ## Methods 27 | ### Init methods 28 | 29 | 30 | ```javascript 31 | bcr.initialize(ocrEngine, crop, language, width, height, QRScanner, dynamicInclude); 32 | ``` 33 | 34 | Initialize the bcr reader. 35 | If ocrEngine is set to ocrEngines.TESSERACT, initialize the tesseract engine. 36 | If ocrEngine is set to ocrEngines.GOOGLEVISION, initialize bcr reader given the ocr from google mobile vision text recognition API ([cordova-plugin-mobile-ocr](https://github.com/NeutrinosPlatform/cordova-plugin-mobile-ocr)). 37 | 38 | Where: 39 | - **STRING** `ocrEngine` the selected engine (see [ocrEngines](#ocrEngines)), default `ocrEngines.TESSERACT`. 40 | - **STRING** `crop`: the crop strategy (see [languages](#languages)), default `languages.GERMAN`. 41 | - **STRING** `language`: the language trained data (see [cropStrategy](#cropStrategy)), default `cropStrategy.SMART`. 42 | - **NUMBER** `width`: max internal width, default `2160`. 43 | - **NUMBER** `height`: max internal height, default `1440`. 44 | - **BOOLEAN** `QRScanner`: check first for VCard QR Code in image, default `true`. 45 | - **BOOLEAN** `dynamicInclude`: if the references are not included externally, default `true`. 46 | - Return Promise about JS loading. 47 | 48 | ----------------- 49 | 50 | ### Recognize business card 51 | 52 | ```javascript 53 | bcr.recognize(base64image, displayResultCallback, displayProgressCallback, ocr); 54 | ``` 55 | 56 | Where: 57 | 58 | - **STRING** `base64image`: base64 string of the image to analyze. 59 | - **FUNCTION** `displayResultCallback(result_data)` function called when the analysis of the business card is completed. 60 | - **FUNCTION** `displayProgressCallback(progress_data)` function called after each progress in the analysis. 61 | - **OBJECT** `ocr`: object containing ocr results data from google mobile vision (optional, default ``). 62 | 63 | ### Getter methods 64 | 65 | ```javascript 66 | bcr.cropStrategy() 67 | ``` 68 | 69 | - Return the strategy label internally set. 70 | 71 | ------------ 72 | 73 | ```javascript 74 | bcr.maxWidth() 75 | ``` 76 | 77 | - Return the value of the max width used internally to normalize the resolution. 78 | 79 | ------------ 80 | 81 | ```javascript 82 | bcr.maxHeight() 83 | ``` 84 | 85 | - Return the value of the max height used internally to normalize the resolution. 86 | 87 | ------------ 88 | 89 | ```javascript 90 | bcr.language() 91 | ``` 92 | 93 | - Return the value of the language trained data. 94 | 95 | ------------ 96 | 97 | ```javascript 98 | bcr.tesseract() 99 | ``` 100 | 101 | - Return the initialized tesseract worker. 102 | 103 | ------------ 104 | 105 | ```javascript 106 | bcr.ocr() 107 | ``` 108 | 109 | - Return the ocr passed. 110 | 111 | ------------ 112 | 113 | ```javascript 114 | bcr.ocrEngine() 115 | ``` 116 | 117 | - Return the ocr engine selected. 118 | 119 | ------------ 120 | 121 | ```javascript 122 | bcr.qrScanner() 123 | ``` 124 | 125 | -if VCard QRScanner read is enabled. 126 | 127 | ------------ 128 | 129 | ## Object 130 | 131 | ### `result_data` 132 | JSON object in the format: 133 | 134 | ```json 135 | { 136 | "Company": "STRING", 137 | "Email": "STRING", 138 | "Address": { 139 | "StreetAddress": "STRING", 140 | "ZipCode": "STRING", 141 | "Country": "STRING", 142 | "Text": "STRING", 143 | "City": "STRING" 144 | }, 145 | "Web": "STRING", 146 | "Phone": "STRING", 147 | "Text": "STRING", 148 | "Fax": "STRING", 149 | "Job": "STRING", 150 | "Mobile": "STRING", 151 | "Name": { 152 | "Text": "STRING", 153 | "Surname": "STRING", 154 | "Name": { 155 | "FirstName": "STRING", 156 | "Text": "STRING", 157 | "MiddleName": "STRING", 158 | "ExtraName": "STRING" 159 | } 160 | } 161 | } 162 | ``` 163 | 164 | ### `progress_data` 165 | 166 | JSON object in the format: 167 | 168 | ```json 169 | { 170 | "section": "STRING", 171 | "progress": { 172 | "status": "STRING", 173 | "progress": "FLOAT" 174 | } 175 | } 176 | ``` 177 | 178 | ## ENUM 179 | 180 | ### languages 181 | 182 | - `languages.DANISH`: Danish language 183 | - `languages.GERMAN`: German language 184 | - `languages.ENGLISH`: English language 185 | - `languages.FRENCH`: French language 186 | - `languages.ITALIAN`: Italian language 187 | - `languages.SPANISH`: Spanish language 188 | - `languages.SWEDISH`: Swedish language 189 | 190 | ### cropStrategy 191 | 192 | - `cropStrategy.SMART`: clean the image 193 | 194 | ### ocrEngines 195 | 196 | - `ocrEngines.TESSERACT`: use the tesseract internal engine 197 | - `ocrEngines.GOOGLEVISION`: use Google Mobile Vision external engine 198 | 199 | ## JS Libraries used 200 | 201 | * [Tesseract.JS](https://github.com/naptha/tesseract.js) - 1.0.19
202 | Tesseract.js wraps an [emscripten](https://github.com/kripken/emscripten) [port](https://github.com/naptha/tesseract.js-core) of the [Tesseract](https://github.com/tesseract-ocr/tesseract) [OCR](https://en.wikipedia.org/wiki/Optical_character_recognition) Engine. 203 | 204 | ## Required Cordova Plugins (in case of cordova project) 205 | 206 | * [cordova-plugin-ionic-webview](https://github.com/ionic-team/cordova-plugin-ionic-webview/) - 4.0.0
207 | A Web View plugin for Cordova, focused on providing the highest performance experience for Ionic apps (but can be used with any Cordova app). 208 | 209 | ### Contribution ### 210 | 211 | The current status of the library is alpha. Looking forward for your contribution to make the first release. 212 | -------------------------------------------------------------------------------- /sample/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/sample/favicon.ico -------------------------------------------------------------------------------- /sample/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Business Card Reader Library DEMO Application 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
Submit a business card
25 |
26 | Original image 28 |
29 |
30 | 31 |
32 |
Result
33 | 34 |
35 |
36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
FieldValue
Namename
Addressaddress
Phonephone
Mobilemobile
Faxfax
Companycompany
Jobjob
Emailemail
Webweb
84 |
85 | 86 |
87 |
Pre-processing steps
88 |
89 | step1 91 |
92 | step2 94 |
95 | step3 97 |
98 | step4 100 |
101 | step5 103 |
104 |
105 | 106 | 219 | 220 | 221 | -------------------------------------------------------------------------------- /sample/js/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Cordova BCR Library 0.0.10 4 | Authors: Gaspare Ferraro, Renzo Sala 5 | Contributors: Simone Ponte, Paolo Macco 6 | Filename: bcr.js 7 | Description: demo app 8 | 9 | */ 10 | 11 | async function init() { 12 | console.log("init BCR"); 13 | await bcr.initialize(ocrEngines.TESSERACT, cropStrategy.SMART, languages.GERMAN, 2160, 1440, true, true); 14 | console.log("BCR initialized"); 15 | } 16 | 17 | // app init 18 | $(document).ready(function() { 19 | init().finally(); 20 | }); 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/qr.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | VCard QR Code Scanner 7 | 8 | 9 | 24 | 25 |
26 |

VCard QR Code Scanner

27 | 28 | Detected QR code:
29 | None 30 | 31 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /sample/style/common-style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/sample/style/common-style.css -------------------------------------------------------------------------------- /sample/style/index.css: -------------------------------------------------------------------------------- 1 | html, div { 2 | padding: 0; 3 | margin: 0; 4 | } 5 | body { 6 | background: #eee; 7 | font-family: Arial, serif; 8 | font-size: 18px; 9 | max-width: 926px; 10 | margin: 0 auto auto; 11 | padding: 0; 12 | } 13 | 14 | #header { 15 | background: #222; 16 | width: calc(100% - 16px); 17 | color: #fff; 18 | font-size: 32px; 19 | font-weight: bold; 20 | padding: 8px; 21 | border-radius: 0 0 3px 3px; 22 | margin: 0; 23 | } 24 | 25 | .section { 26 | width: calc(100% - 18px); 27 | max-width: 926px; 28 | min-width: 128px; 29 | border: 1px black solid; 30 | padding: 8px; 31 | background: #ccc; 32 | border-radius: 3px; 33 | margin-top: 10px; 34 | margin-bottom: 10px; 35 | } 36 | 37 | .title { 38 | border-bottom: 1px black solid; 39 | font-size: 24px; 40 | margin-bottom: 16px; 41 | } 42 | 43 | #tresult { 44 | max-width: 640px; 45 | width: 80%; 46 | margin: auto; 47 | 48 | } 49 | #steps, #result { 50 | display: none; 51 | } 52 | 53 | 54 | #tresult td { 55 | border-bottom: 1px black solid; 56 | } 57 | 58 | .move { 59 | width: 86px; 60 | height: 16px; 61 | background: #eee; 62 | border: 1px black solid; 63 | border-radius: 3px; 64 | padding: 6px 6px 8px; 65 | display: inline-block; 66 | cursor: pointer; 67 | } 68 | 69 | .center { 70 | width: 100%; 71 | text-align: center; 72 | } 73 | 74 | .field { 75 | font-weight: bold; 76 | width: 128px !important; 77 | margin-right: 8px; 78 | } 79 | 80 | .field .fas { 81 | width: 16px !important; 82 | text-align: right; 83 | } 84 | 85 | .value { 86 | max-width: 512px; 87 | } 88 | 89 | .img { 90 | display: inline-block; 91 | padding: 0; 92 | margin: 1px; 93 | width: calc(100% / 3); 94 | } 95 | .img-original { 96 | padding: 0; 97 | margin-bottom: 10px; 98 | width: 100%; 99 | } 100 | .big-button { 101 | width: 100%; 102 | background-color: red; 103 | border: 1px solid black; 104 | } 105 | #inp { 106 | display: none; 107 | } -------------------------------------------------------------------------------- /src/bcr.cities.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 1.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: bcr.streets.js 6 | * Description: dataset of cities 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | window.cities = []; 26 | window.cityDS = {}; 27 | window.countryDS = []; 28 | 29 | for (let k in languages) 30 | cities = cities.concat(languagesDS[languages[k]]["city"]); 31 | 32 | for (let i = 0; i < cities.length; i++) 33 | cities[i] = [cities[i][0].toLowerCase(), cities[i][1].toLowerCase(), (cities[i][2] || "").toLowerCase()]; 34 | 35 | for (let i = 0; i < cities.length; i++) { 36 | if (typeof cityDS[cities[i][1]] === "undefined") 37 | cityDS[cities[i][1]] = []; 38 | cityDS[cities[i][1]].push([cities[i][0], cities[i][2]]) 39 | } 40 | 41 | Object.keys(cityDS).forEach(k => { 42 | cityDS[k].sort(); 43 | countryDS.push(k) 44 | }); 45 | 46 | countryDS.sort(); 47 | console.log("Loaded", countryDS.length, "countries"); -------------------------------------------------------------------------------- /src/bcr.job.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 1.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: bcr.streets.js 6 | * Description: dataset of job definitions 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | window.jobDS = [ 25 | // Corporate title 26 | /\bcae\b/g, 27 | /\bcaio\b/g, 28 | /\bcao\b/g, 29 | /\bcbdo\b/g, 30 | /\bcbo\b/g, 31 | /\bcco\b/g, 32 | /\bcdo\b/g, 33 | /\bceo\b/g, 34 | /\bcfo\b/g, 35 | /\bcgo\b/g, 36 | /\bchro\b/g, 37 | /\bcino\b/g, 38 | /\bcio\b/g, 39 | /\bciso\b/g, 40 | /\bcito\b/g, 41 | /\bcko\b/g, 42 | /\bclo\b/g, 43 | /\bcmo\b/g, 44 | /\bcno\b/g, 45 | /\bcoo\b/g, 46 | /\bcpo\b/g, 47 | /\bcqo\b/g, 48 | /\bcrdo\b/g, 49 | /\bcro\b/g, 50 | /\bcse\b/g, 51 | /\bcso\b/g, 52 | /\bcto\b/g, 53 | /\bcvo\b/g, 54 | /\bcwo\b/g, 55 | /\bcxo\b/g, 56 | 57 | // Levels 58 | /\bintern\b/g, 59 | /\bjunior\b/g, 60 | /\bsenior\b/g, 61 | /\blead\b/g 62 | ]; 63 | 64 | // titles to be kept 65 | window.titleDS = [ 66 | // x-language 67 | /\bprof\b/g, 68 | /\bprof.\b/g 69 | ]; 70 | 71 | // titles to be trashed 72 | window.titleTrashDS = [ 73 | 74 | ]; 75 | 76 | for (let k in languages) 77 | jobDS = jobDS.concat(languagesDS[languages[k]]["job"]); 78 | 79 | for (let k in languages) 80 | titleDS = titleDS.concat(languagesDS[languages[k]]["title"]); 81 | 82 | for (let k in languages) 83 | titleTrashDS = titleDS.concat(languagesDS[languages[k]]["titleTrash"]); 84 | 85 | jobDS.sort(); 86 | titleDS.sort(); 87 | titleTrashDS.sort(); 88 | 89 | console.log("Loaded", jobDS.length, "jobs"); 90 | console.log("Loaded", titleDS.length, "titles"); 91 | console.log("Loaded", titleTrashDS.length, "titles trash"); -------------------------------------------------------------------------------- /src/bcr.names.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 1.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: bcr.names.js 6 | * Description: dataset of names 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | window.namesDS = []; 26 | 27 | for(let k in languages) 28 | namesDS = namesDS.concat(languagesDS[languages[k]]["name"]); 29 | 30 | namesDS.sort(); 31 | console.log("Loaded", namesDS.length, "names"); 32 | -------------------------------------------------------------------------------- /src/bcr.streets.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 1.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: bcr.streets.js 6 | * Description: dataset of street definitions 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | window.streetsDS = []; 26 | 27 | for (let k in languages) 28 | streetsDS = streetsDS.concat(languagesDS[languages[k]]["street"]); 29 | 30 | streetsDS.sort(); 31 | console.log("Loaded", streetsDS.length, "streets"); 32 | -------------------------------------------------------------------------------- /src/bcr.utility.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 1.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: bcr.utility.js 6 | * Description: various utilities 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | function titleCase(text) { 26 | if (!text) return text; 27 | if (typeof text !== 'string') throw "invalid argument"; 28 | 29 | return text.toLowerCase().split(' ').map(value => { 30 | return value.charAt(0).toUpperCase() + value.substring(1); 31 | }).join(' '); 32 | } 33 | 34 | function editDistance(word1, word2) { 35 | let i, j, Cmin; 36 | if (typeof word1 === "undefined" && typeof word2 === "undefined") { 37 | return 1; 38 | } 39 | if (typeof word1 === "undefined" || word1.length === 0) { 40 | return word2.length; 41 | } 42 | if (typeof word2 === "undefined" || word2.length === 0) { 43 | return word1.length; 44 | } 45 | 46 | word1 = word1.toLowerCase(); 47 | word2 = word2.toLowerCase(); 48 | 49 | let len1 = word1.length; 50 | let len2 = word2.length; 51 | 52 | let dp = Array(len1 + 1).fill(0).map(() => Array(len2 + 1).fill(0)); 53 | 54 | for (i = 0; i <= len1; i++) { 55 | dp[i][0] = i; 56 | } 57 | for (j = 0; j <= len2; j++) { 58 | dp[0][j] = j; 59 | } 60 | 61 | for (i = 0; i < len1; i++) { 62 | let c1 = word1.charAt(i); 63 | 64 | for (j = 0; j < len2; j++) { 65 | let c2 = word2.charAt(j); 66 | 67 | if (c1 === c2) { 68 | dp[i + 1][j + 1] = dp[i][j]; 69 | } else { 70 | let Creplace = dp[i][j] + 1; 71 | let Cinsert = dp[i][j + 1] + 1; 72 | let Cdelete = dp[i + 1][j] + 1; 73 | 74 | Cmin = Math.min(Creplace, Math.min(Cinsert, Cdelete)); 75 | dp[i + 1][j + 1] = Cmin; 76 | } 77 | } 78 | } 79 | 80 | return dp[len1][len2]; 81 | } 82 | 83 | function substringEditDistance(word1, word2) { 84 | let i, j, Cmin; 85 | if (typeof word1 === "undefined" && typeof word2 === "undefined") { 86 | return 1; 87 | } 88 | if (word1 === undefined || word1.length === 0) { 89 | return word2.length; 90 | } 91 | if (word2 === undefined || word2.length === 0) { 92 | return word1.length; 93 | } 94 | 95 | word1 = word1.toLowerCase(); 96 | word2 = word2.toLowerCase(); 97 | 98 | let len1 = word1.length; 99 | let len2 = word2.length; 100 | 101 | let dp = Array(len1 + 1).fill(0).map(() => Array(len2 + 1).fill(0)); 102 | 103 | for (i = 0; i <= len1; i++) { 104 | dp[i][0] = i; 105 | } 106 | for (j = 0; j <= len2; j++) { 107 | dp[0][j] = 0; 108 | } 109 | 110 | for (i = 0; i < len1; i++) { 111 | let c1 = word1.charAt(i); 112 | 113 | for (j = 0; j < len2; j++) { 114 | let c2 = word2.charAt(j); 115 | 116 | if (c1 === c2) { 117 | dp[i + 1][j + 1] = dp[i][j]; 118 | } else { 119 | let Creplace = dp[i][j] + 1; 120 | let Cinsert = dp[i][j + 1] + 1; 121 | let Cdelete = dp[i + 1][j] + 1; 122 | 123 | Cmin = Math.min(Creplace, Math.min(Cinsert, Cdelete)); 124 | dp[i + 1][j + 1] = Cmin; 125 | } 126 | } 127 | } 128 | 129 | let minLastRow = dp[len1][0]; 130 | for (i = 0; i <= len2; i++) { 131 | minLastRow = Math.min(minLastRow, dp[len1][i]); 132 | } 133 | 134 | return minLastRow; 135 | } 136 | 137 | function substringSimilarity(word1, word2) { 138 | if (typeof word1 === "undefined" || typeof word2 === "undefined") { 139 | return 0.; 140 | } 141 | if (word1.length === 0 || word2.length === 0) { 142 | return 0.; 143 | } 144 | return 1. - substringEditDistance(word1, word2) / Math.max(word1.length, word2.length); 145 | } 146 | 147 | function stringSimilarity(word1, word2) { 148 | if (typeof word1 === "undefined" || typeof word2 === "undefined") { 149 | return 0.; 150 | } 151 | if (word1.length === 0 || word2.length === 0) { 152 | return 0.; 153 | } 154 | return 1. - editDistance(word1, word2) / Math.max(word1.length, word2.length); 155 | } 156 | 157 | function capitalize(str) { 158 | if (typeof str === "undefined" || str.length === 0) { 159 | return ""; 160 | } 161 | return str.substr(0, 1).toUpperCase() + str.substring(1); 162 | } 163 | 164 | function sSimilarity(sa1, sa2) { 165 | 166 | // for my purposes, comparison should not check case or whitespace 167 | let s1 = sa1.replace(/\s/g, "").toLowerCase(); 168 | let s2 = sa2.replace(/\s/g, "").toLowerCase(); 169 | 170 | function intersect(arr1, arr2) { 171 | // I didn't write this. I'd like to come back sometime 172 | // and write my own intersection algorithm. This one seems 173 | // clean and fast, though. Going to try to find out where 174 | // I got it for attribution. Not sure right now. 175 | let r = [], o = {}, l = arr2.length, i, v; 176 | for (i = 0; i < l; i++) { 177 | o[arr2[i]] = true; 178 | } 179 | l = arr1.length; 180 | for (i = 0; i < l; i++) { 181 | v = arr1[i]; 182 | if (v in o) { 183 | r.push(v); 184 | } 185 | } 186 | return r; 187 | } 188 | 189 | let pairs = function (s) { 190 | // Get an array of all pairs of adjacent letters in a string 191 | let pairs = []; 192 | for (let i = 0; i < s.length - 1; i++) { 193 | pairs[i] = s.slice(i, i + 2); 194 | } 195 | return pairs; 196 | }; 197 | 198 | let similarity_num = 2 * intersect(pairs(s1), pairs(s2)).length; 199 | let similarity_den = pairs(s1).length + pairs(s2).length; 200 | 201 | return similarity_num / similarity_den; 202 | } 203 | 204 | File.prototype.convertToBase64 = function (callback) { 205 | let reader = new FileReader(); 206 | reader.onloadend = function (e) { 207 | console.log(e); 208 | callback(e.target.result, e.target.error); 209 | }; 210 | reader.readAsDataURL(this); 211 | }; 212 | -------------------------------------------------------------------------------- /src/data/dan.traineddata.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/src/data/dan.traineddata.gz -------------------------------------------------------------------------------- /src/data/deu.traineddata.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/src/data/deu.traineddata.gz -------------------------------------------------------------------------------- /src/data/eng.traineddata.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/src/data/eng.traineddata.gz -------------------------------------------------------------------------------- /src/data/fra.traineddata.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/src/data/fra.traineddata.gz -------------------------------------------------------------------------------- /src/data/ita.traineddata.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/src/data/ita.traineddata.gz -------------------------------------------------------------------------------- /src/data/spa.traineddata.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/src/data/spa.traineddata.gz -------------------------------------------------------------------------------- /src/data/swe.traineddata.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syneo-tools-gmbh/Javascript-BCR-Library/d3552bf6cd1ebf72cc320084852a41209c477255/src/data/swe.traineddata.gz -------------------------------------------------------------------------------- /src/lang/dan.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 0.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: ita.js 6 | * Description: Italian language pack 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | languagesDS["dan"] = {}; 26 | 27 | languagesDS["dan"]["job"] = []; 28 | 29 | languagesDS["dan"]["title"] = []; 30 | 31 | languagesDS["dan"]["titleTrash"] = []; 32 | 33 | languagesDS["dan"]["street"] = [ 34 | /\bgade\b/g, 35 | /\bvej\b/g, 36 | /\bvia\b/g, 37 | /\bfirkantet\b/g, 38 | /\bkursus\b/g, 39 | /\bboulevard\b/g 40 | ]; 41 | 42 | languagesDS["dan"]["name"] = [ 43 | "aage", "abraham", "adam", "adolf", "adrian", "agnes", "aksel", "albert", "alexander", "alf", "alfred", "amalia", "anders", "andreas", "anker", "anna", "anneliese", "annika", "anton", "antonia", "arne", "arthur", "asbjørn", "astrid", "august", "aurora", "axel", "baldur", "bernhard", "birgit", "bjarke", "bjarne", "bjorn", "bo", "bodil", "børge", "carl", "caroline", "cecilie", "charlotte", "christian", "clara", "dag", "dagmar", "daniel", "david", "ebba", "ebbe", "edvard", "edvin", "egon", "eiler", "ejnar", "eldar", "elsa", "emilie", "emma", "eric", "erik", "erika", "esben", "estelle", "evald", "felix", "flemming", "folke", "fredrik", "frida", "georg", "gerda", "gert", "grete", "gustav", "hakon", "hans", "harald", "heidi", "helena", "helene", "helga", "helge", "helle", "helmuth", "herman", "hilbert", "hilda", "hilde", "holger", "hulda", "ib", "ida", "indira", "inga", "inger", "ingrid", "irnes", "isabella", "ivalu", "jacob", "janne", "jannik", "jarl", "jens", "joakim", "johan", "johannes", "jonas", "jonathan", "jørgen", "judith", "jytte", "kaj", "karen", "karin", "karl", "kasper", "katja", "kerstin", "kjeld", "klaus", "klavs", "kristi", "kristin", "kristina", "kurt", "lærke", "lars", "lasse", "laurits", "lauritz", "leif", "lennart", "line", "linus", "lotte", "lucia", "ludvig", "lukas", "mads", "marcus", "margit", "maria", "marianne", "martin", "matias", "matthias", "mattias", "minna", "mogens", "monika", "morten", "natalie", "niels", "nikolaj", "nina", "norbert", "olaf", "ole", "oliver", "olivia", "ossian", "osvald", "otto", "ove", "paula", "pearl", "per", "petunia", "philip", "poul", "povl", "ragnar", "ralph", "rasmus", "rita", "robert", "rolf", "rudolph", "rune", "samuel", "selma", "signe", "simon", "siv", "søren", "stefan", "sten", "stig", "susanne", "sven", "svend", "sylvester", "tage", "tara", "thaddeus", "theodor", "thomas", "thor", "thorvald", "tobias", "toke", "torben", "torbjörn", "torkild", "tove", "ulrik", "vagn", "valentin", "valerie", "victoria", "viggo", "vilhelm", "vincent", "walter", "wealhþeow", "werner", "yvonne" 44 | ]; 45 | 46 | languagesDS["dan"]["city"] = [ 47 | ["vejle", "denmark", "syddanmark"], ["hillerød", "denmark", "hovedstaden"], ["københavn", "denmark", "hovedstaden"], ["viborg", "denmark", "midtjylland"], ["sorø", "denmark", "sjælland"], ["roskilde", "denmark", "sjælland"], ["odense", "denmark", "syddanmark"], ["svendborg", "denmark", "syddanmark"], ["esbjerg", "denmark", "syddanmark"], ["århus", "denmark", "midtjylland"], ["aalborg", "denmark", "nordjylland"], ["frederikshavn", "denmark", "nordjylland"] 48 | ]; 49 | -------------------------------------------------------------------------------- /src/lang/deu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 0.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: ita.js 6 | * Description: Italian language pack 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | languagesDS["deu"] = {}; 26 | 27 | languagesDS["deu"]["job"] = [ 28 | /\bgeschäftsführer\b/g, 29 | /\bvertrieb\b/g, 30 | /\bproduktmanagement\b/g, 31 | /\bproduktmanager\b/g, 32 | /\bprodukttechnik\b/g, 33 | /\bleiter\b/g, 34 | /\bberater\b/g, 35 | /\babteilungsdirektor\b/g, 36 | /\bdirektor\b/g, 37 | /\bstellvertretender\b/g, 38 | /\bangestellter\b/g, 39 | /\bangestellte\b/g, 40 | /\banwalt\b/g, 41 | /\banwältin\b/g, 42 | /\banwalt\b/g, 43 | /\bapotheker\b/g, 44 | /\barchitekt\b/g, 45 | /\barzt\b/g, 46 | /\bärztin\b/g, 47 | /\bbauer\b/g, 48 | /\bbäuerin\b/g, 49 | /\bbäuerin\b/g, 50 | /\bbeamter\b/g, 51 | /\bbeamtin\b/g, 52 | /\bbriefträger\b/g, 53 | /\bbriefträgerin\b/g, 54 | /\bbuchhalter\b/g, 55 | /\bbuchhalterin\b/g, 56 | /\bbusfahrer\b/g, 57 | /\bbusfahrerin\b/g, 58 | /\bbäcker\b/g, 59 | /\bbäckerin\b/g, 60 | /\bchemiker\b/g, 61 | /\bchemikerin\b/g, 62 | /\bchirurg\b/g, 63 | /\bchirurgin\b/g, 64 | /\bdolmetscher\b/g, 65 | /\bdolmetscherin\b/g, 66 | /\belektriker\b/g, 67 | /\belektrikerin\b/g, 68 | /\bfernfahrer\b/g, 69 | /\bfernfahrerin\b/g, 70 | /\bfeuerwehrmann\b/g, 71 | /\bfeuerwehrfrau\b/g, 72 | /\bfischer\b/g, 73 | /\bfischerin\b/g, 74 | /\bfleischer\b/g, 75 | /\bfleischerin\b/g, 76 | /\bfremdenführer\b/g, 77 | /\bfremdenführerin\b/g, 78 | /\bfriseur\b/g, 79 | /\bfriseurin\b/g, 80 | /\bfriseuse\b/g, 81 | /\bgärtner\b/g, 82 | /\bgärtnerin\b/g, 83 | /\bhandwerker\b/g, 84 | /\bhandwerkerin\b/g, 85 | /\bhotelfachmann\b/g, 86 | /\bhotelfachfrau\b/g, 87 | /\bingenieur\b/g, 88 | /\bingenieurin\b/g, 89 | /\bjournalist\b/g, 90 | /\bjournalistin\b/g, 91 | /\bkaufmann\b/g, 92 | /\bkauffrau\b/g, 93 | /\bkassierer\b/g, 94 | /\bkassiererin\b/g, 95 | /\bkrankenpfleger\b/g, 96 | /\bkrankenschwester\b/g, 97 | /\bkellner\b/g, 98 | /\bkellnerin\b/g, 99 | /\bkoch\b/g, 100 | /\bköchin\b/g, 101 | /\blehrer\b/g, 102 | /\blehrerin\b/g, 103 | /\bmaler\b/g, 104 | /\bmalerin\b/g, 105 | /\bmathematiker\b/g, 106 | /\bmathematikerin\b/g, 107 | /\bmechaniker\b/g, 108 | /\bmechanikerin\b/g, 109 | /\bmetzger\b/g, 110 | /\bmetzgerin\b/g, 111 | /\bmusiker\b/g, 112 | /\bmusikerin\b/g, 113 | /\bpastor\b/g, 114 | /\bpastorin\b/g, 115 | /\bpfarrer\b/g, 116 | /\bpfarrerin\b/g, 117 | /\bphysiker\b/g, 118 | /\bphysikerin\b/g, 119 | /\bpolitiker\b/g, 120 | /\bpolitikerin\b/g, 121 | /\bpolizist\b/g, 122 | /\bpolizistin\b/g, 123 | /\bprogrammierer\b/g, 124 | /\bprogrammiererin\b/g, 125 | /\bpsychiater\b/g, 126 | /\bpsychiaterin\b/g, 127 | /\bputzfrau\b/g, 128 | /\braumpfleger\b/g, 129 | /\brechtsanwalt\b/g, 130 | /\brechtsanwältin\b/g, 131 | /\breporter\b/g, 132 | /\breporterin\b/g, 133 | /\brichter\b/g, 134 | /\brichterin\b/g, 135 | /\bschauspieler\b/g, 136 | /\bschauspielerin\b/g, 137 | /\bschriftsteller\b/g, 138 | /\bschriftstellerin\b/g, 139 | /\bsekretär\b/g, 140 | /\bsekretärin\b/g, 141 | /\bsportler\b/g, 142 | /\bsportlerin\b/g, 143 | /\bsoldat\b/g, 144 | /\bsoldatin\b/g, 145 | /\btierarzt\b/g, 146 | /\btierärztin\b/g, 147 | /\btänzer\b/g, 148 | /\btänzerin\b/g, 149 | /\bverkäufer\b/g, 150 | /\bverkäuferin\b/g, 151 | /\bvertreter\b/g, 152 | /\bvertreterin\b/g, 153 | /\bwinzer\b/g, 154 | /\bwinzerin\b/g, 155 | /\bzahnarzt\b/g, 156 | /\bzahnärztin\b/g, 157 | /\bübersetzer\b/g, 158 | /\bübersetzerin\b/g, 159 | /\bchef\b/g, 160 | /\bchefin\b/g, 161 | /\bstudent\b/g, 162 | /\bstudentin\b/g 163 | ]; 164 | 165 | languagesDS["deu"]["title"] = [ 166 | /\bmag\b/g, 167 | /\bmag.\b/g, 168 | /\bherr\b/g, 169 | /\bfrau\b/g, 170 | /\bdoktor\b/g, 171 | /\bmagister\b/g, 172 | /\bingenieur\b/g 173 | ]; 174 | 175 | languagesDS["deu"]["titleTrash"] = [ 176 | /\bpd\b/g, 177 | /\bpd.\b/g, 178 | /\bpd.-\b/g, 179 | /\bdipl\b/g, 180 | /\bdipl.\b/g, 181 | /\bdipl.-\b/g 182 | ]; 183 | 184 | languagesDS["deu"]["street"] = [ 185 | /kamp/g, 186 | /allee/g, 187 | /stieg/g, 188 | /damm/g, 189 | /strasse/g, 190 | /straße/g, 191 | /weg/g, 192 | /platz/g, 193 | /moor/g, 194 | /str./g 195 | ]; 196 | 197 | languagesDS["deu"]["name"] = [ 198 | "abraham", "achim", "adam", "adel", "adele", "adelheid", "adolf", "adrian", "agnes", "albert", "albrecht", "alexander", "alfred", "alina", "almut", "alois", "alvin", "alwin", "amalia", "amalie", "amelia", "andrea", "andreas", "anna", "anne", "anneliese", "annemarie", "annika", "ansgar", "antje", "anton", "antonie", "armin", "arndt", "arno", "arnold", "arnulf", "artur", "astrid", "august", "auguste", "aurick", "axel", "baldur", "barbara", "bastian", "beat", "beata", "benedict", "bernd", "bernhard", "bertha", "bertram", "bettina", "bianka", "birgit", "bjorn", "bodo", "bonifaz", "bruno", "calvin", "carl", "carolina", "caroline", "cassandra", "charlotte", "christa", "christel", "christian", "christof", "christoph", "claudia", "clemens", "conrad", "corina", "cornelia", "dagmar", "dagobert", "daniel", "darryl", "david", "delbert", "derek", "detlef", "diederich", "diedrich", "diepold", "dieter", "dieterich", "dietrich", "dirk", "donald", "dustin", "edith", "edmund", "egbert", "egon", "ehren", "eike", "eilhard", "ekkehard", "elfriede", "elias", "elimar", "elke", "elmar", "elsa", "emil", "emilie", "emily", "emma", "emmerich", "engelbert", "erhard", "eric", "erika", "erna", "estelle", "esther", "ethel", "eva", "ewald", "felix", "ferdinand", "florian", "frank", "franz", "frauke", "frederick", "fredrik", "frida", "friedemann", "friedrich", "friedrich heinrich", "fritz", "gabriel", "gabriele", "garibald", "gebhard", "georg", "gerald", "gerard", "gerd", "gerda", "gerhard", "gerhardt", "germar", "gernot", "gert", "gertrude", "gerwin", "gilbert", "gisela", "giselher", "gottfried", "gottlieb", "gottschalk", "götz", "greta", "gretchen", "grete", "gretel", "guido", "gunther", "günther", "gustav", "hannah", "hanne", "hannelore", "hanno", "hans", "hansjörg", "harald", "harold", "hauke", "hedwig", "hedy", "heidemarie", "heidi", "heiko", "heiner", "heini", "heino", "heinrich", "heinz", "helena", "helga", "helge", "hellmuth", "helmut", "helmuth", "henning", "herbert", "herman", "hermann", "hermine", "herta", "hertha", "herwig", "hilda", "hilde", "hildegard", "hilma", "hjalmar", "holger", "horst", "hubert", "hubertus", "hugo", "ignatz", "ilona", "ilse", "imelda", "inga", "inge", "ingo", "ingrid", "irma", "isabella", "jack", "jacob", "jacqueline", "jan", "jana", "jannik", "jasper", "jerome", "jessica", "joachim", "joachim-friedrich", "johann", "johanna", "johannes", "jonas", "jonathan", "jörg", "joseph", "jost", "judith", "julia", "julius", "jupp", "jürgen", "jutta", "karen", "karin", "karl", "karlheinz", "karl-heinz", "karsten", "kaspar", "käthe", "katja", "katrin", "kepler", "kerstin", "killian", "klaus", "klaus-peter", "konrad", "kristi", "kristina", "kurd", "kurt", "ladislaus", "lars", "lena", "leopold", "leopoldine", "levin", "liana", "liesl", "lina", "linus", "lisbeth", "lorentz", "lothar", "lotte", "louise", "lucia", "ludger", "ludolf", "ludwig", "luitpold", "lukas", "luther", "lütold", "lutz", "lydia", "magdalena", "magnus", "malte", "malvina", "manuel", "marcus", "margarete", "margit", "maria", "marianne", "marius", "marlene", "marlies", "marta", "martin", "matthias", "maximilian", "medard", "meike", "meinrad", "melanie", "melvin", "michael", "michaela", "michel", "michelle", "milo", "minna", "miranda", "mirco", "mirjam", "mirko", "mona", "monika", "moritz", "nadine", "nanne", "natalie", "nico", "nicolas", "nicolaus", "nina", "nivaldo", "norbert", "norman", "olaf", "olga", "oliver", "olivia", "orlando", "ortrud", "oscar", "oswald", "othmar", "otto", "ottomar", "pascal", "patrick", "paul", "paula", "pearl", "peter", "philip", "philipp", "rachel", "rainer", "ralph", "randall", "reinhard", "reinhardt", "reinhold", "rhonda", "ricarda", "richenza", "robert", "robin", "roderick", "roger", "roland", "rolf", "roman", "ronald", "rosina", "rudolph", "ruprecht", "rut", "sabine", "samuel", "sander", "sandra", "selma", "sepp", "severin", "siegfried", "sigismund", "sigmund", "sigrid", "simon", "sophie", "stefan", "stephen", "susanne", "sven", "svenja", "sylvester", "tamara", "tanja", "thaddeus", "theobald", "theodor", "thomas", "timo", "tina", "tobias", "tom", "traudl", "traugott", "udo", "ulrich", "ulrike", "urban", "ursula", "ute", "utto", "uwe", "valentin", "valerie", "valter", "vera", "victoria", "vincenz", "vinzenz", "viola", "vollrath", "waldo", "walter", "walther", "waltraud", "wenzel", "werner", "wernher", "wiebke", "wilfried", "wilhelm", "wilhelmina", "william", "wiltrud", "winfried", "wolf", "wolfgang", "wolfram", "xavier", "xenia", "yvonne" 199 | ]; 200 | 201 | languagesDS["deu"]["city"] = [ 202 | ["berlin", "germany", "berlin"], ["cologne", "germany", "north rhine-westphalia"], ["munich", "germany", "bavaria"], ["potsdam", "germany", "brandenburg"], ["norderstedt", "germany", "schleswig-holstein"], ["kiel", "germany", "schleswig-holstein"], ["wiesbaden", "germany", "hesse"], ["magdeburg", "germany", "saxony-anhalt"], ["bremen", "germany", "bremen"], ["nordstemmen", "germany", "lower saxony"], ["hildesheim", "germany", "lower saxony"], ["hannover", "germany", "lower saxony"], ["düsseldorf", "germany", "north rhine-westphalia"], ["saarbrücken", "germany", "saarland"], ["schwerin", "germany", "mecklenburg-western pomerania"], ["hamburg", "germany", "hamburg"], ["stuttgart", "germany", "baden-württemberg"], ["dresden", "germany", "saxony"], ["erfurt", "germany", "thuringia"], ["mainz", "germany", "rhineland-palatinate"], ["rostock", "germany", "mecklenburg-western pomerania"], ["kassel", "germany", "hesse"], ["dortmund", "germany", "north rhine-westphalia"], ["duisburg", "germany", "north rhine-westphalia"], ["essen", "germany", "north rhine-westphalia"], ["bonn", "germany", "north rhine-westphalia"], ["bielefeld", "germany", "north rhine-westphalia"], ["lübeck", "germany", "schleswig-holstein"], ["flensburg", "germany", "schleswig-holstein"], ["emden", "germany", "lower saxony"], ["wuppertal", "germany", "north rhine-westphalia"], ["münster", "germany", "north rhine-westphalia"], ["osnabrück", "germany", "lower saxony"], ["göttingen", "germany", "lower saxony"], ["oldenburg", "germany", "lower saxony"], ["stralsund", "germany", "mecklenburg-western pomerania"], ["braunschweig", "germany", "lower saxony"], ["bremerhaven", "germany", "bremen"], ["freiburg", "germany", "baden-württemberg"], ["karlsruhe", "germany", "baden-württemberg"], ["heidelberg", "germany", "baden-württemberg"], ["ingolstadt", "germany", "bavaria"], ["passau", "germany", "bavaria"], ["rosenheim", "germany", "bavaria"], ["augsburg", "germany", "bavaria"], ["regensburg", "germany", "bavaria"], ["würzburg", "germany", "bavaria"], ["coburg", "germany", "bavaria"], ["hof", "germany", "bavaria"], ["ulm", "germany", "baden-württemberg"], ["nürnberg", "germany", "bavaria"], ["fürth", "germany", "bavaria"], ["gießen", "germany", "hesse"], ["mannheim", "germany", "baden-württemberg"], ["frankfurt", "germany", "hesse"], ["koblenz", "germany", "rhineland-palatinate"], ["chemnitz", "germany", "saxony"], ["cottbus", "germany", "brandenburg"], ["jena", "germany", "thuringia"], ["gera", "germany", "thuringia"], ["leipzig", "germany", "saxony"] 203 | ]; 204 | -------------------------------------------------------------------------------- /src/lang/fra.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 0.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: ita.js 6 | * Description: Italian language pack 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | languagesDS["fra"] = {}; 26 | 27 | languagesDS["fra"]["job"] = []; 28 | 29 | languagesDS["fra"]["title"] = [ 30 | /\bdocteur\b/g, 31 | /\bprofesseur\b/g, 32 | /\bmonsieur\b/g, 33 | /\bmadame\b/g, 34 | /\bmademoiselle\b/g 35 | ]; 36 | 37 | languagesDS["fra"]["titleTrash"] = []; 38 | 39 | languagesDS["fra"]["street"] = [ 40 | /\brue\b/g, 41 | /\bplace\b/g, 42 | /\bpassage\b/g, 43 | /\bcité\b/g, 44 | /\bile\b/g, 45 | /\bboulevard\b/g, 46 | /\bavenue\b/g, 47 | /\ballée\b/g 48 | ]; 49 | 50 | languagesDS["fra"]["name"] = [ 51 | "abel", "abraham", "achille", "adam", "adel", "adele", "ademar", "adhemar", "adolf", "adrien", "adrienne", "aenor", "agathe", "agénor", "aglaé", "agnes", "aimé", "aimée", "alain", "albert", "alberta", "albertet", "alexandre", "alfred", "alice", "alphonse", "alphonse joseph", "alvin", "amable", "amandine", "amélie", "anabelle", "anaïs", "anatole", "andré", "andré-marie", "ange", "angèle", "angélique", "anne", "anne-marie", "anne-sophie", "anouk", "antoine", "antoinette", "anton", "arlette", "armand", "arnaud", "arnaut", "arsène", "arthur", "astrid", "aubin", "audrey", "auguste", "augustin", "aurélie", "aurélien", "aurore", "aymard", "baptiste", "barbara", "barthélemy", "bastien", "baudouin", "béatrice", "beau", "bénédicte", "benoît", "bernadette", "bernard", "bertrand", "bijou", "blaise", "blanchard", "blanche", "blanchefleur", "brigitte", "bruno", "calvin", "camilla", "camille alphonse", "candide", "carine", "carole", "carolina", "caroline", "cécile", "celestia", "céline", "chantal", "charles", "charles-édouard", "charlotte", "chloé", "christian", "christophe", "claire", "claude", "claude-henri", "claudine", "clement", "clémentine", "colette", "constant", "coralie", "corina", "corinne", "cyrille", "daniel", "daniele", "danielle", "daphne", "david", "delbert", "delphine", "denis", "denise", "désiré", "désirée", "diana", "diane", "didier", "dieudonné", "donald", "donatien", "edgar", "edmé", "edmond", "édouard", "edwige", "eleanor", "éliane", "élie", "élise", "élodie", "émilie", "émilien", "emma", "emmanuelle", "éric", "ernest", "erwan", "estelle", "esther", "étienne", "eve", "fabien", "fabienne", "fabrice", "fanny", "félicien", "ferdinand", "fernand", "fleur", "fleury", "florence", "florian", "florimond", "florine", "francis", "franck", "françois", "françoise", "françois-marie", "françois-xavier", "frank", "frédéric", "fulbert", "fulgence", "gabriel", "gabrielle", "gaël", "gaspard", "gaston", "geneviève", "geoffrey", "georges", "gérald", "géraldine", "gérard", "gerbaud", "germain", "ghislain", "gilbert", "gilles", "gisèle", "giselle", "grégoire", "guillaume", "guy", "harold", "helene", "hélène", "henri", "herbert", "hermine", "hervé", "hilaire", "hodierna", "honoré", "horace", "hubert", "hugo", "hugues", "huguette", "isabella", "ivo", "jacqueline", "jacques", "jacques-désiré", "jacquet", "jacqui", "jasper", "jean", "jean-andré", "jean-antoine", "jean-baptiste", "jean-baptiste-alphonse", "jean-bernard", "jean-charles", "jean-christophe", "jean-claude", "jean-denis", "jean-emmanuel", "jean-étienne", "jeanette", "jean-françois", "jean-henri", "jean-jacques", "jean-julien", "jean-louis", "jean-luc", "jean-marc", "jean-marie", "jean-martin", "jean-michel", "jeanne", "jeannie", "jean-noël", "jean-pascal", "jean-paul", "jean-philippe", "jean-pierre", "jean-rené", "jean-robert", "jean-sébastien", "jean-yves", "jérémie", "jérémy", "joan", "jocelyne", "joël", "joëlle", "johanna", "joie", "jolene", "jonathan", "joseph", "judith", "jules", "julie", "julien", "julien-joseph", "juliette", "justin", "justine", "kadia", "karine", "laetitia", "lauren", "laurence", "laurène", "laurent", "lena", "léon", "léonce", "léonie", "liliane", "lilou", "loïc", "louane", "louis", "louis-alphonse", "louise", "louis-étienne", "loup", "luc", "lucie", "lucien", "lucienne", "lucy", "ludo", "ludovic", "lynnette", "madelaine", "madeleine", "maëlys", "maeva", "manon", "manuel", "marc", "marc-andré", "marcel", "marceline", "marcellin", "marco", "margot", "marguerite", "marianne", "marie", "marie-agnès", "marie-andrée", "marie-claire", "marie-claude", "marie-france", "marie-françoise", "marie-georges", "marielle", "marie louise", "marie-madeleine", "marie-noëlle", "marie-odile", "marie-thérèse", "marine", "marthe", "martin", "maryse", "mathieu", "matthias", "matthieu", "maud", "maurice", "maurille", "maxime", "maximilien", "medard", "melanie", "mélanie", "melvin", "michel", "michel-ange", "michele", "micheline", "michelle", "mireille", "moise", "monique", "murielle", "nadia", "nadine", "natalia", "nathalie", "nicolas", "nikita", "nikoleta", "nikolina", "noel", "noelle", "noémie", "norbert", "océane", "octave", "odette", "odile", "odilon", "olga", "olivia", "olivier", "pacôme", "pascal", "pascale", "patrice", "patricia", "patrick", "paul", "paul-antoine", "paule", "paulette", "pauline", "paul-louis", "pearl", "perrine", "petunia", "philippa", "phillippe", "pierre", "pierre-édouard", "pierre-julien", "pierre-paul", "pierre-simon", "pierrick", "rachel", "rainier", "raoul", "raphael", "raymond", "rémy", "rené", "renée", "robert", "roger", "roland", "romain", "roman", "roméo", "romuald", "ronald", "samuel", "sandrine", "sébastien", "séraphin", "séraphine", "serge", "servais", "severin", "simon", "simone", "solange", "sophie", "stéphane", "stéphanie", "suzanne", "sylvain", "sylvestre", "théodore", "théodule", "thérèse", "thibaut", "thierry", "thomas", "tony", "toussaint", "ulysse", "valentin", "valentine", "valerie", "valérie", "veronica", "véronique", "victor", "victoria", "viera", "vincent", "virginie", "viviane", "xavier", "xaviera", "yacine", "yann", "yannick", "yvan", "yves", "yvette", "yvon", "yvonne", "zacharie", "zoé" 52 | ]; 53 | 54 | languagesDS["fra"]["city"] = [ 55 | ["bastia", "france", "corsica"], ["lorient", "france", "bretagne"], ["brest", "france", "bretagne"], ["aix-en-provence", "france", "provence-alpes-côte d’azur"], ["ajaccio", "france", "corsica"], ["marseille", "france", "provence-alpes-côte d’azur"], ["rennes", "france", "bretagne"], ["nantes", "france", "pays de la loire"], ["orléans", "france", "centre-val de loire"], ["paris", "france", "île-de-france"], ["clermont-ferrand", "france", "auvergne-rhône-alpes"], ["metz", "france", "grand est"], ["montpellier", "france", "occitanie"], ["poitier", "france", "nouvelle-aquitaine"], ["bordeaux", "france", "nouvelle-aquitaine"], ["limoges", "france", "nouvelle-aquitaine"], ["dijon", "france", "bourgogne-franche-comté"], ["lille", "france", "hauts-de-france"], ["lyon", "france", "auvergne-rhône-alpes"], ["strasbourg", "france", "grand est"], ["toulouse", "france", "occitanie"], ["rouen", "france", "normandie"], ["amiens", "france", "hauts-de-france"], ["besançon", "france", "bourgogne-franche-comté"], ["caen", "france", "normandie"], ["vichy", "france", "auvergne-rhône-alpes"], ["mulhouse", "france", "grand est"], ["biarritz", "france", "nouvelle-aquitaine"], ["cherbourg", "france", "normandie"], ["reims", "france", "grand est"], ["calais", "france", "hauts-de-france"], ["roanne", "france", "auvergne-rhône-alpes"], ["dieppe", "france", "normandie"], ["le havre", "france", "normandie"], ["brive", "france", "nouvelle-aquitaine"], ["béziers", "france", "occitanie"], ["st.-brieuc", "france", "bretagne"], ["angers", "france", "pays de la loire"], ["le mans", "france", "pays de la loire"], ["arras", "france", "hauts-de-france"], ["troyes", "france", "grand est"], ["nancy", "france", "grand est"], ["nevers", "france", "bourgogne-franche-comté"], ["auxerre", "france", "bourgogne-franche-comté"], ["tours", "france", "centre-val de loire"], ["bourges", "france", "centre-val de loire"], ["versailles", "france", "île-de-france"], ["melun", "france", "île-de-france"], ["la rochelle", "france", "nouvelle-aquitaine"], ["agen", "france", "nouvelle-aquitaine"], ["annecy", "france", "auvergne-rhône-alpes"], ["grenoble", "france", "auvergne-rhône-alpes"], ["saint-étienne", "france", "auvergne-rhône-alpes"], ["toulon", "france", "provence-alpes-côte d’azur"], ["nice", "france", "provence-alpes-côte d’azur"], ["tarbes", "france", "occitanie"], ["perpignan", "france", "occitanie"], ["nîmes", "france", "occitanie"] 56 | ]; 57 | -------------------------------------------------------------------------------- /src/lang/spa.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 0.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: ita.js 6 | * Description: Italian language pack 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | languagesDS["spa"] = {}; 26 | 27 | languagesDS["spa"]["job"] = []; 28 | 29 | languagesDS["spa"]["title"] = []; 30 | 31 | languagesDS["spa"]["titleTrash"] = []; 32 | 33 | languagesDS["spa"]["street"] = [ 34 | /\bcalle\b/g, 35 | /\bcarrera\b/g, 36 | /\bcarretera\b/g, 37 | /\bcuesta\b/g, 38 | /\bpaseo\b/g, 39 | /\bplaza\b/g, 40 | /\bronda\b/g 41 | ]; 42 | 43 | languagesDS["spa"]["name"] = [ 44 | "aarón", "abel", "abelardo", "abraham", "adan", "ademar", "adrià", "adriana", "adriano", "agustin", "agustina", "aida", "alberto", "aldea", "alejandra", "alejandro", "alfredo", "alicia", "alma", "almudena", "alonso", "alphons", "amalia", "amparo", "ana", "anabel", "andrea", "andreina", "angel", "aníbal", "anita", "antero", "antonia", "antonio", "araceli", "armando", "arnaldo", "arsenio", "augusto", "aurora", "aznar", "benito", "bernardo", "beto", "bianca", "blanca", "blanche", "bonita", "bruno", "carlos", "carlos eduardo", "carlota", "carmelita", "carmelo", "carolina", "catalina", "cesar", "cipriano", "claudia", "concepción", "conchita", "consuelo", "cristhian", "cristina", "cynthia", "damián", "daniel", "danilo", "dario", "david", "delia", "diana", "diego", "dolores", "eduardo", "efraín", "elena", "eliana", "elisa", "eliseo", "elvira", "emilio", "emily", "enrique", "erika", "ernesto", "esteban", "ester", "eva", "ezequiel", "fabricio", "fatima", "federico", "feliciano", "felipe", "fernanda", "fernando", "fernando josé", "flavia", "flavio", "flora", "florencio", "florentin", "francisco", "fulgencio", "gabriel", "gabriela", "garbiñe", "gaspar", "genovevo", "gilberto", "ginés", "guido", "guillermo", "guiomar", "gustavo", "helena", "heriberto", "hernándo", "hilda", "hugo", "ignacio", "ileana", "ilona", "imelda", "ines", "inez", "inigo", "iris", "isa", "isabel", "isabella", "ivette", "ivonne", "jacin", "jacinta", "jacinto", "jacqueline", "jaime", "javier", "javiera", "jerónimo", "jimeno", "joaquín", "joaquina", "jorge", "josé", "josé carlos", "josé enrique", "josefina", "josé maría", "juan", "juana", "juanfran", "juanma", "julia", "julián", "julio", "julio cesar", "jusepe", "justina", "karina", "lana", "lara", "laura", "leandro", "lena", "leonardo", "leopoldo", "liberto", "lidia", "liliana", "lolita", "lorena", "lorenzo", "luca", "luciana", "luciano", "lucio", "luis", "luisa", "luis filipe", "lupe", "lupita", "luz", "macarena", "magdalena", "maikel", "manolito", "manolo", "manuel", "manuela", "marcela", "marcelino", "marcelo", "marco", "marcos", "margarita", "maria", "maría alejandra", "maría de lourdes", "maría josé", "mariana", "mariano", "mariela", "marina", "mario", "marisa", "marisol", "marta", "maruja", "mateo", "matías", "maura", "mauricio", "maximiliano", "maya", "melania", "melina", "melquíades", "mercedes", "miguel", "miguel ángel", "milagros", "milena", "millaray", "milo", "mirta", "morena", "nadia", "narciso", "natalia", "nazaret", "nazario", "nemesio", "nestor", "nicolas", "nikolina", "nina", "noelia", "núria", "obdulio", "olga", "omar", "osorio", "osvaldo", "oswaldo", "pablo", "paco", "paloma", "panfilo", "pascual", "pasqual", "patricio", "paula", "paulina", "pepe", "perez", "pilar", "primitivo", "purita", "rachel", "rafa", "ramiro", "ramón", "ramona", "raphael", "raquel", "raul", "reinaldo", "ricardo", "rita", "rocío", "rodolfo", "rogelio", "rolando", "roman", "ronaldo", "rosa", "rosario", "rosendo", "salma", "salvador", "samuel", "sandra", "santiago", "sebastian", "servando", "silvestre", "silvina", "simone", "sixto", "soledad", "sonia", "sophia", "soraya", "tamara", "tara", "tatiana", "tato", "tina", "tomás", "tomasa", "toni", "tupac", "urraca", "urtzi", "valentina", "valeria", "venancio", "veronica", "víctor", "victoria", "victorino", "vilma", "viola", "violeta", "virginia", "viridiana", "wenceslao", "wilfredo", "xavi", "xiomara", "xóchitl", "yanet", "zulema" 45 | ]; 46 | 47 | languagesDS["spa"]["city"] = [ 48 | ["vitoria", "spain", "basque country"], ["santander", "spain", "cantabria"], ["logroño", "spain", "la rioja"], ["barcelona", "spain", "catalonia"], ["mataró", "spain", "catalonia"], ["oviedo", "spain", "asturias"], ["arrecife", "spain", "canary islands"], ["las palmas", "spain", "canary islands"], ["toledo", "spain", "castille-la mancha"], ["lorca", "spain", "murcia"], ["zaragoza", "spain", "aragon"], ["murcia", "spain", "murcia"], ["gijón", "spain", "asturias"], ["linares", "spain", "andalusia"], ["cartagena", "spain", "murcia"], ["vigo", "spain", "galicia"], ["valladolid", "spain", "castille-leon"], ["santiago de compostela", "spain", "galicia"], ["mérida", "spain", "extremadura"], ["algeciras", "spain", "andalusia"], ["marbella", "spain", "andalusia"], ["almería", "spain", "andalusia"], ["córdoba", "spain", "andalusia"], ["granada?", "spain", "andalusia"], ["jaén", "spain", "andalusia"], ["málaga", "spain", "andalusia"], ["albacete", "spain", "castille-la mancha"], ["guadalajara", "spain", "castille-la mancha"], ["burgos", "spain", "castille-leon"], ["león", "spain", "castille-leon"], ["salamanca", "spain", "castille-leon"], ["huelva", "spain", "andalusia"], ["cádiz", "spain", "andalusia"], ["ceuta", "spain", "ceuta"], ["melilla", "spain", "melilla"], ["tarragona", "spain", "catalonia"], ["badajoz", "spain", "extremadura"], ["la coruña", "spain", "galicia"], ["ourense", "spain", "galicia"], ["bilbao", "spain", "basque country"], ["santa cruz de tenerife", "spain", "canary islands"], ["seville", "spain", "andalusia"], ["pamplona", "spain", "navarre"], ["palma", "spain", "balearic islands"], ["valencia", "spain", "valencia"], ["madrid", "spain", "madrid"], ["san sebastián", "spain", "basque country"], ["alicante", "spain", "valencia"], ["castello", "spain", "valencia"] 49 | ]; 50 | -------------------------------------------------------------------------------- /src/lang/swe.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cordova BCR Library 0.0.12 3 | * Authors: Gaspare Ferraro, Renzo Sala 4 | * Contributors: Simone Ponte, Paolo Macco 5 | * Filename: ita.js 6 | * Description: Italian language pack 7 | * 8 | * @license 9 | * Copyright 2019 Syneo Tools GmbH. All Rights Reserved. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | languagesDS["swe"] = {}; 26 | 27 | languagesDS["swe"]["job"] = []; 28 | 29 | languagesDS["swe"]["title"] = []; 30 | 31 | languagesDS["swe"]["titleTrash"] = []; 32 | 33 | languagesDS["swe"]["street"] = [ 34 | /\bmäster\b/g, 35 | /\bnorr\b/g, 36 | /\bgata\b/g, 37 | /gatan\b/g, 38 | /svägen\b/g, 39 | /\bsätt\b/g, 40 | /\bfrån\b/g, 41 | /\bkvadrat\b/g, 42 | /\bnaturligtvis\b/g, 43 | /\bavenue\b/g 44 | ]; 45 | 46 | languagesDS["swe"]["name"] = [ 47 | "abraham", "adam", "adel", "adolf", "adrian", "agatha", "agnes", "agneta", "aina", "åke", "albert", "albina", "alexander", "alf", "alfred", "amalia", "amelia", "anders", "andreas", "anna", "anneli", "anneliese", "annika", "anton", "antonia", "arne", "arthur", "arvid", "astrid", "august", "aurora", "axel", "baldur", "beata", "bengt", "benkt", "bernhard", "bertil", "birgit", "birgitta", "bjorn", "bo", "bodil", "börje", "britta", "bror", "carin", "carl", "carolina", "caroline", "catharina", "cecilie", "charlotte", "christa", "christer", "christian", "clas", "dag", "dagmar", "daniel", "david", "donald", "ebba", "ebbe", "edvard", "edvin", "egon", "einar", "ejnar", "eldar", "elin", "elina", "elisa", "ellen", "elsa", "emil", "emilie", "emma", "eric", "erik", "erika", "erland", "esbjörn", "estelle", "eva", "evald", "evert", "felix", "filippa", "folke", "fredrik", "frida", "fritiof", "gerda", "gert", "göran", "gösta", "göta", "greta", "grete", "gun", "gunilla", "gunnar", "gunnel", "gustav", "håkan", "hans", "harald", "heidi", "helena", "helene", "helga", "helge", "henrika", "herman", "hilda", "hildur", "hjalmar", "hjördís", "holger", "hulda", "indira", "inga", "inge", "ingemar", "inger", "ingmar", "ingrid", "ingvar", "irnes", "isa", "isabella", "ivar", "jack", "jacob", "jan", "janne", "jarl", "joakim", "johan", "johannes", "john", "jonas", "jonatan", "judith", "justina", "kajsa", "kalle", "karen", "karin", "karl", "katarina", "katja", "kerstin", "kjell", "klaus", "krista", "krister", "kristi", "kristin", "kristina", "kristofer", "kurt", "lars", "lasse", "lauritz", "leif", "lena", "lennart", "lina", "linnéa", "linus", "lotta", "lotte", "love", "lovisa", "lucia", "ludvig", "lukas", "magdalena", "magnus", "malin", "marcus", "margareta", "margaretha", "margit", "maria", "marianne", "märta", "mårten", "martin", "matias", "mats", "matthias", "mattias", "mauritz", "monika", "nanne", "natalie", "nils", "nina", "norbert", "ola", "olaf", "oliver", "olivia", "olov", "örjan", "orvar", "ossian", "osvald", "otto", "ove", "owe", "paul", "paula", "pearl", "pelle", "per", "pernilla", "peter", "petunia", "philip", "ragnar", "ralph", "rasmus", "rebecka", "richenza", "rita", "robert", "rolf", "ronald", "ronja", "rudolph", "rune", "rutger", "samuel", "selma", "siv", "sixten", "staffan", "stefan", "stellan", "sten", "stig", "susanna", "susanne", "svante", "svea", "sven", "tage", "tara", "teodor", "thaddeus", "theodor", "thomas", "thor", "tobias", "tomas", "torbjörn", "tore", "torgny", "tove", "ulf", "ulrica", "ulrik", "uno", "vagn", "valentin", "valerie", "vera", "victoria", "vilhelm", "vincent", "walter", "werner", "ylva", "yngve", "yvonne" 48 | ]; 49 | 50 | languagesDS["swe"]["city"] = [ 51 | ["västerås", "sweden", "västmanland"], ["uppsala", "sweden", "uppsala"], ["örebro", "sweden", "örebro"], ["östersund", "sweden", "jämtland"], ["karlstad", "sweden", "värmland"], ["nyköping", "sweden", "södermanland"], ["göteborg", "sweden", "västra götaland"], ["halmstad", "sweden", "halland"], ["linköping", "sweden", "östergötland"], ["jönköping", "sweden", "jönköping"], ["kalmar", "sweden", "kalmar"], ["gävle", "sweden", "gävleborg"], ["malmö", "sweden", "skåne"], ["växjö", "sweden", "kronoberg"], ["luleå", "sweden", "norrbotten"], ["stockholm", "sweden", "stockholm"], ["karlskrona", "sweden", "blekinge"], ["falun", "sweden", "dalarna"], ["härnösand", "sweden", "västernorrland"], ["uppsala", "sweden", "stockholm"], ["umeå", "sweden", "västerbotten"], ["kiruna", "sweden", "norrbotten"], ["helsingborg", "sweden", "skåne"], ["skellefteå", "sweden", "västerbotten"], ["bollnäs", "sweden", "gävleborg"], ["trollhättan", "sweden", "västra götaland"], ["örnsköldsvik", "sweden", "västernorrland"], ["sundsvall", "sweden", "västernorrland"], ["norrköping", "sweden", "östergötland"], ["vannersborg", "sweden", "västra götaland"], ["borås", "sweden", "västra götaland"], ["kristianstad", "sweden", "skåne"], ["borlänge", "sweden", "dalarna"], ["mariestad", "sweden", "västra götaland"], ["visby", "sweden", "gotland"] 52 | ]; 53 | -------------------------------------------------------------------------------- /src/qr/alignpat.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function AlignmentPattern(posX, posY, estimatedModuleSize) 27 | { 28 | this.x=posX; 29 | this.y=posY; 30 | this.count = 1; 31 | this.estimatedModuleSize = estimatedModuleSize; 32 | 33 | this.__defineGetter__("EstimatedModuleSize", function() 34 | { 35 | return this.estimatedModuleSize; 36 | }); 37 | this.__defineGetter__("Count", function() 38 | { 39 | return this.count; 40 | }); 41 | this.__defineGetter__("X", function() 42 | { 43 | return Math.floor(this.x); 44 | }); 45 | this.__defineGetter__("Y", function() 46 | { 47 | return Math.floor(this.y); 48 | }); 49 | this.incrementCount = function() 50 | { 51 | this.count++; 52 | } 53 | this.aboutEquals=function( moduleSize, i, j) 54 | { 55 | if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize) 56 | { 57 | var moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize); 58 | return moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0; 59 | } 60 | return false; 61 | } 62 | 63 | } 64 | 65 | function AlignmentPatternFinder( image, startX, startY, width, height, moduleSize, resultPointCallback) 66 | { 67 | this.image = image; 68 | this.possibleCenters = new Array(); 69 | this.startX = startX; 70 | this.startY = startY; 71 | this.width = width; 72 | this.height = height; 73 | this.moduleSize = moduleSize; 74 | this.crossCheckStateCount = new Array(0,0,0); 75 | this.resultPointCallback = resultPointCallback; 76 | 77 | this.centerFromEnd=function(stateCount, end) 78 | { 79 | return (end - stateCount[2]) - stateCount[1] / 2.0; 80 | } 81 | this.foundPatternCross = function(stateCount) 82 | { 83 | var moduleSize = this.moduleSize; 84 | var maxVariance = moduleSize / 2.0; 85 | for (var i = 0; i < 3; i++) 86 | { 87 | if (Math.abs(moduleSize - stateCount[i]) >= maxVariance) 88 | { 89 | return false; 90 | } 91 | } 92 | return true; 93 | } 94 | 95 | this.crossCheckVertical=function( startI, centerJ, maxCount, originalStateCountTotal) 96 | { 97 | var image = this.image; 98 | 99 | var maxI = qrcode.height; 100 | var stateCount = this.crossCheckStateCount; 101 | stateCount[0] = 0; 102 | stateCount[1] = 0; 103 | stateCount[2] = 0; 104 | 105 | // Start counting up from center 106 | var i = startI; 107 | while (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount) 108 | { 109 | stateCount[1]++; 110 | i--; 111 | } 112 | // If already too many modules in this state or ran off the edge: 113 | if (i < 0 || stateCount[1] > maxCount) 114 | { 115 | return NaN; 116 | } 117 | while (i >= 0 && !image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount) 118 | { 119 | stateCount[0]++; 120 | i--; 121 | } 122 | if (stateCount[0] > maxCount) 123 | { 124 | return NaN; 125 | } 126 | 127 | // Now also count down from center 128 | i = startI + 1; 129 | while (i < maxI && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount) 130 | { 131 | stateCount[1]++; 132 | i++; 133 | } 134 | if (i == maxI || stateCount[1] > maxCount) 135 | { 136 | return NaN; 137 | } 138 | while (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[2] <= maxCount) 139 | { 140 | stateCount[2]++; 141 | i++; 142 | } 143 | if (stateCount[2] > maxCount) 144 | { 145 | return NaN; 146 | } 147 | 148 | var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; 149 | if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) 150 | { 151 | return NaN; 152 | } 153 | 154 | return this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, i):NaN; 155 | } 156 | 157 | this.handlePossibleCenter=function( stateCount, i, j) 158 | { 159 | var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; 160 | var centerJ = this.centerFromEnd(stateCount, j); 161 | var centerI = this.crossCheckVertical(i, Math.floor (centerJ), 2 * stateCount[1], stateCountTotal); 162 | if (!isNaN(centerI)) 163 | { 164 | var estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0; 165 | var max = this.possibleCenters.length; 166 | for (var index = 0; index < max; index++) 167 | { 168 | var center = this.possibleCenters[index]; 169 | // Look for about the same center and module size: 170 | if (center.aboutEquals(estimatedModuleSize, centerI, centerJ)) 171 | { 172 | return new AlignmentPattern(centerJ, centerI, estimatedModuleSize); 173 | } 174 | } 175 | // Hadn't found this before; save it 176 | var point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize); 177 | this.possibleCenters.push(point); 178 | if (this.resultPointCallback != null) 179 | { 180 | this.resultPointCallback.foundPossibleResultPoint(point); 181 | } 182 | } 183 | return null; 184 | } 185 | 186 | this.find = function() 187 | { 188 | var startX = this.startX; 189 | var height = this.height; 190 | var maxJ = startX + width; 191 | var middleI = startY + (height >> 1); 192 | // We are looking for black/white/black modules in 1:1:1 ratio; 193 | // this tracks the number of black/white/black modules seen so far 194 | var stateCount = new Array(0,0,0); 195 | for (var iGen = 0; iGen < height; iGen++) 196 | { 197 | // Search from middle outwards 198 | var i = middleI + ((iGen & 0x01) == 0?((iGen + 1) >> 1):- ((iGen + 1) >> 1)); 199 | stateCount[0] = 0; 200 | stateCount[1] = 0; 201 | stateCount[2] = 0; 202 | var j = startX; 203 | // Burn off leading white pixels before anything else; if we start in the middle of 204 | // a white run, it doesn't make sense to count its length, since we don't know if the 205 | // white run continued to the left of the start point 206 | while (j < maxJ && !image[j + qrcode.width* i]) 207 | { 208 | j++; 209 | } 210 | var currentState = 0; 211 | while (j < maxJ) 212 | { 213 | if (image[j + i*qrcode.width]) 214 | { 215 | // Black pixel 216 | if (currentState == 1) 217 | { 218 | // Counting black pixels 219 | stateCount[currentState]++; 220 | } 221 | else 222 | { 223 | // Counting white pixels 224 | if (currentState == 2) 225 | { 226 | // A winner? 227 | if (this.foundPatternCross(stateCount)) 228 | { 229 | // Yes 230 | var confirmed = this.handlePossibleCenter(stateCount, i, j); 231 | if (confirmed != null) 232 | { 233 | return confirmed; 234 | } 235 | } 236 | stateCount[0] = stateCount[2]; 237 | stateCount[1] = 1; 238 | stateCount[2] = 0; 239 | currentState = 1; 240 | } 241 | else 242 | { 243 | stateCount[++currentState]++; 244 | } 245 | } 246 | } 247 | else 248 | { 249 | // White pixel 250 | if (currentState == 1) 251 | { 252 | // Counting black pixels 253 | currentState++; 254 | } 255 | stateCount[currentState]++; 256 | } 257 | j++; 258 | } 259 | if (this.foundPatternCross(stateCount)) 260 | { 261 | var confirmed = this.handlePossibleCenter(stateCount, i, maxJ); 262 | if (confirmed != null) 263 | { 264 | return confirmed; 265 | } 266 | } 267 | } 268 | 269 | // Hmm, nothing we saw was observed and confirmed twice. If we had 270 | // any guess at all, return it. 271 | if (!(this.possibleCenters.length == 0)) 272 | { 273 | return this.possibleCenters[0]; 274 | } 275 | 276 | throw "Couldn't find enough alignment patterns"; 277 | } 278 | 279 | } -------------------------------------------------------------------------------- /src/qr/bitmat.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function BitMatrix( width, height) 27 | { 28 | if(!height) 29 | height=width; 30 | if (width < 1 || height < 1) 31 | { 32 | throw "Both dimensions must be greater than 0"; 33 | } 34 | this.width = width; 35 | this.height = height; 36 | var rowSize = width >> 5; 37 | if ((width & 0x1f) != 0) 38 | { 39 | rowSize++; 40 | } 41 | this.rowSize = rowSize; 42 | this.bits = new Array(rowSize * height); 43 | for(var i=0;i> 5); 66 | return ((URShift(this.bits[offset], (x & 0x1f))) & 1) != 0; 67 | } 68 | this.set_Renamed=function( x, y) 69 | { 70 | var offset = y * this.rowSize + (x >> 5); 71 | this.bits[offset] |= 1 << (x & 0x1f); 72 | } 73 | this.flip=function( x, y) 74 | { 75 | var offset = y * this.rowSize + (x >> 5); 76 | this.bits[offset] ^= 1 << (x & 0x1f); 77 | } 78 | this.clear=function() 79 | { 80 | var max = this.bits.length; 81 | for (var i = 0; i < max; i++) 82 | { 83 | this.bits[i] = 0; 84 | } 85 | } 86 | this.setRegion=function( left, top, width, height) 87 | { 88 | if (top < 0 || left < 0) 89 | { 90 | throw "Left and top must be nonnegative"; 91 | } 92 | if (height < 1 || width < 1) 93 | { 94 | throw "Height and width must be at least 1"; 95 | } 96 | var right = left + width; 97 | var bottom = top + height; 98 | if (bottom > this.height || right > this.width) 99 | { 100 | throw "The region must fit inside the matrix"; 101 | } 102 | for (var y = top; y < bottom; y++) 103 | { 104 | var offset = y * this.rowSize; 105 | for (var x = left; x < right; x++) 106 | { 107 | this.bits[offset + (x >> 5)] |= 1 << (x & 0x1f); 108 | } 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /src/qr/bmparser.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function BitMatrixParser(bitMatrix) 27 | { 28 | var dimension = bitMatrix.Dimension; 29 | if (dimension < 21 || (dimension & 0x03) != 1) 30 | { 31 | throw "Error BitMatrixParser"; 32 | } 33 | this.bitMatrix = bitMatrix; 34 | this.parsedVersion = null; 35 | this.parsedFormatInfo = null; 36 | 37 | this.copyBit=function( i, j, versionBits) 38 | { 39 | return this.bitMatrix.get_Renamed(i, j)?(versionBits << 1) | 0x1:versionBits << 1; 40 | } 41 | 42 | this.readFormatInformation=function() 43 | { 44 | if (this.parsedFormatInfo != null) 45 | { 46 | return this.parsedFormatInfo; 47 | } 48 | 49 | // Read top-left format info bits 50 | var formatInfoBits = 0; 51 | for (var i = 0; i < 6; i++) 52 | { 53 | formatInfoBits = this.copyBit(i, 8, formatInfoBits); 54 | } 55 | // .. and skip a bit in the timing pattern ... 56 | formatInfoBits = this.copyBit(7, 8, formatInfoBits); 57 | formatInfoBits = this.copyBit(8, 8, formatInfoBits); 58 | formatInfoBits = this.copyBit(8, 7, formatInfoBits); 59 | // .. and skip a bit in the timing pattern ... 60 | for (var j = 5; j >= 0; j--) 61 | { 62 | formatInfoBits = this.copyBit(8, j, formatInfoBits); 63 | } 64 | 65 | this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits); 66 | if (this.parsedFormatInfo != null) 67 | { 68 | return this.parsedFormatInfo; 69 | } 70 | 71 | // Hmm, failed. Try the top-right/bottom-left pattern 72 | var dimension = this.bitMatrix.Dimension; 73 | formatInfoBits = 0; 74 | var iMin = dimension - 8; 75 | for (var i = dimension - 1; i >= iMin; i--) 76 | { 77 | formatInfoBits = this.copyBit(i, 8, formatInfoBits); 78 | } 79 | for (var j = dimension - 7; j < dimension; j++) 80 | { 81 | formatInfoBits = this.copyBit(8, j, formatInfoBits); 82 | } 83 | 84 | this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits); 85 | if (this.parsedFormatInfo != null) 86 | { 87 | return this.parsedFormatInfo; 88 | } 89 | throw "Error readFormatInformation"; 90 | } 91 | this.readVersion=function() 92 | { 93 | 94 | if (this.parsedVersion != null) 95 | { 96 | return this.parsedVersion; 97 | } 98 | 99 | var dimension = this.bitMatrix.Dimension; 100 | 101 | var provisionalVersion = (dimension - 17) >> 2; 102 | if (provisionalVersion <= 6) 103 | { 104 | return Version.getVersionForNumber(provisionalVersion); 105 | } 106 | 107 | // Read top-right version info: 3 wide by 6 tall 108 | var versionBits = 0; 109 | var ijMin = dimension - 11; 110 | for (var j = 5; j >= 0; j--) 111 | { 112 | for (var i = dimension - 9; i >= ijMin; i--) 113 | { 114 | versionBits = this.copyBit(i, j, versionBits); 115 | } 116 | } 117 | 118 | this.parsedVersion = Version.decodeVersionInformation(versionBits); 119 | if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension) 120 | { 121 | return this.parsedVersion; 122 | } 123 | 124 | // Hmm, failed. Try bottom left: 6 wide by 3 tall 125 | versionBits = 0; 126 | for (var i = 5; i >= 0; i--) 127 | { 128 | for (var j = dimension - 9; j >= ijMin; j--) 129 | { 130 | versionBits = this.copyBit(i, j, versionBits); 131 | } 132 | } 133 | 134 | this.parsedVersion = Version.decodeVersionInformation(versionBits); 135 | if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension) 136 | { 137 | return this.parsedVersion; 138 | } 139 | throw "Error readVersion"; 140 | } 141 | this.readCodewords=function() 142 | { 143 | 144 | var formatInfo = this.readFormatInformation(); 145 | var version = this.readVersion(); 146 | 147 | // Get the data mask for the format used in this QR Code. This will exclude 148 | // some bits from reading as we wind through the bit matrix. 149 | var dataMask = DataMask.forReference( formatInfo.DataMask); 150 | var dimension = this.bitMatrix.Dimension; 151 | dataMask.unmaskBitMatrix(this.bitMatrix, dimension); 152 | 153 | var functionPattern = version.buildFunctionPattern(); 154 | 155 | var readingUp = true; 156 | var result = new Array(version.TotalCodewords); 157 | var resultOffset = 0; 158 | var currentByte = 0; 159 | var bitsRead = 0; 160 | // Read columns in pairs, from right to left 161 | for (var j = dimension - 1; j > 0; j -= 2) 162 | { 163 | if (j == 6) 164 | { 165 | // Skip whole column with vertical alignment pattern; 166 | // saves time and makes the other code proceed more cleanly 167 | j--; 168 | } 169 | // Read alternatingly from bottom to top then top to bottom 170 | for (var count = 0; count < dimension; count++) 171 | { 172 | var i = readingUp?dimension - 1 - count:count; 173 | for (var col = 0; col < 2; col++) 174 | { 175 | // Ignore bits covered by the function pattern 176 | if (!functionPattern.get_Renamed(j - col, i)) 177 | { 178 | // Read a bit 179 | bitsRead++; 180 | currentByte <<= 1; 181 | if (this.bitMatrix.get_Renamed(j - col, i)) 182 | { 183 | currentByte |= 1; 184 | } 185 | // If we've made a whole byte, save it off 186 | if (bitsRead == 8) 187 | { 188 | result[resultOffset++] = currentByte; 189 | bitsRead = 0; 190 | currentByte = 0; 191 | } 192 | } 193 | } 194 | } 195 | readingUp ^= true; // readingUp = !readingUp; // switch directions 196 | } 197 | if (resultOffset != version.TotalCodewords) 198 | { 199 | throw "Error readCodewords"; 200 | } 201 | return result; 202 | } 203 | } -------------------------------------------------------------------------------- /src/qr/datablock.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function DataBlock(numDataCodewords, codewords) 27 | { 28 | this.numDataCodewords = numDataCodewords; 29 | this.codewords = codewords; 30 | 31 | this.__defineGetter__("NumDataCodewords", function() 32 | { 33 | return this.numDataCodewords; 34 | }); 35 | this.__defineGetter__("Codewords", function() 36 | { 37 | return this.codewords; 38 | }); 39 | } 40 | 41 | DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel) 42 | { 43 | 44 | if (rawCodewords.length != version.TotalCodewords) 45 | { 46 | throw "ArgumentException"; 47 | } 48 | 49 | // Figure out the number and size of data blocks used by this version and 50 | // error correction level 51 | var ecBlocks = version.getECBlocksForLevel(ecLevel); 52 | 53 | // First count the total number of data blocks 54 | var totalBlocks = 0; 55 | var ecBlockArray = ecBlocks.getECBlocks(); 56 | for (var i = 0; i < ecBlockArray.length; i++) 57 | { 58 | totalBlocks += ecBlockArray[i].Count; 59 | } 60 | 61 | // Now establish DataBlocks of the appropriate size and number of data codewords 62 | var result = new Array(totalBlocks); 63 | var numResultBlocks = 0; 64 | for (var j = 0; j < ecBlockArray.length; j++) 65 | { 66 | var ecBlock = ecBlockArray[j]; 67 | for (var i = 0; i < ecBlock.Count; i++) 68 | { 69 | var numDataCodewords = ecBlock.DataCodewords; 70 | var numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords; 71 | result[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords)); 72 | } 73 | } 74 | 75 | // All blocks have the same amount of data, except that the last n 76 | // (where n may be 0) have 1 more byte. Figure out where these start. 77 | var shorterBlocksTotalCodewords = result[0].codewords.length; 78 | var longerBlocksStartAt = result.length - 1; 79 | while (longerBlocksStartAt >= 0) 80 | { 81 | var numCodewords = result[longerBlocksStartAt].codewords.length; 82 | if (numCodewords == shorterBlocksTotalCodewords) 83 | { 84 | break; 85 | } 86 | longerBlocksStartAt--; 87 | } 88 | longerBlocksStartAt++; 89 | 90 | var shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock; 91 | // The last elements of result may be 1 element longer; 92 | // first fill out as many elements as all of them have 93 | var rawCodewordsOffset = 0; 94 | for (var i = 0; i < shorterBlocksNumDataCodewords; i++) 95 | { 96 | for (var j = 0; j < numResultBlocks; j++) 97 | { 98 | result[j].codewords[i] = rawCodewords[rawCodewordsOffset++]; 99 | } 100 | } 101 | // Fill out the last data block in the longer ones 102 | for (var j = longerBlocksStartAt; j < numResultBlocks; j++) 103 | { 104 | result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; 105 | } 106 | // Now add in error correction blocks 107 | var max = result[0].codewords.length; 108 | for (var i = shorterBlocksNumDataCodewords; i < max; i++) 109 | { 110 | for (var j = 0; j < numResultBlocks; j++) 111 | { 112 | var iOffset = j < longerBlocksStartAt?i:i + 1; 113 | result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++]; 114 | } 115 | } 116 | return result; 117 | } 118 | -------------------------------------------------------------------------------- /src/qr/databr.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) 27 | { 28 | this.blockPointer = 0; 29 | this.bitPointer = 7; 30 | this.dataLength = 0; 31 | this.blocks = blocks; 32 | this.numErrorCorrectionCode = numErrorCorrectionCode; 33 | if (version <= 9) 34 | this.dataLengthMode = 0; 35 | else if (version >= 10 && version <= 26) 36 | this.dataLengthMode = 1; 37 | else if (version >= 27 && version <= 40) 38 | this.dataLengthMode = 2; 39 | 40 | this.getNextBits = function( numBits) 41 | { 42 | var bits = 0; 43 | if (numBits < this.bitPointer + 1) 44 | { 45 | // next word fits into current data block 46 | var mask = 0; 47 | for (var i = 0; i < numBits; i++) 48 | { 49 | mask += (1 << i); 50 | } 51 | mask <<= (this.bitPointer - numBits + 1); 52 | 53 | bits = (this.blocks[this.blockPointer] & mask) >> (this.bitPointer - numBits + 1); 54 | this.bitPointer -= numBits; 55 | return bits; 56 | } 57 | else if (numBits < this.bitPointer + 1 + 8) 58 | { 59 | // next word crosses 2 data blocks 60 | var mask1 = 0; 61 | for (var i = 0; i < this.bitPointer + 1; i++) 62 | { 63 | mask1 += (1 << i); 64 | } 65 | bits = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1)); 66 | this.blockPointer++; 67 | bits += ((this.blocks[this.blockPointer]) >> (8 - (numBits - (this.bitPointer + 1)))); 68 | 69 | this.bitPointer = this.bitPointer - numBits % 8; 70 | if (this.bitPointer < 0) 71 | { 72 | this.bitPointer = 8 + this.bitPointer; 73 | } 74 | return bits; 75 | } 76 | else if (numBits < this.bitPointer + 1 + 16) 77 | { 78 | // next word crosses 3 data blocks 79 | var mask1 = 0; // mask of first block 80 | var mask3 = 0; // mask of 3rd block 81 | //bitPointer + 1 : number of bits of the 1st block 82 | //8 : number of the 2nd block (note that use already 8bits because next word uses 3 data blocks) 83 | //numBits - (bitPointer + 1 + 8) : number of bits of the 3rd block 84 | for (var i = 0; i < this.bitPointer + 1; i++) 85 | { 86 | mask1 += (1 << i); 87 | } 88 | var bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1)); 89 | this.blockPointer++; 90 | 91 | var bitsSecondBlock = this.blocks[this.blockPointer] << (numBits - (this.bitPointer + 1 + 8)); 92 | this.blockPointer++; 93 | 94 | for (var i = 0; i < numBits - (this.bitPointer + 1 + 8); i++) 95 | { 96 | mask3 += (1 << i); 97 | } 98 | mask3 <<= 8 - (numBits - (this.bitPointer + 1 + 8)); 99 | var bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> (8 - (numBits - (this.bitPointer + 1 + 8))); 100 | 101 | bits = bitsFirstBlock + bitsSecondBlock + bitsThirdBlock; 102 | this.bitPointer = this.bitPointer - (numBits - 8) % 8; 103 | if (this.bitPointer < 0) 104 | { 105 | this.bitPointer = 8 + this.bitPointer; 106 | } 107 | return bits; 108 | } 109 | else 110 | { 111 | return 0; 112 | } 113 | } 114 | this.NextMode=function() 115 | { 116 | if ((this.blockPointer > this.blocks.length - this.numErrorCorrectionCode - 2)) 117 | return 0; 118 | else 119 | return this.getNextBits(4); 120 | } 121 | this.getDataLength=function( modeIndicator) 122 | { 123 | var index = 0; 124 | while (true) 125 | { 126 | if ((modeIndicator >> index) == 1) 127 | break; 128 | index++; 129 | } 130 | 131 | return this.getNextBits(qrcode.sizeOfDataLengthInfo[this.dataLengthMode][index]); 132 | } 133 | this.getRomanAndFigureString=function( dataLength) 134 | { 135 | var length = dataLength; 136 | var intData = 0; 137 | var strData = ""; 138 | var tableRomanAndFigure = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'); 139 | do 140 | { 141 | if (length > 1) 142 | { 143 | intData = this.getNextBits(11); 144 | var firstLetter = Math.floor(intData / 45); 145 | var secondLetter = intData % 45; 146 | strData += tableRomanAndFigure[firstLetter]; 147 | strData += tableRomanAndFigure[secondLetter]; 148 | length -= 2; 149 | } 150 | else if (length == 1) 151 | { 152 | intData = this.getNextBits(6); 153 | strData += tableRomanAndFigure[intData]; 154 | length -= 1; 155 | } 156 | } 157 | while (length > 0); 158 | 159 | return strData; 160 | } 161 | this.getFigureString=function( dataLength) 162 | { 163 | var length = dataLength; 164 | var intData = 0; 165 | var strData = ""; 166 | do 167 | { 168 | if (length >= 3) 169 | { 170 | intData = this.getNextBits(10); 171 | if (intData < 100) 172 | strData += "0"; 173 | if (intData < 10) 174 | strData += "0"; 175 | length -= 3; 176 | } 177 | else if (length == 2) 178 | { 179 | intData = this.getNextBits(7); 180 | if (intData < 10) 181 | strData += "0"; 182 | length -= 2; 183 | } 184 | else if (length == 1) 185 | { 186 | intData = this.getNextBits(4); 187 | length -= 1; 188 | } 189 | strData += intData; 190 | } 191 | while (length > 0); 192 | 193 | return strData; 194 | } 195 | this.get8bitByteArray=function( dataLength) 196 | { 197 | var length = dataLength; 198 | var intData = 0; 199 | var output = new Array(); 200 | 201 | do 202 | { 203 | intData = this.getNextBits(8); 204 | output.push( intData); 205 | length--; 206 | } 207 | while (length > 0); 208 | return output; 209 | } 210 | this.getKanjiString=function( dataLength) 211 | { 212 | var length = dataLength; 213 | var intData = 0; 214 | var unicodeString = ""; 215 | do 216 | { 217 | intData = this.getNextBits(13); 218 | var lowerByte = intData % 0xC0; 219 | var higherByte = intData / 0xC0; 220 | 221 | var tempWord = (higherByte << 8) + lowerByte; 222 | var shiftjisWord = 0; 223 | if (tempWord + 0x8140 <= 0x9FFC) 224 | { 225 | // between 8140 - 9FFC on Shift_JIS character set 226 | shiftjisWord = tempWord + 0x8140; 227 | } 228 | else 229 | { 230 | // between E040 - EBBF on Shift_JIS character set 231 | shiftjisWord = tempWord + 0xC140; 232 | } 233 | 234 | //var tempByte = new Array(0,0); 235 | //tempByte[0] = (sbyte) (shiftjisWord >> 8); 236 | //tempByte[1] = (sbyte) (shiftjisWord & 0xFF); 237 | //unicodeString += new String(SystemUtils.ToCharArray(SystemUtils.ToByteArray(tempByte))); 238 | unicodeString += String.fromCharCode(shiftjisWord); 239 | length--; 240 | } 241 | while (length > 0); 242 | 243 | 244 | return unicodeString; 245 | } 246 | 247 | this.parseECIValue = function () 248 | { 249 | var intData = 0; 250 | var firstByte = this.getNextBits(8); 251 | if ((firstByte & 0x80) == 0) { 252 | intData = firstByte & 0x7F; 253 | } 254 | if ((firstByte & 0xC0) == 0x80) { 255 | // two bytes 256 | var secondByte = this.getNextBits(8); 257 | intData = ((firstByte & 0x3F) << 8) | secondByte; 258 | } 259 | if ((firstByte & 0xE0) == 0xC0) { 260 | // three bytes 261 | var secondThirdBytes = this.getNextBits(8);; 262 | intData = ((firstByte & 0x1F) << 16) | secondThirdBytes; 263 | } 264 | return intData; 265 | } 266 | 267 | this.__defineGetter__("DataByte", function() 268 | { 269 | var output = new Array(); 270 | var MODE_NUMBER = 1; 271 | var MODE_ROMAN_AND_NUMBER = 2; 272 | var MODE_8BIT_BYTE = 4; 273 | var MODE_ECI = 7; 274 | var MODE_KANJI = 8; 275 | do 276 | { 277 | var mode = this.NextMode(); 278 | //canvas.println("mode: " + mode); 279 | if (mode == 0) 280 | { 281 | if (output.length > 0) 282 | break; 283 | else 284 | throw "Empty data block"; 285 | } 286 | if (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI && mode != MODE_ECI) 287 | { 288 | throw "Invalid mode: " + mode + " in (block:" + this.blockPointer + " bit:" + this.bitPointer + ")"; 289 | } 290 | 291 | if(mode == MODE_ECI) 292 | { 293 | var temp_sbyteArray3 = this.parseECIValue(); 294 | //output.push(temp_sbyteArray3); 295 | } 296 | else 297 | { 298 | 299 | var dataLength = this.getDataLength(mode); 300 | if (dataLength < 1) 301 | throw "Invalid data length: " + dataLength; 302 | switch (mode) 303 | { 304 | 305 | case MODE_NUMBER: 306 | var temp_str = this.getFigureString(dataLength); 307 | var ta = new Array(temp_str.length); 308 | for(var j=0;j 7) 31 | { 32 | throw "System.ArgumentException"; 33 | } 34 | return DataMask.DATA_MASKS[reference]; 35 | } 36 | 37 | function DataMask000() 38 | { 39 | this.unmaskBitMatrix=function(bits, dimension) 40 | { 41 | for (var i = 0; i < dimension; i++) 42 | { 43 | for (var j = 0; j < dimension; j++) 44 | { 45 | if (this.isMasked(i, j)) 46 | { 47 | bits.flip(j, i); 48 | } 49 | } 50 | } 51 | } 52 | this.isMasked=function( i, j) 53 | { 54 | return ((i + j) & 0x01) == 0; 55 | } 56 | } 57 | 58 | function DataMask001() 59 | { 60 | this.unmaskBitMatrix=function(bits, dimension) 61 | { 62 | for (var i = 0; i < dimension; i++) 63 | { 64 | for (var j = 0; j < dimension; j++) 65 | { 66 | if (this.isMasked(i, j)) 67 | { 68 | bits.flip(j, i); 69 | } 70 | } 71 | } 72 | } 73 | this.isMasked=function( i, j) 74 | { 75 | return (i & 0x01) == 0; 76 | } 77 | } 78 | 79 | function DataMask010() 80 | { 81 | this.unmaskBitMatrix=function(bits, dimension) 82 | { 83 | for (var i = 0; i < dimension; i++) 84 | { 85 | for (var j = 0; j < dimension; j++) 86 | { 87 | if (this.isMasked(i, j)) 88 | { 89 | bits.flip(j, i); 90 | } 91 | } 92 | } 93 | } 94 | this.isMasked=function( i, j) 95 | { 96 | return j % 3 == 0; 97 | } 98 | } 99 | 100 | function DataMask011() 101 | { 102 | this.unmaskBitMatrix=function(bits, dimension) 103 | { 104 | for (var i = 0; i < dimension; i++) 105 | { 106 | for (var j = 0; j < dimension; j++) 107 | { 108 | if (this.isMasked(i, j)) 109 | { 110 | bits.flip(j, i); 111 | } 112 | } 113 | } 114 | } 115 | this.isMasked=function( i, j) 116 | { 117 | return (i + j) % 3 == 0; 118 | } 119 | } 120 | 121 | function DataMask100() 122 | { 123 | this.unmaskBitMatrix=function(bits, dimension) 124 | { 125 | for (var i = 0; i < dimension; i++) 126 | { 127 | for (var j = 0; j < dimension; j++) 128 | { 129 | if (this.isMasked(i, j)) 130 | { 131 | bits.flip(j, i); 132 | } 133 | } 134 | } 135 | } 136 | this.isMasked=function( i, j) 137 | { 138 | return (((URShift(i, 1)) + (j / 3)) & 0x01) == 0; 139 | } 140 | } 141 | 142 | function DataMask101() 143 | { 144 | this.unmaskBitMatrix=function(bits, dimension) 145 | { 146 | for (var i = 0; i < dimension; i++) 147 | { 148 | for (var j = 0; j < dimension; j++) 149 | { 150 | if (this.isMasked(i, j)) 151 | { 152 | bits.flip(j, i); 153 | } 154 | } 155 | } 156 | } 157 | this.isMasked=function( i, j) 158 | { 159 | var temp = i * j; 160 | return (temp & 0x01) + (temp % 3) == 0; 161 | } 162 | } 163 | 164 | function DataMask110() 165 | { 166 | this.unmaskBitMatrix=function(bits, dimension) 167 | { 168 | for (var i = 0; i < dimension; i++) 169 | { 170 | for (var j = 0; j < dimension; j++) 171 | { 172 | if (this.isMasked(i, j)) 173 | { 174 | bits.flip(j, i); 175 | } 176 | } 177 | } 178 | } 179 | this.isMasked=function( i, j) 180 | { 181 | var temp = i * j; 182 | return (((temp & 0x01) + (temp % 3)) & 0x01) == 0; 183 | } 184 | } 185 | function DataMask111() 186 | { 187 | this.unmaskBitMatrix=function(bits, dimension) 188 | { 189 | for (var i = 0; i < dimension; i++) 190 | { 191 | for (var j = 0; j < dimension; j++) 192 | { 193 | if (this.isMasked(i, j)) 194 | { 195 | bits.flip(j, i); 196 | } 197 | } 198 | } 199 | } 200 | this.isMasked=function( i, j) 201 | { 202 | return ((((i + j) & 0x01) + ((i * j) % 3)) & 0x01) == 0; 203 | } 204 | } 205 | 206 | DataMask.DATA_MASKS = new Array(new DataMask000(), new DataMask001(), new DataMask010(), new DataMask011(), new DataMask100(), new DataMask101(), new DataMask110(), new DataMask111()); 207 | 208 | -------------------------------------------------------------------------------- /src/qr/decoder.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | var Decoder={}; 27 | Decoder.rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD); 28 | 29 | Decoder.correctErrors=function( codewordBytes, numDataCodewords) 30 | { 31 | var numCodewords = codewordBytes.length; 32 | // First read into an array of ints 33 | var codewordsInts = new Array(numCodewords); 34 | for (var i = 0; i < numCodewords; i++) 35 | { 36 | codewordsInts[i] = codewordBytes[i] & 0xFF; 37 | } 38 | var numECCodewords = codewordBytes.length - numDataCodewords; 39 | try 40 | { 41 | Decoder.rsDecoder.decode(codewordsInts, numECCodewords); 42 | //var corrector = new ReedSolomon(codewordsInts, numECCodewords); 43 | //corrector.correct(); 44 | } 45 | catch ( rse) 46 | { 47 | throw rse; 48 | } 49 | // Copy back into array of bytes -- only need to worry about the bytes that were data 50 | // We don't care about errors in the error-correction codewords 51 | for (var i = 0; i < numDataCodewords; i++) 52 | { 53 | codewordBytes[i] = codewordsInts[i]; 54 | } 55 | } 56 | 57 | Decoder.decode=function(bits) 58 | { 59 | var parser = new BitMatrixParser(bits); 60 | var version = parser.readVersion(); 61 | var ecLevel = parser.readFormatInformation().ErrorCorrectionLevel; 62 | 63 | // Read codewords 64 | var codewords = parser.readCodewords(); 65 | 66 | // Separate into data blocks 67 | var dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel); 68 | 69 | // Count total number of data bytes 70 | var totalBytes = 0; 71 | for (var i = 0; i < dataBlocks.length; i++) 72 | { 73 | totalBytes += dataBlocks[i].NumDataCodewords; 74 | } 75 | var resultBytes = new Array(totalBytes); 76 | var resultOffset = 0; 77 | 78 | // Error-correct and copy data blocks together into a stream of bytes 79 | for (var j = 0; j < dataBlocks.length; j++) 80 | { 81 | var dataBlock = dataBlocks[j]; 82 | var codewordBytes = dataBlock.Codewords; 83 | var numDataCodewords = dataBlock.NumDataCodewords; 84 | Decoder.correctErrors(codewordBytes, numDataCodewords); 85 | for (var i = 0; i < numDataCodewords; i++) 86 | { 87 | resultBytes[resultOffset++] = codewordBytes[i]; 88 | } 89 | } 90 | 91 | // Decode the contents of that stream of bytes 92 | var reader = new QRCodeDataBlockReader(resultBytes, version.VersionNumber, ecLevel.Bits); 93 | return reader; 94 | //return DecodedBitStreamParser.decode(resultBytes, version, ecLevel); 95 | } 96 | -------------------------------------------------------------------------------- /src/qr/detector.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function PerspectiveTransform( a11, a21, a31, a12, a22, a32, a13, a23, a33) 27 | { 28 | this.a11 = a11; 29 | this.a12 = a12; 30 | this.a13 = a13; 31 | this.a21 = a21; 32 | this.a22 = a22; 33 | this.a23 = a23; 34 | this.a31 = a31; 35 | this.a32 = a32; 36 | this.a33 = a33; 37 | this.transformPoints1=function( points) 38 | { 39 | var max = points.length; 40 | var a11 = this.a11; 41 | var a12 = this.a12; 42 | var a13 = this.a13; 43 | var a21 = this.a21; 44 | var a22 = this.a22; 45 | var a23 = this.a23; 46 | var a31 = this.a31; 47 | var a32 = this.a32; 48 | var a33 = this.a33; 49 | for (var i = 0; i < max; i += 2) 50 | { 51 | var x = points[i]; 52 | var y = points[i + 1]; 53 | var denominator = a13 * x + a23 * y + a33; 54 | points[i] = (a11 * x + a21 * y + a31) / denominator; 55 | points[i + 1] = (a12 * x + a22 * y + a32) / denominator; 56 | } 57 | } 58 | this. transformPoints2=function(xValues, yValues) 59 | { 60 | var n = xValues.length; 61 | for (var i = 0; i < n; i++) 62 | { 63 | var x = xValues[i]; 64 | var y = yValues[i]; 65 | var denominator = this.a13 * x + this.a23 * y + this.a33; 66 | xValues[i] = (this.a11 * x + this.a21 * y + this.a31) / denominator; 67 | yValues[i] = (this.a12 * x + this.a22 * y + this.a32) / denominator; 68 | } 69 | } 70 | 71 | this.buildAdjoint=function() 72 | { 73 | // Adjoint is the transpose of the cofactor matrix: 74 | return new PerspectiveTransform(this.a22 * this.a33 - this.a23 * this.a32, this.a23 * this.a31 - this.a21 * this.a33, this.a21 * this.a32 - this.a22 * this.a31, this.a13 * this.a32 - this.a12 * this.a33, this.a11 * this.a33 - this.a13 * this.a31, this.a12 * this.a31 - this.a11 * this.a32, this.a12 * this.a23 - this.a13 * this.a22, this.a13 * this.a21 - this.a11 * this.a23, this.a11 * this.a22 - this.a12 * this.a21); 75 | } 76 | this.times=function( other) 77 | { 78 | return new PerspectiveTransform(this.a11 * other.a11 + this.a21 * other.a12 + this.a31 * other.a13, this.a11 * other.a21 + this.a21 * other.a22 + this.a31 * other.a23, this.a11 * other.a31 + this.a21 * other.a32 + this.a31 * other.a33, this.a12 * other.a11 + this.a22 * other.a12 + this.a32 * other.a13, this.a12 * other.a21 + this.a22 * other.a22 + this.a32 * other.a23, this.a12 * other.a31 + this.a22 * other.a32 + this.a32 * other.a33, this.a13 * other.a11 + this.a23 * other.a12 +this.a33 * other.a13, this.a13 * other.a21 + this.a23 * other.a22 + this.a33 * other.a23, this.a13 * other.a31 + this.a23 * other.a32 + this.a33 * other.a33); 79 | } 80 | 81 | } 82 | 83 | PerspectiveTransform.quadrilateralToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p) 84 | { 85 | 86 | var qToS = this.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3); 87 | var sToQ = this.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); 88 | return sToQ.times(qToS); 89 | } 90 | 91 | PerspectiveTransform.squareToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3) 92 | { 93 | var dy2 = y3 - y2; 94 | var dy3 = y0 - y1 + y2 - y3; 95 | if (dy2 == 0.0 && dy3 == 0.0) 96 | { 97 | return new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0, 0.0, 1.0); 98 | } 99 | else 100 | { 101 | var dx1 = x1 - x2; 102 | var dx2 = x3 - x2; 103 | var dx3 = x0 - x1 + x2 - x3; 104 | var dy1 = y1 - y2; 105 | var denominator = dx1 * dy2 - dx2 * dy1; 106 | var a13 = (dx3 * dy2 - dx2 * dy3) / denominator; 107 | var a23 = (dx1 * dy3 - dx3 * dy1) / denominator; 108 | return new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0); 109 | } 110 | } 111 | 112 | PerspectiveTransform.quadrilateralToSquare=function( x0, y0, x1, y1, x2, y2, x3, y3) 113 | { 114 | // Here, the adjoint serves as the inverse: 115 | return this.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint(); 116 | } 117 | 118 | function DetectorResult(bits, points) 119 | { 120 | this.bits = bits; 121 | this.points = points; 122 | } 123 | 124 | 125 | function Detector(image) 126 | { 127 | this.image=image; 128 | this.resultPointCallback = null; 129 | 130 | this.sizeOfBlackWhiteBlackRun=function( fromX, fromY, toX, toY) 131 | { 132 | // Mild variant of Bresenham's algorithm; 133 | // see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm 134 | var steep = Math.abs(toY - fromY) > Math.abs(toX - fromX); 135 | if (steep) 136 | { 137 | var temp = fromX; 138 | fromX = fromY; 139 | fromY = temp; 140 | temp = toX; 141 | toX = toY; 142 | toY = temp; 143 | } 144 | 145 | var dx = Math.abs(toX - fromX); 146 | var dy = Math.abs(toY - fromY); 147 | var error = - dx >> 1; 148 | var ystep = fromY < toY?1:- 1; 149 | var xstep = fromX < toX?1:- 1; 150 | var state = 0; // In black pixels, looking for white, first or second time 151 | for (var x = fromX, y = fromY; x != toX; x += xstep) 152 | { 153 | 154 | var realX = steep?y:x; 155 | var realY = steep?x:y; 156 | if (state == 1) 157 | { 158 | // In white pixels, looking for black 159 | if (this.image[realX + realY*qrcode.width]) 160 | { 161 | state++; 162 | } 163 | } 164 | else 165 | { 166 | if (!this.image[realX + realY*qrcode.width]) 167 | { 168 | state++; 169 | } 170 | } 171 | 172 | if (state == 3) 173 | { 174 | // Found black, white, black, and stumbled back onto white; done 175 | var diffX = x - fromX; 176 | var diffY = y - fromY; 177 | return Math.sqrt( (diffX * diffX + diffY * diffY)); 178 | } 179 | error += dy; 180 | if (error > 0) 181 | { 182 | if (y == toY) 183 | { 184 | break; 185 | } 186 | y += ystep; 187 | error -= dx; 188 | } 189 | } 190 | var diffX2 = toX - fromX; 191 | var diffY2 = toY - fromY; 192 | return Math.sqrt( (diffX2 * diffX2 + diffY2 * diffY2)); 193 | } 194 | 195 | 196 | this.sizeOfBlackWhiteBlackRunBothWays=function( fromX, fromY, toX, toY) 197 | { 198 | 199 | var result = this.sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); 200 | 201 | // Now count other way -- don't run off image though of course 202 | var scale = 1.0; 203 | var otherToX = fromX - (toX - fromX); 204 | if (otherToX < 0) 205 | { 206 | scale = fromX / (fromX - otherToX); 207 | otherToX = 0; 208 | } 209 | else if (otherToX >= qrcode.width) 210 | { 211 | scale = (qrcode.width - 1 - fromX) / (otherToX - fromX); 212 | otherToX = qrcode.width - 1; 213 | } 214 | var otherToY = Math.floor (fromY - (toY - fromY) * scale); 215 | 216 | scale = 1.0; 217 | if (otherToY < 0) 218 | { 219 | scale = fromY / (fromY - otherToY); 220 | otherToY = 0; 221 | } 222 | else if (otherToY >= qrcode.height) 223 | { 224 | scale = (qrcode.height - 1 - fromY) / (otherToY - fromY); 225 | otherToY = qrcode.height - 1; 226 | } 227 | otherToX = Math.floor (fromX + (otherToX - fromX) * scale); 228 | 229 | result += this.sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY); 230 | return result - 1.0; // -1 because we counted the middle pixel twice 231 | } 232 | 233 | 234 | 235 | this.calculateModuleSizeOneWay=function( pattern, otherPattern) 236 | { 237 | var moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor( pattern.X), Math.floor( pattern.Y), Math.floor( otherPattern.X), Math.floor(otherPattern.Y)); 238 | var moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.X), Math.floor(otherPattern.Y), Math.floor( pattern.X), Math.floor(pattern.Y)); 239 | if (isNaN(moduleSizeEst1)) 240 | { 241 | return moduleSizeEst2 / 7.0; 242 | } 243 | if (isNaN(moduleSizeEst2)) 244 | { 245 | return moduleSizeEst1 / 7.0; 246 | } 247 | // Average them, and divide by 7 since we've counted the width of 3 black modules, 248 | // and 1 white and 1 black module on either side. Ergo, divide sum by 14. 249 | return (moduleSizeEst1 + moduleSizeEst2) / 14.0; 250 | } 251 | 252 | 253 | this.calculateModuleSize=function( topLeft, topRight, bottomLeft) 254 | { 255 | // Take the average 256 | return (this.calculateModuleSizeOneWay(topLeft, topRight) + this.calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0; 257 | } 258 | 259 | this.distance=function( pattern1, pattern2) 260 | { 261 | var xDiff = pattern1.X - pattern2.X; 262 | var yDiff = pattern1.Y - pattern2.Y; 263 | return Math.sqrt( (xDiff * xDiff + yDiff * yDiff)); 264 | } 265 | this.computeDimension=function( topLeft, topRight, bottomLeft, moduleSize) 266 | { 267 | 268 | var tltrCentersDimension = Math.round(this.distance(topLeft, topRight) / moduleSize); 269 | var tlblCentersDimension = Math.round(this.distance(topLeft, bottomLeft) / moduleSize); 270 | var dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7; 271 | switch (dimension & 0x03) 272 | { 273 | 274 | // mod 4 275 | case 0: 276 | dimension++; 277 | break; 278 | // 1? do nothing 279 | 280 | case 2: 281 | dimension--; 282 | break; 283 | 284 | case 3: 285 | throw "Error"; 286 | } 287 | return dimension; 288 | } 289 | 290 | this.findAlignmentInRegion=function( overallEstModuleSize, estAlignmentX, estAlignmentY, allowanceFactor) 291 | { 292 | // Look for an alignment pattern (3 modules in size) around where it 293 | // should be 294 | var allowance = Math.floor (allowanceFactor * overallEstModuleSize); 295 | var alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance); 296 | var alignmentAreaRightX = Math.min(qrcode.width - 1, estAlignmentX + allowance); 297 | if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) 298 | { 299 | throw "Error"; 300 | } 301 | 302 | var alignmentAreaTopY = Math.max(0, estAlignmentY - allowance); 303 | var alignmentAreaBottomY = Math.min(qrcode.height - 1, estAlignmentY + allowance); 304 | 305 | var alignmentFinder = new AlignmentPatternFinder(this.image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, this.resultPointCallback); 306 | return alignmentFinder.find(); 307 | } 308 | 309 | this.createTransform=function( topLeft, topRight, bottomLeft, alignmentPattern, dimension) 310 | { 311 | var dimMinusThree = dimension - 3.5; 312 | var bottomRightX; 313 | var bottomRightY; 314 | var sourceBottomRightX; 315 | var sourceBottomRightY; 316 | if (alignmentPattern != null) 317 | { 318 | bottomRightX = alignmentPattern.X; 319 | bottomRightY = alignmentPattern.Y; 320 | sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0; 321 | } 322 | else 323 | { 324 | // Don't have an alignment pattern, just make up the bottom-right point 325 | bottomRightX = (topRight.X - topLeft.X) + bottomLeft.X; 326 | bottomRightY = (topRight.Y - topLeft.Y) + bottomLeft.Y; 327 | sourceBottomRightX = sourceBottomRightY = dimMinusThree; 328 | } 329 | 330 | var transform = PerspectiveTransform.quadrilateralToQuadrilateral(3.5, 3.5, dimMinusThree, 3.5, sourceBottomRightX, sourceBottomRightY, 3.5, dimMinusThree, topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomRightX, bottomRightY, bottomLeft.X, bottomLeft.Y); 331 | 332 | return transform; 333 | } 334 | 335 | this.sampleGrid=function( image, transform, dimension) 336 | { 337 | 338 | var sampler = GridSampler; 339 | return sampler.sampleGrid3(image, dimension, transform); 340 | } 341 | 342 | this.processFinderPatternInfo = function( info) 343 | { 344 | 345 | var topLeft = info.TopLeft; 346 | var topRight = info.TopRight; 347 | var bottomLeft = info.BottomLeft; 348 | 349 | var moduleSize = this.calculateModuleSize(topLeft, topRight, bottomLeft); 350 | if (moduleSize < 1.0) 351 | { 352 | throw "Error"; 353 | } 354 | var dimension = this.computeDimension(topLeft, topRight, bottomLeft, moduleSize); 355 | var provisionalVersion = Version.getProvisionalVersionForDimension(dimension); 356 | var modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7; 357 | 358 | var alignmentPattern = null; 359 | // Anything above version 1 has an alignment pattern 360 | if (provisionalVersion.AlignmentPatternCenters.length > 0) 361 | { 362 | 363 | // Guess where a "bottom right" finder pattern would have been 364 | var bottomRightX = topRight.X - topLeft.X + bottomLeft.X; 365 | var bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y; 366 | 367 | // Estimate that alignment pattern is closer by 3 modules 368 | // from "bottom right" to known top left location 369 | var correctionToTopLeft = 1.0 - 3.0 / modulesBetweenFPCenters; 370 | var estAlignmentX = Math.floor (topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X)); 371 | var estAlignmentY = Math.floor (topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y)); 372 | 373 | // Kind of arbitrary -- expand search radius before giving up 374 | for (var i = 4; i <= 16; i <<= 1) 375 | { 376 | //try 377 | //{ 378 | alignmentPattern = this.findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, i); 379 | break; 380 | //} 381 | //catch (re) 382 | //{ 383 | // try next round 384 | //} 385 | } 386 | // If we didn't find alignment pattern... well try anyway without it 387 | } 388 | 389 | var transform = this.createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension); 390 | 391 | var bits = this.sampleGrid(this.image, transform, dimension); 392 | 393 | var points; 394 | if (alignmentPattern == null) 395 | { 396 | points = new Array(bottomLeft, topLeft, topRight); 397 | } 398 | else 399 | { 400 | points = new Array(bottomLeft, topLeft, topRight, alignmentPattern); 401 | } 402 | return new DetectorResult(bits, points); 403 | } 404 | 405 | 406 | 407 | this.detect=function() 408 | { 409 | var info = new FinderPatternFinder().findFinderPattern(this.image); 410 | 411 | return this.processFinderPatternInfo(info); 412 | } 413 | } -------------------------------------------------------------------------------- /src/qr/errorlevel.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function ErrorCorrectionLevel(ordinal, bits, name) 27 | { 28 | this.ordinal_Renamed_Field = ordinal; 29 | this.bits = bits; 30 | this.name = name; 31 | this.__defineGetter__("Bits", function() 32 | { 33 | return this.bits; 34 | }); 35 | this.__defineGetter__("Name", function() 36 | { 37 | return this.name; 38 | }); 39 | this.ordinal=function() 40 | { 41 | return this.ordinal_Renamed_Field; 42 | } 43 | } 44 | 45 | ErrorCorrectionLevel.forBits=function( bits) 46 | { 47 | if (bits < 0 || bits >= FOR_BITS.length) 48 | { 49 | throw "ArgumentException"; 50 | } 51 | return FOR_BITS[bits]; 52 | } 53 | 54 | var L = new ErrorCorrectionLevel(0, 0x01, "L"); 55 | var M = new ErrorCorrectionLevel(1, 0x00, "M"); 56 | var Q = new ErrorCorrectionLevel(2, 0x03, "Q"); 57 | var H = new ErrorCorrectionLevel(3, 0x02, "H"); 58 | var FOR_BITS = new Array( M, L, H, Q); -------------------------------------------------------------------------------- /src/qr/formatinf.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | var FORMAT_INFO_MASK_QR = 0x5412; 27 | var FORMAT_INFO_DECODE_LOOKUP = new Array(new Array(0x5412, 0x00), new Array(0x5125, 0x01), new Array(0x5E7C, 0x02), new Array(0x5B4B, 0x03), new Array(0x45F9, 0x04), new Array(0x40CE, 0x05), new Array(0x4F97, 0x06), new Array(0x4AA0, 0x07), new Array(0x77C4, 0x08), new Array(0x72F3, 0x09), new Array(0x7DAA, 0x0A), new Array(0x789D, 0x0B), new Array(0x662F, 0x0C), new Array(0x6318, 0x0D), new Array(0x6C41, 0x0E), new Array(0x6976, 0x0F), new Array(0x1689, 0x10), new Array(0x13BE, 0x11), new Array(0x1CE7, 0x12), new Array(0x19D0, 0x13), new Array(0x0762, 0x14), new Array(0x0255, 0x15), new Array(0x0D0C, 0x16), new Array(0x083B, 0x17), new Array(0x355F, 0x18), new Array(0x3068, 0x19), new Array(0x3F31, 0x1A), new Array(0x3A06, 0x1B), new Array(0x24B4, 0x1C), new Array(0x2183, 0x1D), new Array(0x2EDA, 0x1E), new Array(0x2BED, 0x1F)); 28 | var BITS_SET_IN_HALF_BYTE = new Array(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4); 29 | 30 | 31 | function FormatInformation(formatInfo) 32 | { 33 | this.errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03); 34 | this.dataMask = (formatInfo & 0x07); 35 | 36 | this.__defineGetter__("ErrorCorrectionLevel", function() 37 | { 38 | return this.errorCorrectionLevel; 39 | }); 40 | this.__defineGetter__("DataMask", function() 41 | { 42 | return this.dataMask; 43 | }); 44 | this.GetHashCode=function() 45 | { 46 | return (this.errorCorrectionLevel.ordinal() << 3) | this.dataMask; 47 | } 48 | this.Equals=function( o) 49 | { 50 | var other = o; 51 | return this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask; 52 | } 53 | } 54 | 55 | FormatInformation.numBitsDiffering=function( a, b) 56 | { 57 | a ^= b; // a now has a 1 bit exactly where its bit differs with b's 58 | // Count bits set quickly with a series of lookups: 59 | return BITS_SET_IN_HALF_BYTE[a & 0x0F] + BITS_SET_IN_HALF_BYTE[(URShift(a, 4) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 8) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 12) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 16) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 20) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 24) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 28) & 0x0F)]; 60 | } 61 | 62 | FormatInformation.decodeFormatInformation=function( maskedFormatInfo) 63 | { 64 | var formatInfo = FormatInformation.doDecodeFormatInformation(maskedFormatInfo); 65 | if (formatInfo != null) 66 | { 67 | return formatInfo; 68 | } 69 | // Should return null, but, some QR codes apparently 70 | // do not mask this info. Try again by actually masking the pattern 71 | // first 72 | return FormatInformation.doDecodeFormatInformation(maskedFormatInfo ^ FORMAT_INFO_MASK_QR); 73 | } 74 | FormatInformation.doDecodeFormatInformation=function( maskedFormatInfo) 75 | { 76 | // Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing 77 | var bestDifference = 0xffffffff; 78 | var bestFormatInfo = 0; 79 | for (var i = 0; i < FORMAT_INFO_DECODE_LOOKUP.length; i++) 80 | { 81 | var decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i]; 82 | var targetInfo = decodeInfo[0]; 83 | if (targetInfo == maskedFormatInfo) 84 | { 85 | // Found an exact match 86 | return new FormatInformation(decodeInfo[1]); 87 | } 88 | var bitsDifference = this.numBitsDiffering(maskedFormatInfo, targetInfo); 89 | if (bitsDifference < bestDifference) 90 | { 91 | bestFormatInfo = decodeInfo[1]; 92 | bestDifference = bitsDifference; 93 | } 94 | } 95 | // Hamming distance of the 32 masked codes is 7, by construction, so <= 3 bits 96 | // differing means we found a match 97 | if (bestDifference <= 3) 98 | { 99 | return new FormatInformation(bestFormatInfo); 100 | } 101 | return null; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /src/qr/gf256.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function GF256( primitive) 27 | { 28 | this.expTable = new Array(256); 29 | this.logTable = new Array(256); 30 | var x = 1; 31 | for (var i = 0; i < 256; i++) 32 | { 33 | this.expTable[i] = x; 34 | x <<= 1; // x = x * 2; we're assuming the generator alpha is 2 35 | if (x >= 0x100) 36 | { 37 | x ^= primitive; 38 | } 39 | } 40 | for (var i = 0; i < 255; i++) 41 | { 42 | this.logTable[this.expTable[i]] = i; 43 | } 44 | // logTable[0] == 0 but this should never be used 45 | var at0=new Array(1);at0[0]=0; 46 | this.zero = new GF256Poly(this, new Array(at0)); 47 | var at1=new Array(1);at1[0]=1; 48 | this.one = new GF256Poly(this, new Array(at1)); 49 | 50 | this.__defineGetter__("Zero", function() 51 | { 52 | return this.zero; 53 | }); 54 | this.__defineGetter__("One", function() 55 | { 56 | return this.one; 57 | }); 58 | this.buildMonomial=function( degree, coefficient) 59 | { 60 | if (degree < 0) 61 | { 62 | throw "System.ArgumentException"; 63 | } 64 | if (coefficient == 0) 65 | { 66 | return this.zero; 67 | } 68 | var coefficients = new Array(degree + 1); 69 | for(var i=0;i 1 && coefficients[0] == 0) 35 | { 36 | // Leading term must be non-zero for anything except the constant polynomial "0" 37 | var firstNonZero = 1; 38 | while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0) 39 | { 40 | firstNonZero++; 41 | } 42 | if (firstNonZero == coefficientsLength) 43 | { 44 | this.coefficients = field.Zero.coefficients; 45 | } 46 | else 47 | { 48 | this.coefficients = new Array(coefficientsLength - firstNonZero); 49 | for(var i=0;i largerCoefficients.length) 121 | { 122 | var temp = smallerCoefficients; 123 | smallerCoefficients = largerCoefficients; 124 | largerCoefficients = temp; 125 | } 126 | var sumDiff = new Array(largerCoefficients.length); 127 | var lengthDiff = largerCoefficients.length - smallerCoefficients.length; 128 | // Copy high-order terms only found in higher-degree polynomial's coefficients 129 | //Array.Copy(largerCoefficients, 0, sumDiff, 0, lengthDiff); 130 | for(var ci=0;ci= other.Degree && !remainder.Zero) 219 | { 220 | var degreeDifference = remainder.Degree - other.Degree; 221 | var scale = this.field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm); 222 | var term = other.multiplyByMonomial(degreeDifference, scale); 223 | var iterationQuotient = this.field.buildMonomial(degreeDifference, scale); 224 | quotient = quotient.addOrSubtract(iterationQuotient); 225 | remainder = remainder.addOrSubtract(term); 226 | } 227 | 228 | return new Array(quotient, remainder); 229 | } 230 | } -------------------------------------------------------------------------------- /src/qr/grid.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | var GridSampler = {}; 27 | 28 | GridSampler.checkAndNudgePoints=function( image, points) 29 | { 30 | var width = qrcode.width; 31 | var height = qrcode.height; 32 | // Check and nudge points from start until we see some that are OK: 33 | var nudged = true; 34 | for (var offset = 0; offset < points.length && nudged; offset += 2) 35 | { 36 | var x = Math.floor (points[offset]); 37 | var y = Math.floor( points[offset + 1]); 38 | if (x < - 1 || x > width || y < - 1 || y > height) 39 | { 40 | throw "Error.checkAndNudgePoints "; 41 | } 42 | nudged = false; 43 | if (x == - 1) 44 | { 45 | points[offset] = 0.0; 46 | nudged = true; 47 | } 48 | else if (x == width) 49 | { 50 | points[offset] = width - 1; 51 | nudged = true; 52 | } 53 | if (y == - 1) 54 | { 55 | points[offset + 1] = 0.0; 56 | nudged = true; 57 | } 58 | else if (y == height) 59 | { 60 | points[offset + 1] = height - 1; 61 | nudged = true; 62 | } 63 | } 64 | // Check and nudge points from end: 65 | nudged = true; 66 | for (var offset = points.length - 2; offset >= 0 && nudged; offset -= 2) 67 | { 68 | var x = Math.floor( points[offset]); 69 | var y = Math.floor( points[offset + 1]); 70 | if (x < - 1 || x > width || y < - 1 || y > height) 71 | { 72 | throw "Error.checkAndNudgePoints "; 73 | } 74 | nudged = false; 75 | if (x == - 1) 76 | { 77 | points[offset] = 0.0; 78 | nudged = true; 79 | } 80 | else if (x == width) 81 | { 82 | points[offset] = width - 1; 83 | nudged = true; 84 | } 85 | if (y == - 1) 86 | { 87 | points[offset + 1] = 0.0; 88 | nudged = true; 89 | } 90 | else if (y == height) 91 | { 92 | points[offset + 1] = height - 1; 93 | nudged = true; 94 | } 95 | } 96 | } 97 | 98 | 99 | 100 | GridSampler.sampleGrid3=function( image, dimension, transform) 101 | { 102 | var bits = new BitMatrix(dimension); 103 | var points = new Array(dimension << 1); 104 | for (var y = 0; y < dimension; y++) 105 | { 106 | var max = points.length; 107 | var iValue = y + 0.5; 108 | for (var x = 0; x < max; x += 2) 109 | { 110 | points[x] = (x >> 1) + 0.5; 111 | points[x + 1] = iValue; 112 | } 113 | transform.transformPoints1(points); 114 | // Quick check to see if points transformed to something inside the image; 115 | // sufficient to check the endpoints 116 | GridSampler.checkAndNudgePoints(image, points); 117 | try 118 | { 119 | for (var x = 0; x < max; x += 2) 120 | { 121 | //var xpoint = (Math.floor( points[x]) * 4) + (Math.floor( points[x + 1]) * qrcode.width * 4); 122 | var bit = image[Math.floor( points[x])+ qrcode.width* Math.floor( points[x + 1])]; 123 | //qrcode.imagedata.data[xpoint] = bit?255:0; 124 | //qrcode.imagedata.data[xpoint+1] = bit?255:0; 125 | //qrcode.imagedata.data[xpoint+2] = 0; 126 | //qrcode.imagedata.data[xpoint+3] = 255; 127 | //bits[x >> 1][ y]=bit; 128 | if(bit) 129 | bits.set_Renamed(x >> 1, y); 130 | } 131 | } 132 | catch ( aioobe) 133 | { 134 | // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting 135 | // transform gets "twisted" such that it maps a straight line of points to a set of points 136 | // whose endpoints are in bounds, but others are not. There is probably some mathematical 137 | // way to detect this about the transformation that I don't know yet. 138 | // This results in an ugly runtime exception despite our clever checks above -- can't have 139 | // that. We could check each point's coordinates but that feels duplicative. We settle for 140 | // catching and wrapping ArrayIndexOutOfBoundsException. 141 | throw "Error.checkAndNudgePoints"; 142 | } 143 | } 144 | return bits; 145 | } 146 | 147 | GridSampler.sampleGridx=function( image, dimension, p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY) 148 | { 149 | var transform = PerspectiveTransform.quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY); 150 | 151 | return GridSampler.sampleGrid3(image, dimension, transform); 152 | } -------------------------------------------------------------------------------- /src/qr/qrcode.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Lazar Laszlo (lazarsoft@gmail.com, www.lazarsoft.info) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | var qrcode = {}; 19 | qrcode.imagedata = null; 20 | qrcode.width = 0; 21 | qrcode.height = 0; 22 | qrcode.qrCodeSymbol = null; 23 | qrcode.debug = false; 24 | qrcode.maxImgSize = 1024*1024; 25 | 26 | qrcode.sizeOfDataLengthInfo = [ [ 10, 9, 8, 8 ], [ 12, 11, 16, 10 ], [ 14, 13, 16, 12 ] ]; 27 | 28 | qrcode.callback = null; 29 | 30 | qrcode.vidSuccess = function (stream) 31 | { 32 | qrcode.localstream = stream; 33 | if(qrcode.webkit) 34 | qrcode.video.src = window.webkitURL.createObjectURL(stream); 35 | else 36 | if(qrcode.moz) 37 | { 38 | qrcode.video.mozSrcObject = stream; 39 | qrcode.video.play(); 40 | } 41 | else 42 | qrcode.video.src = stream; 43 | 44 | qrcode.gUM=true; 45 | 46 | qrcode.canvas_qr2 = document.createElement('canvas'); 47 | qrcode.canvas_qr2.id = "qr-canvas"; 48 | qrcode.qrcontext2 = qrcode.canvas_qr2.getContext('2d'); 49 | qrcode.canvas_qr2.width = qrcode.video.videoWidth; 50 | qrcode.canvas_qr2.height = qrcode.video.videoHeight; 51 | setTimeout(qrcode.captureToCanvas, 500); 52 | } 53 | 54 | qrcode.vidError = function(error) 55 | { 56 | qrcode.gUM=false; 57 | return; 58 | } 59 | 60 | qrcode.captureToCanvas = function() 61 | { 62 | if(qrcode.gUM) 63 | { 64 | try{ 65 | if(qrcode.video.videoWidth == 0) 66 | { 67 | setTimeout(qrcode.captureToCanvas, 500); 68 | return; 69 | } 70 | else 71 | { 72 | qrcode.canvas_qr2.width = qrcode.video.videoWidth; 73 | qrcode.canvas_qr2.height = qrcode.video.videoHeight; 74 | } 75 | qrcode.qrcontext2.drawImage(qrcode.video,0,0); 76 | try{ 77 | qrcode.decode(); 78 | } 79 | catch(e){ 80 | console.log(e); 81 | setTimeout(qrcode.captureToCanvas, 500); 82 | }; 83 | } 84 | catch(e){ 85 | console.log(e); 86 | setTimeout(qrcode.captureToCanvas, 500); 87 | }; 88 | } 89 | } 90 | 91 | qrcode.setWebcam = function(videoId) 92 | { 93 | var n=navigator; 94 | qrcode.video=document.getElementById(videoId); 95 | 96 | var options = true; 97 | if(navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) 98 | { 99 | try{ 100 | navigator.mediaDevices.enumerateDevices() 101 | .then(function(devices) { 102 | devices.forEach(function(device) { 103 | console.log("deb1"); 104 | if (device.kind === 'videoinput') { 105 | if(device.label.toLowerCase().search("back") >-1) 106 | options=[{'sourceId': device.deviceId}] ; 107 | } 108 | console.log(device.kind + ": " + device.label + 109 | " id = " + device.deviceId); 110 | }); 111 | }) 112 | 113 | } 114 | catch(e) 115 | { 116 | console.log(e); 117 | } 118 | } 119 | else{ 120 | console.log("no navigator.mediaDevices.enumerateDevices" ); 121 | } 122 | 123 | if(n.getUserMedia) 124 | n.getUserMedia({video: options, audio: false}, qrcode.vidSuccess, qrcode.vidError); 125 | else 126 | if(n.webkitGetUserMedia) 127 | { 128 | qrcode.webkit=true; 129 | n.webkitGetUserMedia({video:options, audio: false}, qrcode.vidSuccess, qrcode.vidError); 130 | } 131 | else 132 | if(n.mozGetUserMedia) 133 | { 134 | qrcode.moz=true; 135 | n.mozGetUserMedia({video: options, audio: false}, qrcode.vidSuccess, qrcode.vidError); 136 | } 137 | } 138 | 139 | qrcode.decode = function(src){ 140 | 141 | if(arguments.length==0) 142 | { 143 | if(qrcode.canvas_qr2) 144 | { 145 | var canvas_qr = qrcode.canvas_qr2; 146 | var context = qrcode.qrcontext2; 147 | } 148 | else 149 | { 150 | var canvas_qr = document.getElementById("qr-canvas"); 151 | var context = canvas_qr.getContext('2d'); 152 | } 153 | qrcode.width = canvas_qr.width; 154 | qrcode.height = canvas_qr.height; 155 | qrcode.imagedata = context.getImageData(0, 0, qrcode.width, qrcode.height); 156 | qrcode.result = qrcode.process(context); 157 | if(qrcode.callback!=null) 158 | qrcode.callback(qrcode.result); 159 | return qrcode.result; 160 | } 161 | else 162 | { 163 | var image = new Image(); 164 | image.crossOrigin = "Anonymous"; 165 | image.onload=function(){ 166 | //var canvas_qr = document.getElementById("qr-canvas"); 167 | var canvas_out = document.getElementById("out-canvas"); 168 | if(canvas_out!=null) 169 | { 170 | var outctx = canvas_out.getContext('2d'); 171 | outctx.clearRect(0, 0, 320, 240); 172 | outctx.drawImage(image, 0, 0, 320, 240); 173 | } 174 | 175 | var canvas_qr = document.createElement('canvas'); 176 | var context = canvas_qr.getContext('2d'); 177 | var nheight = image.height; 178 | var nwidth = image.width; 179 | if(image.width*image.height>qrcode.maxImgSize) 180 | { 181 | var ir = image.width / image.height; 182 | nheight = Math.sqrt(qrcode.maxImgSize/ir); 183 | nwidth=ir*nheight; 184 | } 185 | 186 | canvas_qr.width = nwidth; 187 | canvas_qr.height = nheight; 188 | 189 | context.drawImage(image, 0, 0, canvas_qr.width, canvas_qr.height ); 190 | qrcode.width = canvas_qr.width; 191 | qrcode.height = canvas_qr.height; 192 | try{ 193 | qrcode.imagedata = context.getImageData(0, 0, canvas_qr.width, canvas_qr.height); 194 | }catch(e){ 195 | qrcode.result = "Cross domain image reading not supported in your browser! Save it to your computer then drag and drop the file!"; 196 | if(qrcode.callback!=null) 197 | qrcode.callback(qrcode.result); 198 | return; 199 | } 200 | 201 | try 202 | { 203 | qrcode.result = qrcode.process(context); 204 | } 205 | catch(e) 206 | { 207 | console.log(e); 208 | qrcode.result = "error decoding QR Code"; 209 | } 210 | if(qrcode.callback!=null) 211 | qrcode.callback(qrcode.result); 212 | } 213 | image.onerror = function () 214 | { 215 | if(qrcode.callback!=null) 216 | qrcode.callback("Failed to load the image"); 217 | } 218 | image.src = src; 219 | } 220 | } 221 | 222 | qrcode.isUrl = function(s) 223 | { 224 | var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; 225 | return regexp.test(s); 226 | } 227 | 228 | qrcode.decode_url = function (s) 229 | { 230 | var escaped = ""; 231 | try{ 232 | escaped = escape( s ); 233 | } 234 | catch(e) 235 | { 236 | console.log(e); 237 | escaped = s; 238 | } 239 | var ret = ""; 240 | try{ 241 | ret = decodeURIComponent( escaped ); 242 | } 243 | catch(e) 244 | { 245 | console.log(e); 246 | ret = escaped; 247 | } 248 | return ret; 249 | } 250 | 251 | qrcode.decode_utf8 = function ( s ) 252 | { 253 | if(qrcode.isUrl(s)) 254 | return qrcode.decode_url(s); 255 | else 256 | return s; 257 | } 258 | 259 | qrcode.process = function(ctx){ 260 | 261 | var start = new Date().getTime(); 262 | 263 | var image = qrcode.grayScaleToBitmap(qrcode.grayscale()); 264 | //var image = qrcode.binarize(128); 265 | 266 | if(qrcode.debug) 267 | { 268 | for (var y = 0; y < qrcode.height; y++) 269 | { 270 | for (var x = 0; x < qrcode.width; x++) 271 | { 272 | var point = (x * 4) + (y * qrcode.width * 4); 273 | qrcode.imagedata.data[point] = image[x+y*qrcode.width]?0:0; 274 | qrcode.imagedata.data[point+1] = image[x+y*qrcode.width]?0:0; 275 | qrcode.imagedata.data[point+2] = image[x+y*qrcode.width]?255:0; 276 | } 277 | } 278 | ctx.putImageData(qrcode.imagedata, 0, 0); 279 | } 280 | 281 | //var finderPatternInfo = new FinderPatternFinder().findFinderPattern(image); 282 | 283 | var detector = new Detector(image); 284 | 285 | var qRCodeMatrix = detector.detect(); 286 | 287 | if(qrcode.debug) 288 | { 289 | for (var y = 0; y < qRCodeMatrix.bits.Height; y++) 290 | { 291 | for (var x = 0; x < qRCodeMatrix.bits.Width; x++) 292 | { 293 | var point = (x * 4*2) + (y*2 * qrcode.width * 4); 294 | qrcode.imagedata.data[point] = qRCodeMatrix.bits.get_Renamed(x,y)?0:0; 295 | qrcode.imagedata.data[point+1] = qRCodeMatrix.bits.get_Renamed(x,y)?0:0; 296 | qrcode.imagedata.data[point+2] = qRCodeMatrix.bits.get_Renamed(x,y)?255:0; 297 | } 298 | } 299 | ctx.putImageData(qrcode.imagedata, 0, 0); 300 | } 301 | 302 | 303 | var reader = Decoder.decode(qRCodeMatrix.bits); 304 | var data = reader.DataByte; 305 | var str=""; 306 | for(var i=0;i minmax[ax][ay][1]) 374 | minmax[ax][ay][1] = target; 375 | } 376 | } 377 | //minmax[ax][ay][0] = (minmax[ax][ay][0] + minmax[ax][ay][1]) / 2; 378 | } 379 | } 380 | var middle = new Array(numSqrtArea); 381 | for (var i3 = 0; i3 < numSqrtArea; i3++) 382 | { 383 | middle[i3] = new Array(numSqrtArea); 384 | } 385 | for (var ay = 0; ay < numSqrtArea; ay++) 386 | { 387 | for (var ax = 0; ax < numSqrtArea; ax++) 388 | { 389 | middle[ax][ay] = Math.floor((minmax[ax][ay][0] + minmax[ax][ay][1]) / 2); 390 | //Console.out.print(middle[ax][ay] + ","); 391 | } 392 | //Console.out.println(""); 393 | } 394 | //Console.out.println(""); 395 | 396 | return middle; 397 | } 398 | 399 | qrcode.grayScaleToBitmap=function(grayScale) 400 | { 401 | var middle = qrcode.getMiddleBrightnessPerArea(grayScale); 402 | var sqrtNumArea = middle.length; 403 | var areaWidth = Math.floor(qrcode.width / sqrtNumArea); 404 | var areaHeight = Math.floor(qrcode.height / sqrtNumArea); 405 | 406 | var buff = new ArrayBuffer(qrcode.width*qrcode.height); 407 | var bitmap = new Uint8Array(buff); 408 | 409 | //var bitmap = new Array(qrcode.height*qrcode.width); 410 | 411 | for (var ay = 0; ay < sqrtNumArea; ay++) 412 | { 413 | for (var ax = 0; ax < sqrtNumArea; ax++) 414 | { 415 | for (var dy = 0; dy < areaHeight; dy++) 416 | { 417 | for (var dx = 0; dx < areaWidth; dx++) 418 | { 419 | bitmap[areaWidth * ax + dx+ (areaHeight * ay + dy)*qrcode.width] = (grayScale[areaWidth * ax + dx+ (areaHeight * ay + dy)*qrcode.width] < middle[ax][ay])?true:false; 420 | } 421 | } 422 | } 423 | } 424 | return bitmap; 425 | } 426 | 427 | qrcode.grayscale = function() 428 | { 429 | var buff = new ArrayBuffer(qrcode.width*qrcode.height); 430 | var ret = new Uint8Array(buff); 431 | //var ret = new Array(qrcode.width*qrcode.height); 432 | 433 | for (var y = 0; y < qrcode.height; y++) 434 | { 435 | for (var x = 0; x < qrcode.width; x++) 436 | { 437 | var gray = qrcode.getPixel(x, y); 438 | 439 | ret[x+y*qrcode.width] = gray; 440 | } 441 | } 442 | return ret; 443 | } 444 | 445 | 446 | 447 | 448 | function URShift( number, bits) 449 | { 450 | if (number >= 0) 451 | return number >> bits; 452 | else 453 | return (number >> bits) + (2 << ~bits); 454 | } 455 | 456 | -------------------------------------------------------------------------------- /src/qr/rsdecoder.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | function ReedSolomonDecoder(field) 27 | { 28 | this.field = field; 29 | this.decode=function(received, twoS) 30 | { 31 | var poly = new GF256Poly(this.field, received); 32 | var syndromeCoefficients = new Array(twoS); 33 | for(var i=0;i= b's 70 | if (a.Degree < b.Degree) 71 | { 72 | var temp = a; 73 | a = b; 74 | b = temp; 75 | } 76 | 77 | var rLast = a; 78 | var r = b; 79 | var sLast = this.field.One; 80 | var s = this.field.Zero; 81 | var tLast = this.field.Zero; 82 | var t = this.field.One; 83 | 84 | // Run Euclidean algorithm until r's degree is less than R/2 85 | while (r.Degree >= Math.floor(R / 2)) 86 | { 87 | var rLastLast = rLast; 88 | var sLastLast = sLast; 89 | var tLastLast = tLast; 90 | rLast = r; 91 | sLast = s; 92 | tLast = t; 93 | 94 | // Divide rLastLast by rLast, with quotient in q and remainder in r 95 | if (rLast.Zero) 96 | { 97 | // Oops, Euclidean algorithm already terminated? 98 | throw "r_{i-1} was zero"; 99 | } 100 | r = rLastLast; 101 | var q = this.field.Zero; 102 | var denominatorLeadingTerm = rLast.getCoefficient(rLast.Degree); 103 | var dltInverse = this.field.inverse(denominatorLeadingTerm); 104 | while (r.Degree >= rLast.Degree && !r.Zero) 105 | { 106 | var degreeDiff = r.Degree - rLast.Degree; 107 | var scale = this.field.multiply(r.getCoefficient(r.Degree), dltInverse); 108 | q = q.addOrSubtract(this.field.buildMonomial(degreeDiff, scale)); 109 | r = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale)); 110 | //r.EXE(); 111 | } 112 | 113 | s = q.multiply1(sLast).addOrSubtract(sLastLast); 114 | t = q.multiply1(tLast).addOrSubtract(tLastLast); 115 | } 116 | 117 | var sigmaTildeAtZero = t.getCoefficient(0); 118 | if (sigmaTildeAtZero == 0) 119 | { 120 | throw "ReedSolomonException sigmaTilde(0) was zero"; 121 | } 122 | 123 | var inverse = this.field.inverse(sigmaTildeAtZero); 124 | var sigma = t.multiply2(inverse); 125 | var omega = r.multiply2(inverse); 126 | return new Array(sigma, omega); 127 | } 128 | this.findErrorLocations=function( errorLocator) 129 | { 130 | // This is a direct application of Chien's search 131 | var numErrors = errorLocator.Degree; 132 | if (numErrors == 1) 133 | { 134 | // shortcut 135 | return new Array(errorLocator.getCoefficient(1)); 136 | } 137 | var result = new Array(numErrors); 138 | var e = 0; 139 | for (var i = 1; i < 256 && e < numErrors; i++) 140 | { 141 | if (errorLocator.evaluateAt(i) == 0) 142 | { 143 | result[e] = this.field.inverse(i); 144 | e++; 145 | } 146 | } 147 | if (e != numErrors) 148 | { 149 | throw "Error locator degree does not match number of roots"; 150 | } 151 | return result; 152 | } 153 | this.findErrorMagnitudes=function( errorEvaluator, errorLocations, dataMatrix) 154 | { 155 | // This is directly applying Forney's Formula 156 | var s = errorLocations.length; 157 | var result = new Array(s); 158 | for (var i = 0; i < s; i++) 159 | { 160 | var xiInverse = this.field.inverse(errorLocations[i]); 161 | var denominator = 1; 162 | for (var j = 0; j < s; j++) 163 | { 164 | if (i != j) 165 | { 166 | denominator = this.field.multiply(denominator, GF256.addOrSubtract(1, this.field.multiply(errorLocations[j], xiInverse))); 167 | } 168 | } 169 | result[i] = this.field.multiply(errorEvaluator.evaluateAt(xiInverse), this.field.inverse(denominator)); 170 | // Thanks to sanfordsquires for this fix: 171 | if (dataMatrix) 172 | { 173 | result[i] = this.field.multiply(result[i], xiInverse); 174 | } 175 | } 176 | return result; 177 | } 178 | } -------------------------------------------------------------------------------- /src/qr/version.js: -------------------------------------------------------------------------------- 1 | /* 2 | Ported to JavaScript by Lazar Laszlo 2011 3 | 4 | lazarsoft@gmail.com, www.lazarsoft.info 5 | 6 | */ 7 | 8 | /* 9 | * 10 | * Copyright 2007 ZXing authors 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | 26 | 27 | function ECB(count, dataCodewords) 28 | { 29 | this.count = count; 30 | this.dataCodewords = dataCodewords; 31 | 32 | this.__defineGetter__("Count", function() 33 | { 34 | return this.count; 35 | }); 36 | this.__defineGetter__("DataCodewords", function() 37 | { 38 | return this.dataCodewords; 39 | }); 40 | } 41 | 42 | function ECBlocks( ecCodewordsPerBlock, ecBlocks1, ecBlocks2) 43 | { 44 | this.ecCodewordsPerBlock = ecCodewordsPerBlock; 45 | if(ecBlocks2) 46 | this.ecBlocks = new Array(ecBlocks1, ecBlocks2); 47 | else 48 | this.ecBlocks = new Array(ecBlocks1); 49 | 50 | this.__defineGetter__("ECCodewordsPerBlock", function() 51 | { 52 | return this.ecCodewordsPerBlock; 53 | }); 54 | 55 | this.__defineGetter__("TotalECCodewords", function() 56 | { 57 | return this.ecCodewordsPerBlock * this.NumBlocks; 58 | }); 59 | 60 | this.__defineGetter__("NumBlocks", function() 61 | { 62 | var total = 0; 63 | for (var i = 0; i < this.ecBlocks.length; i++) 64 | { 65 | total += this.ecBlocks[i].length; 66 | } 67 | return total; 68 | }); 69 | 70 | this.getECBlocks=function() 71 | { 72 | return this.ecBlocks; 73 | } 74 | } 75 | 76 | function Version( versionNumber, alignmentPatternCenters, ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4) 77 | { 78 | this.versionNumber = versionNumber; 79 | this.alignmentPatternCenters = alignmentPatternCenters; 80 | this.ecBlocks = new Array(ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4); 81 | 82 | var total = 0; 83 | var ecCodewords = ecBlocks1.ECCodewordsPerBlock; 84 | var ecbArray = ecBlocks1.getECBlocks(); 85 | for (var i = 0; i < ecbArray.length; i++) 86 | { 87 | var ecBlock = ecbArray[i]; 88 | total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords); 89 | } 90 | this.totalCodewords = total; 91 | 92 | this.__defineGetter__("VersionNumber", function() 93 | { 94 | return this.versionNumber; 95 | }); 96 | 97 | this.__defineGetter__("AlignmentPatternCenters", function() 98 | { 99 | return this.alignmentPatternCenters; 100 | }); 101 | this.__defineGetter__("TotalCodewords", function() 102 | { 103 | return this.totalCodewords; 104 | }); 105 | this.__defineGetter__("DimensionForVersion", function() 106 | { 107 | return 17 + 4 * this.versionNumber; 108 | }); 109 | 110 | this.buildFunctionPattern=function() 111 | { 112 | var dimension = this.DimensionForVersion; 113 | var bitMatrix = new BitMatrix(dimension); 114 | 115 | // Top left finder pattern + separator + format 116 | bitMatrix.setRegion(0, 0, 9, 9); 117 | // Top right finder pattern + separator + format 118 | bitMatrix.setRegion(dimension - 8, 0, 8, 9); 119 | // Bottom left finder pattern + separator + format 120 | bitMatrix.setRegion(0, dimension - 8, 9, 8); 121 | 122 | // Alignment patterns 123 | var max = this.alignmentPatternCenters.length; 124 | for (var x = 0; x < max; x++) 125 | { 126 | var i = this.alignmentPatternCenters[x] - 2; 127 | for (var y = 0; y < max; y++) 128 | { 129 | if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) 130 | { 131 | // No alignment patterns near the three finder paterns 132 | continue; 133 | } 134 | bitMatrix.setRegion(this.alignmentPatternCenters[y] - 2, i, 5, 5); 135 | } 136 | } 137 | 138 | // Vertical timing pattern 139 | bitMatrix.setRegion(6, 9, 1, dimension - 17); 140 | // Horizontal timing pattern 141 | bitMatrix.setRegion(9, 6, dimension - 17, 1); 142 | 143 | if (this.versionNumber > 6) 144 | { 145 | // Version info, top right 146 | bitMatrix.setRegion(dimension - 11, 0, 3, 6); 147 | // Version info, bottom left 148 | bitMatrix.setRegion(0, dimension - 11, 6, 3); 149 | } 150 | 151 | return bitMatrix; 152 | } 153 | this.getECBlocksForLevel=function( ecLevel) 154 | { 155 | return this.ecBlocks[ecLevel.ordinal()]; 156 | } 157 | } 158 | 159 | Version.VERSION_DECODE_INFO = new Array(0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, 0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69); 160 | 161 | Version.VERSIONS = buildVersions(); 162 | 163 | Version.getVersionForNumber=function( versionNumber) 164 | { 165 | if (versionNumber < 1 || versionNumber > 40) 166 | { 167 | throw "ArgumentException"; 168 | } 169 | return Version.VERSIONS[versionNumber - 1]; 170 | } 171 | 172 | Version.getProvisionalVersionForDimension=function(dimension) 173 | { 174 | if (dimension % 4 != 1) 175 | { 176 | throw "Error getProvisionalVersionForDimension"; 177 | } 178 | try 179 | { 180 | return Version.getVersionForNumber((dimension - 17) >> 2); 181 | } 182 | catch ( iae) 183 | { 184 | throw "Error getVersionForNumber"; 185 | } 186 | } 187 | 188 | Version.decodeVersionInformation=function( versionBits) 189 | { 190 | var bestDifference = 0xffffffff; 191 | var bestVersion = 0; 192 | for (var i = 0; i < Version.VERSION_DECODE_INFO.length; i++) 193 | { 194 | var targetVersion = Version.VERSION_DECODE_INFO[i]; 195 | // Do the version info bits match exactly? done. 196 | if (targetVersion == versionBits) 197 | { 198 | return this.getVersionForNumber(i + 7); 199 | } 200 | // Otherwise see if this is the closest to a real version info bit string 201 | // we have seen so far 202 | var bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); 203 | if (bitsDifference < bestDifference) 204 | { 205 | bestVersion = i + 7; 206 | bestDifference = bitsDifference; 207 | } 208 | } 209 | // We can tolerate up to 3 bits of error since no two version info codewords will 210 | // differ in less than 4 bits. 211 | if (bestDifference <= 3) 212 | { 213 | return this.getVersionForNumber(bestVersion); 214 | } 215 | // If we didn't find a close enough match, fail 216 | return null; 217 | } 218 | 219 | function buildVersions() 220 | { 221 | return new Array(new Version(1, new Array(), new ECBlocks(7, new ECB(1, 19)), new ECBlocks(10, new ECB(1, 16)), new ECBlocks(13, new ECB(1, 13)), new ECBlocks(17, new ECB(1, 9))), 222 | new Version(2, new Array(6, 18), new ECBlocks(10, new ECB(1, 34)), new ECBlocks(16, new ECB(1, 28)), new ECBlocks(22, new ECB(1, 22)), new ECBlocks(28, new ECB(1, 16))), 223 | new Version(3, new Array(6, 22), new ECBlocks(15, new ECB(1, 55)), new ECBlocks(26, new ECB(1, 44)), new ECBlocks(18, new ECB(2, 17)), new ECBlocks(22, new ECB(2, 13))), 224 | new Version(4, new Array(6, 26), new ECBlocks(20, new ECB(1, 80)), new ECBlocks(18, new ECB(2, 32)), new ECBlocks(26, new ECB(2, 24)), new ECBlocks(16, new ECB(4, 9))), 225 | new Version(5, new Array(6, 30), new ECBlocks(26, new ECB(1, 108)), new ECBlocks(24, new ECB(2, 43)), new ECBlocks(18, new ECB(2, 15), new ECB(2, 16)), new ECBlocks(22, new ECB(2, 11), new ECB(2, 12))), 226 | new Version(6, new Array(6, 34), new ECBlocks(18, new ECB(2, 68)), new ECBlocks(16, new ECB(4, 27)), new ECBlocks(24, new ECB(4, 19)), new ECBlocks(28, new ECB(4, 15))), 227 | new Version(7, new Array(6, 22, 38), new ECBlocks(20, new ECB(2, 78)), new ECBlocks(18, new ECB(4, 31)), new ECBlocks(18, new ECB(2, 14), new ECB(4, 15)), new ECBlocks(26, new ECB(4, 13), new ECB(1, 14))), 228 | new Version(8, new Array(6, 24, 42), new ECBlocks(24, new ECB(2, 97)), new ECBlocks(22, new ECB(2, 38), new ECB(2, 39)), new ECBlocks(22, new ECB(4, 18), new ECB(2, 19)), new ECBlocks(26, new ECB(4, 14), new ECB(2, 15))), 229 | new Version(9, new Array(6, 26, 46), new ECBlocks(30, new ECB(2, 116)), new ECBlocks(22, new ECB(3, 36), new ECB(2, 37)), new ECBlocks(20, new ECB(4, 16), new ECB(4, 17)), new ECBlocks(24, new ECB(4, 12), new ECB(4, 13))), 230 | new Version(10, new Array(6, 28, 50), new ECBlocks(18, new ECB(2, 68), new ECB(2, 69)), new ECBlocks(26, new ECB(4, 43), new ECB(1, 44)), new ECBlocks(24, new ECB(6, 19), new ECB(2, 20)), new ECBlocks(28, new ECB(6, 15), new ECB(2, 16))), 231 | new Version(11, new Array(6, 30, 54), new ECBlocks(20, new ECB(4, 81)), new ECBlocks(30, new ECB(1, 50), new ECB(4, 51)), new ECBlocks(28, new ECB(4, 22), new ECB(4, 23)), new ECBlocks(24, new ECB(3, 12), new ECB(8, 13))), 232 | new Version(12, new Array(6, 32, 58), new ECBlocks(24, new ECB(2, 92), new ECB(2, 93)), new ECBlocks(22, new ECB(6, 36), new ECB(2, 37)), new ECBlocks(26, new ECB(4, 20), new ECB(6, 21)), new ECBlocks(28, new ECB(7, 14), new ECB(4, 15))), 233 | new Version(13, new Array(6, 34, 62), new ECBlocks(26, new ECB(4, 107)), new ECBlocks(22, new ECB(8, 37), new ECB(1, 38)), new ECBlocks(24, new ECB(8, 20), new ECB(4, 21)), new ECBlocks(22, new ECB(12, 11), new ECB(4, 12))), 234 | new Version(14, new Array(6, 26, 46, 66), new ECBlocks(30, new ECB(3, 115), new ECB(1, 116)), new ECBlocks(24, new ECB(4, 40), new ECB(5, 41)), new ECBlocks(20, new ECB(11, 16), new ECB(5, 17)), new ECBlocks(24, new ECB(11, 12), new ECB(5, 13))), 235 | new Version(15, new Array(6, 26, 48, 70), new ECBlocks(22, new ECB(5, 87), new ECB(1, 88)), new ECBlocks(24, new ECB(5, 41), new ECB(5, 42)), new ECBlocks(30, new ECB(5, 24), new ECB(7, 25)), new ECBlocks(24, new ECB(11, 12), new ECB(7, 13))), 236 | new Version(16, new Array(6, 26, 50, 74), new ECBlocks(24, new ECB(5, 98), new ECB(1, 99)), new ECBlocks(28, new ECB(7, 45), new ECB(3, 46)), new ECBlocks(24, new ECB(15, 19), new ECB(2, 20)), new ECBlocks(30, new ECB(3, 15), new ECB(13, 16))), 237 | new Version(17, new Array(6, 30, 54, 78), new ECBlocks(28, new ECB(1, 107), new ECB(5, 108)), new ECBlocks(28, new ECB(10, 46), new ECB(1, 47)), new ECBlocks(28, new ECB(1, 22), new ECB(15, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(17, 15))), 238 | new Version(18, new Array(6, 30, 56, 82), new ECBlocks(30, new ECB(5, 120), new ECB(1, 121)), new ECBlocks(26, new ECB(9, 43), new ECB(4, 44)), new ECBlocks(28, new ECB(17, 22), new ECB(1, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(19, 15))), 239 | new Version(19, new Array(6, 30, 58, 86), new ECBlocks(28, new ECB(3, 113), new ECB(4, 114)), new ECBlocks(26, new ECB(3, 44), new ECB(11, 45)), new ECBlocks(26, new ECB(17, 21), new ECB(4, 22)), new ECBlocks(26, new ECB(9, 13), new ECB(16, 14))), 240 | new Version(20, new Array(6, 34, 62, 90), new ECBlocks(28, new ECB(3, 107), new ECB(5, 108)), new ECBlocks(26, new ECB(3, 41), new ECB(13, 42)), new ECBlocks(30, new ECB(15, 24), new ECB(5, 25)), new ECBlocks(28, new ECB(15, 15), new ECB(10, 16))), 241 | new Version(21, new Array(6, 28, 50, 72, 94), new ECBlocks(28, new ECB(4, 116), new ECB(4, 117)), new ECBlocks(26, new ECB(17, 42)), new ECBlocks(28, new ECB(17, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(19, 16), new ECB(6, 17))), 242 | new Version(22, new Array(6, 26, 50, 74, 98), new ECBlocks(28, new ECB(2, 111), new ECB(7, 112)), new ECBlocks(28, new ECB(17, 46)), new ECBlocks(30, new ECB(7, 24), new ECB(16, 25)), new ECBlocks(24, new ECB(34, 13))), 243 | new Version(23, new Array(6, 30, 54, 74, 102), new ECBlocks(30, new ECB(4, 121), new ECB(5, 122)), new ECBlocks(28, new ECB(4, 47), new ECB(14, 48)), new ECBlocks(30, new ECB(11, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(16, 15), new ECB(14, 16))), 244 | new Version(24, new Array(6, 28, 54, 80, 106), new ECBlocks(30, new ECB(6, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(6, 45), new ECB(14, 46)), new ECBlocks(30, new ECB(11, 24), new ECB(16, 25)), new ECBlocks(30, new ECB(30, 16), new ECB(2, 17))), 245 | new Version(25, new Array(6, 32, 58, 84, 110), new ECBlocks(26, new ECB(8, 106), new ECB(4, 107)), new ECBlocks(28, new ECB(8, 47), new ECB(13, 48)), new ECBlocks(30, new ECB(7, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(13, 16))), 246 | new Version(26, new Array(6, 30, 58, 86, 114), new ECBlocks(28, new ECB(10, 114), new ECB(2, 115)), new ECBlocks(28, new ECB(19, 46), new ECB(4, 47)), new ECBlocks(28, new ECB(28, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(33, 16), new ECB(4, 17))), 247 | new Version(27, new Array(6, 34, 62, 90, 118), new ECBlocks(30, new ECB(8, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(22, 45), new ECB(3, 46)), new ECBlocks(30, new ECB(8, 23), new ECB(26, 24)), new ECBlocks(30, new ECB(12, 15), new ECB(28, 16))), 248 | new Version(28, new Array(6, 26, 50, 74, 98, 122), new ECBlocks(30, new ECB(3, 117), new ECB(10, 118)), new ECBlocks(28, new ECB(3, 45), new ECB(23, 46)), new ECBlocks(30, new ECB(4, 24), new ECB(31, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(31, 16))), 249 | new Version(29, new Array(6, 30, 54, 78, 102, 126), new ECBlocks(30, new ECB(7, 116), new ECB(7, 117)), new ECBlocks(28, new ECB(21, 45), new ECB(7, 46)), new ECBlocks(30, new ECB(1, 23), new ECB(37, 24)), new ECBlocks(30, new ECB(19, 15), new ECB(26, 16))), 250 | new Version(30, new Array(6, 26, 52, 78, 104, 130), new ECBlocks(30, new ECB(5, 115), new ECB(10, 116)), new ECBlocks(28, new ECB(19, 47), new ECB(10, 48)), new ECBlocks(30, new ECB(15, 24), new ECB(25, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(25, 16))), 251 | new Version(31, new Array(6, 30, 56, 82, 108, 134), new ECBlocks(30, new ECB(13, 115), new ECB(3, 116)), new ECBlocks(28, new ECB(2, 46), new ECB(29, 47)), new ECBlocks(30, new ECB(42, 24), new ECB(1, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(28, 16))), 252 | new Version(32, new Array(6, 34, 60, 86, 112, 138), new ECBlocks(30, new ECB(17, 115)), new ECBlocks(28, new ECB(10, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(10, 24), new ECB(35, 25)), new ECBlocks(30, new ECB(19, 15), new ECB(35, 16))), 253 | new Version(33, new Array(6, 30, 58, 86, 114, 142), new ECBlocks(30, new ECB(17, 115), new ECB(1, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(21, 47)), new ECBlocks(30, new ECB(29, 24), new ECB(19, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(46, 16))), 254 | new Version(34, new Array(6, 34, 62, 90, 118, 146), new ECBlocks(30, new ECB(13, 115), new ECB(6, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(44, 24), new ECB(7, 25)), new ECBlocks(30, new ECB(59, 16), new ECB(1, 17))), 255 | new Version(35, new Array(6, 30, 54, 78, 102, 126, 150), new ECBlocks(30, new ECB(12, 121), new ECB(7, 122)), new ECBlocks(28, new ECB(12, 47), new ECB(26, 48)), new ECBlocks(30, new ECB(39, 24), new ECB(14, 25)),new ECBlocks(30, new ECB(22, 15), new ECB(41, 16))), 256 | new Version(36, new Array(6, 24, 50, 76, 102, 128, 154), new ECBlocks(30, new ECB(6, 121), new ECB(14, 122)), new ECBlocks(28, new ECB(6, 47), new ECB(34, 48)), new ECBlocks(30, new ECB(46, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(2, 15), new ECB(64, 16))), 257 | new Version(37, new Array(6, 28, 54, 80, 106, 132, 158), new ECBlocks(30, new ECB(17, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(29, 46), new ECB(14, 47)), new ECBlocks(30, new ECB(49, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(24, 15), new ECB(46, 16))), 258 | new Version(38, new Array(6, 32, 58, 84, 110, 136, 162), new ECBlocks(30, new ECB(4, 122), new ECB(18, 123)), new ECBlocks(28, new ECB(13, 46), new ECB(32, 47)), new ECBlocks(30, new ECB(48, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(42, 15), new ECB(32, 16))), 259 | new Version(39, new Array(6, 26, 54, 82, 110, 138, 166), new ECBlocks(30, new ECB(20, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(40, 47), new ECB(7, 48)), new ECBlocks(30, new ECB(43, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(10, 15), new ECB(67, 16))), 260 | new Version(40, new Array(6, 30, 58, 86, 114, 142, 170), new ECBlocks(30, new ECB(19, 118), new ECB(6, 119)), new ECBlocks(28, new ECB(18, 47), new ECB(31, 48)), new ECBlocks(30, new ECB(34, 24), new ECB(34, 25)), new ECBlocks(30, new ECB(20, 15), new ECB(61, 16)))); 261 | } -------------------------------------------------------------------------------- /src/tesseract/tesseract.min.js: -------------------------------------------------------------------------------- 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Tesseract=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o1){for(var i=1;i=400){throw new Error("Fail to get image as Blob")}else{loadImage(xhr.response,cb)}};xhr.onerror=function(e){throw e};xhr.send(null);return}}else if(image instanceof File){var fr=new FileReader;fr.onload=function(e){return loadImage(fr.result,cb)};fr.onerror=function(e){throw e};fr.readAsDataURL(image);return}else if(image instanceof Blob){return loadImage(URL.createObjectURL(image),cb)}else if(image.getContext){return loadImage(image.getContext("2d"),cb)}else if(image.tagName=="IMG"||image.tagName=="VIDEO"){var c=document.createElement("canvas");c.width=image.naturalWidth||image.videoWidth;c.height=image.naturalHeight||image.videoHeight;var ctx=c.getContext("2d");ctx.drawImage(image,0,0);return loadImage(ctx,cb)}else if(image.getImageData){var data=image.getImageData(0,0,image.canvas.width,image.canvas.height);return loadImage(data,cb)}else{return cb(image)}throw new Error("Missing return in loadImage cascade")}}).call(this,require("_process"))},{"../../package.json":2,_process:1}],4:[function(require,module,exports){"use strict";module.exports=function circularize(page){page.paragraphs=[];page.lines=[];page.words=[];page.symbols=[];page.blocks.forEach(function(block){block.page=page;block.lines=[];block.words=[];block.symbols=[];block.paragraphs.forEach(function(para){para.block=block;para.page=page;para.words=[];para.symbols=[];para.lines.forEach(function(line){line.paragraph=para;line.block=block;line.page=page;line.symbols=[];line.words.forEach(function(word){word.line=line;word.paragraph=para;word.block=block;word.page=page;word.symbols.forEach(function(sym){sym.word=word;sym.line=line;sym.paragraph=para;sym.block=block;sym.page=page;sym.line.symbols.push(sym);sym.paragraph.symbols.push(sym);sym.block.symbols.push(sym);sym.page.symbols.push(sym)});word.paragraph.words.push(word);word.block.words.push(word);word.page.words.push(word)});line.block.lines.push(line);line.page.lines.push(line)});para.page.paragraphs.push(para)})});return page}},{}],5:[function(require,module,exports){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:{};var worker=new TesseractWorker(Object.assign({},adapter.defaultOptions,workerOptions));worker.create=create;worker.version=version;return worker};var TesseractWorker=function(){function TesseractWorker(workerOptions){_classCallCheck(this,TesseractWorker);this.worker=null;this.workerOptions=workerOptions;this._currentJob=null;this._queue=[]}_createClass(TesseractWorker,[{key:"recognize",value:function recognize(image){var _this=this;var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return this._delay(function(job){if(typeof options==="string")options={lang:options};options.lang=options.lang||"eng";job._send("recognize",{image:image,options:options,workerOptions:_this.workerOptions})})}},{key:"detect",value:function detect(image){var _this2=this;var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return this._delay(function(job){job._send("detect",{image:image,options:options,workerOptions:_this2.workerOptions})})}},{key:"terminate",value:function terminate(){if(this.worker)adapter.terminateWorker(this);this.worker=null;this._currentJob=null;this._queue=[]}},{key:"_delay",value:function _delay(fn){var _this3=this;if(!this.worker)this.worker=adapter.spawnWorker(this,this.workerOptions);var job=new TesseractJob(this);this._queue.push(function(e){_this3._queue.shift();_this3._currentJob=job;fn(job)});if(!this._currentJob)this._dequeue();return job}},{key:"_dequeue",value:function _dequeue(){this._currentJob=null;if(this._queue.length){this._queue[0]()}}},{key:"_recv",value:function _recv(packet){if(packet.status==="resolve"&&packet.action==="recognize"){packet.data=circularize(packet.data)}if(this._currentJob.id===packet.jobId){this._currentJob._handle(packet)}else{console.warn("Job ID "+packet.jobId+" not known.")}}}]);return TesseractWorker}();module.exports=create()},{"../package.json":2,"./common/circularize.js":4,"./common/job":5,"./node/index.js":3}]},{},[6])(6)}); --------------------------------------------------------------------------------