Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/libfreerdp/codec/rfx_decode.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * RemoteFX Codec Library - Decode
4
 *
5
 * Copyright 2011 Vic Lee
6
 * Copyright 2011 Norbert Federa <norbert.federa@thincast.com>
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
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
0
{
43
0
  INT16* dwt_buffer = NULL;
44
0
  dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */
45
0
  PROFILER_ENTER(context->priv->prof_rfx_decode_component)
46
0
  PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode)
47
0
  WINPR_ASSERT(size <= UINT32_MAX);
48
0
  context->rlgr_decode(context->mode, data, (UINT32)size, buffer, 4096);
49
0
  PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode)
50
0
  PROFILER_ENTER(context->priv->prof_rfx_differential_decode)
51
0
  rfx_differential_decode(buffer + 4032, 64);
52
0
  PROFILER_EXIT(context->priv->prof_rfx_differential_decode)
53
0
  PROFILER_ENTER(context->priv->prof_rfx_quantization_decode)
54
0
  context->quantization_decode(buffer, quantization_values);
55
0
  PROFILER_EXIT(context->priv->prof_rfx_quantization_decode)
56
0
  PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode)
57
0
  context->dwt_2d_decode(buffer, dwt_buffer);
58
0
  PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode)
59
0
  PROFILER_EXIT(context->priv->prof_rfx_decode_component)
60
0
  BufferPool_Return(context->priv->BufferPool, dwt_buffer);
61
0
}
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
0
{
69
0
  union
70
0
  {
71
0
    const INT16** cpv;
72
0
    INT16** pv;
73
0
  } cnv;
74
0
  BOOL rc = TRUE;
75
0
  BYTE* pBuffer = NULL;
76
0
  INT16* pSrcDst[3];
77
0
  UINT32* y_quants = NULL;
78
0
  UINT32* cb_quants = NULL;
79
0
  UINT32* cr_quants = NULL;
80
0
  static const prim_size_t roi_64x64 = { 64, 64 };
81
0
  const primitives_t* prims = primitives_get();
82
0
  PROFILER_ENTER(context->priv->prof_rfx_decode_rgb)
83
0
  y_quants = context->quants + (10ULL * tile->quantIdxY);
84
0
  cb_quants = context->quants + (10ULL * tile->quantIdxCb);
85
0
  cr_quants = context->quants + (10ULL * tile->quantIdxCr);
86
0
  pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1);
87
0
  pSrcDst[0] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 0ULL) + 16ULL]));        /* y_r_buffer */
88
0
  pSrcDst[1] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 1ULL) + 16ULL]));        /* cb_g_buffer */
89
0
  pSrcDst[2] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 2ULL) + 16ULL]));        /* cr_b_buffer */
90
0
  rfx_decode_component(context, y_quants, tile->YData, tile->YLen, pSrcDst[0]); /* YData */
91
0
  rfx_decode_component(context, cb_quants, tile->CbData, tile->CbLen, pSrcDst[1]); /* CbData */
92
0
  rfx_decode_component(context, cr_quants, tile->CrData, tile->CrLen, pSrcDst[2]); /* CrData */
93
0
  PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb)
94
95
0
  cnv.pv = pSrcDst;
96
0
  if (prims->yCbCrToRGB_16s8u_P3AC4R(cnv.cpv, 64 * sizeof(INT16), rgb_buffer, stride,
97
0
                                     context->pixel_format, &roi_64x64) != PRIMITIVES_SUCCESS)
98
0
    rc = FALSE;
99
100
0
  PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb)
101
0
  PROFILER_EXIT(context->priv->prof_rfx_decode_rgb)
102
0
  BufferPool_Return(context->priv->BufferPool, pBuffer);
103
0
  return rc;
104
0
}