Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5D07A200BBD for ; Tue, 8 Nov 2016 18:59:53 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5BDB2160B0A; Tue, 8 Nov 2016 17:59:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9F8E9160AD0 for ; Tue, 8 Nov 2016 18:59:52 +0100 (CET) Received: (qmail 73898 invoked by uid 500); 8 Nov 2016 17:59:51 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 73889 invoked by uid 99); 8 Nov 2016 17:59:51 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Nov 2016 17:59:51 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4F6C8183994 for ; Tue, 8 Nov 2016 17:59:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id HJQRqHOLQPUf for ; Tue, 8 Nov 2016 17:59:50 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id E4AE15F1A1 for ; Tue, 8 Nov 2016 17:59:49 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 1A96AE01DC for ; Tue, 8 Nov 2016 17:59:49 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 19ED43A0849 for ; Tue, 8 Nov 2016 17:59:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1768754 - /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java Date: Tue, 08 Nov 2016 17:59:49 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161108175949.19ED43A0849@svn01-us-west.apache.org> archived-at: Tue, 08 Nov 2016 17:59:53 -0000 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);