RawLoad example for Delphi
//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
nWidth: Integer; //width of image
nHeight: Integer; //height of image
nBitsPerPixel: Integer; // bits per pixel of image--if palettized, a gray palette is generated
nViewPerspective: Integer; //view perspective of raw data (TOP_LEFT, BOTTOM_LEFT, etc)
bOrderBGR: Boolean; //TRUE if order BGR, FALSE if order RGB
nOffset: Integer; //offset into file where raw data begins
bPadding: Boolean; //TRUE if each line of data is padded to four bytes
bReverseBits: Boolean; //TRUE if the bits of each byte are reversed
procedure LoadRawData(strFileName: String);
procedure TForm1.LoadRawData(strFileName: String);
var
nRet: Integer;
//Fill in the values of the private variables
//The priavte variables will get access in the LoadInfo event
begin
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)then
ShowMessage('SUCCESS file load: ' + strFileName)
else
ShowMessage('FAILED--file load: ' + strFileName);
end;
procedure TForm1.LEADImage1LoadInfo(Sender: TObject);
var
i: Integer;
nGray: Byte;
nColors: Integer;
begin
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)then
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_PAD4;
if(bOrderBGR = False)then
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_ORDERRGB;
if(bReverseBits)then
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_LSB;
case (nViewPerspective) of
TOP_LEFT:
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_TOPLEFT;
BOTTOM_LEFT:
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_REVERSE;
TOP_RIGHT: //BOTTOM_LEFT180
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_BOTTOMLEFT180;
BOTTOM_RIGHT: //TOP_LEFT180
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_TOPLEFT180;
RIGHT_TOP: //TOP_LEFT90
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_TOPLEFT90;
LEFT_BOTTOM: //TOP_LEFT270
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_TOPLEFT270;
LEFT_TOP: //BOTTOM_LEFT90
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_BOTTOMLEFT90;
RIGHT_BOTTOM: //BOTTOM_LEFT270
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_BOTTOMLEFT270;
end;
//if image is palettized create a grayscale palette
if(nBitsPerPixel <= 8)then
begin
nColors:= Trunc(Power(2, nBitsPerPixel));
LEADImage1.LoadInfoFlags:= LEADImage1.LoadInfoFlags Or LOADINFO_PALETTE;
for i:= 0 to nColors - 1 do
begin
nGray:= Trunc((i * 256) / nColors);
LEADImage1.UserPalette[i]:= RGB(nGray, nGray, nGray);
end;
end;
end;