调整ui图像处理线程

This commit is contained in:
yangjiaxuan 2023-05-19 15:50:47 +08:00
parent a295dadbef
commit f9a72dee1d
2 changed files with 129 additions and 53 deletions

View File

@ -57,7 +57,6 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
, m_currLang(appLang) , m_currLang(appLang)
, m_versionDll(nullptr) , m_versionDll(nullptr)
, m_admin_loggedIn(false) , m_admin_loggedIn(false)
, m_dpi(200)
, m_currFilePath("") , m_currFilePath("")
, m_currIndex(-1) , m_currIndex(-1)
, m_multiPageCount(0) , m_multiPageCount(0)
@ -328,7 +327,7 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
ui->act_consume->setVisible(false); ui->act_consume->setVisible(false);
connect(this, SIGNAL(pre_new_image(void*)), this, SLOT(on_pre_new_image(void*)), Qt::BlockingQueuedConnection); connect(this, SIGNAL(pre_new_image(void*)), this, SLOT(on_pre_new_image(void*)), Qt::BlockingQueuedConnection);
connect(this, SIGNAL(post_new_image(unsigned int, int)), this, SLOT(on_post_new_image(unsigned int, int)), Qt::BlockingQueuedConnection); connect(this, SIGNAL(post_new_image(unsigned int)), this, SLOT(on_post_new_image(unsigned int)), Qt::BlockingQueuedConnection);
m_wndStatusBar->setDeviceStatusInfo(tr("nodevice"), false); m_wndStatusBar->setDeviceStatusInfo(tr("nodevice"), false);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%s", getStdString(tr("nodevice")).c_str()); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%s", getStdString(tr("nodevice")).c_str());
@ -969,41 +968,17 @@ void MainWindow::on_clearCache()
m_thumb->removeItems(removeItems, HGImgThumb::ThumbRemoveFlag_NULL); m_thumb->removeItems(removeItems, HGImgThumb::ThumbRemoveFlag_NULL);
} }
void MainWindow::on_newImage(void *image) void MainWindow::on_pre_new_image(void* img)
{ {
HGImage img = (HGImage)image; m_saveType = 0;
HGUInt xDpi = 0; HGImage image = (HGImage)img;
HGUInt yDpi = 0;
HGBase_GetImageDpi(img, &xDpi, &yDpi);
HGBase_SetImageDpi(img, xDpi, yDpi);
if (1 == m_scanType) if (1 == m_scanType)
{ {
QString fileName = getCacheFileName(img); m_scanFileName = getCacheFileName(image);
m_saveType = 1;
HGImgFmtSaveInfo info; return;
info.jpegQuality = 100;
info.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
info.tiffJpegQuality = 0;
HGResult ret = HGImgFmt_SaveImage(img, 0, &info, getStdString(fileName).c_str());
if(ret == HGBASE_ERR_OK)
{
if (-1 == m_scanInsertPos)
{
m_thumb->addItem(fileName);
}
else
{
m_thumb->insertItem(fileName, m_scanInsertPos);
++m_scanInsertPos;
}
}
else
{
m_wndStatusBar->setDeviceStatusInfo(tr("save image failed: ") + getLogInfo(ret), true);
}
} }
else if (2 == m_scanType) else if (2 == m_scanType)
{ {
@ -1033,10 +1008,6 @@ void MainWindow::on_newImage(void *image)
{ {
assert(m_scanFileName.isEmpty()); assert(m_scanFileName.isEmpty());
HGResult ret = HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str()); HGResult ret = HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str());
if (ret != HGBASE_ERR_OK)
{
m_wndStatusBar->setDeviceStatusInfo(tr("create savepath failed: ") + getLogInfo(ret), true);
}
QString scanFileName; QString scanFileName;
while (1) while (1)
@ -1056,10 +1027,6 @@ void MainWindow::on_newImage(void *image)
} }
ret = HGImgFmt_OpenImageWriter(getStdString(getStdFileName(scanFileName)).c_str(), 0, &m_scanImgFmtWriter); ret = HGImgFmt_OpenImageWriter(getStdString(getStdFileName(scanFileName)).c_str(), 0, &m_scanImgFmtWriter);
if(ret != HGBASE_ERR_OK)
{
m_wndStatusBar->setDeviceStatusInfo(tr("create image doc failed: ") + getLogInfo(ret), true);
}
if (nullptr != m_scanImgFmtWriter) if (nullptr != m_scanImgFmtWriter)
m_scanFileName = scanFileName; m_scanFileName = scanFileName;
@ -1078,7 +1045,7 @@ void MainWindow::on_newImage(void *image)
if (m_aquireIntoSaveParam.m_isUseSubfolderByBlankPages) if (m_aquireIntoSaveParam.m_isUseSubfolderByBlankPages)
{ {
HGBool isBlank = HGFALSE; HGBool isBlank = HGFALSE;
HGImgProc_ImageBlankCheck(img, nullptr, &isBlank); HGImgProc_ImageBlankCheck(image, nullptr, &isBlank);
if (isBlank) if (isBlank)
{ {
m_aquireIntoInBlank = true; m_aquireIntoInBlank = true;
@ -1102,7 +1069,7 @@ void MainWindow::on_newImage(void *image)
{ {
QString colorModeName; QString colorModeName;
HGImageInfo imgInfo; HGImageInfo imgInfo;
HGBase_GetImageInfo(img, &imgInfo); HGBase_GetImageInfo(image, &imgInfo);
if (HGBASE_IMGTYPE_BINARY == imgInfo.type) if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
colorModeName = tr("binary"); colorModeName = tr("binary");
else if (HGBASE_IMGTYPE_GRAY == imgInfo.type) else if (HGBASE_IMGTYPE_GRAY == imgInfo.type)
@ -1114,10 +1081,6 @@ void MainWindow::on_newImage(void *image)
} }
HGResult ret = HGBase_CreateDir(getStdString(savePath).c_str()); HGResult ret = HGBase_CreateDir(getStdString(savePath).c_str());
if(ret != HGBASE_ERR_OK)
{
m_wndStatusBar->setDeviceStatusInfo(tr("create savepath failed: ") + getLogInfo(ret), true);
}
while (1) while (1)
{ {
@ -1140,6 +1103,114 @@ void MainWindow::on_newImage(void *image)
} }
} }
void MainWindow::on_post_new_image(unsigned int ret)
{
if (1 == m_scanType && 1 == m_saveType)
{
if (ret == HGBASE_ERR_OK)
{
if (-1 == m_scanInsertPos)
{
m_thumb->addItem(m_scanFileName);
}
else
{
m_thumb->insertItem(m_scanFileName, m_scanInsertPos);
++m_scanInsertPos;
}
}
}
else if (2 == m_scanType)
{
if (m_aquireIntoSaveParam.m_isSaveAsMultiPage && 2 == m_saveType)
{
++m_aquireIntoMultiPageCount;
}
else if (3 == m_saveType)
{
if (ret == HGBASE_ERR_OK)
{
m_thumb->addItem(m_scanFileName);
++m_aquireIntoSaveParam.m_fileNameStartIndex;
}
}
}
m_currScanCount++;
}
void MainWindow::on_newImage(void *image)
{
HGImage img = (HGImage)image;
emit pre_new_image(img);
HGResult ret = HGBASE_ERR_FAIL;
if (1 == m_saveType)
{
HGImgFmtSaveInfo info;
info.jpegQuality = 100;
info.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
info.tiffJpegQuality = 0;
ret = HGImgFmt_SaveImage(img, 0, &info, getStdString(m_scanFileName).c_str());
}
else if (2 == m_saveType)
{
HGImgFmtSaveInfo saveInfo;
saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality;
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality;
HGImageInfo imgInfo;
HGBase_GetImageInfo(img, &imgInfo);
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
{
if (1 == m_aquireIntoSaveParam.m_tiffCompressionBW)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
else if (2 == m_aquireIntoSaveParam.m_tiffCompressionBW)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
}
else
{
if (1 == m_aquireIntoSaveParam.m_tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
else if (2 == m_aquireIntoSaveParam.m_tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
}
ret = HGImgFmt_SaveImageToWriter(m_scanImgFmtWriter, img, &saveInfo);
}
else if (3 == m_saveType)
{
HGImgFmtSaveInfo saveInfo;
saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality;
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality;
HGImageInfo imgInfo;
HGBase_GetImageInfo(img, &imgInfo);
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
{
if (1 == m_aquireIntoSaveParam.m_tiffCompressionBW)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
else if (2 == m_aquireIntoSaveParam.m_tiffCompressionBW)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
}
else
{
if (1 == m_aquireIntoSaveParam.m_tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
else if (2 == m_aquireIntoSaveParam.m_tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
}
ret = saveImage(img, &saveInfo, m_aquireIntoSaveParam.m_isOcr, 0, getStdString(m_scanFileName).c_str());
}
emit post_new_image(ret);
HGBase_DestroyImage(img);
}
void MainWindow::on_wrong_image_decide(dialog_wrong_img* dlg, bool save) void MainWindow::on_wrong_image_decide(dialog_wrong_img* dlg, bool save)
{ {
int i = 0; int i = 0;
@ -3767,6 +3838,6 @@ void MainWindow::on_act_selectDevice_triggered()
{ {
m_devUser = devUser; m_devUser = devUser;
m_wndStatusBar->setDeviceStatusInfo(tr("Device %1 is open").arg(m_devUser->GetName()), false); m_wndStatusBar->setDeviceStatusInfo(tr("Device %1 is open").arg(m_devUser->GetName()), false);
connect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*))); connect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)), Qt::DirectConnection);
} }
} }

View File

@ -93,6 +93,10 @@ private slots:
void on_act_autoSave_triggered(); void on_act_autoSave_triggered();
signals:
void pre_new_image(void* img);
void post_new_image(unsigned int ret);
private slots: private slots:
void on_AcquireInto2(); void on_AcquireInto2();
void on_reloadAcquireIntoCfg(); void on_reloadAcquireIntoCfg();
@ -113,6 +117,8 @@ private slots:
void on_dialog_multirotate_refreshImgFile(const QString &fileName); void on_dialog_multirotate_refreshImgFile(const QString &fileName);
void on_multiPageLineEditFinished(); void on_multiPageLineEditFinished();
void on_clearCache(); void on_clearCache();
void on_pre_new_image(void* img);
void on_post_new_image(unsigned int ret);
void on_newImage(void *image); void on_newImage(void *image);
void on_wrong_image_decide(dialog_wrong_img* dlg, bool save); void on_wrong_image_decide(dialog_wrong_img* dlg, bool save);
void on_m_pbtn_push_clicked(); void on_m_pbtn_push_clicked();
@ -285,7 +291,6 @@ private:
unsigned int Value; unsigned int Value;
}; };
HGUInt m_dpi;
QString m_currFilePath; QString m_currFilePath;
int m_currIndex; int m_currIndex;
int m_multiPageCount; int m_multiPageCount;