2011-10-02 23:26:33 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-10-03 05:07:07 +04:00
|
|
|
* NSCodec Codec
|
|
|
|
*
|
|
|
|
* Copyright 2011 Samsung, Author Jiten Pathy
|
2012-03-06 14:52:28 +04:00
|
|
|
* Copyright 2012 Vic Lee
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
2011-10-03 05:07:07 +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.
|
|
|
|
*/
|
2011-10-03 04:52:17 +04:00
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2011-10-03 04:52:17 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2011-10-03 04:52:17 +04:00
|
|
|
#include <freerdp/codec/nsc.h>
|
2016-04-05 18:07:45 +03:00
|
|
|
#include <freerdp/codec/color.h>
|
2011-10-02 23:26:33 +04:00
|
|
|
|
2012-03-06 16:06:08 +04:00
|
|
|
#include "nsc_types.h"
|
2012-03-16 08:04:38 +04:00
|
|
|
#include "nsc_encode.h"
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2012-03-18 19:25:07 +04:00
|
|
|
#include "nsc_sse2.h"
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
#define TAG FREERDP_TAG("codec.nsc")
|
|
|
|
|
2012-03-06 16:06:08 +04:00
|
|
|
#ifndef NSC_INIT_SIMD
|
2019-11-06 17:24:51 +03:00
|
|
|
#define NSC_INIT_SIMD(_nsc_context) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
} while (0)
|
2012-03-06 16:06:08 +04:00
|
|
|
#endif
|
|
|
|
|
2018-10-22 17:52:21 +03:00
|
|
|
static BOOL nsc_decode(NSC_CONTEXT* context)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 x;
|
|
|
|
UINT16 y;
|
2018-10-22 17:52:21 +03:00
|
|
|
UINT16 rw;
|
|
|
|
BYTE shift;
|
|
|
|
BYTE* bmpdata;
|
|
|
|
size_t pos = 0;
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
rw = ROUND_UP_TO(context->width, 8);
|
|
|
|
shift = context->ColorLossLevel - 1; /* colorloss recovery + YCoCg shift */
|
|
|
|
bmpdata = context->BitmapData;
|
|
|
|
|
|
|
|
if (!bmpdata)
|
|
|
|
return FALSE;
|
2013-10-09 04:40:58 +04:00
|
|
|
|
2012-03-06 14:52:28 +04:00
|
|
|
for (y = 0; y < context->height; y++)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2016-04-11 15:14:17 +03:00
|
|
|
const BYTE* yplane;
|
|
|
|
const BYTE* coplane;
|
|
|
|
const BYTE* cgplane;
|
2016-11-22 14:12:08 +03:00
|
|
|
const BYTE* aplane = context->priv->PlaneBuffers[3] + y * context->width; /* A */
|
2016-04-11 15:14:17 +03:00
|
|
|
|
2014-09-24 04:00:26 +04:00
|
|
|
if (context->ChromaSubsamplingLevel)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
yplane = context->priv->PlaneBuffers[0] + y * rw; /* Y */
|
|
|
|
coplane = context->priv->PlaneBuffers[1] + (y >> 1) * (rw >> 1); /* Co, supersampled */
|
|
|
|
cgplane = context->priv->PlaneBuffers[2] + (y >> 1) * (rw >> 1); /* Cg, supersampled */
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
2012-03-06 14:52:28 +04:00
|
|
|
else
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
yplane = context->priv->PlaneBuffers[0] + y * context->width; /* Y */
|
2013-08-15 07:16:13 +04:00
|
|
|
coplane = context->priv->PlaneBuffers[1] + y * context->width; /* Co */
|
|
|
|
cgplane = context->priv->PlaneBuffers[2] + y * context->width; /* Cg */
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2012-03-06 14:52:28 +04:00
|
|
|
for (x = 0; x < context->width; x++)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
INT16 y_val = (INT16)*yplane;
|
2016-04-11 15:14:17 +03:00
|
|
|
INT16 co_val = (INT16)(INT8)(*coplane << shift);
|
|
|
|
INT16 cg_val = (INT16)(INT8)(*cgplane << shift);
|
|
|
|
INT16 r_val = y_val + co_val - cg_val;
|
|
|
|
INT16 g_val = y_val + cg_val;
|
|
|
|
INT16 b_val = y_val - co_val - cg_val;
|
2018-10-22 17:52:21 +03:00
|
|
|
|
|
|
|
if (pos + 4 > context->BitmapDataLength)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pos += 4;
|
2012-03-06 14:52:28 +04:00
|
|
|
*bmpdata++ = MINMAX(b_val, 0, 0xFF);
|
|
|
|
*bmpdata++ = MINMAX(g_val, 0, 0xFF);
|
|
|
|
*bmpdata++ = MINMAX(r_val, 0, 0xFF);
|
|
|
|
*bmpdata++ = *aplane;
|
|
|
|
yplane++;
|
2014-09-24 04:00:26 +04:00
|
|
|
coplane += (context->ChromaSubsamplingLevel ? x % 2 : 1);
|
|
|
|
cgplane += (context->ChromaSubsamplingLevel ? x % 2 : 1);
|
2012-03-06 14:52:28 +04:00
|
|
|
aplane++;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
2011-10-03 05:07:07 +04:00
|
|
|
}
|
2018-10-22 17:52:21 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
|
2018-10-22 17:52:21 +03:00
|
|
|
static BOOL nsc_rle_decode(BYTE* in, BYTE* out, UINT32 outSize, UINT32 originalSize)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2020-05-18 18:40:28 +03:00
|
|
|
UINT32 left = originalSize;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2012-03-06 14:52:28 +04:00
|
|
|
while (left > 4)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2020-05-18 18:40:28 +03:00
|
|
|
const BYTE value = *in++;
|
|
|
|
UINT32 len = 0;
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2012-03-06 14:52:28 +04:00
|
|
|
if (left == 5)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2018-10-22 17:52:21 +03:00
|
|
|
if (outSize < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
outSize--;
|
2012-03-06 14:52:28 +04:00
|
|
|
*out++ = value;
|
|
|
|
left--;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
2012-03-06 14:52:28 +04:00
|
|
|
else if (value == *in)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2012-03-06 14:52:28 +04:00
|
|
|
in++;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2012-03-06 14:52:28 +04:00
|
|
|
if (*in < 0xFF)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
len = (UINT32)*in++;
|
2012-03-06 14:52:28 +04:00
|
|
|
len += 2;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-06 14:52:28 +04:00
|
|
|
in++;
|
2020-05-18 18:40:28 +03:00
|
|
|
len = ((UINT32)(*in++));
|
|
|
|
len |= ((UINT32)(*in++)) << 8U;
|
|
|
|
len |= ((UINT32)(*in++)) << 16U;
|
|
|
|
len |= ((UINT32)(*in++)) << 24U;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2018-10-22 17:52:21 +03:00
|
|
|
if (outSize < len)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
outSize -= len;
|
2013-08-15 04:57:16 +04:00
|
|
|
FillMemory(out, len, value);
|
2012-03-07 07:42:37 +04:00
|
|
|
out += len;
|
2012-03-06 14:52:28 +04:00
|
|
|
left -= len;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-22 17:52:21 +03:00
|
|
|
if (outSize < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
outSize--;
|
2012-03-06 14:52:28 +04:00
|
|
|
*out++ = value;
|
|
|
|
left--;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2018-10-22 17:52:21 +03:00
|
|
|
if ((outSize < 4) || (left < 4))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
memcpy(out, in, 4);
|
|
|
|
return TRUE;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
|
2018-10-22 17:52:21 +03:00
|
|
|
static BOOL nsc_rle_decompress_data(NSC_CONTEXT* context)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 i;
|
|
|
|
BYTE* rle;
|
2013-08-15 04:57:16 +04:00
|
|
|
UINT32 planeSize;
|
|
|
|
UINT32 originalSize;
|
2018-10-22 17:52:21 +03:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-09-24 04:00:26 +04:00
|
|
|
rle = context->Planes;
|
2011-10-03 05:07:07 +04:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2013-08-15 04:57:16 +04:00
|
|
|
originalSize = context->OrgByteCount[i];
|
2014-09-24 04:00:26 +04:00
|
|
|
planeSize = context->PlaneByteCount[i];
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2013-08-15 04:57:16 +04:00
|
|
|
if (planeSize == 0)
|
2018-10-22 17:52:21 +03:00
|
|
|
{
|
|
|
|
if (context->priv->PlaneBuffersLength < originalSize)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-08-15 07:16:13 +04:00
|
|
|
FillMemory(context->priv->PlaneBuffers[i], originalSize, 0xFF);
|
2018-10-22 17:52:21 +03:00
|
|
|
}
|
2013-08-15 04:57:16 +04:00
|
|
|
else if (planeSize < originalSize)
|
2018-10-22 17:52:21 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!nsc_rle_decode(rle, context->priv->PlaneBuffers[i],
|
|
|
|
context->priv->PlaneBuffersLength, originalSize))
|
2018-10-22 17:52:21 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-10-02 23:26:33 +04:00
|
|
|
else
|
2018-10-22 17:52:21 +03:00
|
|
|
{
|
|
|
|
if (context->priv->PlaneBuffersLength < originalSize)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-08-15 07:16:13 +04:00
|
|
|
CopyMemory(context->priv->PlaneBuffers[i], rle, originalSize);
|
2018-10-22 17:52:21 +03:00
|
|
|
}
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2013-08-15 04:57:16 +04:00
|
|
|
rle += planeSize;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
2018-10-22 17:52:21 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
static BOOL nsc_stream_initialize(NSC_CONTEXT* context, wStream* s)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 20))
|
2015-05-18 12:28:00 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2011-10-03 05:07:07 +04:00
|
|
|
for (i = 0; i < 4; i++)
|
2014-09-24 04:00:26 +04:00
|
|
|
Stream_Read_UINT32(s, context->PlaneByteCount[i]);
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT8(s, context->ColorLossLevel); /* ColorLossLevel (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, context->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */
|
|
|
|
Stream_Seek(s, 2); /* Reserved (2 bytes) */
|
2014-09-24 04:00:26 +04:00
|
|
|
context->Planes = Stream_Pointer(s);
|
2015-05-18 12:28:00 +03:00
|
|
|
return TRUE;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
static BOOL nsc_context_initialize(NSC_CONTEXT* context, wStream* s)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 length;
|
|
|
|
UINT32 tempWidth;
|
|
|
|
UINT32 tempHeight;
|
2012-03-05 13:32:14 +04:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!nsc_stream_initialize(context, s))
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2012-03-05 13:32:14 +04:00
|
|
|
length = context->width * context->height * 4;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2023-03-24 14:15:06 +03:00
|
|
|
if (!context->BitmapData || (length > context->BitmapDataLength))
|
2012-03-05 13:32:14 +04:00
|
|
|
{
|
2023-03-24 14:15:06 +03:00
|
|
|
void* tmp = winpr_aligned_recalloc(context->BitmapData, length + 16, sizeof(BYTE), 32);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
context->BitmapData = tmp;
|
2013-08-15 07:16:13 +04:00
|
|
|
context->BitmapDataLength = length;
|
2012-03-05 13:32:14 +04:00
|
|
|
}
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2012-03-06 14:52:28 +04:00
|
|
|
tempWidth = ROUND_UP_TO(context->width, 8);
|
|
|
|
tempHeight = ROUND_UP_TO(context->height, 2);
|
|
|
|
/* The maximum length a decoded plane can reach in all cases */
|
|
|
|
length = tempWidth * tempHeight;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2013-08-15 07:16:13 +04:00
|
|
|
if (length > context->priv->PlaneBuffersLength)
|
2012-03-06 14:52:28 +04:00
|
|
|
{
|
|
|
|
for (i = 0; i < 4; i++)
|
2015-05-18 12:28:00 +03:00
|
|
|
{
|
2023-03-24 14:15:06 +03:00
|
|
|
void* tmp = (BYTE*)winpr_aligned_recalloc(context->priv->PlaneBuffers[i], length,
|
|
|
|
sizeof(BYTE), 32);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
context->priv->PlaneBuffers[i] = tmp;
|
|
|
|
}
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2013-08-15 07:16:13 +04:00
|
|
|
context->priv->PlaneBuffersLength = length;
|
2012-03-06 14:52:28 +04:00
|
|
|
}
|
|
|
|
|
2011-10-03 05:07:07 +04:00
|
|
|
for (i = 0; i < 4; i++)
|
2013-08-15 07:16:13 +04:00
|
|
|
{
|
|
|
|
context->OrgByteCount[i] = context->width * context->height;
|
|
|
|
}
|
2011-10-03 05:07:07 +04:00
|
|
|
|
2014-09-24 04:00:26 +04:00
|
|
|
if (context->ChromaSubsamplingLevel)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
|
|
|
context->OrgByteCount[0] = tempWidth * context->height;
|
2012-03-06 14:52:28 +04:00
|
|
|
context->OrgByteCount[1] = (tempWidth >> 1) * (tempHeight >> 1);
|
|
|
|
context->OrgByteCount[2] = context->OrgByteCount[1];
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
2015-05-18 12:28:00 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
static void nsc_profiler_print(NSC_CONTEXT_PRIV* priv)
|
|
|
|
{
|
2021-06-18 10:58:46 +03:00
|
|
|
WINPR_UNUSED(priv);
|
|
|
|
|
|
|
|
PROFILER_PRINT_HEADER
|
|
|
|
PROFILER_PRINT(priv->prof_nsc_rle_decompress_data)
|
|
|
|
PROFILER_PRINT(priv->prof_nsc_decode)
|
|
|
|
PROFILER_PRINT(priv->prof_nsc_rle_compress_data)
|
|
|
|
PROFILER_PRINT(priv->prof_nsc_encode)
|
|
|
|
PROFILER_PRINT_FOOTER
|
2012-03-06 18:42:57 +04:00
|
|
|
}
|
|
|
|
|
2016-03-01 18:17:28 +03:00
|
|
|
BOOL nsc_context_reset(NSC_CONTEXT* context, UINT32 width, UINT32 height)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-10-04 11:13:43 +03:00
|
|
|
if ((width > UINT16_MAX) || (height > UINT16_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
context->width = (UINT16)width;
|
|
|
|
context->height = (UINT16)height;
|
2016-03-01 18:17:28 +03:00
|
|
|
return TRUE;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:16:13 +04:00
|
|
|
NSC_CONTEXT* nsc_context_new(void)
|
|
|
|
{
|
2023-03-24 14:15:06 +03:00
|
|
|
NSC_CONTEXT* context = (NSC_CONTEXT*)winpr_aligned_calloc(1, sizeof(NSC_CONTEXT), 32);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
2023-03-24 14:15:06 +03:00
|
|
|
context->priv = (NSC_CONTEXT_PRIV*)winpr_aligned_calloc(1, sizeof(NSC_CONTEXT_PRIV), 32);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!context->priv)
|
2018-05-15 10:13:00 +03:00
|
|
|
goto error;
|
2013-08-15 07:16:13 +04:00
|
|
|
|
2013-10-09 04:40:58 +04:00
|
|
|
context->priv->log = WLog_Get("com.freerdp.codec.nsc");
|
|
|
|
WLog_OpenAppender(context->priv->log);
|
2013-08-15 07:16:13 +04:00
|
|
|
context->BitmapData = NULL;
|
|
|
|
context->decode = nsc_decode;
|
|
|
|
context->encode = nsc_encode;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_nsc_rle_decompress_data, "nsc_rle_decompress_data")
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_nsc_decode, "nsc_decode")
|
2019-11-06 17:24:51 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_nsc_rle_compress_data, "nsc_rle_compress_data")
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_nsc_encode, "nsc_encode")
|
2013-08-15 07:16:13 +04:00
|
|
|
/* Default encoding parameters */
|
2014-09-24 04:00:26 +04:00
|
|
|
context->ColorLossLevel = 3;
|
|
|
|
context->ChromaSubsamplingLevel = 1;
|
2013-08-15 07:16:13 +04:00
|
|
|
/* init optimized methods */
|
|
|
|
NSC_INIT_SIMD(context);
|
|
|
|
return context;
|
2018-05-15 10:13:00 +03:00
|
|
|
error:
|
|
|
|
nsc_context_free(context);
|
2015-05-18 12:28:00 +03:00
|
|
|
return NULL;
|
2013-08-15 07:16:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-05 13:32:14 +04:00
|
|
|
void nsc_context_free(NSC_CONTEXT* context)
|
2011-10-02 23:26:33 +04:00
|
|
|
{
|
2018-05-15 10:13:00 +03:00
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (context->priv)
|
2012-03-06 14:52:28 +04:00
|
|
|
{
|
2023-03-24 14:15:06 +03:00
|
|
|
for (size_t i = 0; i < 5; i++)
|
|
|
|
winpr_aligned_free(context->priv->PlaneBuffers[i]);
|
2018-05-15 10:13:00 +03:00
|
|
|
|
|
|
|
nsc_profiler_print(context->priv);
|
|
|
|
PROFILER_FREE(context->priv->prof_nsc_rle_decompress_data)
|
|
|
|
PROFILER_FREE(context->priv->prof_nsc_decode)
|
|
|
|
PROFILER_FREE(context->priv->prof_nsc_rle_compress_data)
|
|
|
|
PROFILER_FREE(context->priv->prof_nsc_encode)
|
2023-03-24 14:15:06 +03:00
|
|
|
winpr_aligned_free(context->priv);
|
2012-03-06 14:52:28 +04:00
|
|
|
}
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2023-03-24 14:15:06 +03:00
|
|
|
winpr_aligned_free(context->BitmapData);
|
|
|
|
winpr_aligned_free(context);
|
2012-03-06 16:06:08 +04:00
|
|
|
}
|
|
|
|
|
2021-07-28 16:18:03 +03:00
|
|
|
#if defined(WITH_FREERDP_DEPRECATED)
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL nsc_context_set_pixel_format(NSC_CONTEXT* context, UINT32 pixel_format)
|
2019-10-04 11:13:43 +03:00
|
|
|
{
|
|
|
|
return nsc_context_set_parameters(context, NSC_COLOR_FORMAT, pixel_format);
|
|
|
|
}
|
2021-07-28 16:18:03 +03:00
|
|
|
#endif
|
2019-10-04 11:13:43 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL nsc_context_set_parameters(NSC_CONTEXT* context, NSC_PARAMETER what, UINT32 value)
|
2012-03-15 12:55:29 +04:00
|
|
|
{
|
2017-01-10 12:23:49 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
switch (what)
|
2019-10-04 11:13:43 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case NSC_COLOR_LOSS_LEVEL:
|
|
|
|
context->ColorLossLevel = value;
|
|
|
|
break;
|
|
|
|
case NSC_ALLOW_SUBSAMPLING:
|
|
|
|
context->ChromaSubsamplingLevel = value;
|
|
|
|
break;
|
|
|
|
case NSC_DYNAMIC_COLOR_FIDELITY:
|
|
|
|
context->DynamicColorFidelity = value != 0;
|
|
|
|
break;
|
|
|
|
case NSC_COLOR_FORMAT:
|
|
|
|
context->format = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
2019-10-04 11:13:43 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, UINT32 width, UINT32 height,
|
|
|
|
const BYTE* data, UINT32 length, BYTE* pDstData, UINT32 DstFormat,
|
|
|
|
UINT32 nDstStride, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
|
2016-10-14 11:01:02 +03:00
|
|
|
UINT32 nHeight, UINT32 flip)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
wStream* s;
|
2022-04-27 22:02:18 +03:00
|
|
|
wStream sbuffer = { 0 };
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL ret;
|
2019-10-04 11:13:43 +03:00
|
|
|
if (!context || !data || !pDstData)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-27 22:02:18 +03:00
|
|
|
s = Stream_StaticConstInit(&sbuffer, data, length);
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-11 15:14:17 +03:00
|
|
|
if (nDstStride == 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
nDstStride = nWidth * FreeRDPGetBytesPerPixel(DstFormat);
|
2016-04-11 15:14:17 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
switch (bpp)
|
2012-03-15 12:55:29 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
case 32:
|
|
|
|
context->format = PIXEL_FORMAT_BGRA32;
|
2012-03-15 12:55:29 +04:00
|
|
|
break;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
case 24:
|
|
|
|
context->format = PIXEL_FORMAT_BGR24;
|
2012-03-15 12:55:29 +04:00
|
|
|
break;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
case 16:
|
|
|
|
context->format = PIXEL_FORMAT_BGR16;
|
2012-03-15 12:55:29 +04:00
|
|
|
break;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
case 8:
|
|
|
|
context->format = PIXEL_FORMAT_RGB8;
|
2012-03-15 12:55:29 +04:00
|
|
|
break;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
case 4:
|
|
|
|
context->format = PIXEL_FORMAT_A4;
|
2012-03-15 12:55:29 +04:00
|
|
|
break;
|
2013-08-15 04:57:16 +04:00
|
|
|
|
2012-03-15 12:55:29 +04:00
|
|
|
default:
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2012-03-15 12:55:29 +04:00
|
|
|
}
|
|
|
|
|
2012-03-05 13:32:14 +04:00
|
|
|
context->width = width;
|
|
|
|
context->height = height;
|
2015-05-18 12:28:00 +03:00
|
|
|
ret = nsc_context_initialize(context, s);
|
2011-10-02 23:26:33 +04:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!ret)
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2015-05-18 12:28:00 +03:00
|
|
|
|
2011-10-02 23:26:33 +04:00
|
|
|
/* RLE decode */
|
2018-10-22 17:52:21 +03:00
|
|
|
{
|
|
|
|
BOOL rc;
|
|
|
|
PROFILER_ENTER(context->priv->prof_nsc_rle_decompress_data)
|
|
|
|
rc = nsc_rle_decompress_data(context);
|
|
|
|
PROFILER_EXIT(context->priv->prof_nsc_rle_decompress_data)
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-03-06 14:52:28 +04:00
|
|
|
/* Colorloss recover, Chroma supersample and AYCoCg to ARGB Conversion in one step */
|
2018-10-22 17:52:21 +03:00
|
|
|
{
|
|
|
|
BOOL rc;
|
|
|
|
PROFILER_ENTER(context->priv->prof_nsc_decode)
|
|
|
|
rc = context->decode(context);
|
|
|
|
PROFILER_EXIT(context->priv->prof_nsc_decode)
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-11 15:14:17 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy(pDstData, DstFormat, nDstStride, nXDst, nYDst, width, height,
|
|
|
|
context->BitmapData, PIXEL_FORMAT_BGRA32, 0, 0, 0, NULL, flip))
|
2016-04-11 15:14:17 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
2011-10-02 23:26:33 +04:00
|
|
|
}
|