Не шарю всех тонкостей синтаксиса с++)) Подскажите, что исправить надо
Код:
program bwcoding;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ExtDlgs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Bevel1: TBevel;
Image1: TImage;
Bevel2: TBevel;
Image2: TImage;
BitBtn1: TBitBtn;
OpenPictureDialog1: TOpenPictureDialog;
Label1: TLabel;
BitBtn2: TBitBtn;
Button1: TButton;
Label2: TLabel;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Label3: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
function BinToDec(s:string):integer;
procedure Encode(FileName:string);
procedure Decode(FileName:string);
function cl(x:integer):byte;
function GetXY(n:integer):TPoint;
procedure BitBtn2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
OldFileSize, NewFileSize: real;
mas: array [1..352*352] of byte;
f:File of Byte;
function TForm1.GetXY(n:integer):TPoint;
begin
Result.Y := n div 352;
Result.X := n - (Result.Y * 352);
end;
function TForm1.cl(x:integer):byte;
begin
if x=clWhite then result:=0 else result:=1;
end;
procedure TForm1.Encode(FileName:string);
var
count,i,j:integer;
c: byte;
cc,p:byte;
begin
p:=0;
with image1.Canvas do
for j:=0 to 351 do
for i:=0 to 351 do
if pixels[i,j]=clBlack then mas[j*352+i]:=1 else
mas[j*352+i]:=0;
AssignFile(f, FileName);
Rewrite(f);
i:=1;
p:=mas[1];
count:=1;
cc:=255;
while i<352*352 do
begin
if mas[i]=p then inc(count) else
begin
if count>255 then
begin
for j:=1 to count div 255 do write(f,p,cc);
c:=count mod 255;
write(f,p,c);
end else write(f,p,count);
p:=mas[i];
count:=1;
end;
inc(i);
end;
for j:=1 to count div 255 do write(f,p,cc);
c:=count-(count div 255)*255;
write(f,p,c);
CloseFile(f);
end;
function TForm1.BinToDec(s:string):integer;
var
i,n,sm: integer;
begin
n:=1;
sm:=0;
for i:=length(s) downto 1 do
begin
if s[i]='1' then sm:=sm+n;
n:=n*2;
end;
result := sm;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Label1.Caption := 'Размер исходного файла:';
Label2.Caption := 'Размер сжатого файла:';
Label3.Caption := 'Коэффициент сжатия:-';
with openpicturedialog1 do if execute then
begin
Image1.Picture.LoadFromFile(FileName);
AssignFile(f, FileName);
Reset(f);
Label1.Caption:=Label1.Caption+' '+IntTostr(FileSize(F))+' байт';
OldFileSize:=FileSize(f);
CloseFile(f);
end;
end;
procedure TForm1.Image1Click(Sender: TObject);
begin
Image1.Stretch:= not Image1.Stretch;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
with savedialog1 do if execute then
begin
Encode(FileName);
AssignFile(f, FileName);
Reset(f);
Label2.Caption:=Label2.Caption+' '+IntTostr(FileSize(f))+' байт';
NewFileSize:=FileSize(f);
Label3.Caption:=Label3.Caption+' 1:'+floattostr(trunc(OldFileSize / NewFileSize*10)/10);
CloseFile(F);
end;
end;
procedure TForm1.Decode(FileName:string);
var
p,cur: byte;
k,i,j,l,prev:integer;
begin
AssignFile(f,FileName);
Reset(f);
i:=1;
j:=0;
while not eof(f) do
begin
read(f,p);
read(f,cur);
for l:=1 to cur do
begin
inc(i);
if i>352 then
begin
i:=1;
inc(j);
end;
if p=0 then image2.Canvas.Pixels[i,j]:=clWhite else
if p=1 then image2.Canvas.Pixels[i,j]:=clBlack;
end;
end;
CloseFile(F);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with opendialog1 do if execute then decode(FileName);
end;
end.
i:=1;
p:=mas[1];
count:=1;
cc:=255;
while i<352*352 do
begin
if mas[i]=p then inc(count) else
begin
if count>255 then
begin
for j:=1 to count div 255 do write(f,p,cc);
c:=count mod 255;
write(f,p,c)
end else
write(f,p,count);
count:=1;
p:=mas[i];
end;
inc(i);
end;