# HG changeset patch # User František Kučera # Date 1619884780 -7200 # Node ID 8f434dc384445309cbd8c86f01d0c80ad03669d6 # Parent 500ce0b934e78aabf0223da7086e88c039d28561 rename: qr → barcode diff -r 500ce0b934e7 -r 8f434dc38444 CMakeLists.txt --- a/CMakeLists.txt Fri Apr 16 23:18:03 2021 +0200 +++ b/CMakeLists.txt Sat May 01 17:59:40 2021 +0200 @@ -13,6 +13,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -project (relpipe-in-qr.cpp) +project (relpipe-in-barcode.cpp) cmake_minimum_required(VERSION 3.7.2) add_subdirectory (src) diff -r 500ce0b934e7 -r 8f434dc38444 bash-completion.sh --- a/bash-completion.sh Fri Apr 16 23:18:03 2021 +0200 +++ b/bash-completion.sh Sat May 01 17:59:40 2021 +0200 @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -_relpipe_in_qr_completion() { +_relpipe_in_barcode_completion() { local w0 w1 w2 w3 COMPREPLY=() @@ -36,4 +36,4 @@ fi } -complete -F _relpipe_in_qr_completion relpipe-in-qr +complete -F _relpipe_in_barcode_completion relpipe-in-barcode diff -r 500ce0b934e7 -r 8f434dc38444 nbproject/configurations.xml --- a/nbproject/configurations.xml Fri Apr 16 23:18:03 2021 +0200 +++ b/nbproject/configurations.xml Sat May 01 17:59:40 2021 +0200 @@ -42,8 +42,8 @@ - QRCommand.h - relpipe-in-qr.cpp + BarcodeCommand.h + relpipe-in-barcode.cpp true - + @@ -133,7 +133,7 @@ true - + diff -r 500ce0b934e7 -r 8f434dc38444 nbproject/project.xml --- a/nbproject/project.xml Fri Apr 16 23:18:03 2021 +0200 +++ b/nbproject/project.xml Sat May 01 17:59:40 2021 +0200 @@ -3,7 +3,7 @@ org.netbeans.modules.cnd.makeproject - relpipe-in-qr.cpp + relpipe-in-barcode.cpp cpp h diff -r 500ce0b934e7 -r 8f434dc38444 src/BarcodeCommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/BarcodeCommand.h Sat May 01 17:59:40 2021 +0200 @@ -0,0 +1,129 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +#include "Configuration.h" + +namespace relpipe { +namespace in { +namespace barcode { + +class BarcodeCommand { +private: + 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) { + + // TODO: require PNM input and get rid off the ImageMagick dependency? + 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"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}, + // {L"xml", relpipe::writer::TypeId::STRING}, + {L"x", relpipe::writer::TypeId::INTEGER}, + {L"y", relpipe::writer::TypeId::INTEGER}, + {L"width", relpipe::writer::TypeId::INTEGER}, + {L"height", relpipe::writer::TypeId::INTEGER}, + }, true); + + int n = scanner.scan(image); + + 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())); + // writer->writeAttribute(convertor.from_bytes(symbol->xml())); + + relpipe::common::type::Integer minX = 0; + relpipe::common::type::Integer minY = 0; + relpipe::common::type::Integer maxX = 0; + relpipe::common::type::Integer maxY = 0; + + // TODO: return original polygon in XML + for (int 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); + minX = minX ? std::min(minX, x) : x; + minY = minY ? std::min(minY, y) : y; + maxX = std::max(maxX, x); + maxY = std::max(maxY, y); + } + + relpipe::common::type::Integer width = maxX - minX; + relpipe::common::type::Integer height = maxY - minY; + + writer->writeAttribute(&minX, typeid (minX)); + writer->writeAttribute(&minY, typeid (minY)); + writer->writeAttribute(&width, typeid (width)); + 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); + } +}; + +} +} +} diff -r 500ce0b934e7 -r 8f434dc38444 src/CLIParser.h --- a/src/CLIParser.h Fri Apr 16 23:18:03 2021 +0200 +++ b/src/CLIParser.h Sat May 01 17:59:40 2021 +0200 @@ -27,7 +27,7 @@ namespace relpipe { namespace in { -namespace qr { +namespace barcode { class CLIParser { private: diff -r 500ce0b934e7 -r 8f434dc38444 src/CMakeLists.txt --- a/src/CMakeLists.txt Fri Apr 16 23:18:03 2021 +0200 +++ b/src/CMakeLists.txt Sat May 01 17:59:40 2021 +0200 @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -set(EXECUTABLE_FILE "relpipe-in-qr") +set(EXECUTABLE_FILE "relpipe-in-barcode") # Relpipe libraries: INCLUDE(FindPkgConfig) @@ -29,7 +29,7 @@ # Executable output: add_executable( ${EXECUTABLE_FILE} - relpipe-in-qr.cpp + relpipe-in-barcode.cpp ) add_definitions (${RELPIPE_LIBS_CFLAGS_OTHER}) diff -r 500ce0b934e7 -r 8f434dc38444 src/Configuration.h --- a/src/Configuration.h Fri Apr 16 23:18:03 2021 +0200 +++ b/src/Configuration.h Sat May 01 17:59:40 2021 +0200 @@ -24,7 +24,7 @@ namespace relpipe { namespace in { -namespace qr { +namespace barcode { class Configuration { public: diff -r 500ce0b934e7 -r 8f434dc38444 src/QRCommand.h --- a/src/QRCommand.h Fri Apr 16 23:18:03 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/** - * Relational pipes - * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#include -#include -#include -#include -#include - -#include -#include - -#include "Configuration.h" - -namespace relpipe { -namespace in { -namespace qr { - -class QRCommand { -private: - 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) { - - // TODO: require PNM input and get rid off the ImageMagick dependency? - 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"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}, - // {L"xml", relpipe::writer::TypeId::STRING}, - {L"x", relpipe::writer::TypeId::INTEGER}, - {L"y", relpipe::writer::TypeId::INTEGER}, - {L"width", relpipe::writer::TypeId::INTEGER}, - {L"height", relpipe::writer::TypeId::INTEGER}, - }, true); - - int n = scanner.scan(image); - - 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())); - // writer->writeAttribute(convertor.from_bytes(symbol->xml())); - - relpipe::common::type::Integer minX = 0; - relpipe::common::type::Integer minY = 0; - relpipe::common::type::Integer maxX = 0; - relpipe::common::type::Integer maxY = 0; - - // TODO: return original polygon in XML - for (int 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); - minX = minX ? std::min(minX, x) : x; - minY = minY ? std::min(minY, y) : y; - maxX = std::max(maxX, x); - maxY = std::max(maxY, y); - } - - relpipe::common::type::Integer width = maxX - minX; - relpipe::common::type::Integer height = maxY - minY; - - writer->writeAttribute(&minX, typeid (minX)); - writer->writeAttribute(&minY, typeid (minY)); - writer->writeAttribute(&width, typeid (width)); - 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); - } -}; - -} -} -} diff -r 500ce0b934e7 -r 8f434dc38444 src/relpipe-in-barcode.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/relpipe-in-barcode.cpp Sat May 01 17:59:40 2021 +0200 @@ -0,0 +1,63 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "CLIParser.h" +#include "Configuration.h" + +#include "BarcodeCommand.h" + +using namespace relpipe::cli; +using namespace relpipe::in::barcode; +using namespace relpipe::writer; + +int main(int argc, char** argv) { + setlocale(LC_ALL, ""); + CLI::untieStdIO(); + CLI cli(argc, argv); + + int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; + + try { + CLIParser cliParser; + Configuration configuration = cliParser.parse(cli.arguments()); + BarcodeCommand command; + std::shared_ptr writer(Factory::create(std::cout)); + command.process(configuration, writer, std::bind(fflush, stdout)); // std::bind(fflush, XXX) Factory::create(XXX) must be the same stream XXX + resultCode = CLI::EXIT_CODE_SUCCESS; + } catch (RelpipeWriterException& e) { + fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str()); + fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); + resultCode = CLI::EXIT_CODE_DATA_ERROR; + } catch (RelpipeCLIException& e) { + fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); + fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); + resultCode = e.getExitCode(); + } + + return resultCode; +} diff -r 500ce0b934e7 -r 8f434dc38444 src/relpipe-in-qr.cpp --- a/src/relpipe-in-qr.cpp Fri Apr 16 23:18:03 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/** - * Relational pipes - * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include "CLIParser.h" -#include "Configuration.h" - -#include "QRCommand.h" - -using namespace relpipe::cli; -using namespace relpipe::in::qr; -using namespace relpipe::writer; - -int main(int argc, char** argv) { - setlocale(LC_ALL, ""); - CLI::untieStdIO(); - CLI cli(argc, argv); - - int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; - - try { - CLIParser cliParser; - Configuration configuration = cliParser.parse(cli.arguments()); - QRCommand command; - std::shared_ptr writer(Factory::create(std::cout)); - command.process(configuration, writer, std::bind(fflush, stdout)); // std::bind(fflush, XXX) Factory::create(XXX) must be the same stream XXX - resultCode = CLI::EXIT_CODE_SUCCESS; - } catch (RelpipeWriterException& e) { - fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str()); - fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); - resultCode = CLI::EXIT_CODE_DATA_ERROR; - } catch (RelpipeCLIException& e) { - fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); - fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); - resultCode = e.getExitCode(); - } - - return resultCode; -}