Barcode-Lib4J requires Java 9+

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

public class CompoundColor extends Color
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.
The second type of constructor is likely the one you will use most often, as you typically work with just one of the two color models.

Note: Since the CMYK color model does not support transparency, any transparency information passed as a parameter for RGB colors is ignored.

  • Field Details

    • CC_BLACK

      public static final CompoundColor CC_BLACK
      Constant representing the color black in both RGB and CMYK color models.
    • CC_WHITE

      public static final CompoundColor 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 color
      cmyk - 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 the long parameter, while the CMYK value must occupy the lower 32 bits.
      Parameters:
      rgbAndCmyk - a long 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

      public CompoundColor(Color rgbColor)
      Constructs a new instance with the specified java.awt.Color. The CMYK values are calculated internally from the given RGB values, striving for the closest approximation.
      Parameters:
      rgbColor - the java.awt.Color object from which to construct the CompoundColor
    • CompoundColor

      public CompoundColor(int value, boolean isRGB)
      Constructs a new instance with the specified value. If isRGB is true, 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 color
      isRGB - true if the value represents an RGB color, false if it represents a CMYK color
  • Method Details

    • getRGBandCMYK

      public long getRGBandCMYK()
      Returns a long 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.
      Overrides:
      hashCode in class Color
      Returns:
      a hash code value for this object
    • equals

      public boolean equals(Object obj)
      Determines whether another object is equal to this CompoundColor. The result is true if and only if the argument is not null and is a CompoundColor object that has the same RGB and CMYK values as this object.
      Overrides:
      equals in class Color
      Parameters:
      obj - the object to test for equality with this CompoundColor
      Returns:
      true if the objects are the same, false otherwise
    • toString

      public String toString()
      Returns a string representation of this CompoundColor. This method is intended to be used only for debugging purposes.
      Overrides:
      toString in class Color
      Returns:
      a string representation of this CompoundColor