webscan增加自动大小、纸张大小、空白页检测等配置

This commit is contained in:
luoliangyi 2024-10-17 10:41:45 +08:00
parent 7fa2e7872c
commit 17a4dbff25
3 changed files with 95 additions and 44 deletions

View File

@ -229,6 +229,11 @@ WebUser::WebUser(WebServer* server, HGUInt id, HGMsgPump msgPump, const std::str
m_source = "Adf-duplex"; m_source = "Adf-duplex";
m_mode = "Color"; m_mode = "Color";
m_resolution = "200"; m_resolution = "200";
m_pageauto = "yes";
m_papersize = "A4";
m_blankpageskip = "no";
m_blankpageskipsensitivity = "3";
m_multifeeddetection = "Stop";
SANE_Int version_code = 0; SANE_Int version_code = 0;
sane_init_ex(&version_code, sane_ex_callback, this); sane_init_ex(&version_code, sane_ex_callback, this);
@ -862,12 +867,23 @@ void WebUser::GetSettingInfoNew(const std::string& devName)
AddOptItem(optJson, arrayJson, "filetype", m_filetype.c_str(), fileTypeList); AddOptItem(optJson, arrayJson, "filetype", m_filetype.c_str(), fileTypeList);
const char* showBase64List[] = { "0", "1", NULL }; const char* showBase64List[] = { "0", "1", NULL };
AddOptItem(optJson, arrayJson, "showbase64", m_showbase64.c_str(), showBase64List); AddOptItem(optJson, arrayJson, "showbase64", m_showbase64.c_str(), showBase64List);
const char* sourceList[] = { "Adf-front", "Adf-back", "Adf-duplex", NULL }; const char* sourceList[] = { "Adf-duplex", NULL };
AddOptItem(optJson, arrayJson, "source", m_source.c_str(), sourceList); AddOptItem(optJson, arrayJson, "source", m_source.c_str(), sourceList);
const char* modeList[] = { "Lineart", "Gray", "Color", NULL }; const char* modeList[] = { "Lineart", "Gray", "Color", NULL };
AddOptItem(optJson, arrayJson, "mode", m_mode.c_str(), modeList); AddOptItem(optJson, arrayJson, "mode", m_mode.c_str(), modeList);
const char* resolutionList[] = { "100", "200", "300", NULL }; const char* resolutionList[] = { "100", "200", "300", NULL };
AddOptItem(optJson, arrayJson, "resolution", m_resolution.c_str(), resolutionList); AddOptItem(optJson, arrayJson, "resolution", m_resolution.c_str(), resolutionList);
const char* pageAutoList[] = { "yes", "no", NULL };
AddOptItem(optJson, arrayJson, "page-auto", m_pageauto.c_str(), pageAutoList);
const char* paperSizeList[] = { "A4", "A5", "A6", NULL };
AddOptItem(optJson, arrayJson, "paper-size", m_papersize.c_str(), paperSizeList);
const char* blankPageSkipList[] = { "yes", "no", NULL };
AddOptItem(optJson, arrayJson, "blank-page-skip", m_blankpageskip.c_str(), blankPageSkipList);
const char* blankPageSkipSensitivityList[] = { "1", "2", "3", "4", "5", NULL };
AddOptItem(optJson, arrayJson, "blank-page-skip-sensitivity", m_blankpageskipsensitivity.c_str(), blankPageSkipSensitivityList);
const char* multifeedDetectionList [] = { "yes", "no", NULL };
AddOptItem(optJson, arrayJson, "multifeed-detection", m_multifeeddetection.c_str(), multifeedDetectionList);
} }
cJSON_AddItemToObject(optListJson, "Options", arrayJson); cJSON_AddItemToObject(optListJson, "Options", arrayJson);
@ -999,6 +1015,16 @@ void WebUser::ScanNew(const std::string& devName, const std::string& devParam)
m_mode = p->valuestring; m_mode = p->valuestring;
else if (0 == strcmp(p->string, "resolution")) else if (0 == strcmp(p->string, "resolution"))
m_resolution = p->valuestring; m_resolution = p->valuestring;
else if (0 == strcmp(p->string, "page-auto"))
m_pageauto = p->valuestring;
else if (0 == strcmp(p->string, "paper-size"))
m_papersize = p->valuestring;
else if (0 == strcmp(p->string, "blank-page-skip"))
m_blankpageskip = p->valuestring;
else if (0 == strcmp(p->string, "blank-page-skip-sensitivity"))
m_blankpageskipsensitivity = p->valuestring;
else if (0 == strcmp(p->string, "multifeed-detection"))
m_multifeeddetection = p->valuestring;
p = p->next; p = p->next;
} }
@ -1874,25 +1900,6 @@ void WebUser::SetParam()
{ {
// Set Param // Set Param
if (m_source == "Adf-front")
{
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_DM);
HGBool b = HGFALSE;
SetParam(OPTION_TITLE_JHZFM, &b);
}
else if (m_source == "Adf-back")
{
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_DM);
HGBool b = HGTRUE;
SetParam(OPTION_TITLE_JHZFM, &b);
}
else
{
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_SM);
HGBool b = HGFALSE;
SetParam(OPTION_TITLE_JHZFM, &b);
}
if (m_mode == "Lineart") if (m_mode == "Lineart")
{ {
SetParam(OPTION_TITLE_YSMS, OPTION_VALUE_YSMS_HB); SetParam(OPTION_TITLE_YSMS, OPTION_VALUE_YSMS_HB);
@ -1906,9 +1913,59 @@ void WebUser::SetParam()
SetParam(OPTION_TITLE_YSMS, OPTION_VALUE_YSMS_24WCS); SetParam(OPTION_TITLE_YSMS, OPTION_VALUE_YSMS_24WCS);
} }
HGInt dpi = atoi(m_resolution.c_str()); HGInt dpi = 200;
if (m_resolution == "100")
dpi = 100;
else if (m_resolution == "300")
dpi = 300;
SetParam(OPTION_TITLE_FBL, &dpi); SetParam(OPTION_TITLE_FBL, &dpi);
if (m_pageauto == "yes")
{
SetParam(OPTION_TITLE_ZZCC, OPTION_VALUE_ZZCC_PPYSCC);
}
else
{
if (m_papersize == "A5")
SetParam(OPTION_TITLE_ZZCC, OPTION_VALUE_ZZCC_A5);
else if (m_papersize == "A6")
SetParam(OPTION_TITLE_ZZCC, OPTION_VALUE_ZZCC_A6);
else
SetParam(OPTION_TITLE_ZZCC, OPTION_VALUE_ZZCC_A4);
}
if (m_multifeeddetection == "Do-not-detect")
{
HGBool b = HGFALSE;
SetParam(OPTION_TITLE_CSBJC, &b);
}
else
{
HGBool b = HGTRUE;
SetParam(OPTION_TITLE_CSBJC, &b);
SetParam(OPTION_TITLE_SZTPCL, OPTION_VALUE_SZTPCL_DQTXBTZSM);
}
if (m_blankpageskip == "yes")
{
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_TGKBYTY);
HGInt value = 50;
if (m_blankpageskipsensitivity == "1")
value = 1;
else if (m_blankpageskipsensitivity == "2")
value = 25;
else if (m_blankpageskipsensitivity == "4")
value = 75;
else if (m_blankpageskipsensitivity == "5")
value = 100;
SetParam(OPTION_TITLE_TGKBYLMD, &value);
}
else
{
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_SM);
}
if (atoi(m_deletefilesbeforescan.c_str())) if (atoi(m_deletefilesbeforescan.c_str()))
{ {
ClearPath(m_filepath); ClearPath(m_filepath);

View File

@ -99,4 +99,9 @@ private:
std::string m_source; std::string m_source;
std::string m_mode; std::string m_mode;
std::string m_resolution; std::string m_resolution;
std::string m_pageauto;
std::string m_papersize;
std::string m_blankpageskip;
std::string m_blankpageskipsensitivity;
std::string m_multifeeddetection;
}; };

View File

@ -11,25 +11,9 @@
<select id="devicenames" style="width:200px; height:25px;"> <select id="devicenames" style="width:200px; height:25px;">
</select> </select>
<input id="getdevices" type="button" value="获取设备列表" onclick="getdevices()" /><br> <input id="getdevices" type="button" value="获取设备列表" onclick="getdevices()" /><br>
<label for="showbase64">显示Base64</label>
<input type="checkbox" id="showbase64"><br>
<label for="source">单/双面:</label>
<select id="source">
<option value="Adf-front">Adf-front</option>
<option value="Adf-back">Adf-back</option>
<option value="Adf-duplex" selected>Adf-duplex</option>
</select><br>
<label for="mode">颜色模式:</label>
<select id="mode">
<option value="Lineart">Lineart</option>
<option value="Gray">Gray</option>
<option value="Color" selected>Color</option>
</select><br>
<label for="resolution">分辨率:</label>
<input type="number" id="resolution" min="1" max="600" value="200" step="1"><br>
<input id="scan" type="button" value="扫描" onclick="scan()" /><br> <input id="scan" type="button" value="扫描" onclick="scan()" /><br>
<input id="getsettinginfo" type="button" value="获取扫描参数" onclick="getsettinginfo()" /> <input id="getsettinginfo" type="button" value="获取扫描参数" onclick="getsettinginfo()" /><br>
<input id="converttobase64" type="button" value="转换Base64" onclick="converttobase64()" /> <input id="converttobase64" type="button" value="转换Base64" onclick="converttobase64()" /><br>
</p> </p>
<p> <p>
<img id="myCanvas" width='640' height='480' style="background-color: black;"/> <img id="myCanvas" width='640' height='480' style="background-color: black;"/>
@ -138,14 +122,19 @@
var myCanvas = document.getElementById("myCanvas"); var myCanvas = document.getElementById("myCanvas");
myCanvas.src = 'placeholder.png'; myCanvas.src = 'placeholder.png';
psl.sane.showbase64 = document.getElementById('showbase64').checked ? 1 : 0; psl.sane.showbase64 = 1;
psl.sane.source = document.getElementById('source').value; psl.sane.source = "Adf-duplex";
psl.sane.mode = document.getElementById('mode').value; psl.sane.mode = "Color";
psl.sane.resolution = parseInt(document.getElementById('resolution').value, 10); psl.sane.resolution = "200";
psl.sane.deletefilesbeforescan = 1; psl.sane.deletefilesbeforescan = 1;
psl.sane.filepath = "D:\\123456"; psl.sane.filepath = "D:\\123456";
psl.sane.fileprefix = "KKKKKK"; psl.sane.fileprefix = "KKKKKK";
psl.sane.filetype = 6; psl.sane.filetype = 3;
psl.sane.pageauto = 1;
psl.sane.papersize = "A4";
psl.sane.blankpageskip = 0;
psl.sane.blankpageskipsensitivity = 3;
psl.sane.multifeeddetection = "Stop";
psl.sane.scan(document.getElementById('devicenames').value); psl.sane.scan(document.getElementById('devicenames').value);
} }