OTSScanBase.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. CBSEImgPtr bseImage;
  38. // get simulation image file name
  39. CString strOTSSysDataPath = GetCompanySysDataPathName();
  40. CString strBitmapFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_IMAGE_FILENAME;
  41. // check if the file exist
  42. if (Exists(strBitmapFilePathName))
  43. {
  44. if (!file.Open(strBitmapFilePathName, CFile::modeRead, &fe))
  45. {
  46. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
  47. return nullptr;
  48. }
  49. // read file header
  50. file.Read(m_pBmfh, sizeof(BITMAPFILEHEADER));
  51. m_pBmInfo = new BYTE[m_pBmfh->bfOffBits - 14];
  52. file.Read(m_pBmInfo, m_pBmfh->bfOffBits - 14);
  53. BITMAPINFOHEADER bmih;
  54. memcpy(&bmih, m_pBmInfo, sizeof(BITMAPINFOHEADER));
  55. long width = bmih.biWidth;//获取宽度
  56. int bitCount = bmih.biBitCount;//获取位数
  57. long height = bmih.biHeight;//获取高度
  58. long LineBytes = (width * bitCount + 31) / 32 * 4;//计算每行像素所占的字节数
  59. m_pPixel = new BYTE[height * LineBytes];
  60. file.Read(m_pPixel, height * LineBytes);
  61. file.Close();
  62. CRect imageRect(0, 0, width, height);
  63. bseImage=CBSEImgPtr(new CBSEImg(imageRect));
  64. /*bseImage->SetImageRect(imageRect);*/
  65. bseImage->InitImageData(width, height);
  66. BYTE* pImageData = bseImage->GetImageDataPointer();
  67. long nActImageSize = width * height;
  68. for (int i = 0; i < height; i++)
  69. {
  70. memcpy(pImageData + i * width, m_pPixel + (height - i) * width, width);
  71. }
  72. delete[]m_pPixel;
  73. delete[]m_pBmInfo;
  74. delete m_pBmfh;
  75. }
  76. else
  77. {
  78. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
  79. return nullptr;
  80. }
  81. return bseImage;
  82. }
  83. // get max size index
  84. int COTSScanBase::GetMaxSizeIndex(void)
  85. {
  86. int nRet = (sizeof(m_fieldSizes) / sizeof(CSize) - 1);
  87. return nRet;
  88. }
  89. // bruker scan test
  90. BOOL COTSScanBase::IsBruker()
  91. {
  92. BOOL BRet = (GetType() == ScanController::SCANNER_ID::BRUKER);
  93. return BRet;
  94. }
  95. }