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 2016/11/08 17:59:49 UTC
svn commit: r1768754 -
/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java
Author: tilman
Date: Tue Nov 8 17:59:48 2016
New Revision: 1768754
URL: http://svn.apache.org/viewvc?rev=1768754&view=rev
Log:
PDFBOX-3559: don't use fast path for jpeg if there is a mask; improve javadoc
Modified:
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java
Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java?rev=1768754&r1=1768753&r2=1768754&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java Tue Nov 8 17:59:48 2016
@@ -292,11 +292,23 @@ public final class ExtractImages
}
}
+ private boolean hasMasks(PDImage pdImage) throws IOException
+ {
+ if (pdImage instanceof PDImageXObject)
+ {
+ PDImageXObject ximg = (PDImageXObject) pdImage;
+ return ximg.getMask() != null || ximg.getSoftMask() != null;
+ }
+ return false;
+ }
+
/**
- * 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.
+ * Writes the image to a file with the filename prefix + an appropriate suffix, like "Image.jpg".
+ * The suffix is automatically set depending on the image compression in the PDF.
+ * @param pdImage the image.
+ * @param prefix the filename prefix.
+ * @param directJPEG if true, force saving JPEG streams as they are in the PDF file.
+ * @throws IOException When something is wrong with the corresponding file.
*/
private void write2file(PDImage pdImage, String filename, boolean directJPEG) throws IOException
{
@@ -316,10 +328,12 @@ public final class ExtractImages
if ("jpg".equals(suffix))
{
String colorSpaceName = pdImage.getColorSpace().getName();
- if (directJPEG || PDDeviceGray.INSTANCE.getName().equals(colorSpaceName) ||
- PDDeviceRGB.INSTANCE.getName().equals(colorSpaceName))
+ if (directJPEG ||
+ !hasMasks(pdImage) &&
+ (PDDeviceGray.INSTANCE.getName().equals(colorSpaceName) ||
+ PDDeviceRGB.INSTANCE.getName().equals(colorSpaceName)))
{
- // RGB or Gray colorspace: get and write the unmodifiedJPEG stream
+ // RGB or Gray colorspace: get and write the unmodified JPEG stream
InputStream data = pdImage.createInputStream(JPEG);
IOUtils.copy(data, out);
IOUtils.closeQuietly(data);