Browse Source

Linear blending + Minor fixes

Equbuxu 3 years ago
parent
commit
82219941a0

+ 7 - 1
src/ChunkyImageLib/Chunk.cs

@@ -5,6 +5,7 @@ namespace ChunkyImageLib
 {
     public class Chunk : IDisposable
     {
+        private bool returned = false;
         internal Surface Surface { get; }
         public Vector2i PixelSize { get; }
         public ChunkResolution Resolution { get; }
@@ -26,7 +27,9 @@ namespace ChunkyImageLib
 
         public static Chunk Create(ChunkResolution resolution = ChunkResolution.Full)
         {
-            return ChunkPool.Instance.Get(resolution) ?? new Chunk(resolution);
+            var chunk = ChunkPool.Instance.Get(resolution) ?? new Chunk(resolution);
+            chunk.returned = false;
+            return chunk;
         }
 
         public void DrawOnSurface(SKSurface surface, Vector2i pos, SKPaint? paint = null)
@@ -36,6 +39,9 @@ namespace ChunkyImageLib
 
         public void Dispose()
         {
+            if (returned)
+                return;
+            returned = true;
             ChunkPool.Instance.Push(this);
         }
     }

+ 1 - 0
src/ChunkyImageLib/ChunkPool.cs

@@ -5,6 +5,7 @@ namespace ChunkyImageLib
 {
     internal class ChunkPool
     {
+        //must be divisible by 8
         public const int FullChunkSize = 256;
 
         private static object lockObj = new();

+ 9 - 5
src/ChunkyImageLib/Surface.cs

@@ -50,15 +50,19 @@ namespace ChunkyImageLib
 
         public void SaveToDesktop(string filename = "savedSurface.png")
         {
-            using var snapshot = SkiaSurface.Snapshot();
-            using var stream = File.Create(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), filename));
-            using var png = snapshot.Encode();
-            png.SaveTo(stream);
+            using var final = SKSurface.Create(new SKImageInfo(Width, Height, SKColorType.Rgba8888, SKAlphaType.Premul, SKColorSpace.CreateSrgb()));
+            final.Canvas.DrawSurface(SkiaSurface, 0, 0);
+            using (var snapshot = final.Snapshot())
+            {
+                using var stream = File.Create(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), filename));
+                using var png = snapshot.Encode();
+                png.SaveTo(stream);
+            }
         }
 
         private SKSurface CreateSKSurface()
         {
-            var surface = SKSurface.Create(new SKImageInfo(Width, Height, SKColorType.RgbaF16, SKAlphaType.Premul, SKColorSpace.CreateSrgb()), PixelBuffer);
+            var surface = SKSurface.Create(new SKImageInfo(Width, Height, SKColorType.RgbaF16, SKAlphaType.Premul, SKColorSpace.CreateSrgbLinear()), PixelBuffer);
             if (surface == null)
                 throw new Exception("Could not create surface");
             return surface;

+ 1 - 1
src/PixiEditorPrototype/Models/DocumentUpdater.cs

@@ -50,7 +50,7 @@ namespace PixiEditorPrototype.Models
 
             doc.FinalBitmap = new WriteableBitmap(doc.Tracker.Document.Size.X, doc.Tracker.Document.Size.Y, 96, 96, PixelFormats.Pbgra32, null);
             doc.FinalBitmapSurface = SKSurface.Create(
-                new SKImageInfo(doc.FinalBitmap.PixelWidth, doc.FinalBitmap.PixelHeight, SKColorType.Bgra8888, SKAlphaType.Premul),
+                new SKImageInfo(doc.FinalBitmap.PixelWidth, doc.FinalBitmap.PixelHeight, SKColorType.Bgra8888, SKAlphaType.Premul, SKColorSpace.CreateSrgb()),
                 doc.FinalBitmap.BackBuffer,
                 doc.FinalBitmap.BackBufferStride);
         }

+ 1 - 1
src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs

@@ -92,7 +92,7 @@ namespace PixiEditorPrototype.ViewModels
             MouseUpCommand = new RelayCommand(MouseUp);
 
             FinalBitmapSurface = SKSurface.Create(
-                new SKImageInfo(FinalBitmap.PixelWidth, FinalBitmap.PixelHeight, SKColorType.Bgra8888, SKAlphaType.Premul),
+                new SKImageInfo(FinalBitmap.PixelWidth, FinalBitmap.PixelHeight, SKColorType.Bgra8888, SKAlphaType.Premul, SKColorSpace.CreateSrgb()),
                 FinalBitmap.BackBuffer,
                 FinalBitmap.BackBufferStride);
         }