33 subroutine pngpack(fld, width, height, idrstmpl, cpack, lcpack)
36 integer,
intent(in) :: width, height
37 real,
intent(in) :: fld(width * height)
38 character(len = 1),
intent(out) :: cpack(*)
39 integer,
intent(inout) :: idrstmpl(*)
40 integer,
intent(out) :: lcpack
45 integer :: ifld(width * height), nbits
46 integer,
parameter :: zero = 0
47 character(len = 1),
allocatable :: ctemp(:)
48 real :: bscale, dscale, temp
49 integer :: imax, imin, j, maxdif, nbytes, ndpts
52 function enc_png(data, width, height, nbits, pngbuf)
bind(c, name="enc_png")
54 character(kind = c_char),
intent(in) :: data(*)
55 integer(c_int),
intent(in) :: width, height
56 integer(c_int),
intent(inout) :: nbits
57 character(kind = c_char),
intent(out) :: pngbuf(*)
58 integer(c_int) :: enc_png
62 ndpts = width * height
63 bscale = 2.0**real(-idrstmpl(2))
64 dscale = 10.0**real(idrstmpl(3))
75 if (fld(j) .gt. rmax) rmax = fld(j)
76 if (fld(j) .lt. rmin) rmin = fld(j)
78 maxdif = nint((rmax - rmin) * dscale * bscale)
83 if (rmin .ne. rmax .AND. maxdif .ne. 0)
then
87 if (idrstmpl(2) .eq. 0)
then
90 imin = nint(rmin * dscale)
91 imax = nint(rmax * dscale)
93 temp = alog(real(maxdif + 1)) / alog(2.0)
98 ifld(j) = nint(fld(j) * dscale) - imin
105 maxdif = nint((rmax - rmin) * bscale)
106 temp = alog(real(maxdif + 1)) / alog(2.0)
107 nbits = ceiling(temp)
110 ifld(j) = max(0, nint(((fld(j) * dscale) - rmin) * bscale))
116 if (nbits .le. 8)
then
118 elseif (nbits .le. 16)
then
120 elseif (nbits .le. 24)
then
125 nbytes = (nbits / 8) * ndpts
126 allocate(ctemp(nbytes))
127 call g2_sbytesc(ctemp, ifld, 0, nbits, 0, ndpts)
130 lcpack =
enc_png(ctemp, width, height, nbits, cpack)
131 if (lcpack .le. 0)
then
132 print *,
'pngpack: ERROR Encoding PNG = ', lcpack
142 rmin4 = real(rmin, 4)
143 call mkieee(rmin4, ref, 1)
144 iref = transfer(ref, iref)
170 character(len = 1),
intent(in) :: cpack(len)
171 integer,
intent(in) :: ndpts, len
172 integer,
intent(in) :: idrstmpl(*)
173 real,
intent(out) :: fld(ndpts)
175 integer :: ifld(ndpts)
176 character(len = 1),
allocatable :: ctemp(:)
178 real :: ref, bscale, dscale
179 integer :: width, height
180 integer :: iret, itype, j, nbits
183 function dec_png(pngbuf, width, height, cout)
bind(c, name="dec_png")
185 character(kind = c_char),
intent(in) :: pngbuf(*)
186 integer(c_int),
intent(in) :: width, height
187 character(kind = c_char),
intent(out) :: cout(*)
188 integer(c_int) :: dec_png
194 bscale = 2.0**real(idrstmpl(2))
195 dscale = 10.0**real(-idrstmpl(3))
201 if (nbits .ne. 0)
then
202 allocate(ctemp(ndpts * 4))
203 iret =
dec_png(cpack, width, height, ctemp)
204 call g2_gbytesc(ctemp, ifld, 0, nbits, 0, ndpts)
207 fld(j) = ((real(ifld(j)) * bscale) + ref) * dscale
subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n)
Extract arbitrary size big-endian integer values (up to 32 bits each) from a packed bit string.
subroutine rdieee(rieee, a, num)
Copy array of 32-bit IEEE floating point values to local floating point representation.
subroutine mkieee(a, rieee, num)
Copy an array of real to an array of 32-bit IEEE floating points.
subroutine g2_sbytesc(out, in, iskip, nbits, nskip, n)
Put arbitrary size (up to 32 bits each) integer values into a packed bit string in big-endian order.
int enc_png(char *data, g2int *width, g2int *height, g2int *nbits, char *pngbuf)
create png_structs to write png stream into memory.
int dec_png(unsigned char *pngbuf, g2int *width, g2int *height, char *cout)
Decode some PNG compressed data.
subroutine pngunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field with PNG, defined in [Data Representation Template 5.40](https://www....
subroutine pngpack(fld, width, height, idrstmpl, cpack, lcpack)
Pack a data field into PNG image format, defined in [Data Representation Template 5....