API refactoring.
authorArmin Novak <armin.novak@thincast.com>
Tue, 19 Jul 2016 14:15:38 +0000 (16:15 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 6 Oct 2016 11:43:03 +0000 (13:43 +0200)
18 files changed:
client/X11/xf_client.c
client/X11/xf_event.c
client/X11/xf_gdi.c
client/X11/xf_graphics.c
client/X11/xfreerdp.h
include/freerdp/codec/interleaved.h
include/freerdp/codec/planar.h
include/freerdp/gdi/gdi.h
include/freerdp/gdi/shape.h
libfreerdp/codec/interleaved.c
libfreerdp/codec/planar.c
libfreerdp/codec/test/TestFreeRDPCodecPlanar.c
libfreerdp/core/update.c
libfreerdp/gdi/gdi.c
libfreerdp/gdi/gfx.c
libfreerdp/gdi/graphics.c
libfreerdp/gdi/line.c
libfreerdp/gdi/shape.c

index e03baf8..f1fc4ac 100644 (file)
@@ -122,6 +122,7 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h)
        double yScalingFactor;
        int x2;
        int y2;
+       rdpSettings* settings = xfc->context.settings;
 
        if (xfc->scaledWidth <= 0 || xfc->scaledHeight <= 0)
        {
@@ -129,14 +130,14 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h)
                return;
        }
 
-       if (xfc->sessionWidth <= 0 || xfc->sessionHeight <= 0)
+       if (settings->DesktopWidth <= 0 || settings->DesktopHeight <= 0)
        {
                WLog_ERR(TAG, "the window dimensions are invalid");
                return;
        }
 
-       xScalingFactor = xfc->sessionWidth / (double)xfc->scaledWidth;
-       yScalingFactor = xfc->sessionHeight / (double)xfc->scaledHeight;
+       xScalingFactor = settings->DesktopWidth / (double)xfc->scaledWidth;
+       yScalingFactor = settings->DesktopHeight / (double)xfc->scaledHeight;
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
        XSetForeground(xfc->display, xfc->gc, 0);
        /* Black out possible space between desktop and window borders */
@@ -191,9 +192,11 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h)
 
 BOOL xf_picture_transform_required(xfContext* xfc)
 {
+       rdpSettings* settings = xfc->context.settings;
+
        if (xfc->offset_x || xfc->offset_y ||
-           xfc->scaledWidth != xfc->sessionWidth ||
-           xfc->scaledHeight != xfc->sessionHeight)
+           xfc->scaledWidth != settings->DesktopWidth ||
+           xfc->scaledHeight != settings->DesktopHeight)
        {
                return TRUE;
        }
@@ -236,7 +239,8 @@ static BOOL xf_desktop_resize(rdpContext* context)
 
                if (!(xfc->primary = XCreatePixmap(
                                         xfc->display, xfc->drawable,
-                                        xfc->sessionWidth, xfc->sessionHeight, xfc->depth)))
+                                        settings->DesktopWidth,
+                                        settings->DesktopHeight, xfc->depth)))
                        return FALSE;
 
                if (same)
@@ -247,8 +251,8 @@ static BOOL xf_desktop_resize(rdpContext* context)
 
        if (!xfc->settings->SmartSizing)
        {
-               xfc->scaledWidth = xfc->sessionWidth;
-               xfc->scaledHeight = xfc->sessionHeight;
+               xfc->scaledWidth = settings->DesktopWidth;
+               xfc->scaledHeight = settings->DesktopHeight;
        }
 
 #endif
@@ -267,8 +271,8 @@ static BOOL xf_desktop_resize(rdpContext* context)
                {
                        /* Update the saved width and height values the window will be
                         * resized to when toggling out of fullscreen */
-                       xfc->savedWidth = xfc->sessionWidth;
-                       xfc->savedHeight = xfc->sessionHeight;
+                       xfc->savedWidth = settings->DesktopWidth;
+                       xfc->savedHeight = settings->DesktopHeight;
                }
 
                XSetFunction(xfc->display, xfc->gc, GXcopy);
@@ -357,12 +361,11 @@ static BOOL xf_sw_desktop_resize(rdpContext* context)
 {
        rdpGdi* gdi = context->gdi;
        xfContext* xfc = (xfContext*) context;
+       rdpSettings* settings = context->settings;
        BOOL ret = FALSE;
        xf_lock_x11(xfc, TRUE);
-       xfc->sessionWidth = context->settings->DesktopWidth;
-       xfc->sessionHeight = context->settings->DesktopHeight;
 
-       if (!gdi_resize(gdi, xfc->sessionWidth, xfc->sessionHeight))
+       if (!gdi_resize(gdi, settings->DesktopWidth, settings->DesktopHeight))
                goto out;
 
        if (xfc->image)
@@ -459,11 +462,8 @@ static BOOL xf_hw_end_paint(rdpContext* context)
 static BOOL xf_hw_desktop_resize(rdpContext* context)
 {
        xfContext* xfc = (xfContext*) context;
-       rdpSettings* settings = xfc->settings;
        BOOL ret;
        xf_lock_x11(xfc, TRUE);
-       xfc->sessionWidth = settings->DesktopWidth;
-       xfc->sessionHeight = settings->DesktopHeight;
        ret = xf_desktop_resize(context);
        xf_unlock_x11(xfc, TRUE);
        return ret;
@@ -506,8 +506,8 @@ BOOL xf_create_window(xfContext* xfc)
        char* windowTitle;
        rdpSettings* settings = xfc->settings;
        ZeroMemory(&xevent, sizeof(xevent));
-       width = xfc->sessionWidth;
-       height = xfc->sessionHeight;
+       width = settings->DesktopWidth;
+       height = settings->DesktopHeight;
 
        if (!xfc->hdc)
                if (!(xfc->hdc = gdi_CreateDC(xfc->format)))
@@ -589,8 +589,9 @@ BOOL xf_create_window(xfContext* xfc)
                xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv);
 
        if (!xfc->primary)
-               xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, xfc->sessionWidth,
-                                            xfc->sessionHeight, xfc->depth);
+               xfc->primary = XCreatePixmap(xfc->display, xfc->drawable,
+                                            settings->DesktopWidth,
+                                            settings->DesktopHeight, xfc->depth);
 
        xfc->drawing = xfc->primary;
 
@@ -604,8 +605,9 @@ BOOL xf_create_window(xfContext* xfc)
        XSetFunction(xfc->display, xfc->gc, GXcopy);
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
        XSetForeground(xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen));
-       XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0, xfc->sessionWidth,
-                      xfc->sessionHeight);
+       XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0,
+                      settings->DesktopWidth,
+                      settings->DesktopHeight);
        XFlush(xfc->display);
 
        if (!xfc->image)
@@ -614,7 +616,7 @@ BOOL xf_create_window(xfContext* xfc)
                xfc->image = XCreateImage(xfc->display, xfc->visual,
                                          xfc->depth,
                                          ZPixmap, 0, (char*) gdi->primary_buffer,
-                                         xfc->sessionWidth, xfc->sessionHeight,
+                                         settings->DesktopWidth, settings->DesktopHeight,
                                          xfc->scanline_pad, 0);
        }
 
@@ -1222,12 +1224,9 @@ static BOOL xf_post_connect(freerdp* instance)
                xf_gdi_register_update_callbacks(update);
        }
 
-       xfc->srcBpp = settings->ColorDepth;
-       xfc->sessionWidth = settings->DesktopWidth;
-       xfc->sessionHeight = settings->DesktopHeight;
 #ifdef WITH_XRENDER
-       xfc->scaledWidth = xfc->sessionWidth;
-       xfc->scaledHeight = xfc->sessionHeight;
+       xfc->scaledWidth = settings->DesktopWidth;
+       xfc->scaledHeight = settings->DesktopHeight;
        xfc->offset_x = 0;
        xfc->offset_y = 0;
 #endif
@@ -1649,6 +1648,7 @@ static void xf_ZoomingChangeEventHandler(rdpContext* context,
         ZoomingChangeEventArgs* e)
 {
        xfContext* xfc = (xfContext*) context;
+       rdpSettings* settings = context->settings;
        int w = xfc->scaledWidth + e->dx;
        int h = xfc->scaledHeight + e->dy;
 
@@ -1666,20 +1666,21 @@ static void xf_ZoomingChangeEventHandler(rdpContext* context,
 
        xfc->scaledWidth = w;
        xfc->scaledHeight = h;
-       xf_draw_screen(xfc, 0, 0, xfc->sessionWidth, xfc->sessionHeight);
+       xf_draw_screen(xfc, 0, 0, settings->DesktopWidth, settings->DesktopHeight);
 }
 
 static void xf_PanningChangeEventHandler(rdpContext* context,
         PanningChangeEventArgs* e)
 {
        xfContext* xfc = (xfContext*) context;
+       rdpSettings* settings = context->settings;
 
        if (e->dx == 0 && e->dy == 0)
                return;
 
        xfc->offset_x += e->dx;
        xfc->offset_y += e->dy;
-       xf_draw_screen(xfc, 0, 0, xfc->sessionWidth, xfc->sessionHeight);
+       xf_draw_screen(xfc, 0, 0, settings->DesktopWidth, settings->DesktopHeight);
 }
 #endif
 
index 2948693..852cc3e 100644 (file)
@@ -91,14 +91,13 @@ BOOL xf_event_action_script_init(xfContext* xfc)
        FILE* actionScript;
        char buffer[1024] = { 0 };
        char command[1024] = { 0 };
-
        xfc->xevents = ArrayList_New(TRUE);
+
        if (!xfc->xevents)
                return FALSE;
-       ArrayList_Object(xfc->xevents)->fnObjectFree = free;
 
+       ArrayList_Object(xfc->xevents)->fnObjectFree = free;
        sprintf_s(command, sizeof(command), "%s xevent", xfc->actionScript);
-
        actionScript = popen(command, "r");
 
        if (!actionScript)
@@ -108,6 +107,7 @@ BOOL xf_event_action_script_init(xfContext* xfc)
        {
                strtok(buffer, "\n");
                xevent = _strdup(buffer);
+
                if (!xevent || ArrayList_Add(xfc->xevents, xevent) < 0)
                {
                        ArrayList_Free(xfc->xevents);
@@ -117,7 +117,6 @@ BOOL xf_event_action_script_init(xfContext* xfc)
        }
 
        pclose(actionScript);
-
        return TRUE;
 }
 
@@ -148,7 +147,6 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event)
                return FALSE;
 
        xeventName = X11_EVENT_STRINGS[event->type];
-
        count = ArrayList_Count(xfc->xevents);
 
        for (index = 0; index < count; index++)
@@ -166,8 +164,7 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event)
                return FALSE;
 
        sprintf_s(command, sizeof(command), "%s xevent %s %d",
-                       xfc->actionScript, xeventName, (int) xfc->window->handle);
-
+                 xfc->actionScript, xeventName, (int) xfc->window->handle);
        actionScript = popen(command, "r");
 
        if (!actionScript)
@@ -179,24 +176,33 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event)
        }
 
        pclose(actionScript);
-
        return TRUE;
 }
 
-void xf_event_adjust_coordinates(xfContext* xfc, int* x, int *y)
+void xf_event_adjust_coordinates(xfContext* xfc, int* x, inty)
 {
+       rdpSettings* settings;
+
+       if (!xfc || !xfc->context.settings || !y || !x)
+               return;
+
+       settings = xfc->context.settings;
+
        if (!xfc->remote_app)
        {
 #ifdef WITH_XRENDER
+
                if (xf_picture_transform_required(xfc))
                {
-                       double xScalingFactor = xfc->sessionWidth / (double)xfc->scaledWidth;
-                       double yScalingFactor = xfc->sessionHeight / (double)xfc->scaledHeight;
+                       double xScalingFactor = settings->DesktopWidth / (double)xfc->scaledWidth;
+                       double yScalingFactor = settings->DesktopHeight / (double)xfc->scaledHeight;
                        *x = (int)((*x - xfc->offset_x) * xScalingFactor);
                        *y = (int)((*y - xfc->offset_y) * yScalingFactor);
                }
+
 #endif
        }
+
        CLAMP_COORDINATES(*x, *y);
 }
 
@@ -204,13 +210,14 @@ static BOOL xf_event_Expose(xfContext* xfc, XEvent* event, BOOL app)
 {
        int x, y;
        int w, h;
+       rdpSettings* settings = xfc->context.settings;
 
-       if (!app && (xfc->settings->SmartSizing || xfc->settings->MultiTouchGestures))
+       if (!app && (settings->SmartSizing || settings->MultiTouchGestures))
        {
                x = 0;
                y = 0;
-               w = xfc->sessionWidth;
-               h = xfc->sessionHeight;
+               w = settings->DesktopWidth;
+               h = settings->DesktopHeight;
        }
        else
        {
@@ -233,7 +240,6 @@ static BOOL xf_event_Expose(xfContext* xfc, XEvent* event, BOOL app)
        else
        {
                xfAppWindow* appWindow;
-
                appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
 
                if (appWindow)
@@ -251,11 +257,11 @@ static BOOL xf_event_VisibilityNotify(xfContext* xfc, XEvent* event, BOOL app)
        return TRUE;
 }
 
-BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window window, BOOL app)
+BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state,
+                             Window window, BOOL app)
 {
        rdpInput* input;
        Window childWindow;
-
        input = xfc->instance->input;
 
        if (!xfc->settings->MouseMotion)
@@ -272,17 +278,17 @@ BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window win
 
                /* Translate to desktop coordinates */
                XTranslateCoordinates(xfc->display, window,
-                       RootWindowOfScreen(xfc->screen),
-                       x, y, &x, &y, &childWindow);
+                                     RootWindowOfScreen(xfc->screen),
+                                     x, y, &x, &y, &childWindow);
        }
 
        xf_event_adjust_coordinates(xfc, &x, &y);
-
        input->MouseEvent(input, PTR_FLAGS_MOVE, x, y);
 
        if (xfc->fullscreen && !app)
        {
-               XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot, CurrentTime);
+               XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot,
+                              CurrentTime);
        }
 
        return TRUE;
@@ -294,17 +300,17 @@ static BOOL xf_event_MotionNotify(xfContext* xfc, XEvent* event, BOOL app)
                return TRUE;
 
        return xf_generic_MotionNotify(xfc, event->xmotion.x, event->xmotion.y,
-                       event->xmotion.state, event->xmotion.window, app);
+                                      event->xmotion.state, event->xmotion.window, app);
 }
 
-BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window window, BOOL app)
+BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button,
+                            Window window, BOOL app)
 {
        int flags;
        BOOL wheel;
        BOOL extended;
        rdpInput* input;
        Window childWindow;
-
        flags = 0;
        wheel = FALSE;
        extended = FALSE;
@@ -315,7 +321,7 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win
                case Button1:
                case Button2:
                case Button3:
-                       flags = PTR_FLAGS_DOWN | xfc->button_map[button-BUTTON_BASE];
+                       flags = PTR_FLAGS_DOWN | xfc->button_map[button - BUTTON_BASE];
                        break;
 
                case 4:
@@ -342,14 +348,18 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win
 
                case 6:         /* wheel left */
                        wheel = TRUE;
+
                        if (xfc->settings->HasHorizontalWheel)
                                flags = PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0078;
+
                        break;
 
                case 7:         /* wheel right */
                        wheel = TRUE;
+
                        if (xfc->settings->HasHorizontalWheel)
                                flags = PTR_FLAGS_HWHEEL | 0x0078;
+
                        break;
 
                default:
@@ -375,9 +385,8 @@ BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window win
 
                                /* Translate to desktop coordinates */
                                XTranslateCoordinates(xfc->display, window,
-                                       RootWindowOfScreen(xfc->screen),
-                                       x, y, &x, &y, &childWindow);
-
+                                                     RootWindowOfScreen(xfc->screen),
+                                                     x, y, &x, &y, &childWindow);
                        }
 
                        xf_event_adjust_coordinates(xfc, &x, &y);
@@ -398,17 +407,17 @@ static BOOL xf_event_ButtonPress(xfContext* xfc, XEvent* event, BOOL app)
                return TRUE;
 
        return xf_generic_ButtonPress(xfc, event->xbutton.x, event->xbutton.y,
-                       event->xbutton.button, event->xbutton.window, app);
+                                     event->xbutton.button, event->xbutton.window, app);
 }
 
-BOOL xf_generic_ButtonRelease(xfContext* xfc, int x, int y, int button, Window window, BOOL app)
+BOOL xf_generic_ButtonRelease(xfContext* xfc, int x, int y, int button,
+                              Window window, BOOL app)
 {
        int flags;
        BOOL wheel;
        BOOL extended;
        rdpInput* input;
        Window childWindow;
-
        flags = 0;
        wheel = FALSE;
        extended = FALSE;
@@ -419,7 +428,7 @@ BOOL xf_generic_ButtonRelease(xfContext* xfc, int x, int y, int button, Window w
                case Button1:
                case Button2:
                case Button3:
-                       flags = xfc->button_map[button-BUTTON_BASE];
+                       flags = xfc->button_map[button - BUTTON_BASE];
                        break;
 
                case 6:
@@ -451,8 +460,8 @@ BOOL xf_generic_ButtonRelease(xfContext* xfc, int x, int y, int button, Window w
 
                        /* Translate to desktop coordinates */
                        XTranslateCoordinates(xfc->display, window,
-                               RootWindowOfScreen(xfc->screen),
-                               x, y, &x, &y, &childWindow);
+                                             RootWindowOfScreen(xfc->screen),
+                                             x, y, &x, &y, &childWindow);
                }
 
                xf_event_adjust_coordinates(xfc, &x, &y);
@@ -472,18 +481,15 @@ static BOOL xf_event_ButtonRelease(xfContext* xfc, XEvent* event, BOOL app)
                return TRUE;
 
        return xf_generic_ButtonRelease(xfc, event->xbutton.x, event->xbutton.y,
-                       event->xbutton.button, event->xbutton.window, app);
+                                       event->xbutton.button, event->xbutton.window, app);
 }
 
 static BOOL xf_event_KeyPress(xfContext* xfc, XEvent* event, BOOL app)
 {
        KeySym keysym;
        char str[256];
-
        XLookupString((XKeyEvent*) event, str, sizeof(str), &keysym, NULL);
-
        xf_keyboard_key_press(xfc, event->xkey.keycode, keysym);
-
        return TRUE;
 }
 
@@ -504,7 +510,6 @@ static BOOL xf_event_KeyRelease(xfContext* xfc, XEvent* event, BOOL app)
        }
 
        xf_keyboard_key_release(xfc, event->xkey.keycode);
-
        return TRUE;
 }
 
@@ -516,14 +521,13 @@ static BOOL xf_event_FocusIn(xfContext* xfc, XEvent* event, BOOL app)
        xfc->focused = TRUE;
 
        if (xfc->mouse_active && !app)
-               XGrabKeyboard(xfc->display, xfc->window->handle, TRUE, GrabModeAsync, GrabModeAsync, CurrentTime);
+               XGrabKeyboard(xfc->display, xfc->window->handle, TRUE, GrabModeAsync,
+                             GrabModeAsync, CurrentTime);
 
        if (app)
        {
                xfAppWindow* appWindow;
-
                xf_rail_send_activate(xfc, event->xany.window, TRUE);
-
                appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
 
                /* Update the server with any window changes that occurred while the window was not focused. */
@@ -534,7 +538,6 @@ static BOOL xf_event_FocusIn(xfContext* xfc, XEvent* event, BOOL app)
        }
 
        xf_keyboard_focus_in(xfc);
-
        return TRUE;
 }
 
@@ -578,7 +581,6 @@ static BOOL xf_event_ClientMessage(xfContext* xfc, XEvent* event, BOOL app)
                if (app)
                {
                        xfAppWindow* appWindow;
-
                        appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
 
                        if (appWindow)
@@ -605,15 +607,16 @@ static BOOL xf_event_EnterNotify(xfContext* xfc, XEvent* event, BOOL app)
                xfc->mouse_active = TRUE;
 
                if (xfc->fullscreen)
-                       XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot, CurrentTime);
+                       XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot,
+                                      CurrentTime);
 
                if (xfc->focused)
-                       XGrabKeyboard(xfc->display, xfc->window->handle, TRUE, GrabModeAsync, GrabModeAsync, CurrentTime);
+                       XGrabKeyboard(xfc->display, xfc->window->handle, TRUE, GrabModeAsync,
+                                     GrabModeAsync, CurrentTime);
        }
        else
        {
                xfAppWindow* appWindow;
-
                appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
 
                /* keep track of which window has focus so that we can apply pointer updates */
@@ -642,6 +645,7 @@ static BOOL xf_event_ConfigureNotify(xfContext* xfc, XEvent* event, BOOL app)
 {
        Window childWindow;
        xfAppWindow* appWindow;
+       rdpSettings* settings = xfc->context.settings;
 
        if (!app)
        {
@@ -652,26 +656,29 @@ static BOOL xf_event_ConfigureNotify(xfContext* xfc, XEvent* event, BOOL app)
                        xfc->window->top = event->xconfigure.y;
 
                if (xfc->window->width != event->xconfigure.width ||
-                    xfc->window->height != event->xconfigure.height)
+                   xfc->window->height != event->xconfigure.height)
                {
                        xfc->window->width = event->xconfigure.width;
                        xfc->window->height = event->xconfigure.height;
 #ifdef WITH_XRENDER
                        xfc->offset_x = 0;
                        xfc->offset_y = 0;
+
                        if (xfc->settings->SmartSizing || xfc->settings->MultiTouchGestures)
                        {
                                xfc->scaledWidth = xfc->window->width;
                                xfc->scaledHeight = xfc->window->height;
-                               xf_draw_screen(xfc, 0, 0, xfc->sessionWidth, xfc->sessionHeight);
+                               xf_draw_screen(xfc, 0, 0, settings->DesktopWidth, settings->DesktopHeight);
                        }
                        else
                        {
-                               xfc->scaledWidth = xfc->sessionWidth;
-                               xfc->scaledHeight = xfc->sessionHeight;
+                               xfc->scaledWidth = settings->DesktopWidth;
+                               xfc->scaledHeight = settings->DesktopHeight;
                        }
+
 #endif
                }
+
                return TRUE;
        }
 
@@ -683,11 +690,9 @@ static BOOL xf_event_ConfigureNotify(xfContext* xfc, XEvent* event, BOOL app)
                 * ConfigureNotify coordinates are expressed relative to the window parent.
                 * Translate these to root window coordinates.
                 */
-
                XTranslateCoordinates(xfc->display, appWindow->handle,
-                               RootWindowOfScreen(xfc->screen),
-                               0, 0, &appWindow->x, &appWindow->y, &childWindow);
-
+                                     RootWindowOfScreen(xfc->screen),
+                                     0, 0, &appWindow->x, &appWindow->y, &childWindow);
                appWindow->width = event->xconfigure.width;
                appWindow->height = event->xconfigure.height;
 
@@ -704,11 +709,11 @@ static BOOL xf_event_ConfigureNotify(xfContext* xfc, XEvent* event, BOOL app)
                }
                else
                {
-                       if ((!event->xconfigure.send_event || appWindow->local_move.state == LMS_NOT_ACTIVE)
-                                       && !appWindow->rail_ignore_configure && xfc->focused)
+                       if ((!event->xconfigure.send_event
+                            || appWindow->local_move.state == LMS_NOT_ACTIVE)
+                           && !appWindow->rail_ignore_configure && xfc->focused)
                                xf_rail_adjust_position(xfc, appWindow);
                }
-
        }
 
        return TRUE;
@@ -719,14 +724,14 @@ static BOOL xf_event_MapNotify(xfContext* xfc, XEvent* event, BOOL app)
        RECTANGLE_16 rect;
        xfAppWindow* appWindow;
        rdpUpdate* update = xfc->instance->update;
+       rdpSettings* settings = xfc->context.settings;
 
        if (!app)
        {
                rect.left = 0;
                rect.top = 0;
-               rect.right = xfc->sessionWidth;
-               rect.bottom = xfc->sessionHeight;
-
+               rect.right = settings->DesktopWidth;
+               rect.bottom = settings->DesktopHeight;
                update->SuppressOutput((rdpContext*) xfc, 1, &rect);
        }
        else
@@ -736,12 +741,10 @@ static BOOL xf_event_MapNotify(xfContext* xfc, XEvent* event, BOOL app)
                if (appWindow)
                {
                        /* local restore event */
-
                        /* This is now handled as part of the PropertyNotify
                         * Doing this here would inhibit the ability to restore a maximized window
                         * that is minimized back to the maximized state
                         */
-
                        //xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_RESTORE);
                        appWindow->is_mapped = TRUE;
                }
@@ -754,7 +757,6 @@ static BOOL xf_event_UnmapNotify(xfContext* xfc, XEvent* event, BOOL app)
 {
        xfAppWindow* appWindow;
        rdpUpdate* update = xfc->instance->update;
-
        xf_keyboard_release_all_keypress(xfc);
 
        if (!app)
@@ -781,43 +783,45 @@ static BOOL xf_event_PropertyNotify(xfContext* xfc, XEvent* event, BOOL app)
         * when the window has been minimized, maximized, restored locally
         * ie. not using the buttons on the rail window itself
         */
-
        if (app)
        {
-               xfAppWindow* appWindow;
-
+               xfAppWindow* appWindow;
                appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
 
                if (!appWindow)
                        return TRUE;
 
-               if ((((Atom) event->xproperty.atom == xfc->_NET_WM_STATE) && (event->xproperty.state != PropertyDelete)) ||
-                   (((Atom) event->xproperty.atom == xfc->WM_STATE) && (event->xproperty.state != PropertyDelete)))
-               {
-                       int i;
-                       BOOL status;
-                       BOOL maxVert = FALSE;
-                       BOOL maxHorz = FALSE;
-                       BOOL minimized = FALSE;
-                       unsigned long nitems;
-                       unsigned long bytes;
-                       unsigned char* prop;
-
-                       if ((Atom) event->xproperty.atom == xfc->_NET_WM_STATE)
-                       {
+               if ((((Atom) event->xproperty.atom == xfc->_NET_WM_STATE)
+                    && (event->xproperty.state != PropertyDelete)) ||
+                   (((Atom) event->xproperty.atom == xfc->WM_STATE)
+                    && (event->xproperty.state != PropertyDelete)))
+               {
+                       int i;
+                       BOOL status;
+                       BOOL maxVert = FALSE;
+                       BOOL maxHorz = FALSE;
+                       BOOL minimized = FALSE;
+                       unsigned long nitems;
+                       unsigned long bytes;
+                       unsigned char* prop;
+
+                       if ((Atom) event->xproperty.atom == xfc->_NET_WM_STATE)
+                       {
                                status = xf_GetWindowProperty(xfc, event->xproperty.window,
-                                               xfc->_NET_WM_STATE, 12, &nitems, &bytes, &prop);
+                                                             xfc->_NET_WM_STATE, 12, &nitems, &bytes, &prop);
 
                                if (status)
                                {
                                        for (i = 0; i < nitems; i++)
                                        {
-                                               if ((Atom) ((UINT16**) prop)[i] == XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_VERT", False))
+                                               if ((Atom)((UINT16**) prop)[i] == XInternAtom(xfc->display,
+                                                       "_NET_WM_STATE_MAXIMIZED_VERT", False))
                                                {
                                                        maxVert = TRUE;
                                                }
 
-                                               if ((Atom) ((UINT16**) prop)[i] == XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False))
+                                               if ((Atom)((UINT16**) prop)[i] == XInternAtom(xfc->display,
+                                                       "_NET_WM_STATE_MAXIMIZED_HORZ", False))
                                                {
                                                        maxHorz = TRUE;
                                                }
@@ -825,12 +829,12 @@ static BOOL xf_event_PropertyNotify(xfContext* xfc, XEvent* event, BOOL app)
 
                                        XFree(prop);
                                }
-                       }
+                       }
 
-                       if ((Atom) event->xproperty.atom == xfc->WM_STATE)
-                       {
+                       if ((Atom) event->xproperty.atom == xfc->WM_STATE)
+                       {
                                status = xf_GetWindowProperty(xfc, event->xproperty.window,
-                                               xfc->WM_STATE, 1, &nitems, &bytes, &prop);
+                                                             xfc->WM_STATE, 1, &nitems, &bytes, &prop);
 
                                if (status)
                                {
@@ -842,30 +846,33 @@ static BOOL xf_event_PropertyNotify(xfContext* xfc, XEvent* event, BOOL app)
 
                                        XFree(prop);
                                }
-                       }
-
-                       if (maxVert && maxHorz && !minimized && (appWindow->rail_state != WINDOW_SHOW_MAXIMIZED))
-                       {
-                               appWindow->rail_state = WINDOW_SHOW_MAXIMIZED;
-                               xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_MAXIMIZE);
-                       }
-                       else if (minimized && (appWindow->rail_state != WINDOW_SHOW_MINIMIZED))
-                       {
-                               appWindow->rail_state = WINDOW_SHOW_MINIMIZED;
-                               xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_MINIMIZE);
-                       }
-                       else if (!minimized && !maxVert && !maxHorz && (appWindow->rail_state != WINDOW_SHOW))
-                       {
-                               appWindow->rail_state = WINDOW_SHOW;
-                               xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_RESTORE);
-                       }
-               }
-        }
+                       }
+
+                       if (maxVert && maxHorz && !minimized
+                           && (appWindow->rail_state != WINDOW_SHOW_MAXIMIZED))
+                       {
+                               appWindow->rail_state = WINDOW_SHOW_MAXIMIZED;
+                               xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_MAXIMIZE);
+                       }
+                       else if (minimized && (appWindow->rail_state != WINDOW_SHOW_MINIMIZED))
+                       {
+                               appWindow->rail_state = WINDOW_SHOW_MINIMIZED;
+                               xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_MINIMIZE);
+                       }
+                       else if (!minimized && !maxVert && !maxHorz
+                                && (appWindow->rail_state != WINDOW_SHOW))
+                       {
+                               appWindow->rail_state = WINDOW_SHOW;
+                               xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_RESTORE);
+                       }
+               }
+       }
 
        return TRUE;
 }
 
-static BOOL xf_event_suppress_events(xfContext* xfc, xfAppWindow* appWindow, XEvent* event)
+static BOOL xf_event_suppress_events(xfContext* xfc, xfAppWindow* appWindow,
+                                     XEvent* event)
 {
        if (!xfc->remote_app)
                return FALSE;
@@ -873,51 +880,56 @@ static BOOL xf_event_suppress_events(xfContext* xfc, xfAppWindow* appWindow, XEv
        switch (appWindow->local_move.state)
        {
                case LMS_NOT_ACTIVE:
+
                        /* No local move in progress, nothing to do */
 
                        /* Prevent Configure from happening during indeterminant state of Horz or Vert Max only */
-
-                       if ((event->type == ConfigureNotify) && appWindow->rail_ignore_configure)
-                        {
-                               appWindow->rail_ignore_configure = FALSE;
-                               return TRUE;
-                        }
+                       if ((event->type == ConfigureNotify) && appWindow->rail_ignore_configure)
+                       {
+                               appWindow->rail_ignore_configure = FALSE;
+                               return TRUE;
+                       }
 
                        break;
 
                case LMS_STARTING:
+
                        /* Local move initiated by RDP server, but we have not yet seen any updates from the X server */
                        switch (event->type)
                        {
                                case ConfigureNotify:
                                        /* Starting to see move events from the X server. Local move is now in progress. */
                                        appWindow->local_move.state = LMS_ACTIVE;
-
                                        /* Allow these events to be processed during move to keep our state up to date. */
                                        break;
+
                                case ButtonPress:
                                case ButtonRelease:
                                case KeyPress:
                                case KeyRelease:
                                case UnmapNotify:
-                                       /*
-                                        * A button release event means the X window server did not grab the
-                                        * mouse before the user released it. In this case we must cancel the
-                                        * local move. The event will be processed below as normal, below.
-                                        */
-                                       break;
+                                       /*
+                                        * A button release event means the X window server did not grab the
+                                        * mouse before the user released it. In this case we must cancel the
+                                        * local move. The event will be processed below as normal, below.
+                                        */
+                                       break;
+
                                case VisibilityNotify:
                                case PropertyNotify:
                                case Expose:
                                        /* Allow these events to pass */
                                        break;
+
                                default:
                                        /* Eat any other events */
                                        return TRUE;
                        }
+
                        break;
 
                case LMS_ACTIVE:
+
                        /* Local move is in progress */
                        switch (event->type)
                        {
@@ -928,11 +940,13 @@ static BOOL xf_event_suppress_events(xfContext* xfc, xfAppWindow* appWindow, XEv
                                case GravityNotify:
                                        /* Keep us up to date on position */
                                        break;
+
                                default:
                                        /* Any other event terminates move */
                                        xf_rail_end_local_move(xfc, appWindow);
                                        break;
                        }
+
                        break;
 
                case LMS_TERMINATING:
@@ -967,7 +981,8 @@ BOOL xf_event_process(freerdp* instance, XEvent* event)
        xf_event_execute_action_script(xfc, event);
 
        if (event->type != MotionNotify)
-               DEBUG_X11("%s Event(%d): wnd=0x%04X", X11_EVENT_STRINGS[event->type], event->type, (UINT32) event->xany.window);
+               DEBUG_X11("%s Event(%d): wnd=0x%04X", X11_EVENT_STRINGS[event->type],
+                         event->type, (UINT32) event->xany.window);
 
        switch (event->type)
        {
@@ -1047,7 +1062,6 @@ BOOL xf_event_process(freerdp* instance, XEvent* event)
                case PropertyNotify:
                        status = xf_event_PropertyNotify(xfc, event, xfc->remote_app);
                        break;
-
        }
 
        if (!xfc->remote_app)
@@ -1056,8 +1070,6 @@ BOOL xf_event_process(freerdp* instance, XEvent* event)
        }
 
        xf_input_handle_event(xfc, event);
-
        XSync(xfc->display, FALSE);
-
        return status;
 }
index 184ffa1..9188414 100644 (file)
@@ -268,39 +268,28 @@ static Pixmap xf_mono_bitmap_new(xfContext* xfc, int width, int height,
 BOOL xf_gdi_bitmap_update(rdpContext* context,
                           const BITMAP_UPDATE* bitmapUpdate)
 {
-       int nXDst;
-       int nYDst;
-       int nXSrc;
-       int nYSrc;
-       int nWidth;
-       int nHeight;
        UINT32 index;
-       XImage* image;
-       BYTE* pSrcData;
-       BYTE* pDstData;
-       UINT32 SrcSize;
-       BOOL compressed;
-       UINT32 SrcFormat;
-       BITMAP_DATA* bitmap;
        rdpCodecs* codecs = context->codecs;
        xfContext* xfc = (xfContext*) context;
+       rdpSettings* settings = context->settings;
        BOOL ret = TRUE;
 
        for (index = 0; index < bitmapUpdate->number; index++)
        {
-               UINT32 bitsPerPixel;
-               bitmap = &(bitmapUpdate->rectangles[index]);
-               nXSrc = 0;
-               nYSrc = 0;
-               nXDst = bitmap->destLeft;
-               nYDst = bitmap->destTop;
-               nWidth = bitmap->width;
-               nHeight = bitmap->height;
-               pSrcData = bitmap->bitmapDataStream;
-               SrcSize = bitmap->bitmapLength;
-               compressed = bitmap->compressed;
-               bitsPerPixel = bitmap->bitsPerPixel;
-               SrcFormat = gdi_get_pixel_format(bitsPerPixel, TRUE);
+               BYTE* pDstData;
+               XImage* image;
+               BITMAP_DATA* bitmap = &(bitmapUpdate->rectangles[index]);
+               UINT32 bitsPerPixel = bitmap->bitsPerPixel;
+               UINT32 nXDst = bitmap->destLeft;
+               UINT32 nYDst = bitmap->destTop;
+               UINT32 nWidth = MIN(bitmap->destRight,
+                                   settings->DesktopWidth - 1) - bitmap->destLeft + 1; /* clip width */
+               UINT32 nHeight = MIN(bitmap->destBottom,
+                                    settings->DesktopHeight - 1) - bitmap->destTop + 1; /* clip height */
+               const BYTE* pSrcData = bitmap->bitmapDataStream;
+               UINT32 SrcSize = bitmap->bitmapLength;
+               BOOL compressed = bitmap->compressed;
+               UINT32 SrcFormat = gdi_get_pixel_format(bitsPerPixel, TRUE);
 
                if (compressed)
                {
@@ -310,6 +299,7 @@ BOOL xf_gdi_bitmap_update(rdpContext* context,
                        {
                                if (!interleaved_decompress(codecs->interleaved,
                                                            pSrcData, SrcSize,
+                                                           bitmap->width, bitmap->height,
                                                            bitsPerPixel,
                                                            pDstData,
                                                            xfc->format, 0,
@@ -320,7 +310,8 @@ BOOL xf_gdi_bitmap_update(rdpContext* context,
                        }
                        else
                        {
-                               if (!planar_decompress(codecs->planar, pSrcData, SrcSize, pDstData,
+                               if (!planar_decompress(codecs->planar, pSrcData, SrcSize,
+                                                      bitmap->width, bitmap->height, pDstData,
                                                       xfc->format, 0, 0, 0, nWidth, nHeight, TRUE))
                                        return FALSE;
                        }
index c860c31..0258309 100644 (file)
@@ -151,7 +151,7 @@ static BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
                if (bpp < 32)
                {
                        if (!interleaved_decompress(context->codecs->interleaved,
-                                                   pSrcData, SrcSize, bpp,
+                                                   pSrcData, SrcSize, width, height, bpp,
                                                    pDstData, xfc->format,
                                                    0, 0, 0, width, height,
                                                    &context->gdi->palette))
@@ -160,6 +160,7 @@ static BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
                else
                {
                        if (!planar_decompress(context->codecs->planar, pSrcData, SrcSize,
+                                              width, height,
                                               pDstData, xfc->format, 0, 0, 0, width, height, TRUE))
                                return FALSE;
                }
index 4549355..a250380 100644 (file)
@@ -100,9 +100,7 @@ struct xf_context
        GC gc;
        int xfds;
        int depth;
-       int sessionWidth;
-       int sessionHeight;
-       int srcBpp;
+
        GC gc_mono;
        BOOL invert;
        UINT32 format;
index 73b9442..2db260f 100644 (file)
@@ -44,10 +44,11 @@ extern "C" {
 
 FREERDP_API BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
                                         const BYTE* pSrcData, UINT32 SrcSize,
+                                        UINT32 nSrcWidth, UINT32 nSrcHeight,
                                         UINT32 bpp,
                                         BYTE* pDstData, UINT32 DstFormat,
                                         UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
-                                        UINT32 nWidth, UINT32 nHeight,
+                                        UINT32 nDstWidth, UINT32 nDstHeight,
                                         const gdiPalette* palette);
 
 FREERDP_API BOOL interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
@@ -57,8 +58,8 @@ FREERDP_API BOOL interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
                                       UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
                                       const gdiPalette* palette, UINT32 bpp);
 
-FREERDP_API BOOL bitmap_interleaved_context_reset(BITMAP_INTERLEAVED_CONTEXT*
-        interleaved);
+FREERDP_API BOOL bitmap_interleaved_context_reset(
+    BITMAP_INTERLEAVED_CONTEXT* interleaved);
 
 FREERDP_API BITMAP_INTERLEAVED_CONTEXT* bitmap_interleaved_context_new(
     BOOL Compressor);
index d58c191..bcaba43 100644 (file)
@@ -119,9 +119,10 @@ FREERDP_API void freerdp_bitmap_planar_context_free(
 
 FREERDP_API BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                                    const BYTE* pSrcData, UINT32 SrcSize,
+                                   UINT32 nSrcWidth, UINT32 nSrcHeight,
                                    BYTE* pDstData, UINT32 DstFormat,
                                    UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
-                                   UINT32 nWidth, UINT32 nHeight, BOOL vFlip);
+                                   UINT32 nDstWidth, UINT32 nDstHeight, BOOL vFlip);
 
 #ifdef __cplusplus
 }
index 93e4d04..b028cfd 100644 (file)
@@ -294,7 +294,6 @@ struct rdp_gdi
        gdiBitmap* drawing;
        UINT32 bitmap_size;
        UINT32 bitmap_stride;
-       BYTE* bitmap_buffer;
        BYTE* primary_buffer;
        gdiPalette palette;
        gdiBitmap* image;
index 0f50d52..ae2b8fb 100644 (file)
 #include <freerdp/gdi/gdi.h>
 
 #ifdef __cplusplus
- extern "C" {
+extern "C" {
 #endif
 
-FREERDP_API BOOL gdi_Ellipse(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
-FREERDP_API BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr);
-FREERDP_API BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINT *lpPoints, int nCount);
-FREERDP_API BOOL gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT *lpPoints, int *lpPolyCounts, int nCount);
-FREERDP_API BOOL gdi_Rectangle(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
-
-typedef BOOL (*p_FillRect)(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr);
+FREERDP_API BOOL gdi_Ellipse(HGDI_DC hdc, int nLeftRect, int nTopRect,
+                             int nRightRect, int nBottomRect);
+FREERDP_API BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect,
+                              HGDI_BRUSH hbr);
+FREERDP_API BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINT* lpPoints, int nCount);
+FREERDP_API BOOL gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT* lpPoints,
+                                 int* lpPolyCounts, int nCount);
+FREERDP_API BOOL gdi_Rectangle(HGDI_DC hdc, UINT32 nXDst, UINT32 nYDst,
+                               UINT32 nWidth, UINT32 nHeight);
 
 #ifdef __cplusplus
- }
+}
 #endif
 
 #endif /* FREERDP_GDI_SHAPE_H */
index bc91932..e05a605 100644 (file)
@@ -265,10 +265,11 @@ static INLINE UINT32 ExtractRunLength(UINT32 code, const BYTE* pbOrderHdr,
 
 BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
                             const BYTE* pSrcData, UINT32 SrcSize,
+                            UINT32 nSrcWidth, UINT32 nSrcHeight,
                             UINT32 bpp,
                             BYTE* pDstData, UINT32 DstFormat,
                             UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
-                            UINT32 nWidth, UINT32 nHeight,
+                            UINT32 nDstWidth, UINT32 nDstHeight,
                             const gdiPalette* palette)
 {
        UINT32 scanline;
@@ -283,27 +284,27 @@ BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
                return FALSE;
 
        if (nDstStep <= 0)
-               nDstStep = nWidth * dstBytesPerPixel;
+               nDstStep = nDstWidth * dstBytesPerPixel;
 
        switch (bpp)
        {
                case 24:
-                       scanline = nWidth * 3;
+                       scanline = nSrcWidth * 3;
                        SrcFormat = PIXEL_FORMAT_BGR24_VF;
                        break;
 
                case 16:
-                       scanline = nWidth * 2;
+                       scanline = nSrcWidth * 2;
                        SrcFormat = PIXEL_FORMAT_RGB16_VF;
                        break;
 
                case 15:
-                       scanline = nWidth * 2;
+                       scanline = nSrcWidth * 2;
                        SrcFormat = PIXEL_FORMAT_RGB15_VF;
                        break;
 
                case 8:
-                       scanline = nWidth;
+                       scanline = nSrcWidth;
                        SrcFormat = PIXEL_FORMAT_RGB8_VF;
                        break;
 
@@ -312,7 +313,7 @@ BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
                        return FALSE;
        }
 
-       BufferSize = scanline * nHeight;
+       BufferSize = scanline * nSrcHeight;
 
        if (BufferSize > interleaved->TempSize)
        {
@@ -329,18 +330,18 @@ BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
        {
                case 24:
                        RleDecompress24to24(pSrcData, SrcSize, interleaved->TempBuffer,
-                                           scanline, nWidth, nHeight);
+                                           scanline, nSrcWidth, nSrcHeight);
                        break;
 
                case 16:
                case 15:
                        RleDecompress16to16(pSrcData, SrcSize, interleaved->TempBuffer,
-                                           scanline, nWidth, nHeight);
+                                           scanline, nSrcWidth, nSrcHeight);
                        break;
 
                case 8:
                        RleDecompress8to8(pSrcData, SrcSize, interleaved->TempBuffer,
-                                         scanline, nWidth, nHeight);
+                                         scanline, nSrcWidth, nSrcHeight);
                        break;
 
                default:
@@ -348,7 +349,7 @@ BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
        }
 
        return freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst,
-                                 nWidth, nHeight, interleaved->TempBuffer,
+                                 nDstWidth, nDstHeight, interleaved->TempBuffer,
                                  SrcFormat, scanline, 0, 0, palette);
 }
 
index 959cca7..7577771 100644 (file)
@@ -43,9 +43,9 @@ static BOOL freerdp_bitmap_planar_delta_encode_planes(
     BYTE* outPlanes[4]);
 
 static INT32 planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
-                                   int nWidth, int nHeight)
+                                   UINT32 nDstWidth, UINT32 nDstHeight)
 {
-       int x, y;
+       UINT32 x, y;
        int cRawBytes;
        int nRunLength;
        BYTE controlByte;
@@ -287,9 +287,10 @@ static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4],
 
 BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        const BYTE* pSrcData, UINT32 SrcSize,
+                       UINT32 nSrcWidth, UINT32 nSrcHeight,
                        BYTE* pDstData, UINT32 DstFormat,
                        UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
-                       UINT32 nWidth, UINT32 nHeight, BOOL vFlip)
+                       UINT32 nDstWidth, UINT32 nDstHeight, BOOL vFlip)
 {
        BOOL cs;
        BOOL rle;
@@ -310,19 +311,21 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
        UINT32 dstBytesPerPixel;
        const BYTE* planes[4];
        UINT32 UncompressedSize;
+       const UINT32 w = MIN(nSrcWidth, nDstWidth);
+       const UINT32 h = MIN(nSrcHeight, nDstHeight);
        const primitives_t* prims = primitives_get();
 
-       if ((nWidth < 0) || (nHeight < 0))
+       if ((nSrcWidth < 0) || (nSrcHeight < 0))
                return FALSE;
 
        dstBitsPerPixel = GetBitsPerPixel(DstFormat);
        dstBytesPerPixel = GetBytesPerPixel(DstFormat);
 
        if (nDstStep <= 0)
-               nDstStep = nWidth * GetBytesPerPixel(DstFormat);
+               nDstStep = nDstWidth * GetBytesPerPixel(DstFormat);
 
        srcp = pSrcData;
-       UncompressedSize = nWidth * nHeight * GetBytesPerPixel(DstFormat);
+       UncompressedSize = nSrcWidth * nSrcHeight * GetBytesPerPixel(DstFormat);
 
        if (!pDstData)
        {
@@ -341,31 +344,31 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
        if (!cll && cs)
                return FALSE; /* Chroma subsampling requires YCoCg */
 
-       subWidth = (nWidth / 2) + (nWidth % 2);
-       subHeight = (nHeight / 2) + (nHeight % 2);
-       planeSize = nWidth * nHeight;
+       subWidth = (nSrcWidth / 2) + (nSrcWidth % 2);
+       subHeight = (nSrcHeight / 2) + (nSrcHeight % 2);
+       planeSize = nSrcWidth * nSrcHeight;
        subSize = subWidth * subHeight;
 
        if (!cs)
        {
                rawSizes[0] = planeSize; /* LumaOrRedPlane */
-               rawWidths[0] = nWidth;
-               rawHeights[0] = nHeight;
+               rawWidths[0] = nSrcWidth;
+               rawHeights[0] = nSrcHeight;
                rawSizes[1] = planeSize; /* OrangeChromaOrGreenPlane */
-               rawWidths[1] = nWidth;
-               rawHeights[1] = nHeight;
+               rawWidths[1] = nSrcWidth;
+               rawHeights[1] = nSrcHeight;
                rawSizes[2] = planeSize; /* GreenChromaOrBluePlane */
-               rawWidths[2] = nWidth;
-               rawHeights[2] = nHeight;
+               rawWidths[2] = nSrcWidth;
+               rawHeights[2] = nSrcHeight;
                rawSizes[3] = planeSize; /* AlphaPlane */
-               rawWidths[3] = nWidth;
-               rawHeights[3] = nHeight;
+               rawWidths[3] = nSrcWidth;
+               rawHeights[3] = nSrcHeight;
        }
        else /* Chroma Subsampling */
        {
                rawSizes[0] = planeSize; /* LumaOrRedPlane */
-               rawWidths[0] = nWidth;
-               rawHeights[0] = nHeight;
+               rawWidths[0] = nSrcWidth;
+               rawHeights[0] = nSrcHeight;
                rawSizes[1] = subSize; /* OrangeChromaOrGreenPlane */
                rawWidths[1] = subWidth;
                rawHeights[1] = subHeight;
@@ -373,8 +376,8 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                rawWidths[2] = subWidth;
                rawHeights[2] = subHeight;
                rawSizes[3] = planeSize; /* AlphaPlane */
-               rawWidths[3] = nWidth;
-               rawHeights[3] = nHeight;
+               rawWidths[3] = nSrcWidth;
+               rawHeights[3] = nSrcHeight;
        }
 
        if (!rle) /* RAW */
@@ -461,20 +464,35 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
 
        if (!cll) /* RGB */
        {
+               UINT32 TempFormat;
+               BYTE* pTempData = pDstData;
+               UINT32 nTempStep = nDstStep;
+
+               if (alpha)
+                       TempFormat = PIXEL_FORMAT_BGRA32;
+               else
+                       TempFormat = PIXEL_FORMAT_BGRX32;
+
+               if ((DstFormat != TempFormat) || (nSrcWidth != nDstWidth)
+                   || (nSrcHeight != nDstHeight))
+               {
+                       pTempData = planar->pTempData;
+               }
+
                if (!rle) /* RAW */
                {
                        if (alpha)
                        {
-                               if (!planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep,
-                                                                 nXDst, nYDst, nWidth, nHeight, alpha, vFlip))
+                               if (!planar_decompress_planes_raw(planes, pTempData, DstFormat, nDstStep,
+                                                                 nXDst, nYDst, nSrcWidth, nSrcHeight, alpha, vFlip))
                                        return FALSE;
 
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
                        }
                        else /* NoAlpha */
                        {
-                               if (!planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep,
-                                                                 nXDst, nYDst, nWidth, nHeight, alpha, vFlip))
+                               if (!planar_decompress_planes_raw(planes, pTempData, DstFormat, nDstStep,
+                                                                 nXDst, nYDst, nSrcWidth, nSrcHeight, alpha, vFlip))
                                        return FALSE;
 
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
@@ -485,45 +503,31 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                }
                else /* RLE */
                {
-                       UINT32 TempFormat;
-                       BYTE* pTempData = pDstData;
-                       UINT32 nTempStep = nDstStep;
-
-                       if (alpha)
-                               TempFormat = PIXEL_FORMAT_BGRA32;
-                       else
-                               TempFormat = PIXEL_FORMAT_BGRX32;
-
-                       if (DstFormat != TempFormat)
-                       {
-                               pTempData = planar->pTempData;
-                       }
-
                        if (alpha)
                        {
                                status = planar_decompress_plane_rle(planes[3], rleSizes[3],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 3,
                                                                     vFlip); /* AlphaPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 2,
                                                                     vFlip); /* RedPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 1,
                                                                     vFlip); /* GreenPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 0,
                                                                     vFlip); /* BluePlane */
 
                                if (status < 0)
@@ -534,21 +538,21 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        else /* NoAlpha */
                        {
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 2,
                                                                     vFlip); /* RedPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 1,
                                                                     vFlip); /* GreenPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 0,
                                                                     vFlip); /* BluePlane */
 
                                if (status < 0)
@@ -556,15 +560,14 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
 
                                srcp += rleSizes[0] + rleSizes[1] + rleSizes[2];
                        }
+               }
 
-                       if (pTempData != pDstData)
-                       {
-                               if (!freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth,
-                                                       nHeight,
-                                                       pTempData,
-                                                       TempFormat, nTempStep, nXDst, nYDst, NULL))
-                                       return FALSE;
-                       }
+               if (pTempData != pDstData)
+               {
+                       if (!freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, w,
+                                               h, pTempData,
+                                               TempFormat, nTempStep, nXDst, nYDst, NULL))
+                               return FALSE;
                }
        }
        else /* YCoCg */
@@ -587,7 +590,7 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        if (alpha)
                        {
                                if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep,
-                                                                 nXDst, nYDst, nWidth, nHeight, alpha, vFlip))
+                                                                 nXDst, nYDst, nSrcWidth, nSrcHeight, alpha, vFlip))
                                        return FALSE;
 
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
@@ -595,7 +598,7 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        else /* NoAlpha */
                        {
                                if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep,
-                                                                 nXDst, nYDst, nWidth, nHeight, alpha, vFlip))
+                                                                 nXDst, nYDst, nSrcWidth, nSrcHeight, alpha, vFlip))
                                        return FALSE;
 
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
@@ -609,28 +612,28 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        if (alpha)
                        {
                                status = planar_decompress_plane_rle(planes[3], rleSizes[3],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 3,
                                                                     vFlip); /* AlphaPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 2,
                                                                     vFlip); /* LumaPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 1,
                                                                     vFlip); /* OrangeChromaPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 0,
                                                                     vFlip); /* GreenChromaPlane */
 
                                if (status < 0)
@@ -641,21 +644,21 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        else /* NoAlpha */
                        {
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 2,
                                                                     vFlip); /* LumaPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 1,
                                                                     vFlip); /* OrangeChromaPlane */
 
                                if (status < 0)
                                        return FALSE;
 
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    pTempData, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, 0,
                                                                     vFlip); /* GreenChromaPlane */
 
                                if (status < 0)
@@ -665,8 +668,10 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        }
                }
 
-               prims->YCoCgToRGB_8u_AC4R(pTempData, nTempStep, pDstData, DstFormat, nDstStep,
-                                         nWidth, nHeight, cll, alpha);
+               if (prims->YCoCgToRGB_8u_AC4R(pTempData, nTempStep, pDstData, DstFormat,
+                                             nDstStep,
+                                             w, h, cll, alpha) != PRIMITIVES_SUCCESS)
+                       return FALSE;
        }
 
        return (SrcSize == (srcp - pSrcData)) ? TRUE : FALSE;
index 6be3e20..e430e1a 100644 (file)
@@ -3007,7 +3007,8 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
 
                pDstData = decompressedBitmap;
 
-               if (!planar_decompress(planar, compressedBitmap, dstSize, pDstData,
+               if (!planar_decompress(planar, compressedBitmap, dstSize,
+                                      width, height, pDstData,
                                       PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, FALSE))
                {
                        printf("failed to decompress white bitmap: width: %d height: %d\n", width,
@@ -3054,7 +3055,8 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
 
                pDstData = decompressedBitmap;
 
-               if (!planar_decompress(planar, compressedBitmap, dstSize, pDstData,
+               if (!planar_decompress(planar, compressedBitmap, dstSize,
+                                      width, height, pDstData,
                                       PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, FALSE))
                {
                        printf("failed to decompress black bitmap: width: %d height: %d\n", width,
@@ -3096,7 +3098,8 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
 
        pDstData = decompressedBitmap;
 
-       if (!planar_decompress(planar, compressedBitmap, dstSize, pDstData,
+       if (!planar_decompress(planar, compressedBitmap, dstSize, width, height,
+                              pDstData,
                               PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, FALSE))
        {
                printf("failed to decompress experimental bitmap 01: width: %d height: %d\n",
@@ -3142,7 +3145,8 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
 
        pDstData = decompressedBitmap;
 
-       if (!planar_decompress(planar, compressedBitmap, dstSize, pDstData,
+       if (!planar_decompress(planar, compressedBitmap, dstSize, width, height,
+                              pDstData,
                               PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, FALSE))
        {
                printf("failed to decompress experimental bitmap 02: width: %d height: %d\n",
@@ -3189,7 +3193,8 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
 
        pDstData = decompressedBitmap;
 
-       if (!planar_decompress(planar, compressedBitmap, dstSize, pDstData,
+       if (!planar_decompress(planar, compressedBitmap, dstSize, width, height,
+                              pDstData,
                               PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, FALSE))
        {
                printf("failed to decompress experimental bitmap 03: width: %d height: %d\n",
index 2746903..81bb6e0 100644 (file)
@@ -77,7 +77,8 @@ BOOL update_recv_orders(rdpUpdate* update, wStream* s)
        return TRUE;
 }
 
-BOOL update_read_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmapData)
+static BOOL update_read_bitmap_data(rdpUpdate* update, wStream* s,
+                                    BITMAP_DATA* bitmapData)
 {
        if (Stream_GetRemainingLength(s) < 18)
                return FALSE;
@@ -96,31 +97,31 @@ BOOL update_read_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmapD
        {
                if (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))
                {
-                       Stream_Read_UINT16(s, bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
-                       Stream_Read_UINT16(s, bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
+                       Stream_Read_UINT16(s,
+                                          bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
+                       Stream_Read_UINT16(s,
+                                          bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
                        Stream_Read_UINT16(s, bitmapData->cbScanWidth); /* cbScanWidth (2 bytes) */
-                       Stream_Read_UINT16(s, bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
+                       Stream_Read_UINT16(s,
+                                          bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
                        bitmapData->bitmapLength = bitmapData->cbCompMainBodySize;
                }
 
                bitmapData->compressed = TRUE;
-               Stream_GetPointer(s, bitmapData->bitmapDataStream);
-               Stream_Seek(s, bitmapData->bitmapLength);
        }
        else
-       {
-               if (Stream_GetRemainingLength(s) < bitmapData->bitmapLength)
-                       return FALSE;
-
                bitmapData->compressed = FALSE;
-               Stream_GetPointer(s, bitmapData->bitmapDataStream);
-               Stream_Seek(s, bitmapData->bitmapLength);
-       }
 
+       if (Stream_GetRemainingLength(s) < bitmapData->bitmapLength)
+               return FALSE;
+
+       Stream_GetPointer(s, bitmapData->bitmapDataStream);
+       Stream_Seek(s, bitmapData->bitmapLength);
        return TRUE;
 }
 
-BOOL update_write_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmapData)
+BOOL update_write_bitmap_data(rdpUpdate* update, wStream* s,
+                              BITMAP_DATA* bitmapData)
 {
        if (!Stream_EnsureRemainingCapacity(s, 64 + bitmapData->bitmapLength))
                return FALSE;
@@ -151,10 +152,13 @@ BOOL update_write_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmap
        {
                if (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))
                {
-                       Stream_Write_UINT16(s, bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
-                       Stream_Write_UINT16(s, bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
+                       Stream_Write_UINT16(s,
+                                           bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
+                       Stream_Write_UINT16(s,
+                                           bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
                        Stream_Write_UINT16(s, bitmapData->cbScanWidth); /* cbScanWidth (2 bytes) */
-                       Stream_Write_UINT16(s, bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
+                       Stream_Write_UINT16(s,
+                                           bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
                }
 
                Stream_Write(s, bitmapData->bitmapDataStream, bitmapData->bitmapLength);
@@ -167,48 +171,46 @@ BOOL update_write_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmap
        return TRUE;
 }
 
-BOOL update_read_bitmap_update(rdpUpdate* update, wStream* s, BITMAP_UPDATE* bitmapUpdate)
+BOOL update_read_bitmap_update(rdpUpdate* update, wStream* s,
+                               BITMAP_UPDATE* bitmapUpdate)
 {
-       int i;
+       UINT32 i;
 
        if (Stream_GetRemainingLength(s) < 2)
                return FALSE;
 
        Stream_Read_UINT16(s, bitmapUpdate->number); /* numberRectangles (2 bytes) */
-
-       WLog_Print(update->log, WLOG_DEBUG, "BitmapUpdate: %d", bitmapUpdate->number);
+       WLog_Print(update->log, WLOG_TRACE, "BitmapUpdate: %d", bitmapUpdate->number);
 
        if (bitmapUpdate->number > bitmapUpdate->count)
        {
                UINT16 count;
-               BITMAP_DATA *newdata;
-
+               BITMAP_DATA* newdata;
                count = bitmapUpdate->number * 2;
-
                newdata = (BITMAP_DATA*) realloc(bitmapUpdate->rectangles,
-                               sizeof(BITMAP_DATA) * count);
+                                                sizeof(BITMAP_DATA) * count);
+
                if (!newdata)
                        return FALSE;
 
                bitmapUpdate->rectangles = newdata;
-
                ZeroMemory(&bitmapUpdate->rectangles[bitmapUpdate->count],
-                               sizeof(BITMAP_DATA) * (count - bitmapUpdate->count));
-
+                          sizeof(BITMAP_DATA) * (count - bitmapUpdate->count));
                bitmapUpdate->count = count;
        }
 
        /* rectangles */
-       for (i = 0; i < (int) bitmapUpdate->number; i++)
+       for (i = 0; i < bitmapUpdate->number; i++)
        {
                if (!update_read_bitmap_data(update, s, &bitmapUpdate->rectangles[i]))
                        return FALSE;
        }
+
        return TRUE;
 }
 
 static BOOL update_write_bitmap_update(rdpUpdate* update, wStream* s,
-                               const BITMAP_UPDATE* bitmapUpdate)
+                                       const BITMAP_UPDATE* bitmapUpdate)
 {
        int i;
 
@@ -216,7 +218,6 @@ static BOOL update_write_bitmap_update(rdpUpdate* update, wStream* s,
                return FALSE;
 
        Stream_Write_UINT16(s, UPDATE_TYPE_BITMAP); /* updateType */
-
        Stream_Write_UINT16(s, bitmapUpdate->number); /* numberRectangles (2 bytes) */
 
        /* rectangles */
@@ -229,7 +230,8 @@ static BOOL update_write_bitmap_update(rdpUpdate* update, wStream* s,
        return TRUE;
 }
 
-BOOL update_read_palette(rdpUpdate* update, wStream* s, PALETTE_UPDATE* palette_update)
+BOOL update_read_palette(rdpUpdate* update, wStream* s,
+                         PALETTE_UPDATE* palette_update)
 {
        int i;
        PALETTE_ENTRY* entry;
@@ -238,7 +240,8 @@ BOOL update_read_palette(rdpUpdate* update, wStream* s, PALETTE_UPDATE* palette_
                return FALSE;
 
        Stream_Seek_UINT16(s); /* pad2Octets (2 bytes) */
-       Stream_Read_UINT32(s, palette_update->number); /* numberColors (4 bytes), must be set to 256 */
+       Stream_Read_UINT32(s,
+                          palette_update->number); /* numberColors (4 bytes), must be set to 256 */
 
        if (palette_update->number > 256)
                palette_update->number = 256;
@@ -250,18 +253,17 @@ BOOL update_read_palette(rdpUpdate* update, wStream* s, PALETTE_UPDATE* palette_
        for (i = 0; i < (int) palette_update->number; i++)
        {
                entry = &palette_update->entries[i];
-
                Stream_Read_UINT8(s, entry->red);
                Stream_Read_UINT8(s, entry->green);
                Stream_Read_UINT8(s, entry->blue);
        }
+
        return TRUE;
 }
 
 void update_read_synchronize(rdpUpdate* update, wStream* s)
 {
        Stream_Seek_UINT16(s); /* pad2Octets (2 bytes) */
-
        /**
         * The Synchronize Update is an artifact from the
         * T.128 protocol and should be ignored.
@@ -275,7 +277,6 @@ BOOL update_read_play_sound(wStream* s, PLAY_SOUND_UPDATE* play_sound)
 
        Stream_Read_UINT32(s, play_sound->duration); /* duration (4 bytes) */
        Stream_Read_UINT32(s, play_sound->frequency); /* frequency (4 bytes) */
-
        return TRUE;
 }
 
@@ -288,7 +289,8 @@ BOOL update_recv_play_sound(rdpUpdate* update, wStream* s)
        return TRUE;
 }
 
-BOOL update_read_pointer_position(wStream* s, POINTER_POSITION_UPDATE* pointer_position)
+BOOL update_read_pointer_position(wStream* s,
+                                  POINTER_POSITION_UPDATE* pointer_position)
 {
        if (Stream_GetRemainingLength(s) < 4)
                return FALSE;
@@ -298,7 +300,8 @@ BOOL update_read_pointer_position(wStream* s, POINTER_POSITION_UPDATE* pointer_p
        return TRUE;
 }
 
-BOOL update_read_pointer_system(wStream* s, POINTER_SYSTEM_UPDATE* pointer_system)
+BOOL update_read_pointer_system(wStream* s,
+                                POINTER_SYSTEM_UPDATE* pointer_system)
 {
        if (Stream_GetRemainingLength(s) < 4)
                return FALSE;
@@ -307,9 +310,10 @@ BOOL update_read_pointer_system(wStream* s, POINTER_SYSTEM_UPDATE* pointer_syste
        return TRUE;
 }
 
-BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color, int xorBpp)
+BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color,
+                               int xorBpp)
 {
-       BYTE *newMask;
+       BYTEnewMask;
        int scanlineSize;
 
        if (Stream_GetRemainingLength(s) < 14)
@@ -318,7 +322,6 @@ BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color,
        Stream_Read_UINT16(s, pointer_color->cacheIndex); /* cacheIndex (2 bytes) */
        Stream_Read_UINT16(s, pointer_color->xPos); /* xPos (2 bytes) */
        Stream_Read_UINT16(s, pointer_color->yPos); /* yPos (2 bytes) */
-
        /**
         *  As stated in 2.2.9.1.1.4.4 Color Pointer Update:
         *  The maximum allowed pointer width/height is 96 pixels if the client indicated support
@@ -330,11 +333,14 @@ BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color,
         */
        Stream_Read_UINT16(s, pointer_color->width); /* width (2 bytes) */
        Stream_Read_UINT16(s, pointer_color->height); /* height (2 bytes) */
+
        if ((pointer_color->width > 96) || (pointer_color->height > 96))
                return FALSE;
 
-       Stream_Read_UINT16(s, pointer_color->lengthAndMask); /* lengthAndMask (2 bytes) */
-       Stream_Read_UINT16(s, pointer_color->lengthXorMask); /* lengthXorMask (2 bytes) */
+       Stream_Read_UINT16(s,
+                          pointer_color->lengthAndMask); /* lengthAndMask (2 bytes) */
+       Stream_Read_UINT16(s,
+                          pointer_color->lengthXorMask); /* lengthXorMask (2 bytes) */
 
        /**
         * There does not seem to be any documentation on why
@@ -344,6 +350,7 @@ BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color,
         */
        if (pointer_color->xPos >= pointer_color->width)
                pointer_color->xPos = 0;
+
        if (pointer_color->yPos >= pointer_color->height)
                pointer_color->yPos = 0;
 
@@ -365,20 +372,21 @@ BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color,
 
                scanlineSize = (7 + xorBpp * pointer_color->width) / 8;
                scanlineSize = ((scanlineSize + 1) / 2) * 2;
+
                if (scanlineSize * pointer_color->height != pointer_color->lengthXorMask)
                {
                        WLog_ERR(TAG,  "invalid lengthXorMask: width=%d height=%d, %d instead of %d",
-                                        pointer_color->width, pointer_color->height,
-                                        pointer_color->lengthXorMask, scanlineSize * pointer_color->height);
+                                pointer_color->width, pointer_color->height,
+                                pointer_color->lengthXorMask, scanlineSize * pointer_color->height);
                        return FALSE;
                }
 
                newMask = realloc(pointer_color->xorMaskData, pointer_color->lengthXorMask);
+
                if (!newMask)
                        return FALSE;
 
                pointer_color->xorMaskData = newMask;
-
                Stream_Read(s, pointer_color->xorMaskData, pointer_color->lengthXorMask);
        }
 
@@ -396,19 +404,20 @@ BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color,
 
                scanlineSize = ((7 + pointer_color->width) / 8);
                scanlineSize = ((1 + scanlineSize) / 2) * 2;
+
                if (scanlineSize * pointer_color->height != pointer_color->lengthAndMask)
                {
                        WLog_ERR(TAG,  "invalid lengthAndMask: %d instead of %d",
-                                        pointer_color->lengthAndMask, scanlineSize * pointer_color->height);
+                                pointer_color->lengthAndMask, scanlineSize * pointer_color->height);
                        return FALSE;
                }
 
                newMask = realloc(pointer_color->andMaskData, pointer_color->lengthAndMask);
+
                if (!newMask)
                        return FALSE;
 
                pointer_color->andMaskData = newMask;
-
                Stream_Read(s, pointer_color->andMaskData, pointer_color->lengthAndMask);
        }
 
@@ -424,15 +433,19 @@ BOOL update_read_pointer_new(wStream* s, POINTER_NEW_UPDATE* pointer_new)
                return FALSE;
 
        Stream_Read_UINT16(s, pointer_new->xorBpp); /* xorBpp (2 bytes) */
+
        if ((pointer_new->xorBpp < 1) || (pointer_new->xorBpp > 32))
        {
                WLog_ERR(TAG,  "invalid xorBpp %d", pointer_new->xorBpp);
                return FALSE;
        }
-       return update_read_pointer_color(s, &pointer_new->colorPtrAttr, pointer_new->xorBpp); /* colorPtrAttr */
+
+       return update_read_pointer_color(s, &pointer_new->colorPtrAttr,
+                                        pointer_new->xorBpp); /* colorPtrAttr */
 }
 
-BOOL update_read_pointer_cached(wStream* s, POINTER_CACHED_UPDATE* pointer_cached)
+BOOL update_read_pointer_cached(wStream* s,
+                                POINTER_CACHED_UPDATE* pointer_cached)
 {
        if (Stream_GetRemainingLength(s) < 2)
                return FALSE;
@@ -458,36 +471,42 @@ BOOL update_recv_pointer(rdpUpdate* update, wStream* s)
                case PTR_MSG_TYPE_POSITION:
                        if (!update_read_pointer_position(s, &pointer->pointer_position))
                                return FALSE;
+
                        IFCALL(pointer->PointerPosition, context, &pointer->pointer_position);
                        break;
 
                case PTR_MSG_TYPE_SYSTEM:
                        if (!update_read_pointer_system(s, &pointer->pointer_system))
                                return FALSE;
+
                        IFCALL(pointer->PointerSystem, context, &pointer->pointer_system);
                        break;
 
                case PTR_MSG_TYPE_COLOR:
                        if (!update_read_pointer_color(s, &pointer->pointer_color, 24))
                                return FALSE;
+
                        IFCALL(pointer->PointerColor, context, &pointer->pointer_color);
                        break;
 
                case PTR_MSG_TYPE_POINTER:
                        if (!update_read_pointer_new(s, &pointer->pointer_new))
                                return FALSE;
+
                        IFCALL(pointer->PointerNew, context, &pointer->pointer_new);
                        break;
 
                case PTR_MSG_TYPE_CACHED:
                        if (!update_read_pointer_cached(s, &pointer->pointer_cached))
                                return FALSE;
+
                        IFCALL(pointer->PointerCached, context, &pointer->pointer_cached);
                        break;
 
                default:
                        break;
        }
+
        return TRUE;
 }
 
@@ -504,7 +523,6 @@ BOOL update_recv(rdpUpdate* update, wStream* s)
 
        Stream_Read_UINT16(s, updateType); /* updateType (2 bytes) */
        //WLog_DBG(TAG, "%s Update Data PDU", UPDATE_TYPE_STRINGS[updateType]);
-
        IFCALL(update->BeginPaint, context);
 
        switch (updateType)
@@ -516,6 +534,7 @@ BOOL update_recv(rdpUpdate* update, wStream* s)
                                WLog_ERR(TAG, "UPDATE_TYPE_ORDERS - update_recv_orders() failed");
                                return FALSE;
                        }
+
                        break;
 
                case UPDATE_TYPE_BITMAP:
@@ -524,6 +543,7 @@ BOOL update_recv(rdpUpdate* update, wStream* s)
                                WLog_ERR(TAG, "UPDATE_TYPE_BITMAP - update_read_bitmap_update() failed");
                                return FALSE;
                        }
+
                        IFCALL(update->BitmapUpdate, context, &update->bitmap_update);
                        break;
 
@@ -533,6 +553,7 @@ BOOL update_recv(rdpUpdate* update, wStream* s)
                                WLog_ERR(TAG, "UPDATE_TYPE_PALETTE - update_read_palette() failed");
                                return FALSE;
                        }
+
                        IFCALL(update->Palette, context, &update->palette_update);
                        break;
 
@@ -543,7 +564,6 @@ BOOL update_recv(rdpUpdate* update, wStream* s)
        }
 
        IFCALL(update->EndPaint, context);
-
        return TRUE;
 }
 
@@ -581,7 +601,6 @@ void update_reset_state(rdpUpdate* update)
        ZeroMemory(&primary->polygon_cb, sizeof(POLYGON_CB_ORDER));
        ZeroMemory(&primary->ellipse_sc, sizeof(ELLIPSE_SC_ORDER));
        ZeroMemory(&primary->ellipse_cb, sizeof(ELLIPSE_CB_ORDER));
-
        primary->order_info.orderType = ORDER_TYPE_PATBLT;
 
        if (!update->initialState)
@@ -600,10 +619,9 @@ BOOL update_post_connect(rdpUpdate* update)
                        return FALSE;
 
        update->altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
-       IFCALL(update->altsec->SwitchSurface, update->context, &(update->altsec->switch_surface));
-
+       IFCALL(update->altsec->SwitchSurface, update->context,
+              &(update->altsec->switch_surface));
        update->initialState = FALSE;
-
        return TRUE;
 }
 
@@ -624,11 +642,12 @@ static BOOL update_begin_paint(rdpContext* context)
                update->EndPaint(context);
 
        s = fastpath_update_pdu_init_new(context->rdp->fastpath);
+
        if (!s)
                return FALSE;
+
        Stream_SealLength(s);
        Stream_Seek(s, 2); /* numberOrders (2 bytes) */
-
        update->combineUpdates = TRUE;
        update->numberOrders = 0;
        update->us = s;
@@ -647,7 +666,6 @@ static BOOL update_end_paint(rdpContext* context)
        s = update->us;
        headerLength = Stream_Length(s);
        Stream_SealLength(s);
-
        Stream_SetPosition(s, headerLength);
        Stream_Write_UINT16(s, update->numberOrders); /* numberOrders (2 bytes) */
        Stream_SetPosition(s, Stream_Length(s));
@@ -655,13 +673,13 @@ static BOOL update_end_paint(rdpContext* context)
        if (update->numberOrders > 0)
        {
                WLog_ERR(TAG,  "sending %d orders", update->numberOrders);
-               fastpath_send_update_pdu(context->rdp->fastpath, FASTPATH_UPDATETYPE_ORDERS, s, FALSE);
+               fastpath_send_update_pdu(context->rdp->fastpath, FASTPATH_UPDATETYPE_ORDERS, s,
+                                        FALSE);
        }
 
        update->combineUpdates = FALSE;
        update->numberOrders = 0;
        update->us = NULL;
-
        Stream_Free(s, TRUE);
        return TRUE;
 }
@@ -692,7 +710,6 @@ static BOOL update_check_flush(rdpContext* context, int size)
 {
        wStream* s;
        rdpUpdate* update = context->update;
-
        s = update->us;
 
        if (!update->us)
@@ -711,23 +728,23 @@ static BOOL update_check_flush(rdpContext* context, int size)
 }
 
 static BOOL update_set_bounds(rdpContext* context,
-                                 const rdpBounds* bounds)
+                              const rdpBounds* bounds)
 {
        rdpUpdate* update = context->update;
-
        CopyMemory(&update->previousBounds, &update->currentBounds, sizeof(rdpBounds));
 
        if (!bounds)
                ZeroMemory(&update->currentBounds, sizeof(rdpBounds));
        else
                CopyMemory(&update->currentBounds, bounds, sizeof(rdpBounds));
+
        return TRUE;
 }
 
 BOOL update_bounds_is_null(rdpBounds* bounds)
 {
        if ((bounds->left == 0) && (bounds->top == 0) &&
-                       (bounds->right == 0) && (bounds->bottom == 0))
+           (bounds->right == 0) && (bounds->bottom == 0))
                return TRUE;
 
        return FALSE;
@@ -736,7 +753,7 @@ BOOL update_bounds_is_null(rdpBounds* bounds)
 BOOL update_bounds_equals(rdpBounds* bounds1, rdpBounds* bounds2)
 {
        if ((bounds1->left == bounds2->left) && (bounds1->top == bounds2->top) &&
-               (bounds1->right == bounds2->right) && (bounds1->bottom == bounds2->bottom))
+           (bounds1->right == bounds2->right) && (bounds1->bottom == bounds2->bottom))
                return TRUE;
 
        return FALSE;
@@ -746,7 +763,6 @@ int update_prepare_bounds(rdpContext* context, ORDER_INFO* orderInfo)
 {
        int length = 0;
        rdpUpdate* update = context->update;
-
        orderInfo->boundsFlags = 0;
 
        if (update_bounds_is_null(&update->currentBounds))
@@ -796,53 +812,41 @@ int update_prepare_bounds(rdpContext* context, ORDER_INFO* orderInfo)
 }
 
 static int update_prepare_order_info(rdpContext* context,
-                                        ORDER_INFO* orderInfo, UINT32 orderType)
+                                     ORDER_INFO* orderInfo, UINT32 orderType)
 {
        int length = 1;
-
        orderInfo->fieldFlags = 0;
        orderInfo->orderType = orderType;
-
        orderInfo->controlFlags = ORDER_STANDARD;
-
        orderInfo->controlFlags |= ORDER_TYPE_CHANGE;
        length += 1;
-
        length += PRIMARY_DRAWING_ORDER_FIELD_BYTES[orderInfo->orderType];
-
        length += update_prepare_bounds(context, orderInfo);
-
        return length;
 }
 
 int update_write_order_info(rdpContext* context, wStream* s,
-                               ORDER_INFO* orderInfo, int offset)
+                            ORDER_INFO* orderInfo, int offset)
 {
        int position;
-
        position = Stream_GetPosition(s);
        Stream_SetPosition(s, offset);
-
        Stream_Write_UINT8(s, orderInfo->controlFlags); /* controlFlags (1 byte) */
 
        if (orderInfo->controlFlags & ORDER_TYPE_CHANGE)
                Stream_Write_UINT8(s, orderInfo->orderType); /* orderType (1 byte) */
 
        update_write_field_flags(s, orderInfo->fieldFlags, orderInfo->controlFlags,
-                       PRIMARY_DRAWING_ORDER_FIELD_BYTES[orderInfo->orderType]);
-
+                                PRIMARY_DRAWING_ORDER_FIELD_BYTES[orderInfo->orderType]);
        update_write_bounds(s, orderInfo);
-
        Stream_SetPosition(s, position);
-
        return 0;
 }
 
 static void update_write_refresh_rect(wStream* s, BYTE count,
-                                         const RECTANGLE_16* areas)
+                                      const RECTANGLE_16* areas)
 {
        int i;
-
        Stream_Write_UINT8(s, count); /* numberOfAreas (1 byte) */
        Stream_Seek(s, 3); /* pad3Octets (3 bytes) */
 
@@ -856,7 +860,7 @@ static void update_write_refresh_rect(wStream* s, BYTE count,
 }
 
 static BOOL update_send_refresh_rect(rdpContext* context, BYTE count,
-                                        const RECTANGLE_16* areas)
+                                     const RECTANGLE_16* areas)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
@@ -865,19 +869,21 @@ static BOOL update_send_refresh_rect(rdpContext* context, BYTE count,
        {
                BOOL ret;
                s = rdp_data_pdu_init(rdp);
+
                if (!s)
                        return FALSE;
-               update_write_refresh_rect(s, count, areas);
 
+               update_write_refresh_rect(s, count, areas);
                ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_REFRESH_RECT, rdp->mcs->userId);
                Stream_Release(s);
                return ret;
        }
+
        return TRUE;
 }
 
 static void update_write_suppress_output(wStream* s, BYTE allow,
-                                        const RECTANGLE_16* area)
+        const RECTANGLE_16* area)
 {
        Stream_Write_UINT8(s, allow); /* allowDisplayUpdates (1 byte) */
        /* Use zeros for padding (like mstsc) for compatibility with legacy servers */
@@ -893,7 +899,7 @@ static void update_write_suppress_output(wStream* s, BYTE allow,
 }
 
 static BOOL update_send_suppress_output(rdpContext* context, BYTE allow,
-                                       const RECTANGLE_16* area)
+                                        const RECTANGLE_16* area)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
@@ -902,14 +908,17 @@ static BOOL update_send_suppress_output(rdpContext* context, BYTE allow,
        {
                BOOL ret;
                s = rdp_data_pdu_init(rdp);
+
                if (!s)
                        return FALSE;
-               update_write_suppress_output(s, allow, area);
 
-               ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SUPPRESS_OUTPUT, rdp->mcs->userId);
+               update_write_suppress_output(s, allow, area);
+               ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SUPPRESS_OUTPUT,
+                                       rdp->mcs->userId);
                Stream_Release(s);
                return ret;
        }
+
        return TRUE;
 }
 
@@ -918,47 +927,51 @@ static BOOL update_send_surface_command(rdpContext* context, wStream* s)
        wStream* update;
        rdpRdp* rdp = context->rdp;
        BOOL ret;
-
        update = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!update)
                return FALSE;
+
        if (!Stream_EnsureRemainingCapacity(update, Stream_GetPosition(s)))
        {
                ret = FALSE;
                goto out;
        }
-       Stream_Write(update, Stream_Buffer(s), Stream_GetPosition(s));
-       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, update, FALSE);
 
+       Stream_Write(update, Stream_Buffer(s), Stream_GetPosition(s));
+       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS,
+                                      update, FALSE);
 out:
        Stream_Release(update);
        return ret;
 }
 
 static BOOL update_send_surface_bits(rdpContext* context,
-                                        const SURFACE_BITS_COMMAND* surfaceBitsCommand)
+                                     const SURFACE_BITS_COMMAND* surfaceBitsCommand)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret = FALSE;
-
        update_force_flush(context);
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
 
-       if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) surfaceBitsCommand->bitmapDataLength) ||
-               !update_write_surfcmd_surface_bits_header(s, surfaceBitsCommand))
+       if (!Stream_EnsureRemainingCapacity(s,
+                                           SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) surfaceBitsCommand->bitmapDataLength)
+           ||
+           !update_write_surfcmd_surface_bits_header(s, surfaceBitsCommand))
                goto out_fail;
 
-       Stream_Write(s, surfaceBitsCommand->bitmapData, surfaceBitsCommand->bitmapDataLength);
+       Stream_Write(s, surfaceBitsCommand->bitmapData,
+                    surfaceBitsCommand->bitmapDataLength);
 
-       if (!fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s, surfaceBitsCommand->skipCompression))
+       if (!fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s,
+                                     surfaceBitsCommand->skipCompression))
                goto out_fail;
 
        update_force_flush(context);
-
        ret = TRUE;
 out_fail:
        Stream_Release(s);
@@ -966,24 +979,24 @@ out_fail:
 }
 
 static BOOL update_send_surface_frame_marker(rdpContext* context,
-                                                const SURFACE_FRAME_MARKER* surfaceFrameMarker)
+        const SURFACE_FRAME_MARKER* surfaceFrameMarker)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret = FALSE;
-
        update_force_flush(context);
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
 
-       if (!update_write_surfcmd_frame_marker(s, surfaceFrameMarker->frameAction, surfaceFrameMarker->frameId) ||
-               !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s, FALSE))
+       if (!update_write_surfcmd_frame_marker(s, surfaceFrameMarker->frameAction,
+                                              surfaceFrameMarker->frameId) ||
+           !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s,
+                                     FALSE))
                goto out_fail;
 
        update_force_flush(context);
-
        ret = TRUE;
 out_fail:
        Stream_Release(s);
@@ -991,30 +1004,32 @@ out_fail:
 }
 
 static BOOL update_send_surface_frame_bits(rdpContext* context,
-                                          const SURFACE_BITS_COMMAND* cmd,
-                                          BOOL first, BOOL last, UINT32 frameId)
+        const SURFACE_BITS_COMMAND* cmd,
+        BOOL first, BOOL last, UINT32 frameId)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret = FALSE;
-
        update_force_flush(context);
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
 
-       if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) cmd->bitmapDataLength + 16))
+       if (!Stream_EnsureRemainingCapacity(s,
+                                           SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) cmd->bitmapDataLength + 16))
                goto out_fail;
 
        if (first)
        {
-               if (!update_write_surfcmd_frame_marker(s, SURFACECMD_FRAMEACTION_BEGIN, frameId))
+               if (!update_write_surfcmd_frame_marker(s, SURFACECMD_FRAMEACTION_BEGIN,
+                                                      frameId))
                        goto out_fail;
        }
 
        if (!update_write_surfcmd_surface_bits_header(s, cmd))
                goto out_fail;
+
        Stream_Write(s, cmd->bitmapData, cmd->bitmapDataLength);
 
        if (last)
@@ -1023,10 +1038,9 @@ static BOOL update_send_surface_frame_bits(rdpContext* context,
                        goto out_fail;
        }
 
-       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s, cmd->skipCompression);
-
+       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s,
+                                      cmd->skipCompression);
        update_force_flush(context);
-
 out_fail:
        Stream_Release(s);
        return ret;
@@ -1041,13 +1055,17 @@ static BOOL update_send_frame_acknowledge(rdpContext* context, UINT32 frameId)
        {
                BOOL ret;
                s = rdp_data_pdu_init(rdp);
+
                if (!s)
                        return FALSE;
+
                Stream_Write_UINT32(s, frameId);
-               ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FRAME_ACKNOWLEDGE, rdp->mcs->userId);
+               ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FRAME_ACKNOWLEDGE,
+                                       rdp->mcs->userId);
                Stream_Release(s);
                return ret;
        }
+
        return TRUE;
 }
 
@@ -1056,12 +1074,14 @@ static BOOL update_send_synchronize(rdpContext* context)
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret;
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
+
        Stream_Zero(s, 2); /* pad2Octets (2 bytes) */
-       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SYNCHRONIZE, s, FALSE);
+       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SYNCHRONIZE,
+                                      s, FALSE);
        Stream_Release(s);
        return ret;
 }
@@ -1072,45 +1092,49 @@ static BOOL update_send_desktop_resize(rdpContext* context)
 }
 
 static BOOL update_send_bitmap_update(rdpContext* context,
-                                         const BITMAP_UPDATE* bitmapUpdate)
+                                      const BITMAP_UPDATE* bitmapUpdate)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        rdpUpdate* update = context->update;
        BOOL ret = TRUE;
-
        update_force_flush(context);
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
+
        if (!update_write_bitmap_update(update, s, bitmapUpdate) ||
-               !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_BITMAP, s, bitmapUpdate->skipCompression))
+           !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_BITMAP, s,
+                                     bitmapUpdate->skipCompression))
        {
                ret = FALSE;
                goto out_fail;
        }
 
        update_force_flush(context);
-
 out_fail:
        Stream_Release(s);
        return ret;
 }
 
 static BOOL update_send_play_sound(rdpContext* context,
-                                  const PLAY_SOUND_UPDATE* play_sound)
+                                   const PLAY_SOUND_UPDATE* play_sound)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret;
 
-       if (!rdp->settings->ReceivedCapabilities[CAPSET_TYPE_SOUND]) {
+       if (!rdp->settings->ReceivedCapabilities[CAPSET_TYPE_SOUND])
+       {
                return TRUE;
        }
+
        s = rdp_data_pdu_init(rdp);
+
        if (!s)
                return FALSE;
+
        Stream_Write_UINT32(s, play_sound->duration);
        Stream_Write_UINT32(s, play_sound->frequency);
        ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_PLAY_SOUND, rdp->mcs->userId);
@@ -1122,7 +1146,7 @@ static BOOL update_send_play_sound(rdpContext* context,
  */
 
 static BOOL update_send_dstblt(rdpContext* context,
-                                  const DSTBLT_ORDER* dstblt)
+                               const DSTBLT_ORDER* dstblt)
 {
        wStream* s;
        UINT32 offset;
@@ -1130,25 +1154,26 @@ static BOOL update_send_dstblt(rdpContext* context,
        ORDER_INFO orderInfo;
        int inf;
        rdpUpdate* update = context->update;
-
-       headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_DSTBLT);
-
+       headerLength = update_prepare_order_info(context, &orderInfo,
+                      ORDER_TYPE_DSTBLT);
        inf = update_approximate_dstblt_order(&orderInfo, dstblt);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
+
        offset = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
+
        Stream_Seek(s, headerLength);
 
        if (!update_write_dstblt_order(s, &orderInfo, dstblt))
                return FALSE;
-       update_write_order_info(context, s, &orderInfo, offset);
 
+       update_write_order_info(context, s, &orderInfo, offset);
        update->numberOrders++;
        return TRUE;
 }
@@ -1160,23 +1185,23 @@ static BOOL update_send_patblt(rdpContext* context, PATBLT_ORDER* patblt)
        int headerLength;
        ORDER_INFO orderInfo;
        rdpUpdate* update = context->update;
-
-       headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_PATBLT);
-
-       update_check_flush(context, headerLength + update_approximate_patblt_order(&orderInfo, patblt));
-
+       headerLength = update_prepare_order_info(context, &orderInfo,
+                      ORDER_TYPE_PATBLT);
+       update_check_flush(context,
+                          headerLength + update_approximate_patblt_order(&orderInfo, patblt));
        s = update->us;
+
        if (!s)
                return FALSE;
+
        offset = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
-       Stream_Seek(s, headerLength);
 
+       Stream_Seek(s, headerLength);
        update_write_patblt_order(s, &orderInfo, patblt);
        update_write_order_info(context, s, &orderInfo, offset);
-
        update->numberOrders++;
        return TRUE;
 }
@@ -1189,59 +1214,58 @@ static BOOL update_send_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt)
        ORDER_INFO orderInfo;
        int inf;
        rdpUpdate* update = context->update;
-
-       headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_SCRBLT);
-
+       headerLength = update_prepare_order_info(context, &orderInfo,
+                      ORDER_TYPE_SCRBLT);
        inf = update_approximate_scrblt_order(&orderInfo, scrblt);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return TRUE;
+
        offset = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
-       Stream_Seek(s, headerLength);
 
+       Stream_Seek(s, headerLength);
        update_write_scrblt_order(s, &orderInfo, scrblt);
        update_write_order_info(context, s, &orderInfo, offset);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_opaque_rect(rdpContext* context,
-                                       const OPAQUE_RECT_ORDER* opaque_rect)
+                                    const OPAQUE_RECT_ORDER* opaque_rect)
 {
        wStream* s;
        int offset;
        int headerLength;
        ORDER_INFO orderInfo;
        rdpUpdate* update = context->update;
-
-       headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_OPAQUE_RECT);
-
-       update_check_flush(context, headerLength + update_approximate_opaque_rect_order(&orderInfo, opaque_rect));
-
+       headerLength = update_prepare_order_info(context, &orderInfo,
+                      ORDER_TYPE_OPAQUE_RECT);
+       update_check_flush(context,
+                          headerLength + update_approximate_opaque_rect_order(&orderInfo, opaque_rect));
        s = update->us;
+
        if (!s)
                return FALSE;
+
        offset = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
-       Stream_Seek(s, headerLength);
 
+       Stream_Seek(s, headerLength);
        update_write_opaque_rect_order(s, &orderInfo, opaque_rect);
        update_write_order_info(context, s, &orderInfo, offset);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_line_to(rdpContext* context,
-                               const LINE_TO_ORDER* line_to)
+                                const LINE_TO_ORDER* line_to)
 {
        wStream* s;
        int offset;
@@ -1249,24 +1273,23 @@ static BOOL update_send_line_to(rdpContext* context,
        ORDER_INFO orderInfo;
        int inf;
        rdpUpdate* update = context->update;
-
-       headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_LINE_TO);
-
+       headerLength = update_prepare_order_info(context, &orderInfo,
+                      ORDER_TYPE_LINE_TO);
        inf = update_approximate_line_to_order(&orderInfo, line_to);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
+
        offset = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
-       Stream_Seek(s, headerLength);
 
+       Stream_Seek(s, headerLength);
        update_write_line_to_order(s, &orderInfo, line_to);
        update_write_order_info(context, s, &orderInfo, offset);
-
        update->numberOrders++;
        return TRUE;
 }
@@ -1278,29 +1301,29 @@ static BOOL update_send_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
        int headerLength;
        ORDER_INFO orderInfo;
        rdpUpdate* update = context->update;
-
-       headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_MEMBLT);
-
-       update_check_flush(context, headerLength + update_approximate_memblt_order(&orderInfo, memblt));
-
+       headerLength = update_prepare_order_info(context, &orderInfo,
+                      ORDER_TYPE_MEMBLT);
+       update_check_flush(context,
+                          headerLength + update_approximate_memblt_order(&orderInfo, memblt));
        s = update->us;
+
        if (!s)
                return FALSE;
+
        offset = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
-       Stream_Seek(s, headerLength);
 
+       Stream_Seek(s, headerLength);
        update_write_memblt_order(s, &orderInfo, memblt);
        update_write_order_info(context, s, &orderInfo, offset);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_glyph_index(rdpContext* context,
-                                       GLYPH_INDEX_ORDER* glyph_index)
+                                    GLYPH_INDEX_ORDER* glyph_index)
 {
        wStream* s;
        int offset;
@@ -1308,24 +1331,23 @@ static BOOL update_send_glyph_index(rdpContext* context,
        int inf;
        ORDER_INFO orderInfo;
        rdpUpdate* update = context->update;
-
-       headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_GLYPH_INDEX);
-
+       headerLength = update_prepare_order_info(context, &orderInfo,
+                      ORDER_TYPE_GLYPH_INDEX);
        inf = update_approximate_glyph_index_order(&orderInfo, glyph_index);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
+
        offset = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
-       Stream_Seek(s, headerLength);
 
+       Stream_Seek(s, headerLength);
        update_write_glyph_index_order(s, &orderInfo, glyph_index);
        update_write_order_info(context, s, &orderInfo, offset);
-
        update->numberOrders++;
        return TRUE;
 }
@@ -1335,7 +1357,7 @@ static BOOL update_send_glyph_index(rdpContext* context,
  */
 
 static BOOL update_send_cache_bitmap(rdpContext* context,
-                                        const CACHE_BITMAP_ORDER* cache_bitmap)
+                                     const CACHE_BITMAP_ORDER* cache_bitmap)
 {
        wStream* s;
        int bm, em;
@@ -1345,19 +1367,16 @@ static BOOL update_send_cache_bitmap(rdpContext* context,
        UINT16 extraFlags;
        INT16 orderLength;
        rdpUpdate* update = context->update;
-
        extraFlags = 0;
        headerLength = 6;
-
        orderType = cache_bitmap->compressed ?
-                       ORDER_TYPE_CACHE_BITMAP_COMPRESSED : ORDER_TYPE_BITMAP_UNCOMPRESSED;
-
+                   ORDER_TYPE_CACHE_BITMAP_COMPRESSED : ORDER_TYPE_BITMAP_UNCOMPRESSED;
        inf = update_approximate_cache_bitmap_order(cache_bitmap,
-                                                       cache_bitmap->compressed,
-                                                       &extraFlags);
+               cache_bitmap->compressed,
+               &extraFlags);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
 
@@ -1368,25 +1387,25 @@ static BOOL update_send_cache_bitmap(rdpContext* context,
 
        Stream_Seek(s, headerLength);
 
-       if (!update_write_cache_bitmap_order(s, cache_bitmap, cache_bitmap->compressed, &extraFlags))
+       if (!update_write_cache_bitmap_order(s, cache_bitmap, cache_bitmap->compressed,
+                                            &extraFlags))
                return FALSE;
 
        em = Stream_GetPosition(s);
-
        orderLength = (em - bm) - 13;
-
        Stream_SetPosition(s, bm);
-       Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
+       Stream_Write_UINT8(s, ORDER_STANDARD |
+                          ORDER_SECONDARY); /* controlFlags (1 byte) */
        Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
        Stream_Write_UINT16(s, extraFlags); /* extraFlags (2 bytes) */
        Stream_Write_UINT8(s, orderType); /* orderType (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
-static BOOL update_send_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2)
+static BOOL update_send_cache_bitmap_v2(rdpContext* context,
+                                        CACHE_BITMAP_V2_ORDER* cache_bitmap_v2)
 {
        wStream* s;
        int bm, em;
@@ -1395,19 +1414,19 @@ static BOOL update_send_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORD
        UINT16 extraFlags;
        INT16 orderLength;
        rdpUpdate* update = context->update;
-
        extraFlags = 0;
        headerLength = 6;
-
        orderType = cache_bitmap_v2->compressed ?
-                       ORDER_TYPE_BITMAP_COMPRESSED_V2 : ORDER_TYPE_BITMAP_UNCOMPRESSED_V2;
+                   ORDER_TYPE_BITMAP_COMPRESSED_V2 : ORDER_TYPE_BITMAP_UNCOMPRESSED_V2;
 
        if (context->settings->NoBitmapCompressionHeader)
                cache_bitmap_v2->flags |= CBR2_NO_BITMAP_COMPRESSION_HDR;
 
-       update_check_flush(context, headerLength + update_approximate_cache_bitmap_v2_order(cache_bitmap_v2, cache_bitmap_v2->compressed, &extraFlags));
-
+       update_check_flush(context,
+                          headerLength + update_approximate_cache_bitmap_v2_order(cache_bitmap_v2,
+                                  cache_bitmap_v2->compressed, &extraFlags));
        s = update->us;
+
        if (!s)
                return FALSE;
 
@@ -1418,25 +1437,25 @@ static BOOL update_send_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORD
 
        Stream_Seek(s, headerLength);
 
-       if (!update_write_cache_bitmap_v2_order(s, cache_bitmap_v2, cache_bitmap_v2->compressed, &extraFlags))
+       if (!update_write_cache_bitmap_v2_order(s, cache_bitmap_v2,
+                                               cache_bitmap_v2->compressed, &extraFlags))
                return FALSE;
 
        em = Stream_GetPosition(s);
-
        orderLength = (em - bm) - 13;
-
        Stream_SetPosition(s, bm);
-       Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
+       Stream_Write_UINT8(s, ORDER_STANDARD |
+                          ORDER_SECONDARY); /* controlFlags (1 byte) */
        Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
        Stream_Write_UINT16(s, extraFlags); /* extraFlags (2 bytes) */
        Stream_Write_UINT8(s, orderType); /* orderType (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
-static BOOL update_send_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3)
+static BOOL update_send_cache_bitmap_v3(rdpContext* context,
+                                        CACHE_BITMAP_V3_ORDER* cache_bitmap_v3)
 {
        wStream* s;
        int bm, em;
@@ -1445,14 +1464,14 @@ static BOOL update_send_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORD
        UINT16 extraFlags;
        INT16 orderLength;
        rdpUpdate* update = context->update;
-
        extraFlags = 0;
        headerLength = 6;
        orderType = ORDER_TYPE_BITMAP_COMPRESSED_V3;
-
-       update_check_flush(context, headerLength + update_approximate_cache_bitmap_v3_order(cache_bitmap_v3, &extraFlags));
-
+       update_check_flush(context,
+                          headerLength + update_approximate_cache_bitmap_v3_order(cache_bitmap_v3,
+                                  &extraFlags));
        s = update->us;
+
        if (!s)
                return FALSE;
 
@@ -1467,22 +1486,20 @@ static BOOL update_send_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORD
                return FALSE;
 
        em = Stream_GetPosition(s);
-
        orderLength = (em - bm) - 13;
-
        Stream_SetPosition(s, bm);
-       Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
+       Stream_Write_UINT8(s, ORDER_STANDARD |
+                          ORDER_SECONDARY); /* controlFlags (1 byte) */
        Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
        Stream_Write_UINT16(s, extraFlags); /* extraFlags (2 bytes) */
        Stream_Write_UINT8(s, orderType); /* orderType (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_cache_color_table(rdpContext* context,
-                                         const CACHE_COLOR_TABLE_ORDER* cache_color_table)
+        const CACHE_COLOR_TABLE_ORDER* cache_color_table)
 {
        wStream* s;
        UINT16 flags;
@@ -1490,14 +1507,12 @@ static BOOL update_send_cache_color_table(rdpContext* context,
        int headerLength;
        INT16 orderLength;
        rdpUpdate* update = context->update;
-
        flags = 0;
        headerLength = 6;
-
        inf = update_approximate_cache_color_table_order(cache_color_table, &flags);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
 
@@ -1512,22 +1527,20 @@ static BOOL update_send_cache_color_table(rdpContext* context,
                return FALSE;
 
        em = Stream_GetPosition(s);
-
        orderLength = (em - bm) - 13;
-
        Stream_SetPosition(s, bm);
-       Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
+       Stream_Write_UINT8(s, ORDER_STANDARD |
+                          ORDER_SECONDARY); /* controlFlags (1 byte) */
        Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
        Stream_Write_UINT16(s, flags); /* extraFlags (2 bytes) */
        Stream_Write_UINT8(s, ORDER_TYPE_CACHE_COLOR_TABLE); /* orderType (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_cache_glyph(rdpContext* context,
-                                       const CACHE_GLYPH_ORDER* cache_glyph)
+                                    const CACHE_GLYPH_ORDER* cache_glyph)
 {
        wStream* s;
        UINT16 flags;
@@ -1535,14 +1548,12 @@ static BOOL update_send_cache_glyph(rdpContext* context,
        int headerLength;
        INT16 orderLength;
        rdpUpdate* update = context->update;
-
        flags = 0;
        headerLength = 6;
-
        inf = update_approximate_cache_glyph_order(cache_glyph, &flags);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
 
@@ -1550,28 +1561,27 @@ static BOOL update_send_cache_glyph(rdpContext* context,
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
+
        Stream_Seek(s, headerLength);
 
        if (!update_write_cache_glyph_order(s, cache_glyph, &flags))
                return FALSE;
 
        em = Stream_GetPosition(s);
-
        orderLength = (em - bm) - 13;
-
        Stream_SetPosition(s, bm);
-       Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
+       Stream_Write_UINT8(s, ORDER_STANDARD |
+                          ORDER_SECONDARY); /* controlFlags (1 byte) */
        Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
        Stream_Write_UINT16(s, flags); /* extraFlags (2 bytes) */
        Stream_Write_UINT8(s, ORDER_TYPE_CACHE_GLYPH); /* orderType (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_cache_glyph_v2(rdpContext* context,
-                                          const CACHE_GLYPH_V2_ORDER* cache_glyph_v2)
+                                       const CACHE_GLYPH_V2_ORDER* cache_glyph_v2)
 {
        wStream* s;
        UINT16 flags;
@@ -1579,14 +1589,12 @@ static BOOL update_send_cache_glyph_v2(rdpContext* context,
        int headerLength;
        INT16 orderLength;
        rdpUpdate* update = context->update;
-
        flags = 0;
        headerLength = 6;
-
        inf =  update_approximate_cache_glyph_v2_order(cache_glyph_v2, &flags);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
 
@@ -1594,28 +1602,27 @@ static BOOL update_send_cache_glyph_v2(rdpContext* context,
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
+
        Stream_Seek(s, headerLength);
 
        if (!update_write_cache_glyph_v2_order(s, cache_glyph_v2, &flags))
                return FALSE;
 
        em = Stream_GetPosition(s);
-
        orderLength = (em - bm) - 13;
-
        Stream_SetPosition(s, bm);
-       Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
+       Stream_Write_UINT8(s, ORDER_STANDARD |
+                          ORDER_SECONDARY); /* controlFlags (1 byte) */
        Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
        Stream_Write_UINT16(s, flags); /* extraFlags (2 bytes) */
        Stream_Write_UINT8(s, ORDER_TYPE_CACHE_GLYPH); /* orderType (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_cache_brush(rdpContext* context,
-                                       const CACHE_BRUSH_ORDER* cache_brush)
+                                    const CACHE_BRUSH_ORDER* cache_brush)
 {
        wStream* s;
        UINT16 flags;
@@ -1623,36 +1630,34 @@ static BOOL update_send_cache_brush(rdpContext* context,
        int headerLength;
        INT16 orderLength;
        rdpUpdate* update = context->update;
-
        flags = 0;
        headerLength = 6;
-
        inf = update_approximate_cache_brush_order(cache_brush, &flags);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
+
        bm = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
+
        Stream_Seek(s, headerLength);
 
        if (!update_write_cache_brush_order(s, cache_brush, &flags))
                return FALSE;
 
        em = Stream_GetPosition(s);
-
        orderLength = (em - bm) - 13;
-
        Stream_SetPosition(s, bm);
-       Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
+       Stream_Write_UINT8(s, ORDER_STANDARD |
+                          ORDER_SECONDARY); /* controlFlags (1 byte) */
        Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
        Stream_Write_UINT16(s, flags); /* extraFlags (2 bytes) */
        Stream_Write_UINT8(s, ORDER_TYPE_CACHE_BRUSH); /* orderType (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
@@ -1662,8 +1667,8 @@ static BOOL update_send_cache_brush(rdpContext* context,
  */
 
 static BOOL update_send_create_offscreen_bitmap_order(
-               rdpContext* context,
-               const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap)
+    rdpContext* context,
+    const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap)
 {
        wStream* s;
        int bm, em, inf;
@@ -1671,38 +1676,38 @@ static BOOL update_send_create_offscreen_bitmap_order(
        BYTE controlFlags;
        int headerLength;
        rdpUpdate* update = context->update;
-
        headerLength = 1;
        orderType = ORDER_TYPE_CREATE_OFFSCREEN_BITMAP;
        controlFlags = ORDER_SECONDARY | (orderType << 2);
-
-       inf =  update_approximate_create_offscreen_bitmap_order(create_offscreen_bitmap);
+       inf =  update_approximate_create_offscreen_bitmap_order(
+                  create_offscreen_bitmap);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
+
        bm = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
+
        Stream_Seek(s, headerLength);
 
        if (!update_write_create_offscreen_bitmap_order(s, create_offscreen_bitmap))
                return FALSE;
-       em = Stream_GetPosition(s);
 
+       em = Stream_GetPosition(s);
        Stream_SetPosition(s, bm);
        Stream_Write_UINT8(s, controlFlags); /* controlFlags (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_switch_surface_order(
-               rdpContext* context,
-               const SWITCH_SURFACE_ORDER* switch_surface)
+    rdpContext* context,
+    const SWITCH_SURFACE_ORDER* switch_surface)
 {
        wStream* s;
        int bm, em, inf;
@@ -1710,44 +1715,43 @@ static BOOL update_send_switch_surface_order(
        BYTE controlFlags;
        int headerLength;
        rdpUpdate* update = context->update;
-
        headerLength = 1;
        orderType = ORDER_TYPE_SWITCH_SURFACE;
        controlFlags = ORDER_SECONDARY | (orderType << 2);
-
        inf =  update_approximate_switch_surface_order(switch_surface);
        update_check_flush(context, headerLength + inf);
-
        s = update->us;
+
        if (!s)
                return FALSE;
+
        bm = Stream_GetPosition(s);
 
        if (!Stream_EnsureRemainingCapacity(s, headerLength))
                return FALSE;
+
        Stream_Seek(s, headerLength);
 
        if (!update_write_switch_surface_order(s, switch_surface))
                return FALSE;
-       em = Stream_GetPosition(s);
 
+       em = Stream_GetPosition(s);
        Stream_SetPosition(s, bm);
        Stream_Write_UINT8(s, controlFlags); /* controlFlags (1 byte) */
        Stream_SetPosition(s, em);
-
        update->numberOrders++;
        return TRUE;
 }
 
 static BOOL update_send_pointer_system(rdpContext* context,
-                                                                          const POINTER_SYSTEM_UPDATE* pointer_system)
+                                       const POINTER_SYSTEM_UPDATE* pointer_system)
 {
        wStream* s;
        BYTE updateCode;
        rdpRdp* rdp = context->rdp;
        BOOL ret;
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
 
@@ -1762,13 +1766,13 @@ static BOOL update_send_pointer_system(rdpContext* context,
 }
 
 static BOOL update_send_pointer_position(rdpContext* context,
-                                                                                const POINTER_POSITION_UPDATE* pointerPosition)
+        const POINTER_POSITION_UPDATE* pointerPosition)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret = FALSE;
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
 
@@ -1777,17 +1781,18 @@ static BOOL update_send_pointer_position(rdpContext* context,
 
        Stream_Write_UINT16(s, pointerPosition->xPos); /* xPos (2 bytes) */
        Stream_Write_UINT16(s, pointerPosition->yPos); /* yPos (2 bytes) */
-
-       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_PTR_POSITION, s, FALSE);
+       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_PTR_POSITION,
+                                      s, FALSE);
 out_fail:
        Stream_Release(s);
        return ret;
 }
 
 static BOOL update_write_pointer_color(wStream* s,
-                                                                          const POINTER_COLOR_UPDATE* pointer_color)
+                                       const POINTER_COLOR_UPDATE* pointer_color)
 {
-       if (!Stream_EnsureRemainingCapacity(s, 32 + pointer_color->lengthAndMask + pointer_color->lengthXorMask))
+       if (!Stream_EnsureRemainingCapacity(s,
+                                           32 + pointer_color->lengthAndMask + pointer_color->lengthXorMask))
                return FALSE;
 
        Stream_Write_UINT16(s, pointer_color->cacheIndex);
@@ -1809,34 +1814,34 @@ static BOOL update_write_pointer_color(wStream* s,
 }
 
 static BOOL update_send_pointer_color(rdpContext* context,
-                                                                         const POINTER_COLOR_UPDATE* pointer_color)
+                                      const POINTER_COLOR_UPDATE* pointer_color)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret = FALSE;
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
 
        if (!update_write_pointer_color(s, pointer_color))
                goto out_fail;
 
-       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_COLOR, s, FALSE);
-
+       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_COLOR, s,
+                                      FALSE);
 out_fail:
        Stream_Release(s);
        return ret;
 }
 
 static BOOL update_send_pointer_new(rdpContext* context,
-                                                                       const POINTER_NEW_UPDATE* pointer_new)
+                                    const POINTER_NEW_UPDATE* pointer_new)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret = FALSE;
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
 
@@ -1845,26 +1850,27 @@ static BOOL update_send_pointer_new(rdpContext* context,
 
        Stream_Write_UINT16(s, pointer_new->xorBpp); /* xorBpp (2 bytes) */
        update_write_pointer_color(s, &pointer_new->colorPtrAttr);
-
-       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_POINTER, s, FALSE);
-
+       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_POINTER, s,
+                                      FALSE);
 out_fail:
        Stream_Release(s);
        return ret;
 }
 
 static BOOL update_send_pointer_cached(rdpContext* context,
-                                                                          const POINTER_CACHED_UPDATE* pointer_cached)
+                                       const POINTER_CACHED_UPDATE* pointer_cached)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret;
-
        s = fastpath_update_pdu_init(rdp->fastpath);
+
        if (!s)
                return FALSE;
+
        Stream_Write_UINT16(s, pointer_cached->cacheIndex); /* cacheIndex (2 bytes) */
-       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_CACHED, s, FALSE);
+       ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_CACHED, s,
+                                      FALSE);
        Stream_Release(s);
        return ret;
 }
@@ -1885,6 +1891,7 @@ BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s)
                return FALSE;
 
        areas = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * numberOfAreas);
+
        if (!areas)
                return FALSE;
 
@@ -1902,7 +1909,6 @@ BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s)
                WLog_Print(update->log, WLOG_WARN, "ignoring refresh rect request from client");
 
        free(areas);
-
        return TRUE;
 }
 
@@ -1921,25 +1927,30 @@ BOOL update_read_suppress_output(rdpUpdate* update, wStream* s)
 
        if (update->context->settings->SuppressOutput)
                IFCALL(update->SuppressOutput, update->context, allowDisplayUpdates,
-                       allowDisplayUpdates > 0 ? (RECTANGLE_16*) Stream_Pointer(s) : NULL);
+                      allowDisplayUpdates > 0 ? (RECTANGLE_16*) Stream_Pointer(s) : NULL);
        else
-               WLog_Print(update->log, WLOG_WARN, "ignoring suppress output request from client");
+               WLog_Print(update->log, WLOG_WARN,
+                          "ignoring suppress output request from client");
 
        return TRUE;
 }
 
-static BOOL update_send_set_keyboard_indicators(rdpContext* context, UINT16 led_flags)
+static BOOL update_send_set_keyboard_indicators(rdpContext* context,
+        UINT16 led_flags)
 {
        wStream* s;
        rdpRdp* rdp = context->rdp;
        BOOL ret;
-
        s = rdp_data_pdu_init(rdp);
+
        if (!s)
                return FALSE;
-       Stream_Write_UINT16(s, 0); /* unitId should be 0 according to MS-RDPBCGR 2.2.8.2.1.1 */
+
+       Stream_Write_UINT16(s,
+                           0); /* unitId should be 0 according to MS-RDPBCGR 2.2.8.2.1.1 */
        Stream_Write_UINT16(s, led_flags); /* ledFlags (2 bytes) */
-       ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS, rdp->mcs->userId);
+       ret = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS,
+                               rdp->mcs->userId);
        Stream_Release(s);
        return ret;
 }
@@ -1973,7 +1984,8 @@ void update_register_server_callbacks(rdpUpdate* update)
        update->secondary->CacheGlyph = update_send_cache_glyph;
        update->secondary->CacheGlyphV2 = update_send_cache_glyph_v2;
        update->secondary->CacheBrush = update_send_cache_brush;
-       update->altsec->CreateOffscreenBitmap = update_send_create_offscreen_bitmap_order;
+       update->altsec->CreateOffscreenBitmap =
+           update_send_create_offscreen_bitmap_order;
        update->altsec->SwitchSurface = update_send_switch_surface_order;
        update->pointer->PointerSystem = update_send_pointer_system;
        update->pointer->PointerPosition = update_send_pointer_position;
@@ -1994,10 +2006,9 @@ int update_process_messages(rdpUpdate* update)
        return update_message_queue_process_pending_messages(update);
 }
 
-static void update_free_queued_message(void *obj)
+static void update_free_queued_message(voidobj)
 {
-       wMessage *msg = (wMessage*)obj;
-
+       wMessage* msg = (wMessage*)obj;
        update_message_queue_free_message(msg);
 }
 
@@ -2006,55 +2017,61 @@ rdpUpdate* update_new(rdpRdp* rdp)
        const wObject cb = { NULL, NULL, NULL,  update_free_queued_message, NULL };
        rdpUpdate* update;
        OFFSCREEN_DELETE_LIST* deleteList;
+       update = (rdpUpdate*) calloc(1, sizeof(rdpUpdate));
 
-       update = (rdpUpdate *) calloc(1, sizeof(rdpUpdate));
        if (!update)
                return NULL;
 
        WLog_Init();
        update->log = WLog_Get("com.freerdp.core.update");
-
        update->bitmap_update.count = 64;
-       update->bitmap_update.rectangles = (BITMAP_DATA*) calloc(update->bitmap_update.count, sizeof(BITMAP_DATA));
+       update->bitmap_update.rectangles = (BITMAP_DATA*) calloc(
+                                              update->bitmap_update.count, sizeof(BITMAP_DATA));
+
        if (!update->bitmap_update.rectangles)
                goto error_rectangles;
 
        update->pointer = (rdpPointerUpdate*) calloc(1, sizeof(rdpPointerUpdate));
+
        if (!update->pointer)
                goto error_pointer;
 
        update->primary = (rdpPrimaryUpdate*) calloc(1, sizeof(rdpPrimaryUpdate));
+
        if (!update->primary)
                goto error_primary;
 
        update->secondary = (rdpSecondaryUpdate*) calloc(1, sizeof(rdpSecondaryUpdate));
+
        if (!update->secondary)
                goto error_secondary;
 
        update->altsec = (rdpAltSecUpdate*) calloc(1, sizeof(rdpAltSecUpdate));
+
        if (!update->altsec)
                goto error_altsec;
 
        update->window = (rdpWindowUpdate*) calloc(1, sizeof(rdpWindowUpdate));
+
        if (!update->window)
                goto error_window;
 
        deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
        deleteList->sIndices = 64;
        deleteList->indices = malloc(deleteList->sIndices * 2);
+
        if (!deleteList->indices)
                goto error_indices;
-       deleteList->cIndices = 0;
 
+       deleteList->cIndices = 0;
        update->SuppressOutput = update_send_suppress_output;
-
        update->initialState = TRUE;
-
        update->queue = MessageQueue_New(&cb);
+
        if (!update->queue)
                goto error_queue;
-       return update;
 
+       return update;
 error_queue:
        free(deleteList->indices);
 error_indices:
@@ -2079,29 +2096,22 @@ void update_free(rdpUpdate* update)
        if (update != NULL)
        {
                OFFSCREEN_DELETE_LIST* deleteList;
-
                deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
                free(deleteList->indices);
-
                free(update->bitmap_update.rectangles);
-
                free(update->pointer->pointer_color.andMaskData);
                free(update->pointer->pointer_color.xorMaskData);
                free(update->pointer->pointer_new.colorPtrAttr.andMaskData);
                free(update->pointer->pointer_new.colorPtrAttr.xorMaskData);
                free(update->pointer);
-
                free(update->primary->polyline.points);
                free(update->primary->polygon_sc.points);
                free(update->primary->fast_glyph.glyphData.aj);
                free(update->primary);
-
                free(update->secondary);
                free(update->altsec);
                free(update->window);
-
                MessageQueue_Free(update->queue);
-
                free(update);
        }
 }
index b7a59c6..26033fc 100644 (file)
@@ -491,8 +491,10 @@ static BOOL gdi_bitmap_update(rdpContext* context,
                UINT32 nYSrc = 0;
                UINT32 nXDst = bitmap->destLeft;
                UINT32 nYDst = bitmap->destTop;
-               UINT32 nWidth = bitmap->width;
-               UINT32 nHeight = bitmap->height;
+               UINT32 nWidth = MIN(bitmap->destRight,
+                                   gdi->width - 1) - bitmap->destLeft + 1; /* clip width */
+               UINT32 nHeight = MIN(bitmap->destBottom,
+                                    gdi->height - 1) - bitmap->destTop + 1; /* clip height */
                const BYTE* pSrcData = bitmap->bitmapDataStream;
                UINT32 SrcSize = bitmap->bitmapLength;
                BOOL compressed = bitmap->compressed;
@@ -504,6 +506,7 @@ static BOOL gdi_bitmap_update(rdpContext* context,
                        {
                                if (!interleaved_decompress(codecs->interleaved,
                                                            pSrcData, SrcSize,
+                                                           bitmap->width, bitmap->height,
                                                            bitsPerPixel,
                                                            gdi->primary_buffer,
                                                            gdi->primary->hdc->format,
@@ -515,7 +518,8 @@ static BOOL gdi_bitmap_update(rdpContext* context,
                        else
                        {
                                if (!planar_decompress(codecs->planar, pSrcData,
-                                                      SrcSize, gdi->primary_buffer,
+                                                      SrcSize, bitmap->width, bitmap->height,
+                                                      gdi->primary_buffer,
                                                       gdi->primary->hdc->format,
                                                       gdi->stride,
                                                       nXDst, nYDst, nWidth, nHeight, TRUE))
@@ -526,10 +530,6 @@ static BOOL gdi_bitmap_update(rdpContext* context,
                {
                        UINT32 SrcFormat = gdi_get_pixel_format(bitsPerPixel, TRUE);
                        UINT32 nSrcStep = nWidth * GetBytesPerPixel(SrcFormat);
-                       nWidth = MIN(bitmap->destRight,
-                                    gdi->width - 1) - bitmap->destLeft + 1; /* clip width */
-                       nHeight = MIN(bitmap->destBottom,
-                                     gdi->height - 1) - bitmap->destTop + 1; /* clip height */
 
                        if (!freerdp_image_copy(gdi->primary_buffer, gdi->primary->hdc->format,
                                                gdi->stride,
@@ -1117,7 +1117,7 @@ static BOOL gdi_surface_bits(rdpContext* context,
                                                         PIXEL_FORMAT_BGRX32,
                                                         cmd->bitmapDataLength,
                                                         0, 0,
-                                                        gdi->bitmap_buffer, gdi->dstFormat,
+                                                        gdi->primary_buffer, gdi->dstFormat,
                                                         cmd->width * GetBytesPerPixel(gdi->dstFormat),
                                                         cmd->height, NULL))
                                {
index 8593959..4bbdd83 100644 (file)
@@ -330,6 +330,7 @@ static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
        DstData = surface->data;
 
        if (!planar_decompress(surface->codecs->planar, cmd->data, cmd->length,
+                              cmd->width, cmd->height,
                               DstData, surface->format,
                               surface->scanline, cmd->left, cmd->top,
                               cmd->width, cmd->height, FALSE))
index 281ce17..09a39fc 100644 (file)
@@ -138,6 +138,8 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
        UINT32 SrcSize = length;
        UINT32 SrcFormat;
        UINT32 bytesPerPixel;
+       UINT32 DstWidth = MIN(width, bitmap->width);
+       UINT32 DstHeight = MIN(height, bitmap->height);
        rdpGdi* gdi = context->gdi;
        bytesPerPixel = (bpp + 7) / 8;
        size = width * height * GetBytesPerPixel(gdi->dstFormat);
@@ -156,15 +158,17 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
                {
                        if (!interleaved_decompress(context->codecs->interleaved,
                                                    pSrcData, SrcSize,
+                                                   width, height,
                                                    bpp,
                                                    bitmap->data, bitmap->format,
-                                                   0, 0, 0, width, height,
+                                                   0, 0, 0, DstWidth, DstHeight,
                                                    &gdi->palette))
                                return FALSE;
                }
                else
                {
                        if (!planar_decompress(context->codecs->planar, pSrcData, SrcSize,
+                                              width, height,
                                               bitmap->data, bitmap->format, 0, 0, 0,
                                               width, height, TRUE))
                                return FALSE;
@@ -175,7 +179,7 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
                SrcFormat = gdi_get_pixel_format(bpp, TRUE);
 
                if (!freerdp_image_copy(bitmap->data, bitmap->format, 0, 0, 0,
-                                       width, height, pSrcData, SrcFormat,
+                                       DstWidth, DstHeight, pSrcData, SrcFormat,
                                        0, 0, 0, &gdi->palette))
                        return FALSE;
        }
index de91e1d..99d9b89 100644 (file)
  */
 static BOOL gdi_rop_color(UINT32 rop, BYTE* pixelPtr, UINT32 pen, UINT32 format)
 {
-       UINT32 dstPixel;
-       const UINT32 srcPixel = ReadColor(pixelPtr, format);
+       UINT32 pixel = ReadColor(pixelPtr, format);
 
        switch (rop)
        {
                case GDI_R2_BLACK: /* LineTo_BLACK */
-                       dstPixel = GetColor(format, 0, 0, 0, 0xFF);
+                       pixel = GetColor(format, 0, 0, 0, 0xFF);
                        break;
 
                case GDI_R2_NOTMERGEPEN: /* LineTo_NOTMERGEPEN */
-                       dstPixel = ~(srcPixel | pen);
+                       pixel = ~(pixel | pen);
                        break;
 
                case GDI_R2_MASKNOTPEN: /* LineTo_MASKNOTPEN */
-                       dstPixel = srcPixel & ~pen;
+                       pixel &= ~pen;
                        break;
 
                case GDI_R2_NOTCOPYPEN: /* LineTo_NOTCOPYPEN */
-                       dstPixel = ~pen;
+                       pixel = ~pen;
                        break;
 
                case GDI_R2_MASKPENNOT: /* LineTo_MASKPENNOT */
-                       dstPixel = pen & ~srcPixel;
+                       pixel = pen & ~pixel;
                        break;
 
                case GDI_R2_NOT: /* LineTo_NOT */
-                       dstPixel = ~srcPixel;
+                       pixel = ~pixel;
                        break;
 
                case GDI_R2_XORPEN: /* LineTo_XORPEN */
-                       dstPixel = srcPixel ^ pen;
+                       pixel = pixel ^ pen;
                        break;
 
                case GDI_R2_NOTMASKPEN: /* LineTo_NOTMASKPEN */
-                       dstPixel = ~(srcPixel & pen);
+                       pixel = ~(pixel & pen);
                        break;
 
                case GDI_R2_MASKPEN: /* LineTo_MASKPEN */
-                       dstPixel = srcPixel & pen;
+                       pixel &= pen;
                        break;
 
                case GDI_R2_NOTXORPEN: /* LineTo_NOTXORPEN */
-                       dstPixel = ~(srcPixel ^ pen);
+                       pixel = ~(pixel ^ pen);
                        break;
 
                case GDI_R2_NOP: /* LineTo_NOP */
                        break;
 
                case GDI_R2_MERGENOTPEN: /* LineTo_MERGENOTPEN */
-                       dstPixel = srcPixel | ~pen;
+                       pixel |= ~pen;
                        break;
 
                case GDI_R2_COPYPEN: /* LineTo_COPYPEN */
-                       dstPixel = pen;
+                       pixel = pen;
                        break;
 
                case GDI_R2_MERGEPENNOT: /* LineTo_MERGEPENNOT */
-                       dstPixel = srcPixel | ~pen;
+                       pixel = pixel | ~pen;
                        break;
 
                case GDI_R2_MERGEPEN: /* LineTo_MERGEPEN */
-                       dstPixel = srcPixel | pen;
+                       pixel = pixel | pen;
                        break;
 
                case GDI_R2_WHITE: /* LineTo_WHITE */
-                       dstPixel = GetColor(format, 0, 0, 0, 0xFF);
+                       pixel = GetColor(format, 0, 0, 0, 0);
                        break;
 
                default:
                        return FALSE;
        }
 
-       WriteColor(pixelPtr, format, dstPixel);
+       WriteColor(pixelPtr, format, pixel);
        return TRUE;
 }
 
 BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd)
 {
-       INT64 e2;
-       INT64 bx1, by1;
-       INT64 bx2, by2;
-       HGDI_BITMAP bmp = (HGDI_BITMAP) hdc->selectedObject;
+       UINT32 x, y;
+       UINT32 x1, y1;
+       UINT32 x2, y2;
+       INT32 e, e2;
+       INT32 dx, dy;
+       INT32 sx, sy;
+       INT32 bx1, by1;
+       INT32 bx2, by2;
+       HGDI_BITMAP bmp;
        UINT32 pen;
        UINT32 rop2 = gdi_GetROP2(hdc);
-       UINT32 x1 = hdc->pen->posX;
-       UINT32 y1 = hdc->pen->posY;
-       UINT32 x2 = nXEnd;
-       UINT32 y2 = nYEnd;
-       INT64 dx = (x1 > x2) ? x1 - x2 : x2 - x1;
-       INT64 dy = (y1 > y2) ? y1 - y2 : y2 - y1;
-       INT64 sx = (x1 < x2) ? 1 : -1;
-       INT64 sy = (y1 < y2) ? 1 : -1;
-       INT64 e = dx - dy;
-       UINT32 x = x1;
-       UINT32 y = y1;
+       x1 = hdc->pen->posX;
+       y1 = hdc->pen->posY;
+       x2 = nXEnd;
+       y2 = nYEnd;
+       dx = (x1 > x2) ? x1 - x2 : x2 - x1;
+       dy = (y1 > y2) ? y1 - y2 : y2 - y1;
+       sx = (x1 < x2) ? 1 : -1;
+       sy = (y1 < y2) ? 1 : -1;
+       e = dx - dy;
+       x = x1;
+       y = y1;
+       bmp = (HGDI_BITMAP) hdc->selectedObject;
 
        if (hdc->clip->null)
        {
index 8ad8392..6081911 100644 (file)
@@ -45,11 +45,9 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2)
        INT32 e, e2;
        INT32 dx, dy;
        INT32 a, b, c;
-
        a = (x1 < x2) ? x2 - x1 : x1 - x2;
        b = (y1 < y2) ? y2 - y1 : y1 - y2;
        c = b & 1;
-
        dx = 4 * (1 - a) * b * b;
        dy = 4 * (c + 1) * a * a;
        e = dx + dy + c * a * a;
@@ -65,7 +63,6 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2)
 
        y1 += (b + 1) / 2;
        y2 = y1 - c;
-
        a *= 8 * a;
        c = 8 * b * b;
 
@@ -75,7 +72,6 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2)
                gdi_SetPixel(hdc, x1, y1, 0);
                gdi_SetPixel(hdc, x1, y2, 0);
                gdi_SetPixel(hdc, x2, y2, 0);
-
                e2 = 2 * e;
 
                if (e2 >= dx)
@@ -111,7 +107,8 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2)
  * @param nBottomRect y2
  * @return nonzero if successful, 0 otherwise
  */
-BOOL gdi_Ellipse(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
+BOOL gdi_Ellipse(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect,
+                 int nBottomRect)
 {
        Ellipse_Bresenham(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect);
        return TRUE;
@@ -132,7 +129,6 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr)
        UINT32 color;
        UINT32 nXDest, nYDest;
        UINT32 nWidth, nHeight;
-
        gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight);
 
        if (!gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL))
@@ -145,7 +141,8 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr)
                for (x = 0; x < nWidth; x++)
                {
                        BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x,
-                                                           nYDest + y);
+                                                           nYDest + y);
+
                        if (dstp)
                                WriteColor(dstp, hdc->format, color);
                }
@@ -166,7 +163,7 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr)
  * @param nCount number of points
  * @return nonzero if successful, 0 otherwise
  */
-BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINT *lpPoints, int nCount)
+BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINTlpPoints, int nCount)
 {
        WLog_ERR(TAG, "Not implemented!");
        return FALSE;
@@ -181,24 +178,52 @@ BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINT *lpPoints, int nCount)
  * @param nCount count of number of points in lpPolyCounts
  * @return nonzero if successful, 0 otherwise
  */
-BOOL gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT *lpPoints, int *lpPolyCounts, int nCount)
+BOOL gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT* lpPoints, int* lpPolyCounts,
+                     int nCount)
 {
        WLog_ERR(TAG, "Not implemented!");
        return FALSE;
 }
 
-/**
- * Draw a rectangle
- * @msdn{dd162898}
- * @param hdc device context
- * @param nLeftRect x1
- * @param nTopRect y1
- * @param nRightRect x2
- * @param nBottomRect y2
- * @return nonzero if successful, 0 otherwise
- */
-BOOL gdi_Rectangle(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
+BOOL gdi_Rectangle(HGDI_DC hdc, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
+                   UINT32 nHeight)
 {
-       WLog_ERR(TAG, "Not implemented!");
+       UINT32 x, y;
+       UINT32 color;
+
+       if (!gdi_ClipCoords(hdc, &nXDst, &nYDst, &nWidth, &nHeight, NULL, NULL))
+               return TRUE;
+
+       color = hdc->textColor;
+       color = GetColor(hdc->format, 0, 0xFF, 0, 0xFF);
+
+       for (y = 0; y < nHeight; y++)
+       {
+               BYTE* dstLeft = gdi_get_bitmap_pointer(hdc, nXDst,
+                                                      nYDst + y);
+               BYTE* dstRight = gdi_get_bitmap_pointer(hdc, nXDst + nWidth - 1,
+                                                       nYDst + y);
+
+               if (dstLeft)
+                       WriteColor(dstLeft, hdc->format, color);
+
+               if (dstRight)
+                       WriteColor(dstRight, hdc->format, color);
+       }
+
+       for (x = 0; x < nWidth; x++)
+       {
+               BYTE* dstTop = gdi_get_bitmap_pointer(hdc, nXDst + x,
+                                                     nYDst);
+               BYTE* dstBottom = gdi_get_bitmap_pointer(hdc, nXDst + x,
+                                 nYDst + nHeight - 1);
+
+               if (dstTop)
+                       WriteColor(dstTop, hdc->format, color);
+
+               if (dstBottom)
+                       WriteColor(dstBottom, hdc->format, color);
+       }
+
        return FALSE;
 }