Interface FastPixel

  • All Known Implementing Classes:
    FastPixelByte, FastPixelImpl, FastPixelInt, FastPixelSlowDefault

    public interface FastPixel
    Utility class to access pixel data in a fraction of the time required by the native JDK methods.

    Additionally support different color spaces and bulk operations

    Author:
    Kilian
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Logger LOGGER  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static FastPixel create​(BufferedImage bufferedImage)
      Return a fast pixel instance mapped to the buffered image type
      int[][] getAlpha()
      Get the alpha component of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
      int getAlpha​(int index)
      Get the alpha value of the specified pixel
      default int getAlpha​(int x, int y)
      Get the alpha value of the specified pixel
      int[][] getAverageGrayscale()
      Get the average grayscale of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
      int getAverageGrayscale​(int index)
      Get the average grayscale at the specified offset
      default int getAverageGrayscale​(int x, int y)
      Get the average grayscale of the specified pixel
      int[][] getBlue()
      Get the blue component of the entire image mapped to a 2d array representing the x and y coordinates of the image.
      int getBlue​(int index)
      Get the blue value of the specified offset
      default int getBlue​(int x, int y)
      Get the blue value of the specified pixel
      int[] getBlue1D()
      Get the blue component of the entire image mapped to a 1d array
      default int getCb​(int index)
      Return the Cb(blue-difference) component of the YCbCr color model for the specified offset.
      default int getCb​(int x, int y)
      Return the Cb(blue-difference) component of the YCbCr color model for the specified pixel.
      default int getCr​(int index)  
      default int getCr​(int x, int y)
      Return the Cr(red-difference) component of the YCbCr color model for the specified pixel.
      int[][] getGreen()
      Get the green component of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
      int getGreen​(int index)
      Get the green value of the specified offset
      default int getGreen​(int x, int y)
      Get the green value of the specified pixel
      int[] getGreen1D()
      Get the green component of the entire image mapped to a 1d array
      default int getHue​(int index)
      Return the hue component (angle) of the HSV color model for the specified offset
      default int getHue​(int x, int y)
      Return the hue component (angle) of the HSV color model for the specified pixel
      int[][] getLuma()
      Return the Y(Luma) component of the YCbCr color model for the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
      default int getLuma​(int index)
      Return the Y(Luma) component of the YCbCr color model for the specified offset.
      default int getLuma​(int x, int y)
      Return the Y(Luma) component of the YCbCr color model for the specified pixel.
      int[] getLuma1D()
      Return the Y(Luma) component of the YCbCr color model fof the entire image mapped to a 1d array
      int getOffset​(int x, int y)
      Map the x and y values to the underlying one dimensional data array
      int[][] getRed()
      Get the red component of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
      int getRed​(int index)
      Get the red value at the specified offset
      default int getRed​(int x, int y)
      Get the red value of the specified pixel
      int[] getRed1D()
      Get the red component of the entire image mapped to a 1d array
      int[][] getRGB()
      Returns the rgb values of the entire image in an 2 d array in the default RGB color model(TYPE_INT_ARGB).
      int getRGB​(int index)  
      default int getRGB​(int x, int y)
      Returns an integer pixel in the default RGB color model(TYPE_INT_ARGB).
      default double getSat​(int index)
      Return the saturation component of the HSV color model for the specified offset
      default double getSat​(int x, int y)
      Return the saturation component of the HSV color model for the specified pixel
      default int getVal​(int index)
      Return the value component of the HSV color model for the specified offset
      default int getVal​(int x, int y)
      Return the value component of the HSV color model for the specified pixel
      boolean hasAlpha()
      Check if an image supports alpha values
      boolean isReplaceOpaqueColors()
      Check if the pixel loader replaces opaque colors with a non opaque version.
      void setAlpha​(int[][] newAlpha)
      Set new alpha values for the entire picture
      void setAlpha​(int index, int newAlpha)
      Set the alpha value.
      default void setAlpha​(int x, int y, int newAlpha)
      Set the alpha value of the specified pixel.
      void setAverageGrayscale​(int[][] newGrayValue)
      Set the gray values of the entire image.
      default void setAverageGrayscale​(int index, int newGrayValue)
      Set the gray values at the specified offset
      default void setAverageGrayscale​(int x, int y, int newGrayValue)
      Set the gray values of the specified pixel image.
      void setBlue​(int[][] newBlue)
      Set new blue values for the entire picture
      void setBlue​(int index, int newBlue)  
      default void setBlue​(int x, int y, int newBlue)
      Set the blue value of the specified pixel
      void setGreen​(int[][] newGreen)
      Set new green values for the entire picture
      void setGreen​(int index, int newGreen)
      Set the green value at the specified offset
      default void setGreen​(int x, int y, int newGreen)
      Set the green value of the specified pixel
      void setRed​(int[][] newRed)
      Set new red values for the entire picture
      void setRed​(int index, int newRed)
      Set the red value at the specified offset
      default void setRed​(int x, int y, int newRed)
      Set the red value of the specified pixel
      void setReplaceOpaqueColors​(int alphaThreshold, int r, int g, int b, int a)
      Replace all pixels values in the image which have an alpha < than the specified threshold.
      default void setReplaceOpaqueColors​(int alphaThreshold, Color replacementColor)
      Replace all pixels values in the image which have an alpha < than the specified threshold.
      default void setReplaceOpaqueColors​(int alphaThreshold, javafx.scene.paint.Color replacementColor)
      Replace all pixels values in the image which have an alpha < than the specified threshold.
    • Field Detail

      • LOGGER

        static final Logger LOGGER
    • Method Detail

      • create

        static FastPixel create​(BufferedImage bufferedImage)
        Return a fast pixel instance mapped to the buffered image type
        Parameters:
        bufferedImage - the buffered image to create a fast pixel instance for
        Returns:
        an instantiated FastPixelObject
      • isReplaceOpaqueColors

        boolean isReplaceOpaqueColors()
        Check if the pixel loader replaces opaque colors with a non opaque version. Opaque values are replaced only on get operations. To activate this option call setReplaceOpaqueColors(int, int, int, int, int) and set a color which will be returned in case that the pixel has an alpha value smaller than the specified threshold
        Returns:
        true if opaque colors are replaced by a user defined color
        Since:
        1.0.0
      • setReplaceOpaqueColors

        void setReplaceOpaqueColors​(int alphaThreshold,
                                    int r,
                                    int g,
                                    int b,
                                    int a)
        Replace all pixels values in the image which have an alpha < than the specified threshold. The pixel value is replaced for all get operations, including luminosity calculation. Set operations are not touched by this setting.
        Parameters:
        alphaThreshold - replace each pixel which has an alpha value smaller or equal to the threshold in the range of [0-255]. A value of will disabled color replacement
        r - the red value which will be returned in case of an opaque pixel [0-255]
        g - the green value which will be returned in case of an opaque pixel [0-255]
        b - the blue value which will be returned in case of an opaque pixel [0-255]
        a - the alpha value which will be returned in case of an opaque pixel [0-255]
        Since:
        1.0.0
      • setReplaceOpaqueColors

        default void setReplaceOpaqueColors​(int alphaThreshold,
                                            Color replacementColor)
        Replace all pixels values in the image which have an alpha < than the specified threshold. The pixel value is replaced for all get operations, including luminosity calculation. Set operations are not touched by this setting.
        Parameters:
        alphaThreshold - replace each pixel which has an alpha value smaller or equal to the threshold in the range of [0-255]. A value of will disabled color replacement
        replacementColor - the color which will be returned in case of an opaque pixel
      • setReplaceOpaqueColors

        default void setReplaceOpaqueColors​(int alphaThreshold,
                                            javafx.scene.paint.Color replacementColor)
        Replace all pixels values in the image which have an alpha < than the specified threshold. The pixel value is replaced for all get operations, including luminosity calculation. Set operations are not touched by this setting.
        Parameters:
        alphaThreshold - replace each pixel which has an alpha value smaller or equal to the threshold in the range of [0-255]. A value of will disabled color replacement
        replacementColor - the color which will be returned in case of an opaque pixel
      • getRGB

        int getRGB​(int index)
      • getRGB

        default int getRGB​(int x,
                           int y)
        Returns an integer pixel in the default RGB color model(TYPE_INT_ARGB). There are only 8-bits of precision for each color component in the returned data when using this method. An ArrayOutOfBoundsException may be thrown if the coordinates are not in bounds.
        Parameters:
        x - the X coordinate of the pixel from which to get the pixel in the default RGB color model
        y - the Y coordinate of the pixel from which to get the pixel in the default RGB color model
        Returns:
        an integer pixel in the default RGB color model and default sRGB colorspace.
        Since:
        1.3.0 com.github.kilianB
      • getRGB

        int[][] getRGB()
        Returns the rgb values of the entire image in an 2 d array in the default RGB color model(TYPE_INT_ARGB). There are only 8-bits of precision for each color component in the returned data when using this method. An ArrayOutOfBoundsException may be thrown if the coordinates are not in bounds.
        Returns:
        a 2d integer array containing the argb values of the image
        Since:
        1.3.0 com.github.kilianB
      • getAlpha

        int getAlpha​(int index)
        Get the alpha value of the specified pixel
        Parameters:
        index - the offset in the underlying array
        Returns:
        the alpha value in range [0-255] or -1 if alpha is not supported
        Since:
        1.5.0 com.github.kilianB
      • getAlpha

        default int getAlpha​(int x,
                             int y)
        Get the alpha value of the specified pixel
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        Returns:
        the alpha value in range [0-255] or -1 if alpha is not supported
        Since:
        1.3.0 com.github.kilianB
      • getAlpha

        int[][] getAlpha()
        Get the alpha component of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
        Returns:
        the alpha values or null if alpha is not supported
        Since:
        1.3.0 com.github.kilianB
      • setAlpha

        default void setAlpha​(int x,
                              int y,
                              int newAlpha)
        Set the alpha value of the specified pixel. This method is a NOP if alpha is not supported.
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        newAlpha - the new alpha value in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • setAlpha

        void setAlpha​(int index,
                      int newAlpha)
        Set the alpha value. This method is a NOP if alpha is not supported.
        Parameters:
        index - the offset of the underlying array
        newAlpha - the new alpha value in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • setAlpha

        void setAlpha​(int[][] newAlpha)
        Set new alpha values for the entire picture
        Parameters:
        newAlpha - red values in range [0-255]
        Since:
        1.4.5 com.github.kilianB
      • getRed

        int getRed​(int index)
        Get the red value at the specified offset
        Parameters:
        index - offset of ther underlying array
        Returns:
        the red value in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • getRed

        default int getRed​(int x,
                           int y)
        Get the red value of the specified pixel
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        Returns:
        the red value in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getRed

        int[][] getRed()
        Get the red component of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
        Returns:
        the red values in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getRed1D

        int[] getRed1D()
        Get the red component of the entire image mapped to a 1d array
        Returns:
        the red values in range [0-255]
        Since:
        1.5.5 com.github.kilianB
      • setRed

        default void setRed​(int x,
                            int y,
                            int newRed)
        Set the red value of the specified pixel
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        newRed - the new red value in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • setRed

        void setRed​(int index,
                    int newRed)
        Set the red value at the specified offset
        Parameters:
        index - the offset of the underlying array
        newRed - the new red value in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • setRed

        void setRed​(int[][] newRed)
        Set new red values for the entire picture
        Parameters:
        newRed - red values in range [0-255]
        Since:
        1.4.5 com.github.kilianB
      • getGreen

        int getGreen​(int index)
        Get the green value of the specified offset
        Parameters:
        index - the offset of the underlying array
        Returns:
        the green value in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • getGreen

        default int getGreen​(int x,
                             int y)
        Get the green value of the specified pixel
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        Returns:
        the green value in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • setGreen

        default void setGreen​(int x,
                              int y,
                              int newGreen)
        Set the green value of the specified pixel
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        newGreen - the new green value in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • setGreen

        void setGreen​(int index,
                      int newGreen)
        Set the green value at the specified offset
        Parameters:
        index - the offset of the underlying array
        newGreen - the new green value in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • setGreen

        void setGreen​(int[][] newGreen)
        Set new green values for the entire picture
        Parameters:
        newGreen - red values in range [0-255]
        Since:
        1.4.5 com.github.kilianB
      • getGreen

        int[][] getGreen()
        Get the green component of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
        Returns:
        the green values in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getGreen1D

        int[] getGreen1D()
        Get the green component of the entire image mapped to a 1d array
        Returns:
        the green values in range [0-255]
        Since:
        1.5.5 com.github.kilianB
      • getBlue

        int getBlue​(int index)
        Get the blue value of the specified offset
        Parameters:
        index - the offset of the underlying array
        Returns:
        the green value in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • getBlue

        default int getBlue​(int x,
                            int y)
        Get the blue value of the specified pixel
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        Returns:
        the blue value in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • setBlue

        default void setBlue​(int x,
                             int y,
                             int newBlue)
        Set the blue value of the specified pixel
        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        newBlue - the new blue value in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • setBlue

        void setBlue​(int index,
                     int newBlue)
      • getBlue

        int[][] getBlue()
        Get the blue component of the entire image mapped to a 2d array representing the x and y coordinates of the image.
        Returns:
        the blue values in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getBlue1D

        int[] getBlue1D()
        Get the blue component of the entire image mapped to a 1d array
        Returns:
        the red values in range [0-255]
        Since:
        1.5.5 com.github.kilianB
      • setBlue

        void setBlue​(int[][] newBlue)
        Set new blue values for the entire picture
        Parameters:
        newBlue - red values in range [0-255]
        Since:
        1.4.5 com.github.kilianB
      • getAverageGrayscale

        int getAverageGrayscale​(int index)
        Get the average grayscale at the specified offset

        Average grayscale: (R+G+B)/3

        This

        Parameters:
        index - offset of der underlying array
        Returns:
        the grayscale values in range [0-255]
        Since:
        1.5.0 com.github.kilianB, 1.5.10 will return the default transparency color if com.github.kilianB
      • getAverageGrayscale

        default int getAverageGrayscale​(int x,
                                        int y)
        Get the average grayscale of the specified pixel

        Average grayscale: (R+G+B)/3

        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        Returns:
        the grayscale values in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • getAverageGrayscale

        int[][] getAverageGrayscale()
        Get the average grayscale of the entire image mapped to a 2d array representing the x and y coordinates of the pixel.

        Average grayscale: (R+G+B)/3

        Average grayscale: (R+G+B)/3

        Returns:
        the grayscale values in range [0 - 255]
        Since:
        1.5.0 com.github.kilianB
      • setAverageGrayscale

        default void setAverageGrayscale​(int index,
                                         int newGrayValue)
        Set the gray values at the specified offset

        Average grayscale: (R+G+B)/3

        It is up to the inheriting class to decide how the gray value is reflected at the value level. If the image is still in rgb or argb mode the value of each individual channel will be set to the gray value

        Parameters:
        index - offset of der underlaying array
        newGrayValue - to set the pixels to range [0 - 255]
        Since:
        1.5.0 com.github.kilianB
      • setAverageGrayscale

        default void setAverageGrayscale​(int x,
                                         int y,
                                         int newGrayValue)
        Set the gray values of the specified pixel image.

        Average grayscale: (R+G+B)/3

        It is up to the inheriting class to decide how the gray value is reflected at the value level. If the image is still in rgb or argb mode the value of each individual channel will be set to the gray value

        Parameters:
        x - The x coordinate of the images' pixel
        y - The y coordinate of the images' pixel
        newGrayValue - to set the pixels to range [0 - 255]
        Since:
        1.5.0 com.github.kilianB
      • setAverageGrayscale

        void setAverageGrayscale​(int[][] newGrayValue)
        Set the gray values of the entire image.

        Average grayscale: (R+G+B)/3

        It is up to the inheriting class to decide how the gray value is reflected at the value level. If the image is still in rgb or argb mode the value of each individual channel will be set to the gray value

        Parameters:
        newGrayValue - to set the pixels to range [0 - 255]
        Since:
        1.5.0 com.github.kilianB
      • getLuma

        default int getLuma​(int index)
        Return the Y(Luma) component of the YCbCr color model for the specified offset.
        Parameters:
        index - of the underlying array
        Returns:
        the luma component in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getLuma

        default int getLuma​(int x,
                            int y)
        Return the Y(Luma) component of the YCbCr color model for the specified pixel.
        Parameters:
        x - the x coordinate of the image
        y - the y coordinate of the image
        Returns:
        the luma component in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getLuma

        int[][] getLuma()
        Return the Y(Luma) component of the YCbCr color model for the entire image mapped to a 2d array representing the x and y coordinates of the pixel.
        Returns:
        the luma component in range [0-255]
        Since:
        1.3.1 com.github.kilianB
      • getLuma1D

        int[] getLuma1D()
        Return the Y(Luma) component of the YCbCr color model fof the entire image mapped to a 1d array
        Returns:
        the luma component in range [0-255]
      • getCr

        default int getCr​(int index)
      • getCr

        default int getCr​(int x,
                          int y)
        Return the Cr(red-difference) component of the YCbCr color model for the specified pixel.
        Parameters:
        x - the x coordinate of the image
        y - the y coordinate of the image
        Returns:
        the cr component in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getCb

        default int getCb​(int index)
        Return the Cb(blue-difference) component of the YCbCr color model for the specified offset.
        Parameters:
        index - offset of the underlying array
        Returns:
        the cb component in range [0-255]
        Since:
        1.5.0 com.github.kilianB
      • getCb

        default int getCb​(int x,
                          int y)
        Return the Cb(blue-difference) component of the YCbCr color model for the specified pixel.
        Parameters:
        x - the x coordinate of the image
        y - the y coordinate of the image
        Returns:
        the cb component in range [0-255]
        Since:
        1.3.0 com.github.kilianB
      • getHue

        default int getHue​(int index)
        Return the hue component (angle) of the HSV color model for the specified offset
        Parameters:
        index - offset of der underlying array
        Returns:
        the hue component in range [0-360]. As defined the hue is 0 for undefined colors (e.g. white or black)
        Since:
        1.5.0 com.github.kilianB
      • getHue

        default int getHue​(int x,
                           int y)
        Return the hue component (angle) of the HSV color model for the specified pixel
        Parameters:
        x - the x coordinate of the image
        y - the y coordinate of the image
        Returns:
        the hue component in range [0-360]. As defined the hue is 0 for undefined colors (e.g. white or black)
        Since:
        1.3.0 com.github.kilianB
      • getSat

        default double getSat​(int index)
        Return the saturation component of the HSV color model for the specified offset

        Note: Opposed to all other values for the hsb model saturation is returned as double in the range of [0-1] instead of [0-255] to allow for a higher accuracy.

        Parameters:
        index - the offset of the underlying array
        Returns:
        the sat component in range [0-1]. As defined the sat is 0 for undefined colors (i.e. black)
        Since:
        1.5.0 com.github.kilianB
      • getSat

        default double getSat​(int x,
                              int y)
        Return the saturation component of the HSV color model for the specified pixel

        Note: Opposed to all other values for the hsb model saturation is returned as double in the range of [0-1] instead of [0-255] to allow for a higher accuracy.

        Parameters:
        x - the x coordinate of the image
        y - the y coordinate of the image
        Returns:
        the sat component in range [0-1]. As defined the sat is 0 for undefined colors (i.e. black)
        Since:
        1.3.0 com.github.kilianB
      • getVal

        default int getVal​(int index)
        Return the value component of the HSV color model for the specified offset
        Parameters:
        index - offset of the udnerlying array
        Returns:
        the value component in range [0-255].
        Since:
        1.5.0 com.github.kilianB
      • getVal

        default int getVal​(int x,
                           int y)
        Return the value component of the HSV color model for the specified pixel
        Parameters:
        x - the x coordinate of the image
        y - the y coordinate of the image
        Returns:
        the value component in range [0-255].
      • hasAlpha

        boolean hasAlpha()
        Check if an image supports alpha values
        Returns:
        true if the image has an alpha channel. false otherwise
      • getOffset

        int getOffset​(int x,
                      int y)
        Map the x and y values to the underlying one dimensional data array
        Parameters:
        x - the x coordinate
        y - the y coordinate
        Returns:
        the corresponding 1d array index