Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TMufasaBitmap.Convolute(TargetBitmap : TMufasaBitmap; Matrix: T2DExtendedArray);
- var
- x,y,yy,xx,cx,cy: Integer;
- Row,RowT : TPRGB32Array;
- mW,mH,midx,midy:Integer;
- valR,valG,valB: Extended;
- procedure ForceInBounds(x,y, Wid,Hig: Int32; out cx,cy: Int32); Inline;
- begin
- cx := x;
- cy := y;
- if cx >= Wid then cx := Wid-1
- else if cx < 0 then cx := 0;
- if cy >= Hig then cy := Hig-1
- else if cy < 0 then cy := 0;
- end;
- begin
- TargetBitmap.SetSize(Self.W,Self.H);
- Row := RowPtrs;
- RowT := TargetBitmap.RowPtrs; //Target
- mW := High(Matrix[0]);
- mH := High(Matrix);
- midx := (mW+1) div 2;
- midy := (mH+1) div 2;
- for y:=0 to Self.H-1 do
- for x:=0 to Self.W-1 do
- begin
- valR := 0;
- valG := 0;
- valB := 0;
- for yy:=0 to mH do
- for xx:=0 to mW do
- begin
- ForceInBounds(x+xx-midx, y+yy-midy, Self.W, Self.H, cx, cy);
- valR := valR + (Matrix[yy][xx] * Row[cy][cx].R);
- valG := valG + (Matrix[yy][xx] * Row[cy][cx].G);
- valB := valB + (Matrix[yy][xx] * Row[cy][cx].B);
- end;
- RowT[y][x].R := round(valR);
- RowT[y][x].G := round(valG);
- RowT[y][x].B := round(valB);;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement