53 unsigned char *cpack,
g2int *lcpack,
int verbose)
59 g2int maxdif, nbits, ndpts, nbytes;
60 g2int ccsds_flags, ccsds_block_size, ccsds_rsi;
61 float bscale, dscale, rmax, rmin, temp;
63 static float alog2 =
ALOG2;
69 LOG((2,
"aecpack_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 %ld", idrstmpl[0], idrstmpl[1], idrstmpl[2],
72 idrstmpl[3], idrstmpl[4], idrstmpl[5], idrstmpl[6], idrstmpl[7]));
80 ndpts = width * height;
83 LOG((3,
"ndpts %ld bscale %g dscale %g", ndpts, bscale, dscale));
92 for (j = 1; j < ndpts; j++)
100 maxdif = (
g2int)(rint(rmaxd * dscale) - rint(rmind * dscale));
102 maxdif = (
g2int)rint((rmaxd - rmind) * dscale * bscale);
106 for (j = 1; j < ndpts; j++)
113 if (idrstmpl[1] == 0)
114 maxdif = (
g2int)(rint(rmax * dscale) - rint(rmin * dscale));
116 maxdif = (
g2int)rint((rmax - rmin) * dscale * bscale);
118 LOG((3,
"rmax %g rmaxd %g rmin %g rmind %g", rmax, rmaxd, rmin, rmind));
123 if (((fld_is_double && rmind != rmaxd) || (!fld_is_double && rmin != rmax)) && maxdif != 0)
126 ifld = malloc(ndpts *
sizeof(
g2int));
130 if (idrstmpl[1] == 0)
134 imin = (
g2int)rint((fld_is_double ? rmind : rmin) * dscale);
135 imax = (
g2int)rint((fld_is_double ? rmaxd : rmax) * dscale);
136 maxdif = imax - imin;
137 temp = log((
double)(maxdif + 1)) / alog2;
138 nbits = (
g2int)ceil(temp);
143 for (j = 0; j < ndpts; j++)
144 ifld[j] = (
g2int)rint(dfld[j] * dscale) - imin;
149 for (j = 0; j < ndpts; j++)
150 ifld[j] = (
g2int)rint(ffld[j] * dscale) - imin;
159 rmind = rmind * dscale;
160 rmaxd = rmaxd * dscale;
161 maxdif = (
g2int)rint((rmaxd - rmind) * bscale);
165 rmin = rmin * dscale;
166 rmax = rmax * dscale;
167 maxdif = (
g2int)rint((rmax - rmin) * bscale);
169 temp = log((
double)(maxdif + 1)) / alog2;
170 nbits = (
g2int)ceil(temp);
174 for (j = 0; j < ndpts; j++)
175 ifld[j] = (
g2int)rint(((dfld[j] * dscale) - rmind) * bscale);
179 for (j = 0; j < ndpts; j++)
180 ifld[j] = (
g2int)rint(((ffld[j] * dscale) - rmin) * bscale);
185 if (idrstmpl[3] <= 0)
187 nbits = pow(2, ceil(log(nbits) / log(2)));
192 nbits = pow(2, ceil(log(nbits) / log(2)));
194 nbits = nbits < 8 ? 8 : nbits;
196 if (idrstmpl[5] == 0)
198 ccsds_flags = AEC_DATA_SIGNED | AEC_DATA_PREPROCESS | AEC_DATA_MSB;
202 ccsds_flags = idrstmpl[5];
204 if (idrstmpl[6] == 0)
206 ccsds_block_size = 16;
210 ccsds_block_size = idrstmpl[6];
212 if (idrstmpl[7] == 0)
218 ccsds_rsi = idrstmpl[7];
223 nbytes = (nbits + 7) / 8;
224 ctemp = calloc(ndpts, nbytes);
225 ctemplen = ndpts * nbytes;
226 sbits(ctemp, ifld, 0, nbytes * 8, 0, ndpts);
228 *lcpack =
enc_aec(ctemp, ctemplen, nbits, ccsds_flags, ccsds_block_size, ccsds_rsi, cpack, lcpack);
232 printf(
"aecpack: ERROR Packing AEC = %d\n", ret);
249 mkieee(&rmin, idrstmpl, 1);
251 idrstmpl[5] = ccsds_flags;
252 idrstmpl[6] = ccsds_block_size;
253 idrstmpl[7] = ccsds_rsi;
int g2c_aecpackf(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 AEC code stream.
static int aecpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack, int verbose)
Pack a float or double array into a AEC/CCSDS code stream.
int g2c_aecpackd(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 AEC code stream.
void aecpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This function packs up a float array into a AEC code stream.
int enc_aec(unsigned char *data, g2int ctemplen, g2int nbits, g2int flags, g2int block_size, g2int rsi, unsigned char *aecbuf, g2int *aecbuflen)
Encode data into an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book.
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...