summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cloos <cloos@jhcloos.com>2014-05-17 00:08:51 -0400
committerJames Cloos <cloos@jhcloos.com>2014-05-17 00:08:51 -0400
commit4e6d85ece537cfb0623dc77e3948bec9b0ed50ce (patch)
treeeb97ca7a4ee21f1f64905d8ccd574eccc82354c0
parent93373cd113d046b65538fe983b46842d689a2112 (diff)
Avoid round-off errors when determining raster dimensions.roundoffroundoff
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. Signed-off-by: James Cloos <cloos@jhcloos.com>
-rw-r--r--utils/pdftocairo.cc4
-rw-r--r--utils/pdftoppm.cc4
2 files changed, 4 insertions, 4 deletions
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index b3f57b65..5984dbd5 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -428,8 +428,8 @@ static void getOutputSize(double page_w, double page_h, double *width, double *h
*height = paperHeight;
}
} else {
- getCropSize(page_w * (x_resolution / 72.0),
- page_h * (y_resolution / 72.0),
+ 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 962860b1..5d71155e 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -497,8 +497,8 @@ int main(int argc, char *argv[]) {
x_resolution = y_resolution;
}
}
- pg_w = pg_w * (x_resolution / 72.0);
- pg_h = pg_h * (y_resolution / 72.0);
+ pg_w = pg_w * x_resolution / 72.0;
+ pg_h = pg_h * y_resolution / 72.0;
if ((doc->getPageRotate(pg) == 90) || (doc->getPageRotate(pg) == 270)) {
tmp = pg_w;
pg_w = pg_h;