author | František Kučera <franta-hg@frantovo.cz> |
Sun, 25 Apr 2021 18:47:57 +0200 | |
branch | v_0 |
changeset 89 | 25a11859975b |
parent 88 | streamlet-examples/qr.cpp@8eb799bf1d39 |
child 90 | 59d12eee189f |
permissions | -rw-r--r-- |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#include <unistd.h> |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
#include <Magick++.h> |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <zbar.h> |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
#include <relpipe/xmlwriter/XMLWriter.h> |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
#include "streamlet-common.h" |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
/** |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
* This streamlet extracts QR codes from image files. |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
* |
88
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
30 |
* It provides three attributes: |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
* - qr: first QR code found (if any) |
88
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
32 |
* - qr_count: number of QR codes found |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
* - qr_xml: XML containing all QR cpdes found an additional metadata |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
* |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
*/ |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
class QRStreamlet : public Streamlet { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
private: |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
const wstring XMLNS = L"tag:globalcode.info,2018:qr:FIXME:final-xmlns"; // FIXME: correct xmlns URI |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
|
88
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
41 |
class Point { |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
42 |
public: |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
43 |
int x; |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
44 |
int y; |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
45 |
}; |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
46 |
|
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
class Symbol { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
public: |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
int id; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
std::wstring value; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
std::wstring type; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
int x; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
int y; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
int width; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
int height; |
88
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
56 |
std::vector<Point> polygon; |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
}; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
std::vector<Symbol> findSymbols(std::wstring fileName) { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
std::vector<Symbol> result; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
Magick::Image magick(toBytes(fileName)); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
int width = magick.columns(); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
int height = magick.rows(); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
Magick::Blob blob; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
magick.modifyImage(); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
magick.write(&blob, "GRAY", 8); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
const void *raw = blob.data(); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
zbar::Image image(width, height, "Y800", raw, width * height); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
zbar::ImageScanner scanner; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
scanner.scan(image); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
int id = 0; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol, id++) { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
Symbol s; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
s.id = id; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
s.type = fromBytes(symbol->get_type_name()); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
82 |
s.value = fromBytes(symbol->get_data()); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
83 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
84 |
int minX = 0; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
int minY = 0; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
86 |
int maxX = 0; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
87 |
int maxY = 0; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
88 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
89 |
// TODO: return original polygon in XML |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
90 |
for (int i = 0, locationSize = symbol->get_location_size(); i < locationSize; i++) { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
91 |
int x = symbol->get_location_x(i); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
92 |
int y = symbol->get_location_y(i); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
93 |
minX = minX ? std::min(minX, x) : x; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
94 |
minY = minY ? std::min(minY, y) : y; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
95 |
maxX = std::max(maxX, x); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
96 |
maxY = std::max(maxY, y); |
88
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
97 |
s.polygon.push_back({x, y}); |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
98 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
99 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
100 |
s.x = minX; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
101 |
s.y = minY; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
102 |
s.width = maxX - minX; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
103 |
s.height = maxY - minY; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
104 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
105 |
result.push_back(s); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
106 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
107 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
108 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
109 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
110 |
return result; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
111 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
112 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
113 |
protected: |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
114 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
115 |
std::vector<AttributeMetadata> getOutputAttributesMetadata() override { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
116 |
std::vector<AttributeMetadata> oam; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
117 |
int i = 0; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
118 |
oam.push_back({getAlias(i++, L"qr"), STRING}); |
87
d846da24dd35
streamlet examples: QR: return also the symbol count
František Kučera <franta-hg@frantovo.cz>
parents:
86
diff
changeset
|
119 |
oam.push_back({getAlias(i++, L"qr_count"), INTEGER}); |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
120 |
oam.push_back({getAlias(i++, L"qr_xml"), STRING}); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
121 |
return oam; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
122 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
123 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
124 |
std::vector<OutputAttribute> getOutputAttributes() override { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
125 |
bool validInput = false; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
126 |
bool hasSymbols = false; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
127 |
std::wstring first; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
128 |
std::stringstream xml; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
129 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
130 |
std::vector<Symbol> symbols; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
131 |
try { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
132 |
symbols = findSymbols(getCurrentFile()); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
133 |
validInput = true; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
134 |
} catch (...) { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
135 |
// just ignore the errors; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
136 |
// the file is probably not an image or we do not have read permissions |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
137 |
validInput = false; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
138 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
139 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
140 |
for (Symbol s : symbols) { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
141 |
// TODO: match against pattern (if any) |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
142 |
first = s.value; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
143 |
hasSymbols = true; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
144 |
break; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
145 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
146 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
147 |
relpipe::xmlwriter::XMLWriter xmlWriter(xml); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
148 |
xmlWriter.writeStartElement(L"qr",{L"xmlns", XMLNS}); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
149 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
150 |
// TODO: common metadata |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
151 |
// xmlWriter.writeStartElement(L"source"); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
152 |
// xmlWriter.writeTextElement(L"height",{}, std::to_wstring(...)); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
153 |
// xmlWriter.writeTextElement(L"width",{}, std::to_wstring(...)); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
154 |
// xmlWriter.writeEndElement(); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
155 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
156 |
for (Symbol s : symbols) { |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
157 |
xmlWriter.writeStartElement(L"symbol"); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
158 |
xmlWriter.writeTextElement(L"value",{}, s.value); |
88
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
159 |
|
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
160 |
// TODO: well-designed XML schema |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
161 |
// TODO: synchronize/share common XML parts with relpipe-in-qr |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
162 |
xmlWriter.writeStartElement(L"rectangular-box"); |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
163 |
xmlWriter.writeTextElement(L"x",{}, std::to_wstring(s.x)); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
164 |
xmlWriter.writeTextElement(L"y",{}, std::to_wstring(s.y)); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
165 |
xmlWriter.writeTextElement(L"height",{}, std::to_wstring(s.height)); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
166 |
xmlWriter.writeTextElement(L"width",{}, std::to_wstring(s.width)); |
88
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
167 |
xmlWriter.writeEndElement(); |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
168 |
|
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
169 |
xmlWriter.writeStartElement(L"polygon"); |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
170 |
for (Point p : s.polygon) xmlWriter.writeEmptyElement(L"point",{L"x", std::to_wstring(p.x), L"y", std::to_wstring(p.y)}); |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
171 |
xmlWriter.writeEndElement(); |
8eb799bf1d39
streamlet examples: QR: return also the polygon points
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
172 |
|
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
173 |
xmlWriter.writeEndElement(); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
174 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
175 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
176 |
xmlWriter.writeEndElement(); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
177 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
178 |
std::vector<OutputAttribute> oa; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
179 |
// TODO: report also validInput (distinguish it from hasSymbols) |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
180 |
oa.push_back({first, !hasSymbols}); |
87
d846da24dd35
streamlet examples: QR: return also the symbol count
František Kučera <franta-hg@frantovo.cz>
parents:
86
diff
changeset
|
181 |
oa.push_back({std::to_wstring(symbols.size()), false}); |
86
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
182 |
oa.push_back({fromBytes(xml.str()), false}); |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
183 |
return oa; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
184 |
} |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
185 |
}; |
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
186 |
|
3caa19520689
streamlet examples: QR: first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
187 |
STREAMLET_RUN(QRStreamlet) |