20 #include <winpr/assert.h>
21 #include <winpr/cast.h>
23 #include <freerdp/config.h>
31 static INLINE
void rfx_dwt_2d_decode_block(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT idwt,
34 const size_t total_width = subband_width << 1;
42 const INT16* ll = buffer + subband_width * subband_width * 3;
43 const INT16* hl = buffer;
46 const INT16* lh = buffer + subband_width * subband_width;
47 const INT16* hh = buffer + subband_width * subband_width * 2;
48 INT16* h_dst = idwt + subband_width * subband_width * 2;
50 for (
size_t y = 0; y < subband_width; y++)
53 l_dst[0] = WINPR_ASSERTING_INT_CAST(int16_t, ll[0] - ((hl[0] + hl[0] + 1) >> 1));
54 h_dst[0] = WINPR_ASSERTING_INT_CAST(int16_t, lh[0] - ((hh[0] + hh[0] + 1) >> 1));
55 for (
size_t n = 1; n < subband_width; n++)
57 const size_t x = n << 1;
58 l_dst[x] = WINPR_ASSERTING_INT_CAST(int16_t, ll[n] - ((hl[n - 1] + hl[n] + 1) >> 1));
59 h_dst[x] = WINPR_ASSERTING_INT_CAST(int16_t, lh[n] - ((hh[n - 1] + hh[n] + 1) >> 1));
64 for (; n < subband_width - 1; n++)
66 const size_t x = n << 1;
68 const int ld = (hl[n] << 1) + ((l_dst[x] + l_dst[x + 2]) >> 1);
69 const int hd = (hh[n] << 1) + ((h_dst[x] + h_dst[x + 2]) >> 1);
71 l_dst[x + 1] = WINPR_ASSERTING_INT_CAST(INT16, ld);
72 h_dst[x + 1] = WINPR_ASSERTING_INT_CAST(INT16, hd);
75 const size_t x = n << 1;
77 const int ld = (hl[n] << 1) + (l_dst[x]);
78 const int hd = (hh[n] << 1) + (h_dst[x]);
79 l_dst[x + 1] = WINPR_ASSERTING_INT_CAST(INT16, ld);
80 h_dst[x + 1] = WINPR_ASSERTING_INT_CAST(INT16, hd);
92 for (
size_t x = 0; x < total_width; x++)
94 const INT16* l = idwt + x;
95 const INT16* h = idwt + x + subband_width * total_width;
96 INT16* dst = buffer + x;
98 const int dd = *l - ((*h * 2 + 1) >> 1);
99 *dst = WINPR_ASSERTING_INT_CAST(INT16, dd);
101 for (
size_t n = 1; n < subband_width; n++)
107 const int d2 = *l - ((*(h - total_width) + *h + 1) >> 1);
108 dst[2 * total_width] = WINPR_ASSERTING_INT_CAST(INT16, d2);
111 const int d = (*(h - total_width) << 1) + ((*dst + dst[2 * total_width]) >> 1);
112 dst[total_width] = WINPR_ASSERTING_INT_CAST(INT16, d);
114 dst += 2 * total_width;
117 const int d = (*h << 1) + ((*dst * 2) >> 1);
118 dst[total_width] = WINPR_ASSERTING_INT_CAST(INT16, d);
122 void rfx_dwt_2d_decode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
124 WINPR_ASSERT(buffer);
125 WINPR_ASSERT(dwt_buffer);
127 rfx_dwt_2d_decode_block(&buffer[3840], dwt_buffer, 8);
128 rfx_dwt_2d_decode_block(&buffer[3072], dwt_buffer, 16);
129 rfx_dwt_2d_decode_block(&buffer[0], dwt_buffer, 32);
132 static void rfx_dwt_2d_encode_block(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt,
133 UINT32 subband_width)
145 const UINT32 total_width = subband_width << 1;
148 for (UINT32 x = 0; x < total_width; x++)
150 for (UINT32 n = 0; n < subband_width; n++)
153 l = dwt + 1ULL * n * total_width + x;
154 h = l + 1ULL * subband_width * total_width;
155 src = buffer + 1ULL * y * total_width + x;
158 *h = WINPR_ASSERTING_INT_CAST(
159 int16_t, (src[total_width] -
160 ((src[0] + src[n < subband_width - 1 ? 2 * total_width : 0]) >> 1)) >>
164 *l = WINPR_ASSERTING_INT_CAST(int16_t,
165 src[0] + (n == 0 ? *h : (*(h - total_width) + *h) >> 1));
174 ll = buffer + 3ULL * subband_width * subband_width;
178 lh = buffer + 1ULL * subband_width * subband_width;
179 hh = buffer + 2ULL * subband_width * subband_width;
180 h_src = dwt + 2ULL * subband_width * subband_width;
182 for (
size_t y = 0; y < subband_width; y++)
185 for (UINT32 n = 0; n < subband_width; n++)
190 hl[n] = WINPR_ASSERTING_INT_CAST(
192 (l_src[x + 1] - ((l_src[x] + l_src[n < subband_width - 1 ? x + 2 : x]) >> 1)) >> 1);
194 ll[n] = WINPR_ASSERTING_INT_CAST(
195 int16_t, l_src[x] + (n == 0 ? hl[n] : (hl[n - 1] + hl[n]) >> 1));
199 for (UINT32 n = 0; n < subband_width; n++)
204 hh[n] = WINPR_ASSERTING_INT_CAST(
206 (h_src[x + 1] - ((h_src[x] + h_src[n < subband_width - 1 ? x + 2 : x]) >> 1)) >> 1);
208 lh[n] = WINPR_ASSERTING_INT_CAST(
209 int16_t, h_src[x] + (n == 0 ? hh[n] : (hh[n - 1] + hh[n]) >> 1));
214 l_src += total_width;
218 h_src += total_width;
222 void rfx_dwt_2d_encode(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
224 WINPR_ASSERT(buffer);
225 WINPR_ASSERT(dwt_buffer);
227 rfx_dwt_2d_encode_block(&buffer[0], dwt_buffer, 32);
228 rfx_dwt_2d_encode_block(&buffer[3072], dwt_buffer, 16);
229 rfx_dwt_2d_encode_block(&buffer[3840], dwt_buffer, 8);