Prison

imagescanner.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: MIT
4*/
5
6#include "config-prison-scanner.h"
7
8#include "imagescanner.h"
9#include "format.h"
10#include "format_p.h"
11#include "imagescanner_p.h"
12#include "scanresult.h"
13#include "scanresult_p.h"
14
15#include <QImage>
16
17#define ZX_USE_UTF8 1
18#include <ZXing/BarcodeFormat.h>
19#include <ZXing/ReadBarcode.h>
20#include <ZXing/Result.h>
21
22using namespace Prison;
23
24ZXing::Result ImageScanner::readBarcode(const QImage &image, Format::BarcodeFormats formats)
25{
26 ZXing::DecodeHints hints;
27 hints.setFormats(formats == Format::NoFormat ? ZXing::BarcodeFormats::all() : Format::toZXing(formats));
28
29 // handle formats ZXing supports directly
30 switch (image.format()) {
32#if ZXING_VERSION < QT_VERSION_CHECK(1, 4, 0)
33 return ZXing::Result(ZXing::DecodeStatus::FormatError);
34#else
35 return {};
36#endif
40 break; // needs conversion
44 return ZXing::ReadBarcode({image.bits(), image.width(), image.height(), ZXing::ImageFormat::XRGB, (int)image.bytesPerLine()}, hints);
51 break; // needs conversion
53 return ZXing::ReadBarcode({image.bits(), image.width(), image.height(), ZXing::ImageFormat::RGB, (int)image.bytesPerLine()}, hints);
56 break; // needs conversion
60 return ZXing::ReadBarcode({image.bits(), image.width(), image.height(), ZXing::ImageFormat::RGBX, (int)image.bytesPerLine()}, hints);
65 break; // needs conversion
67#if ZXING_VERSION < QT_VERSION_CHECK(1, 4, 0)
68 return ZXing::Result(ZXing::DecodeStatus::FormatError);
69#else
70 return {};
71#endif
73 return ZXing::ReadBarcode({image.bits(), image.width(), image.height(), ZXing::ImageFormat::Lum, (int)image.bytesPerLine()}, hints);
75 return ZXing::ReadBarcode({image.bits() + 1, image.width(), image.height(), ZXing::ImageFormat::Lum, (int)image.bytesPerLine(), 1}, hints);
79 break; // needs conversion
81 return ZXing::ReadBarcode({image.bits(), image.width(), image.height(), ZXing::ImageFormat::BGR, (int)image.bytesPerLine()}, hints);
88 break; // needs conversion
89
90 case QImage::NImageFormats: // silence warnings
91#if ZXING_VERSION < QT_VERSION_CHECK(1, 4, 0)
92 return ZXing::Result(ZXing::DecodeStatus::FormatError);
93#else
94 return {};
95#endif
96 }
97
98 const auto converted = image.convertedTo(QImage::Format_Grayscale8);
99 return ZXing::ReadBarcode({converted.bits(), converted.width(), converted.height(), ZXing::ImageFormat::Lum, (int)converted.bytesPerLine()}, hints);
100}
101
103{
104 return ScanResultPrivate::fromZXingResult(ImageScanner::readBarcode(image, formats));
105}
Result of a barcode scan attempt.
Definition scanresult.h:31
PRISONSCANNER_EXPORT ScanResult scan(const QImage &image, Format::BarcodeFormats formats={})
Scan image for a barcode.
Provides classes and methods for generating barcodes.
Definition barcode.h:24
uchar * bits()
qsizetype bytesPerLine() const const
QImage convertedTo(Format format, Qt::ImageConversionFlags flags) &&
Format format() const const
int height() const const
int width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.