KItinerary

pdfbarcodeutil.cpp
1/*
2 SPDX-FileCopyrightText: 2018-2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "pdfbarcodeutil_p.h"
8#include "pdfimage.h"
9
10using namespace KItinerary;
11
12enum {
13 // unit is 1/72 inch, assuming landscape orientation
14 MinTargetImageHeight2D = 28,
15 MinTargetImageHeight1D = 20,
16 MinTargetImageWidth = 36,
17 MaxTargetImageHeight = 252,
18 MaxTargetImageWidth2D = 252,
19 MaxTargetImageWidth1D = 272,
20 // vector path complexity limits
21 MinPathElementCount2D = 200,
22 MaxPathElementCount2D = 20000, // ÖBB got creative with vector barcodes...
23 MinPathElementCount1D = 150,
24 MaxPathElementCount1D = 400,
25};
26
27BarcodeDecoder::BarcodeTypes PdfBarcodeUtil::maybeBarcode(const PdfImage &img, BarcodeDecoder::BarcodeTypes hint)
28{
29 const auto w = img.width();
30 const auto h = img.height();
31
32 // image target size checks
33 if (std::max(w, h) < MinTargetImageWidth || std::min(w, h) > MaxTargetImageHeight) {
34 return BarcodeDecoder::None;
35 }
36
37 if (std::max(w, h) > MaxTargetImageWidth2D || std::min(w, h) < MinTargetImageHeight2D) {
38 hint &= ~BarcodeDecoder::Any2D;
39 }
40 if (std::max(w, h) > MaxTargetImageWidth1D || std::min(w, h) < MinTargetImageHeight1D) {
41 hint &= ~BarcodeDecoder::Any1D;
42 }
43
46
47 if (img.isVectorImage()) {
48 hint = isPlausiblePath(img.pathElementsCount(), hint);
49 }
50
51 return hint;
52}
53
54BarcodeDecoder::BarcodeTypes PdfBarcodeUtil::isPlausiblePath(int elementCount, BarcodeDecoder::BarcodeTypes hint)
55{
56 if (elementCount < MinPathElementCount2D || elementCount > MaxPathElementCount2D) {
57 hint &= ~BarcodeDecoder::Any2D;
58 }
59 if (elementCount < MinPathElementCount1D || elementCount > MaxPathElementCount1D) {
60 hint &= ~BarcodeDecoder::Any1D;
61 }
62 return hint;
63}
Barcode decoding with result caching.
static BarcodeTypes isPlausibleSize(int width, int height, BarcodeTypes hint)
Checks if the given image dimensions are plausible for a barcode.
static BarcodeTypes isPlausibleAspectRatio(int width, int height, BarcodeTypes hint)
Checks if the given image dimensions are a barcode of type hint.
An image in a PDF document.
Definition pdfimage.h:74
int pathElementsCount() const
If this is a vector image, this returns the number of vector path elemets.
Definition pdfimage.cpp:209
bool isVectorImage() const
Returns whether this is a raster or vector image.
Definition pdfimage.cpp:204
int sourceWidth() const
Width of the source image.
Definition pdfimage.cpp:168
int sourceHeight() const
Height of the source image.
Definition pdfimage.cpp:163
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:00:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.