pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1771771 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java
Date Mon, 28 Nov 2016 17:13:00 GMT
Author: tilman
Date: Mon Nov 28 17:12:59 2016
New Revision: 1771771

URL: http://svn.apache.org/viewvc?rev=1771771&view=rev
Log:
PDFBOX-3599: support DataBufferUShort for 16 bit images

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java?rev=1771771&r1=1771770&r2=1771771&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java Mon Nov 28 17:12:59
2016
@@ -19,6 +19,7 @@ package org.apache.pdfbox.filter;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBuffer;
 import java.awt.image.DataBufferByte;
+import java.awt.image.DataBufferUShort;
 import java.awt.image.WritableRaster;
 import java.io.IOException;
 import java.io.InputStream;
@@ -56,14 +57,28 @@ public final class JPXFilter extends Fil
         BufferedImage image = readJPX(encoded, result);
 
         WritableRaster raster = image.getRaster();
-        if (raster.getDataBuffer().getDataType() != DataBuffer.TYPE_BYTE)
+        switch (raster.getDataBuffer().getDataType())
         {
-            throw new IOException("Not implemented: greater than 8-bit depth");
-        }
-        DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
-        decoded.write(buffer.getData());
+            case DataBuffer.TYPE_BYTE:
+                DataBufferByte byteBuffer = (DataBufferByte) raster.getDataBuffer();
+                decoded.write(byteBuffer.getData());
+                return result;
 
-        return result;
+            case DataBuffer.TYPE_USHORT:
+                DataBufferUShort wordBuffer = (DataBufferUShort) raster.getDataBuffer();
+                int size = wordBuffer.getSize();
+                short[] data = wordBuffer.getData();
+                for (int i = 0; i < size; ++i)
+                {
+                    short w = data[i];
+                    decoded.write(w >> 8);
+                    decoded.write(w);
+                }
+                return result;
+
+            default:
+                throw new IOException("Data type " + raster.getDataBuffer().getDataType()
+ " not implemented");
+        }        
     }
 
     // try to read using JAI Image I/O



Mime
View raw message