浏览代码

replace texture of solid color by solid color shape

without texture when converting to vectorial
circular17 6 年之前
父节点
当前提交
2970027aeb
共有 1 个文件被更改,包括 33 次插入19 次删除
  1. 33 19
      lazpaint/image/uimagediff.pas

+ 33 - 19
lazpaint/image/uimagediff.pas

@@ -940,28 +940,35 @@ begin
     temp := (imgState.LayeredBitmap.LayerOriginal[ALayerIndex] as TBGRALayerImageOriginal).GetImageCopy;
     if temp <> nil then
     begin
-      shape := TRectShape.Create(orig);
-      shape.QuickDefine(PointF(-0.5,-0.5),PointF(temp.Width-0.5,temp.Height-0.5));
-      shape.PenStyle := ClearPenStyle;
-      shape.BackFill.SetTexture(temp,AffineMatrixIdentity,255,trNone);
+      if not temp.Empty then
+      begin
+        shape := TRectShape.Create(orig);
+        shape.QuickDefine(PointF(-0.5,-0.5),PointF(temp.Width-0.5,temp.Height-0.5));
+        shape.PenStyle := ClearPenStyle;
+        if temp.Equals(temp.GetPixel(0,0)) then
+          shape.BackFill.SetSolid(temp.GetPixel(0,0))
+          else shape.BackFill.SetTexture(temp,AffineMatrixIdentity,255,trNone);
+        shape.Transform(imgState.LayeredBitmap.LayerOriginalMatrix[ALayerIndex]);
+        with imgState.LayeredBitmap.LayerOffset[ALayerIndex] do
+          shape.Transform(AffineMatrixTranslation(-X-FSourceBounds.Left,-Y-FSourceBounds.Top));
+        orig.AddShape(shape);
+      end;
       temp.FreeReference;
-      shape.Transform(imgState.LayeredBitmap.LayerOriginalMatrix[ALayerIndex]);
-      with imgState.LayeredBitmap.LayerOffset[ALayerIndex] do
-        shape.Transform(AffineMatrixTranslation(-X-FSourceBounds.Left,-Y-FSourceBounds.Top));
-      orig.AddShape(shape);
     end;
   end else
   begin
     source := imgState.LayeredBitmap.LayerBitmap[ALayerIndex];
     if not source.Empty then
     begin
+      temp := source.GetPart(FSourceBounds) as TBGRABitmap;
       shape := TRectShape.Create(orig);
       shape.QuickDefine(PointF(-0.5,-0.5),PointF(FSourceBounds.Width-0.5,FSourceBounds.Height-0.5));
       shape.PenStyle := ClearPenStyle;
-      temp := source.GetPart(FSourceBounds) as TBGRABitmap;
-      shape.BackFill.SetTexture(temp,AffineMatrixIdentity,255,trNone);
-      temp.FreeReference;
+      if temp.Equals(temp.GetPixel(0,0)) then
+        shape.BackFill.SetSolid(temp.GetPixel(0,0))
+        else shape.BackFill.SetTexture(temp,AffineMatrixIdentity,255,trNone);
       orig.AddShape(shape);
+      temp.FreeReference;
     end;
   end;
   result := orig;
@@ -2196,13 +2203,18 @@ var
       temp := (ALayeredBitmap.LayerOriginal[ALayerIndex] as TBGRALayerImageOriginal).GetImageCopy;
       if Assigned(temp) then
       begin
-        s := TRectShape.Create(mergedOriginal);
-        s.PenStyle := ClearPenStyle;
-        s.BackFill.SetTexture(temp, AffineMatrixIdentity, 255, trNone);
+        if not temp.Empty then
+        begin
+          s := TRectShape.Create(mergedOriginal);
+          s.PenStyle := ClearPenStyle;
+          if temp.Equals(temp.GetPixel(0,0)) then
+            s.BackFill.SetSolid(temp.GetPixel(0,0))
+            else s.BackFill.SetTexture(temp, AffineMatrixIdentity, 255, trNone);
+          s.QuickDefine(PointF(-0.5,-0.5), PointF(temp.width-0.5,temp.Height-0.5));
+          s.Transform(m);
+          mergedOriginal.AddShape(s);
+        end;
         temp.FreeReference;
-        s.QuickDefine(PointF(-0.5,-0.5), PointF(temp.width-0.5,temp.Height-0.5));
-        s.Transform(m);
-        mergedOriginal.AddShape(s);
       end;
     end else
     begin
@@ -2214,12 +2226,14 @@ var
           temp := ALayeredBitmap.LayerBitmap[ALayerIndex].GetPart(b) as TBGRABitmap;
           s := TRectShape.Create(mergedOriginal);
           s.PenStyle := ClearPenStyle;
-          s.BackFill.SetTexture(temp, AffineMatrixIdentity, 255, trNone);
-          temp.FreeReference;
+          if temp.Equals(temp.GetPixel(0,0)) then
+            s.BackFill.SetSolid(temp.GetPixel(0,0))
+            else s.BackFill.SetTexture(temp, AffineMatrixIdentity, 255, trNone);
           s.QuickDefine(PointF(-0.5,-0.5), PointF(temp.width-0.5,temp.Height-0.5));
           with ALayeredBitmap.LayerOffset[ALayerIndex] do
             s.Transform(AffineMatrixTranslation(b.Left+X,b.Top+Y));
           mergedOriginal.AddShape(s);
+          temp.FreeReference;
         end;
       end;
     end;