diff --git a/BizHawk.Client.EmuHawk/AVOut/Quantize/OctreeQuantizer.cs b/BizHawk.Client.EmuHawk/AVOut/Quantize/OctreeQuantizer.cs
index 4d5e8cc5e9..b58f0d223b 100644
--- a/BizHawk.Client.EmuHawk/AVOut/Quantize/OctreeQuantizer.cs
+++ b/BizHawk.Client.EmuHawk/AVOut/Quantize/OctreeQuantizer.cs
@@ -14,7 +14,7 @@
// Based on: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/colorquant.asp
-//Bizhawk says: adapted from https://github.com/inexorabletash/PcxFileType/blob/master/Quantize
+//BizHawk says: adapted from https://github.com/inexorabletash/PcxFileType/blob/master/Quantize
using System;
using System.Collections.Generic;
@@ -23,87 +23,91 @@ using System.Drawing.Imaging;
namespace BizHawk.Client.EmuHawk
{
- ///
- /// Quantize using an Octree
- ///
- unsafe class OctreeQuantizer : Quantizer
- {
- ///
- /// Stores the tree
- ///
- private Octree _octree;
+ ///
+ /// Quantize using an Octree
+ ///
+ internal class OctreeQuantizer : Quantizer
+ {
+ ///
+ /// Stores the tree
+ ///
+ private readonly Octree _octree;
- ///
- /// Maximum allowed color depth
- ///
- private int _maxColors;
+ ///
+ /// Maximum allowed color depth
+ ///
+ private readonly int _maxColors;
- /// The maximum number of colors to return
- /// The number of significant bits
- /// ≥ 256 or outside range 1..8
- /// The Octree quantizer is a two pass algorithm. The initial pass sets up the octree, the second pass quantizes a color based on the nodes in the tree.
- public OctreeQuantizer(int maxColors, int maxColorBits) : base(false)
- {
- if (maxColors > 255)
- throw new ArgumentOutOfRangeException(nameof(maxColors), maxColors, "The number of colors should be less than 256");
+ /// The maximum number of colors to return
+ /// The number of significant bits
+ /// ≥ 256 or outside range 1..8
+ /// The Octree quantizer is a two pass algorithm. The initial pass sets up the octree, the second pass quantizes a color based on the nodes in the tree.
+ public OctreeQuantizer(int maxColors, int maxColorBits) : base(false)
+ {
+ if (maxColors > 255)
+ {
+ throw new ArgumentOutOfRangeException(nameof(maxColors), maxColors, "The number of colors should be less than 256");
+ }
- if ((maxColorBits < 1) |(maxColorBits > 8))
- throw new ArgumentOutOfRangeException(nameof(maxColorBits), maxColorBits, "This should be between 1 and 8");
+ if ((maxColorBits < 1) | (maxColorBits > 8))
+ {
+ throw new ArgumentOutOfRangeException(nameof(maxColorBits), maxColorBits, "This should be between 1 and 8");
+ }
- _octree = new Octree(maxColorBits);
- _maxColors = maxColors;
- }
+ _octree = new Octree(maxColorBits);
+ _maxColors = maxColors;
+ }
- ///
- /// Process the pixel in the first pass of the algorithm
- ///
- /// The pixel to quantize
- ///
- /// This function need only be overridden if your quantize algorithm needs two passes,
- /// such as an Octree quantizer.
- ///
- protected override void InitialQuantizePixel(int pixel)
- {
- _octree.AddColor(pixel);
- }
+ ///
+ /// Process the pixel in the first pass of the algorithm
+ ///
+ /// The pixel to quantize
+ ///
+ /// This function need only be overridden if your quantize algorithm needs two passes,
+ /// such as an Octree quantizer.
+ ///
+ protected override void InitialQuantizePixel(int pixel)
+ {
+ _octree.AddColor(pixel);
+ }
- ///
- /// Override this to process the pixel in the second pass of the algorithm
- ///
- /// The pixel to quantize
- /// The quantized value
- protected override byte QuantizePixel(int pixel)
- {
- byte paletteIndex = (byte)_maxColors; // The color at [_maxColors] is set to transparent
+ ///
+ /// Override this to process the pixel in the second pass of the algorithm
+ ///
+ /// The pixel to quantize
+ /// The quantized value
+ protected override byte QuantizePixel(int pixel)
+ {
+ byte paletteIndex = (byte)_maxColors; // The color at [_maxColors] is set to transparent
- // Get the palette index if this non-transparent
- int a = (pixel>>24)&0xFF;
+ // Get the palette index if this non-transparent
+ int a = (pixel >> 24) & 0xFF;
#if HANDLE_TRANSPARENCY
if (a > 0)
#endif
- {
- paletteIndex = (byte)_octree.GetPaletteIndex(pixel);
- }
+ {
+ paletteIndex = (byte)_octree.GetPaletteIndex(pixel);
+ }
- return paletteIndex;
- }
+ return paletteIndex;
+ }
- ///
- /// Retrieve the palette for the quantized image
- ///
- /// Any old palette, this is overrwritten
- /// The new color palette
- protected override ColorPalette GetPalette(ColorPalette original)
- {
- // First off convert the octree to _maxColors colors
- List palette = _octree.Palletize(_maxColors - 1);
+ ///
+ /// Retrieve the palette for the quantized image
+ ///
+ /// Any old palette, this is overwritten
+ /// The new color palette
+ protected override ColorPalette GetPalette(ColorPalette original)
+ {
+ // First off convert the octree to _maxColors colors
+ List palette = _octree.Palletize(_maxColors - 1);
- // Then convert the palette based on those colors
- for (int index = 0; index < palette.Count; index++)
- {
- original.Entries[index] = palette[index];
- }
+ // Then convert the palette based on those colors
+ for (int index = 0; index < palette.Count; index++)
+ {
+ original.Entries[index] = palette[index];
+ }
#if ORIGINAL_CODE
for (int i = palette.Count; i < original.Entries.Length; ++i)
@@ -114,461 +118,417 @@ namespace BizHawk.Client.EmuHawk
// Add the transparent color
original.Entries[_maxColors] = Color.FromArgb(0, 0, 0, 0);
#else // PCX Plugin
- // For PCX: Pad with transparency
- for (int i = palette.Count; i < original.Entries.Length; ++i)
- original.Entries[i] = Color.Transparent;
+ // For PCX: Pad with transparency
+ for (int i = palette.Count; i < original.Entries.Length; ++i)
+ {
+ original.Entries[i] = Color.Transparent;
+ }
#endif
- return original;
- }
+ return original;
+ }
- ///
- /// Class which does the actual quantization
- ///
- private class Octree
- {
- ///
- /// Construct the octree
- ///
- /// The maximum number of significant bits in the image
- public Octree(int maxColorBits)
- {
- _maxColorBits = maxColorBits;
- _leafCount = 0;
- _reducibleNodes = new OctreeNode[9];
- _root = new OctreeNode(0, _maxColorBits, this);
- _previousColor = 0;
- _previousNode = null;
- }
+ ///
+ /// Class which does the actual quantization
+ ///
+ private class Octree
+ {
+ ///
+ /// Construct the octree
+ ///
+ /// The maximum number of significant bits in the image
+ public Octree(int maxColorBits)
+ {
+ _maxColorBits = maxColorBits;
+ _leafCount = 0;
+ _reducibleNodes = new OctreeNode[9];
+ _root = new OctreeNode(0, _maxColorBits, this);
+ _previousColor = 0;
+ _previousNode = null;
+ }
- ///
- /// Add a given color value to the octree
- ///
- public void AddColor(int pixel)
- {
- // Check if this request is for the same color as the last
- if (_previousColor == pixel)
- {
- // If so, check if I have a previous node setup. This will only ocurr if the first color in the image
- // happens to be black, with an alpha component of zero.
- if (null == _previousNode)
- {
- _previousColor = pixel;
- _root.AddColor(pixel, _maxColorBits, 0, this);
- }
- else
- {
- // Just update the previous node
- _previousNode.Increment(pixel);
- }
- }
- else
- {
- _previousColor = pixel;
- _root.AddColor(pixel, _maxColorBits, 0, this);
- }
- }
+ ///
+ /// Add a given color value to the octree
+ ///
+ public void AddColor(int pixel)
+ {
+ // Check if this request is for the same color as the last
+ if (_previousColor == pixel)
+ {
+ // If so, check if I have a previous node setup. This will only occur if the first color in the image
+ // happens to be black, with an alpha component of zero.
+ if (null == _previousNode)
+ {
+ _previousColor = pixel;
+ _root.AddColor(pixel, _maxColorBits, 0, this);
+ }
+ else
+ {
+ // Just update the previous node
+ _previousNode.Increment(pixel);
+ }
+ }
+ else
+ {
+ _previousColor = pixel;
+ _root.AddColor(pixel, _maxColorBits, 0, this);
+ }
+ }
- ///
- /// Reduce the depth of the tree
- ///
- public void Reduce()
- {
- int index;
+ ///
+ /// Reduce the depth of the tree
+ ///
+ private void Reduce()
+ {
+ int index;
- // Find the deepest level containing at least one reducible node
- for (index = _maxColorBits - 1; (index > 0) && (null == _reducibleNodes[index]); index--)
- {
- // intentionally blank
- }
+ // Find the deepest level containing at least one reducible node
+ for (index = _maxColorBits - 1; index > 0 && _reducibleNodes[index] == null; index--)
+ {
+ // intentionally blank
+ }
- // Reduce the node most recently added to the list at level 'index'
- OctreeNode node = _reducibleNodes[index];
- _reducibleNodes[index] = node.NextReducible;
+ // Reduce the node most recently added to the list at level 'index'
+ OctreeNode node = _reducibleNodes[index];
+ _reducibleNodes[index] = node.NextReducible;
- // Decrement the leaf count after reducing the node
- _leafCount -= node.Reduce();
+ // Decrement the leaf count after reducing the node
+ _leafCount -= node.Reduce();
- // And just in case I've reduced the last color to be added, and the next color to
- // be added is the same, invalidate the previousNode...
- _previousNode = null;
- }
+ // And just in case I've reduced the last color to be added, and the next color to
+ // be added is the same, invalidate the previousNode...
+ _previousNode = null;
+ }
- ///
- /// Get/Set the number of leaves in the tree
- ///
- public int Leaves
- {
- get
- {
- return _leafCount;
- }
+ ///
+ /// Return the array of reducible nodes
+ ///
+ protected OctreeNode[] ReducibleNodes => _reducibleNodes;
- set
- {
- _leafCount = value;
- }
- }
+ ///
+ /// Keep track of the previous node that was quantized
+ ///
+ /// The node last quantized
+ protected void TrackPrevious(OctreeNode node)
+ {
+ _previousNode = node;
+ }
- ///
- /// Return the array of reducible nodes
- ///
- protected OctreeNode[] ReducibleNodes
- {
- get
- {
- return _reducibleNodes;
- }
- }
+ private Color[] _palette;
+ private PaletteTable _paletteTable;
- ///
- /// Keep track of the previous node that was quantized
- ///
- /// The node last quantized
- protected void TrackPrevious(OctreeNode node)
- {
- _previousNode = node;
- }
+ ///
+ /// Convert the nodes in the octree to a palette with a maximum of colorCount colors
+ ///
+ /// The maximum number of colors
+ /// A list with the palettized colors
+ public List Palletize(int colorCount)
+ {
+ while (_leafCount > colorCount)
+ {
+ Reduce();
+ }
- private Color[] _palette;
- private PaletteTable paletteTable;
+ // Now palletize the nodes
+ var palette = new List(_leafCount);
+ int paletteIndex = 0;
- ///
- /// Convert the nodes in the octree to a palette with a maximum of colorCount colors
- ///
- /// The maximum number of colors
- /// A list with the palettized colors
- public List Palletize(int colorCount)
- {
- while (Leaves > colorCount)
- {
- Reduce();
- }
+ _root.ConstructPalette(palette, ref paletteIndex);
- // Now palettize the nodes
- List palette = new List(Leaves);
- int paletteIndex = 0;
+ // And return the palette
+ _palette = palette.ToArray();
+ _paletteTable = null;
- _root.ConstructPalette(palette, ref paletteIndex);
+ return palette;
+ }
- // And return the palette
- this._palette = palette.ToArray();
- this.paletteTable = null;
-
- return palette;
- }
+ ///
+ /// Get the palette index for the passed color
+ ///
+ public int GetPaletteIndex(int pixel)
+ {
+ var ret = _root.GetPaletteIndex(pixel, 0);
- ///
- /// Get the palette index for the passed color
- ///
- public int GetPaletteIndex(int pixel)
- {
- int ret = -1;
-
- ret = _root.GetPaletteIndex(pixel, 0);
+ if (ret < 0)
+ {
+ if (_paletteTable == null)
+ {
+ _paletteTable = new PaletteTable(_palette);
+ }
- if (ret < 0)
- {
- if (this.paletteTable == null)
- {
- this.paletteTable = new PaletteTable(this._palette);
- }
+ ret = _paletteTable.FindClosestPaletteIndex(Color.FromArgb(pixel));
+ }
- ret = this.paletteTable.FindClosestPaletteIndex(Color.FromArgb(pixel));
- }
+ return ret;
+ }
- return ret;
- }
+ ///
+ /// Mask used when getting the appropriate pixels for a given node
+ ///
+ private static readonly int[] Mask = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
- ///
- /// Mask used when getting the appropriate pixels for a given node
- ///
- private static int[] mask = new int[8] { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+ ///
+ /// The root of the octree
+ ///
+ private readonly OctreeNode _root;
- ///
- /// The root of the octree
- ///
- private OctreeNode _root;
+ ///
+ /// Number of leaves in the tree
+ ///
+ private int _leafCount;
- ///
- /// Number of leaves in the tree
- ///
- private int _leafCount;
+ ///
+ /// Array of reducible nodes
+ ///
+ private readonly OctreeNode[] _reducibleNodes;
- ///
- /// Array of reducible nodes
- ///
- private OctreeNode[] _reducibleNodes;
+ ///
+ /// Maximum number of significant bits in the image
+ ///
+ private readonly int _maxColorBits;
- ///
- /// Maximum number of significant bits in the image
- ///
- private int _maxColorBits;
+ ///
+ /// Store the last node quantized
+ ///
+ private OctreeNode _previousNode;
- ///
- /// Store the last node quantized
- ///
- private OctreeNode _previousNode;
+ ///
+ /// Cache the previous color quantized
+ ///
+ private int _previousColor;
- ///
- /// Cache the previous color quantized
- ///
- private int _previousColor;
+ ///
+ /// Class which encapsulates each node in the tree
+ ///
+ protected class OctreeNode
+ {
+ ///
+ /// Construct the node
+ ///
+ /// The level in the tree = 0 - 7
+ /// The number of significant color bits in the image
+ /// The tree to which this node belongs
+ public OctreeNode(int level, int colorBits, Octree octree)
+ {
+ // Construct the new node
+ _leaf = (level == colorBits);
- ///
- /// Class which encapsulates each node in the tree
- ///
- protected class OctreeNode
- {
- ///
- /// Construct the node
- ///
- /// The level in the tree = 0 - 7
- /// The number of significant color bits in the image
- /// The tree to which this node belongs
- public OctreeNode(int level, int colorBits, Octree octree)
- {
- // Construct the new node
- _leaf = (level == colorBits);
+ _red = 0;
+ _green = 0;
+ _blue = 0;
+ _pixelCount = 0;
- _red = 0;
- _green = 0;
- _blue = 0;
- _pixelCount = 0;
+ // If a leaf, increment the leaf count
+ if (_leaf)
+ {
+ octree._leafCount++;
+ _nextReducible = null;
+ _children = null;
+ }
+ else
+ {
+ // Otherwise add this to the reducible nodes
+ _nextReducible = octree.ReducibleNodes[level];
+ octree.ReducibleNodes[level] = this;
+ _children = new OctreeNode[8];
+ }
+ }
- // If a leaf, increment the leaf count
- if (_leaf)
- {
- octree.Leaves++;
- _nextReducible = null;
- _children = null;
- }
- else
- {
- // Otherwise add this to the reducible nodes
- _nextReducible = octree.ReducibleNodes[level];
- octree.ReducibleNodes[level] = this;
- _children = new OctreeNode[8];
- }
- }
+ ///
+ /// Add a color into the tree
+ ///
+ /// The color
+ /// The number of significant color bits
+ /// The level in the tree
+ /// The tree to which this node belongs
+ public void AddColor(int pixel, int colorBits, int level, Octree octree)
+ {
+ // Update the color information if this is a leaf
+ if (_leaf)
+ {
+ Increment(pixel);
- ///
- /// Add a color into the tree
- ///
- /// The color
- /// The number of significant color bits
- /// The level in the tree
- /// The tree to which this node belongs
- public void AddColor(int pixel, int colorBits, int level, Octree octree)
- {
- // Update the color information if this is a leaf
- if (_leaf)
- {
- Increment(pixel);
+ // Setup the previous node
+ octree.TrackPrevious(this);
+ }
+ else
+ {
+ // Go to the next level down in the tree
+ int shift = 7 - level;
+ int b = pixel & 0xFF;
+ int g = (pixel >> 8) & 0xFF;
+ int r = (pixel >> 16) & 0xFF;
+ int index = ((r & Mask[level]) >> (shift - 2)) |
+ ((g & Mask[level]) >> (shift - 1)) |
+ ((b & Mask[level]) >> (shift));
- // Setup the previous node
- octree.TrackPrevious(this);
- }
- else
- {
- // Go to the next level down in the tree
- int shift = 7 - level;
- int b = pixel & 0xFF;
- int g = (pixel >> 8) & 0xFF;
- int r = (pixel >> 16) & 0xFF;
- int index = ((r & mask[level]) >> (shift - 2)) |
- ((g & mask[level]) >> (shift - 1)) |
- ((b & mask[level]) >> (shift));
+ OctreeNode child = _children[index];
- OctreeNode child = _children[index];
+ if (null == child)
+ {
+ // Create a new child node & store in the array
+ child = new OctreeNode(level + 1, colorBits, octree);
+ _children[index] = child;
+ }
- if (null == child)
- {
- // Create a new child node & store in the array
- child = new OctreeNode(level + 1, colorBits, octree);
- _children[index] = child;
- }
+ // Add the color to the child node
+ child.AddColor(pixel, colorBits, level + 1, octree);
+ }
- // Add the color to the child node
- child.AddColor(pixel, colorBits, level + 1, octree);
- }
+ }
- }
+ ///
+ /// Get/Set the next reducible node
+ ///
+ public OctreeNode NextReducible => _nextReducible;
- ///
- /// Get/Set the next reducible node
- ///
- public OctreeNode NextReducible
- {
- get
- {
- return _nextReducible;
- }
+ ///
+ /// Reduce this node by removing all of its children
+ ///
+ /// The number of leaves removed
+ public int Reduce()
+ {
+ int children = 0;
+ _red = 0;
+ _green = 0;
+ _blue = 0;
- set
- {
- _nextReducible = value;
- }
- }
+ // Loop through all children and add their information to this node
+ for (int index = 0; index < 8; index++)
+ {
+ if (null != _children[index])
+ {
+ _red += _children[index]._red;
+ _green += _children[index]._green;
+ _blue += _children[index]._blue;
+ _pixelCount += _children[index]._pixelCount;
+ ++children;
+ _children[index] = null;
+ }
+ }
- ///
- /// Return the child nodes
- ///
- public OctreeNode[] Children
- {
- get
- {
- return _children;
- }
- }
+ // Now change this to a leaf node
+ _leaf = true;
- ///
- /// Reduce this node by removing all of its children
- ///
- /// The number of leaves removed
- public int Reduce()
- {
- int children = 0;
- _red = 0;
- _green = 0;
- _blue = 0;
+ // Return the number of nodes to decrement the leaf count by
+ return (children - 1);
+ }
- // Loop through all children and add their information to this node
- for (int index = 0; index < 8; index++)
- {
- if (null != _children[index])
- {
- _red += _children[index]._red;
- _green += _children[index]._green;
- _blue += _children[index]._blue;
- _pixelCount += _children[index]._pixelCount;
- ++children;
- _children[index] = null;
- }
- }
+ ///
+ /// Traverse the tree, building up the color palette
+ ///
+ /// The palette
+ /// The current palette index
+ public void ConstructPalette(List palette, ref int paletteIndex)
+ {
+ if (_leaf)
+ {
+ // Consume the next palette index
+ _paletteIndex = paletteIndex++;
- // Now change this to a leaf node
- _leaf = true;
+ // And set the color of the palette entry
+ int r = _red / _pixelCount;
+ int g = _green / _pixelCount;
+ int b = _blue / _pixelCount;
- // Return the number of nodes to decrement the leaf count by
- return(children - 1);
- }
+ palette.Add(Color.FromArgb(r, g, b));
+ }
+ else
+ {
+ // Loop through children looking for leaves
+ for (int index = 0; index < 8; index++)
+ {
+ if (null != _children[index])
+ {
+ _children[index].ConstructPalette(palette, ref paletteIndex);
+ }
+ }
+ }
+ }
- ///
- /// Traverse the tree, building up the color palette
- ///
- /// The palette
- /// The current palette index
- public void ConstructPalette(List palette, ref int paletteIndex)
- {
- if (_leaf)
- {
- // Consume the next palette index
- _paletteIndex = paletteIndex++;
+ ///
+ /// Return the palette index for the passed color
+ ///
+ public int GetPaletteIndex(int pixel, int level)
+ {
+ int paletteIndex = _paletteIndex;
- // And set the color of the palette entry
- int r = _red / _pixelCount;
- int g = _green / _pixelCount;
- int b = _blue / _pixelCount;
+ if (!_leaf)
+ {
+ int shift = 7 - level;
+ int b = pixel & 0xFF;
+ int g = (pixel >> 8) & 0xFF;
+ int r = (pixel >> 16) & 0xFF;
+ int index = ((r & Mask[level]) >> (shift - 2)) |
+ ((g & Mask[level]) >> (shift - 1)) |
+ ((b & Mask[level]) >> (shift));
- palette.Add(Color.FromArgb(r, g, b));
- }
- else
- {
- // Loop through children looking for leaves
- for (int index = 0; index < 8; index++)
- {
- if (null != _children[index])
- {
- _children[index].ConstructPalette(palette, ref paletteIndex);
- }
- }
- }
- }
+ if (null != _children[index])
+ {
+ paletteIndex = _children[index].GetPaletteIndex(pixel, level + 1);
+ }
+ else
+ {
+ paletteIndex = -1;
+ }
+ }
- ///
- /// Return the palette index for the passed color
- ///
- public int GetPaletteIndex(int pixel, int level)
- {
- int paletteIndex = _paletteIndex;
+ return paletteIndex;
+ }
- if (!_leaf)
- {
- int shift = 7 - level;
- int b = pixel & 0xFF;
- int g = (pixel >> 8) & 0xFF;
- int r = (pixel >> 16) & 0xFF;
- int index = ((r & mask[level]) >> (shift - 2)) |
- ((g & mask[level]) >> (shift - 1)) |
- ((b & mask[level]) >> (shift));
+ ///
+ /// Increment the pixel count and add to the color information
+ ///
+ public void Increment(int pixel)
+ {
+ ++_pixelCount;
+ int b = pixel & 0xFF;
+ int g = (pixel >> 8) & 0xFF;
+ int r = (pixel >> 16) & 0xFF;
+ _red += r;
+ _green += g;
+ _blue += b;
+ }
- if (null != _children[index])
- {
- paletteIndex = _children[index].GetPaletteIndex(pixel, level + 1);
- }
- else
- {
- paletteIndex = -1;
- }
- }
+ ///
+ /// Flag indicating that this is a leaf node
+ ///
+ private bool _leaf;
- return paletteIndex;
- }
+ ///
+ /// Number of pixels in this node
+ ///
+ private int _pixelCount;
- ///
- /// Increment the pixel count and add to the color information
- ///
- public void Increment(int pixel)
- {
- ++_pixelCount;
- int b = pixel&0xFF;
- int g = (pixel>>8) & 0xFF;
- int r = (pixel >> 16) & 0xFF;
- _red += r;
- _green += g;
- _blue += b;
- }
+ ///
+ /// Red component
+ ///
+ private int _red;
- ///
- /// Flag indicating that this is a leaf node
- ///
- private bool _leaf;
+ ///
+ /// Green Component
+ ///
+ private int _green;
- ///
- /// Number of pixels in this node
- ///
- private int _pixelCount;
+ ///
+ /// Blue component
+ ///
+ private int _blue;
- ///
- /// Red component
- ///
- private int _red;
+ ///
+ /// Pointers to any child nodes
+ ///
+ private readonly OctreeNode[] _children;
- ///
- /// Green Component
- ///
- private int _green;
+ ///
+ /// Pointer to next reducible node
+ ///
+ private readonly OctreeNode _nextReducible;
- ///
- /// Blue component
- ///
- private int _blue;
-
- ///
- /// Pointers to any child nodes
- ///
- private OctreeNode[] _children;
-
- ///
- /// Pointer to next reducible node
- ///
- private OctreeNode _nextReducible;
-
- ///
- /// The index of this node in the palette
- ///
- private int _paletteIndex;
- }
- }
- }
+ ///
+ /// The index of this node in the palette
+ ///
+ private int _paletteIndex;
+ }
+ }
+ }
}
diff --git a/BizHawk.Client.EmuHawk/AVOut/Quantize/PaletteTable.cs b/BizHawk.Client.EmuHawk/AVOut/Quantize/PaletteTable.cs
index 367e73319f..8b11d20bfb 100644
--- a/BizHawk.Client.EmuHawk/AVOut/Quantize/PaletteTable.cs
+++ b/BizHawk.Client.EmuHawk/AVOut/Quantize/PaletteTable.cs
@@ -12,66 +12,58 @@
// Copyright (C) Joshua Bell
/////////////////////////////////////////////////////////////////////////////////
-//Bizhawk says: adapted from https://github.com/inexorabletash/PcxFileType/blob/master/Quantize
+//BizHawk says: adapted from https://github.com/inexorabletash/PcxFileType/blob/master/Quantize
using System.Drawing;
namespace BizHawk.Client.EmuHawk
{
- public sealed class PaletteTable
- {
- private Color[] palette;
+ public sealed class PaletteTable
+ {
+ private readonly Color[] _palette;
- public Color this[int index]
- {
- get
- {
- return this.palette[index];
- }
+ public Color this[int index]
+ {
+ get => _palette[index];
+ set => _palette[index] = value;
+ }
- set
- {
- this.palette[index] = value;
- }
- }
+ private int GetDistanceSquared(Color a, Color b)
+ {
+ int dsq = 0; // delta squared
- private int GetDistanceSquared(Color a, Color b)
- {
- int dsq = 0; // delta squared
- int v;
+ var v = a.B - b.B;
+ dsq += v * v;
+ v = a.G - b.G;
+ dsq += v * v;
+ v = a.R - b.R;
+ dsq += v * 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;
+ }
- return dsq;
- }
+ public int FindClosestPaletteIndex(Color pixel)
+ {
+ int dsqBest = int.MaxValue;
+ int ret = 0;
- public int FindClosestPaletteIndex(Color pixel)
- {
- int dsqBest = int.MaxValue;
- int ret = 0;
+ for (int i = 0; i < _palette.Length; ++i)
+ {
+ int dsq = GetDistanceSquared(_palette[i], pixel);
- for (int i = 0; i < this.palette.Length; ++i)
- {
- int dsq = GetDistanceSquared(this.palette[i], pixel);
+ if (dsq < dsqBest)
+ {
+ dsqBest = dsq;
+ ret = i;
+ }
+ }
- if (dsq < dsqBest)
- {
- dsqBest = dsq;
- ret = i;
- }
- }
+ return ret;
+ }
- return ret;
- }
-
- public PaletteTable(Color[] palette)
- {
- this.palette = (Color[])palette.Clone();
- }
- }
+ public PaletteTable(Color[] palette)
+ {
+ _palette = (Color[])palette.Clone();
+ }
+ }
}
diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings
index f906baeba0..bfea204500 100644
--- a/BizHawk.sln.DotSettings
+++ b/BizHawk.sln.DotSettings
@@ -318,11 +318,14 @@
True
True
True
+ True
True
True
True
True
True
+ True
+ True
True
True
True
@@ -336,6 +339,7 @@
True
True
True
+ True
True
True
True