pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1587306 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
Date Mon, 14 Apr 2014 20:24:50 GMT
Author: tilman
Date: Mon Apr 14 20:24:49 2014
New Revision: 1587306

URL: http://svn.apache.org/r1587306
Log:
PDFBOX-2026: support grayscale JPEG files

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java?rev=1587306&r1=1587305&r2=1587306&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
Mon Apr 14 20:24:49 2014
@@ -110,12 +110,30 @@ public class PDJpeg extends PDXObjectIma
         getRGBImage();
         if (image != null)
         {
-            setBitsPerComponent( 8 );
-            setColorSpace( PDDeviceRGB.INSTANCE );
-            setHeight( image.getHeight() );
-            setWidth( image.getWidth() );
+            setPropertiesFromAWT(image);
         }
+    }
 
+    private void setPropertiesFromAWT(BufferedImage image) throws IllegalStateException
+    {
+        setBitsPerComponent( 8 );
+        if (image.getColorModel().getNumComponents() == 3)
+        {
+            setColorSpace( PDDeviceRGB.INSTANCE );
+        }
+        else
+        {
+            if (image.getColorModel().getNumComponents() == 1)
+            {
+                setColorSpace( new PDDeviceGray() );
+            }
+            else
+            {
+                throw new IllegalStateException();
+            }
+        }
+        setHeight( image.getHeight() );
+        setWidth( image.getWidth() );
     }
 
     /**
@@ -180,24 +198,7 @@ public class PDJpeg extends PDXObjectIma
                 alphaPdImage = new PDJpeg(doc, alpha, compressionQuality);
                 dic.setItem(COSName.SMASK, alphaPdImage);
             }
-            setBitsPerComponent( 8 );
-            if (bi.getColorModel().getNumComponents() == 3)
-            {
-                setColorSpace( PDDeviceRGB.INSTANCE );
-            }
-            else
-            {
-                if (bi.getColorModel().getNumComponents() == 1)
-                {
-                    setColorSpace( new PDDeviceGray() );
-                }
-                else
-                {
-                    throw new IllegalStateException();
-                }
-            }
-            setHeight( bi.getHeight() );
-            setWidth( bi.getWidth() );
+            setPropertiesFromAWT(bi);
         }
         finally
         {



Mime
View raw message