FreeRDP
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 
38 static INLINE void rfx_decode_component(RFX_CONTEXT* WINPR_RESTRICT context,
39  const UINT32* WINPR_RESTRICT quantization_values,
40  const BYTE* WINPR_RESTRICT data, size_t size,
41  INT16* WINPR_RESTRICT buffer)
42 {
43  INT16* dwt_buffer = NULL;
44  dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */
45  PROFILER_ENTER(context->priv->prof_rfx_decode_component)
46  PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode)
47  WINPR_ASSERT(size <= UINT32_MAX);
48  context->rlgr_decode(context->mode, data, (UINT32)size, buffer, 4096);
49  PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode)
50  PROFILER_ENTER(context->priv->prof_rfx_differential_decode)
51  rfx_differential_decode(buffer + 4032, 64);
52  PROFILER_EXIT(context->priv->prof_rfx_differential_decode)
53  PROFILER_ENTER(context->priv->prof_rfx_quantization_decode)
54  context->quantization_decode(buffer, quantization_values);
55  PROFILER_EXIT(context->priv->prof_rfx_quantization_decode)
56  PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode)
57  context->dwt_2d_decode(buffer, dwt_buffer);
58  PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode)
59  PROFILER_EXIT(context->priv->prof_rfx_decode_component)
60  BufferPool_Return(context->priv->BufferPool, dwt_buffer);
61 }
62 
63 /* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */
64 
65 /* stride is bytes between rows in the output buffer. */
66 BOOL rfx_decode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, const RFX_TILE* WINPR_RESTRICT tile,
67  BYTE* WINPR_RESTRICT rgb_buffer, UINT32 stride)
68 {
69  union
70  {
71  const INT16** cpv;
72  INT16** pv;
73  } cnv;
74  BOOL rc = TRUE;
75  BYTE* pBuffer = NULL;
76  INT16* pSrcDst[3];
77  UINT32* y_quants = NULL;
78  UINT32* cb_quants = NULL;
79  UINT32* cr_quants = NULL;
80  static const prim_size_t roi_64x64 = { 64, 64 };
81  const primitives_t* prims = primitives_get();
82  PROFILER_ENTER(context->priv->prof_rfx_decode_rgb)
83  y_quants = context->quants + (10ULL * tile->quantIdxY);
84  cb_quants = context->quants + (10ULL * tile->quantIdxCb);
85  cr_quants = context->quants + (10ULL * tile->quantIdxCr);
86  pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1);
87  pSrcDst[0] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 0ULL) + 16ULL])); /* y_r_buffer */
88  pSrcDst[1] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 1ULL) + 16ULL])); /* cb_g_buffer */
89  pSrcDst[2] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 2ULL) + 16ULL])); /* cr_b_buffer */
90  rfx_decode_component(context, y_quants, tile->YData, tile->YLen, pSrcDst[0]); /* YData */
91  rfx_decode_component(context, cb_quants, tile->CbData, tile->CbLen, pSrcDst[1]); /* CbData */
92  rfx_decode_component(context, cr_quants, tile->CrData, tile->CrLen, pSrcDst[2]); /* CrData */
93  PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb)
94 
95  cnv.pv = pSrcDst;
96  if (prims->yCbCrToRGB_16s8u_P3AC4R(cnv.cpv, 64 * sizeof(INT16), rgb_buffer, stride,
97  context->pixel_format, &roi_64x64) != PRIMITIVES_SUCCESS)
98  rc = FALSE;
99 
100  PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb)
101  PROFILER_EXIT(context->priv->prof_rfx_decode_rgb)
102  BufferPool_Return(context->priv->BufferPool, pBuffer);
103  return rc;
104 }
Definition: rfx.h:52