RawLoad Example for C++ 5.0 and later
//This example loads RAW data into a LEAD control
//Raw data parameters are set in the LoadInfo event, which gets called
//when the file format is FILE_RAW, or any unrecognized file format
//The LoadInfo event obtains information through class variables
//
//NOTE: This is not a complete example for handling events, some steps have
//been omitted. For a complete example of how to handle events, refer to the
//example "Updating a Gauge and Detecting a User Interrupt".
//class variables used in the LoadInfo event
// int nWidth; //width of image
// int nHeight; //height of image
// int nBitsPerPixel; //bits per pixel of image--if palettized, a gray palette is generated
// int nViewPerspective; //view perspective of raw data (TOP_LEFT, BOTTOM_LEFT, etc)
// int bOrderBGR; //TRUE if order BGR, FALSE if order RGB
// unsigned long nOffset; //offset into file where raw data begins
// int bPadding; //TRUE if each line of data is padded to four bytes
// int bReverseBits; //TRUE if the bits of each byte are reversed
void CRawDlg::RawLoad(TCHAR * pszFileName)
{
int nRet;
TCHAR szMsg[200];
ILEADRasterIO *m_pRasterIO=NULL;
//Fill in the class variables
//The class variables will get access in the LoadInfo event
m_nWidth = 294;
m_nHeight = 415;
m_nBitsPerPixel = 24;
m_nViewPerspective = BOTTOM_LEFT;
m_bOrderBGR = TRUE;
m_nOffset = 250;
m_bPadding = TRUE;
m_bReverseBits = TRUE;
nRet = m_pRasterIO->Load (m_RasterView.GetRaster(), pszFileName, m_nBitsPerPixel, 0, 1);
if (nRet == 0)
wsprintf(szMsg, TEXT("SUCCESS file load: %s"), pszFileName);
else
wsprintf(szMsg, TEXT("FAILED--file load: %s"), pszFileName);
AfxMessageBox(szMsg);
}
void CRasterIOSink::OnLoadInfo ()
{
unsigned int uColors, i;
unsigned int uGray;
unsigned int uFlags;
m_pDlg->m_RasterView.SetScaleMode (3);
m_pDlg->m_pRasterIO->LoadInfoFormat = FILE_RAW;
m_pDlg->m_pRasterIO->LoadInfoWidth = (float)m_pDlg->m_nWidth;
m_pDlg->m_pRasterIO->LoadInfoHeight = (float)m_pDlg->m_nHeight;
m_pDlg->m_pRasterIO->LoadInfoBits = m_pDlg->m_nBitsPerPixel;
m_pDlg->m_pRasterIO->LoadInfoXRes = 150;
m_pDlg->m_pRasterIO->LoadInfoYRes = 150;
m_pDlg->m_pRasterIO->LoadInfoOffset = m_pDlg->m_nOffset;
uFlags = 0;
if (m_pDlg->m_bPadding)
uFlags |= LOADINFO_PAD4;
if (m_pDlg->m_bOrderBGR == FALSE)
uFlags |= LOADINFO_ORDERRGB;
if (m_pDlg->m_bReverseBits)
uFlags |= LOADINFO_LSB;
switch(m_pDlg->m_nViewPerspective)
{
case TOP_LEFT:
uFlags |= LOADINFO_TOPLEFT;
break;
case BOTTOM_LEFT:
uFlags |= LOADINFO_REVERSE;
break;
case TOP_RIGHT: //BOTTOM_LEFT180
uFlags |= LOADINFO_BOTTOMLEFT180;
break;
case BOTTOM_RIGHT: //TOP_LEFT180
uFlags |= LOADINFO_TOPLEFT180;
break;
case RIGHT_TOP: //TOP_LEFT90
uFlags |= LOADINFO_TOPLEFT90;
break;
case LEFT_BOTTOM: //TOP_LEFT270
uFlags |= LOADINFO_TOPLEFT270;
break;
case LEFT_TOP: //BOTTOM_LEFT90
uFlags |= LOADINFO_BOTTOMLEFT90;
break;
case RIGHT_BOTTOM: //BOTTOM_LEFT270
uFlags |= LOADINFO_BOTTOMLEFT270;
break;
}
//if image is palettized create a grayscale palette
if (m_pDlg->m_nBitsPerPixel <= 8)
{
uColors = 1 << m_pDlg->m_nBitsPerPixel;
uFlags |= LOADINFO_PALETTE;
for (i=0; i<uColors; i++)
{
uGray = (i * 256) / uColors;
m_pDlg->m_pRasterIO->PutIOPalette (i, RGB(uGray, uGray, uGray));
}
}
m_pDlg->m_pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)uFlags;
}