|
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "CsvToImg.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CCsvToImg * gCsvToImg = new CCsvToImg;
|
|
|
|
|
std::map<const int, int> m_proportionEnergy;
|
|
|
|
|
int ColorRange::AllCnt = 0;
|
|
|
|
|
CCsvToImg::CCsvToImg()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CCsvToImg::~CCsvToImg()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCsvToImg::ReadCsv2Img(CString CsvPath)
|
|
|
|
|
{
|
|
|
|
|
m_colorSchemeManager.currentScheme->RestRangeCnt();
|
|
|
|
|
int Rows = 0, Cols = 0;
|
|
|
|
|
int* pData= GetCsvData(CsvPath, Rows, Cols);
|
|
|
|
|
CreateImgFromData(pData, Rows, Cols, m_Img);
|
|
|
|
|
delete []pData;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCsvToImg::ShowLastImg(CWnd * pSHowWnd)
|
|
|
|
|
{
|
|
|
|
|
CSingleLock sLck(&m_Section, TRUE);
|
|
|
|
|
if (m_Img.IsNull())
|
|
|
|
|
return false;
|
|
|
|
|
CDC* pDC = pSHowWnd->GetDC();
|
|
|
|
|
HDC hDc = pDC->m_hDC;
|
|
|
|
|
RECT WndRect;
|
|
|
|
|
pSHowWnd->GetClientRect(&WndRect);
|
|
|
|
|
pDC->SetStretchBltMode(HALFTONE);
|
|
|
|
|
m_Img.StretchBlt(hDc, WndRect);
|
|
|
|
|
ReleaseDC(pSHowWnd->m_hWnd, hDc);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCsvToImg::SaveLastImg(const CString & savePath)
|
|
|
|
|
{
|
|
|
|
|
if (m_Img.IsNull())
|
|
|
|
|
return false;
|
|
|
|
|
m_Img.Save(savePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int * CCsvToImg::GetCsvData(const char * path, int & Rows, int & Cols)
|
|
|
|
|
{
|
|
|
|
|
std::ifstream file;
|
|
|
|
|
std::string sFilePath = path;
|
|
|
|
|
file.open(sFilePath, std::ifstream::in | std::ofstream::binary);
|
|
|
|
|
|
|
|
|
|
if (!file.good())
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
std::stringstream buffer;
|
|
|
|
|
buffer << file.rdbuf();
|
|
|
|
|
string sFile = buffer.str();
|
|
|
|
|
const int size = sFile.size();
|
|
|
|
|
const char *str = sFile.c_str();
|
|
|
|
|
|
|
|
|
|
int * p = new int[size]();
|
|
|
|
|
|
|
|
|
|
int start = 0;
|
|
|
|
|
int end = 0;
|
|
|
|
|
|
|
|
|
|
int RowCnt = 0;
|
|
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
|
{
|
|
|
|
|
if (str[i] == ',')
|
|
|
|
|
{
|
|
|
|
|
char s[8]{ 0 };
|
|
|
|
|
memcpy(s, str + start, end);
|
|
|
|
|
p[idx++] = atoi(s);
|
|
|
|
|
start = i + 1;
|
|
|
|
|
end = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (str[i] == '\r')
|
|
|
|
|
{
|
|
|
|
|
char s[8]{ 0 };
|
|
|
|
|
memcpy(s, str + start, end);
|
|
|
|
|
p[idx++] = atoi(s);
|
|
|
|
|
|
|
|
|
|
start = i + 2;
|
|
|
|
|
++i;
|
|
|
|
|
end = 0;
|
|
|
|
|
RowCnt++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
end++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int ColCnt = idx / RowCnt;
|
|
|
|
|
Cols = ColCnt;
|
|
|
|
|
Rows = RowCnt;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCsvToImg::CreateImgFromData(int * pDataOrg, int Rows, int Cols, CImage & image)
|
|
|
|
|
{
|
|
|
|
|
CSingleLock sLck(&m_Section, TRUE);
|
|
|
|
|
image.Destroy();
|
|
|
|
|
image.Create(Rows, Cols,24);
|
|
|
|
|
byte* pSourceData = (byte*)image.GetBits();
|
|
|
|
|
int image_pitch = 3;
|
|
|
|
|
|
|
|
|
|
int r = 0, g = 0, b = 0;
|
|
|
|
|
int idx = 0;
|
|
|
|
|
for (int i = 0; i < Rows; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < Cols; j++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
image.SetPixel(i, j, m_colorSchemeManager.currentScheme->getColor(*pDataOrg++));
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>RGB<47><42><EFBFBD><EFBFBD>
|
|
|
|
|
/*if (pDataOrg[idx++]<100)
|
|
|
|
|
{
|
|
|
|
|
image.SetPixel(i, j, RGB_GREEN);
|
|
|
|
|
|
|
|
|
|
/ **(pSourceData + j * image_pitch + i * 3) = 0;//R
|
|
|
|
|
*(pSourceData + j * image_pitch + i * 3 + 1) = 0;//G
|
|
|
|
|
*(pSourceData + j * image_pitch + i * 3 + 2) = 255;* /
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
image.SetPixel(i, j, RGB_RED);
|
|
|
|
|
} */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_colorSchemeManager.currentScheme->CalRangesPercent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|