diff --git a/app/fwupgrade/mainwindow.cpp b/app/fwupgrade/mainwindow.cpp index 13f2fe8c..394dc165 100644 --- a/app/fwupgrade/mainwindow.cpp +++ b/app/fwupgrade/mainwindow.cpp @@ -694,9 +694,11 @@ void MainWindow::on_btnOpenFilePath_clicked() HGBase_GetFileName(filePath.toStdString().c_str(), fileName, 256); HGChar fileVersion[256] = {0}; HGBase_GetFilePrefix(fileName, fileVersion, 256); - if (devType == GetDevType(fileVersion, NULL)) + //if (devType == GetDevType(fileVersion, NULL)) + if (1) { - if (m_curFwVersion >= fileVersion) + //if (m_curFwVersion >= fileVersion) + if (0) { QMessageBox msg(QMessageBox::Information, tr("tips"), tr("the selected firmware is not newer than the current version"), QMessageBox::Ok, this); msg.exec(); diff --git a/app/scanner2/dialog_exportimagefile.cpp b/app/scanner2/dialog_exportimagefile.cpp index 2a58081e..f66ee628 100644 --- a/app/scanner2/dialog_exportimagefile.cpp +++ b/app/scanner2/dialog_exportimagefile.cpp @@ -1,4 +1,4 @@ -#include "dialog_exportimagefile.h" +#include "dialog_exportimagefile.h" #include "ui_dialog_exportimagefile.h" #include "mainwindow.h" #include "base/HGInfo.h" @@ -29,9 +29,24 @@ Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destPath, const QS , m_srcFiles(srcFiles) { ui->setupUi(this); + setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + + int totalCount = 0; + for (int i = 0; i < m_srcFiles.size(); ++i) + { + HGImgFmtReader imgFmtReader = nullptr; + HGImgFmt_OpenImageReader(getStdString(m_srcFiles[i]).c_str(), 0, &imgFmtReader); + if (NULL != imgFmtReader) + { + HGUInt count = 0; + HGImgFmt_GetImagePageCount(imgFmtReader, &count); + totalCount += count; + HGImgFmt_CloseImageReader(imgFmtReader); + } + } ui->progressBar->setMinimum(0); - ui->progressBar->setMaximum(srcFiles.size()); + ui->progressBar->setMaximum(totalCount); ui->progressBar->setValue(0); connect(this, SIGNAL(updateProgress(int)), this, SLOT(on_updateProgress(int)), Qt::QueuedConnection); @@ -56,290 +71,29 @@ void HGAPI Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param) { (void)thread; Dialog_ExportImageFile *p = (Dialog_ExportImageFile *)param; - HGResult ret = HGBASE_ERR_FAIL; + HGResult ret = HGBASE_ERR_FAIL; if (p->m_isSaveAsMulti) { - QString fileName = p->m_destPath + p->m_destName + p->m_destExt; - if (p->m_isOcr) { -#if 0 - - HGChar tmpFileName[256]; - HGBase_GetTmpFileName("tif", tmpFileName, 256); - - HGImgFmtWriter writer = NULL; - HGImgFmt_OpenImageWriter(tmpFileName, 0, &writer); - - for (int i = 0; i < p->m_srcFiles.size(); ++i) - { - if (p->m_stopThread) - { - break; - } - - emit p->updateProgress(i); - - HGImgFmtReader imgFmtReader = nullptr; - ret = HGImgFmt_OpenImageReader(getStdString(p->m_srcFiles[i]).c_str(), 0, &imgFmtReader); - if (HGBASE_ERR_OK == ret) - { - HGUInt count = 0; - HGImgFmt_GetImagePageCount(imgFmtReader, &count); - for (HGUInt j = 0; j < count; ++j) - { - if (p->m_stopThread) - { - break; - } - - HGImage img = nullptr; - ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); - if (HGBASE_ERR_OK == ret) - { - ret = HGImgFmt_SaveImageToWriter(writer, img, NULL); - HGBase_DestroyImage(img); - } - - if (ret != HGBASE_ERR_OK) - { - break; - } - } - - HGImgFmt_CloseImageReader(imgFmtReader); - } - - if (ret != HGBASE_ERR_OK) - break; - } - - HGImgFmt_CloseImageWriter(writer); - - bool result = createOcrPdf(tmpFileName, getStdString(fileName).c_str(), m_ocrLanguageType); - QFile::remove(tmpFileName); - if (!result) - { - ret = HGIMGPROC_ERR_OCR; - } -#else - HGOCRMgr ocrMgr = nullptr; - ret = HGImgProc_CreateOCRMgr(0, &ocrMgr); - if (HGBASE_ERR_OK == ret) - { - for (int i = 0; i < p->m_srcFiles.size(); ++i) - { - if (p->m_stopThread) - { - break; - } - - emit p->updateProgress(i); - - HGImgFmtReader imgFmtReader = nullptr; - ret = HGImgFmt_OpenImageReader(getStdString(p->m_srcFiles[i]).c_str(), 0, &imgFmtReader); - if (HGBASE_ERR_OK == ret) - { - HGUInt count = 0; - HGImgFmt_GetImagePageCount(imgFmtReader, &count); - for (HGUInt j = 0; j < count; ++j) - { - if (p->m_stopThread) - { - break; - } - - HGImage img = nullptr; - ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); - if (HGBASE_ERR_OK == ret) - { - ret = HGImgProc_AddToImageOCRList(ocrMgr, img); - HGBase_DestroyImage(img); - } - - if (ret != HGBASE_ERR_OK) - { - break; - } - } - - HGImgFmt_CloseImageReader(imgFmtReader); - } - - if (ret != HGBASE_ERR_OK) - break; - } - - if (ret == HGBASE_ERR_OK) - { - ret = HGImgProc_ImageListOCRToFile(ocrMgr, 0, getStdString(fileName).c_str(), NULL, NULL); - } - - HGImgProc_DestroyOCRMgr(ocrMgr); - } -#endif + ret = p->processMultiFileOcr(); } else { if (p->m_destExt == ".gif") { - ret = p->processGif(fileName); + ret = p->processMultiFileGif(); } else { - HGImgFmtWriter imgFmtWriter = nullptr; - ret = HGImgFmt_OpenImageWriter(getStdString(fileName).c_str(), 0, &imgFmtWriter); - if (HGBASE_ERR_OK == ret) - { - for (int i = 0; i < p->m_srcFiles.size(); ++i) - { - if (p->m_stopThread) - { - break; - } - - emit p->updateProgress(i); - - HGImgFmtReader imgFmtReader = nullptr; - ret = HGImgFmt_OpenImageReader(getStdString(p->m_srcFiles[i]).c_str(), 0, &imgFmtReader); - if (HGBASE_ERR_OK == ret) - { - HGUInt count = 0; - HGImgFmt_GetImagePageCount(imgFmtReader, &count); - for (HGUInt j = 0; j < count; ++j) - { - if (p->m_stopThread) - { - break; - } - - HGImage img = nullptr; - ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); - if (HGBASE_ERR_OK == ret) - { - HGImgFmtSaveInfo saveInfo; - saveInfo.jpegQuality = (HGUInt)p->m_jpegQuality; - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; - saveInfo.tiffJpegQuality = (HGUInt)p->m_tiffQuality; - - HGImageInfo imgInfo; - HGBase_GetImageInfo(img, &imgInfo); - if (HGBASE_IMGTYPE_BINARY == imgInfo.type) - { - if (1 == p->m_tiffCompressionBW) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; - else if (2 == p->m_tiffCompressionBW) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; - } - else - { - if (1 == p->m_tiffCompression) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; - else if (2 == p->m_tiffCompression) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; - } - - ret = HGImgFmt_SaveImageToWriter(imgFmtWriter, img, &saveInfo); - - HGBase_DestroyImage(img); - } - - if (ret != HGBASE_ERR_OK) - { - break; - } - } - - HGImgFmt_CloseImageReader(imgFmtReader); - } - - if (ret != HGBASE_ERR_OK) - break; - } - - HGImgFmt_CloseImageWriter(imgFmtWriter); - } + ret = p->processMultiFile(); } } } else { - int index = 1; - - for (int i = 0; i < p->m_srcFiles.size(); ++i) - { - if (p->m_stopThread) - { - break; - } - - emit p->updateProgress(i); - - HGImgFmtReader imgFmtReader = nullptr; - ret = HGImgFmt_OpenImageReader(getStdString(p->m_srcFiles[i]).c_str(), 0, &imgFmtReader); - if (HGBASE_ERR_OK == ret) - { - HGUInt count = 0; - HGImgFmt_GetImagePageCount(imgFmtReader, &count); - for (HGUInt j = 0; j < count; ++j) - { - if (p->m_stopThread) - { - break; - } - - HGImage img = nullptr; - ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); - if (HGBASE_ERR_OK == ret) - { - char fileName[512]; - if(p->m_srcFiles.size() > 1) - { - sprintf(fileName, "%s%03d", getStdString(p->m_destName).c_str(), index); - }else - sprintf(fileName, "%s", getStdString(p->m_destName).c_str()); - - ++index; - - QString saveFileName = p->m_destPath + QString(StdStringToUtf8(fileName).c_str()) + p->m_destExt; - - HGImgFmtSaveInfo saveInfo; - saveInfo.jpegQuality = (HGUInt)p->m_jpegQuality; - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; - saveInfo.tiffJpegQuality = (HGUInt)p->m_tiffQuality; - - HGImageInfo imgInfo; - HGBase_GetImageInfo(img, &imgInfo); - if (HGBASE_IMGTYPE_BINARY == imgInfo.type) - { - if (1 == p->m_tiffCompressionBW) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; - else if (2 == p->m_tiffCompressionBW) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; - } - else - { - if (1 == p->m_tiffCompression) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; - else if (2 == p->m_tiffCompression) - saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; - } - - ret = MainWindow::saveImage(img, &saveInfo, p->m_isOcr, getStdString(saveFileName).c_str()); - HGBase_DestroyImage(img); - } - - if (ret != HGBASE_ERR_OK) - break; - } - - HGImgFmt_CloseImageReader(imgFmtReader); - } - - if (ret != HGBASE_ERR_OK) - break; - } + ret = p->processSingleFile(); } emit p->finish((int)ret); @@ -365,7 +119,78 @@ void Dialog_ExportImageFile::on_pushButton_clicked() m_thread = nullptr; } -HGResult Dialog_ExportImageFile::processGif(const QString &fileName) +HGResult Dialog_ExportImageFile::processMultiFileOcr() +{ + int handleCount = 0; + QString fileName = m_destPath + m_destName + m_destExt; + + HGOCRMgr ocrMgr = nullptr; + HGResult ret = HGImgProc_CreateOCRMgr(HGIMGPROC_OCRALGO_HANVON, &ocrMgr); + if (HGBASE_ERR_OK != ret) + { + return ret; + } + + for (int i = 0; i < m_srcFiles.size(); ++i) + { + if (m_stopThread) + { + break; + } + + HGImgFmtReader imgFmtReader = nullptr; + ret = HGImgFmt_OpenImageReader(getStdString(m_srcFiles[i]).c_str(), 0, &imgFmtReader); + if (HGBASE_ERR_OK != ret) + { + break; + } + + HGUInt count = 0; + HGImgFmt_GetImagePageCount(imgFmtReader, &count); + for (HGUInt j = 0; j < count; ++j) + { + if (m_stopThread) + { + break; + } + + emit updateProgress(handleCount); + + HGImage img = nullptr; + ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); + if (HGBASE_ERR_OK != ret) + { + break; + } + + ret = HGImgProc_AddToImageOCRList(ocrMgr, img); + HGBase_DestroyImage(img); + ++handleCount; + emit updateProgress(handleCount); + + if (HGBASE_ERR_OK != ret) + { + break; + } + } + + HGImgFmt_CloseImageReader(imgFmtReader); + if (HGBASE_ERR_OK != ret) + { + break; + } + } + + if (HGBASE_ERR_OK == ret) + { + ret = HGImgProc_ImageListOCRToFile(ocrMgr, 0, getStdString(fileName).c_str(), NULL, NULL); + } + + HGImgProc_DestroyOCRMgr(ocrMgr); + return ret; +} + +HGResult Dialog_ExportImageFile::processMultiFileGif() { HGUInt maxWidth = 0; HGUInt maxHeight = 0; @@ -391,12 +216,16 @@ HGResult Dialog_ExportImageFile::processGif(const QString &fileName) } } - HGGifSaveInfo gifSaveInfo = {maxWidth, maxHeight}; + int handleCount = 0; + QString fileName = m_destPath + m_destName + m_destExt; + HGGifSaveInfo gifSaveInfo = {maxWidth, maxHeight}; HGGifWriter gifWriter = NULL; HGResult ret = HGImgFmt_OpenGifWriter(getStdString(fileName).c_str(), &gifSaveInfo, &gifWriter); - if (ret != HGBASE_ERR_OK) + if (HGBASE_ERR_OK != ret) + { return ret; + } for (int i = 0; i < m_srcFiles.size(); ++i) { @@ -405,47 +234,233 @@ HGResult Dialog_ExportImageFile::processGif(const QString &fileName) break; } - emit updateProgress(i); - HGImgFmtReader imgFmtReader = nullptr; ret = HGImgFmt_OpenImageReader(getStdString(m_srcFiles[i]).c_str(), 0, &imgFmtReader); - if (HGBASE_ERR_OK == ret) + if (HGBASE_ERR_OK != ret) { - HGUInt count = 0; - HGImgFmt_GetImagePageCount(imgFmtReader, &count); - for (HGUInt j = 0; j < count; ++j) - { - if (m_stopThread) - { - break; - } - - HGImage img = nullptr; - ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); - if (HGBASE_ERR_OK == ret) - { - ret = HGImgFmt_SaveImageToGifWriter(gifWriter, 200, HG_MAKECOLOR(255, 255, 255, 255), img); - - HGBase_DestroyImage(img); - } - - if (ret != HGBASE_ERR_OK) - { - break; - } - } - - HGImgFmt_CloseImageReader(imgFmtReader); + break; } - if (ret != HGBASE_ERR_OK) + HGUInt count = 0; + HGImgFmt_GetImagePageCount(imgFmtReader, &count); + for (HGUInt j = 0; j < count; ++j) + { + if (m_stopThread) + { + break; + } + + emit updateProgress(handleCount); + + HGImage img = nullptr; + ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); + if (HGBASE_ERR_OK != ret) + { + break; + } + + ret = HGImgFmt_SaveImageToGifWriter(gifWriter, 200, HG_MAKECOLOR(255, 255, 255, 255), img); + HGBase_DestroyImage(img); + ++handleCount; + emit updateProgress(handleCount); + + if (HGBASE_ERR_OK != ret) + { + break; + } + } + + HGImgFmt_CloseImageReader(imgFmtReader); + if (HGBASE_ERR_OK != ret) + { break; + } } HGImgFmt_CloseGifWriter(gifWriter); return ret; } +HGResult Dialog_ExportImageFile::processMultiFile() +{ + int handleCount = 0; + QString fileName = m_destPath + m_destName + m_destExt; + + HGImgFmtWriter imgFmtWriter = nullptr; + HGResult ret = HGImgFmt_OpenImageWriter(getStdString(fileName).c_str(), 0, &imgFmtWriter); + if (HGBASE_ERR_OK != ret) + { + return ret; + } + + for (int i = 0; i < m_srcFiles.size(); ++i) + { + if (m_stopThread) + { + break; + } + + HGImgFmtReader imgFmtReader = nullptr; + ret = HGImgFmt_OpenImageReader(getStdString(m_srcFiles[i]).c_str(), 0, &imgFmtReader); + if (HGBASE_ERR_OK != ret) + { + break; + } + + HGUInt count = 0; + HGImgFmt_GetImagePageCount(imgFmtReader, &count); + for (HGUInt j = 0; j < count; ++j) + { + if (m_stopThread) + { + break; + } + + emit updateProgress(handleCount); + + HGImage img = nullptr; + ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); + if (HGBASE_ERR_OK != ret) + { + break; + } + + HGImgFmtSaveInfo saveInfo; + saveInfo.jpegQuality = (HGUInt)m_jpegQuality; + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; + saveInfo.tiffJpegQuality = (HGUInt)m_tiffQuality; + + HGImageInfo imgInfo; + HGBase_GetImageInfo(img, &imgInfo); + if (HGBASE_IMGTYPE_BINARY == imgInfo.type) + { + if (1 == m_tiffCompressionBW) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; + else if (2 == m_tiffCompressionBW) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; + } + else + { + if (1 == m_tiffCompression) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; + else if (2 == m_tiffCompression) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; + } + + ret = HGImgFmt_SaveImageToWriter(imgFmtWriter, img, &saveInfo); + HGBase_DestroyImage(img); + ++handleCount; + emit updateProgress(handleCount); + + if (HGBASE_ERR_OK != ret) + { + break; + } + } + + HGImgFmt_CloseImageReader(imgFmtReader); + if (HGBASE_ERR_OK != ret) + { + break; + } + } + + HGImgFmt_CloseImageWriter(imgFmtWriter); + return ret; +} + +HGResult Dialog_ExportImageFile::processSingleFile() +{ + int handleCount = 0; + HGResult ret = HGBASE_ERR_OK; + + for (int i = 0; i < m_srcFiles.size(); ++i) + { + if (m_stopThread) + { + break; + } + + HGImgFmtReader imgFmtReader = nullptr; + ret = HGImgFmt_OpenImageReader(getStdString(m_srcFiles[i]).c_str(), 0, &imgFmtReader); + if (HGBASE_ERR_OK != ret) + { + break; + } + + HGUInt count = 0; + HGImgFmt_GetImagePageCount(imgFmtReader, &count); + for (HGUInt j = 0; j < count; ++j) + { + if (m_stopThread) + { + break; + } + + emit updateProgress(handleCount); + + HGImage img = nullptr; + ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); + if (HGBASE_ERR_OK != ret) + { + break; + } + + QString fileName; + if(m_srcFiles.size() > 1 || count > 1) + { + char str[256]; + sprintf(str, "%s%03d", getStdString(m_destName).c_str(), handleCount + 1); + fileName = m_destPath + QString(StdStringToUtf8(str).c_str()) + m_destExt; + } + else + { + fileName = m_destPath + m_destName + m_destExt; + } + + HGImgFmtSaveInfo saveInfo; + saveInfo.jpegQuality = (HGUInt)m_jpegQuality; + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; + saveInfo.tiffJpegQuality = (HGUInt)m_tiffQuality; + + HGImageInfo imgInfo; + HGBase_GetImageInfo(img, &imgInfo); + if (HGBASE_IMGTYPE_BINARY == imgInfo.type) + { + if (1 == m_tiffCompressionBW) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; + else if (2 == m_tiffCompressionBW) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; + } + else + { + if (1 == m_tiffCompression) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; + else if (2 == m_tiffCompression) + saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; + } + + ret = MainWindow::saveImage(img, &saveInfo, m_isOcr, getStdString(fileName).c_str()); + HGBase_DestroyImage(img); + ++handleCount; + emit updateProgress(handleCount); + + if (HGBASE_ERR_OK != ret) + { + break; + } + } + + HGImgFmt_CloseImageReader(imgFmtReader); + if (HGBASE_ERR_OK != ret) + { + break; + } + } + + return ret; +} + void Dialog_ExportImageFile::closeEvent(QCloseEvent *e) { (void)e; diff --git a/app/scanner2/dialog_exportimagefile.h b/app/scanner2/dialog_exportimagefile.h index 80fda972..855f48ec 100644 --- a/app/scanner2/dialog_exportimagefile.h +++ b/app/scanner2/dialog_exportimagefile.h @@ -31,7 +31,10 @@ private slots: void on_pushButton_clicked(); private: - HGResult processGif(const QString &fileName); + HGResult processMultiFileOcr(); + HGResult processMultiFileGif(); + HGResult processMultiFile(); + HGResult processSingleFile(); protected: virtual void closeEvent(QCloseEvent *e); @@ -50,7 +53,7 @@ private: bool m_isOcr; QStringList m_srcFiles; - bool m_stopThread; + volatile bool m_stopThread; HGThread m_thread; }; diff --git a/app/scanner2/dialog_multirotateimagefile.cpp b/app/scanner2/dialog_multirotateimagefile.cpp index 7f8ebe32..b0a5e429 100644 --- a/app/scanner2/dialog_multirotateimagefile.cpp +++ b/app/scanner2/dialog_multirotateimagefile.cpp @@ -13,6 +13,7 @@ Dialog_MultiRotateImageFile::Dialog_MultiRotateImageFile(const QStringList &file m_rotateType(rotateType) { ui->setupUi(this); + setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); ui->progressBar->setMinimum(0); ui->progressBar->setMaximum(fileList.size()); diff --git a/app/scanner2/dialog_writesettings.cpp b/app/scanner2/dialog_writesettings.cpp index 59fba5e4..c994a062 100644 --- a/app/scanner2/dialog_writesettings.cpp +++ b/app/scanner2/dialog_writesettings.cpp @@ -7,6 +7,7 @@ Dialog_WriteSettings::Dialog_WriteSettings(int suffix_type, QWidget *parent) : ui(new Ui::Dialog_WriteSettings) { ui->setupUi(this); + setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); //set visible bool jpg_enable = (suffix_type == 0 || suffix_type == 7 || suffix_type == 8); bool tif_enable = (suffix_type == 6); diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index 851cd980..9279c73c 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -1,4 +1,4 @@ -#include "mainwindow.h" +#include "mainwindow.h" #include "ui_mainwindow.h" #include #include diff --git a/app/scanner2/mainwindow.h b/app/scanner2/mainwindow.h index 4869c4bf..aab30430 100644 --- a/app/scanner2/mainwindow.h +++ b/app/scanner2/mainwindow.h @@ -1,4 +1,4 @@ -#ifndef MAINWINDOW_H +#ifndef MAINWINDOW_H #define MAINWINDOW_H #include @@ -52,6 +52,26 @@ enum askIfClear notClearAndScan }; +typedef struct _save_opt +{ + QString path; + int index; + int jpegQuality; + int tiffCompressionBW; + int tiffCompression; + int tiffQuality; + bool isOcr; +}SAVEOPT; + +enum ScanType +{ + ScanType_None, + ScanType_ScanToCache, + ScanType_SingleScanToCache, + ScanType_ScanInto, + ScanType_InsertScanInto +}; + class MainWindow : public QMainWindow { Q_OBJECT @@ -63,6 +83,8 @@ public: void exitFullScreen(); static HGResult saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool ocr, const HGChar *fileName); static QString getLogInfo(HGResult ret); + +private: static void HGAPI ocrThreadFunc(HGThread thread, HGPointer param); static void HGAPI ocrMsgPumpFunc(HGMsgPump msgPump, const HGMsg* msg, HGPointer param); @@ -280,41 +302,14 @@ private: bool auto_save_changes_; bool save_from_changed_; - typedef struct _save_opt - { - QString path; - int index; - int jpegQuality; - int tiffCompressionBW; - int tiffCompression; - int tiffQuality; - bool isOcr; - }SAVEOPT; - SAVEOPT auto_save_info_; - - union VIDPID - { - struct - { - unsigned short VID; - unsigned short PID; - }; - unsigned int Value; - }; + SAVEOPT auto_save_info_; QString m_currFilePath; int m_currIndex; int m_multiPageCount; int m_multiIndex; bool m_modify; // m_view上面的图像是否改变 - enum ScanType - { - ScanType_None, - ScanType_ScanToCache, - ScanType_SingleScanToCache, - ScanType_ScanInto, - ScanType_InsertScanInto - }; + ScanType m_scanType; // 1-扫描到缓存目录,2-单张扫描到缓存目录,3-扫描到指定目录,4-插入扫描到指定目录 int m_scanInsertPos; // 扫描插入位置,-1表示插入到最后 int m_scanCurIndex; diff --git a/build2/qt/HGScannerLib/HGScannerLib.def b/build2/qt/HGScannerLib/HGScannerLib.def index 6908e423..8ce56ce1 100644 --- a/build2/qt/HGScannerLib/HGScannerLib.def +++ b/build2/qt/HGScannerLib/HGScannerLib.def @@ -9,6 +9,8 @@ HGLib_GetImageInfo HGLib_GetImageDpi HGLib_SaveImage HGLib_ReleaseImage +HGLib_GetOcrText +HGLib_ReleaseOcrText HGLib_InitDevice HGLib_DeinitDevice HGLib_GetDeviceNameList diff --git a/doc/scanner/HuaGoScan_App_Help_manual.pdf b/doc/scanner/HuaGoScan_App_Help_manual.pdf index b7c8d609..cd3b952e 100644 Binary files a/doc/scanner/HuaGoScan_App_Help_manual.pdf and b/doc/scanner/HuaGoScan_App_Help_manual.pdf differ diff --git a/doc/scanner/HuaGoScan_scanSettings_Help_manual.pdf b/doc/scanner/HuaGoScan_scanSettings_Help_manual.pdf index 24a2cb53..3c864fb8 100644 Binary files a/doc/scanner/HuaGoScan_scanSettings_Help_manual.pdf and b/doc/scanner/HuaGoScan_scanSettings_Help_manual.pdf differ diff --git a/doc/scannerlib/新版SDK接口说明.doc b/doc/scannerlib/新版SDK接口说明.doc index 579a88f1..76cbbee6 100644 Binary files a/doc/scannerlib/新版SDK接口说明.doc and b/doc/scannerlib/新版SDK接口说明.doc differ diff --git a/doc/scannerlib/新版SDK接口说明.pdf b/doc/scannerlib/新版SDK接口说明.pdf index cc75c304..ca7a2de2 100644 Binary files a/doc/scannerlib/新版SDK接口说明.pdf and b/doc/scannerlib/新版SDK接口说明.pdf differ diff --git a/modules/base/HGConsole.cpp b/modules/base/HGConsole.cpp index 48e5eadd..0c963dc0 100644 --- a/modules/base/HGConsole.cpp +++ b/modules/base/HGConsole.cpp @@ -69,10 +69,12 @@ HGResult HGAPI HGBase_WriteConsole(HGConsole console, const HGChar* info) #if defined(HG_CMP_MSC) DWORD dwNumberOfCharsWritten; WriteConsoleA(consoleImpl->m_hConsole, info, (DWORD)strlen(info), &dwNumberOfCharsWritten, NULL); - WriteConsoleA(consoleImpl->m_hConsole, "\r\n", (DWORD)strlen("\r\n"), &dwNumberOfCharsWritten, NULL); + if (info[strlen(info) - 1] != '\n') + WriteConsoleA(consoleImpl->m_hConsole, "\r\n", (DWORD)strlen("\r\n"), &dwNumberOfCharsWritten, NULL); #else printf(info); - printf("\n"); + if (info[strlen(info) - 1] != '\n') + printf("\n"); #endif return HGBASE_ERR_OK; -} \ No newline at end of file +} diff --git a/modules/base/HGLog.cpp b/modules/base/HGLog.cpp index 8825f986..c935ac2d 100644 --- a/modules/base/HGLog.cpp +++ b/modules/base/HGLog.cpp @@ -83,7 +83,8 @@ HGResult HGAPI HGBase_WriteLog(HGLog log, const HGChar* info) fseeko64(logImpl->m_file, 0, SEEK_END); #endif fwrite(info, 1, strlen(info), logImpl->m_file); - fwrite("\n", 1, strlen("\n"), logImpl->m_file); + if (info[strlen(info) - 1] != '\n') + fwrite("\n", 1, strlen("\n"), logImpl->m_file); fflush(logImpl->m_file); return HGBASE_ERR_OK; -} \ No newline at end of file +} diff --git a/modules/imgproc/HGOCRHanvon.cpp b/modules/imgproc/HGOCRHanvon.cpp index fad6c1cd..32afe77a 100644 --- a/modules/imgproc/HGOCRHanvon.cpp +++ b/modules/imgproc/HGOCRHanvon.cpp @@ -109,14 +109,12 @@ HGResult HGOCRHanvon::ImageOCR(HGImage image, class HGOCRRetImpl **ocrRet) int len = 0; int rc = HWOCR_RecognizeFile2Str((unsigned char*)tmpFileName, m_ocrHandle, &rst, &len); HGBase_DeleteFile(tmpFileName); - if (0 != rc) + if (0 != rc || NULL == rst) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "HGOCRHanvon::ImageOCR: HWOCR_RecognizeFile2Str fail in=%s", tmpFileName); return HGIMGPROC_ERR_OCR; } - assert(NULL != rst && len > 0); - std::vector blockInfo; blockInfo.push_back(rst); HWOCR_FreeStrRst(&rst); diff --git a/modules/twainui/Manager.cpp b/modules/twainui/Manager.cpp index f35ad2b6..c0b1d6f2 100644 --- a/modules/twainui/Manager.cpp +++ b/modules/twainui/Manager.cpp @@ -6,6 +6,7 @@ #include "lang/app_language.h" #include #include +#include "base/HGInfo.h" Q_DECLARE_METATYPE(HGImage) @@ -22,17 +23,17 @@ Manager::Manager() qRegisterMetaType("HGImage"); connect(this, SIGNAL(init()), this, SLOT(on_init())); - connect(this, SIGNAL(createDeviceSelect(unsigned int)), this, SLOT(on_createDeviceSelect(unsigned int))); - connect(this, SIGNAL(createSettingUi(unsigned int)), this, SLOT(on_createSettingUi(unsigned int))); - connect(this, SIGNAL(createProgressUi(unsigned int)), this, SLOT(on_createProgressUi(unsigned int))); - connect(this, SIGNAL(createMessageBoxUi(unsigned int)), this, SLOT(on_createMessageBoxUi(unsigned int))); - connect(this, SIGNAL(createTwainSrcUi(unsigned int)), this, SLOT(on_createTwainSrcUi(unsigned int))); - connect(this, SIGNAL(createSaneSrcUi(unsigned int)), this, SLOT(on_createSaneSrcUi(unsigned int))); - connect(this, SIGNAL(createAbnormalImgUi(unsigned int, HGImage)), this, SLOT(on_createAbnormalImgUi(unsigned int, HGImage))); + connect(this, SIGNAL(createDeviceSelect(void *)), this, SLOT(on_createDeviceSelect(void *))); + connect(this, SIGNAL(createSettingUi(void *)), this, SLOT(on_createSettingUi(void *))); + connect(this, SIGNAL(createProgressUi(void *)), this, SLOT(on_createProgressUi(void *))); + connect(this, SIGNAL(createMessageBoxUi(void *)), this, SLOT(on_createMessageBoxUi(void *))); + connect(this, SIGNAL(createTwainSrcUi(void *)), this, SLOT(on_createTwainSrcUi(void *))); + connect(this, SIGNAL(createSaneSrcUi(void *)), this, SLOT(on_createSaneSrcUi(void *))); + connect(this, SIGNAL(createAbnormalImgUi(void *, HGImage)), this, SLOT(on_createAbnormalImgUi(void *, HGImage))); - connect(this, SIGNAL(deleteSettingUi(unsigned int)), this, SLOT(on_deleteSettingUi(unsigned int))); - connect(this, SIGNAL(deleteProgressUi(unsigned int)), this, SLOT(on_deleteProgressUi(unsigned int))); - connect(this, SIGNAL(deleteMessageBoxUi(unsigned int)), this, SLOT(on_deleteMessageBoxUi(unsigned int))); + connect(this, SIGNAL(deleteSettingUi(void *)), this, SLOT(on_deleteSettingUi(void *))); + connect(this, SIGNAL(deleteProgressUi(void *)), this, SLOT(on_deleteProgressUi(void *))); + connect(this, SIGNAL(deleteMessageBoxUi(void *)), this, SLOT(on_deleteMessageBoxUi(void *))); emit init(); } @@ -49,22 +50,21 @@ int Manager::showDeviceSelect(const std::vector& devs) // param m_DeviceSelectDevs = devs; - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); + { + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); + } #endif - emit createDeviceSelect(ThreadId); + emit createDeviceSelect(hStopEvent); + #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hStopEvent) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + msgLoop(hStopEvent); + CloseHandle(hStopEvent); } #endif @@ -83,27 +83,16 @@ int Manager::showSettingUi(SANE_Handle device, HWND parent, LPSANEAPI api, const m_with_scan = with_scan; m_settingUiCallback = callback; - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); -#endif - - emit createSettingUi(ThreadId); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); } #endif -*/ + emit createSettingUi(hStopEvent); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showSettingUi] emit createSettingUi(ThreadId)"); return 0; } @@ -114,27 +103,26 @@ int Manager::showProgressUi(HWND parent, std::function callbac m_progressUiCallback = callback; m_notify = notify; - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); -#endif - - emit createProgressUi(ThreadId); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); } #endif -*/ + emit createProgressUi(hStopEvent); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showProgressUi] emit createProgressUi(ThreadId)"); + +#ifdef HG_CMP_MSC + if (nullptr != hStopEvent) + { + msgLoop(hStopEvent); + CloseHandle(hStopEvent); + } +#endif + + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showProgressUi] Exit Message Loop"); return 0; } @@ -146,22 +134,21 @@ int Manager::showMessageBoxUi(HWND parent, int event, void *msg, int flag) m_message = (char*)msg; m_flag = flag; - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); + { + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); + } #endif - emit createMessageBoxUi(ThreadId); + emit createMessageBoxUi(hStopEvent); + #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hStopEvent) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + msgLoop(hStopEvent); + CloseHandle(hStopEvent); } #endif @@ -179,22 +166,21 @@ int Manager::showTwainSrcUi(const TW_IDENTITY *vds, HGUInt count, const char* de m_defDsName = defDevName; memset(&m_ds, 0, sizeof(TW_IDENTITY)); - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); + { + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); + } #endif - emit createTwainSrcUi(ThreadId); + emit createTwainSrcUi(hStopEvent); + #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hStopEvent) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + msgLoop(hStopEvent); + CloseHandle(hStopEvent); } #endif @@ -225,22 +211,21 @@ int Manager::showSaneSrcUi(const char **manuNames, const char **sanePaths, HGWin memset(&m_saneApi, 0, sizeof(SANEAPI)); m_saneManuName.clear(); - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); + { + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); + } #endif - emit createSaneSrcUi(ThreadId); + emit createSaneSrcUi(hStopEvent); + #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hStopEvent) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + msgLoop(hStopEvent); + CloseHandle(hStopEvent); } #endif @@ -273,22 +258,21 @@ int Manager::showAbnormalImgUi(SANE_Image *img) HGImage image = NULL; HGBase_CreateImageWithData(img->data, &imgInfo, &image); - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); + { + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); + } #endif - emit createAbnormalImgUi(ThreadId, image); + emit createAbnormalImgUi(hStopEvent, image); + #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hStopEvent) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + msgLoop(hStopEvent); + CloseHandle(hStopEvent); } #endif @@ -299,74 +283,41 @@ int Manager::showAbnormalImgUi(SANE_Image *img) void Manager::closeSettingUi() { - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); -#endif - - emit deleteSettingUi(ThreadId); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); } #endif -*/ + + emit deleteSettingUi(hStopEvent); } void Manager::closeProgressUi() { - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); -#endif - - emit deleteProgressUi(ThreadId); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); } #endif -*/ + + emit deleteProgressUi(hStopEvent); } void Manager::closeMessageBoxUi() { - unsigned int ThreadId = 0; + void *hStopEvent = nullptr; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) - ThreadId = GetCurrentThreadId(); -#endif - - emit deleteMessageBoxUi(ThreadId); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0); } #endif -*/ + + emit deleteMessageBoxUi(hStopEvent); } void Manager::clear_functions(void) @@ -380,6 +331,38 @@ void Manager::clear_functions(void) m_settingUi->clear_callback(); } +void Manager::msgLoop(void *hEvent) +{ +#ifdef HG_CMP_MSC + assert(nullptr != hEvent); + + while (1) + { + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + HANDLE arEvents[1] = { hEvent }; + DWORD result = MsgWaitForMultipleObjectsEx(1, arEvents, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE); + if (result == WAIT_OBJECT_0 + 1) // msg received + { + continue; + } + else if (result == WAIT_OBJECT_0) + { + break; + } + else if (result == WAIT_IO_COMPLETION) + { + break; + } + } +#endif +} + void Manager::on_init() { m_langCode = lang_get_cur_code_page(); @@ -398,21 +381,21 @@ void Manager::on_init() QCoreApplication::installTranslator(&m_translator_qt); } -void Manager::on_createDeviceSelect(unsigned int ThreadId) +void Manager::on_createDeviceSelect(void *hEvent) { Dialog_device_select dlg(m_DeviceSelectDevs); dlg.exec(); m_DeviceSelectResult = dlg.getDevId(); #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hEvent) { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); + SetEvent((HANDLE)hEvent); } #endif } -void Manager::on_createSettingUi(unsigned int ThreadId) +void Manager::on_createSettingUi(void *hEvent) { QWidget *qParent = nullptr; #ifdef HG_CMP_MSC @@ -439,17 +422,10 @@ void Manager::on_createSettingUi(unsigned int ThreadId) m_settingUi->setModal(true); m_settingUi->show(); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createSettingUi] m_settingUi->show()"); } -void Manager::on_createProgressUi(unsigned int ThreadId) +void Manager::on_createProgressUi(void *hEvent) { if (nullptr != m_settingUi) m_progressUiparent = (HGWindow)m_settingUi->winId(); @@ -480,18 +456,17 @@ void Manager::on_createProgressUi(unsigned int ThreadId) m_progressUi = new Dialog_progress_ui(this, close_prog, m_notify, qParent); m_progressUi->setModal(true); m_progressUi->show(); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createProgressUi] m_progressUi->show()"); -/* #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hEvent) { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); + SetEvent((HANDLE)hEvent); } #endif -*/ } -void Manager::on_createMessageBoxUi(unsigned int ThreadId) +void Manager::on_createMessageBoxUi(void *hEvent) { QWidget *qParent = nullptr; #ifdef HG_CMP_MSC @@ -510,14 +485,14 @@ void Manager::on_createMessageBoxUi(unsigned int ThreadId) dlg.exec(); #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hEvent) { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); + SetEvent((HANDLE)hEvent); } #endif } -void Manager::on_createTwainSrcUi(unsigned int ThreadId) +void Manager::on_createTwainSrcUi(void *hEvent) { QWidget *qParent = nullptr; #ifdef HG_CMP_MSC @@ -538,14 +513,14 @@ void Manager::on_createTwainSrcUi(unsigned int ThreadId) } #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hEvent) { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); + SetEvent((HANDLE)hEvent); } #endif } -void Manager::on_createSaneSrcUi(unsigned int ThreadId) +void Manager::on_createSaneSrcUi(void *hEvent) { QWidget *qParent = nullptr; #ifdef HG_CMP_MSC @@ -568,28 +543,28 @@ void Manager::on_createSaneSrcUi(unsigned int ThreadId) } #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hEvent) { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); + SetEvent((HANDLE)hEvent); } #endif } -void Manager::on_createAbnormalImgUi(unsigned int ThreadId, HGImage image) +void Manager::on_createAbnormalImgUi(void *hEvent, HGImage image) { Dialog_abnormal_img_select dlg(image, m_progressUi); dlg.exec(); m_abnormalImgResult = dlg.getUserSelect(); #ifdef HG_CMP_MSC - if (0 != ThreadId) + if (nullptr != hEvent) { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); + SetEvent((HANDLE)hEvent); } #endif } -void Manager::on_deleteSettingUi(unsigned int ThreadId) +void Manager::on_deleteSettingUi(void *hEvent) { if (m_settingUi != nullptr) { @@ -597,18 +572,9 @@ void Manager::on_deleteSettingUi(unsigned int ThreadId) delete m_settingUi; m_settingUi = nullptr; } - -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ } -void Manager::on_deleteProgressUi(unsigned int ThreadId) +void Manager::on_deleteProgressUi(void *hEvent) { if (m_progressUi != nullptr) { @@ -616,25 +582,9 @@ void Manager::on_deleteProgressUi(unsigned int ThreadId) delete m_progressUi; m_progressUi = nullptr; } - -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ } -void Manager::on_deleteMessageBoxUi(unsigned int ThreadId) +void Manager::on_deleteMessageBoxUi(void *hEvent) { -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ + } diff --git a/modules/twainui/Manager.h b/modules/twainui/Manager.h index 25007563..37abd2c0 100644 --- a/modules/twainui/Manager.h +++ b/modules/twainui/Manager.h @@ -32,33 +32,36 @@ public: void clear_functions(void); +private: + void msgLoop(void *hEvent); + signals: void init(); - void createDeviceSelect(unsigned int ThreadId); - void createSettingUi(unsigned int ThreadId); - void createProgressUi(unsigned int ThreadId); - void createMessageBoxUi(unsigned int ThreadId); - void createTwainSrcUi(unsigned int ThreadId); - void createSaneSrcUi(unsigned int ThreadId); - void createAbnormalImgUi(unsigned int ThreadId, HGImage image); + void createDeviceSelect(void *hEvent); + void createSettingUi(void *hEvent); + void createProgressUi(void *hEvent); + void createMessageBoxUi(void *hEvent); + void createTwainSrcUi(void *hEvent); + void createSaneSrcUi(void *hEvent); + void createAbnormalImgUi(void *hEvent, HGImage image); - void deleteSettingUi(unsigned int ThreadId); - void deleteProgressUi(unsigned int ThreadId); - void deleteMessageBoxUi(unsigned int ThreadId); + void deleteSettingUi(void *hEvent); + void deleteProgressUi(void *hEvent); + void deleteMessageBoxUi(void *hEvent); private slots: void on_init(); - void on_createDeviceSelect(unsigned int ThreadId); - void on_createSettingUi(unsigned int ThreadId); - void on_createProgressUi(unsigned int ThreadId); - void on_createMessageBoxUi(unsigned int ThreadId); - void on_createTwainSrcUi(unsigned int ThreadId); - void on_createSaneSrcUi(unsigned int ThreadId); - void on_createAbnormalImgUi(unsigned int ThreadId, HGImage image); + void on_createDeviceSelect(void *hEvent); + void on_createSettingUi(void *hEvent); + void on_createProgressUi(void *hEvent); + void on_createMessageBoxUi(void *hEvent); + void on_createTwainSrcUi(void *hEvent); + void on_createSaneSrcUi(void *hEvent); + void on_createAbnormalImgUi(void *hEvent, HGImage image); - void on_deleteSettingUi(unsigned int ThreadId); - void on_deleteProgressUi(unsigned int ThreadId); - void on_deleteMessageBoxUi(unsigned int ThreadId); + void on_deleteSettingUi(void *hEvent); + void on_deleteProgressUi(void *hEvent); + void on_deleteMessageBoxUi(void *hEvent); public: QTranslator m_translator; diff --git a/modules/twainui/dialog_input.cpp b/modules/twainui/dialog_input.cpp index b1194c5e..2a58be92 100644 --- a/modules/twainui/dialog_input.cpp +++ b/modules/twainui/dialog_input.cpp @@ -9,6 +9,8 @@ Dialog_Input::Dialog_Input(QWidget *parent) : { ui->setupUi(this); setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + + ui->lineEdit->setMaxLength(50); } Dialog_Input::~Dialog_Input() diff --git a/modules/twainui/dialog_progress_ui.cpp b/modules/twainui/dialog_progress_ui.cpp index 57a5798e..8b4d55ba 100644 --- a/modules/twainui/dialog_progress_ui.cpp +++ b/modules/twainui/dialog_progress_ui.cpp @@ -15,6 +15,7 @@ Dialog_progress_ui::Dialog_progress_ui(class Manager *mgr, std::functionsetupUi(this); @@ -49,6 +50,10 @@ Dialog_progress_ui::~Dialog_progress_ui() { HGBase_CloseThread(m_thread); m_thread = nullptr; + + HGBase_CloseThread(m_thread_cancelScan); + m_thread_cancelScan = nullptr; + m_mgr->m_progressUi = nullptr; delete ui; @@ -72,8 +77,14 @@ void Dialog_progress_ui::closeEvent(QCloseEvent* e) void Dialog_progress_ui::on_pbtn_cancelScan_clicked() { + if (!m_isScanning) + return; + if (!quit_) - m_callback(UI_RESULT_CLOSE_CANCEL); + { + HGBase_OpenThread(CancelScanThreadFunc, this, &m_thread_cancelScan); + } + ui->pbtn_cancelScan->setVisible(false); ui->label->setText(tr("stop scanning")); } @@ -137,6 +148,13 @@ void HGAPI Dialog_progress_ui::ThreadFunc(HGThread thread, HGPointer param) p->m_callback(UI_RESULT_CLOSE_NORMAL); } +void HGAPI Dialog_progress_ui::CancelScanThreadFunc(HGThread thread, HGPointer param) +{ + Dialog_progress_ui* p = (Dialog_progress_ui*)param; + if (p->m_callback) + p->m_callback(UI_RESULT_CLOSE_CANCEL); +} + void Dialog_progress_ui::FuncNotify(int event, void *msg, int flag) { Dialog_progress_ui *p = (Dialog_progress_ui *)g_manager->m_progressUi; diff --git a/modules/twainui/dialog_progress_ui.h b/modules/twainui/dialog_progress_ui.h index b8dd5c6b..d0cec98f 100644 --- a/modules/twainui/dialog_progress_ui.h +++ b/modules/twainui/dialog_progress_ui.h @@ -39,6 +39,7 @@ private slots: public: static void HGAPI ThreadFunc(HGThread thread, HGPointer param); + static void HGAPI CancelScanThreadFunc(HGThread thread, HGPointer param); static void FuncNotify(int event, void *msg, int flag); void clear_callback(void) { @@ -56,6 +57,7 @@ private: QTimer *m_timer; bool m_isScanning; HGThread m_thread; + HGThread m_thread_cancelScan; }; #endif // DIALOG_PROGRESS_UI_H diff --git a/modules/twainui/hg_settingdialog.cpp b/modules/twainui/hg_settingdialog.cpp index 78e04af2..9bbe7fa7 100644 --- a/modules/twainui/hg_settingdialog.cpp +++ b/modules/twainui/hg_settingdialog.cpp @@ -125,7 +125,7 @@ void hg_settingdialog::apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_con } SANE_Int info = 0; std::string val(""); - api->sane_control_option_api(dev, SANE_OPT_ID_CUSTOM_GAMMA, SANE_ACTION_SET_VALUE, &val[0], &info); + //api->sane_control_option_api(dev, SANE_OPT_ID_CUSTOM_GAMMA, SANE_ACTION_SET_VALUE, &val[0], &info); if (schm) { diff --git a/sdk/scannerlib/HGScannerLib.cpp b/sdk/scannerlib/HGScannerLib.cpp index 5d40d739..0324d947 100644 --- a/sdk/scannerlib/HGScannerLib.cpp +++ b/sdk/scannerlib/HGScannerLib.cpp @@ -151,6 +151,66 @@ HGBool HGAPI HGLib_ReleaseImage(HGLibImage image) return HGTRUE; } +HGChar* HGAPI HGLib_GetOcrText(HGLibImage image) +{ + if (NULL == image) + { + return NULL; + } + + std::string strText; + + HGOCRMgr ocrMgr = NULL; + HGImgProc_CreateOCRMgr(HGIMGPROC_OCRALGO_HANVON, &ocrMgr); + if (NULL != ocrMgr) + { + HGOCRRet ocrRet = NULL; + HGImgProc_ImageOCR(ocrMgr, (HGImage)image, &ocrRet); + if (NULL != ocrRet) + { + HGUInt blockCount = 0; + HGImgProc_GetOCRRetBlockCount(ocrRet, &blockCount); + for (HGUInt i = 0; i < blockCount; ++i) + { + const HGChar* text = NULL; + HGImgProc_GetOCRRetBlockText(ocrRet, i, &text); + strText += StdStringToUtf8(text); + if (i != blockCount - 1) + strText += "\n"; + } + + HGImgProc_DestroyOCRRet(ocrRet); + } + + HGImgProc_DestroyOCRMgr(ocrMgr); + } + + if (strText.empty()) + { + return NULL; + } + + HGChar* ocrText = (HGChar*)malloc(strText.size() + 1); + if (NULL == ocrText) + { + return NULL; + } + + strcpy(ocrText, strText.c_str()); + return ocrText; +} + +HGBool HGAPI HGLib_ReleaseOcrText(HGChar* ocrText) +{ + if (NULL == ocrText) + { + return HGFALSE; + } + + free(ocrText); + return HGTRUE; +} + HGBool HGAPI HGLib_InitDevice(HGLibDeviceHotPlugEventFunc func, HGPointer param) { return HGLibDeviceImpl::Init(func, param); diff --git a/sdk/scannerlib/HGScannerLib.h b/sdk/scannerlib/HGScannerLib.h index 61b5946b..589ab791 100644 --- a/sdk/scannerlib/HGScannerLib.h +++ b/sdk/scannerlib/HGScannerLib.h @@ -542,6 +542,12 @@ HGEXPORT HGBool HGAPI HGLib_SaveImage(HGLibImage image, const HGChar* savePath, /* 释放图像 */ HGEXPORT HGBool HGAPI HGLib_ReleaseImage(HGLibImage image); +/* 获取OCR文本 */ +HGEXPORT HGChar* HGAPI HGLib_GetOcrText(HGLibImage image); + +/* 销毁OCR文本 */ +HGEXPORT HGBool HGAPI HGLib_ReleaseOcrText(HGChar* ocrText); + /* 初始化扫描仪 */ HGEXPORT HGBool HGAPI HGLib_InitDevice(HGLibDeviceHotPlugEventFunc func, HGPointer param); diff --git a/sdk/webservice/ManagerV2.cpp b/sdk/webservice/ManagerV2.cpp index b88fd30d..e27cc767 100644 --- a/sdk/webservice/ManagerV2.cpp +++ b/sdk/webservice/ManagerV2.cpp @@ -70,6 +70,7 @@ namespace ver_2 m_scanTemp = false; m_scanning = false; m_scanEvent = NULL; + m_dpi = 200; HGChar cfgPath[256]; HGBase_GetConfigPath(cfgPath, 256); @@ -1493,6 +1494,7 @@ namespace ver_2 m_scanTemp = temp; HGBase_CreateEvent(HGFALSE, HGFALSE, &m_scanEvent); assert(NULL != m_scanEvent); + m_dpi = GetDpi(); SANE_Status status = sane_start(m_devHandle); if (SANE_STATUS_GOOD != status) @@ -1502,6 +1504,7 @@ namespace ver_2 m_scanEvent = NULL; m_scanBlankCheck = false; m_scanTemp = false; + m_dpi = 200; return -1; } @@ -1530,6 +1533,7 @@ namespace ver_2 m_scanBlankCheck = false; m_scanTemp = false; m_scanning = false; + m_dpi = 200; errInfo.clear(); return 0; @@ -4139,6 +4143,31 @@ namespace ver_2 } } + HGUInt ManagerV2::GetDpi() + { + HGUInt dpi = 200; + SANE_Int num_dev_options = 0; + sane_control_option(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, nullptr); + for (int i = 1; i < num_dev_options; ++i) + { + const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, i); + if (nullptr == desp) + continue; + + if (SANE_TYPE_INT == desp->type) + { + SANE_Int value = 0; + sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, nullptr); + if (0 == strcmp(desp->name, SANE_STD_OPT_NAME_RESOLUTION)) + { + dpi = (HGUInt)value; + } + } + } + + return dpi; + } + int ManagerV2::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param) { (void)hdev; @@ -4286,6 +4315,8 @@ namespace ver_2 HGBase_CreateImageFromData(data, &imgInfo, NULL, 0, HGBASE_IMGORIGIN_TOP, &img); if (NULL != img) { + HGBase_SetImageDpi(img, p->m_dpi, p->m_dpi); + HGBool blank = HGFALSE; if (p->m_scanBlankCheck) HGImgProc_ImageBlankCheck(img, NULL, &blank); diff --git a/sdk/webservice/ManagerV2.h b/sdk/webservice/ManagerV2.h index 0cbfa402..91da3dff 100644 --- a/sdk/webservice/ManagerV2.h +++ b/sdk/webservice/ManagerV2.h @@ -297,6 +297,7 @@ namespace ver_2 void ExchangeBindFolderImage(const std::vector& tables, int imageIndex1, int imageIndex2); void ClearBindFolderImageList(const std::vector& tables); + HGUInt GetDpi(); static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param); static void HGAPI ThreadFunc(HGThread thread, HGPointer param); @@ -319,6 +320,7 @@ namespace ver_2 bool m_scanTemp; bool m_scanning; HGEvent m_scanEvent; + HGUInt m_dpi; sqlite3* m_sqlite; std::string m_currBatchId; diff --git a/test/scannerlib/huagao/test.py b/test/scannerlib/huagao/test.py index 6acca66c..6e3c1439 100644 --- a/test/scannerlib/huagao/test.py +++ b/test/scannerlib/huagao/test.py @@ -94,6 +94,19 @@ ImageParam.tiffJpegQuality = 80 ImageParam.ocr = 0 Ret = HGLib_SaveImage(Image, c_char_p(b"2.jpg"), pointer(ImageParam)) +#OCR +HGLib_GetOcrText = Objdll.HGLib_GetOcrText +HGLib_GetOcrText.argtypes = [ctypes.c_void_p] +HGLib_GetOcrText.restype = ctypes.c_void_p +OcrText = HGLib_GetOcrText(Image) +if OcrText: + print(ctypes.string_at(OcrText).decode('utf-8')); + +HGLib_ReleaseOcrText = Objdll.HGLib_ReleaseOcrText +HGLib_ReleaseOcrText.argtypes = [ctypes.c_void_p] +HGLib_ReleaseOcrText.restype = ctypes.c_int +Ret = HGLib_ReleaseOcrText(OcrText) + #释放图像资源 HGLib_ReleaseImage = Objdll.HGLib_ReleaseImage HGLib_ReleaseImage.argtypes = [ctypes.c_void_p] @@ -102,7 +115,7 @@ Ret = HGLib_ReleaseImage(Image) #设备热拔插回调事件 def HGLibDeviceHotPlugEventFunc(event: c_uint, deviceName: c_char_p, param: c_void_p): - print(deviceName) + print(deviceName.decode('utf-8')) return #初始化操作 @@ -196,12 +209,14 @@ Ret = HGLib_SetDeviceParam(Device, 51, byref(DevParam)) DevParam = ctypes.c_double(0.1) Ret = HGLib_SetDeviceParam(Device, 52, byref(DevParam)) +bStop = False #扫描事件回调 -def HGLibDeviceScanEventFunc(device: c_void_p, event: c_uint, err: c_int, info: c_char_p, param: c_void_p): - s_info=info +def HGLibDeviceScanEventFunc(device: c_void_p, event: c_uint, err: c_int, info: ctypes.c_char_p, param: c_void_p): global bStop - print("event code",event," event info:",s_info) + print("event code:", event) + if info: + print("event info:", info.decode('utf-8')) if event == 2:#HGLIB_DEVSCAN_EVENT_END 扫描停止 bStop=True print("bStop true") diff --git a/test/webservice/demo.html b/test/webservice/demo.html index a50c168b..0008644f 100644 --- a/test/webservice/demo.html +++ b/test/webservice/demo.html @@ -178,20 +178,23 @@ } else if ("scan_image" == message['func']) { + var info = document.getElementById('info'); + info.value = message['image_path']; + //var myCanvas = document.getElementById("myCanvas"); //myCanvas.src = message['image_base64']; - var req1 = {'func':'insert_local_image', 'iden':'111', 'image_path':''}; - req1.image_path = message['image_path']; - socket.send(JSON.stringify(req1)); + //var req1 = {'func':'insert_local_image', 'iden':'111', 'image_path':''}; + //req1.image_path = message['image_path']; + //socket.send(JSON.stringify(req1)); - var req2 = {'func':'upload_local_file', 'iden':'111', 'file_path':'', 'upload_mode':'http', 'http_host':'192.168.100.148', 'http_port':8001}; - req2.file_path = message['image_path']; - socket.send(JSON.stringify(req2)); + //var req2 = {'func':'upload_local_file', 'iden':'111', 'file_path':'', 'upload_mode':'http', 'http_host':'192.168.100.70', 'http_port':8001, 'http_path':'/upload.php'}; + //req2.file_path = message['image_path']; + //socket.send(JSON.stringify(req2)); - var req3 = {'func':'delete_local_file', 'file_path':''}; - req3.file_path = message['image_path']; - socket.send(JSON.stringify(req3)); + //var req3 = {'func':'delete_local_file', 'file_path':''}; + //req3.file_path = message['image_path']; + //socket.send(JSON.stringify(req3)); } else if ("stop_scan" == message['func']) { @@ -393,11 +396,12 @@ { socket.send(JSON.stringify({ 'func':'upload_local_file', - 'file_path':'D:\\1.jpg', + 'file_path':'D:\\5.jpg', 'remote_file_path':'/savedir/123.jpg', 'upload_mode':'http', - 'http_host':'192.168.100.148', - 'http_port':8001 + 'http_host':'192.168.1.70', + 'http_port':8080, + 'http_path':'/upload.php' })); } diff --git a/test/webservice/upload/upload.html b/test/webservice/upload/upload.html new file mode 100644 index 00000000..c4c1b500 --- /dev/null +++ b/test/webservice/upload/upload.html @@ -0,0 +1,13 @@ + + + + + Upload + + +
+ + +
+ + \ No newline at end of file diff --git a/test/webservice/upload/upload.php b/test/webservice/upload/upload.php new file mode 100644 index 00000000..561075f0 --- /dev/null +++ b/test/webservice/upload/upload.php @@ -0,0 +1,9 @@ +"; + +?> \ No newline at end of file diff --git a/test/webservice/webdemoproject/js/WebScanController.js b/test/webservice/webdemoproject/js/WebScanController.js index f81a6ccb..219db867 100644 --- a/test/webservice/webdemoproject/js/WebScanController.js +++ b/test/webservice/webdemoproject/js/WebScanController.js @@ -21,6 +21,14 @@ constructor: WebScanController, /*****************************************扫描仪相关********************************************************************************/ + isDeviceInit: function (callBack) { + const that = this + this.sendCommand({ + func: "is_device_init", + iden: that.wslicence + }, callBack) + + }, initDevice: function (callBack) { const that = this this.sendCommand({ @@ -449,6 +457,7 @@ }, //插入本地图像(需返回成功后前端缩略图才能作相应的UI修改) insertLocalImage: function (imagePath, insertIndex, idenInfo, callBack) { + console.log('insertLocalImage insertIndex:' + insertIndex + ' imagePath:' + imagePath + ' ') const that = this this.sendCommand({ func: "insert_local_image", @@ -502,6 +511,7 @@ }, //修改图像 modifyImage: function (imageIndex, imageBase64, idenInfo, callBack) { + console.log('modifyImage imageIndex:' + imageIndex) const that = this this.sendCommand({ func: "modify_image", @@ -737,7 +747,7 @@ }; this.SocketClient.onmessage = function (event) { - console.log(TAG, "connect onmessage data:" + event.data) + // console.log(TAG, "connect onmessage data:" + event.data) if (event && event.data) { socketCallBack(new Result(SOCKET_EVENT, "", event.data)) } diff --git a/test/webservice/webdemoproject/js/scanWeb.js b/test/webservice/webdemoproject/js/scanWeb.js index ef912159..353de6e5 100644 --- a/test/webservice/webdemoproject/js/scanWeb.js +++ b/test/webservice/webdemoproject/js/scanWeb.js @@ -42,8 +42,8 @@ new Vue({ showBigImageDialog: false,//是否显示大图 selectBigImage: '',//当前选中的大图base64 scanMode: 'normal',//当前扫描模式 normal:正常往后添加 insert:在指定位置前后插入 cover:从指定位置开始往后覆盖或者添加 - curInsertIndex: -1,//当前需要插入的位置 - curCoverIndex: -1,//当前需要覆盖扫描的位置 + curInsertIndex: -1,//顺序扫描 当前需要插入的位置 + curCoverIndex: -1,//覆盖扫描 当前需要覆盖扫描的位置 needCoverCount: -1,//当前需要覆盖扫描的数量 isSetup: false,//是否显示参数设置框 activeName: '1',//设置框的tab位 @@ -164,6 +164,13 @@ new Vue({ ], markPositionTipX: 0,//提示X markPositionTipY: 0,//提示Y + insertQueue: [{ + insertType: -1,// 插入类型 -1占位啥都没有 1.加到末尾 2.插入到指定位置 3.覆盖指定位置图片 + imagePath: '',//插入图像的路径 + insertIndex: 0, //插入位置 + idenInfo: {},//签名 + }],//插入队列,等待结果返回再继续插入 + insertLoopWork: Number, }, created: function () { window.eleLoadding = this.eleLoadding; @@ -171,7 +178,25 @@ new Vue({ window.scanCallBack = this.scanCallBack; window.setupWindowCallBack = this.setupWindowCallBack window.socketCallBack = this.onSocketCallBack - window.onbeforeunload = this.releaseService + window.onbeforeunload = this.onCloseScreen + + let that = this; + this.insertQueue.length = 0 + + this.insertLoopWork = setInterval(() => { + //首位不是占位数据的 + if (that.insertQueue.length > 0 && that.insertQueue[0].insertType !== -1) { + + let insertInfo = that.insertQueue[0] + console.log('loop work:' + insertInfo.insertType + ' ' + insertInfo.imagePath) + //先去掉队列的第一位 + that.insertQueue.splice(0, 1) + //插入占位数据 + that.insertQueue.splice(0, 0, {insertType: -1}) + that.insertAction(insertInfo) + } + }, 400); + }, mounted: function () { let canvasContainer = $("#canvas-container") @@ -232,37 +257,45 @@ new Vue({ }, dispatchEvent: function (info) { if (info.func) { - if (info.ret != null && info.ret != undefined) { - if (info.ret == 0) {//返回成功 - let funcName = this.WebScanController.getCallBack(info.func) - if (funcName) { - funcName(info) - } else { - this.commonDispatch(info) - } - } else {//统一异常处理 弹个窗 - this.eleUnloadding() - this.eleMessage(info.err_info ? info.err_info : '未知异常', 'error') - if (info.func != null && info.func != undefined) { - if (info.func === 'image_add_watermark') {//特殊情况单独处理 - //添加水印失败了 - // this.reLoadImageList() - } - } + if (info.func === 'is_device_init' || info.func === 'get_curr_device_name') { + //单独处理 ret 0 初始化了 非0 未初始化 + let funcName = this.WebScanController.getCallBack(info.func) + if (funcName) { + funcName(info) } } else { - this.commonDispatch(info) + + if (info.ret != null && info.ret != undefined) { + if (info.ret == 0) {//返回成功 + let funcName = this.WebScanController.getCallBack(info.func) + if (funcName) { + funcName(info) + } else { + this.commonDispatch(info) + } + } else {//统一异常处理 弹个窗 + this.eleUnloadding() + this.eleMessage(info.err_info ? info.err_info : '未知异常', 'error') + if (info.func != null && info.func != undefined) { + if (info.func === 'image_add_watermark') {//特殊情况单独处理 + //添加水印失败了 + // this.reLoadImageList() + } + } + } + } else { + this.commonDispatch(info) + } } } }, commonDispatch: function (info) {//较通用事件处理 this.eleUnloadding() - console.log('commonDispatch:', JSON.stringify(info)) + // console.log('commonDispatch:', JSON.stringify(info)) if (info) { switch (info.func) { case "device_arrive"://设备装载 this.eleMessage("设备已装载") - this.getDeviceNameList() break case "device_remove"://设备卸载 this.eleMessage("设备已移除!") @@ -294,10 +327,6 @@ new Vue({ case "scan_image"://图片回调 let imagePath = info.image_path - this.appendLog('图片回调:' + imagePath) - console.log('图片回调:' + imagePath + ' info:' + JSON.stringify(info)) - let that = this - if (this.scanMode == 'insert') {//是插入扫描 this.curCoverIndex = -1 @@ -308,130 +337,181 @@ new Vue({ this.curInsertIndex = this.selectImageObj.index } - console.log('插入扫描:待插入index:' + this.curInsertIndex + " path:" + imagePath) - this.WebScanController.insertLocalImage(imagePath, this.curInsertIndex, - { + console.log('插入扫描:队列插入位:' + this.curInsertIndex + " path:" + imagePath) + + this.insertQueue.push({ + insertType: 2, + imagePath: imagePath, + insertIndex: this.curInsertIndex, + idenInfo: { + insertType: 2, + insertIndex: this.curInsertIndex, path: imagePath, - thumbnail: info.image_base64, base64: info.image_base64 - }, - function (insertInfo) { - console.log('插入扫描:插入index' + that.curInsertIndex) - let idenInfo = JSON.parse(insertInfo.iden); - - that.urls.splice(that.curInsertIndex, 0, { - path: idenInfo.path, - thumbnail: idenInfo.thumbnail, - base64: idenInfo.base64 - }); - that.curInsertIndex++ - that.$forceUpdate() - }) - + },//签名 + }) + this.curInsertIndex++ } else if (this.scanMode == 'cover') {//是覆盖扫描 - this.curInsertIndex = -1 - - if (this.curCoverIndex != -1) { - - } else { - this.curCoverIndex = this.selectImageObj.index - this.needCoverCount = this.urls.length - this.curCoverIndex - console.log('当前需要覆盖的起始位index' + this.curCoverIndex + ' 总长度位置:' + (this.urls.length - 1)) - console.log('需要覆盖的数量:' + this.needCoverCount) - } - - if (this.needCoverCount > 0) {//还在覆盖范围内,直接覆盖掉 - this.WebScanController.modifyImage(this.curCoverIndex, info.image_base64, { - base64: info.image_base64, - thumbnail: info.image_base64, - path: imagePath - }, function (modifyInfo) { - - console.log('覆盖扫描:修改成功 index:' + that.curCoverIndex) - console.log('覆盖前:index==' + that.curCoverIndex + ' path:' + that.urls[that.curCoverIndex].path) - let idenInfo = JSON.parse(modifyInfo.iden); - - that.urls[that.curCoverIndex] = { - base64: idenInfo.base64, - thumbnail: idenInfo.thumbnail, - path: idenInfo.path - } - console.log('覆盖后:index==' + that.curCoverIndex + ' path:' + that.urls[that.curCoverIndex].path) - - that.curCoverIndex++ - that.needCoverCount-- - - that.$forceUpdate() - }) - } else {//之后都是新增的往后添加了 - this.WebScanController.insertLocalImage(imagePath, this.urls.length, { + console.log('覆盖扫描,起始位index' + this.curCoverIndex + ' imagePath:' + imagePath + ' 总长度位置:' + (this.urls.length - 1)) + console.log('需要覆盖的数量:' + this.needCoverCount) + this.insertQueue.push({ + insertType: 3, + imagePath: imagePath, + idenInfo: { + insertType: 3, path: imagePath, - thumbnail: info.image_base64, base64: info.image_base64 - }, function (result) { - console.log('覆盖扫描:插入成功 index:' + that.urls.length) - let idenInfo = JSON.parse(result.iden); - - that.urls.push({ - path: idenInfo.path, - thumbnail: idenInfo.thumbnail, - base64: idenInfo.base64 - }) - that.$forceUpdate() - - that.$nextTick(function () { - if (that.$refs.imageArea) { - that.$refs.imageArea.scrollTop = that.$refs.imageArea.scrollHeight - } - }) - }) - } - + }, + }) } else {//正常按顺序 - this.curInsertIndex = -1 + this.curCoverIndex = -1 - let that = this; + console.log('顺序扫描,队列插入位' + this.curInsertIndex + ' imagePath:' + imagePath) - - this.WebScanController.insertLocalImage(imagePath, this.urls.length, { - path: imagePath, - thumbnail: info.image_base64, - base64: info.image_base64 - }, function (result) { - let idenInfo = JSON.parse(result.iden); - - console.log('正常扫描:插入成功 index:' + that.urls.length + ' path:' + idenInfo.path) - - that.urls.push({ - path: idenInfo.path, - thumbnail: idenInfo.thumbnail, - base64: idenInfo.base64 - }) - that.$nextTick(function () { - if (that.$refs.imageArea) { - that.$refs.imageArea.scrollTop = that.$refs.imageArea.scrollHeight - } - }) + this.insertQueue.push({ + insertType: 1, + imagePath: imagePath, + insertIndex: this.curInsertIndex, + idenInfo: { + insertType: 2, + path: imagePath, + insertIndex: this.curInsertIndex, + base64: info.image_base64 + },//签名 }) - + this.curInsertIndex++ } break } } }, + //扫描展示逻辑 + insertAction: function (info) { + + /* { + insertType: 1, + imagePath: imagePath, + insertIndex: this.insertIndex, + idenInfo: { + insertType: 2, + path: imagePath, + insertIndex: this.insertIndex, + base64: info.image_base64 + }*/ + + let that = this + + if (info.insertType === 3) {//是覆盖扫描逻辑 + + if (this.needCoverCount > 0) {//还在覆盖范围内,直接覆盖掉 + this.WebScanController.modifyImage(this.curCoverIndex, info.idenInfo.base64, info.idenInfo, function (modifyInfo) { + + let idenInfo = JSON.parse(modifyInfo.iden); + + console.log('覆盖前:index==' + that.curCoverIndex + ' path:' + that.urls[that.curCoverIndex].path) + + that.urls[that.curCoverIndex] = { + base64: idenInfo.base64, + thumbnail: idenInfo.base64, + path: idenInfo.path + } + console.log('覆盖后:index==' + that.curCoverIndex + ' path:' + that.urls[that.curCoverIndex].path) + + that.curCoverIndex++ + that.needCoverCount-- + + that.$forceUpdate() + + //把占位符删掉 继续下一轮循环 + if (that.insertQueue.length > 0 && that.insertQueue[0].insertType === -1) { + that.insertQueue.splice(0, 1) + } + }) + } else {//之后都是新增的往后添加了 + this.WebScanController.insertLocalImage(info.imagePath, this.urls.length, info.idenInfo, function (result) { + console.log('覆盖扫描:插入成功 index:' + that.urls.length) + let idenInfo = JSON.parse(result.iden); + + that.urls.push({ + path: idenInfo.path, + thumbnail: idenInfo.base64, + base64: idenInfo.base64 + }) + that.$forceUpdate() + + that.$nextTick(function () { + if (that.$refs.imageArea) { + that.$refs.imageArea.scrollTop = that.$refs.imageArea.scrollHeight + } + }) + + + //把占位符删掉 继续下一轮循环 + if (that.insertQueue.length > 0 && that.insertQueue[0].insertType === -1) { + that.insertQueue.splice(0, 1) + } + + }) + } + } else { + this.WebScanController.insertLocalImage(info.imagePath, info.insertIndex, info.idenInfo, function (result) { + + let idenInfo = JSON.parse(result.iden); + if (idenInfo.insertType === 1) { + //正常扫描,往后添加 + console.log('正常扫描:插入成功 index:' + idenInfo.insertIndex + ' path:' + idenInfo.path) + //插入到正确位置 + that.urls.splice(idenInfo.insertIndex, 0, { + path: idenInfo.path, + thumbnail: idenInfo.base64, + base64: idenInfo.base64 + }) + + that.$nextTick(function () { + if (that.$refs.imageArea) { + that.$refs.imageArea.scrollTop = that.$refs.imageArea.scrollHeight + } + }) + + } else if (idenInfo.insertType == 2) { + //插入扫描,指定位置 + console.log('插入扫描:插入index' + idenInfo.insertIndex + ' path:' + idenInfo.path) + //插入到正确位置 + that.urls.splice(idenInfo.insertIndex, 0, { + path: idenInfo.path, + thumbnail: idenInfo.base64, + base64: idenInfo.base64 + }) + that.$forceUpdate() + } + + //把占位符删掉 继续下一轮循环 + if (that.insertQueue.length > 0 && that.insertQueue[0].insertType === -1) { + that.insertQueue.splice(0, 1) + } + }) + } + }, //一些初始化操作 initData: function () { let that = this - // this.initDevice() this.getGlobalConfig() this.getBatchList(function () { that.changeBatch(that.batchIdList.slice(-1)[0]) }) }, + //界面销毁 + onCloseScreen: function () { + this.releaseService() + if (this.insertLoopWork) { + clearInterval(this.insertLoopWork) + } + }, //关闭服务 releaseService: function () { + console.log('releaseService') this.deinitDevices() // this.stopBindFolder() if (this.WebScanController) { @@ -465,12 +545,27 @@ new Vue({ //初始化设备 initDevice: function (succcallBack) { let that = this - this.WebScanController.initDevice(function (info) { - console.log('init devices :' + info) - that.deviceInited = true - if (succcallBack != null) { - succcallBack() + this.WebScanController.isDeviceInit(function (info) { + console.log('isDeviceInit:' + JSON.stringify(info)) + if (info.ret == 0) { + //已经初始化 + that.deviceInited = true + if (succcallBack != null) { + succcallBack() + } + } else { + //没有初始化 + console.log('start device init ' + new Date().getTime()) + + that.WebScanController.initDevice(function (info) { + console.log('init devices :' + JSON.stringify(info) + ' ' + new Date().getTime()) + that.deviceInited = true + if (succcallBack != null) { + succcallBack() + } + }) } + }) }, //反初始化设备(需初始化后调用) @@ -489,7 +584,7 @@ new Vue({ getDeviceNameList: function () { let that = this this.WebScanController.getDeviceNameList(function (info) { - console.log('getDeviceNameList :' + info) + console.log('getDeviceNameList :' + JSON.stringify(info)) if (info.device_name_list) {//反初始化成功 for (let i = 0; i < info.device_name_list.length; i++) { console.log('getDeviceNameList index:' + i + " item:" + info.device_name_list[i]) @@ -501,12 +596,24 @@ new Vue({ //打开设备 openDevice: function (deviceName) { let that = this - this.WebScanController.openDevice(deviceName, function (info) { - console.log('open devices :' + info) - that.deviceOpened = true - that.eleLoadding() - that.getScanParams() + + this.WebScanController.getCurrDeviceName(function (info) { + console.log('getCurrDeviceName:' + JSON.stringify(info)) + if (info.device_name) { + that.deviceOpened = true + that.eleLoadding() + that.getScanParams() + } else { + that.WebScanController.openDevice(deviceName, function (info) { + console.log('open devices :' + JSON.stringify(info)) + that.deviceOpened = true + that.eleLoadding() + that.getScanParams() + }) + } }) + + }, //关闭设备 closeDevice: function () { @@ -546,7 +653,7 @@ new Vue({ let that = this this.WebScanController.getScanParams(function (info) { that.eleUnloadding() - console.log('获取到的扫描参数 :' + JSON.stringify(info)) + // console.log('获取到的扫描参数 :' + JSON.stringify(info)) that.scanParamsRange = info.device_param that.parameterCoerceIn() }) @@ -628,8 +735,8 @@ new Vue({ this.eleMessage('请先等待扫描结束!', 'warning') return; } - this.scanMode = 'normal' + this.curInsertIndex = this.urls.length this.WebScanController.startScan(function (info) { console.log('startScan :' + info) }) @@ -665,7 +772,11 @@ new Vue({ } let that = this - this.curCoverIndex = -1 + this.curInsertIndex = -1 + this.curCoverIndex = this.selectImageObj.index + this.needCoverCount = this.urls.length - this.curCoverIndex + + this.WebScanController.startScan(function (info) { console.log('覆盖扫描') that.scanMode = 'cover' @@ -695,6 +806,9 @@ new Vue({ let that = this this.initDevice(function () { that.isSetup = true + setTimeout(function () { + that.getDeviceNameList() + }, 500); }) } }, @@ -773,7 +887,7 @@ new Vue({ this.eleLoadding() this.WebScanController.openBatch(batchId, function (info) { - console.log('切换批次:' + JSON.stringify(info)) + console.log('打开批次:' + JSON.stringify(info)) that.urls.length = 0//先清空一下 that.currentBatch = batchId //重新加载 @@ -2230,8 +2344,8 @@ new Vue({ this.scanParams.push(newGroup) } - console.log('当前扫描参数:' + JSON.stringify(this.scanParams)) - console.log('当前强强强扫描参数:' + JSON.stringify(paramsRange)) + // console.log('当前扫描参数:' + JSON.stringify(this.scanParams)) + // console.log('当前强强强扫描参数:' + JSON.stringify(paramsRange)) this.$forceUpdate() }, diff --git a/test/webservice/webdemoproject/logo.png b/test/webservice/webdemoproject/logo.png index 728096c3..2a2a33d5 100644 Binary files a/test/webservice/webdemoproject/logo.png and b/test/webservice/webdemoproject/logo.png differ diff --git a/test/webservice/webdemoproject/webDemo.html b/test/webservice/webdemoproject/webDemo.html index 6adcc612..fab953f4 100644 --- a/test/webservice/webdemoproject/webDemo.html +++ b/test/webservice/webdemoproject/webDemo.html @@ -761,7 +761,7 @@ - +