You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/02/20 07:31:05 UTC

svn commit: r1570086 [7/7] - in /pdfbox/trunk: examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ examples/src/main/java/org/apache/pdfbox/examples/util/ pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdfbox/filter/...

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/BeginInlineImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/BeginInlineImage.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/BeginInlineImage.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/BeginInlineImage.java Thu Feb 20 06:31:01 2014
@@ -24,27 +24,20 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.pdfviewer.PageDrawer;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDInlinedImage;
-import org.apache.pdfbox.util.ImageParameters;
+import org.apache.pdfbox.pdmodel.graphics.image.PDInlineImage;
 import org.apache.pdfbox.util.Matrix;
 import org.apache.pdfbox.util.PDFOperator;
 import org.apache.pdfbox.util.operator.OperatorProcessor;
 
 /**
- * Implementation of content stream operator for page drawer.
+ * Begins an inline image.
  *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * @author Ben Litchfield
  */
 public class BeginInlineImage extends OperatorProcessor
 {
-
     /**
-     * Log instance.
-     */
-    private static final Log log = LogFactory.getLog(BeginInlineImage.class);
-
-    /**
-     * process : BI : begin inline image.
+     * BI begin inline image.
      * @param operator The operator that is being executed.
      * @param arguments List
      * @throws IOException If there is an error displaying the inline image.
@@ -52,18 +45,12 @@ public class BeginInlineImage extends Op
     public void process(PDFOperator operator, List<COSBase> arguments)  throws IOException
     {
         PageDrawer drawer = (PageDrawer)context;
-        //begin inline image object
-        ImageParameters params = operator.getImageParameters();
-        PDInlinedImage image = new PDInlinedImage();
-        image.setImageParameters( params );
-        image.setImageData( operator.getImageData() );
-        BufferedImage awtImage = image.createImage( context.getColorSpaces() );
 
-        if (awtImage == null) 
-        {
-            log.warn("BeginInlineImage.process(): createImage returned NULL");
-            return;
-        }
+        PDInlineImage image = new PDInlineImage(operator.getImageParameters(),
+                                                operator.getImageData(),
+                                                context.getResources().getColorSpaces());
+
+        BufferedImage awtImage = image.getImage();
         Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
         drawer.drawImage(awtImage, ctm.createAffineTransform());
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java Thu Feb 20 06:31:01 2014
@@ -27,12 +27,15 @@ import org.apache.commons.logging.LogFac
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.filter.MissingImageReaderException;
 import org.apache.pdfbox.pdfviewer.PageDrawer;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
 import org.apache.pdfbox.util.Matrix;
 import org.apache.pdfbox.util.PDFOperator;
 import org.apache.pdfbox.util.operator.OperatorProcessor;
@@ -40,86 +43,85 @@ import org.apache.pdfbox.util.operator.O
 /**
  * Implementation of content stream operator for page drawer.
  * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * 
+ * @author Ben Litchfield
+ * @author John Hewson
  */
 public class Invoke extends OperatorProcessor
 {
-
-    /**
-     * Log instance.
-     */
     private static final Log LOG = LogFactory.getLog(Invoke.class);
 
     /**
-     * process : Do : Paint the specified XObject (section 4.7).
-     * 
-     * @param operator The operator that is being executed.
-     * @param arguments List
-     * @throws IOException If there is an error invoking the sub object.
+     * Do: Paint the specified XObject.
+     * @param operator the operator that is being executed.
+     * @param arguments list
+     * @throws IOException if there is an error invoking the sub object.
      */
     public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
     {
-        PageDrawer drawer = (PageDrawer) context;
-        COSName objectName = (COSName) arguments.get(0);
+        PageDrawer drawer = (PageDrawer)context;
+        COSName objectName = (COSName)arguments.get(0);
         Map<String, PDXObject> xobjects = drawer.getResources().getXObjects();
-        PDXObject xobject = (PDXObject) xobjects.get(objectName.getName());
+        PDXObject xobject = xobjects.get(objectName.getName());
+
         if (xobject == null)
         {
-            LOG.warn("Can't find the XObject for '" + objectName.getName() + "'");
+            LOG.warn("Can't find the XObject named '" + objectName.getName() + "'");
         }
-        else if (xobject instanceof PDXObjectImage)
+        else if (xobject instanceof PDImageXObject)
         {
-            PDXObjectImage image = (PDXObjectImage) xobject;
+            PDImageXObject image = (PDImageXObject)xobject;
             try
             {
-                if (image.getImageMask())
+                BufferedImage awtImage;
+                if (image.isStencil())
                 {
-                    // set the current non stroking colorstate, so that it can
-                    // be used to create a stencil masked image
-                    image.setStencilColor(drawer.getGraphicsState().getNonStrokingColor());
+                    PDColorSpace colorSpace = drawer.getGraphicsState().getNonStrokingColorSpace();
+                    PDColor color = drawer.getGraphicsState().getNonStrokingColor();
+                    awtImage = image.getStencilImage(colorSpace.toPaint(color));
                 }
-                BufferedImage awtImage = image.getRGBImage();
-                if (awtImage == null)
+                else
                 {
-                    LOG.warn("getRGBImage returned NULL");
-                    return;// TODO PKOCH
+                    awtImage = image.getImage();
                 }
-                int imageWidth = awtImage.getWidth();
-                int imageHeight = awtImage.getHeight();
-
-                LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
-
                 Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
                 AffineTransform imageTransform = ctm.createAffineTransform();
                 drawer.drawImage(awtImage, imageTransform);
             }
+            catch (MissingImageReaderException e)
+            {
+                // missing ImageIO plug-in  TODO how far should we escalate this? (after all the user can fix the problem)
+                LOG.error(e.getMessage());
+            }
             catch (Exception e)
             {
+                // TODO we probably shouldn't catch Exception, what errors are expected here?
                 e.printStackTrace();
                 LOG.error(e, e);
             }
         }
-        else if (xobject instanceof PDXObjectForm)
+        else if (xobject instanceof PDFormXObject)
         {
             // save the graphics state
-        	drawer.getGraphicsStack().push((PDGraphicsState) drawer.getGraphicsState().clone());
+            context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone());
+
+            PDFormXObject form = (PDFormXObject) xobject;
+            COSStream formContentStream = form.getCOSStream();
 
-            PDXObjectForm form = (PDXObjectForm) xobject;
-            COSStream formContentstream = form.getCOSStream();
             // find some optional resources, instead of using the current resources
             PDResources pdResources = form.getResources();
+
             // if there is an optional form matrix, we have to map the form space to the user space
             Matrix matrix = form.getMatrix();
             if (matrix != null)
             {
-                Matrix xobjectCTM = matrix.multiply(drawer.getGraphicsState().getCurrentTransformationMatrix());
-                drawer.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
+                Matrix xobjectCTM = matrix.multiply(
+                    context.getGraphicsState().getCurrentTransformationMatrix());
+                    context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
             }
-            drawer.processSubStream(pdResources, formContentstream);
+            getContext().processSubStream(pdResources, formContentStream);
 
             // restore the graphics state
-            drawer.setGraphicsState((PDGraphicsState) drawer.getGraphicsStack().pop());
+            context.setGraphicsState(context.getGraphicsStack().pop());
         }
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineDashPattern.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineDashPattern.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineDashPattern.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineDashPattern.java Thu Feb 20 06:31:01 2014
@@ -48,32 +48,35 @@ public class SetLineDashPattern extends 
         super.process( operator, arguments );
         PDLineDashPattern lineDashPattern = context.getGraphicsState().getLineDashPattern();
         PageDrawer drawer = (PageDrawer)context;
-        BasicStroke stroke = (BasicStroke)drawer.getStroke();
-        if (stroke == null) 
+        BasicStroke stroke = drawer.getStroke();
+
+        final int endCap, lineJoin;
+        final float lineWidth, miterLimit;
+
+        if (stroke != null)
         {
-            if (lineDashPattern.isDashPatternEmpty()) 
-            {
-                drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f) );
-            }
-            else
-            {
-                drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, 
-                        lineDashPattern.getCOSDashPattern().toFloatArray(), lineDashPattern.getPhaseStart()) );
-            }
+            endCap = stroke.getEndCap();
+            lineJoin = stroke.getLineJoin();
+            miterLimit = stroke.getMiterLimit();
+            lineWidth = stroke.getLineWidth();
         }
-        else 
+        else
         {
-            if (lineDashPattern.isDashPatternEmpty()) 
-            {
-                drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), 
-                        stroke.getLineJoin(), stroke.getMiterLimit()) );
-            }
-            else
-            {
-                drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(), 
-                        stroke.getMiterLimit(), lineDashPattern.getCOSDashPattern().toFloatArray(), 
-                        lineDashPattern.getPhaseStart()) );
-            }
+            endCap = BasicStroke.CAP_SQUARE;
+            lineJoin = BasicStroke.JOIN_MITER;
+            miterLimit = 10.0f;
+            lineWidth = 1.0f;
+        }
+
+        if (lineDashPattern.isDashPatternEmpty())
+        {
+            drawer.setStroke(new BasicStroke(lineWidth, endCap, lineJoin, miterLimit));
+        }
+        else
+        {
+            float[] dash = lineDashPattern.getCOSDashPattern().toFloatArray(); // TODO !!!!
+            float phase = lineDashPattern.getPhaseStart(); // TODO !!!
+            drawer.setStroke(new BasicStroke(lineWidth, endCap, lineJoin, miterLimit, dash, phase));
         }
     }
     

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java Thu Feb 20 06:31:01 2014
@@ -70,7 +70,7 @@ public class StrokePath extends Operator
                 lineWidth = 0.25f;
             }
 
-            BasicStroke stroke = (BasicStroke) drawer.getStroke();
+            BasicStroke stroke = drawer.getStroke();
             if (stroke == null)
             {
                 drawer.setStroke(new BasicStroke(lineWidth));

Modified: pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/PageDrawer.properties
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/PageDrawer.properties?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/PageDrawer.properties (original)
+++ pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/PageDrawer.properties Thu Feb 20 06:31:01 2014
@@ -42,16 +42,16 @@ ET=org.apache.pdfbox.util.operator.EndTe
 f=org.apache.pdfbox.util.operator.pagedrawer.FillNonZeroRule
 F=org.apache.pdfbox.util.operator.pagedrawer.FillNonZeroRule
 f*=org.apache.pdfbox.util.operator.pagedrawer.FillEvenOddRule
-G=org.apache.pdfbox.util.operator.SetStrokingGrayColor
-g=org.apache.pdfbox.util.operator.SetNonStrokingGrayColor
+G=org.apache.pdfbox.util.operator.SetStrokingDeviceGrayColor
+g=org.apache.pdfbox.util.operator.SetNonStrokingDeviceGrayColor
 gs=org.apache.pdfbox.util.operator.SetGraphicsStateParameters
 h=org.apache.pdfbox.util.operator.pagedrawer.ClosePath
 #i org.apache.pdfbox.util.operator.NotImplemented
 #ID org.apache.pdfbox.util.operator.NotImplemented
 j=org.apache.pdfbox.util.operator.pagedrawer.SetLineJoinStyle
 J=org.apache.pdfbox.util.operator.pagedrawer.SetLineCapStyle
-K=org.apache.pdfbox.util.operator.SetStrokingCMYKColor
-k=org.apache.pdfbox.util.operator.SetNonStrokingCMYKColor
+K=org.apache.pdfbox.util.operator.SetStrokingDeviceCMYKColor
+k=org.apache.pdfbox.util.operator.SetNonStrokingDeviceCMYKColor
 l=org.apache.pdfbox.util.operator.pagedrawer.LineTo
 m=org.apache.pdfbox.util.operator.pagedrawer.MoveTo
 M=org.apache.pdfbox.util.operator.pagedrawer.SetLineMiterLimit
@@ -60,8 +60,8 @@ n=org.apache.pdfbox.util.operator.pagedr
 q=org.apache.pdfbox.util.operator.GSave
 Q=org.apache.pdfbox.util.operator.GRestore
 re=org.apache.pdfbox.util.operator.pagedrawer.AppendRectangleToPath
-RG=org.apache.pdfbox.util.operator.SetStrokingRGBColor
-rg=org.apache.pdfbox.util.operator.SetNonStrokingRGBColor
+RG=org.apache.pdfbox.util.operator.SetStrokingDeviceRGBColor
+rg=org.apache.pdfbox.util.operator.SetNonStrokingDeviceRGBColor
 #ri org.apache.pdfbox.util.operator.NotImplemented
 s=org.apache.pdfbox.util.operator.CloseAndStrokePath
 S=org.apache.pdfbox.util.operator.pagedrawer.StrokePath

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java Thu Feb 20 06:31:01 2014
@@ -80,7 +80,7 @@ public class TestFilters extends TestCas
                 {
                     // Skip filters that don't currently support roundtripping
                     if( filter instanceof DCTFilter ||
-                        filter instanceof CCITTFaxDecodeFilter ||
+                        filter instanceof CCITTFaxFilter ||
                         filter instanceof JPXFilter ||
                         filter instanceof JBIG2Filter ||
                         filter instanceof RunLengthDecodeFilter )
@@ -96,7 +96,7 @@ public class TestFilters extends TestCas
                     ByteArrayOutputStream decoded = new ByteArrayOutputStream();
                     filter.decode(
                                   new ByteArrayInputStream( encoded.toByteArray() ),
-                                  decoded, new COSDictionary(), 0 );
+                                  decoded, new COSDictionary().asUnmodifiableDictionary(), 0 );
 
                     assertTrue(
                                "Data that is encoded and then decoded through "

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/function/TestPDFunctionType4.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/function/TestPDFunctionType4.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/function/TestPDFunctionType4.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/function/TestPDFunctionType4.java Thu Feb 20 06:31:01 2014
@@ -69,26 +69,22 @@ public class TestPDFunctionType4 extends
                 new float[] {-1.0f, 1.0f, -1.0f, 1.0f},
                 new float[] {-1.0f, 1.0f});
 
-        COSArray input = new COSArray();
-        input.setFloatArray(new float[] {0.8f, 0.1f});
-        COSArray output = function.eval(input);
+        float[] input = new float[] {0.8f, 0.1f};
+        float[] output = function.eval(input);
 
-        assertEquals(1, output.size());
-        assertEquals(0.9f, ((COSFloat)output.get(0)).floatValue(), 0.0001f);
+        assertEquals(1, output.length);
+        assertEquals(0.9f, output[0], 0.0001f);
 
-        input = new COSArray();
-        input.setFloatArray(new float[] {0.8f, 0.3f}); //results in 1.1f being outside Range
+        input = new float[] {0.8f, 0.3f}; //results in 1.1f being outside Range
         output = function.eval(input);
 
-        assertEquals(1, output.size());
-        assertEquals(new COSFloat(1.0f), output.get(0));
+        assertEquals(1, output.length);
+        assertEquals(1f, output[0]);
 
-        input = new COSArray();
-        input.setFloatArray(new float[] {0.8f, 1.2f}); //input argument outside Dimension
-        output = function.eval(input);
+        input = new float[] {0.8f, 1.2f}; //input argument outside Dimension
 
-        assertEquals(1, output.size());
-        assertEquals(new COSFloat(1.0f), output.get(0));
+        assertEquals(1, output.length);
+        assertEquals(1f, output[0]);
     }
 
     /**
@@ -104,12 +100,11 @@ public class TestPDFunctionType4 extends
                 new float[] {-1.0f, 1.0f, -1.0f, 1.0f},
                 new float[] {-1.0f, 1.0f});
 
-        COSArray input = new COSArray();
-        input.setFloatArray(new float[] {-0.7f, 0.0f});
-        COSArray output = function.eval(input);
+        float[] input = new float[] {-0.7f, 0.0f };
+        float[] output = function.eval(input);
 
-        assertEquals(1, output.size());
-        assertEquals(0.0f, ((COSFloat)output.get(0)).floatValue(), 0.0001f);
+        assertEquals(1, output.length);
+        assertEquals(0.0f, output[0], 0.0001f);
         //TODO not sure if this is really correct
     }
 

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/edit/TestPDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/edit/TestPDPageContentStream.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/edit/TestPDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/edit/TestPDPageContentStream.java Thu Feb 20 06:31:01 2014
@@ -38,15 +38,12 @@ public class TestPDPageContentStream ext
     public void testSetCmykColors() throws IOException, COSVisitorException {
         PDDocument doc = new PDDocument();
 
-        ColorSpace colorSpace = PDDeviceCMYK.INSTANCE.getJavaColorSpace();
-
         PDPage page = new PDPage();
         doc.addPage(page);
 
         PDPageContentStream contentStream = new PDPageContentStream(doc, page, false, true);
         // pass a non-stroking color in CMYK color space
-        contentStream.setNonStrokingColor(
-                new Color(colorSpace, new float[]{0.1f, 0.2f, 0.3f, 0.4f}, 1.0f));
+        contentStream.setNonStrokingColor(0.1f, 0.2f, 0.3f, 0.4f);
         contentStream.close();
 
         // now read the PDF stream and verify that the CMYK values are correct
@@ -72,8 +69,7 @@ public class TestPDPageContentStream ext
 
         contentStream = new PDPageContentStream(doc, page, false, false);
         // pass a non-stroking color in CMYK color space
-        contentStream.setStrokingColor(new Color(colorSpace,
-                new float[]{0.5f, 0.6f, 0.7f, 0.8f}, 1.0f));
+        contentStream.setStrokingColor(0.5f, 0.6f, 0.7f, 0.8f);
         contentStream.close();
 
         // now read the PDF stream and verify that the CMYK values are correct

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestImageIOUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestImageIOUtils.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestImageIOUtils.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestImageIOUtils.java Thu Feb 20 06:31:01 2014
@@ -99,11 +99,13 @@ public class TestImageIOUtils extends Te
      * 
      * @throws Exception when there is an exception
      */
+     
     public void testRenderImage() throws Exception
     {
-    	String inDir = "src/test/resources/input/ImageIOUtil";
-    	String outDir = "target/test-output/ImageIOUtil/";
+        String inDir = "src/test/resources/input/ImageIOUtil";
+        String outDir = "target/test-output/ImageIOUtil/";
         new File(outDir).mkdir();
+
         File[] testFiles = new File(inDir).listFiles(new FilenameFilter()
         {
             public boolean accept(File dir, String name)

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java Thu Feb 20 06:31:01 2014
@@ -33,9 +33,9 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup;
 import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentProperties;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
 import org.apache.pdfbox.pdmodel.markedcontent.PDPropertyList;
 
 /**
@@ -71,7 +71,7 @@ public class TestLayerUtility extends Te
         try
         {
             LayerUtility layerUtil = new LayerUtility(targetDoc);
-            PDXObjectForm form = layerUtil.importPageAsForm(overlay1Doc, 0);
+            PDFormXObject form = layerUtil.importPageAsForm(overlay1Doc, 0);
             PDDocumentCatalog catalog = targetDoc.getDocumentCatalog();
             PDPage targetPage = (PDPage)catalog.getAllPages().get(0);
             layerUtil.wrapInSaveRestore(targetPage);

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java Thu Feb 20 06:31:01 2014
@@ -36,7 +36,8 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.common.PDStream;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
 import org.apache.pdfbox.preflight.PreflightContext;
@@ -197,7 +198,8 @@ public abstract class AnnotationValidato
                 }
 
                 // Appearance stream is a XObjectForm, check it.
-                ContextHelper.validateElement(ctx, new PDXObjectForm(COSUtils.getAsStream(apn, cosDocument)),
+                ContextHelper.validateElement(ctx, new PDFormXObject(
+                        new PDStream(COSUtils.getAsStream(apn, cosDocument)), "N"),
                         GRAPHIC_PROCESS);
             }
         } // else ok, nothing to check,this field is optional
@@ -221,9 +223,7 @@ public abstract class AnnotationValidato
     /**
      * This method validates the Popup entry. This entry shall contain an other Annotation. This annotation is validated
      * with the right AnnotationValidator.
-     * 
-     * @param errors
-     * @return
+     *
      * @throws ValidationException
      */
     protected boolean checkPopup() throws ValidationException
@@ -265,9 +265,7 @@ public abstract class AnnotationValidato
     /**
      * Checks if all mandatory fields of an annotation are present. If some fields are missing, the method returns false
      * and the errors list is updated.
-     * 
-     * @param errors
-     *            list of errors which is updated if validation fails
+     *
      * @return true if validation succeed, false otherwise.
      */
     protected boolean checkMandatoryFields()

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamEngine.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamEngine.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamEngine.java Thu Feb 20 06:31:01 2014
@@ -28,7 +28,6 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY;
 import static org.apache.pdfbox.preflight.PreflightConstants.MAX_GRAPHIC_STATES;
 
-import java.awt.color.ColorSpace;
 import java.awt.color.ICC_ColorSpace;
 import java.io.IOException;
 import java.util.HashMap;
@@ -41,13 +40,9 @@ import org.apache.pdfbox.cos.COSDocument
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.graphics.color.PDCalGray;
-import org.apache.pdfbox.pdmodel.graphics.color.PDCalRGB;
+import org.apache.pdfbox.pdmodel.graphics.color.PDCIEBasedColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorState;
 import org.apache.pdfbox.pdmodel.graphics.color.PDICCBased;
-import org.apache.pdfbox.pdmodel.graphics.color.PDLab;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -79,14 +74,14 @@ import org.apache.pdfbox.util.operator.S
 import org.apache.pdfbox.util.operator.SetLineJoinStyle;
 import org.apache.pdfbox.util.operator.SetLineWidth;
 import org.apache.pdfbox.util.operator.SetMatrix;
-import org.apache.pdfbox.util.operator.SetNonStrokingCMYKColor;
+import org.apache.pdfbox.util.operator.SetNonStrokingDeviceCMYKColor;
 import org.apache.pdfbox.util.operator.SetNonStrokingColor;
 import org.apache.pdfbox.util.operator.SetNonStrokingColorSpace;
-import org.apache.pdfbox.util.operator.SetNonStrokingRGBColor;
-import org.apache.pdfbox.util.operator.SetStrokingCMYKColor;
+import org.apache.pdfbox.util.operator.SetNonStrokingDeviceRGBColor;
+import org.apache.pdfbox.util.operator.SetStrokingDeviceCMYKColor;
 import org.apache.pdfbox.util.operator.SetStrokingColor;
 import org.apache.pdfbox.util.operator.SetStrokingColorSpace;
-import org.apache.pdfbox.util.operator.SetStrokingRGBColor;
+import org.apache.pdfbox.util.operator.SetStrokingDeviceRGBColor;
 import org.apache.pdfbox.util.operator.SetTextFont;
 import org.apache.pdfbox.util.operator.SetTextLeading;
 import org.apache.pdfbox.util.operator.SetTextRenderingMode;
@@ -102,7 +97,7 @@ public abstract class ContentStreamEngin
 
     private enum ColorSpaceType
     {
-        RGB, CMYK, ALL;
+        RGB, CMYK, ALL
     }
 
     protected PreflightContext context = null;
@@ -131,11 +126,11 @@ public abstract class ContentStreamEngin
 
         registerOperatorProcessor("j", new SetLineJoinStyle());
         registerOperatorProcessor("J", new SetLineCapStyle());
-        registerOperatorProcessor("K", new SetStrokingCMYKColor());
-        registerOperatorProcessor("k", new SetNonStrokingCMYKColor());
+        registerOperatorProcessor("K", new SetStrokingDeviceCMYKColor());
+        registerOperatorProcessor("k", new SetNonStrokingDeviceCMYKColor());
 
-        registerOperatorProcessor("rg", new SetNonStrokingRGBColor());
-        registerOperatorProcessor("RG", new SetStrokingRGBColor());
+        registerOperatorProcessor("rg", new SetNonStrokingDeviceRGBColor());
+        registerOperatorProcessor("RG", new SetStrokingDeviceRGBColor());
 
         registerOperatorProcessor("SC", new SetStrokingColor());
         registerOperatorProcessor("SCN", new SetStrokingColor());
@@ -281,13 +276,12 @@ public abstract class ContentStreamEngin
     /**
      * Throw a ContentStreamException if the LZW filter is used in a InlinedImage.
      * 
-     * @param operator
-     *            the InlinedImage object (BI to EI)
+     * @param operator the InlinedImage object (BI to EI)
      * @throws ContentStreamException
      */
     protected void validImageFilter(PDFOperator operator) throws ContentStreamException
     {
-        COSDictionary dict = operator.getImageParameters().getDictionary();
+        COSDictionary dict = operator.getImageParameters();
         /*
          * Search a Filter declaration in the InlinedImage dictionary. The LZWDecode Filter is forbidden.
          */
@@ -297,16 +291,15 @@ public abstract class ContentStreamEngin
     }
 
     /**
-     * This method validates if the ColorSpace used by the InlinedImage is consistent with the color space defined in
-     * OutputIntent dictionaries.
+     * This method validates if the ColorSpace used by the InlinedImage is consistent with
+     * the color space defined in OutputIntent dictionaries.
      * 
-     * @param operator
-     *            the InlinedImage object (BI to EI)
+     * @param operator the InlinedImage object (BI to EI)
      * @throws ContentStreamException
      */
-    protected void validImageColorSpace(PDFOperator operator) throws ContentStreamException, IOException
+    protected void validImageColorSpace(PDFOperator operator) throws IOException
     {
-        COSDictionary dict = operator.getImageParameters().getDictionary();
+        COSDictionary dict = operator.getImageParameters();
 
         COSBase csInlinedBase = dict.getItem(COSName.CS);
         ColorSpaceHelper csHelper = null;
@@ -314,9 +307,8 @@ public abstract class ContentStreamEngin
         {
             if (COSUtils.isString(csInlinedBase, cosDocument))
             {
-                /*
-                 * In InlinedImage only DeviceGray/RGB/CMYK and restricted Indexed color spaces are allowed.
-                 */
+                // In InlinedImage only DeviceGray/RGB/CMYK and restricted Indexed
+                // color spaces are allowed.
                 String colorSpace = COSUtils.getAsString(csInlinedBase, cosDocument);
                 ColorSpaces cs = null;
 
@@ -326,11 +318,9 @@ public abstract class ContentStreamEngin
                 }
                 catch (IllegalArgumentException e)
                 {
-                    /*
-                     * The color space is unknown. Try to access the resources dictionary, the color space can be a
-                     * reference.
-                     */
-                    PDColorSpace pdCS = (PDColorSpace) this.getColorSpaces().get(colorSpace);
+                    // The color space is unknown. Try to access the resources dictionary,
+                    // the color space can be a reference.
+                    PDColorSpace pdCS = (PDColorSpace) this.getResources().getColorSpaces().get(colorSpace);
                     if (pdCS != null)
                     {
                         cs = ColorSpaces.valueOf(pdCS.getName());
@@ -349,7 +339,7 @@ public abstract class ContentStreamEngin
 
             if (csHelper == null)
             {
-                PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(csInlinedBase);
+                PDColorSpace pdCS = PDColorSpace.create(csInlinedBase);
                 PreflightConfiguration cfg = context.getConfig();
                 ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
                 csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
@@ -360,15 +350,15 @@ public abstract class ContentStreamEngin
     }
 
     /**
-     * This method validates if the ColorOperator can be used with the color space defined in OutputIntent dictionaries.
+     * This method validates if the ColorOperator can be used with the color space
+     * defined in OutputIntent dictionaries.
      * 
-     * @param operator
-     *            the color operator
+     * @param operation the color operator
      * @throws ContentStreamException
      */
     protected void checkColorOperators(String operation) throws ContentStreamException
     {
-        PDColorState cs = getColorState(operation);
+        PDColorSpace cs = getColorSpace(operation);
 
         if ("rg".equals(operation) || "RG".equals(operation))
         {
@@ -413,36 +403,29 @@ public abstract class ContentStreamEngin
         }
     }
 
-    private boolean validColorSpace(PDColorState colorState, ColorSpaceType expectedType) throws ContentStreamException
+    private boolean validColorSpace(PDColorSpace colorSpace, ColorSpaceType expectedType)
+            throws ContentStreamException
     {
-        boolean result = true;
-        if (colorState == null)
+        if (colorSpace == null)
         {
-            result = validColorSpaceDestOutputProfile(expectedType);
+            return validColorSpaceDestOutputProfile(expectedType);
         }
         else
         {
-            PDColorSpace cs = colorState.getColorSpace();
-            if (isDeviceIndependent(cs, expectedType))
-            {
-                result = true;
-            }
-            else
-            {
-                result = validColorSpaceDestOutputProfile(expectedType);
-            }
+            return isDeviceIndependent(colorSpace, expectedType) ||
+                   validColorSpaceDestOutputProfile(expectedType);
         }
-        return result;
     }
 
-    /**
-     * Check if the ColorProfile provided by the DestOutputProfile entry isn't null and if the ColorSpace represented by
-     * the Profile has the right type (RGB or CMYK)
+    /*
+     * Check if the ColorProfile provided by the DestOutputProfile entry isn't null and
+     * if the ColorSpace represented by the Profile has the right type (RGB or CMYK)
      * 
      * @param expectedType
      * @return
      */
-    private boolean validColorSpaceDestOutputProfile(ColorSpaceType expectedType) throws ContentStreamException
+    private boolean validColorSpaceDestOutputProfile(ColorSpaceType expectedType)
+            throws ContentStreamException
     {
         boolean result = false;
         ICCProfileWrapper profileWrapper;
@@ -472,74 +455,54 @@ public abstract class ContentStreamEngin
         return result;
     }
 
-    /**
-     * Return true if the given ColorSpace is an independent device ColorSpace. If the color space is an ICCBased, check
-     * the embedded profile color (RGB or CMYK)
-     * 
-     * @param cs
-     * @return
+    /*
+     * Return true if the given ColorSpace is an independent device ColorSpace.
+     * If the color space is an ICCBased, check the embedded profile color (RGB or CMYK)
      */
     private boolean isDeviceIndependent(PDColorSpace cs, ColorSpaceType expectedType)
     {
-        boolean result = (cs instanceof PDCalGray || cs instanceof PDCalRGB || cs instanceof PDLab);
         if (cs instanceof PDICCBased)
         {
-            PDICCBased iccBased = (PDICCBased) cs;
-            try
+            int type = ((PDICCBased)cs).getColorSpaceType();
+            switch (expectedType)
             {
-                ColorSpace iccColorSpace = iccBased.getJavaColorSpace();
-                switch (expectedType)
-                {
-                case RGB:
-                    result = (iccColorSpace.getType() == ICC_ColorSpace.TYPE_RGB);
-                    break;
-                case CMYK:
-                    result = (iccColorSpace.getType() == ICC_ColorSpace.TYPE_CMYK);
-                    break;
-                default:
-                    result = true;
-                    break;
-                }
-            }
-            catch (IOException e)
-            {
-                result = false;
+                case RGB: return type == ICC_ColorSpace.TYPE_RGB;
+                case CMYK: return type == ICC_ColorSpace.TYPE_CMYK;
+                default: return true;
             }
         }
-        return result;
+        else
+        {
+            return cs instanceof PDCIEBasedColorSpace;
+        }
     }
 
-    /**
-     * Return the current color state used by the operation
-     * 
-     * @param operation
-     * @return
+    /*
+     * Return the current color space used by the operation
      */
-    private PDColorState getColorState(String operation)
+    private PDColorSpace getColorSpace(String operation)
     {
         if (getGraphicsState() == null)
         {
             return null;
         }
 
-        PDColorState colorState;
-        if (operation.equals("rg") || operation.equals("g") || operation.equals("k") || operation.equals("f")
-                || operation.equals("F") || operation.equals("f*"))
+        if (operation.equals("rg") || operation.equals("g") || operation.equals("k") ||
+            operation.equals("f") || operation.equals("F") || operation.equals("f*"))
         {
             // non stroking operator
-            colorState = getGraphicsState().getNonStrokingColor();
+            return getGraphicsState().getNonStrokingColorSpace();
         }
         else
         {
             // stroking operator
-            colorState = getGraphicsState().getStrokingColor();
+            return getGraphicsState().getStrokingColorSpace();
         }
-        return colorState;
     }
 
     /**
-     * This method validates if the ColorSpace used as operand is consistent with the color space defined in
-     * OutputIntent dictionaries.
+     * This method validates if the ColorSpace used as operand is consistent with
+     * the color space defined in OutputIntent dictionaries.
      * 
      * @param operator
      * @param arguments
@@ -582,7 +545,7 @@ public abstract class ContentStreamEngin
             /*
              * The color space is unknown. Try to access the resources dictionary, the color space can be a reference.
              */
-            PDColorSpace pdCS = (PDColorSpace) this.getColorSpaces().get(colorSpaceName);
+            PDColorSpace pdCS = (PDColorSpace) this.getResources().getColorSpaces().get(colorSpaceName);
             if (pdCS != null)
             {
                 cs = ColorSpaces.valueOf(pdCS.getName());
@@ -600,7 +563,7 @@ public abstract class ContentStreamEngin
 
         if (csHelper == null)
         {
-            PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(COSName.getPDFName(colorSpaceName));
+            PDColorSpace pdCS = PDColorSpace.create(COSName.getPDFName(colorSpaceName));
             PreflightConfiguration cfg = context.getConfig();
             ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
             csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java Thu Feb 20 06:31:01 2014
@@ -41,9 +41,8 @@ import org.apache.pdfbox.pdmodel.PDResou
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.text.PDTextState;
-import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -60,11 +59,12 @@ public class ContentStreamWrapper extend
         super(_context, _page);
     }
 
+
     /**
      * Process the validation of a PageContent (The page is initialized by the constructor)
-     * 
+     *
      * @return A list of validation error. This list is empty if the validation succeed.
-     * @throws ValidationException.
+     * @throws ValidationException
      */
     public void validPageContentStream() throws ValidationException
     {
@@ -94,7 +94,7 @@ public class ContentStreamWrapper extend
      * @return A list of validation error. This list is empty if the validation succeed.
      * @throws ValidationException
      */
-    public void validXObjContentStream(PDXObjectForm xobj) throws ValidationException
+    public void validXObjContentStream(PDFormXObject xobj) throws ValidationException
     {
         try
         {

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PDFAType3StreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PDFAType3StreamParser.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PDFAType3StreamParser.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PDFAType3StreamParser.java Thu Feb 20 06:31:01 2014
@@ -31,10 +31,9 @@ import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDInlinedImage;
+import org.apache.pdfbox.pdmodel.graphics.image.PDInlineImage;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.content.ContentStreamEngine;
-import org.apache.pdfbox.util.ImageParameters;
 import org.apache.pdfbox.util.PDFOperator;
 
 /**
@@ -46,7 +45,7 @@ public class PDFAType3StreamParser exten
     private boolean firstOperator = true;
     private float width = 0;
 
-    private PDInlinedImage image = null;
+    private PDInlineImage image = null;
     private BoundingBox box = null;
 
     public PDFAType3StreamParser(PreflightContext context, PDPage page)
@@ -69,7 +68,7 @@ public class PDFAType3StreamParser exten
     {
         resetEngine();
         processSubStream(null, type3Stream);
-        return image.createImage();
+        return image.getImage();
     }
 
     /**
@@ -90,10 +89,9 @@ public class PDFAType3StreamParser exten
 
         if (operation.equals("BI"))
         {
-            ImageParameters params = operator.getImageParameters();
-            image = new PDInlinedImage();
-            image.setImageParameters(params);
-            image.setImageData(operator.getImageData());
+            image = new PDInlineImage(operator.getImageParameters(),
+                                      operator.getImageData(),
+                                      getResources().getColorSpaces());
 
             validImageFilter(operator);
             validImageColorSpace(operator);

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/DeviceColorSpaceHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/DeviceColorSpaceHelper.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/DeviceColorSpaceHelper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/DeviceColorSpaceHelper.java Thu Feb 20 06:31:01 2014
@@ -24,8 +24,6 @@ package org.apache.pdfbox.preflight.grap
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_INVALID_COLOR_SPACE;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN;
 
-import java.io.IOException;
-
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
 import org.apache.pdfbox.preflight.PreflightContext;
@@ -72,26 +70,18 @@ public class DeviceColorSpaceHelper exte
     protected void processIndexedColorSpace(PDColorSpace pdcs)
     {
         PDIndexed indexed = (PDIndexed) pdcs;
-        try
-        {
-            PDColorSpace based = indexed.getBaseColorSpace();
-            ColorSpaces colorSpace = ColorSpaces.valueOf(based.getName());
-            switch (colorSpace)
-            {
-            case Indexed:
-            case Indexed_SHORT:
-            case Pattern:
-                context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN, colorSpace
-                        .getLabel() + " ColorSpace is forbidden"));
-                break;
-            default:
-                processAllColorSpace(based);
-            }
-        }
-        catch (IOException e)
+        PDColorSpace based = indexed.getBaseColorSpace();
+        ColorSpaces colorSpace = ColorSpaces.valueOf(based.getName());
+        switch (colorSpace)
         {
-            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE,
-                    "Unable to read Indexed Color Space : " + e.getMessage()));
+        case Indexed:
+        case Indexed_SHORT:
+        case Pattern:
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN, colorSpace
+                    .getLabel() + " ColorSpace is forbidden"));
+            break;
+        default:
+            processAllColorSpace(based);
         }
     }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java Thu Feb 20 06:31:01 2014
@@ -38,13 +38,14 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceNAttributes;
 import org.apache.pdfbox.pdmodel.graphics.color.PDICCBased;
 import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
-import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -300,7 +301,8 @@ public class StandardColorSpaceHelper im
                 return;
             }
 
-            PDColorSpace altColor = deviceN.getAlternateColorSpace();
+            COSBase cosAlt = ((COSArray)pdcs.getCOSObject()).getObject(2);
+            PDColorSpace altColor = PDColorSpace.create(cosAlt);
             if (altColor != null)
             {
                 processAllColorSpace(altColor);
@@ -349,29 +351,21 @@ public class StandardColorSpaceHelper im
     protected void processIndexedColorSpace(PDColorSpace pdcs)
     {
         PDIndexed indexed = (PDIndexed) pdcs;
-        try
+        PDColorSpace based = indexed.getBaseColorSpace();
+        ColorSpaces cs = ColorSpaces.valueOf(based.getName());
+        if (cs == ColorSpaces.Indexed || cs == ColorSpaces.Indexed_SHORT)
         {
-            PDColorSpace based = indexed.getBaseColorSpace();
-            ColorSpaces cs = ColorSpaces.valueOf(based.getName());
-            if (cs == ColorSpaces.Indexed || cs == ColorSpaces.Indexed_SHORT)
-            {
-                context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED,
-                        "Indexed color space can't be used as Base color space"));
-                return;
-            }
-            if (cs == ColorSpaces.Pattern)
-            {
-                context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED,
-                        "Pattern color space can't be used as Base color space"));
-                return;
-            }
-            processAllColorSpace(based);
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED,
+                    "Indexed color space can't be used as Base color space"));
+            return;
         }
-        catch (IOException e)
+        if (cs == ColorSpaces.Pattern)
         {
-            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE,
-                    "Unable to read Indexed color space : " + e.getMessage()));
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED,
+                    "Pattern color space can't be used as Base color space"));
+            return;
         }
+        processAllColorSpace(based);
     }
 
     /**
@@ -384,11 +378,10 @@ public class StandardColorSpaceHelper im
      */
     protected void processSeparationColorSpace(PDColorSpace pdcs)
     {
-        PDSeparation separation = (PDSeparation) pdcs;
         try
         {
-
-            PDColorSpace altCol = separation.getAlternateColorSpace();
+            COSBase cosAlt = ((COSArray)pdcs.getCOSObject()).getObject(2);
+            PDColorSpace altCol = PDColorSpace.create(cosAlt);
             if (altCol != null)
             {
                 ColorSpaces acs = ColorSpaces.valueOf(altCol.getName());

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java Thu Feb 20 06:31:01 2014
@@ -25,8 +25,8 @@ import static org.apache.pdfbox.prefligh
 
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
@@ -47,13 +47,13 @@ public class GraphicObjectPageValidation
         PreflightPath vPath = context.getValidationPath();
 
         XObjectValidator validator = null;
-        if (!vPath.isEmpty() && vPath.isExpectedType(PDXObjectImage.class))
+        if (!vPath.isEmpty() && vPath.isExpectedType(PDImageXObject.class))
         {
-            validator = new XObjImageValidator(context, (PDXObjectImage) vPath.peek());
+            validator = new XObjImageValidator(context, (PDImageXObject) vPath.peek());
         }
-        else if (!vPath.isEmpty() && vPath.isExpectedType(PDXObjectForm.class))
+        else if (!vPath.isEmpty() && vPath.isExpectedType(PDFormXObject.class))
         {
-            validator = new XObjFormValidator(context, (PDXObjectForm) vPath.peek());
+            validator = new XObjFormValidator(context, (PDFormXObject) vPath.peek());
         }
         else if (!vPath.isEmpty() && vPath.isExpectedType(COSStream.class))
         {

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java Thu Feb 20 06:31:01 2014
@@ -43,7 +43,7 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDPatternResources;
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPatternResources;
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingResources;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
@@ -185,7 +185,7 @@ public class ResourcesValidationProcess 
                     try
                     {
                         COSStream stream = COSUtils.getAsStream(xobj, cosDocument);
-                        PDXObject pdXObject = PDXObject.createXObject(stream);
+                        PDXObject pdXObject = PDXObject.createXObject(stream, entry.getKey().getName(), resources);
                         if (pdXObject != null)
                         {
                             ContextHelper.validateElement(context, pdXObject, GRAPHIC_PROCESS);

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java Thu Feb 20 06:31:01 2014
@@ -40,11 +40,12 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
 import org.apache.pdfbox.preflight.PreflightConstants;
@@ -147,7 +148,7 @@ public class SinglePageValidationProcess
                 {
                     thumbBase = ((COSObject) thumbBase).getObject();
                 }
-                PDXObject thumbImg = PDXObjectImage.createThumbnailXObject(thumbBase);
+                PDXObject thumbImg = PDImageXObject.createThumbnail((COSStream)thumbBase);
                 ContextHelper.validateElement(context, thumbImg, GRAPHIC_PROCESS);
             }
             catch (IOException e)

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java Thu Feb 20 06:31:01 2014
@@ -35,7 +35,7 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
@@ -53,9 +53,9 @@ public class XObjFormValidator extends A
     /**
      * High level object which represents the XObjectForm
      */
-    PDXObjectForm pdXObj = null;
+    PDFormXObject pdXObj = null;
 
-    public XObjFormValidator(PreflightContext context, PDXObjectForm xobj)
+    public XObjFormValidator(PreflightContext context, PDFormXObject xobj)
     {
         super(context, xobj.getCOSStream());
         this.pdXObj = xobj;

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java Thu Feb 20 06:31:01 2014
@@ -32,8 +32,7 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSBoolean;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -49,9 +48,9 @@ import org.apache.pdfbox.preflight.utils
  */
 public class XObjImageValidator extends AbstractXObjValidator
 {
-    protected PDXObjectImage xImage = null;
+    protected PDImageXObject xImage = null;
 
-    public XObjImageValidator(PreflightContext context, PDXObjectImage xobj)
+    public XObjImageValidator(PreflightContext context, PDImageXObject xobj)
     {
         super(context, xobj.getCOSStream());
         this.xImage = xobj;
@@ -143,7 +142,7 @@ public class XObjImageValidator extends 
             {
                 PreflightConfiguration config = context.getConfig();
                 ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
-                PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(csImg);
+                PDColorSpace pdCS = PDColorSpace.create(csImg);
                 ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_PATTERN);
                 csh.validate();
             }

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/ExtractImages.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/ExtractImages.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/ExtractImages.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/ExtractImages.java Thu Feb 20 06:31:01 2014
@@ -16,7 +16,9 @@
  */
 package org.apache.pdfbox;
 
+import java.awt.image.BufferedImage;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
@@ -27,9 +29,11 @@ import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
 import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
+import org.apache.pdfbox.pdmodel.graphics.image.TIFFInputStream;
+import org.apache.pdfbox.util.ImageIOUtil;
 
 /**
  * This will read a read pdf and extract images. <br/><br/>
@@ -186,9 +190,9 @@ public class ExtractImages
                 String key = xobjectIter.next();
                 PDXObject xobject = xobjects.get( key );
                 // write the images
-                if (xobject instanceof PDXObjectImage)
+                if (xobject instanceof PDImageXObject)
                 {
-                    PDXObjectImage image = (PDXObjectImage)xobject;
+                    PDImageXObject image = (PDImageXObject)xobject;
                     String name = null;
                     if (addKey) 
                     {
@@ -199,12 +203,12 @@ public class ExtractImages
                         name = getUniqueFileName( prefix, image.getSuffix() );
                     }
                     System.out.println( "Writing image:" + name );
-                    image.write2file( name );
+                    write2file( image, name );
                 }
                 // maybe there are more images embedded in a form object
-                else if (xobject instanceof PDXObjectForm)
+                else if (xobject instanceof PDFormXObject)
                 {
-                    PDXObjectForm xObjectForm = (PDXObjectForm)xobject;
+                    PDFormXObject xObjectForm = (PDFormXObject)xobject;
                     PDResources formResources = xObjectForm.getResources();
                     processResources(formResources, prefix, addKey);
                 }
@@ -212,6 +216,41 @@ public class ExtractImages
         }
     }
 
+    /**
+     * Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg".
+     * The suffix is automatically set by the
+     * @param filename the filename
+     * @throws IOException When somethings wrong with the corresponding file.
+     */
+    private void write2file(PDImageXObject xobj, String filename) throws IOException
+    {
+        FileOutputStream out = null;
+        try
+        {
+            out = new FileOutputStream(filename + "." + xobj.getSuffix());
+            BufferedImage image = xobj.getImage();
+            if (image != null)
+            {
+                if ("tiff".equals(xobj.getSuffix()))
+                {
+                    TIFFInputStream.writeToOutputStream(xobj, out);
+                }
+                else
+                {
+                    ImageIOUtil.writeImage(image, xobj.getSuffix(), out);
+                }
+            }
+            out.flush();
+        }
+        finally
+        {
+            if (out != null)
+            {
+                out.close();
+            }
+        }
+    }
+
     private String getUniqueFileName( String prefix, String suffix )
     {
         String uniqueName = null;