扫描时开启预览功能

This commit is contained in:
luoliangyi 2023-09-21 11:09:42 +08:00
parent 3340c83b93
commit d1b21e6f0d
4 changed files with 65 additions and 3 deletions

View File

@ -36,6 +36,7 @@ HGImgView::HGImgView(QWidget* parent)
m_qImage = nullptr; m_qImage = nullptr;
m_showImage = false; m_showImage = false;
memset(&m_showRect, 0, sizeof(HGRectF)); memset(&m_showRect, 0, sizeof(HGRectF));
m_enableHighQuality = true;
m_mouseMoveStatus = MouseStatus_Null; m_mouseMoveStatus = MouseStatus_Null;
m_mousePressStatus = MouseStatus_Null; m_mousePressStatus = MouseStatus_Null;
m_mousePressBeginX = -1; m_mousePressBeginX = -1;
@ -833,8 +834,21 @@ HGResult HGImgView::enableScroll(bool enable)
HGResult HGImgView::addImage(HGImage image) 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; 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) if (ret != HGBASE_ERR_OK)
{ {
return ret; return ret;
@ -909,6 +923,12 @@ HGResult HGImgView::getImage(HGImage *image)
return HGBASE_ERR_OK; return HGBASE_ERR_OK;
} }
HGResult HGImgView::enableHighQuality(bool enable)
{
m_enableHighQuality = enable;
return HGBASE_ERR_OK;
}
HGResult HGImgView::rotateLeft() HGResult HGImgView::rotateLeft()
{ {
if (MouseStatus_Null != m_mousePressStatus || 0 != m_operate || m_draging || nullptr == m_image) 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 srcRect(xSrc, ySrc, wSrc, hSrc);
QRect destRect(xDest, yDest, wDest, hDest); QRect destRect(xDest, yDest, wDest, hDest);
painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(m_enableHighQuality ? QPainter::SmoothPixmapTransform : QPainter::LosslessImageRendering);
painter.drawImage(destRect, *m_qImage, srcRect); painter.drawImage(destRect, *m_qImage, srcRect);
#else #else
QRectF destRect(m_showRect.left, m_showRect.top, m_showRect.right - m_showRect.left, m_showRect.bottom - m_showRect.top); 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); painter.drawImage(destRect, *m_qImage);
#endif #endif

View File

@ -31,6 +31,7 @@ public:
HGResult addImage(HGImage image); HGResult addImage(HGImage image);
HGResult clearImage(); HGResult clearImage();
HGResult getImage(HGImage *image); HGResult getImage(HGImage *image);
HGResult enableHighQuality(bool enable);
HGResult rotateLeft(); HGResult rotateLeft();
HGResult rotateRight(); HGResult rotateRight();
@ -132,6 +133,7 @@ private:
QImage *m_qImage; QImage *m_qImage;
bool m_showImage; bool m_showImage;
HGRectF m_showRect; HGRectF m_showRect;
bool m_enableHighQuality;
MouseStatus m_mouseMoveStatus; MouseStatus m_mouseMoveStatus;
MouseStatus m_mousePressStatus; MouseStatus m_mousePressStatus;
int m_mousePressBeginX; int m_mousePressBeginX;

View File

@ -67,6 +67,7 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
, m_scanType(ScanType_None) , m_scanType(ScanType_None)
, m_scanInsertPos(-1) , m_scanInsertPos(-1)
, m_scanCurIndex(-1) , m_scanCurIndex(-1)
, m_previewImage(nullptr)
, m_scanFileName("") , m_scanFileName("")
, m_scanImgFmtWriter(nullptr) , m_scanImgFmtWriter(nullptr)
, m_isScanning(false) , m_isScanning(false)
@ -87,6 +88,8 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
{ {
ui->setupUi(this); ui->setupUi(this);
m_lockPreviewImage = nullptr;
HGBase_CreateLock(&m_lockPreviewImage);
m_aquireIntoSaveParam.m_fileNameStartIndex = -1; m_aquireIntoSaveParam.m_fileNameStartIndex = -1;
m_versionDll = new VersionDll; m_versionDll = new VersionDll;
@ -338,6 +341,7 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
ui->act_consume->setVisible(false); ui->act_consume->setVisible(false);
connect(this, SIGNAL(post_new_image(QString)), this, SLOT(on_post_new_image(QString))); 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); m_wndStatusBar->setDeviceStatusInfo(tr("Please go to 'Menu Bar ->Scan' to select a device"), false);
@ -441,6 +445,9 @@ MainWindow::~MainWindow()
delete m_versionDll; delete m_versionDll;
m_versionDll = nullptr; m_versionDll = nullptr;
HGBase_DestroyLock(m_lockPreviewImage);
m_lockPreviewImage = nullptr;
delete ui; delete ui;
} }
@ -1009,6 +1016,11 @@ void MainWindow::on_post_new_image(QString fileName)
++m_scanInsertPos; ++m_scanInsertPos;
} }
HGBase_EnterLock(m_lockPreviewImage);
m_view->addImage(m_previewImage);
HGBase_LeaveLock(m_lockPreviewImage);
updateStatusBarPixelInfo();
if ((ScanType_ScanInto == m_scanType)) if ((ScanType_ScanInto == m_scanType))
{ {
m_curBatchFileList.push_back(stdFileName); 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) void MainWindow::on_newImage(void *image)
{ {
HGULonglong t1; HGULonglong t1;
HGBase_GetTickCount(&t1); HGBase_GetTickCount(&t1);
qDebug("on_newImage start, m_currScanCount=%d", m_currScanCount); 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) if (ScanType_ScanToCache == m_scanType || ScanType_SingleScanToCache == m_scanType)
{ {
m_scanFileName = getCacheFileName((HGImage)image); m_scanFileName = getCacheFileName((HGImage)image);
@ -1159,6 +1185,10 @@ void MainWindow::on_newImage(void *image)
++m_aquireIntoSaveParam.m_fileNameStartIndex; ++m_aquireIntoSaveParam.m_fileNameStartIndex;
m_aquireIntoMultiPageCount = 0; m_aquireIntoMultiPageCount = 0;
} }
else
{
emit preview_image();
}
} }
} }
} }
@ -1283,6 +1313,7 @@ void MainWindow::on_newImage(void *image)
void MainWindow::on_scanWorkingEvent() void MainWindow::on_scanWorkingEvent()
{ {
m_view->enableHighQuality(false);
m_isScanning = true; m_isScanning = true;
updateActionStatus(); updateActionStatus();
@ -1297,6 +1328,11 @@ void MainWindow::on_scanWorkingEvent()
void MainWindow::on_scanFinishEvent() 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; m_isScanning = false;
updateActionStatus(); updateActionStatus();

View File

@ -95,6 +95,7 @@ private slots:
signals: signals:
void post_new_image(QString fileName); void post_new_image(QString fileName);
void preview_image();
private slots: private slots:
void on_AcquireInto2(); void on_AcquireInto2();
@ -118,6 +119,7 @@ private slots:
void on_multiPageLineEditFinished(); void on_multiPageLineEditFinished();
void on_clearCache(); void on_clearCache();
void on_post_new_image(QString fileName); void on_post_new_image(QString fileName);
void on_preview_image();
void on_newImage(void *image); void on_newImage(void *image);
void on_scanFinishEvent(); void on_scanFinishEvent();
void on_scanWorkingEvent(); void on_scanWorkingEvent();
@ -315,6 +317,8 @@ private:
ScanType m_scanType; // 1-扫描到缓存目录2-单张扫描到缓存目录3-扫描到指定目录4-插入扫描到指定目录 ScanType m_scanType; // 1-扫描到缓存目录2-单张扫描到缓存目录3-扫描到指定目录4-插入扫描到指定目录
int m_scanInsertPos; // 扫描插入位置,-1表示插入到最后 int m_scanInsertPos; // 扫描插入位置,-1表示插入到最后
int m_scanCurIndex; int m_scanCurIndex;
HGLock m_lockPreviewImage;
HGImage m_previewImage;
QString m_scanFileName; QString m_scanFileName;
HGImgFmtWriter m_scanImgFmtWriter; HGImgFmtWriter m_scanImgFmtWriter;
AquireIntoSaveParam m_aquireIntoSaveParam; AquireIntoSaveParam m_aquireIntoSaveParam;