Class IndexImage

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  IndexImage.Counter
      Used to track a color and the number of pixels of that colors
      private static class  IndexImage.Cube
      Used to define a cube of the color space.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private IndexImage()
      You cannot create this
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      private static void applyAlpha​(java.awt.image.BufferedImage pImage, java.awt.image.BufferedImage pAlpha)
      Applies the alpha-component of the alpha image to the given image.
      private static java.awt.image.IndexColorModel createIndexColorModel​(java.awt.image.BufferedImage pImage, int pNumberOfColors, int pHints)
      Creates an IndexColorModel from the given image, using an adaptive palette.
      private static java.awt.image.BufferedImage createSolid​(java.awt.image.BufferedImage pOriginal, java.awt.Color pBackground)
      Creates a copy of the given image, with a solid background
      static java.awt.image.IndexColorModel getIndexColorModel​(java.awt.Image pImage, int pNumberOfColors, boolean pFast)
      Deprecated.
      Use getIndexColorModel(Image,int,int) instead! This version will be removed in a later version of the API.
      static java.awt.image.IndexColorModel getIndexColorModel​(java.awt.Image pImage, int pNumberOfColors, int pHints)
      Gets an IndexColorModel from the given image.
      static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.
      static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage, int pNumberOfColors, int pHints)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.
      static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage, int pNumberOfColors, java.awt.Color pMatte, int pHints)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.
      static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage, java.awt.image.IndexColorModel pColors, int pHints)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.
      static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage, java.awt.image.IndexColorModel pColors, java.awt.Color pMatte, int pHints)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.
      static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage, java.awt.Image pPalette, int pHints)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.
      static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage, java.awt.Image pPalette, java.awt.Color pMatte, int pHints)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.
      private static boolean isFast​(int pHints)
      Tests if the hint COLOR_SELECTION_QUALITY is not set.
      (package private) static boolean isTransparent​(int pHints)
      Tests if the hint TRANSPARENCY_BITMASK or TRANSPARENCY_TRANSLUCENT is set.
      static void main​(java.lang.String[] pArgs)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DITHER_DEFAULT

        public static final int DITHER_DEFAULT
        Java default dither
        See Also:
        Constant Field Values
      • DITHER_DIFFUSION

        public static final int DITHER_DIFFUSION
        Error diffusion dither
        See Also:
        Constant Field Values
      • DITHER_DIFFUSION_ALTSCANS

        public static final int DITHER_DIFFUSION_ALTSCANS
        Error diffusion dither with alternating scans
        See Also:
        Constant Field Values
      • COLOR_SELECTION_MASK

        protected static final int COLOR_SELECTION_MASK
        Color Selection mask
        See Also:
        Constant Field Values
      • COLOR_SELECTION_DEFAULT

        public static final int COLOR_SELECTION_DEFAULT
        Default color selection
        See Also:
        Constant Field Values
      • COLOR_SELECTION_FAST

        public static final int COLOR_SELECTION_FAST
        Prioritize speed
        See Also:
        Constant Field Values
      • COLOR_SELECTION_QUALITY

        public static final int COLOR_SELECTION_QUALITY
        Prioritize quality
        See Also:
        Constant Field Values
      • TRANSPARENCY_MASK

        protected static final int TRANSPARENCY_MASK
        Transparency mask
        See Also:
        Constant Field Values
      • TRANSPARENCY_DEFAULT

        public static final int TRANSPARENCY_DEFAULT
        Default transparency (none)
        See Also:
        Constant Field Values
      • TRANSPARENCY_OPAQUE

        public static final int TRANSPARENCY_OPAQUE
        Discard any alpha information
        See Also:
        Constant Field Values
      • TRANSPARENCY_BITMASK

        public static final int TRANSPARENCY_BITMASK
        Convert alpha to bitmask
        See Also:
        Constant Field Values
      • TRANSPARENCY_TRANSLUCENT

        protected static final int TRANSPARENCY_TRANSLUCENT
        Keep original alpha (not supported yet)
        See Also:
        Constant Field Values
    • Constructor Detail

      • IndexImage

        private IndexImage()
        You cannot create this
    • Method Detail

      • getIndexColorModel

        @Deprecated
        public static java.awt.image.IndexColorModel getIndexColorModel​(java.awt.Image pImage,
                                                                        int pNumberOfColors,
                                                                        boolean pFast)
        Deprecated.
        Use getIndexColorModel(Image,int,int) instead! This version will be removed in a later version of the API.
        Parameters:
        pImage - the image to get IndexColorModel from
        pNumberOfColors - the number of colors for the IndexColorModel
        pFast - true if fast
        Returns:
        an IndexColorModel
        See Also:
        getIndexColorModel(Image,int,int)
      • getIndexColorModel

        public static java.awt.image.IndexColorModel getIndexColorModel​(java.awt.Image pImage,
                                                                        int pNumberOfColors,
                                                                        int pHints)
                                                                 throws ImageConversionException
        Gets an IndexColorModel from the given image. If the image has an IndexColorModel, this will be returned. Otherwise, an IndexColorModel is created, using an adaptive palette.
        Parameters:
        pImage - the image to get IndexColorModel from
        pNumberOfColors - the number of colors for the IndexColorModel
        pHints - one of COLOR_SELECTION_FAST, COLOR_SELECTION_QUALITY or COLOR_SELECTION_DEFAULT.
        Returns:
        The IndexColorModel from the given image, or a newly created IndexColorModel using an adaptive palette.
        Throws:
        ImageConversionException - if an exception occurred during color model extraction.
      • createIndexColorModel

        private static java.awt.image.IndexColorModel createIndexColorModel​(java.awt.image.BufferedImage pImage,
                                                                            int pNumberOfColors,
                                                                            int pHints)
        Creates an IndexColorModel from the given image, using an adaptive palette.
        Parameters:
        pImage - the image to get IndexColorModel from
        pNumberOfColors - the number of colors for the IndexColorModel
        pHints - use fast mode if possible (might give slightly lower quality)
        Returns:
        a new IndexColorModel created from the given image
      • getIndexedImage

        public static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage)
        Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. Generating an adaptive palette (8 bit) from the color data in the image, and uses default dither.

        The image returned is a new image, the input image is not modified.

        Parameters:
        pImage - the BufferedImage to index and get color information from.
        Returns:
        the indexed BufferedImage. The image will be of type BufferedImage.TYPE_BYTE_INDEXED, and use an IndexColorModel.
        See Also:
        BufferedImage.TYPE_BYTE_INDEXED, IndexColorModel
      • isFast

        private static boolean isFast​(int pHints)
        Tests if the hint COLOR_SELECTION_QUALITY is not set.
        Parameters:
        pHints - hints
        Returns:
        true if the hint COLOR_SELECTION_QUALITY is not set.
      • isTransparent

        static boolean isTransparent​(int pHints)
        Tests if the hint TRANSPARENCY_BITMASK or TRANSPARENCY_TRANSLUCENT is set.
        Parameters:
        pHints - hints
        Returns:
        true if the hint TRANSPARENCY_BITMASK or TRANSPARENCY_TRANSLUCENT is set.
      • getIndexedImage

        public static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage,
                                                                   java.awt.Image pPalette,
                                                                   java.awt.Color pMatte,
                                                                   int pHints)
                                                            throws ImageConversionException
        Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. If the palette image uses an IndexColorModel, this will be used. Otherwise, generating an adaptive palette (8 bit) from the given palette image. Dithering, transparency and color selection is controlled with the pHintsparameter.

        The image returned is a new image, the input image is not modified.

        Parameters:
        pImage - the BufferedImage to index
        pPalette - the Image to read color information from
        pMatte - the background color, used where the original image was transparent
        pHints - hints that control output quality and speed.
        Returns:
        the indexed BufferedImage. The image will be of type BufferedImage.TYPE_BYTE_INDEXED or BufferedImage.TYPE_BYTE_BINARY, and use an IndexColorModel.
        Throws:
        ImageConversionException - if an exception occurred during color model extraction.
        See Also:
        DITHER_DIFFUSION, DITHER_NONE, COLOR_SELECTION_FAST, COLOR_SELECTION_QUALITY, TRANSPARENCY_OPAQUE, TRANSPARENCY_BITMASK, BufferedImage.TYPE_BYTE_INDEXED, BufferedImage.TYPE_BYTE_BINARY, IndexColorModel
      • getIndexedImage

        public static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage,
                                                                   int pNumberOfColors,
                                                                   java.awt.Color pMatte,
                                                                   int pHints)
        Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. Generating an adaptive palette with the given number of colors. Dithering, transparency and color selection is controlled with the pHints parameter.

        The image returned is a new image, the input image is not modified.

        Parameters:
        pImage - the BufferedImage to index
        pNumberOfColors - the number of colors for the image
        pMatte - the background color, used where the original image was transparent
        pHints - hints that control output quality and speed.
        Returns:
        the indexed BufferedImage. The image will be of type BufferedImage.TYPE_BYTE_INDEXED or BufferedImage.TYPE_BYTE_BINARY, and use an IndexColorModel.
        See Also:
        DITHER_DIFFUSION, DITHER_NONE, COLOR_SELECTION_FAST, COLOR_SELECTION_QUALITY, TRANSPARENCY_OPAQUE, TRANSPARENCY_BITMASK, BufferedImage.TYPE_BYTE_INDEXED, BufferedImage.TYPE_BYTE_BINARY, IndexColorModel
      • getIndexedImage

        public static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage,
                                                                   java.awt.image.IndexColorModel pColors,
                                                                   java.awt.Color pMatte,
                                                                   int pHints)
        Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. Using the supplied IndexColorModel's palette. Dithering, transparency and color selection is controlled with the pHints parameter.

        The image returned is a new image, the input image is not modified.

        Parameters:
        pImage - the BufferedImage to index
        pColors - an IndexColorModel containing the color information
        pMatte - the background color, used where the original image was transparent. Also note that any transparent antialias will be rendered against this color.
        pHints - RenderingHints that control output quality and speed.
        Returns:
        the indexed BufferedImage. The image will be of type BufferedImage.TYPE_BYTE_INDEXED or BufferedImage.TYPE_BYTE_BINARY, and use an IndexColorModel.
        See Also:
        DITHER_DIFFUSION, DITHER_NONE, COLOR_SELECTION_FAST, COLOR_SELECTION_QUALITY, TRANSPARENCY_OPAQUE, TRANSPARENCY_BITMASK, BufferedImage.TYPE_BYTE_INDEXED, BufferedImage.TYPE_BYTE_BINARY, IndexColorModel
      • getIndexedImage

        public static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage,
                                                                   int pNumberOfColors,
                                                                   int pHints)
        Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. Generating an adaptive palette with the given number of colors. Dithering, transparency and color selection is controlled with the pHintsparameter.

        The image returned is a new image, the input image is not modified.

        Parameters:
        pImage - the BufferedImage to index
        pNumberOfColors - the number of colors for the image
        pHints - hints that control output quality and speed.
        Returns:
        the indexed BufferedImage. The image will be of type BufferedImage.TYPE_BYTE_INDEXED or BufferedImage.TYPE_BYTE_BINARY, and use an IndexColorModel.
        See Also:
        DITHER_DIFFUSION, DITHER_NONE, COLOR_SELECTION_FAST, COLOR_SELECTION_QUALITY, TRANSPARENCY_OPAQUE, TRANSPARENCY_BITMASK, BufferedImage.TYPE_BYTE_INDEXED, BufferedImage.TYPE_BYTE_BINARY, IndexColorModel
      • getIndexedImage

        public static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage,
                                                                   java.awt.image.IndexColorModel pColors,
                                                                   int pHints)
        Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. Using the supplied IndexColorModel's palette. Dithering, transparency and color selection is controlled with the pHintsparameter.

        The image returned is a new image, the input image is not modified.

        Parameters:
        pImage - the BufferedImage to index
        pColors - an IndexColorModel containing the color information
        pHints - RenderingHints that control output quality and speed.
        Returns:
        the indexed BufferedImage. The image will be of type BufferedImage.TYPE_BYTE_INDEXED or BufferedImage.TYPE_BYTE_BINARY, and use an IndexColorModel.
        See Also:
        DITHER_DIFFUSION, DITHER_NONE, COLOR_SELECTION_FAST, COLOR_SELECTION_QUALITY, TRANSPARENCY_OPAQUE, TRANSPARENCY_BITMASK, BufferedImage.TYPE_BYTE_INDEXED, BufferedImage.TYPE_BYTE_BINARY, IndexColorModel
      • getIndexedImage

        public static java.awt.image.BufferedImage getIndexedImage​(java.awt.image.BufferedImage pImage,
                                                                   java.awt.Image pPalette,
                                                                   int pHints)
        Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. If the palette image uses an IndexColorModel, this will be used. Otherwise, generating an adaptive palette (8 bit) from the given palette image. Dithering, transparency and color selection is controlled with the pHintsparameter.

        The image returned is a new image, the input image is not modified.

        Parameters:
        pImage - the BufferedImage to index
        pPalette - the Image to read color information from
        pHints - hints that control output quality and speed.
        Returns:
        the indexed BufferedImage. The image will be of type BufferedImage.TYPE_BYTE_INDEXED or BufferedImage.TYPE_BYTE_BINARY, and use an IndexColorModel.
        See Also:
        DITHER_DIFFUSION, DITHER_NONE, COLOR_SELECTION_FAST, COLOR_SELECTION_QUALITY, TRANSPARENCY_OPAQUE, TRANSPARENCY_BITMASK, BufferedImage.TYPE_BYTE_INDEXED, BufferedImage.TYPE_BYTE_BINARY, IndexColorModel
      • createSolid

        private static java.awt.image.BufferedImage createSolid​(java.awt.image.BufferedImage pOriginal,
                                                                java.awt.Color pBackground)
        Creates a copy of the given image, with a solid background
        Parameters:
        pOriginal - the original image
        pBackground - the background color
        Returns:
        a new BufferedImage
      • applyAlpha

        private static void applyAlpha​(java.awt.image.BufferedImage pImage,
                                       java.awt.image.BufferedImage pAlpha)
        Applies the alpha-component of the alpha image to the given image. The given image is modified in place.
        Parameters:
        pImage - the image to apply alpha to
        pAlpha - the image containing the alpha
      • main

        public static void main​(java.lang.String[] pArgs)