完善webscan文件类型设置功能

This commit is contained in:
luoliangyi 2024-10-16 17:35:11 +08:00
parent 77b5b76c85
commit 7fa2e7872c
1 changed files with 23 additions and 14 deletions

View File

@ -858,7 +858,7 @@ void WebUser::GetSettingInfoNew(const std::string& devName)
AddOptItem(optJson, arrayJson, "fileprefix", m_fileprefix.c_str(), NULL); AddOptItem(optJson, arrayJson, "fileprefix", m_fileprefix.c_str(), NULL);
const char* deleteFileBeforeScanList[] = { "0", "1", NULL }; const char* deleteFileBeforeScanList[] = { "0", "1", NULL };
AddOptItem(optJson, arrayJson, "deletefilesbeforescan", m_deletefilesbeforescan.c_str(), deleteFileBeforeScanList); AddOptItem(optJson, arrayJson, "deletefilesbeforescan", m_deletefilesbeforescan.c_str(), deleteFileBeforeScanList);
const char* fileTypeList[] = { "1", "2", "3", "4", "5", "6", "7", NULL }; const char* fileTypeList[] = { "1", "2", "3", "4", "6", NULL };
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);
@ -866,7 +866,8 @@ void WebUser::GetSettingInfoNew(const std::string& devName)
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);
AddOptItem(optJson, arrayJson, "resolution", m_resolution.c_str(), NULL); const char* resolutionList[] = { "100", "200", "300", NULL };
AddOptItem(optJson, arrayJson, "resolution", m_resolution.c_str(), resolutionList);
} }
cJSON_AddItemToObject(optListJson, "Options", arrayJson); cJSON_AddItemToObject(optListJson, "Options", arrayJson);
@ -1587,12 +1588,24 @@ int WebUser::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
if (sane_img->header.format == SANE_FRAME_GRAY) if (sane_img->header.format == SANE_FRAME_GRAY)
{ {
if (1 == sane_img->header.depth) if (1 == sane_img->header.depth)
{
imgType = HGBASE_IMGTYPE_BINARY; imgType = HGBASE_IMGTYPE_BINARY;
if (2 == atoi(p->m_filetype.c_str()))
p->m_filesuffix = "pbm";
}
else if (8 == sane_img->header.depth) else if (8 == sane_img->header.depth)
{
imgType = HGBASE_IMGTYPE_GRAY; imgType = HGBASE_IMGTYPE_GRAY;
if (2 == atoi(p->m_filetype.c_str()))
p->m_filesuffix = "pgm";
}
} }
else if (sane_img->header.format == SANE_FRAME_RGB) else if (sane_img->header.format == SANE_FRAME_RGB)
{
imgType = HGBASE_IMGTYPE_RGB; imgType = HGBASE_IMGTYPE_RGB;
if (2 == atoi(p->m_filetype.c_str()))
p->m_filesuffix = "ppm";
}
HGByte* data = sane_img->data; HGByte* data = sane_img->data;
HGImageInfo imgInfo = { (HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines, HGImageInfo imgInfo = { (HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines,
@ -1785,9 +1798,9 @@ std::string WebUser::GetBase64(const std::string& filePath)
else if (HGIMGFMT_TYPE_TIFF == imgType) else if (HGIMGFMT_TYPE_TIFF == imgType)
prefix = "data:image/tiff;base64,"; prefix = "data:image/tiff;base64,";
else if (HGIMGFMT_TYPE_PDF == imgType) else if (HGIMGFMT_TYPE_PDF == imgType)
prefix = "data:image/pdf;base64,"; prefix = "data:application/pdf;base64,";
else if (HGIMGFMT_TYPE_OFD == imgType) else if (HGIMGFMT_TYPE_PNM == imgType)
prefix = "data:image/ofd;base64,"; prefix = "data:image/pnm;base64,";
base64.insert(0, prefix); base64.insert(0, prefix);
} }
@ -1902,21 +1915,17 @@ void WebUser::SetParam()
} }
if (1 == atoi(m_filetype.c_str())) if (1 == atoi(m_filetype.c_str()))
m_filesuffix = "bmp";
else if (2 == atoi(m_filetype.c_str()))
m_filesuffix = "png";
else if (4 == atoi(m_filetype.c_str()))
m_filesuffix = "tif"; m_filesuffix = "tif";
else if (5 == atoi(m_filetype.c_str())) else if (2 == atoi(m_filetype.c_str()))
m_filesuffix = "gif"; m_filesuffix = "ppm";
else if (4 == atoi(m_filetype.c_str()))
m_filesuffix = "png";
else if (6 == atoi(m_filetype.c_str())) else if (6 == atoi(m_filetype.c_str()))
m_filesuffix = "pdf"; m_filesuffix = "pdf";
else if (7 == atoi(m_filetype.c_str()))
m_filesuffix = "ofd";
else else
m_filesuffix = "jpg"; m_filesuffix = "jpg";
if ("tif" == m_filesuffix || "pdf" == m_filesuffix || "ofd" == m_filesuffix) if ("tif" == m_filesuffix || "pdf" == m_filesuffix)
{ {
HGBase_CreateDir(m_filepath.c_str()); HGBase_CreateDir(m_filepath.c_str());
HGChar fileName[256]; HGChar fileName[256];