KItinerary

barcodedecoder.h
1 /*
2  SPDX-FileCopyrightText: 2018-2019 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KITINERARY_BARCODEDECODER_H
8 #define KITINERARY_BARCODEDECODER_H
9 
10 #include "kitinerary_export.h"
11 
12 #include <QFlags>
13 #include <QVariant>
14 
15 #include <unordered_map>
16 
17 class QByteArray;
18 class QImage;
19 class QString;
20 
21 namespace KItinerary {
22 
31 class KITINERARY_EXPORT BarcodeDecoder
32 {
33 public:
35  ~BarcodeDecoder();
36 
37  enum BarcodeType {
38  Aztec = 1,
39  QRCode = 2,
40  PDF417 = 4,
41  DataMatrix = 8,
42  Any = 15,
43  AnySquare = 11,
44  None = 0
45  };
46  Q_DECLARE_FLAGS(BarcodeTypes, BarcodeType)
47 
48 
49  bool isBarcode(const QImage &img, BarcodeTypes hint = Any) const;
50 
52  QByteArray decodeBinary(const QImage &img, BarcodeTypes hint = Any) const;
53 
55  QString decodeString(const QImage &img, BarcodeTypes hint = Any) const;
56 
58  void clearCache();
59 
65  static bool isPlausibleSize(int width, int height);
66 
70  static bool isPlausibleAspectRatio(int width, int height, BarcodeTypes hint = Any);
71 
73  static bool maybeBarcode(int width, int height, BarcodeTypes hint = Any);
74 
75 private:
76  struct Result {
77  BarcodeTypes positive = BarcodeDecoder::None;
78  BarcodeTypes negative = BarcodeDecoder::None;
79  enum ContentType {
80  None = 0,
81  ByteArray = 1,
82  String = 2,
83  Any = 3
84  };
85  int contentType = None;
86  QVariant content;
87  };
88 
89  void decodeIfNeeded(const QImage &img, BarcodeTypes hint, Result &result) const;
90  void decodeZxing(const QImage &img, BarcodeDecoder::BarcodeTypes format, BarcodeDecoder::Result &result) const;
91 
92  mutable std::unordered_map<qint64, Result> m_cache;
93 };
94 
95 }
96 
97 Q_DECLARE_OPERATORS_FOR_FLAGS(KItinerary::BarcodeDecoder::BarcodeTypes)
98 
99 #endif // KITINERARY_BARCODEDECODER_H
Barcode decoding with result caching.
Classes for reservation/travel data models, data extraction and data augmentation.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 5 2020 23:14:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.