mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-18 20:50:09 +08:00
feat: detect multiple QR codes at once (#396)
* Replace zxing-cpp with quirc * fix * fix * Update CMakeLists.txt * Detect multiple QR codes at once
This commit is contained in:
parent
759615e0c1
commit
95d12f9556
15
3rdparty/QrDecoder.cpp
vendored
15
3rdparty/QrDecoder.cpp
vendored
@ -12,22 +12,23 @@ QrDecoder::~QrDecoder()
|
||||
quirc_destroy(m_qr);
|
||||
}
|
||||
|
||||
QString QrDecoder::decode(const QImage &image)
|
||||
QVector<QString> QrDecoder::decode(const QImage &image)
|
||||
{
|
||||
QVector<QString> result;
|
||||
if (m_qr == nullptr)
|
||||
{
|
||||
return "";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (quirc_resize(m_qr, image.width(), image.height()) < 0)
|
||||
{
|
||||
return "";
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t *rawImage = quirc_begin(m_qr, nullptr, nullptr);
|
||||
if (rawImage == nullptr)
|
||||
{
|
||||
return "";
|
||||
return result;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||
std::copy(image.constBits(), image.constBits() + image.sizeInBytes(), rawImage);
|
||||
@ -39,7 +40,7 @@ QString QrDecoder::decode(const QImage &image)
|
||||
const int count = quirc_count(m_qr);
|
||||
if (count < 0)
|
||||
{
|
||||
return "";
|
||||
return result;
|
||||
}
|
||||
|
||||
for (int index = 0; index < count; ++index)
|
||||
@ -51,9 +52,9 @@ QString QrDecoder::decode(const QImage &image)
|
||||
const quirc_decode_error_t err = quirc_decode(&code, &data);
|
||||
if (err == QUIRC_SUCCESS)
|
||||
{
|
||||
return QLatin1String((const char *)data.payload);
|
||||
result.append(QLatin1String((const char *)data.payload));
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
return result;
|
||||
}
|
||||
|
||||
2
3rdparty/QrDecoder.h
vendored
2
3rdparty/QrDecoder.h
vendored
@ -11,7 +11,7 @@ public:
|
||||
QrDecoder();
|
||||
~QrDecoder();
|
||||
|
||||
QString decode(const QImage &image);
|
||||
QVector<QString> decode(const QImage &image);
|
||||
|
||||
private:
|
||||
quirc *m_qr;
|
||||
|
||||
@ -1752,14 +1752,16 @@ void MainWindow::on_menu_scan_qr_triggered() {
|
||||
|
||||
show();
|
||||
if (ok) {
|
||||
const QString text = QrDecoder().decode(qpx.toImage().convertToFormat(QImage::Format_Grayscale8));
|
||||
if (text.isEmpty()) {
|
||||
const QVector<QString> texts = QrDecoder().decode(qpx.toImage().convertToFormat(QImage::Format_Grayscale8));
|
||||
if (texts.isEmpty()) {
|
||||
MessageBoxInfo(software_name, tr("QR Code not found"));
|
||||
} else {
|
||||
for (const QString &text : texts) {
|
||||
show_log_impl("QR Code Result:\n" + text);
|
||||
NekoGui_sub::groupUpdater->AsyncUpdate(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
MessageBoxInfo(software_name, tr("Unable to capture screen"));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user