/src/FreeRDP/libfreerdp/codec/rfx_decode.c
Line | Count | Source |
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 | | WINPR_ATTR_NODISCARD |
39 | | static 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 | 0 | { |
44 | 0 | BOOL res = FALSE; |
45 | 0 | INT16* dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */ |
46 | 0 | WINPR_ASSERT(dwt_buffer); |
47 | |
|
48 | 0 | PROFILER_ENTER(context->priv->prof_rfx_decode_component) |
49 | 0 | PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode) |
50 | 0 | WINPR_ASSERT(size <= UINT32_MAX); |
51 | |
|
52 | 0 | { |
53 | 0 | const int rc = context->rlgr_decode(context->mode, data, (UINT32)size, buffer, 4096); |
54 | 0 | if (rc < 0) |
55 | 0 | { |
56 | 0 | WLog_Print(context->priv->log, WLOG_ERROR, "context->rlgr_decode failed: %d", rc); |
57 | 0 | goto fail; |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | 0 | PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode) |
62 | 0 | PROFILER_ENTER(context->priv->prof_rfx_differential_decode) |
63 | 0 | rfx_differential_decode(buffer + 4032, 64); |
64 | 0 | PROFILER_EXIT(context->priv->prof_rfx_differential_decode) |
65 | 0 | PROFILER_ENTER(context->priv->prof_rfx_quantization_decode) |
66 | 0 | if (!context->quantization_decode(buffer, quantization_values, nrQuantValues)) |
67 | 0 | goto fail; |
68 | 0 | PROFILER_EXIT(context->priv->prof_rfx_quantization_decode) |
69 | 0 | PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode) |
70 | 0 | context->dwt_2d_decode(buffer, dwt_buffer); |
71 | 0 | PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode) |
72 | 0 | PROFILER_EXIT(context->priv->prof_rfx_decode_component) |
73 | |
|
74 | 0 | res = TRUE; |
75 | 0 | fail: |
76 | 0 | BufferPool_Return(context->priv->BufferPool, dwt_buffer); |
77 | 0 | return res; |
78 | 0 | } |
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. */ |
83 | | BOOL rfx_decode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, const RFX_TILE* WINPR_RESTRICT tile, |
84 | | BYTE* WINPR_RESTRICT rgb_buffer, UINT32 stride) |
85 | 0 | { |
86 | 0 | union |
87 | 0 | { |
88 | 0 | const INT16** cpv; |
89 | 0 | INT16** pv; |
90 | 0 | } cnv; |
91 | 0 | BOOL rc = FALSE; |
92 | 0 | BYTE* pBuffer = nullptr; |
93 | 0 | INT16* pSrcDst[3]; |
94 | 0 | UINT32* y_quants = nullptr; |
95 | 0 | UINT32* cb_quants = nullptr; |
96 | 0 | UINT32* cr_quants = nullptr; |
97 | 0 | static const prim_size_t roi_64x64 = { 64, 64 }; |
98 | 0 | const primitives_t* prims = primitives_get(); |
99 | 0 | PROFILER_ENTER(context->priv->prof_rfx_decode_rgb) |
100 | 0 | y_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxY); |
101 | 0 | cb_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxCb); |
102 | 0 | cr_quants = context->quants + (NR_QUANT_VALUES * tile->quantIdxCr); |
103 | 0 | pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1); |
104 | 0 | pSrcDst[0] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 0ULL) + 16ULL])); /* y_r_buffer */ |
105 | 0 | pSrcDst[1] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 1ULL) + 16ULL])); /* cb_g_buffer */ |
106 | 0 | pSrcDst[2] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 2ULL) + 16ULL])); /* cr_b_buffer */ |
107 | 0 | if (!rfx_decode_component(context, y_quants, NR_QUANT_VALUES, tile->YData, tile->YLen, |
108 | 0 | pSrcDst[0])) /* YData */ |
109 | 0 | goto fail; |
110 | 0 | if (!rfx_decode_component(context, cb_quants, NR_QUANT_VALUES, tile->CbData, tile->CbLen, |
111 | 0 | pSrcDst[1])) /* CbData */ |
112 | 0 | goto fail; |
113 | 0 | if (!rfx_decode_component(context, cr_quants, NR_QUANT_VALUES, tile->CrData, tile->CrLen, |
114 | 0 | pSrcDst[2])) /* CrData */ |
115 | 0 | goto fail; |
116 | 0 | PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb) |
117 | |
|
118 | 0 | cnv.pv = pSrcDst; |
119 | 0 | if (prims->yCbCrToRGB_16s8u_P3AC4R(cnv.cpv, 64 * sizeof(INT16), rgb_buffer, stride, |
120 | 0 | context->pixel_format, &roi_64x64) != PRIMITIVES_SUCCESS) |
121 | 0 | goto fail; |
122 | | |
123 | 0 | PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb) |
124 | 0 | PROFILER_EXIT(context->priv->prof_rfx_decode_rgb) |
125 | |
|
126 | 0 | rc = TRUE; |
127 | 0 | fail: |
128 | 0 | BufferPool_Return(context->priv->BufferPool, pBuffer); |
129 | 0 | return rc; |
130 | 0 | } |