58 unsigned char *cpack,
g2int *lcpack)
61 static float alog2 =
ALOG2;
62 g2int j, nbits, imin, imax, maxdif;
63 g2int ndpts, nbytes, nsize, retry;
64 float bscale, dscale, rmax, rmin, temp;
70 LOG((2,
"jpcpack_int() fld_is_double %d width %ld height %ld idrstmpl[1] %ld *lcpack %ld",
71 fld_is_double, width, height, idrstmpl[1], *lcpack));
73 ndpts = width * height;
76 LOG((3,
"ndpts %ld bscale %g dscale %g", ndpts, bscale, dscale));
85 for (j = 1; j < ndpts; j++)
93 maxdif = (
g2int)(rint(rmaxd * dscale) - rint(rmind * dscale));
95 maxdif = (
g2int)rint((rmaxd - rmind) * dscale * bscale);
99 for (j = 1; j < ndpts; j++)
106 if (idrstmpl[1] == 0)
107 maxdif = (
g2int)(rint(rmax * dscale) - rint(rmin * dscale));
109 maxdif = (
g2int)rint((rmax - rmin) * dscale * bscale);
111 LOG((3,
"rmax %g rmaxd %g rmin %g rmind %g", rmax, rmaxd, rmin, rmind));
116 if (((fld_is_double && rmind != rmaxd) || (!fld_is_double && rmin != rmax)) && maxdif != 0)
118 ifld = malloc(ndpts *
sizeof(
g2int));
122 if (idrstmpl[1] == 0)
126 imin = (
g2int)rint((fld_is_double ? rmind : rmin) * dscale);
127 imax = (
g2int)rint((fld_is_double ? rmaxd : rmax) * dscale);
128 maxdif = imax - imin;
129 temp = log((
double)(maxdif + 1)) / alog2;
130 nbits = (
g2int)ceil(temp);
135 for(j = 0; j < ndpts; j++)
136 ifld[j] = (
g2int)rint(dfld[j] * dscale) - imin;
141 for(j = 0; j < ndpts; j++)
142 ifld[j] = (
g2int)rint(ffld[j] * dscale) - imin;
151 rmind = rmind * dscale;
152 rmaxd = rmaxd * dscale;
153 maxdif = (
g2int)rint((rmaxd - rmind) * bscale);
157 rmin = rmin * dscale;
158 rmax = rmax * dscale;
159 maxdif = (
g2int)rint((rmax - rmin) * bscale);
162 temp = log((
double)(maxdif + 1)) / alog2;
163 nbits = (
g2int)ceil(temp);
167 for (j = 0; j < ndpts; j++)
168 ifld[j] = (
g2int)rint(((dfld[j] * dscale) - rmind) * bscale);
172 for (j = 0; j < ndpts; j++)
173 ifld[j] = (
g2int)rint(((ffld[j] * dscale) - rmin) * bscale);
180 nbytes = (nbits + 7) / 8;
182 ctemp = calloc(ndpts, nbytes);
183 sbits(ctemp, ifld, 0, nbytes * 8, 0, ndpts);
185 idrstmpl[6], retry, (
char *)cpack, nsize)) <= 0)
187 printf(
"jpcpack: ERROR Packing JPC = %d\n", (
int)*lcpack);
192 idrstmpl[6], retry, (
char *)cpack, nsize)) <= 0)
193 printf(
"jpcpack: Retry Failed.\n");
195 printf(
"jpcpack: Retry Successful.\n");
209 mkieee(&rmin, idrstmpl, 1);
212 if (idrstmpl[5] == 0)
254 unsigned char *cpack,
g2int *lcpack)
256 jpcpack_int(fld, 0, width, height, idrstmpl, cpack, lcpack);
295 unsigned char *cpack,
g2int *lcpack)
297 jpcpack_int(fld, 1, width, height, idrstmpl, cpack, lcpack);