Package org.apache.commons.imaging.palette

## Class PaletteFactory

- java.lang.Object
- - org.apache.commons.imaging.palette.PaletteFactory

-     public class PaletteFactory
      extends Object

  Factory for creating palettes.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `COMPONENTS` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `PaletteFactory()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `countTransparentColors​(BufferedImage src)` |
    `int` | `countTrasparentColors​(int[] rgbs)` |
    `boolean` | `hasTransparency​(BufferedImage src)` |
    `boolean` | `hasTransparency​(BufferedImage src, int threshold)` |
    `boolean` | `isGrayscale​(BufferedImage src)` |
    `Palette` | `makeExactRgbPaletteFancy​(BufferedImage src)` | Builds an exact complete opaque palette containing all the colors in `src`, using an algorithm that is faster than makeExactRgbPaletteSimple(java.awt.image.BufferedImage, int) for large images but uses 2 mebibytes of working memory.
    `SimplePalette` | `makeExactRgbPaletteSimple​(BufferedImage src, int max)` | Builds an exact complete opaque palette containing all the colors in `src`, and fails by returning `null` if there are more than `max` colors necessary to do this.
    `Palette` | `makeQuantizedRgbaPalette​(BufferedImage src, boolean transparent, int max)` | Builds an inexact possibly translucent palette of at most `max` colors in `src` using the traditional Median Cut algorithm.
    `Palette` | `makeQuantizedRgbPalette​(BufferedImage src, int max)` | Builds an inexact opaque palette of at most `max` colors in `src` using a variation of the Median Cut algorithm.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### COMPONENTS

          public static final int COMPONENTS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PaletteFactory

          public PaletteFactory()

  - ### Method Detail

    - #### makeExactRgbPaletteFancy

          public Palette makeExactRgbPaletteFancy​(BufferedImage src)

      Builds an exact complete opaque palette containing all the colors in `src`, using an algorithm that is faster than makeExactRgbPaletteSimple(java.awt.image.BufferedImage, int) for large images but uses 2 mebibytes of working memory. Treats all the colors as opaque.
      Parameters:
        `src` - the image whose palette to build
      Returns:
        the palette

    - #### makeQuantizedRgbPalette

          public Palette makeQuantizedRgbPalette​(BufferedImage src,
                                                 int max)

      Builds an inexact opaque palette of at most `max` colors in `src` using a variation of the Median Cut algorithm. Accurate to 6 bits per component, and works by splitting the color bounding box most heavily populated by colors along the component which splits the colors in that box most evenly.
      Parameters:
        `src` - the image whose palette to build
        `max` - the maximum number of colors the palette can contain
      Returns:
        the palette of at most `max` colors

    - #### makeQuantizedRgbaPalette

          public Palette makeQuantizedRgbaPalette​(BufferedImage src,
                                                  boolean transparent,
                                                  int max)
                                           throws ImageWriteException

      Builds an inexact possibly translucent palette of at most `max` colors in `src` using the traditional Median Cut algorithm. Color bounding boxes are split along the longest axis, with each step splitting the box. All bits in each component are used. The Algorithm is slower and seems exact than makeQuantizedRgbPalette(BufferedImage, int).
      Parameters:
        `src` - the image whose palette to build
        `transparent` - whether to consider the alpha values
        `max` - the maximum number of colors the palette can contain
      Returns:
        the palette of at most `max` colors
      Throws:
        `ImageWriteException` - if it fails to process the palette

    - #### makeExactRgbPaletteSimple

          public SimplePalette makeExactRgbPaletteSimple​(BufferedImage src,
                                                         int max)

      Builds an exact complete opaque palette containing all the colors in `src`, and fails by returning `null` if there are more than `max` colors necessary to do this.
      Parameters:
        `src` - the image whose palette to build
        `max` - the maximum number of colors the palette can contain
      Returns:
        the complete palette of `max` or less colors, or `null` if more than `max` colors are necessary

    - #### isGrayscale

          public boolean isGrayscale​(BufferedImage src)

    - #### hasTransparency

          public boolean hasTransparency​(BufferedImage src)

    - #### hasTransparency

          public boolean hasTransparency​(BufferedImage src,
                                         int threshold)

    - #### countTrasparentColors

          public int countTrasparentColors​(int[] rgbs)

    - #### countTransparentColors

          public int countTransparentColors​(BufferedImage src)