#include "stdafx.h" #include "BSEImgClr.h" #include "../OTSLog/COTSUtilityDllFunExport.h" namespace OTSCLRINTERFACE { using namespace System; using namespace OTSDATA; const unsigned int CHART_NUM = 0xff; CBSEImgClr::CBSEImgClr() { //m_LpBSEImg = new CBSEImgPtr(new CBSEImg()); } CBSEImgClr::CBSEImgClr(System::Drawing::Rectangle^ a_pRect) // constructor { CRect r = CRect(a_pRect->Left, a_pRect->Top, a_pRect->Right, a_pRect->Bottom); m_LpBSEImg = new CBSEImgPtr(new CBSEImg(r)); } CBSEImgClr::CBSEImgClr(CBSEImgPtr pBSEImg) // copy constructor { ASSERT(pBSEImg); if (!pBSEImg) { LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CBSEImgClr pointer failed.")); return; } m_LpBSEImg = new CBSEImgPtr(pBSEImg); } CBSEImgClr::CBSEImgClr(CBSEImgClr^ a_pSource) { auto src = a_pSource->GetBSEImgPtr(); m_LpBSEImg = new CBSEImgPtr(new CBSEImg(src.get())); } CBSEImgClr::CBSEImgClr(CBSEImg* a_pSource) // copy constructor { ASSERT(a_pSource); if (!a_pSource) { LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CBSEImgClr pointer failed.")); return; } m_LpBSEImg = new CBSEImgPtr(new CBSEImg(a_pSource)); } CBSEImgClr::~CBSEImgClr() { if (m_LpBSEImg != nullptr) { delete m_LpBSEImg; } } CBSEImgClr::!CBSEImgClr() { if (m_LpBSEImg != nullptr) { delete m_LpBSEImg; } } // image rectangle System::Drawing::Rectangle^ CBSEImgClr::GetImageRect() { CBSEImgPtr img = *m_LpBSEImg; CRect Crec=img->GetImageRect(); System::Drawing::Rectangle^ r = gcnew System::Drawing::Rectangle((int)Crec.left, (int)Crec.top, (int)Crec.Width(), (int)Crec.Height()); return r; } void CBSEImgClr::SetImageRect(System::Drawing::Rectangle^ a_pRect) { CRect* r = new CRect(a_pRect->Left, a_pRect->Top, a_pRect->Right, a_pRect->Bottom); m_LpBSEImg = new CBSEImgPtr(new CBSEImg(r)); } int CBSEImgClr::GetWidth() { if (m_LpBSEImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetWidth:invalid pointer.")); return -1; } CBSEImgPtr pBSEImg = GetBSEImgPtr(); ASSERT(pBSEImg); if (!pBSEImg) { LogErrorTrace(__FILE__, __LINE__, _T("GetWidth:invalid pointer.")); return -1; } return pBSEImg->GetWidth(); } int CBSEImgClr::GetHeight() { CBSEImgPtr img= *m_LpBSEImg; return img->GetHeight(); } // image data void CBSEImgClr::InitImageData(int imgwidth,int imgheight) { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("InitImageData: invalid pointer.")); return; } pImg->InitImageData(imgwidth,imgheight); } array^ CBSEImgClr::GetImageDataPtr() { /*return m_pnImageData;*/ CBSEImgPtr img = *m_LpBSEImg; BYTE* imgData= img->GetImageDataPointer(); auto imgSize = img->GetImageSize(); long lngSize = imgSize.cx * imgSize.cy; array^ outData = gcnew array(lngSize); for (int i = 0; i < lngSize; i++) { outData[i] = imgData[i]; } return outData; } // need a byte array, and array length void CBSEImgClr::SetImageData(array^ a_pnImageData, int imgwidth,int imgheight) { if (a_pnImageData == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetImageData: invalid image data")); return; } CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetImageData: invalid pointer.")); return; } pImg->InitImageData(imgwidth,imgheight); pin_ptr pi = &a_pnImageData[0]; byte *pinp = pi; memcpy(pImg->GetImageDataPointer(), pinp, imgwidth*imgheight); BYTE* pImgData = pImg->GetImageDataPointer(); int nImgsize = imgwidth * imgheight; for (int i = 0; i < nImgsize; i++) { pImgData[i] = a_pnImageData[i]; } } int CBSEImgClr::GetImageSize() { CBSEImgPtr pImg = GetBSEImgPtr(); auto imgSize = pImg->GetImageSize(); return imgSize.cx *imgSize.cy; } // BSE chart // NOTE: to use chart data, call SetChartData method first! bool CBSEImgClr::SetChartData() { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetChartData: invalid pointer.")); return FALSE; } pImg->SetChartData(); return TRUE; } void CBSEImgClr::GetBSEChart(array^ % a_wChart) { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetBSEChart: invalid pointer.")); return; } WORD* pChart = pImg->GetBSEChart(); pin_ptr pi = &a_wChart[0]; WORD *pinp = pi; memcpy(pinp, pChart, (DWORD)CHART_NUM); for (int i = 0; i < CHART_NUM; i++) { a_wChart[i] = pChart[i]; } } long CBSEImgClr::CalBSEChartHigh() { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("CalBSEChartHigh: invalid pointer.")); return -1; } return pImg->CalBSEChartHigh(); } long CBSEImgClr::CalBSEChartLow() { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("CalBSEChartLow: invalid pointer.")); return -1; } return pImg->CalBSEChartLow(); } // cal BSE value by position int CBSEImgClr::GetBSEValue(Point^ a_position) { if (a_position == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid point")); return -1; } CPoint pt; pt.x = a_position->X; pt.y = a_position->Y; CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer.")); return -1; } return pImg->GetBSEValue(pt); } int CBSEImgClr::GetBSEValue(const int a_nX, const int a_nY) { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer.")); return -1; } return pImg->GetBSEValue(a_nX, a_nY); } void CBSEImgClr::SetBSEValue(const int a_nX, const int a_nY, int value) { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer.")); return ; } pImg->SetBSEValue(a_nX, a_nY,value); } int CBSEImgClr::GetValueDirect(Point^ a_position) { if (a_position == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirect: invalid point")); return -1; } CPoint pt; pt.x = a_position->X; pt.y = a_position->Y; CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirect: invalid pointer.")); return -1; } return pImg->GetValueDirect(pt); } int CBSEImgClr::GetValueDirectF(int inX, int inY) { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirectF: invalid pointer.")); return -1; } return pImg->GetBSEValue(inX, inY); } bool CBSEImgClr::DoesContainPixelValue(int inValue, int a_nPixel) { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("DoesContainPixelValue: invalid pointer.")); return false; } return pImg->DoesContainPixelValue(inValue, a_nPixel); } // cal area DWORD CBSEImgClr::CalArea() { CBSEImgPtr pImg = GetBSEImgPtr(); if (pImg == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("CalArea: invalid pointer.")); return -1; } return pImg->CalArea(); } CBSEImgPtr CBSEImgClr::GetBSEImgPtr() { return *m_LpBSEImg; } }