|
|
1.1 ! root 1: /* ! 2: ...dump vector in two-digit base-64 compressed format... ! 3: */ ! 4: ! 5: #include <stdio.h> ! 6: #include "../view2d.h" ! 7: #define INF 1e25 ! 8: ! 9: pack(n,f) ! 10: int n; ! 11: float f[]; ! 12: { ! 13: float *t; ! 14: float fmin = INF, fmax = -INF; ! 15: float floor = -INF; ! 16: for(t=f+n; t!=f; t--){ ! 17: if( *t<fmin) fmin= *t; ! 18: if( *t>fmax) fmax= *t; ! 19: } ! 20: printf("%d %e %e\n",n,fmin,fmax); ! 21: v2pack(n,f,fmin,fmax,floor); ! 22: } ! 23: ! 24: /* write compressed values */ ! 25: v2pack(n,data,fmin,fmax,floor) ! 26: int n; ! 27: float *data; ! 28: float fmin, fmax; /* data range before compression */ ! 29: float floor; /* value to flag out of bounds */ ! 30: { ! 31: int code, hi, lo, i; ! 32: float frange, slope, t; ! 33: frange = fmax - fmin; ! 34: if(frange==0.) frange=1.; ! 35: slope = 4095 / frange; ! 36: for(i=1; i<=n; i++, data++){ ! 37: t = *data; ! 38: if( t <= floor ){ ! 39: putchar('~'); ! 40: putchar('~'); ! 41: }else{ ! 42: code = slope*(t-fmin); ! 43: if(code>4095){ code=4095; }else if(code<0){ code = 0; } ! 44: lo = code%64; ! 45: hi = code/64; ! 46: putchar(hi+33); ! 47: putchar(lo+33); ! 48: } ! 49: if(i%38==0) putchar('\n'); ! 50: } ! 51: if(n%38!=0) putchar('\n'); ! 52: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.