20 #include <freerdp/config.h>
28 static INLINE
void rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT idwt,
31 const size_t total_width = subband_width << 1;
39 const INT16* ll = buffer + subband_width * subband_width * 3;
40 const INT16* hl = buffer;
43 const INT16* lh = buffer + subband_width * subband_width;
44 const INT16* hh = buffer + subband_width * subband_width * 2;
45 INT16* h_dst = idwt + subband_width * subband_width * 2;
47 for (
size_t y = 0; y < subband_width; y++)
50 l_dst[0] = ll[0] - ((hl[0] + hl[0] + 1) >> 1);
51 h_dst[0] = lh[0] - ((hh[0] + hh[0] + 1) >> 1);
52 for (
size_t n = 1; n < subband_width; n++)
54 const size_t x = n << 1;
55 l_dst[x] = ll[n] - ((hl[n - 1] + hl[n] + 1) >> 1);
56 h_dst[x] = lh[n] - ((hh[n - 1] + hh[n] + 1) >> 1);
61 for (; n < subband_width - 1; n++)
63 const size_t x = n << 1;
64 l_dst[x + 1] = (hl[n] << 1) + ((l_dst[x] + l_dst[x + 2]) >> 1);
65 h_dst[x + 1] = (hh[n] << 1) + ((h_dst[x] + h_dst[x + 2]) >> 1);
68 const size_t x = n << 1;
69 l_dst[x + 1] = (hl[n] << 1) + (l_dst[x]);
70 h_dst[x + 1] = (hh[n] << 1) + (h_dst[x]);
82 for (
size_t x = 0; x < total_width; x++)
84 const INT16* l = idwt + x;
85 const INT16* h = idwt + x + subband_width * total_width;
86 INT16* dst = buffer + x;
88 *dst = *l - ((*h * 2 + 1) >> 1);
90 for (
size_t n = 1; n < subband_width; n++)
96 dst[2 * total_width] = *l - ((*(h - total_width) + *h + 1) >> 1);
99 dst[total_width] = (*(h - total_width) << 1) + ((*dst + dst[2 * total_width]) >> 1);
101 dst += 2 * total_width;
104 dst[total_width] = (*h << 1) + ((*dst * 2) >> 1);
108 void rfx_dwt_2d_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
110 WINPR_ASSERT(buffer);
111 WINPR_ASSERT(dwt_buffer);
113 rfx_dwt_2d_decode_block(&buffer[3840], dwt_buffer, 8);
114 rfx_dwt_2d_decode_block(&buffer[3072], dwt_buffer, 16);
115 rfx_dwt_2d_decode_block(&buffer[0], dwt_buffer, 32);
118 static void rfx_dwt_2d_encode_block(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt,
119 UINT32 subband_width)
131 const UINT32 total_width = subband_width << 1;
134 for (UINT32 x = 0; x < total_width; x++)
136 for (UINT32 n = 0; n < subband_width; n++)
139 l = dwt + 1ULL * n * total_width + x;
140 h = l + 1ULL * subband_width * total_width;
141 src = buffer + 1ULL * y * total_width + x;
144 *h = (src[total_width] -
145 ((src[0] + src[n < subband_width - 1 ? 2 * total_width : 0]) >> 1)) >>
149 *l = src[0] + (n == 0 ? *h : (*(h - total_width) + *h) >> 1);
158 ll = buffer + 3ULL * subband_width * subband_width;
162 lh = buffer + 1ULL * subband_width * subband_width;
163 hh = buffer + 2ULL * subband_width * subband_width;
164 h_src = dwt + 2ULL * subband_width * subband_width;
166 for (
size_t y = 0; y < subband_width; y++)
169 for (UINT32 n = 0; n < subband_width; n++)
175 (l_src[x + 1] - ((l_src[x] + l_src[n < subband_width - 1 ? x + 2 : x]) >> 1)) >> 1;
177 ll[n] = l_src[x] + (n == 0 ? hl[n] : (hl[n - 1] + hl[n]) >> 1);
181 for (UINT32 n = 0; n < subband_width; n++)
187 (h_src[x + 1] - ((h_src[x] + h_src[n < subband_width - 1 ? x + 2 : x]) >> 1)) >> 1;
189 lh[n] = h_src[x] + (n == 0 ? hh[n] : (hh[n - 1] + hh[n]) >> 1);
194 l_src += total_width;
198 h_src += total_width;
202 void rfx_dwt_2d_encode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
204 WINPR_ASSERT(buffer);
205 WINPR_ASSERT(dwt_buffer);
207 rfx_dwt_2d_encode_block(&buffer[0], dwt_buffer, 32);
208 rfx_dwt_2d_encode_block(&buffer[3072], dwt_buffer, 16);
209 rfx_dwt_2d_encode_block(&buffer[3840], dwt_buffer, 8);