Blame libfreerdp/codec/rfx_decode.c

Packit Service fa4841
/**
Packit Service fa4841
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit Service fa4841
 * RemoteFX Codec Library - Decode
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2011 Vic Lee
Packit Service fa4841
 * Copyright 2011 Norbert Federa <norbert.federa@thincast.com>
Packit Service fa4841
 *
Packit Service fa4841
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit Service fa4841
 * you may not use this file except in compliance with the License.
Packit Service fa4841
 * You may obtain a copy of the License at
Packit Service fa4841
 *
Packit Service fa4841
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit Service fa4841
 *
Packit Service fa4841
 * Unless required by applicable law or agreed to in writing, software
Packit Service fa4841
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service fa4841
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service fa4841
 * See the License for the specific language governing permissions and
Packit Service fa4841
 * limitations under the License.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#ifdef HAVE_CONFIG_H
Packit Service fa4841
#include "config.h"
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
#include <stdio.h>
Packit Service fa4841
#include <stdlib.h>
Packit Service fa4841
#include <string.h>
Packit Service fa4841
Packit Service fa4841
#include <winpr/stream.h>
Packit Service fa4841
#include <freerdp/primitives.h>
Packit Service fa4841
Packit Service fa4841
#include "rfx_types.h"
Packit Service fa4841
#include "rfx_rlgr.h"
Packit Service fa4841
#include "rfx_differential.h"
Packit Service fa4841
#include "rfx_quantization.h"
Packit Service fa4841
#include "rfx_dwt.h"
Packit Service fa4841
Packit Service fa4841
#include "rfx_decode.h"
Packit Service fa4841
Packit Service fa4841
static void rfx_decode_component(RFX_CONTEXT* context, const UINT32* quantization_values,
Packit Service fa4841
                                 const BYTE* data, int size, INT16* buffer)
Packit Service fa4841
{
Packit Service fa4841
	INT16* dwt_buffer;
Packit Service fa4841
	dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */
Packit Service fa4841
	PROFILER_ENTER(context->priv->prof_rfx_decode_component)
Packit Service fa4841
	PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode)
Packit Service fa4841
	context->rlgr_decode(context->mode, data, size, buffer, 4096);
Packit Service fa4841
	PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode)
Packit Service fa4841
	PROFILER_ENTER(context->priv->prof_rfx_differential_decode)
Packit Service fa4841
	rfx_differential_decode(buffer + 4032, 64);
Packit Service fa4841
	PROFILER_EXIT(context->priv->prof_rfx_differential_decode)
Packit Service fa4841
	PROFILER_ENTER(context->priv->prof_rfx_quantization_decode)
Packit Service fa4841
	context->quantization_decode(buffer, quantization_values);
Packit Service fa4841
	PROFILER_EXIT(context->priv->prof_rfx_quantization_decode)
Packit Service fa4841
	PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode)
Packit Service fa4841
	context->dwt_2d_decode(buffer, dwt_buffer);
Packit Service fa4841
	PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode)
Packit Service fa4841
	PROFILER_EXIT(context->priv->prof_rfx_decode_component)
Packit Service fa4841
	BufferPool_Return(context->priv->BufferPool, dwt_buffer);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */
Packit Service fa4841
Packit Service fa4841
/* stride is bytes between rows in the output buffer. */
Packit Service fa4841
BOOL rfx_decode_rgb(RFX_CONTEXT* context, RFX_TILE* tile, BYTE* rgb_buffer, int stride)
Packit Service fa4841
{
Packit Service fa4841
	BOOL rc = TRUE;
Packit Service fa4841
	BYTE* pBuffer;
Packit Service fa4841
	INT16* pSrcDst[3];
Packit Service fa4841
	UINT32 *y_quants, *cb_quants, *cr_quants;
Packit Service fa4841
	static const prim_size_t roi_64x64 = { 64, 64 };
Packit Service fa4841
	const primitives_t* prims = primitives_get();
Packit Service fa4841
	PROFILER_ENTER(context->priv->prof_rfx_decode_rgb)
Packit Service fa4841
	y_quants = context->quants + (tile->quantIdxY * 10);
Packit Service fa4841
	cb_quants = context->quants + (tile->quantIdxCb * 10);
Packit Service fa4841
	cr_quants = context->quants + (tile->quantIdxCr * 10);
Packit Service fa4841
	pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1);
Packit Service fa4841
	pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16]));             /* y_r_buffer */
Packit Service fa4841
	pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16]));             /* cb_g_buffer */
Packit Service fa4841
	pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16]));             /* cr_b_buffer */
Packit Service fa4841
	rfx_decode_component(context, y_quants, tile->YData, tile->YLen, pSrcDst[0]); /* YData */
Packit Service fa4841
	rfx_decode_component(context, cb_quants, tile->CbData, tile->CbLen, pSrcDst[1]); /* CbData */
Packit Service fa4841
	rfx_decode_component(context, cr_quants, tile->CrData, tile->CrLen, pSrcDst[2]); /* CrData */
Packit Service fa4841
	PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb)
Packit Service fa4841
Packit Service fa4841
	if (prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**)pSrcDst, 64 * sizeof(INT16), rgb_buffer,
Packit Service fa4841
	                                   stride, context->pixel_format,
Packit Service fa4841
	                                   &roi_64x64) != PRIMITIVES_SUCCESS)
Packit Service fa4841
		rc = FALSE;
Packit Service fa4841
Packit Service fa4841
	PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb)
Packit Service fa4841
	PROFILER_EXIT(context->priv->prof_rfx_decode_rgb)
Packit Service fa4841
	BufferPool_Return(context->priv->BufferPool, pBuffer);
Packit Service fa4841
	return rc;
Packit Service fa4841
}