readtif: simplify rounding in other places
This commit is contained in:
parent
171db68c3d
commit
61c82d2bb8
1 changed files with 5 additions and 11 deletions
|
@ -1210,16 +1210,14 @@ lzwstrip(Lzw *l, uchar *data, ulong size, ulong *i, long striplen)
|
||||||
static uchar *
|
static uchar *
|
||||||
lzw(Tif *t)
|
lzw(Tif *t)
|
||||||
{
|
{
|
||||||
ulong i, j, size, r, dy, n;
|
ulong i, j, size, r, dy;
|
||||||
long striplen;
|
long striplen;
|
||||||
uchar *data;
|
uchar *data;
|
||||||
Lzw l;
|
Lzw l;
|
||||||
Code *p, *q;
|
Code *p, *q;
|
||||||
int (*predict)(Tif *, uchar *, ulong);
|
int (*predict)(Tif *, uchar *, ulong);
|
||||||
|
|
||||||
n = t->dx * t->dy * t->depth;
|
size = ((t->dx*t->dy*t->depth + 7) / 8) * sizeof *data;
|
||||||
n = n%8 == 0? n/8: n/8+1;
|
|
||||||
size = n * sizeof *data;
|
|
||||||
if((data = malloc(size)) == nil) {
|
if((data = malloc(size)) == nil) {
|
||||||
free(t->data);
|
free(t->data);
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -1239,8 +1237,7 @@ lzw(Tif *t)
|
||||||
else
|
else
|
||||||
l.next = t->ndata;
|
l.next = t->ndata;
|
||||||
r = dy < t->rows? dy: t->rows;
|
r = dy < t->rows? dy: t->rows;
|
||||||
n = t->dx * r * t->depth;
|
striplen = (t->dx*r*t->depth + 7) / 8;
|
||||||
striplen = n%8 == 0? n/8: n/8+1;
|
|
||||||
if(lzwstrip(&l, data, size, &j, striplen) < 0)
|
if(lzwstrip(&l, data, size, &j, striplen) < 0)
|
||||||
break;
|
break;
|
||||||
dy -= t->rows;
|
dy -= t->rows;
|
||||||
|
@ -1280,9 +1277,7 @@ packbits(Tif *t)
|
||||||
ulong i, j, k, size;
|
ulong i, j, k, size;
|
||||||
uchar *data;
|
uchar *data;
|
||||||
|
|
||||||
i = t->dx * t->dy * t->depth;
|
size = ((t->dx*t->dy*t->depth + 7) / 8) * sizeof *data;
|
||||||
i = i%8 == 0? i/8: i/8+1;
|
|
||||||
size = i * sizeof *data;
|
|
||||||
if((data = malloc(size)) == nil) {
|
if((data = malloc(size)) == nil) {
|
||||||
free(t->data);
|
free(t->data);
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -1671,8 +1666,7 @@ checkfields(Tif *t)
|
||||||
if(t->counts == nil && t->comp == Nocomp &&
|
if(t->counts == nil && t->comp == Nocomp &&
|
||||||
t->nstrips == 1 &&
|
t->nstrips == 1 &&
|
||||||
(t->counts = malloc(size)) != nil) {
|
(t->counts = malloc(size)) != nil) {
|
||||||
n = t->dx * t->dy * t->depth;
|
t->counts[0] = (t->dx*t->dy*t->depth + 7) / 8;
|
||||||
t->counts[0] = n%8 == 0? n/8: n/8+1;
|
|
||||||
t->ncounts = t->nstrips;
|
t->ncounts = t->nstrips;
|
||||||
}
|
}
|
||||||
if(t->counts == nil || t->ncounts != t->nstrips) {
|
if(t->counts == nil || t->ncounts != t->nstrips) {
|
||||||
|
|
Loading…
Reference in a new issue