38 |
38 |
39 public: |
39 public: |
40 |
40 |
41 void process(Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) { |
41 void process(Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) { |
42 |
42 |
|
43 // TODO: require PNM input and get rid off the ImageMagick dependency? |
43 Magick::Image magick("/dev/stdin"); |
44 Magick::Image magick("/dev/stdin"); |
44 int width = magick.columns(); |
45 int width = magick.columns(); |
45 int height = magick.rows(); |
46 int height = magick.rows(); |
46 Magick::Blob blob; |
47 Magick::Blob blob; |
47 magick.modifyImage(); |
48 magick.modifyImage(); |
49 const void *raw = blob.data(); |
50 const void *raw = blob.data(); |
50 |
51 |
51 zbar::Image image(width, height, "Y800", raw, width * height); |
52 zbar::Image image(width, height, "Y800", raw, width * height); |
52 zbar::ImageScanner scanner; |
53 zbar::ImageScanner scanner; |
53 |
54 |
54 writer->startRelation(L"qr",{ |
55 writer->startRelation(L"symbol",{ |
|
56 {L"id", relpipe::writer::TypeId::INTEGER}, |
55 {L"type", relpipe::writer::TypeId::STRING}, |
57 {L"type", relpipe::writer::TypeId::STRING}, |
56 // {L"addon_name", relpipe::writer::TypeId::STRING}, |
58 // {L"addon_name", relpipe::writer::TypeId::STRING}, |
57 {L"value", relpipe::writer::TypeId::STRING}, |
59 {L"value", relpipe::writer::TypeId::STRING}, |
58 // {L"xml", relpipe::writer::TypeId::STRING}, |
60 // {L"xml", relpipe::writer::TypeId::STRING}, |
59 {L"x", relpipe::writer::TypeId::INTEGER}, |
61 {L"x", relpipe::writer::TypeId::INTEGER}, |
62 {L"height", relpipe::writer::TypeId::INTEGER}, |
64 {L"height", relpipe::writer::TypeId::INTEGER}, |
63 }, true); |
65 }, true); |
64 |
66 |
65 int n = scanner.scan(image); |
67 int n = scanner.scan(image); |
66 |
68 |
67 for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) { |
69 relpipe::common::type::Integer id = 0; |
|
70 for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol, id++) { |
|
71 writer->writeAttribute(&id, typeid (id)); |
68 writer->writeAttribute(convertor.from_bytes(symbol->get_type_name())); |
72 writer->writeAttribute(convertor.from_bytes(symbol->get_type_name())); |
69 // writer->writeAttribute(convertor.from_bytes(symbol->get_addon_name())); |
73 // writer->writeAttribute(convertor.from_bytes(symbol->get_addon_name())); |
70 writer->writeAttribute(convertor.from_bytes(symbol->get_data())); |
74 writer->writeAttribute(convertor.from_bytes(symbol->get_data())); |
71 // writer->writeAttribute(convertor.from_bytes(symbol->xml())); |
75 // writer->writeAttribute(convertor.from_bytes(symbol->xml())); |
72 |
76 |
92 writer->writeAttribute(&minY, typeid (minY)); |
96 writer->writeAttribute(&minY, typeid (minY)); |
93 writer->writeAttribute(&width, typeid (width)); |
97 writer->writeAttribute(&width, typeid (width)); |
94 writer->writeAttribute(&height, typeid (height)); |
98 writer->writeAttribute(&height, typeid (height)); |
95 } |
99 } |
96 |
100 |
|
101 if (configuration.listPolygonPoints) { |
|
102 relpipe::common::type::Integer id = 0; |
|
103 |
|
104 writer->startRelation(L"polygon_point",{ |
|
105 {L"symbol", relpipe::writer::TypeId::INTEGER}, |
|
106 {L"point", relpipe::writer::TypeId::INTEGER}, |
|
107 {L"x", relpipe::writer::TypeId::INTEGER}, |
|
108 {L"y", relpipe::writer::TypeId::INTEGER}, |
|
109 }, true); |
|
110 |
|
111 for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol, id++) { |
|
112 for (relpipe::common::type::Integer i = 0, locationSize = symbol->get_location_size(); i < locationSize; i++) { |
|
113 relpipe::common::type::Integer x = symbol->get_location_x(i); |
|
114 relpipe::common::type::Integer y = symbol->get_location_y(i); |
|
115 writer->writeAttribute(&id, typeid (id)); |
|
116 writer->writeAttribute(&i, typeid (i)); |
|
117 writer->writeAttribute(&x, typeid (x)); |
|
118 writer->writeAttribute(&y, typeid (y)); |
|
119 } |
|
120 } |
|
121 } |
|
122 |
97 image.set_data(nullptr, 0); |
123 image.set_data(nullptr, 0); |
98 } |
124 } |
99 }; |
125 }; |
100 |
126 |
101 } |
127 } |