Merge pull request #506 from llyzs/nsc

NSCodec encoder
This commit is contained in:
Marc-André Moreau 2012-03-19 21:09:24 -07:00
commit c71f5206aa
10 changed files with 929 additions and 16 deletions

View File

@ -273,6 +273,43 @@ static const uint8 nsc_stress_data[] =
, 0x00, 0x00, 0xff, 0xf7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uint8 rgb_scanline_data[] =
{
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF
};
int init_nsc_suite(void)
{
return 0;
@ -311,4 +348,31 @@ void test_nsc_decode(void)
void test_nsc_encode(void)
{
int i;
uint8* rgb_data;
STREAM* enc_stream;
NSC_CONTEXT* context;
rgb_data = (uint8 *) malloc(64 * 64 * 3);
for (i = 0; i < 64; i++)
memcpy(rgb_data + i * 64 * 3, rgb_scanline_data, 64 * 3);
context = nsc_context_new();
nsc_context_set_cpu_opt(context, CPU_SSE2);
nsc_context_set_pixel_format(context, RDP_PIXEL_FORMAT_R8G8B8);
enc_stream = stream_new(65536);
stream_clear(enc_stream);
for (i = 0; i < 30000; i++)
{
stream_set_pos(enc_stream, 0);
nsc_compose_message(context, enc_stream, rgb_data, 64, 64, 64 * 3);
}
/*freerdp_hexdump(stream_get_head(enc_stream), stream_get_length(enc_stream));*/
nsc_process_message(context, 32, 64, 64, stream_get_head(enc_stream), stream_get_length(enc_stream));
/*freerdp_hexdump(context->bmpdata, 64 * 64 * 4);*/
stream_free(enc_stream);
nsc_context_free(context);
}

View File

@ -3,6 +3,7 @@
* NSCodec Codec
*
* Copyright 2011 Samsung, Author Jiten Pathy
* Copyright 2012 Vic Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,6 +23,7 @@
#include <freerdp/api.h>
#include <freerdp/types.h>
#include <freerdp/constants.h>
#include <freerdp/utils/stream.h>
#ifdef __cplusplus
@ -51,16 +53,24 @@ struct _NSC_CONTEXT
uint16 height;
uint8* bmpdata; /* final argb values in little endian order */
uint32 bmpdata_length; /* the maximum length of the buffer that bmpdata points to */
RDP_PIXEL_FORMAT pixel_format;
/* color palette allocated by the application */
const uint8* palette;
void (*decode)(NSC_CONTEXT* context);
void (*encode)(NSC_CONTEXT* context, uint8* bmpdata, int rowstride);
NSC_CONTEXT_PRIV* priv;
};
FREERDP_API NSC_CONTEXT* nsc_context_new(void);
FREERDP_API void nsc_context_set_cpu_opt(NSC_CONTEXT* context, uint32 cpu_opt);
FREERDP_API void nsc_context_set_pixel_format(NSC_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format);
FREERDP_API void nsc_process_message(NSC_CONTEXT* context, uint16 bpp,
uint16 width, uint16 height, uint8* data, uint32 length);
FREERDP_API void nsc_compose_message(NSC_CONTEXT* context, STREAM* s,
uint8* bmpdata, int width, int height, int rowstride);
FREERDP_API void nsc_context_free(NSC_CONTEXT* context);
#ifdef __cplusplus

View File

@ -39,6 +39,8 @@ set(FREERDP_CODEC_SRCS
rfx_types.h
rfx.c
nsc.c
nsc_encode.c
nsc_encode.h
nsc_types.h
)
@ -46,6 +48,8 @@ if(WITH_SSE2)
set(FREERDP_CODEC_SRCS ${FREERDP_CODEC_SRCS}
rfx_sse2.c
rfx_sse2.h
nsc_sse2.c
nsc_sse2.h
)
set_property(SOURCE rfx_sse2.c PROPERTY COMPILE_FLAGS "-msse2")
endif()

View File

@ -26,14 +26,16 @@
#include <freerdp/utils/memory.h>
#include "nsc_types.h"
#include "nsc_encode.h"
#ifdef WITH_SSE2
#include "nsc_sse2.h"
#endif
#ifndef NSC_INIT_SIMD
#define NSC_INIT_SIMD(_nsc_context) do { } while (0)
#endif
#define ROUND_UP_TO(_b, _n) (_b + ((~(_b & (_n-1)) + 0x1) & (_n-1)))
#define MINMAX(_v,_l,_h) ((_v) < (_l) ? (_l) : ((_v) > (_h) ? (_h) : (_v)))
static void nsc_decode(NSC_CONTEXT* context)
{
uint16 x;
@ -258,12 +260,17 @@ NSC_CONTEXT* nsc_context_new(void)
nsc_context->priv = xnew(NSC_CONTEXT_PRIV);
nsc_context->decode = nsc_decode;
nsc_context->encode = nsc_encode;
PROFILER_CREATE(nsc_context->priv->prof_nsc_rle_decompress_data, "nsc_rle_decompress_data");
PROFILER_CREATE(nsc_context->priv->prof_nsc_decode, "nsc_decode");
PROFILER_CREATE(nsc_context->priv->prof_nsc_rle_compress_data, "nsc_rle_compress_data");
PROFILER_CREATE(nsc_context->priv->prof_nsc_encode, "nsc_encode");
/* Default encoding parameters */
nsc_context->nsc_stream.ColorLossLevel = 3;
nsc_context->nsc_stream.ChromaSubSamplingLevel = 1;
return nsc_context;
}
@ -273,6 +280,35 @@ void nsc_context_set_cpu_opt(NSC_CONTEXT* context, uint32 cpu_opt)
NSC_INIT_SIMD(context);
}
void nsc_context_set_pixel_format(NSC_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format)
{
context->pixel_format = pixel_format;
switch (pixel_format)
{
case RDP_PIXEL_FORMAT_B8G8R8A8:
case RDP_PIXEL_FORMAT_R8G8B8A8:
context->bpp = 32;
break;
case RDP_PIXEL_FORMAT_B8G8R8:
case RDP_PIXEL_FORMAT_R8G8B8:
context->bpp = 24;
break;
case RDP_PIXEL_FORMAT_B5G6R5_LE:
case RDP_PIXEL_FORMAT_R5G6B5_LE:
context->bpp = 16;
break;
case RDP_PIXEL_FORMAT_P4_PLANER:
context->bpp = 4;
break;
case RDP_PIXEL_FORMAT_P8:
context->bpp = 8;
break;
default:
context->bpp = 0;
break;
}
}
void nsc_process_message(NSC_CONTEXT* context, uint16 bpp,
uint16 width, uint16 height, uint8* data, uint32 length)
{

View File

@ -0,0 +1,362 @@
/**
* FreeRDP: A Remote Desktop Protocol client.
* NSCodec Encoder
*
* Copyright 2012 Vic Lee
*
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <freerdp/codec/nsc.h>
#include <freerdp/utils/memory.h>
#include "nsc_types.h"
#include "nsc_encode.h"
static void nsc_context_initialize_encode(NSC_CONTEXT* context)
{
int i;
uint32 length;
uint32 tempWidth;
uint32 tempHeight;
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 + 16;
if (length > context->priv->plane_buf_length)
{
for (i = 0; i < 5; i++)
context->priv->plane_buf[i] = (uint8*) xrealloc(context->priv->plane_buf[i], length);
context->priv->plane_buf_length = length;
}
if (context->nsc_stream.ChromaSubSamplingLevel > 0)
{
context->OrgByteCount[0] = tempWidth * context->height;
context->OrgByteCount[1] = tempWidth * tempHeight / 4;
context->OrgByteCount[2] = tempWidth * tempHeight / 4;
context->OrgByteCount[3] = context->width * context->height;
}
else
{
context->OrgByteCount[0] = context->width * context->height;
context->OrgByteCount[1] = context->width * context->height;
context->OrgByteCount[2] = context->width * context->height;
context->OrgByteCount[3] = context->width * context->height;
}
}
static void nsc_encode_argb_to_aycocg(NSC_CONTEXT* context, uint8* bmpdata, int rowstride)
{
uint16 x;
uint16 y;
uint16 rw;
uint8 ccl;
uint8* src;
uint8* yplane;
uint8* coplane;
uint8* cgplane;
uint8* aplane;
sint16 r_val;
sint16 g_val;
sint16 b_val;
uint8 a_val;
uint32 tempWidth;
uint32 tempHeight;
tempWidth = ROUND_UP_TO(context->width, 8);
tempHeight = ROUND_UP_TO(context->height, 2);
rw = (context->nsc_stream.ChromaSubSamplingLevel > 0 ? tempWidth : context->width);
ccl = context->nsc_stream.ColorLossLevel;
yplane = context->priv->plane_buf[0];
coplane = context->priv->plane_buf[1];
cgplane = context->priv->plane_buf[2];
aplane = context->priv->plane_buf[3];
for (y = 0; y < context->height; y++)
{
src = bmpdata + (context->height - 1 - y) * rowstride;
yplane = context->priv->plane_buf[0] + y * rw;
coplane = context->priv->plane_buf[1] + y * rw;
cgplane = context->priv->plane_buf[2] + y * rw;
aplane = context->priv->plane_buf[3] + y * context->width;
for (x = 0; x < context->width; x++)
{
switch (context->pixel_format)
{
case RDP_PIXEL_FORMAT_B8G8R8A8:
b_val = *src++;
g_val = *src++;
r_val = *src++;
a_val = *src++;
break;
case RDP_PIXEL_FORMAT_R8G8B8A8:
r_val = *src++;
g_val = *src++;
b_val = *src++;
a_val = *src++;
break;
case RDP_PIXEL_FORMAT_B8G8R8:
b_val = *src++;
g_val = *src++;
r_val = *src++;
a_val = 0xFF;
break;
case RDP_PIXEL_FORMAT_R8G8B8:
r_val = *src++;
g_val = *src++;
b_val = *src++;
a_val = 0xFF;
break;
case RDP_PIXEL_FORMAT_B5G6R5_LE:
b_val = (sint16) (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5));
g_val = (sint16) ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3));
r_val = (sint16) ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07));
a_val = 0xFF;
src += 2;
break;
case RDP_PIXEL_FORMAT_R5G6B5_LE:
r_val = (sint16) (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5));
g_val = (sint16) ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3));
b_val = (sint16) ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07));
a_val = 0xFF;
src += 2;
break;
case RDP_PIXEL_FORMAT_P4_PLANER:
{
int shift;
uint8 idx;
shift = (7 - (x % 8));
idx = ((*src) >> shift) & 1;
idx |= (((*(src + 1)) >> shift) & 1) << 1;
idx |= (((*(src + 2)) >> shift) & 1) << 2;
idx |= (((*(src + 3)) >> shift) & 1) << 3;
idx *= 3;
r_val = (sint16) context->palette[idx];
g_val = (sint16) context->palette[idx + 1];
b_val = (sint16) context->palette[idx + 2];
if (shift == 0)
src += 4;
}
a_val = 0xFF;
break;
case RDP_PIXEL_FORMAT_P8:
{
int idx = (*src) * 3;
r_val = (sint16) context->palette[idx];
g_val = (sint16) context->palette[idx + 1];
b_val = (sint16) context->palette[idx + 2];
src++;
}
a_val = 0xFF;
break;
default:
r_val = g_val = b_val = a_val = 0;
break;
}
*yplane++ = (uint8) ((r_val >> 2) + (g_val >> 1) + (b_val >> 2));
/* Perform color loss reduction here */
*coplane++ = (uint8) ((r_val - b_val) >> ccl);
*cgplane++ = (uint8) ((-(r_val >> 1) + g_val - (b_val >> 1)) >> ccl);
*aplane++ = a_val;
}
if (context->nsc_stream.ChromaSubSamplingLevel > 0 && (x % 2) == 1)
{
*yplane = *(yplane - 1);
*coplane = *(coplane - 1);
*cgplane = *(cgplane - 1);
}
}
if (context->nsc_stream.ChromaSubSamplingLevel > 0 && (y % 2) == 1)
{
memcpy(yplane + rw, yplane, rw);
memcpy(coplane + rw, coplane, rw);
memcpy(cgplane + rw, cgplane, rw);
}
}
static void nsc_encode_subsampling(NSC_CONTEXT* context)
{
uint16 x;
uint16 y;
uint8* co_dst;
uint8* cg_dst;
sint8* co_src0;
sint8* co_src1;
sint8* cg_src0;
sint8* cg_src1;
uint32 tempWidth;
uint32 tempHeight;
tempWidth = ROUND_UP_TO(context->width, 8);
tempHeight = ROUND_UP_TO(context->height, 2);
for (y = 0; y < tempHeight >> 1; y++)
{
co_dst = context->priv->plane_buf[1] + y * (tempWidth >> 1);
cg_dst = context->priv->plane_buf[2] + y * (tempWidth >> 1);
co_src0 = (sint8*) context->priv->plane_buf[1] + (y << 1) * tempWidth;
co_src1 = co_src0 + tempWidth;
cg_src0 = (sint8*) context->priv->plane_buf[2] + (y << 1) * tempWidth;
cg_src1 = cg_src0 + tempWidth;
for (x = 0; x < tempWidth >> 1; x++)
{
*co_dst++ = (uint8) (((sint16) *co_src0 + (sint16) *(co_src0 + 1) +
(sint16) *co_src1 + (sint16) *(co_src1 + 1)) >> 2);
*cg_dst++ = (uint8) (((sint16) *cg_src0 + (sint16) *(cg_src0 + 1) +
(sint16) *cg_src1 + (sint16) *(cg_src1 + 1)) >> 2);
co_src0 += 2;
co_src1 += 2;
cg_src0 += 2;
cg_src1 += 2;
}
}
}
void nsc_encode(NSC_CONTEXT* context, uint8* bmpdata, int rowstride)
{
nsc_encode_argb_to_aycocg(context, bmpdata, rowstride);
if (context->nsc_stream.ChromaSubSamplingLevel > 0)
{
nsc_encode_subsampling(context);
}
}
static uint32 nsc_rle_encode(uint8* in, uint8* out, uint32 origsz)
{
uint32 left;
uint32 runlength = 1;
uint32 planesize = 0;
left = origsz;
/**
* We quit the loop if the running compressed size is larger than the original.
* In such cases data will be sent uncompressed.
*/
while (left > 4 && planesize < origsz - 4)
{
if (left > 5 && *in == *(in + 1))
{
runlength++;
}
else if (runlength == 1)
{
*out++ = *in;
planesize++;
}
else if (runlength < 256)
{
*out++ = *in;
*out++ = *in;
*out++ = runlength - 2;
runlength = 1;
planesize += 3;
}
else
{
*out++ = *in;
*out++ = *in;
*out++ = 0xFF;
*out++ = (runlength & 0x000000FF);
*out++ = (runlength & 0x0000FF00) >> 8;
*out++ = (runlength & 0x00FF0000) >> 16;
*out++ = (runlength & 0xFF000000) >> 24;
runlength = 1;
planesize += 7;
}
in++;
left--;
}
if (planesize < origsz - 4)
{
memcpy(out, in, 4);
}
planesize += 4;
return planesize;
}
static void nsc_rle_compress_data(NSC_CONTEXT* context)
{
uint16 i;
uint8* rle;
uint32 origsize;
uint32 planesize;
rle = context->nsc_stream.Planes;
for (i = 0; i < 4; i++)
{
origsize = context->OrgByteCount[i];
if (origsize == 0)
{
planesize = 0;
}
else
{
planesize = nsc_rle_encode(context->priv->plane_buf[i],
context->priv->plane_buf[4], origsize);
if (planesize < origsize)
memcpy(context->priv->plane_buf[i], context->priv->plane_buf[4], planesize);
else
planesize = origsize;
}
context->nsc_stream.PlaneByteCount[i] = planesize;
}
}
void nsc_compose_message(NSC_CONTEXT* context, STREAM* s,
uint8* bmpdata, int width, int height, int rowstride)
{
int i;
context->width = width;
context->height = height;
nsc_context_initialize_encode(context);
/* ARGB to AYCoCg conversion, chroma subsampling and colorloss reduction */
PROFILER_ENTER(context->priv->prof_nsc_encode);
context->encode(context, bmpdata, rowstride);
PROFILER_EXIT(context->priv->prof_nsc_encode);
/* RLE encode */
PROFILER_ENTER(context->priv->prof_nsc_rle_compress_data);
nsc_rle_compress_data(context);
PROFILER_EXIT(context->priv->prof_nsc_rle_compress_data);
/* Assemble the NSCodec message into stream */
stream_check_size(s, 20);
stream_write_uint32(s, context->nsc_stream.PlaneByteCount[0]); /* LumaPlaneByteCount (4 bytes) */
stream_write_uint32(s, context->nsc_stream.PlaneByteCount[1]); /* OrangeChromaPlaneByteCount (4 bytes) */
stream_write_uint32(s, context->nsc_stream.PlaneByteCount[2]); /* GreenChromaPlaneByteCount (4 bytes) */
stream_write_uint32(s, context->nsc_stream.PlaneByteCount[3]); /* AlphaPlaneByteCount (4 bytes) */
stream_write_uint8(s, context->nsc_stream.ColorLossLevel); /* ColorLossLevel (1 byte) */
stream_write_uint8(s, context->nsc_stream.ChromaSubSamplingLevel); /* ChromaSubsamplingLevel (1 byte) */
stream_write_uint16(s, 0); /* Reserved (2 bytes) */
for (i = 0; i < 4; i++)
{
if (context->nsc_stream.PlaneByteCount[i] > 0)
{
stream_check_size(s, context->nsc_stream.PlaneByteCount[i]);
stream_write(s, context->priv->plane_buf[i], context->nsc_stream.PlaneByteCount[i]);
}
}
}

View File

@ -0,0 +1,25 @@
/**
* FreeRDP: A Remote Desktop Protocol client.
* NSCodec Encoder
*
* Copyright 2012 Vic Lee
*
* 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.
*/
#ifndef __NSC_ENCODE_H
#define __NSC_ENCODE_H
void nsc_encode(NSC_CONTEXT* context, uint8* bmpdata, int rowstride);
#endif

345
libfreerdp-codec/nsc_sse2.c Normal file
View File

@ -0,0 +1,345 @@
/**
* FreeRDP: A Remote Desktop Protocol client.
* NSCodec Library - SSE2 Optimizations
*
* Copyright 2012 Vic Lee
*
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xmmintrin.h>
#include <emmintrin.h>
#include "nsc_types.h"
#include "nsc_sse2.h"
static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, uint8* bmpdata, int rowstride)
{
uint16 x;
uint16 y;
uint16 rw;
uint8 ccl;
uint8* src;
uint8* yplane;
uint8* coplane;
uint8* cgplane;
uint8* aplane;
__m128i r_val;
__m128i g_val;
__m128i b_val;
__m128i a_val;
__m128i y_val;
__m128i co_val;
__m128i cg_val;
uint32 tempWidth;
uint32 tempHeight;
tempWidth = ROUND_UP_TO(context->width, 8);
tempHeight = ROUND_UP_TO(context->height, 2);
rw = (context->nsc_stream.ChromaSubSamplingLevel > 0 ? tempWidth : context->width);
ccl = context->nsc_stream.ColorLossLevel;
yplane = context->priv->plane_buf[0];
coplane = context->priv->plane_buf[1];
cgplane = context->priv->plane_buf[2];
aplane = context->priv->plane_buf[3];
for (y = 0; y < context->height; y++)
{
src = bmpdata + (context->height - 1 - y) * rowstride;
yplane = context->priv->plane_buf[0] + y * rw;
coplane = context->priv->plane_buf[1] + y * rw;
cgplane = context->priv->plane_buf[2] + y * rw;
aplane = context->priv->plane_buf[3] + y * context->width;
for (x = 0; x < context->width; x += 8)
{
switch (context->pixel_format)
{
case RDP_PIXEL_FORMAT_B8G8R8A8:
b_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), *(src + 8), *(src + 4), *src);
g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), *(src + 9), *(src + 5), *(src + 1));
r_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), *(src + 10), *(src + 6), *(src + 2));
a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15), *(src + 11), *(src + 7), *(src + 3));
src += 32;
break;
case RDP_PIXEL_FORMAT_R8G8B8A8:
r_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), *(src + 8), *(src + 4), *src);
g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), *(src + 9), *(src + 5), *(src + 1));
b_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), *(src + 10), *(src + 6), *(src + 2));
a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15), *(src + 11), *(src + 7), *(src + 3));
src += 32;
break;
case RDP_PIXEL_FORMAT_B8G8R8:
b_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9), *(src + 6), *(src + 3), *src);
g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10), *(src + 7), *(src + 4), *(src + 1));
r_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11), *(src + 8), *(src + 5), *(src + 2));
a_val = _mm_set1_epi16(0xFF);
src += 24;
break;
case RDP_PIXEL_FORMAT_R8G8B8:
r_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9), *(src + 6), *(src + 3), *src);
g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10), *(src + 7), *(src + 4), *(src + 1));
b_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11), *(src + 8), *(src + 5), *(src + 2));
a_val = _mm_set1_epi16(0xFF);
src += 24;
break;
case RDP_PIXEL_FORMAT_B5G6R5_LE:
b_val = _mm_set_epi16(
(((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)),
(((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)),
(((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)),
(((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)),
(((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)),
(((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)),
(((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)),
(((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)));
g_val = _mm_set_epi16(
((((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)),
((((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)),
((((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)),
((((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)),
((((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)),
((((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)),
((((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)),
((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)));
r_val = _mm_set_epi16(
((((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)),
((((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)),
((((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)),
((((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)),
((((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)),
((((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)),
((((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)),
((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)));
a_val = _mm_set1_epi16(0xFF);
src += 16;
break;
case RDP_PIXEL_FORMAT_R5G6B5_LE:
r_val = _mm_set_epi16(
(((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)),
(((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)),
(((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)),
(((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)),
(((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)),
(((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)),
(((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)),
(((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)));
g_val = _mm_set_epi16(
((((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)),
((((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)),
((((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)),
((((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)),
((((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)),
((((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)),
((((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)),
((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)));
b_val = _mm_set_epi16(
((((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)),
((((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)),
((((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)),
((((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)),
((((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)),
((((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)),
((((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)),
((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)));
a_val = _mm_set1_epi16(0xFF);
src += 16;
break;
case RDP_PIXEL_FORMAT_P4_PLANER:
{
int shift;
uint8 idx[8];
for (shift = 7; shift >= 0; shift--)
{
idx[shift] = ((*src) >> shift) & 1;
idx[shift] |= (((*(src + 1)) >> shift) & 1) << 1;
idx[shift] |= (((*(src + 2)) >> shift) & 1) << 2;
idx[shift] |= (((*(src + 3)) >> shift) & 1) << 3;
idx[shift] *= 3;
}
r_val = _mm_set_epi16(
context->palette[idx[0]],
context->palette[idx[1]],
context->palette[idx[2]],
context->palette[idx[3]],
context->palette[idx[4]],
context->palette[idx[5]],
context->palette[idx[6]],
context->palette[idx[7]]);
g_val = _mm_set_epi16(
context->palette[idx[0] + 1],
context->palette[idx[1] + 1],
context->palette[idx[2] + 1],
context->palette[idx[3] + 1],
context->palette[idx[4] + 1],
context->palette[idx[5] + 1],
context->palette[idx[6] + 1],
context->palette[idx[7] + 1]);
b_val = _mm_set_epi16(
context->palette[idx[0] + 2],
context->palette[idx[1] + 2],
context->palette[idx[2] + 2],
context->palette[idx[3] + 2],
context->palette[idx[4] + 2],
context->palette[idx[5] + 2],
context->palette[idx[6] + 2],
context->palette[idx[7] + 2]);
src += 4;
}
a_val = _mm_set1_epi16(0xFF);
break;
case RDP_PIXEL_FORMAT_P8:
{
r_val = _mm_set_epi16(
context->palette[(*(src + 7)) * 3],
context->palette[(*(src + 6)) * 3],
context->palette[(*(src + 5)) * 3],
context->palette[(*(src + 4)) * 3],
context->palette[(*(src + 3)) * 3],
context->palette[(*(src + 2)) * 3],
context->palette[(*(src + 1)) * 3],
context->palette[(*src) * 3]);
g_val = _mm_set_epi16(
context->palette[(*(src + 7)) * 3 + 1],
context->palette[(*(src + 6)) * 3 + 1],
context->palette[(*(src + 5)) * 3 + 1],
context->palette[(*(src + 4)) * 3 + 1],
context->palette[(*(src + 3)) * 3 + 1],
context->palette[(*(src + 2)) * 3 + 1],
context->palette[(*(src + 1)) * 3 + 1],
context->palette[(*src) * 3 + 1]);
b_val = _mm_set_epi16(
context->palette[(*(src + 7)) * 3 + 2],
context->palette[(*(src + 6)) * 3 + 2],
context->palette[(*(src + 5)) * 3 + 2],
context->palette[(*(src + 4)) * 3 + 2],
context->palette[(*(src + 3)) * 3 + 2],
context->palette[(*(src + 2)) * 3 + 2],
context->palette[(*(src + 1)) * 3 + 2],
context->palette[(*src) * 3 + 2]);
src += 8;
}
a_val = _mm_set1_epi16(0xFF);
break;
default:
r_val = g_val = b_val = a_val = _mm_set1_epi16(0);
break;
}
y_val = _mm_srai_epi16(r_val, 2);
y_val = _mm_add_epi16(y_val, _mm_srai_epi16(g_val, 1));
y_val = _mm_add_epi16(y_val, _mm_srai_epi16(b_val, 2));
co_val = _mm_sub_epi16(r_val, b_val);
co_val = _mm_srai_epi16(co_val, ccl);
cg_val = _mm_sub_epi16(g_val, _mm_srai_epi16(r_val, 1));
cg_val = _mm_sub_epi16(cg_val, _mm_srai_epi16(b_val, 1));
cg_val = _mm_srai_epi16(cg_val, ccl);
y_val = _mm_packus_epi16(y_val, y_val);
_mm_storeu_si128((__m128i*) yplane, y_val);
co_val = _mm_packs_epi16(co_val, co_val);
_mm_storeu_si128((__m128i*) coplane, co_val);
cg_val = _mm_packs_epi16(cg_val, cg_val);
_mm_storeu_si128((__m128i*) cgplane, cg_val);
a_val = _mm_packus_epi16(a_val, a_val);
_mm_storeu_si128((__m128i*) aplane, a_val);
yplane += 8;
coplane += 8;
cgplane += 8;
aplane += 8;
}
if (context->nsc_stream.ChromaSubSamplingLevel > 0 && (context->width % 2) == 1)
{
context->priv->plane_buf[0][y * rw + context->width] = context->priv->plane_buf[0][y * rw + context->width - 1];
context->priv->plane_buf[1][y * rw + context->width] = context->priv->plane_buf[1][y * rw + context->width - 1];
context->priv->plane_buf[2][y * rw + context->width] = context->priv->plane_buf[2][y * rw + context->width - 1];
}
}
if (context->nsc_stream.ChromaSubSamplingLevel > 0 && (y % 2) == 1)
{
memcpy(yplane + rw, yplane, rw);
memcpy(coplane + rw, coplane, rw);
memcpy(cgplane + rw, cgplane, rw);
}
}
static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context)
{
uint16 x;
uint16 y;
uint8* co_dst;
uint8* cg_dst;
sint8* co_src0;
sint8* co_src1;
sint8* cg_src0;
sint8* cg_src1;
uint32 tempWidth;
uint32 tempHeight;
__m128i t;
__m128i val;
__m128i mask = _mm_set1_epi16(0xFF);
tempWidth = ROUND_UP_TO(context->width, 8);
tempHeight = ROUND_UP_TO(context->height, 2);
for (y = 0; y < tempHeight >> 1; y++)
{
co_dst = context->priv->plane_buf[1] + y * (tempWidth >> 1);
cg_dst = context->priv->plane_buf[2] + y * (tempWidth >> 1);
co_src0 = (sint8*) context->priv->plane_buf[1] + (y << 1) * tempWidth;
co_src1 = co_src0 + tempWidth;
cg_src0 = (sint8*) context->priv->plane_buf[2] + (y << 1) * tempWidth;
cg_src1 = cg_src0 + tempWidth;
for (x = 0; x < tempWidth >> 1; x += 8)
{
t = _mm_loadu_si128((__m128i*) co_src0);
t = _mm_avg_epu8(t, _mm_loadu_si128((__m128i*) co_src1));
val = _mm_and_si128(_mm_srli_si128(t, 1), mask);
val = _mm_avg_epu16(val, _mm_and_si128(t, mask));
val = _mm_packus_epi16(val, val);
_mm_storeu_si128((__m128i*) co_dst, val);
co_dst += 8;
co_src0 += 16;
co_src1 += 16;
t = _mm_loadu_si128((__m128i*) cg_src0);
t = _mm_avg_epu8(t, _mm_loadu_si128((__m128i*) cg_src1));
val = _mm_and_si128(_mm_srli_si128(t, 1), mask);
val = _mm_avg_epu16(val, _mm_and_si128(t, mask));
val = _mm_packus_epi16(val, val);
_mm_storeu_si128((__m128i*) cg_dst, val);
cg_dst += 8;
cg_src0 += 16;
cg_src1 += 16;
}
}
}
static void nsc_encode_sse2(NSC_CONTEXT* context, uint8* bmpdata, int rowstride)
{
nsc_encode_argb_to_aycocg_sse2(context, bmpdata, rowstride);
if (context->nsc_stream.ChromaSubSamplingLevel > 0)
{
nsc_encode_subsampling_sse2(context);
}
}
void nsc_init_sse2(NSC_CONTEXT* context)
{
IF_PROFILER(context->priv->prof_nsc_encode->name = "nsc_encode_sse2");
context->encode = nsc_encode_sse2;
}

View File

@ -0,0 +1,31 @@
/**
* FreeRDP: A Remote Desktop Protocol client.
* NSCodec Library - SSE2 Optimizations
*
* Copyright 2012 Vic Lee
*
* 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.
*/
#ifndef __NSC_SSE2_H
#define __NSC_SSE2_H
#include <freerdp/codec/nsc.h>
void nsc_init_sse2(NSC_CONTEXT* context);
#ifndef NSC_INIT_SIMD
#define NSC_INIT_SIMD(_context) nsc_init_sse2(_context)
#endif
#endif /* __NSC_SSE2_H */

View File

@ -25,9 +25,12 @@
#include <freerdp/utils/debug.h>
#include <freerdp/utils/profiler.h>
#define ROUND_UP_TO(_b, _n) (_b + ((~(_b & (_n-1)) + 0x1) & (_n-1)))
#define MINMAX(_v,_l,_h) ((_v) < (_l) ? (_l) : ((_v) > (_h) ? (_h) : (_v)))
struct _NSC_CONTEXT_PRIV
{
uint8* plane_buf[4]; /* Decompressed Plane Buffers in the respective order */
uint8* plane_buf[5]; /* Decompressed Plane Buffers in the respective order */
uint32 plane_buf_length; /* Lengths of each plane buffer */
/* profilers */

View File

@ -30,6 +30,7 @@
#include <freerdp/utils/memory.h>
#include <freerdp/utils/thread.h>
#include <freerdp/codec/rfx.h>
#include <freerdp/codec/nsc.h>
#include <freerdp/listener.h>
#include <freerdp/channels/wtsvc.h>
@ -47,6 +48,7 @@ struct test_peer_context
rdpContext _p;
RFX_CONTEXT* rfx_context;
NSC_CONTEXT* nsc_context;
STREAM* s;
uint8* icon_data;
uint8* bg_data;
@ -69,6 +71,9 @@ void test_peer_context_new(freerdp_peer* client, testPeerContext* context)
context->rfx_context->height = client->settings->height;
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_R8G8B8);
context->nsc_context = nsc_context_new();
nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8);
context->s = stream_new(65536);
context->icon_x = -1;
@ -90,6 +95,7 @@ void test_peer_context_free(freerdp_peer* client, testPeerContext* context)
xfree(context->icon_data);
xfree(context->bg_data);
rfx_context_free(context->rfx_context);
nsc_context_free(context->nsc_context);
if (context->debug_channel)
{
WTSVirtualChannelClose(context->debug_channel);
@ -124,7 +130,7 @@ static void test_peer_draw_background(freerdp_peer* client)
uint8* rgb_data;
int size;
if (!client->settings->rfx_codec)
if (!client->settings->rfx_codec && !client->settings->ns_codec)
return;
s = test_peer_stream_init(context);
@ -138,15 +144,24 @@ static void test_peer_draw_background(freerdp_peer* client)
rgb_data = xmalloc(size);
memset(rgb_data, 0xA0, size);
rfx_compose_message(context->rfx_context, s,
&rect, 1, rgb_data, rect.width, rect.height, rect.width * 3);
if (client->settings->rfx_codec)
{
rfx_compose_message(context->rfx_context, s,
&rect, 1, rgb_data, rect.width, rect.height, rect.width * 3);
cmd->codecID = client->settings->rfx_codec_id;
}
else
{
nsc_compose_message(context->nsc_context, s,
rgb_data, rect.width, rect.height, rect.width * 3);
cmd->codecID = client->settings->ns_codec_id;
}
cmd->destLeft = 0;
cmd->destTop = 0;
cmd->destRight = rect.width;
cmd->destBottom = rect.height;
cmd->bpp = 32;
cmd->codecID = client->settings->rfx_codec_id;
cmd->width = rect.width;
cmd->height = rect.height;
cmd->bitmapDataLength = stream_get_length(s);
@ -165,7 +180,7 @@ static void test_peer_load_icon(freerdp_peer* client)
uint8* rgb_data;
int c;
if (!client->settings->rfx_codec)
if (!client->settings->rfx_codec && !client->settings->ns_codec)
return;
if ((fp = fopen("test_icon.ppm", "r")) == NULL)
@ -209,7 +224,7 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
if (client->update->dump_rfx)
return;
if (!client->settings->rfx_codec || !context)
if (!context)
return;
if (context->icon_width < 1 || !context->activated)
return;
@ -222,15 +237,24 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
if (context->icon_x >= 0)
{
s = test_peer_stream_init(context);
rfx_compose_message(context->rfx_context, s,
&rect, 1, context->bg_data, rect.width, rect.height, rect.width * 3);
if (client->settings->rfx_codec)
{
rfx_compose_message(context->rfx_context, s,
&rect, 1, context->bg_data, rect.width, rect.height, rect.width * 3);
cmd->codecID = client->settings->rfx_codec_id;
}
else
{
nsc_compose_message(context->nsc_context, s,
context->bg_data, rect.width, rect.height, rect.width * 3);
cmd->codecID = client->settings->ns_codec_id;
}
cmd->destLeft = context->icon_x;
cmd->destTop = context->icon_y;
cmd->destRight = context->icon_x + context->icon_width;
cmd->destBottom = context->icon_y + context->icon_height;
cmd->bpp = 32;
cmd->codecID = client->settings->rfx_codec_id;
cmd->width = context->icon_width;
cmd->height = context->icon_height;
cmd->bitmapDataLength = stream_get_length(s);
@ -239,15 +263,24 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
}
s = test_peer_stream_init(context);
rfx_compose_message(context->rfx_context, s,
&rect, 1, context->icon_data, rect.width, rect.height, rect.width * 3);
if (client->settings->rfx_codec)
{
rfx_compose_message(context->rfx_context, s,
&rect, 1, context->icon_data, rect.width, rect.height, rect.width * 3);
cmd->codecID = client->settings->rfx_codec_id;
}
else
{
nsc_compose_message(context->nsc_context, s,
context->icon_data, rect.width, rect.height, rect.width * 3);
cmd->codecID = client->settings->ns_codec_id;
}
cmd->destLeft = x;
cmd->destTop = y;
cmd->destRight = x + context->icon_width;
cmd->destBottom = y + context->icon_height;
cmd->bpp = 32;
cmd->codecID = client->settings->rfx_codec_id;
cmd->width = context->icon_width;
cmd->height = context->icon_height;
cmd->bitmapDataLength = stream_get_length(s);