FreeRDP
Loading...
Searching...
No Matches
rfx_decode.c
1
21#include <freerdp/config.h>
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26
27#include <winpr/stream.h>
28#include <freerdp/primitives.h>
29
30#include "rfx_types.h"
31#include "rfx_rlgr.h"
32#include "rfx_differential.h"
33#include "rfx_quantization.h"
34#include "rfx_dwt.h"
35
36#include "rfx_decode.h"
37
38WINPR_ATTR_NODISCARD
39static inline BOOL rfx_decode_component(RFX_CONTEXT* WINPR_RESTRICT context,
40 const UINT32* WINPR_RESTRICT quantization_values,
41 size_t nrQuantValues, const BYTE* WINPR_RESTRICT data,
42 size_t size, INT16* WINPR_RESTRICT buffer)
43{
44 BOOL res = FALSE;
45 INT16* dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */
46 WINPR_ASSERT(dwt_buffer);
47
48 PROFILER_ENTER(context->priv->prof_rfx_decode_component)
49 PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode)
50 WINPR_ASSERT(size <= UINT32_MAX);
51
52 {
53 const int rc = context->rlgr_decode(context->mode, data, (UINT32)size, buffer, 4096);
54 if (rc < 0)
55 {
56 WLog_Print(context->priv->log, WLOG_ERROR, "context->rlgr_decode failed: %d", rc);
57 goto fail;
58 }
59 }
60
61 PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode)
62 PROFILER_ENTER(context->priv->prof_rfx_differential_decode)
63 if (!rfx_differential_decode(buffer + 4032, 64))
64 goto fail;
65 PROFILER_EXIT(context->priv->prof_rfx_differential_decode)
66 PROFILER_ENTER(context->priv->prof_rfx_quantization_decode)
67 if (!context->quantization_decode(buffer, quantization_values, nrQuantValues))
68 goto fail;
69 PROFILER_EXIT(context->priv->prof_rfx_quantization_decode)
70 PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode)
71 context->dwt_2d_decode(buffer, dwt_buffer);
72 PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode)
73 PROFILER_EXIT(context->priv->prof_rfx_decode_component)
74
75 res = TRUE;
76fail:
77 BufferPool_Return(context->priv->BufferPool, dwt_buffer);
78 return res;
79}
80
81/* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */
82
83/* stride is bytes between rows in the output buffer. */
84BOOL rfx_decode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, const RFX_TILE* WINPR_RESTRICT tile,
85 BYTE* WINPR_RESTRICT rgb_buffer, UINT32 stride)
86{
87 union
88 {
89 const INT16** cpv;
90 INT16** pv;
91 } cnv;
92 BOOL rc = FALSE;
93 BYTE* pBuffer = nullptr;
94 INT16* pSrcDst[3];
95 UINT32* y_quants = nullptr;
96 UINT32* cb_quants = nullptr;
97 UINT32* cr_quants = nullptr;
98 static const prim_size_t roi_64x64 = { 64, 64 };
99 const primitives_t* prims = primitives_get();
100 PROFILER_ENTER(context->priv->prof_rfx_decode_rgb)
101 y_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxY);
102 cb_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxCb);
103 cr_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxCr);
104 pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1);
105 pSrcDst[0] = WINPR_PACKED_ALIGN_CAST(
106 INT16*, ((&pBuffer[((8192ULL + 32ULL) * 0ULL) + 16ULL]))); /* y_r_buffer */
107 pSrcDst[1] = WINPR_PACKED_ALIGN_CAST(
108 INT16*, ((&pBuffer[((8192ULL + 32ULL) * 1ULL) + 16ULL]))); /* cb_g_buffer */
109 pSrcDst[2] = WINPR_PACKED_ALIGN_CAST(
110 INT16*, ((&pBuffer[((8192ULL + 32ULL) * 2ULL) + 16ULL]))); /* cr_b_buffer */
111 if (!rfx_decode_component(context, y_quants, NR_QUANT_VALUES, tile->YData, tile->YLen,
112 pSrcDst[0])) /* YData */
113 goto fail;
114 if (!rfx_decode_component(context, cb_quants, NR_QUANT_VALUES, tile->CbData, tile->CbLen,
115 pSrcDst[1])) /* CbData */
116 goto fail;
117 if (!rfx_decode_component(context, cr_quants, NR_QUANT_VALUES, tile->CrData, tile->CrLen,
118 pSrcDst[2])) /* CrData */
119 goto fail;
120 PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb)
121
122 cnv.pv = pSrcDst;
123 if (prims->yCbCrToRGB_16s8u_P3AC4R(cnv.cpv, 64 * sizeof(INT16), rgb_buffer, stride,
124 context->pixel_format, &roi_64x64) != PRIMITIVES_SUCCESS)
125 goto fail;
126
127 PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb)
128 PROFILER_EXIT(context->priv->prof_rfx_decode_rgb)
129
130 rc = TRUE;
131fail:
132 BufferPool_Return(context->priv->BufferPool, pBuffer);
133 return rc;
134}
Definition rfx.h:52