Klasse OctreeQuantization

java.lang.Object
libsidplay.components.mos656x.OctreeQuantization

class OctreeQuantization extends Object
Classic octree color quantization algorithm. Given a histogram as packed color value and count of occurences, computes and returns the optimal palette when requested from the state of the tree.

The class operates on 24-bit colors. The components are called red, green and blue, but they can be anything. The components should be in some coding that compensates for eye's different sensitivity for errors in each component, as the color distance calculation and quantization assumes so.

Autor:
Antti Lankila
  • Felddetails

    • MAX_DEPTH

      private static final int MAX_DEPTH
      Bits per component
      Siehe auch:
    • MAX_BUCKET_DEPTH

      private static final int MAX_BUCKET_DEPTH
      Bits per component in color lookup bucket
      Siehe auch:
    • COMPONENT_MASK

      private static final int COMPONENT_MASK
      Siehe auch:
    • buckets

      Fast color lookup in least-squares sense- Each color is put in bucket.
    • root

      The start of quantization tree.
    • leaves

      protected final Set<OctreeQuantization.Node> leaves
      List of current leaf nodes. leaf.parents are targets for reduction.
    • max

      private final int max
      Size of palette to compute.
  • Konstruktordetails

    • OctreeQuantization

      protected OctreeQuantization(int max)
      Quantizer instance. Make a new quantizer for specific number of colors, add colors, and finally ask for palette.
      Parameter:
      max - size of palette to quantize to.
  • Methodendetails

    • addColor

      protected void addColor(int color, int weight)
      Add a color to quantization algorithm.
      Parameter:
      color - The packed color to add.
      weight - Number of occurences of this color. (How important it is.)
    • quantize

      private void quantize()
      Actually quantize the palette. Called when a palette is requested.
    • getPalette

      protected int[] getPalette()
      Returns the optimized palette of constructor-time specified length. Pads with 0 if more colors were requested than existed in source material.
    • bucketStore

      private void bucketStore(OctreeQuantization.Node node)
      Generate color buckets for faster color lookup. Each color is distributed to the buckets at granularity of 2 bits per component (4 * 4 * 4 = 64 buckets in total).
      Parameter:
      node -
    • lookup

      public int lookup(int color)
      Do a nearest-node scan looking for best match.
      Parameter:
      color - Color to get the best match of.
      Gibt zurück:
      best node from simple scan