From e84db73f31cdbadf70079bab05937789e5ca89ce Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 10 Apr 2021 03:07:10 -0700 Subject: [PATCH] Qt: Expose e-Reader parsing --- CHANGES | 2 ++ src/platform/qt/Window.cpp | 53 ++++++++++++++++++++++++++++++++++++++ src/platform/qt/Window.h | 1 + 3 files changed, 56 insertions(+) diff --git a/CHANGES b/CHANGES index 387618daa..6b0fedc8f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 0.10.0: (Future) +Features: + - Tool for converting scanned pictures of e-Reader cards to raw dotcode data Emulation fixes: - Core: Fix first event scheduling after loading savestate - GB Serialize: Fix switching speed modes when loading a state (fixes mgba.io/i/2097) diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 59b55b94e..08f3750a4 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -76,6 +76,8 @@ #include #include +#include + using namespace QGBA; Window::Window(CoreManager* manager, ConfigController* config, int playerId, QWidget* parent) @@ -424,6 +426,53 @@ void Window::scanCard() { } } +void Window::parseCard() { +#ifdef USE_FFMPEG + QStringList filenames = GBAApp::app()->getOpenFileNames(this, tr("Select e-Reader card images"), tr("Image file (*.png *.jpg *.jpeg)")); + QMessageBox* dialog = new QMessageBox(QMessageBox::Information, tr("Conversion finished"), + QString("oh"), QMessageBox::Ok); + dialog->setAttribute(Qt::WA_DeleteOnClose); + auto status = std::make_shared>(0, filenames.size()); + GBAApp::app()->submitWorkerJob([filenames, dialog, status]() { + int success = 0; + for (QString filename : filenames) { + if (filename.isEmpty()) { + continue; + } + QImage image(filename); + if (image.isNull()) { + continue; + } + EReaderScan* scan; + switch (image.depth()) { + case 8: + scan = EReaderScanLoadImage8(image.constBits(), image.width(), image.height(), image.bytesPerLine()); + break; + case 24: + scan = EReaderScanLoadImage(image.constBits(), image.width(), image.height(), image.bytesPerLine()); + break; + case 32: + scan = EReaderScanLoadImageA(image.constBits(), image.width(), image.height(), image.bytesPerLine()); + break; + default: + continue; + } + QFileInfo ofile(filename); + if (EReaderScanCard(scan)) { + QString ofilename = ofile.path() + QDir::separator() + ofile.baseName() + ".raw"; + EReaderScanSaveRaw(scan, ofilename.toUtf8().constData(), false); + ++success; + } + EReaderScanDestroy(scan); + } + status->first = success; + }, [dialog, status]() { + dialog->setText(tr("%1 of %2 e-Reader cards converted successfully.").arg(status->first).arg(status->second)); + dialog->show(); + }); +#endif +} + void Window::openView(QWidget* widget) { connect(this, &Window::shutdown, widget, &QWidget::close); widget->setAttribute(Qt::WA_DeleteOnClose); @@ -1121,6 +1170,10 @@ void Window::setupMenu(QMenuBar* menubar) { #ifdef M_CORE_GBA Action* scanCard = addGameAction(tr("Scan e-Reader dotcodes..."), "scanCard", this, &Window::scanCard, "file"); m_platformActions.insert(mPLATFORM_GBA, scanCard); + +#ifdef USE_FFMPEG + m_actions.addAction(tr("Convert e-Reader card image to raw..."), "parseCard", this, &Window::parseCard, "file"); +#endif #endif addGameAction(tr("ROM &info..."), "romInfo", openControllerTView(), "file"); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index a5cca0657..641153f0d 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -82,6 +82,7 @@ public slots: void selectState(bool load); void selectPatch(); void scanCard(); + void parseCard(); void enterFullScreen(); void exitFullScreen(); void toggleFullScreen();