Blame libfreerdp/codec/nsc.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 * NSCodec Codec
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2011 Samsung, Author Jiten Pathy
Packit 1fb8d4
 * Copyright 2012 Vic Lee
Packit 1fb8d4
 * Copyright 2016 Armin Novak <armin.novak@thincast.com>
Packit 1fb8d4
 * Copyright 2016 Thincast Technologies GmbH
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/crt.h>
Packit 1fb8d4
Packit 1fb8d4
#include <freerdp/codec/nsc.h>
Packit 1fb8d4
#include <freerdp/codec/color.h>
Packit 1fb8d4
Packit 1fb8d4
#include "nsc_types.h"
Packit 1fb8d4
#include "nsc_encode.h"
Packit 1fb8d4
Packit 1fb8d4
#include "nsc_sse2.h"
Packit 1fb8d4
Packit 1fb8d4
#ifndef NSC_INIT_SIMD
Packit Service 5a9772
#define NSC_INIT_SIMD(_nsc_context) \
Packit Service 5a9772
	do                              \
Packit Service 5a9772
	{                               \
Packit Service 5a9772
	} while (0)
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
static BOOL nsc_decode(NSC_CONTEXT* context)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT16 x;
Packit 1fb8d4
	UINT16 y;
Packit 1fb8d4
	UINT16 rw;
Packit 1fb8d4
	BYTE shift;
Packit 1fb8d4
	BYTE* bmpdata;
Packit 1fb8d4
	size_t pos = 0;
Packit 1fb8d4
Packit 1fb8d4
	if (!context)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	rw = ROUND_UP_TO(context->width, 8);
Packit 1fb8d4
	shift = context->ColorLossLevel - 1; /* colorloss recovery + YCoCg shift */
Packit 1fb8d4
	bmpdata = context->BitmapData;
Packit 1fb8d4
Packit 1fb8d4
	if (!bmpdata)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	for (y = 0; y < context->height; y++)
Packit 1fb8d4
	{
Packit 1fb8d4
		const BYTE* yplane;
Packit 1fb8d4
		const BYTE* coplane;
Packit 1fb8d4
		const BYTE* cgplane;
Packit 1fb8d4
		const BYTE* aplane = context->priv->PlaneBuffers[3] + y * context->width; /* A */
Packit 1fb8d4
Packit 1fb8d4
		if (context->ChromaSubsamplingLevel)
Packit 1fb8d4
		{
Packit Service 5a9772
			yplane = context->priv->PlaneBuffers[0] + y * rw;                /* Y */
Packit Service 5a9772
			coplane = context->priv->PlaneBuffers[1] + (y >> 1) * (rw >> 1); /* Co, supersampled */
Packit Service 5a9772
			cgplane = context->priv->PlaneBuffers[2] + (y >> 1) * (rw >> 1); /* Cg, supersampled */
Packit 1fb8d4
		}
Packit 1fb8d4
		else
Packit 1fb8d4
		{
Packit Service 5a9772
			yplane = context->priv->PlaneBuffers[0] + y * context->width;  /* Y */
Packit 1fb8d4
			coplane = context->priv->PlaneBuffers[1] + y * context->width; /* Co */
Packit 1fb8d4
			cgplane = context->priv->PlaneBuffers[2] + y * context->width; /* Cg */
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		for (x = 0; x < context->width; x++)
Packit 1fb8d4
		{
Packit Service 5a9772
			INT16 y_val = (INT16)*yplane;
Packit 1fb8d4
			INT16 co_val = (INT16)(INT8)(*coplane << shift);
Packit 1fb8d4
			INT16 cg_val = (INT16)(INT8)(*cgplane << shift);
Packit 1fb8d4
			INT16 r_val = y_val + co_val - cg_val;
Packit 1fb8d4
			INT16 g_val = y_val + cg_val;
Packit 1fb8d4
			INT16 b_val = y_val - co_val - cg_val;
Packit 1fb8d4
Packit 1fb8d4
			if (pos + 4 > context->BitmapDataLength)
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
Packit 1fb8d4
			pos += 4;
Packit 1fb8d4
			*bmpdata++ = MINMAX(b_val, 0, 0xFF);
Packit 1fb8d4
			*bmpdata++ = MINMAX(g_val, 0, 0xFF);
Packit 1fb8d4
			*bmpdata++ = MINMAX(r_val, 0, 0xFF);
Packit 1fb8d4
			*bmpdata++ = *aplane;
Packit 1fb8d4
			yplane++;
Packit 1fb8d4
			coplane += (context->ChromaSubsamplingLevel ? x % 2 : 1);
Packit 1fb8d4
			cgplane += (context->ChromaSubsamplingLevel ? x % 2 : 1);
Packit 1fb8d4
			aplane++;
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL nsc_rle_decode(BYTE* in, BYTE* out, UINT32 outSize, UINT32 originalSize)
Packit 1fb8d4
{
Packit Service 5a9772
	UINT32 left = originalSize;
Packit 1fb8d4
Packit 1fb8d4
	while (left > 4)
Packit 1fb8d4
	{
Packit Service 5a9772
		const BYTE value = *in++;
Packit Service 5a9772
		UINT32 len = 0;
Packit 1fb8d4
Packit 1fb8d4
		if (left == 5)
Packit 1fb8d4
		{
Packit 1fb8d4
			if (outSize < 1)
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
Packit 1fb8d4
			outSize--;
Packit 1fb8d4
			*out++ = value;
Packit 1fb8d4
			left--;
Packit 1fb8d4
		}
Packit 1fb8d4
		else if (value == *in)
Packit 1fb8d4
		{
Packit 1fb8d4
			in++;
Packit 1fb8d4
Packit 1fb8d4
			if (*in < 0xFF)
Packit 1fb8d4
			{
Packit Service 5a9772
				len = (UINT32)*in++;
Packit 1fb8d4
				len += 2;
Packit 1fb8d4
			}
Packit 1fb8d4
			else
Packit 1fb8d4
			{
Packit 1fb8d4
				in++;
Packit Service 5a9772
				len = ((UINT32)(*in++));
Packit Service 5a9772
				len |= ((UINT32)(*in++)) << 8U;
Packit Service 5a9772
				len |= ((UINT32)(*in++)) << 16U;
Packit Service 5a9772
				len |= ((UINT32)(*in++)) << 24U;
Packit 1fb8d4
			}
Packit 1fb8d4
Packit 1fb8d4
			if (outSize < len)
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
Packit 1fb8d4
			outSize -= len;
Packit 1fb8d4
			FillMemory(out, len, value);
Packit 1fb8d4
			out += len;
Packit 1fb8d4
			left -= len;
Packit 1fb8d4
		}
Packit 1fb8d4
		else
Packit 1fb8d4
		{
Packit 1fb8d4
			if (outSize < 1)
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
Packit 1fb8d4
			outSize--;
Packit 1fb8d4
			*out++ = value;
Packit 1fb8d4
			left--;
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if ((outSize < 4) || (left < 4))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	memcpy(out, in, 4);
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL nsc_rle_decompress_data(NSC_CONTEXT* context)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT16 i;
Packit 1fb8d4
	BYTE* rle;
Packit 1fb8d4
	UINT32 planeSize;
Packit 1fb8d4
	UINT32 originalSize;
Packit 1fb8d4
Packit 1fb8d4
	if (!context)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	rle = context->Planes;
Packit 1fb8d4
Packit 1fb8d4
	for (i = 0; i < 4; i++)
Packit 1fb8d4
	{
Packit 1fb8d4
		originalSize = context->OrgByteCount[i];
Packit 1fb8d4
		planeSize = context->PlaneByteCount[i];
Packit 1fb8d4
Packit 1fb8d4
		if (planeSize == 0)
Packit 1fb8d4
		{
Packit 1fb8d4
			if (context->priv->PlaneBuffersLength < originalSize)
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
Packit 1fb8d4
			FillMemory(context->priv->PlaneBuffers[i], originalSize, 0xFF);
Packit 1fb8d4
		}
Packit 1fb8d4
		else if (planeSize < originalSize)
Packit 1fb8d4
		{
Packit Service 5a9772
			if (!nsc_rle_decode(rle, context->priv->PlaneBuffers[i],
Packit Service 5a9772
			                    context->priv->PlaneBuffersLength, originalSize))
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
		}
Packit 1fb8d4
		else
Packit 1fb8d4
		{
Packit 1fb8d4
			if (context->priv->PlaneBuffersLength < originalSize)
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
Packit 1fb8d4
			CopyMemory(context->priv->PlaneBuffers[i], rle, originalSize);
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		rle += planeSize;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL nsc_stream_initialize(NSC_CONTEXT* context, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	int i;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 20)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	for (i = 0; i < 4; i++)
Packit 1fb8d4
		Stream_Read_UINT32(s, context->PlaneByteCount[i]);
Packit 1fb8d4
Packit Service 5a9772
	Stream_Read_UINT8(s, context->ColorLossLevel);         /* ColorLossLevel (1 byte) */
Packit Service 5a9772
	Stream_Read_UINT8(s, context->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */
Packit Service 5a9772
	Stream_Seek(s, 2);                                     /* Reserved (2 bytes) */
Packit 1fb8d4
	context->Planes = Stream_Pointer(s);
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL nsc_context_initialize(NSC_CONTEXT* context, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	int i;
Packit 1fb8d4
	UINT32 length;
Packit 1fb8d4
	UINT32 tempWidth;
Packit 1fb8d4
	UINT32 tempHeight;
Packit 1fb8d4
Packit 1fb8d4
	if (!nsc_stream_initialize(context, s))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	length = context->width * context->height * 4;
Packit 1fb8d4
Packit 1fb8d4
	if (!context->BitmapData)
Packit 1fb8d4
	{
Packit 1fb8d4
		context->BitmapData = calloc(1, length + 16);
Packit 1fb8d4
Packit 1fb8d4
		if (!context->BitmapData)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
Packit 1fb8d4
		context->BitmapDataLength = length;
Packit 1fb8d4
	}
Packit 1fb8d4
	else if (length > context->BitmapDataLength)
Packit 1fb8d4
	{
Packit 1fb8d4
		void* tmp;
Packit 1fb8d4
		tmp = realloc(context->BitmapData, length + 16);
Packit 1fb8d4
Packit 1fb8d4
		if (!tmp)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
Packit 1fb8d4
		context->BitmapData = tmp;
Packit 1fb8d4
		context->BitmapDataLength = length;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	tempWidth = ROUND_UP_TO(context->width, 8);
Packit 1fb8d4
	tempHeight = ROUND_UP_TO(context->height, 2);
Packit 1fb8d4
	/* The maximum length a decoded plane can reach in all cases */
Packit 1fb8d4
	length = tempWidth * tempHeight;
Packit 1fb8d4
Packit 1fb8d4
	if (length > context->priv->PlaneBuffersLength)
Packit 1fb8d4
	{
Packit 1fb8d4
		for (i = 0; i < 4; i++)
Packit 1fb8d4
		{
Packit Service 5a9772
			void* tmp = (BYTE*)realloc(context->priv->PlaneBuffers[i], length);
Packit 1fb8d4
Packit 1fb8d4
			if (!tmp)
Packit 1fb8d4
				return FALSE;
Packit 1fb8d4
Packit 1fb8d4
			context->priv->PlaneBuffers[i] = tmp;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		context->priv->PlaneBuffersLength = length;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	for (i = 0; i < 4; i++)
Packit 1fb8d4
	{
Packit 1fb8d4
		context->OrgByteCount[i] = context->width * context->height;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (context->ChromaSubsamplingLevel)
Packit 1fb8d4
	{
Packit 1fb8d4
		context->OrgByteCount[0] = tempWidth * context->height;
Packit 1fb8d4
		context->OrgByteCount[1] = (tempWidth >> 1) * (tempHeight >> 1);
Packit 1fb8d4
		context->OrgByteCount[2] = context->OrgByteCount[1];
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static void nsc_profiler_print(NSC_CONTEXT_PRIV* priv){
Packit Service 5a9772
	PROFILER_PRINT_HEADER PROFILER_PRINT(priv->prof_nsc_rle_decompress_data)
Packit Service 5a9772
	    PROFILER_PRINT(priv->prof_nsc_decode) PROFILER_PRINT(priv->prof_nsc_rle_compress_data)
Packit Service 5a9772
	        PROFILER_PRINT(priv->prof_nsc_encode) PROFILER_PRINT_FOOTER
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL nsc_context_reset(NSC_CONTEXT* context, UINT32 width, UINT32 height)
Packit 1fb8d4
{
Packit 1fb8d4
	if (!context)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit Service 5a9772
	if ((width > UINT16_MAX) || (height > UINT16_MAX))
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	context->width = (UINT16)width;
Packit Service 5a9772
	context->height = (UINT16)height;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
NSC_CONTEXT* nsc_context_new(void)
Packit 1fb8d4
{
Packit 1fb8d4
	NSC_CONTEXT* context;
Packit Service 5a9772
	context = (NSC_CONTEXT*)calloc(1, sizeof(NSC_CONTEXT));
Packit 1fb8d4
Packit 1fb8d4
	if (!context)
Packit 1fb8d4
		return NULL;
Packit 1fb8d4
Packit Service 5a9772
	context->priv = (NSC_CONTEXT_PRIV*)calloc(1, sizeof(NSC_CONTEXT_PRIV));
Packit 1fb8d4
Packit 1fb8d4
	if (!context->priv)
Packit 1fb8d4
		goto error;
Packit 1fb8d4
Packit 1fb8d4
	context->priv->log = WLog_Get("com.freerdp.codec.nsc");
Packit 1fb8d4
	WLog_OpenAppender(context->priv->log);
Packit 1fb8d4
	context->BitmapData = NULL;
Packit 1fb8d4
	context->decode = nsc_decode;
Packit 1fb8d4
	context->encode = nsc_encode;
Packit 1fb8d4
Packit Service 5a9772
	PROFILER_CREATE(context->priv->prof_nsc_rle_decompress_data, "nsc_rle_decompress_data")
Packit 1fb8d4
	PROFILER_CREATE(context->priv->prof_nsc_decode, "nsc_decode")
Packit Service 5a9772
	PROFILER_CREATE(context->priv->prof_nsc_rle_compress_data, "nsc_rle_compress_data")
Packit 1fb8d4
	PROFILER_CREATE(context->priv->prof_nsc_encode, "nsc_encode")
Packit 1fb8d4
	/* Default encoding parameters */
Packit 1fb8d4
	context->ColorLossLevel = 3;
Packit 1fb8d4
	context->ChromaSubsamplingLevel = 1;
Packit 1fb8d4
	/* init optimized methods */
Packit 1fb8d4
	NSC_INIT_SIMD(context);
Packit 1fb8d4
	return context;
Packit 1fb8d4
error:
Packit 1fb8d4
	nsc_context_free(context);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void nsc_context_free(NSC_CONTEXT* context)
Packit 1fb8d4
{
Packit 1fb8d4
	size_t i;
Packit 1fb8d4
Packit 1fb8d4
	if (!context)
Packit 1fb8d4
		return;
Packit 1fb8d4
Packit 1fb8d4
	if (context->priv)
Packit 1fb8d4
	{
Packit 1fb8d4
		for (i = 0; i < 4; i++)
Packit 1fb8d4
			free(context->priv->PlaneBuffers[i]);
Packit 1fb8d4
Packit 1fb8d4
		nsc_profiler_print(context->priv);
Packit 1fb8d4
		PROFILER_FREE(context->priv->prof_nsc_rle_decompress_data)
Packit 1fb8d4
		PROFILER_FREE(context->priv->prof_nsc_decode)
Packit 1fb8d4
		PROFILER_FREE(context->priv->prof_nsc_rle_compress_data)
Packit 1fb8d4
		PROFILER_FREE(context->priv->prof_nsc_encode)
Packit 1fb8d4
		free(context->priv);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	free(context->BitmapData);
Packit 1fb8d4
	free(context);
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL nsc_context_set_pixel_format(NSC_CONTEXT* context, UINT32 pixel_format)
Packit 1fb8d4
{
Packit Service 5a9772
	return nsc_context_set_parameters(context, NSC_COLOR_FORMAT, pixel_format);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
BOOL nsc_context_set_parameters(NSC_CONTEXT* context, NSC_PARAMETER what, UINT32 value)
Packit Service 5a9772
{
Packit 1fb8d4
	if (!context)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit Service 5a9772
	switch (what)
Packit Service 5a9772
	{
Packit Service 5a9772
		case NSC_COLOR_LOSS_LEVEL:
Packit Service 5a9772
			context->ColorLossLevel = value;
Packit Service 5a9772
			break;
Packit Service 5a9772
		case NSC_ALLOW_SUBSAMPLING:
Packit Service 5a9772
			context->ChromaSubsamplingLevel = value;
Packit Service 5a9772
			break;
Packit Service 5a9772
		case NSC_DYNAMIC_COLOR_FIDELITY:
Packit Service 5a9772
			context->DynamicColorFidelity = value != 0;
Packit Service 5a9772
			break;
Packit Service 5a9772
		case NSC_COLOR_FORMAT:
Packit Service 5a9772
			context->format = value;
Packit Service 5a9772
			break;
Packit Service 5a9772
		default:
Packit Service 5a9772
			return FALSE;
Packit Service 5a9772
	}
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, UINT32 width, UINT32 height,
Packit Service 5a9772
                         const BYTE* data, UINT32 length, BYTE* pDstData, UINT32 DstFormat,
Packit Service 5a9772
                         UINT32 nDstStride, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
Packit 1fb8d4
                         UINT32 nHeight, UINT32 flip)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	BOOL ret;
Packit Service 5a9772
	if (!context || !data || !pDstData)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit 1fb8d4
	s = Stream_New((BYTE*)data, length);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (nDstStride == 0)
Packit 1fb8d4
		nDstStride = nWidth * GetBytesPerPixel(DstFormat);
Packit 1fb8d4
Packit 1fb8d4
	switch (bpp)
Packit 1fb8d4
	{
Packit 1fb8d4
		case 32:
Packit 1fb8d4
			context->format = PIXEL_FORMAT_BGRA32;
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit 1fb8d4
		case 24:
Packit 1fb8d4
			context->format = PIXEL_FORMAT_BGR24;
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit 1fb8d4
		case 16:
Packit 1fb8d4
			context->format = PIXEL_FORMAT_BGR16;
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit 1fb8d4
		case 8:
Packit 1fb8d4
			context->format = PIXEL_FORMAT_RGB8;
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit 1fb8d4
		case 4:
Packit 1fb8d4
			context->format = PIXEL_FORMAT_A4;
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit 1fb8d4
		default:
Packit 1fb8d4
			Stream_Free(s, TRUE);
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	context->width = width;
Packit 1fb8d4
	context->height = height;
Packit 1fb8d4
	ret = nsc_context_initialize(context, s);
Packit 1fb8d4
	Stream_Free(s, FALSE);
Packit 1fb8d4
Packit 1fb8d4
	if (!ret)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	/* RLE decode */
Packit 1fb8d4
	{
Packit 1fb8d4
		BOOL rc;
Packit 1fb8d4
		PROFILER_ENTER(context->priv->prof_nsc_rle_decompress_data)
Packit 1fb8d4
		rc = nsc_rle_decompress_data(context);
Packit 1fb8d4
		PROFILER_EXIT(context->priv->prof_nsc_rle_decompress_data)
Packit 1fb8d4
Packit 1fb8d4
		if (!rc)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
	/* Colorloss recover, Chroma supersample and AYCoCg to ARGB Conversion in one step */
Packit 1fb8d4
	{
Packit 1fb8d4
		BOOL rc;
Packit 1fb8d4
		PROFILER_ENTER(context->priv->prof_nsc_decode)
Packit 1fb8d4
		rc = context->decode(context);
Packit 1fb8d4
		PROFILER_EXIT(context->priv->prof_nsc_decode)
Packit 1fb8d4
Packit 1fb8d4
		if (!rc)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	if (!freerdp_image_copy(pDstData, DstFormat, nDstStride, nXDst, nYDst, width, height,
Packit Service 5a9772
	                        context->BitmapData, PIXEL_FORMAT_BGRA32, 0, 0, 0, NULL, flip))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}