Changeset 472 for GraphicTest/Packages/bgrabitmap/bgrapolygon.pas
- Timestamp:
- Apr 9, 2015, 9:58:36 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgrapolygon.pas
r452 r472 5 5 { This unit contains polygon drawing functions and spline functions. 6 6 7 Shapes are drawn using a T FillShapeInfo object, which calculates the7 Shapes are drawn using a TBGRACustomFillInfo object, which calculates the 8 8 intersection of an horizontal line and the polygon. 9 9 10 10 Various shapes are handled : 11 - TFillPolyInfo : polygon 11 - TFillPolyInfo : polygon scanned in any order 12 - TOnePassFillPolyInfo : polygon scanned from top to bottom 12 13 - TFillEllipseInfo : ellipse 13 14 - TFillBorderEllipseInfo : ellipse border … … 34 35 Classes, SysUtils, Graphics, BGRABitmapTypes, BGRAFillInfo; 35 36 36 procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: T FillShapeInfo;37 c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean );38 procedure FillShapeAntialiasWithTexture(bmp: TBGRACustomBitmap; shapeInfo: T FillShapeInfo;39 scan: IBGRAScanner; NonZeroWinding: boolean );40 procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: T FillShapeInfo;37 procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo; 38 c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean = false); 39 procedure FillShapeAntialiasWithTexture(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo; 40 scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean = false); 41 procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo; 41 42 c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode; AliasingIncludeBottomRight: Boolean= false); 42 43 … … 49 50 nbShapes: integer; 50 51 shapes: array of record 51 info: T FillShapeInfo;52 info: TBGRACustomFillInfo; 52 53 internalInfo: boolean; 53 54 texture: IBGRAScanner; … … 56 57 bounds: TRect; 57 58 end; 58 procedure AddShape(AInfo: T FillShapeInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel);59 procedure AddShape(AInfo: TBGRACustomFillInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel); 59 60 function CheckRectangleBorderBounds(var x1, y1, x2, y2: single; w: single): boolean; 60 61 public … … 65 66 constructor Create; 66 67 destructor Destroy; override; 67 procedure AddShape(AShape: T FillShapeInfo; AColor: TBGRAPixel);68 procedure AddShape(AShape: T FillShapeInfo; ATexture: IBGRAScanner);68 procedure AddShape(AShape: TBGRACustomFillInfo; AColor: TBGRAPixel); 69 procedure AddShape(AShape: TBGRACustomFillInfo; ATexture: IBGRAScanner); 69 70 procedure AddPolygon(const points: array of TPointF; AColor: TBGRAPixel); 70 71 procedure AddPolygon(const points: array of TPointF; ATexture: IBGRAScanner); … … 86 87 procedure AddRectangleBorder(x1, y1, x2, y2, w: single; AColor: TBGRAPixel); 87 88 procedure AddRectangleBorder(x1, y1, x2, y2, w: single; ATexture: IBGRAScanner); 88 procedure Draw(dest: TBGRACustomBitmap );89 procedure Draw(dest: TBGRACustomBitmap; ADrawMode: TDrawMode = dmDrawWithTransparency); 89 90 end; 90 91 … … 94 95 scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode); 95 96 procedure FillPolyAntialias(bmp: TBGRACustomBitmap; points: array of TPointF; 96 c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean );97 c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean; LinearBlend: boolean = false); 97 98 procedure FillPolyAntialiasWithTexture(bmp: TBGRACustomBitmap; points: array of TPointF; 98 scan: IBGRAScanner; NonZeroWinding: boolean );99 scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean = false); 99 100 100 101 procedure FillEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry: single; 101 c: TBGRAPixel; EraseMode: boolean );102 c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean = false); 102 103 procedure FillEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx, ry: single; 103 scan: IBGRAScanner );104 scan: IBGRAScanner; LinearBlend: boolean = false); 104 105 105 106 procedure BorderEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry, w: single; 106 c: TBGRAPixel; EraseMode: boolean );107 c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean = false); 107 108 procedure BorderEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx, ry, w: single; 108 scan: IBGRAScanner );109 scan: IBGRAScanner; LinearBlend: boolean = false); 109 110 110 111 procedure 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); 112 113 procedure FillRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry: single; 113 options: TRoundRectangleOptions; scan: IBGRAScanner );114 options: TRoundRectangleOptions; scan: IBGRAScanner; LinearBlend: boolean = false); 114 115 115 116 procedure 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); 117 118 procedure BorderRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry, w: single; 118 options: TRoundRectangleOptions; scan: IBGRAScanner );119 options: TRoundRectangleOptions; scan: IBGRAScanner; LinearBlend: boolean = false); 119 120 120 121 procedure BorderAndFillRoundRectangleAntialias(bmp: TBGRACustomBitmap; x1, y1, x2, y2, rx, ry, w: single; … … 125 126 uses Math, BGRABlend, BGRAGradientScanner, BGRATransform; 126 127 127 procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: T FillShapeInfo;128 c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean );128 procedure FillShapeAntialias(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo; 129 c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean); 129 130 var 130 131 inter: array of TIntersectionInfo; … … 141 142 density: PDensity; 142 143 143 xb, yb, yc, i, j: integer; 144 xb, yb, yc, i: integer; 145 tempDensity: UInt32or64; 144 146 145 147 x1, x2, x1b,x2b: single; … … 170 172 curdens: single; 171 173 pdens: pdensity; 174 newvalue: Int32or64; 172 175 begin 173 176 if (x1 <> x2) and (x1 < maxx + 1) and (x2 >= minx) then … … 188 191 189 192 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 191 199 else 192 200 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; 194 205 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; 196 212 end; 197 213 if ix2 > ix1 + 1 then … … 201 217 for n := ix2-1-(ix1+1) downto 0 do 202 218 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; 204 223 curdens += slope; 205 224 inc(pdens); … … 308 327 end; 309 328 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; 315 346 end; 316 347 … … 336 367 end; 337 368 338 procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: T FillShapeInfo;369 procedure FillShapeAliased(bmp: TBGRACustomBitmap; shapeInfo: TBGRACustomFillInfo; 339 370 c: TBGRAPixel; EraseMode: boolean; scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode; AliasingIncludeBottomRight: Boolean= false); 340 371 var … … 370 401 for i := 0 to nbinter div 2 - 1 do 371 402 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; 374 405 375 406 if x1 <> x2 then … … 413 444 414 445 procedure FillShapeAntialiasWithTexture(bmp: TBGRACustomBitmap; 415 shapeInfo: T FillShapeInfo; scan: IBGRAScanner; NonZeroWinding: boolean);416 begin 417 FillShapeAntialias(bmp,shapeInfo,BGRAPixelTransparent,False,scan,NonZeroWinding );446 shapeInfo: TBGRACustomFillInfo; scan: IBGRAScanner; NonZeroWinding: boolean; LinearBlend: boolean); 447 begin 448 FillShapeAntialias(bmp,shapeInfo,BGRAPixelTransparent,False,scan,NonZeroWinding,LinearBlend); 418 449 end; 419 450 … … 421 452 c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean; drawmode: TDrawMode); 422 453 var 423 info: T FillPolyInfo;454 info: TCustomFillPolyInfo; 424 455 begin 425 456 if length(points) < 3 then 426 457 exit; 427 458 428 info := T FillPolyInfo.Create(points);459 info := TOnePassFillPolyInfo.Create(points); 429 460 FillShapeAliased(bmp, info, c, EraseMode, nil, NonZeroWinding, drawmode); 430 461 info.Free; … … 434 465 points: array of TPointF; scan: IBGRAScanner; NonZeroWinding: boolean; drawmode: TDrawMode); 435 466 var 436 info: T FillPolyInfo;467 info: TCustomFillPolyInfo; 437 468 begin 438 469 if length(points) < 3 then 439 470 exit; 440 471 441 info := T FillPolyInfo.Create(points);472 info := TOnePassFillPolyInfo.Create(points); 442 473 FillShapeAliased(bmp, info, BGRAPixelTransparent,False,scan, NonZeroWinding, drawmode); 443 474 info.Free; … … 445 476 446 477 procedure FillPolyAntialias(bmp: TBGRACustomBitmap; points: array of TPointF; 447 c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean );448 var 449 info: T FillPolyInfo;478 c: TBGRAPixel; EraseMode: boolean; NonZeroWinding: boolean; LinearBlend: boolean); 479 var 480 info: TCustomFillPolyInfo; 450 481 begin 451 482 if length(points) < 3 then 452 483 exit; 453 484 454 info := T FillPolyInfo.Create(points);455 FillShapeAntialias(bmp, info, c, EraseMode, nil, NonZeroWinding );485 info := TOnePassFillPolyInfo.Create(points); 486 FillShapeAntialias(bmp, info, c, EraseMode, nil, NonZeroWinding, LinearBlend); 456 487 info.Free; 457 488 end; 458 489 459 490 procedure 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); 492 var 493 info: TCustomFillPolyInfo; 464 494 begin 465 495 if length(points) < 3 then 466 496 exit; 467 497 468 info := T FillPolyInfo.Create(points);469 FillShapeAntialiasWithTexture(bmp, info, scan, NonZeroWinding );498 info := TOnePassFillPolyInfo.Create(points); 499 FillShapeAntialiasWithTexture(bmp, info, scan, NonZeroWinding, LinearBlend); 470 500 info.Free; 471 501 end; 472 502 473 503 procedure FillEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry: single; 474 c: TBGRAPixel; EraseMode: boolean );504 c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean); 475 505 var 476 506 info: TFillEllipseInfo; … … 480 510 481 511 info := TFillEllipseInfo.Create(x, y, rx, ry); 482 FillShapeAntialias(bmp, info, c, EraseMode, nil, False );512 FillShapeAntialias(bmp, info, c, EraseMode, nil, False, LinearBlend); 483 513 info.Free; 484 514 end; 485 515 486 516 procedure FillEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx, 487 ry: single; scan: IBGRAScanner );517 ry: single; scan: IBGRAScanner; LinearBlend: boolean); 488 518 var 489 519 info: TFillEllipseInfo; … … 493 523 494 524 info := TFillEllipseInfo.Create(x, y, rx, ry); 495 FillShapeAntialiasWithTexture(bmp, info, scan, False );525 FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend); 496 526 info.Free; 497 527 end; 498 528 499 529 procedure BorderEllipseAntialias(bmp: TBGRACustomBitmap; x, y, rx, ry, w: single; 500 c: TBGRAPixel; EraseMode: boolean );530 c: TBGRAPixel; EraseMode: boolean; LinearBlend: boolean); 501 531 var 502 532 info: TFillBorderEllipseInfo; … … 505 535 exit; 506 536 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); 508 538 info.Free; 509 539 end; 510 540 511 541 procedure BorderEllipseAntialiasWithTexture(bmp: TBGRACustomBitmap; x, y, rx, 512 ry, w: single; scan: IBGRAScanner );542 ry, w: single; scan: IBGRAScanner; LinearBlend: boolean); 513 543 var 514 544 info: TFillBorderEllipseInfo; … … 517 547 exit; 518 548 info := TFillBorderEllipseInfo.Create(x, y, rx, ry, w); 519 FillShapeAntialiasWithTexture(bmp, info, scan, False );549 FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend); 520 550 info.Free; 521 551 end; … … 523 553 { TBGRAMultishapeFiller } 524 554 525 procedure TBGRAMultishapeFiller.AddShape(AInfo: T FillShapeInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel);555 procedure TBGRAMultishapeFiller.AddShape(AInfo: TBGRACustomFillInfo; AInternalInfo: boolean; ATexture: IBGRAScanner; AInternalTexture: TObject; AColor: TBGRAPixel); 526 556 begin 527 557 if length(shapes) = nbShapes then … … 580 610 end; 581 611 582 procedure TBGRAMultishapeFiller.AddShape(AShape: T FillShapeInfo; AColor: TBGRAPixel);612 procedure TBGRAMultishapeFiller.AddShape(AShape: TBGRACustomFillInfo; AColor: TBGRAPixel); 583 613 begin 584 614 AddShape(AShape,False,nil,nil,AColor); 585 615 end; 586 616 587 procedure TBGRAMultishapeFiller.AddShape(AShape: T FillShapeInfo;617 procedure TBGRAMultishapeFiller.AddShape(AShape: TBGRACustomFillInfo; 588 618 ATexture: IBGRAScanner); 589 619 begin … … 595 625 begin 596 626 if length(points) <= 2 then exit; 597 AddShape(T FillPolyInfo.Create(points),True,nil,nil,AColor);627 AddShape(TOnePassFillPolyInfo.Create(points),True,nil,nil,AColor); 598 628 end; 599 629 … … 602 632 begin 603 633 if length(points) <= 2 then exit; 604 AddShape(T FillPolyInfo.Create(points),True,ATexture,nil,BGRAPixelTransparent);634 AddShape(TOnePassFillPolyInfo.Create(points),True,ATexture,nil,BGRAPixelTransparent); 605 635 end; 606 636 … … 611 641 begin 612 642 grad := TBGRAGradientTriangleScanner.Create(pt1,pt2,pt3, c1,c2,c3); 613 AddShape(T FillPolyInfo.Create([pt1,pt2,pt3]),True,grad,grad,BGRAPixelTransparent);643 AddShape(TOnePassFillPolyInfo.Create([pt1,pt2,pt3]),True,grad,grad,BGRAPixelTransparent); 614 644 end; 615 645 … … 620 650 begin 621 651 mapping := TBGRATriangleLinearMapping.Create(texture, pt1,pt2,pt3, tex1, tex2, tex3); 622 AddShape(T FillPolyInfo.Create([pt1,pt2,pt3]),True,mapping,mapping,BGRAPixelTransparent);652 AddShape(TOnePassFillPolyInfo.Create([pt1,pt2,pt3]),True,mapping,mapping,BGRAPixelTransparent); 623 653 end; 624 654 … … 657 687 begin 658 688 persp := TBGRAPerspectiveScannerTransform.Create(texture,[tex1,tex2,tex3,tex4],[pt1,pt2,pt3,pt4]); 659 AddShape(T FillPolyInfo.Create([pt1,pt2,pt3,pt4]),True,persp,persp,BGRAPixelTransparent);689 AddShape(TOnePassFillPolyInfo.Create([pt1,pt2,pt3,pt4]),True,persp,persp,BGRAPixelTransparent); 660 690 end; 661 691 … … 745 775 end; 746 776 747 procedure TBGRAMultishapeFiller.Draw(dest: TBGRACustomBitmap );777 procedure TBGRAMultishapeFiller.Draw(dest: TBGRACustomBitmap; ADrawMode: TDrawMode = dmDrawWithTransparency); 748 778 var 749 779 shapeRow: array of record … … 767 797 procedure AddSegment(xa,xb: single); 768 798 var nb: PInteger; 769 prevNb,k: integer;770 799 begin 771 800 nb := @shapeRow[dest].nbinter; 772 801 if length(shapeRow[dest].inter) < nb^+2 then 802 setlength(shapeRow[dest].inter, nb^*2+2); 803 with shapeRow[dest] do 773 804 begin 774 prevNb := length(shapeRow[dest].inter);775 setlength(shapeRow[dest].inter, nb^*2+2);776 for k := prevNb to high(shapeRow[dest].inter) do777 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; 778 809 end; 779 shapeRow[dest].inter[nb^].interX := xa;780 shapeRow[dest].inter[nb^+1].interX := xb;781 810 inc(nb^,2); 782 811 end; … … 813 842 var 814 843 AliasingOfs: TPointF; 844 useAA: boolean; 815 845 816 846 procedure AddOneLineDensity(cury: single); … … 847 877 begin 848 878 //fill density 849 if not Antialiasingthen879 if not useAA then 850 880 begin 851 881 for i := 0 to nbinter div 2 - 1 do … … 895 925 begin 896 926 if nbShapes = 0 then exit; 927 useAA := Antialiasing and (ADrawMode in [dmDrawWithTransparency,dmLinearBlend]); 897 928 if nbShapes = 1 then 898 929 begin 899 if Antialiasingthen900 FillShapeAntialias(dest,shapes[0].info,GammaCompression(shapes[0].color),False,shapes[0].texture,FillMode = fmWinding ) else901 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, 902 933 AliasingIncludeBottomRight); 903 934 exit; … … 963 994 end; 964 995 965 If Antialiasingthen996 If useAA then 966 997 begin 967 998 //precision scan … … 982 1013 FillChar(sums[rowminx-minx],(rowmaxx-rowminx+1)*sizeof(sums[0]),0); 983 1014 984 if Antialiasingthen1015 if useAA then 985 1016 {$define PARAM_ANTIALIASINGFACTOR} 986 1017 {$i multishapeline.inc} … … 991 1022 xb := rowminx; 992 1023 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 1000 1027 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 1009 1031 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; 1013 1052 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); 1018 1055 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 1022 1179 end; 1023 1180 end; … … 1035 1192 1036 1193 procedure 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); 1038 1195 var 1039 1196 info: TFillRoundRectangleInfo; … … 1041 1198 if (x1 = x2) or (y1 = y2) then exit; 1042 1199 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); 1044 1201 info.Free; 1045 1202 end; … … 1047 1204 procedure FillRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1, 1048 1205 y1, x2, y2, rx, ry: single; options: TRoundRectangleOptions; 1049 scan: IBGRAScanner );1206 scan: IBGRAScanner; LinearBlend: boolean); 1050 1207 var 1051 1208 info: TFillRoundRectangleInfo; … … 1053 1210 if (x1 = x2) or (y1 = y2) then exit; 1054 1211 info := TFillRoundRectangleInfo.Create(x1, y1, x2, y2, rx, ry, options); 1055 FillShapeAntialiasWithTexture(bmp, info, scan, False );1212 FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend); 1056 1213 info.Free; 1057 1214 end; … … 1059 1216 procedure BorderRoundRectangleAntialias(bmp: TBGRACustomBitmap; x1, y1, x2, 1060 1217 y2, rx, ry, w: single; options: TRoundRectangleOptions; c: TBGRAPixel; 1061 EraseMode: boolean );1218 EraseMode: boolean; LinearBlend: boolean); 1062 1219 var 1063 1220 info: TFillBorderRoundRectInfo; … … 1065 1222 if (rx = 0) or (ry = 0) or (w=0) then exit; 1066 1223 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); 1068 1225 info.Free; 1069 1226 end; … … 1071 1228 procedure BorderRoundRectangleAntialiasWithTexture(bmp: TBGRACustomBitmap; x1, 1072 1229 y1, x2, y2, rx, ry, w: single; options: TRoundRectangleOptions; 1073 scan: IBGRAScanner );1230 scan: IBGRAScanner; LinearBlend: boolean); 1074 1231 var 1075 1232 info: TFillBorderRoundRectInfo; … … 1077 1234 if (rx = 0) or (ry = 0) or (w=0) then exit; 1078 1235 info := TFillBorderRoundRectInfo.Create(x1, y1, x2,y2, rx, ry, w, options); 1079 FillShapeAntialiasWithTexture(bmp, info, scan, False );1236 FillShapeAntialiasWithTexture(bmp, info, scan, False, LinearBlend); 1080 1237 info.Free; 1081 1238 end; … … 1106 1263 end else 1107 1264 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); 1110 1267 end; 1111 1268 info.Free; 1112 1269 end; 1113 1270 1114 initialization1115 1116 Randomize;1117 1118 1271 end.
Note:
See TracChangeset
for help on using the changeset viewer.