OTSScanBase.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #include "stdafx.h"
  2. #include "OTSScanBase.h"
  3. #include <atlimage.h>
  4. namespace OTSController {
  5. COTSScanBase::COTSScanBase()
  6. : m_pnFrameStore(NULL)
  7. , m_nFrameStoreSizeWords(0)
  8. , m_nScanStepSize(0)
  9. , m_nPixelDwell(0)
  10. , m_nInterPixelDwell(0)
  11. , m_nNumberOfReads(0)
  12. , m_nMatrix(0)
  13. , m_dMag(0)
  14. , m_bIsSimuation(FALSE)
  15. {
  16. m_fieldSizes[0] = CSize(64, 50);
  17. m_fieldSizes[1] = CSize(128, 100);
  18. m_fieldSizes[2] = CSize(256, 200);
  19. m_fieldSizes[3] = CSize(512, 400);
  20. m_fieldSizes[4] = CSize(1024, 800);
  21. m_fieldSizes[5] = CSize(2048, 1600);
  22. m_fieldSizes[6] = CSize(4096, 3200);
  23. }
  24. COTSScanBase::~COTSScanBase()
  25. {
  26. }
  27. // get image from a file
  28. CBSEImgPtr COTSScanBase::AcquireBSEImageFromBitmapFile()
  29. {
  30. // prepare file
  31. CFile file;
  32. CFileException fe;
  33. BYTE* m_pPixel;
  34. BYTE* m_pBmInfo;
  35. BITMAPFILEHEADER* m_pBmfh;
  36. m_pBmfh = new BITMAPFILEHEADER;
  37. // get simulation image file name
  38. CString strOTSSysDataPath = GetCompanySysDataPathName();
  39. CString strBitmapFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_IMAGE_FILENAME;
  40. CString strtiffFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_TIFFIMAGE_FILENAME;
  41. CString strjpegFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_JPEGIMAGE_FILENAME;
  42. CString strpngFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_PNGIMAGE_FILENAME;
  43. CBSEImgPtr bseImage(new CBSEImg());
  44. // check if the file exist
  45. if (Exists(strBitmapFilePathName))
  46. {
  47. if (!file.Open(strBitmapFilePathName, CFile::modeRead, &fe))
  48. {
  49. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
  50. return nullptr;
  51. }
  52. // read file header
  53. file.Read(m_pBmfh, sizeof(BITMAPFILEHEADER));
  54. m_pBmInfo = new BYTE[m_pBmfh->bfOffBits - 14];
  55. file.Read(m_pBmInfo, m_pBmfh->bfOffBits - 14);
  56. BITMAPINFOHEADER bmih;
  57. memcpy(&bmih, m_pBmInfo, sizeof(BITMAPINFOHEADER));
  58. long width = bmih.biWidth;//获取宽度
  59. int bitCount = bmih.biBitCount;//获取位数
  60. long height = bmih.biHeight;//获取高度
  61. long LineBytes = (width * bitCount + 31) / 32 * 4;//计算每行像素所占的字节数
  62. m_pPixel = new BYTE[height * LineBytes];
  63. file.Read(m_pPixel, height * LineBytes);
  64. file.Close();
  65. CRect imageRect(0, 0, width, height);
  66. bseImage->SetImageRect(imageRect);
  67. bseImage->InitImageData(width, height);
  68. BYTE* pImageData = bseImage->GetImageDataPointer();
  69. long nActImageSize = width * height;
  70. for (int i = 0; i < height; i++)
  71. {
  72. memcpy(pImageData + i * width, m_pPixel + (height - i) * width, width);
  73. }
  74. delete[]m_pPixel;
  75. delete[]m_pBmInfo;
  76. delete m_pBmfh;
  77. }
  78. else if(Exists(strtiffFilePathName))
  79. {
  80. bseImage = AcquireBSEImageFromTiffFile();
  81. }
  82. else if (Exists(strjpegFilePathName))
  83. {
  84. bseImage = AcquireBSEImageFromJpegFile();
  85. }
  86. else if (Exists(strpngFilePathName))
  87. {
  88. bseImage = AcquireBSEImageFromPngFile();
  89. }
  90. return bseImage;
  91. }
  92. CBSEImgPtr COTSScanBase::AcquireBSEImageFromTiffFile()
  93. {
  94. CImage* img = new CImage();
  95. CBSEImgPtr bseImage(new CBSEImg());
  96. CString strOTSSysDataPath = GetCompanySysDataPathName();
  97. CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_TIFFIMAGE_FILENAME;
  98. if (Exists(strImageFilePathName))
  99. {
  100. img->Load(strImageFilePathName);
  101. long width = img->GetWidth();
  102. long height = img->GetHeight();
  103. CRect imageRect(0, 0, width, height);
  104. bseImage->SetImageRect(imageRect);
  105. BYTE* data = (BYTE*)img->GetBits();
  106. bseImage->SetImageData(data, width, height);
  107. }
  108. return bseImage;
  109. }
  110. CBSEImgPtr COTSScanBase::AcquireBSEImageFromJpegFile()
  111. {
  112. CImage* img = new CImage();
  113. CBSEImgPtr bseImage(new CBSEImg());
  114. CString strOTSSysDataPath = GetCompanySysDataPathName();
  115. CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_JPEGIMAGE_FILENAME;
  116. if (Exists(strImageFilePathName))
  117. {
  118. img->Load(strImageFilePathName);
  119. long width = img->GetWidth();
  120. long height = img->GetHeight();
  121. CRect imageRect(0, 0, width, height);
  122. bseImage->SetImageRect(imageRect);
  123. BYTE* data = (BYTE*)img->GetBits();
  124. bseImage->SetImageData(data, width, height);
  125. }
  126. return bseImage;
  127. }
  128. CBSEImgPtr COTSScanBase::AcquireBSEImageFromPngFile()
  129. {
  130. CImage* img = new CImage();
  131. CBSEImgPtr bseImage(new CBSEImg());
  132. CString strOTSSysDataPath = GetCompanySysDataPathName();
  133. CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_PNGIMAGE_FILENAME;
  134. if (Exists(strImageFilePathName))
  135. {
  136. img->Load(strImageFilePathName);
  137. long width = img->GetWidth();
  138. long height = img->GetHeight();
  139. CRect imageRect(0, 0, width, height);
  140. bseImage->SetImageRect(imageRect);
  141. BYTE* data = (BYTE*)img->GetBits();
  142. bseImage->SetImageData(data, width, height);
  143. }
  144. return bseImage;
  145. }
  146. // get max size index
  147. int COTSScanBase::GetMaxSizeIndex(void)
  148. {
  149. int nRet = (sizeof(m_fieldSizes) / sizeof(CSize) - 1);
  150. return nRet;
  151. }
  152. // bruker scan test
  153. BOOL COTSScanBase::IsBruker()
  154. {
  155. BOOL BRet = (GetType() == ScanController::SCANNER_ID::BRUKER);
  156. return BRet;
  157. }
  158. }