20 #include <winpr/assert.h>
21 #include <winpr/cast.h>
23 #include <freerdp/config.h>
25 #include <freerdp/primitives.h>
27 #include "rfx_quantization.h"
47 static INLINE
void rfx_quantization_decode_block(
const primitives_t* WINPR_RESTRICT prims,
48 INT16* WINPR_RESTRICT buffer, UINT32 buffer_size,
54 prims->lShiftC_16s_inplace(buffer, factor, buffer_size);
57 void rfx_quantization_decode(INT16* WINPR_RESTRICT buffer,
const UINT32* WINPR_RESTRICT quantVals)
61 WINPR_ASSERT(quantVals);
63 rfx_quantization_decode_block(prims, &buffer[0], 1024, quantVals[8] - 1);
64 rfx_quantization_decode_block(prims, &buffer[1024], 1024, quantVals[7] - 1);
65 rfx_quantization_decode_block(prims, &buffer[2048], 1024, quantVals[9] - 1);
66 rfx_quantization_decode_block(prims, &buffer[3072], 256, quantVals[5] - 1);
67 rfx_quantization_decode_block(prims, &buffer[3328], 256, quantVals[4] - 1);
68 rfx_quantization_decode_block(prims, &buffer[3584], 256, quantVals[6] - 1);
69 rfx_quantization_decode_block(prims, &buffer[3840], 64, quantVals[2] - 1);
70 rfx_quantization_decode_block(prims, &buffer[3904], 64, quantVals[1] - 1);
71 rfx_quantization_decode_block(prims, &buffer[3968], 64, quantVals[3] - 1);
72 rfx_quantization_decode_block(prims, &buffer[4032], 64, quantVals[0] - 1);
75 static INLINE
void rfx_quantization_encode_block(INT16* WINPR_RESTRICT buffer,
size_t buffer_size,
81 const INT16 half = WINPR_ASSERTING_INT_CAST(INT16, 1 << (factor - 1));
83 for (INT16* dst = buffer; buffer_size > 0; dst++, buffer_size--)
85 *dst = WINPR_ASSERTING_INT_CAST(INT16, (*dst + half) >> factor);
89 void rfx_quantization_encode(INT16* WINPR_RESTRICT buffer,
90 const UINT32* WINPR_RESTRICT quantization_values)
93 WINPR_ASSERT(quantization_values);
95 rfx_quantization_encode_block(buffer, 1024, quantization_values[8] - 6);
96 rfx_quantization_encode_block(buffer + 1024, 1024, quantization_values[7] - 6);
97 rfx_quantization_encode_block(buffer + 2048, 1024, quantization_values[9] - 6);
98 rfx_quantization_encode_block(buffer + 3072, 256, quantization_values[5] - 6);
99 rfx_quantization_encode_block(buffer + 3328, 256, quantization_values[4] - 6);
100 rfx_quantization_encode_block(buffer + 3584, 256, quantization_values[6] - 6);
101 rfx_quantization_encode_block(buffer + 3840, 64, quantization_values[2] - 6);
102 rfx_quantization_encode_block(buffer + 3904, 64, quantization_values[1] - 6);
103 rfx_quantization_encode_block(buffer + 3968, 64, quantization_values[3] - 6);
104 rfx_quantization_encode_block(buffer + 4032, 64, quantization_values[0] - 6);
107 rfx_quantization_encode_block(buffer, 4096, 5);