OTSScanBase.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "stdafx.h"
  2. #include "OTSScanBase.h"
  3. namespace OTSController {
  4. COTSScanBase::COTSScanBase()
  5. : m_pnFrameStore(NULL)
  6. , m_nFrameStoreSizeWords(0)
  7. , m_nScanStepSize(0)
  8. , m_nPixelDwell(0)
  9. , m_nInterPixelDwell(0)
  10. , m_nNumberOfReads(0)
  11. , m_nMatrix(0)
  12. , m_dMag(0)
  13. , m_bIsSimuation(FALSE)
  14. {
  15. m_fieldSizes[0] = CSize(64, 50);
  16. m_fieldSizes[1] = CSize(128, 100);
  17. m_fieldSizes[2] = CSize(256, 200);
  18. m_fieldSizes[3] = CSize(512, 400);
  19. m_fieldSizes[4] = CSize(1024, 800);
  20. m_fieldSizes[5] = CSize(2048, 1600);
  21. m_fieldSizes[6] = CSize(4096, 3200);
  22. }
  23. COTSScanBase::~COTSScanBase()
  24. {
  25. }
  26. // get image from a file
  27. CBSEImgPtr COTSScanBase::AcquireBSEImageFromBitmapFile()
  28. {
  29. // prepare file
  30. CFile file;
  31. CFileException fe;
  32. BYTE* m_pPixel;
  33. BYTE* m_pBmInfo;
  34. BITMAPFILEHEADER* m_pBmfh;
  35. m_pBmfh = new BITMAPFILEHEADER;
  36. // get simulation image file name
  37. CString strOTSSysDataPath = GetCompanySysDataPathName();
  38. CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_IMAGE_FILENAME;
  39. // check if the file exist
  40. if (!Exists(strImageFilePathName))
  41. {
  42. // simulation spectrum file doesn't exist
  43. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: simulation image file doesn't exist."));
  44. return nullptr;
  45. }
  46. if (!file.Open(strImageFilePathName, CFile::modeRead, &fe))
  47. {
  48. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strImageFilePathName);
  49. return nullptr;
  50. }
  51. // read file header
  52. file.Read(m_pBmfh, sizeof(BITMAPFILEHEADER));
  53. m_pBmInfo = new BYTE[m_pBmfh->bfOffBits - 14];
  54. file.Read(m_pBmInfo, m_pBmfh->bfOffBits - 14);
  55. BITMAPINFOHEADER bmih;
  56. memcpy(&bmih, m_pBmInfo, sizeof(BITMAPINFOHEADER));
  57. long width = bmih.biWidth;//获取宽度
  58. int bitCount = bmih.biBitCount;//获取位数
  59. long height = bmih.biHeight;//获取高度
  60. long LineBytes = (width*bitCount + 31) / 32 * 4;//计算每行像素所占的字节数
  61. m_pPixel = new BYTE[height*LineBytes];
  62. file.Read(m_pPixel, height*LineBytes);
  63. file.Close();
  64. CBSEImgPtr bseImage(new CBSEImg());
  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. return bseImage;
  78. }
  79. // get max size index
  80. int COTSScanBase::GetMaxSizeIndex(void)
  81. {
  82. int nRet = (sizeof(m_fieldSizes) / sizeof(CSize) - 1);
  83. return nRet;
  84. }
  85. // bruker scan test
  86. BOOL COTSScanBase::IsBruker()
  87. {
  88. BOOL BRet = (GetType() == ScanController::SCANNER_ID::BRUKER);
  89. return BRet;
  90. }
  91. }