summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cloos <cloos@jhcloos.com>2022-08-09 23:37:07 +0200
committerAlbert Astals Cid <tsdgeos@yahoo.es>2022-09-06 14:10:18 +0000
commit119af9e894a928d9bad7d4f9e1681e54c9923439 (patch)
tree122d5d332e233a2335d0d4ba90bd5d2d4e5f3115
parentd06eb33d1668ca3a08055bd033d8f5ea725e5be7 (diff)
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
-rw-r--r--utils/pdftocairo.cc2
-rw-r--r--utils/pdftoppm.cc4
2 files changed, 3 insertions, 3 deletions
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;
}
}