From d1b21e6f0dee24b834bfd98e6271a917c912e6df Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Thu, 21 Sep 2023 11:09:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E6=8F=8F=E6=97=B6=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner2/HGImgView.cpp | 26 +++++++++++++++++++++++--- app/scanner2/HGImgView.h | 2 ++ app/scanner2/mainwindow.cpp | 36 ++++++++++++++++++++++++++++++++++++ app/scanner2/mainwindow.h | 4 ++++ 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/app/scanner2/HGImgView.cpp b/app/scanner2/HGImgView.cpp index 98ddb67b..893cad71 100644 --- a/app/scanner2/HGImgView.cpp +++ b/app/scanner2/HGImgView.cpp @@ -36,6 +36,7 @@ HGImgView::HGImgView(QWidget* parent) m_qImage = nullptr; m_showImage = false; memset(&m_showRect, 0, sizeof(HGRectF)); + m_enableHighQuality = true; m_mouseMoveStatus = MouseStatus_Null; m_mousePressStatus = MouseStatus_Null; m_mousePressBeginX = -1; @@ -833,8 +834,21 @@ HGResult HGImgView::enableScroll(bool enable) HGResult HGImgView::addImage(HGImage image) { + if (NULL == image) + { + return HGBASE_ERR_INVALIDARG; + } + + HGImageInfo imageInfo; + HGBase_GetImageInfo(image, &imageInfo); + HGUInt type = imageInfo.type; + if (type == HGBASE_IMGTYPE_BGR) + type = HGBASE_IMGTYPE_RGB; + else if (type == HGBASE_IMGTYPE_BGRA) + type = HGBASE_IMGTYPE_RGBA; + HGImage img = nullptr; - HGResult ret = HGBase_CloneImage(image, 0, HGBASE_IMGORIGIN_TOP, &img); + HGResult ret = HGBase_CloneImage(image, type, HGBASE_IMGORIGIN_TOP, &img); if (ret != HGBASE_ERR_OK) { return ret; @@ -909,6 +923,12 @@ HGResult HGImgView::getImage(HGImage *image) return HGBASE_ERR_OK; } +HGResult HGImgView::enableHighQuality(bool enable) +{ + m_enableHighQuality = enable; + return HGBASE_ERR_OK; +} + HGResult HGImgView::rotateLeft() { if (MouseStatus_Null != m_mousePressStatus || 0 != m_operate || m_draging || nullptr == m_image) @@ -1617,11 +1637,11 @@ void HGImgView::paintEvent(QPaintEvent* e) QRect srcRect(xSrc, ySrc, wSrc, hSrc); QRect destRect(xDest, yDest, wDest, hDest); - painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setRenderHint(m_enableHighQuality ? QPainter::SmoothPixmapTransform : QPainter::LosslessImageRendering); painter.drawImage(destRect, *m_qImage, srcRect); #else QRectF destRect(m_showRect.left, m_showRect.top, m_showRect.right - m_showRect.left, m_showRect.bottom - m_showRect.top); - painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setRenderHint(m_enableHighQuality ? QPainter::SmoothPixmapTransform : QPainter::LosslessImageRendering); painter.drawImage(destRect, *m_qImage); #endif diff --git a/app/scanner2/HGImgView.h b/app/scanner2/HGImgView.h index 73f95813..8c8d4a56 100644 --- a/app/scanner2/HGImgView.h +++ b/app/scanner2/HGImgView.h @@ -31,6 +31,7 @@ public: HGResult addImage(HGImage image); HGResult clearImage(); HGResult getImage(HGImage *image); + HGResult enableHighQuality(bool enable); HGResult rotateLeft(); HGResult rotateRight(); @@ -132,6 +133,7 @@ private: QImage *m_qImage; bool m_showImage; HGRectF m_showRect; + bool m_enableHighQuality; MouseStatus m_mouseMoveStatus; MouseStatus m_mousePressStatus; int m_mousePressBeginX; diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index ecd73383..788091e4 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -67,6 +67,7 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) , m_scanType(ScanType_None) , m_scanInsertPos(-1) , m_scanCurIndex(-1) + , m_previewImage(nullptr) , m_scanFileName("") , m_scanImgFmtWriter(nullptr) , m_isScanning(false) @@ -87,6 +88,8 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) { ui->setupUi(this); + m_lockPreviewImage = nullptr; + HGBase_CreateLock(&m_lockPreviewImage); m_aquireIntoSaveParam.m_fileNameStartIndex = -1; m_versionDll = new VersionDll; @@ -338,6 +341,7 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) ui->act_consume->setVisible(false); connect(this, SIGNAL(post_new_image(QString)), this, SLOT(on_post_new_image(QString))); + connect(this, SIGNAL(preview_image()), this, SLOT(on_preview_image())); m_wndStatusBar->setDeviceStatusInfo(tr("Please go to 'Menu Bar ->Scan' to select a device"), false); @@ -441,6 +445,9 @@ MainWindow::~MainWindow() delete m_versionDll; m_versionDll = nullptr; + HGBase_DestroyLock(m_lockPreviewImage); + m_lockPreviewImage = nullptr; + delete ui; } @@ -1009,6 +1016,11 @@ void MainWindow::on_post_new_image(QString fileName) ++m_scanInsertPos; } + HGBase_EnterLock(m_lockPreviewImage); + m_view->addImage(m_previewImage); + HGBase_LeaveLock(m_lockPreviewImage); + updateStatusBarPixelInfo(); + if ((ScanType_ScanInto == m_scanType)) { m_curBatchFileList.push_back(stdFileName); @@ -1042,12 +1054,26 @@ void MainWindow::on_post_new_image(QString fileName) } } +void MainWindow::on_preview_image() +{ + HGBase_EnterLock(m_lockPreviewImage); + m_view->addImage(m_previewImage); + HGBase_LeaveLock(m_lockPreviewImage); + updateStatusBarPixelInfo(); +} + void MainWindow::on_newImage(void *image) { HGULonglong t1; HGBase_GetTickCount(&t1); qDebug("on_newImage start, m_currScanCount=%d", m_currScanCount); + HGBase_EnterLock(m_lockPreviewImage); + HGBase_DestroyImage(m_previewImage); + m_previewImage = nullptr; + HGBase_CloneImage((HGImage)image, 0, 0, &m_previewImage); + HGBase_LeaveLock(m_lockPreviewImage); + if (ScanType_ScanToCache == m_scanType || ScanType_SingleScanToCache == m_scanType) { m_scanFileName = getCacheFileName((HGImage)image); @@ -1159,6 +1185,10 @@ void MainWindow::on_newImage(void *image) ++m_aquireIntoSaveParam.m_fileNameStartIndex; m_aquireIntoMultiPageCount = 0; } + else + { + emit preview_image(); + } } } } @@ -1283,6 +1313,7 @@ void MainWindow::on_newImage(void *image) void MainWindow::on_scanWorkingEvent() { + m_view->enableHighQuality(false); m_isScanning = true; updateActionStatus(); @@ -1297,6 +1328,11 @@ void MainWindow::on_scanWorkingEvent() void MainWindow::on_scanFinishEvent() { + HGBase_EnterLock(m_lockPreviewImage); + HGBase_DestroyImage(m_previewImage); + m_previewImage = nullptr; + HGBase_LeaveLock(m_lockPreviewImage); + m_view->enableHighQuality(true); m_isScanning = false; updateActionStatus(); diff --git a/app/scanner2/mainwindow.h b/app/scanner2/mainwindow.h index 7b81f47a..75b87c6d 100644 --- a/app/scanner2/mainwindow.h +++ b/app/scanner2/mainwindow.h @@ -95,6 +95,7 @@ private slots: signals: void post_new_image(QString fileName); + void preview_image(); private slots: void on_AcquireInto2(); @@ -118,6 +119,7 @@ private slots: void on_multiPageLineEditFinished(); void on_clearCache(); void on_post_new_image(QString fileName); + void on_preview_image(); void on_newImage(void *image); void on_scanFinishEvent(); void on_scanWorkingEvent(); @@ -315,6 +317,8 @@ private: ScanType m_scanType; // 1-扫描到缓存目录,2-单张扫描到缓存目录,3-扫描到指定目录,4-插入扫描到指定目录 int m_scanInsertPos; // 扫描插入位置,-1表示插入到最后 int m_scanCurIndex; + HGLock m_lockPreviewImage; + HGImage m_previewImage; QString m_scanFileName; HGImgFmtWriter m_scanImgFmtWriter; AquireIntoSaveParam m_aquireIntoSaveParam;