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:
parhelia512 2025-05-17 17:49:06 +08:00 committed by GitHub
parent 759615e0c1
commit 95d12f9556
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 12 deletions

View File

@ -12,22 +12,23 @@ QrDecoder::~QrDecoder()
quirc_destroy(m_qr); quirc_destroy(m_qr);
} }
QString QrDecoder::decode(const QImage &image) QVector<QString> QrDecoder::decode(const QImage &image)
{ {
QVector<QString> result;
if (m_qr == nullptr) if (m_qr == nullptr)
{ {
return ""; return result;
} }
if (quirc_resize(m_qr, image.width(), image.height()) < 0) if (quirc_resize(m_qr, image.width(), image.height()) < 0)
{ {
return ""; return result;
} }
uint8_t *rawImage = quirc_begin(m_qr, nullptr, nullptr); uint8_t *rawImage = quirc_begin(m_qr, nullptr, nullptr);
if (rawImage == nullptr) if (rawImage == nullptr)
{ {
return ""; return result;
} }
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
std::copy(image.constBits(), image.constBits() + image.sizeInBytes(), rawImage); 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); const int count = quirc_count(m_qr);
if (count < 0) if (count < 0)
{ {
return ""; return result;
} }
for (int index = 0; index < count; ++index) 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); const quirc_decode_error_t err = quirc_decode(&code, &data);
if (err == QUIRC_SUCCESS) if (err == QUIRC_SUCCESS)
{ {
return QLatin1String((const char *)data.payload); result.append(QLatin1String((const char *)data.payload));
} }
} }
return ""; return result;
} }

View File

@ -11,7 +11,7 @@ public:
QrDecoder(); QrDecoder();
~QrDecoder(); ~QrDecoder();
QString decode(const QImage &image); QVector<QString> decode(const QImage &image);
private: private:
quirc *m_qr; quirc *m_qr;

View File

@ -1752,12 +1752,14 @@ void MainWindow::on_menu_scan_qr_triggered() {
show(); show();
if (ok) { if (ok) {
const QString text = QrDecoder().decode(qpx.toImage().convertToFormat(QImage::Format_Grayscale8)); const QVector<QString> texts = QrDecoder().decode(qpx.toImage().convertToFormat(QImage::Format_Grayscale8));
if (text.isEmpty()) { if (texts.isEmpty()) {
MessageBoxInfo(software_name, tr("QR Code not found")); MessageBoxInfo(software_name, tr("QR Code not found"));
} else { } else {
show_log_impl("QR Code Result:\n" + text); for (const QString &text : texts) {
NekoGui_sub::groupUpdater->AsyncUpdate(text); show_log_impl("QR Code Result:\n" + text);
NekoGui_sub::groupUpdater->AsyncUpdate(text);
}
} }
} }
else { else {