OTSScanBase.cpp 2.9 KB

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