this slowpoke moves

Calculate AntiAliasing on Bitmap

Das Berechnen von Antialiasing auf Bitmap-Grafiken ist nicht identisch mit den Berechnungen auf anderen Grafikformaten.

Hier ein Beispiel, wie sowas berechnet wird.

Es wird benötig : 2xImage, 2xTrackBar, 2xButton
uses ExtDlgs, ExtCtrls, Math, ComCtrls

type
  TRGB = array[1..3] of byte;
  A1DRGB = array[0..5000] of TRGB;
  PA1DRGB = ^A1DRGB;
  A2DRGB = array[0..5000] of PA1DRGB;
  
//

procedure AntiAliasing(X,Result:TBitmap;Zone:Byte;Intensity:Single);
var
  I,J,K:Integer;
  P1,P2:A2DRGB;
  m,dm,s:double;
begin
  if not Assigned(Result) then
    Result:=TBitmap.Create;
    X.PixelFormat:=pf24bit;
    Result.Assign(X);

  for I:=0 to X.Height-2 do
  begin
    P1[I]:=X.ScanLine[I];
    P2[I]:=Result.ScanLine[I];
  end;

  for I:=1 to X.Height-3 do
    for J:=1 to X.Width-3 do
    begin
      for K:=1 to 3 do
      begin
      m  := (P1[I+1,J-1,K] + P1[I,J-1,K] + P1[I-1,J-1,K] +
             P1[I+1,J,K] + P1[I,J,K] + P1[I-1,J,K] +
             P1[I+1,J+1,K] + P1[I,J+1,K] + P1[I-1,J+1,K]) / 9;

      s  := sign(m - P1[I,J,K]);
      dm := abs(m-P1[I,J,K])/255;

        if dm<(Zone/255) then dm:=0;
      P2[I,J,K] := max(0,min(255,P1[I,J,K] + round(s*power(dm,1/Intensity)*m)));
     end;
    end;
end;
Berechnen :
procedure TForm1.Button1Click(Sender: TObject);
begin
  if not OpenPictureDialog1.Execute then
    Exit;

  Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Image1.Picture := Image2.Picture;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  AntiAliasing(Image1.Picture.Bitmap,
               Image2.Picture.Bitmap,
               TrackBar1.Position,
               1+(TrackBar2.Position / 500));
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate