BSEImgClr.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #include "stdafx.h"
  2. #include "BSEImgClr.h"
  3. #include "../OTSLog/COTSUtilityDllFunExport.h"
  4. namespace OTSCLRINTERFACE {
  5. using namespace System;
  6. using namespace OTSDATA;
  7. const unsigned int CHART_NUM = 0xff;
  8. CBSEImgClr::CBSEImgClr()
  9. {
  10. //m_LpBSEImg = new CBSEImgPtr(new CBSEImg());
  11. }
  12. CBSEImgClr::CBSEImgClr(System::Drawing::Rectangle^ a_pRect) // constructor
  13. {
  14. CRect r = CRect(a_pRect->Left, a_pRect->Top, a_pRect->Right, a_pRect->Bottom);
  15. m_LpBSEImg = new CBSEImgPtr(new CBSEImg(r));
  16. }
  17. CBSEImgClr::CBSEImgClr(CBSEImgPtr pBSEImg) // copy constructor
  18. {
  19. ASSERT(pBSEImg);
  20. if (!pBSEImg)
  21. {
  22. LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CBSEImgClr pointer failed."));
  23. return;
  24. }
  25. m_LpBSEImg = new CBSEImgPtr(pBSEImg);
  26. }
  27. CBSEImgClr::CBSEImgClr(CBSEImgClr^ a_pSource)
  28. {
  29. auto src = a_pSource->GetBSEImgPtr();
  30. m_LpBSEImg = new CBSEImgPtr(new CBSEImg(src.get()));
  31. }
  32. CBSEImgClr::CBSEImgClr(CBSEImg* a_pSource) // copy constructor
  33. {
  34. ASSERT(a_pSource);
  35. if (!a_pSource)
  36. {
  37. LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CBSEImgClr pointer failed."));
  38. return;
  39. }
  40. m_LpBSEImg = new CBSEImgPtr(new CBSEImg(a_pSource));
  41. }
  42. CBSEImgClr::~CBSEImgClr()
  43. {
  44. if (m_LpBSEImg != nullptr)
  45. {
  46. delete m_LpBSEImg;
  47. }
  48. }
  49. CBSEImgClr::!CBSEImgClr()
  50. {
  51. if (m_LpBSEImg != nullptr)
  52. {
  53. delete m_LpBSEImg;
  54. }
  55. }
  56. // image rectangle
  57. System::Drawing::Rectangle^ CBSEImgClr::GetImageRect()
  58. {
  59. CBSEImgPtr img = *m_LpBSEImg;
  60. CRect Crec=img->GetImageRect();
  61. System::Drawing::Rectangle^ r = gcnew System::Drawing::Rectangle((int)Crec.left, (int)Crec.top, (int)Crec.Width(), (int)Crec.Height());
  62. return r;
  63. }
  64. void CBSEImgClr::SetImageRect(System::Drawing::Rectangle^ a_pRect)
  65. {
  66. CRect* r = new CRect(a_pRect->Left, a_pRect->Top, a_pRect->Right, a_pRect->Bottom);
  67. m_LpBSEImg = new CBSEImgPtr(new CBSEImg(r));
  68. }
  69. int CBSEImgClr::GetWidth()
  70. {
  71. if (m_LpBSEImg == nullptr)
  72. {
  73. LogErrorTrace(__FILE__, __LINE__, _T("GetWidth:invalid pointer."));
  74. return -1;
  75. }
  76. CBSEImgPtr pBSEImg = GetBSEImgPtr();
  77. ASSERT(pBSEImg);
  78. if (!pBSEImg)
  79. {
  80. LogErrorTrace(__FILE__, __LINE__, _T("GetWidth:invalid pointer."));
  81. return -1;
  82. }
  83. return pBSEImg->GetWidth();
  84. }
  85. int CBSEImgClr::GetHeight()
  86. {
  87. CBSEImgPtr img= *m_LpBSEImg;
  88. return img->GetHeight();
  89. }
  90. // image data
  91. void CBSEImgClr::InitImageData(int imgwidth,int imgheight)
  92. {
  93. CBSEImgPtr pImg = GetBSEImgPtr();
  94. if (pImg == nullptr)
  95. {
  96. LogErrorTrace(__FILE__, __LINE__, _T("InitImageData: invalid pointer."));
  97. return;
  98. }
  99. pImg->InitImageData(imgwidth,imgheight);
  100. }
  101. array<byte>^ CBSEImgClr::GetImageDataPtr()
  102. {
  103. /*return m_pnImageData;*/
  104. CBSEImgPtr img = *m_LpBSEImg;
  105. BYTE* imgData= img->GetImageDataPointer();
  106. auto imgSize = img->GetImageSize();
  107. long lngSize = imgSize.cx * imgSize.cy;
  108. array<byte>^ outData = gcnew array<byte>(lngSize);
  109. for (int i = 0; i < lngSize; i++)
  110. {
  111. outData[i] = imgData[i];
  112. }
  113. return outData;
  114. }
  115. // need a byte array, and array length
  116. void CBSEImgClr::SetImageData(array<byte>^ a_pnImageData, int imgwidth,int imgheight)
  117. {
  118. if (a_pnImageData == nullptr)
  119. {
  120. LogErrorTrace(__FILE__, __LINE__, _T("SetImageData: invalid image data"));
  121. return;
  122. }
  123. CBSEImgPtr pImg = GetBSEImgPtr();
  124. if (pImg == nullptr)
  125. {
  126. LogErrorTrace(__FILE__, __LINE__, _T("SetImageData: invalid pointer."));
  127. return;
  128. }
  129. pImg->InitImageData(imgwidth,imgheight);
  130. pin_ptr<byte> pi = &a_pnImageData[0];
  131. byte *pinp = pi;
  132. memcpy(pImg->GetImageDataPointer(), pinp, imgwidth*imgheight);
  133. BYTE* pImgData = pImg->GetImageDataPointer();
  134. int nImgsize = imgwidth * imgheight;
  135. for (int i = 0; i < nImgsize; i++)
  136. {
  137. pImgData[i] = a_pnImageData[i];
  138. }
  139. }
  140. int CBSEImgClr::GetImageSize()
  141. {
  142. CBSEImgPtr pImg = GetBSEImgPtr();
  143. auto imgSize = pImg->GetImageSize();
  144. return imgSize.cx *imgSize.cy;
  145. }
  146. // BSE chart
  147. // NOTE: to use chart data, call SetChartData method first!
  148. bool CBSEImgClr::SetChartData()
  149. {
  150. CBSEImgPtr pImg = GetBSEImgPtr();
  151. if (pImg == nullptr)
  152. {
  153. LogErrorTrace(__FILE__, __LINE__, _T("SetChartData: invalid pointer."));
  154. return FALSE;
  155. }
  156. pImg->SetChartData();
  157. return TRUE;
  158. }
  159. void CBSEImgClr::GetBSEChart(array<WORD>^ % a_wChart)
  160. {
  161. CBSEImgPtr pImg = GetBSEImgPtr();
  162. if (pImg == nullptr)
  163. {
  164. LogErrorTrace(__FILE__, __LINE__, _T("GetBSEChart: invalid pointer."));
  165. return;
  166. }
  167. WORD* pChart = pImg->GetBSEChart();
  168. pin_ptr<WORD> pi = &a_wChart[0];
  169. WORD *pinp = pi;
  170. memcpy(pinp, pChart, (DWORD)CHART_NUM);
  171. for (int i = 0; i < CHART_NUM; i++)
  172. {
  173. a_wChart[i] = pChart[i];
  174. }
  175. }
  176. long CBSEImgClr::CalBSEChartHigh()
  177. {
  178. CBSEImgPtr pImg = GetBSEImgPtr();
  179. if (pImg == nullptr)
  180. {
  181. LogErrorTrace(__FILE__, __LINE__, _T("CalBSEChartHigh: invalid pointer."));
  182. return -1;
  183. }
  184. return pImg->CalBSEChartHigh();
  185. }
  186. long CBSEImgClr::CalBSEChartLow()
  187. {
  188. CBSEImgPtr pImg = GetBSEImgPtr();
  189. if (pImg == nullptr)
  190. {
  191. LogErrorTrace(__FILE__, __LINE__, _T("CalBSEChartLow: invalid pointer."));
  192. return -1;
  193. }
  194. return pImg->CalBSEChartLow();
  195. }
  196. // cal BSE value by position
  197. int CBSEImgClr::GetBSEValue(Point^ a_position)
  198. {
  199. if (a_position == nullptr)
  200. {
  201. LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid point"));
  202. return -1;
  203. }
  204. CPoint pt;
  205. pt.x = a_position->X;
  206. pt.y = a_position->Y;
  207. CBSEImgPtr pImg = GetBSEImgPtr();
  208. if (pImg == nullptr)
  209. {
  210. LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer."));
  211. return -1;
  212. }
  213. return pImg->GetBSEValue(pt);
  214. }
  215. int CBSEImgClr::GetBSEValue(const int a_nX, const int a_nY)
  216. {
  217. CBSEImgPtr pImg = GetBSEImgPtr();
  218. if (pImg == nullptr)
  219. {
  220. LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer."));
  221. return -1;
  222. }
  223. return pImg->GetBSEValue(a_nX, a_nY);
  224. }
  225. void CBSEImgClr::SetBSEValue(const int a_nX, const int a_nY, int value)
  226. {
  227. CBSEImgPtr pImg = GetBSEImgPtr();
  228. if (pImg == nullptr)
  229. {
  230. LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer."));
  231. return ;
  232. }
  233. pImg->SetBSEValue(a_nX, a_nY,value);
  234. }
  235. int CBSEImgClr::GetValueDirect(Point^ a_position)
  236. {
  237. if (a_position == nullptr)
  238. {
  239. LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirect: invalid point"));
  240. return -1;
  241. }
  242. CPoint pt;
  243. pt.x = a_position->X;
  244. pt.y = a_position->Y;
  245. CBSEImgPtr pImg = GetBSEImgPtr();
  246. if (pImg == nullptr)
  247. {
  248. LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirect: invalid pointer."));
  249. return -1;
  250. }
  251. return pImg->GetValueDirect(pt);
  252. }
  253. int CBSEImgClr::GetValueDirectF(int inX, int inY)
  254. {
  255. CBSEImgPtr pImg = GetBSEImgPtr();
  256. if (pImg == nullptr)
  257. {
  258. LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirectF: invalid pointer."));
  259. return -1;
  260. }
  261. return pImg->GetBSEValue(inX, inY);
  262. }
  263. bool CBSEImgClr::DoesContainPixelValue(int inValue, int a_nPixel)
  264. {
  265. CBSEImgPtr pImg = GetBSEImgPtr();
  266. if (pImg == nullptr)
  267. {
  268. LogErrorTrace(__FILE__, __LINE__, _T("DoesContainPixelValue: invalid pointer."));
  269. return false;
  270. }
  271. return pImg->DoesContainPixelValue(inValue, a_nPixel);
  272. }
  273. // cal area
  274. DWORD CBSEImgClr::CalArea()
  275. {
  276. CBSEImgPtr pImg = GetBSEImgPtr();
  277. if (pImg == nullptr)
  278. {
  279. LogErrorTrace(__FILE__, __LINE__, _T("CalArea: invalid pointer."));
  280. return -1;
  281. }
  282. return pImg->CalArea();
  283. }
  284. CBSEImgPtr CBSEImgClr::GetBSEImgPtr()
  285. {
  286. return *m_LpBSEImg;
  287. }
  288. }