Function Addtion(MInput,MInput2:Matriks):Matriks;
var
i,j,k,l : integer;
MOutput : Matriks;
begin
if (Length(MInput)>Length(MInput2)) then
begin
SetLength(MOutput,Length(MInput),Length(MInput[0]));
for i:=0 to Length(MOutput)-1 do
begin
for j:=0 to Length(MOutput[0])-1 do
begin
MOutput[i,j]:= MInput[i,j];
end;
end;
for k:=0 to Length(MInput2)-1 do
begin
for l:=0 to Length(MInput2)-1 do
begin
MOutput[k,l]:=MInput[k,l] + MInput2[k,l];
if (MOutput[k,l]>255) then MOutput[k,l]:=255
else if (MOutput[k,l]<0) then MOutput[k,l]:=0;
end;
end;
end
else if (Length(MInput)<Length(MInput2)) then
begin
SetLength(MOutput,Length(MInput2),Length(MInput2[0]));
for i:=0 to Length(MOutput)-1 do
begin
for j:=0 to Length(MOutput[0])-1 do
begin
MOutput[i,j]:= MInput2[i,j];
end;
end;
for k:=0 to Length(MInput)-1 do
begin
for l:=0 to Length(MInput)-1 do
begin
MOutput[k,l]:=MInput2[k,l] + MInput[k,l];
if (MOutput[k,l]>255) then MOutput[k,l]:=255
else if (MOutput[k,l]<0) then MOutput[k,l]:=0;
end;
end;
end;
Addtion:=MOutput;
end;
No comments:
Post a Comment