src/QRCommand.h
branchv_0
changeset 1 79d699ed88ab
parent 0 0a0cb749c10f
child 2 6cc693048318
equal deleted inserted replaced
0:0a0cb749c10f 1:79d699ed88ab
    20 #include <memory>
    20 #include <memory>
    21 #include <algorithm>
    21 #include <algorithm>
    22 #include <iostream>
    22 #include <iostream>
    23 #include <stdexcept>
    23 #include <stdexcept>
    24 
    24 
       
    25 #include <Magick++.h>
    25 #include <zbar.h>
    26 #include <zbar.h>
    26 
    27 
    27 #include "Configuration.h"
    28 #include "Configuration.h"
    28 
    29 
    29 namespace relpipe {
    30 namespace relpipe {
    30 namespace in {
    31 namespace in {
    31 namespace qr {
    32 namespace qr {
    32 
    33 
    33 class QRCommand {
    34 class QRCommand {
    34 	std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: use platform encoding as default
    35 	std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: use platform encoding as default / check zbar encoding
    35 
    36 
    36 
    37 
    37 public:
    38 public:
    38 
    39 
    39 	void process(Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) {
    40 	void process(Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) {
    40 
    41 
    41 		zbar::Image image;
    42 		Magick::Image magick("/dev/stdin");
       
    43 		int width = magick.columns();
       
    44 		int height = magick.rows();
       
    45 		Magick::Blob blob;
       
    46 		magick.modifyImage();
       
    47 		magick.write(&blob, "GRAY", 8);
       
    48 		const void *raw = blob.data();
       
    49 
       
    50 		zbar::Image image(width, height, "Y800", raw, width * height);
    42 		zbar::ImageScanner scanner;
    51 		zbar::ImageScanner scanner;
    43 
    52 
    44 		writer->startRelation(L"qr",{
    53 		writer->startRelation(L"qr",{
    45 			{L"value", relpipe::writer::TypeId::STRING}
    54 			{L"type", relpipe::writer::TypeId::STRING},
       
    55 			// {L"addon_name", relpipe::writer::TypeId::STRING},
       
    56 			{L"value", relpipe::writer::TypeId::STRING},
       
    57 			// {L"xml", relpipe::writer::TypeId::STRING},
       
    58 			{L"location_size", relpipe::writer::TypeId::INTEGER},
       
    59 			{L"x_1", relpipe::writer::TypeId::INTEGER},
       
    60 			{L"y_1", relpipe::writer::TypeId::INTEGER},
       
    61 			{L"x_2", relpipe::writer::TypeId::INTEGER},
       
    62 			{L"y_2", relpipe::writer::TypeId::INTEGER},
       
    63 			{L"x_3", relpipe::writer::TypeId::INTEGER},
       
    64 			{L"y_3", relpipe::writer::TypeId::INTEGER},
       
    65 			{L"x_4", relpipe::writer::TypeId::INTEGER},
       
    66 			{L"y_4", relpipe::writer::TypeId::INTEGER},
    46 		}, true);
    67 		}, true);
    47 
    68 
    48 		writer->writeAttribute(L"some");
    69 		int n = scanner.scan(image);
    49 		writer->writeAttribute(L"qr");
    70 
    50 		writer->writeAttribute(L"codes");
    71 		for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) {
       
    72 			writer->writeAttribute(convertor.from_bytes(symbol->get_type_name()));
       
    73 			// writer->writeAttribute(convertor.from_bytes(symbol->get_addon_name()));
       
    74 			writer->writeAttribute(convertor.from_bytes(symbol->get_data()));
       
    75 			// writer->writeAttribute(convertor.from_bytes(symbol->xml()));
       
    76 
       
    77 			relpipe::common::type::Integer locationSize = symbol->get_location_size();
       
    78 			writer->writeAttribute(&locationSize, typeid (locationSize));
       
    79 			
       
    80 			for (int i = 0; i < 4; i++) {
       
    81 				relpipe::common::type::Integer x = -5;
       
    82 				relpipe::common::type::Integer y = -6;
       
    83 				if (i < locationSize) {
       
    84 					x = symbol->get_location_x(i);
       
    85 					y = symbol->get_location_y(i);
       
    86 				}
       
    87 				writer->writeAttribute(&x, typeid (x));
       
    88 				writer->writeAttribute(&y, typeid (y));
       
    89 			}
    51 
    90 
    52 
    91 
       
    92 		}
       
    93 
       
    94 		image.set_data(nullptr, 0);
    53 	}
    95 	}
    54 };
    96 };
    55 
    97 
    56 }
    98 }
    57 }
    99 }