BSEImgClr.cpp 6.7 KB

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