aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.RemoteDesktop/Quantization/PaletteTable.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.RemoteDesktop/Quantization/PaletteTable.cs')
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Quantization/PaletteTable.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Quantization/PaletteTable.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Quantization/PaletteTable.cs
new file mode 100644
index 000000000..5c24fe80f
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Quantization/PaletteTable.cs
@@ -0,0 +1,72 @@
+/////////////////////////////////////////////////////////////////////////////////
+// Paint.NET //
+// Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
+// Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
+// See src/Resources/Files/License.txt for full licensing and attribution //
+// details. //
+// . //
+/////////////////////////////////////////////////////////////////////////////////
+
+using System;
+using System.Collections;
+using System.Drawing;
+
+namespace Tango.RemoteDesktop.Quantization
+{
+ internal sealed class PaletteTable
+ {
+ private Color[] palette;
+
+ public Color this[int index]
+ {
+ get
+ {
+ return this.palette[index];
+ }
+
+ set
+ {
+ this.palette[index] = value;
+ }
+ }
+
+ private int GetDistanceSquared(Color a, Color b)
+ {
+ int dsq = 0; // delta squared
+ int v;
+
+ v = a.B - b.B;
+ dsq += v * v;
+ v = a.G - b.G;
+ dsq += v * v;
+ v = a.R - b.R;
+ dsq += v * v;
+
+ return dsq;
+ }
+
+ public int FindClosestPaletteIndex(Color pixel)
+ {
+ int dsqBest = int.MaxValue;
+ int ret = 0;
+
+ for (int i = 0; i < this.palette.Length; ++i)
+ {
+ int dsq = GetDistanceSquared(this.palette[i], pixel);
+
+ if (dsq < dsqBest)
+ {
+ dsqBest = dsq;
+ ret = i;
+ }
+ }
+
+ return ret;
+ }
+
+ public PaletteTable(Color[] palette)
+ {
+ this.palette = (Color[])palette.Clone();
+ }
+ }
+}