From c35ca6492e0c8050f316faa0aa7ceb8bdf13a9f6 Mon Sep 17 00:00:00 2001 From: Elnur Ismailzada Date: Fri, 17 May 2019 00:43:11 +0200 Subject: [PATCH] simultaneous recognition UPC/EAN and UPC_EAN_EXTENCION --- src/QZXing.cpp | 12 ++++++++++++ src/zxing/zxing/DecodeHints.cpp | 17 +++++++++++++++++ src/zxing/zxing/DecodeHints.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/src/QZXing.cpp b/src/QZXing.cpp index 522b170..8cd15c6 100644 --- a/src/QZXing.cpp +++ b/src/QZXing.cpp @@ -422,6 +422,18 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo lastDecodeOperationSucceded_ = true; } catch(zxing::Exception &/*e*/) {} + if (!lastDecodeOperationSucceded_ && + hints.containsFormat(BarcodeFormat::UPC_EAN_EXTENSION) && + !(hints & DecodeHints::PRODUCT_HINT).isEmpty() ) { + hints.setAllowedEanExtensions(std::set()); + + try { + res = decoder->decode(bb, hints); + processingTime = t.elapsed(); + lastDecodeOperationSucceded_ = true; + } catch(zxing::Exception &/*e*/) {} + } + if (tryHarder_ && bb->isRotateSupported()) { Ref bbTmp = bb; diff --git a/src/zxing/zxing/DecodeHints.cpp b/src/zxing/zxing/DecodeHints.cpp index 63b9c62..3c358ce 100644 --- a/src/zxing/zxing/DecodeHints.cpp +++ b/src/zxing/zxing/DecodeHints.cpp @@ -189,3 +189,20 @@ zxing::DecodeHints zxing::operator | (DecodeHints const& l, DecodeHints const& r return result; } + +zxing::DecodeHints zxing::operator & (DecodeHints const& l, DecodeHints const& r) { + DecodeHints result (l); + result.hints &= r.hints; + if (!result.callback) { + result.callback = r.callback; + } + + std::set intersect; + std::set_intersection(l.allowedEanExtensions.begin(), l.allowedEanExtensions.end(), + r.allowedEanExtensions.begin(), r.allowedEanExtensions.end(), + std::inserter(intersect, intersect.begin())); + + result.allowedEanExtensions = intersect; + + return result; +} diff --git a/src/zxing/zxing/DecodeHints.h b/src/zxing/zxing/DecodeHints.h index f5261b4..b24e349 100644 --- a/src/zxing/zxing/DecodeHints.h +++ b/src/zxing/zxing/DecodeHints.h @@ -30,6 +30,7 @@ namespace zxing { typedef unsigned int DecodeHintType; class DecodeHints; DecodeHints operator | (DecodeHints const&, DecodeHints const&); +DecodeHints operator & (DecodeHints const&, DecodeHints const&); class DecodeHints { private: @@ -87,6 +88,7 @@ class DecodeHints { DecodeHints& operator =(DecodeHints const &other); friend DecodeHints operator| (DecodeHints const&, DecodeHints const&); + friend DecodeHints operator& (DecodeHints const&, DecodeHints const&); }; }