diff --git a/app/demo/mainwindow.cpp b/app/demo/mainwindow.cpp index 910b9c31..59292806 100644 --- a/app/demo/mainwindow.cpp +++ b/app/demo/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "imgfmt/HGImgFmt.h" +#include "base/HGTime.h" #include #include #include @@ -106,8 +107,32 @@ void MainWindow::on_pushButton_selectDev_clicked() void MainWindow::on_pushButton_setting_clicked() { +#if 0 if (nullptr != m_devUser) m_devUser->ShowSettingDlg(); +#else + HGImage img = NULL; + HGULonglong t1; + HGBase_GetTickCount(&t1); + HGImgFmt_LoadImage("D:\\1.bmp", 0, NULL, 0, 0, &img); + HGULonglong t2; + HGBase_GetTickCount(&t2); + HGDouble seconds; + HGBase_GetIntervalSeconds(t1, t2, &seconds); + qDebug("HGImgFmt_LoadImage seconds=%f", seconds); + if (nullptr != img) + { + HGULonglong t1; + HGBase_GetTickCount(&t1); + HGImgFmt_SaveImage(img, 0, NULL, "D:\\2.jpg"); + HGULonglong t2; + HGBase_GetTickCount(&t2); + HGDouble seconds; + HGBase_GetIntervalSeconds(t1, t2, &seconds); + qDebug("HGImgFmt_SaveImage seconds=%f", seconds); + HGBase_DestroyImage(img); + } +#endif } void MainWindow::on_pushButton_scan_clicked() diff --git a/app/scanner/HGImgThumb.cpp b/app/scanner/HGImgThumb.cpp index 62517f6b..9276821e 100644 --- a/app/scanner/HGImgThumb.cpp +++ b/app/scanner/HGImgThumb.cpp @@ -1137,26 +1137,26 @@ HGResult HGImgThumb::getItemCount(int *count) return HGBASE_ERR_OK; } -HGResult HGImgThumb::addItem(const QString &fileName) +HGResult HGImgThumb::addItem(const QString &fileName, bool notifyCurrentItem) { QStringList fileNames; fileNames.append(fileName); - return addItems(fileNames); + return addItems(fileNames, notifyCurrentItem); } -HGResult HGImgThumb::addItems(const QStringList &fileNames) +HGResult HGImgThumb::addItems(const QStringList &fileNames, bool notifyCurrentItem) { - return insertItems(fileNames, (int)m_frontItems.size(), true); + return insertItems(fileNames, (int)m_frontItems.size(), true, notifyCurrentItem); } -HGResult HGImgThumb::insertItem(const QString &fileName, int pos) +HGResult HGImgThumb::insertItem(const QString &fileName, int pos, bool notifyCurrentItem) { QStringList fileNames; fileNames.append(fileName); - return insertItems(fileNames, pos); + return insertItems(fileNames, pos, false, notifyCurrentItem); } -HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos, bool append) +HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos, bool append, bool notifyCurrentItem) { if (pos < 0 || pos > (int)m_frontItems.size()) { @@ -1341,8 +1341,11 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos, bool app if (pos != posEx) { - m_curItemIndex = posEx - 1; - m_signItemIndex = posEx - 1; + if (notifyCurrentItem) + { + m_curItemIndex = posEx - 1; + m_signItemIndex = posEx - 1; + } int showWidth = 0, showHeight = 0; calcShowSize(this->width(), this->height(), m_gapSize, m_scrollSize, m_itemSize, m_itemTextHeight, m_type, (int)m_frontItems.size(), @@ -4637,7 +4640,7 @@ QRect HGImgThumb::getNullScrollPos() void HGImgThumb::Show() { - repaint(); + update(); } void HGAPI HGImgThumb::ThreadFunc(HGThread thread, HGPointer param) diff --git a/app/scanner/HGImgThumb.h b/app/scanner/HGImgThumb.h index 071e921d..f95388b8 100644 --- a/app/scanner/HGImgThumb.h +++ b/app/scanner/HGImgThumb.h @@ -53,10 +53,10 @@ public: HGResult zoomOut(); HGResult getItemCount(int *count); - HGResult addItem(const QString &fileName); - HGResult addItems(const QStringList &fileNames); - HGResult insertItem(const QString &fileName, int pos); - HGResult insertItems(const QStringList &fileNames, int pos, bool append = false); + HGResult addItem(const QString &fileName, bool notifyCurrentItem = true); + HGResult addItems(const QStringList &fileNames, bool notifyCurrentItem = true); + HGResult insertItem(const QString &fileName, int pos, bool notifyCurrentItem = true); + HGResult insertItems(const QStringList &fileNames, int pos, bool append = false, bool notifyCurrentItem = true); HGResult moveItems(const QStringList &fileNames, int pos); HGResult moveItemsTo(const QStringList &fileNames, int index); HGResult getItemFileName(int index, QString &fileName); diff --git a/app/scanner/device_user.cpp b/app/scanner/device_user.cpp index 5f7ef39e..363e427e 100644 --- a/app/scanner/device_user.cpp +++ b/app/scanner/device_user.cpp @@ -33,8 +33,6 @@ DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds, QString password) m_wnd = wnd; m_twainDS = ds; m_password = password; - - connect(this, SIGNAL(closeReq()), this, SLOT(on_closeReq()), Qt::QueuedConnection); } DeviceUser::~DeviceUser() @@ -129,18 +127,7 @@ void HGAPI DeviceUser::DSCloseReqFunc(HGTwainDS ds, HGPointer param) void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param) { DeviceUser* p = (DeviceUser*)param; - HGImage image2 = nullptr; - HGBase_CloneImage(image, 0, 0, &image2); - if (nullptr != image2) - { - emit p->newImage(image2); - } -} - -void DeviceUser::on_closeReq() -{ -// std::this_thread::sleep_for(std::chrono::milliseconds(100)); -// HGTwain_DisableDS(m_twainDS); + emit p->newImage(image); } #else @@ -289,12 +276,7 @@ HGResult DeviceUser::ClearDeviceLog() void HGAPI DeviceUser::DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param) { DeviceUser* p = (DeviceUser*)param; - HGImage image2 = nullptr; - HGBase_CloneImage(image, 0, 0, &image2); - if (nullptr != image2) - { - emit p->newImage(image2); - } + emit p->newImage(image); } #endif diff --git a/app/scanner/device_user.h b/app/scanner/device_user.h index 7f423667..bd83ea69 100644 --- a/app/scanner/device_user.h +++ b/app/scanner/device_user.h @@ -56,10 +56,6 @@ private: signals: void newImage(void *image); - void closeReq(); - -private slots: - void on_closeReq(); private: QWidget *m_wnd; diff --git a/app/scanner/mainwindow.cpp b/app/scanner/mainwindow.cpp index 77128ddb..72cc43a2 100644 --- a/app/scanner/mainwindow.cpp +++ b/app/scanner/mainwindow.cpp @@ -33,6 +33,7 @@ #include "dialog_savemessagebox.h" #include "base/HGInfo.h" #include "huagao/hgscanner_error.h" +#include "base/HGTime.h" #include "imgfmt/HGPdf.h" #include "imgfmt/HGTiff.h" #include "imgfmt/HGImgFmt.h" @@ -65,7 +66,6 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) , m_singleScan(false) , m_scanType(0) , m_scanInsertPos(-1) - , m_saveType(0) , m_scanFileName("") , m_scanImgFmtWriter(nullptr) , m_isScanning(false) @@ -326,8 +326,7 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) ui->act_consume->setVisible(false); - connect(this, SIGNAL(pre_new_image(void*)), this, SLOT(on_pre_new_image(void*)), Qt::BlockingQueuedConnection); - connect(this, SIGNAL(post_new_image(unsigned int)), this, SLOT(on_post_new_image(unsigned int)), Qt::BlockingQueuedConnection); + connect(this, SIGNAL(post_new_image(QString)), this, SLOT(on_post_new_image(QString))); m_wndStatusBar->setDeviceStatusInfo(tr("nodevice"), false); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%s", getStdString(tr("nodevice")).c_str()); @@ -968,17 +967,55 @@ void MainWindow::on_clearCache() m_thumb->removeItems(removeItems, HGImgThumb::ThumbRemoveFlag_NULL); } -void MainWindow::on_pre_new_image(void* img) +void MainWindow::on_post_new_image(QString fileName) { - m_saveType = 0; - - HGImage image = (HGImage)img; + HGULonglong t1; + HGBase_GetTickCount(&t1); + qDebug("on_post_new_image start, m_currScanCount=%d", m_currScanCount); if (1 == m_scanType) { - m_scanFileName = getCacheFileName(image); - m_saveType = 1; - return; + if (-1 == m_scanInsertPos) + { + m_thumb->addItem(fileName, false); + } + else + { + m_thumb->insertItem(fileName, m_scanInsertPos, false); + ++m_scanInsertPos; + } + } + else if (2 == m_scanType) + { + m_thumb->addItem(fileName, false); + } + + HGULonglong t2; + HGBase_GetTickCount(&t2); + HGDouble seconds; + HGBase_GetIntervalSeconds(t1, t2, &seconds); + qDebug("on_post_new_image end, m_currScanCount=%d, seconds=%f", m_currScanCount, seconds); + m_currScanCount++; +} + +void MainWindow::on_newImage(void *image) +{ + HGULonglong t1; + HGBase_GetTickCount(&t1); + qDebug("on_newImage start, m_currScanCount=%d", m_currScanCount); + + if (1 == m_scanType) + { + m_scanFileName = getCacheFileName((HGImage)image); + + HGImgFmtSaveInfo info; + info.jpegQuality = 100; + info.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; + info.tiffJpegQuality = 0; + if (HGBASE_ERR_OK == HGImgFmt_SaveImage((HGImage)image, 0, &info, getStdString(m_scanFileName).c_str())) + { + emit post_new_image(m_scanFileName); + } } else if (2 == m_scanType) { @@ -991,23 +1028,10 @@ void MainWindow::on_pre_new_image(void* img) if (m_aquireIntoSaveParam.m_isSaveAsMultiPage) { - if (1 == m_aquireIntoSaveParam.m_multiPagesType && m_aquireIntoMultiPageCount == m_aquireIntoSaveParam.m_customMultiPages) - { - if (nullptr != m_scanImgFmtWriter) - { - HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); - m_scanImgFmtWriter = nullptr; - m_thumb->addItem(m_scanFileName); - m_scanFileName.clear(); - ++m_aquireIntoSaveParam.m_fileNameStartIndex; - m_aquireIntoMultiPageCount = 0; - } - } - if (nullptr == m_scanImgFmtWriter) { assert(m_scanFileName.isEmpty()); - HGResult ret = HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str()); + HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str()); QString scanFileName; while (1) @@ -1026,15 +1050,53 @@ void MainWindow::on_pre_new_image(void* img) } } - ret = HGImgFmt_OpenImageWriter(getStdString(getStdFileName(scanFileName)).c_str(), 0, &m_scanImgFmtWriter); - + HGImgFmt_OpenImageWriter(getStdString(getStdFileName(scanFileName)).c_str(), 0, &m_scanImgFmtWriter); if (nullptr != m_scanImgFmtWriter) + { m_scanFileName = scanFileName; + } } if (nullptr != m_scanImgFmtWriter) { - m_saveType = 2; + 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((HGImage)image, &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; + } + + if (HGBASE_ERR_OK == HGImgFmt_SaveImageToWriter(m_scanImgFmtWriter, (HGImage)image, &saveInfo)) + { + if (1 == m_aquireIntoSaveParam.m_multiPagesType && m_aquireIntoMultiPageCount == m_aquireIntoSaveParam.m_customMultiPages) + { + HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); + m_scanImgFmtWriter = nullptr; + emit post_new_image(m_scanFileName); + m_scanFileName.clear(); + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + m_aquireIntoMultiPageCount = 0; + } + else + { + ++m_aquireIntoMultiPageCount; + } + } } } else @@ -1045,7 +1107,7 @@ void MainWindow::on_pre_new_image(void* img) if (m_aquireIntoSaveParam.m_isUseSubfolderByBlankPages) { HGBool isBlank = HGFALSE; - HGImgProc_ImageBlankCheck(image, nullptr, &isBlank); + HGImgProc_ImageBlankCheck((HGImage)image, nullptr, &isBlank); if (isBlank) { m_aquireIntoInBlank = true; @@ -1069,7 +1131,7 @@ void MainWindow::on_pre_new_image(void* img) { QString colorModeName; HGImageInfo imgInfo; - HGBase_GetImageInfo(image, &imgInfo); + HGBase_GetImageInfo((HGImage)image, &imgInfo); if (HGBASE_IMGTYPE_BINARY == imgInfo.type) colorModeName = tr("binary"); else if (HGBASE_IMGTYPE_GRAY == imgInfo.type) @@ -1080,7 +1142,7 @@ void MainWindow::on_pre_new_image(void* img) savePath = getStdFileName(savePath + colorModeName + "/"); } - HGResult ret = HGBase_CreateDir(getStdString(savePath).c_str()); + HGBase_CreateDir(getStdString(savePath).c_str()); while (1) { @@ -1098,119 +1160,43 @@ void MainWindow::on_pre_new_image(void* img) } } - m_saveType = 3; - } - } -} + HGImgFmtSaveInfo saveInfo; + saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality; + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; + saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality; -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) + HGImageInfo imgInfo; + HGBase_GetImageInfo((HGImage)image, &imgInfo); + if (HGBASE_IMGTYPE_BINARY == imgInfo.type) { - m_thumb->addItem(m_scanFileName); + if (1 == m_aquireIntoSaveParam.m_tiffCompressionBW) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; + else if (2 == m_aquireIntoSaveParam.m_tiffCompressionBW) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; } else { - m_thumb->insertItem(m_scanFileName, m_scanInsertPos); - ++m_scanInsertPos; + if (1 == m_aquireIntoSaveParam.m_tiffCompression) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; + else if (2 == m_aquireIntoSaveParam.m_tiffCompression) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; } - } - } - 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) + + if (HGBASE_ERR_OK == saveImage((HGImage)image, &saveInfo, m_aquireIntoSaveParam.m_isOcr, 0, getStdString(m_scanFileName).c_str())) { - m_thumb->addItem(m_scanFileName); + emit post_new_image(m_scanFileName); ++m_aquireIntoSaveParam.m_fileNameStartIndex; } } } - m_currScanCount++; + HGULonglong t2; + HGBase_GetTickCount(&t2); + HGDouble seconds; + HGBase_GetIntervalSeconds(t1, t2, &seconds); + qDebug("on_newImage end, m_currScanCount=%d, seconds=%f", m_currScanCount, seconds); } - -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); -} - +#if 0 void MainWindow::on_wrong_image_decide(dialog_wrong_img* dlg, bool save) { int i = 0; @@ -1242,7 +1228,7 @@ void MainWindow::on_wrong_image_decide(dialog_wrong_img* dlg, bool save) delete dlg; } - +#endif void MainWindow::on_m_pbtn_push_clicked() { int mainWndWidth = this->rect().width(); @@ -1383,7 +1369,7 @@ QString MainWindow::getCacheFileName(HGImage img) HGImage MainWindow::createImage() { - qDebug("createImage"); + //qDebug("createImage"); assert(-1 != m_currIndex && -1 != m_multiIndex); assert(!m_currFilePath.isEmpty()); @@ -1429,7 +1415,7 @@ int MainWindow::getMultiPageCount() HGImgFmt_CloseImageReader(imgFmtReader); } - qDebug("pageCount=%d", count); + //qDebug("pageCount=%d", count); return count; } diff --git a/app/scanner/mainwindow.h b/app/scanner/mainwindow.h index ceff42ce..05abe333 100644 --- a/app/scanner/mainwindow.h +++ b/app/scanner/mainwindow.h @@ -94,8 +94,7 @@ private slots: void on_act_autoSave_triggered(); signals: - void pre_new_image(void* img); - void post_new_image(unsigned int ret); + void post_new_image(QString fileName); private slots: void on_AcquireInto2(); @@ -117,10 +116,9 @@ private slots: void on_dialog_multirotate_refreshImgFile(const QString &fileName); void on_multiPageLineEditFinished(); void on_clearCache(); - void on_pre_new_image(void* img); - void on_post_new_image(unsigned int ret); + void on_post_new_image(QString fileName); 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_dialog_sideBar_applyToImage(HGImage img, int brightness, int contrast, double gamma, bool enhanceText); void on_dialog_sideBar_finish(bool ok); @@ -299,7 +297,6 @@ private: bool m_singleScan; // 是否单张扫描 int m_scanType; // 1-扫描到缓存目录,2-扫描到本地目录 int m_scanInsertPos; // 扫描插入位置,-1表示插入到最后 - int m_saveType; QString m_scanFileName; HGImgFmtWriter m_scanImgFmtWriter; AquireIntoSaveParam m_aquireIntoSaveParam; diff --git a/modules/base/HGTime.h b/modules/base/HGTime.h index 8d7ab784..b2b47f52 100644 --- a/modules/base/HGTime.h +++ b/modules/base/HGTime.h @@ -1,4 +1,4 @@ -#ifndef __HGTIME_H__ +#ifndef __HGTIME_H__ #define __HGTIME_H__ #include "HGDef.h" @@ -12,7 +12,7 @@ typedef struct HGUShort year; HGUShort month; HGUShort day; - HGUShort dayOfWeek; /* 0Ϊ, 1-6ʾһ */ + HGUShort dayOfWeek; /* 0为星期天, 1-6表示星期一到星期六 */ HGUShort hour; HGUShort minute; HGUShort second;