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 2021/03/29 04:33:41 UTC
svn commit: r1888156 -
/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/imageio/ImageIOUtil.java
Author: tilman
Date: Mon Mar 29 04:33:41 2021
New Revision: 1888156
URL: http://svn.apache.org/viewvc?rev=1888156&view=rev
Log:
PDFBOX-4892: optimize / simplify + avoid NPE, as suggested by valerybokov
Modified:
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/imageio/ImageIOUtil.java
Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/imageio/ImageIOUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/imageio/ImageIOUtil.java?rev=1888156&r1=1888155&r2=1888156&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/imageio/ImageIOUtil.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/imageio/ImageIOUtil.java Mon Mar 29 04:33:41 2021
@@ -240,12 +240,14 @@ public final class ImageIOUtil
LOG.error("Supported formats: " + Arrays.toString(ImageIO.getWriterFormatNames()));
return false;
}
+
+ boolean isTifFormat = formatName.toLowerCase().startsWith("tif");
// compression
if (param != null && param.canWriteCompressed())
{
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
- if (formatName.toLowerCase().startsWith("tif"))
+ if (isTifFormat)
{
if ("".equals(compressionType))
{
@@ -268,28 +270,28 @@ public final class ImageIOUtil
}
}
- if (formatName.toLowerCase().startsWith("tif"))
+ if (metadata != null)
{
- // TIFF metadata
- TIFFUtil.updateMetadata(metadata, image, dpi);
- }
- else if ("jpeg".equalsIgnoreCase(formatName)
- || "jpg".equalsIgnoreCase(formatName))
- {
- // This segment must be run before other meta operations,
- // or else "IIOInvalidTreeException: Invalid node: app0JFIF"
- // The other (general) "meta" methods may not be used, because
- // this will break the reading of the meta data in tests
- JPEGUtil.updateMetadata(metadata, dpi);
- }
- else
- {
- // write metadata is possible
- if (metadata != null
- && !metadata.isReadOnly()
- && metadata.isStandardMetadataFormatSupported())
+ if (isTifFormat)
+ {
+ // TIFF metadata
+ TIFFUtil.updateMetadata(metadata, image, dpi);
+ }
+ else if ("jpeg".equalsIgnoreCase(formatName) || "jpg".equalsIgnoreCase(formatName))
{
- setDPI(metadata, dpi, formatName);
+ // This segment must be run before other meta operations,
+ // or else "IIOInvalidTreeException: Invalid node: app0JFIF"
+ // The other (general) "meta" methods may not be used, because
+ // this will break the reading of the meta data in tests
+ JPEGUtil.updateMetadata(metadata, dpi);
+ }
+ else
+ {
+ // write metadata is possible
+ if (!metadata.isReadOnly() && metadata.isStandardMetadataFormatSupported())
+ {
+ setDPI(metadata, dpi, formatName);
+ }
}
}