Class CMYKColorSpace

  • All Implemented Interfaces:
    Serializable

    public final class CMYKColorSpace
    extends ColorSpace

    A subclass of ColorSpace representing the uncalibrated (device-dependent) CMYK color space available in PDF documents.

    If colors need to be specified in CMYK, but device-independent color (the kind available with an ICC Profile) is not required, this ColorSpace should be used, as it doesn't require an ICC profile to be embedded in the PDF (resulting in a much smaller file). For some subsets of PDF (specifically PDF/X), RGB colors are not allowed, so anyone creating documents for that profile will probably make heavy use of this colorspace.

    Typically this class will be used as follows:

     Color cyan = CMYKColorSpace.getColor(1,0,0,0);
     

    Conversion to RGB

    When rendering PDFs containing CMYK images or graphics to RGB, the characteristics of this space become important. Since version 2.11.8 the device-dependent space defaults to a fast generic CMYK profile, however this can be changed by setting the System property org.faceless.pdf2.DeviceCMYK to one of the following options:
    genericA generic CMYK profile
    swopA fast approximation of US Web Coated (SWOP) v2
    fograA fast approximation of Coated FOGRA39 from ISO12647-2:2004
    photoA high-contrast CMYK profile of the type used to print photos
    adobeConversion to RGB is done using the algorithm from the PDF specification. This generally gives oversaturated, poor results.
    ghostscriptConversion to RGB is done using the algorithm used by GhostScript. This gives results only slightly better than the Adobe algorithm.
    So for example, to convert the Altona Visual Test Suite PDF to RGB using US Web Coated SWOP as the default CMYK Color profile, you could run our PDFToImage example as follows:
     java -Dorg.faceless.pdf2.DeviceCMYK=swop --model rgb PDFToImage altona_visual_1v2a_x3.pdf
     
    Since:
    1.1.5
    • Field Detail

      • BLACK

        public static final Color BLACK
        A convenient constant that represents the color black in the uncalibrated CMYK colorspace
      • BLACK0

        public static final Color BLACK0
        A convenient constant that represents the color black in the uncalibated Grayscale colorspace
        Since:
        2.23.1
      • WHITE0

        public static final Color WHITE0
        A convenient constant that represents the color black in the uncalibated Grayscale colorspace
        Since:
        2.23.1
      • WHITE

        public static final Color WHITE
        A convenient constant that represents the color white in the uncalibrated CMYK colorspace
      • GRAYSPACE

        public static final ColorSpace GRAYSPACE
    • Method Detail

      • getInstance

        public static CMYKColorSpace getInstance()
        Return a CMYK Color Space
      • toRGB

        public float[] toRGB​(float[] cmyk)
        Specified by:
        toRGB in class ColorSpace
      • toRGB

        public int[] toRGB​(int[] cmyk,
                           int[] rgb,
                           int intent)
      • fromRGB

        public float[] fromRGB​(float[] rgb)
        Specified by:
        fromRGB in class ColorSpace
      • fromCIEXYZ

        public float[] fromCIEXYZ​(float[] xyz)
        Specified by:
        fromCIEXYZ in class ColorSpace
      • toCIEXYZ

        public float[] toCIEXYZ​(float[] cmyk)
        Specified by:
        toCIEXYZ in class ColorSpace
      • getColor

        public static Color getColor​(float c,
                                     float m,
                                     float y,
                                     float k)
        A convenience method, returning an opaque color in the CMYK colorspace with the specified levels of cyan, magenta, yellow and black. The parameters must be in the range from 0.0 to 1.0, or an IllegalArgumentException is thrown
        Parameters:
        c - the level of cyan from 0.0 to 1.0
        m - the level of magenta from 0.0 to 1.0
        y - the level of yellow from 0.0 to 1.0
        k - the level of black from 0.0 to 1.0
        Throws:
        IllegalArgumentException - if any of the parameters are outside the renage 0 <= n <= 1
      • getColor

        public static Color getColor​(float c,
                                     float m,
                                     float y,
                                     float k,
                                     float a)
        A convenience method, returning a color in the CMYK colorspace with the specified levels of cyan, magenta, yellow and black, and the specified alpha value. All the parameters must be in the range from 0.0 to 1.0, or an IllegalArgumentException is thrown
        Parameters:
        c - the level of cyan from 0.0 to 1.0
        m - the level of magenta from 0.0 to 1.0
        y - the level of yellow from 0.0 to 1.0
        k - the level of black from 0.0 to 1.0
        a - the alpha level to use - 0 is transparent, 1 is opaque.
        Throws:
        IllegalArgumentException - if any of the parameters are outside the renage 0 <= n <= 1
      • getDeltaE

        public static double getDeltaE​(ColorSpace c1,
                                       ColorSpace c2)
        Return a number representing the difference between 2 ColorSpaces. Used internally by the PDF library