diff --git a/channels/serial/client/serial_main.c b/channels/serial/client/serial_main.c index df4700e9f..fb6b07915 100644 --- a/channels/serial/client/serial_main.c +++ b/channels/serial/client/serial_main.c @@ -67,7 +67,6 @@ struct _SERIAL_DEVICE wQueue* queue; LIST* pending_irps; - HANDLE in_event; fd_set read_fds; fd_set write_fds; @@ -330,7 +329,9 @@ static void* serial_thread_func(void* arg) if (WaitForSingleObject(serial->stopEvent, 0) == WAIT_OBJECT_0) break; - if (WaitForSingleObject(Queue_Event(serial->queue), 10) == WAIT_OBJECT_0) + status = WaitForSingleObject(Queue_Event(serial->queue), 10); + + if ((status != WAIT_OBJECT_0) && (status != WAIT_TIMEOUT)) break; serial->nfds = 1; @@ -341,18 +342,13 @@ static void* serial_thread_func(void* arg) serial->tv.tv_usec = 0; serial->select_timeout = 0; - irp = (IRP*) Queue_Dequeue(serial->queue); - - if (irp) - serial_process_irp(serial, irp); - - status = WaitForSingleObject(serial->in_event, 0); - - if ((status == WAIT_OBJECT_0) || (status == WAIT_TIMEOUT)) + if (status == WAIT_OBJECT_0) { - if (serial_check_fds(serial)) - ResetEvent(serial->in_event); + if ((irp = (IRP*) Queue_Dequeue(serial->queue))) + serial_process_irp(serial, irp); } + + serial_check_fds(serial); } return NULL; @@ -423,7 +419,6 @@ static void serial_abort_single_io(SERIAL_DEVICE* serial, UINT32 file_id, UINT32 Stream_Write_UINT32(irp->output, 0); irp->Complete(irp); - SetEvent(serial->in_event); break; } @@ -460,8 +455,6 @@ static void serial_check_for_events(SERIAL_DEVICE* serial) prev = irp; irp = (IRP*) list_next(serial->pending_irps, irp); list_remove(serial->pending_irps, prev); - - SetEvent(serial->in_event); } } @@ -537,7 +530,6 @@ static void serial_handle_async_irp(SERIAL_DEVICE* serial, IRP* irp) irp->IoStatus = STATUS_PENDING; list_enqueue(serial->pending_irps, irp); - SetEvent(serial->in_event); } static void __serial_check_fds(SERIAL_DEVICE* serial) @@ -599,10 +591,7 @@ static void __serial_check_fds(SERIAL_DEVICE* serial) irp = (IRP*) list_next(serial->pending_irps, irp); if (irp_completed || (prev->IoStatus == STATUS_SUCCESS)) - { list_remove(serial->pending_irps, prev); - SetEvent(serial->in_event); - } } } @@ -692,7 +681,7 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) name = device->Name; path = device->Path; - if (name[0] && path[0]) + if ((name && name[0]) && (path && path[0])) { serial = (SERIAL_DEVICE*) malloc(sizeof(SERIAL_DEVICE)); ZeroMemory(serial, sizeof(SERIAL_DEVICE)); @@ -711,7 +700,6 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) serial->path = path; serial->queue = Queue_New(TRUE, -1, -1); serial->pending_irps = list_new(); - serial->in_event = CreateEvent(NULL, TRUE, FALSE, NULL); serial->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); diff --git a/client/common/cmdline.c b/client/common/cmdline.c index df714be88..afe978df2 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -865,13 +865,10 @@ int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, int* } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); - if (detect_status == 0) - { - if ((status <= COMMAND_LINE_ERROR) && (status >= COMMAND_LINE_ERROR_LAST)) - detect_status = -1; - } + if ((status <= COMMAND_LINE_ERROR) && (status >= COMMAND_LINE_ERROR_LAST)) + detect_status = -1; - return 0; + return detect_status; } int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, int* count) @@ -901,13 +898,10 @@ int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, int* c } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); - if (detect_status == 0) - { - if ((status <= COMMAND_LINE_ERROR) && (status >= COMMAND_LINE_ERROR_LAST)) - detect_status = -1; - } + if ((status <= COMMAND_LINE_ERROR) && (status >= COMMAND_LINE_ERROR_LAST)) + detect_status = -1; - return 0; + return detect_status; } BOOL freerdp_client_detect_command_line(int argc, char** argv, DWORD* flags) @@ -1034,6 +1028,7 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter); } + arg = CommandLineFindArgumentA(args, "v"); arg = args; @@ -1668,7 +1663,7 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin FillMemory(arg->Value, strlen(arg->Value), '*'); } - return 1; + return status; } int freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* settings, char* name, void* data) diff --git a/include/freerdp/codec/bitmap.h b/include/freerdp/codec/bitmap.h index a0a2e4c82..c652a921b 100644 --- a/include/freerdp/codec/bitmap.h +++ b/include/freerdp/codec/bitmap.h @@ -23,6 +23,12 @@ #include #include +#include +#include + FREERDP_API BOOL bitmap_decompress(BYTE* srcData, BYTE* dstData, int width, int height, int size, int srcBpp, int dstBpp); +FREERDP_API int freerdp_bitmap_compress(char* in_data, int width, int height, + wStream* s, int bpp, int byte_limit, int start_line, wStream* temp_s, int e); + #endif /* FREERDP_CODEC_BITMAP_H */ diff --git a/libfreerdp/codec/CMakeLists.txt b/libfreerdp/codec/CMakeLists.txt index 8895848b2..19533017b 100644 --- a/libfreerdp/codec/CMakeLists.txt +++ b/libfreerdp/codec/CMakeLists.txt @@ -20,9 +20,10 @@ set(MODULE_PREFIX "FREERDP_CODEC") set(${MODULE_PREFIX}_SRCS dsp.c - bitmap.c color.c audio.c + bitmap_decode.c + bitmap_encode.c rfx_bitstream.h rfx_constants.h rfx_decode.c diff --git a/libfreerdp/codec/bitmap.c b/libfreerdp/codec/bitmap_decode.c similarity index 99% rename from libfreerdp/codec/bitmap.c rename to libfreerdp/codec/bitmap_decode.c index 598017081..431a213a8 100644 --- a/libfreerdp/codec/bitmap.c +++ b/libfreerdp/codec/bitmap_decode.c @@ -1,6 +1,6 @@ /** * FreeRDP: A Remote Desktop Protocol Implementation - * Compressed Bitmap + * Bitmap Decompression * * Copyright 2011 Jay Sorg * diff --git a/libfreerdp/codec/bitmap_encode.c b/libfreerdp/codec/bitmap_encode.c new file mode 100644 index 000000000..5cdca0b93 --- /dev/null +++ b/libfreerdp/codec/bitmap_encode.c @@ -0,0 +1,1574 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Bitmap Compression + * + * Copyright 2004-2012 Jay Sorg + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#define GETPIXEL8(d, x, y, w) (*(((unsigned char*)d) + ((y) * (w) + (x)))) +#define GETPIXEL16(d, x, y, w) (*(((unsigned short*)d) + ((y) * (w) + (x)))) +#define GETPIXEL32(d, x, y, w) (*(((unsigned int*)d) + ((y) * (w) + (x)))) + +/*****************************************************************************/ +#define IN_PIXEL8(in_ptr, in_x, in_y, in_w, in_last_pixel, in_pixel); \ + { \ + if (in_ptr == 0) \ + { \ + in_pixel = 0; \ + } \ + else if (in_x < in_w) \ + { \ + in_pixel = GETPIXEL8(in_ptr, in_x, in_y, in_w); \ + } \ + else \ + { \ + in_pixel = in_last_pixel; \ + } \ + } + +/*****************************************************************************/ +#define IN_PIXEL16(in_ptr, in_x, in_y, in_w, in_last_pixel, in_pixel); \ + { \ + if (in_ptr == 0) \ + { \ + in_pixel = 0; \ + } \ + else if (in_x < in_w) \ + { \ + in_pixel = GETPIXEL16(in_ptr, in_x, in_y, in_w); \ + } \ + else \ + { \ + in_pixel = in_last_pixel; \ + } \ + } + +/*****************************************************************************/ +#define IN_PIXEL32(in_ptr, in_x, in_y, in_w, in_last_pixel, in_pixel); \ + { \ + if (in_ptr == 0) \ + { \ + in_pixel = 0; \ + } \ + else if (in_x < in_w) \ + { \ + in_pixel = GETPIXEL32(in_ptr, in_x, in_y, in_w); \ + } \ + else \ + { \ + in_pixel = in_last_pixel; \ + } \ + } + +/*****************************************************************************/ +/* color */ +#define OUT_COLOR_COUNT1(in_count, in_s, in_data) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x3 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_data); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x60); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_data); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf3); \ + Stream_Write_UINT16(in_s, in_count); \ + Stream_Write_UINT8(in_s, in_data); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* color */ +#define OUT_COLOR_COUNT2(in_count, in_s, in_data) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x3 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT16(in_s, in_data); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x60); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT16(in_s, in_data); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf3); \ + Stream_Write_UINT16(in_s, in_count); \ + Stream_Write_UINT16(in_s, in_data); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* color */ +#define OUT_COLOR_COUNT3(in_count, in_s, in_data) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x3 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_data & 0xFF); \ + Stream_Write_UINT8(in_s, (in_data >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_data >> 16) & 0xFF); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x60); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_data & 0xFF); \ + Stream_Write_UINT8(in_s, (in_data >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_data >> 16) & 0xFF); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf3); \ + Stream_Write_UINT16(in_s, in_count); \ + Stream_Write_UINT8(in_s, in_data & 0xFF); \ + Stream_Write_UINT8(in_s, (in_data >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_data >> 16) & 0xFF); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* copy */ +#define OUT_COPY_COUNT1(in_count, in_s, in_data) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x4 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, Stream_Buffer(in_data), in_count); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x80); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, Stream_Buffer(in_data), in_count); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf4); \ + Stream_Write_UINT16(in_s, in_count); \ + Stream_Write(in_s, Stream_Buffer(in_data), in_count); \ + } \ + } \ + in_count = 0; \ + Stream_SetPosition(in_data, 0); \ + } + +/*****************************************************************************/ +/* copy */ +#define OUT_COPY_COUNT2(in_count, in_s, in_data) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x4 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + temp = in_count * 2; \ + Stream_Write(in_s, Stream_Buffer(in_data), temp); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x80); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + temp = in_count * 2; \ + Stream_Write(in_s, Stream_Buffer(in_data), temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf4); \ + Stream_Write_UINT16(in_s, in_count); \ + temp = in_count * 2; \ + Stream_Write(in_s, Stream_Buffer(in_data), temp); \ + } \ + } \ + in_count = 0; \ + Stream_SetPosition(in_data, 0); \ + } + +/*****************************************************************************/ +/* copy */ +#define OUT_COPY_COUNT3(in_count, in_s, in_data) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x4 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + temp = in_count * 3; \ + Stream_Write(in_s, Stream_Pointer(in_data), temp); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x80); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + temp = in_count * 3; \ + Stream_Write(in_s, Stream_Pointer(in_data), temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf4); \ + Stream_Write_UINT16(in_s, in_count); \ + temp = in_count * 3; \ + Stream_Write(in_s, Stream_Pointer(in_data), temp); \ + } \ + } \ + in_count = 0; \ + Stream_SetPosition(in_data, 0); \ + } + +/*****************************************************************************/ +/* bicolor */ +#define OUT_BICOLOR_COUNT1(in_count, in_s, in_color1, in_color2) \ + { \ + if (in_count > 0) \ + { \ + if (in_count / 2 < 16) \ + { \ + temp = (0xe << 4) | (in_count / 2); \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_color1); \ + Stream_Write_UINT8(in_s, in_color2); \ + } \ + else if (in_count / 2 < 256 + 16) \ + { \ + Stream_Write_UINT8(in_s, 0xe0); \ + temp = in_count / 2 - 16; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_color1); \ + Stream_Write_UINT8(in_s, in_color2); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf8); \ + temp = in_count / 2; \ + Stream_Write_UINT16(in_s, temp); \ + Stream_Write_UINT8(in_s, in_color1); \ + Stream_Write_UINT8(in_s, in_color2); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* bicolor */ +#define OUT_BICOLOR_COUNT2(in_count, in_s, in_color1, in_color2) \ + { \ + if (in_count > 0) \ + { \ + if (in_count / 2 < 16) \ + { \ + temp = (0xe << 4) | (in_count / 2); \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT16(in_s, in_color1); \ + Stream_Write_UINT16(in_s, in_color2); \ + } \ + else if (in_count / 2 < 256 + 16) \ + { \ + Stream_Write_UINT8(in_s, 0xe0); \ + temp = in_count / 2 - 16; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT16(in_s, in_color1); \ + Stream_Write_UINT16(in_s, in_color2); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf8); \ + temp = in_count / 2; \ + Stream_Write_UINT16(in_s, temp); \ + Stream_Write_UINT16(in_s, in_color1); \ + Stream_Write_UINT16(in_s, in_color2); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* bicolor */ +#define OUT_BICOLOR_COUNT3(in_count, in_s, in_color1, in_color2) \ + { \ + if (in_count > 0) \ + { \ + if (in_count / 2 < 16) \ + { \ + temp = (0xe << 4) | (in_count / 2); \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_color1 & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color1 >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color1 >> 16) & 0xFF); \ + Stream_Write_UINT8(in_s, in_color2 & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color2 >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color2 >> 16) & 0xFF); \ + } \ + else if (in_count / 2 < 256 + 16) \ + { \ + Stream_Write_UINT8(in_s, 0xe0); \ + temp = in_count / 2 - 16; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write_UINT8(in_s, in_color1 & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color1 >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color1 >> 16) & 0xFF); \ + Stream_Write_UINT8(in_s, in_color2 & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color2 >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color2 >> 16) & 0xFF); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf8); \ + temp = in_count / 2; \ + Stream_Write_UINT16(in_s, temp); \ + Stream_Write_UINT8(in_s, in_color1 & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color1 >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color1 >> 16) & 0xFF); \ + Stream_Write_UINT8(in_s, in_color2 & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color2 >> 8) & 0xFF); \ + Stream_Write_UINT8(in_s, (in_color2 >> 16) & 0xFF); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* fill */ +#define OUT_FILL_COUNT1(in_count, in_s) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + Stream_Write_UINT8(in_s, in_count); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x0); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf0); \ + Stream_Write_UINT16(in_s, in_count); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* fill */ +#define OUT_FILL_COUNT2(in_count, in_s) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + Stream_Write_UINT8(in_s, in_count); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x0); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf0); \ + Stream_Write_UINT16(in_s, in_count); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* fill */ +#define OUT_FILL_COUNT3(in_count, in_s) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + Stream_Write_UINT8(in_s, in_count); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x0); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf0); \ + Stream_Write_UINT16(in_s, in_count); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* mix */ +#define OUT_MIX_COUNT1(in_count, in_s) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x1 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x20); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf1); \ + Stream_Write_UINT16(in_s, in_count); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* mix */ +#define OUT_MIX_COUNT2(in_count, in_s) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x1 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x20); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf1); \ + Stream_Write_UINT16(in_s, in_count); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* mix */ +#define OUT_MIX_COUNT3(in_count, in_s) \ + { \ + if (in_count > 0) \ + { \ + if (in_count < 32) \ + { \ + temp = (0x1 << 5) | in_count; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else if (in_count < 256 + 32) \ + { \ + Stream_Write_UINT8(in_s, 0x20); \ + temp = in_count - 32; \ + Stream_Write_UINT8(in_s, temp); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf1); \ + Stream_Write_UINT16(in_s, in_count); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* fom */ +#define OUT_FOM_COUNT1(in_count, in_s, in_mask, in_mask_len) \ + { \ + if (in_count > 0) \ + { \ + if ((in_count % 8) == 0 && in_count < 249) \ + { \ + temp = (0x2 << 5) | (in_count / 8); \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + else if (in_count < 256) \ + { \ + Stream_Write_UINT8(in_s, 0x40); \ + temp = in_count - 1; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf2); \ + Stream_Write_UINT16(in_s, in_count); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* fom */ +#define OUT_FOM_COUNT2(in_count, in_s, in_mask, in_mask_len) \ + { \ + if (in_count > 0) \ + { \ + if ((in_count % 8) == 0 && in_count < 249) \ + { \ + temp = (0x2 << 5) | (in_count / 8); \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + else if (in_count < 256) \ + { \ + Stream_Write_UINT8(in_s, 0x40); \ + temp = in_count - 1; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf2); \ + Stream_Write_UINT16(in_s, in_count); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +/* fill or mix (fom) */ +#define OUT_FOM_COUNT3(in_count, in_s, in_mask, in_mask_len) \ + { \ + if (in_count > 0) \ + { \ + if ((in_count % 8) == 0 && in_count < 249) \ + { \ + temp = (0x2 << 5) | (in_count / 8); \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + else if (in_count < 256) \ + { \ + Stream_Write_UINT8(in_s, 0x40); \ + temp = in_count - 1; \ + Stream_Write_UINT8(in_s, temp); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + else \ + { \ + Stream_Write_UINT8(in_s, 0xf2); \ + Stream_Write_UINT16(in_s, in_count); \ + Stream_Write(in_s, in_mask, in_mask_len); \ + } \ + } \ + in_count = 0; \ + } + +/*****************************************************************************/ +#define TEST_FILL \ + ((last_line == 0 && pixel == 0) || \ + (last_line != 0 && pixel == ypixel)) +#define TEST_MIX \ + ((last_line == 0 && pixel == mix) || \ + (last_line != 0 && pixel == (ypixel ^ mix))) +#define TEST_FOM (TEST_FILL || TEST_MIX) +#define TEST_COLOR (pixel == last_pixel) +#define TEST_BICOLOR \ + ( \ + (pixel != last_pixel) && \ + ( \ + (!bicolor_spin && pixel == bicolor1 && last_pixel == bicolor2) || \ + (bicolor_spin && pixel == bicolor2 && last_pixel == bicolor1) \ + ) \ + ) +#define RESET_COUNTS \ + { \ + bicolor_count = 0; \ + fill_count = 0; \ + color_count = 0; \ + mix_count = 0; \ + fom_count = 0; \ + fom_mask_len = 0; \ + bicolor_spin = 0; \ + } + +/*****************************************************************************/ +int freerdp_bitmap_compress(char* in_data, int width, int height, + wStream* s, int bpp, int byte_limit, int start_line, wStream* temp_s, int e) +{ + char *line; + char *last_line; + char fom_mask[8192]; /* good for up to 64K bitmap */ + int lines_sent; + int pixel; + int count; + int color_count; + int last_pixel; + int bicolor_count; + int bicolor1; + int bicolor2; + int bicolor_spin; + int end; + int i; + int out_count; + int ypixel; + int last_ypixel; + int fill_count; + int mix_count; + int mix; + int fom_count; + int fom_mask_len; + int temp; /* used in macros */ + + Stream_SetPosition(temp_s, 0); + fom_mask_len = 0; + last_line = 0; + lines_sent = 0; + end = width + e; + count = 0; + color_count = 0; + last_pixel = 0; + last_ypixel = 0; + bicolor_count = 0; + bicolor1 = 0; + bicolor2 = 0; + bicolor_spin = 0; + fill_count = 0; + mix_count = 0; + fom_count = 0; + + if (bpp == 8) + { + mix = 0xFF; + out_count = end; + line = in_data + width * start_line; + + while (start_line >= 0 && out_count < 32768) + { + i = Stream_GetPosition(s) + count; + + if (i - color_count >= byte_limit && + i - bicolor_count >= byte_limit && + i - fill_count >= byte_limit && + i - mix_count >= byte_limit && + i - fom_count >= byte_limit) + { + break; + } + + out_count += end; + + for (i = 0; i < end; i++) + { + /* read next pixel */ + IN_PIXEL8(line, i, 0, width, last_pixel, pixel); + IN_PIXEL8(last_line, i, 0, width, last_ypixel, ypixel); + + if (!TEST_FILL) + { + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_FILL_COUNT1(fill_count, s); + RESET_COUNTS; + } + + fill_count = 0; + } + + if (!TEST_MIX) + { + if (mix_count > 3 && + mix_count >= fill_count && + mix_count >= bicolor_count && + mix_count >= color_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_MIX_COUNT1(mix_count, s); + RESET_COUNTS; + } + + mix_count = 0; + } + + if (!TEST_COLOR) + { + if (color_count > 3 && + color_count >= fill_count && + color_count >= bicolor_count && + color_count >= mix_count && + color_count >= fom_count) + { + count -= color_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_COLOR_COUNT1(color_count, s, last_pixel); + RESET_COUNTS; + } + + color_count = 0; + } + + if (!TEST_BICOLOR) + { + if (bicolor_count > 3 && + bicolor_count >= fill_count && + bicolor_count >= color_count && + bicolor_count >= mix_count && + bicolor_count >= fom_count) + { + if ((bicolor_count % 2) == 0) + { + count -= bicolor_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2); + } + else + { + bicolor_count--; + count -= bicolor_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor2, bicolor1); + } + + RESET_COUNTS; + } + + bicolor_count = 0; + bicolor1 = last_pixel; + bicolor2 = pixel; + bicolor_spin = 0; + } + + if (!TEST_FOM) + { + if (fom_count > 3 && + fom_count >= fill_count && + fom_count >= color_count && + fom_count >= mix_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len); + RESET_COUNTS; + } + + fom_count = 0; + fom_mask_len = 0; + } + + if (TEST_FILL) + { + fill_count++; + } + + if (TEST_MIX) + { + mix_count++; + } + + if (TEST_COLOR) + { + color_count++; + } + + if (TEST_BICOLOR) + { + bicolor_spin = !bicolor_spin; + bicolor_count++; + } + + if (TEST_FOM) + { + if ((fom_count % 8) == 0) + { + fom_mask[fom_mask_len] = 0; + fom_mask_len++; + } + + if (pixel == (ypixel ^ mix)) + { + fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8)); + } + + fom_count++; + } + + Stream_Write_UINT8(temp_s, pixel); + count++; + last_pixel = pixel; + last_ypixel = ypixel; + } + + /* can't take fix, mix, or fom past first line */ + if (last_line == 0) + { + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_FILL_COUNT1(fill_count, s); + RESET_COUNTS; + } + + fill_count = 0; + + if (mix_count > 3 && + mix_count >= fill_count && + mix_count >= bicolor_count && + mix_count >= color_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_MIX_COUNT1(mix_count, s); + RESET_COUNTS; + } + + mix_count = 0; + + if (fom_count > 3 && + fom_count >= fill_count && + fom_count >= color_count && + fom_count >= mix_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len); + RESET_COUNTS; + } + + fom_count = 0; + fom_mask_len = 0; + } + + last_line = line; + line = line - width; + start_line--; + lines_sent++; + } + + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_FILL_COUNT1(fill_count, s); + } + else if (mix_count > 3 && + mix_count >= color_count && + mix_count >= bicolor_count && + mix_count >= fill_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_MIX_COUNT1(mix_count, s); + } + else if (color_count > 3 && + color_count >= mix_count && + color_count >= bicolor_count && + color_count >= fill_count && + color_count >= fom_count) + { + count -= color_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_COLOR_COUNT1(color_count, s, last_pixel); + } + else if (bicolor_count > 3 && + bicolor_count >= mix_count && + bicolor_count >= color_count && + bicolor_count >= fill_count && + bicolor_count >= fom_count) + { + if ((bicolor_count % 2) == 0) + { + count -= bicolor_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2); + } + else + { + bicolor_count--; + count -= bicolor_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor2, bicolor1); + } + + count -= bicolor_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2); + } + else if (fom_count > 3 && + fom_count >= mix_count && + fom_count >= color_count && + fom_count >= fill_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT1(count, s, temp_s); + OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len); + } + else + { + OUT_COPY_COUNT1(count, s, temp_s); + } + } + else if ((bpp == 15) || (bpp == 16)) + { + mix = (bpp == 15) ? 0xBA1F : 0xFFFF; + out_count = end * 2; + line = in_data + width * start_line * 2; + + while (start_line >= 0 && out_count < 32768) + { + i = Stream_GetPosition(s) + count * 2; + + if (i - (color_count * 2) >= byte_limit && + i - (bicolor_count * 2) >= byte_limit && + i - (fill_count * 2) >= byte_limit && + i - (mix_count * 2) >= byte_limit && + i - (fom_count * 2) >= byte_limit) + { + break; + } + + out_count += end * 2; + + for (i = 0; i < end; i++) + { + /* read next pixel */ + IN_PIXEL16(line, i, 0, width, last_pixel, pixel); + IN_PIXEL16(last_line, i, 0, width, last_ypixel, ypixel); + + if (!TEST_FILL) + { + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_FILL_COUNT2(fill_count, s); + RESET_COUNTS; + } + + fill_count = 0; + } + + if (!TEST_MIX) + { + if (mix_count > 3 && + mix_count >= fill_count && + mix_count >= bicolor_count && + mix_count >= color_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_MIX_COUNT2(mix_count, s); + RESET_COUNTS; + } + + mix_count = 0; + } + + if (!TEST_COLOR) + { + if (color_count > 3 && + color_count >= fill_count && + color_count >= bicolor_count && + color_count >= mix_count && + color_count >= fom_count) + { + count -= color_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_COLOR_COUNT2(color_count, s, last_pixel); + RESET_COUNTS; + } + + color_count = 0; + } + + if (!TEST_BICOLOR) + { + if (bicolor_count > 3 && + bicolor_count >= fill_count && + bicolor_count >= color_count && + bicolor_count >= mix_count && + bicolor_count >= fom_count) + { + if ((bicolor_count % 2) == 0) + { + count -= bicolor_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2); + } + else + { + bicolor_count--; + count -= bicolor_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor2, bicolor1); + } + + RESET_COUNTS; + } + + bicolor_count = 0; + bicolor1 = last_pixel; + bicolor2 = pixel; + bicolor_spin = 0; + } + + if (!TEST_FOM) + { + if (fom_count > 3 && + fom_count >= fill_count && + fom_count >= color_count && + fom_count >= mix_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len); + RESET_COUNTS; + } + + fom_count = 0; + fom_mask_len = 0; + } + + if (TEST_FILL) + { + fill_count++; + } + + if (TEST_MIX) + { + mix_count++; + } + + if (TEST_COLOR) + { + color_count++; + } + + if (TEST_BICOLOR) + { + bicolor_spin = !bicolor_spin; + bicolor_count++; + } + + if (TEST_FOM) + { + if ((fom_count % 8) == 0) + { + fom_mask[fom_mask_len] = 0; + fom_mask_len++; + } + + if (pixel == (ypixel ^ mix)) + { + fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8)); + } + + fom_count++; + } + + Stream_Write_UINT16(temp_s, pixel); + count++; + last_pixel = pixel; + last_ypixel = ypixel; + } + + /* can't take fix, mix, or fom past first line */ + if (last_line == 0) + { + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_FILL_COUNT2(fill_count, s); + RESET_COUNTS; + } + + fill_count = 0; + + if (mix_count > 3 && + mix_count >= fill_count && + mix_count >= bicolor_count && + mix_count >= color_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_MIX_COUNT2(mix_count, s); + RESET_COUNTS; + } + + mix_count = 0; + + if (fom_count > 3 && + fom_count >= fill_count && + fom_count >= color_count && + fom_count >= mix_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len); + RESET_COUNTS; + } + + fom_count = 0; + fom_mask_len = 0; + } + + last_line = line; + line = line - width * 2; + start_line--; + lines_sent++; + } + + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_FILL_COUNT2(fill_count, s); + } + else if (mix_count > 3 && + mix_count >= color_count && + mix_count >= bicolor_count && + mix_count >= fill_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_MIX_COUNT2(mix_count, s); + } + else if (color_count > 3 && + color_count >= mix_count && + color_count >= bicolor_count && + color_count >= fill_count && + color_count >= fom_count) + { + count -= color_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_COLOR_COUNT2(color_count, s, last_pixel); + } + else if (bicolor_count > 3 && + bicolor_count >= mix_count && + bicolor_count >= color_count && + bicolor_count >= fill_count && + bicolor_count >= fom_count) + { + if ((bicolor_count % 2) == 0) + { + count -= bicolor_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2); + } + else + { + bicolor_count--; + count -= bicolor_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor2, bicolor1); + } + + count -= bicolor_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2); + } + else if (fom_count > 3 && + fom_count >= mix_count && + fom_count >= color_count && + fom_count >= fill_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT2(count, s, temp_s); + OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len); + } + else + { + OUT_COPY_COUNT2(count, s, temp_s); + } + } + else if (bpp == 24) + { + mix = 0xFFFFFF; + out_count = end * 3; + line = in_data + width * start_line * 4; + + while (start_line >= 0 && out_count < 32768) + { + i = Stream_GetPosition(s) + count * 3; + + if (i - (color_count * 3) >= byte_limit && + i - (bicolor_count * 3) >= byte_limit && + i - (fill_count * 3) >= byte_limit && + i - (mix_count * 3) >= byte_limit && + i - (fom_count * 3) >= byte_limit) + { + break; + } + + out_count += end * 3; + + for (i = 0; i < end; i++) + { + /* read next pixel */ + IN_PIXEL32(line, i, 0, width, last_pixel, pixel); + IN_PIXEL32(last_line, i, 0, width, last_ypixel, ypixel); + + if (!TEST_FILL) + { + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_FILL_COUNT3(fill_count, s); + RESET_COUNTS; + } + + fill_count = 0; + } + + if (!TEST_MIX) + { + if (mix_count > 3 && + mix_count >= fill_count && + mix_count >= bicolor_count && + mix_count >= color_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_MIX_COUNT3(mix_count, s); + RESET_COUNTS; + } + + mix_count = 0; + } + + if (!TEST_COLOR) + { + if (color_count > 3 && + color_count >= fill_count && + color_count >= bicolor_count && + color_count >= mix_count && + color_count >= fom_count) + { + count -= color_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_COLOR_COUNT3(color_count, s, last_pixel); + RESET_COUNTS; + } + + color_count = 0; + } + + if (!TEST_BICOLOR) + { + if (bicolor_count > 3 && + bicolor_count >= fill_count && + bicolor_count >= color_count && + bicolor_count >= mix_count && + bicolor_count >= fom_count) + { + if ((bicolor_count % 2) == 0) + { + count -= bicolor_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2); + } + else + { + bicolor_count--; + count -= bicolor_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor2, bicolor1); + } + + RESET_COUNTS; + } + + bicolor_count = 0; + bicolor1 = last_pixel; + bicolor2 = pixel; + bicolor_spin = 0; + } + + if (!TEST_FOM) + { + if (fom_count > 3 && + fom_count >= fill_count && + fom_count >= color_count && + fom_count >= mix_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len); + RESET_COUNTS; + } + + fom_count = 0; + fom_mask_len = 0; + } + + if (TEST_FILL) + { + fill_count++; + } + + if (TEST_MIX) + { + mix_count++; + } + + if (TEST_COLOR) + { + color_count++; + } + + if (TEST_BICOLOR) + { + bicolor_spin = !bicolor_spin; + bicolor_count++; + } + + if (TEST_FOM) + { + if ((fom_count % 8) == 0) + { + fom_mask[fom_mask_len] = 0; + fom_mask_len++; + } + + if (pixel == (ypixel ^ mix)) + { + fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8)); + } + + fom_count++; + } + + Stream_Write_UINT8(temp_s, pixel & 0xff); + Stream_Write_UINT8(temp_s, (pixel >> 8) & 0xff); + Stream_Write_UINT8(temp_s, (pixel >> 16) & 0xff); + count++; + last_pixel = pixel; + last_ypixel = ypixel; + } + + /* can't take fix, mix, or fom past first line */ + if (last_line == 0) + { + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_FILL_COUNT3(fill_count, s); + RESET_COUNTS; + } + + fill_count = 0; + + if (mix_count > 3 && + mix_count >= fill_count && + mix_count >= bicolor_count && + mix_count >= color_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_MIX_COUNT3(mix_count, s); + RESET_COUNTS; + } + + mix_count = 0; + + if (fom_count > 3 && + fom_count >= fill_count && + fom_count >= color_count && + fom_count >= mix_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len); + RESET_COUNTS; + } + + fom_count = 0; + fom_mask_len = 0; + } + + last_line = line; + line = line - width * 4; + start_line--; + lines_sent++; + } + + if (fill_count > 3 && + fill_count >= color_count && + fill_count >= bicolor_count && + fill_count >= mix_count && + fill_count >= fom_count) + { + count -= fill_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_FILL_COUNT3(fill_count, s); + } + else if (mix_count > 3 && + mix_count >= color_count && + mix_count >= bicolor_count && + mix_count >= fill_count && + mix_count >= fom_count) + { + count -= mix_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_MIX_COUNT3(mix_count, s); + } + else if (color_count > 3 && + color_count >= mix_count && + color_count >= bicolor_count && + color_count >= fill_count && + color_count >= fom_count) + { + count -= color_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_COLOR_COUNT3(color_count, s, last_pixel); + } + else if (bicolor_count > 3 && + bicolor_count >= mix_count && + bicolor_count >= color_count && + bicolor_count >= fill_count && + bicolor_count >= fom_count) + { + if ((bicolor_count % 2) == 0) + { + count -= bicolor_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2); + } + else + { + bicolor_count--; + count -= bicolor_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor2, bicolor1); + } + + count -= bicolor_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2); + } + else if (fom_count > 3 && + fom_count >= mix_count && + fom_count >= color_count && + fom_count >= fill_count && + fom_count >= bicolor_count) + { + count -= fom_count; + OUT_COPY_COUNT3(count, s, temp_s); + OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len); + } + else + { + OUT_COPY_COUNT3(count, s, temp_s); + } + } + + return lines_sent; +} diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index 2b4b71992..875c0ae73 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -1245,6 +1245,7 @@ rdpCredssp* credssp_new(freerdp* instance, rdpTransport* transport, rdpSettings* ZeroMemory(&credssp->negoToken, sizeof(SecBuffer)); ZeroMemory(&credssp->pubKeyAuth, sizeof(SecBuffer)); ZeroMemory(&credssp->authInfo, sizeof(SecBuffer)); + SecInvalidateHandle(&credssp->context); if (credssp->server) { diff --git a/libfreerdp/core/peer.c b/libfreerdp/core/peer.c index 3806a736e..eb4ad60ea 100644 --- a/libfreerdp/core/peer.c +++ b/libfreerdp/core/peer.c @@ -272,6 +272,7 @@ static int peer_recv_callback(rdpTransport* transport, wStream* s, void* extra) sspi_CopyAuthIdentity(&client->identity, &(rdp->nego->transport->credssp->identity)); IFCALLRET(client->Logon, client->authenticated, client, &client->identity, TRUE); credssp_free(rdp->nego->transport->credssp); + rdp->nego->transport->credssp = NULL; } else { diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 781f4ab0d..40885442b 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -159,6 +159,7 @@ BOOL transport_connect_nla(rdpTransport* transport) "If credentials are valid, the NTLMSSP implementation may be to blame.\n"); credssp_free(transport->credssp); + transport->credssp = NULL; return FALSE; } @@ -292,6 +293,7 @@ BOOL transport_accept_nla(rdpTransport* transport) { fprintf(stderr, "client authentication failure\n"); credssp_free(transport->credssp); + transport->credssp = NULL; return FALSE; } @@ -786,7 +788,6 @@ static void* transport_client_thread(void* arg) freerdp* instance; rdpContext* context; rdpTransport* transport; - TerminateEventArgs e; transport = (rdpTransport*) arg; instance = (freerdp*) transport->settings->instance; diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index 3e4c2350e..0c4bce4c9 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -685,7 +685,8 @@ BOOL tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname) } #ifndef _WIN32 - free(common_name); + if (common_name) + free(common_name); #endif return verification_status; @@ -715,25 +716,20 @@ void tls_print_certificate_name_mismatch_error(char* hostname, char* common_name fprintf(stderr, "@ WARNING: CERTIFICATE NAME MISMATCH! @\n"); fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); fprintf(stderr, "The hostname used for this connection (%s) \n", hostname); - - if (alt_names_count < 1) + fprintf(stderr, "does not match %s given in the certificate:\n", alt_names_count < 1 ? "the name" : "any of the names"); + fprintf(stderr, "Common Name (CN):\n"); + fprintf(stderr, "\t%s\n", common_name ? common_name : "no CN found in certificate"); + if (alt_names_count > 1) { - fprintf(stderr, "does not match the name given in the certificate:\n"); - fprintf(stderr, "%s\n", common_name); - } - else - { - fprintf(stderr, "does not match the names given in the certificate:\n"); - fprintf(stderr, "%s", common_name); - - for (index = 0; index < alt_names_count; index++) + fprintf(stderr, "Alternative names:\n"); + if (alt_names_count > 1) { - fprintf(stderr, ", %s", alt_names[index]); + for (index = 0; index < alt_names_count; index++) + { + fprintf(stderr, "\t %s\n", alt_names[index]); + } } - - fprintf(stderr, "\n"); } - fprintf(stderr, "A valid certificate for the wrong name should NOT be trusted!\n"); } diff --git a/winpr/libwinpr/sspi/sspi.c b/winpr/libwinpr/sspi/sspi.c index 8747e3f01..96c959995 100644 --- a/winpr/libwinpr/sspi/sspi.c +++ b/winpr/libwinpr/sspi/sspi.c @@ -248,7 +248,7 @@ void* sspi_SecureHandleGetLowerPointer(SecHandle* handle) { void* pointer; - if (!handle) + if (!handle || !SecIsValidHandle(handle)) return NULL; pointer = (void*) ~((size_t) handle->dwLower); @@ -268,7 +268,7 @@ void* sspi_SecureHandleGetUpperPointer(SecHandle* handle) { void* pointer; - if (!handle) + if (!handle || !SecIsValidHandle(handle)) return NULL; pointer = (void*) ~((size_t) handle->dwUpper); @@ -839,7 +839,7 @@ SECURITY_STATUS SEC_ENTRY CompleteAuthToken(PCtxtHandle phContext, PSecBufferDes SECURITY_STATUS SEC_ENTRY DeleteSecurityContext(PCtxtHandle phContext) { - char* Name; + char* Name = NULL; SECURITY_STATUS status; SecurityFunctionTableA* table;