Package qupath.lib.color
Class ColorToolsAwt
java.lang.Object
qupath.lib.color.ColorToolsAwt
Helper class for converting between packed RGB colors and Java's AWT representation, as well as creating some ColorModels for BufferedImages.
- Author:
- Pete Bankhead
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic IndexColorModel
createIndexColorModel
(int red, int green, int blue, boolean whiteBackground) Get anIndexColorModel
representing a linear LUT based on a RGB color.static Color
darkenColor
(Color color) Get a (slightly) darker version of the specified color.static Color
getCachedColor
(int r, int g, int b) Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).static Color
getCachedColor
(int r, int g, int b, int a) Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).static Color
getCachedColor
(Integer rgb) Get cached color.static Color
getCachedColor
(Integer rgb, boolean hasAlpha) Get cached color, explicitly stating whether alpha should be included or not.static Color
getColorWithOpacity
(Color color, double opacity) Get a color with a specified opacity, setting the alpha channel accordingly.static Color
getColorWithOpacity
(Integer rgb, double opacity) Get a color with a specified opacity, based on the packed RGB values in an Integer.static IndexColorModel
getIndexColorModel
(StainVector stain) Create an IndexColorModel, ranging from white (low values) to a stain vector color (high values).static IndexColorModel
getIndexColorModel
(StainVector stain, boolean whiteBackground) Get anIndexColorModel
representing a color deconvolution stain.static Color
getMoreTranslucentColor
(Color color) Get a (slightly more) translucent version of the specified color.static Color
getTranslucentColor
(Color color) Get a (slightly) translucent version of the specified color.static Color
scaleColor
(Color color, double factor) Get a scaled version of the specified color, where the RGB values are independently scaled by a specified factor.
-
Field Details
-
TRANSLUCENT_WHITE
White, with 50% opacity. -
TRANSLUCENT_BLACK
Black, with 50% opacity.
-
-
Constructor Details
-
ColorToolsAwt
public ColorToolsAwt()
-
-
Method Details
-
getCachedColor
Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).- Parameters:
r
-g
-b
-a
-- Returns:
-
getCachedColor
Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).- Parameters:
r
-g
-b
-- Returns:
-
getCachedColor
Get cached color. Assumed not to have alpha set, unless the relevant bits are non-zero.- Parameters:
rgb
-- Returns:
-
getCachedColor
Get cached color, explicitly stating whether alpha should be included or not.- Parameters:
rgb
-hasAlpha
-- Returns:
-
getIndexColorModel
Get anIndexColorModel
representing a color deconvolution stain. The color is just an approximation for visualization purposes, it does not perfectly match the stain itself.- Parameters:
stain
- the stain to usewhiteBackground
- if true, the color model will have a white background; if false, it will have a black background- Returns:
-
createIndexColorModel
public static IndexColorModel createIndexColorModel(int red, int green, int blue, boolean whiteBackground) Get anIndexColorModel
representing a linear LUT based on a RGB color.- Parameters:
red
- the red value of the color for the maximum valuegreen
- the green value of the color for the maximum valueblue
- the blue value of the color for the maximum valuewhiteBackground
- if true, the color model will have a white background; if false, it will have a black background- Returns:
-
getIndexColorModel
Create an IndexColorModel, ranging from white (low values) to a stain vector color (high values).- Parameters:
stain
-- Returns:
-
getMoreTranslucentColor
Get a (slightly more) translucent version of the specified color.If possible, a cached version will be used.
- Parameters:
color
-- Returns:
- See Also:
-
darkenColor
Get a (slightly) darker version of the specified color.If possible, a cached version will be used.
- Parameters:
color
-- Returns:
-
getTranslucentColor
Get a (slightly) translucent version of the specified color.If possible, a cached version will be used.
- Parameters:
color
-- Returns:
-
scaleColor
Get a scaled version of the specified color, where the RGB values are independently scaled by a specified factor.The alpha value is preserved unchanged.
- Parameters:
color
-factor
-- Returns:
-
getColorWithOpacity
Get a color with a specified opacity, based on the packed RGB values in an Integer.- Parameters:
rgb
-opacity
-- Returns:
-
getColorWithOpacity
Get a color with a specified opacity, setting the alpha channel accordingly.- Parameters:
color
-opacity
-- Returns:
-