42 unsigned char *cpack,
g2int *lcpack)
45 static float alog2 =
ALOG2;
46 g2int j, nbits, imin, imax, maxdif;
48 float bscale, dscale, rmax, rmin, temp;
54 LOG((2,
"pngpack_int fld_is_double %d width %ld height %ld idrstmpl[1] %d",
55 fld_is_double, width, height, idrstmpl[1]));
57 ndpts = width * height;
60 LOG((3,
"ndpts %d bscale %g dscale %g", ndpts, bscale, dscale));
71 for (j = 1; j < ndpts; j++)
78 maxdif = (
g2int)rint((rmaxd - rmind) * dscale * bscale);
82 for (j = 1; j < ndpts; j++)
89 maxdif = (
g2int)rint((rmax - rmin) * dscale * bscale);
91 LOG((3,
"rmax %g rmaxd %g rmin %g rmind %g", rmax, rmaxd, rmin, rmind));
96 if (((fld_is_double && rmind != rmaxd) || (!fld_is_double && rmin != rmax)) && maxdif != 0)
98 ifld = malloc(ndpts *
sizeof(
g2int));
102 if (idrstmpl[1] == 0)
106 imin = (
g2int)rint((fld_is_double ? rmind : rmin) * dscale);
107 imax = (
g2int)rint((fld_is_double ? rmaxd : rmax) * dscale);
108 maxdif = imax - imin;
109 temp = log((
double)(maxdif + 1)) / alog2;
110 nbits = (
g2int)ceil(temp);
115 for(j = 0; j < ndpts; j++)
116 ifld[j] = (
g2int)rint(dfld[j] * dscale) - imin;
121 for(j = 0; j < ndpts; j++)
122 ifld[j] = (
g2int)rint(ffld[j] * dscale) - imin;
131 rmind = rmind * dscale;
132 rmaxd = rmaxd * dscale;
133 maxdif = (
g2int)rint((rmaxd - rmind) * bscale);
137 rmin = rmin * dscale;
138 rmax = rmax * dscale;
139 maxdif = (
g2int)rint((rmax - rmin) * bscale);
141 temp = log((
double)(maxdif + 1)) / alog2;
142 nbits = (
g2int)ceil(temp);
146 for (j = 0; j < ndpts; j++)
147 ifld[j] = (
g2int)rint(((dfld[j] * dscale) - rmind) * bscale);
151 for (j = 0; j < ndpts; j++)
152 ifld[j] = (
g2int)rint(((ffld[j] * dscale) - rmin) * bscale);
160 else if (nbits <= 16)
162 else if (nbits <= 24)
167 nbytes = (nbits / 8) * ndpts;
168 ctemp = calloc(nbytes, 1);
169 sbits(ctemp, ifld, 0, nbits, 0, ndpts);
172 if ((*lcpack = (
g2int)
enc_png(ctemp, width, height, nbits, cpack)) <= 0)
173 printf(
"pngpack: ERROR Packing PNG = %d\n", (
int)*lcpack);
186 mkieee(&rmin, idrstmpl, 1);
225 unsigned char *cpack,
g2int *lcpack)
227 pngpack_int(fld, 0, width, height, idrstmpl, cpack, lcpack);
260 unsigned char *cpack,
g2int *lcpack)
262 pngpack_int(fld, 1, width, height, idrstmpl, cpack, lcpack);