Function Addtion2(MInput,MInput2:Matriks ; X,Y:integer):Matriks;
var
i,j,k,l : integer;
MOutput : Matriks;
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;
if ((Length(MOutput)-X)>=Length(MInput2)) and ((Length(MOutput[0])-Y)>=Length(MInput2[0])) then
begin
for k:=0 to Length(MInput2)-1 do
begin
for l:=0 to Length(MInput2[0])-1 do
begin
MOutput[X+k,Y+l]:=MInput[X+k,Y+l] + MInput2[k,l];
if (MOutput[X+k,Y+l]>255) then MOutput[X+k,Y+l]:=255
else if (MOutput[X+k,Y+l]<0) then MOutput[X+k,Y+l]:=0;
end;
end;
end
else if ((Length(MOutput)-X)<Length(MInput2)) and ((Length(MOutput[0])-Y)>=Length(MInput2[0])) then
begin
for k:=0 to (Length(MOutput)-X)-1 do
begin
for l:=0 to Length(MInput2[0])-1 do
begin
MOutput[X+k,Y+l]:=MInput[X+k,Y+l] + MInput2[k,l];
if (MOutput[X+k,Y+l]>255) then MOutput[X+k,Y+l]:=255
else if (MOutput[X+k,Y+l]<0) then MOutput[X+k,Y+l]:=0;
end;
end;
end
else if ((Length(MOutput)-X)>=Length(MInput2)) and ((Length(MOutput[0])-Y)<Length(MInput2[0])) then
begin
for k:=0 to Length(MInput2)-1 do
begin
for l:=0 to ((Length(MOutput[0]))-Y)-1 do
begin
MOutput[X+k,Y+l]:=MInput[X+k,Y+l] + MInput2[k,l];
if (MOutput[X+k,Y+l]>255) then MOutput[X+k,Y+l]:=255
else if (MOutput[X+k,Y+l]<0) then MOutput[X+k,Y+l]:=0;
end;
end;
end
else if ((Length(MOutput)-X)<Length(MInput2)) and ((Length(MOutput[0])-Y)<Length(MInput2[0])) then
begin
for k:=0 to ((Length(MOutput))-X)-1 do
begin
for l:=0 to ((Length(MOutput[0]))-Y)-1 do
begin
MOutput[X+k,Y+l]:=MInput[X+k,Y+l] + MInput2[k,l];
if (MOutput[X+k,Y+l]>255) then MOutput[X+k,Y+l]:=255
else if (MOutput[X+k,Y+l]<0) then MOutput[X+k,Y+l]:=0;
end;
end;
end;
Addtion2:=MOutput;
end;
No comments:
Post a Comment