31 subroutine jpcpack(fld,width,height,idrstmpl,cpack,lcpack)
34 integer,
intent(in) :: width,height
35 real,
intent(in) :: fld(width*height)
36 character(len=1),
intent(out) :: cpack(*)
37 integer,
intent(inout) :: idrstmpl(*)
38 integer,
intent(inout) :: lcpack
39 integer :: ndpts, nbits, maxdif, imin, imax, j, nbytes
40 real :: dscale, bscale, temp
43 function enc_jpeg2000(cin, width, height, nbits, ltype, ratio, retry, outjpc, jpclen) &
44 bind(c, name="g2c_enc_jpeg2000")
46 character(kind = c_char),
intent(in) :: cin(*)
47 integer(c_int),
value,
intent(in) :: width, height, nbits, ltype, ratio, retry
48 character(kind = c_char),
intent(inout) :: outjpc(*)
49 integer(c_size_t),
value,
intent(in) :: jpclen
50 integer(c_int) :: enc_jpeg2000
58 integer :: ifld(width * height), retry
59 integer,
parameter :: zero = 0
60 character(len = 1),
allocatable :: ctemp(:)
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 if (idrstmpl(2) .eq. 0)
then
79 maxdif = nint(rmax * dscale) - nint(rmin * dscale)
81 maxdif = nint((rmax - rmin) * dscale * bscale)
87 if (rmin .ne. rmax .AND. maxdif .ne. 0)
then
90 if (idrstmpl(2) .eq. 0)
then
93 imin = nint(rmin * dscale)
94 imax = nint(rmax * dscale)
96 temp = alog(real(maxdif + 1)) / alog(2.0)
101 ifld(j) = nint(fld(j) * dscale) - imin
108 maxdif = nint((rmax - rmin) * bscale)
109 temp = alog(real(maxdif + 1)) / alog(2.0)
110 nbits = ceiling(temp)
113 ifld(j) = max(0, nint(((fld(j) * dscale) - rmin) * bscale))
120 nbytes = (nbits + 7) / 8
122 allocate(ctemp(nbytes * ndpts))
123 call g2_sbytesc(ctemp, ifld, 0, nbytes * 8, 0, ndpts)
124 lcpack =
enc_jpeg2000(ctemp, width, height, nbits, idrstmpl(6), &
125 idrstmpl(7), retry, cpack, nsize)
126 if (lcpack .le. 0)
then
127 print *,
'jpcpack: ERROR Packing JPC = ',lcpack
128 if (lcpack .eq. -3)
then
130 print *,
'jpcpack: Retrying....'
131 lcpack =
enc_jpeg2000(ctemp, width, height, nbits, idrstmpl(6), &
132 idrstmpl(7), retry, cpack, nsize)
133 if (lcpack .le. 0)
then
134 print *,
'jpcpack: Retry Failed.'
136 print *,
'jpcpack: Retry Successful.'
147 rmin4 = real(rmin, 4)
148 call mkieee(rmin4, ref, 1)
149 iref = transfer(ref, iref)
153 if (idrstmpl(6) .eq. 0) idrstmpl(7) = 255
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 g2_sbytesc(out, in, iskip, nbits, nskip, n)
Put arbitrary size values into a packed bit string, taking the low order bits from each value in the ...
subroutine jpcpack(fld, width, height, idrstmpl, cpack, lcpack)
Pack a data field into a JPEG2000 code stream.
subroutine mkieee(a, rieee, num)
Copy an array of real to an array of 32-bit IEEE floating points.