-
Notifications
You must be signed in to change notification settings - Fork 17
/
xzingDecode.html
176 lines (170 loc) · 10.3 KB
/
xzingDecode.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<script type="text/javascript">
(function () {
RED.nodes.registerType('Barcode Decoder', {
category: 'image tools',
paletteLabel: "Barcode Decoder",
//labelStyle: "node-label-white",
icon: "font-awesome/fa-barcode",
color: '#FFAAAA',//'#f24b69',
defaults: {
name: { value: "" },
data: { value: "payload", validate: RED.validators.typedInput("dataType") },
dataType: { value: "msg" },
tryharder: { value: false, validate: RED.validators.typedInput("tryharderType") },
tryharderType: { value: "bool" },
charEncoding: { value: 'Auto Detect' },
charEncodingType: { value: "enc" },
QR_CODE: { value: true },
DATA_MATRIX: { value: false },
PDF_417: { value: false },
EAN_8: { value: false },
EAN_13: { value: false },
CODE_39: { value: false },
CODE_128: { value: false },
ITF: { value: false },
RSS_14: { value: false },
},
inputs: 1,
outputs: 1,
label: function () {
return this.name || "Barcode Decoder";
},
oneditprepare: function () {
let node = this;
function setupTypedInput(varName, types, def) {
let varSel = '#node-input-' + varName;
let typeSel = varSel + 'Type';
let varVal = node[varName];
let typeVal = node[varName + 'Type'];
if (typeVal == null || typeVal === 'none') {
typeVal = def;
} else if (typeVal === 'string') {
typeVal = "str";
} else if (typeVal === 'number') {
typeVal = "num";
}
$(typeSel).val(typeVal);
$(varSel).typedInput({
default: def,
typeField: $(typeSel),
types: types
});
$(varSel).typedInput('type', typeVal);
}
const knownEncodings = ["Auto Detect", 'ascii', 'utf-8', 'ibm866', 'iso-8859-2', 'iso-8859-3', 'iso-8859-4', 'iso-8859-5', 'iso-8859-6', 'iso-8859-7', 'iso-8859-8', 'iso-8859-8-i', 'iso-8859-10', 'iso-8859-13', 'iso-8859-14', 'iso-8859-15', 'koi8-r', 'koi8-u', 'macintosh', 'windows-874', 'windows-1250', 'windows-1251', 'windows-1252', 'windows-1253', 'windows-1254', 'windows-1255', 'windows-1256', 'windows-1257', 'windows-1258', 'x-mac-cyrillic', 'gbk', 'gb18030', 'big5', 'euc-jp', 'iso-2022-jp', 'shift_jis', 'euc-kr', 'utf-16le', 'utf-16be']
setupTypedInput('data', ['msg', 'flow', 'global', 'bin', 'str'], 'str');
setupTypedInput('tryharder', ['bool', 'msg', 'flow', 'global'], 'bool');
debugger
node._charEncUnset = (typeof node.charEncoding === 'undefined' && typeof node.charEncodingType === 'undefined');
$('#node-input-charEncoding').typedInput({
types: [
{
type: 'enc',
options: knownEncodings.map(function (enc) {
return { value: enc, label: enc }
}),
icon: 'fa fa-globe',
label: 'encoding',
},
'str', 'msg', 'flow', 'global']
})
$('#node-input-charEncoding').typedInput('type', node.charEncodingType || 'enc');
$('#node-input-charEncoding').typedInput('value', node.charEncoding || 'Auto Detect');
},
oneditsave() {
const node = this;
const charEncoding = $('#node-input-charEncoding').typedInput('value') || 'Auto Detect'
const charEncodingType = $('#node-input-charEncoding').typedInput('type') || 'enc'
if (node._charEncUnset && charEncodingType === 'enc' && charEncoding === 'Auto Detect') {
// skip setting default values to avoid unnecessary dirty state
} else {
node.charEncoding = charEncoding;
node.charEncodingType = charEncodingType;
}
}
});
})();
</script>
<script type="text/html" data-template-name="Barcode Decoder">
<link rel="stylesheet" href="image-tools/static/css/common.css" type="text/css"/>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-data"><i class="fa fa-file-image-o"></i><span data-i18n="xzingDecode.label.data"> image</span></label>
<input type="hidden" id="node-input-dataType">
<input style="width: 70%" type="text" id="node-input-data" placeholder="image.jpg">
</div>
<div class="form-row">
<label for="node-input-format"><i class="fa fa-barcode"></i><span data-i18n="xzingDecode.label.format"> format</span></label>
<div class="image-tools-checklist">
<input type="checkbox" id="node-input-DATA_MATRIX" title="DATA_MATRIX" data-value="DATA_MATRIX">
<label for="node-input-DATA_MATRIX" title="DATA_MATRIX">Datamatrix</label>
<input type="checkbox" id="node-input-QR_CODE" title="QR_CODE" data-value="QR_CODE">
<label for="node-input-QR_CODE" title="QR_CODE">QR</label>
<input type="checkbox" id="node-input-PDF_417" title="PDF_417" data-value="PDF_417">
<label for="node-input-PDF_417" title="PDF_417">PDF 417</label>
<input type="checkbox" id="node-input-EAN_8" title="EAN_8" data-value="EAN_8">
<label for="node-input-EAN_8" title="EAN_8">EAN 8</label>
<input type="checkbox" id="node-input-EAN_13" title="EAN_13" data-value="EAN_13">
<label for="node-input-EAN_13" title="EAN_13">EAN 13</label>
<input type="checkbox" id="node-input-CODE_39" title="CODE_39" data-value="CODE_39">
<label for="node-input-CODE_39" title="CODE_39">Code 39</label>
<input type="checkbox" id="node-input-CODE_128" title="CODE_128" data-value="CODE_128">
<label for="node-input-CODE_128" title="CODE_128">Code 128</label>
<input type="checkbox" id="node-input-ITF" title="ITF" data-value="ITF">
<label for="node-input-ITF" title="ITF">ITF</label>
<input type="checkbox" id="node-input-RSS_14" title="RSS_14" data-value="RSS_14">
<label for="node-input-RSS_14" title="RSS_14">RSS 14</label>
</div>
</div>
<div class="form-row">
<label for="node-input-tryharder"><i class="fa fa-cogs"></i><span data-i18n="xzingDecode.label.tryharder"> try harder</span></label>
<input type="hidden" id="node-input-tryharderType">
<input style="width: 70%" type="text" id="node-input-tryharder" >
</div>
<div class="form-row">
<label for="node-input-charEncoding"><i class="fa fa-globe"></i><span data-i18n="xzingDecode.label.charEncoding"> encoding</span></label>
<input type="hidden" id="node-input-charEncodingType">
<input style="width: 70%" type="text" id="node-input-charEncoding" >
</div>
</script>
<script type="text/html" data-help-name="Barcode Decoder">
<link rel="stylesheet" href="image-tools/static/css/common.css" type="text/css"/>
<p>A barcode decoder node built with zxing and Jimp</p>
<h3>Foreword</h3>
<dl class="message-properties">
Examples have been included to help you do some common tasks.
<a onclick="RED.actions.invoke('core:show-examples-import-dialog')" href="#">Click here</a> to import an example or click the hamburger menu <a class="button" href="#"><i class="fa fa-bars"></i></a> select <b>import</b> then <b>examples</b> or press <kbd>ctrl+i</kbd>
</dl>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>image <span class="property-type">string | base64 | buffer | object</span></dt>
<dd> the image (Jimp image / buffer / base64 string / file name / URL) to be decoded. </dd>
<dt>format <span class="property-type">JSON</span></dt>
<dd>
The barcode formats to use can be overridden by sending an array of strings in <code>msg.barcodeFormats</code>.
Choosing the correct format can reduce processing time and improve accuracy.
<p style="padding-left: 2px">
<b>Overriding barcode formats by setting <code>msg.barcodeFormats</code>...</b><br>
Example to read QR only: <code>["QR_CODE"]</code><br>
Example to read Datamatrix only: <code>["DATA_MATRIX"]</code><br>
Example to read 3 different types of barcode: <code>["EAN_32", "RSS_14", "ITF"]</code><br>
<b>To see all currently supported types, import the example "Barcodes" or refer to <a target="_blank" href="https://github.com/zxing-js/library#supported-formats">supported-formats</a> </b>
</p>
</dd>
<dt>tryharder <span class="property-type">bool</span></dt>
<dd> if <code>true</code>, this flag instructs the decoder to try harder when looking for a barcode (slower).</dd>
<dt>encoding <span class="property-type">string</span></dt>
<dd> if <code>Auto Detect</code> is selected, this flag instructs the text decoder to guess the encoding. In tests, it is not great when there are accented characters in the string. Selecting <code>ascii</code>, <code>iso-8859-x</code> or <code>utf-8</code> works better in these cases</dd>
</dl>
<h3>Output</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>The results.</dd>
<dt>performance <span class="property-type">object</span></dt>
<dd>Performance measurements of the image loading and processing</dd>
<h4>Additional useful properties are available in the <code>msg</code> object. Use a debug node to inspect them</h4>
</dl>
</script>