调整高dpi大幅面纸张连续扫描导致内存过高
This commit is contained in:
parent
8f242dc071
commit
a9a6222ddc
|
@ -342,6 +342,10 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
|
|||
connect(this, SIGNAL(scan_working(QString)), this, SLOT(on_scan_working(QString)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(scan_finish(QString, int)), this, SLOT(on_scan_finish(QString, int)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(fwUpgradeAndDevLock_Finish()), this, SLOT(on_fwUpgradeAndDevLock_Finish()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(addNewImage(QString)), this, SLOT(on_addNewImage(QString)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(wrong_image(QString,int)), this, SLOT(on_wrong_image(QString,int)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(determineMemory()), this, SLOT(on_determineMemory()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(promptScanStatusInfo(QString,bool)), this, SLOT(on_promptScanStatusInfo(QString,bool)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(sane_dev_error(QString)), this, SLOT(on_sane_dev_error(QString)), Qt::QueuedConnection);
|
||||
connect(m_dialogLog, SIGNAL(continueScan()), this, SLOT(on_continueScan()));
|
||||
connect(m_dialogLog, SIGNAL(stopScan()), this, SLOT(on_stopScan()));
|
||||
|
@ -1456,6 +1460,64 @@ void MainWindow::on_fwUpgradeAndDevLock_Finish()
|
|||
upgradeFwAndLockDevice();
|
||||
}
|
||||
|
||||
void MainWindow::on_addNewImage(const QString &filename)
|
||||
{
|
||||
if (-1 == m_scanInsertPos)
|
||||
{
|
||||
m_thumb->addItem(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_thumb->insertItem(filename, m_scanInsertPos);
|
||||
++m_scanInsertPos;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_wrong_image(const QString &fileName, int status)
|
||||
{
|
||||
int count = 0;
|
||||
if(m_scanInsertPos == -1)
|
||||
m_thumb->getItemCount(&count);
|
||||
else
|
||||
count = m_scanInsertPos;
|
||||
|
||||
dialog_wrong_img *dlg = new dialog_wrong_img(this, fileName, count, status);
|
||||
connect(dlg, SIGNAL(handle_wrong_img(dialog_wrong_img*, bool)), this, SLOT(on_wrong_image_decide(dialog_wrong_img*, bool)));
|
||||
wrong_imgs_.push_back(dlg);
|
||||
dlg->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_determineMemory()
|
||||
{
|
||||
if (!m_cacheDirNotify)
|
||||
{
|
||||
m_cacheDirNotify = true;
|
||||
QString info = tr("the disk space in the current path is unsufficient, please select a new path or clear the disk space in time.");
|
||||
m_wndStatusBar->setDeviceStatusInfo(info, true);
|
||||
m_dialogLog->addLog(info, true);
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "disk space is unsufficient!");
|
||||
QMessageBox::warning(this, tr("warning"), info);
|
||||
}
|
||||
|
||||
if (!m_AquirePathNotify)
|
||||
{
|
||||
m_AquirePathNotify = true;
|
||||
QString info = tr("the disk space in the current path is unsufficient, please select a new path or clear the disk space in time.");
|
||||
m_wndStatusBar->setDeviceStatusInfo(info, true);
|
||||
m_dialogLog->addLog(info, true);
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "disk space is unsufficient!");
|
||||
QMessageBox::warning(this, tr("warning"), info);
|
||||
}
|
||||
|
||||
on_stopScan();
|
||||
}
|
||||
|
||||
void MainWindow::on_promptScanStatusInfo(QString info, bool error)
|
||||
{
|
||||
m_dialogLog->addLog(info, error);
|
||||
m_wndStatusBar->setDeviceStatusInfo(info, error);
|
||||
}
|
||||
|
||||
void MainWindow::on_export_scanned_image(void)
|
||||
{
|
||||
m_dialogLog->hide();
|
||||
|
@ -2884,11 +2946,257 @@ int MainWindow::sane_ex_callback(SANE_Handle hdev, int code, void *data, unsigne
|
|||
HGImageInfo imgInfo = {(HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines,
|
||||
imgType, (HGUInt)sane_img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP};
|
||||
|
||||
int statu = sane_img->flag.statu;
|
||||
HGImage img = nullptr;
|
||||
HGBase_CreateImageFromData(imgData, &imgInfo, nullptr, imgType, HGBASE_IMGORIGIN_TOP, &img);
|
||||
if (nullptr != img)
|
||||
{
|
||||
emit p->new_image(img, sane_img->flag.statu);
|
||||
HGBase_SetImageDpi(img, p->m_dpi, p->m_dpi);
|
||||
if (1 == p->m_scanType)
|
||||
{
|
||||
if (!p->judgeDiskSpace(Dialog_ClrCache::getCachePath(), false))
|
||||
{
|
||||
emit p->determineMemory();
|
||||
|
||||
HGBase_DestroyImage(img);
|
||||
break;
|
||||
}
|
||||
|
||||
QString fileName = p->getCacheFileName(img);
|
||||
|
||||
HGImgFmtSaveInfo info;
|
||||
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 (statu != SANE_Image_Statu_OK)
|
||||
{
|
||||
emit p->wrong_image(fileName, statu);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit p->addNewImage(fileName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emit p->promptScanStatusInfo(tr("save image failed: ") + getLogInfo(ret), true);
|
||||
}
|
||||
}
|
||||
else if (2 == p->m_scanType)
|
||||
{
|
||||
if (!p->judgeDiskSpace(p->m_aquireIntoSaveParam.m_savePath, false))
|
||||
{
|
||||
emit p->determineMemory();
|
||||
|
||||
HGBase_DestroyImage(img);
|
||||
break;
|
||||
}
|
||||
|
||||
++p->m_aquireIntoPageIndex;
|
||||
if ((1 == p->m_aquireIntoSaveParam.m_fileNameOddEventType && 1 != p->m_aquireIntoPageIndex % 2)
|
||||
|| (2 == p->m_aquireIntoSaveParam.m_fileNameOddEventType && 0 != p->m_aquireIntoPageIndex % 2))
|
||||
{
|
||||
HGBase_DestroyImage(img);
|
||||
break;
|
||||
}
|
||||
|
||||
if (p->m_aquireIntoSaveParam.m_isSaveAsMultiPage)
|
||||
{
|
||||
if (1 == p->m_aquireIntoSaveParam.m_multiPagesType && p->m_aquireIntoMultiPageCount == p->m_aquireIntoSaveParam.m_customMultiPages)
|
||||
{
|
||||
if (nullptr != p->m_scanImgFmtWriter)
|
||||
{
|
||||
HGImgFmt_CloseImageWriter(p->m_scanImgFmtWriter);
|
||||
p->m_scanImgFmtWriter = nullptr;
|
||||
|
||||
emit p->addNewImage(p->m_scanFileName);
|
||||
|
||||
p->m_scanFileName.clear();
|
||||
++p->m_aquireIntoSaveParam.m_fileNameStartIndex;
|
||||
p->m_aquireIntoMultiPageCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullptr == p->m_scanImgFmtWriter)
|
||||
{
|
||||
assert(p->m_scanFileName.isEmpty());
|
||||
HGResult ret = HGBase_CreateDir(getStdString(p->m_aquireIntoSaveParam.m_savePath).c_str());
|
||||
if (ret != HGBASE_ERR_OK)
|
||||
{
|
||||
emit p->promptScanStatusInfo(tr("create savepath failed: ") + getLogInfo(ret), true);
|
||||
}
|
||||
|
||||
QString scanFileName;
|
||||
while (1)
|
||||
{
|
||||
scanFileName = p->m_aquireIntoSaveParam.m_savePath + p->m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2")
|
||||
.arg(p->m_aquireIntoSaveParam.m_fileNameStartIndex, p->m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
|
||||
.arg(p->m_aquireIntoSaveParam.m_fileNameExt);
|
||||
QFileInfo fileInfo(scanFileName);
|
||||
if (fileInfo.isFile())
|
||||
{
|
||||
++p->m_aquireIntoSaveParam.m_fileNameStartIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = HGImgFmt_OpenImageWriter(getStdString(getStdFileName(scanFileName)).c_str(), 0, &p->m_scanImgFmtWriter);
|
||||
if(ret != HGBASE_ERR_OK)
|
||||
{
|
||||
emit p->promptScanStatusInfo(tr("create image doc failed: ") + getLogInfo(ret), true);
|
||||
}
|
||||
|
||||
if (nullptr != p->m_scanImgFmtWriter)
|
||||
p->m_scanFileName = scanFileName;
|
||||
}
|
||||
|
||||
if (nullptr != p->m_scanImgFmtWriter)
|
||||
{
|
||||
HGImgFmtSaveInfo saveInfo;
|
||||
saveInfo.jpegQuality = (HGUInt)p->m_aquireIntoSaveParam.m_jpegQuality;
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
||||
saveInfo.tiffJpegQuality = (HGUInt)p->m_aquireIntoSaveParam.m_tiffQuality;
|
||||
|
||||
HGImageInfo imgInfo;
|
||||
HGBase_GetImageInfo(img, &imgInfo);
|
||||
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
||||
{
|
||||
if (1 == p->m_aquireIntoSaveParam.m_tiffCompressionBW)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
||||
else if (2 == p->m_aquireIntoSaveParam.m_tiffCompressionBW)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (1 == p->m_aquireIntoSaveParam.m_tiffCompression)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
||||
else if (2 == p->m_aquireIntoSaveParam.m_tiffCompression)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
|
||||
}
|
||||
|
||||
HGResult ret = HGImgFmt_SaveImageToWriter(p->m_scanImgFmtWriter, img, &saveInfo);
|
||||
if(ret != HGBASE_ERR_OK)
|
||||
{
|
||||
emit p->promptScanStatusInfo(tr("save image doc failed: ") + getLogInfo(ret), true);
|
||||
}
|
||||
|
||||
++p->m_aquireIntoMultiPageCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(p->m_scanFileName.isEmpty());
|
||||
assert(nullptr == p->m_scanImgFmtWriter);
|
||||
|
||||
QString savePath = p->m_aquireIntoSaveParam.m_savePath;
|
||||
if (p->m_aquireIntoSaveParam.m_isUseSubfolderByBlankPages)
|
||||
{
|
||||
HGBool isBlank = HGFALSE;
|
||||
HGImgProc_ImageBlankCheck(img, nullptr, &isBlank);
|
||||
if (isBlank)
|
||||
{
|
||||
p->m_aquireIntoInBlank = true;
|
||||
HGBase_DestroyImage(img);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p->m_aquireIntoInBlank)
|
||||
{
|
||||
++p->m_aquireIntoBatchStartIndex;
|
||||
}
|
||||
|
||||
p->m_aquireIntoInBlank = false;
|
||||
}
|
||||
|
||||
char batchDir[20];
|
||||
sprintf(batchDir, "batch%d", p->m_aquireIntoBatchStartIndex);
|
||||
savePath = getStdFileName(savePath + batchDir + "/");
|
||||
}
|
||||
|
||||
if (p->m_aquireIntoSaveParam.m_isUseSubfolderByColor)
|
||||
{
|
||||
QString colorModeName;
|
||||
HGImageInfo imgInfo;
|
||||
HGBase_GetImageInfo(img, &imgInfo);
|
||||
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
||||
colorModeName = tr("binary");
|
||||
else if (HGBASE_IMGTYPE_GRAY == imgInfo.type)
|
||||
colorModeName = tr("gray");
|
||||
else
|
||||
colorModeName = tr("rgb");
|
||||
|
||||
savePath = getStdFileName(savePath + colorModeName + "/");
|
||||
}
|
||||
|
||||
HGResult ret = HGBase_CreateDir(getStdString(savePath).c_str());
|
||||
if(ret != HGBASE_ERR_OK)
|
||||
{
|
||||
emit p->promptScanStatusInfo(tr("create savepath failed: ") + getLogInfo(ret), true);
|
||||
}
|
||||
|
||||
QString scanFileName;
|
||||
while (1)
|
||||
{
|
||||
scanFileName = savePath + p->m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2")
|
||||
.arg(p->m_aquireIntoSaveParam.m_fileNameStartIndex, p->m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
|
||||
.arg(p->m_aquireIntoSaveParam.m_fileNameExt);
|
||||
QFileInfo fileInfo(scanFileName);
|
||||
if (fileInfo.isFile())
|
||||
{
|
||||
++p->m_aquireIntoSaveParam.m_fileNameStartIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HGImgFmtSaveInfo saveInfo;
|
||||
saveInfo.jpegQuality = (HGUInt)p->m_aquireIntoSaveParam.m_jpegQuality;
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
||||
saveInfo.tiffJpegQuality = (HGUInt)p->m_aquireIntoSaveParam.m_tiffQuality;
|
||||
|
||||
HGImageInfo imgInfo;
|
||||
HGBase_GetImageInfo(img, &imgInfo);
|
||||
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
||||
{
|
||||
if (1 == p->m_aquireIntoSaveParam.m_tiffCompressionBW)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
||||
else if (2 == p->m_aquireIntoSaveParam.m_tiffCompressionBW)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (1 == p->m_aquireIntoSaveParam.m_tiffCompression)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
||||
else if (2 == p->m_aquireIntoSaveParam.m_tiffCompression)
|
||||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
|
||||
}
|
||||
|
||||
ret = saveImage(img, &saveInfo, p->m_aquireIntoSaveParam.m_isOcr, 0, getStdString(scanFileName).c_str());
|
||||
if(ret == HGBASE_ERR_OK)
|
||||
{
|
||||
emit p->addNewImage(scanFileName);
|
||||
++p->m_aquireIntoSaveParam.m_fileNameStartIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit p->promptScanStatusInfo(tr("save image doc failed: ") + getLogInfo(ret), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p->m_currScanCount++;
|
||||
HGBase_DestroyImage(img);
|
||||
if(statu == SANE_Image_Statu_OK)
|
||||
p->m_dialogLog->image_received_from_scanner();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -125,6 +125,10 @@ signals:
|
|||
void scan_working(QString workingInfo);
|
||||
void scan_finish(QString finishInfo, int err);
|
||||
void fwUpgradeAndDevLock_Finish();
|
||||
void addNewImage(const QString& filename);
|
||||
void wrong_image(const QString& fileName, int status);
|
||||
void determineMemory();
|
||||
void promptScanStatusInfo(QString info, bool error);
|
||||
|
||||
private slots:
|
||||
void on_AcquireInto2();
|
||||
|
@ -153,6 +157,10 @@ private slots:
|
|||
void on_scan_working(QString workingInfo);
|
||||
void on_scan_finish(QString finishInfo, int err);
|
||||
void on_fwUpgradeAndDevLock_Finish();
|
||||
void on_addNewImage(const QString& filename);
|
||||
void on_wrong_image(const QString& fileName, int status);
|
||||
void on_determineMemory();
|
||||
void on_promptScanStatusInfo(QString info, bool error);
|
||||
void on_export_scanned_image(void);
|
||||
void on_continueScan();
|
||||
void on_stopScan();
|
||||
|
|
Loading…
Reference in New Issue