|
@@ -6,6 +6,7 @@ using PixiEditor.DrawingApi.Core.Surface.PaintImpl;
|
|
|
|
|
|
namespace ChunkyImageLib.Operations;
|
|
namespace ChunkyImageLib.Operations;
|
|
|
|
|
|
|
|
+public delegate Color PixelProcessor(Color input);
|
|
internal class PixelOperation : IMirroredDrawOperation
|
|
internal class PixelOperation : IMirroredDrawOperation
|
|
{
|
|
{
|
|
public bool IgnoreEmptyChunks => false;
|
|
public bool IgnoreEmptyChunks => false;
|
|
@@ -14,6 +15,8 @@ internal class PixelOperation : IMirroredDrawOperation
|
|
private readonly BlendMode blendMode;
|
|
private readonly BlendMode blendMode;
|
|
private readonly Paint paint;
|
|
private readonly Paint paint;
|
|
|
|
|
|
|
|
+ private readonly PixelProcessor? _colorProcessor = null;
|
|
|
|
+
|
|
public PixelOperation(VecI pixel, Color color, BlendMode blendMode)
|
|
public PixelOperation(VecI pixel, Color color, BlendMode blendMode)
|
|
{
|
|
{
|
|
this.pixel = pixel;
|
|
this.pixel = pixel;
|
|
@@ -22,10 +25,18 @@ internal class PixelOperation : IMirroredDrawOperation
|
|
paint = new Paint() { BlendMode = blendMode };
|
|
paint = new Paint() { BlendMode = blendMode };
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public PixelOperation(VecI pixel, PixelProcessor colorProcessor, BlendMode blendMode)
|
|
|
|
+ {
|
|
|
|
+ this.pixel = pixel;
|
|
|
|
+ this._colorProcessor = colorProcessor;
|
|
|
|
+ this.blendMode = blendMode;
|
|
|
|
+ paint = new Paint() { BlendMode = blendMode };
|
|
|
|
+ }
|
|
|
|
+
|
|
public void DrawOnChunk(Chunk chunk, VecI chunkPos)
|
|
public void DrawOnChunk(Chunk chunk, VecI chunkPos)
|
|
{
|
|
{
|
|
// a hacky way to make the lines look slightly better on non full res chunks
|
|
// 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 * chunk.Resolution.Multiplier()));
|
|
|
|
|
|
+ paint.Color = GetColor(chunk, chunkPos);
|
|
|
|
|
|
DrawingSurface surf = chunk.Surface.DrawingSurface;
|
|
DrawingSurface surf = chunk.Surface.DrawingSurface;
|
|
surf.Canvas.Save();
|
|
surf.Canvas.Save();
|
|
@@ -35,6 +46,17 @@ internal class PixelOperation : IMirroredDrawOperation
|
|
surf.Canvas.Restore();
|
|
surf.Canvas.Restore();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Color GetColor(Chunk chunk, VecI chunkPos)
|
|
|
|
+ {
|
|
|
|
+ Color pixelColor = color;
|
|
|
|
+ if (_colorProcessor != null)
|
|
|
|
+ {
|
|
|
|
+ pixelColor = _colorProcessor(chunk.Surface.GetSRGBPixel(pixel - chunkPos * ChunkyImage.FullChunkSize));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new Color(pixelColor.R, pixelColor.G, pixelColor.B, (byte)(pixelColor.A * chunk.Resolution.Multiplier()));
|
|
|
|
+ }
|
|
|
|
+
|
|
public AffectedArea FindAffectedArea(VecI imageSize)
|
|
public AffectedArea FindAffectedArea(VecI imageSize)
|
|
{
|
|
{
|
|
return new AffectedArea(new HashSet<VecI>() { OperationHelper.GetChunkPos(pixel, ChunkyImage.FullChunkSize) }, new RectI(pixel, VecI.One));
|
|
return new AffectedArea(new HashSet<VecI>() { OperationHelper.GetChunkPos(pixel, ChunkyImage.FullChunkSize) }, new RectI(pixel, VecI.One));
|
|
@@ -46,7 +68,12 @@ internal class PixelOperation : IMirroredDrawOperation
|
|
if (verAxisX is not null)
|
|
if (verAxisX is not null)
|
|
pixelRect = (RectI)pixelRect.ReflectX((double)verAxisX).Round();
|
|
pixelRect = (RectI)pixelRect.ReflectX((double)verAxisX).Round();
|
|
if (horAxisY is not null)
|
|
if (horAxisY is not null)
|
|
- pixelRect = (RectI)pixelRect.ReflectY((double)horAxisY).Round();
|
|
|
|
|
|
+ pixelRect = (RectI)pixelRect.ReflectY((double)horAxisY);
|
|
|
|
+ if (_colorProcessor != null)
|
|
|
|
+ {
|
|
|
|
+ return new PixelOperation(pixelRect.Pos, _colorProcessor, blendMode);
|
|
|
|
+ }
|
|
|
|
+
|
|
return new PixelOperation(pixelRect.Pos, color, blendMode);
|
|
return new PixelOperation(pixelRect.Pos, color, blendMode);
|
|
}
|
|
}
|
|
|
|
|