Barcode-Lib4J requires Java 9+
Package de.vwsoft.barcodelib4j.image
Java Class «CompoundColor» – Stores CMYK and RGB independently
java.lang.Object
java.awt.Color
de.vwsoft.barcodelib4j.image.CompoundColor
- All Implemented Interfaces:
Paint
,Transparency
,Serializable
Stores a color independently in the RGB and CMYK color models.
There are two types of constructors available:
- The first type accepts colors in both RGB and CMYK color models as parameters and stores them separately.
- The second type accepts either an RGB or a CMYK color as a parameter and converts the other color using a simple algorithm based on the provided color.
Note: Since the CMYK color model does not support transparency, any transparency information passed as a parameter for RGB colors is ignored.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final CompoundColor
Constant representing the color black in both RGB and CMYK color models.static final CompoundColor
Constant representing the color white in both RGB and CMYK color models.Fields inherited from class java.awt.Color
black, BLACK, blue, BLUE, cyan, CYAN, DARK_GRAY, darkGray, gray, GRAY, green, GREEN, LIGHT_GRAY, lightGray, magenta, MAGENTA, orange, ORANGE, pink, PINK, red, RED, white, WHITE, yellow, YELLOW
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
Constructor Summary
ConstructorDescriptionCompoundColor
(int value, boolean isRGB) Constructs a new instance with the specified value.CompoundColor
(int rgb, int cmyk) Constructs a new instance with the specified RGB and CMYK values.CompoundColor
(int r, int g, int b) Constructs a new instance with the specified RGB values.CompoundColor
(int c, int m, int y, int k) Constructs a new instance with the specified CMYK values.CompoundColor
(int r, int g, int b, int c, int m, int y, int k) Constructs a new instance with the specified RGB and CMYK values.CompoundColor
(long rgbAndCmyk) Constructs a new instance with the specified RGB and CMYK values.CompoundColor
(Color rgbColor) Constructs a new instance with the specifiedjava.awt.Color
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determines whether another object is equal to thisCompoundColor
.int
getCMYK()
Returns the CMYK color value.int
getCyan()
Returns the cyan component of the CMYK color, ranging from 0 to 100.int
getKey()
Returns the key (black) component of the CMYK color, ranging from 0 to 100.int
Returns the magenta component of the CMYK color, ranging from 0 to 100.long
Returns along
value representing both the RGB and CMYK colors.int
Returns the yellow component of the CMYK color, ranging from 0 to 100.int
hashCode()
Returns a hash code value for this object.toString()
Returns a string representation of thisCompoundColor
.Methods inherited from class java.awt.Color
brighter, createContext, darker, decode, getAlpha, getBlue, getColor, getColor, getColor, getColorComponents, getColorComponents, getColorSpace, getComponents, getComponents, getGreen, getHSBColor, getRed, getRGB, getRGBColorComponents, getRGBComponents, getTransparency, HSBtoRGB, RGBtoHSB
-
Field Details
-
CC_BLACK
Constant representing the color black in both RGB and CMYK color models. -
CC_WHITE
Constant representing the color white in both RGB and CMYK color models.
-
-
Constructor Details
-
CompoundColor
public CompoundColor(int r, int g, int b, int c, int m, int y, int k) Constructs a new instance with the specified RGB and CMYK values. No conversion between RGB and CMYK color models takes place.- Parameters:
r
- the red component of the RGB color (0-255)g
- the green component of the RGB color (0-255)b
- the blue component of the RGB color (0-255)c
- the cyan component of the CMYK color (0-100)m
- the magenta component of the CMYK color (0-100)y
- the yellow component of the CMYK color (0-100)k
- the key (black) component of the CMYK color (0-100)
-
CompoundColor
public CompoundColor(int rgb, int cmyk) Constructs a new instance with the specified RGB and CMYK values. No conversion between RGB and CMYK color models takes place.- Parameters:
rgb
- the RGB value of the colorcmyk
- the CMYK value of the color
-
CompoundColor
public CompoundColor(long rgbAndCmyk) Constructs a new instance with the specified RGB and CMYK values. No conversion between RGB and CMYK color models takes place. The RGB value must occupy the higher 32 bits of thelong
parameter, while the CMYK value must occupy the lower 32 bits.- Parameters:
rgbAndCmyk
- along
value representing both the RGB and CMYK colors- See Also:
-
CompoundColor
public CompoundColor(int r, int g, int b) Constructs a new instance with the specified RGB values. The CMYK values are calculated internally from the given RGB values, striving for the closest approximation.- Parameters:
r
- the red component of the RGB color (0-255)g
- the green component of the RGB color (0-255)b
- the blue component of the RGB color (0-255)
-
CompoundColor
public CompoundColor(int c, int m, int y, int k) Constructs a new instance with the specified CMYK values. The RGB values are calculated internally from the given CMYK values, striving for the closest approximation.- Parameters:
c
- the cyan component of the CMYK color (0-100)m
- the magenta component of the CMYK color (0-100)y
- the yellow component of the CMYK color (0-100)k
- the key (black) component of the CMYK color (0-100)
-
CompoundColor
Constructs a new instance with the specifiedjava.awt.Color
. The CMYK values are calculated internally from the given RGB values, striving for the closest approximation.- Parameters:
rgbColor
- thejava.awt.Color
object from which to construct theCompoundColor
-
CompoundColor
public CompoundColor(int value, boolean isRGB) Constructs a new instance with the specified value. IfisRGB
istrue
, the integer value represents an RGB color, otherwise, it represents a CMYK color. The CMYK values are calculated internally if the integer value represents an RGB color, or the RGB values are calculated internally if the integer value represents a CMYK color, striving for the closest approximation.- Parameters:
value
- the integer value representing either an RGB or CMYK colorisRGB
-true
if the value represents an RGB color,false
if it represents a CMYK color
-
-
Method Details
-
getRGBandCMYK
public long getRGBandCMYK()Returns along
value representing both the RGB and CMYK colors. The RGB value occupies the higher 32 bits and the CMYK value occupies the lower 32 bits.- Returns:
- a
long
value representing both the RGB and CMYK colors
-
getCMYK
public int getCMYK()Returns the CMYK color value. The cyan component occupies the higher 8 bits, the magenta component occupies the next 8 bits, the yellow component occupies the next 8 bits, and the key (black) component occupies the lower 8 bits.- Returns:
- the CMYK color value
-
getCyan
public int getCyan()Returns the cyan component of the CMYK color, ranging from 0 to 100.- Returns:
- the cyan component of the CMYK color, ranging from 0 to 100
-
getMagenta
public int getMagenta()Returns the magenta component of the CMYK color, ranging from 0 to 100.- Returns:
- the magenta component of the CMYK color, ranging from 0 to 100
-
getYellow
public int getYellow()Returns the yellow component of the CMYK color, ranging from 0 to 100.- Returns:
- the yellow component of the CMYK color, ranging from 0 to 100
-
getKey
public int getKey()Returns the key (black) component of the CMYK color, ranging from 0 to 100.- Returns:
- the key (black) component of the CMYK color, ranging from 0 to 100
-
hashCode
public int hashCode()Returns a hash code value for this object. -
equals
Determines whether another object is equal to thisCompoundColor
. The result istrue
if and only if the argument is notnull
and is aCompoundColor
object that has the same RGB and CMYK values as this object. -
toString
Returns a string representation of thisCompoundColor
. This method is intended to be used only for debugging purposes.
-