diff --git a/HaoGaoCOrrect修改记录.txt b/HaoGaoCOrrect修改记录.txt index d03b596..69cab33 100644 --- a/HaoGaoCOrrect修改记录.txt +++ b/HaoGaoCOrrect修改记录.txt @@ -3,4 +3,7 @@ 2,通过选择扫描框中的保存校正前后原图进行图片保存 3,软件打开时自动查找已有设备打开,然后将打开的型号显示在型号选择框中,也可以通过型号选择框更换型号 4,界面整合,幅面页面等设置统一在扫描框中 -5,CIS的通道,阀值以及畸变检测中目标值,偏差值等参数自动加载和保存 \ No newline at end of file +5,CIS的通道,阀值以及畸变检测中目标值,偏差值等参数自动加载和保存 + +2021年7月31日 +1.增加3399 板子g100 g200 校正及配置功能 \ No newline at end of file diff --git a/HuaGoCorrect/A3.cpp b/HuaGoCorrect/A3.cpp index 71bd364..78b933d 100644 --- a/HuaGoCorrect/A3.cpp +++ b/HuaGoCorrect/A3.cpp @@ -5,6 +5,7 @@ #include "HuaGoCorrect.h" #include "A3.h" #include "afxdialogex.h" +#include "HuaGoCorrectDlg.h" // CA3 Ի @@ -28,6 +29,14 @@ void CA3::DoDataExchange(CDataExchange* pDX) BEGIN_MESSAGE_MAP(CA3, CDialog) + ON_BN_CLICKED(IDC_BTNGETGRAYSP, &CA3::OnBnClickedBtngetgraysp) + ON_BN_CLICKED(IDC_BTNSETGRAYSP, &CA3::OnBnClickedBtnsetgraysp) + ON_BN_CLICKED(IDC_BTNGETUVSP, &CA3::OnBnClickedBtngetuvsp) + ON_BN_CLICKED(IDC_BTNSETUVSP, &CA3::OnBnClickedBtnsetuvsp) + ON_BN_CLICKED(IDC_BTNGETCOLORSP, &CA3::OnBnClickedBtngetcolorsp) + ON_BN_CLICKED(IDC_BTNSETCOLORSP, &CA3::OnBnClickedBtnsetcolorsp) + ON_BN_CLICKED(IDC_BTNGETSLEEPTIME, &CA3::OnBnClickedBtngetsleeptime) + ON_BN_CLICKED(IDC_BTNSETSLEEPTIME, &CA3::OnBnClickedBtnsetsleeptime) END_MESSAGE_MAP() @@ -43,3 +52,130 @@ BOOL CA3::OnInitDialog() return TRUE; // return TRUE unless you set the focus to a control // 쳣: OCX ҳӦ FALSE } + + +void CA3::OnBnClickedBtngetsp() +{ + // TODO: ڴӿؼ֪ͨ +} + + +void CA3::OnBnClickedBtnsetsp() +{ + // TODO: ڴӿؼ֪ͨ +} + +void CA3::OnBnClickedBtngetgraysp() +{ + // TODO: ڴӿؼ֪ͨ + OnGetOrSetSp(true, 0); +} + + +void CA3::OnBnClickedBtnsetgraysp() +{ + // TODO: ڴӿؼ֪ͨ + OnGetOrSetSp(false, 0); +} + + +void CA3::OnBnClickedBtngetuvsp() +{ + // TODO: ڴӿؼ֪ͨ + OnGetOrSetSp(true, 2); +} + + +void CA3::OnBnClickedBtnsetuvsp() +{ + // TODO: ڴӿؼ֪ͨ + OnGetOrSetSp(false, 2); +} + + +void CA3::OnBnClickedBtngetcolorsp() +{ + // TODO: ڴӿؼ֪ͨ + OnGetOrSetSp(true, 1); +} + + +void CA3::OnBnClickedBtnsetcolorsp() +{ + OnGetOrSetSp(false, 1); +} + + +void CA3::OnGetOrSetSp(bool get,int type) +{ + int sp; + CString str_sp; + auto parent = (CHuaGoCorrectDlg*)GetParent(); + int itemid = type == 0 ? IDC_LBGRAYSP : (type == 1 ? IDC_LBCOLORSP : IDC_LBGUVSP); //IDC_LBCOLORSP + if (get) + { + + parent->m_drv->GetSptime(type, sp); + str_sp.Format("%d", sp); + SetDlgItemText(itemid, str_sp); + } + else + { + GetDlgItemText(itemid, str_sp); + int value= atoi(str_sp); + parent->m_drv->SetSptime(type, value); + } +} + + +void CA3::OnGetOrSetSleepTime(bool get, int type) +{ + int sp; + CString str_sp; + auto parent = (CHuaGoCorrectDlg*)GetParent(); + int itemid = type == 0 ? IDC_LBGRAYSP : (type == 1 ? IDC_LBCOLORSP : IDC_LBGUVSP); //IDC_LBCOLORSP + if (get) + { + + parent->m_drv->GetSptime(type, sp); + str_sp.Format("%d", sp); + SetDlgItemText(itemid, str_sp); + } + else + { + GetDlgItemText(itemid, str_sp); + int value = atoi(str_sp); + parent->m_drv->SetSptime(type, value); + } +} + +void CA3::UpdateSleepTime(bool get) +{ + int sp; + CString str_sp; + auto parent = (CHuaGoCorrectDlg*)GetParent(); + if (get) + { + parent->m_drv->GetSleepTime(sp); + str_sp.Format("%d", sp); + SetDlgItemText(IDC_LBSLEEPTIME, str_sp); + } + else + { + GetDlgItemText(IDC_LBSLEEPTIME, str_sp); + int value = atoi(str_sp); + if (value <= 0) value = 60; + parent->m_drv->SetSleepTime(value); + } +} + +void CA3::OnBnClickedBtngetsleeptime() +{ + UpdateSleepTime(true); +} + + +void CA3::OnBnClickedBtnsetsleeptime() +{ + UpdateSleepTime(false); +} \ No newline at end of file diff --git a/HuaGoCorrect/A3.h b/HuaGoCorrect/A3.h index c3eb43d..6c55965 100644 --- a/HuaGoCorrect/A3.h +++ b/HuaGoCorrect/A3.h @@ -20,4 +20,23 @@ protected: DECLARE_MESSAGE_MAP() public: virtual BOOL OnInitDialog(); + afx_msg void OnBnClickedBtngetsp(); + afx_msg void OnBnClickedBtnsetsp(); + afx_msg void OnBnClickedBtngetgraysp(); + afx_msg void OnBnClickedBtnsetgraysp(); + afx_msg void OnBnClickedBtngetuvsp(); + afx_msg void OnBnClickedBtnsetuvsp(); + afx_msg void OnBnClickedBtngetcolorsp(); + afx_msg void OnBnClickedBtnsetcolorsp(); + +private: + void OnGetOrSetSp(bool get, int type); +public: + afx_msg + void OnGetOrSetSleepTime(bool get, int type); + void UpdateSleepTime(bool get); + void OnBnClickedBtngetsleeptime(); + afx_msg void OnBnClickedBtnsetsleeptime(); + afx_msg void OnBnClickedBtngetcolorsp2(); + afx_msg void OnBnClickedBtnsetcolorsp2(); }; diff --git a/HuaGoCorrect/A4.cpp b/HuaGoCorrect/A4.cpp index 1c744e7..acd4809 100644 --- a/HuaGoCorrect/A4.cpp +++ b/HuaGoCorrect/A4.cpp @@ -5,7 +5,7 @@ #include "HuaGoCorrect.h" #include "A4.h" #include "afxdialogex.h" - +#include "HuaGoCorrectDlg.h" // CA4 Ի @@ -13,44 +13,11 @@ IMPLEMENT_DYNAMIC(CA4, CDialog) CA4::CA4(CWnd* pParent /*=NULL*/) : CDialog(CA4::IDD, pParent) - , m_tbxAGain(0) - , m_tbxBGain(0) - , m_tbxAOffset(0) - , m_tbxBOffset(0) { m_iLastIndex = 0; m_iSelIndex = 0; - - m_tbxFRExposure = 0; - m_tbxFGExposure = 0; - m_tbxFBExposure = 0; - m_tbxF1Gain = 0; - m_tbxF2Gain = 0; - m_tbxF3Gain = 0; - m_tbxF4Gain = 0; - m_tbxF5Gain = 0; - m_tbxF6Gain = 0; - m_tbxF1Offset = 0; - m_tbxF2Offset = 0; - m_tbxF3Offset = 0; - m_tbxF4Offset = 0; - m_tbxF5Offset = 0; - m_tbxF6Offset = 0; - m_tbxBRExposure = 0; - m_tbxBGExposure = 0; - m_tbxBBExposure = 0; - m_tbxB1Gain = 0; - m_tbxB2Gain = 0; - m_tbxB3Gain = 0; - m_tbxB4Gain = 0; - m_tbxB5Gain = 0; - m_tbxB6Gain = 0; - m_tbxB1Offset = 0; - m_tbxB2Offset = 0; - m_tbxB3Offset = 0; - m_tbxB4Offset = 0; - m_tbxB5Offset = 0; - m_tbxB6Offset = 0; + jsonparams = { 0 }; + params = { 0 }; } CA4::~CA4() @@ -60,54 +27,50 @@ CA4::~CA4() void CA4::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); - DDX_Text(pDX, IDC_tbxFRExposure, m_tbxFRExposure); - DDX_Text(pDX, IDC_tbxFGExposure, m_tbxFGExposure); - DDX_Text(pDX, IDC_tbxFBExposure, m_tbxFBExposure); - DDX_Text(pDX, IDC_tbxF1Gain, m_tbxF1Gain); - DDX_Text(pDX, IDC_tbxF2Gain, m_tbxF2Gain); - DDX_Text(pDX, IDC_tbxF3Gain, m_tbxF3Gain); - DDX_Text(pDX, IDC_tbxF4Gain, m_tbxF4Gain); - DDX_Text(pDX, IDC_tbxF5Gain, m_tbxF5Gain); - DDX_Text(pDX, IDC_tbxF6Gain, m_tbxF6Gain); - DDX_Text(pDX, IDC_tbxF1Offset, m_tbxF1Offset); - DDX_Text(pDX, IDC_tbxF2Offset, m_tbxF2Offset); - DDX_Text(pDX, IDC_tbxF3Offset, m_tbxF3Offset); - DDX_Text(pDX, IDC_tbxF4Offset, m_tbxF4Offset); - DDX_Text(pDX, IDC_tbxF5Offset, m_tbxF5Offset); - DDX_Text(pDX, IDC_tbxF6Offset, m_tbxF6Offset); - DDX_Text(pDX, IDC_tbxBRExposure, m_tbxBRExposure); - DDX_Text(pDX, IDC_tbxBGExposure, m_tbxBGExposure); - DDX_Text(pDX, IDC_tbxBBExposure, m_tbxBBExposure); - DDX_Text(pDX, IDC_tbxB1Gain, m_tbxB1Gain); - DDX_Text(pDX, IDC_tbxB2Gain, m_tbxB2Gain); - DDX_Text(pDX, IDC_tbxB3Gain, m_tbxB3Gain); - DDX_Text(pDX, IDC_tbxB4Gain, m_tbxB4Gain); - DDX_Text(pDX, IDC_tbxB5Gain, m_tbxB5Gain); - DDX_Text(pDX, IDC_tbxB6Gain, m_tbxB6Gain); - DDX_Text(pDX, IDC_tbxB1Offset, m_tbxB1Offset); - DDX_Text(pDX, IDC_tbxB2Offset, m_tbxB2Offset); - DDX_Text(pDX, IDC_tbxB3Offset, m_tbxB3Offset); - DDX_Text(pDX, IDC_tbxB4Offset, m_tbxB4Offset); - DDX_Text(pDX, IDC_tbxB5Offset, m_tbxB5Offset); - DDX_Text(pDX, IDC_tbxB6Offset, m_tbxB6Offset); + DDX_Control(pDX, IDC_BTNGET_SERIAL, m_GetSerial); + DDX_Control(pDX,IDC_BTN_SET_SERIAL,m_SetSerial); + DDX_Control(pDX, IDC_BTN_GENSERIAL, m_AutoGenSerial); + DDX_Control(pDX, IDC_BTN_GETVIDPID, m_GetVid); + DDX_Control(pDX, IDC_BTN_SETVIDPID, m_SetVid); + DDX_Control(pDX, IDC_BTN_REBOOT, m_Reboot); + for (size_t i = 0; i < Exposures.size(); i++) + { + DDX_Text(pDX, Exposures[i], params.Exposures[i]);; + } + + for (size_t i = 0; i < Gains.size(); i++) + { + DDX_Text(pDX, Gains[i], params.Gain[i]); + } + + for (size_t i = 0; i < Offsets.size(); i++) + { + DDX_Text(pDX, Offsets[i], params.Offset[i]); + } DDX_Control(pDX, IDC_CMB_A4FlatModel, m_A4FlatModel); - DDX_Text(pDX, IDC_EDIT_AGAIN, m_tbxAGain); - DDV_MinMaxUInt(pDX, m_tbxAGain, 0, 1000); - DDX_Text(pDX, IDC_EDIT_BGAIN, m_tbxBGain); - DDV_MinMaxUInt(pDX, m_tbxBGain, 0, 1000); - DDX_Text(pDX, IDC_EDIT_AOFFSET, m_tbxAOffset); - DDV_MinMaxUInt(pDX, m_tbxAOffset, 0, 1000); - DDX_Text(pDX, IDC_EDIT_BOFFSET, m_tbxBOffset); - DDV_MinMaxUInt(pDX, m_tbxBOffset, 0, 1000); } BEGIN_MESSAGE_MAP(CA4, CDialog) ON_CBN_SELCHANGE(IDC_CMB_A4FlatModel, &CA4::OnCbnSelChangeA4FlatModel) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_AGAIN, &CA4::OnDeltaposSpinAgain) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_AOFFSET, &CA4::OnDeltaposSpinAoffset) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_BGAIN, &CA4::OnDeltaposSpinBgain) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_BOFFSET, &CA4::OnDeltaposSpinBoffset) + ON_BN_CLICKED(IDC_BTN_REBOOT, &CA4::OnBnClickedBtnReboot) + ON_BN_CLICKED(IDC_BTN_SETVIDPID, &CA4::OnBnClickedBtnSetvidpid) + ON_BN_CLICKED(IDC_BTN_GETVIDPID, &CA4::OnBnClickedBtnGetvidpid) + ON_BN_CLICKED(IDC_BTNGET_SERIAL, &CA4::OnBnClickedBtngetSerial) + ON_BN_CLICKED(IDC_BTN_GENSERIAL, &CA4::OnBnClickedBtnGenserial) + ON_BN_CLICKED(IDC_BTN_SET_SERIAL, &CA4::OnBnClickedBtnSetSerial) + ON_BN_CLICKED(IDC_BTN_GETHOR, &CA4::OnBnClickedBtnGethor) + ON_BN_CLICKED(IDC_BTN_GETVER, &CA4::OnBnClickedBtnGetver) + ON_BN_CLICKED(IDC_BTN_SETHOR, &CA4::OnBnClickedBtnSethor) + ON_BN_CLICKED(IDC_BTN_SETVER, &CA4::OnBnClickedBtnSetver) + ON_BN_CLICKED(IDC_BTNGET_VERSION, &CA4::OnBnClickedBtngetVersion) + ON_EN_CHANGE(IDC_tbxSerial, &CA4::OnEnChangetbxserial) + ON_BN_CLICKED(IDC_BTN_GETEXPOS, &CA4::OnBnClickedBtnGetexpos) + ON_BN_CLICKED(IDC_BTN_SETEXPOS, &CA4::OnBnClickedBtnSetexpos) + ON_BN_CLICKED(IDC_BTNAUP, &CA4::OnBnClickedBtnaup) + ON_BN_CLICKED(IDC_BTNADOWN, &CA4::OnBnClickedBtnadown) + ON_BN_CLICKED(IDC_BTNBUP, &CA4::OnBnClickedBtnbup) + ON_BN_CLICKED(IDC_BTNBDOWN, &CA4::OnBnClickedBtnbdown) END_MESSAGE_MAP() @@ -128,740 +91,301 @@ BOOL CA4::OnInitDialog() m_A4FlatModel.InsertString(3, _T("Ҷ")); m_A4FlatModel.SetCurSel(0); - //GetDlgItem(IDC_CMB_A4FlatModel)->EnableWindow(FALSE); - default0param(); - + GetDlgItem(IDC_BTN_GENSERIAL)->EnableWindow(FALSE); + GetDlgItem(IDC_BTN_GETVIDPID)->EnableWindow(FALSE); + GetDlgItem(IDC_BTN_SETVIDPID)->EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control // 쳣: OCX ҳӦ FALSE } +void CA4::SetCallBack(std::function t_call) +{ + m_func = t_call; +} + +void CA4::EnableItem(bool enable) +{ + this->GetDlgItem(IDC_BTNGET_SERIAL) ->EnableWindow(enable); + this->GetDlgItem(IDC_BTN_GENSERIAL)->EnableWindow(enable); + this->GetDlgItem(IDC_BTN_SET_SERIAL)->EnableWindow(enable); + this->GetDlgItem(IDC_BTN_GETVIDPID)->EnableWindow(enable); + this->GetDlgItem(IDC_BTN_SETVIDPID)->EnableWindow(enable); + this->GetDlgItem(IDC_BTN_REBOOT)->EnableWindow(enable); +} + +void CA4::SendCorrectParam() +{ + UpdateData(); + int index = m_A4FlatModel.GetCurSel(); + auto parent = (CHuaGoCorrectDlg*)GetParent(); + parent->m_drv->SendFlatData(params, index); +} + void CA4::OnCbnSelChangeA4FlatModel() { - // TODO: ڴӿؼ֪ͨ - //int nSel; - // ȡϿؼбѡ - m_iSelIndex = m_A4FlatModel.GetCurSel(); - - if(m_iLastIndex != m_iSelIndex) + auto parent = (CHuaGoCorrectDlg*)GetParent(); + if (parent->m_drv->IsConnected()) { - SaveNewParam(m_iLastIndex); - m_iLastIndex = m_iSelIndex; + auto correctdata = parent->m_drv->GetFlatData(); + updateA4Config(correctdata); } +} - switch (m_iSelIndex) - { +void CA4::updateA4Config(CaptureParams& pValues) +{ + UpdateData(TRUE); + switch (m_A4FlatModel.GetCurSel()) + { case 0: - default0param(); - break; + memcpy(params.Exposures, pValues.correctColorExposure, sizeof(pValues.correctColorExposure)); + memcpy(params.Gain, pValues.correctColorGain, sizeof(pValues.correctColorGain)); + memcpy(params.Offset, pValues.correctColorOffset, sizeof(pValues.correctColorOffset)); + break; case 1: - default1param(); + memcpy(params.Exposures, pValues.colorExposure, sizeof(pValues.colorExposure)); + memcpy(params.Gain, pValues.colorGain, sizeof(pValues.colorGain)); + memcpy(params.Offset, pValues.colorOffset, sizeof(pValues.colorOffset)); break; case 2: - default2param(); - break; + memcpy(params.Exposures, pValues.correctGrayExposure, sizeof(pValues.correctGrayExposure)); + memcpy(params.Gain, pValues.correctGrayGain, sizeof(pValues.correctGrayGain)); + memcpy(params.Offset, pValues.correctGrayOffset, sizeof(pValues.correctGrayOffset)); + break; case 3: - default3param(); - break; - default: - break; - } -} - -void CA4::default0param() -{ - UpdateData(TRUE); - m_tbxFRExposure = m_sFlatCorrection.ColorCorrection[0]; - m_tbxFGExposure = m_sFlatCorrection.ColorCorrection[1]; - m_tbxFBExposure = m_sFlatCorrection.ColorCorrection[2]; - m_tbxF1Gain = m_sFlatCorrection.ColorCorrection[3]; - m_tbxF2Gain = m_sFlatCorrection.ColorCorrection[4]; - m_tbxF3Gain = m_sFlatCorrection.ColorCorrection[5]; - m_tbxF4Gain = m_sFlatCorrection.ColorCorrection[6]; - m_tbxF5Gain = m_sFlatCorrection.ColorCorrection[7]; - m_tbxF6Gain = m_sFlatCorrection.ColorCorrection[8]; - m_tbxF1Offset = m_sFlatCorrection.ColorCorrection[9]; - m_tbxF2Offset = m_sFlatCorrection.ColorCorrection[10]; - m_tbxF3Offset = m_sFlatCorrection.ColorCorrection[11]; - m_tbxF4Offset = m_sFlatCorrection.ColorCorrection[12]; - m_tbxF5Offset = m_sFlatCorrection.ColorCorrection[13]; - m_tbxF6Offset = m_sFlatCorrection.ColorCorrection[14]; - m_tbxBRExposure = m_sFlatCorrection.ColorCorrection[15]; - m_tbxBGExposure = m_sFlatCorrection.ColorCorrection[16]; - m_tbxBBExposure = m_sFlatCorrection.ColorCorrection[17]; - m_tbxB1Gain = m_sFlatCorrection.ColorCorrection[18]; - m_tbxB2Gain = m_sFlatCorrection.ColorCorrection[19]; - m_tbxB3Gain = m_sFlatCorrection.ColorCorrection[20]; - m_tbxB4Gain = m_sFlatCorrection.ColorCorrection[21]; - m_tbxB5Gain = m_sFlatCorrection.ColorCorrection[22]; - m_tbxB6Gain = m_sFlatCorrection.ColorCorrection[23]; - m_tbxB1Offset = m_sFlatCorrection.ColorCorrection[24]; - m_tbxB2Offset = m_sFlatCorrection.ColorCorrection[25]; - m_tbxB3Offset = m_sFlatCorrection.ColorCorrection[26]; - m_tbxB4Offset = m_sFlatCorrection.ColorCorrection[27]; - m_tbxB5Offset = m_sFlatCorrection.ColorCorrection[28]; - m_tbxB6Offset = m_sFlatCorrection.ColorCorrection[29]; - UpdateData(FALSE); -} - -void CA4::default1param() -{ - UpdateData(TRUE); - m_tbxFRExposure = m_sFlatCorrection.ColorFlat[0]; - m_tbxFGExposure = m_sFlatCorrection.ColorFlat[1]; - m_tbxFBExposure = m_sFlatCorrection.ColorFlat[2]; - m_tbxF1Gain = m_sFlatCorrection.ColorFlat[3]; - m_tbxF2Gain = m_sFlatCorrection.ColorFlat[4]; - m_tbxF3Gain = m_sFlatCorrection.ColorFlat[5]; - m_tbxF4Gain = m_sFlatCorrection.ColorFlat[6]; - m_tbxF5Gain = m_sFlatCorrection.ColorFlat[7]; - m_tbxF6Gain = m_sFlatCorrection.ColorFlat[8]; - m_tbxF1Offset = m_sFlatCorrection.ColorFlat[9]; - m_tbxF2Offset = m_sFlatCorrection.ColorFlat[10]; - m_tbxF3Offset = m_sFlatCorrection.ColorFlat[11]; - m_tbxF4Offset = m_sFlatCorrection.ColorFlat[12]; - m_tbxF5Offset = m_sFlatCorrection.ColorFlat[13]; - m_tbxF6Offset = m_sFlatCorrection.ColorFlat[14]; - m_tbxBRExposure = m_sFlatCorrection.ColorFlat[15]; - m_tbxBGExposure = m_sFlatCorrection.ColorFlat[16]; - m_tbxBBExposure = m_sFlatCorrection.ColorFlat[17]; - m_tbxB1Gain = m_sFlatCorrection.ColorFlat[18]; - m_tbxB2Gain = m_sFlatCorrection.ColorFlat[19]; - m_tbxB3Gain = m_sFlatCorrection.ColorFlat[20]; - m_tbxB4Gain = m_sFlatCorrection.ColorFlat[21]; - m_tbxB5Gain = m_sFlatCorrection.ColorFlat[22]; - m_tbxB6Gain = m_sFlatCorrection.ColorFlat[23]; - m_tbxB1Offset = m_sFlatCorrection.ColorFlat[24]; - m_tbxB2Offset = m_sFlatCorrection.ColorFlat[25]; - m_tbxB3Offset = m_sFlatCorrection.ColorFlat[26]; - m_tbxB4Offset = m_sFlatCorrection.ColorFlat[27]; - m_tbxB5Offset = m_sFlatCorrection.ColorFlat[28]; - m_tbxB6Offset = m_sFlatCorrection.ColorFlat[29]; - UpdateData(FALSE); -} - -void CA4::default2param() -{ - UpdateData(TRUE); - m_tbxFRExposure = m_sFlatCorrection.GrayCorrection[0]; - m_tbxFGExposure = m_sFlatCorrection.GrayCorrection[1]; - m_tbxFBExposure = m_sFlatCorrection.GrayCorrection[2]; - m_tbxF1Gain = m_sFlatCorrection.GrayCorrection[3]; - m_tbxF2Gain = m_sFlatCorrection.GrayCorrection[4]; - m_tbxF3Gain = m_sFlatCorrection.GrayCorrection[5]; - m_tbxF4Gain = m_sFlatCorrection.GrayCorrection[6]; - m_tbxF5Gain = m_sFlatCorrection.GrayCorrection[7]; - m_tbxF6Gain = m_sFlatCorrection.GrayCorrection[8]; - m_tbxF1Offset = m_sFlatCorrection.GrayCorrection[9]; - m_tbxF2Offset = m_sFlatCorrection.GrayCorrection[10]; - m_tbxF3Offset = m_sFlatCorrection.GrayCorrection[11]; - m_tbxF4Offset = m_sFlatCorrection.GrayCorrection[12]; - m_tbxF5Offset = m_sFlatCorrection.GrayCorrection[13]; - m_tbxF6Offset = m_sFlatCorrection.GrayCorrection[14]; - m_tbxBRExposure = m_sFlatCorrection.GrayCorrection[15]; - m_tbxBGExposure = m_sFlatCorrection.GrayCorrection[16]; - m_tbxBBExposure = m_sFlatCorrection.GrayCorrection[17]; - m_tbxB1Gain = m_sFlatCorrection.GrayCorrection[18]; - m_tbxB2Gain = m_sFlatCorrection.GrayCorrection[19]; - m_tbxB3Gain = m_sFlatCorrection.GrayCorrection[20]; - m_tbxB4Gain = m_sFlatCorrection.GrayCorrection[21]; - m_tbxB5Gain = m_sFlatCorrection.GrayCorrection[22]; - m_tbxB6Gain = m_sFlatCorrection.GrayCorrection[23]; - m_tbxB1Offset = m_sFlatCorrection.GrayCorrection[24]; - m_tbxB2Offset = m_sFlatCorrection.GrayCorrection[25]; - m_tbxB3Offset = m_sFlatCorrection.GrayCorrection[26]; - m_tbxB4Offset = m_sFlatCorrection.GrayCorrection[27]; - m_tbxB5Offset = m_sFlatCorrection.GrayCorrection[28]; - m_tbxB6Offset = m_sFlatCorrection.GrayCorrection[29]; - UpdateData(FALSE); -} - -void CA4::default3param() -{ - UpdateData(TRUE); - m_tbxFRExposure = m_sFlatCorrection.GrayFlat[0]; - m_tbxFGExposure = m_sFlatCorrection.GrayFlat[1]; - m_tbxFBExposure = m_sFlatCorrection.GrayFlat[2]; - m_tbxF1Gain = m_sFlatCorrection.GrayFlat[3]; - m_tbxF2Gain = m_sFlatCorrection.GrayFlat[4]; - m_tbxF3Gain = m_sFlatCorrection.GrayFlat[5]; - m_tbxF4Gain = m_sFlatCorrection.GrayFlat[6]; - m_tbxF5Gain = m_sFlatCorrection.GrayFlat[7]; - m_tbxF6Gain = m_sFlatCorrection.GrayFlat[8]; - m_tbxF1Offset = m_sFlatCorrection.GrayFlat[9]; - m_tbxF2Offset = m_sFlatCorrection.GrayFlat[10]; - m_tbxF3Offset = m_sFlatCorrection.GrayFlat[11]; - m_tbxF4Offset = m_sFlatCorrection.GrayFlat[12]; - m_tbxF5Offset = m_sFlatCorrection.GrayFlat[13]; - m_tbxF6Offset = m_sFlatCorrection.GrayFlat[14]; - m_tbxBRExposure = m_sFlatCorrection.GrayFlat[15]; - m_tbxBGExposure = m_sFlatCorrection.GrayFlat[16]; - m_tbxBBExposure = m_sFlatCorrection.GrayFlat[17]; - m_tbxB1Gain = m_sFlatCorrection.GrayFlat[18]; - m_tbxB2Gain = m_sFlatCorrection.GrayFlat[19]; - m_tbxB3Gain = m_sFlatCorrection.GrayFlat[20]; - m_tbxB4Gain = m_sFlatCorrection.GrayFlat[21]; - m_tbxB5Gain = m_sFlatCorrection.GrayFlat[22]; - m_tbxB6Gain = m_sFlatCorrection.GrayFlat[23]; - m_tbxB1Offset = m_sFlatCorrection.GrayFlat[24]; - m_tbxB2Offset = m_sFlatCorrection.GrayFlat[25]; - m_tbxB3Offset = m_sFlatCorrection.GrayFlat[26]; - m_tbxB4Offset = m_sFlatCorrection.GrayFlat[27]; - m_tbxB5Offset = m_sFlatCorrection.GrayFlat[28]; - m_tbxB6Offset = m_sFlatCorrection.GrayFlat[29]; - UpdateData(FALSE); -} - -void CA4::updateA4Config(int *pValues) -{ - UpdateData(TRUE); - m_tbxFRExposure = pValues[0]; - m_tbxFGExposure = pValues[1]; - m_tbxFBExposure = pValues[2]; - m_tbxF1Gain = pValues[6]; - m_tbxF2Gain = pValues[7]; - m_tbxF3Gain = pValues[8]; - m_tbxF4Gain = pValues[9]; - m_tbxF5Gain = pValues[10]; - m_tbxF6Gain = pValues[11]; - m_tbxF1Offset = pValues[18]; - m_tbxF2Offset = pValues[19]; - m_tbxF3Offset = pValues[20]; - m_tbxF4Offset = pValues[21]; - m_tbxF5Offset = pValues[22]; - m_tbxF6Offset = pValues[23]; - m_tbxBRExposure = pValues[3]; - m_tbxBGExposure = pValues[4]; - m_tbxBBExposure = pValues[5]; - m_tbxB1Gain = pValues[12]; - m_tbxB2Gain = pValues[13]; - m_tbxB3Gain = pValues[14]; - m_tbxB4Gain = pValues[15]; - m_tbxB5Gain = pValues[16]; - m_tbxB6Gain = pValues[17]; - m_tbxB1Offset = pValues[24]; - m_tbxB2Offset = pValues[25]; - m_tbxB3Offset = pValues[26]; - m_tbxB4Offset = pValues[27]; - m_tbxB5Offset = pValues[28]; - m_tbxB6Offset = pValues[29]; + memcpy(params.Exposures, pValues.grayExposure, sizeof(pValues.grayExposure)); + memcpy(params.Gain, pValues.grayGain, sizeof(pValues.grayGain)); + memcpy(params.Offset, pValues.grayOffset, sizeof(pValues.grayOffset)); + break; + default: + break; + } UpdateData(FALSE); } void CA4::LoadCfg() -{ - UINT iColorCorrectionParam[30] = {0}; - UINT iColorFlatParam[30] = {0}; - UINT iGrayCorrectionParam[30] = {0}; - UINT iGrayFlatParam[30] = {0}; - - //GetDlgItem(IDC_CMB_A4FlatModel)->EnableWindow(TRUE); - - iColorCorrectionParam[0] = ::GetPrivateProfileInt("ColorCorrection", "FBExposure", 340, INI_FILE_NAME); - iColorCorrectionParam[1] = ::GetPrivateProfileInt("ColorCorrection", "FGExposure", 620, INI_FILE_NAME); - iColorCorrectionParam[2] = ::GetPrivateProfileInt("ColorCorrection", "FRExposure", 324, INI_FILE_NAME); - iColorCorrectionParam[3] = ::GetPrivateProfileInt("ColorCorrection", "F3Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[4] = ::GetPrivateProfileInt("ColorCorrection", "F2Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[5] = ::GetPrivateProfileInt("ColorCorrection", "F1Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[6] = ::GetPrivateProfileInt("ColorCorrection", "F6Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[7] = ::GetPrivateProfileInt("ColorCorrection", "F5Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[8] = ::GetPrivateProfileInt("ColorCorrection", "F4Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[9] = ::GetPrivateProfileInt("ColorCorrection", "F3Offset", 117, INI_FILE_NAME); - iColorCorrectionParam[10] = ::GetPrivateProfileInt("ColorCorrection", "F2Offset", 117, INI_FILE_NAME); - iColorCorrectionParam[11] = ::GetPrivateProfileInt("ColorCorrection", "F1Offset", 117, INI_FILE_NAME); - iColorCorrectionParam[12] = ::GetPrivateProfileInt("ColorCorrection", "F6Offset", 117, INI_FILE_NAME); - iColorCorrectionParam[13] = ::GetPrivateProfileInt("ColorCorrection", "F5Offset", 117, INI_FILE_NAME); - iColorCorrectionParam[14] = ::GetPrivateProfileInt("ColorCorrection", "F4Offset", 117, INI_FILE_NAME); - iColorCorrectionParam[15] = ::GetPrivateProfileInt("ColorCorrection", "BBExposure", 233, INI_FILE_NAME); - iColorCorrectionParam[16] = ::GetPrivateProfileInt("ColorCorrection", "BGExposure", 418, INI_FILE_NAME); - iColorCorrectionParam[17] = ::GetPrivateProfileInt("ColorCorrection", "BRExposure", 220, INI_FILE_NAME); - iColorCorrectionParam[18] = ::GetPrivateProfileInt("ColorCorrection", "B3Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[19] = ::GetPrivateProfileInt("ColorCorrection", "B2Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[20] = ::GetPrivateProfileInt("ColorCorrection", "B1Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[21] = ::GetPrivateProfileInt("ColorCorrection", "B6Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[22] = ::GetPrivateProfileInt("ColorCorrection", "B5Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[23] = ::GetPrivateProfileInt("ColorCorrection", "B4Gain", 24, INI_FILE_NAME); - iColorCorrectionParam[24] = ::GetPrivateProfileInt("ColorCorrection", "B3Offset", 64, INI_FILE_NAME); - iColorCorrectionParam[25] = ::GetPrivateProfileInt("ColorCorrection", "B2Offset", 64, INI_FILE_NAME); - iColorCorrectionParam[26] = ::GetPrivateProfileInt("ColorCorrection", "B1Offset", 64, INI_FILE_NAME); - iColorCorrectionParam[27] = ::GetPrivateProfileInt("ColorCorrection", "B6Offset", 64, INI_FILE_NAME); - iColorCorrectionParam[28] = ::GetPrivateProfileInt("ColorCorrection", "B5Offset", 64, INI_FILE_NAME); - iColorCorrectionParam[29] = ::GetPrivateProfileInt("ColorCorrection", "B4Offset", 64, INI_FILE_NAME); - - memcpy(m_sFlatCorrection.ColorCorrection,iColorCorrectionParam,sizeof(iColorCorrectionParam)); - - iColorFlatParam[0] = ::GetPrivateProfileInt("ColorFlat", "FBExposure", 340, INI_FILE_NAME); - iColorFlatParam[1] = ::GetPrivateProfileInt("ColorFlat", "FGExposure", 620, INI_FILE_NAME); - iColorFlatParam[2] = ::GetPrivateProfileInt("ColorFlat", "FRExposure", 324, INI_FILE_NAME); - iColorFlatParam[3] = ::GetPrivateProfileInt("ColorFlat", "F3Gain", 24, INI_FILE_NAME); - iColorFlatParam[4] = ::GetPrivateProfileInt("ColorFlat", "F2Gain", 24, INI_FILE_NAME); - iColorFlatParam[5] = ::GetPrivateProfileInt("ColorFlat", "F1Gain", 24, INI_FILE_NAME); - iColorFlatParam[6] = ::GetPrivateProfileInt("ColorFlat", "F6Gain", 24, INI_FILE_NAME); - iColorFlatParam[7] = ::GetPrivateProfileInt("ColorFlat", "F5Gain", 24, INI_FILE_NAME); - iColorFlatParam[8] = ::GetPrivateProfileInt("ColorFlat", "F4Gain", 24, INI_FILE_NAME); - iColorFlatParam[9] = ::GetPrivateProfileInt("ColorFlat", "F3Offset", 117, INI_FILE_NAME); - iColorFlatParam[10] = ::GetPrivateProfileInt("ColorFlat", "F2Offset", 117, INI_FILE_NAME); - iColorFlatParam[11] = ::GetPrivateProfileInt("ColorFlat", "F1Offset", 117, INI_FILE_NAME); - iColorFlatParam[12] = ::GetPrivateProfileInt("ColorFlat", "F6Offset", 117, INI_FILE_NAME); - iColorFlatParam[13] = ::GetPrivateProfileInt("ColorFlat", "F5Offset", 117, INI_FILE_NAME); - iColorFlatParam[14] = ::GetPrivateProfileInt("ColorFlat", "F4Offset", 117, INI_FILE_NAME); - iColorFlatParam[15] = ::GetPrivateProfileInt("ColorFlat", "BBExposure", 233, INI_FILE_NAME); - iColorFlatParam[16] = ::GetPrivateProfileInt("ColorFlat", "BGExposure", 418, INI_FILE_NAME); - iColorFlatParam[17] = ::GetPrivateProfileInt("ColorFlat", "BRExposure", 220, INI_FILE_NAME); - iColorFlatParam[18] = ::GetPrivateProfileInt("ColorFlat", "B3Gain", 24, INI_FILE_NAME); - iColorFlatParam[19] = ::GetPrivateProfileInt("ColorFlat", "B2Gain", 24, INI_FILE_NAME); - iColorFlatParam[20] = ::GetPrivateProfileInt("ColorFlat", "B1Gain", 24, INI_FILE_NAME); - iColorFlatParam[21] = ::GetPrivateProfileInt("ColorFlat", "B6Gain", 24, INI_FILE_NAME); - iColorFlatParam[22] = ::GetPrivateProfileInt("ColorFlat", "B5Gain", 24, INI_FILE_NAME); - iColorFlatParam[23] = ::GetPrivateProfileInt("ColorFlat", "B4Gain", 24, INI_FILE_NAME); - iColorFlatParam[24] = ::GetPrivateProfileInt("ColorFlat", "B3Offset", 64, INI_FILE_NAME); - iColorFlatParam[25] = ::GetPrivateProfileInt("ColorFlat", "B2Offset", 64, INI_FILE_NAME); - iColorFlatParam[26] = ::GetPrivateProfileInt("ColorFlat", "B1Offset", 64, INI_FILE_NAME); - iColorFlatParam[27] = ::GetPrivateProfileInt("ColorFlat", "B6Offset", 64, INI_FILE_NAME); - iColorFlatParam[28] = ::GetPrivateProfileInt("ColorFlat", "B5Offset", 64, INI_FILE_NAME); - iColorFlatParam[29] = ::GetPrivateProfileInt("ColorFlat", "B4Offset", 64, INI_FILE_NAME); - - memcpy(m_sFlatCorrection.ColorFlat,iColorFlatParam,sizeof(iColorFlatParam)); - - iGrayCorrectionParam[0] = ::GetPrivateProfileInt("GrayCorrection", "FBExposure", 340, INI_FILE_NAME); - iGrayCorrectionParam[1] = ::GetPrivateProfileInt("GrayCorrection", "FGExposure", 620, INI_FILE_NAME); - iGrayCorrectionParam[2] = ::GetPrivateProfileInt("GrayCorrection", "FRExposure", 324, INI_FILE_NAME); - iGrayCorrectionParam[3] = ::GetPrivateProfileInt("GrayCorrection", "F3Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[4] = ::GetPrivateProfileInt("GrayCorrection", "F2Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[5] = ::GetPrivateProfileInt("GrayCorrection", "F1Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[6] = ::GetPrivateProfileInt("GrayCorrection", "F6Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[7] = ::GetPrivateProfileInt("GrayCorrection", "F5Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[8] = ::GetPrivateProfileInt("GrayCorrection", "F4Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[9] = ::GetPrivateProfileInt("GrayCorrection", "F3Offset", 117, INI_FILE_NAME); - iGrayCorrectionParam[10] = ::GetPrivateProfileInt("GrayCorrection", "F2Offset", 117, INI_FILE_NAME); - iGrayCorrectionParam[11] = ::GetPrivateProfileInt("GrayCorrection", "F1Offset", 117, INI_FILE_NAME); - iGrayCorrectionParam[12] = ::GetPrivateProfileInt("GrayCorrection", "F6Offset", 117, INI_FILE_NAME); - iGrayCorrectionParam[13] = ::GetPrivateProfileInt("GrayCorrection", "F5Offset", 117, INI_FILE_NAME); - iGrayCorrectionParam[14] = ::GetPrivateProfileInt("GrayCorrection", "F4Offset", 117, INI_FILE_NAME); - iGrayCorrectionParam[15] = ::GetPrivateProfileInt("GrayCorrection", "BBExposure", 233, INI_FILE_NAME); - iGrayCorrectionParam[16] = ::GetPrivateProfileInt("GrayCorrection", "BGExposure", 418, INI_FILE_NAME); - iGrayCorrectionParam[17] = ::GetPrivateProfileInt("GrayCorrection", "BRExposure", 220, INI_FILE_NAME); - iGrayCorrectionParam[18] = ::GetPrivateProfileInt("GrayCorrection", "B3Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[19] = ::GetPrivateProfileInt("GrayCorrection", "B2Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[20] = ::GetPrivateProfileInt("GrayCorrection", "B1Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[21] = ::GetPrivateProfileInt("GrayCorrection", "B6Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[22] = ::GetPrivateProfileInt("GrayCorrection", "B5Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[23] = ::GetPrivateProfileInt("GrayCorrection", "B4Gain", 24, INI_FILE_NAME); - iGrayCorrectionParam[24] = ::GetPrivateProfileInt("GrayCorrection", "B3Offset", 64, INI_FILE_NAME); - iGrayCorrectionParam[25] = ::GetPrivateProfileInt("GrayCorrection", "B2Offset", 64, INI_FILE_NAME); - iGrayCorrectionParam[26] = ::GetPrivateProfileInt("GrayCorrection", "B1Offset", 64, INI_FILE_NAME); - iGrayCorrectionParam[27] = ::GetPrivateProfileInt("GrayCorrection", "B6Offset", 64, INI_FILE_NAME); - iGrayCorrectionParam[28] = ::GetPrivateProfileInt("GrayCorrection", "B5Offset", 64, INI_FILE_NAME); - iGrayCorrectionParam[29] = ::GetPrivateProfileInt("GrayCorrection", "B4Offset", 64, INI_FILE_NAME); - - memcpy(m_sFlatCorrection.GrayCorrection,iGrayCorrectionParam,sizeof(iGrayCorrectionParam)); - - iGrayFlatParam[0] = ::GetPrivateProfileInt("GrayFlat", "FBExposure", 340, INI_FILE_NAME); - iGrayFlatParam[1] = ::GetPrivateProfileInt("GrayFlat", "FGExposure", 620, INI_FILE_NAME); - iGrayFlatParam[2] = ::GetPrivateProfileInt("GrayFlat", "FRExposure", 324, INI_FILE_NAME); - iGrayFlatParam[3] = ::GetPrivateProfileInt("GrayFlat", "F3Gain", 24, INI_FILE_NAME); - iGrayFlatParam[4] = ::GetPrivateProfileInt("GrayFlat", "F2Gain", 24, INI_FILE_NAME); - iGrayFlatParam[5] = ::GetPrivateProfileInt("GrayFlat", "F1Gain", 24, INI_FILE_NAME); - iGrayFlatParam[6] = ::GetPrivateProfileInt("GrayFlat", "F6Gain", 24, INI_FILE_NAME); - iGrayFlatParam[7] = ::GetPrivateProfileInt("GrayFlat", "F5Gain", 24, INI_FILE_NAME); - iGrayFlatParam[8] = ::GetPrivateProfileInt("GrayFlat", "F4Gain", 24, INI_FILE_NAME); - iGrayFlatParam[9] = ::GetPrivateProfileInt("GrayFlat", "F3Offset", 117, INI_FILE_NAME); - iGrayFlatParam[10] = ::GetPrivateProfileInt("GrayFlat", "F2Offset", 117, INI_FILE_NAME); - iGrayFlatParam[11] = ::GetPrivateProfileInt("GrayFlat", "F1Offset", 117, INI_FILE_NAME); - iGrayFlatParam[12] = ::GetPrivateProfileInt("GrayFlat", "F6Offset", 117, INI_FILE_NAME); - iGrayFlatParam[13] = ::GetPrivateProfileInt("GrayFlat", "F5Offset", 117, INI_FILE_NAME); - iGrayFlatParam[14] = ::GetPrivateProfileInt("GrayFlat", "F4Offset", 117, INI_FILE_NAME); - iGrayFlatParam[15] = ::GetPrivateProfileInt("GrayFlat", "BBExposure", 233, INI_FILE_NAME); - iGrayFlatParam[16] = ::GetPrivateProfileInt("GrayFlat", "BGExposure", 418, INI_FILE_NAME); - iGrayFlatParam[17] = ::GetPrivateProfileInt("GrayFlat", "BRExposure", 220, INI_FILE_NAME); - iGrayFlatParam[18] = ::GetPrivateProfileInt("GrayFlat", "B3Gain", 24, INI_FILE_NAME); - iGrayFlatParam[19] = ::GetPrivateProfileInt("GrayFlat", "B2Gain", 24, INI_FILE_NAME); - iGrayFlatParam[20] = ::GetPrivateProfileInt("GrayFlat", "B1Gain", 24, INI_FILE_NAME); - iGrayFlatParam[21] = ::GetPrivateProfileInt("GrayFlat", "B6Gain", 24, INI_FILE_NAME); - iGrayFlatParam[22] = ::GetPrivateProfileInt("GrayFlat", "B5Gain", 24, INI_FILE_NAME); - iGrayFlatParam[23] = ::GetPrivateProfileInt("GrayFlat", "B4Gain", 24, INI_FILE_NAME); - iGrayFlatParam[24] = ::GetPrivateProfileInt("GrayFlat", "B3Offset", 64, INI_FILE_NAME); - iGrayFlatParam[25] = ::GetPrivateProfileInt("GrayFlat", "B2Offset", 64, INI_FILE_NAME); - iGrayFlatParam[26] = ::GetPrivateProfileInt("GrayFlat", "B1Offset", 64, INI_FILE_NAME); - iGrayFlatParam[27] = ::GetPrivateProfileInt("GrayFlat", "B6Offset", 64, INI_FILE_NAME); - iGrayFlatParam[28] = ::GetPrivateProfileInt("GrayFlat", "B5Offset", 64, INI_FILE_NAME); - iGrayFlatParam[29] = ::GetPrivateProfileInt("GrayFlat", "B4Offset", 64, INI_FILE_NAME); - - memcpy(m_sFlatCorrection.GrayFlat,iGrayFlatParam,sizeof(iGrayFlatParam)); -} - -void CA4::SaveNewParam(int iIndex) -{ - UINT iTempParam[30] = {0}; - +{ UpdateData(TRUE); - iTempParam[0] = m_tbxFRExposure; - iTempParam[1] = m_tbxFGExposure; - iTempParam[2] = m_tbxFBExposure; - iTempParam[3] = m_tbxF1Gain; - iTempParam[4] = m_tbxF2Gain; - iTempParam[5] = m_tbxF3Gain; - iTempParam[6] = m_tbxF4Gain; - iTempParam[7] = m_tbxF5Gain; - iTempParam[8] = m_tbxF6Gain; - iTempParam[9] = m_tbxF1Offset; - iTempParam[10] = m_tbxF2Offset; - iTempParam[11] = m_tbxF3Offset; - iTempParam[12] = m_tbxF4Offset; - iTempParam[13] = m_tbxF5Offset; - iTempParam[14] = m_tbxF6Offset; - iTempParam[15] = m_tbxBRExposure; - iTempParam[16] = m_tbxBGExposure; - iTempParam[17] = m_tbxBBExposure; - iTempParam[18] = m_tbxB1Gain; - iTempParam[19] = m_tbxB2Gain; - iTempParam[20] = m_tbxB3Gain; - iTempParam[21] = m_tbxB4Gain; - iTempParam[22] = m_tbxB5Gain; - iTempParam[23] = m_tbxB6Gain; - iTempParam[24] = m_tbxB1Offset; - iTempParam[25] = m_tbxB2Offset; - iTempParam[26] = m_tbxB3Offset; - iTempParam[27] = m_tbxB4Offset; - iTempParam[28] = m_tbxB5Offset; - iTempParam[29] = m_tbxB6Offset; + jsonConfig.ReadParam(jsonparams); + memcpy(params.Exposures, jsonparams.correctColorExposure, sizeof(jsonparams.correctColorExposure)); + memcpy(params.Gain, jsonparams.correctColorGain, sizeof(jsonparams.correctColorGain)); + memcpy(params.Offset, jsonparams.correctColorOffset, sizeof(jsonparams.correctColorOffset)); UpdateData(FALSE); - - switch (iIndex) - { - case 0: - memcpy(m_sFlatCorrection.ColorCorrection, iTempParam, sizeof(iTempParam)); - WriteParamFile(); - break; - case 1: - memcpy(m_sFlatCorrection.ColorFlat, iTempParam, sizeof(iTempParam)); - WriteParamFile(); - break; - case 2: - memcpy(m_sFlatCorrection.GrayCorrection, iTempParam, sizeof(iTempParam)); - WriteParamFile(); - break; - case 3: - memcpy(m_sFlatCorrection.GrayFlat, iTempParam, sizeof(iTempParam)); - WriteParamFile(); - break; - default: - break; - } - } -void CA4::WriteParamFile() +/// +/// ɨ +/// +void CA4::OnBnClickedBtnReboot() { - CString csColorCorrection[30]; - CString csColorFlat[30]; - CString csGrayCorrection[30]; - CString csGrayFlat[30]; + auto parent = (CHuaGoCorrectDlg*)GetParent(); + parent->m_drv->Reboot(); +} - for(int i = 0;i < 30; i++) +/// +/// vidpid +/// +void CA4::OnBnClickedBtnSetvidpid() +{ +} + +/// +/// ȡvidpid +/// +void CA4::OnBnClickedBtnGetvidpid() +{ + // TODO: ڴӿؼ֪ͨ +} + +/// +/// ȡк +/// +void CA4::OnBnClickedBtngetSerial() +{ + auto parent = (CHuaGoCorrectDlg*)GetParent(); + std::string serial= parent->m_drv->GetSerialNum(); + CString c_serial(serial.c_str()); + SetDlgItemText(IDC_tbxSerial, c_serial); +} + +/// +/// к +/// +void CA4::OnBnClickedBtnGenserial() +{ + // TODO: ڴӿؼ֪ͨ +} + +/// +/// к +/// +void CA4::OnBnClickedBtnSetSerial() +{ + auto parent = (CHuaGoCorrectDlg*)GetParent(); + CString cserial; + GetDlgItemText(IDC_tbxSerial, cserial); + if (!cserial.IsEmpty()) { - csColorCorrection[i].Format(_T("%d"),m_sFlatCorrection.ColorCorrection[i]); - csColorFlat[i].Format(_T("%d"),m_sFlatCorrection.ColorFlat[i]); - csGrayCorrection[i].Format(_T("%d"),m_sFlatCorrection.GrayCorrection[i]); - csGrayFlat[i].Format(_T("%d"),m_sFlatCorrection.GrayFlat[i]); + std::string ser(cserial.GetBuffer()); + parent->m_drv->SetSerialNum(ser); } - - WritePrivateProfileString("ColorCorrection", "FBExposure", csColorCorrection[0], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "FGExposure", csColorCorrection[1], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "FRExposure", csColorCorrection[2], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F3Gain", csColorCorrection[3], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F2Gain", csColorCorrection[4], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F1Gain", csColorCorrection[5], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F6Gain", csColorCorrection[6], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F5Gain", csColorCorrection[7], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F4Gain", csColorCorrection[8], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F3Offset", csColorCorrection[9], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F2Offset", csColorCorrection[10], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F1Offset", csColorCorrection[11], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F6Offset", csColorCorrection[12], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F5Offset", csColorCorrection[13], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "F4Offset", csColorCorrection[14], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "BBExposure", csColorCorrection[15], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "BGExposure", csColorCorrection[16], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "BRExposure", csColorCorrection[17], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B3Gain", csColorCorrection[18], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B2Gain", csColorCorrection[19], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B1Gain", csColorCorrection[20], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B6Gain", csColorCorrection[21], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B5Gain", csColorCorrection[22], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B4Gain", csColorCorrection[23], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B3Offset", csColorCorrection[24], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B2Offset", csColorCorrection[25], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B1Offset", csColorCorrection[26], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B6Offset", csColorCorrection[27], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B5Offset", csColorCorrection[28], INI_FILE_NAME); - WritePrivateProfileString("ColorCorrection", "B4Offset", csColorCorrection[29], INI_FILE_NAME); - - WritePrivateProfileString("ColorFlat", "FBExposure", csColorFlat[0], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "FGExposure", csColorFlat[1], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "FRExposure", csColorFlat[2], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F3Gain", csColorFlat[3], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F2Gain", csColorFlat[4], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F1Gain", csColorFlat[5], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F6Gain", csColorFlat[6], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F5Gain", csColorFlat[7], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F4Gain", csColorFlat[8], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F3Offset", csColorFlat[9], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F2Offset", csColorFlat[10], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F1Offset", csColorFlat[11], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F6Offset", csColorFlat[12], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F5Offset", csColorFlat[13], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "F4Offset", csColorFlat[14], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "BBExposure", csColorFlat[15], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "BGExposure", csColorFlat[16], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "BRExposure", csColorFlat[17], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B3Gain", csColorFlat[18], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B2Gain", csColorFlat[19], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B1Gain", csColorFlat[20], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B6Gain", csColorFlat[21], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B5Gain", csColorFlat[22], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B4Gain", csColorFlat[23], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B3Offset", csColorFlat[24], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B2Offset", csColorFlat[25], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B1Offset", csColorFlat[26], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B6Offset", csColorFlat[27], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B5Offset", csColorFlat[28], INI_FILE_NAME); - WritePrivateProfileString("ColorFlat", "B4Offset", csColorFlat[29], INI_FILE_NAME); - - WritePrivateProfileString("GrayCorrection", "FBExposure", csGrayCorrection[0], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "FGExposure", csGrayCorrection[1], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "FRExposure", csGrayCorrection[2], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F3Gain", csGrayCorrection[3], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F2Gain", csGrayCorrection[4], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F1Gain", csGrayCorrection[5], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F6Gain", csGrayCorrection[6], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F5Gain", csGrayCorrection[7], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F4Gain", csGrayCorrection[8], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F3Offset", csGrayCorrection[9], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F2Offset", csGrayCorrection[10], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F1Offset", csGrayCorrection[11], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F6Offset", csGrayCorrection[12], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F5Offset", csGrayCorrection[13], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "F4Offset", csGrayCorrection[14], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "BBExposure", csGrayCorrection[15], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "BGExposure", csGrayCorrection[16], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "BRExposure", csGrayCorrection[17], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B3Gain", csGrayCorrection[18], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B2Gain", csGrayCorrection[19], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B1Gain", csGrayCorrection[20], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B6Gain", csGrayCorrection[21], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B5Gain", csGrayCorrection[22], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B4Gain", csGrayCorrection[23], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B3Offset", csGrayCorrection[24], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B2Offset", csGrayCorrection[25], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B1Offset", csGrayCorrection[26], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B6Offset", csGrayCorrection[27], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B5Offset", csGrayCorrection[28], INI_FILE_NAME); - WritePrivateProfileString("GrayCorrection", "B4Offset", csGrayCorrection[29], INI_FILE_NAME); - - WritePrivateProfileString("GrayFlat", "FBExposure", csGrayFlat[0], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "FGExposure", csGrayFlat[1], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "FRExposure", csGrayFlat[2], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F3Gain", csGrayFlat[3], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F2Gain", csGrayFlat[4], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F1Gain", csGrayFlat[5], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F6Gain", csGrayFlat[6], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F5Gain", csGrayFlat[7], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F4Gain", csGrayFlat[8], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F3Offset", csGrayFlat[9], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F2Offset", csGrayFlat[10], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F1Offset", csGrayFlat[11], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F6Offset", csGrayFlat[12], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F5Offset", csGrayFlat[13], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "F4Offset", csGrayFlat[14], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "BBExposure", csGrayFlat[15], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "BGExposure", csGrayFlat[16], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "BRExposure", csGrayFlat[17], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B3Gain", csGrayFlat[18], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B2Gain", csGrayFlat[19], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B1Gain", csGrayFlat[20], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B6Gain", csGrayFlat[21], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B5Gain", csGrayFlat[22], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B4Gain", csGrayFlat[23], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B3Offset", csGrayFlat[24], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B2Offset", csGrayFlat[25], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B1Offset", csGrayFlat[26], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B6Offset", csGrayFlat[27], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B5Offset", csGrayFlat[28], INI_FILE_NAME); - WritePrivateProfileString("GrayFlat", "B4Offset", csGrayFlat[29], INI_FILE_NAME); } -void CA4::OnDeltaposSpinAgain(NMHDR *pNMHDR, LRESULT *pResult) + +void CA4::OnBnClickedBtnGethor() +{ + auto parent = (CHuaGoCorrectDlg*)GetParent(); + int ratio = 0; + parent->m_drv->GetRatio(0, ratio); + float f_ratio = *(float*)∶ + CString str; + str.Format("%.4f", f_ratio); + SetDlgItemText(IDC_tbxHOR, str); +} + + +void CA4::OnBnClickedBtnGetver() +{ + auto parent = (CHuaGoCorrectDlg*)GetParent(); + int ratio = 0; + parent->m_drv->GetRatio(1, ratio); + float f_ratio = *(float*)∶ + CString str; + str.Format("%.4f", f_ratio); + SetDlgItemText(IDC_tbxVER, str); +} + + +void CA4::OnBnClickedBtnSethor() +{ + auto parent = (CHuaGoCorrectDlg*)GetParent(); + CString str; + GetDlgItemText(IDC_tbxHOR, str); + float f_value = atof(str); + int value = *(int*)&f_value; + parent->m_drv->SetRatio(0, value); +} + + +void CA4::OnBnClickedBtnSetver() +{ + auto parent = (CHuaGoCorrectDlg*)GetParent(); + CString str; + GetDlgItemText(IDC_tbxVER, str); + float f_value = atof(str); + int value = *(int*)&f_value; + parent->m_drv->SetRatio(1, value); +} + + +void CA4::OnBnClickedBtngetVersion() +{ + auto parent = (CHuaGoCorrectDlg*)GetParent(); + std::string ver = parent->m_drv->GetFWVersion(); + if (ver.size() > 0) + { + CString str(ver.c_str()); + SetDlgItemText(IDC_tbxVersion, str); + } +} + +#define MAX_LENGTH 14 +void CA4::OnEnChangetbxserial() +{ + // TODO: ÿؼ RICHEDIT ؼ + // ʹ֪ͨд CDialog::OnInitDialog() + // CRichEditCtrl().SetEventMask() + // ͬʱ ENM_CHANGE ־㵽С + auto tbxSerial = (CEdit*)GetDlgItem(IDC_tbxSerial); + CString str; + GetDlgItemText(IDC_tbxSerial, str); + int length = str.GetLength(); + if (length > 14) + { + if (tbxSerial) + { + SetDlgItemText(IDC_tbxSerial, str.Left(MAX_LENGTH)); + tbxSerial->SetSel(str.GetLength(), str.GetLength()); + } + } +} + + +void CA4::OnBnClickedBtnGetexpos() { - LPNMUPDOWN pNMUpDown = reinterpret_cast(pNMHDR); // TODO: ڴӿؼ֪ͨ - UpdateData(true); + auto parent = (CHuaGoCorrectDlg*)GetParent(); + int esposeA, exposeB; + parent->m_drv->GetExpose(esposeA,exposeB); + CString expA, expB; + expA.Format("%d", esposeA); + expB.Format("%d", exposeB); + SetDlgItemText(IDC_tbxUVAExpos, expA); + SetDlgItemText(IDC_tbxUVBExpos, expB); - if(pNMUpDown->iDelta == -1) // ֵΪ-1 , ˵Spinµļͷ - { - AUpGain(); - } - else if(pNMUpDown->iDelta == 1) // ֵΪ1, ˵Spinϵļͷ - { - ADownGain(); - } - UpdateData(false); - - *pResult = 0; } -void CA4::OnDeltaposSpinAoffset(NMHDR *pNMHDR, LRESULT *pResult) +void CA4::OnBnClickedBtnSetexpos() { - LPNMUPDOWN pNMUpDown = reinterpret_cast(pNMHDR); // TODO: ڴӿؼ֪ͨ - UpdateData(true); - - if(pNMUpDown->iDelta == -1) // ֵΪ-1 , ˵Spinµļͷ - { - AUpOffset(); - } - else if(pNMUpDown->iDelta == 1) // ֵΪ1, ˵Spinϵļͷ - { - ADownOffset(); - } - UpdateData(false); - - *pResult = 0; + auto parent = (CHuaGoCorrectDlg*)GetParent(); + int esposeA, exposeB; + CString expA, expB; + GetDlgItemText(IDC_tbxUVAExpos, expA); + GetDlgItemText(IDC_tbxUVBExpos, expB); + esposeA= atoi(expA); + exposeB = atoi(expB); + parent->m_drv->SetExpose(esposeA, exposeB); } -void CA4::OnDeltaposSpinBgain(NMHDR *pNMHDR, LRESULT *pResult) +void CA4::OnBnClickedBtnaup() { - LPNMUPDOWN pNMUpDown = reinterpret_cast(pNMHDR); // TODO: ڴӿؼ֪ͨ - UpdateData(true); - - if(pNMUpDown->iDelta == -1) // ֵΪ-1 , ˵Spinµļͷ - { - BUpGain(); - } - else if(pNMUpDown->iDelta == 1) // ֵΪ1, ˵Spinϵļͷ - { - BDownGain(); - } - UpdateData(false); - - *pResult = 0; + UpdateGains(IDC_BTNAUP, true); } -void CA4::OnDeltaposSpinBoffset(NMHDR *pNMHDR, LRESULT *pResult) +void CA4::OnBnClickedBtnadown() { - LPNMUPDOWN pNMUpDown = reinterpret_cast(pNMHDR); // TODO: ڴӿؼ֪ͨ - UpdateData(true); - - if(pNMUpDown->iDelta == -1) // ֵΪ-1 , ˵Spinµļͷ - { - BUpOffset(); - } - else if(pNMUpDown->iDelta == 1) // ֵΪ1, ˵Spinϵļͷ - { - BDownOffset(); - } - UpdateData(false); - - *pResult = 0; + UpdateGains(IDC_BTNADOWN, false); } -void CA4::ADownGain() + +void CA4::OnBnClickedBtnbup() { - UpdateData(true); - m_tbxF1Gain -= m_tbxAGain; - m_tbxF2Gain -= m_tbxAGain; - m_tbxF3Gain -= m_tbxAGain; - m_tbxF4Gain -= m_tbxAGain; - m_tbxF5Gain -= m_tbxAGain; - m_tbxF6Gain -= m_tbxAGain; - UpdateData(false); + // TODO: ڴӿؼ֪ͨ + UpdateGains(IDC_BTNBUP, true); } -void CA4::AUpGain() + +void CA4::OnBnClickedBtnbdown() { - UpdateData(true); - m_tbxF1Gain += m_tbxAGain; - m_tbxF2Gain += m_tbxAGain; - m_tbxF3Gain += m_tbxAGain; - m_tbxF4Gain += m_tbxAGain; - m_tbxF5Gain += m_tbxAGain; - m_tbxF6Gain += m_tbxAGain; - UpdateData(false); + // TODO: ڴӿؼ֪ͨ + UpdateGains(IDC_BTNBDOWN, false); } -void CA4::BDownGain() -{ - UpdateData(true); - m_tbxB1Gain -= m_tbxBGain; - m_tbxB2Gain -= m_tbxBGain; - m_tbxB3Gain -= m_tbxBGain; - m_tbxB4Gain -= m_tbxBGain; - m_tbxB5Gain -= m_tbxBGain; - m_tbxB6Gain -= m_tbxBGain; - UpdateData(false); -} -void CA4::BUpGain() +void CA4::UpdateGains(int id, bool increase) { - UpdateData(true); - m_tbxB1Gain += m_tbxBGain; - m_tbxB2Gain += m_tbxBGain; - m_tbxB3Gain += m_tbxBGain; - m_tbxB4Gain += m_tbxBGain; - m_tbxB5Gain += m_tbxBGain; - m_tbxB6Gain += m_tbxBGain; - UpdateData(false); -} - -void CA4::ADownOffset() -{ - UpdateData(true); - m_tbxF1Offset -= m_tbxAOffset; - m_tbxF2Offset -= m_tbxAOffset; - m_tbxF3Offset -= m_tbxAOffset; - m_tbxF4Offset -= m_tbxAOffset; - m_tbxF5Offset -= m_tbxAOffset; - m_tbxF6Offset -= m_tbxAOffset; - UpdateData(false); -} - -void CA4::AUpOffset() -{ - UpdateData(true); - m_tbxF1Offset += m_tbxAOffset; - m_tbxF2Offset += m_tbxAOffset; - m_tbxF3Offset += m_tbxAOffset; - m_tbxF4Offset += m_tbxAOffset; - m_tbxF5Offset += m_tbxAOffset; - m_tbxF6Offset += m_tbxAOffset; - UpdateData(false); -} - -void CA4::BDownOffset() -{ - UpdateData(true); - m_tbxB1Offset -= m_tbxBOffset; - m_tbxB2Offset -= m_tbxBOffset; - m_tbxB3Offset -= m_tbxBOffset; - m_tbxB4Offset -= m_tbxBOffset; - m_tbxB5Offset -= m_tbxBOffset; - m_tbxB6Offset -= m_tbxBOffset; - UpdateData(false); -} - -void CA4::BUpOffset() -{ - UpdateData(true); - m_tbxB1Offset += m_tbxBOffset; - m_tbxB2Offset += m_tbxBOffset; - m_tbxB3Offset += m_tbxBOffset; - m_tbxB4Offset += m_tbxBOffset; - m_tbxB5Offset += m_tbxBOffset; - m_tbxB6Offset += m_tbxBOffset; - UpdateData(false); + UpdateData(TRUE); + if ((id == IDC_BTNAUP || id == IDC_BTNBUP) && increase) + { + int startindex = id == IDC_BTNAUP ? 0 : 6; + for (size_t i = startindex; i < (6+ startindex); i++) + { + params.Gain[i] = params.Gain[i]++; + } + } + else if((id==IDC_BTNADOWN||id==IDC_BTNBDOWN)&&!increase) + { + int startindex = id == IDC_BTNADOWN ? 0 : 6; + for (size_t i = startindex; i < (6 + startindex); i++) + { + params.Gain[i] = params.Gain[i]--; + } + } + UpdateData(FALSE); } \ No newline at end of file diff --git a/HuaGoCorrect/A4.h b/HuaGoCorrect/A4.h index 33b7c68..e2965d2 100644 --- a/HuaGoCorrect/A4.h +++ b/HuaGoCorrect/A4.h @@ -3,6 +3,10 @@ #include "Config.h" #include "DefHSStructure.h" #include "afxwin.h" +#include "PublicFunc.h" +#include +#include "JsonConfig.h" +#include // CA4 Ի #define INI_FILE_NAME "./HuaGoScan.ini" @@ -13,19 +17,8 @@ class CA4 : public CDialog public: CA4(CWnd* pParent = NULL); // ׼캯 virtual ~CA4(); - - CConfig m_Cfg; - - void default0param(); - void default1param(); - void default2param(); - void default3param(); - - void updateA4Config(int *pValues); + void updateA4Config(CaptureParams& pValues); void LoadCfg(); - void SaveNewParam(int iIndex); - - void WriteParamFile(); // Ի enum { IDD = IDD_A4_DIALOG }; @@ -36,56 +29,49 @@ protected: DECLARE_MESSAGE_MAP() public: virtual BOOL OnInitDialog(); + void SetCallBack(std::function t_call); + void EnableItem(bool enable); + void SendCorrectParam(); + CorrectParam params; + CaptureParams jsonparams; + std::vector Exposures = { IDC_tbxFRExposure ,IDC_tbxFGExposure ,IDC_tbxFBExposure ,IDC_tbxBRExposure ,IDC_tbxBGExposure ,IDC_tbxBBExposure }; + std::vector Gains = { IDC_tbxF1Gain ,IDC_tbxF2Gain ,IDC_tbxF3Gain ,IDC_tbxF4Gain ,IDC_tbxF5Gain ,IDC_tbxF6Gain ,IDC_tbxB1Gain ,IDC_tbxB2Gain ,IDC_tbxB3Gain ,IDC_tbxB4Gain ,IDC_tbxB5Gain ,IDC_tbxB6Gain }; + //std::vector Gains = { IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain ,IDC_tbxF3Gain }; - FlatCorrection m_sFlatCorrection; + std::vector Offsets = { IDC_tbxF1Offset ,IDC_tbxF2Offset ,IDC_tbxF3Offset ,IDC_tbxF4Offset ,IDC_tbxF5Offset ,IDC_tbxF6Offset ,IDC_tbxB1Offset ,IDC_tbxB2Offset ,IDC_tbxB3Offset ,IDC_tbxB4Offset ,IDC_tbxB5Offset ,IDC_tbxB6Offset }; int m_iLastIndex; int m_iSelIndex; - UINT m_tbxFRExposure; - UINT m_tbxFGExposure; - UINT m_tbxFBExposure; - UINT m_tbxF1Gain; - UINT m_tbxF2Gain; - UINT m_tbxF3Gain; - UINT m_tbxF4Gain; - UINT m_tbxF5Gain; - UINT m_tbxF6Gain; - UINT m_tbxF1Offset; - UINT m_tbxF2Offset; - UINT m_tbxF3Offset; - UINT m_tbxF4Offset; - UINT m_tbxF5Offset; - UINT m_tbxF6Offset; - UINT m_tbxBRExposure; - UINT m_tbxBGExposure; - UINT m_tbxBBExposure; - UINT m_tbxB1Gain; - UINT m_tbxB2Gain; - UINT m_tbxB3Gain; - UINT m_tbxB4Gain; - UINT m_tbxB5Gain; - UINT m_tbxB6Gain; - UINT m_tbxB1Offset; - UINT m_tbxB2Offset; - UINT m_tbxB3Offset; - UINT m_tbxB4Offset; - UINT m_tbxB5Offset; - UINT m_tbxB6Offset; - afx_msg void OnCbnSelChangeA4FlatModel(); CComboBox m_A4FlatModel; - UINT m_tbxAGain; - UINT m_tbxBGain; - UINT m_tbxAOffset; - UINT m_tbxBOffset; - afx_msg void OnDeltaposSpinAgain(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnDeltaposSpinAoffset(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnDeltaposSpinBgain(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnDeltaposSpinBoffset(NMHDR *pNMHDR, LRESULT *pResult); - void ADownGain(); - void AUpGain(); - void BDownGain(); - void BUpGain(); - void ADownOffset(); - void AUpOffset(); - void BDownOffset(); - void BUpOffset(); + CButton m_GetSerial; + CButton m_SetSerial; + CButton m_AutoGenSerial; + CButton m_GetVid; + CButton m_SetVid; + CButton m_Reboot; + JsonConfig jsonConfig; +private: + std::function m_func; +private: + afx_msg void OnCbnSelChangeA4FlatModel(); + afx_msg void OnBnClickedBtnReboot(); + afx_msg void OnBnClickedBtnSetvidpid(); + afx_msg void OnBnClickedBtnGetvidpid(); + afx_msg void OnBnClickedBtngetSerial(); + afx_msg void OnBnClickedBtnGenserial(); + afx_msg void OnBnClickedBtnSetSerial(); +public: + afx_msg void OnBnClickedBtnGethor(); + afx_msg void OnBnClickedBtnGetver(); + afx_msg void OnBnClickedBtnSethor(); + afx_msg void OnBnClickedBtnSetver(); + afx_msg void OnBnClickedBtngetVersion(); + afx_msg void OnBnClickedBtnSetVersion(); + afx_msg void OnEnChangetbxserial(); + afx_msg void OnBnClickedBtnGetexpos(); + afx_msg void OnBnClickedBtnSetexpos(); + afx_msg void OnBnClickedBtnaup(); + afx_msg void OnBnClickedBtnadown(); + afx_msg void OnBnClickedBtnbup(); + afx_msg void OnBnClickedBtnbdown(); + void UpdateGains(int id, bool get); }; diff --git a/HuaGoCorrect/BlockingQueue.h b/HuaGoCorrect/BlockingQueue.h index 26ea5b7..ff96f9d 100644 --- a/HuaGoCorrect/BlockingQueue.h +++ b/HuaGoCorrect/BlockingQueue.h @@ -2,38 +2,31 @@ #include #include #include - +#include +#include template class BlockingQueue { private: - BlockingQueue(const BlockingQueue& rhs); - BlockingQueue& operator =(const BlockingQueue& rhs); + BlockingQueue(const BlockingQueue &rhs); + BlockingQueue &operator=(const BlockingQueue &rhs); mutable std::mutex _mutex; std::condition_variable _condvar; std::deque _queue; - volatile bool isShutDown = false; + bool isShutDown = false; T tRet; public: BlockingQueue() - : _mutex() - , _condvar() - , _queue() + : _mutex(), _condvar(), _queue() { } ~BlockingQueue() { ShutDown(); - } - - void Clear() - { - std::lock_guard lock(_mutex); - _condvar.notify_all(); - _queue.clear(); + std::cout << "blocking queue release" << std::endl; } void ShutDown() @@ -51,8 +44,11 @@ public: void Put(const T task) { std::lock_guard lock(_mutex); - if (!isShutDown) { - _queue.push_back(task); + if (!isShutDown) + { + { + _queue.push_back(task); + } _condvar.notify_all(); } } @@ -64,7 +60,9 @@ public: _condvar.wait(lock); if (isShutDown || _queue.empty()) + { return tRet; + } T front(_queue.front()); _queue.pop_front(); @@ -79,15 +77,28 @@ public: _condvar.wait(lock); if (isShutDown || _queue.empty()) + { return tRet; + } T front(_queue.front()); return front; } + size_t Size() const { std::lock_guard lock(_mutex); return _queue.size(); } - + + void Clear() + { + std::unique_lock lock(_mutex); + if (_queue.size() <= 0) + return; + if (_queue.size()>0) + { + _queue.clear(); + } + } }; \ No newline at end of file diff --git a/HuaGoCorrect/CVISON.cpp b/HuaGoCorrect/CVISON.cpp index 3a04927..1e8fa17 100644 --- a/HuaGoCorrect/CVISON.cpp +++ b/HuaGoCorrect/CVISON.cpp @@ -2,20 +2,53 @@ #include "CVISON.h" #include "HuaGoCorrect.h" #include "afxdialogex.h" - +#include "HuaGoCorrectDlg.h" // CA3 Ի - +using namespace cv; IMPLEMENT_DYNAMIC(CVISON, CDialog) CVISON::CVISON(CWnd* pParent /*=NULL*/) : CDialog(CVISON::IDD, pParent) { - + m_run = true; + m_auireable = false; + m_updateimgshow = std::thread(&CVISON::showfun, this); } CVISON::~CVISON() { + if (m_updateimgshow.joinable()) + { + m_auireable = false; + m_run = false; + m_updateimgshow.join(); + } +} + +void CVISON::DrawPicture(CString path) +{ + CImage img; + img.Load(path); + CRect rectf; + int cx = img.GetWidth(); + int cy = img.GetHeight(); + if (cx == 0 || cy == 0) + return; + CWnd* pWnd = GetDlgItem(IDC_PIC); + pWnd->GetClientRect(&rectf); + CDC* pDC = pWnd->GetDC(); + SetStretchBltMode(pDC->m_hDC, STRETCH_HALFTONE); + CPoint pos = rectf.TopLeft(); + rectf = CRect(pos, CSize(630,535)); + img.Draw(pDC->m_hDC, rectf); + ReleaseDC(pDC); + img.Destroy(); +} + +void CVISON::SetCallBack(std::function onstop) +{ + m_onStop = onstop; } void CVISON::DoDataExchange(CDataExchange* pDX) @@ -25,6 +58,8 @@ void CVISON::DoDataExchange(CDataExchange* pDX) BEGIN_MESSAGE_MAP(CVISON, CDialog) + ON_BN_CLICKED(IDC_BTN_PREPAGE, &CVISON::OnBnClickedBtnPrepage) + ON_BN_CLICKED(IDC_BTN_NEXT, &CVISON::OnBnClickedBtnNext) END_MESSAGE_MAP() @@ -41,3 +76,122 @@ BOOL CVISON::OnInitDialog() // 쳣: OCX ҳӦ FALSE } +void CVISON::MatToCImage(cv::Mat& mat, CImage& cimage) +{ + if (0 == mat.total()) + { + return; + } + int nChannels = mat.channels(); + if ((1 != nChannels) && (3 != nChannels)) + { + return; + } + int nWidth = mat.cols; + int nHeight = mat.rows; + //ؽcimage + cimage.Destroy(); + cimage.Create(nWidth, nHeight, 8 * nChannels); + // + uchar* pucRow;//ָָ + uchar* pucImage = (uchar*)cimage.GetBits();//ָָ + int nStep = cimage.GetPitch();//ÿеֽ,עֵи + if (1 == nChannels)//ڵͨͼҪʼɫ + { + RGBQUAD* rgbquadColorTable; + int nMaxColors = 256; + rgbquadColorTable = new RGBQUAD[nMaxColors]; + cimage.GetColorTable(0, nMaxColors, rgbquadColorTable); + for (int nColor = 0; nColor < nMaxColors; nColor++) + { + rgbquadColorTable[nColor].rgbBlue = (uchar)nColor; + rgbquadColorTable[nColor].rgbGreen = (uchar)nColor; + rgbquadColorTable[nColor].rgbRed = (uchar)nColor; + } + cimage.SetColorTable(0, nMaxColors, rgbquadColorTable); + delete[]rgbquadColorTable; + } + for (int nRow = 0; nRow < nHeight; nRow++) + { + pucRow = (mat.ptr(nRow)); + for (int nCol = 0; nCol < nWidth; nCol++) + { + if (1 == nChannels) + { + *(pucImage + nRow * nStep + nCol) = pucRow[nCol]; + } + else if (3 == nChannels) + { + for (int nCha = 0; nCha < 3; nCha++) + { + *(pucImage + nRow * nStep + nCol * 3 + nCha) = pucRow[nCol * 3 + nCha]; + } + } + } + } +} + + +void CVISON::OnBnClickedBtnPrepage() +{ + // TODO: ڴӿؼ֪ͨ + imageindex--; + if (imageindex < 0) + imageindex = 0; + + if (m_path.size() > 0) + { + DrawPicture(m_path[imageindex]); + } +} + + +void CVISON::OnBnClickedBtnNext() +{ + // TODO: ڴӿؼ֪ͨ + imageindex++; + if (imageindex >= m_path.size()) + imageindex = m_path.size() - 1; + if (m_path.size() > 0) + { + DrawPicture(m_path[imageindex]); + } +} + +void CVISON::SetEnableShow(bool show) +{ + m_auireable = show; + aquiredimgindx = 0; + parent = (CHuaGoCorrectDlg*)GetParent(); +} + +void CVISON::showfun() +{ + while (m_run) + { + if (m_auireable) + { + if (parent) + { + std::string path; + auto ret = ((CHuaGoCorrectDlg*)parent)->m_drv->aquire_image(path, 0); + if (ret != -1) + { + imageindex++; + aquiredimgindx++; + CString cPath(path.c_str()); + m_path.push_back(cPath); + m_onStop(false, aquiredimgindx); + DrawPicture(cPath); + } + else + { + m_auireable = false; + m_onStop(true,0); + } + } + } + else + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } +} diff --git a/HuaGoCorrect/CVISON.h b/HuaGoCorrect/CVISON.h index 4bd559c..742a989 100644 --- a/HuaGoCorrect/CVISON.h +++ b/HuaGoCorrect/CVISON.h @@ -1,5 +1,9 @@ #pragma once #include "resource.h" +#include +#include +#include +#include //cvisionԻ @@ -12,10 +16,27 @@ public: // Ի enum { IDD = IDD_VISION_DIALOG }; - + void DrawPicture(CString path); + void SetCallBack(std::function onstop); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ DECLARE_MESSAGE_MAP() -virtual BOOL OnInitDialog(); + virtual BOOL OnInitDialog(); + void MatToCImage(cv::Mat& mat, CImage& cimage); +public: + afx_msg void OnBnClickedBtnPrepage(); + afx_msg void OnBnClickedBtnNext(); + void SetEnableShow(bool show); +private: + void showfun(); +private: + std::vector m_path; + volatile int imageindex = 0; + volatile int aquiredimgindx = 0; + volatile bool m_auireable; + volatile bool m_run; + std::thread m_updateimgshow; + void* parent; + std::function m_onStop; }; diff --git a/HuaGoCorrect/HuaGoCorrect.aps b/HuaGoCorrect/HuaGoCorrect.aps new file mode 100644 index 0000000..a56ad61 Binary files /dev/null and b/HuaGoCorrect/HuaGoCorrect.aps differ diff --git a/HuaGoCorrect/HuaGoCorrect.rc b/HuaGoCorrect/HuaGoCorrect.rc index 7693248..8235658 100644 Binary files a/HuaGoCorrect/HuaGoCorrect.rc and b/HuaGoCorrect/HuaGoCorrect.rc differ diff --git a/HuaGoCorrect/HuaGoCorrect.sln b/HuaGoCorrect/HuaGoCorrect.sln new file mode 100644 index 0000000..a367b1d --- /dev/null +++ b/HuaGoCorrect/HuaGoCorrect.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30621.155 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HuaGoCorrect_V3.0", "HuaGoCorrect.vcxproj", "{988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Debug|x64.ActiveCfg = Debug|x64 + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Debug|x64.Build.0 = Debug|x64 + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Debug|x86.ActiveCfg = Debug|Win32 + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Debug|x86.Build.0 = Debug|Win32 + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Release|x64.ActiveCfg = Release|x64 + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Release|x64.Build.0 = Release|x64 + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Release|x86.ActiveCfg = Release|Win32 + {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B764F5EE-C301-4B09-84ED-7E482F7F1D0F} + EndGlobalSection +EndGlobal diff --git a/HuaGoCorrect/HuaGoCorrect.vcxproj b/HuaGoCorrect/HuaGoCorrect.vcxproj index 6b1612d..110900f 100644 --- a/HuaGoCorrect/HuaGoCorrect.vcxproj +++ b/HuaGoCorrect/HuaGoCorrect.vcxproj @@ -22,7 +22,7 @@ {988CC4D3-44EC-4A9D-AC05-B2AF0EA48E75} HuaGoCorrect MFCProj - 10.0.17763.0 + 10.0.19041.0 HuaGoCorrect_V3.0 @@ -31,7 +31,7 @@ true MultiByte Dynamic - v141 + v142 @@ -41,7 +41,7 @@ MultiByte Dynamic v142 - 14.20.27508 + 14.28.29910 Application @@ -77,13 +77,14 @@ false - ./pub/opencv/include;$(IncludePath) + HGScannerTool false false + HGScannerTool false @@ -93,14 +94,15 @@ Use Level3 Disabled - WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) .\pub\opencv\bin;.\pub\external\bin;.\pub\opencv\include;.\pub\external\include;.\pub\ddk;.\pub\json;D:\local\boost_1_71_0_b1_rc1;D:\OpenCV2.4.10\opencv\build\include\opencv;D:\OpenCV2.4.10\opencv\build\include\opencv2 Windows true .\pub\external\lib;.\pub\opencv\lib;D:\local\boost_1_71_0_b1_rc1\lib32-msvc-14.1 - ./pub/external/lib/turbojpeg.lib;./pub/opencv/lib/opencv_world346d.lib;%(AdditionalDependencies) + turbojpeg.lib;opencv_core2410d.lib;opencv_highgui2410d.lib; +opencv_imgproc2410d.lib;%(AdditionalDependencies) false @@ -146,7 +148,7 @@ opencv_imgproc2410d.lib;%(AdditionalDependencies) true - %(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) .\pub\opencv\bin;.\pub\external\bin;.\pub\opencv\include;.\pub\external\include;.\pub\ddk;.\pub\json;D:\local\boost_1_71_0_b1_rc1;D:\OpenCV2.4.10\opencv\build\include\opencv;D:\OpenCV2.4.10\opencv\build\include\opencv2 false Default @@ -214,76 +216,50 @@ opencv_imgproc2410.lib;%(AdditionalDependencies) - + + - - - - - - - - - - - - - - - + + - + - + - + - - - - - - - - - - - - - - @@ -297,9 +273,6 @@ opencv_imgproc2410.lib;%(AdditionalDependencies) - - - diff --git a/HuaGoCorrect/HuaGoCorrect.vcxproj.filters b/HuaGoCorrect/HuaGoCorrect.vcxproj.filters index bf330e1..10c3ea8 100644 --- a/HuaGoCorrect/HuaGoCorrect.vcxproj.filters +++ b/HuaGoCorrect/HuaGoCorrect.vcxproj.filters @@ -22,9 +22,6 @@ {4947e7b4-3e27-433f-a80c-23bc7a009204} - - {c3c1bbc0-cb36-414d-bab7-7d40e277918e} - @@ -105,65 +102,29 @@ 头文件 - - 头文件 + + 源文件\USB通信 - - 头文件 - - + 头文件 头文件 - + 头文件 - - 头文件\文件处理 + + 头文件\USB通信 - - 头文件\文件处理 + + 头文件 - - 头文件\文件处理 + + 头文件\USB通信 - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 + + 头文件 @@ -215,53 +176,11 @@ 源文件 - - 源文件 - - - 源文件 - 源文件 - - 源文件 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 - - - 头文件\文件处理 + + 源文件\USB通信 @@ -269,9 +188,4 @@ 资源文件 - - - 头文件\文件处理 - - \ No newline at end of file diff --git a/HuaGoCorrect/HuaGoCorrectDlg.cpp b/HuaGoCorrect/HuaGoCorrectDlg.cpp index 93836c6..d019991 100644 --- a/HuaGoCorrect/HuaGoCorrectDlg.cpp +++ b/HuaGoCorrect/HuaGoCorrectDlg.cpp @@ -9,7 +9,10 @@ #include "scn_config.h" #include #include "imageprocess.h" -#include "ImageApplyHeaders.h" +#include +#include +#include "gscan3399.h" +#include "gscn_drv.h" using namespace std; @@ -18,7 +21,7 @@ using namespace std; #endif #define N_TIME_SEC 1000 //һʱ -#define N_TIME_SHOW 200 //0.2sˢʾ +#define N_TIME_SHOW 300 //0.2sˢʾ #define N_TIMER_SEC 1 #define N_TIMER_SHOW 2 @@ -29,10 +32,10 @@ class CAboutDlg : public CDialogEx public: CAboutDlg(); -// Ի + // Ի enum { IDD = IDD_ABOUTBOX }; - protected: +protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ // ʵ @@ -42,7 +45,6 @@ protected: CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { - } void CAboutDlg::DoDataExchange(CDataExchange* pDX) @@ -58,16 +60,12 @@ END_MESSAGE_MAP() CHuaGoCorrectDlg::CHuaGoCorrectDlg(CWnd* pParent /*=NULL*/) : CDialogEx(CHuaGoCorrectDlg::IDD, pParent) - ,usb_pid(0x7823) - ,usb_vid(0x064b) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + papercount = 0; ls_flat = FALSE; m_bExit = FALSE; - m_hThread = NULL; - m_bPause = TRUE; - m_bParamError = FALSE; m_iPicIndex = 0; m_iflatIndex = -2; @@ -75,69 +73,21 @@ CHuaGoCorrectDlg::CHuaGoCorrectDlg(CWnd* pParent /*=NULL*/) m_iDpiIndex = 0; m_iColorIndex = 0; - bABlackImage = true; - bBBlackImage = true; - bAGrayWhiteImage = true; - bBGrayWhiteImage = true; - bAColorWhiteImage = true; - bAcolr = true; - bAcolg = true; - bAcolb = true; - bBColorWhiteImage = true; - bBcolr = true; - bBcolg = true; - bBcolb = true; - bAGrayWhiteGain = true; - bBGrayWhiteGain = true; - bAColorWhiteGain = true; - bBColorWhiteGain = true; - - iAMaxStep = 0; - iAMiddleStep = 0; - iAMinStep = 0; - iBMaxStep = 0; - iBMiddleStep = 0; - iBMinStep = 0; - iAERMaxStep = 0; - iAERMiddleStep = 0; - iAERMinStep = 0; - iAEGMaxStep = 0; - iAEGMiddleStep = 0; - iAEGMinStep = 0; - iAEBMaxStep = 0; - iAEBMiddleStep = 0; - iAEBMinStep = 0; - iBERMaxStep = 0; - iBERMiddleStep = 0; - iBERMinStep = 0; - iBEGMaxStep = 0; - iBEGMiddleStep = 0; - iBEGMinStep = 0; - iBEBMaxStep = 0; - iBEBMiddleStep = 0; - iBEBMinStep = 0; - iGainStep = 0; - b_review = FALSE; - b_suspend = FALSE; + b_suspend = FALSE; } void CHuaGoCorrectDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_TAB1, m_tab); - DDX_Control(pDX, IDC_CHECK_BLACK, m_pBlack); - DDX_Control(pDX, IDC_CHECK_WExposure, m_pWExposure); - DDX_Control(pDX, IDC_CHECK_WGain, m_pWGain); DDX_Control(pDX, IDC_dpi_comboBox, m_ComboxDpi); DDX_Control(pDX, IDC_color_comboBox, m_ComboxColor); - DDX_Control(pDX, IDC_lsFpgaFlat, m_check_FpgaFlat); + DDX_Control(pDX, IDC_lsFpgaFlat, m_A4Scanner); + DDX_Control(pDX, IDC_CMB_USBS, m_Usbs); DDX_Text(pDX, IDC_EDIT_HOUR, s_hour); DDX_Text(pDX, IDC_EDIT_MINUTE, s_minute); DDX_Text(pDX, IDC_EDIT_SECOND, s_second); - DDX_Control(pDX, IDC_color_comboBox2, twss); - DDX_Control(pDX, IDC_color_comboBox3, duplex); - DDX_Control(pDX, IDC_COMBO1, Version); } BEGIN_MESSAGE_MAP(CHuaGoCorrectDlg, CDialogEx) @@ -148,20 +98,15 @@ BEGIN_MESSAGE_MAP(CHuaGoCorrectDlg, CDialogEx) ON_BN_CLICKED(IDC_CheckParamSet, &CHuaGoCorrectDlg::OnBnClickedCheckparamset) ON_BN_CLICKED(IDC_CheckParamRead, &CHuaGoCorrectDlg::OnBnClickedCheckparamread) ON_BN_CLICKED(IDC_BTN_FLAT, &CHuaGoCorrectDlg::OnBnClickedBtnFlat) - ON_BN_CLICKED(IDC_BTN_FLATM, &CHuaGoCorrectDlg::OnBnClickedBtnFlatm) - ON_BN_CLICKED(IDC_BTN_BLACKFLAT, &CHuaGoCorrectDlg::OnBnClickedBtnBlackflat) - ON_BN_CLICKED(IDC_BTN_EXFLAT, &CHuaGoCorrectDlg::OnBnClickedBtnExflat) - ON_BN_CLICKED(IDC_BTN_GAINFLAT, &CHuaGoCorrectDlg::OnBnClickedBtnGainflat) - ON_BN_CLICKED(IDC_BTN_CONTINUE, &CHuaGoCorrectDlg::OnBnClickedBtnContinue) - ON_BN_CLICKED(IDC_BTN_PAUSE, &CHuaGoCorrectDlg::OnBnClickedBtnPause) ON_CBN_SELCHANGE(IDC_dpi_comboBox, &CHuaGoCorrectDlg::OnCbnSelChangeDpi) ON_CBN_SELCHANGE(IDC_color_comboBox, &CHuaGoCorrectDlg::OnCbnSelChangeColor) - ON_BN_CLICKED(IDC_BUTTON1, &CHuaGoCorrectDlg::OnBnClickedConfirm) - ON_BN_CLICKED(IDC_BTN_PARAMCFG, &CHuaGoCorrectDlg::OnBnClickedBtnParamcfg) - ON_BN_CLICKED(IDC_BUTTON3, &CHuaGoCorrectDlg::OnBnClickedStopScan) - ON_WM_TIMER() - ON_MESSAGE(WM_MYMESSAGE, &CHuaGoCorrectDlg::OnMyMessage) - ON_CBN_SELCHANGE(IDC_COMBO1, &CHuaGoCorrectDlg::OnCbnSelchangeCombo1) + //ON_WM_TIMER() + ON_BN_CLICKED(IDC_BTN_SELECTFILE, &CHuaGoCorrectDlg::OnBnClickedBtnSelectfile) + ON_BN_CLICKED(IDC_BTN_UPDATE, &CHuaGoCorrectDlg::OnBnClickedBtnUpdate) + ON_BN_CLICKED(IDC_BTN_REFRESH, &CHuaGoCorrectDlg::OnBnClickedBtnRefresh) + ON_CBN_SELCHANGE(IDC_CMB_USBS, &CHuaGoCorrectDlg::OnCbnSelchangeCmbUsbs) + ON_BN_CLICKED(IDC_BTNSTART, &CHuaGoCorrectDlg::OnBnClickedBtnstart) + ON_BN_CLICKED(IDC_BTNSTOP, &CHuaGoCorrectDlg::OnBnClickedBtnstop) END_MESSAGE_MAP() @@ -170,36 +115,10 @@ END_MESSAGE_MAP() BOOL CHuaGoCorrectDlg::OnInitDialog() { CDialogEx::OnInitDialog(); - this->SetWindowTextA("HuaGaoCorrect"); - m_drv.reset(new GScn_Drv()); - - m_drv->open(usb_vid); - int version_num =0; - int num = 0; - if (m_drv->device_id == 0) - MessageBox(TEXT("δҵ豸!"), TEXT("ʾ"), MB_OK | MB_ICONWARNING); - Version.InsertString(num++, _T("Ĭ")); - Version.InsertString(num++, _T("G100")); - //m_tab.InsertItem(2, _T("ͼ")); - Version.InsertString(num++, _T("G200")); - Version.InsertString(num++, _T("G300")); - Version.InsertString(num++, _T("G400")); - for (int q = 0; q < 5; q++) - { - if ((1 << (q * 4)) & m_drv->device_id) - { - version_num = q; - } - - } - Version.SetCurSel(version_num); - //m_drv->open(0x3072, 0x0100,0); // ...˵ӵϵͳ˵С - // IDM_ABOUTBOX ϵͳΧڡ ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); - CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { @@ -219,60 +138,56 @@ BOOL CHuaGoCorrectDlg::OnInitDialog() SetIcon(m_hIcon, TRUE); // ôͼ SetIcon(m_hIcon, FALSE); // Сͼ - // TODO: ڴӶijʼ - m_tab.InsertItem(0, _T("A3")); - m_tab.InsertItem(1, _T("A4")); - //m_tab.InsertItem(2, _T("ͼ")); - m_tab.InsertItem(2, _T("CIS⹤")); - m_tab.InsertItem(3, _T("")); - m_A3Dlg.Create(IDD_A3_DIALOG, &m_tab); // һǩҳ + // TODO: ڴӶijʼ + m_tab.InsertItem(0, _T("")); + m_tab.InsertItem(1, _T("ʾͼ")); + m_tab.InsertItem(2, _T("CIS")); m_A4Dlg.Create(IDD_A4_DIALOG, &m_tab); // ڶǩҳ - //m_VisonDlg.Create(IDD_VISION_DIALOG, &m_tab); //ǩҳ - m_CISDlg.Create(IDD_CIS_DIALOG1, &m_tab); - m_dis.Create(IDD_DIS_DIALOG1, &m_tab); - //m_CISDlg.Cis_box.SetCurSel(0); - + m_VisonDlg.Create(IDD_VISION_DIALOG, &m_tab); //ǩҳ + m_A3dlg.Create(IDD_A3_DIALOG, &m_tab); + m_A4Dlg.SetParent(this); + m_VisonDlg.SetParent(this); + m_A3dlg.SetParent(this); + auto callback = [this](bool stoped, int num) { + if (stoped) + { + KillTimer(N_TIMER_SEC); + KillTimer(N_TIMER_SHOW); + } + else + { + CString str; + str.Format("%d", num); + SetDlgItemText(IDC_STATIC_NUM, str); + } + }; + m_VisonDlg.SetCallBack(callback); m_tab.GetClientRect(&tabRect); // ȡǩؼͻRect // tabRectʹ串ǷΧʺϷñǩҳ - tabRect.left += 1; - tabRect.right -= 1; - tabRect.top += 25; - tabRect.bottom -= 1; + tabRect.left += 1; + tabRect.right -= 1; + tabRect.top += 35; + tabRect.bottom -= 1; // ݵõtabRectm_A3DlgӶԻ򣬲Ϊʾ - m_A3Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); + m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); // ݵõtabRectm_A4DlgӶԻ򣬲Ϊ - m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); + m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); // ݵõtabRectm_VisonDlgӶԻ򣬲Ϊ - //m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); - m_CISDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_dis.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_tab.SetCurSel(1); + m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_ComboxDpi.InsertString(0, _T("300")); + m_ComboxDpi.InsertString(0, _T("300")); m_ComboxDpi.InsertString(1, _T("200")); m_ComboxDpi.InsertString(2, _T("150")); m_ComboxDpi.SetCurSel(1); - twss.InsertString(0, _T("A4")); - twss.InsertString(1, _T("A3")); - twss.InsertString(2, _T("Զü")); - twss.SetCurSel(0); - duplex.InsertString(0, _T("")); - duplex.InsertString(1, _T("˫")); - duplex.SetCurSel(0); - m_ComboxColor.InsertString(0, _T("gray")); - m_ComboxColor.InsertString(1, _T("color")); + + m_ComboxColor.InsertString(0, _T("gray")); + m_ComboxColor.InsertString(1, _T("color")); m_ComboxColor.SetCurSel(1); - m_drv->set_decompress_pix_type(TWPT_RGB); - - m_check_FpgaFlat.SetCheck(0); - m_pBlack.SetCheck(0); - m_pWExposure.SetCheck(0); - m_pWGain.SetCheck(0); - - m_drv->SetPath(GetMainApp()->path); + //m_drv->set_decompress_pix_type(TWPT_RGB); + m_A4Scanner.SetCheck(0); n_hour = 0; n_minute = 0; n_second = 0; @@ -281,16 +196,59 @@ BOOL CHuaGoCorrectDlg::OnInitDialog() s_second = "00"; UpdateData(FALSE); - //InitButton(); - - //У߳ - unsigned threadId; - // Create the thread. - m_hThread = (HANDLE)::_beginthreadex( NULL, 0, &CorrectThread, this, 0, &threadId); - + bool ret = RefreshUSBList(); + if (ret) + { + m_Usbs.SetCurSel(0);//Ĭѡһ豸 + OnCbnSelchangeCmbUsbs(); + } + m_tab.SetCurSel(0); + RefreshTabChange(); return TRUE; // ǽõؼ򷵻 TRUE } +void CHuaGoCorrectDlg::EnableUIItem(bool enbale) +{ + GetDlgItem(IDC_CMB_USBS)->EnableWindow(enbale); + GetDlgItem(IDC_BTNSTART)->EnableWindow(enbale); + GetDlgItem(IDC_BTNSTOP)->EnableWindow(enbale); + GetDlgItem(IDC_CheckParamSet)->EnableWindow(enbale); + GetDlgItem(IDC_CheckParamRead)->EnableWindow(enbale); + GetDlgItem(IDC_BTN_FLAT)->EnableWindow(enbale); + GetDlgItem(IDC_BTN_SELECTFILE)->EnableWindow(enbale); + GetDlgItem(IDC_BTN_UPDATE)->EnableWindow(enbale); + m_A4Dlg.EnableItem(enbale); +} + +bool CHuaGoCorrectDlg::RefreshUSBList() +{ + auto ret = UsbScan_List::find_all_usb(); + if (m_Usbs.GetCount() > 0) + m_Usbs.ResetContent(); + if (ret.size() <= 0) + { + EnableUIItem(false); + MessageBox(TEXT("δҵɨǣ"), TEXT("ʾ"), MB_OK | MB_ICONWARNING); + return false; + } + else + { + EnableUIItem(true); + auto info = ret.begin(); + int i = 0; + while (info != ret.end()) + { + CString strinfo; + strinfo.Format("vid0x%x pid0X%x", info->vid, info->pid); + m_Usbs.InsertString(i, strinfo); + info++; + i++; + } + m_Usbs.SetCurSel(0); + OnCbnSelchangeCmbUsbs(); + return true; + } +} void CHuaGoCorrectDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) @@ -323,6 +281,7 @@ void CHuaGoCorrectDlg::OnPaint() GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; + // ͼ dc.DrawIcon(x, y, m_hIcon); } @@ -339,78 +298,11 @@ HCURSOR CHuaGoCorrectDlg::OnQueryDragIcon() return static_cast(m_hIcon); } -unsigned WINAPI CHuaGoCorrectDlg::CorrectThread(void* pCorrect) -{ - CHuaGoCorrectDlg *pDlg = (CHuaGoCorrectDlg *)pCorrect; - if (pDlg != NULL) - { - pDlg->CorrectThreadFunc(); - } - return 0; -} - -void CHuaGoCorrectDlg::CorrectThreadFunc() -{ - BOOL bNewConnect = FALSE; //Ƿһ - while (!m_bExit) - { - m_deviceLock.Lock(); - - if(true != m_bPause) - { - m_drv->FlatA4(); - Sleep(28000); - - if(1 == m_pBlack.GetCheck()) - { - if(1 == m_pWExposure.GetCheck()) - { - if(0 == m_pWGain.GetCheck()) - { - CorrectWhiteGain(); - } - else - { - m_bPause = true; - } - } - else - { - CorrectWhiteImage(); - } - } - else - { - CorrectBlackImage(); - } - } - m_deviceLock.Unlock(); - } -} - -BOOL CHuaGoCorrectDlg::PreCreateWindow(CREATESTRUCT & cs) -{ - - cs.style = cs.style&~WS_MAXIMIZEBOX&~WS_SYSMENU&~WS_MINIMIZEBOX; - - if (!CDialogEx::PreCreateWindow(cs)) - - return FALSE; - - // TODO: Modify the Window class or styles here by modifying - - // the CREATESTRUCT cs - - - - return TRUE; -} - -void CHuaGoCorrectDlg::OnTcnSelChangeTab(NMHDR *pNMHDR, LRESULT *pResult) +void CHuaGoCorrectDlg::OnTcnSelChangeTab(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: ڴӿؼ֪ͨ *pResult = 0; - RefreshTabChange(); + RefreshTabChange(); } void CHuaGoCorrectDlg::RefreshTabChange() @@ -419,219 +311,61 @@ void CHuaGoCorrectDlg::RefreshTabChange() // ȡǩؼͻRectʺϷñǩҳ m_tab.GetClientRect(&tabRect); - tabRect.left += 1; + tabRect.left += 10; tabRect.right -= 1; - tabRect.top += 25; + tabRect.top += 35; tabRect.bottom -= 1; - int currentselect = m_tab.GetCurSel(); - switch (currentselect) + + switch (m_tab.GetCurSel()) { case 0: - m_A3Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); - m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - //m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_CISDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_dis.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); + m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); + m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); + m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); break; case 1: - //m_check_FpgaFlat.SetCheck(1); - m_A3Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); - //m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_CISDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_dis.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); + m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); + m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); + m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); break; - //case 2: - // m_A3Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - // m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - // m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); - // m_CISDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - // m_dis.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - // break; case 2: - m_A3Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - //m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_CISDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); - m_dis.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_CISDlg.SetGscan_drv(m_drv.get()); - break; - case 3: - m_A3Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - //m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_CISDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); - m_dis.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); - m_dis.setgcn_drv(m_drv.get()); + m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW); + m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW); break; default: break; } - - m_CISDlg.SetEnableGetImage(currentselect == 2); - m_dis.SetEnableGetImage(currentselect == 3); } void CHuaGoCorrectDlg::Scan() -{ - hgConfigClass cf; - CONFIGPARAMS configItem; - if(m_iColorIndex == 0) - { - cf.setTwPixelType(TWPT_GRAY); - configItem.Pixtype = TWPT_GRAY; - } - else - { - cf.setTwPixelType(TWPT_RGB); - configItem.Pixtype = TWPT_RGB; - } - - if (twss.GetCurSel() == 0) - { - cf.settwSS(TWSS_A3); - configItem.PaperSize = A3; - } - else if(twss.GetCurSel()==1) - { - cf.settwSS(TWSS_A4); - configItem.PaperSize = A4; - } - else - { - cf.settwSS(TWSS_A4); - configItem.PaperSize = USStatement; - } - if(m_ComboxDpi.GetCurSel() == 0) - { - cf.setResolution(300.0); - configItem.Resolution = 300; - } - else if(m_ComboxDpi.GetCurSel() == 1) - { - cf.setResolution(200.0); - configItem.Resolution = 200; - } - else - { - cf.setResolution(150.0); - configItem.Resolution = 150; - } - - cf.setDoubleFeedEnable(FALSE); - cf.setStapleEnable(FALSE); - configItem.Duplex = 0; - - if(0 == m_check_FpgaFlat.GetCheck()) - { - cf.setIsConrrect(TRUE); - } - else - { - cf.setIsConrrect(FALSE); - } - bool b_save_origin = ((CButton*)(GetDlgItem(IDC_CHECK3)))->GetCheck() == 1; - bool b_save_origin_fixed = ((CButton*)(GetDlgItem(IDC_CHECK4)))->GetCheck() == 1; - m_drv->save_config(b_save_origin, b_save_origin_fixed); - UpdateList(configItem, true); - m_drv->setlist(m_iaList); - m_dis.updatadistorionparam(); - m_dis.d_distortonoaram = m_dis.getdistorionparam(); - UINT32 cfg_Value =cf.GetData(); - USBCB usbcb = { CONFIGURED_DATA , cfg_Value,0 }; - m_drv->Config_Scanner(&usbcb); - BOOL isduplex = duplex.GetCurSel(); - m_CISDlg.isduplex = isduplex; - m_drv->SetIsDuplex(isduplex); - Sleep(2000); - - m_drv->Scanner_StartScan(0); - - if (b_review||b_suspend) - KillTimer(N_TIMER_SEC); - b_review = FALSE; - b_suspend = FALSE; - n_hour = 0; - n_minute = 0; - n_second = 0; - SetTimer(N_TIMER_SEC, N_TIME_SEC, NULL); - SetTimer(N_TIMER_SHOW, N_TIME_SHOW, NULL); -} -static map, CSize> dpiDct; -static void initialDictionary() { - //A3 - dpiDct.insert(pair, CSize>(pair(A3, 100), CSize(1169, 1653))); - dpiDct.insert(pair, CSize>(pair(A3, 150), CSize(1753, 2480))); - dpiDct.insert(pair, CSize>(pair(A3, 200), CSize(2338, 3307))); - dpiDct.insert(pair, CSize>(pair(A3, 240), CSize(2806, 3968))); - dpiDct.insert(pair, CSize>(pair(A3, 300), CSize(3507, 4960))); + HGScanConfig config = { 0 }; + config.g200params.dpi = 1;//only support 200DPI + config.g200params.paper = 0; + config.g200params.pc_correct = !((CButton*)GetDlgItem(IDC_CKBORGINIMG))->GetCheck(); + config.g200params.color = m_iColorIndex == 1 ? 1 : 0; + config.g200params.double_feed_enbale = TRUE; + config.g200params.screw_detect_enable = FALSE; + config.g200params.iscorrect_mode = 1;//Уģʽ + m_drv->Config_Scanner(config); + this_thread::sleep_for(std::chrono::milliseconds(1000)); - //A4 - dpiDct.insert(pair, CSize>(pair(A4, 100), CSize(826, 1169))); - dpiDct.insert(pair, CSize>(pair(A4, 150), CSize(1240, 1753))); - dpiDct.insert(pair, CSize>(pair(A4, 200), CSize(1653, 2338))); - dpiDct.insert(pair, CSize>(pair(A4, 240), CSize(1984, 2806))); - dpiDct.insert(pair, CSize>(pair(A4, 300), CSize(2480, 3507))); + m_drv->Scanner_StartScan(-1); + m_drv->run(); - //1.5A3 - dpiDct.insert(pair, CSize>(pair(USStatement, 100), CSize(1169, (LONG)(1653 * 1.5)))); - dpiDct.insert(pair, CSize>(pair(USStatement, 150), CSize(1753, (LONG)(2480 * 1.5)))); - dpiDct.insert(pair, CSize>(pair(USStatement, 200), CSize(2338, (LONG)(3307 * 1.5)))); - dpiDct.insert(pair, CSize>(pair(USStatement, 240), CSize(2806, (LONG)(3968 * 1.5)))); - dpiDct.insert(pair, CSize>(pair(USStatement, 300), CSize(3507, (LONG)(4960 * 1.5)))); + //if (b_suspend) + // KillTimer(N_TIMER_SEC); - /*dpiDct[{USStatement, 50.0f}] = { 585, (LONG)(827 * 1.5) }; - dpiDct[{USStatement, 75.0f}] = { 877, (LONG)(1240 * 1.5) }; - dpiDct[{USStatement, 100.0f}] = { 1169, (LONG)(1653 * 1.5) }; - dpiDct[{USStatement, 150.0f}] = { 1753, (LONG)(2480 * 1.5) }; - dpiDct[{USStatement, 200.0f}] = { 2338, (LONG)(3307 * 1.5) }; - dpiDct[{USStatement, 240.0f}] = { 2806, (LONG)(3968 * 1.5) }; - dpiDct[{USStatement, 300.0f}] = { 3507, (LONG)(4960 * 1.5) }; - dpiDct[{USStatement, 400.0f}] = { 4677, (LONG)(6614 * 1.5) }; - dpiDct[{USStatement, 600.0f}] = { 7015, (LONG)(9921 * 1.5) };*/ + //b_suspend = FALSE; + //n_hour = 0; + //n_minute = 0; + //n_second = 0; + //SetTimer(N_TIMER_SEC, N_TIME_SEC, NULL); + //SetTimer(N_TIMER_SHOW, N_TIME_SHOW, NULL); } -static CSize getSize(TwSS paperType, float dpi) -{ - CSize retSize; - map, CSize>::iterator iter; - iter = dpiDct.find(pair(paperType, dpi)); - if (iter != dpiDct.end()) { - retSize = (*iter).second; - return retSize; - } - return CSize(2338, 3307); -} -void CHuaGoCorrectDlg::UpdateList(CONFIGPARAMS configParams, bool canUpdate) -{ - m_iaList.clear(); - CSize fixedSize = getSize((TwSS)configParams.PaperSize, 200.0f); - bool autocrop = (TwSS)configParams.PaperSize == TwSS::USStatement; - m_iaList.push_back(std::shared_ptr(new CImageApplyAutoCrop(true, true, true, cv::Size(fixedSize.cx, fixedSize.cy), true))); - if (configParams.Pixtype != 0) - { - m_iaList.push_back(std::shared_ptr(new CImageApplySharpen())); - } - - if (configParams.Pixtype == 0) //threshold - m_iaList.push_back(std::shared_ptr(new CImageApplyBWBinaray(CImageApplyBWBinaray::THRESH_BINARY))); - - if (configParams.Resolution != 200.0) - { - CImageApplyResize* apply; - if (true) { - double ratio = configParams.Resolution / 200.0; - apply = new CImageApplyResize(CImageApplyResize::RATIO, cv::Size(0, 0), ratio, ratio); - } - else { - CSize dSize = getSize((TwSS)configParams.PaperSize, configParams.Resolution); - apply = new CImageApplyResize(CImageApplyResize::DSIZE, cv::Size(dSize.cx, dSize.cy), 1.0, 1.0); - } - m_iaList.push_back(std::shared_ptr< CImageApply>(apply)); - } -} void CHuaGoCorrectDlg::OnBnClickedCheckparamset() { // TODO: ڴӿؼ֪ͨ @@ -640,17 +374,7 @@ void CHuaGoCorrectDlg::OnBnClickedCheckparamset() MessageBox("ɨδӣ"); return; } - - int iSel = m_tab.GetCurSel(); - if(iSel == 0) - { - A3ParamSet(); - } - else - { - //A4ParamSet(); - CorrectCMDUpdate(); - } + m_A4Dlg.SendCorrectParam(); } @@ -662,1989 +386,40 @@ void CHuaGoCorrectDlg::OnBnClickedCheckparamread() MessageBox("ɨδӣ"); return; } - - if (m_tab.GetCurSel() == 1) - { - try - { - int offset = 0; - UINT iDes[128] = {0}; - byte bValue[512] = {0}; - byte *read = m_drv->GetFlatData(); - - for(int i = 0; i < 512; i++) - { - bValue[i] = read[i]; - } - - for (int j = 0; j < 128; j++) - { - int value = (int)((bValue[offset+0] & 0xFF) - | ((bValue[offset + 1] & 0xFF) << 8) - | ((bValue[offset + 2] & 0xFF) << 16) - | ((bValue[offset + 3] & 0xFF) << 24)); - - iDes[j] = value; - offset += 4; - } - - int flatType = m_A4Dlg.m_A4FlatModel.GetCurSel(); - int startindex = -1; - switch (flatType) - { - case 0://ɫƽУ0~29 - startindex = 3; - break; - case 1://ɫУ30~59 - startindex = 63; - break; - case 2://ҶƽУ60~89 - startindex = 33; - break; - case 3://ҶУ90~120 - startindex = 93; - break; - default: - break; - } - - int iValues[30] = {0}; - int j = 0; - for(int i = startindex; i < startindex+30; i++) - { - iValues[j] = iDes[i]; - j++; - } - - if (startindex!=-1) - { - m_A4Dlg.updateA4Config(iValues); - } - } - catch (Exception) - { - - throw; - } - } - else - { - byte *buffer = m_drv->GetCisPara(); - byte bValue[30] = {0}; - - for(int i = 0; i < 30; i++) - { - bValue[i] = buffer[i]; - } - - //m_A3Dlg.updateA3Config(bValue); - } + m_tab.SetCurSel(0); + auto read = m_drv->GetFlatData(); + m_A4Dlg.updateA4Config(read); } - void CHuaGoCorrectDlg::OnBnClickedBtnFlat() { // TODO: ڴӿؼ֪ͨ m_iflatIndex = -2; - - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(TRUE); - if (!m_drv->IsConnected()) { MessageBox("ɨδӣ"); return; } - - if (m_tab.GetCurSel() == 1) + if (GetDlgItem(IDC_CKBCORRECTMODE)->IsWindowVisible()) { - if(m_bParamError == true) - { - m_drv->reset(); - m_bParamError = false; - } - else - { - m_drv->reset(); - m_drv->DevStateChange(); - } - - //m_drv->FlatA4(); - //Sleep(28000); - //m_iflatIndex += 2; - m_bPause = false; + m_drv->StartFlat(((CButton*)GetDlgItem(IDC_CKBCORRECTMODE))->GetCheck()); + } - //ShowFrontImage(m_iflatIndex); - //Sleep(500); - //m_iflatIndex += 2; - //ShowFrontImage(m_iflatIndex); - //CorrectBlackImage(m_iflatIndex); - //MessageBox("У"); - } else - { - /* - if(1 == m_A3Dlg.m_200dpi_gray.GetCheck()) - { - m_drv->FlatA3(0x40); - Sleep(2000); - m_drv->Stop_scan(); - Sleep(1000); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - Sleep(500); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - MessageBox("У"); - m_drv->DevStateChange(); - } - - if(1 == m_A3Dlg.m_200dpi_color.GetCheck()) - { - m_drv->FlatA3(0x60); - Sleep(2000); - m_drv->Stop_scan(); - Sleep(1000); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - Sleep(500); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - MessageBox("У"); - m_drv->DevStateChange(); - } - - if(1 == m_A3Dlg.m_300dpi_gray.GetCheck()) - { - m_drv->FlatA3(0x00); - Sleep(2000); - m_drv->Stop_scan(); - Sleep(1000); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - Sleep(500); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - MessageBox("У"); - m_drv->DevStateChange(); - } - - if(1 == m_A3Dlg.m_300dpi_color.GetCheck()) - { - m_drv->FlatA3(0x20); - Sleep(2000); - m_drv->Stop_scan(); - Sleep(1000); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - Sleep(500); - m_iflatIndex += 2; - ShowFrontImage(m_iflatIndex); - MessageBox("У"); - m_drv->DevStateChange(); - } - */ - } -} - -void CHuaGoCorrectDlg::A3ParamSet() -{ - CString csParam; - /* - UINT adpara = m_A3Dlg.m_gray_gain_f; - adpara = (adpara | (m_A3Dlg.m_gray_gain_b << 8)); - adpara = (adpara | (m_A3Dlg.m_gray_offset_f << 16)); - adpara = (adpara | (m_A3Dlg.m_gray_offset_b << 24)); - m_drv->SendrAdPara(adpara); - - Sleep(500); - UINT Rgbadpara = m_A3Dlg.m_rgb_gain_f; - Rgbadpara = (Rgbadpara | (m_A3Dlg.m_rgb_gain_b << 8)); - Rgbadpara = (Rgbadpara | (m_A3Dlg.m_rgb_offset_f << 16)); - Rgbadpara = (Rgbadpara | (m_A3Dlg.m_rgb_offset_b << 24)); - m_drv->SendrRgbAdPara(Rgbadpara); - - Sleep(500); - //SenGRPara(0x011000a0); - UINT GRtimepara = ((m_A3Dlg.m_Redtime << 16) | m_A3Dlg.m_Graytime); - m_drv->SenGRPara(GRtimepara); - - Sleep(500); - //SenGBPara(0x01ba0215); - UINT GBtimepara = ((m_A3Dlg.m_Bluetime << 16) | m_A3Dlg.m_Greentime); - m_drv->SenGBPara(GBtimepara); - - MessageBox("ͳɹ"); - */ -} - -void CHuaGoCorrectDlg::A4ParamSet() -{ - if (!m_drv->IsConnected()) - { - MessageBox("ɨδӣ"); - return; - } - - switch (m_A4Dlg.m_A4FlatModel.GetCurSel()) - { - case 0: - { - UINT gains[30] = {0}; - byte gain[512] = {0}; - byte gain_data[524] = {0}; - - m_A4Dlg.UpdateData(TRUE); - gains[0] = m_A4Dlg.m_tbxFRExposure; - gains[1] = m_A4Dlg.m_tbxFGExposure; - gains[2] = m_A4Dlg.m_tbxFBExposure; - gains[3] = m_A4Dlg.m_tbxBRExposure; - gains[4] = m_A4Dlg.m_tbxBGExposure; - gains[5] = m_A4Dlg.m_tbxBBExposure; - gains[6] = m_A4Dlg.m_tbxF1Gain; - gains[7] = m_A4Dlg.m_tbxF2Gain; - gains[8] = m_A4Dlg.m_tbxF3Gain; - gains[9] = m_A4Dlg.m_tbxF4Gain; - gains[10] = m_A4Dlg.m_tbxF5Gain; - gains[11] = m_A4Dlg.m_tbxF6Gain; - gains[12] = m_A4Dlg.m_tbxB1Gain; - gains[13] = m_A4Dlg.m_tbxB2Gain; - gains[14] = m_A4Dlg.m_tbxB3Gain; - gains[15] = m_A4Dlg.m_tbxB4Gain; - gains[16] = m_A4Dlg.m_tbxB5Gain; - gains[17] = m_A4Dlg.m_tbxB6Gain; - gains[18] = m_A4Dlg.m_tbxF1Offset; - gains[19] = m_A4Dlg.m_tbxF2Offset; - gains[20] = m_A4Dlg.m_tbxF3Offset; - gains[21] = m_A4Dlg.m_tbxF4Offset; - gains[22] = m_A4Dlg.m_tbxF5Offset; - gains[23] = m_A4Dlg.m_tbxF6Offset; - gains[24] = m_A4Dlg.m_tbxB1Offset; - gains[25] = m_A4Dlg.m_tbxB2Offset; - gains[26] = m_A4Dlg.m_tbxB3Offset; - gains[27] = m_A4Dlg.m_tbxB4Offset; - gains[28] = m_A4Dlg.m_tbxB5Offset; - gains[29] = m_A4Dlg.m_tbxB6Offset; - m_A4Dlg.UpdateData(FALSE); - - intToByte(gains, gain, 30); - USBCBA4 ubc; - ubc.u32_Command = SEND_COLORCORRECT_FLAT; - ubc.u32_Count = 120; - memcpy(ubc.buffer,gain,512); - ubc.u32_Data = 0; - - int length = sizeof(ubc); - memmove(gain_data,&ubc,length); - - m_drv->SendColorCorrentFlat(gain_data,length); - } - break; - case 1: - { - UINT gains[30] = {0}; - byte gain[512] = {0}; - byte gain_data[524] = {0}; - - m_A4Dlg.UpdateData(TRUE); - gains[0] = m_A4Dlg.m_tbxFRExposure; - gains[1] = m_A4Dlg.m_tbxFGExposure; - gains[2] = m_A4Dlg.m_tbxFBExposure; - gains[3] = m_A4Dlg.m_tbxBRExposure; - gains[4] = m_A4Dlg.m_tbxBGExposure; - gains[5] = m_A4Dlg.m_tbxBBExposure; - gains[6] = m_A4Dlg.m_tbxF1Gain; - gains[7] = m_A4Dlg.m_tbxF2Gain; - gains[8] = m_A4Dlg.m_tbxF3Gain; - gains[9] = m_A4Dlg.m_tbxF4Gain; - gains[10] = m_A4Dlg.m_tbxF5Gain; - gains[11] = m_A4Dlg.m_tbxF6Gain; - gains[12] = m_A4Dlg.m_tbxB1Gain; - gains[13] = m_A4Dlg.m_tbxB2Gain; - gains[14] = m_A4Dlg.m_tbxB3Gain; - gains[15] = m_A4Dlg.m_tbxB4Gain; - gains[16] = m_A4Dlg.m_tbxB5Gain; - gains[17] = m_A4Dlg.m_tbxB6Gain; - gains[18] = m_A4Dlg.m_tbxF1Offset; - gains[19] = m_A4Dlg.m_tbxF2Offset; - gains[20] = m_A4Dlg.m_tbxF3Offset; - gains[21] = m_A4Dlg.m_tbxF4Offset; - gains[22] = m_A4Dlg.m_tbxF5Offset; - gains[23] = m_A4Dlg.m_tbxF6Offset; - gains[24] = m_A4Dlg.m_tbxB1Offset; - gains[25] = m_A4Dlg.m_tbxB2Offset; - gains[26] = m_A4Dlg.m_tbxB3Offset; - gains[27] = m_A4Dlg.m_tbxB4Offset; - gains[28] = m_A4Dlg.m_tbxB5Offset; - gains[29] = m_A4Dlg.m_tbxB6Offset; - m_A4Dlg.UpdateData(FALSE); - - intToByte(gains, gain, 30); - USBCBA4 ubcColor; - ubcColor.u32_Command = SEND_COLOR_FLAT; - ubcColor.u32_Count = 120; - memcpy(ubcColor.buffer,gain,512); - ubcColor.u32_Data = 0; - - int length = sizeof(ubcColor); - memmove(gain_data,&ubcColor,length); - - m_drv->SendColorFlat(gain_data,length); - } - break; - case 2: - { - UINT gains[30] = {0}; - byte gain[512] = {0}; - byte gain_data[524] = {0}; - - m_A4Dlg.UpdateData(TRUE); - gains[0] = m_A4Dlg.m_tbxFRExposure; - gains[1] = m_A4Dlg.m_tbxFGExposure; - gains[2] = m_A4Dlg.m_tbxFBExposure; - gains[3] = m_A4Dlg.m_tbxBRExposure; - gains[4] = m_A4Dlg.m_tbxBGExposure; - gains[5] = m_A4Dlg.m_tbxBBExposure; - gains[6] = m_A4Dlg.m_tbxF1Gain; - gains[7] = m_A4Dlg.m_tbxF2Gain; - gains[8] = m_A4Dlg.m_tbxF3Gain; - gains[9] = m_A4Dlg.m_tbxF4Gain; - gains[10] = m_A4Dlg.m_tbxF5Gain; - gains[11] = m_A4Dlg.m_tbxF6Gain; - gains[12] = m_A4Dlg.m_tbxB1Gain; - gains[13] = m_A4Dlg.m_tbxB2Gain; - gains[14] = m_A4Dlg.m_tbxB3Gain; - gains[15] = m_A4Dlg.m_tbxB4Gain; - gains[16] = m_A4Dlg.m_tbxB5Gain; - gains[17] = m_A4Dlg.m_tbxB6Gain; - gains[18] = m_A4Dlg.m_tbxF1Offset; - gains[19] = m_A4Dlg.m_tbxF2Offset; - gains[20] = m_A4Dlg.m_tbxF3Offset; - gains[21] = m_A4Dlg.m_tbxF4Offset; - gains[22] = m_A4Dlg.m_tbxF5Offset; - gains[23] = m_A4Dlg.m_tbxF6Offset; - gains[24] = m_A4Dlg.m_tbxB1Offset; - gains[25] = m_A4Dlg.m_tbxB2Offset; - gains[26] = m_A4Dlg.m_tbxB3Offset; - gains[27] = m_A4Dlg.m_tbxB4Offset; - gains[28] = m_A4Dlg.m_tbxB5Offset; - gains[29] = m_A4Dlg.m_tbxB6Offset; - m_A4Dlg.UpdateData(FALSE); - - intToByte(gains, gain, 30); - USBCBA4 ubcGrayC; - ubcGrayC.u32_Command = SEND_GRAYCORRECT_FLAT; - ubcGrayC.u32_Count = 120; - memcpy(ubcGrayC.buffer,gain,512); - ubcGrayC.u32_Data = 0; - - int length = sizeof(ubcGrayC); - memmove(gain_data,&ubcGrayC,length); - - m_drv->SendGrayCorrectFlat(gain_data,length); - } - break; - case 3: - { - UINT gains[30] = {0}; - byte gain[512] = {0}; - byte gain_data[524] = {0}; - - m_A4Dlg.UpdateData(TRUE); - gains[0] = m_A4Dlg.m_tbxFRExposure; - gains[1] = m_A4Dlg.m_tbxFGExposure; - gains[2] = m_A4Dlg.m_tbxFBExposure; - gains[3] = m_A4Dlg.m_tbxBRExposure; - gains[4] = m_A4Dlg.m_tbxBGExposure; - gains[5] = m_A4Dlg.m_tbxBBExposure; - gains[6] = m_A4Dlg.m_tbxF1Gain; - gains[7] = m_A4Dlg.m_tbxF2Gain; - gains[8] = m_A4Dlg.m_tbxF3Gain; - gains[9] = m_A4Dlg.m_tbxF4Gain; - gains[10] = m_A4Dlg.m_tbxF5Gain; - gains[11] = m_A4Dlg.m_tbxF6Gain; - gains[12] = m_A4Dlg.m_tbxB1Gain; - gains[13] = m_A4Dlg.m_tbxB2Gain; - gains[14] = m_A4Dlg.m_tbxB3Gain; - gains[15] = m_A4Dlg.m_tbxB4Gain; - gains[16] = m_A4Dlg.m_tbxB5Gain; - gains[17] = m_A4Dlg.m_tbxB6Gain; - gains[18] = m_A4Dlg.m_tbxF1Offset; - gains[19] = m_A4Dlg.m_tbxF2Offset; - gains[20] = m_A4Dlg.m_tbxF3Offset; - gains[21] = m_A4Dlg.m_tbxF4Offset; - gains[22] = m_A4Dlg.m_tbxF5Offset; - gains[23] = m_A4Dlg.m_tbxF6Offset; - gains[24] = m_A4Dlg.m_tbxB1Offset; - gains[25] = m_A4Dlg.m_tbxB2Offset; - gains[26] = m_A4Dlg.m_tbxB3Offset; - gains[27] = m_A4Dlg.m_tbxB4Offset; - gains[28] = m_A4Dlg.m_tbxB5Offset; - gains[29] = m_A4Dlg.m_tbxB6Offset; - m_A4Dlg.UpdateData(FALSE); - - intToByte(gains, gain, 30); - USBCBA4 ubcGray; - ubcGray.u32_Command = SEND_GRAY_FLAT; - ubcGray.u32_Count = 120; - memcpy(ubcGray.buffer,gain,512); - ubcGray.u32_Data = 0; - - int length = sizeof(ubcGray); - memmove(gain_data,&ubcGray,length); - - m_drv->SendGrayFlat(gain_data,length); - } - break; - default: - break; - } -} - -//intתbyte -void CHuaGoCorrectDlg::intToByte(UINT *src,byte *bytes,int iLength) -{ - int offset = 0; - - for (int i = 0; i < iLength; i++) - { - bytes[offset + 3] = (byte)((src[i] >> 24) & 0xFF); - bytes[offset + 2] = (byte)((src[i] >> 16) & 0xFF); - bytes[offset + 1] = (byte)((src[i] >> 8) & 0xFF); - bytes[offset + 0] = (byte)(src[i] & 0xFF); - offset += 4; - } -} - -//byteתint -void CHuaGoCorrectDlg::bytesToInt(byte* bytes,UINT *des, int iLength) -{ - UINT iTemp[128] = {0}; - int offset = 0; - - for (int i = 0; i < iLength; i++) - { - int value = (int)((bytes[offset+0] & 0xFF) - | ((bytes[offset + 1] & 0xFF) << 8) - | ((bytes[offset + 2] & 0xFF) << 16) - | ((bytes[offset + 3] & 0xFF) << 24)); - - iTemp[i] = value; - offset += 4; - } - - memcpy(des,iTemp,128); - - return; -} - -int CHuaGoCorrectDlg::Mat2CImage(Mat *mat, CImage &img) -{ - if (!mat || mat->empty()) - return -1; - int nBPP = mat->channels() * 8; - img.Create(mat->cols, mat->rows, nBPP); - if (nBPP == 8) - { - static RGBQUAD pRGB[256]; - for (int i = 0; i < 256; i++) - pRGB[i].rgbBlue = pRGB[i].rgbGreen = pRGB[i].rgbRed = i; - img.SetColorTable(0, 256, pRGB); - } - uchar* psrc = mat->data; - uchar* pdst = (uchar*)img.GetBits(); - int imgPitch = img.GetPitch(); - for (int y = 0; y < mat->rows; y++) - { - memcpy(pdst, psrc, mat->cols*mat->channels());//mat->step is incorrect for those images created by roi (sub-images!) - psrc += mat->step; - pdst += imgPitch; - } - - return 0; -} - -static int Bcycle = 0; -static int WEcycle = 0; -static int WGcycle = 0; -void CHuaGoCorrectDlg::CorrectBlackImage() -{ - cv::Mat mPicFrontImage; - cv::Mat mPicBackImage; - cv::Mat mPicImage; - - Bcycle++; - CString csCycle; - csCycle.Format("ѭ%d", Bcycle); - GetDlgItem(IDC_STATIC_BLACK)->SetWindowText(csCycle); - - int ret = m_drv->aquire_image(mPicImage,0); - - if (ret) - { - XdPrint("Failed - could not acquire image"); - return; - } - - if (mPicImage.empty()) - { - XdPrint("Failed - could not acquire image"); - return; - } - - mPicFrontImage = mPicImage(cv::Rect(0,0,mPicImage.cols/2,mPicImage.rows)).clone(); - mPicBackImage = mPicImage(cv::Rect(mPicImage.cols/2,0,mPicImage.cols/2,mPicImage.rows)).clone(); - - vector rf; - vector gf; - vector bf; - vector rb; - vector gb; - vector bb; - - int nSizef = 0; - int nCountf = 0;//ͳ0ֵĴ - int maxValuef = 0; //ֵ - int minValuef = 0; //Сֵ - int sumf = 0; - double meanf = 0.0; - - int iAAddStep = 0; - int iAPlusStep = 0; - - if(bABlackImage) - { - histogram_bit32(mPicFrontImage.data,mPicFrontImage.rows,mPicFrontImage.cols,rf,gf,bf); - nSizef = rf.size(); - nCountf = count(rf.begin(),rf.end(),0);//ͳ0ֵĴ - /* - maxValuef = (int)*max_element(rf.begin(),rf.end()); //ֵ - minValuef = (int)*min_element(rf.begin(),rf.end()); //Сֵ - sumf = accumulate(rf.begin(), rf.end(), 0); - meanf = sumf / rf.size(); //ֵ - */ - if(nCountf > 10) - { - iAMinStep = iAMiddleStep; - - iAAddStep = iAMinStep + (iAMaxStep - iAMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[9] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[10] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[11] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[12] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[13] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[14] = iAAddStep; - - m_A4Dlg.m_sFlatCorrection.GrayCorrection[9] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[10] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[11] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[12] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[13] = iAAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[14] = iAAddStep; - - if(iAAddStep != iAMiddleStep) - { - iAMiddleStep = iAAddStep; - } - else - { - CString csMessage; - csMessage.Format("AҪ,0ִֵ%d,ֵΪ%d",nCountf,iAMaxStep); - MessageBox(csMessage); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - Bcycle = 0; - return; - } - } - } - else if(nCountf == 0) - { - iAMaxStep = iAMiddleStep; - - iAPlusStep = (iAMaxStep - (iAMaxStep - iAMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[9] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[10] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[11] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[12] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[13] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[14] = iAPlusStep; - - m_A4Dlg.m_sFlatCorrection.GrayCorrection[9] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[10] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[11] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[12] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[13] = iAPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[14] = iAPlusStep; - - if(iAPlusStep != iAMiddleStep) - { - iAMiddleStep = iAPlusStep; - } - else - { - CString csMessage; - csMessage.Format("AҪ,0ִֵ%d,СֵΪ%d",nCountf,iAPlusStep); - MessageBox(csMessage); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - Bcycle = 0; - return; - } - } - } - else - { - bABlackImage = false; - } - - CString csABlack; - csABlack.Format("%d---%d", nCountf,m_A4Dlg.m_sFlatCorrection.GrayCorrection[9]); - GetDlgItem(IDC_STATIC_AOFFSET)->SetWindowText(csABlack); - } - - int nSizeb = 0; - int nCountb = 0;//ͳ100ֵĴ - int maxValueb = 0; //ֵ - int minValueb = 0; //Сֵ - int sumb = 0; - double meanb = 0.0; //ֵ - - int iBAddStep = 0; - int iBPlusStep = 0; - - if(bBBlackImage) - { - //WriteLog("ͼƬ"); - histogram_bit32(mPicBackImage.data,mPicBackImage.rows,mPicBackImage.cols,rb,gb,bb); - nSizeb = rb.size(); - nCountb = count(rb.begin(),rb.end(),0);//ͳ100ֵĴ - /* - maxValueb = (int)*max_element(rb.begin(),rb.end()); //ֵ - minValueb = (int)*min_element(rb.begin(),rb.end()); //Сֵ - sumb = accumulate(rb.begin(), rb.end(), 0); - meanb = sumb / rb.size(); //ֵ - */ - - //WriteLog("ƫ"); - if(nCountb > 10) - { - iBMinStep = iBMiddleStep; - - iBAddStep = (iBMinStep + (iBMaxStep - iBMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[24] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[25] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[26] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[27] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[28] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[29] = iBAddStep; - - m_A4Dlg.m_sFlatCorrection.GrayCorrection[24] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[25] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[26] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[27] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[28] = iBAddStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[29] = iBAddStep; - - if(iBAddStep != iBMiddleStep) - { - iBMiddleStep = iBAddStep; - } - else - { - CString csMessage; - csMessage.Format("BҪ,0ִֵ%d,ֵΪ%d",nCountb,iBMaxStep); - MessageBox(csMessage); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - Bcycle = 0; - return; - } - } - } - else if(nCountb == 0) - { - iBMaxStep = iBMiddleStep; - - iBPlusStep = iBMaxStep - (iBMaxStep - iBMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[24] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[25] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[26] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[27] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[28] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[29] = iBPlusStep; - - m_A4Dlg.m_sFlatCorrection.GrayCorrection[24] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[25] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[26] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[27] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[28] = iBPlusStep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[29] = iBPlusStep; - - if(iBPlusStep != iBMiddleStep) - { - iBMiddleStep = iBPlusStep; - } - else - { - CString csMessage; - csMessage.Format("BҪ,0ִֵ%d,СֵΪ%d",nCountb,iBPlusStep); - MessageBox(csMessage); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - Bcycle = 0; - return; - } - } - } - else - { - bBBlackImage = false; - } - - CString csBBlack; - csBBlack.Format("%d---%d", nCountb,m_A4Dlg.m_sFlatCorrection.ColorCorrection[24]); - GetDlgItem(IDC_STATIC_BOFFSET)->SetWindowText(csBBlack); - } - - mPicImage.release(); - mPicFrontImage.release(); - mPicBackImage.release(); - - if(!bABlackImage && !bBBlackImage) - { - //MessageBox("У"); - //WriteLog("У"); - GetDlgItem(IDC_STATIC_STATUES)->SetWindowText(_T("У")); - m_pBlack.SetCheck(1); - - if(0 == m_pWExposure.GetCheck()) - { - CorrectWhiteImage(); - } - else - { - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(FALSE); - - m_bPause = true; - } - } - else - { - GetDlgItem(IDC_STATIC_STATUES)->SetWindowText(_T("ڴУ...")); - m_A4Dlg.WriteParamFile(); - CyclePro(); - } -} - -void CHuaGoCorrectDlg::CorrectWhiteImage() -{ - cv::Mat mPicWGImage; - cv::Mat mPicWCImage; - cv::Mat matGFImage; - cv::Mat matGBImage; - cv::Mat matCFImage; - cv::Mat matCBImage; - - WEcycle++; - CString csCycle; - csCycle.Format("ѭ%d", WEcycle); - GetDlgItem(IDC_STATIC_WE)->SetWindowText(csCycle); - - int retg = m_drv->aquire_image(mPicWGImage,1); - int retc = m_drv->aquire_image(mPicWCImage,3); - - if (retg && retc) - //if (retg) - { - XdPrint("Failed - could not acquire image"); - return; - } - - if (mPicWGImage.empty() && mPicWCImage.empty()) - //if (mPicWGImage.empty()) - { - XdPrint("Failed - could not acquire image"); - return; - } - - matGFImage = mPicWGImage(cv::Rect(0,0,mPicWGImage.cols/2,mPicWGImage.rows)).clone(); - matGBImage = mPicWGImage(cv::Rect(mPicWGImage.cols/2,0,mPicWGImage.cols/2,mPicWGImage.rows)).clone(); - - matCFImage = mPicWCImage(cv::Rect(0,0,mPicWCImage.cols/2,mPicWCImage.rows)).clone(); - matCBImage = mPicWCImage(cv::Rect(mPicWCImage.cols/2,0,mPicWCImage.cols/2,mPicWCImage.rows)).clone(); - - int igstep = 10; - if(bAGrayWhiteImage) - { - vector rgf; - vector ggf; - vector bgf; - int sumf = 0; - double meanf = 0.0; - - histogram_bit32(matGFImage.data,matGFImage.rows,matGFImage.cols,rgf,ggf,bgf); - sumf = accumulate(rgf.begin(), rgf.end(), 0); - meanf = sumf / rgf.size(); //ֵ - - if(meanf < 145.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[0] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[1] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[2] += igstep; - } - else if(meanf > 155.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[0] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[1] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[2] -= igstep; - } - else - { - bAGrayWhiteImage = false; - } - - CString csAGray,csAGraylog; - csAGray.Format("%0.1f---%d", meanf,m_A4Dlg.m_sFlatCorrection.GrayCorrection[0]); - csAGraylog.Format("ҶA棺%0.1f---%d", meanf,m_A4Dlg.m_sFlatCorrection.GrayCorrection[0]); - GetDlgItem(IDC_STATIC_AExposure)->SetWindowText(csAGray); - WriteLog(csAGraylog); - } - - if(bBGrayWhiteImage) - { - vector rgb; - vector ggb; - vector bgb; - int sumb = 0; - double meanb = 0.0; //ֵ - histogram_bit32(matGBImage.data,matGBImage.rows,matGBImage.cols,rgb,ggb,bgb); - sumb = accumulate(rgb.begin(), rgb.end(), 0); - meanb = sumb / rgb.size(); //ֵ - - if(meanb < 145.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[15] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[16] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[17] += igstep; - } - else if(meanb > 155.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[15] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[16] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[17] -= igstep; - } - else - { - bBGrayWhiteImage = false; - } - - CString csBGray,csBGraylog; - csBGray.Format("%0.1f---%d", meanb,m_A4Dlg.m_sFlatCorrection.GrayCorrection[15]); - csBGraylog.Format("ҶB棺%0.1f---%d", meanb,m_A4Dlg.m_sFlatCorrection.GrayCorrection[15]); - GetDlgItem(IDC_STATIC_BExposure)->SetWindowText(csBGray); - WriteLog(csBGraylog); - } - - if(bAColorWhiteImage) - { - vector rcf; - vector gcf; - vector bcf; - int sumrf = 0; - int sumgf = 0; - int sumbf = 0; - double meanrf = 0.0; - double meangf = 0.0; - double meanbf = 0.0; - - histogram_bit32(matCFImage.data,matCFImage.rows,matCFImage.cols,rcf,gcf,bcf); - sumrf = accumulate(rcf.begin(), rcf.end(), 0); - meanrf = sumrf / rcf.size(); //ֵ - sumgf = accumulate(gcf.begin(), gcf.end(), 0); - meangf = sumgf / gcf.size(); //ֵ - sumbf = accumulate(bcf.begin(), bcf.end(), 0); - meanbf = sumbf / bcf.size(); //ֵ - - int iAERAddStep = 0; - int iAEGAddStep = 0; - int iAEBAddStep = 0; - int iAERPlusStep = 0; - int iAEGPlusStep = 0; - int iAEBPlusStep = 0; - - if(bAcolr) - { - if(meanrf < 148.00) - { - iAERMinStep = iAERMiddleStep; - - iAERAddStep = iAERMinStep + (iAERMaxStep - iAERMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[0] = iAERAddStep; - - if(iAERAddStep != iAERMiddleStep) - { - iAERMiddleStep = iAERAddStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫARҪ,ֵΪ%d,ֵΪ%d",meanrf,iAERMaxStep); - MessageBox(csMessage); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else if(meanrf > 152.00) - { - iAERMaxStep = iAERMiddleStep; - - iAERPlusStep = (iAERMaxStep - (iAERMaxStep - iAERMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[0] = iAERPlusStep; - - if(iAERPlusStep != iAERMiddleStep) - { - iAERMiddleStep = iAERPlusStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫARҪ,ֵΪ%d,СֵΪ%d",meanrf,iAERPlusStep); - MessageBox(csMessage); - //MessageBox("׳ɫARҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else - { - bAcolr = false; - } - } - - if(bAcolg) - { - if(meangf < 148.00) - { - iAEGMinStep = iAEGMiddleStep; - - iAEGAddStep = iAEGMinStep + (iAEGMaxStep - iAEGMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[1] = iAEGAddStep; - - if(iAEGAddStep != iAEGMiddleStep) - { - iAEGMiddleStep = iAEGAddStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫAGҪ,ֵΪ%d,ֵΪ%d",meangf,iAEGMaxStep); - MessageBox(csMessage); - //MessageBox("׳ɫAGҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else if(meangf > 152.00) - { - iAEGMaxStep = iAEGMiddleStep; - - iAEGPlusStep = (iAEGMaxStep - (iAEGMaxStep - iAEGMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[1] = iAEGPlusStep; //m_tab.SetCurSel(1); - - if(iAEGPlusStep != iAEGMiddleStep) - { - iAEGMiddleStep = iAEGPlusStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫAGҪ,ֵΪ%d,СֵΪ%d",meangf,iAEGPlusStep); - MessageBox(csMessage); - //MessageBox("׳ɫAGҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else - { - bAcolg = false; - } - } - - if(bAcolb) - { - if(meanbf < 148.00) - { - iAEBMinStep = iAEBMiddleStep; - - iAEBAddStep = iAEBMinStep + (iAEBMaxStep - iAEBMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[2] = iAEBAddStep; - - if(iAEBAddStep != iAEBMiddleStep) - { - iAEBMiddleStep = iAEBAddStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫABҪ,ֵΪ%d,ֵΪ%d",meanbf,iAEBMaxStep); - MessageBox(csMessage); - //MessageBox("׳ɫABҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else if(meanbf > 152.00) - { - iAEBMaxStep = iAEBMiddleStep; - - iAEBPlusStep = (iAEBMaxStep - (iAEBMaxStep - iAEBMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[2] = iAEBPlusStep; - - if(iAEBPlusStep != iAEBMiddleStep) - { - iAEBMiddleStep = iAEBPlusStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫABҪ,ֵΪ%d,СֵΪ%d",meanbf,iAEBPlusStep); - MessageBox(csMessage); - //MessageBox("׳ɫABҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else - { - bAcolb = false; - } - } - - if(!bAcolr && !bAcolg && !bAcolb) - { - bAColorWhiteImage = false; - } - - CString csColorR,csColorG,csColorB,csAColorlog; - csColorR.Format("%0.1f---%d", meanrf,m_A4Dlg.m_sFlatCorrection.ColorCorrection[0]); - GetDlgItem(IDC_STATIC_ARExposure)->SetWindowText(csColorR); - - csColorG.Format("%0.1f---%d", meangf,m_A4Dlg.m_sFlatCorrection.ColorCorrection[1]); - GetDlgItem(IDC_STATIC_AGExposure)->SetWindowText(csColorG); - - csColorB.Format("%0.1f---%d", meanbf,m_A4Dlg.m_sFlatCorrection.ColorCorrection[2]); - GetDlgItem(IDC_STATIC_ABExposure)->SetWindowText(csColorB); - - csAColorlog.Format("ɫA棺R:%0.1f---%d, G:%0.1f---%d, B:%0.1f---%d", meanrf,m_A4Dlg.m_sFlatCorrection.ColorCorrection[0],meangf,m_A4Dlg.m_sFlatCorrection.ColorCorrection[1],meanbf,m_A4Dlg.m_sFlatCorrection.ColorCorrection[2]); - WriteLog(csAColorlog); - } - - - if(bBColorWhiteImage) - { - vector rcb; - vector gcb; - vector bcb; - int sumrb = 0; - int sumgb = 0; - int sumbb = 0; - double meanrb = 0.0; - double meangb = 0.0; - double meanbb = 0.0; - - histogram_bit32(matCBImage.data,matCBImage.rows,matCBImage.cols,rcb,gcb,bcb); - sumrb = accumulate(rcb.begin(), rcb.end(), 0); - meanrb = sumrb / rcb.size(); //ֵ - sumgb = accumulate(gcb.begin(), gcb.end(), 0); - meangb = sumgb / gcb.size(); //ֵ - sumbb = accumulate(bcb.begin(), bcb.end(), 0); - meanbb = sumbb / bcb.size(); //ֵ - - int iBERAddStep = 0; - int iBEGAddStep = 0; - int iBEBAddStep = 0; - int iBERPlusStep = 0; - int iBEGPlusStep = 0; - int iBEBPlusStep = 0; - - if(bBcolr) - { - if(meanrb < 148.00) - { - iBERMinStep = iBERMiddleStep; - - iBERAddStep = iBERMinStep + (iBERMaxStep - iBERMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[15] = iBERAddStep; - - if(iBERAddStep != iBERMiddleStep) - { - iBERMiddleStep = iBERAddStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫBRҪ,ֵΪ%d,ֵΪ%d",meanrb,iBERMaxStep); - MessageBox(csMessage); - //MessageBox("׳ɫBRҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else if(meanrb > 152.00) - { - iBERMaxStep = iBERMiddleStep; - - iBERPlusStep = (iBERMaxStep - (iBERMaxStep - iBERMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[15] = iBERPlusStep; - - if(iBERPlusStep != iBERMiddleStep) - { - iBERMiddleStep = iBERPlusStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫABҪ,ֵΪ%d,СֵΪ%d",meanrb,iBERPlusStep); - MessageBox(csMessage); - //MessageBox("׳ɫBRҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else - { - bBcolr = false; - } - } - - if(bBcolg) - { - if(meangb < 148.00) - { - iBEGMinStep = iBEGMiddleStep; - - iBEGAddStep = iBEGMinStep + (iBEGMaxStep - iBEGMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[16] = iBEGAddStep; - - if(iBEGAddStep != iBEGMiddleStep) - { - iBEGMiddleStep = iBEGAddStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫBGҪ,ֵΪ%d,ֵΪ%d",meangb,iBEGMaxStep); - MessageBox(csMessage); - //MessageBox("׳ɫBGҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else if(meangb > 152.00) - { - iBEGMaxStep = iBEGMiddleStep; - - iBEGPlusStep = (iBEGMaxStep - (iBEGMaxStep - iBEGMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[16] = iBEGPlusStep; - - if(iBEGPlusStep != iBEGMiddleStep) - { - iBEGMiddleStep = iBEGPlusStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫBGҪ,ֵΪ%d,СֵΪ%d",meangb,iBEGPlusStep); - MessageBox(csMessage); - //MessageBox("׳ɫBGҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else - { - bBcolg = false; - } - } - - if(bBcolb) - { - if(meanbb < 148.00) - { - iBEBMinStep = iBEBMiddleStep; - - iBEBAddStep = iBEBMinStep + (iBEBMaxStep - iBEBMinStep)/2; - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[17] = iBEBAddStep; - - if(iBEBAddStep != iBEBMiddleStep) - { - iBEBMiddleStep = iBEBAddStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫBGҪ,ֵΪ%d,ֵΪ%d",meanbb,iBEBMaxStep); - MessageBox(csMessage); - //MessageBox("׳ɫBBҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else if(meanbb > 152.00) - { - iBEBMaxStep = iBEBMiddleStep; - - iBEBPlusStep = (iBEBMaxStep - (iBEBMaxStep - iBEBMinStep)/2); - - m_A4Dlg.m_sFlatCorrection.ColorCorrection[17] = iBEBPlusStep; - - if(iBEBPlusStep != iBEBMiddleStep) - { - iBEBMiddleStep = iBEBPlusStep; - } - else - { - CString csMessage; - csMessage.Format("׳ɫBBҪ,ֵΪ%d,СֵΪ%d",meanbb,iBEBPlusStep); - MessageBox(csMessage); - //MessageBox("׳ɫBBҪ"); - if(m_bParamError != true) - { - InitButton(); - m_bPause = true; - m_bParamError = true; - WEcycle = 0; - return; - } - } - } - else - { - bBcolb = false; - } - } - - if(!bBcolr && !bBcolg && !bBcolb) - { - bBColorWhiteImage = false; - } - - CString csColorR,csColorG,csColorB,csBColorlog; - csColorR.Format("%0.1f---%d", meanrb,m_A4Dlg.m_sFlatCorrection.ColorCorrection[15]); - GetDlgItem(IDC_STATIC_BRExposure)->SetWindowText(csColorR); - - csColorG.Format("%0.1f---%d", meangb,m_A4Dlg.m_sFlatCorrection.ColorCorrection[16]); - GetDlgItem(IDC_STATIC_BGExposure)->SetWindowText(csColorG); - - csColorB.Format("%0.1f---%d", meanbb,m_A4Dlg.m_sFlatCorrection.ColorCorrection[17]); - GetDlgItem(IDC_STATIC_BBExposure)->SetWindowText(csColorB); - - csBColorlog.Format("ɫB棺R:%0.1f---%d, G:%0.1f---%d, B:%0.1f---%d", meanrb,m_A4Dlg.m_sFlatCorrection.ColorCorrection[15],meangb,m_A4Dlg.m_sFlatCorrection.ColorCorrection[16],meanbb,m_A4Dlg.m_sFlatCorrection.ColorCorrection[17]); - WriteLog(csBColorlog); - } - - mPicWGImage.release(); - mPicWCImage.release(); - matGFImage.release(); - matGBImage.release(); - matCFImage.release(); - matCBImage.release(); - - if(!bAGrayWhiteImage && !bBGrayWhiteImage && !bAColorWhiteImage && !bBColorWhiteImage) - { - //MessageBox("׳У"); - GetDlgItem(IDC_STATIC_STATUES2)->SetWindowText(_T("׳عУ")); - m_pWExposure.SetCheck(1); - - if(0 == m_pWGain.GetCheck()) - { - CorrectWhiteGain(); - } - else - { - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(FALSE); - - m_bPause = true; - } - } - else - { - GetDlgItem(IDC_STATIC_STATUES2)->SetWindowText(_T("ڴ׳عУ...")); - m_A4Dlg.WriteParamFile(); - CyclePro(); - } -} - -void CHuaGoCorrectDlg::CorrectWhiteGain() -{ - cv::Mat mPicWGImage; - cv::Mat mPicWCImage; - cv::Mat matGFImage; - cv::Mat matGBImage; - cv::Mat matCFImage; - cv::Mat matCBImage; - - WGcycle++; - CString csCycle; - csCycle.Format("ѭ%d", WGcycle); - GetDlgItem(IDC_STATIC_WG)->SetWindowText(csCycle); - - int retg = m_drv->aquire_image(mPicWGImage,1); - int retc = m_drv->aquire_image(mPicWCImage,3); - - if (retg && retc) - { - XdPrint("Failed - could not acquire image"); - return; - } - - if (mPicWGImage.empty() && mPicWCImage.empty()) - { - XdPrint("Failed - could not acquire image"); - return; - } - - matGFImage = mPicWGImage(cv::Rect(0,0,mPicWGImage.cols/2,mPicWGImage.rows)).clone(); - matGBImage = mPicWGImage(cv::Rect(mPicWGImage.cols/2,0,mPicWGImage.cols/2,mPicWGImage.rows)).clone(); - matCFImage = mPicWCImage(cv::Rect(0,0,mPicWCImage.cols/2,mPicWCImage.rows)).clone(); - matCBImage = mPicWCImage(cv::Rect(mPicWCImage.cols/2,0,mPicWCImage.cols/2,mPicWCImage.rows)).clone(); - - int igstep = 5; - if(bAGrayWhiteGain) - { - vector rgf; - vector ggf; - vector bgf; - int sumf = 0; - double meanf = 0.0; - //int kk = m_matFImage.channels(); - histogram_bit32(matGFImage.data,matGFImage.rows,matGFImage.cols,rgf,ggf,bgf); - sumf = accumulate(rgf.begin(), rgf.end(), 0); - meanf = sumf / rgf.size(); //ֵ - - if(meanf < 200.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[3] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[4] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[5] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[6] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[7] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[8] += igstep; - } - else if(meanf > 225.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[3] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[4] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[5] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[6] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[7] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[8] -= igstep; - } - else - { - bAGrayWhiteGain = false; - } - - CString csAGray; - csAGray.Format("%d", m_A4Dlg.m_sFlatCorrection.GrayCorrection[3]); - GetDlgItem(IDC_STATIC_AGain)->SetWindowText(csAGray); - } - - if(bBGrayWhiteGain) - { - vector rgb; - vector ggb; - vector bgb; - int sumb = 0; - double meanb = 0.0; //ֵ - histogram_bit32(matGBImage.data,matGBImage.rows,matGBImage.cols,rgb,ggb,bgb); - sumb = accumulate(rgb.begin(), rgb.end(), 0); - meanb = sumb / rgb.size(); //ֵ - - if(meanb < 200.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[18] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[19] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[20] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[21] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[22] += igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[23] += igstep; - } - else if(meanb > 225.00) - { - m_A4Dlg.m_sFlatCorrection.GrayCorrection[18] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[19] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[20] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[21] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[22] -= igstep; - m_A4Dlg.m_sFlatCorrection.GrayCorrection[23] -= igstep; - } - else - { - bBGrayWhiteGain = false; - } - - CString csBGray; - csBGray.Format("%d", m_A4Dlg.m_sFlatCorrection.GrayCorrection[18]); - GetDlgItem(IDC_STATIC_BGain)->SetWindowText(csBGray); - } - - int icstep = 5; - if(bAColorWhiteGain) - { - vector rcf; - vector gcf; - vector bcf; - int sumrf = 0; - int sumgf = 0; - int sumbf = 0; - double meanrf = 0.0; - double meangf = 0.0; - double meanbf = 0.0; - - //int kk = m_matFImage.channels(); - histogram_bit32(matCFImage.data,matCFImage.rows,matCFImage.cols,rcf,gcf,bcf); - sumrf = accumulate(rcf.begin(), rcf.end(), 0); - meanrf = sumrf / rcf.size(); //ֵ - sumgf = accumulate(gcf.begin(), gcf.end(), 0); - meangf = sumgf / gcf.size(); //ֵ - sumbf = accumulate(bcf.begin(), bcf.end(), 0); - meanbf = sumbf / bcf.size(); //ֵ - - if((meanrf < 200.00) || (meangf < 200.00) || (meanbf < 200.00)) - { - m_A4Dlg.m_sFlatCorrection.ColorCorrection[3] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[4] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[5] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[6] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[7] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[8] += igstep; - } - else if((meanrf > 225.00) || (meangf > 225.00) || (meanbf > 225.00)) - { - m_A4Dlg.m_sFlatCorrection.ColorCorrection[3] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[4] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[5] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[6] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[7] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[8] -= igstep; - } - else - { - bAColorWhiteGain = false; - } - - CString csColor; - csColor.Format("%d", m_A4Dlg.m_sFlatCorrection.ColorCorrection[3]); - GetDlgItem(IDC_STATIC_ACGain)->SetWindowText(csColor); - } - - if(bBColorWhiteGain) - { - vector rcb; - vector gcb; - vector bcb; - int sumrb = 0; - int sumgb = 0; - int sumbb = 0; - double meanrb = 0.0; - double meangb = 0.0; - double meanbb = 0.0; - - //int kk = m_matFImage.channels(); - histogram_bit32(matCBImage.data,matCBImage.rows,matCBImage.cols,rcb,gcb,bcb); - sumrb = accumulate(rcb.begin(), rcb.end(), 0); - meanrb = sumrb / rcb.size(); //ֵ - sumgb = accumulate(gcb.begin(), gcb.end(), 0); - meangb = sumgb / gcb.size(); //ֵ - sumbb = accumulate(bcb.begin(), bcb.end(), 0); - meanbb = sumbb / bcb.size(); //ֵ - - if((meanrb < 200.00) || (meangb < 200.00) || (meanbb < 200.00)) - { - m_A4Dlg.m_sFlatCorrection.ColorCorrection[18] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[19] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[20] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[21] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[22] += igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[23] += igstep; - } - else if((meanrb > 225.00) || (meangb > 225.00) || (meanbb > 225.00)) - { - m_A4Dlg.m_sFlatCorrection.ColorCorrection[18] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[19] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[20] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[21] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[22] -= igstep; - m_A4Dlg.m_sFlatCorrection.ColorCorrection[23] -= igstep; - } - else - { - bBColorWhiteGain = false; - } - - CString csColor; - csColor.Format("%d", m_A4Dlg.m_sFlatCorrection.ColorCorrection[18]); - GetDlgItem(IDC_STATIC_BCGain)->SetWindowText(csColor); - } - - mPicWGImage.release(); - mPicWCImage.release(); - matGFImage.release(); - matGBImage.release(); - matCFImage.release(); - matCBImage.release(); - - if(!bAGrayWhiteGain && !bBGrayWhiteGain && !bAColorWhiteGain && !bBColorWhiteGain) - { - GetDlgItem(IDC_STATIC_STATUES3)->SetWindowText(_T("׳У")); - m_pWGain.SetCheck(1); - CorrectFinish(); - } - else - { - GetDlgItem(IDC_STATIC_STATUES3)->SetWindowText(_T("ڴ׳У...")); - m_A4Dlg.WriteParamFile(); - CyclePro(); - } -} - -void CHuaGoCorrectDlg::CorrectFinish() -{ - for(int i = 0; i < 30; i++) - { - m_A4Dlg.m_sFlatCorrection.GrayFlat[i] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[i]; - } - - m_A4Dlg.m_sFlatCorrection.GrayFlat[3] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[4] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[5] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[6] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[7] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[8] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[18] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[19] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[20] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[21] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[22] += 24; - m_A4Dlg.m_sFlatCorrection.GrayFlat[23] += 24; - - for(int j = 0; j < 30; j++) - { - m_A4Dlg.m_sFlatCorrection.ColorFlat[j] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[j]; - } - - m_A4Dlg.m_sFlatCorrection.ColorFlat[3] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[4] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[5] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[6] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[7] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[8] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[18] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[19] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[20] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[21] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[22] += 24; - m_A4Dlg.m_sFlatCorrection.ColorFlat[23] += 24; - - m_A4Dlg.WriteParamFile(); - CorrectEndUpdate(); - - MessageBox("У"); - - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(FALSE); - - m_bPause = true; -} - -void CHuaGoCorrectDlg::ShowFrontImage(int index) -{ - m_matFImage.release(); - m_matBImage.release(); - - int retf = m_drv->aquire_image(m_matFImage,index); - int retb = m_drv->aquire_image(m_matBImage,index+2); - - if (retf && retb) - { - XdPrint("Failed - could not acquire image"); - return; - } - - if (m_matFImage.empty() && m_matBImage.empty()) - { - XdPrint("Failed - could not acquire image"); - return; - } - - CRect rectf,rectb; - cv::Size winfSize(rectf.right, rectf.bottom); - cv::Size winbSize(rectb.right, rectb.bottom); - - // Resize the source to the size of the destination image if necessary - cv::Mat cvImgFTmp(winfSize, CV_8UC3); - cv::Mat cvImgBTmp(winbSize, CV_8UC3); - - if (m_matFImage.size() != winfSize) - { - cv::resize(m_matFImage, cvImgFTmp, winfSize); - } - else - { - cvImgFTmp = m_matFImage; - } - - if (m_matBImage.size() != winbSize) - { - cv::resize(m_matBImage, cvImgBTmp, winbSize); - } - else - { - cvImgBTmp = m_matBImage; - } - - CImage imgfDst,imgbDst; - Mat2CImage(&cvImgFTmp, imgfDst); - Mat2CImage(&cvImgBTmp, imgbDst); - //imgfDst.Draw(GetDlgItem(IDC_STATIC_PIC1)->GetDC()->GetSafeHdc(), rectf); - //Sleep(500); - //imgbDst.Draw(GetDlgItem(IDC_STATIC_PIC2)->GetDC()->GetSafeHdc(), rectb); -} - -void CHuaGoCorrectDlg::ShowBackImage(int index) -{ - m_matFImage.release(); - m_matBImage.release(); - int retf = m_drv->aquire_image(m_matFImage,index); - int retb = m_drv->aquire_image(m_matBImage,index+1); - - if (retf && retb) - { - XdPrint("Failed - could not acquire image"); - return; - } - - if (m_matFImage.empty() && m_matBImage.empty()) - { - XdPrint("Failed - could not acquire image"); - return; - }; - - CRect rectf,rectb; - //GetDlgItem(IDC_STATIC_PIC1)->GetClientRect(&rectf); - //GetDlgItem(IDC_STATIC_PIC2)->GetClientRect(&rectb); - cv::Size winfSize(rectf.right, rectf.bottom); - cv::Size winbSize(rectb.right, rectb.bottom); - - // Resize the source to the size of the destination image if necessary - cv::Mat cvImgFTmp(winfSize, CV_8UC3); - cv::Mat cvImgBTmp(winbSize, CV_8UC3); - - if (m_matFImage.size() != winfSize) - { - cv::resize(m_matFImage, cvImgFTmp, winfSize); - } - else - { - cvImgFTmp = m_matFImage; - } - - if (m_matBImage.size() != winbSize) - { - cv::resize(m_matBImage, cvImgBTmp, winbSize); - } - else - { - cvImgBTmp = m_matBImage; - } - - CImage imgfDst,imgbDst; - Mat2CImage(&cvImgFTmp, imgfDst); - Mat2CImage(&cvImgBTmp, imgbDst); - //imgfDst.Draw(GetDlgItem(IDC_STATIC_PIC1)->GetDC()->GetSafeHdc(), rectf); - //Sleep(500); - //imgbDst.Draw(GetDlgItem(IDC_STATIC_PIC2)->GetDC()->GetSafeHdc(), rectb); -} - - -void CHuaGoCorrectDlg::CyclePro() -{ - - UINT gains_Color[30] = {0}; - UINT gains_Gray[30] = {0}; - byte gain_Color[512] = {0}; - byte gain_Gray[512] = {0}; - byte gain_data_Color[524] = {0}; - byte gain_data_Gray[524] = {0}; - - //WriteLog("ƫøֵ"); - - gains_Color[0] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[2]; - gains_Color[1] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[1]; - gains_Color[2] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[0]; - gains_Color[3] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[17]; - gains_Color[4] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[16]; - gains_Color[5] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[15]; - gains_Color[6] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[5]; - gains_Color[7] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[4]; - gains_Color[8] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[3]; - gains_Color[9] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[8]; - gains_Color[10] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[7]; - gains_Color[11] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[6]; - gains_Color[12] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[20]; - gains_Color[13] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[19]; - gains_Color[14] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[18]; - gains_Color[15] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[23]; - gains_Color[16] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[22]; - gains_Color[17] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[21]; - gains_Color[18] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[11]; - gains_Color[19] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[10]; - gains_Color[20] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[9]; - gains_Color[21] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[14]; - gains_Color[22] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[13]; - gains_Color[23] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[12]; - gains_Color[24] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[26]; - gains_Color[25] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[25]; - gains_Color[26] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[24]; - gains_Color[27] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[29]; - gains_Color[28] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[28]; - gains_Color[29] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[27]; - - gains_Gray[0] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[2]; - gains_Gray[1] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[1]; - gains_Gray[2] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[0]; - gains_Gray[3] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[17]; - gains_Gray[4] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[16]; - gains_Gray[5] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[15]; - gains_Gray[6] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[5]; - gains_Gray[7] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[4]; - gains_Gray[8] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[3]; - gains_Gray[9] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[8]; - gains_Gray[10] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[7]; - gains_Gray[11] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[6]; - gains_Gray[12] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[20]; - gains_Gray[13] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[19]; - gains_Gray[14] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[18]; - gains_Gray[15] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[23]; - gains_Gray[16] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[22]; - gains_Gray[17] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[21]; - gains_Gray[18] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[11]; - gains_Gray[19] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[10]; - gains_Gray[20] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[9]; - gains_Gray[21] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[14]; - gains_Gray[22] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[13]; - gains_Gray[23] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[12]; - gains_Gray[24] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[26]; - gains_Gray[25] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[25]; - gains_Gray[26] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[24]; - gains_Gray[27] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[29]; - gains_Gray[28] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[28]; - gains_Gray[29] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[27]; - - intToByte(gains_Color, gain_Color, 30); - intToByte(gains_Gray, gain_Gray, 30); - - Sleep(1000); - - USBCBA4 ubc_Color; - ubc_Color.u32_Command = SEND_COLORCORRECT_FLAT; - ubc_Color.u32_Count = 120; - memcpy(ubc_Color.buffer,gain_Color,512); - ubc_Color.u32_Data = 0; - int length_Color = sizeof(ubc_Color); - memmove(gain_data_Color,&ubc_Color,length_Color); - WriteLog("·ɫƽУָ"); - m_drv->SendColorCorrentFlat(gain_data_Color,length_Color); - - Sleep(2000); - - USBCBA4 ubc_Gray; - ubc_Gray.u32_Command = SEND_GRAYCORRECT_FLAT; - ubc_Gray.u32_Count = 120; - memcpy(ubc_Gray.buffer,gain_Gray,512); - ubc_Gray.u32_Data = 0; - int length_Gray = sizeof(ubc_Gray); - memmove(gain_data_Gray,&ubc_Gray,length_Gray); - WriteLog("·ҶƽУָ"); - m_drv->SendGrayCorrectFlat(gain_data_Gray,length_Gray); - - Sleep(2000); - - //OnBnClickedBtnFlat(); - //WriteLog("ͼƬ"); - m_drv->reset(); - //WriteLog("ʼƽУ"); - /* - m_drv->FlatA4Conrrect(); - Sleep(28000); - //WriteLog("У"); - - if(1 == m_pBlack.GetCheck()) - { - if(1 == m_pWExposure.GetCheck()) - { - if(0 == m_pWGain.GetCheck()) - { - CorrectWhiteGain(); - } - } - else - { - CorrectWhiteImage(); - } - } - else - { - CorrectBlackImage(); - } - */ + m_drv->StartFlat(true);//ɫ } void CHuaGoCorrectDlg::WriteLog(CString msg) { if (!msg.IsEmpty()) { - FILE *pFile = fopen(".//log//CorrectLog.log", "a+"); + FILE* pFile = fopen(".//log//CorrectLog.log", "a+"); if (pFile != NULL) { char cTime[32]; CTime currTime = CTime::GetCurrentTime(); - _snprintf(cTime, 30, "[%04d-%02d-%02d %02d:%02d:%02d]", - currTime.GetYear(), currTime.GetMonth(), currTime.GetDay(), + _snprintf(cTime, 30, "[%04d-%02d-%02d %02d:%02d:%02d]", + currTime.GetYear(), currTime.GetMonth(), currTime.GetDay(), currTime.GetHour(), currTime.GetMinute(), currTime.GetSecond()); fwrite(cTime, 1, strlen(cTime), pFile); fwrite(msg, 1, strlen(msg), pFile); @@ -2654,475 +429,11 @@ void CHuaGoCorrectDlg::WriteLog(CString msg) } } -void CHuaGoCorrectDlg::CorrectCMDUpdate() -{ - //GetDlgItem(IDC_STATIC_SHOW)->SetWindowText(_T("У·")); - //WriteLog(csCycle); - m_A4Dlg.SaveNewParam(m_A4Dlg.m_iSelIndex); - - UINT gains_Color[30] = {0}; - UINT Color[30] = {0}; - UINT gains_Gray[30] = {0}; - UINT Gray[30] = {0}; - byte gain_Color[512] = {0}; - byte Colors[512] = {0}; - byte gain_Gray[512] = {0}; - byte Grays[512] = {0}; - byte gain_data_Color[524] = {0}; - byte data_Color[524] = {0}; - byte gain_data_Gray[524] = {0}; - byte data_Gray[524] = {0}; - - gains_Color[0] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[0]; - gains_Color[1] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[1]; - gains_Color[2] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[2]; - gains_Color[3] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[15]; - gains_Color[4] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[16]; - gains_Color[5] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[17]; - gains_Color[6] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[3]; - gains_Color[7] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[4]; - gains_Color[8] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[5]; - gains_Color[9] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[6]; - gains_Color[10] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[7]; - gains_Color[11] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[8]; - gains_Color[12] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[18]; - gains_Color[13] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[19]; - gains_Color[14] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[20]; - gains_Color[15] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[21]; - gains_Color[16] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[22]; - gains_Color[17] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[23]; - gains_Color[18] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[9]; - gains_Color[19] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[10]; - gains_Color[20] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[11]; - gains_Color[21] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[12]; - gains_Color[22] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[13]; - gains_Color[23] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[14]; - gains_Color[24] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[24]; - gains_Color[25] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[25]; - gains_Color[26] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[26]; - gains_Color[27] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[27]; - gains_Color[28] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[28]; - gains_Color[29] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[29]; - - Color[0] = m_A4Dlg.m_sFlatCorrection.ColorFlat[0]; - Color[1] = m_A4Dlg.m_sFlatCorrection.ColorFlat[1]; - Color[2] = m_A4Dlg.m_sFlatCorrection.ColorFlat[2]; - Color[3] = m_A4Dlg.m_sFlatCorrection.ColorFlat[15]; - Color[4] = m_A4Dlg.m_sFlatCorrection.ColorFlat[16]; - Color[5] = m_A4Dlg.m_sFlatCorrection.ColorFlat[17]; - Color[6] = m_A4Dlg.m_sFlatCorrection.ColorFlat[3]; - Color[7] = m_A4Dlg.m_sFlatCorrection.ColorFlat[4]; - Color[8] = m_A4Dlg.m_sFlatCorrection.ColorFlat[5]; - Color[9] = m_A4Dlg.m_sFlatCorrection.ColorFlat[6]; - Color[10] = m_A4Dlg.m_sFlatCorrection.ColorFlat[7]; - Color[11] = m_A4Dlg.m_sFlatCorrection.ColorFlat[8]; - Color[12] = m_A4Dlg.m_sFlatCorrection.ColorFlat[18]; - Color[13] = m_A4Dlg.m_sFlatCorrection.ColorFlat[19]; - Color[14] = m_A4Dlg.m_sFlatCorrection.ColorFlat[20]; - Color[15] = m_A4Dlg.m_sFlatCorrection.ColorFlat[21]; - Color[16] = m_A4Dlg.m_sFlatCorrection.ColorFlat[22]; - Color[17] = m_A4Dlg.m_sFlatCorrection.ColorFlat[23]; - Color[18] = m_A4Dlg.m_sFlatCorrection.ColorFlat[9]; - Color[19] = m_A4Dlg.m_sFlatCorrection.ColorFlat[10]; - Color[20] = m_A4Dlg.m_sFlatCorrection.ColorFlat[11]; - Color[21] = m_A4Dlg.m_sFlatCorrection.ColorFlat[12]; - Color[22] = m_A4Dlg.m_sFlatCorrection.ColorFlat[13]; - Color[23] = m_A4Dlg.m_sFlatCorrection.ColorFlat[14]; - Color[24] = m_A4Dlg.m_sFlatCorrection.ColorFlat[24]; - Color[25] = m_A4Dlg.m_sFlatCorrection.ColorFlat[25]; - Color[26] = m_A4Dlg.m_sFlatCorrection.ColorFlat[26]; - Color[27] = m_A4Dlg.m_sFlatCorrection.ColorFlat[27]; - Color[28] = m_A4Dlg.m_sFlatCorrection.ColorFlat[28]; - Color[29] = m_A4Dlg.m_sFlatCorrection.ColorFlat[29]; - - gains_Gray[0] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[0]; - gains_Gray[1] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[1]; - gains_Gray[2] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[2]; - gains_Gray[3] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[15]; - gains_Gray[4] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[16]; - gains_Gray[5] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[17]; - gains_Gray[6] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[3]; - gains_Gray[7] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[4]; - gains_Gray[8] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[5]; - gains_Gray[9] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[6]; - gains_Gray[10] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[7]; - gains_Gray[11] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[8]; - gains_Gray[12] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[18]; - gains_Gray[13] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[19]; - gains_Gray[14] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[20]; - gains_Gray[15] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[21]; - gains_Gray[16] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[22]; - gains_Gray[17] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[23]; - gains_Gray[18] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[9]; - gains_Gray[19] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[10]; - gains_Gray[20] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[11]; - gains_Gray[21] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[12]; - gains_Gray[22] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[13]; - gains_Gray[23] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[14]; - gains_Gray[24] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[24]; - gains_Gray[25] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[25]; - gains_Gray[26] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[26]; - gains_Gray[27] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[27]; - gains_Gray[28] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[28]; - gains_Gray[29] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[29]; - - Gray[0] = m_A4Dlg.m_sFlatCorrection.GrayFlat[0]; - Gray[1] = m_A4Dlg.m_sFlatCorrection.GrayFlat[1]; - Gray[2] = m_A4Dlg.m_sFlatCorrection.GrayFlat[2]; - Gray[3] = m_A4Dlg.m_sFlatCorrection.GrayFlat[15]; - Gray[4] = m_A4Dlg.m_sFlatCorrection.GrayFlat[16]; - Gray[5] = m_A4Dlg.m_sFlatCorrection.GrayFlat[17]; - Gray[6] = m_A4Dlg.m_sFlatCorrection.GrayFlat[3]; - Gray[7] = m_A4Dlg.m_sFlatCorrection.GrayFlat[4]; - Gray[8] = m_A4Dlg.m_sFlatCorrection.GrayFlat[5]; - Gray[9] = m_A4Dlg.m_sFlatCorrection.GrayFlat[6]; - Gray[10] = m_A4Dlg.m_sFlatCorrection.GrayFlat[7]; - Gray[11] = m_A4Dlg.m_sFlatCorrection.GrayFlat[8]; - Gray[12] = m_A4Dlg.m_sFlatCorrection.GrayFlat[18]; - Gray[13] = m_A4Dlg.m_sFlatCorrection.GrayFlat[19]; - Gray[14] = m_A4Dlg.m_sFlatCorrection.GrayFlat[20]; - Gray[15] = m_A4Dlg.m_sFlatCorrection.GrayFlat[21]; - Gray[16] = m_A4Dlg.m_sFlatCorrection.GrayFlat[22]; - Gray[17] = m_A4Dlg.m_sFlatCorrection.GrayFlat[23]; - Gray[18] = m_A4Dlg.m_sFlatCorrection.GrayFlat[9]; - Gray[19] = m_A4Dlg.m_sFlatCorrection.GrayFlat[10]; - Gray[20] = m_A4Dlg.m_sFlatCorrection.GrayFlat[11]; - Gray[21] = m_A4Dlg.m_sFlatCorrection.GrayFlat[12]; - Gray[22] = m_A4Dlg.m_sFlatCorrection.GrayFlat[13]; - Gray[23] = m_A4Dlg.m_sFlatCorrection.GrayFlat[14]; - Gray[24] = m_A4Dlg.m_sFlatCorrection.GrayFlat[24]; - Gray[25] = m_A4Dlg.m_sFlatCorrection.GrayFlat[25]; - Gray[26] = m_A4Dlg.m_sFlatCorrection.GrayFlat[26]; - Gray[27] = m_A4Dlg.m_sFlatCorrection.GrayFlat[27]; - Gray[28] = m_A4Dlg.m_sFlatCorrection.GrayFlat[28]; - Gray[29] = m_A4Dlg.m_sFlatCorrection.GrayFlat[29]; - - intToByte(gains_Color, gain_Color, 30); - intToByte(Color, Colors, 30); - intToByte(gains_Gray, gain_Gray, 30); - intToByte(Gray, Grays, 30); - - Sleep(1000); - - USBCBA4 ubc_Color; - ubc_Color.u32_Command = SEND_COLORCORRECT_FLAT; - ubc_Color.u32_Count = 120; - memcpy(ubc_Color.buffer,gain_Color,512); - ubc_Color.u32_Data = 0; - int length_Color = sizeof(ubc_Color); - memmove(gain_data_Color,&ubc_Color,length_Color); - m_drv->SendColorCorrentFlat(gain_data_Color,length_Color); - - Sleep(1000); - - USBCBA4 ubc_Colors; - ubc_Colors.u32_Command = SEND_COLOR_FLAT; - ubc_Colors.u32_Count = 120; - memcpy(ubc_Colors.buffer,Colors,512); - ubc_Colors.u32_Data = 0; - int length_Colors = sizeof(ubc_Colors); - memmove(data_Color,&ubc_Colors,length_Colors); - m_drv->SendColorFlat(data_Color,length_Colors); - - Sleep(1000); - - USBCBA4 ubc_Gray; - ubc_Gray.u32_Command = SEND_GRAYCORRECT_FLAT; - ubc_Gray.u32_Count = 120; - memcpy(ubc_Gray.buffer,gain_Gray,512); - ubc_Gray.u32_Data = 0; - int length_Gray = sizeof(ubc_Gray); - memmove(gain_data_Gray,&ubc_Gray,length_Gray); - m_drv->SendGrayCorrectFlat(gain_data_Gray,length_Gray); - - Sleep(1000); - - USBCBA4 ubc_Grays; - ubc_Grays.u32_Command = SEND_GRAY_FLAT; - ubc_Grays.u32_Count = 120; - memcpy(ubc_Grays.buffer,Grays,512); - ubc_Grays.u32_Data = 0; - int length_Grays = sizeof(ubc_Grays); - memmove(data_Gray,&ubc_Grays,length_Grays); - m_drv->SendGrayFlat(data_Gray,length_Grays); - - //m_A4Dlg.WriteParamFile(); - - MessageBox(_T("Уóɹ")); -} - -void CHuaGoCorrectDlg::CorrectEndUpdate() -{ - UINT gains_Color[30] = {0}; - UINT Color[30] = {0}; - UINT gains_Gray[30] = {0}; - UINT Gray[30] = {0}; - byte gain_Color[512] = {0}; - byte Colors[512] = {0}; - byte gain_Gray[512] = {0}; - byte Grays[512] = {0}; - byte gain_data_Color[524] = {0}; - byte data_Color[524] = {0}; - byte gain_data_Gray[524] = {0}; - byte data_Gray[524] = {0}; - - gains_Color[0] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[2]; - gains_Color[1] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[1]; - gains_Color[2] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[0]; - gains_Color[3] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[17]; - gains_Color[4] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[16]; - gains_Color[5] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[15]; - gains_Color[6] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[5]; - gains_Color[7] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[4]; - gains_Color[8] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[3]; - gains_Color[9] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[8]; - gains_Color[10] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[7]; - gains_Color[11] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[6]; - gains_Color[12] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[20]; - gains_Color[13] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[19]; - gains_Color[14] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[18]; - gains_Color[15] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[23]; - gains_Color[16] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[22]; - gains_Color[17] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[21]; - gains_Color[18] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[11]; - gains_Color[19] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[10]; - gains_Color[20] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[9]; - gains_Color[21] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[14]; - gains_Color[22] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[13]; - gains_Color[23] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[12]; - gains_Color[24] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[26]; - gains_Color[25] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[25]; - gains_Color[26] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[24]; - gains_Color[27] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[29]; - gains_Color[28] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[28]; - gains_Color[29] = m_A4Dlg.m_sFlatCorrection.ColorCorrection[27]; - - Color[0] = m_A4Dlg.m_sFlatCorrection.ColorFlat[2]; - Color[1] = m_A4Dlg.m_sFlatCorrection.ColorFlat[1]; - Color[2] = m_A4Dlg.m_sFlatCorrection.ColorFlat[0]; - Color[3] = m_A4Dlg.m_sFlatCorrection.ColorFlat[17]; - Color[4] = m_A4Dlg.m_sFlatCorrection.ColorFlat[16]; - Color[5] = m_A4Dlg.m_sFlatCorrection.ColorFlat[15]; - Color[6] = m_A4Dlg.m_sFlatCorrection.ColorFlat[5]; - Color[7] = m_A4Dlg.m_sFlatCorrection.ColorFlat[4]; - Color[8] = m_A4Dlg.m_sFlatCorrection.ColorFlat[3]; - Color[9] = m_A4Dlg.m_sFlatCorrection.ColorFlat[8]; - Color[10] = m_A4Dlg.m_sFlatCorrection.ColorFlat[7]; - Color[11] = m_A4Dlg.m_sFlatCorrection.ColorFlat[6]; - Color[12] = m_A4Dlg.m_sFlatCorrection.ColorFlat[20]; - Color[13] = m_A4Dlg.m_sFlatCorrection.ColorFlat[19]; - Color[14] = m_A4Dlg.m_sFlatCorrection.ColorFlat[18]; - Color[15] = m_A4Dlg.m_sFlatCorrection.ColorFlat[23]; - Color[16] = m_A4Dlg.m_sFlatCorrection.ColorFlat[22]; - Color[17] = m_A4Dlg.m_sFlatCorrection.ColorFlat[21]; - Color[18] = m_A4Dlg.m_sFlatCorrection.ColorFlat[11]; - Color[19] = m_A4Dlg.m_sFlatCorrection.ColorFlat[10]; - Color[20] = m_A4Dlg.m_sFlatCorrection.ColorFlat[9]; - Color[21] = m_A4Dlg.m_sFlatCorrection.ColorFlat[14]; - Color[22] = m_A4Dlg.m_sFlatCorrection.ColorFlat[13]; - Color[23] = m_A4Dlg.m_sFlatCorrection.ColorFlat[12]; - Color[24] = m_A4Dlg.m_sFlatCorrection.ColorFlat[26]; - Color[25] = m_A4Dlg.m_sFlatCorrection.ColorFlat[25]; - Color[26] = m_A4Dlg.m_sFlatCorrection.ColorFlat[24]; - Color[27] = m_A4Dlg.m_sFlatCorrection.ColorFlat[29]; - Color[28] = m_A4Dlg.m_sFlatCorrection.ColorFlat[28]; - Color[29] = m_A4Dlg.m_sFlatCorrection.ColorFlat[27]; - - gains_Gray[0] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[2]; - gains_Gray[1] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[1]; - gains_Gray[2] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[0]; - gains_Gray[3] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[17]; - gains_Gray[4] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[16]; - gains_Gray[5] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[15]; - gains_Gray[6] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[5]; - gains_Gray[7] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[4]; - gains_Gray[8] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[3]; - gains_Gray[9] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[8]; - gains_Gray[10] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[7]; - gains_Gray[11] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[6]; - gains_Gray[12] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[20]; - gains_Gray[13] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[19]; - gains_Gray[14] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[18]; - gains_Gray[15] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[23]; - gains_Gray[16] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[22]; - gains_Gray[17] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[21]; - gains_Gray[18] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[11]; - gains_Gray[19] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[10]; - gains_Gray[20] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[9]; - gains_Gray[21] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[14]; - gains_Gray[22] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[13]; - gains_Gray[23] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[12]; - gains_Gray[24] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[26]; - gains_Gray[25] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[25]; - gains_Gray[26] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[24]; - gains_Gray[27] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[29]; - gains_Gray[28] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[28]; - gains_Gray[29] = m_A4Dlg.m_sFlatCorrection.GrayCorrection[27]; - - Gray[0] = m_A4Dlg.m_sFlatCorrection.GrayFlat[2]; - Gray[1] = m_A4Dlg.m_sFlatCorrection.GrayFlat[1]; - Gray[2] = m_A4Dlg.m_sFlatCorrection.GrayFlat[0]; - Gray[3] = m_A4Dlg.m_sFlatCorrection.GrayFlat[17]; - Gray[4] = m_A4Dlg.m_sFlatCorrection.GrayFlat[16]; - Gray[5] = m_A4Dlg.m_sFlatCorrection.GrayFlat[15]; - Gray[6] = m_A4Dlg.m_sFlatCorrection.GrayFlat[5]; - Gray[7] = m_A4Dlg.m_sFlatCorrection.GrayFlat[4]; - Gray[8] = m_A4Dlg.m_sFlatCorrection.GrayFlat[3]; - Gray[9] = m_A4Dlg.m_sFlatCorrection.GrayFlat[8]; - Gray[10] = m_A4Dlg.m_sFlatCorrection.GrayFlat[7]; - Gray[11] = m_A4Dlg.m_sFlatCorrection.GrayFlat[6]; - Gray[12] = m_A4Dlg.m_sFlatCorrection.GrayFlat[20]; - Gray[13] = m_A4Dlg.m_sFlatCorrection.GrayFlat[19]; - Gray[14] = m_A4Dlg.m_sFlatCorrection.GrayFlat[18]; - Gray[15] = m_A4Dlg.m_sFlatCorrection.GrayFlat[23]; - Gray[16] = m_A4Dlg.m_sFlatCorrection.GrayFlat[22]; - Gray[17] = m_A4Dlg.m_sFlatCorrection.GrayFlat[21]; - Gray[18] = m_A4Dlg.m_sFlatCorrection.GrayFlat[11]; - Gray[19] = m_A4Dlg.m_sFlatCorrection.GrayFlat[10]; - Gray[20] = m_A4Dlg.m_sFlatCorrection.GrayFlat[9]; - Gray[21] = m_A4Dlg.m_sFlatCorrection.GrayFlat[14]; - Gray[22] = m_A4Dlg.m_sFlatCorrection.GrayFlat[13]; - Gray[23] = m_A4Dlg.m_sFlatCorrection.GrayFlat[12]; - Gray[24] = m_A4Dlg.m_sFlatCorrection.GrayFlat[26]; - Gray[25] = m_A4Dlg.m_sFlatCorrection.GrayFlat[25]; - Gray[26] = m_A4Dlg.m_sFlatCorrection.GrayFlat[24]; - Gray[27] = m_A4Dlg.m_sFlatCorrection.GrayFlat[29]; - Gray[28] = m_A4Dlg.m_sFlatCorrection.GrayFlat[28]; - Gray[29] = m_A4Dlg.m_sFlatCorrection.GrayFlat[27]; - - intToByte(gains_Color, gain_Color, 30); - intToByte(Color, Colors, 30); - intToByte(gains_Gray, gain_Gray, 30); - intToByte(Gray, Grays, 30); - - Sleep(1000); - - USBCBA4 ubc_Color; - ubc_Color.u32_Command = SEND_COLORCORRECT_FLAT; - ubc_Color.u32_Count = 120; - memcpy(ubc_Color.buffer,gain_Color,512); - ubc_Color.u32_Data = 0; - int length_Color = sizeof(ubc_Color); - memmove(gain_data_Color,&ubc_Color,length_Color); - m_drv->SendColorCorrentFlat(gain_data_Color,length_Color); - - Sleep(1000); - - USBCBA4 ubc_Colors; - ubc_Colors.u32_Command = SEND_COLOR_FLAT; - ubc_Colors.u32_Count = 120; - memcpy(ubc_Colors.buffer,Colors,512); - ubc_Colors.u32_Data = 0; - int length_Colors = sizeof(ubc_Colors); - memmove(data_Color,&ubc_Colors,length_Colors); - m_drv->SendColorFlat(data_Color,length_Colors); - - Sleep(1000); - - USBCBA4 ubc_Gray; - ubc_Gray.u32_Command = SEND_GRAYCORRECT_FLAT; - ubc_Gray.u32_Count = 120; - memcpy(ubc_Gray.buffer,gain_Gray,512); - ubc_Gray.u32_Data = 0; - int length_Gray = sizeof(ubc_Gray); - memmove(gain_data_Gray,&ubc_Gray,length_Gray); - m_drv->SendGrayCorrectFlat(gain_data_Gray,length_Gray); - - Sleep(1000); - - USBCBA4 ubc_Grays; - ubc_Grays.u32_Command = SEND_GRAY_FLAT; - ubc_Grays.u32_Count = 120; - memcpy(ubc_Grays.buffer,Grays,512); - ubc_Grays.u32_Data = 0; - int length_Grays = sizeof(ubc_Grays); - memmove(data_Gray,&ubc_Grays,length_Grays); - m_drv->SendGrayFlat(data_Gray,length_Grays); - - //m_A4Dlg.WriteParamFile(); - - switch (m_A4Dlg.m_iSelIndex) - { - case 0: - m_A4Dlg.default0param(); - break; - case 1: - m_A4Dlg.default1param(); - break; - case 2: - m_A4Dlg.default2param(); - break; - case 3: - m_A4Dlg.default3param(); - break; - default: - break; - } - - GetDlgItem(IDC_STATIC_SHOW)->SetWindowText(_T("Уóɹ")); -} - -void CHuaGoCorrectDlg::OnBnClickedBtnFlatm() -{ - // TODO: ڴӿؼ֪ͨ - if (!m_drv->IsConnected()) - { - MessageBox("ɨδӣ"); - return; - } - - m_drv->reset(); - m_drv->DevStateChange(); - GetDlgItem(IDC_STATIC_NUM)->SetWindowText("0"); - GetDlgItem(IDC_STATIC_SHOW)->SetWindowText(_T("")); - - if (m_tab.GetCurSel() == 1) - { - - m_drv->FlatA4(); - -/* - if (b_review||b_suspend) - KillTimer(N_TIMER_SEC); - b_review = FALSE; - b_suspend = FALSE; - n_hour = 0; - n_minute = 0; - n_second = 0; - SetTimer(N_TIMER_SEC, N_TIME_SEC, NULL); - SetTimer(N_TIMER_SHOW, N_TIME_SHOW, NULL);*/ - - //Sleep(28000); - //MessageBox("У"); - - //OnBnClickedStopScan(); - } - else - { - - } -} - -void CHuaGoCorrectDlg::FSongleCorrect() -{ - m_drv->reset(); - m_drv->DevStateChange(); - - GetDlgItem(IDC_STATIC_SHOW)->SetWindowText(_T("")); - m_drv->FlatA4(); - - SetTimer(N_TIMER_SEC, N_TIME_SEC, NULL); - SetTimer(N_TIMER_SHOW, N_TIME_SHOW, NULL); -} - - void CHuaGoCorrectDlg::OnCancel() { // TODO: ڴרô/û - m_CISDlg.set_config(); - m_dis.updatadistorionparam(); - if (IDOK != AfxMessageBox("ȷҪ˳", MB_ICONQUESTION|MB_OKCANCEL)) - { + if (IDOK != AfxMessageBox("ȷҪ˳", MB_ICONQUESTION | MB_OKCANCEL)) + { return; } @@ -3131,323 +442,209 @@ void CHuaGoCorrectDlg::OnCancel() } -void CHuaGoCorrectDlg::OnBnClickedBtnBlackflat() -{ - // TODO: ڴӿؼ֪ͨ - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(TRUE); - - iAMaxStep = iAMaxStep * 2; - if(iAMaxStep > 255) - { - iAMaxStep = 255; - } - iAMiddleStep = iAMaxStep; - iAMinStep = 0; - - iBMaxStep = iBMaxStep * 2; - if(iBMaxStep > 255) - { - iBMaxStep = 255; - } - iBMiddleStep = iBMaxStep; - iBMinStep = 0; - - m_pWExposure.SetCheck(1); - m_pWGain.SetCheck(1); - m_bPause = false; -} - - -void CHuaGoCorrectDlg::OnBnClickedBtnExflat() -{ - // TODO: ڴӿؼ֪ͨ - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(TRUE); - - iAERMaxStep = iAERMaxStep * 2; - if(iAERMaxStep > 900) - { - iAERMaxStep = 900; - } - iAERMiddleStep = iAERMaxStep; - iAERMinStep = 0; - - iAEGMaxStep = iAEGMaxStep * 2; - if(iAEGMaxStep > 900) - { - iAEGMaxStep = 900; - } - iAEGMiddleStep = iAEGMaxStep; - iAEGMinStep = 0; - - iAEBMaxStep = iAEBMaxStep * 2; - if(iAEBMaxStep > 900) - { - iAEBMaxStep = 900; - } - iAEBMiddleStep = iAEBMaxStep; - iAEBMinStep = 0; - - iBERMaxStep = iBERMaxStep * 2; - if(iBERMaxStep > 900) - { - iBERMaxStep = 900; - } - iBERMiddleStep = iBERMaxStep; - iBERMinStep = 0; - - iBEGMaxStep = iBEGMaxStep * 2; - if(iBEGMaxStep > 900) - { - iBEGMaxStep = 900; - } - iBEGMiddleStep = iBEGMaxStep; - iBEGMinStep = 0; - - iBEBMaxStep = iBEBMaxStep * 2; - if(iBEBMaxStep > 900) - { - iBEBMaxStep = 900; - } - iBEBMiddleStep = iBEBMaxStep; - iBEBMinStep = 0; - - m_pBlack.SetCheck(1); - m_pWGain.SetCheck(1); - m_bPause = false; -} - - -void CHuaGoCorrectDlg::OnBnClickedBtnGainflat() -{ - // TODO: ڴӿؼ֪ͨ - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(TRUE); - - m_pBlack.SetCheck(1); - m_pWExposure.SetCheck(1); - m_bPause = false; -} - - -void CHuaGoCorrectDlg::OnBnClickedBtnContinue() -{ - // TODO: ڴӿؼ֪ͨ - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(TRUE); - - m_bPause = false; -} - - -void CHuaGoCorrectDlg::OnBnClickedBtnPause() -{ - // TODO: ڴӿؼ֪ͨ - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(FALSE); - - m_bPause = true; -} - void CHuaGoCorrectDlg::InitButton() { ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(FALSE); ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(FALSE); ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(FALSE); } void CHuaGoCorrectDlg::OnCbnSelChangeDpi() { // TODO: ڴӿؼ֪ͨ - m_iDpiIndex = m_ComboxDpi.GetCurSel(); + m_iDpiIndex = m_ComboxDpi.GetCurSel(); } void CHuaGoCorrectDlg::OnCbnSelChangeColor() { // TODO: ڴӿؼ֪ͨ - m_iColorIndex = m_ComboxColor.GetCurSel(); + m_iColorIndex = m_ComboxColor.GetCurSel(); + //m_drv->set_decompress_pix_type(0 == m_iColorIndex ? TWPT_GRAY : TWPT_RGB); +} - if(0 == m_iColorIndex) - { - m_drv->set_decompress_pix_type(TWPT_GRAY); - } - else - { - //m_drv->set_decompress_pix_type(TJPF_BGR); - m_drv->set_decompress_pix_type(TWPT_RGB); - } +void CHuaGoCorrectDlg::OnBnClickedStopScan() +{ + // TODO: ڴӿؼ֪ͨ } -void CHuaGoCorrectDlg::OnBnClickedConfirm() +//void CHuaGoCorrectDlg::OnTimer(UINT_PTR nIDEvent) +//{ +// // TODO: ڴϢ/Ĭֵ +// switch (nIDEvent) +// { +// case 1: +// { +// if (b_review == FALSE) +// { +// n_second++; +// if (n_second == 60) +// { +// n_second = 0; +// n_minute++; +// } +// if (n_minute == 60) +// { +// n_minute = 0; +// n_hour++; +// } +// } +// } +// case 2: +// { +// if (b_review == FALSE) +// { +// int h1, h2, m1, m2, s1, s2; +// h1 = n_hour / 10; +// h2 = n_hour % 10; +// m1 = n_minute / 10; +// m2 = n_minute % 10; +// s1 = n_second / 10; +// s2 = n_second % 10; +// s_hour.Format("%d%d", h1, h2); +// s_minute.Format("%d%d", m1, m2); +// s_second.Format("%d%d", s1, s2); +// } +// UpdateData(FALSE); +// } +// default: +// break; +// } +// +// CDialogEx::OnTimer(nIDEvent); +//} + +/// +/// ѡļ +/// +void CHuaGoCorrectDlg::OnBnClickedBtnSelectfile() +{ + CProgressCtrl* prb = (CProgressCtrl*)GetDlgItem(IDC_PRB_UPDATE); + prb->SetRange(0, 100); + CFileDialog ofd(TRUE, + _T(".zip"), + NULL, + OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + _TEXT("Upda Files (*.zip)|*.zip||)"), + NULL); + if (IDOK == ofd.DoModal()) + { + updateFilePath = ofd.GetPathName(); + SetDlgItemText(IDC_LB_FILEPATH, updateFilePath.c_str()); + } +} + +/// +/// ʼϵͳ +/// +void CHuaGoCorrectDlg::OnBnClickedBtnUpdate() +{ + if (m_updateThread.joinable()) + { + m_updateThread.join(); + } + + m_updateThread = std::thread(&CHuaGoCorrectDlg::updatefunc, this); +} + +/// +/// ɨUSB +/// +void CHuaGoCorrectDlg::OnBnClickedBtnRefresh() +{ + RefreshUSBList(); +} + +/// +/// USBбѡ仯 +/// +void CHuaGoCorrectDlg::OnCbnSelchangeCmbUsbs() +{ + int ret = m_Usbs.GetCurSel(); + if (ret >= 0) + { + if (m_drv.get() && m_drv->IsConnected()) + m_drv->close(); + + auto usbs = UsbScan_List::find_all_usb(); + if (usbs.size() > 0) + { + int vid, pid; + int j = 0; + for (auto i = usbs.begin(); i != usbs.end(); i++, j++) + { + if (j == ret) + { + if ((i->vid == 0x3072 && i->pid == 0x0139) || (i->vid == 0x3072 && i->pid == 0x0239)) + m_drv.reset(new gscan3399()); + else + { + m_drv.reset(new GScn_Drv()); + GetDlgItem(IDC_CKBUVMODEL)->EnableWindow(i->vid == 0x3072 && i->pid == 0x0300); + } + m_drv->open(i->vid, i->pid, 0); + std::string savepath(GetMainApp()->path.GetBuffer()); + m_drv->SetPath(savepath); + if (i->pid & 0x39) + { + GetDlgItem(IDC_CKBCORRECTMODE)->EnableWindow(TRUE); + m_A3dlg.GetDlgItem(IDC_STATICUVSP)->ShowWindow(SW_HIDE); + m_A3dlg.GetDlgItem(IDC_LBGUVSP)->ShowWindow(SW_HIDE); + m_A3dlg.GetDlgItem(IDC_BTNGETUVSP)->ShowWindow(SW_HIDE); + m_A3dlg.GetDlgItem(IDC_BTNSETUVSP)->ShowWindow(SW_HIDE); + } + else + { + GetDlgItem(IDC_CKBCORRECTMODE)->EnableWindow(FALSE); + ((CButton*)GetDlgItem(IDC_CKBCORRECTMODE))->SetCheck(FALSE); + m_A3dlg.GetDlgItem(IDC_STATICUVSP)->ShowWindow(SW_SHOW); + m_A3dlg.GetDlgItem(IDC_LBGUVSP)->ShowWindow(SW_SHOW); + m_A3dlg.GetDlgItem(IDC_BTNGETUVSP)->ShowWindow(SW_SHOW); + m_A3dlg.GetDlgItem(IDC_BTNSETUVSP)->ShowWindow(SW_SHOW); + } + + if (!m_drv->IsConnected()) + { + MessageBox(TEXT("open current select usb scanner failed"), TEXT("Notify"), MB_OK | MB_ICONINFORMATION); + } + + } + } + } + } +} + +/// +/// ʼɨ +/// +void CHuaGoCorrectDlg::OnBnClickedBtnstart() { - // TODO: ڴӿؼ֪ͨ m_iPicIndex = 0; + if (!m_drv->IsConnected()) { MessageBox("ɨδӣ"); return; } - + m_iColorIndex = m_ComboxColor.GetCurSel(); GetDlgItem(IDC_STATIC_NUM)->SetWindowText("0"); m_drv->DevStateChange(); m_drv->reset(); - Scan(); papercount = 0; - - //лtab3 - //m_tab.SetCurSel(2); - //RefreshTabChange(); + m_tab.SetCurSel(1); + RefreshTabChange(); + m_VisonDlg.SetEnableShow(true); } -void CHuaGoCorrectDlg::OnBnClickedBtnParamcfg() +/// +/// ֹͣɨ +/// +void CHuaGoCorrectDlg::OnBnClickedBtnstop() { - // TODO: ڴӿؼ֪ͨ - if (IDOK == m_ConfigParam.DoModal()) - { - ConfigParamUpdate(); - m_A4Dlg.LoadCfg(); - m_A4Dlg.default0param(); - - ((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLATM))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_BLACKFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_EXFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_GAINFLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_CONTINUE))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PARAMCFG))->EnableWindow(TRUE); - ((CButton*)GetDlgItem(IDC_BTN_PAUSE))->EnableWindow(TRUE); - } -} - -void CHuaGoCorrectDlg::ConfigParamUpdate() -{ - iAMaxStep = m_ConfigParam.m_AMaxStep; - iAMiddleStep = iAMaxStep; - iAMinStep = m_ConfigParam.m_AMinStep; - iBMaxStep = m_ConfigParam.m_BMaxStep; - iBMiddleStep = iBMaxStep; - iBMinStep = m_ConfigParam.m_BMinStep; - - iAERMaxStep = m_ConfigParam.m_AERMaxStep; - iAERMiddleStep = iAERMaxStep; - iAERMinStep = m_ConfigParam.m_AERMinStep; - - iAEGMaxStep = m_ConfigParam.m_AEGMaxStep; - iAEGMiddleStep = iAEGMaxStep; - iAEGMinStep = m_ConfigParam.m_AEGMinStep; - - iAEBMaxStep = m_ConfigParam.m_AEBMaxStep; - iAEBMiddleStep = iAEBMaxStep; - iAEBMinStep = m_ConfigParam.m_AEBMinStep; - - iBERMaxStep = m_ConfigParam.m_BERMaxStep; - iBERMiddleStep = iBERMaxStep; - iBERMinStep = m_ConfigParam.m_BERMinStep; - - iBEGMaxStep = m_ConfigParam.m_BEGMaxStep; - iBEGMiddleStep = iBEGMaxStep; - iBEGMinStep = m_ConfigParam.m_BEGMinStep; - - iBEBMaxStep = m_ConfigParam.m_BEBMaxStep; - iBEBMiddleStep = iBEBMaxStep; - iBEBMinStep = m_ConfigParam.m_BEBMinStep; - - iGainStep = m_ConfigParam.m_GainStep; -} - -afx_msg LRESULT CHuaGoCorrectDlg::OnMyMessage(/*HWND hWnd, UINT Msg, */ WPARAM wParam, LPARAM lParam) -{ - CString sParam = ""; - int nParam = 0; - nParam = wParam; - sParam.Format(_T("%d"),nParam); - - if(nParam != 200) - { - GetDlgItem(IDC_STATIC_NUM)->SetWindowText(sParam); - CString sMessage; - sMessage.Format("ǰɨ%sͼƬ,ۼʱ%s%s%s",sParam,s_hour,s_minute,s_second); - WriteLog(sMessage); - } - else - { - - KillTimer(N_TIMER_SEC); - KillTimer(N_TIMER_SHOW); -// GetDlgItem(IDC_STATIC_SHOW)->SetWindowText(_T("У")); -// Sleep(5000); -// FSongleCorrect(); - } - - return 0; -} - - -void CHuaGoCorrectDlg::OnBnClickedStopScan() -{ - // TODO: ڴӿؼ֪ͨ - b_suspend =!b_suspend; + b_suspend = !b_suspend; if (b_suspend) { KillTimer(N_TIMER_SEC); @@ -3464,104 +661,78 @@ void CHuaGoCorrectDlg::OnBnClickedStopScan() s_second.Format("%d%d", s1, s2); UpdateData(FALSE); } - m_drv->Stop_scan(); -// else -// { -// SetTimer(N_TIMER_SEC, N_TIME_SEC, NULL); -// SetTimer(N_TIMER_SHOW, N_TIME_SHOW, NULL); -// } } - -void CHuaGoCorrectDlg::OnTimer(UINT_PTR nIDEvent) +void CHuaGoCorrectDlg::updatefunc() { - // TODO: ڴϢ/Ĭֵ - switch (nIDEvent) + CProgressCtrl* prb = (CProgressCtrl*)GetDlgItem(IDC_PRB_UPDATE); + int ret= m_drv->Updata(updateFilePath, [this,&prb](long pos, long len) { + prb->SetRange32(0,len); + prb->SetPos(pos); + }); + if (ret == false) { - case 1: - { - if (b_review == FALSE) - { - n_second++; - if (n_second == 60) - { - n_second = 0; - n_minute++; - } - if (n_minute == 60) - { - n_minute = 0; - n_hour++; - } - /* - if (n_hour == 1) - n_hour = 0; - - if (n_minute == 5) - b_review = TRUE;*/ - } - else if (b_review) - { - n_hour = 0; - n_minute = 0; - n_second = 0; - s_hour.Format("%s", "Re"); - s_minute.Format("%s", "vi"); - s_second.Format("%s", "ew"); - } - } - case 2: - { - if (b_review == FALSE) - { - int h1, h2, m1, m2, s1, s2; - h1 = n_hour / 10; - h2 = n_hour % 10; - m1 = n_minute / 10; - m2 = n_minute % 10; - s1 = n_second / 10; - s2 = n_second % 10; - s_hour.Format("%d%d", h1, h2); - s_minute.Format("%d%d", m1, m2); - s_second.Format("%d%d", s1, s2); - } - else if (b_review) - { - n_hour = 0; - n_minute = 0; - n_second = 0; - s_hour.Format("%s", "Re"); - s_minute.Format("%s", "vi"); - s_second.Format("%s", "ew"); - } - UpdateData(FALSE); - } - default: - break; + MessageBox(TEXT("ʧܣ"), TEXT("ʾ"), MB_OK); } + else + { + MessageBox(TEXT("ɣ"), TEXT("ʾ"), MB_OK | MB_ICONINFORMATION); + } + //std::ifstream updatefile; + //updatefile.open(updateFilePath, std::ios_base::in | std::ios_base::binary); + //if (!updatefile.is_open()) + //{ + // MessageBox(TEXT("ļʧܣ"), TEXT("ʾ"), MB_OK); + //} + //CProgressCtrl* prb = (CProgressCtrl*)GetDlgItem(IDC_PRB_UPDATE); + //updatefile.seekg(0, std::ios::end); + //size_t length = updatefile.tellg(); + //prb->SetRange32(0, length); + //updatefile.seekg(0, std::ios::beg); + //USBCB pre_update = { PRE_UPGRADE,0,length }; + //m_drv->m_usb->write_bulk(&pre_update, sizeof(pre_update)); + //size_t nreaded = 0; + //size_t nleft = length; + //int buffersize = 1024 * 1024; + //if (length <= buffersize)//С1MB + //{ + // char* uotstream = new char[length]; + // USBCB update = { START_UPGRADE,0,length }; + // m_drv->m_usb->write_bulk(&update, sizeof(update)); + // updatefile.read(uotstream, length); + // m_drv->m_usb->write_bulk(uotstream, length); + // m_drv->m_usb->read_bulk(&update, sizeof(update)); + // if (update.u32_Count != length) + // MessageBox(TEXT("ʧܣ"), TEXT("棡"), MB_OK); + // delete[] uotstream; + //} + //else + //{ + // while (true) + // { + // int ntotransfer; + // if (nleft < buffersize) + // ntotransfer = nleft; + // else + // ntotransfer = buffersize; + // USBCB update = { START_UPGRADE,0,ntotransfer }; + // m_drv->m_usb->write_bulk(&update, sizeof(update)); + // std::vector data; + // data.resize(ntotransfer); + // updatefile.read(data.data(), ntotransfer); + // m_drv->m_usb->write_bulk(data.data(), ntotransfer); + // m_drv->m_usb->read_bulk(&update, sizeof(update)); + // nreaded += ntotransfer; + // nleft -= ntotransfer; + // prb->SetPos(nreaded); + // if (nreaded >= length) + // break; + // this_thread::sleep_for(std::chrono::milliseconds(10)); + // } + //} - CDialogEx::OnTimer(nIDEvent); -} - - - - -void CHuaGoCorrectDlg::OnCbnSelchangeCombo1() -{ - // TODO: ڴӿؼ֪ͨ - CString num; - CString text; - int cursel = Version.GetCurSel(); - num.Format("%d", cursel); - if(m_drv->isusbopened()) - m_drv->close(); - - if(m_drv->device_id==0) - MessageBox(TEXT("δҵ豸!"), TEXT("ʾ"), MB_OK | MB_ICONWARNING); - m_drv->open(Version_id[cursel][0], Version_id[cursel][1], 0); - if (!m_drv->isusbopened()) - MessageBox(TEXT("δҵ豸!"), TEXT("ʾ"), MB_OK | MB_ICONWARNING); - ::WritePrivateProfileString(_T("USB"), _T("Version_num"), _T(num), INI_FILE_NAME); - + //USBCB updatefinished = { UPDATE_FINISHED,0,0 }; + //m_drv->m_usb->write_bulk(&updatefinished, sizeof(updatefinished)); + //MessageBox(TEXT("̼ɣ"), TEXT("ʾ"), MB_OK | MB_ICONINFORMATION); } diff --git a/HuaGoCorrect/HuaGoCorrectDlg.h b/HuaGoCorrect/HuaGoCorrectDlg.h index c0cff1d..5c6e0f1 100644 --- a/HuaGoCorrect/HuaGoCorrectDlg.h +++ b/HuaGoCorrect/HuaGoCorrectDlg.h @@ -6,42 +6,41 @@ #include "afxcmn.h" #include "HuaGoCorrect.h" #include "DefHSCommon.h" -#include "gscn_drv.h" +#include "IScanner.h" #include "Config.h" #include "twain.h" #include "A3.h" #include "A4.h" -#include "CIS.h" -#include "m_Dis.h" #include "ConfigParam.h" #include "afxwin.h" #include "CVISON.h" -#include -#include "ImageApply.h" -#include "ImageApplyAdjustColors.h" -#include "ImageApplyAutoCrop.h" -#include "ImageApplyBWBinaray.h" -#include "ImageApplyChannel.h" -#include "ImageApplyCrop.h" -#include "ImageApplyDiscardBlank.h" -#include "ImageApplyResize.h" -#include "ImageApplyRotation.h" -#include "ImageApplySharpen.h" -using namespace std; +#include "scn_usb.h" +#include "JsonConfig.h" #define WM_MYMESSAGE (WM_USER+100) -enum TwSS : ushort +union HG_ScanConfiguration { - A4 = 1, - A3 = 11, - USStatement = 52 + struct + { + unsigned int pageSize : 5; + unsigned int isColor : 1; + unsigned int dpi : 2; + unsigned int doubleFeeded : 1; + unsigned int enableUV : 1; + unsigned int enableLed : 1; + unsigned int reversed1 : 6; + unsigned int isCorrect : 1; + unsigned int dstHeight : 8; + unsigned int reversed2 : 6; + } params; + unsigned int value; }; // CHuaGoCorrectDlg Ի class CHuaGoCorrectDlg : public CDialogEx { -// + // public: CHuaGoCorrectDlg(CWnd* pParent = NULL); // ׼캯 @@ -52,158 +51,68 @@ public: bool ls_flat; int papercount; int m_iPicIndex; - int m_iflatIndex; - int m_iDpiIndex; int m_iColorIndex; - int iAMaxStep; - int iAMiddleStep; - int iAMinStep; - int iBMaxStep; - int iBMiddleStep; - int iBMinStep; - - int iAERMaxStep; - int iAERMiddleStep; - int iAERMinStep; - int iAEGMaxStep; - int iAEGMiddleStep; - int iAEGMinStep; - int iAEBMaxStep; - int iAEBMiddleStep; - int iAEBMinStep; - int iBERMaxStep; - int iBERMiddleStep; - int iBERMinStep; - int iBEGMaxStep; - int iBEGMiddleStep; - int iBEGMinStep; - int iBEBMaxStep; - int iBEBMiddleStep; - int iBEBMinStep; - int iGainStep; - int n_hour; int n_minute; int n_second; - int usb_vid; - int usb_pid; BOOL b_review; BOOL b_suspend; - - CConfig m_Cfg; - CA3 m_A3Dlg; CA4 m_A4Dlg; - CIS m_CISDlg; - m_Dis m_dis; CVISON m_VisonDlg; + CA3 m_A3dlg; CConfigParam m_ConfigParam; - shared_ptr m_drv; + std::shared_ptr m_drv; CRect tabRect; // ǩؼͻλúʹС void Scan(); void RefreshTabChange(); - int Mat2CImage(Mat *mat, CImage &img); - - cv::Mat m_matFImage; - cv::Mat m_matBImage; - int Version_id[5][2] = { {0x064b,0x7823},{0x3072,0x0100},{0x3072 ,0x0200},{0x3072 ,0x0300},{0x3072 ,0x0400} }; - void ShowFrontImage(int index); - void ShowBackImage(int index); - void A3ParamSet(); - void A4ParamSet(); - void intToByte(UINT *src,byte *bytes,int iLength); - void bytesToInt(byte* bytes,UINT *des, int iLength); - - void CorrectBlackImage(); - void CorrectWhiteImage(); - void CorrectWhiteGain(); - void CorrectFinish(); void WriteLog(CString msg); - void CyclePro(); - - void CorrectCMDUpdate(); - void CorrectEndUpdate(); - void ConfigParamUpdate(); void InitButton(); - void FSongleCorrect(); - bool bABlackImage; - bool bBBlackImage; - - bool bAGrayWhiteImage; - bool bBGrayWhiteImage; - bool bAColorWhiteImage; - bool bAcolr; - bool bAcolg; - bool bAcolb; - bool bBColorWhiteImage; - bool bBcolr; - bool bBcolg; - bool bBcolb; - - bool bAGrayWhiteGain; - bool bBGrayWhiteGain; - bool bAColorWhiteGain; - bool bBColorWhiteGain; - std::vector> m_iaList; - protected: +protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧ - // ʵ protected: HICON m_hIcon; - - HANDLE m_hThread; BOOL m_bExit; - void CorrectThreadFunc(); - static unsigned WINAPI CorrectThread(void* pCorrect); - // ɵϢӳ亯 virtual BOOL OnInitDialog(); - afx_msg void OnSysCommand(UINT nID, LPARAM lParam); + afx_msg void EnableUIItem(bool enbale); + bool RefreshUSBList(); + void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() public: CTabCtrl m_tab; - afx_msg BOOL PreCreateWindow(CREATESTRUCT& cs); - afx_msg void OnTcnSelChangeTab(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnBnClickedCheckparamset(); + afx_msg void OnTcnSelChangeTab(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnBnClickedCheckparamset(); afx_msg void OnBnClickedCheckparamread(); - void UpdateList(CONFIGPARAMS configParams, bool canUpdate); afx_msg void OnBnClickedBtnFlat(); - CButton m_pBlack; - CButton m_pWExposure; - CButton m_pWGain; - afx_msg void OnBnClickedBtnFlatm(); CCriticalSection m_deviceLock; virtual void OnCancel(); - BOOL m_bPause; - BOOL m_bParamError; - afx_msg void OnBnClickedBtnBlackflat(); - afx_msg void OnBnClickedBtnExflat(); - afx_msg void OnBnClickedBtnGainflat(); - afx_msg void OnBnClickedBtnContinue(); - afx_msg void OnBnClickedBtnPause(); CComboBox m_ComboxDpi; CComboBox m_ComboxColor; + CComboBox m_Usbs; afx_msg void OnCbnSelChangeDpi(); afx_msg void OnCbnSelChangeColor(); - afx_msg void OnBnClickedConfirm(); - afx_msg void OnBnClickedBtnParamcfg(); - CButton m_check_FpgaFlat; + CButton m_A4Scanner; CString s_hour; CString s_minute; CString s_second; afx_msg void OnBnClickedStopScan(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - afx_msg LRESULT OnMyMessage(/*HWND hWnd, UINT Msg,*/ WPARAM w,LPARAM l); - CButton close_butten; - CComboBox twss; - CComboBox duplex; - CComboBox Version; - afx_msg void OnCbnSelchangeCombo1(); + //afx_msg void OnTimer(UINT_PTR nIDEvent); + afx_msg void OnBnClickedBtnSelectfile(); + afx_msg void OnBnClickedBtnUpdate(); + afx_msg void OnBnClickedBtnRefresh(); + afx_msg void OnCbnSelchangeCmbUsbs(); + afx_msg void OnBnClickedBtnstart(); + afx_msg void OnBnClickedBtnstop(); +private: + std::string updateFilePath; + std::thread m_updateThread; + void updatefunc(); }; diff --git a/HuaGoCorrect/HuaGoScan.ini b/HuaGoCorrect/HuaGoScan.ini index 02442c6..38d9b46 100644 --- a/HuaGoCorrect/HuaGoScan.ini +++ b/HuaGoCorrect/HuaGoScan.ini @@ -1,131 +1,131 @@ [ColorCorrection] ;ɫУģʽ -FRExposure=442 -FGExposure=629 -FBExposure=998 -F1Gain=45 -F2Gain=45 -F3Gain=45 -F4Gain=45 -F5Gain=45 -F6Gain=45 -F1Offset=122 -F2Offset=122 -F3Offset=122 -F4Offset=122 -F5Offset=122 -F6Offset=122 -BRExposure=416 -BGExposure=682 -BBExposure=792 -B1Gain=45 -B2Gain=45 -B3Gain=45 -B4Gain=45 -B5Gain=45 -B6Gain=45 -B1Offset=120 -B2Offset=120 -B3Offset=120 -B4Offset=120 -B5Offset=120 -B6Offset=120 -[ColorFlat] -;ɫ -FRExposure=402 -FGExposure=649 -FBExposure=958 -F1Gain=60 -F2Gain=60 -F3Gain=60 -F4Gain=60 -F5Gain=60 -F6Gain=60 -F1Offset=122 -F2Offset=122 -F3Offset=122 -F4Offset=122 -F5Offset=122 -F6Offset=122 -BRExposure=376 -BGExposure=702 -BBExposure=752 -B1Gain=60 -B2Gain=60 -B3Gain=60 -B4Gain=60 -B5Gain=60 -B6Gain=60 -B1Offset=120 -B2Offset=120 -B3Offset=120 -B4Offset=120 -B5Offset=120 -B6Offset=120 -[GrayCorrection] -;ҶУģʽ -FRExposure=271 -FGExposure=271 -FBExposure=271 -F1Gain=30 -F2Gain=30 -F3Gain=30 +FRExposure=524 +FGExposure=812 +FBExposure=1100 +F1Gain=444 +F2Gain=754 +F3Gain=990 F4Gain=30 F5Gain=30 F6Gain=30 -F1Offset=122 -F2Offset=122 -F3Offset=122 -F4Offset=122 -F5Offset=122 -F6Offset=122 -BRExposure=256 -BGExposure=256 -BBExposure=256 -B1Gain=30 -B2Gain=30 -B3Gain=30 -B4Gain=30 -B5Gain=30 -B6Gain=30 -B1Offset=120 -B2Offset=120 -B3Offset=120 -B4Offset=120 -B5Offset=120 -B6Offset=120 -[GrayFlat] -;Ҷ -FRExposure=271 -FGExposure=271 -FBExposure=271 -F1Gain=47 -F2Gain=47 -F3Gain=47 +F1Offset=30 +F2Offset=30 +F3Offset=30 +F4Offset=30 +F5Offset=30 +F6Offset=30 +BRExposure=30 +BGExposure=30 +BBExposure=30 +B1Gain=123 +B2Gain=123 +B3Gain=123 +B4Gain=123 +B5Gain=123 +B6Gain=123 +B1Offset=118 +B2Offset=118 +B3Offset=118 +B4Offset=118 +B5Offset=118 +B6Offset=118 +[ColorFlat] +;ɫ +FRExposure=289 +FGExposure=289 +FBExposure=289 +F1Gain=257 +F2Gain=257 +F3Gain=257 +F4Gain=30 +F5Gain=30 +F6Gain=30 +F1Offset=30 +F2Offset=30 +F3Offset=30 +F4Offset=30 +F5Offset=30 +F6Offset=30 +BRExposure=30 +BGExposure=30 +BBExposure=30 +B1Gain=120 +B2Gain=120 +B3Gain=120 +B4Gain=120 +B5Gain=120 +B6Gain=120 +B1Offset=115 +B2Offset=115 +B3Offset=115 +B4Offset=115 +B5Offset=115 +B6Offset=115 +[GrayCorrection] +;ҶУģʽ +FRExposure=524 +FGExposure=812 +FBExposure=1100 +F1Gain=444 +F2Gain=754 +F3Gain=990 F4Gain=47 F5Gain=47 F6Gain=47 -F1Offset=122 -F2Offset=122 -F3Offset=122 -F4Offset=122 -F5Offset=122 -F6Offset=122 -BRExposure=256 -BGExposure=256 -BBExposure=256 -B1Gain=47 -B2Gain=47 -B3Gain=47 -B4Gain=47 -B5Gain=47 -B6Gain=47 -B1Offset=120 -B2Offset=120 -B3Offset=120 -B4Offset=120 -B5Offset=120 -B6Offset=120 +F1Offset=47 +F2Offset=47 +F3Offset=47 +F4Offset=47 +F5Offset=47 +F6Offset=47 +BRExposure=47 +BGExposure=47 +BBExposure=47 +B1Gain=123 +B2Gain=123 +B3Gain=123 +B4Gain=123 +B5Gain=123 +B6Gain=123 +B1Offset=118 +B2Offset=118 +B3Offset=118 +B4Offset=118 +B5Offset=118 +B6Offset=118 +[GrayFlat] +;Ҷ +FRExposure=289 +FGExposure=289 +FBExposure=289 +F1Gain=257 +F2Gain=257 +F3Gain=257 +F4Gain=47 +F5Gain=47 +F6Gain=47 +F1Offset=47 +F2Offset=47 +F3Offset=47 +F4Offset=47 +F5Offset=47 +F6Offset=47 +BRExposure=47 +BGExposure=47 +BBExposure=47 +B1Gain=120 +B2Gain=120 +B3Gain=120 +B4Gain=120 +B5Gain=120 +B6Gain=120 +B1Offset=115 +B2Offset=115 +B3Offset=115 +B4Offset=115 +B5Offset=115 +B6Offset=115 [GrayBlack] ;ҶȰ AGMaxStep=255 @@ -149,33 +149,6 @@ BCBMinStep=0 [GainStep] ;沽 ABGainStep=24 -[ObjValue] -;Ŀֵ -objvalue_x1=0 -objvalue_x2=0 -objvalue_x3=0 -objvalue_y1=0 -objvalue_y2=0 -objvalue_y3=0 -[LimitOffset] -;ƫֵ -limitoffset_x1=0 -limitoffset_x2=0 -limitoffset_x3=0 -limitoffset_y1=0 -limitoffset_y2=0 -limitoffset_y3=0 -[CIS] -;cis -channle=1 -total_up=28 -total_low=10 -total_area_up=298 -total_area_low=300 -[USB] -;USB豸VIDPID -VID=0x064b -PID=0x7823 -Version_num=1 + diff --git a/HuaGoCorrect/IScanner.h b/HuaGoCorrect/IScanner.h new file mode 100644 index 0000000..fe6dbec --- /dev/null +++ b/HuaGoCorrect/IScanner.h @@ -0,0 +1,63 @@ +#pragma once +#include "ImageMatQueue.h" +#include "IUsb.h" +#include "commondef.h" +#include + +class IScanner +{ +public: + virtual ~IScanner() {}; + virtual void open(int vid, int pid, int index)=0; + virtual int aquire_image(std::string& image, int num)=0; + virtual bool IsConnected() = 0; + virtual std::string GetFWVersion() = 0; + virtual void SetFWVersion() = 0; + virtual std::string GetSerialNum() = 0; + virtual void SetSerialNum(std::string serial) = 0; + virtual void SetRatio(int tyepe, int ration) = 0; + virtual void GetRatio(int type, int& ratio) = 0; + virtual void Reboot() = 0; + virtual void PowerOff() = 0; + virtual bool is_scan() = 0; + virtual bool Get_Scanner_PaperOn() = 0; + virtual void Config_Scanner(HGScanConfig config) = 0; + virtual void Scanner_StartScan(unsigned short count) = 0; + virtual void Stop_scan() = 0; + virtual void ResetScanner() = 0; + virtual bool Get_IsImageQueueEmpty() = 0; + virtual void reset() = 0; + virtual void run() = 0; + virtual void ActiveteUSB() = 0; + virtual int GetScanNum() = 0; + virtual void ClrRollerNum() = 0; + virtual void ClrScanNum() = 0; + virtual void SendFlatData(CorrectParam param, int index) = 0; + virtual CaptureParams GetFlatData() = 0; + virtual void StartFlat(bool iscolor) = 0; + virtual void DevStateChange() = 0; + virtual int getMatSum() = 0; + virtual void close() = 0; + virtual void GetExpose(int& Aside, int& Bside) = 0; + virtual void SetExpose(int aside, int bside) = 0; + virtual void GetSptime(int type, int& time) = 0; + virtual void SetSptime(int type, int time) = 0; + virtual void GetSleepTime(int& sleeptime) = 0; + virtual void SetSleepTime(int sleeptime) = 0; + virtual bool Updata(std::string filename, std::function func) = 0; + + void SetPath(std::string csFilePath) + { + csPath = csFilePath; + } + + std::string GetPath() + { + return csPath; + } + std::shared_ptr m_usb; +//protected: + ImageMatQueue m_pImages; + HWND h; + std::string csPath; +}; \ No newline at end of file diff --git a/HuaGoCorrect/IUsb.h b/HuaGoCorrect/IUsb.h new file mode 100644 index 0000000..2d3a17d --- /dev/null +++ b/HuaGoCorrect/IUsb.h @@ -0,0 +1,18 @@ +#pragma once +typedef void(*usbhotplug_callback)(bool isleft, void* userdata); + +class IUsb +{ +public: + virtual ~IUsb() {} + virtual bool open() = 0; + virtual void set_usbhotplug_callback(usbhotplug_callback callback = nullptr, void* userdata = nullptr) = 0; + virtual bool close() = 0; + virtual bool is_open() = 0; + virtual bool is_connected() = 0; + virtual void set_timeout(int timeout) = 0; + virtual int read_bulk(void* data, int len) = 0; + virtual int write_bulk(void* data, int len) = 0; + virtual int read_int(void* data, int len) = 0; + virtual int control_msg(int rtype, int req, int value, int index, int len, void* data) = 0; +}; diff --git a/HuaGoCorrect/ImageMatQueue.cpp b/HuaGoCorrect/ImageMatQueue.cpp index 9155e20..1b103c7 100644 --- a/HuaGoCorrect/ImageMatQueue.cpp +++ b/HuaGoCorrect/ImageMatQueue.cpp @@ -4,134 +4,85 @@ #include "filetools.h" #include "imageprocess.h" #include -#include -//using namespace std::this_thread; -using namespace std; - -ImageMatQueue::ImageMatQueue(void) :b_save_origin(false), -b_save_fixed_origin(false) +static int imgindex = 0; +ImageMatQueue::ImageMatQueue(void) { - pixType=-1; - DevModel=-1; - - if(!bRun) - { - m_threadProc = std::thread(&ImageMatQueue::proc, this); - bRun = true; - } + pixType = -1; + DevModel = -1; + bScanning = false; + imageremain = 0; } void ImageMatQueue::run() { - if(m_threadProc.joinable()) + if (m_threadProc.joinable()) { bRun = false; m_threadProc.join(); } bRun = true; + imgindex = 0; m_threadProc = std::thread(&ImageMatQueue::proc, this); } void ImageMatQueue::setmultioutputR(bool canoutput/*=false*/) { - can_multi_outputR=canoutput; + can_multi_outputR = canoutput; } void ImageMatQueue::SetDevModel(int dev/*=-1*/) { - DevModel=dev; + DevModel = dev; } ImageMatQueue::~ImageMatQueue(void) { - - if (m_threadProc.joinable()) - { - bRun = false; - m_threadProc.join(); - XdPrint("m_threadProc Released True 111111111111111111111111111\n"); - } if (m_images.Size() > 0) { m_images.Clear(); m_images.ShutDown(); } - if (m_pImages.Size() > 0) { m_pImages.Clear(); m_pImages.ShutDown(); } + if (m_threadProc.joinable()) + { + bRun = false; + m_threadProc.join(); + } } void ImageMatQueue::pushMat(JpegBuffer& data) { + imageremain++; m_pImages.Put(data); int k = 0; } -void ImageMatQueue::UpdateSaveConfig(bool saveOrigin, bool saveFixedOrigin) +std::string ImageMatQueue::popMat(int num) { - b_save_origin= saveOrigin; - b_save_fixed_origin=saveFixedOrigin ; -} - -cv::Mat ImageMatQueue::popMat(int num) -{ - return _popMat(num); -} - -cv::Mat ImageMatQueue::popMat() -{ - return m_images.Take(); + return m_images.Take(); } bool ImageMatQueue::valid() { - bool bIsEmpty = m_images.Size()==0; - return !bIsEmpty; + return m_images.Size(); } void ImageMatQueue::clear() { - m_images.Clear(); - m_pImages.Clear(); -} - -cv::Mat ImageMatQueue::_popMat(int num) -{ - std::queue m_Tempimages; // ʱ - cv::Mat Tempimage; - cv::Mat image; - - int i = 0; - int iSize = m_images.Size(); - - for(i = 0;i < iSize;i++) + while (m_images.Size()>0) { - image = m_images.Front(); - m_Tempimages.push(image); - image.release(); + m_images.Take(); } - - for(i = 0;i < iSize;i++) + while (m_pImages.Size()>0) { - Tempimage = m_Tempimages.front(); - if(i == num) - { - return Tempimage; - } - - m_Tempimages.pop(); + m_pImages.Clear(); } - - return Tempimage; } -void ImageMatQueue::saveimg(std::string csImage,cv::Mat& mat) -{ - imwrite(csImage, mat); -} int ImageMatQueue::getMatSum() { @@ -140,123 +91,68 @@ int ImageMatQueue::getMatSum() return iSum; } +bool ImageMatQueue::isScanning() +{ + return (imageremain != 0 )|| (m_pImages.Size() != 0); +} + bool ImageMatQueue::empty() { - return m_images.Size()==0 && m_pImages.Size()==0; + return m_images.Size()==0 && imageremain ==0 && !bScanning; } void ImageMatQueue::proc() { - while(bRun) + while (bRun) { this_thread::sleep_for(std::chrono::milliseconds(5)); { - if(m_pImages.Size()>0)//m_images.empty() && + if (m_pImages.Size()>0)//m_images.empty() && { - if (pixType!=-1) + if (pixType != -1) { + std::string csName; + SYSTEMTIME st = { 0 }; + GetLocalTime(&st); //ȡǰʱ ɾȷms + //csName.Format("%02d%02d%02d-%d.bmp", st.wHour, st.wMinute, st.wSecond,++imgindex); + cv::Mat matPicImage; - cv::Mat matFront,matBack; - vector mats; - switch(DevModel) + cv::Mat matFront, matBack; + //vector mats; + switch (DevModel) { case 0://G100 case 1://G200//ͼֿ + { + if (m_pImages.Size() >= 2) { - if (m_pImages.Size()>=2) - { - matFront=m_pImages.Take().getMat(pixType); - matBack=m_pImages.Take().getMat(pixType); - mats.push_back(matFront); - if (duplexFlag) - { - mats.push_back(matBack); - } - if (b_save_origin) - { - CString csName; - SYSTEMTIME st = { 0 }; - GetLocalTime(&st); //ȡǰʱ ɾȷms - csName.Format("%02d%02d%02d.jpg", st.wHour, st.wMinute, st.wSecond); - CString csImage; - csImage = csPath + "\\G200-Origin" + csName; - saveimg(std::string(csImage.GetBuffer()), matBack); - } - for (int j = 0; j < m_iaList.size(); j++) - { - m_iaList[j]->apply(mats, duplexFlag);//ҪÿͼapplyIJ жߵmatǷΪ Ŀǰû - } - - } + matFront = m_pImages.Take().getMat(pixType); + matBack = m_pImages.Take().getMat(pixType); + //mats.push_back(matFront); + //mats.push_back(matBack); } - break; + } + break; case 2://G300 case 3://G400 case 4://G500 ͼһͼϣҪͼ - { - cv::Mat mat=m_pImages.Take().getMat(pixType); - matFront=mat(cv::Rect(0,0,mat.cols/2,mat.rows)); - matBack=mat(cv::Rect(mat.cols/2,0,mat.cols/2,mat.rows)); - if (duplexFlag) - { - mats.push_back(matBack); - } - if (b_save_origin) - { - CString csName; - SYSTEMTIME st = { 0 }; - GetLocalTime(&st); //ȡǰʱ ɾȷms - csName.Format("%02d%02d%02d.jpg", st.wHour, st.wMinute, st.wSecond); - CString csImage; - csImage = csPath + "\\G500-Origin" + csName; - saveimg(std::string(csImage.GetBuffer()), matBack); - } - for (int j = 0; j < m_iaList.size(); j++) - { - m_iaList[j]->apply(mats, duplexFlag);//ҪÿͼapplyIJ жߵmatǷΪ Ŀǰû - } - mats.push_back(matFront); - - XdPrint("m_pImagesȡ굱ǰ==========================\n"); - } - break; + { + std::string csImage; + csImage = csPath + "\\G300" + csName; + //cv::Mat mat = m_pImages.Take().getMat(pixType); + //matPicImage = mat(cv::Rect(0, 0, mat.cols, mat.rows)); + ////mats.push_back(matPicImage); + //IplImage qqImg; + //qqImg = IplImage(matPicImage); // cv::Mat -> IplImage + //cvSaveImage(csImage, &qqImg); + m_images.Put(csImage); + } + break; default: break; } - static int index = 0; - if (b_save_fixed_origin) - { - for (int i = 0; i < mats.size(); i++) - { - //CString outinfo; - //outinfo.Format("Tring to save image index of %d \n", ++index); - //XdPrint(outinfo.GetBuffer()); - if (!mats[i].empty()) - { - CString csName; - SYSTEMTIME st = { 0 }; - GetLocalTime(&st); //ȡǰʱ ɾȷms - csName.Format("%02d%02d%02d.jpg", st.wHour, st.wMinute, st.wSecond); - CString csImage; - csImage = csPath + "\\G300-" + csName; - saveimg(std::string(csImage.GetBuffer()), mats[i]); - //outinfo.Format("Saved image index of %d \n", index); - //XdPrint(outinfo.GetBuffer()); - } - } - } - //if (!mats[0].empty()&&!mats[1].empty()) - if (!mats[0].empty()) - { - for (int i=0,length=mats.size();i #include #include "JpegBuffer.h" -#include "BlockingQueue.h" +#include #include "PublicFunc.h" -#include "ImageApplyHeaders.h" +#include "BlockingQueue.h" class ImageMatQueue { @@ -14,49 +14,40 @@ public: virtual ~ImageMatQueue(void); void pushMat(JpegBuffer& data); - void UpdateSaveConfig(bool saveOrigin, bool saveFixedOrigin); - cv::Mat popMat(int num); - cv::Mat popMat(); + std::string popMat(int num); bool empty(); bool valid(); void clear(); void run(); int getMatSum(); - bool b_save_origin; - bool b_save_fixed_origin; - volatile BOOL duplexFlag; - void SetFilePath(CString csFilePath) + bool isScanning(); + void SetScanFlag(bool scannning) { bScanning = bScanning; } + void SetFilePath(std::string csFilePath) { csPath = csFilePath; } - void ImageMatQueue::setduplexflag(BOOL value) - { - duplexFlag = value; - } - CString GetFilePath() + + std::string GetFilePath() { return csPath; } - void ImageMatQueue::setlist(std::vector> list) - { - m_iaList = list; - } + public: int pixType; void setmultioutputR(bool canoutput=false); void SetDevModel(int dev=-1); - std::vector> m_iaList; - CString csPath; + + std::string csPath; private: void proc(); - cv::Mat _popMat(int num); - void saveimg(std::string csImage,cv::Mat &mat); - BlockingQueue m_images; //!< Ѵͼ + BlockingQueue m_images; //!< Ѵͼ BlockingQueue m_pImages; std::thread m_threadProc; volatile bool bRun; bool can_multi_outputR; int DevModel; + volatile bool bScanning; + volatile int imageremain; }; diff --git a/HuaGoCorrect/JpegBuffer.cpp b/HuaGoCorrect/JpegBuffer.cpp index 8c03eca..53e27b6 100644 --- a/HuaGoCorrect/JpegBuffer.cpp +++ b/HuaGoCorrect/JpegBuffer.cpp @@ -7,6 +7,10 @@ using namespace std; +JpegBuffer::JpegBuffer() +{ +} + JpegBuffer::JpegBuffer(cv::Mat buffer, int color_type,int side,int mFilter) { this->m_buffer = buffer; @@ -42,11 +46,10 @@ cv::Mat JpegBuffer::getMat( int pixType) JpegLib jl; //cv::Mat image = jl.decode(m_buffer, 6);//oixtype StopWatch sw; - sw.start(); //XdPrint("buffer size is :%d ==========================\n",getSize()); cv::Mat image = jl.decode(m_buffer, pixType);//oixtype - sw.stop(); - //XdPrint("Decode Image time epleased :%lf ==========================\n",sw.time_run()); + + XdPrint("Decode Image time epleased :%lf ==========================\n",sw.elapsed_ms()); //XdPrint("==image col is :%d, image row is :%d, image size is :%d===\n",image.cols, image.rows, image.size); //FileTools::write_log("D:/1.txt",) diff --git a/HuaGoCorrect/JpegBuffer.h b/HuaGoCorrect/JpegBuffer.h index 6fe186a..9111140 100644 --- a/HuaGoCorrect/JpegBuffer.h +++ b/HuaGoCorrect/JpegBuffer.h @@ -5,7 +5,7 @@ class JpegBuffer { public: - JpegBuffer() {} + JpegBuffer(); JpegBuffer(cv::Mat buffer,int color_type=2,int side=0,int mFilter=0); virtual ~JpegBuffer(void); diff --git a/HuaGoCorrect/JsonConfig.cpp b/HuaGoCorrect/JsonConfig.cpp index e9686ca..9f115fd 100644 --- a/HuaGoCorrect/JsonConfig.cpp +++ b/HuaGoCorrect/JsonConfig.cpp @@ -1,552 +1,107 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "JsonConfig.h" #include -#include -#include #include -#include "CJsonObject.hpp" +#include +#include +#ifdef WIN32 +#include +#else +#include +#endif -JsonConfig::JsonConfig(void) +#define JSON_FILE "config.json" +#define SCAN_INFO_TITLE "ScanInfo" +#define SCAN_TOTAL "TotalScanned" +#define SCAN_CUONUM "CuoNum" +#define SCAN_JAMINNUM "JamInNum" +#define SCAN_JAMOUTNUM "JamOutNum" +#define SCAN_DOUNUM "DoubleNum" +#define SCAN_ERRORNUM "ErrorNum" +#define SCAN_SERIALNUM "SerialNum" +#define SCAN_FWVERSION "FWVersion" + +JsonConfig::JsonConfig() +{ + //if (access(SCANNER_SCAN_INFO_PATH, F_OK) == -1) //不存在 + //{ + // ScannerScanInfo defaultinfo = CreateDefaultScanInfo(); + // SaveScanInfo(defaultinfo); + //} +} +JsonConfig::JsonConfig(ConfigType type) : m_cfgType(type) { } - -JsonConfig::~JsonConfig(void) +JsonConfig::~JsonConfig() { } -/************************************************************************/ -/* ò */ -/************************************************************************/ -void JsonConfig::WriteToJson(PCONFIGPARAMS pConfigItem,const std::string fileNames,bool isConfigItem) +bool JsonConfig::ReadParam(CaptureParams& param) { - //neb::CJsonObject outJson; - //outJson.AddEmptySubObject("Config");//header - //outJson["Config"].Add(PIXTYPE,(int)(pConfigItem->Pixtype)); - //outJson["Config"].Add(PAPARSIZE,(int)(pConfigItem->PaperSize)); - //outJson["Config"].Add(RESOLUTION,(int)(pConfigItem->Resolution)); - //outJson["Config"].Add(DUPLEX,(int)(pConfigItem->Duplex)); - - //std::ofstream os; - //os.open(fileNames.c_str()); - //os<> j; + auto &jobject = j["Config"]; + + jobject["CorrectColorExposure"].get_to(param.correctColorExposure); + jobject["CorrectColorGain"].get_to(param.correctColorGain); + jobject["CorrectColorOffset"].get_to(param.correctColorOffset); + jobject["ColorExposure"].get_to(param.colorExposure); + jobject["ColorGain"].get_to(param.colorGain); + jobject["ColorOffset"].get_to(param.colorOffset); + jobject["CorrectGrayExposure"].get_to(param.correctGrayExposure); + jobject["CorrectGrayGain"].get_to(param.correctGrayGain); + jobject["CorrectGrayOffset"].get_to(param.correctGrayOffset); + jobject["GrayExposure"].get_to(param.grayExposure); + jobject["GrayGain"].get_to(param.grayGain); + jobject["GrayOffset"].get_to(param.grayOffset); + return true; } -void JsonConfig::WriteJsonData(const std::string fileName) +void JsonConfig::WriteParam(CaptureParams& t_param) { - + json m_json; + auto &jobject = m_json["Config"]; + jobject["CorrectColorExposure"] = t_param.correctColorExposure; + jobject["CorrectColorGain"] = t_param.correctColorGain; + jobject["CorrectColorOffset"] = t_param.correctColorOffset; + jobject["ColorExposure"] = t_param.colorExposure; + jobject["ColorGain"] = t_param.colorGain; + jobject["ColorOffset"] = t_param.colorOffset; + jobject["CorrectGrayExposure"] = t_param.correctGrayExposure; + jobject["CorrectGrayGain"] = t_param.correctGrayGain; + jobject["CorrectGrayOffset"] = t_param.correctGrayOffset; + jobject["GrayExposure"] = t_param.grayExposure; + jobject["GrayGain"] = t_param.grayGain; + jobject["GrayOffset"] = t_param.grayOffset; + std::ofstream o(JSON_FILE); + o << std::setw(4) << m_json << std::endl; } -void JsonConfig::WriteJsonArrayToFile(CONFIGPARAMS cfgConfig,const std::string filename) +void JsonConfig::CreateDefault(CaptureParams& param) { - //neb::CJsonObject root; - // - //root.AddEmptySubObject("Config"); - //root["Config"].AddEmptySubArray(PIXTYPE); - //root["Config"].AddEmptySubArray(PAPARSIZE); - //root["Config"].AddEmptySubArray(RESOLUTION); - //root["Config"].AddEmptySubArray(DUPLEX); - //root["Config"].AddEmptySubArray(TABINDEX); - // - //root["Config"][PIXTYPE].Add(cfgConfig.Pixtype); - //root["Config"][PAPARSIZE].Add(cfgConfig.PaperSize); - //root["Config"][RESOLUTION].Add(cfgConfig.Resolution); - //root["Config"][DUPLEX].Add(cfgConfig.Duplex); - //root["Config"][TABINDEX].Add(cfgConfig.TabIndex); + for (size_t i = 0; i <6; i++) + { + param.colorExposure[i] = 259; + param.correctColorExposure[i] = 238; + param.correctGrayExposure[i] = 259; + param.grayExposure[i] = 238; + } - //std::ofstream os; - //os.open(filename.c_str()); - //os< cfgArray,const std::string filename) -{ - /*neb::CJsonObject root; - - root.AddEmptySubObject("Distor"); - root["Distor"].AddEmptySubArray(OBJVALUE1); - root["Distor"].AddEmptySubArray(OBJVALUE2); - root["Distor"].AddEmptySubArray(OBJVALUE3); - root["Distor"].AddEmptySubArray(OBJVALUE4); - root["Distor"].AddEmptySubArray(OBJVALUE5); - root["Distor"].AddEmptySubArray(OBJVALUE6); - root["Distor"].AddEmptySubArray(LIMITOFFSET1); - root["Distor"].AddEmptySubArray(LIMITOFFSET2); - root["Distor"].AddEmptySubArray(LIMITOFFSET3); - root["Distor"].AddEmptySubArray(LIMITOFFSET4); - root["Distor"].AddEmptySubArray(LIMITOFFSET5); - root["Distor"].AddEmptySubArray(LIMITOFFSET6); - - for (int i=0;i cfgArray,const std::string filename) -{ - /*neb::CJsonObject root; - - root.AddEmptySubObject("Match"); - root["Match"].AddEmptySubArray(LOADNUM); - root["Match"].AddEmptySubArray(XPOINT); - root["Match"].AddEmptySubArray(YPOINT); - root["Match"].AddEmptySubArray(PWIGHT); - root["Match"].AddEmptySubArray(PHEIGHT); - root["Match"].AddEmptySubArray(MATCHPATH); - - for (int i=0;i vc; - vc=ReadJsonArrayFromFile(s_default.c_str()); - if (vc.size()!=0) - { - return vc[0]; - } - return GetDefaultConfigParams();*/ - return CONFIGPARAMS(); -} - -DISTORTIONPARAMS JsonConfig::ReadDistorConfig() -{ - //TCHAR szIniFile[MAX_PATH] = { 0 }; - - //SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE); - //_tcscat(szIniFile, HUAGAO_SCAN); - //_tcscat(szIniFile, PAPER_TEST); - //_tcscat(szIniFile, TEXT("\\")); - //_tcscat(szIniFile, DISTOR_JSON_NAME); - //std::string s_default(szIniFile); - //vector vc; - //vc=ReadDistorJsonFromFile(s_default.c_str()); - //if (vc.size()!=0) - //{ - // return vc[0]; - //} - //return GetDistorConfigParams(); - return GetDistorConfigParams(); -} - -MATCHPARAMS JsonConfig::ReadMacthConfig() -{ - //TCHAR szIniFile[MAX_PATH] = { 0 }; - - //SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE); - //_tcscat(szIniFile, HUAGAO_SCAN); - //_tcscat(szIniFile, PAPER_TEST); - //_tcscat(szIniFile, TEXT("\\")); - //_tcscat(szIniFile, MATCH_JSON_NAME); - //std::string s_default(szIniFile); - //vector vc; - //vc=ReadMacthJsonFromFile(s_default.c_str()); - //if (vc.size()!=0) - //{ - // return vc[0]; - //} - //return GetMacthConfigParams(); - return MATCHPARAMS(); -} - -bool JsonConfig::DeleteJsonFile(std::string path) -{ - return (remove(path.c_str())); -} - -std::vector JsonConfig::ReadJsonArrayFromFile(const std::string filename) -{ - std::vector re; - /*FILE* file=fopen(filename.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; -} - -std::vector JsonConfig::ReadDistorJsonFromFile(const std::string filename) -{ - std::vector re; - //FILE* file=fopen(filename.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=parseDistorFromString(text); - return re; -} - -std::vector JsonConfig::ReadMacthJsonFromFile(const std::string filename) -{ - std::vector re; - /*FILE* file=fopen(filename.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=parseMacthFromString(text);*/ - return re; -} - -CONFIGPARAMS JsonConfig::GetDefaultConfigParams() -{ - CONFIGPARAMS params; - - params.Pixtype=1;//Ҷ - params.PaperSize=11;//A3 - params.Resolution=200;//200dpi - params.Duplex=1;//˫ - params.TabIndex = 1; - - return params; -} - -DISTORTIONPARAMS JsonConfig::GetDistorConfigParams() -{ - DISTORTIONPARAMS params; - for(int i = 0;i < 6;i++) - { - params.ObjValues[i] = 10; - params.LimitOffset[i] = 2; - } - - return params; -} - -MATCHPARAMS JsonConfig::GetMacthConfigParams() -{ - MATCHPARAMS params; - params.LoadNum = 4; - params.XPoint = 10; - params.YPoint = 10; - params.PWight = 100; - params.PHeight = 100; - - return params; -} - -std::vector JsonConfig::parseJsonFromString(const std::string str) -{ - //neb::CJsonObject root(str); - vector 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 itmRes; - root["Config"].Get(RESOLUTION,itmRes); - neb::CJsonObject itmDulpex; - root["Config"].Get(DUPLEX,itmDulpex); - neb::CJsonObject itmTabIndex; - root["Config"].Get(TABINDEX,itmTabIndex); - - for (int i=0;i JsonConfig::parseDistorFromString(const std::string str) -{ - //neb::CJsonObject root(str); - vector vcConfig; - - //int size=0; - //neb::CJsonObject itmObjValue1; - //root["Distor"].Get(OBJVALUE1,itmObjValue1); - //size = itmObjValue1.GetArraySize(); - //if (size>0) - //{ - // neb::CJsonObject itmObjValue2; - // root["Distor"].Get(OBJVALUE2,itmObjValue2); - // neb::CJsonObject itmObjValue3; - // root["Distor"].Get(OBJVALUE3,itmObjValue3); - // neb::CJsonObject itmObjValue4; - // root["Distor"].Get(OBJVALUE4,itmObjValue4); - // neb::CJsonObject itmObjValue5; - // root["Distor"].Get(OBJVALUE5,itmObjValue5); - // neb::CJsonObject itmObjValue6; - // root["Distor"].Get(OBJVALUE6,itmObjValue6); - // neb::CJsonObject itmLimitOffset1; - // root["Distor"].Get(LIMITOFFSET1,itmLimitOffset1); - // neb::CJsonObject itmLimitOffset2; - // root["Distor"].Get(LIMITOFFSET2,itmLimitOffset2); - // neb::CJsonObject itmLimitOffset3; - // root["Distor"].Get(LIMITOFFSET3,itmLimitOffset3); - // neb::CJsonObject itmLimitOffset4; - // root["Distor"].Get(LIMITOFFSET4,itmLimitOffset4); - // neb::CJsonObject itmLimitOffset5; - // root["Distor"].Get(LIMITOFFSET5,itmLimitOffset5); - // neb::CJsonObject itmLimitOffset6; - // root["Distor"].Get(LIMITOFFSET6,itmLimitOffset6); - - // for (int i=0;i JsonConfig::parseMacthFromString(const std::string str) -{ - //neb::CJsonObject root(str); - vector vcConfig; - - /*int size=0; - neb::CJsonObject itmLoadNum; - root["Match"].Get(LOADNUM,itmLoadNum); - size=itmLoadNum.GetArraySize(); - if (size>0) - { - neb::CJsonObject itmXPoint; - root["Match"].Get(XPOINT,itmXPoint); - neb::CJsonObject itmYPoint; - root["Match"].Get(YPOINT,itmYPoint); - neb::CJsonObject itmPWight; - root["Match"].Get(PWIGHT,itmPWight); - neb::CJsonObject itmPHeight; - root["Match"].Get(PHEIGHT,itmPHeight); - - neb::CJsonObject itmMatchPath; - if (!root["Match"][MATCHPATH].IsEmpty()) - { - root["Match"].Get(MATCHPATH,itmMatchPath); - } - - for (int i=0;i +#include #include "PublicFunc.h" -#include -#include +#define SCANNER_SCAN_INFO_PATH "/usr/local/huago/jsonconfig.json" using namespace std; - -struct DISTORTIONPARAMS -{ - /**/ - INT ObjValues[6]; - INT LimitOffset[6]; -}; +using json = nlohmann::json; class JsonConfig { public: - JsonConfig(void); - ~JsonConfig(void); -public: - void WriteToJson(PCONFIGPARAMS pConfigItem,const std::string fileName,bool isConfigItem=true); - //PCONFIGPARAMS ReadJsonFromFile(const char* fileNames); - void WriteJsonData(const std::string fileName); - void WriteJsonArrayToFile(CONFIGPARAMS cfgConfig,const std::string filename); - void WriteDistorJsonToFile(std::vector cfgArray,const std::string filename); - void WriteMacthJsonToFile(std::vector cfgArray,const std::string filename); - CONFIGPARAMS ReadDefaultConfig(); - DISTORTIONPARAMS ReadDistorConfig(); - MATCHPARAMS ReadMacthConfig(); - bool DeleteJsonFile(std::string path); - std::vector ReadJsonArrayFromFile(const std::string filename); - std::vector ReadDistorJsonFromFile(const std::string filename); - std::vector ReadMacthJsonFromFile(const std::string filename); - CONFIGPARAMS GetDefaultConfigParams(); - DISTORTIONPARAMS GetDistorConfigParams(); - MATCHPARAMS GetMacthConfigParams(); -private: - std::vector parseJsonFromString(const std::string str) ; - std::vector parseDistorFromString(const std::string str) ; - std::vector parseMacthFromString(const std::string str) ; +enum class ConfigType +{ + Color_Flat, + Color_Correct, + Gray_Flat, + Gray_Correct }; +private: + map cfgPaths={ + {ConfigType::Color_Flat,"/usr/local/etc/huago/Color_Flat.json"}, + {ConfigType::Color_Correct,"/usr/local/etc/huago/Color_Correct.json"}, + {ConfigType::Gray_Flat,"/usr/local/etc/huago/Gray_Flat.json"}, + {ConfigType::Gray_Correct,"/usr/local/etc/huago/Gray_Correct.json"} + }; + map cfgPrefix={ + {ConfigType::Color_Flat,"Color_Flat"}, + {ConfigType::Color_Correct,"Color_Correct"}, + {ConfigType::Gray_Flat,"Gray_Flat"}, + {ConfigType::Gray_Correct,"Gray_Correct"} + }; + ConfigType m_cfgType; +public: + JsonConfig(); + JsonConfig(ConfigType type); + ~JsonConfig(); + /* + *若返回false 则表示文件不存在或文件读取失败 + */ + bool ReadParam(CaptureParams& param); + + void WriteParam(CaptureParams& t_param); + +// ScannerScanInfo GetScanInfo(); +// +// void SaveScanInfo(const ScannerScanInfo& info); +private: + void CreateDefault(CaptureParams& param); +// ScannerScanInfo CreateDefaultScanInfo(); +}; diff --git a/HuaGoCorrect/PublicFunc.h b/HuaGoCorrect/PublicFunc.h index bf8398a..4726566 100644 --- a/HuaGoCorrect/PublicFunc.h +++ b/HuaGoCorrect/PublicFunc.h @@ -4,86 +4,9 @@ #include "stdafx.h" #include -//#include "UI_INI.h" -//#include "DirectshowCaptureVideo.h" -//#include "DirectshowCaptureVideoUvc.h" using namespace std; -#define PIXTYPE "iPixType" -#define PAPARSIZE "iPaparSize" -#define RESOLUTION "iResolution" -#define DUPLEX "iDuplex" -#define TABINDEX "iTabIndex" - -#define OBJVALUE1 "fObjValue1" -#define OBJVALUE2 "fObjValue2" -#define OBJVALUE3 "fObjValue3" -#define OBJVALUE4 "fObjValue4" -#define OBJVALUE5 "fObjValue5" -#define OBJVALUE6 "fObjValue6" -#define LIMITOFFSET1 "iLimitOffset1" -#define LIMITOFFSET2 "iLimitOffset2" -#define LIMITOFFSET3 "iLimitOffset3" -#define LIMITOFFSET4 "iLimitOffset4" -#define LIMITOFFSET5 "iLimitOffset5" -#define LIMITOFFSET6 "iLimitOffset6" - -#define LOADNUM "iLoadNum" -#define XPOINT "iXPonit" -#define YPOINT "iYPoint" -#define PWIGHT "iWight" -#define PHEIGHT "iHeight" -#define MATCHPATH "MacthPath" - - -/************************************ -**ɨjsonʽ** -*************************************/ -/* -#define PIXTYPE "iPixType" -#define PAPARSIZE "iPaparSize" -#define AUTOCROP "bAuotCrop" -#define RESOLUTION "iResolution" -#define DUPLEX "iDuplex" -#define DISCARBLANK "bDiscardBlank" -#define DISCARBLANKVINCE "bDiscardBlankVince" -#define FLOD "bFlod" -#define BRIGHTNESS "iBrightness" -#define AUTOCONTRAST "bAutoContrast" -#define CONTRAST "iContrast" -#define GAMMA "dGamma" -#define FILTERTYPE "iFilter" -#define FILLBLACK "bFillBlcak" -#define AUTODESCREW "bAutoDescrew" -#define ULTRADETECT "bUltrasonicDetect" -#define BINDINGDETECT "bBindingDetect" -#define SCANCOUNT "ScanCount" -#define DOCORIENTATION "bOrientation" -#define BACKROTATE180 "iBackRotate180" -#define SCREWDETECT "bScrewDetect" -#define SCREWLEVEL "iScrewLevel" -#define ITEMCAPTION "Caption" -#define SAVEPATH "SavePath" -#define MULTIOUTPUT "iMultiOutPut" -#define OUTHOLE "bOutHole" -#define OUTHOLERATIO "iOutHoleRatio" -*/ -/****************** -**ṹ** -*******************/ - -struct tagMATCHPARAMS -{ - /**/ - INT LoadNum; - INT XPoint; - INT YPoint; - INT PWight; - INT PHeight; - std::string MatchPath; -}; -typedef tagMATCHPARAMS MATCHPARAMS, *PMATCHPARAMS; -struct tagCONFIGPARAMS_1 +struct tagCONFIGPARAMS { /*ѡ*/ @@ -124,6 +47,7 @@ struct tagCONFIGPARAMS_1 std::string SavePath; }; +typedef tagCONFIGPARAMS CONFIGPARAMS,*PCONFIGPARAMS; struct tagCONFIGINFO { @@ -131,105 +55,65 @@ struct tagCONFIGINFO std::string SavePath; }; +struct SPSET +{ + unsigned int FSP; + unsigned int BSP; +}; + typedef struct tagCONFIGINFO CONFIGINFO,*PCONFIGINFO; -struct tagCONFIGPARAMS + +typedef unsigned int u32; +typedef struct { - /**/ - INT Pixtype; - INT PaperSize; - INT Resolution; - INT Duplex; - INT TabIndex; -}; -typedef tagCONFIGPARAMS CONFIGPARAMS, *PCONFIGPARAMS; -/**/ -/* -struct tagOutHole + u32 gainF[6]; + u32 gainB[6]; + u32 offsetsF[6]; + u32 offsetsB[6]; + u32 expF[3]; + u32 expB[3]; + u32 sp; +}HGCISConfig; + + +typedef struct { - BOOL EnOutHole; - INT OutHoleRatio; -}; + HGCISConfig colorCorrect; + HGCISConfig color; + HGCISConfig grayCorrect; + HGCISConfig gray; +}HGCorrectConfigs; -typedef tagOutHole OutHole,*pOutHole; +typedef struct Correct_Param { + unsigned int Exposures[6]; + unsigned int Gain[12]; + unsigned int Offset[12]; +}CorrectParam; -#define CAPTION_LEN 256 -#define TWAIN_IMAGE_FILE_LIST_NAME TEXT(".dat") +typedef struct CaptureParams +{ -#ifndef malloc_my -#define malloc_my malloc -#endif -*/ -//#define TWSS_A4R 60 -//enum TwSS -//{ -// None = 0, -// A4Letter = 1, -// A4 = 1, -// B5Letter = 2, -// JISB5 = 2, -// B5 = 2, -// USLetter = 3, -// USLegal = 4, -// A5 = 5, -// B4 = 6, -// ISOB4 = 6, -// B6 = 7, -// ISOB6 = 7, -// USLedger = 9, -// USExecutive = 10, -// A3 = 11, -// B3 = 12, -// ISOB3 = 12, -// A6 = 13, -// C4 = 14, -// C5 = 15, -// C6 = 16, -// _4A0 = 17, -// _2A0 = 18, -// A0 = 19, -// A1 = 20, -// A2 = 21, -// A7 = 22, -// A8 = 23, -// A9 = 24, -// A10 = 25, -// ISOB0 = 26, -// ISOB1 = 27, -// ISOB2 = 28, -// ISOB5 = 29, -// ISOB7 = 30, -// ISOB8 = 31, -// ISOB9 = 32, -// ISOB10 = 33, -// JISB0 = 34, -// JISB1 = 35, -// JISB2 = 36, -// JISB3 = 37, -// JISB4 = 38, -// JISB6 = 39, -// JISB7 = 40, -// JISB8 = 41, -// JISB9 = 42, -// JISB10 = 43, -// C0 = 44, -// C1 = 45, -// C2 = 46, -// C3 = 47, -// C7 = 48, -// C8 = 49, -// C9 = 50, -// C10 = 51, -// USStatement = 52, -// BusinessCard = 53, -// A4R = 60, -// A5R = 61, -// A6R = 62, -// B5R = 70, -// B6R = 71, -// USLetterR = 80, -// DOUBLELetter = 81, -// AUTO = 90 -//}; + int correctColorExposure[6]; + int correctColorGain[12]; + int correctColorOffset[12]; + + int correctGrayExposure[6]; + int correctGrayGain[12]; + int correctGrayOffset[12]; + + int colorExposure[6]; + int colorGain[12]; + int colorOffset[12]; + + int grayExposure[6]; + int grayGain[12]; + int grayOffset[12]; + + int uvCorrectColorExposure[2]; + int uvCorrectGrayExposure[2]; + int uvColorExposure[2]; + int uvGrayExposure[2]; +} CaptureParams; typedef struct tagTWAIN_IMAGE_FILE_LIST { diff --git a/HuaGoCorrect/Resource.h b/HuaGoCorrect/Resource.h index 3759c64..cace58a 100644 Binary files a/HuaGoCorrect/Resource.h and b/HuaGoCorrect/Resource.h differ diff --git a/HuaGoCorrect/ThreadPool.h b/HuaGoCorrect/ThreadPool.h new file mode 100644 index 0000000..4183203 --- /dev/null +++ b/HuaGoCorrect/ThreadPool.h @@ -0,0 +1,98 @@ +#ifndef THREAD_POOL_H +#define THREAD_POOL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class ThreadPool { +public: + ThreadPool(size_t); + template + auto enqueue(F&& f, Args&&... args) + -> std::future::type>; + ~ThreadPool(); +private: + // need to keep track of threads so we can join them + std::vector< std::thread > workers; + // the task queue + std::queue< std::function > tasks; + + // synchronization + std::mutex queue_mutex; + std::condition_variable condition; + bool stop; +}; + +// the constructor just launches some amount of workers +inline ThreadPool::ThreadPool(size_t threads) + : stop(false) +{ + for(size_t i = 0;i task; + + { + std::unique_lock lock(this->queue_mutex); + this->condition.wait(lock, + [this]{ return this->stop || !this->tasks.empty(); }); + if(this->stop && this->tasks.empty()) + return; + task = std::move(this->tasks.front()); + this->tasks.pop(); + } + + task(); + } + } + ); +} + +// add new work item to the pool +template +auto ThreadPool::enqueue(F&& f, Args&&... args) + -> std::future::type> +{ + using return_type = typename std::result_of::type; + + auto task = std::make_shared< std::packaged_task >( + std::bind(std::forward(f), std::forward(args)...) + ); + + std::future res = task->get_future(); + { + std::unique_lock lock(queue_mutex); + + // don't allow enqueueing after stopping the pool + if(stop) + throw std::runtime_error("enqueue on stopped ThreadPool"); + + tasks.emplace([task](){ (*task)(); }); + } + condition.notify_one(); + return res; +} + +// the destructor joins all threads +inline ThreadPool::~ThreadPool() +{ + { + std::unique_lock lock(queue_mutex); + stop = true; + } + condition.notify_all(); + for(std::thread &worker: workers) + worker.join(); +} + +#endif diff --git a/HuaGoCorrect/commondef.h b/HuaGoCorrect/commondef.h new file mode 100644 index 0000000..029dc06 --- /dev/null +++ b/HuaGoCorrect/commondef.h @@ -0,0 +1,399 @@ +#pragma once +#include + + +typedef struct tag_USBCB { + int u32_CMD; + int u32_Data; + int u32_Count; +}USBCB, * PUSBCB; + +typedef struct tag_USBCBA4 +{ + unsigned int u32_Command; /* command to execute */ + unsigned int u32_Data; /* generic data field */ + unsigned int u32_Count; /* number of bytes to transfer */ + byte buffer[512]; //=new byte[1024]; +}USBCBA4, * PUSBCBA4; + +//u32_CMD +enum tagUsbKeyWords :unsigned int +{ + NO_COMMAND = 0, + //ȡdsp ״̬ + GET_DSP_STATUS = 1, + //ȡͼ + GET_IMAGE = 2, + //DSPפͼ + POP_IMAGE = 3, + //ʼɨ + START_COMMAND = 4, + //ֹͣɨ + STOP = 5, + //ȡɨɨģʽ + GET_SCAN_MODE = 6, + //ȡ̼汾 + GET_FW_VERSION = 7, + //PC˵״̬ + SEND_STATUS_PC = 8, + //·ɨò + CONFIGURED_DATA = 9, + //·̼Ϣ + SEND_FW = 10, + //ȡɨ + GET_CONFIG_DATA = 11, + //ȡɨ + GET_SCANN_NUM = 12, + //ȡֽ״̬ + GET_PAPERFEEDER_STATUS = 13, + //DSPʼ + INIT_HARDWARE_SYS = 14, + //·ԪòҶȣLED Rعʱ䣩 + SEND_COMPONENTS_GR = 15, + //·ԪòLED G/Bعʱ䣩 + SEND_COMPONENTS_GB = 16, + //·ɨģʽ + SEND_SCAN_MODE = 17, + //ʼƽ + START_FLAT = 18, + //ֹͣƽ + STOP_FLAT = 19, + //·200dpiɫƽ + SEND_200_COLOR_FLAT_DATA = 20, + //·300dpiɫƽ + SEND_300_COLOR_FLAT_DATA = 21, + //ȡ200dpiɫƽ + GET_200_COLOR_FLAT_DATA = 22, + //ȡ300dpiɫƽ + GET_300_COLOR_FLAT_DATA = 23, + //·200dpiҶƽУ + SEND_200_GRAY_FLAT_DATA = 24, + //·300dpiҶƽУ + SEND_300_GRAY_FLAT_DATA = 25, + //ȡ200DPIҶƽУ + GET_200_GRAY_FLAT_DATA = 26, + //ȡ300DPIҶƽУ + GET_300_GRAY_FLAT_DATA = 27, + //·к + SEND_SERIAL = 28, + //ȡк + GET_SERIAL = 29, + //ȡ + GET_ROLLER_NUM = 0x1e, + // + CLR_ROLLER_NUM = 0x1f, + //ɨ + CLR_SCAN_NUM = 0x20, + //׼¹̼ + PRE_UPGRADE = 0X21, + //ʼ¹̼ + START_UPGRADE = 0x22, + //ɫAD + RGB_ADI_PARA = 0x23, + //ҶȵAD + ADI_PARA = 0x24, + //ȡCISعʱ䣬ad) + GET_CIS_PARA = 0x25, + //ɨ + START_COMMAND_COUNT = 0x26, + //·ʱ + SET_SLEEP_TIME = 0x27, + //ȡʱ + GET_SLEEP_TIME = 0x28, + // + CLR_CACHE = 0x29, + //·ٶģʽ + SET_SPEED_MODE = 0x2a, + //ȡɨٶģʽ + GET_SPEED_MODE = 0X2b, + //ù̼汾һ8ֽ + SET_FW_VERSION = 0X2c, + //ȡDSP汾 + GET_DSP_VERSION = 0X2d, + //ɼFPGA̼汾 + GET_SCANFPGA_VERSION = 0x2e, + //FPGA̼汾 + GET_MOTORFPGA_VERSION = 0X2f, + //Ϣ + SET_USB_INFOR_MANUFACTURE = 0X30, + //ȡϢ + GET_USB_INFOR_MANUFACTURE = 0X31, + //òƷͺϢ + SET_USB_INFOR_MODEL_NAME = 0X32, + //ȡƷͺϢ + GET_USB_INFOR_MODEL_NAME = 0X33, + //USB PID / VIDϢ + SET_USB_INFOR_VIDPID = 0X34, + GET_USB_INFOR_VIDPID = 0X35, + //ÿֽͣ + SET_JAM_DETECT_SENSITIVE = 0X36, + //ȡֽͣ + GET_JAM_DETECT_SENSITIVE = 0X37, + //úϵ + SET_JUST_COF_H = 0x38, + //ȡϵ + GET_JUST_COF_H = 0x39, + //G400 Ӳ쳣 + CLEAR_HWERROR = 0x40, + //ϵ + SET_JUST_COF_V = 0x41, + //ȡϵ + GET_JUST_COF_V = 0x42, + //òɫУ + SEND_COLOR_FLAT = 0x43, + //òɫƽУ + SEND_COLORCORRECT_FLAT = 0x44, + //ûҶУ + SEND_GRAY_FLAT = 0x45, + //ûҶƽУ + SEND_GRAYCORRECT_FLAT = 0x46, + //ƽУ + GET_FLAT_DATA = 0x47, + // + UPDATE_FINISHED = 0x48, + // + REBOOT = 0x49, + GET_LOG_FILES_INFO = 0x50, + //logļ + GET_UPDATE_RESULT = 0x51, + //־ + CLEAR_LOG_FILES = 0x52, + //ȡֽʧ + GET_CUO_ERROR, + //ȡ˫ʧܴ + GET_DOU_ERROR, + //ȡֽ + GET_JAM_ERROR, + GET_UV_EXPOSA = 0x100, + GET_UV_EXPOSB = 0x101, + SET_UV_EXPOSA = 0x102, + SET_UV_EXPOSB = 0x103 +}; + +typedef enum tagUsbKeyWords UsbKeyWords, * PUsbKeyWords; +//u32_Data +enum tagUsbSupported +{ + //ֹͣɨ + SCAN_STOP = -2, + //쳣 + HAVE_ERROR = -1, + //״̬ + NORMAL = 0, + // + OPEN_COVER = 1, + // ֽ + NO_FEED = 2, + // ֽʧ + FEED_IN_ERROR = 4, + // ֽ + PAPER_JAM = 8, + // ⵽˫ + DETECT_DOUBLE_FEED = 16, + // ⵽鶤 + DETECT_STAPLE = 32, + // ֽб + PAPER_SKEW = 64, + // Զģʽ + AUTO_SCAN_MODE = 65, + // ֶģʽ + MANAUL_SCAN_MODE = 66, + // ģʽ + COUNT_MODE = 67, + // Ӳ + HARDWARE_ERROR = 68, + // FPGA + FPGA_ERROR = 68, + // ʼ + START_SCAN = 69, + //ֹͣ + STOP_SCAN = 70, + //ͼ + HAVE_IMAGE = 71, + // ɨ + UPDATE_SCAN_PARAMETER = 72, + // PCæ + PC_SCAN_BUSY_or_ERROR = 73, + // + STS_UPDATE_FINISHED = 74,//confilict whit DOG_EAR + // + SIZE_ERROR = 75, + //ȡͼʱ + AQUIRE_IMAGE_TIMEOUT = 76, + //ȡͼƬɨƥ + LOSE_IMAGE = 77, + //usbȡݴ + USB_BULK_ERROR = 78, + //v4l2ȡͼʧ + V4L2_AQULRE_ERROR = 79, + //ɨڲͼƬʧ + V4L2_IMAGE_EMPTY = 80, + //USB δ + USB_DISCONNECTED = 200, + //ûֹͣ + USER_STOP = 201, + //ԶƽУ + AUTO_FLAT_FINISHED = 202 +}; + +typedef enum tagUsbSupported UsbSupported, * PUsbSupported; + +enum tagDevState +{ + DEV_STOP = -1, + DEV_ISRUNNING, + DEV_WRONG +}; + +typedef enum tagDevState DevState, PDevState; + +enum tagEventIndex +{ + EVENT_IMAGE, + EVENT_NUM +}; + +enum tagDEVMODEL +{ + G100 = 0, + G200, + G300, + G400, + G500 +}; + + + +#define USB_REQ_GET_FPGA_REGS 0x40 +#define USB_REQ_SET_FPGA_REGS 0x41 +#define USB_REQ_GET_MOTOR_REGS 0x42 +#define USB_REQ_SET_MOTOR_REGS 0x43 + +#define USB_REQ_GET_DEV_STATUS 0x60 +#define USB_REQ_GET_DEV_CONFIGURATION 0x61 +#define USB_REQ_SET_DEV_CONFIGURATION 0x62 +#define USB_REQ_GET_DEV_REGS 0x63 +#define USB_REQ_SET_DEV_REGS 0x64 + +enum Scanner_Reg_Defs +{ + SR_CMD, + SR_STATUS, + SR_SCAN_COUNT, + SR_OS, + SR_SENSORS, + SR_MOTOR, + SR_IM_TYPE, + SR_IM_COUNT, + SR_IM_TX, + SR_IM_FRONT_SIZE, + SR_IM_CLEAR, + SR_IM_TXING, + SR_IM_POP, + SR_IM_ABORT, + SR_COUNT, + SR_CONFIG_SCAN_PARAM, + SR_GET_FWVERSION, + SR_SET_FWERSION, + SR_GET_SERIALNUM, + SR_SET_SERIALNUM, + SR_CONFIF_IMGPROCPARAM, + SC_AUTOCORRECT, + SC_GET_CORRECT_PARAM, + SC_SET_CORRECT_PARAM, + SR_GET_H_RATIO, + SR_SET_H_RATIO, + SR_GET_V_RATIO, + SR_SET_V_RATIO, + SR_GET_SERIAL_LEN, + SR_GET_GRAY_SP, + SR_GET_COLOR_SP, + SR_SET_GRAY_SP, + SR_SET_COLOR_SP, + SR_SET_SLEEPTIME, + SR_GET_SLEEPTIME, + SR_GET_SLEEP_STAUTUS, + SR_GET_CUO_ERROR = 0x50, + SR_GET_DOU_ERROR, + SR_GET_JAM_ERROR, + SR_GET_SCANN_NUM, + SR_CLR_ROLLER_NUM, + SR_GET_ROLLER_NUM, + SR_CLR_SCANN_NUM, + SR_UPDATA_START = 0x100, + SR_UPDATA_STAUTUS = 0x101, + SR_UPDATA_MD5_RELUST = 0x102, + SR_UPDATA_RECOVERY = 0x103, + SR_UPDATA_REBOOT = 0x104, + SR_POWEROFF = 0x105, + SR_REBOOT = 0x106 +}; + +enum Scanner_Cmd_Defs +{ + SC_START, + SC_STOP, + SC_CLEAR, + SC_COUNT +}; + + +enum Updata_Stautus { + Start_updata, + Download_file, + Download_file_error, + Download_file_finish, + MD5_Reovery, + MD5_Rboot, + MD5_Error, + Reboot +}; + +enum HGType +{ + MtBoard = 1, + FPGA, + V4L2, + IMG, + STOPSCAN, +}; + +typedef union HG_ScanConfig +{ + unsigned int value; + struct + { + unsigned int paper : 5; + unsigned int color : 1; + unsigned int dpi : 2; + unsigned int double_feed_enbale : 1; + unsigned int stable_enbale : 1; + unsigned int screw_detect_enable : 1; + unsigned int screw_detect_level : 3;//ʮλ + unsigned int iscorrect_mode : 1; + unsigned int unused_one : 5; + unsigned int pc_correct : 1; + unsigned int enable_sizecheck : 1; + unsigned int enabledsp_cache : 1; + unsigned int sizeerror_errorratio : 9; + }g200params; + struct + { + unsigned int pageSize : 5; + unsigned int isColor : 1; + unsigned int dpi : 2; + unsigned int doubleFeeded : 1; + unsigned int enableStable : 1; + unsigned int enableLed : 1; + unsigned int reversed1 : 6; + unsigned int isCorrect : 1; + unsigned int dstHeight : 8; + unsigned int reversed2 : 6; + }g400params; +}HGScanConfig; + +struct HGEIntInfo +{ + HGType From; + unsigned int Code; +}; \ No newline at end of file diff --git a/HuaGoCorrect/config.json b/HuaGoCorrect/config.json new file mode 100644 index 0000000..2b4fd5f --- /dev/null +++ b/HuaGoCorrect/config.json @@ -0,0 +1,148 @@ +{ + "Config": { + "ColorExposure": [ + 259, + 259, + 259, + 259, + 259, + 259 + ], + "ColorGain": [ + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30 + ], + "ColorOffset": [ + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119 + ], + "CorrectColorExposure": [ + 238, + 238, + 238, + 238, + 238, + 238 + ], + "CorrectColorGain": [ + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30, + 30 + ], + "CorrectColorOffset": [ + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119 + ], + "CorrectGrayExposure": [ + 259, + 259, + 259, + 259, + 259, + 259 + ], + "CorrectGrayGain": [ + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47 + ], + "CorrectGrayOffset": [ + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119 + ], + "GrayExposure": [ + 238, + 238, + 238, + 238, + 238, + 238 + ], + "GrayGain": [ + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47, + 47 + ], + "GrayOffset": [ + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119, + 119 + ] + } +} diff --git a/HuaGoCorrect/filetools.h b/HuaGoCorrect/filetools.h index e481035..40986c4 100644 --- a/HuaGoCorrect/filetools.h +++ b/HuaGoCorrect/filetools.h @@ -3,6 +3,7 @@ #include #include #include +#include class FileTools { @@ -54,13 +55,31 @@ private: class StopWatch { public: - StopWatch() { valEnd = valStart = clock(); } - void start() { valStart = clock(); } - void stop() { valEnd =clock(); } - double time_run() { return (double)(valEnd - valStart)/CLOCKS_PER_SEC; } + StopWatch() { + _start = std::chrono::steady_clock::now(); + } + + void reset() { + _start = std::chrono::steady_clock::now(); + } + + double elapsed_s() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_ms() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_us() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_ns() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } private: - clock_t valStart; - clock_t valEnd; + std::chrono::steady_clock::time_point _start; }; diff --git a/HuaGoCorrect/gscan3399.cpp b/HuaGoCorrect/gscan3399.cpp new file mode 100644 index 0000000..22ba9c8 --- /dev/null +++ b/HuaGoCorrect/gscan3399.cpp @@ -0,0 +1,638 @@ +#include "stdafx.h" +#include "gscan3399.h" +#include "scn_usb.h" +#include "filetools.h" +#include + +using namespace cv; +static std::mutex mx_ctrl; + +void DoEvents() { + MSG msg; + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + DispatchMessage(&msg); + TranslateMessage(&msg); + } +} +static int scanner_read_reg(std::shared_ptr& usb, int addr) +{ + int val = 0; + std::lock_guard lck(mx_ctrl); + usb->control_msg(0xc0, USB_REQ_GET_DEV_REGS, addr, 0, 4, &val); + return val; +} + +static void scanner_write_reg(std::shared_ptr& usb, int addr, int val) +{ + std::lock_guard lck(mx_ctrl); + usb->control_msg(0x40, USB_REQ_SET_DEV_REGS, addr, 0, 4, &val); +} + +static void scanner_cmd(std::shared_ptr& usb, int cmd) +{ + scanner_write_reg(usb, 0, cmd); +} + +gscan3399::gscan3399() : + m_imgthread(1) +{ + im_data.reset(new std::vector()); +} + +gscan3399::~gscan3399() +{ + if (m_usbthread.get() && m_usbthread->joinable()) + { + b_usbthread = false; + m_usbthread->join(); + m_usbthread.reset(); + } + + if (m_usb.get()) + m_usb.reset(); +} + +void gscan3399::open(int vid, int pid, int index) +{ + if (m_usb.get() && m_usb->is_connected()) + return; + auto usbs = UsbScan_List::find_vid_pid(vid, pid); + if (!usbs.empty()) + { + m_usb = *usbs.begin(); + m_usb->open(); + if (m_usb->is_connected()) + { + m_usb->set_usbhotplug_callback(gscan3399::usbcallback, this); + } + } +} + +int gscan3399::aquire_image(std::string& image, int num) +{ + StopWatch sw; + while (true) + { + if ((imgremains == 0) && (!is_runing())) + { + DoEvents(); + this_thread::sleep_for(chrono::milliseconds(1)); + if (!is_runing()) + { + if (devState == DEV_WRONG) + return Error_Code; + return -1; + } + if (sw.elapsed_s() > 30.0) + { + devState = DEV_STOP; + Stop_scan(); + ResetScanner(); + return AQUIRE_IMAGE_TIMEOUT; + } + } + else + { + if ((m_imagespath.Size() > 0)) + { + image = m_imagespath.Take(); + imgremains--; + return 0; + } + DoEvents(); + this_thread::sleep_for(chrono::milliseconds(2)); + } + + } +} +bool gscan3399::IsConnected() +{ + return true; +} + +std::string gscan3399::GetFWVersion() +{ + std::string fw = "0123456789"; + if (m_usb.get() && m_usb->is_connected()) + { + scanner_write_reg(m_usb, SR_GET_FWVERSION, 0); + fw.resize(10); + read_data(&fw[0], fw.length(), 200); + } + return fw; +} +void gscan3399::SetFWVersion() +{ + +} +std::string gscan3399::GetSerialNum() +{ + std::string sr = "01234567890123"; + if (m_usb.get() && m_usb->is_connected()) + { + int length = scanner_read_reg(m_usb, SR_GET_SERIAL_LEN); + sr.resize(length); + scanner_write_reg(m_usb, SR_GET_SERIALNUM, 0); + read_data(&sr[0], sr.length(), 200); + } + return sr; +} + +void gscan3399::SetSerialNum(std::string serial) +{ + if (m_usb.get() && m_usb->is_connected()) + { + scanner_write_reg(m_usb, SR_SET_SERIALNUM, serial.length()); + m_usb->write_bulk(&serial[0], serial.length()); + } +} + +void gscan3399::SetRatio(int tyepe, int ration) +{ + scanner_write_reg(m_usb, tyepe == 0 ? SR_SET_H_RATIO : SR_SET_V_RATIO, ration); + +} +void gscan3399::GetRatio(int type, int& ratio) +{ + ratio = scanner_read_reg(m_usb, type == 0 ? SR_GET_H_RATIO : SR_GET_V_RATIO); +} + +void gscan3399::Reboot() +{ + scanner_write_reg(m_usb, SR_REBOOT, 0); +} + +void gscan3399::PowerOff() +{ + scanner_write_reg(m_usb, SR_POWEROFF, 0); +} + +bool gscan3399::is_scan() +{ + return 0; +} + +bool gscan3399::Get_Scanner_PaperOn() +{ + return true; +} + + +void gscan3399::Config_Scanner(HGScanConfig config) +{ + m_config = config; + scanner_write_reg(m_usb, SR_CONFIG_SCAN_PARAM, config.value); +} +void gscan3399::Scanner_StartScan(UINT16 count) +{ + scanner_cmd(m_usb, SC_START); + if (m_usbthread.get()) + { + b_usbthread = false; + if (m_usbthread->joinable()) + { + m_usbthread->join(); + m_usbthread.reset(); + } + } + b_usbthread = true; + m_usbthread.reset(new thread(&gscan3399::usb_run, this)); +} +void gscan3399::Stop_scan() +{ + scanner_cmd(m_usb, SC_STOP); +} +void gscan3399::ResetScanner() +{ + +} +bool gscan3399::Get_IsImageQueueEmpty() +{ + return true; +} +void gscan3399::reset() +{ + +} +void gscan3399::run() +{ + +} +int gscan3399::get_decompress_pix_type() +{ + return 0; +} +void gscan3399::set_decompress_pix_type(int pixtype) +{ + +} + +bool gscan3399::Updata(std::string filename, std::function func) +{ + std::ifstream updatefile; + updatefile.open(filename, std::ios_base::in | std::ios_base::binary); + if (!updatefile.is_open()) + { + return false; + } + updatefile.seekg(0, std::ios::end); + size_t length = updatefile.tellg(); + func(0, length); + updatefile.seekg(0, std::ios::beg); + scanner_write_reg(m_usb, 0x100, length); + size_t nreaded = 0; + size_t nleft = length; + int buffersize = 512 * 1024; + if (length <= buffersize)//С1MB + { + char* uotstream = new char[length]; + updatefile.read(uotstream, length); + m_usb->write_bulk(uotstream, length); + delete[] uotstream; + } + else + { + while (true) + { + int ntotransfer; + if (nleft < buffersize) + ntotransfer = nleft; + else + ntotransfer = buffersize; + std::vector data; + data.resize(ntotransfer); + updatefile.read(data.data(), ntotransfer); + m_usb->write_bulk(data.data(), ntotransfer); + nreaded += ntotransfer; + nleft -= ntotransfer; + func(nreaded, length); + if (nreaded >= length) + break; + this_thread::sleep_for(std::chrono::milliseconds(5)); + } + } + this_thread::sleep_for(std::chrono::milliseconds(200)); + if (!scanner_read_reg(m_usb, 0x101)) + return false; + auto now = std::chrono::steady_clock::now(); + while (std::chrono::duration(std::chrono::steady_clock::now() - now).count() < 60) + { + int status= scanner_read_reg(m_usb, 0x102); + if (status == 2) + { + scanner_read_reg(m_usb, 0x104); + return true; + } + if (status == 3) + { + scanner_read_reg(m_usb, 0x103); + return true; + } + if (status == 6) + { + return false; + } + this_thread::sleep_for(std::chrono::milliseconds(20)); + } + return false; +} + +void gscan3399::SetIsDuplex(bool value) +{ + +} + +void gscan3399::ActiveteUSB() +{ + +} + + +int gscan3399::GetScanNum() +{ + return scanner_read_reg(m_usb, SR_SCAN_COUNT); +} + +void gscan3399::ClrRollerNum() +{ + +} + +void gscan3399::ClrScanNum() +{ + +} + +void gscan3399::SendFlatData(CorrectParam param, int index) +{ + if (m_usb.get() && m_usb->is_connected()) + { + scanner_write_reg(m_usb, SC_SET_CORRECT_PARAM, index); + HGCISConfig cisconfig = { 0 }; + int t_index = index; + memcpy(cisconfig.expF, param.Exposures, sizeof(u32) * 3); + memcpy(cisconfig.expB, ¶m.Exposures[0] + 3, sizeof(u32) * 3); + memcpy(cisconfig.gainF, param.Gain, sizeof(u32) * 6); + memcpy(cisconfig.gainB, ¶m.Gain[0] + 6, sizeof(u32) * 6); + memcpy(cisconfig.offsetsF, param.Offset, sizeof(u32) * 6); + memcpy(cisconfig.offsetsB, ¶m.Offset[0] + 6, sizeof(u32) * 6); + m_usb->write_bulk(&cisconfig, sizeof(HGCISConfig)); + } +} + +CaptureParams gscan3399::GetFlatData() +{ + CaptureParams param; + HGCorrectConfigs cisconfigs = { 0 }; + scanner_write_reg(m_usb, SC_GET_CORRECT_PARAM, 0); + m_usb->read_bulk(&cisconfigs, sizeof(HGCorrectConfigs)); + for (size_t i = 0; i < 2; i++) + { + memcpy(¶m.correctColorExposure[0] + i * 3, i == 0 ? &cisconfigs.colorCorrect.expF[0] : &cisconfigs.colorCorrect.expB[0], sizeof(u32) * 3); + memcpy(¶m.colorExposure[0] + i * 3, i == 0 ? &cisconfigs.color.expF[0] : &cisconfigs.color.expB[0], sizeof(u32) * 3); + memcpy(¶m.correctGrayExposure[0] + i * 3, i == 0 ? &cisconfigs.grayCorrect.expF[0] : &cisconfigs.grayCorrect.expB[0], sizeof(u32) * 3); + memcpy(¶m.grayExposure[0] + i * 3, i == 0 ? &cisconfigs.gray.expF[0] : &cisconfigs.gray.expB[0], sizeof(u32) * 3); + + memcpy(¶m.correctColorGain[0] + i * 6, i == 0 ? &cisconfigs.colorCorrect.gainF[0] : &cisconfigs.colorCorrect.gainB[0], sizeof(u32) * 6); + memcpy(¶m.colorGain[0] + i * 6, i == 0 ? &cisconfigs.color.gainF[0] : &cisconfigs.color.gainB[0], sizeof(u32) * 6); + memcpy(¶m.correctGrayGain[0] + i * 6, i == 0 ? &cisconfigs.grayCorrect.gainF[0] : &cisconfigs.grayCorrect.gainB[0], sizeof(u32) * 6); + memcpy(¶m.grayGain[0] + i * 6, i == 0 ? &cisconfigs.gray.gainF[0] : &cisconfigs.gray.gainB[0], sizeof(u32) * 6); + + memcpy(¶m.correctColorOffset[0] + i * 6, i == 0 ? &cisconfigs.colorCorrect.offsetsF[0] : &cisconfigs.colorCorrect.offsetsB[0], sizeof(u32) * 6); + memcpy(¶m.colorOffset[0] + i * 6, i == 0 ? &cisconfigs.color.offsetsF[0] : &cisconfigs.color.offsetsB[0], sizeof(u32) * 6); + memcpy(¶m.correctGrayOffset[0] + i * 6, i == 0 ? &cisconfigs.grayCorrect.offsetsF[0] : &cisconfigs.grayCorrect.offsetsB[0], sizeof(u32) * 6); + memcpy(¶m.grayOffset[0] + i * 6, i == 0 ? &cisconfigs.gray.offsetsF[0] : &cisconfigs.gray.offsetsB[0], sizeof(u32) * 6); + } + return param; +} + +void gscan3399::StartFlat(bool iscolor) +{ + int color = iscolor ? 1 : 0; + scanner_write_reg(m_usb, SC_AUTOCORRECT, color); + unsigned char buff[64] = { 0 }; + StopWatch sw; + while (sw.elapsed_s() < 120) + { + auto lenght = m_usb->read_int(buff, sizeof(buff)); + if (lenght == sizeof(buff)) + { + HGEIntInfo info = *(HGEIntInfo*)&buff; + if (info.From == 5 && info.Code == 6) + break; + } + this_thread::sleep_for(chrono::milliseconds(30)); + DoEvents(); + } + if(sw.elapsed_s()<120) + MessageBox(NULL, TEXT(iscolor?"ɫԶУɣ":"ҶԶУɣ"), TEXT("ʾ"), MB_OK); + else + MessageBox(NULL, TEXT(iscolor ? "ɫԶУʧܣ" : "ɫԶУʧܣ"), TEXT("ʾ"), MB_OK); +} + +void gscan3399::DevStateChange() +{ + +} + +int gscan3399::getMatSum() +{ + return 0; +} + +void gscan3399::close() +{ + if (m_usb.get()) + m_usb->close(); + +} + +void gscan3399::GetExpose(int& Aside, int& Bside) +{ + +} +void gscan3399::SetExpose(int aside, int bside) +{ + +} + +void gscan3399::GetSptime(int type, int& time) +{ + if (type == 0) + time = scanner_read_reg(m_usb, SR_GET_GRAY_SP); + if (type == 1) + time = scanner_read_reg(m_usb, SR_GET_COLOR_SP); +} +void gscan3399::SetSptime(int type, int time) +{ + if (type == 0) + scanner_write_reg(m_usb, SR_SET_GRAY_SP, time); + if (type == 1) + scanner_write_reg(m_usb, SR_SET_COLOR_SP, time); +} + +void gscan3399::GetSleepTime(int& sleeptime) +{ + sleeptime = scanner_read_reg(m_usb, SR_GET_SLEEPTIME); +} +void gscan3399::SetSleepTime(int sleeptime) +{ + scanner_write_reg(m_usb, SR_SET_SLEEPTIME, sleeptime); +} + + +void gscan3399::usbcallback(bool isleft, void* usrdata) +{ + gscan3399* This = (gscan3399*)usrdata; + This->OnUsbHotplug(isleft); +} + +int gscan3399::read_data(void* data, int length, int timeout) +{ + int nread = 0; + int reading = 0; + const int buffer_size = 2 * 1024 * 1024; + StopWatch sw; + while (nread < length && sw.elapsed_ms() < timeout) { + reading = std::max(0, std::min(length - nread, buffer_size)); + reading = m_usb->read_bulk((unsigned char*)data + nread, reading); + if (reading > 0) { + nread += reading; + } + } + return nread; +} + +void gscan3399::get_imgdata() +{ + m_imgthread.enqueue([this] { + while (get_imgremains()) + { + if (is_bulktransferring()) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + continue; + } + imgremains++; + auto& buffi = im_data; + int count = front_datasize(); + buffi->resize(count); + bulk_starttransfer(); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + count = read_data(buffi->data(), count, count / (0.01 * 1024 * 1024)); + popimg(); + imgproce(buffi); + } + }); +} + +bool gscan3399::is_runing() +{ + return scanner_read_reg(m_usb, SR_STATUS) & 0x01; +} + +bool gscan3399::bulk_starttransfer() +{ + scanner_write_reg(m_usb, SR_IM_TX, 1); + return true; +} + +bool gscan3399::is_bulktransferring() +{ + return scanner_read_reg(m_usb, SR_IM_TXING); +} + +void gscan3399::popimg() +{ + scanner_write_reg(m_usb, SR_IM_POP, 1); //!< to-list +} + +int gscan3399::front_datasize() +{ + return scanner_read_reg(m_usb, SR_IM_FRONT_SIZE); +} + +int gscan3399::get_imgremains() +{ + return scanner_read_reg(m_usb, SR_IM_COUNT); //!< to-list ; +} + +void gscan3399::imgproce(std::shared_ptr>& buffs) +{ + vector mats; + bool isbwimg = false; + + auto rmc = m_config.g200params.color? cv::IMREAD_COLOR:cv::IMREAD_GRAYSCALE; + if (buffs->at(0) == -119 && buffs->at(1) == 0x50 && buffs->at(2) == 0x4e && buffs->at(3) == 0x47)//blackwhite + { + isbwimg = true; + rmc = cv::IMREAD_GRAYSCALE; + } + cv::Mat mat = cv::imdecode(*buffs, rmc); + time_t timp; + tm* p; + time(&timp); + p = localtime(&timp); + std::string filename = std::to_string(p->tm_hour) + "_" + std::to_string(p->tm_min) + "_" + std::to_string(p->tm_sec); + static int indeximg = 0; + std::string path = csPath+"\\"+filename + ".png"; + if (!mat.empty()) { + cv::imwrite(path, mat); + m_imagespath.Put(path); + } +} + +void gscan3399::OnUsbHotplug(bool isleft) +{ + +} + +void gscan3399::usb_run() +{ + unsigned char buff[64]; + while (b_usbthread) + { + if (!m_usb.get() || !m_usb->is_connected()) + { + this_thread::sleep_for(chrono::milliseconds(20)); + continue; + } + memset(buff, 0, sizeof(buff)); + auto length = m_usb->read_int(buff, sizeof(buff)); + if (((length) == sizeof(buff)) || is_bulktransferring()) + { + HGEIntInfo info = *(HGEIntInfo*)&buff; + switch (info.From) + { + case IMG: + if (is_runing()) + get_imgdata(); + break; + default: + break; + } + Error_Code = codeconvter(info); + if (Error_Code != 0) + { + devState = Error_Code == -1 ? DEV_STOP : DEV_WRONG; + } + this_thread::sleep_for(chrono::microseconds(2)); + } + } +} + +int gscan3399::codeconvter(HGEIntInfo code) +{ + if (code.From == HGType::FPGA) + { + switch (code.Code) + { + default: + break; + } + } + if (code.From == HGType::MtBoard) + { + switch (code.Code) + { + case 0x00002: + return NO_FEED; + case 0x00004: + return OPEN_COVER; + case 0x00008: + return FEED_IN_ERROR; + case 0x00010: + return PAPER_JAM; + case 0x00020: + return DETECT_DOUBLE_FEED; + case 0x00040: + return DETECT_STAPLE; + case 0x00080: + return PAPER_SKEW; + case 0x10000: + return AQUIRE_IMAGE_TIMEOUT; + case 0x20000: + return SIZE_ERROR; + default: + break; + } + } + + if (code.From == HGType::V4L2) + { + switch (code.Code) + { + case 0: + return V4L2_AQULRE_ERROR; + break; + case 1: + return V4L2_IMAGE_EMPTY; + default: + break; + } + } + if (code.From == HGType::STOPSCAN) + return -1; + + return 0; +} diff --git a/HuaGoCorrect/gscan3399.h b/HuaGoCorrect/gscan3399.h new file mode 100644 index 0000000..987f0c8 --- /dev/null +++ b/HuaGoCorrect/gscan3399.h @@ -0,0 +1,91 @@ +#pragma once +#include "IScanner.h" +#include "ThreadPool.h" +#include +#include + +class gscan3399 :public IScanner +{ +public: + gscan3399(); + virtual ~gscan3399(); + virtual void open(int vid, int pid, int index); + virtual int aquire_image(std::string& image, int num); + virtual bool IsConnected(); + virtual std::string GetFWVersion(); + virtual void SetFWVersion(); + virtual std::string GetSerialNum(); + virtual void SetSerialNum(std::string serial); + virtual void SetRatio(int tyepe, int ration); + virtual void GetRatio(int type, int& ratio); + virtual void Reboot(); + virtual void PowerOff(); + virtual bool is_scan(); + virtual bool Get_Scanner_PaperOn(); + virtual void Config_Scanner(HGScanConfig config); + virtual void Scanner_StartScan(UINT16 count); + virtual void Stop_scan(); + virtual void ResetScanner(); + virtual bool Get_IsImageQueueEmpty(); + virtual void reset(); + virtual void run(); + virtual int get_decompress_pix_type(); + virtual void set_decompress_pix_type(int pixtype); + + virtual bool Updata(std::string filename, std::function func); + + virtual void SetIsDuplex(bool value); + + virtual void ActiveteUSB(); + + virtual int GetScanNum(); + + virtual void ClrRollerNum(); + + virtual void ClrScanNum(); + + virtual void SendFlatData(CorrectParam param, int index); + + virtual CaptureParams GetFlatData(); + + virtual void StartFlat(bool iscolor); + + virtual void DevStateChange(); + + virtual int getMatSum(); + + virtual void close(); + + virtual void GetExpose(int& Aside, int& Bside); + virtual void SetExpose(int aside, int bside); + + virtual void GetSptime(int type, int& time); + virtual void SetSptime(int type, int time); + + virtual void GetSleepTime(int& sleeptime); + virtual void SetSleepTime(int sleeptime); +private: + static void usbcallback(bool isleft, void* usrdata); + int read_data(void* data, int length, int timeout); + void get_imgdata(); + bool is_runing(); + bool bulk_starttransfer(); + bool is_bulktransferring(); + void popimg(); + int front_datasize(); + int get_imgremains(); + void imgproce(std::shared_ptr>& buffs); + void OnUsbHotplug(bool isleft); + void usb_run(); + int codeconvter(HGEIntInfo code); +private: + volatile int devState; + volatile int Error_Code; + volatile bool b_usbthread; + ThreadPool m_imgthread; + std::shared_ptr m_usbthread; + std::shared_ptr> im_data; + BlockingQueue m_imagespath; + std::atomic_int imgremains; + HGScanConfig m_config; +}; \ No newline at end of file diff --git a/HuaGoCorrect/gscn_drv.cpp b/HuaGoCorrect/gscn_drv.cpp index fdd7e40..334495b 100644 --- a/HuaGoCorrect/gscn_drv.cpp +++ b/HuaGoCorrect/gscn_drv.cpp @@ -9,39 +9,37 @@ #include #include "twain.h" #include "filetools.h" -//extern CHuaGoCorrectDlg theApp; +#include "scn_usb.h" //#define BYTE unsigned char GScn_Drv::GScn_Drv() - : canUseDiscardBlank(false),selectDeviceIndex(-1),m_scannerType(-1) - , device_id(0) + :selectDeviceIndex(-1),m_scannerType(-1),m_isScanning(false) { + //run(); + XdPrint("Init GScn_Drv() \n"); + m_bRun = false; devState = DEV_STOP; - isDuplex=TRUE; InitMSGMap(); InitScannerDiviceMap(); } - GScn_Drv::~GScn_Drv() { if (m_threadUsb.joinable()) { + m_bRun = false; devState = DEV_STOP; m_threadUsb.join(); XdPrint("m_threadUsb Released True 22222222222222222222222 \n"); } XdPrint("~ GScn_Drv() \n"); } -void GScn_Drv::save_config(bool saveOrigin, bool saveFixedOrigin) -{ - m_pImages.UpdateSaveConfig(saveOrigin, saveFixedOrigin); -} + void GScn_Drv::InitMSGMap() { if (ntcMsg.size()>0) @@ -76,33 +74,18 @@ static int iNum = 0; void GScn_Drv::open(int vid, int pid,int index) { - usb_scan_dev devs = Devices(vid, pid); - if (devs._NumberOfDevs != 0) + auto devs = UsbScan_List::find_vid_pid(vid, pid); + + if (devs.size() != 0) { - device_id = devs._CURNUMBER; - m_usb.open(devs.dev_infos[index].index);//ͬʱڶͬɨ豸ʱĬѡȡһvid pidƥ豸 + m_usb = *devs.begin(); + m_usb->open();//ͬʱڶͬɨ豸ʱĬѡȡһvid pidƥ豸 selectDeviceIndex=index; - m_scannerType=G200; - } -} -void GScn_Drv::open(int vid) -{ - usb_scan_dev devs = Devices(vid); - if (devs._NumberOfDevs != 0) - { - device_id = devs._CURNUMBER; - m_usb.open(devs.dev_infos[0].index);//ͬʱڶͬɨ豸ʱĬѡȡһvid pidƥ豸 - selectDeviceIndex = 0; - m_scannerType = G200; - } -} -void GScn_Drv::close() -{ - if (m_usb.is_connected()) - { - m_usb.close(); + m_scannerType=G300; + h= ::FindWindow(NULL, "HGScannerTool"); } } + static void DoEvents() { MSG msg; @@ -110,25 +93,26 @@ static void DoEvents() , NULL, 0, 0, PM_REMOVE)) { DispatchMessage(&msg); + TranslateMessage(&msg); } } -cv::Mat GScn_Drv::popMat(int num) +std::string GScn_Drv::popMat(int num) { - cv::Mat image = m_pImages.popMat(num); + auto image = m_pImages.popMat(num); return image; } -int GScn_Drv::aquire_image(cv::Mat& image,int num) +int GScn_Drv::aquire_image(std::string& image,int num) { while (true) { - if (Get_IsImageQueueEmpty()) + if (this->Get_IsImageQueueEmpty()) { DoEvents(); - if (!is_scan()) + if (!this->is_scan()) break; } else @@ -139,30 +123,6 @@ int GScn_Drv::aquire_image(cv::Mat& image,int num) return 0; } } - this_thread::sleep_for(std::chrono::milliseconds(2)); - } - return -1; -} - -int GScn_Drv::aquire_image(cv::Mat & image) -{ - while (true) - { - if (Get_IsImageQueueEmpty()) - { - DoEvents(); - if (!is_scan()) - break; - } - else - { - if (m_pImages.valid()) - { - image = m_pImages.popMat(); - return 0; - } - } - this_thread::sleep_for(std::chrono::milliseconds(2)); } return -1; } @@ -174,6 +134,95 @@ int GScn_Drv::getMatSum() return iSum; } +void GScn_Drv::close() +{ + m_usb->close(); +} + +void GScn_Drv::GetExpose(int& Aside, int& Bside) +{ + USBCB asideexp = { GET_UV_EXPOSA,0,0 }; + m_usb->write_bulk(&asideexp, sizeof(asideexp)); + m_usb->read_bulk(&asideexp, sizeof(asideexp)); + Aside = asideexp.u32_Data; + USBCB bsideexp = { GET_UV_EXPOSB,0,0 }; + m_usb->write_bulk(&bsideexp, sizeof(asideexp)); + m_usb->read_bulk(&bsideexp, sizeof(asideexp)); + Bside = bsideexp.u32_Data; + +} + +void GScn_Drv::SetExpose(int aside, int bside) +{ + USBCB asideexp = { SET_UV_EXPOSA,aside,0 }; + m_usb->write_bulk(&asideexp, sizeof(asideexp)); + USBCB bsideexp = { SET_UV_EXPOSB,bside,0 }; + m_usb->write_bulk(&bsideexp, sizeof(bsideexp)); + +} + +void GScn_Drv::GetSptime(int type, int& time) +{ + USBCB usb = {0,0,0}; + switch (type) + { + case 0: + usb.u32_CMD = 0x100;//GET_GRAY_SP + break; + case 1: + usb.u32_CMD = 0x102;//GET_COLOR_SP + break; + case 2: + usb.u32_CMD = 0x104;//GET_UV_SP + break; + default: + break; + } + m_usb->write_bulk(&usb, sizeof(usb)); + m_usb->read_bulk(&usb, sizeof(usb)); + time = usb.u32_Data; +} + +void GScn_Drv::SetSptime(int type, int time) +{ + USBCB usb = { 0,time,0 }; + switch (type) + { + case 0: + usb.u32_CMD = 0x101;//GET_GRAY_SP + break; + case 1: + usb.u32_CMD = 0x103;//GET_COLOR_SP + break; + case 2: + usb.u32_CMD = 0x105;//GET_UV_SP + break; + default: + break; + } + m_usb->write_bulk(&usb, sizeof(usb)); +} + +void GScn_Drv::GetSleepTime(int& sleeptime) +{ + if (m_usb.get() && m_usb->is_connected()) + { + USBCB usb = { GET_SLEEP_TIME,0,0 }; + m_usb->write_bulk(&usb, sizeof(usb)); + m_usb->read_bulk(&usb, sizeof(usb)); + sleeptime=usb.u32_Data; + } +} + +void GScn_Drv::SetSleepTime(int sleeptime) +{ + if (m_usb.get() && m_usb->is_connected()) + { + USBCB usb = { SET_SLEEP_TIME,sleeptime,0 }; + m_usb->write_bulk(&usb, sizeof(usb)); + } +} + void GScn_Drv::reset() { while (!m_pImages.empty()) @@ -184,13 +233,17 @@ void GScn_Drv::reset() void GScn_Drv::pushMat(JpegBuffer& data) { + std::lock_guard lck(m_imgLocker); m_pImages.pushMat(data); } -BOOL GScn_Drv::IsConnected() +bool GScn_Drv::IsConnected() { - //XdPrint("Check for Connected!\n"); - return m_usb.is_connected(); + if(m_usb.get()) + return m_usb->is_connected(); + else + return false; + } @@ -200,99 +253,26 @@ cv::Mat GScn_Drv::Get_Img_Data(int bufferSize) cv::Mat iData(1, bufferSize,CV_8UC1); USBCB usbcb = { GET_IMAGE,0,bufferSize }; DWORD transfer; - //XdPrint("Get_Img_Data bulk_out GET_IMAGE CV_8UC1 \n....................."); - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - StopWatch sw; - sw.start(); - - //XdPrint("Get_Img_Data Read_Data bufferSize begin \n....................."); - m_usb.Read_Data(iData.data, bufferSize, 2000, &transfer); - sw.stop(); - //XdPrint("GetDate Consume time %lf \n.....................................",sw.time_run()); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + m_usb->read_bulk(iData.data, bufferSize); return iData; } void GScn_Drv::run() { + //m_isScanning=false; if (m_threadUsb.joinable()) { + m_bRun = false; devState = DEV_STOP; m_threadUsb.join(); } + m_bRun = true; devState = DEV_ISRUNNING; m_threadUsb = std::thread(&GScn_Drv::usbmain, this); } -INT GScn_Drv::get_decompress_pix_type() -{ - return pixType; -} - -void GScn_Drv::set_decompress_pix_type(int pixtype) -{ - if (pixtype==TWPT_RGB)//TWPT_RGB=2 - { - pixType=TJPF_BGR; - XdPrint("TurboJpeg TJPF_BGR\n"); - } - else - { - pixType=TJPF_GRAY; - XdPrint("TurboJpeg TJPF_GRAY\n"); - } -} - -void GScn_Drv::enableDiscardBlank(bool bVal) -{ - canUseDiscardBlank=bVal; -} - -void GScn_Drv::SetIsDuplex(BOOL value) -{ - isDuplex=value; - m_pImages.setduplexflag(value); -} - -void GScn_Drv::SetRotate(int rotateType) -{ - m_rotate=rotateType; -} - -void GScn_Drv::SetBackRotate(bool enBackRoate) -{ - backRotate=enBackRoate; -} - -std::vector GScn_Drv::GetSerials(int vid,int pid) -{ - usb_scan_dev devs=Devices(vid,pid); - for (int i=0;i0) - { - vcSerials.push_back(serial); - } - usb.close(); - } - return vcSerials; -} void GScn_Drv::ActiveteUSB() { @@ -300,26 +280,84 @@ void GScn_Drv::ActiveteUSB() { DWORD transfer; USBCB usbcb = { 1024,0 ,0 }; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); } } +bool GScn_Drv::Updata(std::string filename, std::function func) +{ + std::ifstream updatefile; + updatefile.open(filename, std::ios_base::in | std::ios_base::binary); + if (!updatefile.is_open()) + { + return false; + } + updatefile.seekg(0, std::ios::end); + size_t length = updatefile.tellg(); + func(0, length); + updatefile.seekg(0, std::ios::beg); + USBCB pre_update = { PRE_UPGRADE,0,length }; + m_usb->write_bulk(&pre_update, sizeof(pre_update)); + size_t nreaded = 0; + size_t nleft = length; + int buffersize = 1024 * 1024; + if (length <= buffersize)//С1MB + { + char* uotstream = new char[length]; + USBCB update = { START_UPGRADE,0,length }; + m_usb->write_bulk(&update, sizeof(update)); + updatefile.read(uotstream, length); + m_usb->write_bulk(uotstream, length); + m_usb->read_bulk(&update, sizeof(update)); + if (update.u32_Count != length) + return false; + delete[] uotstream; + } + else + { + while (true) + { + int ntotransfer; + if (nleft < buffersize) + ntotransfer = nleft; + else + ntotransfer = buffersize; + USBCB update = { START_UPGRADE,0,ntotransfer }; + m_usb->write_bulk(&update, sizeof(update)); + std::vector data; + data.resize(ntotransfer); + updatefile.read(data.data(), ntotransfer); + m_usb->write_bulk(data.data(), ntotransfer); + m_usb->read_bulk(&update, sizeof(update)); + nreaded += ntotransfer; + nleft -= ntotransfer; + func(nreaded, length); + if (nreaded >= length) + break; + this_thread::sleep_for(std::chrono::milliseconds(10)); + } + } + + USBCB updatefinished = { UPDATE_FINISHED,0,0 }; + m_usb->write_bulk(&updatefinished, sizeof(updatefinished)); + return true; +} + DWORD GScn_Drv::usbmain() { try { - while (devState == DEV_ISRUNNING) + while (m_bRun) { + if (devState==DEV_ISRUNNING) + { if (!IsConnected()) { Sleep(200); continue; } USBCB usbcb = Get_Scanner_Status(); - - //XdPrint("u32_CMD is %d, u32_Data is %d, u32_Count is %d \n", usbcb.u32_CMD, usbcb.u32_Data, usbcb.u32_Count); - switch (usbcb.u32_Data) { case HAVE_IMAGE: @@ -350,45 +388,55 @@ DWORD GScn_Drv::usbmain() memcpy(&(bufferF.data[(k - 1) * 1023]), &(imgData.data[(j + k - 1) * 1024]), 1023); } } - pushMat(JpegBuffer(bufferB,pixType,0,0)); - pushMat(JpegBuffer(bufferF,pixType,1,0)); - Pop_Image(); + pushMat(JpegBuffer(bufferB,m_config.g200params.color==1?TJPF_BGR:TJPF_GRAY,0,0)); + pushMat(JpegBuffer(bufferF, m_config.g200params.color == 1 ? TJPF_BGR : TJPF_GRAY,1,0)); break; } case G300: case G400: case G500: - pushMat(JpegBuffer(imgData,pixType,0,0)); + pushMat(JpegBuffer(imgData, m_config.g200params.color == 1 ? TJPF_BGR : TJPF_GRAY,0,0)); break; default: break; } + Pop_Image(); break; } case STOP_SCAN: { + m_isScanning=false; devState = DEV_STOP; - //::PostMessage(HWND_BROADCAST,WM_MYMESSAGE,200,NULL); + m_pImages.SetScanFlag(false); break; } + case AUTO_FLAT_FINISHED: + { + m_isScanning = false; + devState = DEV_STOP; + MessageBox(NULL,TEXT("ԶУɣ"), TEXT("ʾ"), MB_OK); + } + break; case COUNT_MODE: case NO_FEED: case OPEN_COVER: case FEED_IN_ERROR: - //case PAPER_JAM: case DETECT_DOUBLE_FEED: case DETECT_STAPLE: case PAPER_SKEW: case HARDWARE_ERROR: case PC_SCAN_BUSY_or_ERROR: + MessageBox(h, ntcMsg[usbcb.u32_Data].c_str(), "ʾ", MB_OK | MB_ICONERROR); devState = DEV_WRONG; + m_pImages.SetScanFlag(false); break; case NORMAL: break; default: break; } - this_thread::sleep_for(std::chrono::milliseconds(10)); + this_thread::sleep_for(std::chrono::milliseconds(20)); + } } return 0; } @@ -404,117 +452,91 @@ DWORD GScn_Drv::usbmain() { XdPrint("CException"); } - + return 0; } /////////////////////////////////////////////////////////////////////////// void GScn_Drv::Config_Scanner(PUSBCB pUSBCB) { - if (m_usb.is_connected()) + if (m_usb->is_connected()) { std::lock_guard lck(m_imgLocker); DWORD transfer; - m_usb.bulk_out(0x00, pUSBCB, sizeof(USBCB), &transfer); + m_usb->write_bulk(pUSBCB, sizeof(USBCB)); } } -//void GScn_Drv::setlist(std::vector >list) -//{ -// m_pImages.setlist(list); -//} + +void GScn_Drv::Config_Scanner(HGScanConfig config) +{ + m_config = config; + USBCB usbcb = { CONFIGURED_DATA ,m_config.value,0 }; + if (m_usb->is_connected()) + { + std::lock_guard lck(m_imgLocker); + DWORD transfer; + m_usb->write_bulk(&usbcb, sizeof(USBCB)); + } +} + /////////////////////////////////////////////////////////////////////////// void GScn_Drv::Scanner_StartScan(UINT16 count) { //count = 0; //XdPrint("Scanner_StartScan.............\n"); - if (m_usb.is_connected()) + if (m_usb->is_connected()) { //XdPrint("Scanner Isconnected.............\n"); std::lock_guard lck(m_imgLocker); DWORD transfer; USBCB usbcb = { START_COMMAND,AUTO_SCAN_MODE ,0 }; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); iNum = 0; - m_pImages.pixType=pixType; + m_pImages.pixType=m_config.g200params.color; m_pImages.SetDevModel(m_scannerType); m_pImages.SetFilePath(csPath); m_pImages.run(); + m_pImages.SetScanFlag(true); run(); } } -void GScn_Drv::Set_Scanner_Correct_Ratio(float hrz, float vtc) -{ - if (m_usb.is_connected()) { - lock_guard lck(m_imgLocker); - UINT32 hv = *(UINT32*)(&hrz); - USBCB usbcbH = { SET_JUST_COF_H,hv,0 }; - DWORD transfer; - m_usb.bulk_out(0x00,&usbcbH,sizeof(usbcbH), &transfer); - this_thread::sleep_for(std::chrono::milliseconds(200)); - UINT32 vv = *(UINT32*)(&vtc); - USBCB usbcbV = { SET_JUST_COF_V,vv,0 }; - m_usb.bulk_out(00,&usbcbV, sizeof(usbcbV),&transfer); - } -} - -void GScn_Drv::Get_Scanner_Correct_Ratio(float& hrz, float& vtc) -{ - if (m_usb.is_connected()) { - lock_guard lck(m_imgLocker); - USBCB usbcb = { GET_JUST_COF_H ,0,0 }; - DWORD transfer; - m_usb.bulk_out(00,&usbcb, sizeof(usbcb),&transfer); - m_usb.bulk_in(00,&usbcb, sizeof(usbcb),200, &transfer); - float hratio = *((float*)(&usbcb.u32_Data)); - hrz = hratio; - usbcb = { GET_JUST_COF_V ,0,0 }; - m_usb.bulk_out(00, &usbcb, sizeof(usbcb), &transfer); - m_usb.bulk_in(00, &usbcb, sizeof(usbcb),200, &transfer); - float vratio = *((float*)(&usbcb.u32_Data)); - vtc = vratio; - } -} /////////////////////////////////////////////////////////////////////////// std::string GScn_Drv::GetFWVersion() { - if (m_usb.is_connected()) + if (m_usb->is_connected()) { std::lock_guard lck(m_imgLocker); - std::string pFWVersion = " "; - USBCB usbcb = { GET_FW_VERSION,8,0 }; - DWORD transfer; + std::string pFWVersion = " "; + USBCB usbcb = { GET_FW_VERSION,0,0 }; XdPrint("Get GetFWVersion"); - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); CString cslog; cslog.Format("GetFWVersion Read_Data %d",usbcb.u32_Data); - //WriteLog(cslog); - - m_usb.Read_Data(&pFWVersion[0], 8, 200, &transfer); + m_usb->read_bulk(&pFWVersion[0], 10); return pFWVersion; } return ""; } -void GScn_Drv::SetSerialNum(byte *pvalue) +void GScn_Drv::SetFWVersion() { - if (m_usb.is_connected()) + if (m_usb->is_connected()) { std::lock_guard lck(m_imgLocker); - for (UINT i = 0; i < 12; i = i + 4) - { - USBCB usbcb; - usbcb.u32_CMD = SEND_SERIAL; - usbcb.u32_Data = (UINT)pvalue[i] + ((UINT)pvalue[i + 1] << 8) + ((UINT)pvalue[i + 2] << 16) + ((UINT)pvalue[i + 3] << 24); - usbcb.u32_Count = i; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - //m_usb.bulk_out(0x00, &pvalue, 12, &transfer); - Sleep(1000); - } + } +} + +void GScn_Drv::SetSerialNum(std::string pvalue) +{ + if (m_usb->is_connected()) + { + std::lock_guard lck(m_imgLocker); + USBCB sercmd = { SEND_SERIAL ,0,14}; + m_usb->write_bulk(&sercmd, sizeof(sercmd)); + m_usb->write_bulk(&pvalue, pvalue.length()); } return; } @@ -525,13 +547,13 @@ int GScn_Drv::GetScanNum() USBCB usbcb = { GET_SCANN_NUM,0,4 }; DWORD transfer; XdPrint("Get GetScanNum"); - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); CString cslog; cslog.Format("GetScanNum Read_Data %d",usbcb.u32_Data); //WriteLog(cslog); - m_usb.Read_Data(&usbcb, sizeof(usbcb), 200, &transfer); + m_usb->read_bulk(&usbcb, sizeof(usbcb)); return usbcb.u32_Data; } @@ -541,7 +563,7 @@ void GScn_Drv::ClrRollerNum() USBCB usbcb = { CLR_ROLLER_NUM,0,4 }; DWORD transfer; XdPrint("Get ClrRollerNum"); - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); return; } @@ -551,168 +573,61 @@ void GScn_Drv::ClrScanNum() USBCB usbcb = { CLR_SCAN_NUM,0,4 }; DWORD transfer; XdPrint("Get ClrScanNum"); - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); return; } -void GScn_Drv::SendColorCorrentFlat(byte buffer[],int size) +void GScn_Drv::SendFlatData(CorrectParam param, int index) { - DWORD transfer; - byte temp[524] = {0}; - for(int i = 0; i<524;i++) + UsbKeyWords keyword; + switch (index) { - temp[i] = buffer[i]; + case 0: + keyword = SEND_COLORCORRECT_FLAT; + break; + case 1: + keyword = SEND_COLOR_FLAT; + break; + case 2: + keyword = SEND_GRAYCORRECT_FLAT; + break; + case 3: + keyword = SEND_GRAY_FLAT; + break; + default: + break; } - m_usb.bulk_out(0x00, &temp, size, &transfer); - return; + USBCB cmd = { keyword ,0,0 }; + m_usb->write_bulk(&cmd, sizeof(cmd)); + m_usb->write_bulk(¶m, sizeof(param)); } -void GScn_Drv::SendColorFlat(byte buffer[],int size) +CaptureParams GScn_Drv::GetFlatData() { - DWORD transfer; - byte temp[524] = {0}; - for(int i = 0; i<524;i++) - { - temp[i] = buffer[i]; - } - m_usb.bulk_out(0x00, &temp, size, &transfer); - return; -} - -void GScn_Drv::SendGrayCorrectFlat(byte buffer[],int size) -{ - DWORD transfer; - byte temp[524] = {0}; - for(int i = 0; i<524;i++) - { - temp[i] = buffer[i]; - } - m_usb.bulk_out(0x00, &temp, size, &transfer); - return; -} - -void GScn_Drv::SendGrayFlat(byte buffer[],int size) -{ - DWORD transfer; - byte temp[524] = {0}; - for(int i = 0; i<524;i++) - { - temp[i] = buffer[i]; - } - m_usb.bulk_out(0x00, &temp, size, &transfer); - return; -} - -byte* GScn_Drv::GetFlatData() -{ - byte buffer[512] = {0}; + CaptureParams param = {0}; USBCB usbcb = { GET_FLAT_DATA,0,0 }; DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - - CString cslog; - cslog.Format("GetFlatData Read_Data %d",usbcb.u32_Data); - //WriteLog(cslog); - m_usb.Read_Data(&buffer, 512, 200, &transfer); - - return buffer; + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + m_usb->read_bulk(¶m, sizeof(param)); + return param; } -byte* GScn_Drv::GetCisPara() +void GScn_Drv::StartFlat(bool iscolor) { - byte buffer[16] = {0}; - USBCB usbcb = { GET_CIS_PARA,0,16 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + if (!m_usb->is_connected()) + return; - CString cslog; - cslog.Format("GetCisPara Read_Data %d",usbcb.u32_Data); - //WriteLog(cslog); - - m_usb.Read_Data(&buffer, 16, 200, &transfer); - - return buffer; -} - -bool GScn_Drv::FlatA4() -{ - if (!m_usb.is_connected()) - { - return false; - } - - //XdPrint("·START_FLAT \n....................."); USBCB usbcb = { START_FLAT,0,0 }; DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - //XdPrint("·START_FLAT \n....................."); - - //Sleep(1500); - - if(devState != DEV_ISRUNNING) - { - //XdPrint("DEV_ISRUNNING \n....................."); - devState = DEV_ISRUNNING; + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + if (m_threadUsb.joinable()) { + m_bRun = false; + devState = DEV_STOP; + m_threadUsb.join(); } - //iNum = 0; - m_pImages.pixType=pixType; - m_pImages.SetDevModel(m_scannerType); - m_pImages.SetFilePath(csPath); - m_pImages.run(); - - return true; -} - -bool GScn_Drv::FlatA4Conrrect() -{ - char cTime[32]; - CTime currTime = CTime::GetCurrentTime(); - _snprintf(cTime, 30, "[%04d-%02d-%02d %02d:%02d:%02d]", - currTime.GetYear(), currTime.GetMonth(), currTime.GetDay(), - currTime.GetHour(), currTime.GetMinute(), currTime.GetSecond()); - - if (!m_usb.is_connected()) - { - XdPrint("%s m_usb δ \n...................", cTime); - return false; - } - - //XdPrint("%s ·START_FLAT \n.....................", cTime); - USBCB usbcb = { START_FLAT,0,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - //XdPrint("%s ·START_FLAT \n.................", cTime); - - //Sleep(1500); - - if(devState != DEV_ISRUNNING) - { - //XdPrint("%s DEV_ISRUNNING \n.....................", cTime); - devState = DEV_ISRUNNING; - } - - return true; -} - -bool GScn_Drv::FlatA3(UINT para) -{ - if (!m_usb.is_connected()) - { - return false; - } - - USBCB usbcb = { START_FLAT,para,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - - Sleep(1500); + m_bRun = true; devState = DEV_ISRUNNING; - m_pImages.pixType=pixType; - m_pImages.SetDevModel(m_scannerType); - m_pImages.SetFilePath(csPath); - m_pImages.run(); - - return true; + m_threadUsb = std::thread(&GScn_Drv::usbmain, this); } void GScn_Drv::DevStateChange() @@ -720,110 +635,65 @@ void GScn_Drv::DevStateChange() devState = DEV_STOP; } -bool GScn_Drv::SendrAdPara(UINT para) -{ - if (!m_usb.is_connected()) - { - return false; - } - - std::lock_guard lck(m_imgLocker); - USBCB usbcb = { ADI_PARA,para,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - - //Sleep(500); - return true; -} - -bool GScn_Drv::SendrRgbAdPara(UINT para) -{ - if (!m_usb.is_connected()) - { - return false; - } - - std::lock_guard lck(m_imgLocker); - USBCB usbcb = { RGB_ADI_PARA,para,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - - //Sleep(500); - return true; -} - -bool GScn_Drv::SenGRPara(UINT para) -{ - if (!m_usb.is_connected()) - { - return false; - } - - std::lock_guard lck(m_imgLocker); - USBCB usbcb = { SEND_COMPONENTS_GR,para,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - - Sleep(500); - return true; -} - -bool GScn_Drv::SenGBPara(UINT para) -{ - if (!m_usb.is_connected()) - { - return false; - } - - std::lock_guard lck(m_imgLocker); - USBCB usbcb = { SEND_COMPONENTS_GB,para,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - - Sleep(500); - return true; -} - /////////////////////////////////////////////////////////////////////////// -byte* GScn_Drv::GetSerialNum() +std::string GScn_Drv::GetSerialNum() { - if (!m_usb.is_connected()) + if (!m_usb.get()&&!m_usb->is_connected()) { - return false; + return ""; } std::lock_guard lck(m_imgLocker); - byte buffer[16] = {0}; - USBCB usbcb = { GET_SERIAL,0,12 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - + std::string str; + str.resize(14); + USBCB usbcb = { GET_SERIAL,0,14 }; + m_usb->write_bulk(&usbcb, sizeof(usbcb)); XdPrint("GetSerialNum Read_Data %d",usbcb.u32_Data); + m_usb->read_bulk(&str, 14); + return str; +} - m_usb.Read_Data(&buffer, 16, 50, &transfer); +void GScn_Drv::SetRatio(int tyepe, int ration) +{ + UsbKeyWords keyword = tyepe == 0 ? SET_JUST_COF_H : SET_JUST_COF_V; + USBCB cmd = { keyword ,ration,0}; + m_usb->write_bulk(&cmd, sizeof(cmd)); +} - return buffer; +void GScn_Drv::GetRatio(int type, int& ratio) +{ + UsbKeyWords keyword = type == 0 ? GET_JUST_COF_H : GET_JUST_COF_V; + USBCB cmd = { keyword ,0,0 }; + m_usb->write_bulk(&cmd, sizeof(cmd)); + m_usb->read_bulk(&cmd, sizeof(cmd)); + ratio = cmd.u32_Data; +} + +void GScn_Drv::Reboot() +{ + USBCB cmd = { REBOOT,0,0 }; + m_usb->write_bulk(&cmd, sizeof(cmd)); } /////////////////////////////////////////////////////////////////////////// USBCB GScn_Drv::Get_Scanner_Status() { std::lock_guard lck(m_imgLocker); - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) { //XdPrint("Get_Scanner_Status Error\n"); USBCB errorType = { NO_COMMAND ,PC_SCAN_BUSY_or_ERROR ,0 }; return errorType; } - //XdPrint("Get_Scanner_Status GET_DSP_STATUS bulk_out\n"); + //XdPrint("Get_Scanner_Status GET_DSP_STATUS write_bulk\n"); USBCB usbcb = { GET_DSP_STATUS ,0,0 }; DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); //XdPrint("Get_Scanner_Status Read_Data %d \n",usbcb.u32_Data); - m_usb.Read_Data(&usbcb, sizeof(usbcb), 200, &transfer); + m_usb->read_bulk(&usbcb,sizeof(usbcb)); //XdPrint("Get_Scanner_Status return usbcb \n",usbcb.u32_Data); return usbcb; @@ -832,63 +702,63 @@ USBCB GScn_Drv::Get_Scanner_Status() /////////////////////////////////////////////////////////////////////////// bool GScn_Drv::is_scan() { - return devState == DEV_ISRUNNING; + return devState==DEV_ISRUNNING; } /////////////////////////////////////////////////////////////////////////// -BOOL GScn_Drv::Get_Scanner_PaperOn() +bool GScn_Drv::Get_Scanner_PaperOn() { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) { - return FALSE; + return false; } - USBCB usbcb = { GET_PAPER_STATUS ,0,0 }; + USBCB usbcb = { GET_PAPERFEEDER_STATUS ,0,0 }; DWORD transfer; std::lock_guard lck(m_imgLocker); - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - m_usb.bulk_in(0x00, &usbcb, sizeof(usbcb), 200, &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + m_usb->read_bulk(&usbcb, sizeof(usbcb)); return usbcb.u32_Data != 0; } /////////////////////////////////////////////////////////////////////////// void GScn_Drv::Pop_Image() { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) { return; } + std::lock_guard lck(m_imgLocker); USBCB usbcb = { POP_IMAGE ,0,0 }; DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); } /////////////////////////////////////////////////////////////////////////// void GScn_Drv::Stop_scan() { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) { return; } std::lock_guard lck(m_imgLocker); USBCB usbcb = { STOP ,0,0 }; DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); } void GScn_Drv::ResetScanner() { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) return; std::lock_guard lck(m_imgLocker); USBCB usbcb = { INIT_HARDWARE_SYS ,0,0 }; DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); } /////////////////////////////////////////////////////////////////////////// bool GScn_Drv::Get_IsImageQueueEmpty() { - bool bIsEmpty = m_pImages.empty(); - return bIsEmpty; + return m_pImages.empty(); } \ No newline at end of file diff --git a/HuaGoCorrect/gscn_drv.h b/HuaGoCorrect/gscn_drv.h index 6a8a7ab..d0e2172 100644 --- a/HuaGoCorrect/gscn_drv.h +++ b/HuaGoCorrect/gscn_drv.h @@ -1,375 +1,98 @@ #pragma once -#include "scn_usb.h" +#include "IUsb.h" #include #include #include -#include #include -#include "MutexEx.h" #include "opencv2/core/core.hpp" -#include -#include "jpeglib.h" -#include #include #include #include "ImageMatQueue.h" #include #include "PublicFunc.h" -#include "HuaGoCorrect.h" +#include "IScanner.h" using namespace cv; -typedef struct tag_USBCB { - UINT32 u32_CMD; - UINT32 u32_Data; - UINT32 u32_Count; -}USBCB, *PUSBCB; -typedef struct tag_USBCBA4 -{ - UINT u32_Command; /* command to execute */ - UINT u32_Data; /* generic data field */ - UINT u32_Count; /* number of bytes to transfer */ - byte buffer[512]; //=new byte[1024]; -}USBCBA4, *PUSBCBA4; - -//u32_CMD -enum tagUsbKeyWords :UINT32 -{ - // - NO_COMMAND = 0, - //ȡdsp ״̬ - GET_DSP_STATUS = 1, - //ȡͼ - GET_IMAGE = 2, - //DSPפͼ - POP_IMAGE = 3, - //ʼɨ - START_COMMAND = 4, - //ֹͣɨ - STOP = 5, - //ȡɨɨģʽ - GET_SCAN_MODE = 6, - //ȡ̼汾 - GET_FW_VERSION = 7, - //PC˵״̬ - SEND_STATUS_PC = 8, - //·ɨò - CONFIGURED_DATA = 9, - //·̼Ϣ - SEND_FW = 10, - //ȡɨ - GET_CONFIG_DATA = 11, - //ȡɨ - GET_SCANN_NUM = 12, - //ȡֽ״̬ - GET_PAPERFEEDER_STATUS = 13, - //DSPʼ - INIT_HARDWARE_SYS = 14, - //ȡֽ״̬ - GET_PAPER_STATUS = 0x0d, - //·ԪòҶȣLED Rعʱ䣩 - SEND_COMPONENTS_GR = 15, - //·ԪòLED G/Bعʱ䣩 - SEND_COMPONENTS_GB = 16, - //·ɨģʽ - SEND_SCAN_MODE = 17, - //ʼƽ - START_FLAT = 18, - //ֹͣƽ - STOP_FLAT = 19, - //·200dpiɫƽ - SEND_200_COLOR_FLAT_DATA = 20, - //·300dpiɫƽ - SEND_300_COLOR_FLAT_DATA = 21, - //ȡ200dpiɫƽ - GET_200_COLOR_FLAT_DATA = 22, - //ȡ300dpiɫƽ - GET_300_COLOR_FLAT_DATA = 23, - //·200dpiҶƽУ - SEND_200_GRAY_FLAT_DATA = 24, - //·300dpiҶƽУ - SEND_300_GRAY_FLAT_DATA = 25, - //ȡ200DPIҶƽУ - GET_200_GRAY_FLAT_DATA = 26, - //ȡ300DPIҶƽУ - GET_300_GRAY_FLAT_DATA = 27, - //·к - SEND_SERIAL = 28, - //ȡк - GET_SERIAL = 29, - //ȡ - GET_ROLLER_NUM = 30, - // - CLR_ROLLER_NUM = 31, - //ɨ - CLR_SCAN_NUM = 32, - PRE_UPGRADE =33, - START_UPGRADE = 34, - RGB_ADI_PARA =35, - ADI_PARA =36, - GET_CIS_PARA =37, - SEND_COLOR_FLAT = 41, - SEND_COLORCORRECT_FLAT=42, - SEND_GRAY_FLAT=43, - SEND_GRAYCORRECT_FLAT=44, - GET_FLAT_DATA=45, - //úϵ - SET_JUST_COF_H = 0x38, - //ȡϵ - GET_JUST_COF_H = 0x39, - - //ϵ - SET_JUST_COF_V = 0x41, - //ȡϵ - GET_JUST_COF_V -}; - -typedef enum tagUsbKeyWords UsbKeyWords, *PUsbKeyWords; -//u32_Data -enum tagUsbSupported -{ - //ֹͣɨ - SCAN_STOP = -2, - //쳣 - HAVE_ERROR = -1, - //״̬ - NORMAL = 0, - // - OPEN_COVER = 1, - // ֽ - NO_FEED = 2, - // ֽʧ - FEED_IN_ERROR = 4, - // ֽ - PAPER_JAM = 8, - // ⵽˫ - DETECT_DOUBLE_FEED = 16, - // ⵽鶤 - DETECT_STAPLE = 32, - // ֽб - PAPER_SKEW = 64, - // Զģʽ - AUTO_SCAN_MODE = 65, - // ֶģʽ - MANAUL_SCAN_MODE = 66, - // ģʽ - COUNT_MODE = 67, - // Ӳ - HARDWARE_ERROR = 68, - // FPGA - FPGA_ERROR = 68, - // ʼ - START_SCAN = 69, - //ֹͣ - STOP_SCAN = 70, - //ͼ - HAVE_IMAGE = 71, - // ɨ - UPDATE_SCAN_PARAMETER = 72, - // PCæ - PC_SCAN_BUSY_or_ERROR = 73 -}; - -typedef enum tagUsbSupported UsbSupported, *PUsbSupported; - -enum tagDevState -{ - DEV_STOP = -1, - DEV_ISRUNNING, - DEV_WRONG -}; - -typedef enum tagDevState DevState, PDevState; - -enum tagEventIndex -{ - EVENT_IMAGE, - EVENT_NUM -}; - -enum tagDEVMODEL -{ - G100=0, - G200, - G300, - G400, - G500 -}; - -class twainImage -{ -public: - twainImage(){} - - ~twainImage() - { - release(); - } - - twainImage(cv::Mat image,int side=-1) - { - this->m_image=image; - this->m_side=side; - this->m_width=image.cols; - this->m_height=image.rows; - } - - bool empty() - { - return m_image.empty(); - } - - int GetWidth() - { - return m_image.cols; - } - - int GetHeight() - { - return m_image.rows; - } - - void release() - { - if (!m_image.empty()) - { - m_image.release(); - } - } - -public: - cv::Mat m_image; - int m_side; -private: - int m_height; - int m_width; -}; - -class GScn_Drv +class GScn_Drv :public IScanner { public: GScn_Drv(); + virtual ~GScn_Drv(); + virtual void open(int vid, int pid, int index); + virtual int aquire_image(std::string& image, int num); + virtual bool IsConnected(); + virtual std::string GetFWVersion(); + virtual void SetFWVersion(); + virtual std::string GetSerialNum(); + virtual void SetSerialNum(std::string serial); + virtual void SetRatio(int tyepe, int ration); + virtual void GetRatio(int type, int& ratio); + virtual void Reboot(); + virtual void PowerOff() {}; + virtual bool is_scan(); + virtual bool Get_Scanner_PaperOn(); + virtual void Config_Scanner(PUSBCB pUSBCB); + virtual void Config_Scanner(HGScanConfig config); + virtual void Scanner_StartScan(UINT16 count); + virtual void Stop_scan(); + virtual void ResetScanner(); + virtual bool Get_IsImageQueueEmpty(); + virtual void reset(); + virtual void run(); + virtual void ActiveteUSB(); + virtual bool Updata(std::string filename, std::function func); + virtual int GetScanNum(); - ~GScn_Drv(); - void save_config(bool saveOrigin, bool saveFixedOrigin); - void open(int vid, int pid,int index); - void open(int vid); - void close(); - int aquire_image(cv::Mat& image,int num); - int aquire_image(cv::Mat& image); - BOOL IsConnected(); - void Get_Scanner_Correct_Ratio(float & hrz, float & vtc); - std::string GetFWVersion(); - byte* GetSerialNum(); - bool is_scan(); - USBCB Get_Scanner_Status(); - BOOL Get_Scanner_PaperOn(); - void Config_Scanner(PUSBCB pUSBCB); - //void setlist(std::vector> list); - void Scanner_StartScan(UINT16 count); - void Set_Scanner_Correct_Ratio(float hrz, float vtc); - void Stop_scan(); - void ResetScanner(); - bool Get_IsImageQueueEmpty(); - void reset(); - INT get_decompress_pix_type(); - void set_decompress_pix_type(int pixtype); + virtual void ClrRollerNum(); - void enableDiscardBlank(bool bVal); + virtual void ClrScanNum(); - void SetIsDuplex(BOOL value); - - void SetRotate(int rotateType); + virtual void SendFlatData(CorrectParam param, int index); - void SetBackRotate(bool enBackRoate); + virtual CaptureParams GetFlatData(); - std::vector GetSerials(int vid,int pid); + virtual void StartFlat(bool iscolor); - void ActiveteUSB(); + virtual void DevStateChange(); - void SetSerialNum(byte *pvalue); + virtual int getMatSum(); - int GetScanNum(); + virtual void close(); - void ClrRollerNum(); + virtual void GetExpose(int& Aside, int& Bside); + virtual void SetExpose(int aside, int bside); - void ClrScanNum(); + virtual void GetSptime(int type, int& time); + virtual void SetSptime(int type, int time); - bool SendrAdPara(UINT para); + virtual void GetSleepTime(int& sleeptime); + virtual void SetSleepTime(int sleeptime); - bool SendrRgbAdPara(UINT para); - - bool SenGRPara(UINT para); - - bool SenGBPara(UINT para); - - void SendColorCorrentFlat(byte buffer[],int size); - - void SendColorFlat(byte buffer[],int size); - - void SendGrayCorrectFlat(byte buffer[],int size); - - void SendGrayFlat(byte buffer[],int size); - - byte* GetFlatData(); - - byte* GetCisPara(); - - bool FlatA4(); - - bool FlatA3(UINT para); - - void DevStateChange(); - - int getMatSum(); - - void SetPath(CString csFilePath) - { - csPath = csFilePath; - } - - CString GetPath() - { - return csPath; - } - void setlist(std::vector >list) - { - m_pImages.setlist(list); - } - bool FlatA4Conrrect(); - - ImageMatQueue m_pImages; - //HWND h; - int device_id; - bool isusbopened() { return m_usb.is_connected(); } private: - cscn_usb m_usb; volatile int devState; - volatile BOOL isDuplex; + volatile bool m_bRun; std::mutex m_Locker; std::mutex m_imgLocker; - int pixType; - int m_rotate; - bool backRotate; - BOOL canUseDiscardBlank; std::thread m_threadUsb; - std::map ntcMsg; - std::map devType; + std::map ntcMsg; + std::map devType; std::vector vcSerials; int selectDeviceIndex; int m_scannerType; - CString csPath; + bool m_isScanning; private: - void run(); - cv::Mat popMat(int num); + std::string popMat(int num); void pushMat(JpegBuffer& data); + USBCB Get_Scanner_Status(); void InitMSGMap(); void InitScannerDiviceMap(); cv::Mat Get_Img_Data(int buffersize); DWORD usbmain(); void Pop_Image(); + HGScanConfig m_config; }; \ No newline at end of file diff --git a/HuaGoCorrect/json.hpp b/HuaGoCorrect/json.hpp new file mode 100644 index 0000000..06da815 --- /dev/null +++ b/HuaGoCorrect/json.hpp @@ -0,0 +1,22875 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ +| | |__ | | | | | | version 3.7.3 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2013-2019 Niels Lohmann . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef INCLUDE_NLOHMANN_JSON_HPP_ +#define INCLUDE_NLOHMANN_JSON_HPP_ + +#define NLOHMANN_JSON_VERSION_MAJOR 3 +#define NLOHMANN_JSON_VERSION_MINOR 7 +#define NLOHMANN_JSON_VERSION_PATCH 3 + +#include // all_of, find, for_each +#include // assert +#include // and, not, or +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#include // istream, ostream +#include // random_access_iterator_tag +#include // unique_ptr +#include // accumulate +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap +#include // vector + +// #include + + +#include + +// #include + + +#include // transform +#include // array +#include // and, not +#include // forward_list +#include // inserter, front_inserter, end +#include // map +#include // string +#include // tuple, make_tuple +#include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +#include // unordered_map +#include // pair, declval +#include // valarray + +// #include + + +#include // exception +#include // runtime_error +#include // to_string + +// #include + + +#include // size_t + +namespace nlohmann +{ +namespace detail +{ +/// struct to capture the start position of the current token +struct position_t +{ + /// the total number of characters read + std::size_t chars_read_total = 0; + /// the number of characters read in the current line + std::size_t chars_read_current_line = 0; + /// the number of lines read + std::size_t lines_read = 0; + + /// conversion to size_t to preserve SAX interface + constexpr operator size_t() const + { + return chars_read_total; + } +}; + +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // pair +// #include +/* Hedley - https://nemequ.github.io/hedley + * Created by Evan Nemerson + * + * To the extent possible under law, the author(s) have dedicated all + * copyright and related and neighboring rights to this software to + * the public domain worldwide. This software is distributed without + * any warranty. + * + * For details, see . + * SPDX-License-Identifier: CC0-1.0 + */ + +#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 11) +#if defined(JSON_HEDLEY_VERSION) + #undef JSON_HEDLEY_VERSION +#endif +#define JSON_HEDLEY_VERSION 11 + +#if defined(JSON_HEDLEY_STRINGIFY_EX) + #undef JSON_HEDLEY_STRINGIFY_EX +#endif +#define JSON_HEDLEY_STRINGIFY_EX(x) #x + +#if defined(JSON_HEDLEY_STRINGIFY) + #undef JSON_HEDLEY_STRINGIFY +#endif +#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) + +#if defined(JSON_HEDLEY_CONCAT_EX) + #undef JSON_HEDLEY_CONCAT_EX +#endif +#define JSON_HEDLEY_CONCAT_EX(a,b) a##b + +#if defined(JSON_HEDLEY_CONCAT) + #undef JSON_HEDLEY_CONCAT +#endif +#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) + +#if defined(JSON_HEDLEY_VERSION_ENCODE) + #undef JSON_HEDLEY_VERSION_ENCODE +#endif +#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) + #undef JSON_HEDLEY_VERSION_DECODE_MAJOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) + #undef JSON_HEDLEY_VERSION_DECODE_MINOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) + #undef JSON_HEDLEY_VERSION_DECODE_REVISION +#endif +#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) + +#if defined(JSON_HEDLEY_GNUC_VERSION) + #undef JSON_HEDLEY_GNUC_VERSION +#endif +#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#elif defined(__GNUC__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) +#endif + +#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) + #undef JSON_HEDLEY_GNUC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GNUC_VERSION) + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION) + #undef JSON_HEDLEY_MSVC_VERSION +#endif +#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) +#elif defined(_MSC_FULL_VER) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) +#elif defined(_MSC_VER) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) + #undef JSON_HEDLEY_MSVC_VERSION_CHECK +#endif +#if !defined(_MSC_VER) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) +#elif defined(_MSC_VER) && (_MSC_VER >= 1200) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) +#else + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION) + #undef JSON_HEDLEY_INTEL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) +#elif defined(__INTEL_COMPILER) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_VERSION) + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION) + #undef JSON_HEDLEY_PGI_VERSION +#endif +#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) + #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) + #undef JSON_HEDLEY_PGI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #undef JSON_HEDLEY_SUNPRO_VERSION +#endif +#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) +#elif defined(__SUNPRO_C) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) +#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) +#elif defined(__SUNPRO_CC) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) + #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION +#endif +#if defined(__EMSCRIPTEN__) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION) + #undef JSON_HEDLEY_ARM_VERSION +#endif +#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) +#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) + #undef JSON_HEDLEY_ARM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_ARM_VERSION) + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION) + #undef JSON_HEDLEY_IBM_VERSION +#endif +#if defined(__ibmxl__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) +#elif defined(__xlC__) && defined(__xlC_ver__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) +#elif defined(__xlC__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) + #undef JSON_HEDLEY_IBM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IBM_VERSION) + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_VERSION) + #undef JSON_HEDLEY_TI_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) + #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_VERSION_CHECK) + #undef JSON_HEDLEY_TI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_VERSION) + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION) + #undef JSON_HEDLEY_CRAY_VERSION +#endif +#if defined(_CRAYC) + #if defined(_RELEASE_PATCHLEVEL) + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) + #else + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) + #undef JSON_HEDLEY_CRAY_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_CRAY_VERSION) + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION) + #undef JSON_HEDLEY_IAR_VERSION +#endif +#if defined(__IAR_SYSTEMS_ICC__) + #if __VER__ > 1000 + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) + #else + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __VER__ % 100, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) + #undef JSON_HEDLEY_IAR_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IAR_VERSION) + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION) + #undef JSON_HEDLEY_TINYC_VERSION +#endif +#if defined(__TINYC__) + #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) + #undef JSON_HEDLEY_TINYC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION) + #undef JSON_HEDLEY_DMC_VERSION +#endif +#if defined(__DMC__) + #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) + #undef JSON_HEDLEY_DMC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_DMC_VERSION) + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #undef JSON_HEDLEY_COMPCERT_VERSION +#endif +#if defined(__COMPCERT_VERSION__) + #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) + #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION) + #undef JSON_HEDLEY_PELLES_VERSION +#endif +#if defined(__POCC__) + #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) + #undef JSON_HEDLEY_PELLES_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PELLES_VERSION) + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION) + #undef JSON_HEDLEY_GCC_VERSION +#endif +#if \ + defined(JSON_HEDLEY_GNUC_VERSION) && \ + !defined(__clang__) && \ + !defined(JSON_HEDLEY_INTEL_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_ARM_VERSION) && \ + !defined(JSON_HEDLEY_TI_VERSION) && \ + !defined(__COMPCERT__) + #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE +#endif +#if \ + defined(__has_cpp_attribute) && \ + defined(__cplusplus) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS +#endif +#if !defined(__cplusplus) || !defined(__has_cpp_attribute) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#elif \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ + (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_BUILTIN) + #undef JSON_HEDLEY_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) +#else + #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) + #undef JSON_HEDLEY_GNUC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) + #undef JSON_HEDLEY_GCC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_FEATURE) + #undef JSON_HEDLEY_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) +#else + #define JSON_HEDLEY_HAS_FEATURE(feature) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) + #undef JSON_HEDLEY_GNUC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) + #undef JSON_HEDLEY_GCC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_EXTENSION) + #undef JSON_HEDLEY_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) +#else + #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) + #undef JSON_HEDLEY_GNUC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) + #undef JSON_HEDLEY_GCC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_WARNING) + #undef JSON_HEDLEY_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) +#else + #define JSON_HEDLEY_HAS_WARNING(warning) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) + #undef JSON_HEDLEY_GNUC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_WARNING) + #undef JSON_HEDLEY_GCC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ +#endif +#if defined(__cplusplus) && JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +#else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x +#endif + +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + defined(__clang__) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) + #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_PRAGMA(value) __pragma(value) +#else + #define JSON_HEDLEY_PRAGMA(value) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) + #undef JSON_HEDLEY_DIAGNOSTIC_PUSH +#endif +#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) + #undef JSON_HEDLEY_DIAGNOSTIC_POP +#endif +#if defined(__clang__) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) + #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) +#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_PUSH + #define JSON_HEDLEY_DIAGNOSTIC_POP +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif + +#if defined(JSON_HEDLEY_DEPRECATED) + #undef JSON_HEDLEY_DEPRECATED +#endif +#if defined(JSON_HEDLEY_DEPRECATED_FOR) + #undef JSON_HEDLEY_DEPRECATED_FOR +#endif +#if defined(__cplusplus) && (__cplusplus >= 201402L) + #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) +#elif \ + JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,3,0) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") +#else + #define JSON_HEDLEY_DEPRECATED(since) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) +#endif + +#if defined(JSON_HEDLEY_UNAVAILABLE) + #undef JSON_HEDLEY_UNAVAILABLE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) +#else + #define JSON_HEDLEY_UNAVAILABLE(available_since) +#endif + +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT +#endif +#if defined(__cplusplus) && (__cplusplus >= 201703L) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) +#elif defined(_Check_return_) /* SAL */ + #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ +#else + #define JSON_HEDLEY_WARN_UNUSED_RESULT +#endif + +#if defined(JSON_HEDLEY_SENTINEL) + #undef JSON_HEDLEY_SENTINEL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) + #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) +#else + #define JSON_HEDLEY_SENTINEL(position) +#endif + +#if defined(JSON_HEDLEY_NO_RETURN) + #undef JSON_HEDLEY_NO_RETURN +#endif +#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NO_RETURN __noreturn +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define JSON_HEDLEY_NO_RETURN _Noreturn +#elif defined(__cplusplus) && (__cplusplus >= 201103L) + #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(18,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(17,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#else + #define JSON_HEDLEY_NO_RETURN +#endif + +#if defined(JSON_HEDLEY_NO_ESCAPE) + #undef JSON_HEDLEY_NO_ESCAPE +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) + #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) +#else + #define JSON_HEDLEY_NO_ESCAPE +#endif + +#if defined(JSON_HEDLEY_UNREACHABLE) + #undef JSON_HEDLEY_UNREACHABLE +#endif +#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #undef JSON_HEDLEY_UNREACHABLE_RETURN +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) + #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) + #define JSON_HEDLEY_UNREACHABLE() __assume(0) +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) + #if defined(__cplusplus) + #define JSON_HEDLEY_UNREACHABLE() std::_nassert(0) + #else + #define JSON_HEDLEY_UNREACHABLE() _nassert(0) + #endif + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value +#elif defined(EXIT_FAILURE) + #define JSON_HEDLEY_UNREACHABLE() abort() +#else + #define JSON_HEDLEY_UNREACHABLE() + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value +#endif +#if !defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() +#endif + +#if defined(JSON_HEDLEY_ASSUME) + #undef JSON_HEDLEY_ASSUME +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_ASSUME(expr) __assume(expr) +#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) + #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) + #if defined(__cplusplus) + #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) + #else + #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #endif +#elif \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && !defined(JSON_HEDLEY_ARM_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) + #define JSON_HEDLEY_ASSUME(expr) ((void) ((expr) ? 1 : (__builtin_unreachable(), 1))) +#else + #define JSON_HEDLEY_ASSUME(expr) ((void) (expr)) +#endif + +JSON_HEDLEY_DIAGNOSTIC_PUSH +#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") + #pragma clang diagnostic ignored "-Wpedantic" +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) + #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" +#endif +#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) + #if defined(__clang__) + #pragma clang diagnostic ignored "-Wvariadic-macros" + #elif defined(JSON_HEDLEY_GCC_VERSION) + #pragma GCC diagnostic ignored "-Wvariadic-macros" + #endif +#endif +#if defined(JSON_HEDLEY_NON_NULL) + #undef JSON_HEDLEY_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) +#else + #define JSON_HEDLEY_NON_NULL(...) +#endif +JSON_HEDLEY_DIAGNOSTIC_POP + +#if defined(JSON_HEDLEY_PRINTF_FORMAT) + #undef JSON_HEDLEY_PRINTF_FORMAT +#endif +#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) +#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) +#else + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) +#endif + +#if defined(JSON_HEDLEY_CONSTEXPR) + #undef JSON_HEDLEY_CONSTEXPR +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #endif +#endif +#if !defined(JSON_HEDLEY_CONSTEXPR) + #define JSON_HEDLEY_CONSTEXPR +#endif + +#if defined(JSON_HEDLEY_PREDICT) + #undef JSON_HEDLEY_PREDICT +#endif +#if defined(JSON_HEDLEY_LIKELY) + #undef JSON_HEDLEY_LIKELY +#endif +#if defined(JSON_HEDLEY_UNLIKELY) + #undef JSON_HEDLEY_UNLIKELY +#endif +#if defined(JSON_HEDLEY_UNPREDICTABLE) + #undef JSON_HEDLEY_UNPREDICTABLE +#endif +#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) + #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable(!!(expr)) +#endif +#if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) +# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability(expr, value, probability) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1, probability) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, probability) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#if !defined(JSON_HEDLEY_BUILTIN_UNPREDICTABLE) + #define JSON_HEDLEY_BUILTIN_UNPREDICTABLE(expr) __builtin_expect_with_probability(!!(expr), 1, 0.5) +#endif +#elif \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) +# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ + (((probability) >= 0.9) ? __builtin_expect(!!(expr), (expected)) : (((void) (expected)), !!(expr))) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ + (__extension__ ({ \ + JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ + })) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ + (__extension__ ({ \ + JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ + })) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#else +# define JSON_HEDLEY_PREDICT(expr, expected, probability) (((void) (expected)), !!(expr)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) +# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) +#endif +#if !defined(JSON_HEDLEY_UNPREDICTABLE) + #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) +#endif + +#if defined(JSON_HEDLEY_MALLOC) + #undef JSON_HEDLEY_MALLOC +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) + #define JSON_HEDLEY_MALLOC __declspec(restrict) +#else + #define JSON_HEDLEY_MALLOC +#endif + +#if defined(JSON_HEDLEY_PURE) + #undef JSON_HEDLEY_PURE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_PURE __attribute__((__pure__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") +#else + #define JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_CONST) + #undef JSON_HEDLEY_CONST +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_CONST __attribute__((__const__)) +#elif \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_CONST _Pragma("no_side_effect") +#else + #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_RESTRICT) + #undef JSON_HEDLEY_RESTRICT +#endif +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT restrict +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + defined(__clang__) + #define JSON_HEDLEY_RESTRICT __restrict +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT _Restrict +#else + #define JSON_HEDLEY_RESTRICT +#endif + +#if defined(JSON_HEDLEY_INLINE) + #undef JSON_HEDLEY_INLINE +#endif +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define JSON_HEDLEY_INLINE inline +#elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) + #define JSON_HEDLEY_INLINE __inline__ +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_INLINE __inline +#else + #define JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_ALWAYS_INLINE) + #undef JSON_HEDLEY_ALWAYS_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) + #define JSON_HEDLEY_ALWAYS_INLINE __forceinline +#elif JSON_HEDLEY_TI_VERSION_CHECK(7,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") +#else + #define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_NEVER_INLINE) + #undef JSON_HEDLEY_NEVER_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#else + #define JSON_HEDLEY_NEVER_INLINE +#endif + +#if defined(JSON_HEDLEY_PRIVATE) + #undef JSON_HEDLEY_PRIVATE +#endif +#if defined(JSON_HEDLEY_PUBLIC) + #undef JSON_HEDLEY_PUBLIC +#endif +#if defined(JSON_HEDLEY_IMPORT) + #undef JSON_HEDLEY_IMPORT +#endif +#if defined(_WIN32) || defined(__CYGWIN__) + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC __declspec(dllexport) + #define JSON_HEDLEY_IMPORT __declspec(dllimport) +#else + #if \ + JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_EABI__) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) + #define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) + #else + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC + #endif + #define JSON_HEDLEY_IMPORT extern +#endif + +#if defined(JSON_HEDLEY_NO_THROW) + #undef JSON_HEDLEY_NO_THROW +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NO_THROW __declspec(nothrow) +#else + #define JSON_HEDLEY_NO_THROW +#endif + +#if defined(JSON_HEDLEY_FALL_THROUGH) + #undef JSON_HEDLEY_FALL_THROUGH +#endif +#if JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(fallthrough,7,0,0) && !defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) +#elif defined(__fallthrough) /* SAL */ + #define JSON_HEDLEY_FALL_THROUGH __fallthrough +#else + #define JSON_HEDLEY_FALL_THROUGH +#endif + +#if defined(JSON_HEDLEY_RETURNS_NON_NULL) + #undef JSON_HEDLEY_RETURNS_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) +#elif defined(_Ret_notnull_) /* SAL */ + #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ +#else + #define JSON_HEDLEY_RETURNS_NON_NULL +#endif + +#if defined(JSON_HEDLEY_ARRAY_PARAM) + #undef JSON_HEDLEY_ARRAY_PARAM +#endif +#if \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(__STDC_NO_VLA__) && \ + !defined(__cplusplus) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_ARRAY_PARAM(name) (name) +#else + #define JSON_HEDLEY_ARRAY_PARAM(name) +#endif + +#if defined(JSON_HEDLEY_IS_CONSTANT) + #undef JSON_HEDLEY_IS_CONSTANT +#endif +#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) + #undef JSON_HEDLEY_REQUIRE_CONSTEXPR +#endif +/* JSON_HEDLEY_IS_CONSTEXPR_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #undef JSON_HEDLEY_IS_CONSTEXPR_ +#endif +#if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) + #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) +#endif +#if !defined(__cplusplus) +# if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) +#endif +# elif \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(JSON_HEDLEY_SUNPRO_VERSION) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) +#endif +# elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + defined(JSON_HEDLEY_INTEL_VERSION) || \ + defined(JSON_HEDLEY_TINYC_VERSION) || \ + defined(JSON_HEDLEY_TI_VERSION) || \ + defined(__clang__) +# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ + sizeof(void) != \ + sizeof(*( \ + 1 ? \ + ((void*) ((expr) * 0L) ) : \ +((struct { char v[sizeof(void) * 2]; } *) 1) \ + ) \ + ) \ + ) +# endif +#endif +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) +#else + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) +#endif + +#if defined(JSON_HEDLEY_BEGIN_C_DECLS) + #undef JSON_HEDLEY_BEGIN_C_DECLS +#endif +#if defined(JSON_HEDLEY_END_C_DECLS) + #undef JSON_HEDLEY_END_C_DECLS +#endif +#if defined(JSON_HEDLEY_C_DECL) + #undef JSON_HEDLEY_C_DECL +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { + #define JSON_HEDLEY_END_C_DECLS } + #define JSON_HEDLEY_C_DECL extern "C" +#else + #define JSON_HEDLEY_BEGIN_C_DECLS + #define JSON_HEDLEY_END_C_DECLS + #define JSON_HEDLEY_C_DECL +#endif + +#if defined(JSON_HEDLEY_STATIC_ASSERT) + #undef JSON_HEDLEY_STATIC_ASSERT +#endif +#if \ + !defined(__cplusplus) && ( \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ + JSON_HEDLEY_HAS_FEATURE(c_static_assert) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + defined(_Static_assert) \ + ) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) +#elif \ + (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ + (defined(__cplusplus) && JSON_HEDLEY_TI_VERSION_CHECK(8,3,0)) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) +#else +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) +#endif + +#if defined(JSON_HEDLEY_CONST_CAST) + #undef JSON_HEDLEY_CONST_CAST +#endif +#if defined(__cplusplus) +# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast(expr)) +#elif \ + JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_REINTERPRET_CAST) + #undef JSON_HEDLEY_REINTERPRET_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast(expr)) +#else + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (*((T*) &(expr))) +#endif + +#if defined(JSON_HEDLEY_STATIC_CAST) + #undef JSON_HEDLEY_STATIC_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast(expr)) +#else + #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_CPP_CAST) + #undef JSON_HEDLEY_CPP_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_CPP_CAST(T, expr) static_cast(expr) +#else + #define JSON_HEDLEY_CPP_CAST(T, expr) (expr) +#endif + +#if defined(JSON_HEDLEY_NULL) + #undef JSON_HEDLEY_NULL +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #elif defined(NULL) + #define JSON_HEDLEY_NULL NULL + #else + #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #endif +#elif defined(NULL) + #define JSON_HEDLEY_NULL NULL +#else + #define JSON_HEDLEY_NULL ((void*) 0) +#endif + +#if defined(JSON_HEDLEY_MESSAGE) + #undef JSON_HEDLEY_MESSAGE +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_MESSAGE(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(message msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) +#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_WARNING) + #undef JSON_HEDLEY_WARNING +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_WARNING(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(clang warning msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_REQUIRE) + #undef JSON_HEDLEY_REQUIRE +#endif +#if defined(JSON_HEDLEY_REQUIRE_MSG) + #undef JSON_HEDLEY_REQUIRE_MSG +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) +# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") +# define JSON_HEDLEY_REQUIRE(expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), #expr, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), msg, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) +# endif +#else +# define JSON_HEDLEY_REQUIRE(expr) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) +#endif + +#if defined(JSON_HEDLEY_FLAGS) + #undef JSON_HEDLEY_FLAGS +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) + #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) +#endif + +#if defined(JSON_HEDLEY_FLAGS_CAST) + #undef JSON_HEDLEY_FLAGS_CAST +#endif +#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) +# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("warning(disable:188)") \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) +#endif + +#if defined(JSON_HEDLEY_EMPTY_BASES) + #undef JSON_HEDLEY_EMPTY_BASES +#endif +#if JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0) + #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) +#else + #define JSON_HEDLEY_EMPTY_BASES +#endif + +/* Remaining macros are deprecated. */ + +#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK +#endif +#if defined(__clang__) + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) +#else + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) + #undef JSON_HEDLEY_CLANG_HAS_BUILTIN +#endif +#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) + +#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) + #undef JSON_HEDLEY_CLANG_HAS_FEATURE +#endif +#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) + +#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) + #undef JSON_HEDLEY_CLANG_HAS_EXTENSION +#endif +#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) + +#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) + #undef JSON_HEDLEY_CLANG_HAS_WARNING +#endif +#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) + +#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ + + +// This file contains all internal macro definitions +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// C++ language standard detection +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 +#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 +#endif + +// disable float-equal warnings on GCC/clang +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdocumentation" +#endif + +// allow to disable exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #include + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [&j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + + +namespace nlohmann +{ +namespace detail +{ +//////////////// +// exceptions // +//////////////// + +/*! +@brief general exception of the @ref basic_json class + +This class is an extension of `std::exception` objects with a member @a id for +exception ids. It is used as the base class for all exceptions thrown by the +@ref basic_json class. This class can hence be used as "wildcard" to catch +exceptions. + +Subclasses: +- @ref parse_error for exceptions indicating a parse error +- @ref invalid_iterator for exceptions indicating errors with iterators +- @ref type_error for exceptions indicating executing a member function with + a wrong type +- @ref out_of_range for exceptions indicating access out of the defined range +- @ref other_error for exceptions indicating other library errors + +@internal +@note To have nothrow-copy-constructible exceptions, we internally use + `std::runtime_error` which can cope with arbitrary-length error messages. + Intermediate strings are built with static functions and then passed to + the actual constructor. +@endinternal + +@liveexample{The following code shows how arbitrary library exceptions can be +caught.,exception} + +@since version 3.0.0 +*/ +class exception : public std::exception +{ + public: + /// returns the explanatory string + JSON_HEDLEY_RETURNS_NON_NULL + const char* what() const noexcept override + { + return m.what(); + } + + /// the id of the exception + const int id; + + protected: + JSON_HEDLEY_NON_NULL(3) + exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} + + static std::string name(const std::string& ename, int id_) + { + return "[json.exception." + ename + "." + std::to_string(id_) + "] "; + } + + private: + /// an exception object as storage for error messages + std::runtime_error m; +}; + +/*! +@brief exception indicating a parse error + +This exception is thrown by the library when a parse error occurs. Parse errors +can occur during the deserialization of JSON text, CBOR, MessagePack, as well +as when using JSON Patch. + +Member @a byte holds the byte index of the last read character in the input +file. + +Exceptions have ids 1xx. + +name / id | example message | description +------------------------------ | --------------- | ------------------------- +json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position. +json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. +json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid. +json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects. +json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. +json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`. +json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character. +json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape sequences. +json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number. +json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. +json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. +json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read. +json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F | The parsing of the corresponding BSON record type is not implemented (yet). + +@note For an input with n bytes, 1 is the index of the first character and n+1 + is the index of the terminating null byte or the end of file. This also + holds true when reading a byte vector (CBOR or MessagePack). + +@liveexample{The following code shows how a `parse_error` exception can be +caught.,parse_error} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class parse_error : public exception +{ + public: + /*! + @brief create a parse error exception + @param[in] id_ the id of the exception + @param[in] pos the position where the error occurred (or with + chars_read_total=0 if the position cannot be + determined) + @param[in] what_arg the explanatory string + @return parse_error object + */ + static parse_error create(int id_, const position_t& pos, const std::string& what_arg) + { + std::string w = exception::name("parse_error", id_) + "parse error" + + position_string(pos) + ": " + what_arg; + return parse_error(id_, pos.chars_read_total, w.c_str()); + } + + static parse_error create(int id_, std::size_t byte_, const std::string& what_arg) + { + std::string w = exception::name("parse_error", id_) + "parse error" + + (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + + ": " + what_arg; + return parse_error(id_, byte_, w.c_str()); + } + + /*! + @brief byte index of the parse error + + The byte index of the last read character in the input file. + + @note For an input with n bytes, 1 is the index of the first character and + n+1 is the index of the terminating null byte or the end of file. + This also holds true when reading a byte vector (CBOR or MessagePack). + */ + const std::size_t byte; + + private: + parse_error(int id_, std::size_t byte_, const char* what_arg) + : exception(id_, what_arg), byte(byte_) {} + + static std::string position_string(const position_t& pos) + { + return " at line " + std::to_string(pos.lines_read + 1) + + ", column " + std::to_string(pos.chars_read_current_line); + } +}; + +/*! +@brief exception indicating errors with iterators + +This exception is thrown if iterators passed to a library function do not match +the expected semantics. + +Exceptions have ids 2xx. + +name / id | example message | description +----------------------------------- | --------------- | ------------------------- +json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. +json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. +json.exception.invalid_iterator.203 | iterators do not fit current value | Either iterator passed to function @ref erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from. +json.exception.invalid_iterator.204 | iterators out of range | When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (@ref begin(), @ref end()), because this is the only way the single stored value is expressed. All other ranges are invalid. +json.exception.invalid_iterator.205 | iterator out of range | When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the @ref begin() iterator, because it is the only way to address the stored value. All other iterators are invalid. +json.exception.invalid_iterator.206 | cannot construct with iterators from null | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range. +json.exception.invalid_iterator.207 | cannot use key() for non-object iterators | The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key. +json.exception.invalid_iterator.208 | cannot use operator[] for object iterators | The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. +json.exception.invalid_iterator.209 | cannot use offsets with object iterators | The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. +json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. +json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to. +json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container. +json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered. +json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to @ref begin(). + +@liveexample{The following code shows how an `invalid_iterator` exception can be +caught.,invalid_iterator} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class invalid_iterator : public exception +{ + public: + static invalid_iterator create(int id_, const std::string& what_arg) + { + std::string w = exception::name("invalid_iterator", id_) + what_arg; + return invalid_iterator(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + invalid_iterator(int id_, const char* what_arg) + : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating executing a member function with a wrong type + +This exception is thrown in case of a type error; that is, a library function is +executed on a JSON value whose type does not match the expected semantics. + +Exceptions have ids 3xx. + +name / id | example message | description +----------------------------- | --------------- | ------------------------- +json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead. +json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types. +json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual type is object | To retrieve a reference to a value stored in a @ref basic_json object with @ref get_ref, the type of the reference must match the value type. For instance, for a JSON array, the @a ReferenceType must be @ref array_t &. +json.exception.type_error.304 | cannot use at() with string | The @ref at() member functions can only be executed for certain JSON types. +json.exception.type_error.305 | cannot use operator[] with string | The @ref operator[] member functions can only be executed for certain JSON types. +json.exception.type_error.306 | cannot use value() with string | The @ref value() member functions can only be executed for certain JSON types. +json.exception.type_error.307 | cannot use erase() with string | The @ref erase() member functions can only be executed for certain JSON types. +json.exception.type_error.308 | cannot use push_back() with string | The @ref push_back() and @ref operator+= member functions can only be executed for certain JSON types. +json.exception.type_error.309 | cannot use insert() with | The @ref insert() member functions can only be executed for certain JSON types. +json.exception.type_error.310 | cannot use swap() with number | The @ref swap() member functions can only be executed for certain JSON types. +json.exception.type_error.311 | cannot use emplace_back() with string | The @ref emplace_back() member function can only be executed for certain JSON types. +json.exception.type_error.312 | cannot use update() with string | The @ref update() member functions can only be executed for certain JSON types. +json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined. +json.exception.type_error.314 | only objects can be unflattened | The @ref unflatten function only works for an object whose keys are JSON Pointers. +json.exception.type_error.315 | values in object must be primitive | The @ref unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive. +json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref dump function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. | +json.exception.type_error.317 | JSON value cannot be serialized to requested format | The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw `true` or `null` JSON object cannot be serialized to BSON) | + +@liveexample{The following code shows how a `type_error` exception can be +caught.,type_error} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class type_error : public exception +{ + public: + static type_error create(int id_, const std::string& what_arg) + { + std::string w = exception::name("type_error", id_) + what_arg; + return type_error(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating access out of the defined range + +This exception is thrown in case a library function is called on an input +parameter that exceeds the expected range, for instance in case of array +indices or nonexisting object keys. + +Exceptions have ids 4xx. + +name / id | example message | description +------------------------------- | --------------- | ------------------------- +json.exception.out_of_range.401 | array index 3 is out of range | The provided array index @a i is larger than @a size-1. +json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it. +json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object. +json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved. +json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. +json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. +json.exception.out_of_range.407 | number overflow serializing '9223372036854775808' | UBJSON and BSON only support integer numbers up to 9223372036854775807. | +json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | The size (following `#`) of an UBJSON array or object exceeds the maximal capacity. | +json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string | + +@liveexample{The following code shows how an `out_of_range` exception can be +caught.,out_of_range} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class out_of_range : public exception +{ + public: + static out_of_range create(int id_, const std::string& what_arg) + { + std::string w = exception::name("out_of_range", id_) + what_arg; + return out_of_range(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating other library errors + +This exception is thrown in case of errors that cannot be classified with the +other exception types. + +Exceptions have ids 5xx. + +name / id | example message | description +------------------------------ | --------------- | ------------------------- +json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed. + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range + +@liveexample{The following code shows how an `other_error` exception can be +caught.,other_error} + +@since version 3.0.0 +*/ +class other_error : public exception +{ + public: + static other_error create(int id_, const std::string& what_arg) + { + std::string w = exception::name("other_error", id_) + what_arg; + return other_error(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +#include // not +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type + +namespace nlohmann +{ +namespace detail +{ +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +template +using uncvref_t = typename std::remove_cv::type>::type; + +// implementation of C++14 index_sequence and affiliates +// source: https://stackoverflow.com/a/32223343 +template +struct index_sequence +{ + using type = index_sequence; + using value_type = std::size_t; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +template +struct merge_and_renumber; + +template +struct merge_and_renumber, index_sequence> + : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; + +template +struct make_index_sequence + : merge_and_renumber < typename make_index_sequence < N / 2 >::type, + typename make_index_sequence < N - N / 2 >::type > {}; + +template<> struct make_index_sequence<0> : index_sequence<> {}; +template<> struct make_index_sequence<1> : index_sequence<0> {}; + +template +using index_sequence_for = make_index_sequence; + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static constexpr T value{}; +}; + +template +constexpr T static_const::value; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // not +#include // numeric_limits +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval + +// #include + + +#include // random_access_iterator_tag + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; +} // namespace detail +} // namespace nlohmann + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template +struct iterator_types {}; + +template +struct iterator_types < + It, + void_t> +{ + using difference_type = typename It::difference_type; + using value_type = typename It::value_type; + using pointer = typename It::pointer; + using reference = typename It::reference; + using iterator_category = typename It::iterator_category; +}; + +// This is required as some compilers implement std::iterator_traits in a way that +// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. +template +struct iterator_traits +{ +}; + +template +struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> + : iterator_types +{ +}; + +template +struct iterator_traits::value>> +{ + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + +// #include + + +#include + +// #include + + +// http://en.cppreference.com/w/cpp/experimental/is_detected +namespace nlohmann +{ +namespace detail +{ +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template