54 unsigned char *cpack,
g2int *lcpack)
57 static g2float alog2 = 0.69314718;
58 g2int j, nbits, imin, imax, maxdif;
59 g2int ndpts, nbytes, nsize, retry;
60 g2float bscale, dscale, rmax, rmin, temp;
64 ndpts = width * height;
71 for (j = 1; j < ndpts; j++)
79 maxdif = (
g2int)(rint(rmax * dscale) - rint(rmin * dscale));
81 maxdif = (
g2int)rint((rmax - rmin) * dscale * bscale);
86 if (rmin != rmax && maxdif != 0)
88 ifld = malloc(ndpts *
sizeof(
g2int));
96 imin = (
g2int)rint(rmin * dscale);
97 imax = (
g2int)rint(rmax * dscale);
99 temp = log((
double)(maxdif + 1)) / alog2;
100 nbits = (
g2int)ceil(temp);
103 for(j = 0; j < ndpts; j++)
104 ifld[j] = (
g2int)rint(fld[j] * dscale) - imin;
110 rmin = rmin * dscale;
111 rmax = rmax * dscale;
112 maxdif = (
g2int)rint((rmax - rmin) * bscale);
113 temp = log((
double)(maxdif + 1)) / alog2;
114 nbits = (
g2int)ceil(temp);
116 for (j = 0; j < ndpts; j++)
117 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
123 nbytes = (nbits + 7) / 8;
125 ctemp = calloc(ndpts, nbytes);
126 sbits(ctemp, ifld, 0, nbytes * 8, 0, ndpts);
128 idrstmpl[6], retry, (
char *)cpack, nsize)) <= 0)
130 printf(
"jpcpack: ERROR Packing JPC = %d\n", (
int)*lcpack);
135 idrstmpl[6], retry, (
char *)cpack, nsize)) <= 0)
136 printf(
"jpcpack: Retry Failed.\n");
138 printf(
"jpcpack: Retry Successful.\n");
150 mkieee(&rmin, idrstmpl, 1);
153 if (idrstmpl[5] == 0)
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.
int enc_jpeg2000(unsigned char *, g2int, g2int, g2int, g2int, g2int, g2int, char *, g2int)
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 ...
void jpcpack(g2float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field into a JPEG2000 code stream.
void mkieee(g2float *a, g2int *rieee, g2int num)
This subroutine stores a list of real values in 32-bit IEEE floating point format.