You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/08/11 18:55:36 UTC

svn commit: r1617326 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java

Author: tilman
Date: Mon Aug 11 16:55:36 2014
New Revision: 1617326

URL: http://svn.apache.org/r1617326
Log:
PDFBOX-2267: use getter instead of uninitalized variable; rethrow unhandled exception; treat /Alternate as ONE colorspace

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java?rev=1617326&r1=1617325&r2=1617326&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java Mon Aug 11 16:55:36 2014
@@ -31,9 +31,11 @@ import org.apache.pdfbox.pdmodel.common.
 
 import java.awt.Color;
 import java.awt.Transparency;
+import java.awt.color.CMMException;
 import java.awt.color.ColorSpace;
 import java.awt.color.ICC_ColorSpace;
 import java.awt.color.ICC_Profile;
+import java.awt.color.ProfileDataException;
 import java.awt.image.ColorModel;
 import java.awt.image.ComponentColorModel;
 import java.awt.image.DataBuffer;
@@ -110,6 +112,7 @@ public class PDICCBased extends PDColorS
      *
      * @return The cos object that matches this Java object.
      */
+    @Override
     public COSBase getCOSObject()
     {
         return array;
@@ -141,19 +144,27 @@ public class PDICCBased extends PDColorS
             profile = stream.createInputStream();
             ICC_Profile iccProfile = ICC_Profile.getInstance( profile );
             cSpace = new ICC_ColorSpace( iccProfile );
-            float[] components = new float[numberOfComponents];
             // there maybe a ProfileDataException or a CMMException as there
             // are some issues when loading ICC_Profiles, see PDFBOX-1295
             // Try to create a color as test ...
-            new Color(cSpace,components,1f);
+            new Color(cSpace,new float[getNumberOfComponents()],1f);
         }
         catch (RuntimeException e)
         {
-            // we are using an alternate colorspace as fallback
-            LOG.debug("Can't read ICC-profile, using alternate colorspace instead");
-            List alternateCSList = getAlternateColorSpaces();
-            PDColorSpace alternate = (PDColorSpace)alternateCSList.get(0);
-            cSpace = alternate.getJavaColorSpace();
+            if (e instanceof ProfileDataException
+                    || e instanceof CMMException
+                    || e instanceof IllegalArgumentException)
+            {
+                // we are using an alternate colorspace as fallback
+                List alternateCSList = getAlternateColorSpaces();
+                PDColorSpace alternate = (PDColorSpace) alternateCSList.get(0);
+                LOG.error("Can't read ICC-profile, using alternate colorspace instead: " + alternate);
+                cSpace = alternate.getJavaColorSpace();
+            }
+            else
+            {
+                throw e;
+            }
         }
         finally
         {
@@ -286,10 +297,7 @@ public class PDICCBased extends PDColorS
             }
         }
         List retval = new ArrayList();
-        for( int i=0; i<alternateArray.size(); i++ )
-        {
-            retval.add( PDColorSpaceFactory.createColorSpace( alternateArray.get( i ) ) );
-        }
+        retval.add( PDColorSpaceFactory.createColorSpace( alternateArray ) );
         return new COSArrayList( retval, alternateArray );
     }