Skip to content

Commit

Permalink
It builds, somehow
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Aug 31, 2021
1 parent 83f9a10 commit 89ef6ce
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 124 deletions.
9 changes: 4 additions & 5 deletions PixiEditor/Helpers/Extensions/ParserHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using PixiEditor.Models.Layers;
using PixiEditor.Parser;
using PixiEditor.Parser.Models;
using SkiaSharp;
using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using SDColor = System.Drawing.Color;

namespace PixiEditor.Helpers.Extensions
{
Expand All @@ -18,8 +18,7 @@ public static Document ToDocument(this Parser.SerializableDocument serializableD
Document document = new Document(serializableDocument.Width, serializableDocument.Height)
{
Layers = serializableDocument.ToLayers(),
Swatches = new ObservableCollection<Color>(serializableDocument.Swatches.Select(x =>
Color.FromArgb(x.A, x.R, x.G, x.B)))
Swatches = new ObservableCollection<SKColor>(serializableDocument.Swatches.Select(x => new SKColor(x.R, x.G, x.B, x.A)))
};

document.LayerStructure.Groups = serializableDocument.ToGroups();
Expand Down Expand Up @@ -70,7 +69,7 @@ public static SerializableDocument ToSerializable(this Document document)
Height = document.Height,
Layers = document.Layers.Select(x => x.ToSerializable()).ToList(),
Groups = document.LayerStructure.Groups.Select(x => x.ToSerializable()).ToArray(),
Swatches = document.Swatches.Select(x => SDColor.FromArgb(x.A, x.R, x.G, x.B)).ToList()
Swatches = document.Swatches.Select(x => Color.FromArgb(x.Alpha, x.Red, x.Green, x.Blue)).ToList()
};

return serializable;
Expand Down
42 changes: 0 additions & 42 deletions PixiEditor/Helpers/LayerBitmapContext.cs

This file was deleted.

15 changes: 8 additions & 7 deletions PixiEditor/Models/Controllers/PixelChangesController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using PixiEditor.Models.DataHolders;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using PixiEditor.Models.DataHolders;

namespace PixiEditor.Models.Controllers
{
Expand Down Expand Up @@ -52,9 +53,9 @@ public void AddChanges(LayerChange changes, LayerChange oldValues)
int i = 0;
foreach (KeyValuePair<Guid, LayerChange> change in LastChanges)
{
Dictionary<Position.Coordinates, System.Windows.Media.Color> pixelChanges =
Dictionary<Position.Coordinates, SKColor> pixelChanges =
change.Value.PixelChanges.ChangedPixels.ToDictionary(entry => entry.Key, entry => entry.Value);
Dictionary<Position.Coordinates, System.Windows.Media.Color> oldValues = LastOldValues[change.Key].PixelChanges.ChangedPixels
Dictionary<Position.Coordinates, SKColor> oldValues = LastOldValues[change.Key].PixelChanges.ChangedPixels
.ToDictionary(entry => entry.Key, entry => entry.Value);

LayerChange tmp = new LayerChange(new BitmapPixelChanges(pixelChanges), change.Key);
Expand All @@ -77,7 +78,7 @@ private void AddNewLayerChange(LayerChange changes, LayerChange oldValues)

private void AddToExistingLayerChange(LayerChange layerChange, LayerChange oldValues)
{
foreach (KeyValuePair<Position.Coordinates, System.Windows.Media.Color> change in layerChange.PixelChanges.ChangedPixels)
foreach (KeyValuePair<Position.Coordinates, SKColor> change in layerChange.PixelChanges.ChangedPixels)
{
if (LastChanges[layerChange.LayerGuid].PixelChanges.ChangedPixels.ContainsKey(change.Key))
{
Expand All @@ -89,7 +90,7 @@ private void AddToExistingLayerChange(LayerChange layerChange, LayerChange oldVa
}
}

foreach (KeyValuePair<Position.Coordinates, System.Windows.Media.Color> change in oldValues.PixelChanges.ChangedPixels)
foreach (KeyValuePair<Position.Coordinates, SKColor> change in oldValues.PixelChanges.ChangedPixels)
{
if (LastOldValues[layerChange.LayerGuid].PixelChanges.ChangedPixels.ContainsKey(change.Key))
{
Expand All @@ -102,4 +103,4 @@ private void AddToExistingLayerChange(LayerChange layerChange, LayerChange oldVa
}
}
}
}
}
2 changes: 1 addition & 1 deletion PixiEditor/Models/DataHolders/Document/Document.Layers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void AddNewLayer(string name, Surface bitmap, bool setAsActive = true)

public void AddNewLayer(string name, bool setAsActive = true)
{
AddNewLayer(name, 0, 0, setAsActive);
AddNewLayer(name, 1, 1, setAsActive);
}

public void AddNewLayer(string name, int width, int height, bool setAsActive = true)
Expand Down
4 changes: 2 additions & 2 deletions PixiEditor/Models/DataHolders/Document/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using PixiEditor.Models.Position;
using PixiEditor.Models.Undo;
using PixiEditor.ViewModels;
using SkiaSharp;
using System;
using System.Buffers;
using System.Collections.Generic;
Expand All @@ -13,7 +14,6 @@
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Media;

namespace PixiEditor.Models.DataHolders
{
Expand Down Expand Up @@ -107,7 +107,7 @@ public Selection ActiveSelection

public UndoManager UndoManager { get; set; }

public ObservableCollection<Color> Swatches { get; set; } = new ObservableCollection<Color>();
public ObservableCollection<SKColor> Swatches { get; set; } = new ObservableCollection<SKColor>();

public void RaisePropertyChange(string name)
{
Expand Down
22 changes: 11 additions & 11 deletions PixiEditor/Models/DataHolders/Selection.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Windows.Media;
using PixiEditor.Helpers;
using PixiEditor.Helpers;
using PixiEditor.Models.Enums;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;
using SkiaSharp;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;

namespace PixiEditor.Models.DataHolders
{
[DebuggerDisplay("{SelectedPoints.Count} selected Pixels")]
public class Selection : NotifyableObject
{
private readonly Color selectionBlue;
private readonly SKColor selectionBlue;
private Layer selectionLayer;

public Selection(Coordinates[] selectedPoints)
{
SelectedPoints = new ObservableCollection<Coordinates>(selectedPoints);
SelectionLayer = new Layer("_selectionLayer");
selectionBlue = Color.FromArgb(127, 142, 202, 255);
selectionBlue = new SKColor(142, 202, 255, 127);
}

public ObservableCollection<Coordinates> SelectedPoints { get; private set; }
Expand All @@ -37,7 +37,7 @@ public Layer SelectionLayer

public void SetSelection(IEnumerable<Coordinates> selection, SelectionType mode)
{
Color selectionColor = selectionBlue;
SKColor selectionColor = selectionBlue;
switch (mode)
{
case SelectionType.New:
Expand All @@ -49,7 +49,7 @@ public void SetSelection(IEnumerable<Coordinates> selection, SelectionType mode)
break;
case SelectionType.Subtract:
SelectedPoints = new ObservableCollection<Coordinates>(SelectedPoints.Except(selection));
selectionColor = System.Windows.Media.Colors.Transparent;
selectionColor = SKColors.Transparent;
break;
}

Expand All @@ -62,4 +62,4 @@ public void Clear()
SelectedPoints.Clear();
}
}
}
}
12 changes: 11 additions & 1 deletion PixiEditor/Models/DataHolders/Surface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class Surface : IDisposable

public Surface(int w, int h)
{
if (w <= 0 || h <= 0)
throw new ArgumentException("Surface dimensions must be non-zero");
SkiaSurface = CreateSurface(w, h);
Width = w;
Height = h;
Expand All @@ -37,6 +39,8 @@ public Surface(Surface original)

public Surface(int w, int h, byte[] pbgra32Bytes)
{
if (w <= 0 || h <= 0)
throw new ArgumentException("Surface dimensions must be non-zero");
Width = w;
Height = h;
SkiaSurface = Pbgra32BytesToSkSurface(w, h, pbgra32Bytes);
Expand All @@ -46,6 +50,9 @@ public Surface(WriteableBitmap original)
{
if (original.Format != PixelFormats.Pbgra32)
throw new ArgumentException("This method only supports Pbgra32 bitmaps");
if (original.PixelWidth <= 0 || original.PixelHeight <= 0)
throw new ArgumentException("Surface dimensions must be non-zero");

byte[] pixels = new byte[original.PixelWidth * original.PixelHeight * 4];
original.CopyPixels(pixels, original.PixelWidth * 4, 0);

Expand Down Expand Up @@ -157,7 +164,10 @@ private static SKSurface Pbgra32BytesToSkSurface(int w, int h, byte[] pbgra32Byt

private static SKSurface CreateSurface(int w, int h)
{
return SKSurface.Create(new SKImageInfo(w, h, SKColorType.RgbaF16, SKAlphaType.Premul, SKColorSpace.CreateSrgb()));
var surface = SKSurface.Create(new SKImageInfo(w, h, SKColorType.RgbaF16, SKAlphaType.Premul, SKColorSpace.CreateSrgb()));
if (surface == null)
throw new Exception("Could not create surface");
return surface;
}

}
Expand Down
8 changes: 4 additions & 4 deletions PixiEditor/Models/ImageManipulation/BitmapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public static WriteableBitmap GeneratePreviewBitmap(IEnumerable<SerializableLaye
maxPreviewHeight);
}

public static Dictionary<Guid, Color[]> GetPixelsForSelection(Layer[] layers, Coordinates[] selection)
public static Dictionary<Guid, SKColor[]> GetPixelsForSelection(Layer[] layers, Coordinates[] selection)
{
Dictionary<Guid, Color[]> result = new();
Dictionary<Guid, SKColor[]> result = new();

foreach (Layer layer in layers)
{
Color[] pixels = new Color[selection.Length];
SKColor[] pixels = new SKColor[selection.Length];

for (int j = 0; j < pixels.Length; j++)
{
Expand All @@ -121,7 +121,7 @@ public static WriteableBitmap GeneratePreviewBitmap(IEnumerable<SerializableLaye
}

var cl = layer.GetPixel(position.X, position.Y);
pixels[j] = Color.FromArgb(cl.Alpha, cl.Red, cl.Green, cl.Blue);
pixels[j] = cl;
}
result[layer.LayerGuid] = pixels;
}
Expand Down
12 changes: 6 additions & 6 deletions PixiEditor/Models/Tools/Tools/ColorPickerTool.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using PixiEditor.Models.Position;
using PixiEditor.ViewModels;
using SkiaSharp;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Input;
using PixiEditor.Models.Position;
using PixiEditor.ViewModels;
using Color = System.Windows.Media.Color;

namespace PixiEditor.Models.Tools.Tools
{
Expand All @@ -29,7 +29,7 @@ public override void Use(List<Coordinates> coordinates)
ViewModelMain.Current.ColorsSubViewModel.PrimaryColor = GetColorUnderMouse();
}

public Color GetColorUnderMouse()
public SKColor GetColorUnderMouse()
{
System.Drawing.Color color;
using (Bitmap bitmap = new Bitmap(1, 1))
Expand All @@ -42,7 +42,7 @@ public Color GetColorUnderMouse()
color = bitmap.GetPixel(0, 0);
}

return Color.FromArgb(color.A, color.R, color.G, color.B);
return new SKColor(color.R, color.G, color.B, color.A);
}
}
}
}

0 comments on commit 89ef6ce

Please sign in to comment.