From 3ac12a10472512da8d0df8d64dd4edaf242e7837 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Tue, 25 Jun 2024 22:24:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8A=A8=E6=80=81=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E6=A0=A1=E6=AD=A3=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/HGProductionTool/analysisjson.cpp | 5 +- app/HGProductionTool/analysisjson.h | 5 +- app/HGProductionTool/form_maininterface.cpp | 40 +- app/HGProductionTool/form_maininterface.h | 1 + code/base/test.vcxproj | 23 +- code/base/test.vcxproj.filters | 6 - code/base/test_base.cpp | 414 ++++---------------- code/base/test_base.h | 49 ++- 8 files changed, 154 insertions(+), 389 deletions(-) diff --git a/app/HGProductionTool/analysisjson.cpp b/app/HGProductionTool/analysisjson.cpp index fa6bf99..57f3c34 100644 --- a/app/HGProductionTool/analysisjson.cpp +++ b/app/HGProductionTool/analysisjson.cpp @@ -39,6 +39,7 @@ std::vector AnalysisJson::GetNode() obj[key].toObject()["err-level"].toInt(), obj[key].toObject()["desc"].toString(), obj[key].toObject()["station"].toString(), + obj[key].toObject()["dynamic-correct-data"].toString(), obj[key].toObject()["resolution"].toInt(), obj[key].toObject()["correct-value"].toInt()}); } @@ -57,8 +58,8 @@ AnalysisJson::json_global AnalysisJson::GetGlobal() obj["speed-mode"].toInt(), obj["sleep-time"].toInt(), obj["device-model"].toString(), - obj["cpu-size"].toInt(), - obj["disk-size"].toInt(), + obj["cpu-size"].toDouble(), + obj["disk-size"].toDouble(), obj["firmware-version"].toString()}; } diff --git a/app/HGProductionTool/analysisjson.h b/app/HGProductionTool/analysisjson.h index 2ecccef..e915e79 100644 --- a/app/HGProductionTool/analysisjson.h +++ b/app/HGProductionTool/analysisjson.h @@ -14,6 +14,7 @@ public: std::int32_t err_level; QString desc; QString station; + QString dynamic_correct_data; int resolution; int correct_value; }; @@ -26,8 +27,8 @@ public: std::int32_t speed_mode; std::int32_t sleep_time; QString device_model; - std::int32_t cpu_size; - std::int32_t disk_size; + double cpu_size; + double disk_size; QString firmware_version; }; diff --git a/app/HGProductionTool/form_maininterface.cpp b/app/HGProductionTool/form_maininterface.cpp index f3c72e0..2f332eb 100644 --- a/app/HGProductionTool/form_maininterface.cpp +++ b/app/HGProductionTool/form_maininterface.cpp @@ -282,8 +282,8 @@ void Form_mainInterface::on_testGetDevCpuDisk(int cpu, int disk) { AnalysisJson analysisJson(m_profileName); AnalysisJson::json_global jsonGlobal = analysisJson.GetGlobal(); - int cpu_size = jsonGlobal.cpu_size; - int disk_size = jsonGlobal.disk_size; + float cpu_size = jsonGlobal.cpu_size; + float disk_size = jsonGlobal.disk_size; float devCpuSize = (float)cpu / 1024 / 1024; char buf[10] = { 0 }; @@ -757,6 +757,22 @@ void Form_mainInterface::writeTestLog(QString logContent) file.close(); } +int Form_mainInterface::str_to_wchar(std::string str, wchar_t *s, size_t *strlen) +{ + if (str.empty()) + return ERROR_INSUFFICIENT_BUFFER; + + int len = 0; + len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0); + if (*strlen < len) + { + *strlen = len; + return ERROR_INSUFFICIENT_BUFFER; + } + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, s, len); + return 0; +} + void Form_mainInterface::on_tableWidget_currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous) { (void)previous; @@ -854,7 +870,7 @@ void Form_mainInterface::on_pbtn_start_clicked() if (name == "AUTO_FLAT_FIELD") correct_value = 0; - wchar_t buf[5] = {0}; + wchar_t buf[128] = {0}; if (dpi > 0) { m_curDpi = dpi; @@ -865,6 +881,13 @@ void Form_mainInterface::on_pbtn_start_clicked() swprintf(buf, L"%d", correct_value); } + std::string correctData = m_map_title_name.value(title).dynamic_correct_data.toStdString(); + if (!correctData.empty()) + { + unsigned int len = sizeof(buf) / sizeof(buf[0]); + str_to_wchar(correctData, buf, &len); + } + if (m_hg != nullptr) { updateUiEnabled(false); @@ -872,10 +895,15 @@ void Form_mainInterface::on_pbtn_start_clicked() m_mainwnd->addTestingRef(); int ret = 0; - if (buf != nullptr && (dpi > 0 || (correct_value > -1 && correct_value < 7))) - ret = func_test_go(name.toStdWString().c_str(), (const wchar_t*)buf, m_hg); + if (buf != nullptr || (dpi > 0 || (correct_value > -1 && correct_value < 7))) + { + ret = func_test_go(name.toStdWString().c_str(), (const wchar_t*)buf, m_hg); + } else - ret = func_test_go(name.toStdWString().c_str(), L"null", m_hg); + { + ret = func_test_go(name.toStdWString().c_str(), L"null", m_hg); + } + if (ret > SANE_STATUS_GOOD) { //getLogInfo(ret); diff --git a/app/HGProductionTool/form_maininterface.h b/app/HGProductionTool/form_maininterface.h index 804b8df..ce74191 100644 --- a/app/HGProductionTool/form_maininterface.h +++ b/app/HGProductionTool/form_maininterface.h @@ -99,6 +99,7 @@ private: void getLogInfo(int ret); QString getLogPath(); void writeTestLog(QString logContent); + int str_to_wchar(std::string str, wchar_t* s, size_t* strlen); private: union VIDPID diff --git a/code/base/test.vcxproj b/code/base/test.vcxproj index 90959b5..f94b013 100644 --- a/code/base/test.vcxproj +++ b/code/base/test.vcxproj @@ -90,16 +90,12 @@ Level3 true - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ZIP_STATIC;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true - ../../../code_app/third_party/opencv/windows/include;../../../code_app/third_party/libzip/windows/include;%(AdditionalIncludeDirectories) - MultiThreadedDebug Console true - ../../../code_app/third_party/opencv/windows/lib/x86/opencv_core3416d.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_highgui3416d.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_features2d3416d.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_imgproc3416d.lib;../../../code_app/third_party/opencv/windows/lib/x86/ittnotifyd.lib;../../../code_app/third_party/opencv/windows/lib/x86/zlibd.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_imgcodecs3416d.lib;../../../code_app/third_party/opencv/windows/lib/x86/IlmImfd.lib;../../../code_app/third_party/opencv/windows/lib/x86/libjasperd.lib;../../../code_app/third_party/opencv/windows/lib/x86/libjpeg-turbod.lib;../../../code_app/third_party/opencv/windows/lib/x86/libpngd.lib;../../../code_app/third_party/opencv/windows/lib/x86/libtiffd.lib;../../../code_app/third_party/opencv/windows/lib/x86/libwebpd.lib;../../../code_app/third_party/libzip/windows/lib/x86/zip.lib;%(AdditionalDependencies) - /ignore:4099 %(AdditionalOptions) copy $(OutDir)test.dll $(SolutionDir)..\..\..\code_app\build2\build\windows\huagao\x86\Debug\ @@ -111,17 +107,14 @@ true true true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ZIP_STATIC;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true - ../../../code_app/third_party/opencv/windows/include;../../../code_app/third_party/libzip/windows/include;%(AdditionalIncludeDirectories) - MultiThreaded Console true true true - ../../../code_app/third_party/opencv/windows/lib/x86/opencv_core3416.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_highgui3416.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_features2d3416.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_imgproc3416.lib;../../../code_app/third_party/opencv/windows/lib/x86/ittnotify.lib;../../../code_app/third_party/opencv/windows/lib/x86/zlib.lib;../../../code_app/third_party/opencv/windows/lib/x86/opencv_imgcodecs3416.lib;../../../code_app/third_party/opencv/windows/lib/x86/IlmImf.lib;../../../code_app/third_party/opencv/windows/lib/x86/libjasper.lib;../../../code_app/third_party/opencv/windows/lib/x86/libjpeg-turbo.lib;../../../code_app/third_party/opencv/windows/lib/x86/libpng.lib;../../../code_app/third_party/opencv/windows/lib/x86/libtiff.lib;../../../code_app/third_party/opencv/windows/lib/x86/libwebp.lib;../../../code_app/third_party/libzip/windows/lib/x86/zip.lib;%(AdditionalDependencies) copy $(OutDir)test.dll $(SolutionDir)..\..\..\release\win\x86\Release\ @@ -132,15 +125,12 @@ copy $(OutDir)test.dll $(SolutionDir)..\..\..\code_app\build2\build\windows\huag Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;ZIP_STATIC + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS; true - ../../../code_app/third_party/opencv/windows/include;../../../code_app/third_party/libzip/windows/include;%(AdditionalIncludeDirectories) - MultiThreadedDebug Console true - ../../../code_app/third_party/opencv/windows/lib/x64/opencv_core3416d.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_highgui3416d.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_features2d3416d.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_imgproc3416d.lib;../../../code_app/third_party/opencv/windows/lib/x64/ittnotifyd.lib;../../../code_app/third_party/opencv/windows/lib/x64/zlibd.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_imgcodecs3416d.lib;../../../code_app/third_party/opencv/windows/lib/x64/IlmImfd.lib;../../../code_app/third_party/opencv/windows/lib/x64/libjasperd.lib;../../../code_app/third_party/opencv/windows/lib/x64/libjpeg-turbod.lib;../../../code_app/third_party/opencv/windows/lib/x64/libpngd.lib;../../../code_app/third_party/opencv/windows/lib/x64/libtiffd.lib;../../../code_app/third_party/opencv/windows/lib/x64/libwebpd.lib;../../../code_app/third_party/libzip/windows/lib/x64/zip.lib;%(AdditionalDependencies) @@ -149,28 +139,23 @@ copy $(OutDir)test.dll $(SolutionDir)..\..\..\code_app\build2\build\windows\huag true true true - NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ZIP_STATIC;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true - MultiThreaded - ../../../code_app/third_party/opencv/windows/include;../../../code_app/third_party/libzip/windows/include;%(AdditionalIncludeDirectories) Console true true true - ../../../code_app/third_party/opencv/windows/lib/x64/opencv_core3416.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_highgui3416.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_features2d3416.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_imgproc3416.lib;../../../code_app/third_party/opencv/windows/lib/x64/ittnotify.lib;../../../code_app/third_party/opencv/windows/lib/x64/zlib.lib;../../../code_app/third_party/opencv/windows/lib/x64/opencv_imgcodecs3416.lib;../../../code_app/third_party/opencv/windows/lib/x64/IlmImf.lib;../../../code_app/third_party/opencv/windows/lib/x64/libjasper.lib;../../../code_app/third_party/opencv/windows/lib/x64/libjpeg-turbo.lib;../../../code_app/third_party/opencv/windows/lib/x64/libpng.lib;../../../code_app/third_party/opencv/windows/lib/x64/libtiff.lib;../../../code_app/third_party/opencv/windows/lib/x64/libwebp.lib;../../../code_app/third_party/libzip/windows/lib/x64/zip.lib;%(AdditionalDependencies) copy $(OutDir)test.dll $(SolutionDir)..\..\..\release\win\x64\Release\ - - diff --git a/code/base/test.vcxproj.filters b/code/base/test.vcxproj.filters index f100f62..0356207 100644 --- a/code/base/test.vcxproj.filters +++ b/code/base/test.vcxproj.filters @@ -18,16 +18,10 @@ 源文件 - - 源文件 - 头文件 - - 头文件 - \ No newline at end of file diff --git a/code/base/test_base.cpp b/code/base/test_base.cpp index 795bb17..30c9c3f 100644 --- a/code/base/test_base.cpp +++ b/code/base/test_base.cpp @@ -1,18 +1,11 @@ -#include "test_base.h" -#include +#include"test_base.h" +#include #include #include #include #include -#include -#include "correctProcess.h" #include "huagao/hgscanner_error.h" -#include "sane/sane_option_definitions.h" -extern "C" -{ -#include "zip.h" -}; - +#include "sane/sane_option_definitions.h"; static struct Test_Map { const wchar_t* name; // DIAL_SWITCH @@ -57,12 +50,12 @@ static struct Test_Map {HGPDTTOOLDB_NAME_BACKUP ,HGPDTTOOLDB_TITLE_BACKUP}, {HGPDTTOOLDB_NAME_SHUTDOWN ,HGPDTTOOLDB_TITLE_SHUTDOWN}, {HGPDTTOOLDB_NAME_SET_FIRMWARE_LANGUAGE ,HGPDTTOOLDB_TITLE_SET_FIRMWARE_LANGUAGE}, - {HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_200DPI ,HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_RGB_200DPI}, - {HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_200DPI ,HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_GRAY_200DPI}, - {HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_300DPI ,HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_RGB_300DPI}, - {HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_300DPI ,HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_GRAY_300DPI}, - {HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_600DPI ,HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_RGB_600DPI}, - {HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_600DPI ,HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_GRAY_600DPI} + {HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_200DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_200DPI}, + {HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_200DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_200DPI}, + {HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_300DPI}, + {HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_300DPI}, + {HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_600DPI}, + {HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_600DPI} }; static std::string StringToUtf(std::string strValue) @@ -138,130 +131,12 @@ int get_json_config_file() fread(buf, len, 1, fp); fclose(fp); std::cout << buf << std::endl; - return 0; } - -static std::string AnsiToUtf8(const char* text) -{ - int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0); - WCHAR* pUnicode = new WCHAR[wlen]; - ::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen); - int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL); - CHAR* pUTF8 = new CHAR[len]; - ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL); - delete[] pUnicode; - std::string ret = pUTF8; - delete[] pUTF8; - return ret; -} - -static bool GetFileName(const char* fileName, char* name, unsigned int maxLen) -{ - if (NULL == fileName || NULL == name || 0 == maxLen) - { - return false; - } - - const char* pcName = strrchr(fileName, '\\'); - if (NULL == pcName) - { - pcName = strrchr(fileName, '/'); - if (NULL == pcName) - return false; - } - - ++pcName; - if (maxLen < strlen(pcName) + 1) - return false; - strcpy(name, pcName); - return true; -} - -static bool FileZip(const std::string& srcFile, const std::string& destFile) -{ - int error = 0; - zip* z = zip_open(AnsiToUtf8(destFile.c_str()).c_str(), ZIP_CREATE | ZIP_TRUNCATE, &error); - if (NULL == z) - { - return false; - } - - zip_source_t* s = zip_source_file(z, AnsiToUtf8(srcFile.c_str()).c_str(), 0, 0); - if (NULL == s) - { - zip_close(z); - return false; - } - - char name[256]; - GetFileName(srcFile.c_str(), name, 256); - if (zip_file_add(z, AnsiToUtf8(name).c_str(), s, ZIP_FL_OVERWRITE) < 0) - { - zip_source_free(s); - zip_close(z); - return false; - } - - zip_close(z); - return true; -} - -static void correctProcess(cv::Mat& image1, cv::Mat& image2, int blackLevel, bool colorCastEnable, const std::vector& referValues, int dpi, const std::string& path, - std::vector& imgFiles, std::vector& zipFiles) -{ - imgFiles.clear(); - zipFiles.clear(); - - std::vector datFiles; - datFiles.push_back(path + std::to_string(dpi) + (image1.channels() == 3 ? "c" : "g") + ".dat"); - datFiles.push_back(path + "cc" + std::to_string(dpi) + "f.dat"); - datFiles.push_back(path + "cc" + std::to_string(dpi) + "b.dat"); - DeleteFileA(datFiles[0].c_str()); - DeleteFileA(datFiles[1].c_str()); - DeleteFileA(datFiles[2].c_str()); - - imgFiles.push_back(path + "Textlut" + std::to_string(dpi) + (image1.channels() == 3 ? "clr" : "gray") + ".bmp"); - imgFiles.push_back(path + "ColorCast" + std::to_string(dpi) + "_F.bmp"); - imgFiles.push_back(path + "ColorCast" + std::to_string(dpi) + "_B.bmp"); - DeleteFileA(imgFiles[0].c_str()); - DeleteFileA(imgFiles[1].c_str()); - DeleteFileA(imgFiles[2].c_str()); - - zipFiles.push_back(path + std::to_string(dpi) + (image1.channels() == 3 ? "c" : "g") + ".zip"); - zipFiles.push_back(path + "cc" + std::to_string(dpi) + "f.zip"); - zipFiles.push_back(path + "cc" + std::to_string(dpi) + "b.zip"); - DeleteFileA(zipFiles[0].c_str()); - DeleteFileA(zipFiles[1].c_str()); - DeleteFileA(zipFiles[2].c_str()); - - std::vector retImgs = correctProcess(image1, image2, blackLevel, colorCastEnable, referValues, dpi, path); - assert(retImgs.size() == 3); - - if (retImgs[0].empty() || !cv::imwrite(imgFiles[0], retImgs[0])) - imgFiles[0].clear(); - if (retImgs[1].empty() || !cv::imwrite(imgFiles[1], retImgs[1])) - imgFiles[1].clear(); - if (retImgs[2].empty() || !cv::imwrite(imgFiles[2], retImgs[2])) - imgFiles[2].clear(); - - if (!FileZip(datFiles[0], zipFiles[0])) - zipFiles[0].clear(); - if (!FileZip(datFiles[1], zipFiles[1])) - zipFiles[1].clear(); - if (!FileZip(datFiles[2], zipFiles[2])) - zipFiles[2].clear(); - - DeleteFileA(datFiles[0].c_str()); - DeleteFileA(datFiles[1].c_str()); - DeleteFileA(datFiles[2].c_str()); -} - static std::wstring set_test_name_ =L""; //bool is_distortion_get_image = false; //bool is_distortion_get_image_abnormal = false; std::atomic is_distortion_get_image_abnormal(false); std::atomic is_distortion_get_image(false); -cv::Mat m_image1, m_image2; class test { ui_helper* helper_; @@ -488,12 +363,6 @@ public: //std::string str = StringToUtf((char*)data); switch (code) { - case SANE_EVENT_WORKING: - { - m_image1 = cv::Mat(); - m_image2 = cv::Mat(); - } - break; case SANE_EVENT_SCAN_FINISHED: { SANE_Bool close = false; @@ -632,103 +501,11 @@ public: wcscpy(buf, L"单张测试失败, 原因--->"); } } - else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_200DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_200DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_300DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_300DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_600DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_600DPI) == 0) - { - if (m_image1.empty() || m_image2.empty()) - { - type = false; - wcscpy(buf, L"自动图像校正测试失败, 原因--->图像缺失"); - } - else - { - int dpi = 200; - if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_300DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_300DPI) == 0) - dpi = 300; - else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_600DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_600DPI) == 0) - dpi = 600; - - int blackLevel = 4; - std::vector referValues; - referValues.push_back(252); - referValues.push_back(12); - referValues.push_back(29); - referValues.push_back(37); - referValues.push_back(74); - referValues.push_back(131); - referValues.push_back(158); - referValues.push_back(168); - referValues.push_back(189); - referValues.push_back(231); - referValues.push_back(245); - referValues.push_back(249); - - CHAR tmpPath[MAX_PATH] = { 0 }; - DWORD len = GetTempPathA(MAX_PATH, tmpPath); - if (tmpPath[strlen(tmpPath) - 1] != '\\') - strcat(tmpPath, "\\"); - std::string path = tmpPath; - - std::vector imgFiles, zipFiles; - correctProcess(m_image1, m_image2, blackLevel, true, referValues, dpi, path, imgFiles, zipFiles); - - if (1) // 是否是7010 - { - if (m_image1.channels() == 3 && 0 == _access(zipFiles[0].c_str(), 0) - && 0 == _access(zipFiles[1].c_str(), 0) && 0 == _access(zipFiles[2].c_str(), 0)) - { - // 上传zipFiles[0]、zipFiles[1]、zipFiles[2]到设备 - } - else if (m_image1.channels() == 1 && 0 == _access(zipFiles[0].c_str(), 0)) - { - // 上传zipFiles[0]到设备 - } - else - { - type = false; - wcscpy(buf, L"自动图像校正测试失败, 原因--->校正算法处理出错"); - } - } - else - { - if (m_image1.channels() == 3 && 0 == _access(imgFiles[0].c_str(), 0) - && 0 == _access(imgFiles[1].c_str(), 0) && 0 == _access(imgFiles[2].c_str(), 0)) - { - // 上传imgFiles[0]、imgFiles[1]、imgFiles[2]到设备 - } - else if (m_image1.channels() == 1 && 0 == _access(imgFiles[0].c_str(), 0)) - { - // 上传imgFiles[0]到设备 - } - else - { - type = false; - wcscpy(buf, L"自动图像校正测试失败, 原因--->校正算法处理出错"); - } - } - - DeleteFileA(imgFiles[0].c_str()); - DeleteFileA(imgFiles[1].c_str()); - DeleteFileA(imgFiles[2].c_str()); - DeleteFileA(zipFiles[0].c_str()); - DeleteFileA(zipFiles[1].c_str()); - DeleteFileA(zipFiles[2].c_str()); - } - } wcscat(buf, wstr.c_str()); //ret = h->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);//结束恢复默认 h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)buf, type); - - m_image1 = cv::Mat(); - m_image2 = cv::Mat(); } break; case SANE_EVENT_ERROR: @@ -747,10 +524,10 @@ public: case SANE_EVENT_IMAGE_OK: { if ( wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY) == 0 + ||wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY) == 0 || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_GET_DISTORTION_VAL) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CONFIRM_DISTORTION_VAL) == 0 + ||wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_GET_DISTORTION_VAL) == 0 + ||wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CONFIRM_DISTORTION_VAL) == 0 || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SCANNING_SENSOR) == 0 || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY) == 0 || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY) == 0 @@ -761,38 +538,13 @@ public: || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_300DPI) == 0 || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_300DPI) == 0 || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_600DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_600DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_200DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_200DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_300DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_300DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_600DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_600DPI) == 0) + || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_600DPI) == 0) { if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_GET_DISTORTION_VAL) == 0) { is_distortion_get_image = true; } - else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_200DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_200DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_300DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_300DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_600DPI) == 0 - || wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_600DPI) == 0) - { - SANE_Image* sane_img = (SANE_Image*)data; - - cv::Mat img(sane_img->header.lines, sane_img->header.pixels_per_line, - CV_8UC(sane_img->header.format == SANE_FRAME_RGB ? 3 : 1), sane_img->data, sane_img->header.bytes_per_line); - cvCvtColor(&img, &img, CV_RGB2BGR); - - if (m_image1.empty()) - m_image1 = img.clone(); - else if (m_image2.empty()) - m_image2 = img.clone(); - } - h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_HAVE_IMAGE, data, true); } } @@ -861,12 +613,12 @@ public: test_map_[HGPDTTOOLDB_NAME_BACKUP] = &test::test_backup; test_map_[HGPDTTOOLDB_NAME_SHUTDOWN] = &test::test_shutdown; test_map_[HGPDTTOOLDB_NAME_SET_FIRMWARE_LANGUAGE] = &test::test_set_firmware_language; - test_map_[HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_200DPI] = &test::test_auto_color_correction_rgb_200dpi; - test_map_[HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_200DPI] = &test::test_auto_color_correction_gray_200dpi; - test_map_[HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_300DPI] = &test::test_auto_color_correction_rgb_300dpi; - test_map_[HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_300DPI] = &test::test_auto_color_correction_gray_300dpi; - test_map_[HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_600DPI] = &test::test_auto_color_correction_rgb_600dpi; - test_map_[HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_600DPI] = &test::test_auto_color_correction_gray_600dpi; + test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_200DPI] = &test::test_image_correct_rgb_200dpi; + test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_200DPI] = &test::test_image_correct_gray_200dpi; + test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI] = &test::test_image_correct_rgb_300dpi; + test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI] = &test::test_image_correct_gray_300dpi; + test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI] = &test::test_image_correct_rgb_600dpi; + test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI] = &test::test_image_correct_gray_600dpi; } int set_test(const wchar_t* name,const wchar_t* oper) { @@ -1858,67 +1610,6 @@ public: return ret; } - - int test_auto_color_correction_rgb_200dpi(void* data) - { - const char* color = OPTION_VALUE_YSMS_24WCS; - int dpi = 200; - unsigned int len = strlen(color); - helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len); - helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len); - return helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL); - } - - int test_auto_color_correction_gray_200dpi(void* data) - { - const char* color = OPTION_VALUE_YSMS_256JHD; - int dpi = 200; - unsigned int len = strlen(color); - helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len); - helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len); - return helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL); - } - - int test_auto_color_correction_rgb_300dpi(void* data) - { - const char* color = OPTION_VALUE_YSMS_24WCS; - int dpi = 300; - unsigned int len = strlen(color); - helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len); - helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len); - return helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL); - } - - int test_auto_color_correction_gray_300dpi(void* data) - { - const char* color = OPTION_VALUE_YSMS_256JHD; - int dpi = 300; - unsigned int len = strlen(color); - helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len); - helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len); - return helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL); - } - - int test_auto_color_correction_rgb_600dpi(void* data) - { - const char* color = OPTION_VALUE_YSMS_24WCS; - int dpi = 600; - unsigned int len = strlen(color); - helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len); - helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len); - return helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL); - } - - int test_auto_color_correction_gray_600dpi(void* data) - { - const char* color = OPTION_VALUE_YSMS_256JHD; - int dpi = 600; - unsigned int len = strlen(color); - helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len); - helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len); - return helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL); - } - /*设置设备型号*/ int test_set_devs_model(void* data) { @@ -1943,11 +1634,76 @@ public: } unsigned int l = str.size(); ret = helper_->io_control(IO_CTRL_CODE_SET_DEVS_MODEL, &str[0], &l); - if (ret != SCANNER_ERR_OK)return ret; + if (ret != SCANNER_ERR_OK) + return ret; helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"设置设备类型成功", true); return ret; } + int public_test_image_correct(void* data, int dpi, bool isColor) + { + if (!data) + { + return SCANNER_ERR_NO_DATA; + } + wchar_t* sc = (wchar_t*)data; + std::string str; + size_t len = 0; + int ret = wchar_to_char(str, sc, &len); + if (ret == ERROR_INSUFFICIENT_BUFFER) + { + str.resize(len); + ret = wchar_to_char(str, sc, &len); + } + if (str.empty()) + { + helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"校正失败", false); + + return -1; + } + + unsigned int l = str.size(); + ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &l); + const char* color = isColor ? OPTION_VALUE_YSMS_24WCS : OPTION_VALUE_YSMS_256JHD; + unsigned int colorlen = strlen(color); + ret = helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen); + + SANE_Bool isOriImg = true; + ret = ret = helper_->io_control(IO_CTRL_CODE_ORIGINAL_IMAGE, (void*)&isOriImg, &l); + + ret = helper_->io_control(IO_CTRL_CODE_SET_CORRECT_IMAGE, &str[0], &l); + ret = helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL); + + if (ret != SCANNER_ERR_OK) + return ret; + + //helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"校正完成", true); + return ret; + } + int test_image_correct_rgb_200dpi(void* data) + { + return public_test_image_correct(data, 200, true); + } + int test_image_correct_gray_200dpi(void* data) + { + return public_test_image_correct(data, 200, false); + } + int test_image_correct_rgb_300dpi(void* data) + { + return public_test_image_correct(data, 300, true); + } + int test_image_correct_gray_300dpi(void* data) + { + return public_test_image_correct(data, 300, false); + } + int test_image_correct_rgb_600dpi(void* data) + { + return public_test_image_correct(data, 600, true); + } + int test_image_correct_gray_600dpi(void* data) + { + return public_test_image_correct(data, 600, false); + } private: }; diff --git a/code/base/test_base.h b/code/base/test_base.h index 60f2676..c8a6a18 100644 --- a/code/base/test_base.h +++ b/code/base/test_base.h @@ -98,19 +98,18 @@ #define HGPDTTOOLDB_TITLE_SHUTDOWN L"关机" /*设置固件语言模式*/ #define HGPDTTOOLDB_TITLE_SET_FIRMWARE_LANGUAGE L"设置固件语言模式" -/* 自动图像校正彩色+200dpi */ -#define HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_RGB_200DPI L"自动图像校正彩色_200dpi" -/* 自动图像校正灰度+200dpi */ -#define HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_GRAY_200DPI L"自动图像校正灰度_200dpi" -/* 自动图像校正彩色+300dpi */ -#define HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_RGB_300DPI L"自动图像校正彩色_300dpi" -/* 自动图像校正灰度+300dpi */ -#define HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_GRAY_300DPI L"自动图像校正灰度_300dpi" -/* 自动图像校正彩色+600dpi */ -#define HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_RGB_600DPI L"自动图像校正彩色_600dpi" -/* 自动图像校正灰度+600dpi */ -#define HGPDTTOOLDB_TITLE_AUTO_COLOR_CORRECTION_GRAY_600DPI L"自动图像校正灰度_600dpi" - +/*彩色图像扫描校正+200dpi*/ +#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_200DPI L"彩色图像扫描校正+200dpi" +/*灰度图像扫描校正+200dpi*/ +#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_200DPI L"灰度图像扫描校正+200dpi" +/*彩色图像扫描校正+300dpi*/ +#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_300DPI L"彩色图像扫描校正+300dpi" +/*灰度图像扫描校正+300dpi*/ +#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_300DPI L"灰度图像扫描校正+300dpi" +/*彩色图像扫描校正+600dpi*/ +#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_600DPI L"彩色图像扫描校正+600dpi" +/*灰度图像扫描校正+600dpi*/ +#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_600DPI L"灰度图像扫描校正+600dpi" //////////////////////////////////////NAME////////////////////////////////////// #define WRITE_CFG_NAME L"write-cfg" /* 设置json序列号 */ @@ -215,18 +214,18 @@ #define HGPDTTOOLDB_NAME_SHUTDOWN L"SHUTDOWN" /*设置固件语言模式*/ #define HGPDTTOOLDB_NAME_SET_FIRMWARE_LANGUAGE L"SET_FIRMWARE_LANGUAGE" -/* 自动图像校正彩色+200dpi */ -#define HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_200DPI L"AUTO_COLOR_CORRECTION_RGB_200DPI" -/* 自动图像校正灰度+200dpi */ -#define HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_200DPI L"AUTO_COLOR_CORRECTION_GRAY_200DPI" -/* 自动图像校正彩色+300dpi */ -#define HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_300DPI L"AUTO_COLOR_CORRECTION_RGB_300DPI" -/* 自动图像校正灰度+300dpi */ -#define HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_300DPI L"AUTO_COLOR_CORRECTION_GRAY_300DPI" -/* 自动图像校正彩色+600dpi */ -#define HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_RGB_600DPI L"AUTO_COLOR_CORRECTION_RGB_600DPI" -/* 自动图像校正灰度+600dpi */ -#define HGPDTTOOLDB_NAME_AUTO_COLOR_CORRECTION_GRAY_600DPI L"AUTO_COLOR_CORRECTION_GRAY_600DPI" +/*彩色图像扫描校正+200dpi*/ +#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_200DPI L"IMAGE_CORRECTION_RGB_200DPI" +/*灰度图像扫描校正+200dpi*/ +#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_200DPI L"IMAGE_CORRECTION_GRAY_200DPI" +/*彩色图像扫描校正+300dpi*/ +#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI L"IMAGE_CORRECTION_RGB_300DPI" +/*灰度图像扫描校正+300dpi*/ +#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI L"IMAGE_CORRECTION_GRAY_300DPI" +/*彩色图像扫描校正+600dpi*/ +#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI L"IMAGE_CORRECTION_RGB_600DPI" +/*灰度图像扫描校正+600dpi*/ +#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI L"IMAGE_CORRECTION_GRAY_600DPI" #define TEST_DLL #ifdef TEST_DLL