Răsfoiți Sursa

Fixed flood fill and bleeding scene rendering

Krzysztof Krysiński 2 săptămâni în urmă
părinte
comite
3701a573ed

+ 1 - 1
src/ChunkyImageLib/Chunk.cs

@@ -59,7 +59,7 @@ public class Chunk : IDisposable
         Resolution = resolution;
         ColorSpace = colorSpace;
         PixelSize = new(size, size);
-        internalSurface = new Texture(new ImageInfo(size, size, ColorType.RgbaF16, AlphaType.Premul, colorSpace) {GpuBacked = true});
+        internalSurface = new Texture(new ImageInfo(size, size, ColorType.RgbaF16, AlphaType.Premul, colorSpace) { GpuBacked = true });
     }
 
     /// <summary>

+ 1 - 1
src/ChunkyImageLib/ChunkyImageEx.cs

@@ -115,7 +115,7 @@ public static class IReadOnlyChunkyImageEx
             for (int i = chunkTopLeft.X; i <= chunkBotRight.X; i++)
             {
                 var chunkPos = new VecI(i, j);
-                if (area.Chunks.Contains(chunkPos))
+                if (area.Chunks != null && area.Chunks.Contains(chunkPos))
                 {
                     drawingFunc(chunkPos, resolution, surface,
                         offsetTargetRes + (chunkPos - chunkTopLeft) * resolution.PixelSize() + pos, paint,

+ 0 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ImageLayerNode.cs

@@ -128,7 +128,6 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
     private void DrawLayer(DrawingSurface workingSurface, Paint paint, SceneObjectRenderContext ctx)
     {
         int saved = workingSurface.Canvas.Save();
-        AllowHighDpiRendering = true;
 
         var sceneSize = GetSceneSize(ctx.FrameTime);
         var region = ctx.VisibleDocumentRegion ?? new RectI(0, 0, layerImage.LatestSize.X, layerImage.LatestSize.Y);

+ 0 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/LayerNode.cs

@@ -37,7 +37,6 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
 
     private void RenderContent(SceneObjectRenderContext context, DrawingSurface renderOnto, bool useFilters)
     {
-        AllowHighDpiRendering = true;
         if (!HasOperations())
         {
             if (Background.Value != null)

+ 8 - 1
src/PixiEditor.ChangeableDocument/Changes/Drawing/FloodFill/FloodFillHelper.cs

@@ -6,6 +6,7 @@ using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces.ImageData;
+using Drawie.Backend.Core.Surfaces.PaintImpl;
 using Drawie.Backend.Core.Vector;
 using Drawie.Numerics;
 
@@ -212,7 +213,9 @@ public static class FloodFillHelper
         using var refPixmap = referenceChunk.Surface.PeekPixels();
         Half* refArray = (Half*)refPixmap.GetPixels();
 
-        using var drawPixmap = drawingChunk.Surface.PeekPixels();
+        Surface cpuSurface = Surface.ForProcessing(new VecI(chunkSize), referenceChunk.Surface.ColorSpace);
+        cpuSurface.DrawingSurface.Canvas.DrawSurface(drawingChunk.Surface.DrawingSurface, 0, 0);
+        using var drawPixmap = cpuSurface.PeekPixels();
         Half* drawArray = (Half*)drawPixmap.GetPixels();
 
         Stack<VecI> toVisit = new();
@@ -240,6 +243,10 @@ public static class FloodFillHelper
                 toVisit.Push(new(curPos.X, curPos.Y + 1));
         }
 
+        using Paint replacePaint = new Paint();
+        replacePaint.BlendMode = BlendMode.Src;
+        drawingChunk.Surface.DrawingSurface.Canvas.DrawSurface(cpuSurface.DrawingSurface, 0, 0, replacePaint);
+
         return pixelStates;
     }
 

+ 13 - 15
src/PixiEditor/Models/Rendering/SceneRenderer.cs

@@ -83,8 +83,6 @@ internal class SceneRenderer : IDisposable
             target.DeviceClipBounds.Size.ShortestAxis <= 0) return;*/
         //RenderOnionSkin(target, resolution, samplingOptions, targetOutput);
 
-        string adjustedTargetOutput = targetOutput ?? "";
-
         IReadOnlyNodeGraph finalGraph = RenderingUtils.SolveFinalNodeGraph(targetOutput, Document);
         bool shouldRerender =
             ShouldRerender(renderTargetSize, targetMatrix, resolution, viewportId, targetOutput, finalGraph);
@@ -94,7 +92,8 @@ internal class SceneRenderer : IDisposable
 
         if (shouldRerender)
         {
-            return RenderGraph(renderTargetSize, targetMatrix, viewportId, resolution, samplingOptions, affectedArea, visibleDocumentRegion, targetOutput,
+            return RenderGraph(renderTargetSize, targetMatrix, viewportId, resolution, samplingOptions, affectedArea,
+                visibleDocumentRegion, targetOutput,
                 finalGraph);
         }
         //previewRenderer.RenderPreviews(DocumentViewModel.AnimationHandler.ActiveFrameTime);
@@ -135,7 +134,8 @@ internal class SceneRenderer : IDisposable
         }
         else
         {
-            renderTexture = textureCache.RequestTexture(viewportId.GetHashCode(), renderTargetSize, Document.ProcessingColorSpace);
+            renderTexture = textureCache.RequestTexture(viewportId.GetHashCode(), renderTargetSize,
+                Document.ProcessingColorSpace);
 
             renderTarget = renderTexture.DrawingSurface;
 
@@ -143,7 +143,6 @@ internal class SceneRenderer : IDisposable
             renderTarget.Canvas.Save();*/
 
             /*target.Canvas.SetMatrix(Matrix3X3.Identity);*/
-            renderTarget.Canvas.ClipRect(new RectD(0, 0, finalSize.X, finalSize.Y));
             renderTarget.Canvas.SetMatrix(targetMatrix);
         }
 
@@ -201,7 +200,8 @@ internal class SceneRenderer : IDisposable
 
     private bool RenderInOutputSize(IReadOnlyNodeGraph finalGraph, VecI renderTargetSize, VecI finalSize)
     {
-        return !HighResRendering || (!HighDpiRenderNodePresent(finalGraph) && renderTargetSize.Length > finalSize.Length);
+        return !HighResRendering ||
+               (!HighDpiRenderNodePresent(finalGraph) && renderTargetSize.Length > finalSize.Length);
     }
 
     private bool ShouldRerender(VecI targetSize, Matrix3X3 matrix, ChunkResolution resolution,
@@ -261,17 +261,15 @@ internal class SceneRenderer : IDisposable
             }
         }
 
-        if (!renderInDocumentSize)
+        // if (!renderInDocumentSize)
+        //{
+        double zoomDiff = Math.Abs(matrix.ScaleX - cachedTexture.DrawingSurface.Canvas.TotalMatrix.ScaleX);
+        zoomDiff += Math.Abs(matrix.ScaleY - cachedTexture.DrawingSurface.Canvas.TotalMatrix.ScaleY);
+        if (zoomDiff != 0)
         {
-            if (!renderInDocumentSize)
-            {
-                double zoomDiff = Math.Abs(matrix.ScaleX - cachedTexture.DrawingSurface.Canvas.TotalMatrix.ScaleX);
-                if (zoomDiff != 0)
-                {
-                    return true;
-                }
-            }
+            return true;
         }
+        //}
 
         int currentGraphCacheHash = finalGraph.GetCacheHash();
         if (lastGraphCacheHash != currentGraphCacheHash)

+ 1 - 0
src/PixiEditor/Views/Rendering/Scene.cs

@@ -354,6 +354,7 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
             if (tex.Size == (VecI)RealDimensions)
             {
                 saved = texture.Canvas.Save();
+                texture.Canvas.ClipRect(bounds);
                 texture.Canvas.SetMatrix(Matrix3X3.Identity);
                 hasSaved = true;
             }