Author: tilman
Date: Mon Jun 15 18:08:33 2026
New Revision: 1935371

Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #475

Modified:
   
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Modified: 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
==============================================================================
--- 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
        Mon Jun 15 18:08:30 2026        (r1935370)
+++ 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
        Mon Jun 15 18:08:33 2026        (r1935371)
@@ -1363,7 +1363,9 @@ public class PageDrawer extends PDFGraph
         // calculate subsampling according to the resulting image size
         double scale = Math.abs(at.getDeterminant() * xform.getDeterminant());
 
-        int subsampling = (int) Math.floor(Math.sqrt(pdImage.getWidth() * 
pdImage.getHeight() / scale));
+        int imageWidth = pdImage.getWidth();
+        int imageHeight = pdImage.getHeight();
+        int subsampling = (int) Math.floor(Math.sqrt(imageWidth * imageHeight 
/ scale));
         if (subsampling > 8)
         {
             subsampling = 8;
@@ -1372,11 +1374,11 @@ public class PageDrawer extends PDFGraph
         {
             subsampling = 1;
         }
-        if (subsampling > pdImage.getWidth() || subsampling > 
pdImage.getHeight())
+        if (subsampling > imageWidth || subsampling > imageHeight)
         {
             // For very small images it is possible that the subsampling would 
imply 0 size.
             // To avoid problems, the subsampling is set to no less than the 
smallest dimension.
-            subsampling = Math.min(pdImage.getWidth(), pdImage.getHeight());
+            subsampling = Math.min(imageWidth, imageHeight);
         }
         return subsampling;
     }

Reply via email to