39 unsigned char *cpack,
g2int *lcpack)
42 static g2float alog2 = 0.69314718;
43 g2int j, nbits, imin, imax, maxdif;
45 g2float bscale, dscale, rmax, rmin, temp;
49 ndpts = width * height;
56 for (j = 1; j < ndpts; j++)
63 maxdif = (
g2int)rint((rmax-rmin) * dscale * bscale);
68 if (rmin != rmax && maxdif != 0)
70 ifld = malloc(ndpts *
sizeof(
g2int));
78 imin = (
g2int)rint(rmin * dscale);
79 imax = (
g2int)rint(rmax * dscale);
81 temp = log((
double)(maxdif + 1)) / alog2;
82 nbits = (
g2int)ceil(temp);
85 for(j = 0; j < ndpts; j++)
86 ifld[j] = (
g2int)rint(fld[j] * dscale) - imin;
94 maxdif = (
g2int)rint((rmax - rmin) * bscale);
95 temp = log((
double)(maxdif + 1)) / alog2;
96 nbits = (
g2int)ceil(temp);
98 for (j = 0; j < ndpts; j++)
99 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
106 else if (nbits <= 16)
108 else if (nbits <= 24)
113 nbytes = (nbits / 8) * ndpts;
114 ctemp = calloc(nbytes, 1);
115 sbits(ctemp, ifld, 0, nbits, 0, ndpts);
118 if ((*lcpack = (
g2int)
enc_png((
char *)ctemp, width, height, nbits, (
char *)cpack)) <= 0)
119 printf(
"pngpack: ERROR Packing PNG = %d\n", (
int)*lcpack);
129 mkieee(&rmin, idrstmpl, 1);
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbyte, g2int nskip, g2int n)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.
double int_power(double x, g2int y)
Function similar to C pow() power function.
void mkieee(g2float *a, g2int *rieee, g2int num)
This subroutine stores a list of real values in 32-bit IEEE floating point format.
int enc_png(char *, g2int, g2int, g2int, char *)
Encode PNG.
void pngpack(g2float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field into PNG image format.