+ +
+ +

Class QualityPalette

+
+
java.lang.Object +
com.github.tommyettinger.anim8.PaletteReducer +
com.github.tommyettinger.anim8.QualityPalette
+
+
+
+
+
public class QualityPalette +extends PaletteReducer
+
This is just like PaletteReducer, except that it uses a higher-quality, slower color difference calculation + when creating a palette. This calculates the difference between colors using Euclidean distance in the Oklab color + space, rather than what PaletteReducer uses, which is Euclidean distance in RGB. +
+ A quirk of how this calculates the color difference between colors A and B is that it avoids converting both A and B + to Oklab. Instead, it gets the absolute value of the difference between the RGB channels, and converts that to Oklab, + then just gets its magnitude. For identical colors, the difference should be 0. For colors that are only slightly + different, the difference may be roughly 800, and for the most different colors, the difference is over 200000. +
+ This tends to use fewer very-dark colors than PaletteReducer or FastPalette, but seems to avoid the problem + case for those two where if a maximum of n colors are requested, fewer than n unique colors might be found for the + palette. If you use the HueWise methods, those will probably still do + poorly at separating out enough different colors.
+
+
+ +
+
+
    + +
  • +
    +

    Constructor Details

    +
      +
    • +
      +

      QualityPalette

      +
      public QualityPalette()
      +
      Constructs a default QualityPalette that uses the "Aurora" 255-color-plus-transparent palette. + Note that this uses a more-detailed and higher-quality metric than you would get by just specifying + new QualityPalette(PaletteReducer.AURORA); this metric would be too slow to calculate at + runtime, but as pre-calculated data it works very well.
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(int[] rgbaPalette)
      +
      Constructs a QualityPalette that uses the given array of RGBA8888 ints as a palette (see PaletteReducer.exact(int[]) + for more info).
      +
      +
      Parameters:
      +
      rgbaPalette - an array of RGBA8888 ints to use as a palette
      +
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(int[] rgbaPalette, + int limit)
      +
      Constructs a QualityPalette that uses the given array of RGBA8888 ints as a palette (see + PaletteReducer.exact(int[], int) for more info).
      +
      +
      Parameters:
      +
      rgbaPalette - an array of RGBA8888 ints to use as a palette
      +
      limit - how many int items to use from rgbaPalette (this always starts at index 0)
      +
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(com.badlogic.gdx.graphics.Color[] colorPalette)
      +
      Constructs a QualityPalette that uses the given array of Color objects as a palette (see PaletteReducer.exact(Color[]) + for more info).
      +
      +
      Parameters:
      +
      colorPalette - an array of Color objects to use as a palette
      +
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(com.badlogic.gdx.graphics.Color[] colorPalette, + int limit)
      +
      Constructs a QualityPalette that uses the given array of Color objects as a palette (see + PaletteReducer.exact(Color[], int) for more info).
      +
      +
      Parameters:
      +
      colorPalette - an array of Color objects to use as a palette
      +
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(com.badlogic.gdx.graphics.Pixmap pixmap)
      +
      Constructs a QualityPalette that analyzes the given Pixmap for color count and frequency to generate a palette + (see PaletteReducer.analyze(Pixmap) for more info).
      +
      +
      Parameters:
      +
      pixmap - a Pixmap to analyze in detail to produce a palette
      +
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.Pixmap> pixmaps)
      +
      Constructs a QualityPalette that analyzes the given Pixmaps for color count and frequency to generate a palette + (see PaletteReducer.analyze(Array) for more info).
      +
      +
      Parameters:
      +
      pixmaps - an Array of Pixmap to analyze in detail to produce a palette
      +
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(int[] palette, + byte[] preload)
      +
      Constructs a QualityPalette that uses the given array of RGBA8888 ints as a palette (see + PaletteReducer.exact(int[], byte[]) for more info) and an encoded byte array to use to look up pre-loaded color data. + You can use PaletteReducer.writePreloadFile(FileHandle) to write the preload data for a given QualityPalette, and + PaletteReducer.loadPreloadFile(FileHandle) to get a byte array of preload data from a previously-written file.
      +
      +
      Parameters:
      +
      palette - an array of RGBA8888 ints to use as a palette
      +
      preload - a byte array containing preload data
      +
      +
      +
    • +
    • +
      +

      QualityPalette

      +
      public QualityPalette(com.badlogic.gdx.graphics.Pixmap pixmap, + double threshold)
      +
      Constructs a QualityPalette that analyzes the given Pixmap for color count and frequency to generate a palette + (see PaletteReducer.analyze(Pixmap, double) for more info).
      +
      +
      Parameters:
      +
      pixmap - a Pixmap to analyze in detail to produce a palette
      +
      threshold - the minimum difference between colors required to put them in the palette (default 100)
      +
      +
      +
    • +
    +
    +
  • + +
  • +
    +

    Method Details

    +
      +
    • +
      +

      differenceMatch

      +
      public double differenceMatch(int color1, + int color2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. + If you want to change this, just change differenceMatch(int, int, int, int, int, int), which this + calls.
      +
      +
      Overrides:
      +
      differenceMatch in class PaletteReducer
      +
      Parameters:
      +
      color1 - the first color, as an RGBA8888 int
      +
      color2 - the second color, as an RGBA8888 int
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceAnalyzing

      +
      public double differenceAnalyzing(int color1, + int color2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. + If you want to change this, just change differenceAnalyzing(int, int, int, int, int, int), which this + calls.
      +
      +
      Overrides:
      +
      differenceAnalyzing in class PaletteReducer
      +
      Parameters:
      +
      color1 - the first color, as an RGBA8888 int
      +
      color2 - the second color, as an RGBA8888 int
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceHW

      +
      public double differenceHW(int color1, + int color2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. + If you want to change this, just change differenceHW(int, int, int, int, int, int), which this calls.
      +
      +
      Overrides:
      +
      differenceHW in class PaletteReducer
      +
      Parameters:
      +
      color1 - the first color, as an RGBA8888 int
      +
      color2 - the second color, as an RGBA8888 int
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceMatch

      +
      public double differenceMatch(int color1, + int r2, + int g2, + int b2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. + If you want to change this, just change differenceMatch(int, int, int, int, int, int), which this calls.
      +
      +
      Overrides:
      +
      differenceMatch in class PaletteReducer
      +
      Parameters:
      +
      color1 - the first color, as an RGBA8888 int
      +
      r2 - red of the second color, from 0 to 255
      +
      g2 - green of the second color, from 0 to 255
      +
      b2 - blue of the second color, from 0 to 255
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceAnalyzing

      +
      public double differenceAnalyzing(int color1, + int r2, + int g2, + int b2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. If + you want to change this, just change differenceAnalyzing(int, int, int, int, int, int), which this + calls.
      +
      +
      Overrides:
      +
      differenceAnalyzing in class PaletteReducer
      +
      Parameters:
      +
      color1 - the first color, as an RGBA8888 int
      +
      r2 - red of the second color, from 0 to 255
      +
      g2 - green of the second color, from 0 to 255
      +
      b2 - blue of the second color, from 0 to 255
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceHW

      +
      public double differenceHW(int color1, + int r2, + int g2, + int b2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. If + you want to change this, just change differenceHW(int, int, int, int, int, int), which this calls.
      +
      +
      Overrides:
      +
      differenceHW in class PaletteReducer
      +
      Parameters:
      +
      color1 - the first color, as an RGBA8888 int
      +
      r2 - red of the second color, from 0 to 255
      +
      g2 - green of the second color, from 0 to 255
      +
      b2 - blue of the second color, from 0 to 255
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceMatch

      +
      public double differenceMatch(int r1, + int g1, + int b1, + int r2, + int g2, + int b2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. + This can be changed in an extending (possibly anonymous) class to use a different squared metric. This is used + when matching to an existing palette, as with PaletteReducer.exact(int[]). +
      + This uses Euclidean distance between the RGB colors in the 256-edge-length color cube. This does absolutely + nothing fancy with the colors, but this approach does well often. The same code is used by + differenceMatch(int, int, int, int, int, int), + differenceAnalyzing(int, int, int, int, int, int), and + differenceHW(int, int, int, int, int, int), but classes can (potentially anonymously) subclass + QualityPalette to change one, some, or all of these methods. The other difference methods call the 6-argument + overloads, so the override only needs to affect one method.
      +
      +
      Overrides:
      +
      differenceMatch in class PaletteReducer
      +
      Parameters:
      +
      r1 - red of the first color, from 0 to 255
      +
      g1 - green of the first color, from 0 to 255
      +
      b1 - blue of the first color, from 0 to 255
      +
      r2 - red of the second color, from 0 to 255
      +
      g2 - green of the second color, from 0 to 255
      +
      b2 - blue of the second color, from 0 to 255
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceAnalyzing

      +
      public double differenceAnalyzing(int r1, + int g1, + int b1, + int r2, + int g2, + int b2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. + This can be changed in an extending (possibly anonymous) class to use a different squared metric. This is used + when analyzing an image, as with PaletteReducer.analyze(Pixmap). +
      + This uses Euclidean distance between the RGB colors in the 256-edge-length color cube. This does absolutely + nothing fancy with the colors, but this approach does well often. The same code is used by + differenceMatch(int, int, int, int, int, int), + differenceAnalyzing(int, int, int, int, int, int), and + differenceHW(int, int, int, int, int, int), but classes can (potentially anonymously) subclass + QualityPalette to change one, some, or all of these methods. The other difference methods call the 6-argument + overloads, so the override only needs to affect one method.
      +
      +
      Overrides:
      +
      differenceAnalyzing in class PaletteReducer
      +
      Parameters:
      +
      r1 - red of the first color, from 0 to 255
      +
      g1 - green of the first color, from 0 to 255
      +
      b1 - blue of the first color, from 0 to 255
      +
      r2 - red of the second color, from 0 to 255
      +
      g2 - green of the second color, from 0 to 255
      +
      b2 - blue of the second color, from 0 to 255
      +
      Returns:
      +
      the squared Euclidean distance between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      differenceHW

      +
      public double differenceHW(int r1, + int g1, + int b1, + int r2, + int g2, + int b2)
      +
      Gets a squared estimate of how different two colors are, with noticeable differences typically at least 25. + This can be changed in an extending (possibly anonymous) class to use a different squared metric. This is used + when analyzing an image with PaletteReducer.analyzeHueWise(Pixmap, double, int) . +
      + This uses Euclidean distance between the RGB colors in the 256-edge-length color cube. This does absolutely + nothing fancy with the colors, but this approach does well often. The same code is used by + differenceMatch(int, int, int, int, int, int), + differenceAnalyzing(int, int, int, int, int, int), and + differenceHW(int, int, int, int, int, int), but classes can (potentially anonymously) subclass + QualityPalette to change one, some, or all of these methods. The other difference methods call the 6-argument + overloads, so the override only needs to affect one method.
      +
      +
      Overrides:
      +
      differenceHW in class PaletteReducer
      +
      Parameters:
      +
      r1 - red of the first color, from 0 to 255
      +
      g1 - green of the first color, from 0 to 255
      +
      b1 - blue of the first color, from 0 to 255
      +
      r2 - red of the second color, from 0 to 255
      +
      g2 - green of the second color, from 0 to 255
      +
      b2 - blue of the second color, from 0 to 255
      +
      Returns:
      +
      the squared Euclidean distance, between colors 1 and 2
      +
      +
      +
    • +
    • +
      +

      forwardLight

      +
      public static double forwardLight(double L)
      +
      Changes the curve of a requested L value so that it matches the internally-used curve. This takes a curve with a + very-dark area similar to sRGB (a very small one), and makes it significantly larger. This is typically used on + "to Oklab" conversions.
      +
      +
      Parameters:
      +
      L - lightness, from 0 to 1 inclusive
      +
      Returns:
      +
      an adjusted L value that can be used internally
      +
      +
      +
    • +
    • +
      +

      reverseLight

      +
      public static double reverseLight(double L)
      +
      Changes the curve of the internally-used lightness when it is output to another format. This makes the very-dark + area smaller, matching (kind-of) the curve that the standard sRGB lightness uses. This is typically used on "from + Oklab" conversions.
      +
      +
      Parameters:
      +
      L - lightness, from 0 to 1 inclusive
      +
      Returns:
      +
      an adjusted L value that can be fed into a conversion to RGBA or something similar
      +
      +
      +
    • +
    • +
      +

      difference

      +
      public double difference(int color1, + int color2)
      +
      +
    • +
    • +
      +

      difference

      +
      public double difference(int color1, + int r2, + int g2, + int b2)
      +
      +
    • +
    • +
      +

      difference

      +
      public double difference(int r1, + int g1, + int b1, + int r2, + int g2, + int b2)
      +
      +
    • +
    +
    +
  • +
+
+ +