2011-08-10 11:13:39 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-10 11:13:39 +04:00
|
|
|
* RemoteFX Codec Library - Decode
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
2013-12-04 14:37:57 +04:00
|
|
|
* Copyright 2011 Norbert Federa <norbert.federa@thincast.com>
|
2011-08-10 11:13:39 +04: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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2013-01-19 02:32:58 +04:00
|
|
|
#include <freerdp/primitives.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2011-08-10 11:13:39 +04: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"
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* stride is bytes between rows in the output buffer. */
|
2016-04-05 18:07:45 +03:00
|
|
|
static void rfx_decode_format_rgb(const INT16* r_buf, const INT16* g_buf,
|
|
|
|
const INT16* b_buf, UINT32 pixel_format,
|
|
|
|
BYTE* dst_buf, UINT32 stride)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
primitives_t* prims = primitives_get();
|
|
|
|
const INT16* r = r_buf;
|
|
|
|
const INT16* g = g_buf;
|
|
|
|
const INT16* b = b_buf;
|
|
|
|
const INT16* pSrc[3];
|
2013-01-19 02:32:58 +04:00
|
|
|
static const prim_size_t roi_64x64 = { 64, 64 };
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* dst = dst_buf;
|
2016-04-05 18:07:45 +03:00
|
|
|
pSrc[0] = r;
|
|
|
|
pSrc[1] = g;
|
|
|
|
pSrc[2] = b;
|
|
|
|
prims->RGBToRGB_16s8u_P3AC4R(
|
|
|
|
(const INT16**) pSrc, 64 * sizeof(INT16),
|
|
|
|
dst, stride, pixel_format, &roi_64x64);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static void rfx_decode_component(RFX_CONTEXT* context,
|
|
|
|
const UINT32* quantization_values,
|
|
|
|
const BYTE* data, int size, INT16* buffer)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-01-23 06:24:04 +04:00
|
|
|
INT16* dwt_buffer;
|
|
|
|
dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_decode_component);
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode);
|
2016-04-05 18:07:45 +03:00
|
|
|
rfx_rlgr_decode(data, size, buffer, 4096, (context->mode == RLGR1) ? 1 : 3);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode);
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_differential_decode);
|
2016-04-05 18:07:45 +03:00
|
|
|
rfx_differential_decode(buffer + 4032, 64);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_differential_decode);
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_quantization_decode);
|
2016-04-05 18:07:45 +03:00
|
|
|
context->quantization_decode(buffer, quantization_values);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_quantization_decode);
|
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode);
|
2016-04-05 18:07:45 +03:00
|
|
|
context->dwt_2d_decode(buffer, dwt_buffer);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode);
|
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_decode_component);
|
2013-01-23 06:24:04 +04:00
|
|
|
BufferPool_Return(context->priv->BufferPool, dwt_buffer);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */
|
|
|
|
|
|
|
|
/* stride is bytes between rows in the output buffer. */
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL rfx_decode_rgb(RFX_CONTEXT* context, RFX_TILE* tile, BYTE* rgb_buffer,
|
|
|
|
int stride)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-20 02:39:19 +04:00
|
|
|
BYTE* pBuffer;
|
2013-01-23 03:14:50 +04:00
|
|
|
INT16* pSrcDst[3];
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32* y_quants, *cb_quants, *cr_quants;
|
2013-01-19 02:32:58 +04:00
|
|
|
static const prim_size_t roi_64x64 = { 64, 64 };
|
2016-04-05 18:07:45 +03:00
|
|
|
const primitives_t* prims = primitives_get();
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_decode_rgb);
|
2013-08-13 18:09:32 +04:00
|
|
|
y_quants = context->quants + (tile->quantIdxY * 10);
|
|
|
|
cb_quants = context->quants + (tile->quantIdxCb * 10);
|
|
|
|
cr_quants = context->quants + (tile->quantIdxCr * 10);
|
2013-08-20 02:39:19 +04:00
|
|
|
pBuffer = (BYTE*) BufferPool_Take(context->priv->BufferPool, -1);
|
2016-04-05 18:07:45 +03:00
|
|
|
pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) +
|
|
|
|
16])); /* y_r_buffer */
|
|
|
|
pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) +
|
|
|
|
16])); /* cb_g_buffer */
|
|
|
|
pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) +
|
|
|
|
16])); /* cr_b_buffer */
|
|
|
|
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 */
|
2013-06-18 16:33:07 +04:00
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb);
|
2013-01-23 03:14:50 +04:00
|
|
|
prims->yCbCrToRGB_16s16s_P3P3((const INT16**) pSrcDst, 64 * sizeof(INT16),
|
2016-04-05 18:07:45 +03:00
|
|
|
pSrcDst, 64 * sizeof(INT16), &roi_64x64);
|
2013-06-18 16:33:07 +04:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_ENTER(context->priv->prof_rfx_decode_format_rgb);
|
2016-04-05 18:07:45 +03:00
|
|
|
rfx_decode_format_rgb(pSrcDst[0], pSrcDst[1], pSrcDst[2],
|
|
|
|
context->pixel_format, rgb_buffer, stride);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_decode_format_rgb);
|
|
|
|
PROFILER_EXIT(context->priv->prof_rfx_decode_rgb);
|
2013-08-20 02:39:19 +04:00
|
|
|
BufferPool_Return(context->priv->BufferPool, pBuffer);
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|