java.lang.Object
imagingbook.common.color.RgbUtils
This class defines static methods for manipulating and converting RGB colors.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double[]ITU BR.601 weights for RGB to Y (luma) conversion.static final double[]ITU BR.709 weights for RGB to Y (luma) conversion. -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddecodeIntToRgb(int argb, int[] RGB) Converts the given integer-encoded 8-bit RGB color to a 3-elementint[]with components red, green and blue.static int[]denormalize(float[] rgb) Converts float RGB values (with components assumed to be in [0,1]) to integer values in [0,255].static int[]denormalizeD(double[] rgb) Converts double RGB values (with components assumed to be in [0,1]) to integer values in [0,255].static intencodeRgbToInt(int[] RGB) Encodes the given RGB component values into a single 32-bitintvalue in ARGB format (with transparency A set to zero).static intencodeRgbToInt(int r, int g, int b) Encodes the given r, g, b component values into a single 32-bitintvalue in ARGB format (with transparency A set to zero).static double[]static Colorinterpolate(Color[] palette, double t) Interpolates linearly between the colors in the specified color palette.static Colorinterpolate(Color ca, Color cb, double t) Interpolates linearly between two specified colors.static int[]intToRgb(int argb) Converts the given integer-encoded 8-bit RGB color to a 3-elementint[]with components red, green and blue.static float[]normalize(int[] RGB) Converts integer RGB values (with components assumed to be in [0,255]) to float values in [0,1].static double[]normalizeD(int[] RGB) static intrgbToInt(int[] RGB) Converts the given 3-elementint[]with components red, green and blue to an integer-encoded 8-bit RGB color.
-
Field Details
-
ITU601RgbWeights
ITU BR.601 weights for RGB to Y (luma) conversion. -
ITU709RgbWeights
ITU BR.709 weights for RGB to Y (luma) conversion.
-
-
Method Details
-
getDefaultWeights
-
intToRgb
Converts the given integer-encoded 8-bit RGB color to a 3-elementint[]with components red, green and blue.- Parameters:
argb- integer-encoded 8-bit RGB color in ARGB format- Returns:
int[]with R, G, B components in [0,255]
-
rgbToInt
Converts the given 3-elementint[]with components red, green and blue to an integer-encoded 8-bit RGB color.- Parameters:
RGB-int[]with R, G, B components in [0,255]- Returns:
- integer-encoded 8-bit RGB color in ARGB format
- See Also:
-
decodeIntToRgb
Converts the given integer-encoded 8-bit RGB color to a 3-elementint[]with components red, green and blue. Fills the specifiedint[], nothing is returned.- Parameters:
argb- integer-encoded 8-bit RGB color in ARGB formatRGB-int[]with R, G, B components
-
encodeRgbToInt
Encodes the given RGB component values into a single 32-bitintvalue in ARGB format (with transparency A set to zero).- Parameters:
RGB-int[]with R, G, B components- Returns:
- integer-encoded 8-bit RGB color in ARGB format
-
encodeRgbToInt
Encodes the given r, g, b component values into a single 32-bitintvalue in ARGB format (with transparency A set to zero).- Parameters:
r- red component valueg- breen component valueb- blue component value- Returns:
- integer-encoded 8-bit RGB color in ARGB format
-
normalize
Converts integer RGB values (with components assumed to be in [0,255]) to float values in [0,1].- Parameters:
RGB- a sequence of R,G,B values orint[]- Returns:
- the RGB values normalized to [0,1]
-
normalizeD
-
denormalize
Converts float RGB values (with components assumed to be in [0,1]) to integer values in [0,255].- Parameters:
rgb- RGB float values in [0,1]- Returns:
- RGB integer values in [0,255]
-
denormalizeD
Converts double RGB values (with components assumed to be in [0,1]) to integer values in [0,255].- Parameters:
rgb- RGB float values in [0,1]- Returns:
- RGB integer values in [0,255]
-
interpolate
Interpolates linearly between two specified colors.- Parameters:
ca- first color (to be interpolated from)cb- second color (to be interpolated to)t- interpolation coefficient, must be in [0,1]- Returns:
- the interpolated color
-
interpolate
Interpolates linearly between the colors in the specified color palette. The interpolation coefficient must be in [0,1]. If 0, the first palette color is returned, if 1 the last color.- Parameters:
palette- an array of colors (at least 2)t- interpolation coefficient, must be in [0,1]- Returns:
- the interpolated color
-