RawLoad example for C++ Builder
//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 private variables.
Add these variables and procedure declarations to the private section of the Form1.
//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)
bool bOrderBGR; //TRUE if order BGR, FALSE if order RGB
int nOffset; //offset into file where raw data begins
bool bPadding; //TRUE if each line of data is padded to four bytes
bool bReverseBits; //TRUE if the bits of each byte are reversed
void LoadRawData(AnsiString strFileName);
void TForm1::LoadRawData(AnsiString strFileName)
{
int nRet;
//Fill in the values of the private variables
//The priavte variables will get access in the LoadInfo event
nWidth= 294;
nHeight= 415;
nBitsPerPixel= 24;
nViewPerspective= BOTTOM_LEFT;
bOrderBGR= True;
nOffset= 100;
bPadding= True;
bReverseBits= True;
LEADImage1->EnableLoadInfoEvent=
true;
nRet= LEADImage1->Load(strFileName, nBitsPerPixel, 0, 1);
LEADImage1->EnableLoadInfoEvent= false;
if(nRet == SUCCESS)
ShowMessage("SUCCESS file load: " + strFileName);
else
ShowMessage("FAILED--file load: " + strFileName);
}
void __fastcall TForm1::LEADImage1LoadInfo(TObject *Sender)
{
int i;
byte nGray;
int nColors;
LEADImage1->LoadInfoFormat= FILE_RAW;
LEADImage1->LoadInfoWidth= nWidth;
LEADImage1->LoadInfoHeight= nHeight;
LEADImage1->LoadInfoBits= nBitsPerPixel;
LEADImage1->LoadInfoXRes= 150;
LEADImage1->LoadInfoYRes= 150;
LEADImage1->LoadInfoOffset= nOffset;
LEADImage1->LoadInfoFlags= 0;
if(bPadding)
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_PAD4;
if(!bOrderBGR)
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_ORDERRGB;
if(bReverseBits)
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_LSB;
switch (nViewPerspective)
{
case TOP_LEFT:
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_TOPLEFT;
break;
case BOTTOM_LEFT:
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_REVERSE;
break;
case TOP_RIGHT: //BOTTOM_LEFT180
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_BOTTOMLEFT180;
break;
case BOTTOM_RIGHT: //TOP_LEFT180
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_TOPLEFT180;
break;
case RIGHT_TOP: //TOP_LEFT90
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_TOPLEFT90;
break;
case LEFT_BOTTOM: //TOP_LEFT270
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_TOPLEFT270;
break;
case LEFT_TOP: //BOTTOM_LEFT90
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_BOTTOMLEFT90;
break;
case RIGHT_BOTTOM: //BOTTOM_LEFT270
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_BOTTOMLEFT270;
break;
}
//if image is palettized create a grayscale palette
if(nBitsPerPixel <= 8)
{
nColors= (2 ^ nBitsPerPixel);
LEADImage1->LoadInfoFlags= LEADImage1->LoadInfoFlags | LOADINFO_PALETTE;
for(i= 0; i < nColors; i ++)
{
nGray= (i * 256) / nColors;
LEADImage1->UserPalette[i]= RGB(nGray, nGray, nGray);
}
}
}