From 171db68c3dfb64b7d4671f7ba68ff9e0b5e726df Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sat, 20 Jul 2013 18:00:34 -0400 Subject: readtif, writetif: simplify rounding --- sys/src/cmd/jpg/readtif.c | 5 +---- sys/src/cmd/jpg/writetif.c | 9 ++------- 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'sys/src') diff --git a/sys/src/cmd/jpg/readtif.c b/sys/src/cmd/jpg/readtif.c index 9572689b8..2871869e7 100644 --- a/sys/src/cmd/jpg/readtif.c +++ b/sys/src/cmd/jpg/readtif.c @@ -1574,7 +1574,6 @@ readfield(Tif *t, Fld *f) static int checkfields(Tif *t) { - double a, b; ulong n, size; if(t->dx == 0) { @@ -1647,9 +1646,7 @@ checkfields(Tif *t) werrstr("rows per strip"); return -1; } - a = (double)t->dy; - b = (double)t->rows; - n = (ulong)floor((a+b-1)/b); + n = (t->dy + t->rows - 1) / t->rows; if(t->strips == nil || t->nstrips != n) { werrstr("strip offsets"); return -1; diff --git a/sys/src/cmd/jpg/writetif.c b/sys/src/cmd/jpg/writetif.c index 983684e1a..10de12ed7 100644 --- a/sys/src/cmd/jpg/writetif.c +++ b/sys/src/cmd/jpg/writetif.c @@ -1041,19 +1041,14 @@ alloctif(Tif *t) { int rgb; ulong i, count, n; - double a, b; count = t->ndata < 0x2000? t->ndata: 0x2000; - t->rows = count / t->bpl; - if(count%t->bpl != 0) - t->rows++; + t->rows = (count + t->bpl - 1) / t->bpl; if(t->comp == Tt4enc && t->opt) { if((n = t->rows%Kpar) != 0) t->rows += Kpar - n; } - a = (double)t->dy; - b = (double)t->rows; - t->nstrips = (ulong)floor((a+b-1)/b); + t->nstrips = (t->dy + t->rows - 1) / t->rows; t->strips = malloc(t->nstrips*sizeof *t->strips); if(t->strips == nil) return memerr; -- cgit v1.2.3