Advertisement
WarPie90

Untitled

Apr 21st, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.22 KB | None | 0 0
  1. procedure TMufasaBitmap.Convolute(TargetBitmap : TMufasaBitmap; Matrix: T2DExtendedArray);
  2. var
  3.   x,y,yy,xx,cx,cy: Integer;
  4.   Row,RowT : TPRGB32Array;
  5.   mW,mH,midx,midy:Integer;
  6.   valR,valG,valB: Extended;
  7.  
  8. procedure ForceInBounds(x,y, Wid,Hig: Int32; out cx,cy: Int32); Inline;
  9. begin
  10.   cx := x;
  11.   cy := y;
  12.   if cx >= Wid then   cx := Wid-1
  13.   else if cx < 0 then cx := 0;
  14.   if cy >= Hig then   cy := Hig-1
  15.   else if cy < 0 then cy := 0;
  16. end;
  17.  
  18. begin
  19.   TargetBitmap.SetSize(Self.W,Self.H);
  20.   Row := RowPtrs;
  21.   RowT := TargetBitmap.RowPtrs; //Target
  22.  
  23.   mW := High(Matrix[0]);
  24.   mH := High(Matrix);
  25.   midx := (mW+1) div 2;
  26.   midy := (mH+1) div 2;
  27.   for y:=0 to Self.H-1 do
  28.     for x:=0 to Self.W-1 do
  29.     begin
  30.       valR := 0;
  31.       valG := 0;
  32.       valB := 0;
  33.       for yy:=0 to mH do
  34.         for xx:=0 to mW do
  35.         begin
  36.           ForceInBounds(x+xx-midx, y+yy-midy, Self.W, Self.H, cx, cy);
  37.           valR := valR + (Matrix[yy][xx] * Row[cy][cx].R);
  38.           valG := valG + (Matrix[yy][xx] * Row[cy][cx].G);
  39.           valB := valB + (Matrix[yy][xx] * Row[cy][cx].B);
  40.         end;
  41.       RowT[y][x].R := round(valR);
  42.       RowT[y][x].G := round(valG);
  43.       RowT[y][x].B := round(valB);;
  44.   end;
  45. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement