pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1552553 - in /pdfbox/branches/1.8: ./ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceGray.java
Date Fri, 20 Dec 2013 09:17:59 GMT
Author: lehmi
Date: Fri Dec 20 09:17:59 2013
New Revision: 1552553

URL: http://svn.apache.org/r1552553
Log:
PDFBOX-1810: fixed the handling of bitsPerComponent when creating a color model for DeviceGray
based on a proposal by Tilman Hausherr

Modified:
    pdfbox/branches/1.8/   (props changed)
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceGray.java

Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
  Merged /pdfbox/trunk:r1552552

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceGray.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceGray.java?rev=1552553&r1=1552552&r2=1552553&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceGray.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceGray.java
Fri Dec 20 09:17:59 2013
@@ -17,19 +17,18 @@
 package org.apache.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.image.IndexColorModel;
 import java.awt.Transparency;
-
 import java.io.IOException;
 
 /**
  * This class represents a Gray color space.
  *
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.6 $
+ * 
  */
 public class PDDeviceGray extends PDColorSpace
 {
@@ -86,11 +85,24 @@ public class PDDeviceGray extends PDColo
      */
     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);
+    	ColorModel colorModel = null;
+    	if (bpc == 8)
+    	{
+    		ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
+            int[] nBits = {bpc};
+            colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE,DataBuffer.TYPE_BYTE);
+    	}
+    	else
+    	{
+        	int numEntries = 1 << bpc;
+            // calculate all possible values
+            byte[] indexedValues = new byte[numEntries];
+            for (int i = 0; i < numEntries; i++) 
+            {
+            	indexedValues[i] = (byte)(i*255/(numEntries - 1));
+            }
+            colorModel = new IndexColorModel(bpc, numEntries, indexedValues, indexedValues,
indexedValues);
+    	}
         return colorModel;
-
     }
 }



Mime
View raw message