aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/pdfbox/pdmodel/graphics/color
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/pdfbox/pdmodel/graphics/color')
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalGray.java240
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalRGB.java289
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpace.java97
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java218
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java130
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java137
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceGray.java112
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceN.java244
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java126
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java130
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDGamma.java151
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDICCBased.java343
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDIndexed.java271
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDLab.java300
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDPattern.java122
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDSeparation.java198
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/PDTristimulus.java155
-rw-r--r--src/main/java/org/pdfbox/pdmodel/graphics/color/package.html9
18 files changed, 3272 insertions, 0 deletions
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalGray.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalGray.java
new file mode 100644
index 0000000..fc6f84e
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalGray.java
@@ -0,0 +1,240 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSDictionary;
+import org.pdfbox.cos.COSFloat;
+import org.pdfbox.cos.COSName;
+import org.pdfbox.cos.COSNumber;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+
+import java.io.IOException;
+
+/**
+ * This class represents a Cal Gray color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.4 $
+ */
+public class PDCalGray extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "CalGray";
+
+ private COSArray array;
+ private COSDictionary dictionary;
+
+ /**
+ * Constructor.
+ */
+ public PDCalGray()
+ {
+ array = new COSArray();
+ dictionary = new COSDictionary();
+ array.add( COSName.getPDFName( NAME ) );
+ array.add( dictionary );
+ }
+
+ /**
+ * Constructor with array.
+ *
+ * @param gray The underlying color space.
+ */
+ public PDCalGray( COSArray gray )
+ {
+ array = gray;
+ dictionary = (COSDictionary)array.getObject( 1 );
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return 1;
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return array;
+ }
+
+ /**
+ * This will get the gamma value. If none is present then the default of 1
+ * will be returned.
+ *
+ * @return The gamma value.
+ */
+ public float getGamma()
+ {
+ float retval = 1.0f;
+ COSNumber gamma = (COSNumber)dictionary.getDictionaryObject( COSName.getPDFName( "Gamma" ) );
+ if( gamma != null )
+ {
+ retval = gamma.floatValue();
+ }
+ return retval;
+ }
+
+ /**
+ * Set the gamma value.
+ *
+ * @param value The new gamma value.
+ */
+ public void setGamma( float value )
+ {
+ dictionary.setItem( COSName.getPDFName( "Gamma" ), new COSFloat( value ) );
+ }
+
+ /**
+ * This will return the whitepoint tristimulus. As this is a required field
+ * this will never return null. A default of 1,1,1 will be returned if the
+ * pdf does not have any values yet.
+ *
+ * @return The whitepoint tristimulus.
+ */
+ public PDTristimulus getWhitepoint()
+ {
+ PDTristimulus retval = null;
+ COSArray wp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "WhitePoint" ) );
+ if( wp == null )
+ {
+ wp.add( new COSFloat( 1.0f ) );
+ wp.add( new COSFloat( 1.0f ) );
+ wp.add( new COSFloat( 1.0f ) );
+ dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wp );
+ }
+ return new PDTristimulus( wp );
+ }
+
+ /**
+ * This will set the whitepoint tristimulus. As this is a required field
+ * this null should not be passed into this function.
+ *
+ * @param wp The whitepoint tristimulus.
+ */
+ public void setWhitepoint( PDTristimulus wp )
+ {
+ COSBase wpArray = wp.getCOSObject();
+ if( wpArray != null )
+ {
+ dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wpArray );
+ }
+ }
+
+ /**
+ * This will return the BlackPoint tristimulus. This is an optional field but
+ * has defaults so this will never return null.
+ * A default of 0,0,0 will be returned if the pdf does not have any values yet.
+ *
+ * @return The blackpoint tristimulus.
+ */
+ public PDTristimulus getBlackPoint()
+ {
+ PDTristimulus retval = null;
+ COSArray bp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "BlackPoint" ) );
+ if( bp == null )
+ {
+ bp.add( new COSFloat( 0.0f ) );
+ bp.add( new COSFloat( 0.0f ) );
+ bp.add( new COSFloat( 0.0f ) );
+ dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bp );
+ }
+ return new PDTristimulus( bp );
+ }
+
+ /**
+ * This will set the BlackPoint tristimulus. As this is a required field
+ * this null should not be passed into this function.
+ *
+ * @param bp The BlackPoint tristimulus.
+ */
+ public void setBlackPoint( PDTristimulus bp )
+ {
+ COSBase bpArray = null;
+ if( bp != null )
+ {
+ bpArray = bp.getCOSObject();
+ }
+ dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bpArray );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalRGB.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalRGB.java
new file mode 100644
index 0000000..6aa4eb1
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDCalRGB.java
@@ -0,0 +1,289 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSDictionary;
+import org.pdfbox.cos.COSFloat;
+import org.pdfbox.cos.COSName;
+
+import org.pdfbox.pdmodel.common.PDMatrix;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+
+import java.io.IOException;
+
+/**
+ * This class represents a Cal RGB color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.2 $
+ */
+public class PDCalRGB extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "CalRGB";
+
+ private COSArray array;
+ private COSDictionary dictionary;
+
+ /**
+ * Constructor.
+ */
+ public PDCalRGB()
+ {
+ array = new COSArray();
+ dictionary = new COSDictionary();
+ array.add( COSName.getPDFName( NAME ) );
+ array.add( dictionary );
+ }
+
+ /**
+ * Constructor with array.
+ *
+ * @param rgb The underlying color space.
+ */
+ public PDCalRGB( COSArray rgb )
+ {
+ array = rgb;
+ dictionary = (COSDictionary)array.getObject( 1 );
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return 3;
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return array;
+ }
+
+ /**
+ * This will return the whitepoint tristimulus. As this is a required field
+ * this will never return null. A default of 1,1,1 will be returned if the
+ * pdf does not have any values yet.
+ *
+ * @return The whitepoint tristimulus.
+ */
+ public PDTristimulus getWhitepoint()
+ {
+ PDTristimulus retval = null;
+ COSArray wp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "WhitePoint" ) );
+ if( wp == null )
+ {
+ wp.add( new COSFloat( 1.0f ) );
+ wp.add( new COSFloat( 1.0f ) );
+ wp.add( new COSFloat( 1.0f ) );
+ dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wp );
+ }
+ return new PDTristimulus( wp );
+ }
+
+ /**
+ * This will set the whitepoint tristimulus. As this is a required field
+ * this null should not be passed into this function.
+ *
+ * @param wp The whitepoint tristimulus.
+ */
+ public void setWhitepoint( PDTristimulus wp )
+ {
+ COSBase wpArray = wp.getCOSObject();
+ if( wpArray != null )
+ {
+ dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wpArray );
+ }
+ }
+
+ /**
+ * This will return the BlackPoint tristimulus. This is an optional field but
+ * has defaults so this will never return null.
+ * A default of 0,0,0 will be returned if the pdf does not have any values yet.
+ *
+ * @return The blackpoint tristimulus.
+ */
+ public PDTristimulus getBlackPoint()
+ {
+ PDTristimulus retval = null;
+ COSArray bp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "BlackPoint" ) );
+ if( bp == null )
+ {
+ bp.add( new COSFloat( 0.0f ) );
+ bp.add( new COSFloat( 0.0f ) );
+ bp.add( new COSFloat( 0.0f ) );
+ dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bp );
+ }
+ return new PDTristimulus( bp );
+ }
+
+ /**
+ * This will set the BlackPoint tristimulus. As this is a required field
+ * this null should not be passed into this function.
+ *
+ * @param bp The BlackPoint tristimulus.
+ */
+ public void setBlackPoint( PDTristimulus bp )
+ {
+
+ COSBase bpArray = null;
+ if( bp != null )
+ {
+ bpArray = bp.getCOSObject();
+ }
+ dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bpArray );
+ }
+
+ /**
+ * This will get the gamma value. If none is present then the default of 1,1,1
+ * will be returned.
+ *
+ * @return The gamma value.
+ */
+ public PDGamma getGamma()
+ {
+ COSArray gamma = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "Gamma" ) );
+ if( gamma == null )
+ {
+ gamma = new COSArray();
+ gamma.add( new COSFloat( 1.0f ) );
+ gamma.add( new COSFloat( 1.0f ) );
+ gamma.add( new COSFloat( 1.0f ) );
+ dictionary.setItem( COSName.getPDFName( "Gamma" ), gamma );
+ }
+ return new PDGamma( gamma );
+ }
+
+ /**
+ * Set the gamma value.
+ *
+ * @param value The new gamma value.
+ */
+ public void setGamma( PDGamma value )
+ {
+ COSArray gamma = null;
+ if( value != null )
+ {
+ gamma = (COSArray)value.getCOSArray();
+ }
+ dictionary.setItem( COSName.getPDFName( "Gamma" ), gamma );
+ }
+
+ /**
+ * This will get the linear interpretation array. This is guaranteed to not
+ * return null. If the underlying dictionary contains null then the identity
+ * matrix will be returned.
+ *
+ * @return The linear interpretation matrix.
+ */
+ public PDMatrix getLinearInterpretation()
+ {
+ PDMatrix retval = null;
+ COSArray matrix = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "Matrix" ) );
+ if( matrix == null )
+ {
+ retval = new PDMatrix();
+ setLinearInterpretation( retval );
+ }
+ else
+ {
+ retval = new PDMatrix( matrix );
+ }
+ return retval;
+ }
+
+ /**
+ * This will set the linear interpretation matrix. Passing in null will
+ * clear the matrix.
+ *
+ * @param matrix The new linear interpretation matrix.
+ */
+ public void setLinearInterpretation( PDMatrix matrix )
+ {
+ COSArray matrixArray = null;
+ if( matrix != null )
+ {
+ matrixArray = matrix.getCOSArray();
+ }
+ dictionary.setItem( COSName.getPDFName( "Matrix" ), matrixArray );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpace.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpace.java
new file mode 100644
index 0000000..33ac0a1
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpace.java
@@ -0,0 +1,97 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSName;
+
+import org.pdfbox.pdmodel.common.COSObjectable;
+
+import java.io.IOException;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+
+
+/**
+ * This class represents a color space in a pdf document.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.4 $
+ */
+public abstract class PDColorSpace implements COSObjectable
+{
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public abstract String getName();
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public abstract int getNumberOfComponents() throws IOException;
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return COSName.getPDFName( getName() );
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public abstract ColorSpace createColorSpace() throws IOException;
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public abstract ColorModel createColorModel( int bpc ) throws IOException;
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java
new file mode 100644
index 0000000..8c9aad5
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java
@@ -0,0 +1,218 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSFloat;
+import org.pdfbox.cos.COSName;
+import org.pdfbox.pdmodel.PDDocument;
+import org.pdfbox.pdmodel.common.PDStream;
+
+/**
+ * This class represents a color space in a pdf document.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.10 $
+ */
+public final class PDColorSpaceFactory
+{
+ /**
+ * Private constructor for utility classes.
+ */
+ private PDColorSpaceFactory()
+ {
+ //utility class should not be implemented
+ }
+
+ /**
+ * This will create the correct color space given the name.
+ *
+ * @param colorSpace The color space object.
+ *
+ * @return The color space.
+ *
+ * @throws IOException If the color space name is unknown.
+ */
+ public static PDColorSpace createColorSpace( COSBase colorSpace ) throws IOException
+ {
+ PDColorSpace retval = null;
+ if( colorSpace instanceof COSName )
+ {
+ retval = createColorSpace( ((COSName)colorSpace).getName() );
+ }
+ else if( colorSpace instanceof COSArray )
+ {
+ COSArray array = (COSArray)colorSpace;
+ COSName type = (COSName)array.getObject( 0 );
+ if( type.getName().equals( PDCalGray.NAME ) )
+ {
+ retval = new PDCalGray( array );
+ }
+ else if( type.getName().equals( PDCalRGB.NAME ) )
+ {
+ retval = new PDCalRGB( array );
+ }
+ else if( type.getName().equals( PDDeviceN.NAME ) )
+ {
+ retval = new PDDeviceN( array );
+ }
+ else if( type.getName().equals( PDIndexed.NAME ) ||
+ type.getName().equals( PDIndexed.ABBREVIATED_NAME ))
+ {
+ retval = new PDIndexed( array );
+ }
+ else if( type.getName().equals( PDLab.NAME ) )
+ {
+ retval = new PDLab( array );
+ }
+ else if( type.getName().equals( PDSeparation.NAME ) )
+ {
+ retval = new PDSeparation( array );
+ }
+ else if( type.getName().equals( PDICCBased.NAME ) )
+ {
+ retval = new PDICCBased( array );
+ }
+ else if( type.getName().equals( PDPattern.NAME ) )
+ {
+ retval = new PDPattern( array );
+ }
+ else
+ {
+ throw new IOException( "Unknown colorspace array type:" + type );
+ }
+ }
+ else
+ {
+ throw new IOException( "Unknown colorspace type:" + colorSpace );
+ }
+ return retval;
+ }
+
+ /**
+ * This will create the correct color space given the name.
+ *
+ * @param colorSpaceName The name of the colorspace.
+ *
+ * @return The color space.
+ *
+ * @throws IOException If the color space name is unknown.
+ */
+ public static PDColorSpace createColorSpace( String colorSpaceName ) throws IOException
+ {
+ PDColorSpace cs = null;
+ if( colorSpaceName.equals( PDDeviceCMYK.NAME ) ||
+ colorSpaceName.equals( PDDeviceCMYK.ABBREVIATED_NAME ) )
+ {
+ cs = PDDeviceCMYK.INSTANCE;
+ }
+ else if( colorSpaceName.equals( PDDeviceRGB.NAME ) ||
+ colorSpaceName.equals( PDDeviceRGB.ABBREVIATED_NAME ) )
+ {
+ cs = PDDeviceRGB.INSTANCE;
+ }
+ else if( colorSpaceName.equals( PDDeviceGray.NAME ) ||
+ colorSpaceName.equals( PDDeviceGray.ABBREVIATED_NAME ))
+ {
+ cs = new PDDeviceGray();
+ }
+ else if( colorSpaceName.equals( PDLab.NAME ) )
+ {
+ cs = new PDLab();
+ }
+ else if( colorSpaceName.equals( PDPattern.NAME ) )
+ {
+ cs = new PDPattern();
+ }
+ else
+ {
+ throw new IOException( "Error: Unknown colorspace '" + colorSpaceName + "'" );
+ }
+ return cs;
+ }
+
+ /**
+ * This will create the correct color space from a java colorspace.
+ *
+ * @param doc The doc to potentiall write information to.
+ * @param cs The awt colorspace.
+ *
+ * @return The color space.
+ *
+ * @throws IOException If the color space name is unknown.
+ */
+ public static PDColorSpace createColorSpace( PDDocument doc, ColorSpace cs ) throws IOException
+ {
+ PDColorSpace retval = null;
+ if( cs.isCS_sRGB() )
+ {
+ retval = PDDeviceRGB.INSTANCE;
+ }
+ else if( cs instanceof ICC_ColorSpace )
+ {
+ ICC_ColorSpace ics = (ICC_ColorSpace)cs;
+ PDICCBased pdCS = new PDICCBased( doc );
+ retval = pdCS;
+ COSArray ranges = new COSArray();
+ for( int i=0; i<cs.getNumComponents(); i++ )
+ {
+ ranges.add( new COSFloat( ics.getMinValue( i ) ) );
+ ranges.add( new COSFloat( ics.getMaxValue( i ) ) );
+ }
+ PDStream iccData = pdCS.getPDStream();
+ OutputStream output = null;
+ try
+ {
+ output = iccData.createOutputStream();
+ output.write( ics.getProfile().getData() );
+ }
+ finally
+ {
+ if( output != null )
+ {
+ output.close();
+ }
+ }
+ pdCS.setNumberOfComponents( cs.getNumComponents() );
+ }
+ else
+ {
+ throw new IOException( "Not yet implemented:" + cs );
+ }
+ return retval;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java
new file mode 100644
index 0000000..23693df
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java
@@ -0,0 +1,130 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import java.awt.Color;
+import java.io.IOException;
+
+import org.pdfbox.cos.COSArray;
+
+/**
+ * This class represents a color space and the color value for that colorspace.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.3 $
+ */
+public class PDColorSpaceInstance
+{
+ private PDColorSpace colorSpace = new PDDeviceGray();
+ private COSArray colorSpaceValue = new COSArray();
+
+ /**
+ * Default constructor.
+ *
+ */
+ public PDColorSpaceInstance()
+ {
+ //do nothing
+ }
+
+ /**
+ * Create the current color from the colorspace and values.
+ * @return The current awt color.
+ * @throws IOException If there is an error creating the color.
+ */
+ public Color createColor() throws IOException
+ {
+ float[] components = colorSpaceValue.toFloatArray();
+ Color color = new Color( colorSpace.createColorSpace(), components, 1f );
+ return color;
+ }
+
+ /**
+ * Constructor with an existing color set. Default colorspace is PDDeviceGray.
+ *
+ * @param csValues The color space values.
+ */
+ public PDColorSpaceInstance( COSArray csValues )
+ {
+ colorSpaceValue = csValues;
+ }
+
+
+ /**
+ * This will get the current colorspace.
+ *
+ * @return The current colorspace.
+ */
+ public PDColorSpace getColorSpace()
+ {
+ return colorSpace;
+ }
+
+ /**
+ * This will set the current colorspace.
+ *
+ * @param value The new colorspace.
+ */
+ public void setColorSpace(PDColorSpace value)
+ {
+ colorSpace = value;
+ }
+
+ /**
+ * This will get the color space values. Either 1 for gray or 3 for RGB.
+ *
+ * @return The colorspace values.
+ */
+ public float[] getColorSpaceValue()
+ {
+ return colorSpaceValue.toFloatArray();
+ }
+
+ /**
+ * This will get the color space values. Either 1 for gray or 3 for RGB.
+ *
+ * @return The colorspace values.
+ */
+ public COSArray getCOSColorSpaceValue()
+ {
+ return colorSpaceValue;
+ }
+
+ /**
+ * This will update the colorspace values.
+ *
+ * @param value The new colorspace values.
+ */
+ public void setColorSpaceValue(float[] value)
+ {
+ colorSpaceValue.setFloatArray( value );
+ }
+}
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
new file mode 100644
index 0000000..dfbdfe5
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
@@ -0,0 +1,137 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
+import java.awt.color.ICC_Profile;
+import java.awt.image.ColorModel;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.pdfbox.util.ResourceLoader;
+
+/**
+ * This class represents a CMYK color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.5 $
+ */
+public class PDDeviceCMYK extends PDColorSpace
+{
+ /**
+ * The single instance of this class.
+ */
+ public static final PDDeviceCMYK INSTANCE = new PDDeviceCMYK();
+
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "DeviceCMYK";
+
+ /**
+ * The abbreviated name of this color space.
+ */
+ public static final String ABBREVIATED_NAME = "CMYK";
+
+ private ColorSpace cSpace = null;
+
+ private PDDeviceCMYK()
+ {
+
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return 4;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ if( cSpace == null )
+ {
+ InputStream profile = null;
+ try
+ {
+ profile = ResourceLoader.loadResource( "Resources/colorspace-profiles/CMYK.pf" );
+ ICC_Profile iccProfile = ICC_Profile.getInstance( profile );
+ cSpace = new ICC_ColorSpace( iccProfile );
+ }
+ finally
+ {
+ if( profile != null )
+ {
+ profile.close();
+ }
+ }
+ }
+ return cSpace;
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceGray.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceGray.java
new file mode 100644
index 0000000..a9afddb
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceGray.java
@@ -0,0 +1,112 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import java.awt.color.ColorSpace;
+
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.Transparency;
+
+import java.io.IOException;
+
+/**
+ * This class represents a Gray color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.5 $
+ */
+public class PDDeviceGray extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "DeviceGray";
+
+ /**
+ * The abbreviated name of this color space.
+ */
+ public static final String ABBREVIATED_NAME = "G";
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return 1;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ return ColorSpace.getInstance( ColorSpace.CS_GRAY );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
+ int[] nBits = {bpc};
+ ColorModel colorModel = new ComponentColorModel(cs, nBits, false,false,
+ Transparency.OPAQUE,DataBuffer.TYPE_BYTE);
+ return colorModel;
+
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceN.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceN.java
new file mode 100644
index 0000000..92561e7
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceN.java
@@ -0,0 +1,244 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+
+import java.io.IOException;
+
+import java.util.List;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSName;
+import org.pdfbox.cos.COSNull;
+
+import org.pdfbox.pdmodel.common.COSArrayList;
+
+/**
+ * This class represents a DeviceN color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.2 $
+ */
+public class PDDeviceN extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "DeviceN";
+
+ private COSArray array;
+
+ /**
+ * Constructor.
+ */
+ public PDDeviceN()
+ {
+ array = new COSArray();
+ array.add( COSName.getPDFName( NAME ) );
+ array.add( COSName.getPDFName( "" ) );
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param separation The array containing all separation information.
+ */
+ public PDDeviceN( COSArray separation )
+ {
+ array = separation;
+ }
+
+ /**
+ * This will return the name of the color space. For a PDSeparation object
+ * this will always return "Separation"
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return getColorantNames().size();
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * This will get the colorant names. A list of string objects.
+ *
+ * @return A list of colorants
+ */
+ public List getColorantNames()
+ {
+ COSArray names = (COSArray)array.getObject( 1 );
+ return COSArrayList.convertCOSNameCOSArrayToList( names );
+ }
+
+ /**
+ * This will set the list of colorants.
+ *
+ * @param names The list of colorant names.
+ */
+ public void setColorantNames( List names )
+ {
+ COSArray namesArray = COSArrayList.convertStringListToCOSNameCOSArray( names );
+ array.set( 1, namesArray );
+ }
+
+ /**
+ * This will get the alternate color space for this separation.
+ *
+ * @return The alternate color space.
+ *
+ * @throws IOException If there is an error getting the alternate color space.
+ */
+ public PDColorSpace getAlternateColorSpace() throws IOException
+ {
+ COSBase alternate = array.getObject( 2 );
+ return PDColorSpaceFactory.createColorSpace( alternate );
+ }
+
+ /**
+ * This will set the alternate color space.
+ *
+ * @param cs The alternate color space.
+ */
+ public void setAlternateColorSpace( PDColorSpace cs )
+ {
+ COSBase space = null;
+ if( cs != null )
+ {
+ space = cs.getCOSObject();
+ }
+ array.set( 2, space );
+ }
+
+ /**
+ * This will get the tint transform function. At this time the PDModel
+ * does not support functions so we will just return the COSBase object. This
+ * method will change in the future to be a PDModel object.
+ *
+ * @return The tint transform function.
+ */
+ public COSBase getTintTransform()
+ {
+ return array.get( 3 );
+ }
+
+ /**
+ * This will set the tint transform function. At this time the PDModel
+ * does not support functions so we will just return the COSBase object. This
+ * method will change in the future to be a PDModel object.
+ *
+ * @param tint The tint transform function.
+ */
+ public void setTintTransform( COSBase tint )
+ {
+ array.set( 3, tint );
+ }
+
+ /**
+ * This will get the attributes that are associated with the deviceN
+ * color space.
+ *
+ * @return The DeviceN attributes.
+ */
+ public PDDeviceNAttributes getAttributes()
+ {
+ PDDeviceNAttributes retval = null;
+ if( array.size() <5)
+ {
+ retval = new PDDeviceNAttributes();
+ setAttributes( retval );
+ }
+ return retval;
+ }
+
+ /**
+ * This will set the color space attributes. If null is passed in then
+ * all attribute will be removed.
+ *
+ * @param attributes The color space attributes.
+ */
+ public void setAttributes( PDDeviceNAttributes attributes )
+ {
+ if( attributes == null )
+ {
+ array.remove( 4 );
+ }
+ else
+ {
+ //make sure array is large enough
+ while( array.size() < 5 )
+ {
+ array.add( COSNull.NULL );
+ }
+ array.set( 4, attributes.getCOSDictionary() );
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
new file mode 100644
index 0000000..00366df
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSDictionary;
+import org.pdfbox.cos.COSName;
+
+import org.pdfbox.pdmodel.common.COSDictionaryMap;
+
+import java.io.IOException;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * This class represents attributes for a DeviceN color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.1 $
+ */
+public class PDDeviceNAttributes
+{
+ private COSDictionary dictionary;
+
+ /**
+ * Constructor.
+ */
+ public PDDeviceNAttributes()
+ {
+ dictionary = new COSDictionary();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param attributes A dictionary that has all of the attributes.
+ */
+ public PDDeviceNAttributes( COSDictionary attributes )
+ {
+ dictionary = attributes;
+ }
+
+ /**
+ * This will get the underlying cos dictionary.
+ *
+ * @return The dictionary that this object wraps.
+ */
+ public COSDictionary getCOSDictionary()
+ {
+ return dictionary;
+ }
+
+ /**
+ * This will get a map of colorants. See the PDF Reference for more details about
+ * this attribute. The map will contain a java.lang.String as the key, a colorant name,
+ * and a PDColorSpace as the value.
+ *
+ * @return The colorant map.
+ *
+ * @throws IOException If there is an error getting the colorspaces.
+ */
+ public Map getColorants() throws IOException
+ {
+ Map actuals = new HashMap();
+ COSDictionary colorants = (COSDictionary)dictionary.getDictionaryObject( COSName.getPDFName( "Colorants" ) );
+ if( colorants == null )
+ {
+ colorants = new COSDictionary();
+ dictionary.setItem( COSName.getPDFName( "Colorants" ), colorants );
+ }
+ Iterator iter = colorants.keyList().iterator();
+ while( iter.hasNext() )
+ {
+ COSName name = (COSName)iter.next();
+ COSBase value = colorants.getDictionaryObject( name );
+ actuals.put( name.getName(), PDColorSpaceFactory.createColorSpace( value ) );
+ }
+ return new COSDictionaryMap( actuals, colorants );
+ }
+
+ /**
+ * This will replace the existing colorant attribute. The key should be strings
+ * and the values should be PDColorSpaces.
+ *
+ * @param colorants The map of colorants.
+ */
+ public void setColorants( Map colorants )
+ {
+ COSDictionary colorantDict = null;
+ if( colorants != null )
+ {
+ colorantDict = COSDictionaryMap.convert( colorants );
+ }
+ dictionary.setItem( COSName.getPDFName( "Colorants" ), colorantDict );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
new file mode 100644
index 0000000..14c0dc3
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
@@ -0,0 +1,130 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import java.awt.Transparency;
+
+import java.awt.color.ColorSpace;
+
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+
+import java.io.IOException;
+
+/**
+ * This class represents an RGB color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.7 $
+ */
+public class PDDeviceRGB extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "DeviceRGB";
+
+ /**
+ * The abbreviated name of this color space.
+ */
+ public static final String ABBREVIATED_NAME = "RGB";
+
+ /**
+ * This is the single instance of this class.
+ */
+ public static final PDDeviceRGB INSTANCE = new PDDeviceRGB();
+
+ /**
+ * This class is immutable.
+ */
+ private PDDeviceRGB()
+ {
+ //only here to make immutable.
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return 3;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ return ColorSpace.getInstance( ColorSpace.CS_sRGB );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ int[] nbBits = { bpc, bpc, bpc };
+ ComponentColorModel componentColorModel =
+ new ComponentColorModel( createColorSpace(),
+ nbBits,
+ false,
+ false,
+ Transparency.OPAQUE,
+ DataBuffer.TYPE_BYTE );
+
+ return (ColorModel)componentColorModel;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDGamma.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDGamma.java
new file mode 100644
index 0000000..31fa82e
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDGamma.java
@@ -0,0 +1,151 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSFloat;
+import org.pdfbox.cos.COSNumber;
+
+import org.pdfbox.pdmodel.common.COSObjectable;
+
+/**
+ * A gamma array, or collection of three floating point parameters used for
+ * color operations.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.1 $
+ */
+public class PDGamma implements COSObjectable
+{
+ private COSArray values = null;
+
+ /**
+ * Constructor. Defaults all values to 0, 0, 0.
+ */
+ public PDGamma()
+ {
+ values = new COSArray();
+ values.add( new COSFloat( 0.0f ) );
+ values.add( new COSFloat( 0.0f ) );
+ values.add( new COSFloat( 0.0f ) );
+ }
+
+ /**
+ * Constructor from COS object.
+ *
+ * @param array The array containing the XYZ values.
+ */
+ public PDGamma( COSArray array )
+ {
+ values = array;
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return values;
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSArray getCOSArray()
+ {
+ return values;
+ }
+
+ /**
+ * This will get the r value of the tristimulus.
+ *
+ * @return The R value.
+ */
+ public float getR()
+ {
+ return ((COSNumber)values.get( 0 )).floatValue();
+ }
+
+ /**
+ * This will set the r value of the tristimulus.
+ *
+ * @param r The r value for the tristimulus.
+ */
+ public void setR( float r )
+ {
+ values.set( 0, new COSFloat( r ) );
+ }
+
+ /**
+ * This will get the g value of the tristimulus.
+ *
+ * @return The g value.
+ */
+ public float getG()
+ {
+ return ((COSNumber)values.get( 1 )).floatValue();
+ }
+
+ /**
+ * This will set the g value of the tristimulus.
+ *
+ * @param g The g value for the tristimulus.
+ */
+ public void setG( float g )
+ {
+ values.set( 1, new COSFloat( g ) );
+ }
+
+ /**
+ * This will get the b value of the tristimulus.
+ *
+ * @return The B value.
+ */
+ public float getB()
+ {
+ return ((COSNumber)values.get( 2 )).floatValue();
+ }
+
+ /**
+ * This will set the b value of the tristimulus.
+ *
+ * @param b The b value for the tristimulus.
+ */
+ public void setB( float b )
+ {
+ values.set( 2, new COSFloat( b ) );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDICCBased.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDICCBased.java
new file mode 100644
index 0000000..d8189d0
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDICCBased.java
@@ -0,0 +1,343 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSInteger;
+import org.pdfbox.cos.COSFloat;
+import org.pdfbox.cos.COSName;
+import org.pdfbox.cos.COSNumber;
+import org.pdfbox.cos.COSStream;
+
+import org.pdfbox.pdmodel.PDDocument;
+import org.pdfbox.pdmodel.common.COSArrayList;
+import org.pdfbox.pdmodel.common.PDRange;
+import org.pdfbox.pdmodel.common.PDStream;
+
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
+import java.awt.color.ICC_Profile;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class represents a ICC profile color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.5 $
+ */
+public class PDICCBased extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "ICCBased";
+
+ private COSArray array;
+ private PDStream stream;
+
+ /**
+ * Default constructor, creates empty stream.
+ *
+ * @param doc The document to store the icc data.
+ */
+ public PDICCBased( PDDocument doc )
+ {
+ array = new COSArray();
+ array.add( COSName.getPDFName( NAME ) );
+ array.add( new PDStream( doc ) );
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param iccArray The ICC stream object.
+ */
+ public PDICCBased( COSArray iccArray )
+ {
+ array = iccArray;
+ stream = new PDStream( (COSStream)iccArray.getObject( 1 ) );
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return array;
+ }
+
+ /**
+ * Get the pd stream for this icc color space.
+ *
+ * @return Get the stream for this icc based color space.
+ */
+ public PDStream getPDStream()
+ {
+ return stream;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ InputStream profile = null;
+ ColorSpace cSpace = null;
+ try
+ {
+ profile = stream.createInputStream();
+ ICC_Profile iccProfile = ICC_Profile.getInstance( profile );
+ cSpace = new ICC_ColorSpace( iccProfile );
+ }
+ finally
+ {
+ if( profile != null )
+ {
+ profile.close();
+ }
+ }
+ return cSpace;
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ int[] nbBits = { bpc, bpc, bpc };
+ ComponentColorModel componentColorModel =
+ new ComponentColorModel( createColorSpace(),
+ nbBits,
+ false,
+ false,
+ Transparency.OPAQUE,
+ DataBuffer.TYPE_BYTE );
+
+ return componentColorModel;
+ }
+
+ /**
+ * This will return the number of color components. As of PDF 1.4 this will
+ * be 1,3,4.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ COSNumber n = (COSNumber)stream.getStream().getDictionaryObject( COSName.getPDFName( "N" ) );
+ return n.intValue();
+ }
+
+ /**
+ * This will set the number of color components.
+ *
+ * @param n The number of color components.
+ */
+ public void setNumberOfComponents( int n )
+ {
+ stream.getStream().setItem( COSName.getPDFName( "N" ), new COSInteger( n ) );
+ }
+
+ /**
+ * This will return a list of alternate color spaces(PDColorSpace) if the display application
+ * does not support this icc stream.
+ *
+ * @return A list of alternate color spaces.
+ *
+ * @throws IOException If there is an error getting the alternate color spaces.
+ */
+ public List getAlternateColorSpaces() throws IOException
+ {
+ COSBase alternate = stream.getStream().getDictionaryObject( COSName.getPDFName( "Alternate" ) );
+ COSArray alternateArray = null;
+ if( alternate == null )
+ {
+ alternateArray = new COSArray();
+ int numComponents = getNumberOfComponents();
+ String csName = null;
+ if( numComponents == 1 )
+ {
+ csName = PDDeviceGray.NAME;
+ }
+ else if( numComponents == 3 )
+ {
+ csName = PDDeviceRGB.NAME;
+ }
+ else if( numComponents == 4 )
+ {
+ csName = PDDeviceCMYK.NAME;
+ }
+ else
+ {
+ throw new IOException( "Unknown colorspace number of components:" + numComponents );
+ }
+ alternateArray.add( COSName.getPDFName( csName ) );
+ }
+ else
+ {
+ if( alternate instanceof COSArray )
+ {
+ alternateArray = (COSArray)alternate;
+ }
+ else if( alternate instanceof COSName )
+ {
+ alternateArray = new COSArray();
+ alternateArray.add( alternate );
+ }
+ else
+ {
+ throw new IOException( "Error: expected COSArray or COSName and not " +
+ alternate.getClass().getName() );
+ }
+ }
+ List retval = new ArrayList();
+ for( int i=0; i<alternateArray.size(); i++ )
+ {
+ retval.add( PDColorSpaceFactory.createColorSpace( alternateArray.get( i ) ) );
+ }
+ return new COSArrayList( retval, alternateArray );
+ }
+
+ /**
+ * This will set the list of alternate color spaces. This should be a list
+ * of PDColorSpace objects.
+ *
+ * @param list The list of colorspace objects.
+ */
+ public void setAlternateColorSpaces( List list )
+ {
+ COSArray altArray = null;
+ if( list != null )
+ {
+ altArray = COSArrayList.converterToCOSArray( list );
+ }
+ stream.getStream().setItem( COSName.getPDFName( "Alternate" ), altArray );
+ }
+
+ private COSArray getRangeArray( int n )
+ {
+ COSArray rangeArray = (COSArray)stream.getStream().getDictionaryObject( COSName.getPDFName( "Range" ) );
+ if( rangeArray == null )
+ {
+ rangeArray = new COSArray();
+ stream.getStream().setItem( COSName.getPDFName( "Range" ), rangeArray );
+ while( rangeArray.size() < n*2 )
+ {
+ rangeArray.add( new COSFloat( -100 ) );
+ rangeArray.add( new COSFloat( 100 ) );
+ }
+ }
+ return rangeArray;
+ }
+
+ /**
+ * This will get the range for a certain component number. This is will never
+ * return null. If it is not present then the range -100 to 100 will
+ * be returned.
+ *
+ * @param n The component number to get the range for.
+ *
+ * @return The range for this component.
+ */
+ public PDRange getRangeForComponent( int n )
+ {
+ COSArray rangeArray = getRangeArray( n );
+ return new PDRange( rangeArray, n );
+ }
+
+ /**
+ * This will set the a range for this color space.
+ *
+ * @param range The new range for the a component.
+ * @param n The component to set the range for.
+ */
+ public void setRangeForComponent( PDRange range, int n )
+ {
+ COSArray rangeArray = getRangeArray( n );
+ rangeArray.set( n*2, new COSFloat( range.getMin() ) );
+ rangeArray.set( n*2+1, new COSFloat( range.getMax() ) );
+ }
+
+ /**
+ * This will get the metadata stream for this object. Null if there is no
+ * metadata stream.
+ *
+ * @return The metadata stream, if it exists.
+ */
+ public COSStream getMetadata()
+ {
+ return (COSStream)stream.getStream().getDictionaryObject( COSName.getPDFName( "Metadata" ) );
+ }
+
+ /**
+ * This will set the metadata stream that is associated with this color space.
+ *
+ * @param metadata The new metadata stream.
+ */
+ public void setMetadata( COSStream metadata )
+ {
+ stream.getStream().setItem( COSName.getPDFName( "Metadata" ), metadata );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDIndexed.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDIndexed.java
new file mode 100644
index 0000000..cd1d9e7
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDIndexed.java
@@ -0,0 +1,271 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSInteger;
+import org.pdfbox.cos.COSName;
+import org.pdfbox.cos.COSNumber;
+import org.pdfbox.cos.COSStream;
+import org.pdfbox.cos.COSString;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+import java.awt.image.IndexColorModel;
+
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * This class represents an Indexed color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.3 $
+ */
+public class PDIndexed extends PDColorSpace
+{
+
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "Indexed";
+
+ /**
+ * The abbreviated name of this color space.
+ */
+ public static final String ABBREVIATED_NAME = "I";
+
+ private COSArray array;
+
+ /**
+ * Constructor, default DeviceRGB, hival 255.
+ */
+ public PDIndexed()
+ {
+ array = new COSArray();
+ array.add( COSName.getPDFName( NAME ) );
+ array.add( COSName.getPDFName( PDDeviceRGB.NAME ) );
+ array.add( new COSInteger( 255 ) );
+ array.add( org.pdfbox.cos.COSNull.NULL );
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param indexedArray The array containing the indexed parameters
+ */
+ public PDIndexed( COSArray indexedArray )
+ {
+ array = indexedArray;
+ }
+
+ /**
+ * This will return the number of color components. This will return the
+ * number of color components in the base color.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return getBaseColorSpace().getNumberOfComponents();
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ int size = getHighValue();
+ byte[] index = getLookupData();
+ //for (int i=0;i<index.length;i++) System.out.print(index[i]+" ");
+
+ ColorModel cm = new IndexColorModel(bpc, size+1, index,0,false);
+ return cm;
+ }
+
+ /**
+ * This will get the color space that acts as the index for this color space.
+ *
+ * @return The base color space.
+ *
+ * @throws IOException If there is error creating the base color space.
+ */
+ public PDColorSpace getBaseColorSpace() throws IOException
+ {
+ PDColorSpace retval = null;
+ COSBase base = array.getObject( 1 );
+ if( base instanceof COSName )
+ {
+ retval = PDColorSpaceFactory.createColorSpace( (COSName)base );
+ }
+ else
+ {
+ throw new IOException( "Error:unknown base colorspace" );
+ }
+
+ return retval;
+ }
+
+ /**
+ * This will set the base color space.
+ *
+ * @param base The base color space to use as the index.
+ */
+ public void setBaseColorSpace( PDColorSpace base )
+ {
+ array.set( 1, base.getCOSObject() );
+ }
+
+ /**
+ * Get the highest value for the lookup.
+ *
+ * @return The hival entry.
+ */
+ public int getHighValue()
+ {
+ return ((COSNumber)array.getObject( 2 )).intValue();
+ }
+
+ /**
+ * This will set the highest value that is allowed. This cannot be higher
+ * than 255.
+ *
+ * @param high The highest value for the lookup table.
+ */
+ public void setHighValue( int high )
+ {
+ array.set( 2, new COSInteger( high ) );
+ }
+
+ /**
+ * This will perform a lookup into the color lookup table.
+ *
+ * @param componentNumber The component number, probably 1,2,3,3.
+ * @param lookupIndex The zero-based index into the table, should not exceed the high value.
+ *
+ * @return The value that was from the lookup table.
+ *
+ * @throws IOException If there is an error looking up the color.
+ */
+ public int lookupColor( int componentNumber, int lookupIndex ) throws IOException
+ {
+ COSBase lookupTable = array.getObject( 3 );
+ PDColorSpace baseColor = getBaseColorSpace();
+ byte[] data = getLookupData();
+ int numberOfComponents = baseColor.getNumberOfComponents();
+ return (data[componentNumber*numberOfComponents + lookupIndex]+256)%256;
+ }
+
+ private byte[] getLookupData() throws IOException
+ {
+ COSBase lookupTable = array.getObject( 3 );
+ byte[] data = null;
+ if( lookupTable instanceof COSString )
+ {
+ data = ((COSString)lookupTable).getBytes();
+ }
+ else if( lookupTable instanceof COSStream )
+ {
+ //Data will be small so just load the whole thing into memory for
+ //easier processing
+ COSStream lookupStream = (COSStream)lookupTable;
+ InputStream input = lookupStream.getUnfilteredStream();
+ ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
+ byte[] buffer = new byte[ 1024 ];
+ int amountRead;
+ while( (amountRead = input.read(buffer, 0, buffer.length)) != -1 )
+ {
+ output.write( buffer, 0, amountRead );
+ }
+ data = output.toByteArray();
+ }
+ else if( lookupTable == null )
+ {
+ data = new byte[0];
+ }
+ else
+ {
+ throw new IOException( "Error: Unknown type for lookup table " + lookupTable );
+ }
+ return data;
+ }
+
+ /**
+ * This will set a color in the color lookup table.
+ *
+ * @param componentNumber The component number, probably 1,2,3,3.
+ * @param lookupIndex The zero-based index into the table, should not exceed the high value.
+ * @param color The color that will go into the table.
+ *
+ * @throws IOException If there is an error looking up the color.
+ */
+ public void setLookupColor( int componentNumber, int lookupIndex, int color ) throws IOException
+ {
+ PDColorSpace baseColor = getBaseColorSpace();
+ int numberOfComponents = baseColor.getNumberOfComponents();
+ byte[] data = getLookupData();
+ data[componentNumber*numberOfComponents + lookupIndex] = (byte)color;
+ COSString string = new COSString( data );
+ array.set( 3, string );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDLab.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDLab.java
new file mode 100644
index 0000000..9bd3220
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDLab.java
@@ -0,0 +1,300 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSDictionary;
+import org.pdfbox.cos.COSFloat;
+import org.pdfbox.cos.COSName;
+
+import org.pdfbox.pdmodel.common.PDRange;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+
+import java.io.IOException;
+
+/**
+ * This class represents a Lab color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.2 $
+ */
+public class PDLab extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "Lab";
+
+ private COSArray array;
+ private COSDictionary dictionary;
+
+ /**
+ * Constructor.
+ */
+ public PDLab()
+ {
+ array = new COSArray();
+ dictionary = new COSDictionary();
+ array.add( COSName.getPDFName( NAME ) );
+ array.add( dictionary );
+ }
+
+ /**
+ * Constructor with array.
+ *
+ * @param lab The underlying color space.
+ */
+ public PDLab( COSArray lab )
+ {
+ array = lab;
+ dictionary = (COSDictionary)array.getObject( 1 );
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return array;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ //BJL
+ //hmm is this correct, I am not 100% sure.
+ return 3;
+ }
+
+ /**
+ * This will return the whitepoint tristimulus. As this is a required field
+ * this will never return null. A default of 1,1,1 will be returned if the
+ * pdf does not have any values yet.
+ *
+ * @return The whitepoint tristimulus.
+ */
+ public PDTristimulus getWhitepoint()
+ {
+ PDTristimulus retval = null;
+ COSArray wp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "WhitePoint" ) );
+ if( wp == null )
+ {
+ wp.add( new COSFloat( 1.0f ) );
+ wp.add( new COSFloat( 1.0f ) );
+ wp.add( new COSFloat( 1.0f ) );
+ dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wp );
+ }
+ return new PDTristimulus( wp );
+ }
+
+ /**
+ * This will set the whitepoint tristimulus. As this is a required field
+ * this null should not be passed into this function.
+ *
+ * @param wp The whitepoint tristimulus.
+ */
+ public void setWhitepoint( PDTristimulus wp )
+ {
+ COSBase wpArray = wp.getCOSObject();
+ if( wpArray != null )
+ {
+ dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wpArray );
+ }
+ }
+
+ /**
+ * This will return the BlackPoint tristimulus. This is an optional field but
+ * has defaults so this will never return null.
+ * A default of 0,0,0 will be returned if the pdf does not have any values yet.
+ *
+ * @return The blackpoint tristimulus.
+ */
+ public PDTristimulus getBlackPoint()
+ {
+ PDTristimulus retval = null;
+ COSArray bp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "BlackPoint" ) );
+ if( bp == null )
+ {
+ bp.add( new COSFloat( 0.0f ) );
+ bp.add( new COSFloat( 0.0f ) );
+ bp.add( new COSFloat( 0.0f ) );
+ dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bp );
+ }
+ return new PDTristimulus( bp );
+ }
+
+ /**
+ * This will set the BlackPoint tristimulus. As this is a required field
+ * this null should not be passed into this function.
+ *
+ * @param bp The BlackPoint tristimulus.
+ */
+ public void setBlackPoint( PDTristimulus bp )
+ {
+
+ COSBase bpArray = null;
+ if( bp != null )
+ {
+ bpArray = bp.getCOSObject();
+ }
+ dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bpArray );
+ }
+
+ private COSArray getRangeArray()
+ {
+ COSArray range = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "Range" ) );
+ if( range == null )
+ {
+ range = new COSArray();
+ dictionary.setItem( COSName.getPDFName( "Range" ), array );
+ range.add( new COSFloat( -100 ) );
+ range.add( new COSFloat( 100 ) );
+ range.add( new COSFloat( -100 ) );
+ range.add( new COSFloat( 100 ) );
+ }
+ return range;
+ }
+
+ /**
+ * This will get the valid range for the a component. If none is found
+ * then the default will be returned, which is -100 to 100.
+ *
+ * @return The a range.
+ */
+ public PDRange getARange()
+ {
+ COSArray range = getRangeArray();
+ return new PDRange( range, 0 );
+ }
+
+ /**
+ * This will set the a range for this color space.
+ *
+ * @param range The new range for the a component.
+ */
+ public void setARange( PDRange range )
+ {
+ COSArray rangeArray = null;
+ //if null then reset to defaults
+ if( range == null )
+ {
+ rangeArray = getRangeArray();
+ rangeArray.set( 0, new COSFloat( -100 ) );
+ rangeArray.set( 1, new COSFloat( 100 ) );
+ }
+ else
+ {
+ rangeArray = range.getCOSArray();
+ }
+ dictionary.setItem( COSName.getPDFName( "Range" ), rangeArray );
+ }
+
+ /**
+ * This will get the valid range for the b component. If none is found
+ * then the default will be returned, which is -100 to 100.
+ *
+ * @return The b range.
+ */
+ public PDRange getBRange()
+ {
+ COSArray range = getRangeArray();
+ return new PDRange( range, 2 );
+ }
+
+ /**
+ * This will set the b range for this color space.
+ *
+ * @param range The new range for the b component.
+ */
+ public void setBRange( PDRange range )
+ {
+ COSArray rangeArray = null;
+ //if null then reset to defaults
+ if( range == null )
+ {
+ rangeArray = getRangeArray();
+ rangeArray.set( 2, new COSFloat( -100 ) );
+ rangeArray.set( 3, new COSFloat( 100 ) );
+ }
+ else
+ {
+ rangeArray = range.getCOSArray();
+ }
+ dictionary.setItem( COSName.getPDFName( "Range" ), rangeArray );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDPattern.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDPattern.java
new file mode 100644
index 0000000..4c43914
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDPattern.java
@@ -0,0 +1,122 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSName;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+
+import java.io.IOException;
+
+/**
+ * This class represents a Pattern color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.3 $
+ */
+public class PDPattern extends PDColorSpace
+{
+ private COSArray array;
+
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "Pattern";
+
+ /**
+ * Default constructor.
+ */
+ public PDPattern()
+ {
+ array = new COSArray();
+ array.add( COSName.getPDFName( NAME ) );
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param pattern The pattern array.
+ */
+ public PDPattern( COSArray pattern)
+ {
+ array = pattern;
+ }
+
+ /**
+ * This will return the name of the color space.
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return -1;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDSeparation.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDSeparation.java
new file mode 100644
index 0000000..cc92f6f
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDSeparation.java
@@ -0,0 +1,198 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+
+import java.io.IOException;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSName;
+
+/**
+ * This class represents a Separation color space.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.2 $
+ */
+public class PDSeparation extends PDColorSpace
+{
+ /**
+ * The name of this color space.
+ */
+ public static final String NAME = "Separation";
+
+ private COSArray array;
+
+ /**
+ * Constructor.
+ */
+ public PDSeparation()
+ {
+ array = new COSArray();
+ array.add( COSName.getPDFName( NAME ) );
+ array.add( COSName.getPDFName( "" ) );
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param separation The array containing all separation information.
+ */
+ public PDSeparation( COSArray separation )
+ {
+ array = separation;
+ }
+
+ /**
+ * This will return the name of the color space. For a PDSeparation object
+ * this will always return "Separation"
+ *
+ * @return The name of the color space.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * This will get the number of components that this color space is made up of.
+ *
+ * @return The number of components in this color space.
+ *
+ * @throws IOException If there is an error getting the number of color components.
+ */
+ public int getNumberOfComponents() throws IOException
+ {
+ return 1;
+ }
+
+ /**
+ * Create a Java colorspace for this colorspace.
+ *
+ * @return A color space that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color space.
+ */
+ public ColorSpace createColorSpace() throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * Create a Java color model for this colorspace.
+ *
+ * @param bpc The number of bits per component.
+ *
+ * @return A color model that can be used for Java AWT operations.
+ *
+ * @throws IOException If there is an error creating the color model.
+ */
+ public ColorModel createColorModel( int bpc ) throws IOException
+ {
+ throw new IOException( "Not implemented" );
+ }
+
+ /**
+ * This will get the separation name.
+ *
+ * @return The name in the separation.
+ */
+ public String getColorantName()
+ {
+ COSName name = (COSName)array.getObject( 1 );
+ return name.getName();
+ }
+
+ /**
+ * This will set the separation name.
+ *
+ * @param name The separation name.
+ */
+ public void setColorantName( String name )
+ {
+ array.set( 1, COSName.getPDFName( name ) );
+ }
+
+ /**
+ * This will get the alternate color space for this separation.
+ *
+ * @return The alternate color space.
+ *
+ * @throws IOException If there is an error getting the alternate color space.
+ */
+ public PDColorSpace getAlternateColorSpace() throws IOException
+ {
+ COSBase alternate = array.getObject( 2 );
+ return PDColorSpaceFactory.createColorSpace( alternate );
+ }
+
+ /**
+ * This will set the alternate color space.
+ *
+ * @param cs The alternate color space.
+ */
+ public void setAlternateColorSpace( PDColorSpace cs )
+ {
+ COSBase space = null;
+ if( cs != null )
+ {
+ space = cs.getCOSObject();
+ }
+ array.set( 2, space );
+ }
+
+ /**
+ * This will get the tint transform function. At this time the PDModel
+ * does not support functions so we will just return the COSBase object. This
+ * method will change in the future to be a PDModel object.
+ *
+ * @return The tint transform function.
+ */
+ public COSBase getTintTransform()
+ {
+ return array.get( 3 );
+ }
+
+ /**
+ * This will set the tint transform function. At this time the PDModel
+ * does not support functions so we will just return the COSBase object. This
+ * method will change in the future to be a PDModel object.
+ *
+ * @param tint The tint transform function.
+ */
+ public void setTintTransform( COSBase tint )
+ {
+ array.set( 3, tint );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/PDTristimulus.java b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDTristimulus.java
new file mode 100644
index 0000000..296b147
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/PDTristimulus.java
@@ -0,0 +1,155 @@
+/**
+ * Copyright (c) 2004, www.pdfbox.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of pdfbox; nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://www.pdfbox.org
+ *
+ */
+package org.pdfbox.pdmodel.graphics.color;
+
+import org.pdfbox.cos.COSArray;
+import org.pdfbox.cos.COSBase;
+import org.pdfbox.cos.COSFloat;
+import org.pdfbox.cos.COSNumber;
+
+import org.pdfbox.pdmodel.common.COSObjectable;
+
+/**
+ * A tristimulus, or collection of three floating point parameters used for
+ * color operations.
+ *
+ * @author Ben Litchfield (ben@csh.rit.edu)
+ * @version $Revision: 1.1 $
+ */
+public class PDTristimulus implements COSObjectable
+{
+ private COSArray values = null;
+
+ /**
+ * Constructor. Defaults all values to 0, 0, 0.
+ */
+ public PDTristimulus()
+ {
+ values = new COSArray();
+ values.add( new COSFloat( 0.0f ) );
+ values.add( new COSFloat( 0.0f ) );
+ values.add( new COSFloat( 0.0f ) );
+ }
+
+ /**
+ * Constructor from COS object.
+ *
+ * @param array The array containing the XYZ values.
+ */
+ public PDTristimulus( COSArray array )
+ {
+ values = array;
+ }
+
+ /**
+ * Constructor from COS object.
+ *
+ * @param array The array containing the XYZ values.
+ */
+ public PDTristimulus( float[] array )
+ {
+ values = new COSArray();
+ for( int i=0; i<array.length && i<3; i++ )
+ {
+ values.add( new COSFloat( array[i] ) );
+ }
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return values;
+ }
+
+ /**
+ * This will get the x value of the tristimulus.
+ *
+ * @return The X value.
+ */
+ public float getX()
+ {
+ return ((COSNumber)values.get( 0 )).floatValue();
+ }
+
+ /**
+ * This will set the x value of the tristimulus.
+ *
+ * @param x The x value for the tristimulus.
+ */
+ public void setX( float x )
+ {
+ values.set( 0, new COSFloat( x ) );
+ }
+
+ /**
+ * This will get the y value of the tristimulus.
+ *
+ * @return The Y value.
+ */
+ public float getY()
+ {
+ return ((COSNumber)values.get( 1 )).floatValue();
+ }
+
+ /**
+ * This will set the y value of the tristimulus.
+ *
+ * @param y The y value for the tristimulus.
+ */
+ public void setY( float y )
+ {
+ values.set( 1, new COSFloat( y ) );
+ }
+
+ /**
+ * This will get the z value of the tristimulus.
+ *
+ * @return The Z value.
+ */
+ public float getZ()
+ {
+ return ((COSNumber)values.get( 2 )).floatValue();
+ }
+
+ /**
+ * This will set the z value of the tristimulus.
+ *
+ * @param z The z value for the tristimulus.
+ */
+ public void setZ( float z )
+ {
+ values.set( 2, new COSFloat( z ) );
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/pdfbox/pdmodel/graphics/color/package.html b/src/main/java/org/pdfbox/pdmodel/graphics/color/package.html
new file mode 100644
index 0000000..733efff
--- /dev/null
+++ b/src/main/java/org/pdfbox/pdmodel/graphics/color/package.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+
+</head>
+<body>
+This package deals with colors that are stored in a PDF document.
+</body>
+</html> \ No newline at end of file