55 unsigned char *cpack,
g2int *lcpack,
int verbose)
58 static float alog2 =
ALOG2;
59 g2int j, nbits, imin, imax, maxdif;
60 g2int ndpts, nbytes, nsize, retry;
61 float bscale, dscale, rmax, rmin, temp;
68 LOG((2,
"jpcpack_int() fld_is_double %d width %ld height %ld idrstmpl[1] %d *lcpack %ld",
69 fld_is_double, width, height, idrstmpl[1], *lcpack));
70 LOG((3,
"idrstmpl: %ld %ld %ld %ld %ld %ld %ld", idrstmpl[0], idrstmpl[1], idrstmpl[2],
71 idrstmpl[3], idrstmpl[4], idrstmpl[5], idrstmpl[6]));
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)
188 printf(
"jpcpack: ERROR Packing JPC = %d\n", (
int)*lcpack);
194 idrstmpl[6], retry, (
char *)cpack, nsize)) <= 0)
197 printf(
"jpcpack: Retry Failed.\n");
203 printf(
"jpcpack: Retry Successful.\n");
219 mkieee(&rmin, idrstmpl, 1);
222 if (idrstmpl[5] == 0)
int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char *outjpc, g2int jpclen)
Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n)
Store arbitrary size values into a packed bit string, taking the low order bits from each value in th...
int g2c_jpcpackd(double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)
This function packs up a double array into a JPEG2000 code stream.
int g2c_jpcpackf(float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)
This function packs up a float array into a JPEG2000 code stream.
void jpcpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This function packs up a float array into a JPEG2000 code stream.
static int jpcpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack, int verbose)
Packs a float or double array into a JPEG2000 code stream.