public class

ColorSpace

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.ColorSpace

Class Overview

This abstract class is used to serve as a color space tag to identify the specific color space of a Color object. It contains methods that transform colors in a specific color space to/from several color space such as DeviceRGB and DeviceCMYK. For purposes of the methods in this class, colors are represented as arrays of color components represented as doubles in a normalized range defined by each ColorSpace. For many ColorSpaces (e.g. DeviceRGB), this range is 0.0 to 1.0. However, some ColorSpaces have components whose values have a different range. Methods are provided to inquire per component minimum and maximum normalized values.

Note: In Pattern color space (i.e. for ColorSpace::e_pattern) 'color values' are PDF::PatternColor objects instead of the numeric component values (i.e. ColorPt) used with other spaces.

Summary

Constants
int e_cal_gray The Constant e_cal_gray.
int e_cal_rgb The Constant e_cal_rgb.
int e_device_cmyk The Constant e_device_cmyk.
int e_device_gray The Constant e_device_gray.
int e_device_n The Constant e_device_n.
int e_device_rgb The Constant e_device_rgb.
int e_icc The Constant e_icc.
int e_indexed The Constant e_indexed.
int e_lab The Constant e_lab.
int e_null The Constant e_null.
int e_pattern The Constant e_pattern.
int e_separation The Constant e_separation.
Public Constructors
ColorSpace(Obj color_space)
Create a ColorSpace from the given SDF/Cos object listed under ColorSpaces entry in page Resource dictionary.
Public Methods
static ColorSpace __Create(long impl, Object ref)
ColorPt convert2CMYK(ColorPt in_color)
A convenience function used to convert color points from the current color space to DeviceCMYK color space.
ColorPt convert2Gray(ColorPt in_color)
A convenience function used to convert color points from the current color space to DeviceGray color space.
ColorPt convert2RGB(ColorPt in_color)
A convenience function used to convert color points from the current color space to DeviceRGB color space.
static ColorSpace createDeviceCMYK()
Create a new DeviceCMYK ColorSpace object.
static ColorSpace createDeviceGray()
Create a new DeviceGray ColorSpace object.
static ColorSpace createDeviceRGB()
Create a new DeviceRGB ColorSpace object.
static ColorSpace createICCFromBuffer(Doc doc, byte[] data)
Creates the icc from buffer in the given document
static ColorSpace createICCFromFile(Doc doc, String filepath)
Create a PDF 'ICCBased' color space given an ICC profile in the given document
static ColorSpace createICCFromFilter(Doc doc, Filter filter)
Creates the icc from filter in the given document
static ColorSpace createPattern()
Create a new Pattern ColorSpace object.
ColorSpace getAlternateColorSpace()
Get the alternate color space.
ColorPt getBaseColor(byte color_idx)
Get the base color given a component value (index) in Indexed color space.
ColorSpace getBaseColorSpace()
Get the base color space.
static int getComponentNum(int cs_type, Obj cs)
Get the number of components (tint components) used to represent color point for this color space
int getComponentNum()
Get the component number
byte[] getLookupTable()
Get the lookup table.
Obj getSDFObj()
Get the SDFObj
Function getTintFunction()
Get the tint function.
int getType()
Get ColorSpace type
static int getType(Obj cs)
Get type from specified ColorSpace object
void initColor(ColorPt out_colorants)
Set color to the initial value used for this color space.
void initComponentRanges(double[] out_decode_low, double[] out_decode_range)
Initialize default ranges for each color component in the color space.
boolean isAll()
Checks if Separation color space contains the colorant All.
boolean isNone()
Checks if Separation or DeviceN color space contains None colorants.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int e_cal_gray

The Constant e_cal_gray.

Constant Value: 3 (0x00000003)

public static final int e_cal_rgb

The Constant e_cal_rgb.

Constant Value: 4 (0x00000004)

public static final int e_device_cmyk

The Constant e_device_cmyk.

Constant Value: 2 (0x00000002)

public static final int e_device_gray

The Constant e_device_gray.

Constant Value: 0 (0x00000000)

public static final int e_device_n

The Constant e_device_n.

Constant Value: 10 (0x0000000a)

public static final int e_device_rgb

The Constant e_device_rgb.

Constant Value: 1 (0x00000001)

public static final int e_icc

The Constant e_icc.

Constant Value: 6 (0x00000006)

public static final int e_indexed

The Constant e_indexed.

Constant Value: 7 (0x00000007)

public static final int e_lab

The Constant e_lab.

Constant Value: 5 (0x00000005)

public static final int e_null

The Constant e_null.

Constant Value: 11 (0x0000000b)

public static final int e_pattern

The Constant e_pattern.

Constant Value: 8 (0x00000008)

public static final int e_separation

The Constant e_separation.

Constant Value: 9 (0x00000009)

Public Constructors

public ColorSpace (Obj color_space)

Create a ColorSpace from the given SDF/Cos object listed under ColorSpaces entry in page Resource dictionary. If color_space dictionary is null, a non valid ColorSpace object is created.

Parameters
color_space the input color space as Obj

Public Methods

public static ColorSpace __Create (long impl, Object ref)

public ColorPt convert2CMYK (ColorPt in_color)

A convenience function used to convert color points from the current color space to DeviceCMYK color space.

Note: the number to input colorants must match the number of colorants expected by the current color space.

Parameters
in_color input color point in the current color space
Returns
  • output color point in the DeviceRGB color space

public ColorPt convert2Gray (ColorPt in_color)

A convenience function used to convert color points from the current color space to DeviceGray color space.

Note: the number to input colorants must match the number of colorants expected by the current color space.

Parameters
in_color input color point in the current color space
Returns
  • output color point in the DeviceGray color space

public ColorPt convert2RGB (ColorPt in_color)

A convenience function used to convert color points from the current color space to DeviceRGB color space.

Note: the number to input colorants must match the number of colorants expected by the current color space.

Parameters
in_color input color point in the current color space
Returns
  • output color point in the DeviceRGB color space

public static ColorSpace createDeviceCMYK ()

Create a new DeviceCMYK ColorSpace object.

Returns
  • the created color space

public static ColorSpace createDeviceGray ()

Create a new DeviceGray ColorSpace object.

Returns
  • the created color space

public static ColorSpace createDeviceRGB ()

Create a new DeviceRGB ColorSpace object.

Returns
  • the created color space

public static ColorSpace createICCFromBuffer (Doc doc, byte[] data)

Creates the icc from buffer in the given document

Parameters
doc the input document
data the input buffer
Returns
  • the created color space

public static ColorSpace createICCFromFile (Doc doc, String filepath)

Create a PDF 'ICCBased' color space given an ICC profile in the given document

Parameters
doc input document
filepath input document filepath
Returns
  • the created color space

public static ColorSpace createICCFromFilter (Doc doc, Filter filter)

Creates the icc from filter in the given document

Parameters
doc the input document
filter the input filter
Returns
  • the created color space

public static ColorSpace createPattern ()

Create a new Pattern ColorSpace object.

Returns
  • the created color space

public ColorSpace getAlternateColorSpace ()

Get the alternate color space.

Returns
  • the alternate color space if it is available or NULL otherwise. Color spaces that include alternate color space are e_separation, e_device_n, and e_icc.

public ColorPt getBaseColor (byte color_idx)

Get the base color given a component value (index) in Indexed color space.

Note: for color spaces other than Indexed this method throws an exception.

Parameters
color_idx color value represented in the index color space
Returns
  • the color represented in the base (associated) color space

public ColorSpace getBaseColorSpace ()

Get the base color space.

Returns
  • the base color space if this is an e_indexed or e_pattern with associated base color space; NULL otherwise.

public static int getComponentNum (int cs_type, Obj cs)

Get the number of components (tint components) used to represent color point for this color space

Parameters
cs_type ColorSpace type
cs Cos/SDF color space object.
Returns
  • The number of components (tint components) used to represent color point for this created color space

public int getComponentNum ()

Get the component number

Returns
  • The number of colorants (tint components) used to represent color point in this color space

public byte[] getLookupTable ()

Get the lookup table.

Note: for color spaces other than Indexed this method throws an exception.

Returns
  • the color lookup table for Indexed color space. for color spaces other than indexed the method returns null.

public Obj getSDFObj ()

Get the SDFObj

Returns
  • the underlying SDF/Cos object

public Function getTintFunction ()

Get the tint function.

Note: for color spaces other than Separation this method throws an exception.

Returns
  • the function that transforms tint values into color component values in the alternate color space.

public int getType ()

Get ColorSpace type

Returns
  • The type of this color space

public static int getType (Obj cs)

Get type from specified ColorSpace object

Parameters
cs Cos/SDF color space object.
Returns
  • The Type of a given SDF/Cos color space, or e_null for if SDF object is not a valid color space

public void initColor (ColorPt out_colorants)

Set color to the initial value used for this color space. The initial value depends on the color space (see 4.5.7 in PDF Ref. Manual).

Parameters
out_colorants initial value

public void initComponentRanges (double[] out_decode_low, double[] out_decode_range)

Initialize default ranges for each color component in the color space. For example, default ranges for DeviceRGB are [0 1 0 1 0 1] but for Lab the default values might be [0 100 -100 100 -100 100].

Note: the size of resulting vectors will match the number of color components in this color space

Parameters
out_decode_low an array of numbers representing the lower bound for each color component.
out_decode_range an array of numbers representing the difference between high and low bound for each color component.
Throws
PDFNetException .

public boolean isAll ()

Checks if Separation color space contains the colorant All.

Note: for color spaces other than Separation this method throws an exception.

Returns
  • True if Separation color space contains the colorant All.

public boolean isNone ()

Checks if Separation or DeviceN color space contains None colorants.

Note: for color spaces other than Separation or DeviceN this method throws an exception.

Returns
  • True if Separation or DeviceN color space contains None colorants. For DeviceN the function returns true only if component colorant names are all None.