Browse Source

Changed AllLayers to Canvas and improved surface color space creation

Krzysztof Krysiński 4 months ago
parent
commit
6a716a2fa5

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changeables/Document.cs

@@ -85,7 +85,7 @@ internal class Document : IChangeable, IReadOnlyDocument
 
         tightBounds = tightBounds.Value.Intersect(RectI.Create(0, 0, Size.X, Size.Y));
 
-        Surface surface = new Surface(tightBounds.Value.Size);
+        Surface surface = Surface.ForProcessing(tightBounds.Value.Size, ProcessingColorSpace);
 
         using var paint = new Paint();
 
@@ -94,7 +94,7 @@ internal class Document : IChangeable, IReadOnlyDocument
         if (layer is IReadOnlyImageNode imageNode)
         {
             var chunkyImage = imageNode.GetLayerImageAtFrame(frame);
-            using Surface chunkSurface = new Surface(chunkyImage.CommittedSize);
+            using Surface chunkSurface = Surface.ForProcessing(chunkyImage.CommittedSize, chunkyImage.ProcessingColorSpace);
             chunkyImage.DrawCommittedRegionOn(
                 new RectI(0, 0, chunkyImage.CommittedSize.X, chunkyImage.CommittedSize.Y),
                 ChunkResolution.Full,

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

@@ -240,7 +240,7 @@ public static class FloodFillHelper
 
     public static Surface FillSelection(IReadOnlyDocument document, VectorPath selection)
     {
-        Surface surface = new Surface(document.Size);
+        Surface surface = Surface.ForProcessing(document.Size, document.ProcessingColorSpace);
 
         var inverse = new VectorPath();
         inverse.AddRect((RectD)new RectI(new(0, 0), document.Size));

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changes/Root/FlipImage_Change.cs

@@ -66,14 +66,14 @@ internal sealed class FlipImage_Change : Change
             }
         }
 
-        using Surface originalSurface = new(img.LatestSize);
+        using Surface originalSurface = Surface.ForProcessing(img.LatestSize, img.ProcessingColorSpace);
         img.DrawMostUpToDateRegionOn(
             new RectI(VecI.Zero, img.LatestSize), 
             ChunkResolution.Full,
             originalSurface.DrawingSurface,
             VecI.Zero);
 
-        using Surface flipped = new Surface(img.LatestSize);
+        using Surface flipped = Surface.ForProcessing(img.LatestSize, img.ProcessingColorSpace);
 
         bool flipX = flipType == FlipType.Horizontal;
         bool flipY = flipType == FlipType.Vertical;

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changes/Root/ResizeImage_Change.cs

@@ -51,7 +51,7 @@ internal class ResizeImage_Change : Change
 
     private void ScaleChunkyImage(ChunkyImage image)
     {
-        using Surface originalSurface = new(originalSize);
+        using Surface originalSurface = Surface.ForProcessing(originalSize, image.ProcessingColorSpace);
         image.DrawMostUpToDateRegionOn(
             new(VecI.Zero, originalSize),
             ChunkResolution.Full,
@@ -62,7 +62,7 @@ internal class ResizeImage_Change : Change
         FilterQuality quality = ToFilterQuality(method, downscaling);
         using Paint paint = new() { FilterQuality = quality, BlendMode = BlendMode.Src, };
 
-        using Surface newSurface = new(newSize);
+        using Surface newSurface = Surface.ForProcessing(newSize, image.ProcessingColorSpace);
         newSurface.DrawingSurface.Canvas.Save();
         newSurface.DrawingSurface.Canvas.Scale(newSize.X / (float)originalSize.X, newSize.Y / (float)originalSize.Y);
         newSurface.DrawingSurface.Canvas.DrawSurface(originalSurface.DrawingSurface, 0, 0, paint);

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changes/Root/RotateImage_Change.cs

@@ -100,14 +100,14 @@ internal sealed class RotateImage_Change : Change
 
         using Paint paint = new() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.Src };
 
-        using Surface originalSurface = new(oldSize);
+        using Surface originalSurface = Surface.ForProcessing(oldSize, img.ProcessingColorSpace);
         img.DrawMostUpToDateRegionOn(
             bounds,
             ChunkResolution.Full,
             originalSurface.DrawingSurface,
             VecI.Zero);
 
-        using Surface flipped = new Surface(newSize);
+        using Surface flipped = Surface.ForProcessing(newSize, img.ProcessingColorSpace);
 
         float translationX = newSize.X;
         float translationY = newSize.Y;

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changes/Structure/RasterizeMember_Change.cs

@@ -50,7 +50,7 @@ internal class RasterizeMember_Change : Change
 
         target.NodeGraph.AddNode(imageLayer);
         
-        using Surface surface = new Surface(target.Size);
+        using Surface surface = Surface.ForProcessing(target.Size, target.ProcessingColorSpace);
         rasterizable.Rasterize(surface.DrawingSurface, null);
         
         var image = imageLayer.GetLayerImageAtFrame(0);

+ 1 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -519,7 +519,7 @@
   "FAILED_ASSOCIATE_PIXI": "Failed to associate .pixi file with PixiEditor.",
   "COULD_NOT_SAVE_PALETTE": "There was an error while saving the palette.",
   "NO_COLORS_TO_SAVE": "There are no colors to save.",
-  "ALL_LAYERS": "All Layers",
+  "CANVAS": "Canvas",
   "SINGLE_LAYER": "Single Layer",
   "CHOOSE": "Choose",
   "REMOVE": "Remove",

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/MagicWandToolExecutor.cs

@@ -27,7 +27,7 @@ internal class MagicWandToolExecutor : UpdateableChangeExecutor
 
         mode = magicWand.SelectMode;
         memberGuids = members;
-        considerAllLayers = magicWand.DocumentScope == DocumentScope.AllLayers;
+        considerAllLayers = magicWand.DocumentScope == DocumentScope.Canvas;
         if (considerAllLayers)
             memberGuids = document!.StructureHelper.GetAllLayers().Select(x => x.Id).ToList();
         var pos = controller!.LastPixelPosition;

+ 2 - 2
src/PixiEditor/Models/Tools/DocumentScope.cs

@@ -6,6 +6,6 @@ public enum DocumentScope
 {
     [Description("SINGLE_LAYER")]
     SingleLayer,
-    [Description("ALL_LAYERS")]
-    AllLayers
+    [Description("CANVAS")]
+    Canvas
 }

+ 4 - 6
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -765,12 +765,10 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         {
             // it might've been a better idea to implement this function asynchronously
             // via a passthrough action to avoid all the try catches
-            if (scope == DocumentScope.AllLayers)
+            if (scope == DocumentScope.Canvas)
             {
-                using Surface tmpSurface = new Surface(SizeBindable);
-                HashSet<Guid> layers = StructureHelper.TraverseAllMembers().Select(x => x.Id).ToHashSet();
-                Renderer.RenderLayers(tmpSurface.DrawingSurface, layers, frameTime.Frame, ChunkResolution.Full,
-                    SizeBindable);
+                using Surface tmpSurface = new Surface(SizeBindable); // new Surface is on purpose, Surface.ForDisplay doesn't work here
+                Renderer.RenderDocument(tmpSurface.DrawingSurface, frameTime, SizeBindable);
 
                 return tmpSurface.GetSrgbPixel(pos);
             }
@@ -782,7 +780,7 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
             {
                 if (maybeMember is IRasterizable rasterizable)
                 {
-                    using Texture texture = new Texture(SizeBindable);
+                    using Texture texture = Texture.ForDisplay(SizeBindable);
                     using Paint paint = new Paint();
                     rasterizable.Rasterize(texture.DrawingSurface, paint);
                     return texture.GetSRGBPixel(pos);

+ 1 - 1
src/PixiEditor/ViewModels/Tools/Tools/ColorPickerToolViewModel.cs

@@ -66,7 +66,7 @@ internal class ColorPickerToolViewModel : ToolViewModel, IColorPickerHandler
 
     public bool PickOnlyFromReferenceLayer => !pickFromCanvas && pickFromReferenceLayer;
 
-    [Settings.Enum("SCOPE_LABEL", DocumentScope.AllLayers)]
+    [Settings.Enum("SCOPE_LABEL", DocumentScope.Canvas)]
     public DocumentScope Mode => GetValue<DocumentScope>();
 
     public ColorPickerToolViewModel()

+ 2 - 2
src/PixiEditor/Views/Dialogs/ExportFilePopup.axaml.cs

@@ -289,7 +289,7 @@ internal partial class ExportFilePopup : PixiEditorPopup
         if (previewSize != ExportPreview.Size)
         {
             ExportPreview?.Dispose();
-            ExportPreview = new Surface(previewSize);
+            ExportPreview = Surface.ForDisplay(previewSize);
 
             Task.Run(() =>
             {
@@ -340,7 +340,7 @@ internal partial class ExportFilePopup : PixiEditorPopup
                 if (previewSize != ExportPreview.Size)
                 {
                     ExportPreview?.Dispose();
-                    ExportPreview = new Surface(previewSize);
+                    ExportPreview = Surface.ForDisplay(previewSize);
                 }
 
                 IsGeneratingPreview = false;

+ 1 - 1
src/PixiEditor/Views/Main/DocumentPreview.axaml.cs

@@ -158,7 +158,7 @@ internal partial class DocumentPreview : UserControl
 
         ColorCursorPosition = new VecI(x, y);
         
-        var color = Document.PickColor(new(x, y), DocumentScope.AllLayers, false, true, Document.AnimationDataViewModel.ActiveFrameBindable);
+        var color = Document.PickColor(new(x, y), DocumentScope.Canvas, false, true, Document.AnimationDataViewModel.ActiveFrameBindable);
         ColorCursorColor = Color.FromArgb(color.A, color.R, color.G, color.B);
     }
 }