34 subroutine jpcpack(fld,width,height,idrstmpl,cpack,lcpack)
37 integer,
intent(in) :: width,height
38 real,
intent(in) :: fld(width*height)
39 character(len=1),
intent(out) :: cpack(*)
40 integer,
intent(inout) :: idrstmpl(*)
41 integer,
intent(inout) :: lcpack
42 integer :: ndpts, nbits, maxdif, imin, imax, j, nbytes
43 real :: dscale, bscale, temp
46 function enc_jpeg2000(cin, width, height, nbits, ltype, ratio, retry, outjpc, jpclen) &
47 bind(c, name="g2c_enc_jpeg2000")
49 character(kind = c_char),
intent(in) :: cin(*)
50 integer(c_int),
value,
intent(in) :: width, height, nbits, ltype, ratio, retry
51 character(kind = c_char),
intent(inout) :: outjpc(*)
52 integer(c_size_t),
value,
intent(in) :: jpclen
53 integer(c_int) :: enc_jpeg2000
61 integer :: ifld(width * height), retry
62 integer,
parameter :: zero = 0
63 character(len = 1),
allocatable :: ctemp(:)
65 ndpts = width * height
66 bscale = 2.0**real(-idrstmpl(2))
67 dscale = 10.0**real(idrstmpl(3))
78 if (fld(j) .gt. rmax) rmax = fld(j)
79 if (fld(j) .lt. rmin) rmin = fld(j)
81 if (idrstmpl(2) .eq. 0)
then
82 maxdif = nint(rmax * dscale) - nint(rmin * dscale)
84 maxdif = nint((rmax - rmin) * dscale * bscale)
90 if (rmin .ne. rmax .AND. maxdif .ne. 0)
then
93 if (idrstmpl(2) .eq. 0)
then
96 imin = nint(rmin * dscale)
97 imax = nint(rmax * dscale)
99 temp = alog(real(maxdif + 1)) / alog(2.0)
100 nbits = ceiling(temp)
104 ifld(j) = nint(fld(j) * dscale) - imin
111 maxdif = nint((rmax - rmin) * bscale)
112 temp = alog(real(maxdif + 1)) / alog(2.0)
113 nbits = ceiling(temp)
116 ifld(j) = max(0, nint(((fld(j) * dscale) - rmin) * bscale))
123 nbytes = (nbits + 7) / 8
125 allocate(ctemp(nbytes * ndpts))
126 call g2_sbytesc(ctemp, ifld, 0, nbytes * 8, 0, ndpts)
127 lcpack =
enc_jpeg2000(ctemp, width, height, nbits, idrstmpl(6), &
128 idrstmpl(7), retry, cpack, nsize)
129 if (lcpack .le. 0)
then
130 print *,
'jpcpack: ERROR Packing JPC = ',lcpack
131 if (lcpack .eq. -3)
then
133 print *,
'jpcpack: Retrying....'
134 lcpack =
enc_jpeg2000(ctemp, width, height, nbits, idrstmpl(6), &
135 idrstmpl(7), retry, cpack, nsize)
136 if (lcpack .le. 0)
then
137 print *,
'jpcpack: Retry Failed.'
139 print *,
'jpcpack: Retry Successful.'
150 rmin4 = real(rmin, 4)
151 call mkieee(rmin4, ref, 1)
152 iref = transfer(ref, iref)
156 if (idrstmpl(6) .eq. 0) idrstmpl(7) = 255
179 character(len=1),
intent(in) :: cpack(len)
180 integer,
intent(in) :: ndpts,len
181 integer,
intent(in) :: idrstmpl(*)
182 real,
intent(out) :: fld(ndpts)
184 integer :: ifld(ndpts)
187 real :: ref,bscale,dscale
188 integer :: nbits, j, iret
192 bind(c, name="g2c_dec_jpeg2000")
194 character(kind = c_char),
intent(in) :: cin(*)
195 integer(c_size_t),
value,
intent(in) :: len
196 integer(c_int),
intent(inout) :: ifld(*)
197 integer(c_int) :: dec_jpeg2000
203 bscale = 2.0**real(idrstmpl(2))
204 dscale = 10.0**real(-idrstmpl(3))
214 fld(j)=((real(ifld(j))*bscale)+ref)*dscale
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 dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
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 ...
subroutine jpcunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field from a JPEG2000 code stream as defined in Data Representation Template 5....
subroutine jpcpack(fld, width, height, idrstmpl, cpack, lcpack)
Pack a data field into a JPEG2000 code stream as defined in Data Representation Template 5....