Class FastPixelSlowDefault

  • All Implemented Interfaces:
    FastPixel

    public class FastPixelSlowDefault
    extends FastPixelImpl
    A fallback instance of fast pixel using a cached getRGB instance instead of the underlying buffer due to the fact that no other implementation currently is available. This allows to support all image formats but individual implementations should be replaced by faster alternatives in the future.
    Since:
    1.5.2 com.github.kilianB
    Author:
    Kilian
    • Constructor Detail

      • FastPixelSlowDefault

        public FastPixelSlowDefault​(BufferedImage bImage)
        Constructs a fast pixel object with the underlying buffered image.

        Note that calling this method may cause this DataBufferobject to be incompatible with performance optimizations used by some implementations (such as caching an associated image in video memory).

        Parameters:
        bImage - The buffered image to extract data from
        Since:
        1.3.0 com.github.kilianB
    • Method Detail

      • getRGB

        public int getRGB​(int index)
      • getRGB

        public int[][] getRGB()
        Description copied from class: FastPixelImpl
        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.
        Specified by:
        getRGB in interface FastPixel
        Overrides:
        getRGB in class FastPixelImpl
        Returns:
        a 2d integer array containing the argb values of the image
      • setAlpha

        public void setAlpha​(int index,
                             int newAlpha)
        Description copied from interface: FastPixel
        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]
      • setAlpha

        public void setAlpha​(int[][] newAlpha)
        Description copied from class: FastPixelImpl
        Set new alpha values for the entire picture
        Specified by:
        setAlpha in interface FastPixel
        Overrides:
        setAlpha in class FastPixelImpl
        Parameters:
        newAlpha - red values in range [0-255]
      • setRed

        public void setRed​(int index,
                           int newRed)
        Description copied from interface: FastPixel
        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]
      • setRed

        public void setRed​(int[][] newRed)
        Description copied from class: FastPixelImpl
        Set new red values for the entire picture
        Specified by:
        setRed in interface FastPixel
        Overrides:
        setRed in class FastPixelImpl
        Parameters:
        newRed - red values in range [0-255]
      • setGreen

        public void setGreen​(int index,
                             int newGreen)
        Description copied from interface: FastPixel
        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]
      • setGreen

        public void setGreen​(int[][] newGreen)
        Description copied from class: FastPixelImpl
        Set new green values for the entire picture
        Specified by:
        setGreen in interface FastPixel
        Overrides:
        setGreen in class FastPixelImpl
        Parameters:
        newGreen - red values in range [0-255]
      • setBlue

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

        public void setBlue​(int[][] newBlue)
        Description copied from class: FastPixelImpl
        Set new blue values for the entire picture
        Specified by:
        setBlue in interface FastPixel
        Overrides:
        setBlue in class FastPixelImpl
        Parameters:
        newBlue - red values in range [0-255]
      • setAverageGrayscale

        public void setAverageGrayscale​(int[][] newGrayValue)
        Description copied from interface: FastPixel
        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

        Specified by:
        setAverageGrayscale in interface FastPixel
        Overrides:
        setAverageGrayscale in class FastPixelImpl
        Parameters:
        newGrayValue - to set the pixels to range [0 - 255]
      • getOffset

        public int getOffset​(int x,
                             int y)
        Description copied from interface: FastPixel
        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