procedure TForm1.ReadPicture(Header:HeaderType; Palette:Palette256; FileName: string);
var f:file; Rep,Desc,p:byte; i,x,y:word;
begin
AssignFile(f,FileName);
reset(f,1);
// seek(F,129);
if Header.BitPerPixel=8 then seek(F,129);
if Header.BitPerPixel=4 then seek(F,128);
blockread(f,Rep,1);
x:=0;
y:=0;
repeat //for i:=1 to Header.Xend do
if Rep>=192 then
begin
Rep:=Rep-192;
if Header.BitPerPixel=4 then Rep:=Rep*2;
//if Header.BitPerPixel=4 then Rep:=(Rep-192)*2
// else if Header.BitPerPixel=8 then Rep:=Rep-192; blockread(f,Desc,1);
//Rep:=Rep-192;
blockread(f,Desc,1);
for i:=1 to Rep do
begin
//Image1.Canvas.Pixels[x,y]:=Header.Palette[Desc];
if Header.BitPerPixel=4 then
begin
Desc:=Desc and $0F;
Image1.Canvas.Pixels[x,y]:=Header.Palette[1,Desc]
+(integer(Header.Palette[2,Desc]) shl 8)+
+(integer(Header.Palette[3,Desc]) shl 16)
end
else
if Header.BitPerPixel=8 then
Image1.Canvas.Pixels[x,y]:=Palette.Colors[1,Desc]
+(integer(Palette.Colors[2,Desc]) shl 8)+
+(integer(Palette.Colors[3,Desc]) shl 16);
if x>=Header.Xend then begin
y:=y+1;
x:=0
end
else x:=x+1;
end;
blockread(f,Rep,1);
end
else
begin
//Image1.Canvas.Pixels[x,y]:=//Header.Palette[Desc];
if Header.BitPerPixel=4 then p:=2
else if Header.BitPerPixel=8 then p:=1;
for i:=1 to p do
begin
if Header.BitPerPixel=4 then
begin
Rep:=Rep and $0F;
Image1.Canvas.Pixels[x,y]:=Header.Palette[1,Rep]
+(integer(Header.Palette[2,Rep]) shl 8)+
+(integer(Header.Palette[3,Rep]) shl 16)
end
else
if Header.BitPerPixel=8 then
Image1.Canvas.Pixels[x,y]:=Palette.Colors[1,Rep]
+(integer(Palette.Colors[2,Rep]) shl 8)+
+(integer(Palette.Colors[3,Rep]) shl 16);
if x>=Header.Xend then begin
y:=y+1;
x:=0
end
else x:=x+1;
end;
blockread(f,Rep,1);
end
until (Filepos(f)>=Filesize(F)-769){or((x>=Header.Xend)and(y>=Header.Yend))};
CloseFile(F);
end;
Чтение заголовка:
procedure TForm1.HeaderRead(var Header: HeaderType; var Palette:Palette256; FileName: string);
var f:file; i,j:byte;
begin
Label1.Caption:='Identifier'+#13+'Version'+#13+'Encoding'+#13+'BitPerPixel'
+#13+'Xstart'+#13+'Ystart'+#13+'Xend'+#13+'Yend'+#13+'HorizRez'+#13+
'VertRez'+#13+'Palette'+#13+#13+#13+'VideoMode'+#13+'NumBitPlanes'+#13+'BytesPerLine'
+#13+'PaletteType'+#13+'HorizScrSize'+#13+'VertScrSize'+#13+'Palette';
AssignFile(f,FileName);
reset(f,1);
blockread(f,Header.Identifier,1);
if Header.Identifier<>10 then begin
showmessage('Неверное изображение');
exit
end;
blockread(f,Header.Version,1);
blockread(f,Header.Encoding,1);
blockread(f,Header.BitPerPixel,1);
blockread(f,Header.Xstart,2);
blockread(f,Header.Ystart,2);
blockread(f,Header.Xend,2);
blockread(f,Header.Yend,2);
blockread(f,Header.HorizRez,2);
blockread(f,Header.VertRez,2);
for j:=0 to 15 do
begin
for i:=1 to 3 do
begin
blockread(f,Header.Palette[i,j],1);
//Header.Palette[i,j]:=Header.Palette[i,j] shr 3;
end;
end;
{for j:=1 to 16 do
begin
blockread(f,Header.Palette[j],3);
end;}
blockread(f,Header.VideoMode,1);
blockread(f,Header.NumBitPlanes,1);
blockread(f,Header.BytesPerLine,2);
blockread(f,Header.PaletteType,2);
blockread(f,Header.HorizScrSize,2);
blockread(f,Header.VertScrSize,2);
seek(F,Filesize(F)-769);
blockread(f,Palette.PaletteType,1);
{for i:=1 to 3 do
begin
for j:=0 to 255 do
begin
blockread(f,Palette.Colors[i,j],1);
//Palette.Colors[i,j]:=Palette.Colors[i,j] or $3F;
end;
end;}
for j:=0 to 255 do
begin
for i:=1 to 3 do
begin
blockread(f,Palette.Colors[i,j],1);
//Palette.Colors[i,j]:=Palette.Colors[i,j] div 4;
end;
end;
CloseFile(F);
Form1.Label2.Caption:='';
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.Identifier)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.Version)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.Encoding)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.BitPerPixel)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.Xstart)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.Ystart)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.Xend)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.Yend)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.HorizRez)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.VertRez);
for i:=1 to 3 do
begin
Form1.Label2.Caption:=Form1.Label2.Caption+#13;
for j:=0 to 15 do
begin
Form1.Label2.Caption:=Form1.Label2.Caption
+inttohex(Header.Palette[i,j],2)+' ';
end;
end;
{for j:=1 to 16 do
begin
Form3.Label2.Caption:=Form3.Label2.Caption
+inttostr(Header.Palette[j])+' ';
end;}
Form1.Label2.Caption:=Form1.Label2.Caption+#13+inttostr(Header.VideoMode)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.NumBitPlanes)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.BytesPerLine)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.PaletteType)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.HorizScrSize)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Header.VertScrSize)+#13;
Form1.Label2.Caption:=Form1.Label2.Caption+inttostr(Palette.PaletteType)+#13;
for i:=1 to 3 do
begin
for j:=0 to 255 do
begin
Form1.Label2.Caption:=Form1.Label2.Caption
+inttohex(Palette.Colors[i,j],2)+' ';
end;
Form1.Label2.Caption:=Form1.Label2.Caption+#13;
end;
end;
http://www.ekbforex.ru/publ/strategii_foreks/13 |