# HG changeset patch # User František Kučera # Date 1618426578 -7200 # Node ID 79d699ed88ab9d66baa48beff9a13fdf6459ece1 # Parent 0a0cb749c10f845fddae67d711468a0424167a13 dirty and buggy first version diff -r 0a0cb749c10f -r 79d699ed88ab nbproject/configurations.xml --- a/nbproject/configurations.xml Wed Apr 14 19:01:54 2021 +0200 +++ b/nbproject/configurations.xml Wed Apr 14 20:56:18 2021 +0200 @@ -82,6 +82,8 @@ ../relpipe-lib-writer.cpp/include ../relpipe-lib-common.cpp/include ../relpipe-lib-cli.cpp/include + /usr/include/x86_64-linux-gnu/ImageMagick-6 + /usr/include/ImageMagick-6 build/Debug/src diff -r 0a0cb749c10f -r 79d699ed88ab src/CMakeLists.txt --- a/src/CMakeLists.txt Wed Apr 14 19:01:54 2021 +0200 +++ b/src/CMakeLists.txt Wed Apr 14 20:56:18 2021 +0200 @@ -17,7 +17,7 @@ # Relpipe libraries: INCLUDE(FindPkgConfig) -pkg_check_modules (RELPIPE_LIBS relpipe-lib-writer.cpp relpipe-lib-cli.cpp zbar) +pkg_check_modules (RELPIPE_LIBS relpipe-lib-writer.cpp relpipe-lib-cli.cpp zbar Magick++) include_directories(${RELPIPE_LIBS_INCLUDE_DIRS}) link_directories(${RELPIPE_LIBS_LIBRARY_DIRS}) diff -r 0a0cb749c10f -r 79d699ed88ab src/QRCommand.h --- a/src/QRCommand.h Wed Apr 14 19:01:54 2021 +0200 +++ b/src/QRCommand.h Wed Apr 14 20:56:18 2021 +0200 @@ -22,6 +22,7 @@ #include #include +#include #include #include "Configuration.h" @@ -31,25 +32,66 @@ namespace qr { class QRCommand { - std::wstring_convert> convertor; // TODO: use platform encoding as default + std::wstring_convert> convertor; // TODO: use platform encoding as default / check zbar encoding public: void process(Configuration& configuration, std::shared_ptr writer, std::function relationalWriterFlush) { - zbar::Image image; + Magick::Image magick("/dev/stdin"); + int width = magick.columns(); + int height = magick.rows(); + Magick::Blob blob; + magick.modifyImage(); + magick.write(&blob, "GRAY", 8); + const void *raw = blob.data(); + + zbar::Image image(width, height, "Y800", raw, width * height); zbar::ImageScanner scanner; writer->startRelation(L"qr",{ - {L"value", relpipe::writer::TypeId::STRING} + {L"type", relpipe::writer::TypeId::STRING}, + // {L"addon_name", relpipe::writer::TypeId::STRING}, + {L"value", relpipe::writer::TypeId::STRING}, + // {L"xml", relpipe::writer::TypeId::STRING}, + {L"location_size", relpipe::writer::TypeId::INTEGER}, + {L"x_1", relpipe::writer::TypeId::INTEGER}, + {L"y_1", relpipe::writer::TypeId::INTEGER}, + {L"x_2", relpipe::writer::TypeId::INTEGER}, + {L"y_2", relpipe::writer::TypeId::INTEGER}, + {L"x_3", relpipe::writer::TypeId::INTEGER}, + {L"y_3", relpipe::writer::TypeId::INTEGER}, + {L"x_4", relpipe::writer::TypeId::INTEGER}, + {L"y_4", relpipe::writer::TypeId::INTEGER}, }, true); - writer->writeAttribute(L"some"); - writer->writeAttribute(L"qr"); - writer->writeAttribute(L"codes"); + int n = scanner.scan(image); + + for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) { + writer->writeAttribute(convertor.from_bytes(symbol->get_type_name())); + // writer->writeAttribute(convertor.from_bytes(symbol->get_addon_name())); + writer->writeAttribute(convertor.from_bytes(symbol->get_data())); + // writer->writeAttribute(convertor.from_bytes(symbol->xml())); + + relpipe::common::type::Integer locationSize = symbol->get_location_size(); + writer->writeAttribute(&locationSize, typeid (locationSize)); + + for (int i = 0; i < 4; i++) { + relpipe::common::type::Integer x = -5; + relpipe::common::type::Integer y = -6; + if (i < locationSize) { + x = symbol->get_location_x(i); + y = symbol->get_location_y(i); + } + writer->writeAttribute(&x, typeid (x)); + writer->writeAttribute(&y, typeid (y)); + } + } + + image.set_data(nullptr, 0); } };