|
@@ -1,40 +1,17 @@
|
|
-using System;
|
|
|
|
-using System.Collections.Generic;
|
|
|
|
-using System.Linq;
|
|
|
|
-using System.Windows.Media;
|
|
|
|
-using System.Windows.Media.Imaging;
|
|
|
|
-using PixiEditor.Models.DataHolders;
|
|
|
|
|
|
+using PixiEditor.Models.DataHolders;
|
|
using PixiEditor.Models.ImageManipulation;
|
|
using PixiEditor.Models.ImageManipulation;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Position;
|
|
using PixiEditor.Models.Position;
|
|
-using PixiEditorTests.ModelsTests.ColorsTests;
|
|
|
|
|
|
+using SkiaSharp;
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
using Xunit;
|
|
using Xunit;
|
|
|
|
|
|
namespace PixiEditorTests.ModelsTests.ImageManipulationTests
|
|
namespace PixiEditorTests.ModelsTests.ImageManipulationTests
|
|
{
|
|
{
|
|
public class BitmapUtilsTests
|
|
public class BitmapUtilsTests
|
|
{
|
|
{
|
|
- [Fact]
|
|
|
|
- public void TestBytesToSurface()
|
|
|
|
- {
|
|
|
|
- int width = 10;
|
|
|
|
- int height = 10;
|
|
|
|
- Coordinates[] coloredPoints = { new Coordinates(0, 0), new Coordinates(3, 6), new Coordinates(9, 9) };
|
|
|
|
- Surface bmp = BitmapFactory.New(width, height);
|
|
|
|
- for (int i = 0; i < coloredPoints.Length; i++)
|
|
|
|
- {
|
|
|
|
- bmp.SetPixel(coloredPoints[i].X, coloredPoints[i].Y, ExtendedColorTests.green);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- byte[] byteArray = bmp.ToByteArray();
|
|
|
|
-
|
|
|
|
- Surface convertedBitmap = BitmapUtils.BytesToSurface(width, height, byteArray);
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < coloredPoints.Length; i++)
|
|
|
|
- {
|
|
|
|
- Assert.Equal(ExtendedColorTests.green, convertedBitmap.GetPixel(coloredPoints[i].X, coloredPoints[i].Y));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
public void TestThatCombineLayersReturnsCorrectBitmap()
|
|
public void TestThatCombineLayersReturnsCorrectBitmap()
|
|
@@ -42,14 +19,14 @@ namespace PixiEditorTests.ModelsTests.ImageManipulationTests
|
|
Coordinates[] cords = { new Coordinates(0, 0), new Coordinates(1, 1) };
|
|
Coordinates[] cords = { new Coordinates(0, 0), new Coordinates(1, 1) };
|
|
Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) };
|
|
Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) };
|
|
|
|
|
|
- layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[0] }, ExtendedColorTests.green));
|
|
|
|
|
|
+ layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[0] }, SKColors.Lime));
|
|
|
|
|
|
- layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[1] }, ExtendedColorTests.red));
|
|
|
|
|
|
+ layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[1] }, SKColors.Red));
|
|
|
|
|
|
Surface outputBitmap = BitmapUtils.CombineLayers(2, 2, layers);
|
|
Surface outputBitmap = BitmapUtils.CombineLayers(2, 2, layers);
|
|
|
|
|
|
- Assert.Equal(ExtendedColorTests.green, outputBitmap.GetPixel(0, 0));
|
|
|
|
- Assert.Equal(ExtendedColorTests.red, outputBitmap.GetPixel(1, 1));
|
|
|
|
|
|
+ Assert.Equal(SKColors.Lime, outputBitmap.GetSRGBPixel(0, 0));
|
|
|
|
+ Assert.Equal(SKColors.Red, outputBitmap.GetSRGBPixel(1, 1));
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -58,13 +35,13 @@ namespace PixiEditorTests.ModelsTests.ImageManipulationTests
|
|
Coordinates[] cords = { new Coordinates(0, 0) };
|
|
Coordinates[] cords = { new Coordinates(0, 0) };
|
|
Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) };
|
|
Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) };
|
|
|
|
|
|
- layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(cords, ExtendedColorTests.green));
|
|
|
|
|
|
+ layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(cords, SKColors.Lime));
|
|
|
|
|
|
- layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(cords, ExtendedColorTests.red));
|
|
|
|
|
|
+ layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(cords, SKColors.Red));
|
|
|
|
|
|
Surface outputBitmap = BitmapUtils.CombineLayers(2, 2, layers);
|
|
Surface outputBitmap = BitmapUtils.CombineLayers(2, 2, layers);
|
|
|
|
|
|
- Assert.Equal(ExtendedColorTests.red, outputBitmap.GetSRGBPixel(0, 0));
|
|
|
|
|
|
+ Assert.Equal(SKColors.Red, outputBitmap.GetSRGBPixel(0, 0));
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -77,26 +54,26 @@ namespace PixiEditorTests.ModelsTests.ImageManipulationTests
|
|
};
|
|
};
|
|
Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) };
|
|
Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) };
|
|
|
|
|
|
- layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[0] }, ExtendedColorTests.green));
|
|
|
|
- layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[1] }, ExtendedColorTests.red));
|
|
|
|
|
|
+ layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[0] }, SKColors.Lime));
|
|
|
|
+ layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[1] }, SKColors.Red));
|
|
|
|
|
|
- Dictionary<Guid, Color[]> output = BitmapUtils.GetPixelsForSelection(layers, cords);
|
|
|
|
|
|
+ Dictionary<Guid, SKColor[]> output = BitmapUtils.GetPixelsForSelection(layers, cords);
|
|
|
|
|
|
- List<Color> colors = new List<Color>();
|
|
|
|
|
|
+ List<SKColor> colors = new List<SKColor>();
|
|
|
|
|
|
- foreach (KeyValuePair<Guid, Color[]> layerColor in output.ToArray())
|
|
|
|
|
|
+ foreach (KeyValuePair<Guid, SKColor[]> layerColor in output.ToArray())
|
|
{
|
|
{
|
|
- foreach (Color color in layerColor.Value)
|
|
|
|
|
|
+ foreach (SKColor color in layerColor.Value)
|
|
{
|
|
{
|
|
colors.Add(color);
|
|
colors.Add(color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- Assert.Single(colors.Where(x => x == ExtendedColorTests.green));
|
|
|
|
- Assert.Single(colors.Where(x => x == ExtendedColorTests.red));
|
|
|
|
- Assert.Equal(6, colors.Count(x => x.A == 0)); // 6 because layer is 4 pixels,
|
|
|
|
|
|
+ Assert.Single(colors.Where(x => x == SKColors.Lime));
|
|
|
|
+ Assert.Single(colors.Where(x => x == SKColors.Red));
|
|
|
|
+ Assert.Equal(6, colors.Count(x => x.Alpha == 0)); // 6 because layer is 4 pixels,
|
|
|
|
|
|
// 2 * 4 = 8, 2 other color pixels, so 8 - 2 = 6
|
|
// 2 * 4 = 8, 2 other color pixels, so 8 - 2 = 6
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|