Class PixelUtils


  • public class PixelUtils
    extends java.lang.Object
    Some more useful math functions for image processing. These are becoming obsolete as we move to Java2D. Use MiscComposite instead.
    • Constructor Summary

      Constructors 
      Constructor Description
      PixelUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int brightness​(int rgb)
      Return the brightness.
      static int clamp​(int c)
      Clamp a value to the range 0..255.
      static int combinePixels​(int rgb1, int rgb2, int op)
      Return rgb1 painted onto rgb2.
      static int combinePixels​(int rgb1, int rgb2, int op, int extraAlpha)
      Return rgb1 painted onto rgb2.
      static int combinePixels​(int rgb1, int rgb2, int op, int extraAlpha, int channelMask)
      Return rgb1 painted onto rgb2.
      static int interpolate​(int v1, int v2, float f)
      Interpolate between two values.
      static boolean nearColors​(int rgb1, int rgb2, int tolerance)
      Return true of the colors are near each other.
      • Methods inherited from class java.lang.Object

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

      • PixelUtils

        public PixelUtils()
    • Method Detail

      • clamp

        public static int clamp​(int c)
        Clamp a value to the range 0..255.
        Parameters:
        c - The value to be clamped
        Returns:
        the clamped value.
      • interpolate

        public static int interpolate​(int v1,
                                      int v2,
                                      float f)
        Interpolate between two values.
        Parameters:
        v1 - The first value
        v2 - The second value
        f - The amount of interpolation, typically between 0 and 1.
        Returns:
        the interpolated value, clamped to 0..255.
      • brightness

        public static int brightness​(int rgb)
        Return the brightness.
        Parameters:
        rgb - RFB encoded.
        Returns:
        The average of the R, G and B.
      • nearColors

        public static boolean nearColors​(int rgb1,
                                         int rgb2,
                                         int tolerance)
        Return true of the colors are near each other.
        Parameters:
        rgb1 - The first color
        rgb2 - The second color
        tolerance - The maximum difference for r, g, and b between the two values.
        Returns:
        True if the colors are near each other.
      • combinePixels

        public static int combinePixels​(int rgb1,
                                        int rgb2,
                                        int op)
        Return rgb1 painted onto rgb2.
        Parameters:
        rgb1 - The first pixel.
        rgb2 - The second pixel.
        op - The operation as defined by this class.
        Returns:
        the combined pixel.
      • combinePixels

        public static int combinePixels​(int rgb1,
                                        int rgb2,
                                        int op,
                                        int extraAlpha,
                                        int channelMask)
        Return rgb1 painted onto rgb2.
        Parameters:
        rgb1 - The first pixel.
        rgb2 - The second pixel.
        op - The operation as defined by this class.
        extraAlpha - The extra alpha.
        channelMask - The channel mask.
        Returns:
        the combined pixel.
      • combinePixels

        public static int combinePixels​(int rgb1,
                                        int rgb2,
                                        int op,
                                        int extraAlpha)
        Return rgb1 painted onto rgb2.
        Parameters:
        rgb1 - The first pixel.
        rgb2 - The second pixel.
        op - The operation as defined by this class.
        extraAlpha - The extra alpha.
        Returns:
        the combined pixel.