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 global variables*/
LEADRasterIO* pRasterIO;
//Global 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
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 TForm1::LoadRawData(AnsiString szFileName)
{
int nRet;
//Fill in the values of the global variables
//The global 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;
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
LEADEventSink1->Connect (pRasterIO, DIID__LEADRasterIOEvents);
nRet = pRasterIO->Load (LEADRasterView1->Raster, AnsiToOLESTR(szFileName.c_str()), (short)nBitsPerPixel, 0, 1);
if (nRet == 0)
ShowMessage ("SUCCESS file load: " + szFileName);
else
ShowMessage ("FAILED--file load: " + szFileName);
}
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(pRasterIO)
pRasterIO->Release();
}
void __fastcall TForm1:: LEADEventSink1Invoke(TObject *Sender, int DispID,
const TGUID &IID, int LocaleID, WORD Flags, tagDISPPARAMS &Params,
Pointer varResult, Pointer ExcepInfo, Pointer ArgErr)
{
switch (DispID)
{
case LEADRASTERIOEVENTS_LOADINFO:
{
int nColors;
int i;
int nGray;
pRasterIO->LoadInfoFormat = FILE_RAW;
pRasterIO->LoadInfoWidth = nWidth;
pRasterIO->LoadInfoHeight = nHeight;
pRasterIO->LoadInfoBits = (short)nBitsPerPixel;
pRasterIO->LoadInfoXRes = 150;
pRasterIO->LoadInfoYRes = 150;
pRasterIO->LoadInfoOffset = nOffset;
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)0;
if (bPadding)
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_PAD4);
if (bOrderBGR == False)
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_ORDERRGB);
if (bReverseBits)
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_LSB);
switch (nViewPerspective)
{
case TOP_LEFT:
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_TOPLEFT);
break;
case BOTTOM_LEFT:
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_REVERSE);
break;
case TOP_RIGHT: //BOTTOM_LEFT180
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_BOTTOMLEFT180);
break;
case BOTTOM_RIGHT: //TOP_LEFT180
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_TOPLEFT180);
break;
case RIGHT_TOP: //TOP_LEFT90
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_TOPLEFT90);
break;
case LEFT_BOTTOM: //TOP_LEFT270
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_TOPLEFT270);
break;
case LEFT_TOP: //BOTTOM_LEFT90
pRasterIO->LoadInfoFlags =(LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_BOTTOMLEFT90);
break;
case RIGHT_BOTTOM: //BOTTOM_LEFT270
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_BOTTOMLEFT270);
break;
}
//if image is palettized create a grayscale palette
if (nBitsPerPixel <= 8)
{
nColors = pow(2, nBitsPerPixel);
pRasterIO->LoadInfoFlags = (LoadInfoFlagConstants)(pRasterIO->LoadInfoFlags + LOADINFO_PALETTE);
for (i = 0; i < nColors; i ++)
{
nGray = (i * 256) / nColors;
pRasterIO->set_IOPalette ((short)i, (TColor)RGB(nGray, nGray, nGray));
}
}
}
}
}