Class PDColorSpace
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace
-
- All Implemented Interfaces:
COSObjectable
- Direct Known Subclasses:
PDCIEBasedColorSpace
,PDDeviceColorSpace
,PDJPXColorSpace
,PDSpecialColorSpace
public abstract class PDColorSpace extends java.lang.Object implements COSObjectable
A color space specifies how the colours of graphics objects will be painted on the page.
-
-
Constructor Summary
Constructors Constructor Description PDColorSpace()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static PDColorSpace
create(COSBase colorSpace)
Creates a color space given a name or array.static PDColorSpace
create(COSBase colorSpace, PDResources resources)
Creates a color space given a name or array.static PDColorSpace
create(COSBase colorSpace, PDResources resources, boolean wasDefault)
Creates a color space given a name or array.private static PDColorSpace
createFromCOSObject(COSObject colorSpace, PDResources resources)
COSBase
getCOSObject()
Convert this standard java object to a COS object.abstract float[]
getDefaultDecode(int bitsPerComponent)
Returns the default decode array for this color space.abstract PDColor
getInitialColor()
Returns the initial color value for this color space.abstract java.lang.String
getName()
Returns the name of the color space.abstract int
getNumberOfComponents()
Returns the number of components in this color spaceabstract java.awt.image.BufferedImage
toRawImage(java.awt.image.WritableRaster raster)
Returns the image in this colorspace or null.protected java.awt.image.BufferedImage
toRawImage(java.awt.image.WritableRaster raster, java.awt.color.ColorSpace awtColorSpace)
Returns the given raster as BufferedImage with the given awtColorSpace using a ComponentColorModel.abstract float[]
toRGB(float[] value)
Returns the RGB equivalent of the given color value.abstract java.awt.image.BufferedImage
toRGBImage(java.awt.image.WritableRaster raster)
Returns the (A)RGB equivalent of the given raster.protected java.awt.image.BufferedImage
toRGBImageAWT(java.awt.image.WritableRaster raster, java.awt.color.ColorSpace colorSpace)
Returns the (A)RGB equivalent of the given raster, using the given AWT color space to perform the conversion.
-
-
-
Field Detail
-
array
protected COSArray array
-
-
Method Detail
-
create
public static PDColorSpace create(COSBase colorSpace) throws java.io.IOException
Creates a color space given a name or array.- Parameters:
colorSpace
- the color space COS object- Returns:
- a new color space
- Throws:
java.io.IOException
- if the color space is unknown or cannot be created
-
create
public static PDColorSpace create(COSBase colorSpace, PDResources resources) throws java.io.IOException
Creates a color space given a name or array. Abbreviated device color names are not supported here, please replace them first.- Parameters:
colorSpace
- the color space COS objectresources
- the current resources.- Returns:
- a new color space
- Throws:
MissingResourceException
- if the color space is missing in the resources dictionaryjava.io.IOException
- if the color space is unknown or cannot be created
-
create
public static PDColorSpace create(COSBase colorSpace, PDResources resources, boolean wasDefault) throws java.io.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 usecreate(COSBase, PDResources)
.- Parameters:
colorSpace
- the color space COS objectresources
- the current resources.wasDefault
- if current color space was used by a default color space.- Returns:
- a new color space.
- Throws:
MissingResourceException
- if the color space is missing in the resources dictionaryjava.io.IOException
- if the color space is unknown or cannot be created.
-
createFromCOSObject
private static PDColorSpace createFromCOSObject(COSObject colorSpace, PDResources resources) throws java.io.IOException
- Throws:
java.io.IOException
-
getName
public abstract java.lang.String getName()
Returns the name of the color space.- Returns:
- the name of the color space
-
getNumberOfComponents
public abstract int getNumberOfComponents()
Returns the number of components in this color space- Returns:
- the number of components in this color space
-
getDefaultDecode
public abstract float[] getDefaultDecode(int bitsPerComponent)
Returns the default decode array for this color space.- Parameters:
bitsPerComponent
- the number of bits per component.- Returns:
- the default decode array
-
getInitialColor
public abstract PDColor getInitialColor()
Returns the initial color value for this color space.- Returns:
- the initial color value for this color space
-
toRGB
public abstract float[] toRGB(float[] value) throws java.io.IOException
Returns the RGB equivalent of the given color value.- Parameters:
value
- a color value with component values between 0 and 1- Returns:
- an array of R,G,B value between 0 and 255
- Throws:
java.io.IOException
- if the color conversion fails
-
toRGBImage
public abstract java.awt.image.BufferedImage toRGBImage(java.awt.image.WritableRaster raster) throws java.io.IOException
Returns the (A)RGB equivalent of the given raster.- Parameters:
raster
- the source raster- Returns:
- an (A)RGB buffered image
- Throws:
java.io.IOException
- if the color conversion fails
-
toRawImage
public abstract java.awt.image.BufferedImage toRawImage(java.awt.image.WritableRaster raster) throws java.io.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 totoRGBImage(WritableRaster)
if this returns null.- Parameters:
raster
- the source raster- Returns:
- an buffered image in this colorspace. Or null if it is not possible to extract that image with the original colorspace without conversion.
- Throws:
java.io.IOException
-
toRawImage
protected final java.awt.image.BufferedImage toRawImage(java.awt.image.WritableRaster raster, java.awt.color.ColorSpace awtColorSpace)
Returns the given raster as BufferedImage with the given awtColorSpace using a ComponentColorModel.- Parameters:
raster
- the source rasterawtColorSpace
- the AWT colorspace- Returns:
- a BufferedImage in this colorspace
-
toRGBImageAWT
protected java.awt.image.BufferedImage toRGBImageAWT(java.awt.image.WritableRaster raster, java.awt.color.ColorSpace colorSpace)
Returns the (A)RGB equivalent of the given raster, using the given AWT color space to perform the conversion.- Parameters:
raster
- the source rastercolorSpace
- the AWT- Returns:
- an (A)RGB buffered image
-
getCOSObject
public COSBase getCOSObject()
Description copied from interface:COSObjectable
Convert this standard java object to a COS object.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
-