Blame libfreerdp/codec/rfx_decode.c

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