2011-08-10 15:13:39 +08:00
|
|
|
/**
|
2012-10-08 23:02:04 -04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-10 15:13:39 +08:00
|
|
|
* RemoteFX Codec Library - Decode
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2011 Vic Lee
|
2013-12-04 11:37:57 +01:00
|
|
|
* Copyright 2011 Norbert Federa <norbert.federa@thincast.com>
|
2011-08-10 15:13:39 +08:00
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-16 11:20:38 +01:00
|
|
|
#include <freerdp/config.h>
|
2012-08-14 17:09:01 -04:00
|
|
|
|
2011-08-10 15:13:39 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2012-08-14 17:09:01 -04:00
|
|
|
|
2013-03-21 16:45:25 -04:00
|
|
|
#include <winpr/stream.h>
|
2013-01-18 15:32:58 -07:00
|
|
|
#include <freerdp/primitives.h>
|
2012-08-14 17:09:01 -04:00
|
|
|
|
2011-08-10 15:13:39 +08:00
|
|
|
#include "rfx_types.h"
|
|
|
|
|
#include "rfx_rlgr.h"
|
|
|
|
|
#include "rfx_differential.h"
|
|
|
|
|
#include "rfx_quantization.h"
|
|
|
|
|
#include "rfx_dwt.h"
|
|
|
|
|
|
|
|
|
|
#include "rfx_decode.h"
|
|
|
|
|
|
2025-09-22 12:19:02 +02:00
|
|
|
static inline void rfx_decode_component(RFX_CONTEXT* WINPR_RESTRICT context,
|
2024-05-29 23:48:22 +02:00
|
|
|
const UINT32* WINPR_RESTRICT quantization_values,
|
|
|
|
|
const BYTE* WINPR_RESTRICT data, size_t size,
|
|
|
|
|
INT16* WINPR_RESTRICT buffer)
|
2011-08-10 15:13:39 +08:00
|
|
|
{
|
2026-02-24 11:28:38 +01:00
|
|
|
INT16* dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */
|
|
|
|
|
WINPR_ASSERT(dwt_buffer);
|
|
|
|
|
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_decode_component)
|
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode)
|
2024-10-14 15:50:38 +02:00
|
|
|
WINPR_ASSERT(size <= UINT32_MAX);
|
2026-02-24 11:28:38 +01:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const int rc = context->rlgr_decode(context->mode, data, (UINT32)size, buffer, 4096);
|
|
|
|
|
if (rc < 0)
|
|
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "context->rlgr_decode failed: %d", rc);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode)
|
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_differential_decode)
|
2016-04-05 17:07:45 +02:00
|
|
|
rfx_differential_decode(buffer + 4032, 64);
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_differential_decode)
|
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_quantization_decode)
|
2016-04-05 17:07:45 +02:00
|
|
|
context->quantization_decode(buffer, quantization_values);
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_quantization_decode)
|
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode)
|
2016-04-05 17:07:45 +02:00
|
|
|
context->dwt_2d_decode(buffer, dwt_buffer);
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode)
|
|
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_decode_component)
|
2013-01-22 21:24:04 -05:00
|
|
|
BufferPool_Return(context->priv->BufferPool, dwt_buffer);
|
2011-08-10 15:13:39 +08:00
|
|
|
}
|
|
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
/* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */
|
|
|
|
|
|
|
|
|
|
/* stride is bytes between rows in the output buffer. */
|
2024-05-29 23:48:22 +02:00
|
|
|
BOOL rfx_decode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, const RFX_TILE* WINPR_RESTRICT tile,
|
|
|
|
|
BYTE* WINPR_RESTRICT rgb_buffer, UINT32 stride)
|
2011-08-10 15:13:39 +08:00
|
|
|
{
|
2022-04-27 21:02:18 +02:00
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
const INT16** cpv;
|
|
|
|
|
INT16** pv;
|
|
|
|
|
} cnv;
|
2017-01-24 11:37:24 +01:00
|
|
|
BOOL rc = TRUE;
|
2026-02-26 15:06:27 +01:00
|
|
|
BYTE* pBuffer = nullptr;
|
2013-01-22 18:14:50 -05:00
|
|
|
INT16* pSrcDst[3];
|
2026-02-26 15:06:27 +01:00
|
|
|
UINT32* y_quants = nullptr;
|
|
|
|
|
UINT32* cb_quants = nullptr;
|
|
|
|
|
UINT32* cr_quants = nullptr;
|
2013-01-18 15:32:58 -07:00
|
|
|
static const prim_size_t roi_64x64 = { 64, 64 };
|
2016-04-05 17:07:45 +02:00
|
|
|
const primitives_t* prims = primitives_get();
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_decode_rgb)
|
2024-08-26 16:33:59 +02:00
|
|
|
y_quants = context->quants + (10ULL * tile->quantIdxY);
|
|
|
|
|
cb_quants = context->quants + (10ULL * tile->quantIdxCb);
|
|
|
|
|
cr_quants = context->quants + (10ULL * tile->quantIdxCr);
|
2019-11-06 15:24:51 +01:00
|
|
|
pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1);
|
2024-08-29 11:11:11 +02:00
|
|
|
pSrcDst[0] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 0ULL) + 16ULL])); /* y_r_buffer */
|
|
|
|
|
pSrcDst[1] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 1ULL) + 16ULL])); /* cb_g_buffer */
|
|
|
|
|
pSrcDst[2] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 2ULL) + 16ULL])); /* cr_b_buffer */
|
2018-11-30 11:37:23 +01:00
|
|
|
rfx_decode_component(context, y_quants, tile->YData, tile->YLen, pSrcDst[0]); /* YData */
|
|
|
|
|
rfx_decode_component(context, cb_quants, tile->CbData, tile->CbLen, pSrcDst[1]); /* CbData */
|
|
|
|
|
rfx_decode_component(context, cr_quants, tile->CrData, tile->CrLen, pSrcDst[2]); /* CrData */
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb)
|
2017-01-24 11:37:24 +01:00
|
|
|
|
2022-04-27 21:02:18 +02:00
|
|
|
cnv.pv = pSrcDst;
|
|
|
|
|
if (prims->yCbCrToRGB_16s8u_P3AC4R(cnv.cpv, 64 * sizeof(INT16), rgb_buffer, stride,
|
|
|
|
|
context->pixel_format, &roi_64x64) != PRIMITIVES_SUCCESS)
|
2017-01-24 11:37:24 +01:00
|
|
|
rc = FALSE;
|
|
|
|
|
|
2018-02-15 10:19:15 +01:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb)
|
|
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_decode_rgb)
|
2013-08-19 18:39:19 -04:00
|
|
|
BufferPool_Return(context->priv->BufferPool, pBuffer);
|
2017-01-24 11:37:24 +01:00
|
|
|
return rc;
|
2011-08-10 15:13:39 +08:00
|
|
|
}
|