Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.graphics.color

public abstract Class PDColorSpace

extends Object
implements COSObjectable
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.common.COSObjectable
Known Direct Subclasses
org.apache.pdfbox.pdmodel.graphics.color.PDDeviceColorSpace, org.apache.pdfbox.pdmodel.graphics.color.PDJPXColorSpace, org.apache.pdfbox.pdmodel.graphics.color.PDSpecialColorSpace, org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace
Imports
java.awt.Graphics, .Transparency, java.awt.image.BufferedImage, .ColorConvertOp, .ComponentColorModel, .WritableRaster, .ColorModel, java.awt.color.ColorSpace, java.io.IOException, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, .COSObject, org.apache.pdfbox.pdmodel.MissingResourceException, .PDResources, .ResourceCache, org.apache.pdfbox.pdmodel.common.COSObjectable

A color space specifies how the colours of graphics objects will be painted on the page.
Authors
John Hewson, Ben Litchfield

Field Summary

Modifier and TypeField and Description
protected COSArray
private final ColorConvertOp

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static PDColorSpace

Returns:

a new color space
create
(COSBase
the color space COS object
colorSpace
)

Creates a color space given a name or array.

public static PDColorSpace

Returns:

a new color space
create
(COSBase
the color space COS object
colorSpace
,
PDResources
the current resources.
resources
)

Creates a color space given a name or array.

public static PDColorSpace

Returns:

a new color space.
create
(COSBase
the color space COS object
colorSpace
,
PDResources
the current resources.
resources
,
boolean
if current color space was used by a default color space.
wasDefault
)

Creates a color space given a name or array.

private static PDColorSpace
createFromCOSObject(COSObject colorSpace, PDResources resources)

public COSBase
getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS object.

public abstract float[]

Returns:

the default decode array
getDefaultDecode
(int
the number of bits per component.
bitsPerComponent
)

Returns the default decode array for this color space.

public abstract PDColor

Returns:

the initial color value for this color space
getInitialColor
()

Returns the initial color value for this color space.

public abstract String

Returns:

the name of the color space
getName
()

Returns the name of the color space.

public abstract int

Returns:

the number of components in this color space
getNumberOfComponents
()

Returns the number of components in this color space

public abstract BufferedImage

Returns:

an buffered image in this colorspace. Or null if it is not possible to extract that image with the original colorspace without conversion.
toRawImage
(WritableRaster
the source raster
raster
)

Returns the image in this colorspace or null.

protected final BufferedImage

Returns:

a BufferedImage in this colorspace
toRawImage
(WritableRaster
the source raster
raster
,
ColorSpace
the AWT colorspace
awtColorSpace
)

Returns the given raster as BufferedImage with the given awtColorSpace using a ComponentColorModel.

public abstract float[]

Returns:

an array of R,G,B value between 0 and 255
toRGB
(float[]
a color value with component values between 0 and 1
value
)

Returns the RGB equivalent of the given color value.

public abstract BufferedImage

Returns:

an (A)RGB buffered image
toRGBImage
(WritableRaster
the source raster
raster
)

Returns the (A)RGB equivalent of the given raster.

protected BufferedImage

Returns:

an (A)RGB buffered image
toRGBImageAWT
(WritableRaster
the source raster
raster
,
ColorSpace
the AWT
colorSpace
)

Returns the (A)RGB equivalent of the given raster, using the given AWT color space to perform the conversion.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayback to summary
protected COSArray array
colorConvertOpback to summary
private final ColorConvertOp colorConvertOp

Constructor Detail

PDColorSpaceback to summary
public PDColorSpace()

Method Detail

createback to summary
public static PDColorSpace create(COSBase colorSpace) throws IOException

Creates a color space given a name or array.

Parameters
colorSpace:COSBase

the color space COS object

Returns:PDColorSpace

a new color space

Exceptions
IOException:
if the color space is unknown or cannot be created
createback to summary
public static PDColorSpace create(COSBase colorSpace, PDResources resources) throws IOException

Creates a color space given a name or array. Abbreviated device color names are not supported here, please replace them first.

Parameters
colorSpace:COSBase

the color space COS object

resources:PDResources

the current resources.

Returns:PDColorSpace

a new color space

Exceptions
IOException:
if the color space is unknown or cannot be created
MissingResourceException:
if the color space is missing in the resources dictionary
createback to summary
public static PDColorSpace create(COSBase colorSpace, PDResources resources, boolean wasDefault) throws IOException

Creates a color space given a name or array. Abbreviated device color names are not supported here, please replace them first. This method is for PDFBox internal use only, others should use create(COSBase, PDResources).

Parameters
colorSpace:COSBase

the color space COS object

resources:PDResources

the current resources.

wasDefault:boolean

if current color space was used by a default color space.

Returns:PDColorSpace

a new color space.

Exceptions
IOException:
if the color space is unknown or cannot be created.
MissingResourceException:
if the color space is missing in the resources dictionary
createFromCOSObjectback to summary
private static PDColorSpace createFromCOSObject(COSObject colorSpace, PDResources resources) throws IOException
getCOSObjectback to summary
public COSBase getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Doc from org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS object.

Returns:COSBase

The cos object that matches this Java object.

Annotations
@Override
getDefaultDecodeback to summary
public abstract float[] getDefaultDecode(int bitsPerComponent)

Returns the default decode array for this color space.

Parameters
bitsPerComponent:int

the number of bits per component.

Returns:float[]

the default decode array

getInitialColorback to summary
public abstract PDColor getInitialColor()

Returns the initial color value for this color space.

Returns:PDColor

the initial color value for this color space

getNameback to summary
public abstract String getName()

Returns the name of the color space.

Returns:String

the name of the color space

getNumberOfComponentsback to summary
public abstract int getNumberOfComponents()

Returns the number of components in this color space

Returns:int

the number of components in this color space

toRawImageback to summary
public abstract BufferedImage toRawImage(WritableRaster raster) throws IOException

Returns the image in this colorspace or null. No conversion is performed. For special colorspaces like PDSeparation the image is returned in the gray colorspace. For undefined colorspaces like DeviceCMYK/DeviceRGB and DeviceGray null is returned. You can always fallback to toRGBImage(WritableRaster) if this returns null.

Parameters
raster:WritableRaster

the source raster

Returns:BufferedImage

an buffered image in this colorspace. Or null if it is not possible to extract that image with the original colorspace without conversion.

Exceptions
IOException:
if the image conversion fails
toRawImageback to summary
protected final BufferedImage toRawImage(WritableRaster raster, ColorSpace awtColorSpace)

Returns the given raster as BufferedImage with the given awtColorSpace using a ComponentColorModel.

Parameters
raster:WritableRaster

the source raster

awtColorSpace:ColorSpace

the AWT colorspace

Returns:BufferedImage

a BufferedImage in this colorspace

toRGBback to summary
public abstract float[] toRGB(float[] value) throws IOException

Returns the RGB equivalent of the given color value.

Parameters
value:float[]

a color value with component values between 0 and 1

Returns:float[]

an array of R,G,B value between 0 and 255

Exceptions
IOException:
if the color conversion fails
toRGBImageback to summary
public abstract BufferedImage toRGBImage(WritableRaster raster) throws IOException

Returns the (A)RGB equivalent of the given raster.

Parameters
raster:WritableRaster

the source raster

Returns:BufferedImage

an (A)RGB buffered image

Exceptions
IOException:
if the color conversion fails
toRGBImageAWTback to summary
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)

Returns the (A)RGB equivalent of the given raster, using the given AWT color space to perform the conversion.

Parameters
raster:WritableRaster

the source raster

colorSpace:ColorSpace

the AWT

Returns:BufferedImage

an (A)RGB buffered image