浏览代码

gradient draft optimization

Johann 6 年之前
父节点
当前提交
ae45c30191
共有 1 个文件被更改,包括 21 次插入1 次删除
  1. 21 1
      lazpaint/utoolfloodfill.pas

+ 21 - 1
lazpaint/utoolfloodfill.pas

@@ -26,6 +26,7 @@ type
   TToolGradient = class(TVectorialTool)
   protected
     function CreateShape: TVectorShape; override;
+    procedure DrawCustomShape(ADest: TBGRABitmap; AMatrix: TAffineMatrix; ADraft: boolean); override;
     procedure AssignShapeStyle(AMatrix: TAffineMatrix); override;
     procedure QuickDefineShape(AStart,AEnd: TPointF); override;
     function SlowShape: boolean; override;
@@ -34,7 +35,8 @@ type
 
 implementation
 
-uses ugraph, LazPaintType, BGRAGradientScanner, LCVectorRectShapes;
+uses ugraph, LazPaintType, BGRAGradientScanner, LCVectorRectShapes,
+  math, BGRATransform;
 
 { TToolGradient }
 
@@ -46,6 +48,24 @@ begin
   result.Usermode := vsuEditBackFill;
 end;
 
+procedure TToolGradient.DrawCustomShape(ADest: TBGRABitmap;
+  AMatrix: TAffineMatrix; ADraft: boolean);
+var
+  temp: TBGRABitmap;
+begin
+  if ADraft and (ADest.NbPixels > 384*384) then
+  begin
+    temp := TBGRABitmap.Create(0,0);
+    temp.SetSize(min(384,ADest.Width),min(384,ADest.Height));
+    FShape.BackFill.Gradient.Render(temp,
+      AffineMatrixScale(temp.Width/ADest.Width,
+                        temp.Height/ADest.Height)*AMatrix, ADraft);
+    ADest.StretchPutImage(rect(0,0,ADest.Width,Adest.Height),temp,dmSet);
+    temp.Free;
+  end else
+    FShape.BackFill.Gradient.Render(ADest,AMatrix,ADraft);
+end;
+
 procedure TToolGradient.AssignShapeStyle(AMatrix: TAffineMatrix);
 begin
   with FShape.BackFill.Gradient do