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

public final Class PDICCBased

extends PDCIEBasedColorSpace
Class Inheritance
Imports
java.awt.Transparency, java.awt.color.CMMException, .ColorSpace, .ICC_ColorSpace, .ICC_Profile, .ProfileDataException, java.awt.image.BufferedImage, .ComponentColorModel, .DataBuffer, .WritableRaster, java.io.IOException, .InputStream, java.nio.charset.StandardCharsets, java.util.Arrays, .List, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSFloat, .COSName, .COSStream, .COSObject, org.apache.pdfbox.pdmodel.PDDocument, .PDResources, .ResourceCache, org.apache.pdfbox.pdmodel.common.PDRange, .PDStream

ICCBased color spaces are based on a cross-platform color profile as defined by the International Color Consortium (ICC).
Authors
Ben Litchfield, John Hewson

Field Summary

Modifier and TypeField and Description
private PDColorSpace
private ICC_ColorSpace
private ICC_Profile
private PDColor
private boolean
private static final Log
private int
private final PDStream
private boolean

Constructor Summary

AccessConstructor and Description
public
PDICCBased(PDDocument
the document to store the ICC data
doc
)

Creates a new ICC color space with an empty stream.

private
PDICCBased(COSArray
the ICC stream object.
iccArray
)

Creates a new ICC color space using the PDF array.

Method Summary

Modifier and TypeMethod and Description
private static void
checkArray(COSArray iccArray)

private float[]
clampColors(ICC_ColorSpace cs, float[] value)

public static PDICCBased

Returns:

an ICC color space.
create
(COSArray
the ICC stream object.
iccArray
,
PDResources
resources to use as cache, or null for no caching.
resources
)

Creates a new ICC color space using the PDF array, optionally using a resource cache.

private static ICC_Profile
private void
public PDColorSpace

Returns:

A list of alternateColorSpace color spaces.
getAlternateColorSpace
()

Returns a list of alternate color spaces for non-conforming readers.

public int

Returns:

an ICC color space type. See ColorSpace#getType() and the static values of ColorSpace for more details.
getColorSpaceType
()

Returns the type of the color space in the ICC profile.

public float[]
getDefaultDecode(int
the number of bits per component.
bitsPerComponent
)

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getDefaultDecode.

Returns the default decode array for this color space.

public PDColor
getInitialColor()

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getInitialColor.

Returns the initial color value for this color space.

public COSStream

Returns:

the metadata stream, or null if there is none
getMetadata
()

Returns the metadata stream for this object, or null if there is no metadata stream.

public String
getName()

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getName.

Returns the name of the color space.

public int
getNumberOfComponents()

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getNumberOfComponents.

Returns the number of components in this color space

public PDStream

Returns:

the underlying ICC profile stream
getPDStream
()

Get the underlying ICC profile stream.

public PDRange

Returns:

the range for this component
getRangeForComponent
(int
the component number to get the range for
n
)

Returns the range for a certain component number.

private static void
intToBigEndian(int value, byte[] array, int index)

private boolean
is_sRGB(ICC_Profile profile)

Returns true if the given profile represents sRGB.

pack-priv boolean

Returns:

true if this colorspace is sRGB.
isSRGB
()

Internal accessor to support indexed raw images.

private void
loadICCProfile()

Load the ICC profile, or init alternateColorSpace color space.

public void
setAlternateColorSpaces(List<PDColorSpace>
the list of color space objects
list
)

Sets the list of alternateColorSpace color spaces.

public void
setMetadata(COSStream
the new metadata stream
metadata
)

Sets the metadata stream that is associated with this color space.

public void
setRangeForComponent(PDRange
the new range for the a component
range
,
int
the component to set the range for
n
)

Sets the range for this color space.

public BufferedImage
toRawImage(WritableRaster
the source raster
raster
)

Overrides org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace.toRawImage.

Returns the image in this colorspace or null.

public float[]
toRGB(float[]
a color value with component values between 0 and 1
value
)

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.toRGB.

Returns the RGB equivalent of the given color value.

public BufferedImage
toRGBImage(WritableRaster
the source raster
raster
)

Overrides org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace.toRGBImage.

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

public String
toString()

Overrides org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace.toString.

Returns a string representation of the object.

Field Detail

alternateColorSpaceback to summary
private PDColorSpace alternateColorSpace
awtColorSpaceback to summary
private ICC_ColorSpace awtColorSpace
iccProfileback to summary
private ICC_Profile iccProfile
initialColorback to summary
private PDColor initialColor
isRGBback to summary
private boolean isRGB
LOGback to summary
private static final Log LOG
numberOfComponentsback to summary
private int numberOfComponents
streamback to summary
private final PDStream stream
useOnlyAlternateColorSpaceback to summary
private boolean useOnlyAlternateColorSpace

Constructor Detail

PDICCBasedback to summary
public PDICCBased(PDDocument doc)

Creates a new ICC color space with an empty stream.

Parameters
doc:PDDocument

the document to store the ICC data

PDICCBasedback to summary
private PDICCBased(COSArray iccArray) throws IOException

Creates a new ICC color space using the PDF array.

Parameters
iccArray:COSArray

the ICC stream object.

Exceptions
IOException:
if there is an error reading the ICC profile or if the parameter is invalid.

Method Detail

checkArrayback to summary
private static void checkArray(COSArray iccArray) throws IOException
clampColorsback to summary
private float[] clampColors(ICC_ColorSpace cs, float[] value)
createback to summary
public static PDICCBased create(COSArray iccArray, PDResources resources) throws IOException

Creates a new ICC color space using the PDF array, optionally using a resource cache.

Parameters
iccArray:COSArray

the ICC stream object.

resources:PDResources

resources to use as cache, or null for no caching.

Returns:PDICCBased

an ICC color space.

Exceptions
IOException:
if there is an error reading the ICC profile or if the parameter is invalid.
ensureDisplayProfileback to summary
private static ICC_Profile ensureDisplayProfile(ICC_Profile profile)
fallbackToAlternateColorSpaceback to summary
private void fallbackToAlternateColorSpace(Exception e) throws IOException
getAlternateColorSpaceback to summary
public PDColorSpace getAlternateColorSpace() throws IOException

Returns a list of alternate color spaces for non-conforming readers.

Warning

Do not use the information in a conforming reader.

Returns:PDColorSpace

A list of alternateColorSpace color spaces.

Exceptions
IOException:
If there is an error getting the alternateColorSpace color spaces.
getColorSpaceTypeback to summary
public int getColorSpaceType()

Returns the type of the color space in the ICC profile. If the ICC profile is invalid, the type of the alternate colorspace is returned, which will be one of TYPE_GRAY, TYPE_RGB, TYPE_CMYK, or -1 if that one is invalid.

Returns:int

an ICC color space type. See ColorSpace#getType() and the static values of ColorSpace for more details.

getDefaultDecodeback to summary
public float[] getDefaultDecode(int bitsPerComponent)

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getDefaultDecode.

Doc from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getDefaultDecode.

Returns the default decode array for this color space.

Parameters
bitsPerComponent:int

the number of bits per component.

Returns:float[]

the default decode array

Annotations
@Override
getInitialColorback to summary
public PDColor getInitialColor()

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getInitialColor.

Doc from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getInitialColor.

Returns the initial color value for this color space.

Returns:PDColor

the initial color value for this color space

Annotations
@Override
getMetadataback to summary
public COSStream getMetadata()

Returns the metadata stream for this object, or null if there is no metadata stream.

Returns:COSStream

the metadata stream, or null if there is none

getNameback to summary
public String getName()

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getName.

Doc from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getName.

Returns the name of the color space.

Returns:String

the name of the color space

Annotations
@Override
getNumberOfComponentsback to summary
public int getNumberOfComponents()

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getNumberOfComponents.

Doc from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.getNumberOfComponents.

Returns the number of components in this color space

Returns:int

the number of components in this color space

Annotations
@Override
getPDStreamback to summary
public PDStream getPDStream()

Get the underlying ICC profile stream.

Returns:PDStream

the underlying ICC profile stream

getRangeForComponentback to summary
public PDRange getRangeForComponent(int n)

Returns the range for a certain component number. This will never return null. If it is not present then the range 0..1 will be returned.

Parameters
n:int

the component number to get the range for

Returns:PDRange

the range for this component

intToBigEndianback to summary
private static void intToBigEndian(int value, byte[] array, int index)
is_sRGBback to summary
private boolean is_sRGB(ICC_Profile profile)

Returns true if the given profile represents sRGB. (unreliable on the data of ColorSpace.CS_sRGB in openjdk)

isSRGBback to summary
pack-priv boolean isSRGB()

Internal accessor to support indexed raw images.

Returns:boolean

true if this colorspace is sRGB.

loadICCProfileback to summary
private void loadICCProfile() throws IOException

Load the ICC profile, or init alternateColorSpace color space.

setAlternateColorSpacesback to summary
public void setAlternateColorSpaces(List<PDColorSpace> list)

Sets the list of alternateColorSpace color spaces.

Parameters
list:List<PDColorSpace>

the list of color space objects

setMetadataback to summary
public void setMetadata(COSStream metadata)

Sets the metadata stream that is associated with this color space.

Parameters
metadata:COSStream

the new metadata stream

setRangeForComponentback to summary
public void setRangeForComponent(PDRange range, int n)

Sets the range for this color space.

Parameters
range:PDRange

the new range for the a component

n:int

the component to set the range for

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

Overrides org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace.toRawImage.

Doc from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.toRawImage.

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.

Annotations
@Override
Exceptions
IOException:
if the image conversion fails
toRGBback to summary
public float[] toRGB(float[] value) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.toRGB.

Doc from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.toRGB.

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

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

Overrides org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace.toRGBImage.

Doc from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.toRGBImage.

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

Parameters
raster:WritableRaster

the source raster

Returns:BufferedImage

an (A)RGB buffered image

Annotations
@Override
Exceptions
IOException:
if the color conversion fails
toStringback to summary
public String toString()

Overrides org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override