56 unsigned char *cpack,
g2int *lcpack,
int verbose)
59 static float alog2 =
ALOG2;
60 g2int j, nbits, imin, imax, maxdif;
61 g2int ndpts, nbytes, nsize, retry;
62 float bscale, dscale, rmax, rmin, temp;
69 LOG((2,
"jpcpack_int() fld_is_double %d width %ld height %ld idrstmpl[1] %d *lcpack %ld",
70 fld_is_double, width, height, idrstmpl[1], *lcpack));
71 LOG((3,
"idrstmpl: %ld %ld %ld %ld %ld %ld %ld", idrstmpl[0], idrstmpl[1], idrstmpl[2],
72 idrstmpl[3], idrstmpl[4], idrstmpl[5], idrstmpl[6]));
74 ndpts = width * height;
77 LOG((3,
"ndpts %ld bscale %g dscale %g", ndpts, bscale, dscale));
86 for (j = 1; j < ndpts; j++)
94 maxdif = (
g2int)(rint(rmaxd * dscale) - rint(rmind * dscale));
96 maxdif = (
g2int)rint((rmaxd - rmind) * dscale * bscale);
100 for (j = 1; j < ndpts; j++)
107 if (idrstmpl[1] == 0)
108 maxdif = (
g2int)(rint(rmax * dscale) - rint(rmin * dscale));
110 maxdif = (
g2int)rint((rmax - rmin) * dscale * bscale);
112 LOG((3,
"rmax %g rmaxd %g rmin %g rmind %g", rmax, rmaxd, rmin, rmind));
117 if (((fld_is_double && rmind != rmaxd) || (!fld_is_double && rmin != rmax)) && maxdif != 0)
119 ifld = malloc(ndpts *
sizeof(
g2int));
123 if (idrstmpl[1] == 0)
127 imin = (
g2int)rint((fld_is_double ? rmind : rmin) * dscale);
128 imax = (
g2int)rint((fld_is_double ? rmaxd : rmax) * dscale);
129 maxdif = imax - imin;
130 temp = log((
double)(maxdif + 1)) / alog2;
131 nbits = (
g2int)ceil(temp);
136 for(j = 0; j < ndpts; j++)
137 ifld[j] = (
g2int)rint(dfld[j] * dscale) - imin;
142 for(j = 0; j < ndpts; j++)
143 ifld[j] = (
g2int)rint(ffld[j] * dscale) - imin;
152 rmind = rmind * dscale;
153 rmaxd = rmaxd * dscale;
154 maxdif = (
g2int)rint((rmaxd - rmind) * bscale);
158 rmin = rmin * dscale;
159 rmax = rmax * dscale;
160 maxdif = (
g2int)rint((rmax - rmin) * bscale);
163 temp = log((
double)(maxdif + 1)) / alog2;
164 nbits = (
g2int)ceil(temp);
168 for (j = 0; j < ndpts; j++)
169 ifld[j] = (
g2int)rint(((dfld[j] * dscale) - rmind) * bscale);
173 for (j = 0; j < ndpts; j++)
174 ifld[j] = (
g2int)rint(((ffld[j] * dscale) - rmin) * bscale);
181 nbytes = (nbits + 7) / 8;
183 ctemp = calloc(ndpts, nbytes);
184 sbits(ctemp, ifld, 0, nbytes * 8, 0, ndpts);
186 idrstmpl[6], retry, (
char *)cpack, nsize)) <= 0)
189 printf(
"jpcpack: ERROR Packing JPC = %d\n", (
int)*lcpack);
195 idrstmpl[6], retry, (
char *)cpack, nsize)) <= 0)
198 printf(
"jpcpack: Retry Failed.\n");
204 printf(
"jpcpack: Retry Successful.\n");
220 mkieee(&rmin, idrstmpl, 1);
223 if (idrstmpl[5] == 0)
271 unsigned char *cpack,
g2int *lcpack)
273 jpcpack_int(fld, 0, width, height, idrstmpl, cpack, lcpack, 1);
322 unsigned char *cpack,
size_t *lcpack)
324 g2int width8 = width, height8 = height, lcpack8 = *lcpack;
329 idrstmpl8[i] = idrstmpl[i];
331 ret =
jpcpack_int(fld, 0, width8, height8, idrstmpl8, cpack, &lcpack8, 0);
336 idrstmpl[i] = (
int)idrstmpl8[i];
337 *lcpack = (
g2int)lcpack8;
388 unsigned char *cpack,
size_t *lcpack)
390 g2int width8 = width, height8 = height, lcpack8 = *lcpack;
395 idrstmpl8[i] = idrstmpl[i];
397 ret =
jpcpack_int(fld, 1, width8, height8, idrstmpl8, cpack, &lcpack8, 0);
402 idrstmpl[i] = (
int)idrstmpl8[i];
403 *lcpack = (
g2int)lcpack8;
int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char *outjpc, g2int jpclen)
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 ...
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
#define G2C_JPEG_DRS_TEMPLATE_LEN
Length of the idrstmpl array for JPEG packing.
#define G2C_EJPEG
Error encoding/decoding JPEG data.
int64_t g2int
Long integer type.
#define G2C_NOERROR
No error.
Header file with internal function prototypes NCEPLIBS-g2c library.
void mkieee(float *a, g2int *rieee, g2int num)
This subroutine stores a list of real values in 32-bit IEEE floating point format.
double int_power(double x, g2int y)
Function similar to C pow() power function.
#define LOG(e)
Ignore logging to stdout.
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)
This internal function packs up a float or double array into a JPEG2000 code stream.