Class OctTreeQuantizer

java.lang.Object
bdsup2sub.tools.OctTreeQuantizer

class OctTreeQuantizer extends Object
An image Quantizer based on the Octree algorithm. This is a very basic implementation at present and could be much improved by picking the nodes to reduce more carefully (i.e. not completely at random).
  • Field Details

    • MAX_LEVEL

      private static final int MAX_LEVEL
      The greatest depth the tree is allowed to reach
      See Also:
    • root

    • reduceColors

      private int reduceColors
    • maximumColors

      private int maximumColors
    • colors

      private int colors
    • colorList

      private Vector[] colorList
  • Constructor Details

    • OctTreeQuantizer

      public OctTreeQuantizer()
  • Method Details

    • setup

      public void setup(int numColors)
      Initialize the quantizer. This should be called before adding any pixels.
      Parameters:
      numColors - Number of colors we're quantizing to.
    • addPixels

      public void addPixels(int[] pixels, int offset, int count)
      Add pixels to the quantizer.
      Parameters:
      pixels - Array of ARGB pixels
      offset - Offset into the array
      count - Count of pixels
    • getIndexForColor

      public int getIndexForColor(int argb)
      Get the color table index for a color.
      Parameters:
      argb - Color in ARGB format
      Returns:
      Index of color in table
    • insertColor

      private void insertColor(int rgb)
    • reduceTree

      private void reduceTree(int numColors)
    • buildColorTable

      public int[] buildColorTable()
      Build the color table.
      Returns:
      Color table
    • buildColorTable

      public void buildColorTable(int[] pixels, int[] table)
      A quick way to use the quantizer. Just create a table the right size and pass in the pixels.
      Parameters:
      pixels - Integer array containing the pixels
      table - Output color table
    • buildColorTable

      private int buildColorTable(OctTreeQuantizer.OctTreeNode node, int[] table, int index)
      Build color table
      Parameters:
      node - Octree node
      table - Color table
      index - Index
      Returns:
      Index