From 6b106f21ad3493f1273b89a1355ad41ffdda641f Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 22 Apr 2021 23:37:10 +0200 Subject: [PATCH] APT demod: save image in image worker --- plugins/channelrx/demodapt/aptdemod.cpp | 10 ++++-- .../demodapt/aptdemodimageworker.cpp | 35 +++++++++++++++++++ .../channelrx/demodapt/aptdemodimageworker.h | 18 ++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/plugins/channelrx/demodapt/aptdemod.cpp b/plugins/channelrx/demodapt/aptdemod.cpp index 28c16dca4..4bcc86014 100644 --- a/plugins/channelrx/demodapt/aptdemod.cpp +++ b/plugins/channelrx/demodapt/aptdemod.cpp @@ -651,19 +651,25 @@ int APTDemod::webapiActionsPost( { SWGSDRangel::SWGAPTDemodActions_los* los = swgAPTDemodActions->getLos(); QString *satelliteName = los->getSatelliteName(); + if (satelliteName != nullptr) { if (matchSatellite(*satelliteName)) { // Save image if (m_settings.m_autoSave) - saveImageToDisk(); + { + APTDemodImageWorker::MsgSaveImageToDisk *msg = APTDemodImageWorker::MsgSaveImageToDisk::create(); + m_imageWorker->getInputMessageQueue()->push(msg); + } // Disable decoder APTDemodSettings settings = m_settings; settings.m_decodeEnabled = false; m_inputMessageQueue.push(MsgConfigureAPTDemod::create(settings, false)); - if (m_guiMessageQueue) + + if (m_guiMessageQueue) { m_guiMessageQueue->push(MsgConfigureAPTDemod::create(settings, false)); + } } return 202; diff --git a/plugins/channelrx/demodapt/aptdemodimageworker.cpp b/plugins/channelrx/demodapt/aptdemodimageworker.cpp index e75214077..fee0ee01d 100644 --- a/plugins/channelrx/demodapt/aptdemodimageworker.cpp +++ b/plugins/channelrx/demodapt/aptdemodimageworker.cpp @@ -18,10 +18,14 @@ #include +#include +#include + #include "aptdemod.h" #include "aptdemodimageworker.h" MESSAGE_CLASS_DEFINITION(APTDemodImageWorker::MsgConfigureAPTDemodImageWorker, Message) +MESSAGE_CLASS_DEFINITION(APTDemodImageWorker::MsgSaveImageToDisk, Message) APTDemodImageWorker::APTDemodImageWorker() : m_messageQueueToGUI(nullptr), @@ -90,6 +94,11 @@ bool APTDemodImageWorker::handleMessage(const Message& cmd) applySettings(cfg.getSettings(), cfg.getForce()); return true; } + else if (MsgSaveImageToDisk::match(cmd)) + { + saveImageToDisk(); + return true; + } else if (APTDemod::MsgPixels::match(cmd)) { QMutexLocker mutexLocker(&m_mutex); @@ -259,6 +268,32 @@ QImage APTDemodImageWorker::extractImage(QImage image) } } +void APTDemodImageWorker::saveImageToDisk() +{ + QStringList imageTypes; + QImage image = processImage(imageTypes); + + if (image.height() >= m_settings.m_autoSaveMinScanLines) + { + QString filename; + QDateTime datetime = QDateTime::currentDateTime(); + filename = QString("apt_%1_%2.png").arg(m_satelliteName).arg(datetime.toString("yyyyMMdd_hhmm")); + + if (!m_settings.m_autoSavePath.isEmpty()) + { + if (m_settings.m_autoSavePath.endsWith('/')) { + filename = m_settings.m_autoSavePath + filename; + } else { + filename = m_settings.m_autoSavePath + '/' + filename; + } + } + + if (!image.save(filename)) { + qCritical() << "Failed to save APT image to: " << filename; + } + } +} + void APTDemodImageWorker::copyImage(apt_image_t *dst, apt_image_t *src) { dst->nrow = src->nrow; diff --git a/plugins/channelrx/demodapt/aptdemodimageworker.h b/plugins/channelrx/demodapt/aptdemodimageworker.h index 2b7db866d..a4b47a9dc 100644 --- a/plugins/channelrx/demodapt/aptdemodimageworker.h +++ b/plugins/channelrx/demodapt/aptdemodimageworker.h @@ -57,6 +57,23 @@ public: { } }; + class MsgSaveImageToDisk : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgSaveImageToDisk* create() + { + return new MsgSaveImageToDisk(); + } + + private: + + MsgSaveImageToDisk() : + Message() + { + } + }; + APTDemodImageWorker(); ~APTDemodImageWorker(); void reset(); @@ -87,6 +104,7 @@ private: void resetDecoder(); void processPixels(const float *pixels); void sendImageToGUI(); + void saveImageToDisk(); QImage processImage(QStringList& imageTypes); QImage extractImage(QImage image);