Ignore:
Timestamp:
Apr 9, 2015, 9:58:36 PM (9 years ago)
Author:
chronos
Message:
  • Fixed: Use csOpaque control style also to Image, PaintBox and OpenGLControl.
  • Modified: Change size of test frame with SpinEdits as delayed using timer.
  • Updated: BRGABitmap package to version 8.1.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgrapolygon.pas

    r452 r472  
    55{ This unit contains polygon drawing functions and spline functions.
    66
    7   Shapes are drawn using a TFillShapeInfo object, which calculates the
     7  Shapes are drawn using a TBGRACustomFillInfo object, which calculates the
    88  intersection of an horizontal line and the polygon.
    99
    1010  Various shapes are handled :
    11   - TFillPolyInfo : polygon
     11  - TFillPolyInfo : polygon scanned in any order
     12  - TOnePassFillPolyInfo : polygon scanned from top to bottom
    1213  - TFillEllipseInfo : ellipse
    1314  - TFillBorderEllipseInfo : ellipse border
     
    3435  Classes, SysUtils, Graphics, BGRABitmapTypes, BGRAFillInfo;
    3536
    36 procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: TFillShapeInfo;
    37   c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean);
    38 procedure FillShapeAntialiasWithTexture(bmp: TBGRACustomBitmap; shapeInfo: TFillShapeInfo;
    39   scan: IBGRAScanner; NonZeroWinding: boolean);
    40 procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: TFillShapeInfo;
     37procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo;
     38  c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean = false);
     39procedure FillShapeAntialiasWithTexture(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo;
     40  scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean = false);
     41procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo;
    4142  c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode; AliasingIncludeBottomRight: Boolean= false);
    4243
     
    4950    nbShapes: integer;
    5051    shapes: array of record
    51         info: TFillShapeInfo;
     52        info: TBGRACustomFillInfo;
    5253        internalInfo: boolean;
    5354        texture: IBGRAScanner;
     
    5657        bounds: TRect;
    5758      end;
    58     procedure AddShape(AInfo: TFillShapeInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel);
     59    procedure AddShape(AInfo: TBGRACustomFillInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel);
    5960    function CheckRectangleBorderBounds(var x1, y1, x2, y2: single; w: single): boolean;
    6061  public
     
    6566    constructor Create;
    6667    destructor Destroy; override;
    67     procedure AddShape(AShape: TFillShapeInfo; AColor: TBGRAPixel);
    68     procedure AddShape(AShape: TFillShapeInfo; ATexture: IBGRAScanner);
     68    procedure AddShape(AShape: TBGRACustomFillInfo; AColor: TBGRAPixel);
     69    procedure AddShape(AShape: TBGRACustomFillInfo; ATexture: IBGRAScanner);
    6970    procedure AddPolygon(const points: array of TPointF; AColor: TBGRAPixel);
    7071    procedure AddPolygon(const points: array of TPointF; ATexture: IBGRAScanner);
     
    8687    procedure AddRectangleBorder(x1, y1, x2, y2, w: single; AColor: TBGRAPixel);
    8788    procedure AddRectangleBorder(x1, y1, x2, y2, w: single; ATexture: IBGRAScanner);
    88     procedure Draw(dest: TBGRACustomBitmap);
     89    procedure Draw(dest: TBGRACustomBitmap; ADrawMode: TDrawMode = dmDrawWithTransparency);
    8990  end;
    9091
     
    9495  scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode);
    9596procedure FillPolyAntialias(bmp: TBGRACustomBitmap; points: array of TPointF;
    96   c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean);
     97  c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean; LinearBlend: boolean = false);
    9798procedure FillPolyAntialiasWithTexture(bmp: TBGRACustomBitmap; points: array of TPointF;
    98   scan: IBGRAScanner; NonZeroWinding: boolean);
     99  scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean = false);
    99100
    100101procedure FillEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry: single;
    101   c: TBGRAPixel; EraseMode: boolean);
     102  c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean = false);
    102103procedure FillEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx, ry: single;
    103   scan: IBGRAScanner);
     104  scan: IBGRAScanner; LinearBlend: boolean = false);
    104105
    105106procedure BorderEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry, w: single;
    106   c: TBGRAPixel; EraseMode: boolean);
     107  c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean = false);
    107108procedure BorderEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx, ry, w: single;
    108   scan: IBGRAScanner);
     109  scan: IBGRAScanner; LinearBlend: boolean = false);
    109110
    110111procedure FillRoundRectangleAntialias(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry: single;
    111   options: TRoundRectangleOptions; c: TBGRAPixel; EraseMode: boolean);
     112  options: TRoundRectangleOptions; c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean = false);
    112113procedure FillRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry: single;
    113   options: TRoundRectangleOptions; scan: IBGRAScanner);
     114  options: TRoundRectangleOptions; scan: IBGRAScanner; LinearBlend: boolean = false);
    114115
    115116procedure BorderRoundRectangleAntialias(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry, w: single;
    116   options: TRoundRectangleOptions; c: TBGRAPixel; EraseMode: boolean);
     117  options: TRoundRectangleOptions; c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean = false);
    117118procedure BorderRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry, w: single;
    118   options: TRoundRectangleOptions; scan: IBGRAScanner);
     119  options: TRoundRectangleOptions; scan: IBGRAScanner; LinearBlend: boolean = false);
    119120
    120121procedure BorderAndFillRoundRectangleAntialias(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry, w: single;
     
    125126uses Math, BGRABlend, BGRAGradientScanner, BGRATransform;
    126127
    127 procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: TFillShapeInfo;
    128   c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean);
     128procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo;
     129  c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean);
    129130var
    130131  inter:   array of TIntersectionInfo;
     
    141142  density: PDensity;
    142143
    143   xb, yb, yc, i, j: integer;
     144  xb, yb, yc, i: integer;
     145  tempDensity: UInt32or64;
    144146
    145147  x1, x2, x1b,x2b: single;
     
    170172      curdens: single;
    171173      pdens: pdensity;
     174      newvalue: Int32or64;
    172175  begin
    173176    if (x1 <> x2) and (x1 < maxx + 1) and (x2 >= minx) then
     
    188191
    189192      if ix1 = ix2 then
    190         (density + (ix1 - minx))^ -= round((x2 - x1)*(density1+density2)/2)
     193      begin
     194        newValue := (density + (ix1 - minx))^ - round((x2 - x1)*(density1+density2)/2);
     195        if newValue < 0 then newValue := 0;
     196        if newValue > 256 then newValue := 256;
     197        (density + (ix1 - minx))^ := newValue
     198      end
    191199      else
    192200      begin
    193         (density + (ix1 - minx))^ := max(0, (density + (ix1 - minx))^ - round((1 - (x1 - ix1))*(density1+densityAt(ix1+1))/2) );
     201        newValue := (density + (ix1 - minx))^ - round((1 - (x1 - ix1))*(density1+densityAt(ix1+1))/2) ;
     202        if newValue < 0 then newValue := 0;
     203        if newValue > 256 then newValue := 256;
     204        (density + (ix1 - minx))^ := newValue;
    194205        if (ix2 <= maxx) then
    195           (density + (ix2 - minx))^ := max(0, (density + (ix2 - minx))^ - round((x2 - ix2)*(density2+densityAt(ix2))/2) );
     206        begin
     207          newValue := (density + (ix2 - minx))^ - round((x2 - ix2)*(density2+densityAt(ix2))/2);
     208          if newValue < 0 then newValue := 0;
     209          if newValue > 256 then newValue := 256;
     210          (density + (ix2 - minx))^ := newValue;
     211        end;
    196212      end;
    197213      if ix2 > ix1 + 1 then
     
    201217        for n := ix2-1-(ix1+1) downto 0 do
    202218        begin
    203           pdens^ -= round(curdens);
     219          newValue := pdens^ - round(curdens);
     220          if newValue < 0 then newValue := 0;
     221          if newValue > 256 then newValue := 256;
     222          pdens^ := newValue;
    204223          curdens += slope;
    205224          inc(pdens);
     
    308327    end;
    309328
    310     if optimised then
    311       {$i renderdensity256.inc}
    312     else
    313       {$define PARAM_ANTIALIASINGFACTOR}
    314       {$i renderdensity256.inc}
     329    if LinearBlend then
     330    begin
     331      if optimised then
     332        {$define PARAM_LINEARANTIALIASING}
     333        {$i renderdensity256.inc}
     334      else
     335        {$define PARAM_LINEARANTIALIASING}
     336        {$define PARAM_ANTIALIASINGFACTOR}
     337        {$i renderdensity256.inc}
     338    end else
     339    begin
     340      if optimised then
     341        {$i renderdensity256.inc}
     342      else
     343        {$define PARAM_ANTIALIASINGFACTOR}
     344        {$i renderdensity256.inc}
     345    end;
    315346  end;
    316347
     
    336367end;
    337368
    338 procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: TFillShapeInfo;
     369procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo;
    339370  c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode; AliasingIncludeBottomRight: Boolean= false);
    340371var
     
    370401    for i := 0 to nbinter div 2 - 1 do
    371402    begin
    372       x1 := inter[i + i].interX-AliasingOfs.X;
    373       x2 := inter[i + i+ 1].interX-AliasingOfs.X;
     403      x1 := inter[i + i].interX+AliasingOfs.X;
     404      x2 := inter[i + i+ 1].interX+AliasingOfs.X;
    374405
    375406      if x1 <> x2 then
     
    413444
    414445procedure FillShapeAntialiasWithTexture(bmp: TBGRACustomBitmap;
    415   shapeInfo: TFillShapeInfo; scan: IBGRAScanner; NonZeroWinding: boolean);
    416 begin
    417   FillShapeAntialias(bmp,shapeInfo,BGRAPixelTransparent,False,scan,NonZeroWinding);
     446  shapeInfo: TBGRACustomFillInfo; scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean);
     447begin
     448  FillShapeAntialias(bmp,shapeInfo,BGRAPixelTransparent,False,scan,NonZeroWinding,LinearBlend);
    418449end;
    419450
     
    421452  c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean; drawmode: TDrawMode);
    422453var
    423   info: TFillPolyInfo;
     454  info: TCustomFillPolyInfo;
    424455begin
    425456  if length(points) < 3 then
    426457    exit;
    427458
    428   info := TFillPolyInfo.Create(points);
     459  info := TOnePassFillPolyInfo.Create(points);
    429460  FillShapeAliased(bmp, info, c, EraseMode, nil, NonZeroWinding, drawmode);
    430461  info.Free;
     
    434465  points: array of TPointF; scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode);
    435466var
    436   info: TFillPolyInfo;
     467  info: TCustomFillPolyInfo;
    437468begin
    438469  if length(points) < 3 then
    439470    exit;
    440471
    441   info := TFillPolyInfo.Create(points);
     472  info := TOnePassFillPolyInfo.Create(points);
    442473  FillShapeAliased(bmp, info, BGRAPixelTransparent,False,scan, NonZeroWinding, drawmode);
    443474  info.Free;
     
    445476
    446477procedure FillPolyAntialias(bmp: TBGRACustomBitmap; points: array of TPointF;
    447   c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean);
    448 var
    449   info: TFillPolyInfo;
     478  c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean; LinearBlend: boolean);
     479var
     480  info: TCustomFillPolyInfo;
    450481begin
    451482  if length(points) < 3 then
    452483    exit;
    453484
    454   info := TFillPolyInfo.Create(points);
    455   FillShapeAntialias(bmp, info, c, EraseMode, nil, NonZeroWinding);
     485  info := TOnePassFillPolyInfo.Create(points);
     486  FillShapeAntialias(bmp, info, c, EraseMode, nil, NonZeroWinding, LinearBlend);
    456487  info.Free;
    457488end;
    458489
    459490procedure FillPolyAntialiasWithTexture(bmp: TBGRACustomBitmap;
    460   points: array of TPointF; scan: IBGRAScanner; NonZeroWinding: boolean
    461   );
    462 var
    463   info: TFillPolyInfo;
     491  points: array of TPointF; scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean);
     492var
     493  info: TCustomFillPolyInfo;
    464494begin
    465495  if length(points) < 3 then
    466496    exit;
    467497
    468   info := TFillPolyInfo.Create(points);
    469   FillShapeAntialiasWithTexture(bmp, info, scan, NonZeroWinding);
     498  info := TOnePassFillPolyInfo.Create(points);
     499  FillShapeAntialiasWithTexture(bmp, info, scan, NonZeroWinding, LinearBlend);
    470500  info.Free;
    471501end;
    472502
    473503procedure FillEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry: single;
    474   c: TBGRAPixel; EraseMode: boolean);
     504  c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean);
    475505var
    476506  info: TFillEllipseInfo;
     
    480510
    481511  info := TFillEllipseInfo.Create(x, y, rx, ry);
    482   FillShapeAntialias(bmp, info, c, EraseMode, nil, False);
     512  FillShapeAntialias(bmp, info, c, EraseMode, nil, False, LinearBlend);
    483513  info.Free;
    484514end;
    485515
    486516procedure FillEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx,
    487   ry: single; scan: IBGRAScanner);
     517  ry: single; scan: IBGRAScanner; LinearBlend: boolean);
    488518var
    489519  info: TFillEllipseInfo;
     
    493523
    494524  info := TFillEllipseInfo.Create(x, y, rx, ry);
    495   FillShapeAntialiasWithTexture(bmp, info, scan, False);
     525  FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend);
    496526  info.Free;
    497527end;
    498528
    499529procedure BorderEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry, w: single;
    500   c: TBGRAPixel; EraseMode: boolean);
     530  c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean);
    501531var
    502532  info: TFillBorderEllipseInfo;
     
    505535    exit;
    506536  info := TFillBorderEllipseInfo.Create(x, y, rx, ry, w);
    507   FillShapeAntialias(bmp, info, c, EraseMode, nil, False);
     537  FillShapeAntialias(bmp, info, c, EraseMode, nil, False, LinearBlend);
    508538  info.Free;
    509539end;
    510540
    511541procedure BorderEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx,
    512   ry, w: single; scan: IBGRAScanner);
     542  ry, w: single; scan: IBGRAScanner; LinearBlend: boolean);
    513543var
    514544  info: TFillBorderEllipseInfo;
     
    517547    exit;
    518548  info := TFillBorderEllipseInfo.Create(x, y, rx, ry, w);
    519   FillShapeAntialiasWithTexture(bmp, info, scan, False);
     549  FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend);
    520550  info.Free;
    521551end;
     
    523553{ TBGRAMultishapeFiller }
    524554
    525 procedure TBGRAMultishapeFiller.AddShape(AInfo: TFillShapeInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel);
     555procedure TBGRAMultishapeFiller.AddShape(AInfo: TBGRACustomFillInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel);
    526556begin
    527557  if length(shapes) = nbShapes then
     
    580610end;
    581611
    582 procedure TBGRAMultishapeFiller.AddShape(AShape: TFillShapeInfo; AColor: TBGRAPixel);
     612procedure TBGRAMultishapeFiller.AddShape(AShape: TBGRACustomFillInfo; AColor: TBGRAPixel);
    583613begin
    584614  AddShape(AShape,False,nil,nil,AColor);
    585615end;
    586616
    587 procedure TBGRAMultishapeFiller.AddShape(AShape: TFillShapeInfo;
     617procedure TBGRAMultishapeFiller.AddShape(AShape: TBGRACustomFillInfo;
    588618  ATexture: IBGRAScanner);
    589619begin
     
    595625begin
    596626  if length(points) <= 2 then exit;
    597   AddShape(TFillPolyInfo.Create(points),True,nil,nil,AColor);
     627  AddShape(TOnePassFillPolyInfo.Create(points),True,nil,nil,AColor);
    598628end;
    599629
     
    602632begin
    603633  if length(points) <= 2 then exit;
    604   AddShape(TFillPolyInfo.Create(points),True,ATexture,nil,BGRAPixelTransparent);
     634  AddShape(TOnePassFillPolyInfo.Create(points),True,ATexture,nil,BGRAPixelTransparent);
    605635end;
    606636
     
    611641begin
    612642  grad := TBGRAGradientTriangleScanner.Create(pt1,pt2,pt3, c1,c2,c3);
    613   AddShape(TFillPolyInfo.Create([pt1,pt2,pt3]),True,grad,grad,BGRAPixelTransparent);
     643  AddShape(TOnePassFillPolyInfo.Create([pt1,pt2,pt3]),True,grad,grad,BGRAPixelTransparent);
    614644end;
    615645
     
    620650begin
    621651  mapping := TBGRATriangleLinearMapping.Create(texture, pt1,pt2,pt3, tex1, tex2, tex3);
    622   AddShape(TFillPolyInfo.Create([pt1,pt2,pt3]),True,mapping,mapping,BGRAPixelTransparent);
     652  AddShape(TOnePassFillPolyInfo.Create([pt1,pt2,pt3]),True,mapping,mapping,BGRAPixelTransparent);
    623653end;
    624654
     
    657687begin
    658688  persp := TBGRAPerspectiveScannerTransform.Create(texture,[tex1,tex2,tex3,tex4],[pt1,pt2,pt3,pt4]);
    659   AddShape(TFillPolyInfo.Create([pt1,pt2,pt3,pt4]),True,persp,persp,BGRAPixelTransparent);
     689  AddShape(TOnePassFillPolyInfo.Create([pt1,pt2,pt3,pt4]),True,persp,persp,BGRAPixelTransparent);
    660690end;
    661691
     
    745775end;
    746776
    747 procedure TBGRAMultishapeFiller.Draw(dest: TBGRACustomBitmap);
     777procedure TBGRAMultishapeFiller.Draw(dest: TBGRACustomBitmap; ADrawMode: TDrawMode = dmDrawWithTransparency);
    748778var
    749779  shapeRow: array of record
     
    767797      procedure AddSegment(xa,xb: single);
    768798      var nb: PInteger;
    769           prevNb,k: integer;
    770799      begin
    771800        nb := @shapeRow[dest].nbinter;
    772801        if length(shapeRow[dest].inter) < nb^+2 then
     802          setlength(shapeRow[dest].inter, nb^*2+2);
     803        with shapeRow[dest] do
    773804        begin
    774           prevNb := length(shapeRow[dest].inter);
    775           setlength(shapeRow[dest].inter, nb^*2+2);
    776           for k := prevNb to high(shapeRow[dest].inter) do
    777             shapeRow[dest].inter[k] := shapes[dest].info.CreateIntersectionInfo;
     805          if inter[nb^] = nil then inter[nb^] := shapes[dest].info.CreateIntersectionInfo;
     806          inter[nb^].interX := xa;
     807          if inter[nb^+1] = nil then inter[nb^+1] := shapes[dest].info.CreateIntersectionInfo;
     808          inter[nb^+1].interX := xb;
    778809        end;
    779         shapeRow[dest].inter[nb^].interX := xa;
    780         shapeRow[dest].inter[nb^+1].interX := xb;
    781810        inc(nb^,2);
    782811      end;
     
    813842var
    814843    AliasingOfs: TPointF;
     844    useAA: boolean;
    815845
    816846  procedure AddOneLineDensity(cury: single);
     
    847877      begin
    848878        //fill density
    849         if not Antialiasing then
     879        if not useAA then
    850880        begin
    851881          for i := 0 to nbinter div 2 - 1 do
     
    895925begin
    896926  if nbShapes = 0 then exit;
     927  useAA := Antialiasing and (ADrawMode in [dmDrawWithTransparency,dmLinearBlend]);
    897928  if nbShapes = 1 then
    898929  begin
    899     if Antialiasing then
    900       FillShapeAntialias(dest,shapes[0].info,GammaCompression(shapes[0].color),False,shapes[0].texture,FillMode = fmWinding) else
    901       FillShapeAliased(dest,shapes[0].info,GammaCompression(shapes[0].color),False,shapes[0].texture,FillMode = fmWinding, dmDrawWithTransparency,
     930    if useAA then
     931      FillShapeAntialias(dest,shapes[0].info,GammaCompression(shapes[0].color),False,shapes[0].texture,FillMode = fmWinding, ADrawMode=dmLinearBlend) else
     932      FillShapeAliased(dest,shapes[0].info,GammaCompression(shapes[0].color),False,shapes[0].texture,FillMode = fmWinding, ADrawMode,
    902933        AliasingIncludeBottomRight);
    903934    exit;
     
    963994    end;
    964995
    965     If Antialiasing then
     996    If useAA then
    966997    begin
    967998      //precision scan
     
    9821013      FillChar(sums[rowminx-minx],(rowmaxx-rowminx+1)*sizeof(sums[0]),0);
    9831014
    984       if Antialiasing then
     1015      if useAA then
    9851016        {$define PARAM_ANTIALIASINGFACTOR}
    9861017        {$i multishapeline.inc}
     
    9911022      xb := rowminx;
    9921023      nextSum := @sums[xb-minx];
    993       while xb <= rowmaxx do
    994       begin
    995         curSum := nextSum;
    996         inc(nextSum);
    997         with curSum^ do
    998         begin
    999           if sumA <> 0 then
     1024      case ADrawMode of
     1025        dmDrawWithTransparency:
     1026          while xb <= rowmaxx do
    10001027          begin
    1001             ec.red := (sumR+sumA shr 1) div sumA;
    1002             ec.green := (sumG+sumA shr 1) div sumA;
    1003             ec.blue := (sumB+sumA shr 1) div sumA;
    1004             if sumA > 255 then sumA := 255;
    1005             ec.alpha := sumA shl 8 + sumA;
    1006             count := 1;
    1007             while (xb < rowmaxx) and (nextSum^.sumA = sumA) and (nextSum^.sumB = sumB)
    1008               and (nextSum^.sumG = sumG) and (nextSum^.sumR = sumR) do
     1028            curSum := nextSum;
     1029            inc(nextSum);
     1030            with curSum^ do
    10091031            begin
    1010               inc(xb);
    1011               inc(nextSum);
    1012               inc(count);
     1032              if sumA <> 0 then
     1033              begin
     1034                ec.red := (sumR+sumA shr 1) div sumA;
     1035                ec.green := (sumG+sumA shr 1) div sumA;
     1036                ec.blue := (sumB+sumA shr 1) div sumA;
     1037                if sumA > 255 then sumA := 255;
     1038                ec.alpha := sumA shl 8 + sumA;
     1039                count := 1;
     1040                while (xb < rowmaxx) and (nextSum^.sumA = sumA) and (nextSum^.sumB = sumB)
     1041                  and (nextSum^.sumG = sumG) and (nextSum^.sumR = sumR) do
     1042                begin
     1043                  inc(xb);
     1044                  inc(nextSum);
     1045                  inc(count);
     1046                end;
     1047                if count = 1 then
     1048                  DrawExpandedPixelInlineNoAlphaCheck(pdest,ec,sumA) else
     1049                   DrawExpandedPixelsInline(pdest, ec, count );
     1050                inc(pdest,count-1);
     1051              end;
    10131052            end;
    1014             if count = 1 then
    1015               DrawExpandedPixelInlineWithAlphaCheck(pdest,ec) else
    1016                DrawExpandedPixelsInline(pdest, ec, count );
    1017             inc(pdest,count-1);
     1053            inc(xb);
     1054            inc(pdest);
    10181055          end;
    1019         end;
    1020         inc(xb);
    1021         inc(pdest);
     1056
     1057        dmLinearBlend:
     1058          while xb <= rowmaxx do
     1059          begin
     1060            curSum := nextSum;
     1061            inc(nextSum);
     1062            with curSum^ do
     1063            begin
     1064              if sumA <> 0 then
     1065              begin
     1066                ec.red := (sumR+sumA shr 1) div sumA;
     1067                ec.green := (sumG+sumA shr 1) div sumA;
     1068                ec.blue := (sumB+sumA shr 1) div sumA;
     1069                if sumA > 255 then sumA := 255;
     1070                ec.alpha := sumA shl 8 + sumA;
     1071                count := 1;
     1072                while (xb < rowmaxx) and (nextSum^.sumA = sumA) and (nextSum^.sumB = sumB)
     1073                  and (nextSum^.sumG = sumG) and (nextSum^.sumR = sumR) do
     1074                begin
     1075                  inc(xb);
     1076                  inc(nextSum);
     1077                  inc(count);
     1078                end;
     1079                if count = 1 then
     1080                  DrawPixelInlineNoAlphaCheck(pdest,GammaCompression(ec)) else
     1081                   DrawPixelsInline(pdest, GammaCompression(ec), count );
     1082                inc(pdest,count-1);
     1083              end;
     1084            end;
     1085            inc(xb);
     1086            inc(pdest);
     1087          end;
     1088
     1089        dmXor:
     1090          while xb <= rowmaxx do
     1091          begin
     1092            curSum := nextSum;
     1093            inc(nextSum);
     1094            with curSum^ do
     1095            begin
     1096              if sumA <> 0 then
     1097              begin
     1098                ec.red := (sumR+sumA shr 1) div sumA;
     1099                ec.green := (sumG+sumA shr 1) div sumA;
     1100                ec.blue := (sumB+sumA shr 1) div sumA;
     1101                if sumA > 255 then sumA := 255;
     1102                ec.alpha := sumA shl 8 + sumA;
     1103                count := 1;
     1104                while (xb < rowmaxx) and (nextSum^.sumA = sumA) and (nextSum^.sumB = sumB)
     1105                  and (nextSum^.sumG = sumG) and (nextSum^.sumR = sumR) do
     1106                begin
     1107                  inc(xb);
     1108                  inc(nextSum);
     1109                  inc(count);
     1110                end;
     1111                XorInline(pdest,GammaCompression(ec),count);
     1112                inc(pdest,count-1);
     1113              end;
     1114            end;
     1115            inc(xb);
     1116            inc(pdest);
     1117          end;
     1118
     1119        dmSet:
     1120          while xb <= rowmaxx do
     1121          begin
     1122            curSum := nextSum;
     1123            inc(nextSum);
     1124            with curSum^ do
     1125            begin
     1126              if sumA <> 0 then
     1127              begin
     1128                ec.red := (sumR+sumA shr 1) div sumA;
     1129                ec.green := (sumG+sumA shr 1) div sumA;
     1130                ec.blue := (sumB+sumA shr 1) div sumA;
     1131                if sumA > 255 then sumA := 255;
     1132                ec.alpha := sumA shl 8 + sumA;
     1133                count := 1;
     1134                while (xb < rowmaxx) and (nextSum^.sumA = sumA) and (nextSum^.sumB = sumB)
     1135                  and (nextSum^.sumG = sumG) and (nextSum^.sumR = sumR) do
     1136                begin
     1137                  inc(xb);
     1138                  inc(nextSum);
     1139                  inc(count);
     1140                end;
     1141                FillInline(pdest,GammaCompression(ec),count);
     1142                inc(pdest,count-1);
     1143              end;
     1144            end;
     1145            inc(xb);
     1146            inc(pdest);
     1147          end;
     1148
     1149        dmSetExceptTransparent:
     1150          while xb <= rowmaxx do
     1151          begin
     1152            curSum := nextSum;
     1153            inc(nextSum);
     1154            with curSum^ do
     1155            begin
     1156              if sumA >= 255 then
     1157              begin
     1158                ec.red := (sumR+sumA shr 1) div sumA;
     1159                ec.green := (sumG+sumA shr 1) div sumA;
     1160                ec.blue := (sumB+sumA shr 1) div sumA;
     1161                if sumA > 255 then sumA := 255;
     1162                ec.alpha := sumA shl 8 + sumA;
     1163                count := 1;
     1164                while (xb < rowmaxx) and (nextSum^.sumA = sumA) and (nextSum^.sumB = sumB)
     1165                  and (nextSum^.sumG = sumG) and (nextSum^.sumR = sumR) do
     1166                begin
     1167                  inc(xb);
     1168                  inc(nextSum);
     1169                  inc(count);
     1170                end;
     1171                FillInline(pdest,GammaCompression(ec),count);
     1172                inc(pdest,count-1);
     1173              end;
     1174            end;
     1175            inc(xb);
     1176            inc(pdest);
     1177          end;
     1178
    10221179      end;
    10231180    end;
     
    10351192
    10361193procedure FillRoundRectangleAntialias(bmp: TBGRACustomBitmap; x1, y1, x2, y2,
    1037   rx, ry: single; options: TRoundRectangleOptions; c: TBGRAPixel; EraseMode: boolean);
     1194  rx, ry: single; options: TRoundRectangleOptions; c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean);
    10381195var
    10391196  info: TFillRoundRectangleInfo;
     
    10411198  if (x1 = x2) or (y1 = y2) then exit;
    10421199  info := TFillRoundRectangleInfo.Create(x1, y1, x2, y2, rx, ry, options);
    1043   FillShapeAntialias(bmp, info, c, EraseMode,nil, False);
     1200  FillShapeAntialias(bmp, info, c, EraseMode,nil, False, LinearBlend);
    10441201  info.Free;
    10451202end;
     
    10471204procedure FillRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1,
    10481205  y1, x2, y2, rx, ry: single; options: TRoundRectangleOptions;
    1049   scan: IBGRAScanner);
     1206  scan: IBGRAScanner; LinearBlend: boolean);
    10501207var
    10511208  info: TFillRoundRectangleInfo;
     
    10531210  if (x1 = x2) or (y1 = y2) then exit;
    10541211  info := TFillRoundRectangleInfo.Create(x1, y1, x2, y2, rx, ry, options);
    1055   FillShapeAntialiasWithTexture(bmp, info, scan, False);
     1212  FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend);
    10561213  info.Free;
    10571214end;
     
    10591216procedure BorderRoundRectangleAntialias(bmp: TBGRACustomBitmap; x1, y1, x2,
    10601217  y2, rx, ry, w: single; options: TRoundRectangleOptions; c: TBGRAPixel;
    1061   EraseMode: boolean);
     1218  EraseMode: boolean; LinearBlend: boolean);
    10621219var
    10631220  info: TFillBorderRoundRectInfo;
     
    10651222  if (rx = 0) or (ry = 0) or (w=0) then exit;
    10661223  info := TFillBorderRoundRectInfo.Create(x1, y1, x2,y2, rx, ry, w, options);
    1067   FillShapeAntialias(bmp, info, c, EraseMode, nil, False);
     1224  FillShapeAntialias(bmp, info, c, EraseMode, nil, False, LinearBlend);
    10681225  info.Free;
    10691226end;
     
    10711228procedure BorderRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1,
    10721229  y1, x2, y2, rx, ry, w: single; options: TRoundRectangleOptions;
    1073   scan: IBGRAScanner);
     1230  scan: IBGRAScanner; LinearBlend: boolean);
    10741231var
    10751232  info: TFillBorderRoundRectInfo;
     
    10771234  if (rx = 0) or (ry = 0) or (w=0) then exit;
    10781235  info := TFillBorderRoundRectInfo.Create(x1, y1, x2,y2, rx, ry, w, options);
    1079   FillShapeAntialiasWithTexture(bmp, info, scan, False);
     1236  FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend);
    10801237  info.Free;
    10811238end;
     
    11061263  end else
    11071264  begin
    1108     FillShapeAntialias(bmp, info.innerBorder, fillcolor, EraseMode, nil, False);
    1109     FillShapeAntialias(bmp, info, bordercolor, EraseMode, nil, False);
     1265    FillShapeAntialias(bmp, info.innerBorder, fillcolor, EraseMode, nil, False, False);
     1266    FillShapeAntialias(bmp, info, bordercolor, EraseMode, nil, False, False);
    11101267  end;
    11111268  info.Free;
    11121269end;
    11131270
    1114 initialization
    1115 
    1116   Randomize;
    1117 
    11181271end.
Note: See TracChangeset for help on using the changeset viewer.