[poppler] utils/pdftocairo.cc utils/pdftoppm.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Sep 6 14:13:33 UTC 2022


 utils/pdftocairo.cc |    2 +-
 utils/pdftoppm.cc   |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 119af9e894a928d9bad7d4f9e1681e54c9923439
Author: James Cloos <cloos at jhcloos.com>
Date:   Tue Aug 9 23:37:07 2022 +0200

    Avoid round-off errors when determining raster dimensions.
    
    The code in pdftoppm.cc and pdftocairo.cc carefully avoided overflow
    when converting page sizes from points to pixels.
    
    This worked well when the math was performed at extended precision,
    as is done when using x387 opcodes, but could lead to results too
    large by a ulp when computed without extra precision.
    
    The code then needs to call ceil(3) to round fractional results up
    to the next larger integer, resulting in an off-by-one error if the
    computed size is even one ulp more than an integer.
    
    The initial size is already a multiple of 72, so rearranging the math
    to multiply before dividing by 72 avoids that imprecision.
    
    Issue #253

diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index 476f0be2..9e92f774 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -527,7 +527,7 @@ static void getOutputSize(double page_w, double page_h, double *width, double *h
             }
         }
     } else {
-        getCropSize(page_w * (x_resolution / 72.0), page_h * (y_resolution / 72.0), width, height);
+        getCropSize(page_w * x_resolution / 72.0, page_h * y_resolution / 72.0, width, height);
     }
 }
 
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 69e56a72..b1aa9248 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -666,10 +666,10 @@ int main(int argc, char *argv[])
 
             // No specific image size requested---compute the size from the resolution
             if (x_scaleTo <= 0) {
-                pg_w = pg_w * (x_resolution / 72.0);
+                pg_w = pg_w * x_resolution / 72.0;
             }
             if (y_scaleTo <= 0) {
-                pg_h = pg_h * (y_resolution / 72.0);
+                pg_h = pg_h * y_resolution / 72.0;
             }
         }
 


More information about the poppler mailing list