Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/NesTiler.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'NesTiler/Palette.cs')
-rw-r--r--NesTiler/Palette.cs39
1 files changed, 20 insertions, 19 deletions
diff --git a/NesTiler/Palette.cs b/NesTiler/Palette.cs
index 5b8703f..44cb940 100644
--- a/NesTiler/Palette.cs
+++ b/NesTiler/Palette.cs
@@ -1,4 +1,5 @@
-using System;
+using SkiaSharp;
+using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
@@ -7,12 +8,12 @@ using Color = System.Drawing.Color;
namespace com.clusterrr.Famicom.NesTiler
{
- class Palette : IEquatable<Palette>, IEnumerable<Color>
+ class Palette : IEquatable<Palette>, IEnumerable<SKColor>
{
- private Color?[] colors = new Color?[3];
- private Dictionary<ColorPair, (Color color, double delta)> deltaCache = new();
+ private SKColor?[] colors = new SKColor?[3];
+ private Dictionary<ColorPair, (SKColor color, double delta)> deltaCache = new();
- public Color? this[int i]
+ public SKColor? this[int i]
{
get
{
@@ -32,9 +33,9 @@ namespace com.clusterrr.Famicom.NesTiler
// Empty palette
}
- public Palette(FastBitmap image, int leftX, int topY, int width, int height, Color bgColor)
+ public Palette(FastBitmap image, int leftX, int topY, int width, int height, SKColor bgColor)
{
- Dictionary<Color, int> colorCounter = new Dictionary<Color, int>();
+ Dictionary<SKColor, int> colorCounter = new();
for (int y = topY; y < topY + height; y++)
{
if (y < 0) continue;
@@ -54,21 +55,21 @@ namespace com.clusterrr.Famicom.NesTiler
this[i + 1] = sortedColors[i].Key;
}
- public void Add(Color color)
+ public void Add(SKColor color)
{
if (Count >= 3) throw new IndexOutOfRangeException();
this[Count + 1] = color;
deltaCache.Clear();
}
- public Palette(IEnumerable<Color> colors)
+ public Palette(IEnumerable<SKColor> colors)
{
var colorsList = colors.ToList();
for (int i = 0; i < 3; i++)
if (colorsList.Count > i) this[i + 1] = colorsList[i];
}
- public double GetTileDelta(FastBitmap image, int leftX, int topY, int width, int height, Color bgColor)
+ public double GetTileDelta(FastBitmap image, int leftX, int topY, int width, int height, SKColor bgColor)
{
double delta = 0;
for (int y = topY; y < topY + height; y++)
@@ -83,7 +84,7 @@ namespace com.clusterrr.Famicom.NesTiler
return delta;
}
- private (Color color, double delta) GetMinDelta(Color color, Color bgColor)
+ private (SKColor color, double delta) GetMinDelta(SKColor color, SKColor bgColor)
{
var pair = new ColorPair()
{
@@ -91,7 +92,7 @@ namespace com.clusterrr.Famicom.NesTiler
Color2 = bgColor
};
if (deltaCache.ContainsKey(pair)) return deltaCache[pair];
- var ac = Enumerable.Concat(colors.Where(c => c.HasValue).Select(c => c!.Value), new Color[] { bgColor });
+ var ac = Enumerable.Concat(colors.Where(c => c.HasValue).Select(c => c!.Value), new SKColor[] { bgColor });
var result = ac.OrderBy(c => c.GetDelta(color)).First();
var r = (result, result.GetDelta(color));
deltaCache[pair] = r;
@@ -105,7 +106,7 @@ namespace com.clusterrr.Famicom.NesTiler
.OrderBy(c => c!.Value.ToArgb())
.Select(c => c!.Value)
.ToArray();
- var colors2 = new Color?[] { other[1], other[2], other[3] }
+ var colors2 = new SKColor?[] { other[1], other[2], other[3] }
.Where(c => c.HasValue)
.OrderBy(c => c!.Value.ToArgb())
.Select(c => c!.Value)
@@ -116,7 +117,7 @@ namespace com.clusterrr.Famicom.NesTiler
public bool Contains(Palette other)
{
var thisColors = colors.Where(c => c.HasValue);
- var otherColors = new Color?[] { other[1], other[2], other[3] }.Where(c => c.HasValue).Select(c => c!.Value);
+ var otherColors = new SKColor?[] { other[1], other[2], other[3] }.Where(c => c.HasValue).Select(c => c!.Value);
foreach (var color in otherColors)
{
@@ -126,7 +127,7 @@ namespace com.clusterrr.Famicom.NesTiler
return true;
}
- public IEnumerator<Color> GetEnumerator()
+ public IEnumerator<SKColor> GetEnumerator()
{
return colors.Where(c => c.HasValue).Select(c => c!.Value).GetEnumerator();
}
@@ -136,13 +137,13 @@ namespace com.clusterrr.Famicom.NesTiler
return GetEnumerator();
}
- public override string ToString() => string.Join(", ", colors.Where(c => c.HasValue).Select(c => ColorTranslator.ToHtml(c!.Value)).OrderBy(c => c));
+ public override string ToString() => string.Join(", ", colors.Where(c => c.HasValue).Select(c => ColorTranslator.ToHtml(c!.Value.ToColor())).OrderBy(c => c));
public override int GetHashCode()
{
- return ((this[1]?.R ?? 0) + (this[2]?.R ?? 0) + (this[3]?.R ?? 0))
- | (((this[1]?.G ?? 0) + (this[2]?.G ?? 0) + (this[3]?.G ?? 0)) << 10)
- | (((this[1]?.B ?? 0) + (this[2]?.B ?? 0) + (this[3]?.B ?? 0)) << 20);
+ return ((this[1]?.Red ?? 0) + (this[2]?.Red ?? 0) + (this[3]?.Red ?? 0))
+ | (((this[1]?.Green ?? 0) + (this[2]?.Green ?? 0) + (this[3]?.Green ?? 0)) << 10)
+ | (((this[1]?.Blue ?? 0) + (this[2]?.Blue ?? 0) + (this[3]?.Blue ?? 0)) << 20);
}
}
}