From 8a3b2ceb0ff632c47e1516d3ffef8572dc8eb974 Mon Sep 17 00:00:00 2001 From: rsc Date: Sat, 24 Apr 2004 17:05:43 +0000 Subject: Add scat. Temporary fix to rc r.e. note groups. --- src/cmd/scat/hinv.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 src/cmd/scat/hinv.c (limited to 'src/cmd/scat/hinv.c') diff --git a/src/cmd/scat/hinv.c b/src/cmd/scat/hinv.c new file mode 100644 index 00000000..c76b00ea --- /dev/null +++ b/src/cmd/scat/hinv.c @@ -0,0 +1,231 @@ +#include +#include +#include +#include "sky.h" + +static void unshuffle(Pix*, int, int, Pix*); +static void unshuffle1(Pix*, int, Pix*); + +void +hinv(Pix *a, int nx, int ny) +{ + int nmax, log2n, h0, hx, hy, hc, i, j, k; + int nxtop, nytop, nxf, nyf, c; + int oddx, oddy; + int shift; + int s10, s00; + Pix *tmp; + + /* + * log2n is log2 of max(nx, ny) rounded up to next power of 2 + */ + nmax = ny; + if(nx > nmax) + nmax = nx; + log2n = log(nmax)/LN2 + 0.5; + if(nmax > (1<=0; k--) { + /* + * this somewhat cryptic code generates the sequence + * ntop[k-1] = (ntop[k]+1)/2, where ntop[log2n] = n + */ + c = c>>1; + nxtop = nxtop<<1; + nytop = nytop<<1; + if(nxf <= c) + nxtop--; + else + nxf -= c; + if(nyf <= c) + nytop--; + else + nyf -= c; + + /* + * halve divisors on last pass + */ + if(k == 0) + shift = 0; + + /* + * unshuffle in each dimension to interleave coefficients + */ + for(i = 0; i> 2; + a[s10 ] = (h0 + hx - hy - hc + 2) >> 2; + a[s00+1] = (h0 - hx + hy - hc + 2) >> 2; + a[s00 ] = (h0 - hx - hy + hc + 2) >> 2; + s00 += 2; + s10 += 2; + } + if(oddy) { + /* + * do last element in row if row length is odd + * s00+1, s10+1 are off edge + */ + h0 = a[s00 ] << shift; + hx = a[s10 ] << shift; + a[s10 ] = (h0 + hx + 2) >> 2; + a[s00 ] = (h0 - hx + 2) >> 2; + } + } + if(oddx) { + /* + * do last row if column length is odd + * s10, s10+1 are off edge + */ + s00 = ny*i; + for(j = 0; j> 2; + a[s00 ] = (h0 - hy + 2) >> 2; + s00 += 2; + } + if(oddy) { + /* + * do corner element if both row and column lengths are odd + * s00+1, s10, s10+1 are off edge + */ + h0 = a[s00 ] << shift; + a[s00 ] = (h0 + 2) >> 2; + } + } + } + free(tmp); +} + +static +void +unshuffle(Pix *a, int n, int n2, Pix *tmp) +{ + int i; + int nhalf, twon2, n2xnhalf; + Pix *p1, *p2, *pt; + + twon2 = n2<<1; + nhalf = (n+1)>>1; + n2xnhalf = n2*nhalf; /* pointer to a[i] */ + + /* + * copy 2nd half of array to tmp + */ + pt = tmp; + p1 = &a[n2xnhalf]; /* pointer to a[i] */ + for(i=nhalf; i=0; i--) { + p1 -= twon2; + p2 -= n2; + *p1 = *p2; + } + + /* + * now distribute 2nd half of array (in tmp) to odd elements + */ + pt = tmp; + p1 = &a[n2]; /* pointer to a[i] */ + for(i=1; i> 1; + + /* + * copy 2nd half of array to tmp + */ + pt = tmp; + p1 = &a[nhalf]; /* pointer to a[i] */ + for(i=nhalf; i=0; i--) { + p1 -= 2; + p2--; + *p1 = *p2; + } + + /* + * now distribute 2nd half of array (in tmp) to odd elements + */ + pt = tmp; + p1 = &a[1]; /* pointer to a[i] */ + for(i=1; i