فهرست منبع

Removed passing ChunkyImage

Krzysztof Krysiński 2 سال پیش
والد
کامیت
d19da51429

+ 2 - 2
src/ChunkyImageLib/ChunkyImage.cs

@@ -612,7 +612,7 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable
         lock (lockObject)
         {
             ThrowIfDisposed();
-            PixelOperation operation = new(pos, pixelProcessor, blendMode);
+            PixelOperation operation = new(pos, pixelProcessor, GetCommittedPixel, blendMode);
             EnqueueOperation(operation);
         }
     }
@@ -1089,7 +1089,7 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable
         affectedAreaSize = affectedAreaSize * scale;
         targetChunk.Surface.DrawingSurface.Canvas.ClipRect(new RectD(affectedAreaPos, affectedAreaSize));
 
-        operation.DrawOnChunk(targetChunk, chunkPos, this);
+        operation.DrawOnChunk(targetChunk, chunkPos);
         targetChunk.Surface.DrawingSurface.Canvas.RestoreToCount(count);
     }
 

+ 1 - 1
src/ChunkyImageLib/Operations/ApplyMaskOperation.cs

@@ -22,7 +22,7 @@ internal class ApplyMaskOperation : IDrawOperation
         return new AffectedArea(mask.FindCommittedChunks());
     }
     
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         mask.DrawCommittedChunkOn(chunkPos, targetChunk.Resolution, targetChunk.Surface.DrawingSurface, VecI.Zero, clippingPaint);
     }

+ 1 - 1
src/ChunkyImageLib/Operations/BresenhamLineOperation.cs

@@ -25,7 +25,7 @@ internal class BresenhamLineOperation : IMirroredDrawOperation
         points = BresenhamLineHelper.GetBresenhamLine(from, to);
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         // a hacky way to make the lines look slightly better on non full res chunks
         paint.Color = new Color(color.R, color.G, color.B, (byte)(color.A * targetChunk.Resolution.Multiplier()));

+ 1 - 1
src/ChunkyImageLib/Operations/ChunkyImageOperation.cs

@@ -19,7 +19,7 @@ internal class ChunkyImageOperation : IMirroredDrawOperation
         this.mirrorVertical = mirrorVertical;
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         targetChunk.Surface.DrawingSurface.Canvas.Save();
         {

+ 1 - 1
src/ChunkyImageLib/Operations/ClearPathOperation.cs

@@ -16,7 +16,7 @@ internal class ClearPathOperation : IMirroredDrawOperation
         this.pathTightBounds = (pathTightBounds ?? (RectI)path.TightBounds);
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         targetChunk.Surface.DrawingSurface.Canvas.Save();
 

+ 1 - 1
src/ChunkyImageLib/Operations/ClearRegionOperation.cs

@@ -14,7 +14,7 @@ internal class ClearRegionOperation : IMirroredDrawOperation
         this.rect = rect;
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         VecI convPos = OperationHelper.ConvertForResolution(rect.Pos, targetChunk.Resolution);
         VecI convSize = OperationHelper.ConvertForResolution(rect.Size, targetChunk.Resolution);

+ 1 - 1
src/ChunkyImageLib/Operations/DrawingSurfaceLineOperation.cs

@@ -27,7 +27,7 @@ internal class DrawingSurfaceLineOperation : IMirroredDrawOperation
         this.to = to;
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         paint.IsAntiAliased = targetChunk.Resolution != ChunkResolution.Full;
         var surf = targetChunk.Surface.DrawingSurface;

+ 1 - 1
src/ChunkyImageLib/Operations/EllipseOperation.cs

@@ -53,7 +53,7 @@ internal class EllipseOperation : IMirroredDrawOperation
         }
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         if (!init)
             Init();

+ 1 - 1
src/ChunkyImageLib/Operations/IDrawOperation.cs

@@ -6,6 +6,6 @@ namespace ChunkyImageLib.Operations;
 internal interface IDrawOperation : IOperation
 {
     bool IgnoreEmptyChunks { get; }
-    void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller);
+    void DrawOnChunk(Chunk targetChunk, VecI chunkPos);
     AffectedArea FindAffectedArea(VecI imageSize);
 }

+ 1 - 1
src/ChunkyImageLib/Operations/ImageOperation.cs

@@ -79,7 +79,7 @@ internal class ImageOperation : IMirroredDrawOperation
 
 
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         //customPaint.FilterQuality = chunk.Resolution != ChunkResolution.Full;
         float scaleMult = (float)targetChunk.Resolution.Multiplier();

+ 1 - 1
src/ChunkyImageLib/Operations/PathOperation.cs

@@ -24,7 +24,7 @@ internal class PathOperation : IMirroredDrawOperation
         bounds = floatBounds.Inflate((int)Math.Ceiling(strokeWidth) + 1);
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         paint.IsAntiAliased = targetChunk.Resolution != ChunkResolution.Full;
         var surf = targetChunk.Surface.DrawingSurface;

+ 12 - 10
src/ChunkyImageLib/Operations/PixelOperation.cs

@@ -14,8 +14,9 @@ internal class PixelOperation : IMirroredDrawOperation
     private readonly Color color;
     private readonly BlendMode blendMode;
     private readonly Paint paint;
+    private readonly Func<VecI, Color>? getCommitedPixelFunc = null;
 
-    private readonly PixelProcessor? _colorProcessor = null;
+    private readonly PixelProcessor? colorProcessor = null;
 
     public PixelOperation(VecI pixel, Color color, BlendMode blendMode)
     {
@@ -25,18 +26,19 @@ internal class PixelOperation : IMirroredDrawOperation
         paint = new Paint() { BlendMode = blendMode };
     }
 
-    public PixelOperation(VecI pixel, PixelProcessor colorProcessor, BlendMode blendMode)
+    public PixelOperation(VecI pixel, PixelProcessor colorProcessor, Func<VecI, Color> getCommitedPixelFunc, BlendMode blendMode)
     {
         this.pixel = pixel;
-        this._colorProcessor = colorProcessor;
+        this.colorProcessor = colorProcessor;
         this.blendMode = blendMode;
+        this.getCommitedPixelFunc = getCommitedPixelFunc;
         paint = new Paint() { BlendMode = blendMode };
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         // a hacky way to make the lines look slightly better on non full res chunks
-        paint.Color = GetColor(targetChunk, chunkPos, caller);
+        paint.Color = GetColor(targetChunk, chunkPos);
 
         DrawingSurface surf = targetChunk.Surface.DrawingSurface;
         surf.Canvas.Save();
@@ -46,13 +48,13 @@ internal class PixelOperation : IMirroredDrawOperation
         surf.Canvas.Restore();
     }
 
-    private Color GetColor(Chunk chunk, VecI chunkPos, ChunkyImage chunkyImage)
+    private Color GetColor(Chunk chunk, VecI chunkPos)
     {
         Color pixelColor = color;
-        if (_colorProcessor != null)
+        if (colorProcessor != null && getCommitedPixelFunc != null)
         {
             var pos = pixel - chunkPos * ChunkyImage.FullChunkSize;
-            pixelColor = _colorProcessor(chunkyImage.GetCommittedPixel(pos), chunk.Surface.GetSRGBPixel(pos));
+            pixelColor = colorProcessor(getCommitedPixelFunc(pos), chunk.Surface.GetSRGBPixel(pos));
         }
 
         return new Color(pixelColor.R, pixelColor.G, pixelColor.B, (byte)(pixelColor.A * chunk.Resolution.Multiplier()));
@@ -70,9 +72,9 @@ internal class PixelOperation : IMirroredDrawOperation
             pixelRect = (RectI)pixelRect.ReflectX((double)verAxisX).Round();
         if (horAxisY is not null)
             pixelRect = (RectI)pixelRect.ReflectY((double)horAxisY);
-        if (_colorProcessor != null)
+        if (colorProcessor != null && getCommitedPixelFunc != null)
         {
-            return new PixelOperation(pixelRect.Pos, _colorProcessor, blendMode);
+            return new PixelOperation(pixelRect.Pos, colorProcessor, getCommitedPixelFunc, blendMode);
         }
 
         return new PixelOperation(pixelRect.Pos, color, blendMode);

+ 1 - 1
src/ChunkyImageLib/Operations/PixelsOperation.cs

@@ -24,7 +24,7 @@ internal class PixelsOperation : IMirroredDrawOperation
         paint = new Paint() { BlendMode = blendMode };
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         // a hacky way to make the lines look slightly better on non full res chunks
         paint.Color = new Color(color.R, color.G, color.B, (byte)(color.A * targetChunk.Resolution.Multiplier()));

+ 1 - 1
src/ChunkyImageLib/Operations/RectangleOperation.cs

@@ -15,7 +15,7 @@ internal class RectangleOperation : IMirroredDrawOperation
 
     public bool IgnoreEmptyChunks => false;
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         var skiaSurf = targetChunk.Surface.DrawingSurface;
 

+ 1 - 1
src/ChunkyImageLib/Operations/ReplaceColorOperation.cs

@@ -22,7 +22,7 @@ internal class ReplaceColorOperation : IDrawOperation
         newColorBits = newColor.ToULong();
     }
 
-    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos, ChunkyImage caller)
+    public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
         ReplaceColor(oldColorBounds, newColorBits, targetChunk);
     }