author | František Kučera <franta-hg@frantovo.cz> |
Wed, 14 Apr 2021 20:56:18 +0200 | |
branch | v_0 |
changeset 1 | 79d699ed88ab |
parent 0 | 0a0cb749c10f |
child 2 | 6cc693048318 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
19 |
#include <codecvt> |
|
20 |
#include <memory> |
|
21 |
#include <algorithm> |
|
22 |
#include <iostream> |
|
23 |
#include <stdexcept> |
|
24 |
||
1
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
25 |
#include <Magick++.h> |
0 | 26 |
#include <zbar.h> |
27 |
||
28 |
#include "Configuration.h" |
|
29 |
||
30 |
namespace relpipe { |
|
31 |
namespace in { |
|
32 |
namespace qr { |
|
33 |
||
34 |
class QRCommand { |
|
1
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
35 |
std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: use platform encoding as default / check zbar encoding |
0 | 36 |
|
37 |
||
38 |
public: |
|
39 |
||
40 |
void process(Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) { |
|
41 |
||
1
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
42 |
Magick::Image magick("/dev/stdin"); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
43 |
int width = magick.columns(); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
44 |
int height = magick.rows(); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
45 |
Magick::Blob blob; |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
46 |
magick.modifyImage(); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
47 |
magick.write(&blob, "GRAY", 8); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
48 |
const void *raw = blob.data(); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
49 |
|
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
50 |
zbar::Image image(width, height, "Y800", raw, width * height); |
0 | 51 |
zbar::ImageScanner scanner; |
52 |
||
53 |
writer->startRelation(L"qr",{ |
|
1
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
54 |
{L"type", relpipe::writer::TypeId::STRING}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
55 |
// {L"addon_name", relpipe::writer::TypeId::STRING}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
56 |
{L"value", relpipe::writer::TypeId::STRING}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
57 |
// {L"xml", relpipe::writer::TypeId::STRING}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
58 |
{L"location_size", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
59 |
{L"x_1", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
60 |
{L"y_1", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
61 |
{L"x_2", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
62 |
{L"y_2", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
63 |
{L"x_3", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
64 |
{L"y_3", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
65 |
{L"x_4", relpipe::writer::TypeId::INTEGER}, |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
66 |
{L"y_4", relpipe::writer::TypeId::INTEGER}, |
0 | 67 |
}, true); |
68 |
||
1
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
69 |
int n = scanner.scan(image); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
70 |
|
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
71 |
for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) { |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
72 |
writer->writeAttribute(convertor.from_bytes(symbol->get_type_name())); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
73 |
// writer->writeAttribute(convertor.from_bytes(symbol->get_addon_name())); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
74 |
writer->writeAttribute(convertor.from_bytes(symbol->get_data())); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
75 |
// writer->writeAttribute(convertor.from_bytes(symbol->xml())); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
76 |
|
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
77 |
relpipe::common::type::Integer locationSize = symbol->get_location_size(); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
78 |
writer->writeAttribute(&locationSize, typeid (locationSize)); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
79 |
|
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
80 |
for (int i = 0; i < 4; i++) { |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
81 |
relpipe::common::type::Integer x = -5; |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
82 |
relpipe::common::type::Integer y = -6; |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
83 |
if (i < locationSize) { |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
84 |
x = symbol->get_location_x(i); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
85 |
y = symbol->get_location_y(i); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
86 |
} |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
87 |
writer->writeAttribute(&x, typeid (x)); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
88 |
writer->writeAttribute(&y, typeid (y)); |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
89 |
} |
0 | 90 |
|
91 |
||
1
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
92 |
} |
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
93 |
|
79d699ed88ab
dirty and buggy first version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
94 |
image.set_data(nullptr, 0); |
0 | 95 |
} |
96 |
}; |
|
97 |
||
98 |
} |
|
99 |
} |
|
100 |
} |