Class PDICCBased
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace
-
- org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace
-
- org.apache.pdfbox.pdmodel.graphics.color.PDICCBased
-
- All Implemented Interfaces:
COSObjectable
public final class PDICCBased extends PDCIEBasedColorSpace
ICCBased color spaces are based on a cross-platform color profile as defined by the International Color Consortium (ICC).
-
-
Field Summary
Fields Modifier and Type Field Description private PDColorSpacealternateColorSpaceprivate java.awt.color.ICC_ColorSpaceawtColorSpaceprivate java.awt.color.ICC_ProfileiccProfileprivate PDColorinitialColorprivate booleanisRGBprivate static org.apache.commons.logging.LogLOGprivate intnumberOfComponentsprivate PDStreamstreamprivate booleanuseOnlyAlternateColorSpace-
Fields inherited from class org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace
array
-
-
Constructor Summary
Constructors Modifier Constructor Description privatePDICCBased(COSArray iccArray)Creates a new ICC color space using the PDF array.PDICCBased(PDDocument doc)Creates a new ICC color space with an empty stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidcheckArray(COSArray iccArray)private float[]clampColors(java.awt.color.ICC_ColorSpace cs, float[] value)static PDICCBasedcreate(COSArray iccArray, PDResources resources)Creates a new ICC color space using the PDF array, optionally using a resource cache.private static java.awt.color.ICC_ProfileensureDisplayProfile(java.awt.color.ICC_Profile profile)private voidfallbackToAlternateColorSpace(java.lang.Exception e)PDColorSpacegetAlternateColorSpace()Returns a list of alternate color spaces for non-conforming readers.intgetColorSpaceType()Returns the type of the color space in the ICC profile.float[]getDefaultDecode(int bitsPerComponent)Returns the default decode array for this color space.PDColorgetInitialColor()Returns the initial color value for this color space.COSStreamgetMetadata()Returns the metadata stream for this object, or null if there is no metadata stream.java.lang.StringgetName()Returns the name of the color space.intgetNumberOfComponents()Returns the number of components in this color spacePDStreamgetPDStream()Get the underlying ICC profile stream.PDRangegetRangeForComponent(int n)Returns the range for a certain component number.private static voidintToBigEndian(int value, byte[] array, int index)private booleanis_sRGB(java.awt.color.ICC_Profile profile)Returns true if the given profile represents sRGB.(package private) booleanisSRGB()Internal accessor to support indexed raw images.private voidloadICCProfile()Load the ICC profile, or init alternateColorSpace color space.voidsetAlternateColorSpaces(java.util.List<PDColorSpace> list)Sets the list of alternateColorSpace color spaces.voidsetMetadata(COSStream metadata)Sets the metadata stream that is associated with this color space.voidsetRangeForComponent(PDRange range, int n)Sets the range for this color space.java.awt.image.BufferedImagetoRawImage(java.awt.image.WritableRaster raster)Returns the image in this colorspace or null.float[]toRGB(float[] value)Returns the RGB equivalent of the given color value.java.awt.image.BufferedImagetoRGBImage(java.awt.image.WritableRaster raster)Returns the (A)RGB equivalent of the given raster.java.lang.StringtoString()-
Methods inherited from class org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace
create, create, create, getCOSObject, toRawImage, toRGBImageAWT
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
stream
private final PDStream stream
-
numberOfComponents
private int numberOfComponents
-
iccProfile
private java.awt.color.ICC_Profile iccProfile
-
alternateColorSpace
private PDColorSpace alternateColorSpace
-
awtColorSpace
private java.awt.color.ICC_ColorSpace awtColorSpace
-
initialColor
private PDColor initialColor
-
isRGB
private boolean isRGB
-
useOnlyAlternateColorSpace
private boolean useOnlyAlternateColorSpace
-
-
Constructor Detail
-
PDICCBased
public PDICCBased(PDDocument doc)
Creates a new ICC color space with an empty stream.- Parameters:
doc- the document to store the ICC data
-
PDICCBased
private PDICCBased(COSArray iccArray) throws java.io.IOException
Creates a new ICC color space using the PDF array.- Parameters:
iccArray- the ICC stream object.- Throws:
java.io.IOException- if there is an error reading the ICC profile or if the parameter is invalid.
-
-
Method Detail
-
create
public static PDICCBased create(COSArray iccArray, PDResources resources) throws java.io.IOException
Creates a new ICC color space using the PDF array, optionally using a resource cache.- Parameters:
iccArray- the ICC stream object.resources- resources to use as cache, or null for no caching.- Returns:
- an ICC color space.
- Throws:
java.io.IOException- if there is an error reading the ICC profile or if the parameter is invalid.
-
checkArray
private static void checkArray(COSArray iccArray) throws java.io.IOException
- Throws:
java.io.IOException
-
getName
public java.lang.String getName()
Description copied from class:PDColorSpaceReturns the name of the color space.- Specified by:
getNamein classPDColorSpace- Returns:
- the name of the color space
-
getPDStream
public PDStream getPDStream()
Get the underlying ICC profile stream.- Returns:
- the underlying ICC profile stream
-
loadICCProfile
private void loadICCProfile() throws java.io.IOExceptionLoad the ICC profile, or init alternateColorSpace color space.- Throws:
java.io.IOException
-
fallbackToAlternateColorSpace
private void fallbackToAlternateColorSpace(java.lang.Exception e) throws java.io.IOException- Throws:
java.io.IOException
-
is_sRGB
private boolean is_sRGB(java.awt.color.ICC_Profile profile)
Returns true if the given profile represents sRGB. (unreliable on the data of ColorSpace.CS_sRGB in openjdk)
-
ensureDisplayProfile
private static java.awt.color.ICC_Profile ensureDisplayProfile(java.awt.color.ICC_Profile profile)
-
intToBigEndian
private static void intToBigEndian(int value, byte[] array, int index)
-
toRGB
public float[] toRGB(float[] value) throws java.io.IOExceptionDescription copied from class:PDColorSpaceReturns the RGB equivalent of the given color value.- Specified by:
toRGBin classPDColorSpace- 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
-
clampColors
private float[] clampColors(java.awt.color.ICC_ColorSpace cs, float[] value)
-
toRGBImage
public java.awt.image.BufferedImage toRGBImage(java.awt.image.WritableRaster raster) throws java.io.IOExceptionDescription copied from class:PDColorSpaceReturns the (A)RGB equivalent of the given raster.- Overrides:
toRGBImagein classPDCIEBasedColorSpace- Parameters:
raster- the source raster- Returns:
- an (A)RGB buffered image
- Throws:
java.io.IOException- if the color conversion fails
-
toRawImage
public java.awt.image.BufferedImage toRawImage(java.awt.image.WritableRaster raster) throws java.io.IOExceptionDescription copied from class:PDColorSpaceReturns 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 toPDColorSpace.toRGBImage(WritableRaster)if this returns null.- Overrides:
toRawImagein classPDCIEBasedColorSpace- 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- if the image conversion fails
-
getNumberOfComponents
public int getNumberOfComponents()
Description copied from class:PDColorSpaceReturns the number of components in this color space- Specified by:
getNumberOfComponentsin classPDColorSpace- Returns:
- the number of components in this color space
-
getDefaultDecode
public float[] getDefaultDecode(int bitsPerComponent)
Description copied from class:PDColorSpaceReturns the default decode array for this color space.- Specified by:
getDefaultDecodein classPDColorSpace- Parameters:
bitsPerComponent- the number of bits per component.- Returns:
- the default decode array
-
getInitialColor
public PDColor getInitialColor()
Description copied from class:PDColorSpaceReturns the initial color value for this color space.- Specified by:
getInitialColorin classPDColorSpace- Returns:
- the initial color value for this color space
-
getAlternateColorSpace
public PDColorSpace getAlternateColorSpace() throws java.io.IOException
Returns a list of alternate color spaces for non-conforming readers. WARNING: Do not use the information in a conforming reader.- Returns:
- A list of alternateColorSpace color spaces.
- Throws:
java.io.IOException- If there is an error getting the alternateColorSpace color spaces.
-
getRangeForComponent
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- the component number to get the range for- Returns:
- the range for this component
-
getMetadata
public COSStream getMetadata()
Returns the metadata stream for this object, or null if there is no metadata stream.- Returns:
- the metadata stream, or null if there is none
-
getColorSpaceType
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 ofTYPE_GRAY,TYPE_RGB,TYPE_CMYK, or -1 if that one is invalid.- Returns:
- an ICC color space type. See
ColorSpace.getType()and the static values ofColorSpacefor more details.
-
setAlternateColorSpaces
public void setAlternateColorSpaces(java.util.List<PDColorSpace> list)
Sets the list of alternateColorSpace color spaces.- Parameters:
list- the list of color space objects
-
setRangeForComponent
public void setRangeForComponent(PDRange range, int n)
Sets the range for this color space.- Parameters:
range- the new range for the a componentn- the component to set the range for
-
setMetadata
public void setMetadata(COSStream metadata)
Sets the metadata stream that is associated with this color space.- Parameters:
metadata- the new metadata stream
-
isSRGB
boolean isSRGB()
Internal accessor to support indexed raw images.- Returns:
- true if this colorspace is sRGB.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classPDCIEBasedColorSpace
-
-