|
|
@@ -1,5 +1,6 @@
|
|
|
#include "stdafx.h"
|
|
|
#include "OTSScanBase.h"
|
|
|
+#include <atlimage.h>
|
|
|
|
|
|
|
|
|
namespace OTSController {
|
|
|
@@ -34,6 +35,7 @@ namespace OTSController {
|
|
|
// get image from a file
|
|
|
CBSEImgPtr COTSScanBase::AcquireBSEImageFromBitmapFile()
|
|
|
{
|
|
|
+
|
|
|
// prepare file
|
|
|
CFile file;
|
|
|
CFileException fe;
|
|
|
@@ -45,56 +47,132 @@ namespace OTSController {
|
|
|
|
|
|
// get simulation image file name
|
|
|
CString strOTSSysDataPath = GetCompanySysDataPathName();
|
|
|
- CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_IMAGE_FILENAME;
|
|
|
-
|
|
|
+ CString strBitmapFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_IMAGE_FILENAME;
|
|
|
+ CString strtiffFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_TIFFIMAGE_FILENAME;
|
|
|
+ CString strjpegFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_JPEGIMAGE_FILENAME;
|
|
|
+ CString strpngFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_PNGIMAGE_FILENAME;
|
|
|
+ CBSEImgPtr bseImage(new CBSEImg());
|
|
|
// check if the file exist
|
|
|
- if (!Exists(strImageFilePathName))
|
|
|
+ if (Exists(strBitmapFilePathName))
|
|
|
{
|
|
|
- // simulation spectrum file doesn't exist
|
|
|
- LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: simulation image file doesn't exist."));
|
|
|
- return nullptr;
|
|
|
- }
|
|
|
-
|
|
|
- if (!file.Open(strImageFilePathName, CFile::modeRead, &fe))
|
|
|
+ if (!file.Open(strBitmapFilePathName, CFile::modeRead, &fe))
|
|
|
+ {
|
|
|
+ LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ // read file header
|
|
|
+ file.Read(m_pBmfh, sizeof(BITMAPFILEHEADER));
|
|
|
+ m_pBmInfo = new BYTE[m_pBmfh->bfOffBits - 14];
|
|
|
+
|
|
|
+ file.Read(m_pBmInfo, m_pBmfh->bfOffBits - 14);
|
|
|
+
|
|
|
+ BITMAPINFOHEADER bmih;
|
|
|
+ memcpy(&bmih, m_pBmInfo, sizeof(BITMAPINFOHEADER));
|
|
|
+
|
|
|
+ long width = bmih.biWidth;//获取宽度
|
|
|
+ int bitCount = bmih.biBitCount;//获取位数
|
|
|
+ long height = bmih.biHeight;//获取高度
|
|
|
+ long LineBytes = (width * bitCount + 31) / 32 * 4;//计算每行像素所占的字节数
|
|
|
+
|
|
|
+ m_pPixel = new BYTE[height * LineBytes];
|
|
|
+ file.Read(m_pPixel, height * LineBytes);
|
|
|
+ file.Close();
|
|
|
+
|
|
|
+
|
|
|
+ CRect imageRect(0, 0, width, height);
|
|
|
+ bseImage->SetImageRect(imageRect);
|
|
|
+ bseImage->InitImageData(width, height);
|
|
|
+ BYTE* pImageData = bseImage->GetImageDataPointer();
|
|
|
+
|
|
|
+ long nActImageSize = width * height;
|
|
|
+ for (int i = 0; i < height; i++)
|
|
|
+ {
|
|
|
+ memcpy(pImageData + i * width, m_pPixel + (height - i) * width, width);
|
|
|
+ }
|
|
|
+
|
|
|
+ delete[]m_pPixel;
|
|
|
+ delete[]m_pBmInfo;
|
|
|
+ delete m_pBmfh;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(Exists(strtiffFilePathName))
|
|
|
{
|
|
|
- LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strImageFilePathName);
|
|
|
- return nullptr;
|
|
|
+ bseImage = AcquireBSEImageFromTiffFile();
|
|
|
}
|
|
|
+ else if (Exists(strjpegFilePathName))
|
|
|
+ {
|
|
|
+ bseImage = AcquireBSEImageFromJpegFile();
|
|
|
|
|
|
- // read file header
|
|
|
- file.Read(m_pBmfh, sizeof(BITMAPFILEHEADER));
|
|
|
- m_pBmInfo = new BYTE[m_pBmfh->bfOffBits - 14];
|
|
|
-
|
|
|
- file.Read(m_pBmInfo, m_pBmfh->bfOffBits - 14);
|
|
|
-
|
|
|
- BITMAPINFOHEADER bmih;
|
|
|
- memcpy(&bmih, m_pBmInfo, sizeof(BITMAPINFOHEADER));
|
|
|
+ }
|
|
|
+ else if (Exists(strpngFilePathName))
|
|
|
+ {
|
|
|
+ bseImage = AcquireBSEImageFromPngFile();
|
|
|
+ }
|
|
|
+ return bseImage;
|
|
|
+ }
|
|
|
+ CBSEImgPtr COTSScanBase::AcquireBSEImageFromTiffFile()
|
|
|
+ {
|
|
|
+ CImage* img = new CImage();
|
|
|
+ CBSEImgPtr bseImage(new CBSEImg());
|
|
|
+ CString strOTSSysDataPath = GetCompanySysDataPathName();
|
|
|
+ CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_TIFFIMAGE_FILENAME;
|
|
|
+ if (Exists(strImageFilePathName))
|
|
|
+ {
|
|
|
+ img->Load(strImageFilePathName);
|
|
|
+ long width = img->GetWidth();
|
|
|
+
|
|
|
+ long height = img->GetHeight();
|
|
|
+
|
|
|
+ CRect imageRect(0, 0, width, height);
|
|
|
+ bseImage->SetImageRect(imageRect);
|
|
|
+ BYTE* data = (BYTE*)img->GetBits();
|
|
|
+ bseImage->SetImageData(data, width, height);
|
|
|
+
|
|
|
+ }
|
|
|
+ return bseImage;
|
|
|
+ }
|
|
|
+ CBSEImgPtr COTSScanBase::AcquireBSEImageFromJpegFile()
|
|
|
+ {
|
|
|
+ CImage* img = new CImage();
|
|
|
+ CBSEImgPtr bseImage(new CBSEImg());
|
|
|
+ CString strOTSSysDataPath = GetCompanySysDataPathName();
|
|
|
+ CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_JPEGIMAGE_FILENAME;
|
|
|
+ if (Exists(strImageFilePathName))
|
|
|
+ {
|
|
|
+ img->Load(strImageFilePathName);
|
|
|
+ long width = img->GetWidth();
|
|
|
|
|
|
- long width = bmih.biWidth;//获取宽度
|
|
|
- int bitCount = bmih.biBitCount;//获取位数
|
|
|
- long height = bmih.biHeight;//获取高度
|
|
|
- long LineBytes = (width*bitCount + 31) / 32 * 4;//计算每行像素所占的字节数
|
|
|
+ long height = img->GetHeight();
|
|
|
|
|
|
- m_pPixel = new BYTE[height*LineBytes];
|
|
|
- file.Read(m_pPixel, height*LineBytes);
|
|
|
- file.Close();
|
|
|
+ CRect imageRect(0, 0, width, height);
|
|
|
+ bseImage->SetImageRect(imageRect);
|
|
|
+ BYTE* data = (BYTE*)img->GetBits();
|
|
|
+ bseImage->SetImageData(data, width, height);
|
|
|
|
|
|
+ }
|
|
|
+ return bseImage;
|
|
|
+ }
|
|
|
+ CBSEImgPtr COTSScanBase::AcquireBSEImageFromPngFile()
|
|
|
+ {
|
|
|
+ CImage* img = new CImage();
|
|
|
CBSEImgPtr bseImage(new CBSEImg());
|
|
|
- CRect imageRect(0, 0, width, height);
|
|
|
- bseImage->SetImageRect(imageRect);
|
|
|
- bseImage->InitImageData(width, height);
|
|
|
- BYTE* pImageData = bseImage->GetImageDataPointer();
|
|
|
-
|
|
|
- long nActImageSize = width * height;
|
|
|
- for (int i = 0; i < height; i++)
|
|
|
+ CString strOTSSysDataPath = GetCompanySysDataPathName();
|
|
|
+ CString strImageFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_PNGIMAGE_FILENAME;
|
|
|
+ if (Exists(strImageFilePathName))
|
|
|
{
|
|
|
- memcpy(pImageData + i * width, m_pPixel + (height - i)*width, width);
|
|
|
- }
|
|
|
+ img->Load(strImageFilePathName);
|
|
|
+ long width = img->GetWidth();
|
|
|
|
|
|
- delete[]m_pPixel;
|
|
|
- delete[]m_pBmInfo;
|
|
|
- delete m_pBmfh;
|
|
|
+ long height = img->GetHeight();
|
|
|
|
|
|
+ CRect imageRect(0, 0, width, height);
|
|
|
+ bseImage->SetImageRect(imageRect);
|
|
|
+ BYTE* data = (BYTE*)img->GetBits();
|
|
|
+ bseImage->SetImageData(data, width, height);
|
|
|
+
|
|
|
+ }
|
|
|
return bseImage;
|
|
|
}
|
|
|
|