54 unsigned char *cpack,
g2int *lcpack,
int verbose)
57 static float alog2 =
ALOG2;
58 g2int j, nbits, imin, imax, maxdif;
60 float bscale, dscale, rmax, rmin, temp;
67 LOG((2,
"pngpack_int fld_is_double %d width %ld height %ld idrstmpl[1] %d",
68 fld_is_double, width, height, idrstmpl[1]));
70 ndpts = width * height;
73 LOG((3,
"ndpts %d bscale %g dscale %g", ndpts, bscale, dscale));
84 for (j = 1; j < ndpts; j++)
91 maxdif = (
g2int)rint((rmaxd - rmind) * dscale * bscale);
95 for (j = 1; j < ndpts; j++)
102 maxdif = (
g2int)rint((rmax - rmin) * dscale * bscale);
104 LOG((3,
"rmax %g rmaxd %g rmin %g rmind %g", rmax, rmaxd, rmin, rmind));
109 if (((fld_is_double && rmind != rmaxd) || (!fld_is_double && rmin != rmax)) && maxdif != 0)
111 ifld = malloc(ndpts *
sizeof(
g2int));
115 if (idrstmpl[1] == 0)
119 imin = (
g2int)rint((fld_is_double ? rmind : rmin) * dscale);
120 imax = (
g2int)rint((fld_is_double ? rmaxd : rmax) * dscale);
121 maxdif = imax - imin;
122 temp = log((
double)(maxdif + 1)) / alog2;
123 nbits = (
g2int)ceil(temp);
128 for(j = 0; j < ndpts; j++)
129 ifld[j] = (
g2int)rint(dfld[j] * dscale) - imin;
134 for(j = 0; j < ndpts; j++)
135 ifld[j] = (
g2int)rint(ffld[j] * dscale) - imin;
144 rmind = rmind * dscale;
145 rmaxd = rmaxd * dscale;
146 maxdif = (
g2int)rint((rmaxd - rmind) * bscale);
150 rmin = rmin * dscale;
151 rmax = rmax * dscale;
152 maxdif = (
g2int)rint((rmax - rmin) * bscale);
154 temp = log((
double)(maxdif + 1)) / alog2;
155 nbits = (
g2int)ceil(temp);
159 for (j = 0; j < ndpts; j++)
160 ifld[j] = (
g2int)rint(((dfld[j] * dscale) - rmind) * bscale);
164 for (j = 0; j < ndpts; j++)
165 ifld[j] = (
g2int)rint(((ffld[j] * dscale) - rmin) * bscale);
173 else if (nbits <= 16)
175 else if (nbits <= 24)
180 nbytes = (nbits / 8) * ndpts;
181 ctemp = calloc(nbytes, 1);
182 sbits(ctemp, ifld, 0, nbits, 0, ndpts);
185 if ((*lcpack = (
g2int)
enc_png(ctemp, width, height, nbits, cpack)) <= 0)
188 printf(
"pngpack: ERROR Packing PNG = %d\n", (
int)*lcpack);
202 mkieee(&rmin, idrstmpl, 1);
243 unsigned char *cpack,
g2int *lcpack)
246 pngpack_int(fld, 0, width, height, idrstmpl, cpack, lcpack, 1);
283 unsigned char *cpack,
int *lcpack)
285 g2int width8 = width, height8 = height, lcpack8 = *lcpack;
290 idrstmpl8[i] = idrstmpl[i];
292 ret =
pngpack_int(fld, 0, width8, height8, idrstmpl8, cpack, &lcpack8, 0);
297 idrstmpl[i] = (
int)idrstmpl8[i];
298 *lcpack = (
g2int)lcpack8;
337 unsigned char *cpack,
int *lcpack)
339 g2int width8 = width, height8 = height, lcpack8 = *lcpack;
344 idrstmpl8[i] = idrstmpl[i];
346 ret =
pngpack_int(fld, 1, width8, height8, idrstmpl8, cpack, &lcpack8, 0);
351 idrstmpl[i] = (
int)idrstmpl8[i];
352 *lcpack = (
g2int)lcpack8;
int enc_png(unsigned char *data, g2int width, g2int height, g2int nbits, unsigned char *pngbuf)
Encode PNG.
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_EPNG
Error encoding/decoding PNG data.
#define G2C_PNG_DRS_TEMPLATE_LEN
Length of the idrstmpl array for PNG packing.
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.
void pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a float data field into PNG image format.
int g2c_pngpackd(double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack)
This subroutine packs up a double data field into PNG image format.
int g2c_pngpackf(float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack)
This subroutine packs up a float data field into PNG image format.
static int pngpack_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 float or double data into PNG image format.