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 rfx_differential_decode(buffer + 4032, 64);
64 PROFILER_EXIT(context->priv->prof_rfx_differential_decode)
65 PROFILER_ENTER(context->priv->prof_rfx_quantization_decode)
66 if (!context->quantization_decode(buffer, quantization_values, nrQuantValues))
67 goto fail;
68 PROFILER_EXIT(context->priv->prof_rfx_quantization_decode)
69 PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode)
70 context->dwt_2d_decode(buffer, dwt_buffer);
71 PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode)
72 PROFILER_EXIT(context->priv->prof_rfx_decode_component)
73
74 res = TRUE;
75fail:
76 BufferPool_Return(context->priv->BufferPool, dwt_buffer);
77 return res;
78}
79
80/* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */
81
82/* stride is bytes between rows in the output buffer. */
83BOOL rfx_decode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, const RFX_TILE* WINPR_RESTRICT tile,
84 BYTE* WINPR_RESTRICT rgb_buffer, UINT32 stride)
85{
86 union
87 {
88 const INT16** cpv;
89 INT16** pv;
90 } cnv;
91 BOOL rc = FALSE;
92 BYTE* pBuffer = nullptr;
93 INT16* pSrcDst[3];
94 UINT32* y_quants = nullptr;
95 UINT32* cb_quants = nullptr;
96 UINT32* cr_quants = nullptr;
97 static const prim_size_t roi_64x64 = { 64, 64 };
98 const primitives_t* prims = primitives_get();
99 PROFILER_ENTER(context->priv->prof_rfx_decode_rgb)
100 y_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxY);
101 cb_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxCb);
102 cr_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxCr);
103 pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1);
104 pSrcDst[0] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 0ULL) + 16ULL])); /* y_r_buffer */
105 pSrcDst[1] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 1ULL) + 16ULL])); /* cb_g_buffer */
106 pSrcDst[2] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 2ULL) + 16ULL])); /* cr_b_buffer */
107 if (!rfx_decode_component(context, y_quants, NR_QUANT_VALUES, tile->YData, tile->YLen,
108 pSrcDst[0])) /* YData */
109 goto fail;
110 if (!rfx_decode_component(context, cb_quants, NR_QUANT_VALUES, tile->CbData, tile->CbLen,
111 pSrcDst[1])) /* CbData */
112 goto fail;
113 if (!rfx_decode_component(context, cr_quants, NR_QUANT_VALUES, tile->CrData, tile->CrLen,
114 pSrcDst[2])) /* CrData */
115 goto fail;
116 PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb)
117
118 cnv.pv = pSrcDst;
119 if (prims->yCbCrToRGB_16s8u_P3AC4R(cnv.cpv, 64 * sizeof(INT16), rgb_buffer, stride,
120 context->pixel_format, &roi_64x64) != PRIMITIVES_SUCCESS)
121 goto fail;
122
123 PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb)
124 PROFILER_EXIT(context->priv->prof_rfx_decode_rgb)
125
126 rc = TRUE;
127fail:
128 BufferPool_Return(context->priv->BufferPool, pBuffer);
129 return rc;
130}
Definition rfx.h:52