twain3.0/huagao/GscanJsonConfig.cpp

958 lines
34 KiB
C++

#include "GscanJsonConfig.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <sstream>
#include "Device/filetools.h"
#include "Device/CJsonObject.hpp"
GscanJsonConfig::GscanJsonConfig()
{
}
GscanJsonConfig::~GscanJsonConfig()
{
}
GScanCap GscanJsonConfig::GetDefaultGscancapValue()
{
GScanCap gcap;
gcap = JsonToGscancap(GetDefaultJson());
return gcap;
// /*< basic page setting*/
// gcap.pixtype = 2;//默认彩色
// gcap.automaticcolor = FALSE;
// gcap.automaticcolortype = 1;
// gcap.paperAlign = PaperAlign::Rot0;
// gcap.papertype = 0;//TwSS::NONE
// gcap.en_sizecheck = FALSE;
//
//#ifdef UV
// gcap.hardwarecaps.en_uv = FALSE;
//#endif
// gcap.is_autocrop = TRUE;//默认自动裁切
// gcap.is_duplex = TRUE;
// gcap.is_autodiscradblank_normal = FALSE;
// gcap.is_autodiscradblank_vince = FALSE;
// gcap.discardblank_percent = 20;
// gcap.is_switchfrontback = FALSE;
// gcap.resolution_dst = 200.0f;
// gcap.resolution_native = 200.0f;
//
// /*< brightness setting*/
// gcap.brightness = 0.0f;//默认亮度为0
// gcap.contrast = 0.0f;//默认对比度为0
// gcap.threshold = 128;
// gcap.gamma = 1.0;
// gcap.is_autocontrast = FALSE;//默认不自动对比度
//
// /*< image proecss setting*/
// gcap.autodescrew = TRUE;//自动纠偏 可用
// gcap.enhance_color = EnchaceColor::Enhance_None;//默认不进行颜色增强
// gcap.en_fold = FALSE;//默认不对折
// gcap.fillbackground = true;//默认不填黑框
// gcap.fillhole.is_fillhole = FALSE;
// gcap.fillhole.fillholeratio = 10;
// gcap.detachnoise.detachnoise = 30;
// gcap.detachnoise.is_detachnoise = FALSE;
// gcap.filter = 3;//对应Filter::None
// gcap.multi_output_red = FALSE;
// gcap.sharpen = SharpenBlur::Sharpen_None;
// gcap.hsvcorrect = FALSE;//默认不开启答题卡除红
//
// /*< feeder setting*/
// gcap.hardwarecaps.en_doublefeed = TRUE;//默认开启双张
// gcap.hardwarecaps.en_skrewdetect = TRUE;//默认开启歪斜检测
// gcap.hardwarecaps.en_stapledetect = FALSE;//默认不开启订书针检测
// gcap.hardwarecaps.skrewdetectlevel = 3;//默认处于3挡
// gcap.hardwarecaps.capturepixtype = 2;//彩色模式
// gcap.imageRotateDegree = 0.0f;//默认不进行旋转
// gcap.is_autotext = FALSE;
// gcap.is_backrotate180 = FALSE;
// gcap.AutoCrop_threshold = 40;
// gcap.is_convex = TRUE;
// gcap.noise = 8;
// gcap.indent = 5;
// gcap.is_dogeardetection = FALSE;
// gcap.scannum = -1;//默认连续扫描
// gcap.hardwarecaps.lowpowermode = (LowPowerMode)4;
// //gcap.scanrect = { 0 };
//
// return gcap;
}
void GscanJsonConfig::SaveGscanCapConfig(const GScanCap & gcap, const std::string path)
{
neb::CJsonObject outJson;
outJson.AddEmptySubObject("Config");//header
outJson["Config"].Add(PIXTYPE, (int)gcap.pixtype);
outJson["Config"].Add(AUTOMATICCOLOR, (bool)gcap.automaticcolor,false);
outJson["Config"].Add(AUTOMATICCOLORTYPR, (int)gcap.automaticcolortype);
outJson["Config"].Add(PAPARSIZE, (int)(gcap.papertype));
outJson["Config"].Add(PAPERALIGN, (int)(gcap.paperAlign));
outJson["Config"].Add(ENSIZECHECK, (bool)(gcap.en_sizecheck), false);
outJson["Config"].Add(AUTOCROP, (bool)(gcap.is_autocrop), false);
outJson["Config"].Add(RESOLUTION, (int)(gcap.resolution_dst));
outJson["Config"].Add(DUPLEX, (bool)(gcap.is_duplex),false);
outJson["Config"].Add(DISCARBLANK, (bool)(gcap.is_autodiscradblank_normal), false);
outJson["Config"].Add(DISCARBLANKVINCE, (bool)(gcap.is_autodiscradblank_vince), false);
//outJson["Config"].Add(DB_AREANUM, (int)(pConfigItem->DBlank_AreaNum));
//outJson["Config"].Add(DB_DEVNMAX, (int)(pConfigItem->DBlank_DevnMax));
outJson["Config"].Add(FLOD, (bool)(gcap.en_fold), false);
outJson["Config"].Add(SWITCHFRONTBACK, (bool)(gcap.is_switchfrontback), false);
#ifdef UV
outJson["Config"].Add(ENUVMODEL, (bool)(gcap.hardwarecaps.en_uv), false);
#endif
outJson["Config"].Add(BRIGHTNESS, (int)(gcap.brightness));
outJson["Config"].Add(AUTOCONTRAST, (bool)(gcap.is_autocontrast), false);
outJson["Config"].Add(CONTRAST, (int)(gcap.contrast));
outJson["Config"].Add(GAMMA_, (double)(gcap.gamma));
outJson["Config"].Add(FILTERTYPE, (int)(gcap.filter));
outJson["Config"].Add(ENHANCECOLOR,((int)gcap.enhance_color));
outJson["Config"].Add(SHARPENTYPE, (int)(gcap.sharpen));
outJson["Config"].Add(AUTODESCREW, (bool)(gcap.autodescrew), false);
outJson["Config"].Add(FILLBLACK, (bool)(gcap.fillbackground), false);
outJson["Config"].Add(MULTIOUTPUT, (bool)(gcap.multi_output_red), false);
outJson["Config"].Add(OUTHOLE, (bool)(gcap.fillhole.is_fillhole), false);
outJson["Config"].Add(OUTHOLERATIO, (int)(gcap.fillhole.fillholeratio));
outJson["Config"].Add(DETACHNOISE, (bool)(gcap.detachnoise.is_detachnoise), false);
outJson["Config"].Add(DETACHNOISEVALUE, (int)(gcap.detachnoise.detachnoise));
outJson["Config"].Add(HSVCORRECT, (bool)(gcap.hsvcorrect),false);
outJson["Config"].Add(ULTRADETECT, (bool)(gcap.hardwarecaps.en_doublefeed), false);
outJson["Config"].Add(BINDINGDETECT, (bool)(gcap.hardwarecaps.en_stapledetect), false);
outJson["Config"].Add(SCANCOUNT, (int)(gcap.scannum));
outJson["Config"].Add(DOCORIENTATION, (int)(gcap.imageRotateDegree));
outJson["Config"].Add(AUTO_TEXT, (bool)(gcap.is_autotext),false);
outJson["Config"].Add(BACKROTATE180, (bool)(gcap.is_backrotate180), false);
outJson["Config"].Add(NOISE, (int)(gcap.noise), false);
outJson["Config"].Add(ISCONVEX, (bool)(gcap.is_convex), false);
outJson["Config"].Add(INDENT, (int)(gcap.indent), false);
outJson["Config"].Add(AUTOCROP_THRESHOLD, (int)(gcap.AutoCrop_threshold), false);
outJson["Config"].Add(DOGEAR_DETECTION, (bool)(gcap.is_dogeardetection), false);
outJson["Config"].Add(SCREWDETECT, (bool)(gcap.hardwarecaps.en_skrewdetect), false);
outJson["Config"].Add(SCREWLEVEL, (int)(gcap.hardwarecaps.skrewdetectlevel));
outJson["Config"].Add(ITEMCAPTION, (string)(gcap.Caption));
outJson["Config"].Add(SAVEPATH, (string)(gcap.SavePath));
std::ofstream os;
os.open(path.c_str());
os << outJson.ToFormattedString();
os.close();
}
void GscanJsonConfig::WriteJsonArrayToFile(std::vector<GScanCap> cfgArray, const std::string filename)
{
neb::CJsonObject root;
root.AddEmptySubObject("Config");
/*< basic setting*/
root["Config"].AddEmptySubArray(PIXTYPE);
root["Config"].AddEmptySubArray(AUTOMATICCOLOR);
root["Config"].AddEmptySubArray(AUTOMATICCOLORTYPR);
root["Config"].AddEmptySubArray(PAPARSIZE);
root["Config"].AddEmptySubArray(PAPERALIGN);
root["Config"].AddEmptySubArray(ENSIZECHECK);
root["Config"].AddEmptySubArray(AUTOCROP);
root["Config"].AddEmptySubArray(RESOLUTION);
root["Config"].AddEmptySubArray(DUPLEX);
root["Config"].AddEmptySubArray(DISCARBLANK);
root["Config"].AddEmptySubArray(DISCARBLANKVINCE);
root["Config"].AddEmptySubArray(DISCARBLANK_VALUE);
#ifdef UV
root["Config"].AddEmptySubArray(ENUVMODEL);
#endif
//root["Config"].AddEmptySubArray(DB_AREANUM);
//root["Config"].AddEmptySubArray(DB_DEVNMAX);
root["Config"].AddEmptySubArray(FLOD);
root["Config"].AddEmptySubArray(SWITCHFRONTBACK);
root["Config"].AddEmptySubArray(DETACHNOISE);
root["Config"].AddEmptySubArray(DETACHNOISEVALUE);
/*< brightness setting*/
root["Config"].AddEmptySubArray(BRIGHTNESS);
root["Config"].AddEmptySubArray(AUTOCONTRAST);
root["Config"].AddEmptySubArray(CONTRAST);
root["Config"].AddEmptySubArray(GAMMA_);
/*< image process settings*/
root["Config"].AddEmptySubArray(FILTERTYPE);
root["Config"].AddEmptySubArray(ENHANCECOLOR);
root["Config"].AddEmptySubArray(SHARPENTYPE);
root["Config"].AddEmptySubArray(AUTODESCREW);
root["Config"].AddEmptySubArray(FILLBLACK);
root["Config"].AddEmptySubArray(MULTIOUTPUT);
root["Config"].AddEmptySubArray(OUTHOLE);
root["Config"].AddEmptySubArray(OUTHOLERATIO);
root["Config"].AddEmptySubArray(HSVCORRECT);
/*< feeder settings*/
root["Config"].AddEmptySubArray(ULTRADETECT);
root["Config"].AddEmptySubArray(BINDINGDETECT);
root["Config"].AddEmptySubArray(SCANCOUNT);
root["Config"].AddEmptySubArray(DOCORIENTATION);
root["Config"].AddEmptySubArray(AUTO_TEXT);
root["Config"].AddEmptySubArray(BACKROTATE180);
root["Config"].AddEmptySubArray(DOGEAR_DETECTION);
root["Config"].AddEmptySubArray(SCREWDETECT);
root["Config"].AddEmptySubArray(SCREWLEVEL);
root["Config"].AddEmptySubArray(NOISE);
root["Config"].AddEmptySubArray(INDENT);
root["Config"].AddEmptySubArray(AUTOCROP_THRESHOLD);
root["Config"].AddEmptySubArray(ISCONVEX);
/*< other settings*/
root["Config"].AddEmptySubArray(ITEMCAPTION);
root["Config"].AddEmptySubArray(SAVEPATH);
for (int i = 0; i < cfgArray.size(); i++)
{
root["Config"][PIXTYPE].Add((int)cfgArray[i].pixtype);
root["Config"][AUTOMATICCOLOR].Add(i,(bool)cfgArray[i].automaticcolor);
root["Config"][AUTOMATICCOLORTYPR].Add((int)cfgArray[i].automaticcolortype);
root["Config"][PAPARSIZE].Add((int)cfgArray[i].papertype);
root["Config"][PAPERALIGN].Add((int)cfgArray[i].paperAlign);
root["Config"][ENSIZECHECK].Add(i, (bool)cfgArray[i].en_sizecheck);
root["Config"][AUTOCROP].Add(i, (bool)cfgArray[i].is_autocrop);
root["Config"][RESOLUTION].Add((int)cfgArray[i].resolution_dst);
root["Config"][DUPLEX].Add(i,(bool)cfgArray[i].is_duplex);
root["Config"][DISCARBLANK].Add(i, (bool)cfgArray[i].is_autodiscradblank_normal);
root["Config"][DISCARBLANKVINCE].Add(i, (bool)cfgArray[i].is_autodiscradblank_vince);
root["Config"][DISCARBLANK_VALUE].Add((int)cfgArray[i].discardblank_percent);
//root["Config"][DB_AREANUM].Add(cfgArray[i].DBlank_AreaNum);
//root["Config"][DB_DEVNMAX].Add(cfgArray[i].DBlank_DevnMax);
root["Config"][FLOD].Add(i, (bool)cfgArray[i].en_fold);
root["Config"][SWITCHFRONTBACK].Add(i,(bool)cfgArray[i].is_switchfrontback);
#ifdef UV
root["Config"][ENUVMODEL].Add(i, cfgArray[i].hardwarecaps.en_uv);
#endif
root["Config"][BRIGHTNESS].Add((int)cfgArray[i].brightness);
root["Config"][AUTOCONTRAST].Add(i, (bool)cfgArray[i].is_autocontrast);
root["Config"][CONTRAST].Add((int)cfgArray[i].contrast);
root["Config"][GAMMA_].Add((double)cfgArray[i].gamma);
root["Config"][FILTERTYPE].Add((int)cfgArray[i].filter);
root["Config"][ENHANCECOLOR].Add((int)cfgArray[i].enhance_color);
root["Config"][SHARPENTYPE].Add((int)cfgArray[i].sharpen);
root["Config"][AUTODESCREW].Add(i, (bool)cfgArray[i].autodescrew);
root["Config"][FILLBLACK].Add(i, (bool)cfgArray[i].fillbackground);
root["Config"][MULTIOUTPUT].Add(i, (bool)cfgArray[i].multi_output_red);
root["Config"][OUTHOLE].Add(i, (bool)cfgArray[i].fillhole.is_fillhole);
root["Config"][OUTHOLERATIO].Add((int)cfgArray[i].fillhole.fillholeratio);
root["Config"][DETACHNOISE].Add(i, (bool)cfgArray[i].detachnoise.is_detachnoise);
root["Config"][DETACHNOISEVALUE].Add((int)cfgArray[i].detachnoise.detachnoise);
root["Config"][HSVCORRECT].Add(i, (bool)cfgArray[i].hsvcorrect);
root["Config"][ULTRADETECT].Add(i, (bool)cfgArray[i].hardwarecaps.en_doublefeed);
root["Config"][BINDINGDETECT].Add(i, (bool)cfgArray[i].hardwarecaps.en_stapledetect);
root["Config"][SCANCOUNT].Add((int)cfgArray[i].scannum);
root["Config"][DOCORIENTATION].Add((int)cfgArray[i].imageRotateDegree);
root["Config"][AUTO_TEXT].Add(i, (bool)cfgArray[i].is_autotext);
root["Config"][BACKROTATE180].Add(i, (bool)cfgArray[i].is_backrotate180);
root["Config"][NOISE].Add((int)cfgArray[i].noise);
root["Config"][INDENT].Add((int)cfgArray[i].indent);
root["Config"][ISCONVEX].Add(i, (bool)cfgArray[i].is_convex);
root["Config"][AUTOCROP_THRESHOLD].Add((int)cfgArray[i].AutoCrop_threshold);
root["Config"][DOGEAR_DETECTION].Add(i, (bool)cfgArray[i].is_dogeardetection);
root["Config"][SCREWDETECT].Add(i, (bool)cfgArray[i].hardwarecaps.en_skrewdetect);
root["Config"][SCREWLEVEL].Add((int)cfgArray[i].hardwarecaps.skrewdetectlevel);
if (cfgArray[i].Caption.c_str() != NULL)
{
root["Config"][ITEMCAPTION].Add(cfgArray[i].Caption);
}
if (cfgArray[i].SavePath.c_str() != NULL)
{
root["Config"][SAVEPATH].Add(cfgArray[i].SavePath);
}
}
std::ofstream os;
os.open(filename.c_str());
os << root.ToFormattedString();
os.close();
}
GScanCap GscanJsonConfig::ReadGscanCap()
{
TCHAR szIniFile[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE);
_tcscat(szIniFile, HUAGAO_SCAN);
_tcscat(szIniFile, TWAIN_INIPATH);
_tcscat(szIniFile, TEXT("\\"));
std::string dirpath = TCHAR2STRING(szIniFile);
bool is_exist = isFileExist(dirpath+ TCHAR2STRING(TWAIN_JSON_NAME));
try {
if (is_exist)
return JsonToGscancap(Readjson(dirpath + TCHAR2STRING(TWAIN_JSON_NAME)));
else {
throw std::exception();
}
}
catch (...){
FileTools::writelog(log_ERROR, "ReadGscanCap Error");
remove((dirpath + TCHAR2STRING(TWAIN_JSON_NAME)).c_str());
createDirectory((char*)dirpath.c_str());
SaveGscancapJson(JsonToGscancap(GetDefaultJson()), dirpath + TCHAR2STRING(TWAIN_JSON_NAME));
return JsonToGscancap(Readjson(dirpath + TCHAR2STRING(TWAIN_JSON_NAME)));
}
//if (!is_exist) {
// createDirectory((char*)dirpath.c_str());
// _tcscat(szIniFile, TWAIN_JSON_NAME);
// std::string dstpath = TCHAR2STRING(szIniFile);
// vector<GScanCap> vc;
// vc.push_back(GetDefaultGscancapValue());
// WriteJsonArrayToFile(vc, dstpath);
// return vc[0];
//}
//_tcscat(szIniFile, TWAIN_JSON_NAME);
//std::string s_default = TCHAR2STRING(szIniFile);
//vector<GScanCap> vc;
//vc = ReadGscanCapsVector(s_default.c_str());
//if (vc.size() != 0)
//{
// return vc[0];
//}
//return GetDefaultGscancapValue();
}
std::vector<GScanCap> GscanJsonConfig::ReadGscanCapsVector(const std::string gcapsfilepath)
{
std::vector<GScanCap> re;
FILE* file = fopen(gcapsfilepath.c_str(), "rb");
if (!file)
{
return re;
}
fseek(file, 0, SEEK_END);
long size = ftell(file);
fseek(file, 0, SEEK_SET);
std::string text;
char* buffer = new char[size + 1];
buffer[size] = 0;
if (!fread(buffer, 1, size, file) == (unsigned long)size)
{
return re;
}
text = buffer;
fclose(file);
delete[]buffer;
re = parseJsonFromString(text);
return re;
}
bool GscanJsonConfig::DeleteJsonFile(std::string path)
{
return remove(path.c_str());
}
std::vector<GScanCap> GscanJsonConfig::parseJsonFromString(const std::string str)
{
neb::CJsonObject root(str);
vector<GScanCap> vcConfig;
int size = 0;
neb::CJsonObject itmPaparSize;
root["Config"].Get(PAPARSIZE, itmPaparSize);
size = itmPaparSize.GetArraySize();
if (size > 0)
{
neb::CJsonObject itmPixType;
root["Config"].Get(PIXTYPE, itmPixType);
neb::CJsonObject itmautomaticcolor;
root["Config"].Get(AUTOMATICCOLOR, itmautomaticcolor);
neb::CJsonObject itmautomaticcolortype;
root["Config"].Get(AUTOMATICCOLORTYPR, itmautomaticcolortype);
neb::CJsonObject itmAutoCrop;
root["Config"].Get(AUTOCROP, itmAutoCrop);
neb::CJsonObject itmPaperAlign;
root["Config"].Get(PAPERALIGN, itmPaperAlign);
neb::CJsonObject itmSizeCheck;
root["Config"].Get(ENSIZECHECK, itmSizeCheck);
neb::CJsonObject itmRes;
root["Config"].Get(RESOLUTION, itmRes);
neb::CJsonObject itmDulpex;
root["Config"].Get(DUPLEX, itmDulpex);
neb::CJsonObject itmDiscardBlk;
root["Config"].Get(DISCARBLANK, itmDiscardBlk);
neb::CJsonObject itmDiscardBlkVince;
root["Config"].Get(DISCARBLANKVINCE, itmDiscardBlkVince);
//neb::CJsonObject itmDBAreaNum;
//root["Config"].Get(DB_AREANUM, itmDBAreaNum);
//neb::CJsonObject itmDBDevnMax;
//root["Config"].Get(DB_DEVNMAX, itmDBDevnMax);
neb::CJsonObject itmEnFlod;
root["Config"].Get(FLOD, itmEnFlod);
neb::CJsonObject itmEnSwitchFrontBack;
root["Config"].Get(SWITCHFRONTBACK, itmEnSwitchFrontBack);
neb::CJsonObject itmdiscarbrank_value;
root["Config"].Get(DISCARBLANK_VALUE, itmdiscarbrank_value);
#ifdef UV
neb::CJsonObject itmEnUV;
root["Config"].Get(ENUVMODEL, itmEnUV);
#endif
neb::CJsonObject itmBrtnes;
root["Config"].Get(BRIGHTNESS, itmBrtnes);
neb::CJsonObject itmAutoCrnt;
root["Config"].Get(AUTOCONTRAST, itmAutoCrnt);
neb::CJsonObject itmContrast;
root["Config"].Get(CONTRAST, itmContrast);
neb::CJsonObject itmGamma;
root["Config"].Get(GAMMA_, itmGamma);
neb::CJsonObject itmFilter;
root["Config"].Get(FILTERTYPE, itmFilter);
neb::CJsonObject itmEnchace;
root["Config"].Get(ENHANCECOLOR, itmEnchace);
neb::CJsonObject itmSharpen;
root["Config"].Get(SHARPENTYPE, itmSharpen);
neb::CJsonObject itmAutoDescrew;
root["Config"].Get(AUTODESCREW, itmAutoDescrew);
neb::CJsonObject itmFillBlack;
root["Config"].Get(FILLBLACK, itmFillBlack);
neb::CJsonObject itmMultiOutput;
root["Config"].Get(MULTIOUTPUT, itmMultiOutput);
neb::CJsonObject itmOutHole;
root["Config"].Get(OUTHOLE, itmOutHole);
neb::CJsonObject itmOutHoleRatio;
root["Config"].Get(OUTHOLERATIO, itmOutHoleRatio);
neb::CJsonObject itmDetachNoise;
root["Config"].Get(DETACHNOISE, itmDetachNoise);
neb::CJsonObject itmDetachNoiseValue;
root["Config"].Get(DETACHNOISEVALUE, itmDetachNoiseValue);
neb::CJsonObject itmHsvCorrect;
root["Config"].Get(HSVCORRECT, itmHsvCorrect);
neb::CJsonObject itmUltDetect;
root["Config"].Get(ULTRADETECT, itmUltDetect);
neb::CJsonObject itmBingdingDetect;
root["Config"].Get(BINDINGDETECT, itmBingdingDetect);
neb::CJsonObject itmScanCount;
root["Config"].Get(SCANCOUNT, itmScanCount);
neb::CJsonObject itmDocOrientation;
root["Config"].Get(DOCORIENTATION, itmDocOrientation);
neb::CJsonObject itmAutotext;
root["Config"].Get(AUTO_TEXT, itmAutotext);
neb::CJsonObject itmBackRotate;
root["Config"].Get(BACKROTATE180, itmBackRotate);
neb::CJsonObject itmNoise;
root["Config"].Get(NOISE, itmNoise);
neb::CJsonObject itmIndent;
root["Config"].Get(INDENT, itmIndent);
neb::CJsonObject itmisConvex;
root["Config"].Get(ISCONVEX, itmisConvex);
neb::CJsonObject itmAutoCrop_t;
root["Config"].Get(AUTOCROP_THRESHOLD, itmAutoCrop_t);
neb::CJsonObject itmdogeardetection;
root["Config"].Get(DOGEAR_DETECTION, itmdogeardetection);
neb::CJsonObject itmScrewDetct;
root["Config"].Get(SCREWDETECT, itmScrewDetct);
neb::CJsonObject itmScrewLevel;
root["Config"].Get(SCREWLEVEL, itmScrewLevel);
neb::CJsonObject itmCaption;
if (!root["Config"][ITEMCAPTION].IsEmpty())
{
root["Config"].Get(ITEMCAPTION, itmCaption);
}
neb::CJsonObject itmSavePtah;
if (!root["Config"][SAVEPATH].IsEmpty())
{
root["Config"].Get(SAVEPATH, itmSavePtah);
}
for (int i = 0; i < size; i++)
{
GScanCap cfp;
int i_value;
double f_value;
bool b_value;
std::string s_value;
itmPixType.Get(i, i_value);
cfp.pixtype = i_value;
itmautomaticcolor.Get(i, b_value);
cfp.automaticcolor = b_value;
itmautomaticcolortype.Get(i, i_value);
cfp.automaticcolortype = i_value;
itmPaparSize.Get(i, i_value);
cfp.papertype = (byte)i_value;
itmPaperAlign.Get(i, i_value);
cfp.paperAlign = (PaperAlign)i_value;
itmSizeCheck.Get(i, b_value);
cfp.en_sizecheck = b_value ? 1 : 0;
itmAutoCrop.Get(i, b_value);
cfp.is_autocrop = b_value ? 1 : 0;
itmRes.Get(i, i_value);
cfp.resolution_dst = i_value;
itmDulpex.Get(i, b_value);
cfp.is_duplex = b_value ? 1 : 0;
itmdiscarbrank_value.Get(i, i_value);
cfp.discardblank_percent = i_value;
itmDiscardBlk.Get(i, b_value);
cfp.is_autodiscradblank_normal = b_value ? 1 : 0;
itmDiscardBlkVince.Get(i, b_value);
cfp.is_autodiscradblank_vince = b_value ? 1 : 0;
//itmDBAreaNum.Get(i, i_value);
//cfp.DBlank_AreaNum = i_value;
//itmDBDevnMax.Get(i, i_value);
//cfp.DBlank_DevnMax = i_value;
itmEnFlod.Get(i, b_value);
cfp.en_fold = b_value ? 1 : 0;
itmEnSwitchFrontBack.Get(i, b_value);
cfp.is_switchfrontback = b_value ? 1 : 0;
#ifdef UV
itmEnUV.Get(i, b_value);
cfp.hardwarecaps.en_uv = b_value ? 1 : 0;
#endif
itmBrtnes.Get(i, i_value);
cfp.brightness = i_value;
itmAutoCrnt.Get(i, b_value);
cfp.is_autocontrast = b_value ? 1 : 0;
itmContrast.Get(i, i_value);
cfp.contrast = i_value;
itmGamma.Get(i, f_value);
cfp.gamma = f_value;
itmFilter.Get(i, i_value);
cfp.filter = i_value;
itmEnchace.Get(i, i_value);
cfp.enhance_color = i_value;
itmSharpen.Get(i, i_value);
cfp.sharpen = i_value;
itmAutoDescrew.Get(i, b_value);
cfp.autodescrew = b_value ? 1 : 0;
itmFillBlack.Get(i, b_value);
cfp.fillbackground = b_value ? 1 : 0;
itmMultiOutput.Get(i, b_value);
cfp.multi_output_red = b_value ? 1 : 0;
itmOutHole.Get(i, b_value);
cfp.fillhole.is_fillhole = b_value ? 1 : 0;
itmOutHoleRatio.Get(i, i_value);
cfp.fillhole.fillholeratio = i_value;
itmDetachNoise.Get(i, b_value);
cfp.detachnoise.is_detachnoise = b_value ? 1 : 0;
itmDetachNoiseValue.Get(i, i_value);
cfp.detachnoise.detachnoise = i_value;
itmHsvCorrect.Get(i, b_value);
cfp.hsvcorrect = b_value ? 1 : 0;
itmUltDetect.Get(i, b_value);
cfp.hardwarecaps.en_doublefeed = b_value ? 1 : 0;
itmBingdingDetect.Get(i, b_value);
cfp.hardwarecaps.en_stapledetect = b_value ? 1 : 0;
itmScanCount.Get(i, i_value);
cfp.scannum = i_value;
itmDocOrientation.Get(i, i_value);
cfp.imageRotateDegree = i_value;
itmAutoCrop_t.Get(i, i_value);
cfp.AutoCrop_threshold = i_value;
itmNoise.Get(i, i_value);
cfp.noise = i_value;
itmIndent.Get(i, i_value);
cfp.indent = i_value;
itmAutotext.Get(i, b_value);
cfp.is_autotext = b_value?1:0;
itmBackRotate.Get(i, b_value);
cfp.is_backrotate180 = b_value ? 1 : 0;
itmisConvex.Get(i, b_value);
cfp.is_convex = b_value ? 1 : 0;
itmdogeardetection.Get(i, b_value);
cfp.is_dogeardetection = b_value ? 1 : 0;
itmScrewDetct.Get(i, b_value);
cfp.hardwarecaps.en_skrewdetect = b_value ? 1 : 0;
itmScrewLevel.Get(i, i_value);
cfp.hardwarecaps.skrewdetectlevel = i_value;
if (!root["Config"][ITEMCAPTION].IsEmpty())
{
itmCaption.Get(i, s_value);
cfp.Caption = s_value;
}
if (!root["Config"][SAVEPATH].IsEmpty())
{
itmSavePtah.Get(i, s_value);
cfp.SavePath = s_value;
}
vcConfig.push_back(cfp);
}
}
else
{
GScanCap cfp;
int index;
bool bvalue;
double fvalue;
std::string svalue;
root["Config"].Get(PIXTYPE, index);
cfp.pixtype = index;
root["Config"].Get(AUTOMATICCOLOR, bvalue);
cfp.automaticcolor = bvalue;
root["Config"].Get(AUTOMATICCOLORTYPR, index);
cfp.automaticcolortype = index;
root["Config"].Get(PAPARSIZE, index);
cfp.papertype = index;
root["Config"].Get(PAPERALIGN, index);
cfp.paperAlign =(PaperAlign) index;
root["Config"].Get(ENSIZECHECK, bvalue);
cfp.en_sizecheck = bvalue ? 1 : 0;
root["Config"].Get(AUTOCROP, bvalue);
cfp.is_autocrop = bvalue?1:0;
root["Config"].Get(RESOLUTION, index);
cfp.resolution_dst = index;
root["Config"].Get(DUPLEX, bvalue);
cfp.is_duplex = bvalue?1:0;
root["Config"].Get(DISCARBLANK, bvalue);
cfp.is_autodiscradblank_normal = bvalue?1:0;
root["Config"].Get(DISCARBLANKVINCE, bvalue);
cfp.is_autodiscradblank_vince = bvalue?1:0;
root["Config"].Get(DISCARBLANK_VALUE, index);
cfp.discardblank_percent = index ;
root["Config"].Get(FLOD, bvalue);
cfp.en_fold = bvalue?1:0;
root["Config"].Get(SWITCHFRONTBACK, bvalue);
cfp.is_switchfrontback = bvalue?1:0;
#ifdef UV
root["Config"].Get(ENUVMODEL, bvalue);
cfp.hardwarecaps.en_uv = bvalue ? 1 : 0;
#endif
root["Config"].Get(BRIGHTNESS, index);
cfp.brightness = index;
root["Config"].Get(AUTOCONTRAST, bvalue);
cfp.is_autocontrast = bvalue?1:0;
root["Config"].Get(CONTRAST, index);
cfp.contrast = index;
root["Config"].Get(GAMMA_, fvalue);
cfp.gamma = fvalue;
root["Config"].Get(FILTERTYPE, index);
cfp.filter = (byte)index;
root["Config"].Get(ENHANCECOLOR, index);
cfp.enhance_color =(byte) index;
root["config"].Get(SHARPENTYPE, index);
cfp.sharpen = (byte)index;
root["Config"].Get(AUTODESCREW, bvalue);
cfp.autodescrew = bvalue?1:0;
root["Config"].Get(FILLBLACK, bvalue);
cfp.fillbackground = bvalue?1:0;
root["Config"].Get(MULTIOUTPUT, bvalue);
cfp.multi_output_red = bvalue?1:0;
root["Config"].Get(OUTHOLE, bvalue);
cfp.fillhole.is_fillhole = bvalue?1:0;
root["Config"].Get(OUTHOLERATIO, index);
cfp.fillhole.fillholeratio = index;
root["Config"].Get(DETACHNOISE, bvalue);
cfp.detachnoise.is_detachnoise = bvalue ? 1 : 0;
root["Config"].Get(DETACHNOISEVALUE, index);
cfp.detachnoise.detachnoise = index;
root["Config"].Get(HSVCORRECT, bvalue);
cfp.hsvcorrect = bvalue ? 1 : 0;
root["Config"].Get(NOISE, index);
cfp.noise = index;
root["Config"].Get(INDENT, index);
cfp.indent = index;
root["Config"].Get(AUTOCROP_THRESHOLD, index);
cfp.AutoCrop_threshold = index;
root["Config"].Get(ULTRADETECT, bvalue);
cfp.hardwarecaps.en_doublefeed = bvalue?1:0;
root["Config"].Get(BINDINGDETECT, bvalue);
cfp.hardwarecaps.en_stapledetect = bvalue ? 1 : 0;
root["Config"].Get(SCANCOUNT, index);
cfp.scannum = index;
root["Config"].Get(DOCORIENTATION, index);
cfp.imageRotateDegree = index;
root["Config"].Get(AUTO_TEXT, bvalue);
cfp.is_autotext = bvalue?1:0;
root["Config"].Get(BACKROTATE180, bvalue);
cfp.is_backrotate180 = bvalue ? 1 : 0;
root["Config"].Get(ISCONVEX, bvalue);
cfp.is_convex = bvalue ? 1 : 0;
root["Config"].Get(DOGEAR_DETECTION, bvalue);
cfp.is_dogeardetection = bvalue ? 1 : 0;
root["Config"].Get(SCREWDETECT, bvalue);
cfp.hardwarecaps.en_skrewdetect = bvalue ? 1 : 0;
root["Config"].Get(SCREWLEVEL, index);
cfp.hardwarecaps.skrewdetectlevel = index;
if (!root["Config"][ITEMCAPTION].IsEmpty())
{
root["Config"].Get(ITEMCAPTION, svalue);
cfp.Caption = svalue;
}
if (!root["Config"][SAVEPATH].IsEmpty())
{
root["Config"].Get(SAVEPATH, svalue);
cfp.SavePath = svalue;
}
vcConfig.push_back(cfp);
}
return vcConfig;
}
void GscanJsonConfig::SaveGscancapJson(GScanCap cap, std::string path)
{
cap.SavePath = cap.Caption = "";
json js = GscancapToJson(cap);
std::ofstream of;
try {
of.open(path, std::ios::out|std::ios::binary);
of.write(js.dump().data(), js.dump().size());
of.close();
}
catch (std::exception &e) {
if (of.is_open())
of.close();
FileTools::writelog(log_ERROR, "save json error :"+std::string(e.what()));
}
}
json GscanJsonConfig::GscancapToJson(GScanCap& cap)
{
auto js = GetDefaultJson();
js[CONFIG][PIXTYPE] = cap.pixtype;
js[CONFIG][AUTOMATICCOLOR] = cap.automaticcolor;
js[CONFIG][AUTOMATICCOLORTYPR] = cap.automaticcolortype;
js[CONFIG][PAPARSIZE] = cap.papertype;
js[CONFIG][PAPERALIGN] = cap.paperAlign;
js[CONFIG][ENSIZECHECK] = cap.en_sizecheck;
js[CONFIG][AUTOCROP] = cap.is_autocrop;
js[CONFIG][RESOLUTION] = cap.resolution_dst;
js[CONFIG][DUPLEX] = cap.is_duplex;
js[CONFIG][DISCARBLANK] = cap.is_autodiscradblank_normal;
js[CONFIG][DISCARBLANKVINCE] = cap.is_autodiscradblank_vince;
js[CONFIG][DISCARBLANK_VALUE] = cap.discardblank_percent;
js[CONFIG][FLOD] = cap.en_fold;
js[CONFIG][SWITCHFRONTBACK] = cap.is_switchfrontback;
#ifdef UV
js[CONFIG][ENUVMODEL] = cap.hardwarecaps.en_uv;
#endif
js[CONFIG][DETACHNOISE] = cap.detachnoise.is_detachnoise;
js[CONFIG][DETACHNOISEVALUE] = cap.detachnoise.detachnoise;
js[CONFIG][BRIGHTNESS] = cap.brightness;
js[CONFIG][AUTOCONTRAST] = cap.is_autocontrast;
js[CONFIG][CONTRAST] = cap.contrast;
js[CONFIG][GAMMA_] = cap.gamma;
js[CONFIG][CROPMODEL] = cap.normalCrop;
js[CONFIG][FILTERTYPE] = cap.filter;
js[CONFIG][ENHANCECOLOR] = cap.enhance_color;
js[CONFIG][SHARPENTYPE] = cap.sharpen;
js[CONFIG][AUTODESCREW] = cap.autodescrew;
js[CONFIG][FILLBLACK] = cap.fillbackground;
js[CONFIG][MULTIOUTPUT] = cap.multi_output_red;
js[CONFIG][OUTHOLE] = cap.fillhole.is_fillhole;
js[CONFIG][OUTHOLERATIO] = cap.fillhole.fillholeratio;
js[CONFIG][HSVCORRECT] = cap.hsvcorrect;
js[CONFIG][ULTRADETECT] = cap.hardwarecaps.en_doublefeed;
js[CONFIG][BINDINGDETECT] = cap.hardwarecaps.en_stapledetect;
js[CONFIG][SCANCOUNT] = cap.scannum;
js[CONFIG][DOCORIENTATION] = cap.imageRotateDegree;
js[CONFIG][AUTO_TEXT] = cap.is_autotext;
js[CONFIG][BACKROTATE180] = cap.is_backrotate180;
js[CONFIG][DOGEAR_DETECTION] = cap.is_dogeardetection;
js[CONFIG][SCREWDETECT] = cap.hardwarecaps.en_skrewdetect;
js[CONFIG][SCREWLEVEL] = cap.hardwarecaps.skrewdetectlevel;
js[CONFIG][NOISE] = cap.noise;
js[CONFIG][INDENT] = cap.indent;
js[CONFIG][AUTOCROP_THRESHOLD] = cap.AutoCrop_threshold;
js[CONFIG][ISCONVEX] = cap.is_convex;
js[CONFIG][ITEMCAPTION] = cap.Caption;
js[CONFIG][SAVEPATH] = cap.SavePath.c_str();
js[CONFIG][LOWPOWERMODE] = cap.hardwarecaps.lowpowermode;
return js;
}
GScanCap GscanJsonConfig::JsonToGscancap(json& js)
{
if (!js.is_object())
js = GetDefaultJson();
GScanCap cap{ 0 };
cap.pixtype = json_cast(js[CONFIG][PIXTYPE]).to_int();
cap.automaticcolor = json_cast(js[CONFIG][AUTOMATICCOLOR]).to_int();
cap.automaticcolortype = json_cast(js[CONFIG][AUTOMATICCOLORTYPR]).to_int();
cap.papertype = json_cast(js[CONFIG][PAPARSIZE]).to_int();
cap.paperAlign = static_cast<PaperAlign>(json_cast(js[CONFIG][PAPERALIGN]).to_uint8());
cap.en_sizecheck = json_cast(js[CONFIG][ENSIZECHECK]).to_int();
cap.is_autocrop = json_cast(js[CONFIG][AUTOCROP]).to_int();
cap.resolution_dst = json_cast(js[CONFIG][RESOLUTION]).to_float();
cap.is_duplex = json_cast(js[CONFIG][DUPLEX]).to_int();
cap.is_autodiscradblank_normal = json_cast(js[CONFIG][DISCARBLANK]).to_int();
cap.is_autodiscradblank_vince = json_cast(js[CONFIG][DISCARBLANKVINCE]).to_int();
cap.discardblank_percent = json_cast(js[CONFIG][DISCARBLANK_VALUE]).to_int();
cap.en_fold = json_cast(js[CONFIG][FLOD]).to_int();
cap.is_switchfrontback = json_cast(js[CONFIG][SWITCHFRONTBACK]).to_int();
#ifdef UV
cap.hardwarecaps.en_uv = json_cast(js[CONFIG][ENUVMODEL]).to_int();
#endif // UV
cap.normalCrop = json_cast(js[CONFIG][CROPMODEL]).to_bool();
cap.detachnoise.is_detachnoise = json_cast(js[CONFIG][DETACHNOISE]).to_int();
cap.detachnoise.detachnoise = json_cast(js[CONFIG][DETACHNOISEVALUE]).to_int();
cap.brightness = json_cast(js[CONFIG][BRIGHTNESS]).to_float();
cap.is_autocontrast = json_cast(js[CONFIG][AUTOCONTRAST]).to_int();
cap.contrast = json_cast(js[CONFIG][CONTRAST]).to_float();
cap.gamma = json_cast(js[CONFIG][GAMMA_]).to_float();
cap.filter = json_cast(js[CONFIG][FILTERTYPE]).to_int();
cap.enhance_color = json_cast(js[CONFIG][ENHANCECOLOR]).to_int();
cap.sharpen = json_cast(js[CONFIG][SHARPENTYPE]).to_int();
cap.autodescrew = json_cast(js[CONFIG][AUTODESCREW]).to_int();
cap.fillbackground = json_cast(js[CONFIG][FILLBLACK]).to_int();
cap.multi_output_red = json_cast(js[CONFIG][MULTIOUTPUT]).to_int();
cap.fillhole.is_fillhole = json_cast(js[CONFIG][OUTHOLE]).to_int();
cap.fillhole.fillholeratio = json_cast(js[CONFIG][OUTHOLERATIO]).to_int();
cap.hsvcorrect = json_cast(js[CONFIG][HSVCORRECT]).to_int();
cap.hardwarecaps.en_doublefeed = json_cast(js[CONFIG][ULTRADETECT]).to_int();
cap.hardwarecaps.en_stapledetect = json_cast(js[CONFIG][BINDINGDETECT]).to_int();
cap.scannum = json_cast(js[CONFIG][SCANCOUNT]).to_int();
cap.imageRotateDegree = json_cast(js[CONFIG][DOCORIENTATION]).to_int();
cap.is_autotext = json_cast(js[CONFIG][AUTO_TEXT]).to_int();
cap.is_backrotate180 = json_cast(js[CONFIG][BACKROTATE180]).to_int();
cap.is_dogeardetection = json_cast(js[CONFIG][DOGEAR_DETECTION]).to_int();
cap.hardwarecaps.en_skrewdetect = json_cast(js[CONFIG][SCREWDETECT]).to_int();
cap.hardwarecaps.skrewdetectlevel = json_cast(js[CONFIG][SCREWLEVEL]).to_int();
cap.noise = json_cast(js[CONFIG][NOISE]).to_int();
cap.indent = json_cast(js[CONFIG][INDENT]).to_int();
cap.AutoCrop_threshold = json_cast(js[CONFIG][AUTOCROP_THRESHOLD]).to_int();
cap.hardwarecaps.lowpowermode = (LowPowerMode)json_cast(js[CONFIG][LOWPOWERMODE]).to_int();
cap.is_convex = json_cast(js[CONFIG][ISCONVEX]).to_int();
cap.Caption = json_cast(js[CONFIG][ITEMCAPTION]).to_string();
cap.SavePath = json_cast(js[CONFIG][SAVEPATH]).to_string();
return cap;
}
json GscanJsonConfig::GetDefaultJson()
{
#ifdef UV
return json::parse(R"({
"Config": {
"iPixType": 2 ,
"bAutoMaticColorDetece": false ,
"iAutoMaticColorDeteceType": 1 ,
"iPaparSize": 0 ,
"iPaperAlign": 0 ,
"iEnSizeCheck": false ,
"bAuotCrop": true ,
"bcropmodel": false,
"iResolution": 200 ,
"iDuplex": true ,
"bDiscardBlank": false ,
"bDiscardBlankVince": false ,
"discardblank_percent": 20 ,
"bFlod": false ,
"bSwitchFrontBack": false ,
"bUVmodel": false,
"detachnoise": false ,
"detachnoisevalue": 30 ,
"iBrightness": 0 ,
"bAutoContrast": false ,
"iContrast": 0 ,
"dGamma": 1 ,
"iFilter": 3 ,
"iEnhance": 0 ,
"iSharpen": 0 ,
"bAutoDescrew": true ,
"bFillBlcak": true ,
"iMultiOutPut": false ,
"bOutHole": false ,
"iOutHoleRatio": 10 ,
"bHsvCorrect": false ,
"bUltrasonicDetect": true ,
"bBindingDetect": false ,
"ScanCount": 65535 ,
"bOrientation": 0 ,
"bAutoText": false ,
"iBackRotate180": false ,
"dogeardetection": false ,
"bScrewDetect": true ,
"iScrewLevel": 3 ,
"Noise": 8 ,
"Indent": 5 ,
"AutoCrop_Threshold": 40 ,
"isConvex": true ,
"ilowpowermode": 4,
"Caption": "" ,
"SavePath": ""
}
})");
#else
return json::parse(R"({
"Config": {
"iPixType": 2 ,
"bAutoMaticColorDetece": false ,
"iAutoMaticColorDeteceType": 1 ,
"iPaparSize": 0 ,
"iPaperAlign": 0 ,
"iEnSizeCheck": false ,
"bAuotCrop": true ,
"bcropmodel": false,
"iResolution": 200 ,
"iDuplex": true ,
"bDiscardBlank": false ,
"bDiscardBlankVince": false ,
"discardblank_percent": 20 ,
"bFlod": false ,
"bSwitchFrontBack": false ,
"detachnoise": false ,
"detachnoisevalue": 30 ,
"iBrightness": 0 ,
"bAutoContrast": false ,
"iContrast": 0 ,
"dGamma": 1 ,
"iFilter": 3 ,
"iEnhance": 0 ,
"iSharpen": 0 ,
"bAutoDescrew": true ,
"bFillBlcak": true ,
"iMultiOutPut": false ,
"bOutHole": false ,
"iOutHoleRatio": 10 ,
"bHsvCorrect": false ,
"bUltrasonicDetect": true ,
"bBindingDetect": false ,
"ScanCount": 65535 ,
"bOrientation": 0 ,
"bAutoText": false ,
"iBackRotate180": false ,
"dogeardetection": false ,
"bScrewDetect": true ,
"iScrewLevel": 3 ,
"Noise": 8 ,
"Indent": 5 ,
"AutoCrop_Threshold": 40 ,
"isConvex": true ,
"ilowpowermode": 4,
"Caption": "" ,
"SavePath": ""
}
})");
#endif
}
json GscanJsonConfig::Readjson(std::string path)
{
std::ifstream f;
f.open(path, std::ios::in|std::ios::binary);
json js;
try {
if(f.is_open()){
std::string text = (std::ostringstream() << f.rdbuf()).str();
js = json::parse(text);
f.close();
}
return js.is_object() ? js: throw std::exception("js pares error");
}
catch (...)
{
FileTools::writelog(log_ERROR, "read json error");
f.is_open() ? f.close() : void();
return GetDefaultJson();
}
}