# HG changeset patch # User František Kučera # Date 1618607883 -7200 # Node ID 500ce0b934e78aabf0223da7086e88c039d28561 # Parent 18bb23fc811fa903073ba9990e7c1b4327e741a7 optional listing of polygon points (more accurate than rectangular box, but requires separate relation): --list-polygon-points diff -r 18bb23fc811f -r 500ce0b934e7 bash-completion.sh --- a/bash-completion.sh Thu Apr 15 20:45:10 2021 +0200 +++ b/bash-completion.sh Fri Apr 16 23:18:03 2021 +0200 @@ -27,12 +27,10 @@ "false" ) - if [[ "$w1" == "--list-xxx" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) - elif [[ "$w1" == "--list-zzz" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) + if [[ "$w1" == "--list-polygon-points" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) else OPTIONS=( - "--list-xxx" - "--list-zzz" + "--list-polygon-points" ) COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) fi diff -r 18bb23fc811f -r 500ce0b934e7 src/CLIParser.h --- a/src/CLIParser.h Thu Apr 15 20:45:10 2021 +0200 +++ b/src/CLIParser.h Fri Apr 16 23:18:03 2021 +0200 @@ -48,7 +48,7 @@ public: - static const relpipe::common::type::StringX OPTION_LIST_XXX; + static const relpipe::common::type::StringX OPTION_LIST_POLYGON_POINTS; static const relpipe::common::type::StringX OPTION_LIST_ZZZ; Configuration parse(const std::vector& arguments) { @@ -57,10 +57,8 @@ for (int i = 0; i < arguments.size();) { relpipe::common::type::StringX option = readNext(arguments, i); - if (option == OPTION_LIST_XXX) { - c.listXXX = parseBoolean(readNext(arguments, i)); - } else if (option == OPTION_LIST_ZZZ) { - c.listZZZ = parseBoolean(readNext(arguments, i)); + if (option == OPTION_LIST_POLYGON_POINTS) { + c.listPolygonPoints = parseBoolean(readNext(arguments, i)); } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); } @@ -71,8 +69,7 @@ } }; -const relpipe::common::type::StringX CLIParser::OPTION_LIST_XXX = L"--list-xxx"; -const relpipe::common::type::StringX CLIParser::OPTION_LIST_ZZZ = L"--list-zzz"; +const relpipe::common::type::StringX CLIParser::OPTION_LIST_POLYGON_POINTS = L"--list-polygon-points"; } } diff -r 18bb23fc811f -r 500ce0b934e7 src/Configuration.h --- a/src/Configuration.h Thu Apr 15 20:45:10 2021 +0200 +++ b/src/Configuration.h Fri Apr 16 23:18:03 2021 +0200 @@ -28,8 +28,7 @@ class Configuration { public: - bool listXXX = false; - bool listZZZ = false; + bool listPolygonPoints = false; virtual ~Configuration() { } diff -r 18bb23fc811f -r 500ce0b934e7 src/QRCommand.h --- a/src/QRCommand.h Thu Apr 15 20:45:10 2021 +0200 +++ b/src/QRCommand.h Fri Apr 16 23:18:03 2021 +0200 @@ -40,6 +40,7 @@ void process(Configuration& configuration, std::shared_ptr writer, std::function relationalWriterFlush) { + // TODO: require PNM input and get rid off the ImageMagick dependency? Magick::Image magick("/dev/stdin"); int width = magick.columns(); int height = magick.rows(); @@ -51,7 +52,8 @@ zbar::Image image(width, height, "Y800", raw, width * height); zbar::ImageScanner scanner; - writer->startRelation(L"qr",{ + writer->startRelation(L"symbol",{ + {L"id", relpipe::writer::TypeId::INTEGER}, {L"type", relpipe::writer::TypeId::STRING}, // {L"addon_name", relpipe::writer::TypeId::STRING}, {L"value", relpipe::writer::TypeId::STRING}, @@ -64,7 +66,9 @@ int n = scanner.scan(image); - for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) { + relpipe::common::type::Integer id = 0; + for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol, id++) { + writer->writeAttribute(&id, typeid (id)); 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())); @@ -94,6 +98,28 @@ writer->writeAttribute(&height, typeid (height)); } + if (configuration.listPolygonPoints) { + relpipe::common::type::Integer id = 0; + + writer->startRelation(L"polygon_point",{ + {L"symbol", relpipe::writer::TypeId::INTEGER}, + {L"point", relpipe::writer::TypeId::INTEGER}, + {L"x", relpipe::writer::TypeId::INTEGER}, + {L"y", relpipe::writer::TypeId::INTEGER}, + }, true); + + for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol, id++) { + for (relpipe::common::type::Integer i = 0, locationSize = symbol->get_location_size(); i < locationSize; i++) { + relpipe::common::type::Integer x = symbol->get_location_x(i); + relpipe::common::type::Integer y = symbol->get_location_y(i); + writer->writeAttribute(&id, typeid (id)); + writer->writeAttribute(&i, typeid (i)); + writer->writeAttribute(&x, typeid (x)); + writer->writeAttribute(&y, typeid (y)); + } + } + } + image.set_data(nullptr, 0); } };