diff --git a/channels/rdpgfx/client/rdpgfx_main.c b/channels/rdpgfx/client/rdpgfx_main.c index e2aa58607..e32ecd039 100644 --- a/channels/rdpgfx/client/rdpgfx_main.c +++ b/channels/rdpgfx/client/rdpgfx_main.c @@ -5,6 +5,8 @@ * Copyright 2013-2014 Marc-Andre Moreau * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -586,7 +588,18 @@ static UINT rdpgfx_recv_wire_to_surface_1_pdu(RDPGFX_CHANNEL_CALLBACK* callback, cmd.surfaceId = pdu.surfaceId; cmd.codecId = pdu.codecId; cmd.contextId = 0; - cmd.format = pdu.pixelFormat; + switch(pdu.pixelFormat) + { + case PIXEL_FORMAT_XRGB_8888: + cmd.format = PIXEL_FORMAT_BGRX32; + break; + case PIXEL_FORMAT_ARGB_8888: + cmd.format = PIXEL_FORMAT_BGRA32; + break; + default: + return ERROR_INVALID_DATA; + } + cmd.left = pdu.destRect.left; cmd.top = pdu.destRect.top; cmd.right = pdu.destRect.right; diff --git a/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionActivity.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionActivity.java index 8eaac0a98..2cee2bdb4 100644 --- a/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionActivity.java +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/SessionActivity.java @@ -1124,7 +1124,7 @@ public class SessionActivity extends ActionBarActivity implements } @Override - public int OnVerifiyChangedCertificate(String commonName, String subject, String issuer, String fingerprint, String oldSubject, String oldIssuer, String oldFingerprint) { + public int OnVerifyChangedCertificate(String commonName, String subject, String issuer, String fingerprint, String oldSubject, String oldIssuer, String oldFingerprint) { // see if global settings says accept all if (GlobalSettings.getAcceptAllCertificates()) return 0; diff --git a/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java index b45f45c83..d60452f16 100644 --- a/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java +++ b/client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java @@ -93,7 +93,7 @@ public class LibFreeRDP { int OnVerifiyCertificate(String commonName, String subject, String issuer, String fingerprint, boolean mismatch); - int OnVerifiyChangedCertificate(String commonName, String subject, + int OnVerifyChangedCertificate(String commonName, String subject, String issuer, String fingerprint, String oldSubject, String oldIssuer, String oldFingerprint); @@ -403,7 +403,7 @@ public class LibFreeRDP { return 0; } - private static int OnVerifyCertificate(int inst, String commonName, String subject, + private static int OnVerifyChangedCertificate(int inst, String commonName, String subject, String issuer, String fingerprint, String oldSubject, String oldIssuer, String oldFingerprint) { SessionState s = GlobalApp.getSession(inst); @@ -411,7 +411,7 @@ public class LibFreeRDP { return 0; UIEventListener uiEventListener = s.getUIEventListener(); if (uiEventListener != null) - return uiEventListener.OnVerifiyChangedCertificate(commonName, subject, issuer, + return uiEventListener.OnVerifyChangedCertificate(commonName, subject, issuer, fingerprint, oldSubject, oldIssuer, oldFingerprint); return 0; } diff --git a/client/Android/android_freerdp.c b/client/Android/android_freerdp.c index b3a548d34..8c9ff385a 100644 --- a/client/Android/android_freerdp.c +++ b/client/Android/android_freerdp.c @@ -334,7 +334,7 @@ static BOOL android_pre_connect(freerdp* instance) static BOOL android_post_connect(freerdp* instance) { - UINT32 gdi_flags; + UINT32 gdi_format; rdpSettings *settings; if (!instance || !instance->settings || !instance->context || !instance->update) @@ -346,11 +346,11 @@ static BOOL android_post_connect(freerdp* instance) return FALSE; if (instance->settings->ColorDepth > 16) - gdi_flags = CLRBUF_32BPP | CLRCONV_ALPHA | CLRCONV_INVERT; + gdi_format = PIXEL_FORMAT_ARGB32; else - gdi_flags = CLRBUF_16BPP; + gdi_format = PIXEL_FORMAT_RGB16; - if (!gdi_init(instance, gdi_flags, NULL)) + if (!gdi_init(instance, gdi_format)) return FALSE; instance->update->BeginPaint = android_begin_paint; @@ -916,7 +916,7 @@ static jboolean JNICALL jni_freerdp_update_graphics( } copy_pixel_buffer(pixels, gdi->primary_buffer, x, y, width, height, - gdi->width, gdi->height, gdi->bytesPerPixel); + gdi->width, gdi->height, GetBytesPerPixel(gdi->dstFormat)); if ((ret = AndroidBitmap_unlockPixels(env, bitmap)) < 0) { diff --git a/client/Sample/freerdp.c b/client/Sample/freerdp.c index 2e0d92b91..b00bc98f3 100644 --- a/client/Sample/freerdp.c +++ b/client/Sample/freerdp.c @@ -3,6 +3,8 @@ * FreeRDP Test UI * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,7 +119,7 @@ static BOOL tf_pre_connect(freerdp* instance) static BOOL tf_post_connect(freerdp* instance) { - if (!gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_16BPP | CLRBUF_32BPP, NULL)) + if (!gdi_init(instance, PIXEL_FORMAT_XRGB32)) return FALSE; instance->update->BeginPaint = tf_begin_paint; diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c index 1768969f2..d2f8f9648 100644 --- a/client/Wayland/wlfreerdp.c +++ b/client/Wayland/wlfreerdp.c @@ -3,6 +3,8 @@ * Wayland Client * * Copyright 2014 Manuel Bachmann + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,9 +99,9 @@ static BOOL wl_end_paint(rdpContext* context) for (i = 0; i < h; i++) { - memcpy(data + ((i+y)*(gdi->width*4)) + x*4, - gdi->primary_buffer + ((i+y)*(gdi->width*4)) + x*4, - w*4); + memcpy(data + ((i+y)*(gdi->width*GetBytesPerPixel(gdi->dstFormat))) + x*GetBytesPerPixel(gdi->dstFormat), + gdi->primary_buffer + ((i+y)*(gdi->width*GetBytesPerPixel(gdi->dstFormat))) + x*GetBytesPerPixel(gdi->dstFormat), + w*GetBytesPerPixel(gdi->dstFormat)); } if (UwacWindowAddDamage(context_w->window, x, y, w, h) != UWAC_SUCCESS) @@ -132,7 +134,7 @@ static BOOL wl_post_connect(freerdp* instance) UwacWindow* window; wlfContext* context; - if (!gdi_init(instance, CLRCONV_ALPHA | CLRBUF_32BPP, NULL)) + if (!gdi_init(instance, PIXEL_FORMAT_ARGB32)) return FALSE; gdi = instance->context->gdi; @@ -241,8 +243,8 @@ static int wlfreerdp_run(freerdp* instance) if (!freerdp_connect(instance)) { - printf("Failed to connect\n"); - return -1; + printf("Failed to connect\n"); + return -1; } handle_uwac_events(instance, g_display); @@ -271,11 +273,11 @@ static int wlfreerdp_run(freerdp* instance) } //if (WaitForMultipleObjects(count, &handles[1], FALSE, INFINITE)) { - if (freerdp_check_event_handles(instance->context) != TRUE) - { - printf("Failed to check FreeRDP file descriptor\n"); - break; - } + if (freerdp_check_event_handles(instance->context) != TRUE) + { + printf("Failed to check FreeRDP file descriptor\n"); + break; + } //} } diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index b7340b205..4ea30fe24 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -6,6 +6,8 @@ * Copyright 2013 Corey Clayton * Copyright 2014 Thincast Technologies GmbH * Copyright 2014 Norbert Federa + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -135,10 +137,8 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) xScalingFactor = xfc->sessionWidth / (double)xfc->scaledWidth; yScalingFactor = xfc->sessionHeight / (double)xfc->scaledHeight; - XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, 0); - /* Black out possible space between desktop and window borders */ { XRectangle box1 = { 0, 0, xfc->window->width, xfc->window->height }; @@ -151,22 +151,21 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) if (XSubtractRegion(reg1, reg2, reg1) && !XEmptyRegion(reg1)) { XSetRegion(xfc->display, xfc->gc, reg1); - XFillRectangle(xfc->display, xfc->window->handle, xfc->gc, 0, 0, xfc->window->width, xfc->window->height); + XFillRectangle(xfc->display, xfc->window->handle, xfc->gc, 0, 0, + xfc->window->width, xfc->window->height); XSetClipMask(xfc->display, xfc->gc, None); } XDestroyRegion(reg1); XDestroyRegion(reg2); } - picFormat = XRenderFindVisualFormat(xfc->display, xfc->visual); - pa.subwindow_mode = IncludeInferiors; - primaryPicture = XRenderCreatePicture(xfc->display, xfc->primary, picFormat, CPSubwindowMode, &pa); - windowPicture = XRenderCreatePicture(xfc->display, xfc->window->handle, picFormat, CPSubwindowMode, &pa); - + primaryPicture = XRenderCreatePicture(xfc->display, xfc->primary, picFormat, + CPSubwindowMode, &pa); + windowPicture = XRenderCreatePicture(xfc->display, xfc->window->handle, + picFormat, CPSubwindowMode, &pa); XRenderSetPictureFilter(xfc->display, primaryPicture, FilterBilinear, 0, 0); - transform.matrix[0][0] = XDoubleToFixed(xScalingFactor); transform.matrix[0][1] = XDoubleToFixed(0.0); transform.matrix[0][2] = XDoubleToFixed(0.0); @@ -176,7 +175,6 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) transform.matrix[2][0] = XDoubleToFixed(0.0); transform.matrix[2][1] = XDoubleToFixed(0.0); transform.matrix[2][2] = XDoubleToFixed(1.0); - /* calculate and fix up scaled coordinates */ x2 = x + w; y2 = y + h; @@ -184,9 +182,9 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) y = floor(y / yScalingFactor) - 1; w = ceil(x2 / xScalingFactor) + 1 - x; h = ceil(y2 / yScalingFactor) + 1 - y; - XRenderSetPictureTransform(xfc->display, primaryPicture, &transform); - XRenderComposite(xfc->display, PictOpSrc, primaryPicture, 0, windowPicture, x, y, 0, 0, xfc->offset_x + x, xfc->offset_y + y, w, h); + XRenderComposite(xfc->display, PictOpSrc, primaryPicture, 0, windowPicture, x, + y, 0, 0, xfc->offset_x + x, xfc->offset_y + y, w, h); XRenderFreePicture(xfc->display, primaryPicture); XRenderFreePicture(xfc->display, windowPicture); } @@ -194,8 +192,8 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) BOOL xf_picture_transform_required(xfContext* xfc) { if (xfc->offset_x || xfc->offset_y || - xfc->scaledWidth != xfc->sessionWidth || - xfc->scaledHeight != xfc->sessionHeight) + xfc->scaledWidth != xfc->sessionWidth || + xfc->scaledHeight != xfc->sessionHeight) { return TRUE; } @@ -213,12 +211,16 @@ void xf_draw_screen(xfContext* xfc, int x, int y, int w, int h) } #ifdef WITH_XRENDER - if (xf_picture_transform_required(xfc)) { + + if (xf_picture_transform_required(xfc)) + { xf_draw_screen_scaled(xfc, x, y, w, h); return; } + #endif - XCopyArea(xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y, w, h, x, y); + XCopyArea(xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y, w, h, + x, y); } static BOOL xf_desktop_resize(rdpContext* context) @@ -231,27 +233,35 @@ static BOOL xf_desktop_resize(rdpContext* context) { BOOL same = (xfc->primary == xfc->drawing) ? TRUE : FALSE; XFreePixmap(xfc->display, xfc->primary); - if (!(xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, xfc->sessionWidth, xfc->sessionHeight, xfc->depth))) + + if (!(xfc->primary = XCreatePixmap( + xfc->display, xfc->drawable, + xfc->sessionWidth, xfc->sessionHeight, xfc->depth))) return FALSE; + if (same) xfc->drawing = xfc->primary; } #ifdef WITH_XRENDER + if (!xfc->settings->SmartSizing) { xfc->scaledWidth = xfc->sessionWidth; xfc->scaledHeight = xfc->sessionHeight; } + #endif if (!xfc->fullscreen) { - xf_ResizeDesktopWindow(xfc, xfc->window, settings->DesktopWidth, settings->DesktopHeight); + xf_ResizeDesktopWindow(xfc, xfc->window, settings->DesktopWidth, + settings->DesktopHeight); } else { #ifdef WITH_XRENDER + if (!xfc->settings->SmartSizing) #endif { @@ -260,16 +270,18 @@ static BOOL xf_desktop_resize(rdpContext* context) xfc->savedWidth = xfc->sessionWidth; xfc->savedHeight = xfc->sessionHeight; } + XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, 0); - XFillRectangle(xfc->display, xfc->drawable, xfc->gc, 0, 0, xfc->window->width, xfc->window->height); + XFillRectangle(xfc->display, xfc->drawable, xfc->gc, 0, 0, xfc->window->width, + xfc->window->height); } return TRUE; } -BOOL xf_sw_begin_paint(rdpContext* context) +static BOOL xf_sw_begin_paint(rdpContext* context) { rdpGdi* gdi = context->gdi; gdi->primary->hdc->hwnd->invalid->null = 1; @@ -277,7 +289,7 @@ BOOL xf_sw_begin_paint(rdpContext* context) return TRUE; } -BOOL xf_sw_end_paint(rdpContext* context) +static BOOL xf_sw_end_paint(rdpContext* context) { int i; INT32 x, y; @@ -286,12 +298,10 @@ BOOL xf_sw_end_paint(rdpContext* context) HGDI_RGN cinvalid; xfContext* xfc = (xfContext*) context; rdpGdi* gdi = context->gdi; - x = gdi->primary->hdc->hwnd->invalid->x; y = gdi->primary->hdc->hwnd->invalid->y; w = gdi->primary->hdc->hwnd->invalid->w; h = gdi->primary->hdc->hwnd->invalid->h; - ninvalid = gdi->primary->hdc->hwnd->ninvalid; cinvalid = gdi->primary->hdc->hwnd->cinvalid; @@ -303,11 +313,9 @@ BOOL xf_sw_end_paint(rdpContext* context) return TRUE; xf_lock_x11(xfc, FALSE); - - XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, x, y, x, y, w, h); - + XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, + x, y, x, y, w, h); xf_draw_screen(xfc, x, y, w, h); - xf_unlock_x11(xfc, FALSE); } else @@ -323,14 +331,12 @@ BOOL xf_sw_end_paint(rdpContext* context) y = cinvalid[i].y; w = cinvalid[i].w; h = cinvalid[i].h; - - XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, x, y, x, y, w, h); - + XPutImage(xfc->display, xfc->primary, xfc->gc, + xfc->image, x, y, x, y, w, h); xf_draw_screen(xfc, x, y, w, h); } XFlush(xfc->display); - xf_unlock_x11(xfc, FALSE); } } @@ -340,22 +346,19 @@ BOOL xf_sw_end_paint(rdpContext* context) return TRUE; xf_lock_x11(xfc, FALSE); - xf_rail_paint(xfc, x, y, x + w, y + h); - xf_unlock_x11(xfc, FALSE); } + return TRUE; } -BOOL xf_sw_desktop_resize(rdpContext* context) +static BOOL xf_sw_desktop_resize(rdpContext* context) { rdpGdi* gdi = context->gdi; xfContext* xfc = (xfContext*) context; BOOL ret = FALSE; - xf_lock_x11(xfc, TRUE); - xfc->sessionWidth = context->settings->DesktopWidth; xfc->sessionHeight = context->settings->DesktopHeight; @@ -366,22 +369,22 @@ BOOL xf_sw_desktop_resize(rdpContext* context) { xfc->image->data = NULL; XDestroyImage(xfc->image); + } - if (!(xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) gdi->primary_buffer, gdi->width, gdi->height, xfc->scanline_pad, 0))) - { - goto out; - } + if (!(xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, + 0, + (char*) gdi->primary_buffer, gdi->width, gdi->height, xfc->scanline_pad, 0))) + { + goto out; } ret = xf_desktop_resize(context); - out: xf_unlock_x11(xfc, TRUE); return ret; } -BOOL xf_hw_begin_paint(rdpContext* context) +static BOOL xf_hw_begin_paint(rdpContext* context) { xfContext* xfc = (xfContext*) context; xfc->hdc->hwnd->invalid->null = 1; @@ -389,7 +392,7 @@ BOOL xf_hw_begin_paint(rdpContext* context) return TRUE; } -BOOL xf_hw_end_paint(rdpContext* context) +static BOOL xf_hw_end_paint(rdpContext* context) { INT32 x, y; UINT32 w, h; @@ -406,11 +409,8 @@ BOOL xf_hw_end_paint(rdpContext* context) y = xfc->hdc->hwnd->invalid->y; w = xfc->hdc->hwnd->invalid->w; h = xfc->hdc->hwnd->invalid->h; - xf_lock_x11(xfc, FALSE); - xf_draw_screen(xfc, x, y, w, h); - xf_unlock_x11(xfc, FALSE); } else @@ -424,7 +424,6 @@ BOOL xf_hw_end_paint(rdpContext* context) ninvalid = xfc->hdc->hwnd->ninvalid; cinvalid = xfc->hdc->hwnd->cinvalid; - xf_lock_x11(xfc, FALSE); for (i = 0; i < ninvalid; i++) @@ -433,12 +432,10 @@ BOOL xf_hw_end_paint(rdpContext* context) y = cinvalid[i].y; w = cinvalid[i].w; h = cinvalid[i].h; - xf_draw_screen(xfc, x, y, w, h); } XFlush(xfc->display); - xf_unlock_x11(xfc, FALSE); } } @@ -451,34 +448,29 @@ BOOL xf_hw_end_paint(rdpContext* context) y = xfc->hdc->hwnd->invalid->y; w = xfc->hdc->hwnd->invalid->w; h = xfc->hdc->hwnd->invalid->h; - xf_lock_x11(xfc, FALSE); - xf_rail_paint(xfc, x, y, x + w, y + h); - xf_unlock_x11(xfc, FALSE); } + return TRUE; } -BOOL xf_hw_desktop_resize(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; } -BOOL xf_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount) +BOOL xf_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, + int* wcount) { xfContext* xfc = (xfContext*) instance->context; rfds[*rcount] = (void*)(long)(xfc->xfds); @@ -492,7 +484,6 @@ BOOL xf_process_x_events(freerdp* instance) XEvent xevent; int pending_status; xfContext* xfc = (xfContext*) instance->context; - status = TRUE; pending_status = TRUE; @@ -506,13 +497,13 @@ BOOL xf_process_x_events(freerdp* instance) { ZeroMemory(&xevent, sizeof(xevent)); XNextEvent(xfc->display, &xevent); - status = xf_event_process(instance, &xevent); if (!status) return status; } } + return status; } @@ -523,14 +514,12 @@ BOOL xf_create_window(xfContext* xfc) int width, height; char* windowTitle; rdpSettings* settings = xfc->settings; - ZeroMemory(&xevent, sizeof(xevent)); - width = xfc->sessionWidth; height = xfc->sessionHeight; if (!xfc->hdc) - if (!(xfc->hdc = gdi_CreateDC(CLRBUF_32BPP, xfc->bpp))) + if (!(xfc->hdc = gdi_CreateDC(xfc->format))) return FALSE; if (!xfc->remote_app) @@ -542,7 +531,6 @@ BOOL xf_create_window(xfContext* xfc) xfc->attribs.colormap = xfc->colormap; xfc->attribs.bit_gravity = NorthWestGravity; xfc->attribs.win_gravity = NorthWestGravity; - #ifdef WITH_XRENDER xfc->offset_x = 0; xfc->offset_y = 0; @@ -551,42 +539,46 @@ BOOL xf_create_window(xfContext* xfc) if (settings->WindowTitle) { windowTitle = _strdup(settings->WindowTitle); + if (!windowTitle) return FALSE; } else if (settings->ServerPort == 3389) { - windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname)); + windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen( + settings->ServerHostname)); sprintf(windowTitle, "FreeRDP: %s", settings->ServerHostname); } else { - windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname) + sizeof(":00000")); - sprintf(windowTitle, "FreeRDP: %s:%i", settings->ServerHostname, settings->ServerPort); + windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname) + + sizeof(":00000")); + sprintf(windowTitle, "FreeRDP: %s:%i", settings->ServerHostname, + settings->ServerPort); } #ifdef WITH_XRENDER + if (settings->SmartSizing && !xfc->fullscreen) { if (settings->SmartSizingWidth) width = settings->SmartSizingWidth; + if (settings->SmartSizingHeight) height = settings->SmartSizingHeight; xfc->scaledWidth = width; xfc->scaledHeight = height; } + #endif - xfc->window = xf_CreateDesktopWindow(xfc, windowTitle, width, height); - free(windowTitle); if (xfc->fullscreen) xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen); xfc->unobscured = (xevent.xvisibility.state == VisibilityUnobscured); - XSetWMProtocols(xfc->display, xfc->window->handle, &(xfc->WM_DELETE_WINDOW), 1); xfc->drawable = xfc->window->handle; } @@ -601,23 +593,39 @@ BOOL xf_create_window(xfContext* xfc) XFreeModifiermap(xfc->modifierMap); xfc->modifierMap = XGetModifierMapping(xfc->display); + if (!xfc->gc) 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, xfc->sessionWidth, + xfc->sessionHeight, xfc->depth); + xfc->drawing = xfc->primary; + if (!xfc->bitmap_mono) xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1); + if (!xfc->gc_mono) - xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv); + xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, + &gcv); + 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, xfc->sessionWidth, + xfc->sessionHeight); XFlush(xfc->display); + if (!xfc->image) - xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) xfc->primary_buffer, xfc->sessionWidth, xfc->sessionHeight, xfc->scanline_pad, 0); + { + rdpGdi* gdi = xfc->context.gdi; + xfc->image = XCreateImage(xfc->display, xfc->visual, + xfc->depth, + ZPixmap, 0, (char*) gdi->primary_buffer, + xfc->sessionWidth, xfc->sessionHeight, + xfc->scanline_pad, 0); + } return TRUE; } @@ -648,13 +656,6 @@ void xf_window_free(xfContext* xfc) xfc->xv_context = NULL; } - if (xfc->bitmap_buffer) - { - _aligned_free(xfc->bitmap_buffer); - xfc->bitmap_buffer = NULL; - xfc->bitmap_size = 0; - } - if (xfc->image) { xfc->image->data = NULL; @@ -692,12 +693,9 @@ void xf_toggle_fullscreen(xfContext* xfc) WindowStateChangeEventArgs e; rdpContext* context = (rdpContext*) xfc; rdpSettings* settings = context->settings; - xfc->fullscreen = (xfc->fullscreen) ? FALSE : TRUE; xfc->decorations = (xfc->fullscreen) ? FALSE : settings->Decorations; - xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen); - EventArgsInit(&e, "xfreerdp"); e.state = xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0; PubSub_OnWindowStateChange(context->pubSub, context, &e); @@ -707,7 +705,6 @@ void xf_toggle_control(xfContext* xfc) { EncomspClientContext* encomsp; ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU pdu; - encomsp = xfc->encomsp; if (!encomsp) @@ -720,7 +717,6 @@ void xf_toggle_control(xfContext* xfc) pdu.Flags |= ENCOMSP_REQUEST_INTERACT; encomsp->ChangeParticipantControlLevel(encomsp, &pdu); - xfc->controlToggle = !xfc->controlToggle; } @@ -729,7 +725,8 @@ void xf_toggle_control(xfContext* xfc) * * @return 0 on success, otherwise a Win32 error code */ -UINT xf_encomsp_participant_created(EncomspClientContext* context, ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) +UINT xf_encomsp_participant_created(EncomspClientContext* context, + ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) { return CHANNEL_RC_OK; } @@ -738,7 +735,6 @@ void xf_encomsp_init(xfContext* xfc, EncomspClientContext* encomsp) { xfc->encomsp = encomsp; encomsp->custom = (void*) xfc; - encomsp->ParticipantCreated = xf_encomsp_participant_created; } @@ -808,25 +804,25 @@ BOOL xf_get_pixmap_info(xfContext* xfc) if (pf->depth == xfc->depth) { - xfc->bpp = pf->bits_per_pixel; xfc->scanline_pad = pf->scanline_pad; break; } } XFree(pfs); - ZeroMemory(&template, sizeof(template)); template.class = TrueColor; template.screen = xfc->screen_number; - if (XGetWindowAttributes(xfc->display, RootWindowOfScreen(xfc->screen), &window_attributes) == 0) + if (XGetWindowAttributes(xfc->display, RootWindowOfScreen(xfc->screen), + &window_attributes) == 0) { WLog_ERR(TAG, "XGetWindowAttributes failed"); return FALSE; } - vis = XGetVisualInfo(xfc->display, VisualClassMask | VisualScreenMask, &template, &vi_count); + vis = XGetVisualInfo(xfc->display, VisualClassMask | VisualScreenMask, + &template, &vi_count); if (!vis) { @@ -839,6 +835,7 @@ BOOL xf_get_pixmap_info(xfContext* xfc) for (i = 0; i < vi_count; i++) { vi = vis + i; + if (vi->visual == window_attributes.visual) { xfc->visual = vi->visual; @@ -859,8 +856,10 @@ BOOL xf_get_pixmap_info(xfContext* xfc) /* calculate color shifts required for rdp order color conversion */ xf_calculate_color_shifts(vi->red_mask, &xfc->red_shift_r, &xfc->red_shift_l); - xf_calculate_color_shifts(vi->green_mask, &xfc->green_shift_r, &xfc->green_shift_l); - xf_calculate_color_shifts(vi->blue_mask, &xfc->blue_shift_r, &xfc->blue_shift_l); + xf_calculate_color_shifts(vi->green_mask, &xfc->green_shift_r, + &xfc->green_shift_l); + xf_calculate_color_shifts(vi->blue_mask, &xfc->blue_shift_r, + &xfc->blue_shift_l); } XFree(vis); @@ -876,17 +875,14 @@ BOOL xf_get_pixmap_info(xfContext* xfc) int xf_error_handler(Display* d, XErrorEvent* ev) { char buf[256]; - int do_abort = TRUE; XGetErrorText(d, ev->error_code, buf, sizeof(buf)); - WLog_ERR(TAG, "%s", buf); if (do_abort) abort(); _def_error_handler(d, ev); - return FALSE; } @@ -901,7 +897,8 @@ int _xf_error_handler(Display* d, XErrorEvent* ev) return xf_error_handler(d, ev); } -static BOOL xf_play_sound(rdpContext* context, PLAY_SOUND_UPDATE* play_sound) +static BOOL xf_play_sound(rdpContext* context, + const PLAY_SOUND_UPDATE* play_sound) { xfContext* xfc = (xfContext*) context; XkbBell(xfc->display, None, 100, 0); @@ -914,8 +911,9 @@ void xf_check_extensions(xfContext* context) int xkb_major = XkbMajorVersion; int xkb_minor = XkbMinorVersion; - if (XkbLibraryVersion(&xkb_major, &xkb_minor) && XkbQueryExtension(context->display, &xkb_opcode, &xkb_event, - &xkb_error, &xkb_major, &xkb_minor)) + if (XkbLibraryVersion(&xkb_major, &xkb_minor) + && XkbQueryExtension(context->display, &xkb_opcode, &xkb_event, + &xkb_error, &xkb_major, &xkb_minor)) { context->xkbAvailable = TRUE; } @@ -926,7 +924,7 @@ void xf_check_extensions(xfContext* context) int xrender_error_base; if (XRenderQueryExtension(context->display, &xrender_event_base, - &xrender_error_base)) + &xrender_error_base)) { context->xrenderAvailable = TRUE; } @@ -938,13 +936,13 @@ void xf_check_extensions(xfContext* context) /* Input device which does NOT have the correct mapping. We must disregard */ /* this device when trying to find the input device which is the pointer. */ static const char TEST_PTR_STR [] = "Virtual core XTEST pointer"; -static const size_t TEST_PTR_LEN = sizeof (TEST_PTR_STR) / sizeof (char); +static const size_t TEST_PTR_LEN = sizeof(TEST_PTR_STR) / sizeof(char); /* Invalid device identifier which indicate failure. */ static const int INVALID_XID = -1; #endif /* WITH_XI */ -static void xf_get_x11_button_map (xfContext* xfc, unsigned char* x11_map) +static void xf_get_x11_button_map(xfContext* xfc, unsigned char* x11_map) { #ifdef WITH_XI int opcode, event, error; @@ -955,57 +953,64 @@ static void xf_get_x11_button_map (xfContext* xfc, unsigned char* x11_map) XIDeviceInfo* devices2; int i, num_devices; - if (XQueryExtension (xfc->display, "XInputExtension", &opcode, &event, &error)) + if (XQueryExtension(xfc->display, "XInputExtension", &opcode, &event, &error)) { WLog_DBG(TAG, "Searching for XInput pointer device"); xid = INVALID_XID; /* loop through every device, looking for a pointer */ - version = XGetExtensionVersion (xfc->display, INAME); + version = XGetExtensionVersion(xfc->display, INAME); + if (version->major_version >= 2) { /* XID of pointer device using XInput version 2 */ - devices2 = XIQueryDevice (xfc->display, XIAllDevices, &num_devices); + devices2 = XIQueryDevice(xfc->display, XIAllDevices, &num_devices); + if (devices2) { for (i = 0; i < num_devices; ++i) { if ((devices2[i].use == XISlavePointer) && - (strncmp (devices2[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0)) + (strncmp(devices2[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0)) { xid = devices2[i].deviceid; break; } } - XIFreeDeviceInfo (devices2); + + XIFreeDeviceInfo(devices2); } } else { /* XID of pointer device using XInput version 1 */ - devices1 = XListInputDevices (xfc->display, &num_devices); + devices1 = XListInputDevices(xfc->display, &num_devices); + if (devices1) { for (i = 0; i < num_devices; ++i) { if ((devices1[i].use == IsXExtensionPointer) && - (strncmp (devices1[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0)) + (strncmp(devices1[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0)) { xid = devices1[i].id; break; } } - XFreeDeviceList (devices1); + + XFreeDeviceList(devices1); } } - XFree (version); + + XFree(version); + /* get button mapping from input extension if there is a pointer device; */ /* otherwise leave unchanged. */ if (xid != INVALID_XID) { WLog_DBG(TAG, "Pointer device: %d", xid); - ptr_dev = XOpenDevice (xfc->display, xid); - XGetDeviceButtonMapping (xfc->display, ptr_dev, x11_map, NUM_BUTTONS_MAPPED); - XCloseDevice (xfc->display, ptr_dev); + ptr_dev = XOpenDevice(xfc->display, xid); + XGetDeviceButtonMapping(xfc->display, ptr_dev, x11_map, NUM_BUTTONS_MAPPED); + XCloseDevice(xfc->display, ptr_dev); } else { @@ -1016,27 +1021,28 @@ static void xf_get_x11_button_map (xfContext* xfc, unsigned char* x11_map) #endif /* WITH_XI */ { WLog_DBG(TAG, "Get global pointer mapping (no XInput)"); - XGetPointerMapping (xfc->display, x11_map, NUM_BUTTONS_MAPPED); + XGetPointerMapping(xfc->display, x11_map, NUM_BUTTONS_MAPPED); } } /* Assignment of physical (not logical) mouse buttons to wire flags. */ /* Notice that the middle button is 2 in X11, but 3 in RDP. */ -static const int xf_button_flags[NUM_BUTTONS_MAPPED] = { +static const int xf_button_flags[NUM_BUTTONS_MAPPED] = +{ PTR_FLAGS_BUTTON1, PTR_FLAGS_BUTTON3, PTR_FLAGS_BUTTON2 }; -static void xf_button_map_init (xfContext* xfc) +static void xf_button_map_init(xfContext* xfc) { /* loop counter for array initialization */ int physical; int logical; - /* logical mouse button which is used for each physical mouse */ /* button (indexed from zero). This is the default map. */ - unsigned char x11_map[NUM_BUTTONS_MAPPED] = { + unsigned char x11_map[NUM_BUTTONS_MAPPED] = + { Button1, Button2, Button3 @@ -1045,7 +1051,7 @@ static void xf_button_map_init (xfContext* xfc) /* query system for actual remapping */ if (!xfc->settings->UnmapButtons) { - xf_get_x11_button_map (xfc, x11_map); + xf_get_x11_button_map(xfc, x11_map); } /* iterate over all (mapped) physical buttons; for each of them */ @@ -1054,14 +1060,15 @@ static void xf_button_map_init (xfContext* xfc) for (physical = 0; physical < NUM_BUTTONS_MAPPED; ++physical) { logical = x11_map[physical]; + if (Button1 <= logical && logical <= Button3) { - xfc->button_map[logical-BUTTON_BASE] = xf_button_flags[physical]; + xfc->button_map[logical - BUTTON_BASE] = xf_button_flags[physical]; } else { - WLog_ERR(TAG,"Mouse physical button %d is mapped to logical button %d", - physical, logical); + WLog_ERR(TAG, "Mouse physical button %d is mapped to logical button %d", + physical, logical); } } } @@ -1084,18 +1091,13 @@ BOOL xf_pre_connect(freerdp* instance) xfContext* xfc = (xfContext*) instance->context; UINT32 maxWidth = 0; UINT32 maxHeight = 0; - - xfc->codecs = context->codecs; xfc->settings = instance->settings; xfc->instance = instance; - settings = instance->settings; channels = context->channels; - settings->OsMajorType = OSMAJORTYPE_UNIX; settings->OsMinorType = OSMINORTYPE_NATIVE_XSERVER; - ZeroMemory(settings->OrderSupport, 32); settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE; settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE; @@ -1110,22 +1112,24 @@ BOOL xf_pre_connect(freerdp* instance) settings->OrderSupport[NEG_LINETO_INDEX] = TRUE; settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE; settings->OrderSupport[NEG_MEMBLT_INDEX] = settings->BitmapCacheEnabled; - settings->OrderSupport[NEG_MEM3BLT_INDEX] = (settings->SoftwareGdi) ? TRUE : FALSE; + settings->OrderSupport[NEG_MEM3BLT_INDEX] = (settings->SoftwareGdi) ? TRUE : + FALSE; settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = settings->BitmapCacheEnabled; settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE; settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE; settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE; settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE; settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE; - settings->OrderSupport[NEG_POLYGON_SC_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE; - settings->OrderSupport[NEG_POLYGON_CB_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE; + settings->OrderSupport[NEG_POLYGON_SC_INDEX] = (settings->SoftwareGdi) ? FALSE : + TRUE; + settings->OrderSupport[NEG_POLYGON_CB_INDEX] = (settings->SoftwareGdi) ? FALSE : + TRUE; settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE; settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE; - PubSub_SubscribeChannelConnected(instance->context->pubSub, - (pChannelConnectedEventHandler) xf_OnChannelConnectedEventHandler); + (pChannelConnectedEventHandler) xf_OnChannelConnectedEventHandler); PubSub_SubscribeChannelDisconnected(instance->context->pubSub, - (pChannelDisconnectedEventHandler) xf_OnChannelDisconnectedEventHandler); + (pChannelDisconnectedEventHandler) xf_OnChannelDisconnectedEventHandler); if (!freerdp_client_load_addins(channels, instance->settings)) return FALSE; @@ -1140,8 +1144,10 @@ BOOL xf_pre_connect(freerdp* instance) if (login_name) { settings->Username = _strdup(login_name); + if (!settings->Username) return FALSE; + WLog_INFO(TAG, "No user name set. - Using login name: %s", settings->Username); } } @@ -1176,24 +1182,24 @@ BOOL xf_pre_connect(freerdp* instance) } #ifdef WITH_XRENDER + /** * If /f is specified in combination with /smart-sizing:widthxheight then * we run the session in the /smart-sizing dimensions scaled to full screen */ if (settings->Fullscreen && settings->SmartSizing && - settings->SmartSizingWidth && settings->SmartSizingHeight) + settings->SmartSizingWidth && settings->SmartSizingHeight) { settings->DesktopWidth = settings->SmartSizingWidth; settings->DesktopHeight = settings->SmartSizingHeight; } -#endif +#endif xfc->fullscreen = settings->Fullscreen; xfc->decorations = settings->Decorations; xfc->grab_keyboard = settings->GrabKeyboard; xfc->fullscreen_toggle = settings->ToggleFullscreen; - xf_button_map_init (xfc); - + xf_button_map_init(xfc); return TRUE; } @@ -1204,7 +1210,6 @@ BOOL xf_pre_connect(freerdp* instance) */ BOOL xf_post_connect(freerdp* instance) { - UINT32 flags; rdpCache* cache; rdpUpdate* update; rdpContext* context; @@ -1212,7 +1217,6 @@ BOOL xf_post_connect(freerdp* instance) rdpSettings* settings; ResizeWindowEventArgs e; xfContext* xfc = (xfContext*) instance->context; - context = instance->context; cache = context->cache; channels = context->channels; @@ -1225,34 +1229,23 @@ BOOL xf_post_connect(freerdp* instance) return FALSE; } - flags = CLRCONV_ALPHA; - - if (xfc->bpp > 16) - flags |= CLRBUF_32BPP; - else - flags |= CLRBUF_16BPP; + if (!gdi_init(instance, xfc->format)) + return FALSE; if (settings->SoftwareGdi) { - rdpGdi* gdi; - - if (!gdi_init(instance, flags, NULL)) - return FALSE; - - gdi = context->gdi; - xfc->primary_buffer = gdi->primary_buffer; + rdpGdi* gdi = context->gdi; xfc->palette = gdi->palette; } else { xfc->palette = xfc->palette_hwgdi; - xfc->srcBpp = settings->ColorDepth; 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; @@ -1322,7 +1315,6 @@ BOOL xf_post_connect(freerdp* instance) e.width = settings->DesktopWidth; e.height = settings->DesktopHeight; PubSub_OnResizeWindow(context->pubSub, xfc, &e); - return TRUE; } @@ -1336,9 +1328,7 @@ static void xf_post_disconnect(freerdp* instance) context = instance->context; xfc = (xfContext*) context; - freerdp_channels_disconnect(context->channels, instance); - gdi_free(instance); if (xfc->clipboard) @@ -1377,9 +1367,7 @@ void* xf_input_thread(void* arg) int process_status = 1; freerdp* instance = (freerdp*) arg; xfContext* xfc = (xfContext*) instance->context; - queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE); - nCount = 0; events[nCount++] = MessageQueue_Event(queue); events[nCount++] = xfc->x11event; @@ -1408,12 +1396,9 @@ void* xf_input_thread(void* arg) if (pending_status) { xf_lock_x11(xfc, FALSE); - ZeroMemory(&xevent, sizeof(xevent)); XNextEvent(xfc->display, &xevent); - process_status = xf_event_process(instance, &xevent); - xf_unlock_x11(xfc, FALSE); if (!process_status) @@ -1424,7 +1409,6 @@ void* xf_input_thread(void* arg) if (!process_status) break; - } } @@ -1439,7 +1423,6 @@ BOOL xf_auto_reconnect(freerdp* instance) UINT32 numRetries = 0; xfContext* xfc = (xfContext*) instance->context; rdpSettings* settings = xfc->settings; - maxRetries = settings->AutoReconnectMaxRetries; /* Only auto reconnect on network disconnects. */ @@ -1477,7 +1460,6 @@ BOOL xf_auto_reconnect(freerdp* instance) } WLog_ERR(TAG, "Maximum reconnect retries exceeded"); - return FALSE; } @@ -1502,28 +1484,28 @@ void* xf_client_thread(void* param) HANDLE inputThread = NULL; rdpChannels* channels; rdpSettings* settings; - exit_code = 0; instance = (freerdp*) param; context = instance->context; - status = freerdp_connect(instance); - xfc = (xfContext*) instance->context; /* --authonly ? */ if (instance->settings->AuthenticationOnly) { WLog_ERR(TAG, "Authentication only, exit status %d", !status); + if (!status) { - if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_AUTHENTICATION_FAILED) + if (freerdp_get_last_error(instance->context) == + FREERDP_ERROR_AUTHENTICATION_FAILED) exit_code = XF_EXIT_AUTH_FAILURE; else exit_code = XF_EXIT_CONN_FAILED; } else exit_code = XF_EXIT_SUCCESS; + goto disconnect; } @@ -1531,10 +1513,13 @@ void* xf_client_thread(void* param) { WLog_ERR(TAG, "Freerdp connect error exit status %d", !status); exit_code = freerdp_error_info(instance); - if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_AUTHENTICATION_FAILED) + + if (freerdp_get_last_error(instance->context) == + FREERDP_ERROR_AUTHENTICATION_FAILED) exit_code = XF_EXIT_AUTH_FAILURE; else exit_code = XF_EXIT_CONN_FAILED; + goto disconnect; } @@ -1547,13 +1532,16 @@ void* xf_client_thread(void* param) } else { - if (!(inputEvent = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE))) + if (!(inputEvent = freerdp_get_message_queue_event_handle(instance, + FREERDP_INPUT_MESSAGE_QUEUE))) { WLog_ERR(TAG, "async input: failed to get input event handle"); exit_code = XF_EXIT_UNKNOWN; goto disconnect; } - if (!(inputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_input_thread, instance, 0, NULL))) + + if (!(inputThread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) xf_input_thread, instance, 0, NULL))) { WLog_ERR(TAG, "async input: failed to create input thread"); exit_code = XF_EXIT_UNKNOWN; @@ -1616,7 +1604,8 @@ void* xf_client_thread(void* param) { if (WaitForSingleObject(inputEvent, 0) == WAIT_OBJECT_0) { - if (!freerdp_message_queue_process_pending_messages(instance, FREERDP_INPUT_MESSAGE_QUEUE)) + if (!freerdp_message_queue_process_pending_messages(instance, + FREERDP_INPUT_MESSAGE_QUEUE)) { WLog_INFO(TAG, "User Disconnect"); xfc->disconnect = TRUE; @@ -1628,9 +1617,12 @@ void* xf_client_thread(void* param) if (settings->AsyncInput) { - wMessageQueue* inputQueue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE); + wMessageQueue* inputQueue = freerdp_get_message_queue(instance, + FREERDP_INPUT_MESSAGE_QUEUE); + if (MessageQueue_PostQuit(inputQueue, 0)) WaitForSingleObject(inputThread, INFINITE); + CloseHandle(inputThread); } @@ -1645,17 +1637,18 @@ disconnect: DWORD xf_exit_code_from_disconnect_reason(DWORD reason) { - if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_AUTH_FAILURE)) - return reason; + if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS + && reason <= XF_EXIT_AUTH_FAILURE)) + return reason; /* License error set */ else if (reason >= 0x100 && reason <= 0x10A) - reason -= 0x100 + XF_EXIT_LICENSE_INTERNAL; + reason -= 0x100 + XF_EXIT_LICENSE_INTERNAL; /* RDP protocol error set */ else if (reason >= 0x10c9 && reason <= 0x1193) - reason = XF_EXIT_RDP; + reason = XF_EXIT_RDP; /* There's no need to test protocol-independent codes: they match */ else if (!(reason <= 0xC)) - reason = XF_EXIT_UNKNOWN; + reason = XF_EXIT_UNKNOWN; return reason; } @@ -1663,12 +1656,12 @@ DWORD xf_exit_code_from_disconnect_reason(DWORD reason) void xf_TerminateEventHandler(rdpContext* context, TerminateEventArgs* e) { wMessageQueue* queue; - xfContext* xfc = (xfContext*) context; if (context->settings->AsyncInput) { - queue = freerdp_get_message_queue(context->instance, FREERDP_INPUT_MESSAGE_QUEUE); + queue = freerdp_get_message_queue(context->instance, + FREERDP_INPUT_MESSAGE_QUEUE); if (queue) MessageQueue_PostQuit(queue, 0); @@ -1680,7 +1673,8 @@ void xf_TerminateEventHandler(rdpContext* context, TerminateEventArgs* e) } #ifdef WITH_XRENDER -static void xf_ZoomingChangeEventHandler(rdpContext* context, ZoomingChangeEventArgs* e) +static void xf_ZoomingChangeEventHandler(rdpContext* context, + ZoomingChangeEventArgs* e) { xfContext* xfc = (xfContext*) context; int w = xfc->scaledWidth + e->dx; @@ -1690,21 +1684,21 @@ static void xf_ZoomingChangeEventHandler(rdpContext* context, ZoomingChangeEvent return; if (w < 10) - w = 10; + w = 10; if (h < 10) - h = 10; + h = 10; if (w == xfc->scaledWidth && h == xfc->scaledHeight) return; xfc->scaledWidth = w; xfc->scaledHeight = h; - xf_draw_screen(xfc, 0, 0, xfc->sessionWidth, xfc->sessionHeight); } -static void xf_PanningChangeEventHandler(rdpContext* context, PanningChangeEventArgs* e) +static void xf_PanningChangeEventHandler(rdpContext* context, + PanningChangeEventArgs* e) { xfContext* xfc = (xfContext*) context; @@ -1713,7 +1707,6 @@ static void xf_PanningChangeEventHandler(rdpContext* context, PanningChangeEvent xfc->offset_x += e->dx; xfc->offset_y += e->dy; - xf_draw_screen(xfc, 0, 0, xfc->sessionWidth, xfc->sessionHeight); } #endif @@ -1725,14 +1718,15 @@ static void xf_PanningChangeEventHandler(rdpContext* context, PanningChangeEvent static BOOL xfreerdp_client_global_init() { setlocale(LC_ALL, ""); + if (freerdp_handle_signals() != 0) return FALSE; + return TRUE; } static void xfreerdp_client_global_uninit() { - } static int xfreerdp_client_start(rdpContext* context) @@ -1742,15 +1736,16 @@ static int xfreerdp_client_start(rdpContext* context) if (!settings->ServerHostname) { - WLog_ERR(TAG, "error: server hostname was not specified with /v:[:port]"); + WLog_ERR(TAG, + "error: server hostname was not specified with /v:[:port]"); return -1; } xfc->disconnect = FALSE; if (!(xfc->thread = CreateThread(NULL, 0, - (LPTHREAD_START_ROUTINE) xf_client_thread, - context->instance, 0, NULL))) + (LPTHREAD_START_ROUTINE) xf_client_thread, + context->instance, 0, NULL))) { WLog_ERR(TAG, "failed to create client thread"); return -1; @@ -1766,8 +1761,8 @@ static int xfreerdp_client_stop(rdpContext* context) if (context->settings->AsyncInput) { wMessageQueue* queue; - - queue = freerdp_get_message_queue(context->instance, FREERDP_INPUT_MESSAGE_QUEUE); + queue = freerdp_get_message_queue(context->instance, + FREERDP_INPUT_MESSAGE_QUEUE); if (queue) MessageQueue_PostQuit(queue, 0); @@ -1791,7 +1786,6 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) { rdpSettings* settings; xfContext* xfc = (xfContext*) instance->context; - assert(context); assert(xfc); assert(!context->channels); @@ -1810,18 +1804,18 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) instance->VerifyCertificate = client_cli_verify_certificate; instance->VerifyChangedCertificate = client_cli_verify_changed_certificate; instance->LogonErrorInfo = xf_logon_error_info; - settings = instance->settings; xfc->settings = instance->context->settings; - - PubSub_SubscribeTerminate(context->pubSub, (pTerminateEventHandler) xf_TerminateEventHandler); - + PubSub_SubscribeTerminate(context->pubSub, + (pTerminateEventHandler) xf_TerminateEventHandler); #ifdef WITH_XRENDER - PubSub_SubscribeZoomingChange(context->pubSub, (pZoomingChangeEventHandler) xf_ZoomingChangeEventHandler); - PubSub_SubscribePanningChange(context->pubSub, (pPanningChangeEventHandler) xf_PanningChangeEventHandler); + PubSub_SubscribeZoomingChange(context->pubSub, + (pZoomingChangeEventHandler) xf_ZoomingChangeEventHandler); + PubSub_SubscribePanningChange(context->pubSub, + (pPanningChangeEventHandler) xf_PanningChangeEventHandler); #endif - xfc->UseXThreads = TRUE; + //xfc->debug = TRUE; if (xfc->UseXThreads) { @@ -1837,7 +1831,8 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) if (!xfc->display) { WLog_ERR(TAG, "failed to open display: %s", XDisplayName(NULL)); - WLog_ERR(TAG, "Please check that the $DISPLAY environment variable is properly set."); + WLog_ERR(TAG, + "Please check that the $DISPLAY environment variable is properly set."); goto fail_open_display; } @@ -1851,31 +1846,44 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) xfc->_NET_WM_ICON = XInternAtom(xfc->display, "_NET_WM_ICON", False); xfc->_MOTIF_WM_HINTS = XInternAtom(xfc->display, "_MOTIF_WM_HINTS", False); - xfc->_NET_CURRENT_DESKTOP = XInternAtom(xfc->display, "_NET_CURRENT_DESKTOP", False); + xfc->_NET_CURRENT_DESKTOP = XInternAtom(xfc->display, "_NET_CURRENT_DESKTOP", + False); xfc->_NET_WORKAREA = XInternAtom(xfc->display, "_NET_WORKAREA", False); xfc->_NET_WM_STATE = XInternAtom(xfc->display, "_NET_WM_STATE", False); - xfc->_NET_WM_STATE_FULLSCREEN = XInternAtom(xfc->display, "_NET_WM_STATE_FULLSCREEN", False); - xfc->_NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); - xfc->_NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(xfc->display, "_NET_WM_STATE_MAXIMIZED_VERT", False); - xfc->_NET_WM_FULLSCREEN_MONITORS = XInternAtom(xfc->display, "_NET_WM_FULLSCREEN_MONITORS", False); + xfc->_NET_WM_STATE_FULLSCREEN = XInternAtom(xfc->display, + "_NET_WM_STATE_FULLSCREEN", False); + xfc->_NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(xfc->display, + "_NET_WM_STATE_MAXIMIZED_HORZ", False); + xfc->_NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(xfc->display, + "_NET_WM_STATE_MAXIMIZED_VERT", False); + xfc->_NET_WM_FULLSCREEN_MONITORS = XInternAtom(xfc->display, + "_NET_WM_FULLSCREEN_MONITORS", False); xfc->_NET_WM_NAME = XInternAtom(xfc->display, "_NET_WM_NAME", False); xfc->_NET_WM_PID = XInternAtom(xfc->display, "_NET_WM_PID", False); - xfc->_NET_WM_WINDOW_TYPE = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE", False); - xfc->_NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_NORMAL", False); - xfc->_NET_WM_WINDOW_TYPE_DIALOG = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_DIALOG", False); - xfc->_NET_WM_WINDOW_TYPE_POPUP = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_POPUP", False); - xfc->_NET_WM_WINDOW_TYPE_UTILITY = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_UTILITY", False); - xfc->_NET_WM_WINDOW_TYPE_DROPDOWN_MENU = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False); - xfc->_NET_WM_STATE_SKIP_TASKBAR = XInternAtom(xfc->display, "_NET_WM_STATE_SKIP_TASKBAR", False); - xfc->_NET_WM_STATE_SKIP_PAGER = XInternAtom(xfc->display, "_NET_WM_STATE_SKIP_PAGER", False); - xfc->_NET_WM_MOVERESIZE = XInternAtom(xfc->display, "_NET_WM_MOVERESIZE", False); - xfc->_NET_MOVERESIZE_WINDOW = XInternAtom(xfc->display, "_NET_MOVERESIZE_WINDOW", False); - + xfc->_NET_WM_WINDOW_TYPE = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE", + False); + xfc->_NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(xfc->display, + "_NET_WM_WINDOW_TYPE_NORMAL", False); + xfc->_NET_WM_WINDOW_TYPE_DIALOG = XInternAtom(xfc->display, + "_NET_WM_WINDOW_TYPE_DIALOG", False); + xfc->_NET_WM_WINDOW_TYPE_POPUP = XInternAtom(xfc->display, + "_NET_WM_WINDOW_TYPE_POPUP", False); + xfc->_NET_WM_WINDOW_TYPE_UTILITY = XInternAtom(xfc->display, + "_NET_WM_WINDOW_TYPE_UTILITY", False); + xfc->_NET_WM_WINDOW_TYPE_DROPDOWN_MENU = XInternAtom(xfc->display, + "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False); + xfc->_NET_WM_STATE_SKIP_TASKBAR = XInternAtom(xfc->display, + "_NET_WM_STATE_SKIP_TASKBAR", False); + xfc->_NET_WM_STATE_SKIP_PAGER = XInternAtom(xfc->display, + "_NET_WM_STATE_SKIP_PAGER", False); + xfc->_NET_WM_MOVERESIZE = XInternAtom(xfc->display, "_NET_WM_MOVERESIZE", + False); + xfc->_NET_MOVERESIZE_WINDOW = XInternAtom(xfc->display, + "_NET_MOVERESIZE_WINDOW", False); xfc->UTF8_STRING = XInternAtom(xfc->display, "UTF8_STRING", FALSE); xfc->WM_PROTOCOLS = XInternAtom(xfc->display, "WM_PROTOCOLS", False); xfc->WM_DELETE_WINDOW = XInternAtom(xfc->display, "WM_DELETE_WINDOW", False); xfc->WM_STATE = XInternAtom(xfc->display, "WM_STATE", False); - xfc->xfds = ConnectionNumber(xfc->display); xfc->screen_number = DefaultScreen(xfc->display); xfc->screen = ScreenOfDisplay(xfc->display, xfc->screen_number); @@ -1883,8 +1891,9 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) xfc->big_endian = (ImageByteOrder(xfc->display) == MSBFirst); xfc->invert = (ImageByteOrder(xfc->display) == MSBFirst) ? TRUE : FALSE; xfc->complex_regions = TRUE; + xfc->x11event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfc->xfds, + WINPR_FD_READ); - xfc->x11event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfc->xfds, WINPR_FD_READ); if (!xfc->x11event) { WLog_ERR(TAG, "Could not create xfds event"); @@ -1892,18 +1901,18 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) } xfc->colormap = DefaultColormap(xfc->display, xfc->screen_number); - xfc->format = PIXEL_FORMAT_XRGB32; + xfc->format = PIXEL_FORMAT_RGBX32; if (xfc->depth == 32) - xfc->format = (!xfc->invert) ? PIXEL_FORMAT_XRGB32 : PIXEL_FORMAT_XBGR32; + xfc->format = (!xfc->invert) ? PIXEL_FORMAT_RGBA32 : PIXEL_FORMAT_BGRA32; else if (xfc->depth == 24) - xfc->format = (!xfc->invert) ? PIXEL_FORMAT_XRGB32 : PIXEL_FORMAT_XBGR32; + xfc->format = (!xfc->invert) ? PIXEL_FORMAT_RGBX32 : PIXEL_FORMAT_BGRX32; else if (xfc->depth == 16) - xfc->format = (!xfc->invert) ? PIXEL_FORMAT_RGB565 : PIXEL_FORMAT_BGR565; + xfc->format = (!xfc->invert) ? PIXEL_FORMAT_RGB16 : PIXEL_FORMAT_BGR16; else if (xfc->depth == 15) - xfc->format = (!xfc->invert) ? PIXEL_FORMAT_RGB555 : PIXEL_FORMAT_BGR555; + xfc->format = (!xfc->invert) ? PIXEL_FORMAT_RGB16 : PIXEL_FORMAT_BGR16; else - xfc->format = PIXEL_FORMAT_XRGB32; + xfc->format = PIXEL_FORMAT_RGBX32; if (xfc->debug) { @@ -1926,7 +1935,6 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) goto fail_vscreen_monitors; return TRUE; - fail_vscreen_monitors: fail_pixmap_info: CloseHandle(xfc->x11event); diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index bb8573172..dbafce602 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -215,60 +215,64 @@ BOOL xf_set_rop3(xfContext* xfc, int rop3) } XSetFunction(xfc->display, xfc->gc, function); - return TRUE; } UINT32 xf_convert_rdp_order_color(xfContext* xfc, UINT32 color) { - UINT32 r = 0, g = 0, b = 0; + BYTE r = 0, g = 0, b = 0; switch (xfc->srcBpp) { - case 32: - case 24: - if (xfc->visual->red_mask == 0xFF0000 && - xfc->visual->green_mask == 0xFF00 && - xfc->visual->blue_mask == 0xFF) - { + case 32: + case 24: + if (xfc->visual->red_mask == 0xFF0000 && + xfc->visual->green_mask == 0xFF00 && + xfc->visual->blue_mask == 0xFF) + { + return color; + } + + color = GetColor(xfc->format, r, g, b, 0xFF); + break; + + case 16: + color = (color & 0xFF00) | ((color >> 16) & 0xFF); + + if (xfc->visual->red_mask == 0xF800 && + xfc->visual->green_mask == 0x07E0 && + xfc->visual->blue_mask == 0x001F) + { + return color; + } + + color = GetColor(xfc->format, r, g, b, 0xFF); + break; + + case 15: + color = (color & 0xFF00) | ((color >> 16) & 0xFF); + color = GetColor(xfc->format, r, g, b, 0xFF); + break; + + case 8: + color = (color >> 16) & (UINT32) 0xFF; + + if (xfc->palette) + { + UINT32 dstColor = xfc->palette[color]; + SplitColor(dstColor, xfc->format, &r, &g, &b, + NULL, NULL); + } + + break; + + default: return color; - } - GetRGB32(r, g, b, color); - break; - - case 16: - color = (color & 0xFF00) | ((color >> 16) & 0xFF); - if (xfc->visual->red_mask == 0xF800 && - xfc->visual->green_mask == 0x07E0 && - xfc->visual->blue_mask == 0x001F) - { - return color; - } - GetRGB16(r, g, b, color); - break; - - case 15: - color = (color & 0xFF00) | ((color >> 16) & 0xFF); - GetRGB15(r, g, b, color); - break; - - case 8: - color = (color >> 16) & (UINT32) 0xFF; - if (xfc->palette) - { - r = xfc->palette[(color * 4) + 2]; - g = xfc->palette[(color * 4) + 1]; - b = xfc->palette[(color * 4) + 0]; - } - break; - - default: - return color; } - return ( ((r >> xfc->red_shift_r) << xfc->red_shift_l) | - ((g >> xfc->green_shift_r) << xfc->green_shift_l) | - ((b >> xfc->blue_shift_r) << xfc->blue_shift_l) ); + return (((r >> xfc->red_shift_r) << xfc->red_shift_l) | + ((g >> xfc->green_shift_r) << xfc->green_shift_l) | + ((b >> xfc->blue_shift_r) << xfc->blue_shift_l)); } Pixmap xf_brush_new(xfContext* xfc, int width, int height, int bpp, BYTE* data) @@ -278,21 +282,16 @@ Pixmap xf_brush_new(xfContext* xfc, int width, int height, int bpp, BYTE* data) BYTE* cdata; XImage* image; UINT32 brushFormat; - bitmap = XCreatePixmap(xfc->display, xfc->drawable, width, height, xfc->depth); if (data) { brushFormat = gdi_get_pixel_format(bpp, FALSE); - cdata = (BYTE*) _aligned_malloc(width * height * 4, 16); - freerdp_image_copy(cdata, xfc->format, -1, 0, 0, - width, height, data, brushFormat, -1, 0, 0, xfc->palette); - + width, height, data, brushFormat, -1, 0, 0, xfc->palette); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, - ZPixmap, 0, (char*) cdata, width, height, xfc->scanline_pad, 0); - + ZPixmap, 0, (char*) cdata, width, height, xfc->scanline_pad, 0); gc = XCreateGC(xfc->display, xfc->drawable, 0, NULL); XPutImage(xfc->display, bitmap, gc, image, 0, 0, 0, 0, width, height); XFree(image); @@ -311,21 +310,17 @@ Pixmap xf_mono_bitmap_new(xfContext* xfc, int width, int height, BYTE* data) int scanline; XImage* image; Pixmap bitmap; - scanline = (width + 7) / 8; - bitmap = XCreatePixmap(xfc->display, xfc->drawable, width, height, 1); - image = XCreateImage(xfc->display, xfc->visual, 1, - ZPixmap, 0, (char*) data, width, height, 8, scanline); - + ZPixmap, 0, (char*) data, width, height, 8, scanline); XPutImage(xfc->display, bitmap, xfc->gc_mono, image, 0, 0, 0, 0, width, height); XFree(image); - return bitmap; } -BOOL xf_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) +BOOL xf_gdi_bitmap_update(rdpContext* context, + const BITMAP_UPDATE* bitmapUpdate) { int status; int nXDst; @@ -341,8 +336,6 @@ BOOL xf_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) UINT32 SrcSize; BOOL compressed; UINT32 SrcFormat; - UINT32 bitsPerPixel; - UINT32 bytesPerPixel; BITMAP_DATA* bitmap; rdpCodecs* codecs = context->codecs; xfContext* xfc = (xfContext*) context; @@ -350,58 +343,45 @@ BOOL xf_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) 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; - bytesPerPixel = (bitsPerPixel + 7) / 8; - SrcFormat = gdi_get_pixel_format(bitsPerPixel, TRUE); - if (xfc->bitmap_size < (nWidth * nHeight * 4)) - { - xfc->bitmap_size = nWidth * nHeight * 4; - xfc->bitmap_buffer = (BYTE*) _aligned_realloc(xfc->bitmap_buffer, xfc->bitmap_size, 16); - - if (!xfc->bitmap_buffer) - return FALSE; - } - if (compressed) { pDstData = xfc->bitmap_buffer; if (bitsPerPixel < 32) { - if (!freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_INTERLEAVED, - xfc->settings->DesktopWidth, - xfc->settings->DesktopHeight)) + if (!freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_INTERLEAVED)) return FALSE; - status = interleaved_decompress(codecs->interleaved, pSrcData, SrcSize, bitsPerPixel, - &pDstData, xfc->format, -1, 0, 0, nWidth, nHeight, xfc->palette); + status = interleaved_decompress(codecs->interleaved, + pSrcData, SrcSize, + bitsPerPixel, + pDstData, + xfc->format, -1, + 0, 0, + nWidth, nHeight, + xfc->palette); } else { - if (!freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_PLANAR, - xfc->settings->DesktopWidth, - xfc->settings->DesktopHeight)) + if (!freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_PLANAR)) return FALSE; status = planar_decompress(codecs->planar, pSrcData, SrcSize, &pDstData, - xfc->format, -1, 0, 0, nWidth, nHeight, TRUE); + xfc->format, -1, 0, 0, nWidth, nHeight, TRUE); } if (status < 0) @@ -415,19 +395,16 @@ BOOL xf_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) else { pDstData = xfc->bitmap_buffer; - status = freerdp_image_copy(pDstData, xfc->format, -1, 0, 0, - nWidth, nHeight, pSrcData, SrcFormat, -1, 0, 0, xfc->palette); - + nWidth, nHeight, pSrcData, SrcFormat, -1, 0, 0, xfc->palette); pSrcData = xfc->bitmap_buffer; } xf_lock_x11(xfc, FALSE); - XSetFunction(xfc->display, xfc->gc, GXcopy); - image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) pSrcData, nWidth, nHeight, xfc->scanline_pad, 0); + (char*) pSrcData, nWidth, nHeight, xfc->scanline_pad, 0); + if (!image) { xf_unlock_x11(xfc, FALSE); @@ -436,48 +413,45 @@ BOOL xf_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) nWidth = bitmap->destRight - bitmap->destLeft + 1; /* clip width */ nHeight = bitmap->destBottom - bitmap->destTop + 1; /* clip height */ - XPutImage(xfc->display, xfc->primary, xfc->gc, - image, 0, 0, nXDst, nYDst, nWidth, nHeight); - + image, 0, 0, nXDst, nYDst, nWidth, nHeight); XFree(image); - ret = gdi_InvalidateRegion(xfc->hdc, nXDst, nYDst, nWidth, nHeight); - xf_unlock_x11(xfc, FALSE); if (!ret) break; } + return ret; } -static BOOL xf_gdi_palette_update(rdpContext* context, PALETTE_UPDATE* palette) +static BOOL xf_gdi_palette_update(rdpContext* context, + const PALETTE_UPDATE* palette) { int index; - PALETTE_ENTRY* pe; + const PALETTE_ENTRY* pe; UINT32* palette32; xfContext* xfc = (xfContext*) context; - xf_lock_x11(xfc, FALSE); - palette32 = (UINT32*) xfc->palette; for (index = 0; index < palette->number; index++) { pe = &(palette->entries[index]); - palette32[index] = RGB32(pe->red, pe->green, pe->blue); + palette32[index] = GetColor(xfc->format, + pe->red, pe->green, pe->blue, 0xFF); } xf_unlock_x11(xfc, FALSE); return TRUE; } -static BOOL xf_gdi_set_bounds(rdpContext* context, rdpBounds* bounds) +static BOOL xf_gdi_set_bounds(rdpContext* context, + const rdpBounds* bounds) { XRectangle clip; xfContext* xfc = (xfContext*) context; - xf_lock_x11(xfc, FALSE); if (bounds) @@ -497,25 +471,22 @@ static BOOL xf_gdi_set_bounds(rdpContext* context, rdpBounds* bounds) return TRUE; } -static BOOL xf_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) +static BOOL xf_gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt) { xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - xf_set_rop3(xfc, gdi_rop3_code(dstblt->bRop)); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, - dstblt->nLeftRect, dstblt->nTopRect, - dstblt->nWidth, dstblt->nHeight); + dstblt->nLeftRect, dstblt->nTopRect, + dstblt->nWidth, dstblt->nHeight); if (xfc->drawing == xfc->primary) - ret = gdi_InvalidateRegion(xfc->hdc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth, dstblt->nHeight); + ret = gdi_InvalidateRegion(xfc->hdc, dstblt->nLeftRect, dstblt->nTopRect, + dstblt->nWidth, dstblt->nHeight); XSetFunction(xfc->display, xfc->gc, GXcopy); - xf_unlock_x11(xfc, FALSE); return ret; } @@ -523,17 +494,14 @@ static BOOL xf_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { Pixmap pattern; - rdpBrush* brush; + const rdpBrush* brush; UINT32 foreColor; UINT32 backColor; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - brush = &patblt->brush; xf_set_rop3(xfc, gdi_rop3_code(patblt->bRop)); - foreColor = xf_convert_rdp_order_color(xfc, patblt->foreColor); backColor = xf_convert_rdp_order_color(xfc, patblt->backColor); @@ -541,23 +509,20 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, foreColor); - XFillRectangle(xfc->display, xfc->drawing, xfc->gc, - patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); + patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); } else if (brush->style == GDI_BS_HATCHED) { - pattern = xf_mono_bitmap_new(xfc, 8, 8, GDI_BS_HATCHED_PATTERNS + 8 * brush->hatch); - + pattern = xf_mono_bitmap_new(xfc, 8, 8, + GDI_BS_HATCHED_PATTERNS + 8 * brush->hatch); XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); - XFillRectangle(xfc->display, xfc->drawing, xfc->gc, - patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); - + patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XFreePixmap(xfc->display, pattern); } else if (brush->style == GDI_BS_PATTERN) @@ -565,31 +530,24 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) if (brush->bpp > 1) { pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data); - XSetFillStyle(xfc->display, xfc->gc, FillTiled); XSetTile(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); - XFillRectangle(xfc->display, xfc->drawing, xfc->gc, - patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); - + patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XSetTile(xfc->display, xfc->gc, xfc->primary); - XFreePixmap(xfc->display, pattern); } else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); - XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); - XFillRectangle(xfc->display, xfc->drawing, xfc->gc, - patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); - + patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XFreePixmap(xfc->display, pattern); } } @@ -599,73 +557,71 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) } if (xfc->drawing == xfc->primary) - ret = gdi_InvalidateRegion(xfc->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); + ret = gdi_InvalidateRegion(xfc->hdc, patblt->nLeftRect, patblt->nTopRect, + patblt->nWidth, patblt->nHeight); XSetFunction(xfc->display, xfc->gc, GXcopy); - xf_unlock_x11(xfc, FALSE); return ret; } -static BOOL xf_gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) +static BOOL xf_gdi_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt) { xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; + if (!xfc->display || !xfc->drawing) + return FALSE; + xf_lock_x11(xfc, FALSE); - xf_set_rop3(xfc, gdi_rop3_code(scrblt->bRop)); - - XCopyArea(xfc->display, xfc->primary, xfc->drawing, xfc->gc, scrblt->nXSrc, scrblt->nYSrc, - scrblt->nWidth, scrblt->nHeight, scrblt->nLeftRect, scrblt->nTopRect); + XCopyArea(xfc->display, xfc->primary, xfc->drawing, xfc->gc, scrblt->nXSrc, + scrblt->nYSrc, + scrblt->nWidth, scrblt->nHeight, scrblt->nLeftRect, scrblt->nTopRect); if (xfc->drawing == xfc->primary) - ret = gdi_InvalidateRegion(xfc->hdc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth, scrblt->nHeight); + ret = gdi_InvalidateRegion(xfc->hdc, scrblt->nLeftRect, scrblt->nTopRect, + scrblt->nWidth, scrblt->nHeight); XSetFunction(xfc->display, xfc->gc, GXcopy); - xf_unlock_x11(xfc, FALSE); return ret; } -BOOL xf_gdi_opaque_rect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect) +static BOOL xf_gdi_opaque_rect(rdpContext* context, + const OPAQUE_RECT_ORDER* opaque_rect) { UINT32 color; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - color = xf_convert_rdp_order_color(xfc, opaque_rect->color); - XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, color); - XFillRectangle(xfc->display, xfc->drawing, xfc->gc, - opaque_rect->nLeftRect, opaque_rect->nTopRect, - opaque_rect->nWidth, opaque_rect->nHeight); + opaque_rect->nLeftRect, opaque_rect->nTopRect, + opaque_rect->nWidth, opaque_rect->nHeight); if (xfc->drawing == xfc->primary) - ret = gdi_InvalidateRegion(xfc->hdc, opaque_rect->nLeftRect, opaque_rect->nTopRect, - opaque_rect->nWidth, opaque_rect->nHeight); + ret = gdi_InvalidateRegion(xfc->hdc, opaque_rect->nLeftRect, + opaque_rect->nTopRect, + opaque_rect->nWidth, opaque_rect->nHeight); xf_unlock_x11(xfc, FALSE); return ret; } -BOOL xf_gdi_multi_opaque_rect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) +static BOOL xf_gdi_multi_opaque_rect(rdpContext* context, + const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) { - int i; + UINT32 i; UINT32 color; - DELTA_RECT* rectangle; + const DELTA_RECT* rectangle; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - color = xf_convert_rdp_order_color(xfc, multi_opaque_rect->color); - XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, color); @@ -673,14 +629,14 @@ BOOL xf_gdi_multi_opaque_rect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* mult for (i = 1; i < multi_opaque_rect->numRectangles + 1; i++) { rectangle = &multi_opaque_rect->rectangles[i]; - XFillRectangle(xfc->display, xfc->drawing, xfc->gc, - rectangle->left, rectangle->top, - rectangle->width, rectangle->height); + rectangle->left, rectangle->top, + rectangle->width, rectangle->height); if (xfc->drawing == xfc->primary) { - if (!(ret = gdi_InvalidateRegion(xfc->hdc, rectangle->left, rectangle->top, rectangle->width, rectangle->height))) + if (!(ret = gdi_InvalidateRegion(xfc->hdc, rectangle->left, rectangle->top, + rectangle->width, rectangle->height))) break; } } @@ -689,48 +645,42 @@ BOOL xf_gdi_multi_opaque_rect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* mult return ret; } -void xf_gdi_draw_nine_grid(rdpContext* context, DRAW_NINE_GRID_ORDER* draw_nine_grid) +void xf_gdi_draw_nine_grid(rdpContext* context, + DRAW_NINE_GRID_ORDER* draw_nine_grid) { WLog_ERR(TAG, "DrawNineGrid"); } -BOOL xf_gdi_line_to(rdpContext* context, LINE_TO_ORDER* line_to) +static BOOL xf_gdi_line_to(rdpContext* context, const LINE_TO_ORDER* line_to) { UINT32 color; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - xf_set_rop2(xfc, line_to->bRop2); color = xf_convert_rdp_order_color(xfc, line_to->penColor); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, color); - XDrawLine(xfc->display, xfc->drawing, xfc->gc, - line_to->nXStart, line_to->nYStart, line_to->nXEnd, line_to->nYEnd); + line_to->nXStart, line_to->nYStart, line_to->nXEnd, line_to->nYEnd); if (xfc->drawing == xfc->primary) { int x, y, w, h; - x = MIN(line_to->nXStart, line_to->nXEnd); y = MIN(line_to->nYStart, line_to->nYEnd); - w = abs(line_to->nXEnd - line_to->nXStart) + 1; h = abs(line_to->nYEnd - line_to->nYStart) + 1; - ret = gdi_InvalidateRegion(xfc->hdc, x, y, w, h); } XSetFunction(xfc->display, xfc->gc, GXcopy); - xf_unlock_x11(xfc, FALSE); return ret; } -static BOOL xf_gdi_invalidate_poly_region(xfContext* xfc, XPoint* points, int npoints) +static BOOL xf_gdi_invalidate_poly_region(xfContext* xfc, XPoint* points, + int npoints) { int x, y, x1, y1, x2, y2; @@ -748,21 +698,24 @@ static BOOL xf_gdi_invalidate_poly_region(xfContext* xfc, XPoint* points, int np if (x > x2) x2 = x; + if (x < x1) x1 = x; + if (y > y2) y2 = y; + if (y < y1) y1 = y; } x2++; y2++; - return gdi_InvalidateRegion(xfc->hdc, x1, y1, x2 - x1, y2 - y1); } -BOOL xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) +static BOOL xf_gdi_polyline(rdpContext* context, + const POLYLINE_ORDER* polyline) { int i; int npoints; @@ -770,17 +723,14 @@ BOOL xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) XPoint* points; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - xf_set_rop2(xfc, polyline->bRop2); color = xf_convert_rdp_order_color(xfc, polyline->penColor); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, color); - npoints = polyline->numDeltaEntries + 1; points = malloc(sizeof(XPoint) * npoints); + if (!points) { xf_unlock_x11(xfc, FALSE); @@ -796,7 +746,8 @@ BOOL xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) points[i + 1].y = polyline->points[i].y; } - XDrawLines(xfc->display, xfc->drawing, xfc->gc, points, npoints, CoordModePrevious); + XDrawLines(xfc->display, xfc->drawing, xfc->gc, points, npoints, + CoordModePrevious); if (xfc->drawing == xfc->primary) { @@ -806,38 +757,42 @@ BOOL xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) XSetFunction(xfc->display, xfc->gc, GXcopy); free(points); - xf_unlock_x11(xfc, FALSE); return ret; } -BOOL xf_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) +static BOOL xf_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { - xfBitmap* bitmap; + xfBitmap* bitmap = (xfBitmap*) memblt->bitmap; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; + if (!xfc->display || !xfc->drawing) + return FALSE; + xf_lock_x11(xfc, FALSE); - bitmap = (xfBitmap*) memblt->bitmap; - xf_set_rop3(xfc, gdi_rop3_code(memblt->bRop)); + if (xf_set_rop3(xfc, gdi_rop3_code(memblt->bRop))) + { + XCopyArea(xfc->display, bitmap->pixmap, xfc->drawing, xfc->gc, + memblt->nXSrc, memblt->nYSrc, memblt->nWidth, memblt->nHeight, + memblt->nLeftRect, memblt->nTopRect); - XCopyArea(xfc->display, bitmap->pixmap, xfc->drawing, xfc->gc, - memblt->nXSrc, memblt->nYSrc, memblt->nWidth, memblt->nHeight, - memblt->nLeftRect, memblt->nTopRect); + if (xfc->drawing == xfc->primary) + ret = gdi_InvalidateRegion(xfc->hdc, memblt->nLeftRect, + memblt->nTopRect, memblt->nWidth, + memblt->nHeight); - if (xfc->drawing == xfc->primary) - ret = gdi_InvalidateRegion(xfc->hdc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth, memblt->nHeight); - - XSetFunction(xfc->display, xfc->gc, GXcopy); + XSetFunction(xfc->display, xfc->gc, GXcopy); + } xf_unlock_x11(xfc, FALSE); return ret; } -BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) +static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) { - rdpBrush* brush; + const rdpBrush* brush; xfBitmap* bitmap; UINT32 foreColor; UINT32 backColor; @@ -845,8 +800,10 @@ BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); + if (!xfc->display || !xfc->drawing) + return FALSE; + xf_lock_x11(xfc, FALSE); brush = &mem3blt->brush; bitmap = (xfBitmap*) mem3blt->bitmap; xf_set_rop3(xfc, gdi_rop3_code(mem3blt->bRop)); @@ -858,7 +815,6 @@ BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) if (brush->bpp > 1) { pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data); - XSetFillStyle(xfc->display, xfc->gc, FillTiled); XSetTile(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); @@ -866,7 +822,6 @@ BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); - XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); @@ -879,7 +834,6 @@ BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); - XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); } else @@ -888,11 +842,12 @@ BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) } XCopyArea(xfc->display, bitmap->pixmap, xfc->drawing, xfc->gc, - mem3blt->nXSrc, mem3blt->nYSrc, mem3blt->nWidth, mem3blt->nHeight, - mem3blt->nLeftRect, mem3blt->nTopRect); + mem3blt->nXSrc, mem3blt->nYSrc, mem3blt->nWidth, mem3blt->nHeight, + mem3blt->nLeftRect, mem3blt->nTopRect); if (xfc->drawing == xfc->primary) - ret = gdi_InvalidateRegion(xfc->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth, mem3blt->nHeight); + ret = gdi_InvalidateRegion(xfc->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, + mem3blt->nWidth, mem3blt->nHeight); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetTSOrigin(xfc->display, xfc->gc, 0, 0); @@ -901,27 +856,25 @@ BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) XFreePixmap(xfc->display, pattern); XSetFunction(xfc->display, xfc->gc, GXcopy); - xf_unlock_x11(xfc, FALSE); return ret; } -BOOL xf_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc) +static BOOL xf_gdi_polygon_sc(rdpContext* context, + const POLYGON_SC_ORDER* polygon_sc) { int i, npoints; XPoint* points; UINT32 brush_color; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - xf_set_rop2(xfc, polygon_sc->bRop2); brush_color = xf_convert_rdp_order_color(xfc, polygon_sc->brushColor); - npoints = polygon_sc->numPoints + 1; points = malloc(sizeof(XPoint) * npoints); + if (!points) { xf_unlock_x11(xfc, FALSE); @@ -954,9 +907,8 @@ BOOL xf_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc) XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, brush_color); - XFillPolygon(xfc->display, xfc->drawing, xfc->gc, - points, npoints, Complex, CoordModePrevious); + points, npoints, Complex, CoordModePrevious); if (xfc->drawing == xfc->primary) { @@ -966,31 +918,29 @@ BOOL xf_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc) XSetFunction(xfc->display, xfc->gc, GXcopy); free(points); - xf_unlock_x11(xfc, FALSE); return ret; } -BOOL xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) +static BOOL xf_gdi_polygon_cb(rdpContext* context, + POLYGON_CB_ORDER* polygon_cb) { int i, npoints; XPoint* points; Pixmap pattern; - rdpBrush* brush; + const rdpBrush* brush; UINT32 foreColor; UINT32 backColor; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - xf_lock_x11(xfc, FALSE); - brush = &(polygon_cb->brush); xf_set_rop2(xfc, polygon_cb->bRop2); foreColor = xf_convert_rdp_order_color(xfc, polygon_cb->foreColor); backColor = xf_convert_rdp_order_color(xfc, polygon_cb->backColor); - npoints = polygon_cb->numPoints + 1; points = malloc(sizeof(XPoint) * npoints); + if (!points) { xf_unlock_x11(xfc, FALSE); @@ -1026,14 +976,12 @@ BOOL xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) if (brush->bpp > 1) { pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data); - XSetFillStyle(xfc->display, xfc->gc, FillTiled); XSetTile(xfc->display, xfc->gc, pattern); } else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); - XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); @@ -1046,10 +994,8 @@ BOOL xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) } XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); - XFillPolygon(xfc->display, xfc->drawing, xfc->gc, - points, npoints, Complex, CoordModePrevious); - + points, npoints, Complex, CoordModePrevious); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetTSOrigin(xfc->display, xfc->gc, 0, 0); XFreePixmap(xfc->display, pattern); @@ -1067,37 +1013,37 @@ BOOL xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) XSetFunction(xfc->display, xfc->gc, GXcopy); free(points); - xf_unlock_x11(xfc, FALSE); return ret; } -BOOL xf_gdi_ellipse_sc(rdpContext* context, ELLIPSE_SC_ORDER* ellipse_sc) +static BOOL xf_gdi_ellipse_sc(rdpContext* context, + const ELLIPSE_SC_ORDER* ellipse_sc) { WLog_ERR(TAG, "Not implemented: EllipseSC"); return TRUE; } -BOOL xf_gdi_ellipse_cb(rdpContext* context, ELLIPSE_CB_ORDER* ellipse_cb) +static BOOL xf_gdi_ellipse_cb(rdpContext* context, + const ELLIPSE_CB_ORDER* ellipse_cb) { WLog_ERR(TAG, "Not implemented: EllipseCB"); return TRUE; } -BOOL xf_gdi_frame_marker(rdpContext* context, FRAME_MARKER_ORDER* frameMarker) +static BOOL xf_gdi_frame_marker(rdpContext* context, + const FRAME_MARKER_ORDER* frameMarker) { return TRUE; } -BOOL xf_gdi_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surface_frame_marker) +static BOOL xf_gdi_surface_frame_marker(rdpContext* context, + const SURFACE_FRAME_MARKER* surface_frame_marker) { rdpSettings* settings; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - settings = xfc->instance->settings; - - xf_lock_x11(xfc, FALSE); switch (surface_frame_marker->frameAction) @@ -1112,13 +1058,17 @@ BOOL xf_gdi_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surf case SURFACECMD_FRAMEACTION_END: xfc->frame_begin = FALSE; + if ((xfc->frame_x2 > xfc->frame_x1) && (xfc->frame_y2 > xfc->frame_y1)) ret = gdi_InvalidateRegion(xfc->hdc, xfc->frame_x1, xfc->frame_y1, - xfc->frame_x2 - xfc->frame_x1, xfc->frame_y2 - xfc->frame_y1); + xfc->frame_x2 - xfc->frame_x1, xfc->frame_y2 - xfc->frame_y1); + if (settings->FrameAcknowledge > 0) { - IFCALL(xfc->instance->update->SurfaceFrameAcknowledge, context, surface_frame_marker->frameId); + IFCALL(xfc->instance->update->SurfaceFrameAcknowledge, context, + surface_frame_marker->frameId); } + break; } @@ -1126,9 +1076,11 @@ BOOL xf_gdi_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surf return ret; } -static BOOL xf_gdi_surface_update_frame(xfContext* xfc, UINT16 tx, UINT16 ty, UINT16 width, UINT16 height) +static BOOL xf_gdi_surface_update_frame(xfContext* xfc, UINT16 tx, UINT16 ty, + UINT16 width, UINT16 height) { BOOL ret = TRUE; + if (!xfc->remote_app) { if (xfc->frame_begin) @@ -1157,32 +1109,36 @@ static BOOL xf_gdi_surface_update_frame(xfContext* xfc, UINT16 tx, UINT16 ty, UI { ret = gdi_InvalidateRegion(xfc->hdc, tx, ty, width, height); } + return ret; } -BOOL xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) +static BOOL xf_gdi_surface_bits(rdpContext* context, + const SURFACE_BITS_COMMAND* cmd) { int i, tx, ty; XImage* image; BYTE* pSrcData; BYTE* pDstData; - RFX_MESSAGE* message; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - + rdpGdi* gdi = context->gdi; + REGION16 invalidRegion; xf_lock_x11(xfc, FALSE); if (cmd->codecID == RDP_CODEC_ID_REMOTEFX) { - if (!freerdp_client_codecs_prepare(xfc->codecs, FREERDP_CODEC_REMOTEFX, - xfc->settings->DesktopWidth, - xfc->settings->DesktopHeight)) + if (!freerdp_client_codecs_prepare(xfc->codecs, FREERDP_CODEC_REMOTEFX)) { xf_unlock_x11(xfc, FALSE); return FALSE; } - if (!(message = rfx_process_message(xfc->codecs->rfx, cmd->bitmapData, cmd->bitmapDataLength))) + if (!rfx_process_message(xfc->codecs->rfx, cmd->bitmapData, + PIXEL_FORMAT_XRGB32, cmd->bitmapDataLength, + cmd->destLeft, cmd->destTop, + gdi->primary_buffer, gdi->dstFormat, gdi->stride, + gdi->height, &invalidRegion)) { WLog_ERR(TAG, "Failed to process RemoteFX message"); xf_unlock_x11(xfc, FALSE); @@ -1191,47 +1147,8 @@ BOOL xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetClipRectangles(xfc->display, xfc->gc, cmd->destLeft, cmd->destTop, - (XRectangle*) message->rects, message->numRects, YXBanded); - - if (xfc->bitmap_size < (64 * 64 * 4)) - { - xfc->bitmap_size = 64 * 64 * 4; - xfc->bitmap_buffer = (BYTE*) _aligned_realloc(xfc->bitmap_buffer, xfc->bitmap_size, 16); - - if (!xfc->bitmap_buffer) - { - rfx_message_free(xfc->codecs->rfx, message); - XSetClipMask(xfc->display, xfc->gc, None); - xf_unlock_x11(xfc, FALSE); - return FALSE; - } - } - - /* Draw the tiles to primary surface, each is 64x64. */ - for (i = 0; i < message->numTiles; i++) - { - pSrcData = message->tiles[i]->data; - pDstData = pSrcData; - - if ((xfc->depth != 24) && (xfc->depth != 32)) - { - pDstData = xfc->bitmap_buffer; - - freerdp_image_copy(pDstData, xfc->format, -1, 0, 0, - 64, 64, pSrcData, PIXEL_FORMAT_XRGB32, -1, 0, 0, xfc->palette); - } - - image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) pDstData, 64, 64, xfc->scanline_pad, 0); - - tx = message->tiles[i]->x + cmd->destLeft; - ty = message->tiles[i]->y + cmd->destTop; - - XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, tx, ty, 64, 64); - XFree(image); - } + (XRectangle*) message->rects, message->numRects, YXBanded); /* Invalidate the updated region */ for (i = 0; i < message->numRects; i++) @@ -1239,7 +1156,8 @@ BOOL xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) tx = message->rects[i].x + cmd->destLeft; ty = message->rects[i].y + cmd->destTop; - if (!xf_gdi_surface_update_frame(xfc, tx, ty, message->rects[i].width, message->rects[i].height)) + if (!xf_gdi_surface_update_frame(xfc, tx, ty, message->rects[i].width, + message->rects[i].height)) { ret = FALSE; break; @@ -1251,82 +1169,47 @@ BOOL xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) } else if (cmd->codecID == RDP_CODEC_ID_NSCODEC) { - if (!freerdp_client_codecs_prepare(xfc->codecs, FREERDP_CODEC_NSCODEC, - xfc->settings->DesktopWidth, - xfc->settings->DesktopHeight)) + if (!freerdp_client_codecs_prepare(xfc->codecs, FREERDP_CODEC_NSCODEC)) { xf_unlock_x11(xfc, FALSE); return FALSE; } - nsc_process_message(xfc->codecs->nsc, cmd->bpp, cmd->width, cmd->height, cmd->bitmapData, cmd->bitmapDataLength); - + nsc_process_message(xfc->codecs->nsc, cmd->bpp, cmd->width, cmd->height, + cmd->bitmapData, cmd->bitmapDataLength); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - - if (xfc->bitmap_size < (cmd->width * cmd->height * 4)) - { - xfc->bitmap_size = cmd->width * cmd->height * 4; - xfc->bitmap_buffer = (BYTE*) _aligned_realloc(xfc->bitmap_buffer, xfc->bitmap_size, 16); - - if (!xfc->bitmap_buffer) - { - xf_unlock_x11(xfc, FALSE); - return FALSE; - } - } - pSrcData = xfc->codecs->nsc->BitmapData; pDstData = xfc->bitmap_buffer; - freerdp_image_copy(pDstData, xfc->format, -1, 0, 0, - cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, xfc->palette); - + cmd->width, cmd->height, pSrcData, + PIXEL_FORMAT_BGRX32_VF, -1, 0, 0, xfc->palette); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) pDstData, cmd->width, cmd->height, xfc->scanline_pad, 0); - + (char*) pDstData, cmd->width, cmd->height, xfc->scanline_pad, 0); XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, - cmd->destLeft, cmd->destTop, cmd->width, cmd->height); - + cmd->destLeft, cmd->destTop, cmd->width, cmd->height); XFree(image); - - ret = xf_gdi_surface_update_frame(xfc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height); - + ret = xf_gdi_surface_update_frame(xfc, cmd->destLeft, cmd->destTop, cmd->width, + cmd->height); XSetClipMask(xfc->display, xfc->gc, None); } else if (cmd->codecID == RDP_CODEC_ID_NONE) { XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - - if (xfc->bitmap_size < (cmd->width * cmd->height * 4)) - { - xfc->bitmap_size = cmd->width * cmd->height * 4; - xfc->bitmap_buffer = (BYTE*) _aligned_realloc(xfc->bitmap_buffer, xfc->bitmap_size, 16); - - if (!xfc->bitmap_buffer) - { - xf_unlock_x11(xfc, FALSE); - return FALSE; - } - } - pSrcData = cmd->bitmapData; pDstData = xfc->bitmap_buffer; - freerdp_image_copy(pDstData, xfc->format, -1, 0, 0, - cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, xfc->palette); - + cmd->width, cmd->height, pSrcData, + PIXEL_FORMAT_BGRX32_VF, -1, 0, 0, xfc->palette); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) pDstData, cmd->width, cmd->height, xfc->scanline_pad, 0); - + (char*) pDstData, cmd->width, cmd->height, xfc->scanline_pad, 0); XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, - cmd->destLeft, cmd->destTop, - cmd->width, cmd->height); + cmd->destLeft, cmd->destTop, + cmd->width, cmd->height); XFree(image); - - ret = xf_gdi_surface_update_frame(xfc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height); - + ret = xf_gdi_surface_update_frame(xfc, cmd->destLeft, cmd->destTop, cmd->width, + cmd->height); XSetClipMask(xfc->display, xfc->gc, None); } else @@ -1341,10 +1224,8 @@ BOOL xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) void xf_gdi_register_update_callbacks(rdpUpdate* update) { rdpPrimaryUpdate* primary = update->primary; - update->Palette = xf_gdi_palette_update; update->SetBounds = xf_gdi_set_bounds; - primary->DstBlt = xf_gdi_dstblt; primary->PatBlt = xf_gdi_patblt; primary->ScrBlt = xf_gdi_scrblt; @@ -1367,10 +1248,8 @@ void xf_gdi_register_update_callbacks(rdpUpdate* update) primary->PolygonCB = xf_gdi_polygon_cb; primary->EllipseSC = xf_gdi_ellipse_sc; primary->EllipseCB = xf_gdi_ellipse_cb; - update->SurfaceBits = xf_gdi_surface_bits; update->SurfaceFrameMarker = xf_gdi_surface_frame_marker; - update->altsec->FrameMarker = xf_gdi_frame_marker; } diff --git a/client/X11/xf_gdi.h b/client/X11/xf_gdi.h index 5467d89e0..f2d779488 100644 --- a/client/X11/xf_gdi.h +++ b/client/X11/xf_gdi.h @@ -3,6 +3,8 @@ * X11 GDI * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +28,7 @@ #include "xfreerdp.h" void xf_gdi_register_update_callbacks(rdpUpdate* update); -BOOL xf_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate); +BOOL xf_gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate); UINT32 xf_convert_rdp_order_color(xfContext* xfc, UINT32 color); #endif /* __XF_GDI_H */ diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 0bec6d037..55c8fb537 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -3,6 +3,8 @@ * X11 Graphics Pipeline * * Copyright 2014 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,86 +28,45 @@ #define TAG CLIENT_TAG("x11") -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* resetGraphics) -{ - int index; - UINT16 count; - xfGfxSurface* surface; - UINT16* pSurfaceIds = NULL; - xfContext* xfc = (xfContext*) context->custom; - - context->GetSurfaceIds(context, &pSurfaceIds, &count); - - for (index = 0; index < count; index++) - { - surface = (xfGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]); - - if (!surface || !surface->outputMapped) - continue; - - if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL, - surface->width, surface->height)) - { - free(pSurfaceIds); - return ERROR_INTERNAL_ERROR; - } - - region16_clear(&surface->invalidRegion); - } - - free(pSurfaceIds); - - if (!freerdp_client_codecs_reset(xfc->codecs, FREERDP_CODEC_ALL, - xfc->settings->DesktopWidth, - xfc->settings->DesktopHeight)) - return ERROR_INTERNAL_ERROR; - - xfc->graphicsReset = TRUE; - - return CHANNEL_RC_OK; -} - -static int xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) +static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) { UINT16 width, height; UINT32 surfaceX, surfaceY; RECTANGLE_16 surfaceRect; const RECTANGLE_16* extents; - surfaceX = surface->outputOriginX; - surfaceY = surface->outputOriginY; + surfaceX = surface->gdi.outputOriginX; + surfaceY = surface->gdi.outputOriginY; surfaceRect.left = surfaceX; surfaceRect.top = surfaceY; - surfaceRect.right = surfaceX + surface->width; - surfaceRect.bottom = surfaceY + surface->height; + surfaceRect.right = surfaceX + surface->gdi.width; + surfaceRect.bottom = surfaceY + surface->gdi.height; XSetClipMask(xfc->display, xfc->gc, None); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - if (!region16_is_empty(&surface->invalidRegion)) + if (!region16_is_empty(&surface->gdi.invalidRegion)) { - extents = region16_extents(&surface->invalidRegion); + extents = region16_extents(&surface->gdi.invalidRegion); width = extents->right - extents->left; height = extents->bottom - extents->top; - if (width > surface->width) - width = surface->width; + if (width > surface->gdi.width) + width = surface->gdi.width; - if (height > surface->height) - height = surface->height; + if (height > surface->gdi.height) + height = surface->gdi.height; if (surface->stage) { - freerdp_image_copy(surface->stage, xfc->format, surface->stageStep, 0, 0, - surface->width, surface->height, surface->data, surface->format, surface->scanline, 0, 0, NULL); + freerdp_image_copy(surface->stage, xfc->format, + surface->stageScanline, 0, 0, + surface->gdi.width, surface->gdi.height, + surface->gdi.data, surface->gdi.format, + surface->gdi.scanline, 0, 0, NULL); } #ifdef WITH_XRENDER @@ -119,30 +80,37 @@ static int xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) else #endif { - XPutImage(xfc->display, xfc->drawable, xfc->gc, surface->image, - extents->left, extents->top, extents->left + surfaceX, extents->top + surfaceY, width, height); + XPutImage(xfc->display, xfc->drawable, xfc->gc, + surface->image, extents->left, extents->top, + extents->left + surfaceX, extents->top + surfaceY, + width, height); } } - region16_clear(&surface->invalidRegion); + region16_clear(&surface->gdi.invalidRegion); XSetClipMask(xfc->display, xfc->gc, None); XSync(xfc->display, False); - return 1; + return 0; } -static int xf_UpdateSurfaces(xfContext* xfc) +static UINT xf_UpdateSurfaces(RdpgfxClientContext* context) { UINT16 count; - int index; - int status = 1; + UINT32 index; + UINT status = CHANNEL_RC_OK; xfGfxSurface* surface; UINT16* pSurfaceIds = NULL; - RdpgfxClientContext* context = xfc->gfx; + rdpContext* ctx = (rdpContext*)context->custom; + xfContext* xfc = (xfContext*) ctx; + rdpGdi* gdi = ctx->instance->context->gdi; - if (!xfc->graphicsReset) - return 1; + if (!gdi) + return status; + + if (!gdi->graphicsReset) + return status; context->GetSurfaceIds(context, &pSurfaceIds, &count); @@ -150,12 +118,12 @@ static int xf_UpdateSurfaces(xfContext* xfc) { surface = (xfGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]); - if (!surface || !surface->outputMapped) + if (!surface || !surface->gdi.outputMapped) continue; status = xf_OutputUpdate(xfc, surface); - if (status < 0) + if (status != 0) break; } @@ -164,11 +132,12 @@ static int xf_UpdateSurfaces(xfContext* xfc) return status; } -int xf_OutputExpose(xfContext* xfc, int x, int y, int width, int height) +UINT xf_OutputExpose(xfContext* xfc, UINT32 x, UINT32 y, + UINT32 width, UINT32 height) { UINT16 count; - int index; - int status = 1; + UINT32 index; + UINT status = CHANNEL_RC_OK; xfGfxSurface* surface; RECTANGLE_16 invalidRect; RECTANGLE_16 surfaceRect; @@ -187,13 +156,13 @@ int xf_OutputExpose(xfContext* xfc, int x, int y, int width, int height) { surface = (xfGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]); - if (!surface || !surface->outputMapped) + if (!surface || !surface->gdi.outputMapped) continue; - surfaceRect.left = surface->outputOriginX; - surfaceRect.top = surface->outputOriginY; - surfaceRect.right = surface->outputOriginX + surface->width; - surfaceRect.bottom = surface->outputOriginY + surface->height; + surfaceRect.left = surface->gdi.outputOriginX; + surfaceRect.top = surface->gdi.outputOriginY; + surfaceRect.right = surface->gdi.outputOriginX + surface->gdi.width; + surfaceRect.bottom = surface->gdi.outputOriginY + surface->gdi.height; if (rectangles_intersection(&invalidRect, &surfaceRect, &intersection)) { @@ -203,13 +172,16 @@ int xf_OutputExpose(xfContext* xfc, int x, int y, int width, int height) intersection.right -= surfaceRect.left; intersection.bottom -= surfaceRect.top; - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &intersection); + region16_union_rect(&surface->gdi.invalidRegion, + &surface->gdi.invalidRegion, + &intersection); } } free(pSurfaceIds); - if (xf_UpdateSurfaces(xfc) < 0) + IFCALLRET(context->UpdateSurfaces, status, context); + if (status < 0) status = -1; return status; @@ -220,633 +192,83 @@ int xf_OutputExpose(xfContext* xfc, int x, int y, int width, int height) * * @return 0 on success, otherwise a Win32 error code */ -static UINT xf_StartFrame(RdpgfxClientContext* context, RDPGFX_START_FRAME_PDU* startFrame) -{ - xfContext* xfc = (xfContext*) context->custom; - - xfc->inGfxFrame = TRUE; - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_EndFrame(RdpgfxClientContext* context, RDPGFX_END_FRAME_PDU* endFrame) -{ - xfContext* xfc = (xfContext*) context->custom; - - xf_UpdateSurfaces(xfc); - - xfc->inGfxFrame = FALSE; - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_Uncompressed(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - xfGfxSurface* surface; - RECTANGLE_16 invalidRect; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - freerdp_image_copy(surface->data, surface->format, surface->scanline, cmd->left, cmd->top, - cmd->width, cmd->height, cmd->data, PIXEL_FORMAT_XRGB32, -1, 0, 0, NULL); - - invalidRect.left = cmd->left; - invalidRect.top = cmd->top; - invalidRect.right = cmd->right; - invalidRect.bottom = cmd->bottom; - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect); - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_RemoteFX(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - int j; - UINT16 i; - RFX_RECT* rect; - RFX_TILE* tile; - int nXDst, nYDst; - int nWidth, nHeight; - int nbUpdateRects; - RFX_MESSAGE* message; - xfGfxSurface* surface; - REGION16 updateRegion; - RECTANGLE_16 updateRect; - RECTANGLE_16* updateRects; - REGION16 clippingRects; - RECTANGLE_16 clippingRect; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_REMOTEFX, - surface->width, surface->height)) - return ERROR_INTERNAL_ERROR; - - if (!(message = rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length))) - { - WLog_ERR(TAG, "Failed to process RemoteFX message"); - return ERROR_INTERNAL_ERROR; - } - - region16_init(&clippingRects); - - for (i = 0; i < message->numRects; i++) - { - rect = &(message->rects[i]); - - clippingRect.left = cmd->left + rect->x; - clippingRect.top = cmd->top + rect->y; - clippingRect.right = clippingRect.left + rect->width; - clippingRect.bottom = clippingRect.top + rect->height; - - region16_union_rect(&clippingRects, &clippingRects, &clippingRect); - } - - for (i = 0; i < message->numTiles; i++) - { - tile = message->tiles[i]; - - updateRect.left = cmd->left + tile->x; - updateRect.top = cmd->top + tile->y; - updateRect.right = updateRect.left + 64; - updateRect.bottom = updateRect.top + 64; - - region16_init(&updateRegion); - region16_intersect_rect(&updateRegion, &clippingRects, &updateRect); - updateRects = (RECTANGLE_16*) region16_rects(&updateRegion, &nbUpdateRects); - - for (j = 0; j < nbUpdateRects; j++) - { - nXDst = updateRects[j].left; - nYDst = updateRects[j].top; - nWidth = updateRects[j].right - updateRects[j].left; - nHeight = updateRects[j].bottom - updateRects[j].top; - - freerdp_image_copy(surface->data, surface->format, surface->scanline, - nXDst, nYDst, nWidth, nHeight, - tile->data, PIXEL_FORMAT_XRGB32, 64 * 4, 0, 0, NULL); - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &updateRects[j]); - } - - region16_uninit(&updateRegion); - } - - rfx_message_free(surface->codecs->rfx, message); - - region16_uninit(&clippingRects); - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_ClearCodec(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - int status; - BYTE* DstData = NULL; - xfGfxSurface* surface; - RECTANGLE_16 invalidRect; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - if (!freerdp_client_codecs_prepare(xfc->codecs, FREERDP_CODEC_CLEARCODEC, - xfc->settings->DesktopWidth, - xfc->settings->DesktopHeight)) - return ERROR_INTERNAL_ERROR; - - DstData = surface->data; - - status = clear_decompress(xfc->codecs->clear, cmd->data, cmd->length, &DstData, - surface->format, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height); - - if (status < 0) - { - WLog_ERR(TAG, "clear_decompress failure: %d", status); - return ERROR_INTERNAL_ERROR; - } - - invalidRect.left = cmd->left; - invalidRect.top = cmd->top; - invalidRect.right = cmd->right; - invalidRect.bottom = cmd->bottom; - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect); - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_Planar(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - int status; - BYTE* DstData = NULL; - xfGfxSurface* surface; - RECTANGLE_16 invalidRect; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PLANAR, - surface->width, surface->height)) - return ERROR_INTERNAL_ERROR; - - DstData = surface->data; - - status = planar_decompress(surface->codecs->planar, cmd->data, cmd->length, &DstData, - surface->format, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height, FALSE); - - invalidRect.left = cmd->left; - invalidRect.top = cmd->top; - invalidRect.right = cmd->right; - invalidRect.bottom = cmd->bottom; - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect); - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_AVC420(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - int status; - UINT32 i; - xfGfxSurface* surface; - RDPGFX_H264_METABLOCK* meta; - RDPGFX_AVC420_BITMAP_STREAM* bs; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_AVC420, - surface->width, surface->height)) - return ERROR_INTERNAL_ERROR; - - bs = (RDPGFX_AVC420_BITMAP_STREAM*) cmd->extra; - - if (!bs) - return ERROR_INTERNAL_ERROR; - - meta = &(bs->meta); - - status = avc420_decompress(surface->codecs->h264, bs->data, bs->length, - surface->data, surface->format, - surface->scanline , surface->width, - surface->height, meta->regionRects, - meta->numRegionRects); - - if (status < 0) - { - WLog_WARN(TAG, "avc420_decompress failure: %d, ignoring update.", status); - return CHANNEL_RC_OK; - } - - for (i = 0; i < meta->numRegionRects; i++) - { - region16_union_rect(&surface->invalidRegion, - &surface->invalidRegion, - &(meta->regionRects[i])); - } - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_AVC444(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - int status; - UINT32 i; - xfGfxSurface* surface; - RDPGFX_AVC444_BITMAP_STREAM* bs; - RDPGFX_AVC420_BITMAP_STREAM* avc1; - RDPGFX_AVC420_BITMAP_STREAM* avc2; - RDPGFX_H264_METABLOCK* meta1; - RDPGFX_H264_METABLOCK* meta2; - RECTANGLE_16* regionRects = NULL; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_AVC444, - surface->width, surface->height)) - return ERROR_INTERNAL_ERROR; - - bs = (RDPGFX_AVC444_BITMAP_STREAM*) cmd->extra; - - if (!bs) - return ERROR_INTERNAL_ERROR; - - avc1 = &bs->bitstream[0]; - avc2 = &bs->bitstream[1]; - meta1 = &avc1->meta; - meta2 = &avc2->meta; - - status = avc444_decompress(surface->codecs->h264, bs->LC, - meta1->regionRects, meta1->numRegionRects, - avc1->data, avc1->length, - meta2->regionRects, meta2->numRegionRects, - avc2->data, avc2->length, surface->data, - surface->format, surface->scanline, - surface->width, surface->height); - - if (status < 0) - { - WLog_WARN(TAG, "avc444_decompress failure: %d, ignoring update.", status); - return CHANNEL_RC_OK; - } - - for (i = 0; i < meta1->numRegionRects; i++) - { - region16_union_rect(&surface->invalidRegion, - &surface->invalidRegion, - &(meta1->regionRects[i])); - } - for (i = 0; i < meta2->numRegionRects; i++) - { - region16_union_rect(&surface->invalidRegion, - &surface->invalidRegion, - &(meta2->regionRects[i])); - } - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - free (regionRects); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_Alpha(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - int status = 0; - xfGfxSurface* surface; - RECTANGLE_16 invalidRect; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_ALPHACODEC, - surface->width, surface->height)) - return ERROR_INTERNAL_ERROR; - - WLog_DBG(TAG, "xf_SurfaceCommand_Alpha: status: %d", status); - /* fill with green for now to distinguish from the rest */ - - freerdp_image_fill(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline, - cmd->left, cmd->top, cmd->width, cmd->height, 0x00FF00); - - invalidRect.left = cmd->left; - invalidRect.top = cmd->top; - invalidRect.right = cmd->right; - invalidRect.bottom = cmd->bottom; - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect); - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand_Progressive(xfContext* xfc, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - int i, j; - int status; - BYTE* DstData; - RFX_RECT* rect; - int nXDst, nYDst; - int nXSrc, nYSrc; - int nWidth, nHeight; - int nbUpdateRects; - xfGfxSurface* surface; - REGION16 updateRegion; - RECTANGLE_16 updateRect; - RECTANGLE_16* updateRects; - REGION16 clippingRects; - RECTANGLE_16 clippingRect; - RFX_PROGRESSIVE_TILE* tile; - PROGRESSIVE_BLOCK_REGION* region; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PROGRESSIVE, - surface->width, surface->height)) - return ERROR_INTERNAL_ERROR; - - progressive_create_surface_context(surface->codecs->progressive, cmd->surfaceId, surface->width, surface->height); - - DstData = surface->data; - - status = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, &DstData, - surface->format, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height, cmd->surfaceId); - - if (status < 0) - { - WLog_ERR(TAG, "progressive_decompress failure: %d", status); - return ERROR_INTERNAL_ERROR; - } - - region = &(surface->codecs->progressive->region); - - region16_init(&clippingRects); - - for (i = 0; i < region->numRects; i++) - { - rect = &(region->rects[i]); - - clippingRect.left = cmd->left + rect->x; - clippingRect.top = cmd->top + rect->y; - clippingRect.right = clippingRect.left + rect->width; - clippingRect.bottom = clippingRect.top + rect->height; - - region16_union_rect(&clippingRects, &clippingRects, &clippingRect); - } - - for (i = 0; i < region->numTiles; i++) - { - tile = region->tiles[i]; - - updateRect.left = cmd->left + tile->x; - updateRect.top = cmd->top + tile->y; - updateRect.right = updateRect.left + 64; - updateRect.bottom = updateRect.top + 64; - - region16_init(&updateRegion); - region16_intersect_rect(&updateRegion, &clippingRects, &updateRect); - updateRects = (RECTANGLE_16*) region16_rects(&updateRegion, &nbUpdateRects); - - for (j = 0; j < nbUpdateRects; j++) - { - nXDst = updateRects[j].left; - nYDst = updateRects[j].top; - nWidth = updateRects[j].right - updateRects[j].left; - nHeight = updateRects[j].bottom - updateRects[j].top; - - nXSrc = nXDst - (cmd->left + tile->x); - nYSrc = nYDst - (cmd->top + tile->y); - - freerdp_image_copy(surface->data, PIXEL_FORMAT_XRGB32, - surface->scanline, nXDst, nYDst, nWidth, nHeight, - tile->data, PIXEL_FORMAT_XRGB32, 64 * 4, nXSrc, nYSrc, NULL); - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &updateRects[j]); - } - - region16_uninit(&updateRegion); - } - - region16_uninit(&clippingRects); - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceCommand(RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd) -{ - UINT status = CHANNEL_RC_OK; - xfContext* xfc = (xfContext*) context->custom; - - switch (cmd->codecId) - { - case RDPGFX_CODECID_UNCOMPRESSED: - status = xf_SurfaceCommand_Uncompressed(xfc, context, cmd); - break; - - case RDPGFX_CODECID_CAVIDEO: - status = xf_SurfaceCommand_RemoteFX(xfc, context, cmd); - break; - - case RDPGFX_CODECID_CLEARCODEC: - status = xf_SurfaceCommand_ClearCodec(xfc, context, cmd); - break; - - case RDPGFX_CODECID_PLANAR: - status = xf_SurfaceCommand_Planar(xfc, context, cmd); - break; - - case RDPGFX_CODECID_AVC420: - status = xf_SurfaceCommand_AVC420(xfc, context, cmd); - break; - - case RDPGFX_CODECID_AVC444: - status = xf_SurfaceCommand_AVC444(xfc, context, cmd); - break; - - case RDPGFX_CODECID_ALPHA: - status = xf_SurfaceCommand_Alpha(xfc, context, cmd); - break; - - case RDPGFX_CODECID_CAPROGRESSIVE: - status = xf_SurfaceCommand_Progressive(xfc, context, cmd); - break; - - case RDPGFX_CODECID_CAPROGRESSIVE_V2: - WLog_WARN(TAG, "SurfaceCommand %08X not implemented", cmd->codecId); - break; - - default: - WLog_WARN(TAG, "Invalid SurfaceCommand %08X", cmd->codecId); - break; - } - - return status; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_DeleteEncodingContext(RdpgfxClientContext* context, RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext) -{ - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* createSurface) +static UINT xf_CreateSurface(RdpgfxClientContext* context, + const RDPGFX_CREATE_SURFACE_PDU* createSurface) { size_t size; - UINT32 bytesPerPixel; xfGfxSurface* surface; - xfContext* xfc = (xfContext*) context->custom; + rdpContext* ctx = (rdpContext*)context->custom; + xfContext* xfc = (xfContext*) ctx; surface = (xfGfxSurface*) calloc(1, sizeof(xfGfxSurface)); if (!surface) return CHANNEL_RC_NO_MEMORY; - surface->codecs = codecs_new((rdpContext*) xfc); + surface->gdi.codecs = codecs_new((rdpContext*) xfc); - if (!surface->codecs) + if (!surface->gdi.codecs) { free (surface); return CHANNEL_RC_NO_MEMORY; } - surface->surfaceId = createSurface->surfaceId; - surface->width = (UINT32) createSurface->width; - surface->height = (UINT32) createSurface->height; - surface->alpha = (createSurface->pixelFormat == PIXEL_FORMAT_ARGB_8888) ? TRUE : FALSE; - surface->format = PIXEL_FORMAT_XRGB32; + if (!freerdp_client_codecs_reset(surface->gdi.codecs, FREERDP_CODEC_ALL, + createSurface->width, createSurface->height)) + { + free (surface); + return ERROR_INTERNAL_ERROR; + } - surface->scanline = surface->width * 4; - surface->scanline += (surface->scanline % (xfc->scanline_pad / 8)); + surface->gdi.surfaceId = createSurface->surfaceId; + surface->gdi.width = (UINT32) createSurface->width; + surface->gdi.height = (UINT32) createSurface->height; + switch(createSurface->pixelFormat) + { + case PIXEL_FORMAT_ARGB_8888: + surface->gdi.format = PIXEL_FORMAT_BGRA32; + break; + case PIXEL_FORMAT_XRGB_8888: + surface->gdi.format = PIXEL_FORMAT_BGRX32; + break; + default: + free (surface); + return ERROR_INTERNAL_ERROR; + } - size = surface->scanline * surface->height; - surface->data = (BYTE*) _aligned_malloc(size, 16); + surface->gdi.scanline = surface->gdi.width * GetBytesPerPixel(surface->gdi.format); + surface->gdi.scanline += (xfc->scanline_pad / 8) - (surface->gdi.scanline % (xfc->scanline_pad / 8)); - if (!surface->data) + size = surface->gdi.scanline * surface->gdi.height; + surface->gdi.data = (BYTE*) _aligned_malloc(size, 16); + + if (!surface->gdi.data) { free(surface); return CHANNEL_RC_NO_MEMORY; } - ZeroMemory(surface->data, size); - - if ((xfc->depth == 24) || (xfc->depth == 32)) + ZeroMemory(surface->gdi.data, size); + if (xfc->format == surface->gdi.format) { surface->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) surface->data, surface->width, surface->height, xfc->scanline_pad, surface->scanline); + (char*) surface->gdi.data, surface->gdi.width, surface->gdi.height, xfc->scanline_pad, surface->gdi.scanline); } else { - bytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(xfc->format) / 8); - surface->stageStep = surface->width * bytesPerPixel; - surface->stageStep += (surface->stageStep % (xfc->scanline_pad / 8)); - size = surface->stageStep * surface->height; + UINT32 width = surface->gdi.width; + UINT32 bytes = GetBytesPerPixel(xfc->format); + + surface->stageScanline = width * bytes; + surface->stageScanline += (xfc->scanline_pad / 8) - (surface->stageScanline % (xfc->scanline_pad / 8)); + + size = surface->stageScanline * surface->gdi.height; surface->stage = (BYTE*) _aligned_malloc(size, 16); if (!surface->stage) { - free(surface->data); + free(surface->gdi.data); free(surface); return CHANNEL_RC_NO_MEMORY; } @@ -854,14 +276,14 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE ZeroMemory(surface->stage, size); surface->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) surface->stage, surface->width, surface->height, xfc->scanline_pad, surface->stageStep); + (char*) surface->stage, surface->gdi.width, surface->gdi.height, xfc->scanline_pad, surface->gdi.scanline); } - surface->outputMapped = FALSE; + surface->gdi.outputMapped = FALSE; - region16_init(&surface->invalidRegion); + region16_init(&surface->gdi.invalidRegion); - context->SetSurfaceData(context, surface->surfaceId, (void*) surface); + context->SetSurfaceData(context, surface->gdi.surfaceId, (void*) surface); return CHANNEL_RC_OK; } @@ -871,7 +293,8 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE * * @return 0 on success, otherwise a Win32 error code */ -static UINT xf_DeleteSurface(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE_PDU* deleteSurface) +static UINT xf_DeleteSurface(RdpgfxClientContext* context, + const RDPGFX_DELETE_SURFACE_PDU* deleteSurface) { rdpCodecs* codecs = NULL; xfGfxSurface* surface = NULL; @@ -881,10 +304,10 @@ static UINT xf_DeleteSurface(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE if (surface) { XFree(surface->image); - _aligned_free(surface->data); + _aligned_free(surface->gdi.data); _aligned_free(surface->stage); - region16_uninit(&surface->invalidRegion); - codecs = surface->codecs; + region16_uninit(&surface->gdi.invalidRegion); + codecs = surface->gdi.codecs; free(surface); } @@ -898,306 +321,22 @@ static UINT xf_DeleteSurface(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE return CHANNEL_RC_OK; } -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SolidFill(RdpgfxClientContext* context, RDPGFX_SOLID_FILL_PDU* solidFill) -{ - UINT16 index; - UINT32 color; - BYTE a, r, g, b; - int nWidth, nHeight; - RECTANGLE_16* rect; - xfGfxSurface* surface; - RECTANGLE_16 invalidRect; - xfContext* xfc = (xfContext*) context->custom; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, solidFill->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - b = solidFill->fillPixel.B; - g = solidFill->fillPixel.G; - r = solidFill->fillPixel.R; - a = solidFill->fillPixel.XA; - - color = ARGB32(a, r, g, b); - - for (index = 0; index < solidFill->fillRectCount; index++) - { - rect = &(solidFill->fillRects[index]); - - nWidth = rect->right - rect->left; - nHeight = rect->bottom - rect->top; - - invalidRect.left = rect->left; - invalidRect.top = rect->top; - invalidRect.right = rect->right; - invalidRect.bottom = rect->bottom; - - freerdp_image_fill(surface->data, surface->format, surface->scanline, - rect->left, rect->top, nWidth, nHeight, color); - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect); - } - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceToSurface(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface) -{ - UINT16 index; - BOOL sameSurface; - int nWidth, nHeight; - RECTANGLE_16* rectSrc; - RDPGFX_POINT16* destPt; - RECTANGLE_16 invalidRect; - xfGfxSurface* surfaceSrc; - xfGfxSurface* surfaceDst; - xfContext* xfc = (xfContext*) context->custom; - - rectSrc = &(surfaceToSurface->rectSrc); - destPt = &surfaceToSurface->destPts[0]; - - surfaceSrc = (xfGfxSurface*) context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc); - - sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest) ? TRUE : FALSE; - - if (!sameSurface) - surfaceDst = (xfGfxSurface*) context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest); - else - surfaceDst = surfaceSrc; - - if (!surfaceSrc || !surfaceDst) - return ERROR_INTERNAL_ERROR; - - nWidth = rectSrc->right - rectSrc->left; - nHeight = rectSrc->bottom - rectSrc->top; - - for (index = 0; index < surfaceToSurface->destPtsCount; index++) - { - destPt = &surfaceToSurface->destPts[index]; - - if (sameSurface) - { - freerdp_image_move(surfaceDst->data, surfaceDst->format, surfaceDst->scanline, - destPt->x, destPt->y, nWidth, nHeight, rectSrc->left, rectSrc->top); - } - else - { - freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline, - destPt->x, destPt->y, nWidth, nHeight, surfaceSrc->data, surfaceSrc->format, - surfaceSrc->scanline, rectSrc->left, rectSrc->top, NULL); - } - - invalidRect.left = destPt->x; - invalidRect.top = destPt->y; - invalidRect.right = destPt->x + rectSrc->right; - invalidRect.bottom = destPt->y + rectSrc->bottom; - - region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion, &invalidRect); - } - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_SurfaceToCache(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache) -{ - size_t size; - RECTANGLE_16* rect; - xfGfxSurface* surface; - xfGfxCacheEntry* cacheEntry; - xfContext* xfc = (xfContext*) context->custom; - - rect = &(surfaceToCache->rectSrc); - - surface = (xfGfxSurface*) context->GetSurfaceData(context, surfaceToCache->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - cacheEntry = (xfGfxCacheEntry*) calloc(1, sizeof(xfGfxCacheEntry)); - - if (!cacheEntry) - return CHANNEL_RC_NO_MEMORY; - - cacheEntry->width = (UINT32) (rect->right - rect->left); - cacheEntry->height = (UINT32) (rect->bottom - rect->top); - cacheEntry->alpha = surface->alpha; - cacheEntry->format = surface->format; - - cacheEntry->scanline = cacheEntry->width * 4; - cacheEntry->scanline += (cacheEntry->scanline % (xfc->scanline_pad / 8)); - - size = cacheEntry->scanline * cacheEntry->height; - cacheEntry->data = (BYTE*) _aligned_malloc(size, 16); - - if (!cacheEntry->data) - { - free(cacheEntry); - return CHANNEL_RC_NO_MEMORY; - } - - ZeroMemory(cacheEntry->data, size); - - freerdp_image_copy(cacheEntry->data, cacheEntry->format, cacheEntry->scanline, - 0, 0, cacheEntry->width, cacheEntry->height, surface->data, - surface->format, surface->scanline, rect->left, rect->top, NULL); - - context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (void*) cacheEntry); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_CacheToSurface(RdpgfxClientContext* context, RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface) -{ - UINT16 index; - RDPGFX_POINT16* destPt; - xfGfxSurface* surface; - xfGfxCacheEntry* cacheEntry; - RECTANGLE_16 invalidRect; - xfContext* xfc = (xfContext*) context->custom; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, cacheToSurface->surfaceId); - cacheEntry = (xfGfxCacheEntry*) context->GetCacheSlotData(context, cacheToSurface->cacheSlot); - - if (!surface || !cacheEntry) - return ERROR_INTERNAL_ERROR; - - for (index = 0; index < cacheToSurface->destPtsCount; index++) - { - destPt = &cacheToSurface->destPts[index]; - - freerdp_image_copy(surface->data, surface->format, surface->scanline, - destPt->x, destPt->y, cacheEntry->width, cacheEntry->height, - cacheEntry->data, cacheEntry->format, cacheEntry->scanline, 0, 0, NULL); - - invalidRect.left = destPt->x; - invalidRect.top = destPt->y; - invalidRect.right = destPt->x + cacheEntry->width - 1; - invalidRect.bottom = destPt->y + cacheEntry->height - 1; - - region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect); - } - - if (!xfc->inGfxFrame) - xf_UpdateSurfaces(xfc); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_CacheImportReply(RdpgfxClientContext* context, RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply) -{ - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_EvictCacheEntry(RdpgfxClientContext* context, RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry) -{ - xfGfxCacheEntry* cacheEntry; - - cacheEntry = (xfGfxCacheEntry*) context->GetCacheSlotData(context, evictCacheEntry->cacheSlot); - - if (cacheEntry) - { - _aligned_free(cacheEntry->data); - free(cacheEntry); - } - - context->SetCacheSlotData(context, evictCacheEntry->cacheSlot, NULL); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_MapSurfaceToOutput(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput) -{ - xfGfxSurface* surface; - - surface = (xfGfxSurface*) context->GetSurfaceData(context, surfaceToOutput->surfaceId); - - if (!surface) - return ERROR_INTERNAL_ERROR; - - surface->outputMapped = TRUE; - surface->outputOriginX = surfaceToOutput->outputOriginX; - surface->outputOriginY = surfaceToOutput->outputOriginY; - - region16_clear(&surface->invalidRegion); - - return CHANNEL_RC_OK; -} - -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT xf_MapSurfaceToWindow(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow) -{ - return CHANNEL_RC_OK; -} - void xf_graphics_pipeline_init(xfContext* xfc, RdpgfxClientContext* gfx) { - xfc->gfx = gfx; - gfx->custom = (void*) xfc; + rdpGdi* gdi = xfc->context.gdi; - gfx->ResetGraphics = xf_ResetGraphics; - gfx->StartFrame = xf_StartFrame; - gfx->EndFrame = xf_EndFrame; - gfx->SurfaceCommand = xf_SurfaceCommand; - gfx->DeleteEncodingContext = xf_DeleteEncodingContext; + xfc->gfx = gfx; + gfx->custom = xfc->instance->context; + + gdi_graphics_pipeline_init(gdi, gfx); + + gfx->UpdateSurfaces = xf_UpdateSurfaces; gfx->CreateSurface = xf_CreateSurface; gfx->DeleteSurface = xf_DeleteSurface; - gfx->SolidFill = xf_SolidFill; - gfx->SurfaceToSurface = xf_SurfaceToSurface; - gfx->SurfaceToCache = xf_SurfaceToCache; - gfx->CacheToSurface = xf_CacheToSurface; - gfx->CacheImportReply = xf_CacheImportReply; - gfx->EvictCacheEntry = xf_EvictCacheEntry; - gfx->MapSurfaceToOutput = xf_MapSurfaceToOutput; - gfx->MapSurfaceToWindow = xf_MapSurfaceToWindow; } void xf_graphics_pipeline_uninit(xfContext* xfc, RdpgfxClientContext* gfx) { - + rdpGdi* gdi = xfc->context.gdi; + gdi_graphics_pipeline_uninit(gdi, gfx); } diff --git a/client/X11/xf_gfx.h b/client/X11/xf_gfx.h index 423b3357e..c10c287ea 100644 --- a/client/X11/xf_gfx.h +++ b/client/X11/xf_gfx.h @@ -3,6 +3,8 @@ * X11 Graphics Pipeline * * Copyright 2014 Marc-Andre Moreau + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,21 +29,10 @@ struct xf_gfx_surface { - UINT16 surfaceId; - rdpCodecs* codecs; - UINT32 width; - UINT32 height; - BOOL alpha; - BYTE* data; + gdiGfxSurface gdi; BYTE* stage; + UINT32 stageScanline; XImage* image; - int scanline; - int stageStep; - UINT32 format; - BOOL outputMapped; - UINT32 outputOriginX; - UINT32 outputOriginY; - REGION16 invalidRegion; }; typedef struct xf_gfx_surface xfGfxSurface; @@ -50,14 +41,14 @@ struct xf_gfx_cache_entry UINT64 cacheKey; UINT32 width; UINT32 height; - BOOL alpha; BYTE* data; - int scanline; + UINT32 scanline; UINT32 format; }; typedef struct xf_gfx_cache_entry xfGfxCacheEntry; -int xf_OutputExpose(xfContext* xfc, int x, int y, int width, int height); +UINT xf_OutputExpose(xfContext* xfc, UINT32 x, UINT32 y, + UINT32 width, UINT32 height); void xf_graphics_pipeline_init(xfContext* xfc, RdpgfxClientContext* gfx); void xf_graphics_pipeline_uninit(xfContext* xfc, RdpgfxClientContext* gfx); diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index 7536ecb67..8f1d8fe4c 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -3,6 +3,8 @@ * X11 Graphical Objects * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,8 +43,7 @@ #define TAG CLIENT_TAG("x11") /* Bitmap Class */ - -BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) +static BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) { int depth; BYTE* data; @@ -73,7 +74,9 @@ BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) SrcFormat = gdi_get_pixel_format(bitmap->bpp, TRUE); freerdp_image_copy(data, xfc->format, -1, 0, 0, - bitmap->width, bitmap->height, bitmap->data, SrcFormat, -1, 0, 0, xfc->palette); + bitmap->width, bitmap->height, + bitmap->data, SrcFormat, + -1, 0, 0, xfc->palette); _aligned_free(bitmap->data); bitmap->data = data; @@ -82,7 +85,7 @@ BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) } image = XCreateImage(xfc->display, xfc->visual, xfc->depth, - ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height, xfc->scanline_pad, 0); + ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height, xfc->scanline_pad, 0); XPutImage(xfc->display, pixmap, xfc->gc, image, 0, 0, 0, 0, bitmap->width, bitmap->height); @@ -95,7 +98,7 @@ BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) return TRUE; } -void xf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap) +static void xf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap) { xfContext* xfc = (xfContext*) context; @@ -107,7 +110,7 @@ void xf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap) xf_unlock_x11(xfc, FALSE); } -BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) +static BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) { XImage* image; int width, height; @@ -122,10 +125,10 @@ BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) XSetFunction(xfc->display, xfc->gc, GXcopy); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, - ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height, xfc->scanline_pad, 0); + ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height, xfc->scanline_pad, 0); XPutImage(xfc->display, xfc->primary, xfc->gc, - image, 0, 0, bitmap->left, bitmap->top, width, height); + image, 0, 0, bitmap->left, bitmap->top, width, height); XFree(image); @@ -135,13 +138,13 @@ BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) return TRUE; } -BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, - BYTE* data, int width, int height, int bpp, int length, - BOOL compressed, int codecId) +static BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, + const BYTE* data, UINT32 width, UINT32 height, UINT32 bpp, UINT32 length, + BOOL compressed, UINT32 codecId) { int status; UINT16 size; - BYTE* pSrcData; + const BYTE* pSrcData; BYTE* pDstData; UINT32 SrcSize; UINT32 SrcFormat; @@ -168,8 +171,11 @@ BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, xfc->settings->DesktopHeight)) return FALSE; - status = interleaved_decompress(xfc->codecs->interleaved, pSrcData, SrcSize, bpp, - &pDstData, xfc->format, -1, 0, 0, width, height, xfc->palette); + status = interleaved_decompress(xfc->codecs->interleaved, + pSrcData, SrcSize, bpp, + pDstData, xfc->format, + -1, 0, 0, width, height, + xfc->palette); } else { @@ -179,7 +185,7 @@ BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, return FALSE; status = planar_decompress(xfc->codecs->planar, pSrcData, SrcSize, - &pDstData, xfc->format, -1, 0, 0, width, height, TRUE); + &pDstData, xfc->format, -1, 0, 0, width, height, TRUE); } if (status < 0) @@ -193,7 +199,8 @@ BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, SrcFormat = gdi_get_pixel_format(bpp, TRUE); status = freerdp_image_copy(pDstData, xfc->format, -1, 0, 0, - width, height, pSrcData, SrcFormat, -1, 0, 0, xfc->palette); + width, height, pSrcData, + SrcFormat, -1, 0, 0, xfc->palette); } bitmap->compressed = FALSE; @@ -202,7 +209,7 @@ BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, return TRUE; } -BOOL xf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) +static BOOL xf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) { xfContext* xfc = (xfContext*) context; @@ -218,8 +225,7 @@ BOOL xf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) } /* Pointer Class */ - -BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer) +static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer) { #ifdef WITH_XCURSOR XcursorImage ci; @@ -242,11 +248,11 @@ BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer) } if (freerdp_image_copy_from_pointer_data( - (BYTE*) ci.pixels, PIXEL_FORMAT_ARGB32, - pointer->width * 4, 0, 0, pointer->width, pointer->height, - pointer->xorMaskData, pointer->lengthXorMask, - pointer->andMaskData, pointer->lengthAndMask, - pointer->xorBpp, xfc->palette) < 0) + (BYTE*) ci.pixels, xfc->format, + pointer->width * 4, 0, 0, pointer->width, pointer->height, + pointer->xorMaskData, pointer->lengthXorMask, + pointer->andMaskData, pointer->lengthAndMask, + pointer->xorBpp, xfc->palette) < 0) { free(ci.pixels); xf_unlock_x11(xfc, FALSE); @@ -262,7 +268,7 @@ BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer) return TRUE; } -void xf_Pointer_Free(rdpContext* context, rdpPointer* pointer) +static void xf_Pointer_Free(rdpContext* context, rdpPointer* pointer) { #ifdef WITH_XCURSOR xfContext* xfc = (xfContext*) context; @@ -276,7 +282,8 @@ void xf_Pointer_Free(rdpContext* context, rdpPointer* pointer) #endif } -BOOL xf_Pointer_Set(rdpContext* context, rdpPointer* pointer) +static BOOL xf_Pointer_Set(rdpContext* context, + const rdpPointer* pointer) { #ifdef WITH_XCURSOR xfContext* xfc = (xfContext*) context; @@ -295,7 +302,7 @@ BOOL xf_Pointer_Set(rdpContext* context, rdpPointer* pointer) return TRUE; } -BOOL xf_Pointer_SetNull(rdpContext* context) +static BOOL xf_Pointer_SetNull(rdpContext* context) { #ifdef WITH_XCURSOR xfContext* xfc = (xfContext*) context; @@ -326,7 +333,7 @@ BOOL xf_Pointer_SetNull(rdpContext* context) return TRUE; } -BOOL xf_Pointer_SetDefault(rdpContext* context) +static BOOL xf_Pointer_SetDefault(rdpContext* context) { #ifdef WITH_XCURSOR xfContext* xfc = (xfContext*) context; @@ -343,7 +350,7 @@ BOOL xf_Pointer_SetDefault(rdpContext* context) return TRUE; } -BOOL xf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y) +static BOOL xf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y) { xfContext* xfc = (xfContext*) context; XWindowAttributes current; @@ -375,8 +382,7 @@ out: } /* Glyph Class */ - -BOOL xf_Glyph_New(rdpContext* context, rdpGlyph* glyph) +static BOOL xf_Glyph_New(rdpContext* context, rdpGlyph* glyph) { int scanline; XImage* image; @@ -392,7 +398,7 @@ BOOL xf_Glyph_New(rdpContext* context, rdpGlyph* glyph) xf_glyph->pixmap = XCreatePixmap(xfc->display, xfc->drawing, glyph->cx, glyph->cy, 1); image = XCreateImage(xfc->display, xfc->visual, 1, - ZPixmap, 0, (char*) glyph->aj, glyph->cx, glyph->cy, 8, scanline); + ZPixmap, 0, (char*) glyph->aj, glyph->cx, glyph->cy, 8, scanline); image->byte_order = MSBFirst; image->bitmap_bit_order = MSBFirst; @@ -405,7 +411,7 @@ BOOL xf_Glyph_New(rdpContext* context, rdpGlyph* glyph) return TRUE; } -void xf_Glyph_Free(rdpContext* context, rdpGlyph* glyph) +static void xf_Glyph_Free(rdpContext* context, rdpGlyph* glyph) { xfContext* xfc = (xfContext*) context; @@ -417,7 +423,7 @@ void xf_Glyph_Free(rdpContext* context, rdpGlyph* glyph) xf_unlock_x11(xfc, FALSE); } -BOOL xf_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y) +static BOOL xf_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, UINT32 x, UINT32 y) { xfGlyph* xf_glyph; xfContext* xfc = (xfContext*) context; @@ -435,7 +441,9 @@ BOOL xf_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y) return TRUE; } -BOOL xf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant) +static BOOL xf_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 bgcolor, + UINT32 fgcolor, BOOL fOpRedundant) { xfContext* xfc = (xfContext*) context; @@ -462,7 +470,9 @@ BOOL xf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height return TRUE; } -BOOL xf_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor) +static BOOL xf_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, + UINT32 bgcolor, UINT32 fgcolor) { xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 95c29a066..130fdf473 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -4,6 +4,8 @@ * * Copyright 2011 Marc-Andre Moreau * Copyright 2012 HP Development Company, LLC + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -590,7 +592,7 @@ void xf_SetWindowText(xfContext* xfc, xfAppWindow* appWindow, char* name) Atom utf8Str = xfc->UTF8_STRING; XChangeProperty(xfc->display, appWindow->handle, wm_Name, utf8Str, 8, - PropModeReplace, (unsigned char *)name, i); + PropModeReplace, (unsigned char *)name, i); } void xf_FixWindowCoordinates(xfContext* xfc, int* x, int* y, int* width, int* height) @@ -959,7 +961,8 @@ void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, UINT32 } -void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, int width, int height) +void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, + int width, int height) { int ax, ay; diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index b90ac095b..79ffca68a 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -3,6 +3,8 @@ * X11 Client * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +99,6 @@ struct xf_context rdpCodecs* codecs; GC gc; - int bpp; int xfds; int depth; int sessionWidth; @@ -135,15 +136,12 @@ struct xf_context HANDLE mutex; BOOL UseXThreads; BOOL cursorHidden; - BYTE* palette; - BYTE palette_hwgdi[256 * 4]; + UINT32* palette; + UINT32 palette_hwgdi[256]; HGDI_DC hdc; UINT32 bitmap_size; BYTE* bitmap_buffer; - BYTE* primary_buffer; - BOOL inGfxFrame; - BOOL graphicsReset; BOOL frame_begin; UINT16 frame_x1; diff --git a/include/freerdp/altsec.h b/include/freerdp/altsec.h index 84c71d880..879cf61ed 100644 --- a/include/freerdp/altsec.h +++ b/include/freerdp/altsec.h @@ -165,18 +165,30 @@ struct _DRAW_GDIPLUS_CACHE_END_ORDER }; typedef struct _DRAW_GDIPLUS_CACHE_END_ORDER DRAW_GDIPLUS_CACHE_END_ORDER; -typedef BOOL (*pCreateOffscreenBitmap)(rdpContext* context, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); -typedef BOOL (*pSwitchSurface)(rdpContext* context, SWITCH_SURFACE_ORDER* switch_surface); -typedef BOOL (*pCreateNineGridBitmap)(rdpContext* context, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap); -typedef BOOL (*pFrameMarker)(rdpContext* context, FRAME_MARKER_ORDER* frame_marker); -typedef BOOL (*pStreamBitmapFirst)(rdpContext* context, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first); -typedef BOOL (*pStreamBitmapNext)(rdpContext* context, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next); -typedef BOOL (*pDrawGdiPlusFirst)(rdpContext* context, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first); -typedef BOOL (*pDrawGdiPlusNext)(rdpContext* context, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next); -typedef BOOL (*pDrawGdiPlusEnd)(rdpContext* context, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end); -typedef BOOL (*pDrawGdiPlusCacheFirst)(rdpContext* context, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first); -typedef BOOL (*pDrawGdiPlusCacheNext)(rdpContext* context, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next); -typedef BOOL (*pDrawGdiPlusCacheEnd)(rdpContext* context, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end); +typedef BOOL (*pCreateOffscreenBitmap)(rdpContext* context, + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); +typedef BOOL (*pSwitchSurface)(rdpContext* context, + const SWITCH_SURFACE_ORDER* switch_surface); +typedef BOOL (*pCreateNineGridBitmap)(rdpContext* context, + const CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap); +typedef BOOL (*pFrameMarker)(rdpContext* context, + const FRAME_MARKER_ORDER* frame_marker); +typedef BOOL (*pStreamBitmapFirst)(rdpContext* context, + const STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first); +typedef BOOL (*pStreamBitmapNext)(rdpContext* context, + const STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next); +typedef BOOL (*pDrawGdiPlusFirst)(rdpContext* context, + const DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first); +typedef BOOL (*pDrawGdiPlusNext)(rdpContext* context, + const DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next); +typedef BOOL (*pDrawGdiPlusEnd)(rdpContext* context, + const DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end); +typedef BOOL (*pDrawGdiPlusCacheFirst)(rdpContext* context, + const DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first); +typedef BOOL (*pDrawGdiPlusCacheNext)(rdpContext* context, + const DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next); +typedef BOOL (*pDrawGdiPlusCacheEnd)(rdpContext* context, + const DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end); struct rdp_altsec_update { diff --git a/include/freerdp/cache/bitmap.h b/include/freerdp/cache/bitmap.h index 7883b4c51..3cf515895 100644 --- a/include/freerdp/cache/bitmap.h +++ b/include/freerdp/cache/bitmap.h @@ -64,9 +64,6 @@ struct rdp_bitmap_cache extern "C" { #endif -FREERDP_API rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index); -FREERDP_API void bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index, rdpBitmap* bitmap); - FREERDP_API void bitmap_cache_register_callbacks(rdpUpdate* update); FREERDP_API rdpBitmapCache* bitmap_cache_new(rdpSettings* settings); diff --git a/include/freerdp/cache/brush.h b/include/freerdp/cache/brush.h index 3c3131541..d710b3300 100644 --- a/include/freerdp/cache/brush.h +++ b/include/freerdp/cache/brush.h @@ -61,8 +61,10 @@ struct rdp_brush_cache extern "C" { #endif -FREERDP_API void* brush_cache_get(rdpBrushCache* brush, UINT32 index, UINT32* bpp); -FREERDP_API void brush_cache_put(rdpBrushCache* brush, UINT32 index, void* entry, UINT32 bpp); +FREERDP_API void* brush_cache_get(rdpBrushCache* brush, UINT32 index, + UINT32* bpp); +FREERDP_API void brush_cache_put(rdpBrushCache* brush, UINT32 index, + void* entry, UINT32 bpp); FREERDP_API void brush_cache_register_callbacks(rdpUpdate* update); diff --git a/include/freerdp/cache/glyph.h b/include/freerdp/cache/glyph.h index c46102803..4af0118b6 100644 --- a/include/freerdp/cache/glyph.h +++ b/include/freerdp/cache/glyph.h @@ -66,12 +66,6 @@ struct rdp_glyph_cache extern "C" { #endif -FREERDP_API rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index); -FREERDP_API void glyph_cache_put(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index, rdpGlyph* entry); - -FREERDP_API void* glyph_cache_fragment_get(rdpGlyphCache* glyph, UINT32 index, UINT32* count); -FREERDP_API void glyph_cache_fragment_put(rdpGlyphCache* glyph, UINT32 index, UINT32 count, void* entry); - FREERDP_API void glyph_cache_register_callbacks(rdpUpdate* update); FREERDP_API rdpGlyphCache* glyph_cache_new(rdpSettings* settings); diff --git a/include/freerdp/cache/nine_grid.h b/include/freerdp/cache/nine_grid.h index 3f5525bb4..2b85f978e 100644 --- a/include/freerdp/cache/nine_grid.h +++ b/include/freerdp/cache/nine_grid.h @@ -57,9 +57,6 @@ struct rdp_nine_grid_cache extern "C" { #endif -FREERDP_API void* nine_grid_cache_get(rdpNineGridCache* nine_grid, UINT32 index); -FREERDP_API void nine_grid_cache_put(rdpNineGridCache* nine_grid, UINT32 index, void* entry); - FREERDP_API void nine_grid_cache_register_callbacks(rdpUpdate* update); FREERDP_API rdpNineGridCache* nine_grid_cache_new(rdpSettings* settings); diff --git a/include/freerdp/cache/offscreen.h b/include/freerdp/cache/offscreen.h index 0ed319769..ab5e1e166 100644 --- a/include/freerdp/cache/offscreen.h +++ b/include/freerdp/cache/offscreen.h @@ -49,8 +49,6 @@ extern "C" { #endif FREERDP_API rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreen_cache, UINT32 index); -FREERDP_API void offscreen_cache_put(rdpOffscreenCache* offscreen_cache, UINT32 index, rdpBitmap* bitmap); -FREERDP_API void offscreen_cache_delete(rdpOffscreenCache* offscreen, UINT32 index); FREERDP_API void offscreen_cache_register_callbacks(rdpUpdate* update); diff --git a/include/freerdp/cache/palette.h b/include/freerdp/cache/palette.h index 80fa747b1..31aa93e28 100644 --- a/include/freerdp/cache/palette.h +++ b/include/freerdp/cache/palette.h @@ -51,9 +51,6 @@ struct rdp_palette_cache extern "C" { #endif -FREERDP_API void* palette_cache_get(rdpPaletteCache* palette, UINT32 index); -FREERDP_API void palette_cache_put(rdpPaletteCache* palette, UINT32 index, void* entry); - FREERDP_API void palette_cache_register_callbacks(rdpUpdate* update); FREERDP_API rdpPaletteCache* palette_cache_new(rdpSettings* settings); diff --git a/include/freerdp/cache/pointer.h b/include/freerdp/cache/pointer.h index 949c3f0e6..35fcbeefb 100644 --- a/include/freerdp/cache/pointer.h +++ b/include/freerdp/cache/pointer.h @@ -35,7 +35,7 @@ typedef struct rdp_pointer_cache rdpPointerCache; struct rdp_pointer_cache { UINT32 cacheSize; /* 0 */ - rdpPointer** entries; /* 1 */ + rdpPointer** entries; /* 1 */ /* internal */ @@ -47,9 +47,6 @@ struct rdp_pointer_cache extern "C" { #endif -FREERDP_API rdpPointer* pointer_cache_get(rdpPointerCache* pointer_cache, UINT32 index); -FREERDP_API void pointer_cache_put(rdpPointerCache* pointer_cache, UINT32 index, rdpPointer* pointer); - FREERDP_API void pointer_cache_register_callbacks(rdpUpdate* update); FREERDP_API rdpPointerCache* pointer_cache_new(rdpSettings* settings); diff --git a/include/freerdp/client/rdpgfx.h b/include/freerdp/client/rdpgfx.h index 7ffc5d636..d1c69b112 100644 --- a/include/freerdp/client/rdpgfx.h +++ b/include/freerdp/client/rdpgfx.h @@ -30,22 +30,38 @@ typedef struct _rdpgfx_client_context RdpgfxClientContext; -typedef UINT (*pcRdpgfxResetGraphics)(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* resetGraphics); -typedef UINT (*pcRdpgfxStartFrame)(RdpgfxClientContext* context, RDPGFX_START_FRAME_PDU* startFrame); -typedef UINT (*pcRdpgfxEndFrame)(RdpgfxClientContext* context, RDPGFX_END_FRAME_PDU* endFrame); -typedef UINT (*pcRdpgfxSurfaceCommand)(RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd); -typedef UINT (*pcRdpgfxDeleteEncodingContext)(RdpgfxClientContext* context, RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext); -typedef UINT (*pcRdpgfxCreateSurface)(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* createSurface); -typedef UINT (*pcRdpgfxDeleteSurface)(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE_PDU* deleteSurface); -typedef UINT (*pcRdpgfxSolidFill)(RdpgfxClientContext* context, RDPGFX_SOLID_FILL_PDU* solidFill); -typedef UINT (*pcRdpgfxSurfaceToSurface)(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface); -typedef UINT (*pcRdpgfxSurfaceToCache)(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache); -typedef UINT (*pcRdpgfxCacheToSurface)(RdpgfxClientContext* context, RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface); -typedef UINT (*pcRdpgfxCacheImportOffer)(RdpgfxClientContext* context, RDPGFX_CACHE_IMPORT_OFFER_PDU* cacheImportOffer); -typedef UINT (*pcRdpgfxCacheImportReply)(RdpgfxClientContext* context, RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply); -typedef UINT (*pcRdpgfxEvictCacheEntry)(RdpgfxClientContext* context, RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry); -typedef UINT (*pcRdpgfxMapSurfaceToOutput)(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput); -typedef UINT (*pcRdpgfxMapSurfaceToWindow)(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow); +typedef UINT (*pcRdpgfxResetGraphics)(RdpgfxClientContext* context, + const RDPGFX_RESET_GRAPHICS_PDU* resetGraphics); +typedef UINT (*pcRdpgfxStartFrame)(RdpgfxClientContext* context, + const RDPGFX_START_FRAME_PDU* startFrame); +typedef UINT (*pcRdpgfxEndFrame)(RdpgfxClientContext* context, + const RDPGFX_END_FRAME_PDU* endFrame); +typedef UINT (*pcRdpgfxSurfaceCommand)(RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd); +typedef UINT (*pcRdpgfxDeleteEncodingContext)(RdpgfxClientContext* context, + const RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext); +typedef UINT (*pcRdpgfxCreateSurface)(RdpgfxClientContext* context, + const RDPGFX_CREATE_SURFACE_PDU* createSurface); +typedef UINT (*pcRdpgfxDeleteSurface)(RdpgfxClientContext* context, + const RDPGFX_DELETE_SURFACE_PDU* deleteSurface); +typedef UINT (*pcRdpgfxSolidFill)(RdpgfxClientContext* context, + const RDPGFX_SOLID_FILL_PDU* solidFill); +typedef UINT (*pcRdpgfxSurfaceToSurface)(RdpgfxClientContext* context, + const RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface); +typedef UINT (*pcRdpgfxSurfaceToCache)(RdpgfxClientContext* context, + const RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache); +typedef UINT (*pcRdpgfxCacheToSurface)(RdpgfxClientContext* context, + const RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface); +typedef UINT (*pcRdpgfxCacheImportOffer)(RdpgfxClientContext* context, + const RDPGFX_CACHE_IMPORT_OFFER_PDU* cacheImportOffer); +typedef UINT (*pcRdpgfxCacheImportReply)(RdpgfxClientContext* context, + const RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply); +typedef UINT (*pcRdpgfxEvictCacheEntry)(RdpgfxClientContext* context, + const RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry); +typedef UINT (*pcRdpgfxMapSurfaceToOutput)(RdpgfxClientContext* context, + const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput); +typedef UINT (*pcRdpgfxMapSurfaceToWindow)(RdpgfxClientContext* context, + const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow); typedef UINT (*pcRdpgfxSetSurfaceData)(RdpgfxClientContext* context, UINT16 surfaceId, void* pData); typedef void* (*pcRdpgfxGetSurfaceData)(RdpgfxClientContext* context, UINT16 surfaceId); @@ -53,6 +69,8 @@ typedef UINT (*pcRdpgfxGetSurfaceIds)(RdpgfxClientContext* context, UINT16** ppS typedef UINT (*pcRdpgfxSetCacheSlotData)(RdpgfxClientContext* context, UINT16 cacheSlot, void* pData); typedef void* (*pcRdpgfxGetCacheSlotData)(RdpgfxClientContext* context, UINT16 cacheSlot); +typedef UINT (*pcRdpgfxUpdateSurfaces)(RdpgfxClientContext* context); + struct _rdpgfx_client_context { void* handle; @@ -80,6 +98,8 @@ struct _rdpgfx_client_context pcRdpgfxGetSurfaceData GetSurfaceData; pcRdpgfxSetCacheSlotData SetCacheSlotData; pcRdpgfxGetCacheSlotData GetCacheSlotData; + + pcRdpgfxUpdateSurfaces UpdateSurfaces; }; #endif /* FREERDP_CHANNEL_CLIENT_RDPGFX_H */ diff --git a/include/freerdp/codec/clear.h b/include/freerdp/codec/clear.h index baca737c7..1485dfd2b 100644 --- a/include/freerdp/codec/clear.h +++ b/include/freerdp/codec/clear.h @@ -44,7 +44,7 @@ struct _CLEAR_VBAR_ENTRY { UINT32 size; UINT32 count; - UINT32* pixels; + BYTE* pixels; }; typedef struct _CLEAR_VBAR_ENTRY CLEAR_VBAR_ENTRY; @@ -55,6 +55,7 @@ struct _CLEAR_CONTEXT UINT32 seqNumber; BYTE* TempBuffer; UINT32 TempSize; + UINT32 format; CLEAR_GLYPH_ENTRY GlyphCache[4000]; UINT32 VBarStorageCursor; CLEAR_VBAR_ENTRY VBarStorage[32768]; @@ -68,8 +69,10 @@ extern "C" { FREERDP_API int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize); -FREERDP_API int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight); +FREERDP_API INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, + UINT32 SrcSize, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight); FREERDP_API BOOL clear_context_reset(CLEAR_CONTEXT* clear); diff --git a/include/freerdp/codec/color.h b/include/freerdp/codec/color.h index b682591e0..1b72f9617 100644 --- a/include/freerdp/codec/color.h +++ b/include/freerdp/codec/color.h @@ -3,6 +3,8 @@ * Color Conversion Routines * * Copyright 2010 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +24,13 @@ #include #include +#include #define FREERDP_PIXEL_FORMAT_TYPE_A 0 #define FREERDP_PIXEL_FORMAT_TYPE_ARGB 1 #define FREERDP_PIXEL_FORMAT_TYPE_ABGR 2 +#define FREERDP_PIXEL_FORMAT_TYPE_RGBA 3 +#define FREERDP_PIXEL_FORMAT_TYPE_BGRA 4 #define FREERDP_PIXEL_FORMAT_IS_ABGR(_format) (FREERDP_PIXEL_FORMAT_TYPE(_format) == FREERDP_PIXEL_FORMAT_TYPE_ABGR) @@ -37,447 +42,704 @@ ((_flip << 30) | (_bpp << 24) | (_type << 16) | (_a << 12) | (_r << 8) | (_g << 4) | (_b)) #define FREERDP_PIXEL_FORMAT_FLIP(_format) (((_format) >> 30) & 0x03) -#define FREERDP_PIXEL_FORMAT_BPP(_format) (((_format) >> 24) & 0x3F) -#define FREERDP_PIXEL_FORMAT_TYPE(_format) (((_format) >> 16) & 0xFF) -#define FREERDP_PIXEL_FORMAT_A(_format) (((_format) >> 12) & 0x0F) -#define FREERDP_PIXEL_FORMAT_R(_format) (((_format) >> 8) & 0x0F) -#define FREERDP_PIXEL_FORMAT_G(_format) (((_format) >> 4) & 0x0F) -#define FREERDP_PIXEL_FORMAT_B(_format) (((_format) ) & 0x0F) -#define FREERDP_PIXEL_FORMAT_RGB(_format) (((_format) ) & 0xFFF) -#define FREERDP_PIXEL_FORMAT_VIS(_format) (((_format) ) & 0xFFFF) +#define FREERDP_PIXEL_FORMAT_TYPE(_format) (((_format) >> 16) & 0x07) -#define FREERDP_PIXEL_FORMAT_DEPTH(_format) \ - (FREERDP_PIXEL_FORMAT_A(_format) + \ - FREERDP_PIXEL_FORMAT_R(_format) + \ - FREERDP_PIXEL_FORMAT_G(_format) + \ - FREERDP_PIXEL_FORMAT_B(_format)) +#define FREERDP_PIXEL_FORMAT_FLIP_MASKED(_format) (_format & 0x3FFFFFFF) /* 32bpp formats */ - #define PIXEL_FORMAT_A8R8G8B8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 8, 8, 8, 8) -#define PIXEL_FORMAT_A8R8G8B8 PIXEL_FORMAT_A8R8G8B8_F(0) -#define PIXEL_FORMAT_ARGB32 PIXEL_FORMAT_A8R8G8B8 -#define PIXEL_FORMAT_A8R8G8B8_VF PIXEL_FORMAT_A8R8G8B8_F(1) -#define PIXEL_FORMAT_ARGB32_VF PIXEL_FORMAT_A8R8G8B8_VF +#define PIXEL_FORMAT_ARGB32 PIXEL_FORMAT_A8R8G8B8_F(0) +#define PIXEL_FORMAT_ARGB32_VF PIXEL_FORMAT_A8R8G8B8_F(1) #define PIXEL_FORMAT_X8R8G8B8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8) -#define PIXEL_FORMAT_X8R8G8B8 PIXEL_FORMAT_X8R8G8B8_F(0) -#define PIXEL_FORMAT_XRGB32 PIXEL_FORMAT_X8R8G8B8 -#define PIXEL_FORMAT_RGB32 PIXEL_FORMAT_XRGB32 -#define PIXEL_FORMAT_X8R8G8B8_VF PIXEL_FORMAT_X8R8G8B8_F(1) -#define PIXEL_FORMAT_XRGB32_VF PIXEL_FORMAT_X8R8G8B8_VF -#define PIXEL_FORMAT_RGB32_VF PIXEL_FORMAT_XRGB32_VF +#define PIXEL_FORMAT_XRGB32 PIXEL_FORMAT_X8R8G8B8_F(0) +#define PIXEL_FORMAT_XRGB32_VF PIXEL_FORMAT_X8R8G8B8_F(1) #define PIXEL_FORMAT_A8B8G8R8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 8, 8, 8, 8) -#define PIXEL_FORMAT_A8B8G8R8 PIXEL_FORMAT_A8B8G8R8_F(0) -#define PIXEL_FORMAT_ABGR32 PIXEL_FORMAT_A8B8G8R8 -#define PIXEL_FORMAT_A8B8G8R8_VF PIXEL_FORMAT_A8B8G8R8_F(1) -#define PIXEL_FORMAT_ABGR32_VF PIXEL_FORMAT_A8B8G8R8_VF +#define PIXEL_FORMAT_ABGR32 PIXEL_FORMAT_A8B8G8R8_F(0) +#define PIXEL_FORMAT_ABGR32_VF PIXEL_FORMAT_A8B8G8R8_F(1) #define PIXEL_FORMAT_X8B8G8R8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8) -#define PIXEL_FORMAT_X8B8G8R8 PIXEL_FORMAT_X8B8G8R8_F(0) -#define PIXEL_FORMAT_XBGR32 PIXEL_FORMAT_X8B8G8R8 -#define PIXEL_FORMAT_BGR32 PIXEL_FORMAT_XBGR32 -#define PIXEL_FORMAT_X8B8G8R8_VF PIXEL_FORMAT_X8B8G8R8_F(1) -#define PIXEL_FORMAT_XBGR32_VF PIXEL_FORMAT_X8B8G8R8_VF -#define PIXEL_FORMAT_BGR32_VF PIXEL_FORMAT_XBGR32_VF +#define PIXEL_FORMAT_XBGR32 PIXEL_FORMAT_X8B8G8R8_F(0) +#define PIXEL_FORMAT_XBGR32_VF PIXEL_FORMAT_X8B8G8R8_F(1) #define PIXEL_FORMAT_B8G8R8A8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 8, 8, 8, 8) -#define PIXEL_FORMAT_B8G8R8A8 PIXEL_FORMAT_B8G8R8A8_F(0) -#define PIXEL_FORMAT_BGRA32 PIXEL_FORMAT_B8G8R8A8 -#define PIXEL_FORMAT_B8G8R8A8_VF PIXEL_FORMAT_B8G8R8A8_F(1) -#define PIXEL_FORMAT_BGRA32_VF PIXEL_FORMAT_B8G8R8A8_VF +#define PIXEL_FORMAT_BGRA32 PIXEL_FORMAT_B8G8R8A8_F(0) +#define PIXEL_FORMAT_BGRA32_VF PIXEL_FORMAT_B8G8R8A8_F(1) #define PIXEL_FORMAT_B8G8R8X8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 8, 8, 8) -#define PIXEL_FORMAT_B8G8R8X8 PIXEL_FORMAT_B8G8R8X8_F(0) -#define PIXEL_FORMAT_BGRX32 PIXEL_FORMAT_B8G8R8X8 -#define PIXEL_FORMAT_B8G8R8X8_VF PIXEL_FORMAT_B8G8R8X8_F(1) -#define PIXEL_FORMAT_BGRX32_VF PIXEL_FORMAT_B8G8R8X8_VF +#define PIXEL_FORMAT_BGRX32 PIXEL_FORMAT_B8G8R8X8_F(0) +#define PIXEL_FORMAT_BGRX32_VF PIXEL_FORMAT_B8G8R8X8_F(1) #define PIXEL_FORMAT_R8G8B8A8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 8, 8, 8, 8) -#define PIXEL_FORMAT_R8G8B8A8 PIXEL_FORMAT_R8G8B8A8_F(0) -#define PIXEL_FORMAT_RGBA32 PIXEL_FORMAT_R8G8B8A8 -#define PIXEL_FORMAT_R8G8B8A8_VF PIXEL_FORMAT_R8G8B8A8_F(1) -#define PIXEL_FORMAT_RGBA32_VF PIXEL_FORMAT_R8G8B8A8_VF +#define PIXEL_FORMAT_RGBA32 PIXEL_FORMAT_R8G8B8A8_F(0) +#define PIXEL_FORMAT_RGBA32_VF PIXEL_FORMAT_R8G8B8A8_F(1) #define PIXEL_FORMAT_R8G8B8X8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 8, 8, 8) -#define PIXEL_FORMAT_R8G8B8X8 PIXEL_FORMAT_R8G8B8X8_F(0) -#define PIXEL_FORMAT_RGBX32 PIXEL_FORMAT_R8G8B8X8 -#define PIXEL_FORMAT_R8G8B8X8_VF PIXEL_FORMAT_R8G8B8X8_F(1) -#define PIXEL_FORMAT_RGBX32_VF PIXEL_FORMAT_R8G8B8X8_VF +#define PIXEL_FORMAT_RGBX32 PIXEL_FORMAT_R8G8B8X8_F(0) +#define PIXEL_FORMAT_RGBX32_VF PIXEL_FORMAT_R8G8B8X8_F(1) /* 24bpp formats */ - #define PIXEL_FORMAT_R8G8B8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 24, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8) -#define PIXEL_FORMAT_R8G8B8 PIXEL_FORMAT_R8G8B8_F(0) -#define PIXEL_FORMAT_RGB24 PIXEL_FORMAT_R8G8B8 -#define PIXEL_FORMAT_R8G8B8_VF PIXEL_FORMAT_R8G8B8_F(1) -#define PIXEL_FORMAT_RGB24_VF PIXEL_FORMAT_R8G8B8_VF +#define PIXEL_FORMAT_RGB24 PIXEL_FORMAT_R8G8B8_F(0) +#define PIXEL_FORMAT_RGB24_VF PIXEL_FORMAT_R8G8B8_F(1) #define PIXEL_FORMAT_B8G8R8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 24, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8) -#define PIXEL_FORMAT_B8G8R8 PIXEL_FORMAT_B8G8R8_F(0) -#define PIXEL_FORMAT_BGR24 PIXEL_FORMAT_B8G8R8 -#define PIXEL_FORMAT_B8G8R8_VF PIXEL_FORMAT_B8G8R8_F(1) -#define PIXEL_FORMAT_BGR24_VF PIXEL_FORMAT_B8G8R8_VF +#define PIXEL_FORMAT_BGR24 PIXEL_FORMAT_B8G8R8_F(0) +#define PIXEL_FORMAT_BGR24_VF PIXEL_FORMAT_B8G8R8_F(1) /* 16bpp formats */ - #define PIXEL_FORMAT_R5G6B5_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 6, 5) -#define PIXEL_FORMAT_R5G6B5 PIXEL_FORMAT_R5G6B5_F(0) -#define PIXEL_FORMAT_RGB565 PIXEL_FORMAT_R5G6B5 -#define PIXEL_FORMAT_RGB16 PIXEL_FORMAT_R5G6B5 -#define PIXEL_FORMAT_R5G6B5_VF PIXEL_FORMAT_R5G6B5_F(1) -#define PIXEL_FORMAT_RGB565_VF PIXEL_FORMAT_R5G6B5_VF -#define PIXEL_FORMAT_RGB16_VF PIXEL_FORMAT_R5G6B5_VF +#define PIXEL_FORMAT_RGB16 PIXEL_FORMAT_R5G6B5_F(0) +#define PIXEL_FORMAT_RGB16_VF PIXEL_FORMAT_R5G6B5_F(1) #define PIXEL_FORMAT_B5G6R5_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 6, 5) -#define PIXEL_FORMAT_B5G6R5 PIXEL_FORMAT_B5G6R5_F(0) -#define PIXEL_FORMAT_BGR565 PIXEL_FORMAT_B5G6R5 -#define PIXEL_FORMAT_BGR16 PIXEL_FORMAT_B5G6R5 -#define PIXEL_FORMAT_B5G6R5_VF PIXEL_FORMAT_B5G6R5_F(1) -#define PIXEL_FORMAT_BGR565_VF PIXEL_FORMAT_B5G6R5_VF -#define PIXEL_FORMAT_BGR16_VF PIXEL_FORMAT_B5G6R5_VF +#define PIXEL_FORMAT_BGR16 PIXEL_FORMAT_B5G6R5_F(0) +#define PIXEL_FORMAT_BGR16_VF PIXEL_FORMAT_B5G6R5_F(1) #define PIXEL_FORMAT_A1R5G5B5_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 1, 5, 5, 5) -#define PIXEL_FORMAT_A1R5G5B5 PIXEL_FORMAT_A1R5G5B5_F(0) -#define PIXEL_FORMAT_ARGB555 PIXEL_FORMAT_A1R5G5B5 -#define PIXEL_FORMAT_ARGB15 PIXEL_FORMAT_A1R5G5B5 -#define PIXEL_FORMAT_A1R5G5B5_VF PIXEL_FORMAT_A1R5G5B5_F(1) -#define PIXEL_FORMAT_ARGB555_VF PIXEL_FORMAT_A1R5G5B5_VF -#define PIXEL_FORMAT_ARGB15_VF PIXEL_FORMAT_A1R5G5B5_VF +#define PIXEL_FORMAT_ARGB15 PIXEL_FORMAT_A1R5G5B5_F(0) +#define PIXEL_FORMAT_ARGB15_VF PIXEL_FORMAT_A1R5G5B5_F(1) #define PIXEL_FORMAT_X1R5G5B5_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 5, 5) -#define PIXEL_FORMAT_X1R5G5B5 PIXEL_FORMAT_X1R5G5B5_F(0) -#define PIXEL_FORMAT_XRGB555 PIXEL_FORMAT_X1R5G5B5 -#define PIXEL_FORMAT_RGB555 PIXEL_FORMAT_X1R5G5B5 -#define PIXEL_FORMAT_RGB15 PIXEL_FORMAT_X1R5G5B5 -#define PIXEL_FORMAT_X1R5G5B5_VF PIXEL_FORMAT_X1R5G5B5_F(1) -#define PIXEL_FORMAT_XRGB555_VF PIXEL_FORMAT_X1R5G5B5_VF -#define PIXEL_FORMAT_RGB555_VF PIXEL_FORMAT_X1R5G5B5_VF -#define PIXEL_FORMAT_RGB15_VF PIXEL_FORMAT_X1R5G5B5_VF +#define PIXEL_FORMAT_RGB15 PIXEL_FORMAT_X1R5G5B5_F(0) +#define PIXEL_FORMAT_RGB15_VF PIXEL_FORMAT_X1R5G5B5_F(1) #define PIXEL_FORMAT_A1B5G5R5_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 1, 5, 5, 5) -#define PIXEL_FORMAT_A1B5G5R5 PIXEL_FORMAT_A1B5G5R5_F(0) -#define PIXEL_FORMAT_ABGR555 PIXEL_FORMAT_A1B5G5R5 -#define PIXEL_FORMAT_ABGR15 PIXEL_FORMAT_A1B5G5R5 -#define PIXEL_FORMAT_A1B5G5R5_VF PIXEL_FORMAT_A1B5G5R5_F(1) -#define PIXEL_FORMAT_ABGR555_VF PIXEL_FORMAT_A1B5G5R5_VF -#define PIXEL_FORMAT_ABGR15_VF PIXEL_FORMAT_A1B5G5R5_VF +#define PIXEL_FORMAT_ABGR15 PIXEL_FORMAT_A1B5G5R5_F(0) +#define PIXEL_FORMAT_ABGR15_VF PIXEL_FORMAT_A1B5G5R5_F(1) #define PIXEL_FORMAT_X1B5G5R5_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 5, 5) -#define PIXEL_FORMAT_X1B5G5R5 PIXEL_FORMAT_X1B5G5R5_F(0) -#define PIXEL_FORMAT_XBGR555 PIXEL_FORMAT_X1B5G5R5 -#define PIXEL_FORMAT_BGR555 PIXEL_FORMAT_X1B5G5R5 -#define PIXEL_FORMAT_BGR15 PIXEL_FORMAT_X1B5G5R5 -#define PIXEL_FORMAT_X1B5G5R5_VF PIXEL_FORMAT_X1B5G5R5_F(1) -#define PIXEL_FORMAT_XBGR555_VF PIXEL_FORMAT_X1B5G5R5_VF -#define PIXEL_FORMAT_BGR555_VF PIXEL_FORMAT_X1B5G5R5_VF -#define PIXEL_FORMAT_BGR15_VF PIXEL_FORMAT_X1B5G5R5_VF +#define PIXEL_FORMAT_BGR15 PIXEL_FORMAT_X1B5G5R5_F(0) +#define PIXEL_FORMAT_BGR15_VF PIXEL_FORMAT_X1B5G5R5_F(1) /* 8bpp formats */ - #define PIXEL_FORMAT_A8_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 8, FREERDP_PIXEL_FORMAT_TYPE_A, 8, 0, 0, 0) -#define PIXEL_FORMAT_A8 PIXEL_FORMAT_A8_F(0) -#define PIXEL_FORMAT_8BPP PIXEL_FORMAT_A8 -#define PIXEL_FORMAT_256 PIXEL_FORMAT_A8 -#define PIXEL_FORMAT_RGB8 PIXEL_FORMAT_A8 -#define PIXEL_FORMAT_A8_VF PIXEL_FORMAT_A8_F(1) -#define PIXEL_FORMAT_8BPP_VF PIXEL_FORMAT_A8_VF -#define PIXEL_FORMAT_256_VF PIXEL_FORMAT_A8_VF -#define PIXEL_FORMAT_RGB8_VF PIXEL_FORMAT_A8_VF +#define PIXEL_FORMAT_RGB8 PIXEL_FORMAT_A8_F(0) +#define PIXEL_FORMAT_RGB8_VF PIXEL_FORMAT_A8_F(1) /* 4 bpp formats */ - #define PIXEL_FORMAT_A4_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 4, FREERDP_PIXEL_FORMAT_TYPE_A, 4, 0, 0, 0) #define PIXEL_FORMAT_A4 PIXEL_FORMAT_A4_F(0) -#define PIXEL_FORMAT_4BPP PIXEL_FORMAT_A4 #define PIXEL_FORMAT_A4_VF PIXEL_FORMAT_A4_F(1) -#define PIXEL_FORMAT_4BPP_VF PIXEL_FORMAT_A4_VF /* 1bpp formats */ - #define PIXEL_FORMAT_A1_F(_flip) FREERDP_PIXEL_FORMAT(_flip, 1, FREERDP_PIXEL_FORMAT_TYPE_A, 1, 0, 0, 0) -#define PIXEL_FORMAT_A1 PIXEL_FORMAT_A1_F(0) -#define PIXEL_FORMAT_1BPP PIXEL_FORMAT_A1 -#define PIXEL_FORMAT_MONO PIXEL_FORMAT_A1 -#define PIXEL_FORMAT_A1_VF PIXEL_FORMAT_A1_F(1) -#define PIXEL_FORMAT_1BPP_VF PIXEL_FORMAT_A1_VF -#define PIXEL_FORMAT_MONO_VF PIXEL_FORMAT_A1_VF +#define PIXEL_FORMAT_MONO PIXEL_FORMAT_A1_F(0) +#define PIXEL_FORMAT_MONO_VF PIXEL_FORMAT_A1_F(1) #ifdef __cplusplus extern "C" { #endif /* Color Space Conversions: http://msdn.microsoft.com/en-us/library/ff566496/ */ - -/* Color Space Conversion */ - -#define RGB_555_565(_r, _g, _b) \ - _r = _r; \ - _g = (_g << 1 & ~0x1) | (_g >> 4); \ - _b = _b; - -#define RGB_565_555(_r, _g, _b) \ - _r = _r; \ - _g = (_g >> 1); \ - _b = _b; - -#define RGB_555_888(_r, _g, _b) \ - _r = (_r << 3 & ~0x7) | (_r >> 2); \ - _g = (_g << 3 & ~0x7) | (_g >> 2); \ - _b = (_b << 3 & ~0x7) | (_b >> 2); - -#define RGB_565_888(_r, _g, _b) \ - _r = (_r << 3 & ~0x7) | (_r >> 2); \ - _g = (_g << 2 & ~0x3) | (_g >> 4); \ - _b = (_b << 3 & ~0x7) | (_b >> 2); - -#define RGB_888_565(_r, _g, _b) \ - _r = (_r >> 3); \ - _g = (_g >> 2); \ - _b = (_b >> 3); - -#define RGB_888_555(_r, _g, _b) \ - _r = (_r >> 3); \ - _g = (_g >> 3); \ - _b = (_b >> 3); - -/* RGB 15 (RGB_555) */ - -#define RGB555(_r, _g, _b) \ - ((_r & 0x1F) << 10) | ((_g & 0x1F) << 5) | (_b & 0x1F) - -#define RGB15(_r, _g, _b) \ - (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_b >> 3) & 0x1F) - -#define GetRGB_555(_r, _g, _b, _p) \ - _r = (_p & 0x7C00) >> 10; \ - _g = (_p & 0x3E0) >> 5; \ - _b = (_p & 0x1F); - -#define GetRGB15(_r, _g, _b, _p) \ - GetRGB_555(_r, _g, _b, _p); \ - RGB_555_888(_r, _g, _b); - -/* BGR 15 (BGR_555) */ - -#define BGR555(_r, _g, _b) \ - ((_b & 0x1F) << 10) | ((_g & 0x1F) << 5) | (_r & 0x1F) - -#define BGR15(_r, _g, _b) \ - (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_r >> 3) & 0x1F) - -#define GetBGR_555(_r, _g, _b, _p) \ - _b = (_p & 0x7C00) >> 10; \ - _g = (_p & 0x3E0) >> 5; \ - _r = (_p & 0x1F); - -#define GetBGR15(_r, _g, _b, _p) \ - GetBGR_555(_r, _g, _b, _p); \ - RGB_555_888(_r, _g, _b); - -/* RGB 16 (RGB_565) */ - -#define RGB565(_r, _g, _b) \ - ((_r & 0x1F) << 11) | ((_g & 0x3F) << 5) | (_b & 0x1F) - -#define RGB16(_r, _g, _b) \ - (((_r >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | ((_b >> 3) & 0x1F) - -#define GetRGB_565(_r, _g, _b, _p) \ - _r = (_p & 0xF800) >> 11; \ - _g = (_p & 0x7E0) >> 5; \ - _b = (_p & 0x1F); - -#define GetRGB16(_r, _g, _b, _p) \ - GetRGB_565(_r, _g, _b, _p); \ - RGB_565_888(_r, _g, _b); - -/* BGR 16 (BGR_565) */ - -#define BGR565(_r, _g, _b) \ - ((_b & 0x1F) << 11) | ((_g & 0x3F) << 5) | (_r & 0x1F) - -#define BGR16(_r, _g, _b) \ - (((_b >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | ((_r >> 3) & 0x1F) - -#define GetBGR_565(_r, _g, _b, _p) \ - _b = (_p & 0xF800) >> 11; \ - _g = (_p & 0x7E0) >> 5; \ - _r = (_p & 0x1F); - -#define GetBGR16(_r, _g, _b, _p) \ - GetBGR_565(_r, _g, _b, _p); \ - RGB_565_888(_r, _g, _b); - -/* RGB 24 (RGB_888) */ - -#define RGB24(_r, _g, _b) \ - (_r << 16) | (_g << 8) | _b - -#define GetRGB24(_r, _g, _b, _p) \ - _r = (_p & 0xFF0000) >> 16; \ - _g = (_p & 0xFF00) >> 8; \ - _b = (_p & 0xFF); - -/* BGR 24 (BGR_888) */ - -#define BGR24(_r, _g, _b) \ - (_b << 16) | (_g << 8) | _r - -#define GetBGR24(_r, _g, _b, _p) \ - _b = (_p & 0xFF0000) >> 16; \ - _g = (_p & 0xFF00) >> 8; \ - _r = (_p & 0xFF); - -/* RGB 32 (ARGB_8888), alpha ignored */ - -#define RGB32(_r, _g, _b) \ - (_r << 16) | (_g << 8) | _b - -#define GetRGB32(_r, _g, _b, _p) \ - _r = (_p & 0xFF0000) >> 16; \ - _g = (_p & 0xFF00) >> 8; \ - _b = (_p & 0xFF); - -/* ARGB 32 (ARGB_8888) */ - -#define ARGB32(_a,_r, _g, _b) \ - (_a << 24) | (_r << 16) | (_g << 8) | _b - -#define GetARGB32(_a, _r, _g, _b, _p) \ - _a = (_p & 0xFF000000) >> 24; \ - _r = (_p & 0xFF0000) >> 16; \ - _g = (_p & 0xFF00) >> 8; \ - _b = (_p & 0xFF); - -/* BGR 32 (ABGR_8888), alpha ignored */ - -#define BGR32(_r, _g, _b) \ - (_b << 16) | (_g << 8) | _r - -#define GetBGR32(_r, _g, _b, _p) \ - _b = (_p & 0xFF0000) >> 16; \ - _g = (_p & 0xFF00) >> 8; \ - _r = (_p & 0xFF); - -/* BGR 32 (ABGR_8888) */ - -#define ABGR32(_a, _r, _g, _b) \ - (_a << 24) | (_b << 16) | (_g << 8) | _r - -#define GetABGR32(_a, _r, _g, _b, _p) \ - _a = (_p & 0xFF000000) >> 24; \ - _b = (_p & 0xFF0000) >> 16; \ - _g = (_p & 0xFF00) >> 8; \ - _r = (_p & 0xFF); - -/* Color Conversion */ - -#define BGR16_RGB32(_r, _g, _b, _p) \ - GetBGR16(_r, _g, _b, _p); \ - RGB_565_888(_r, _g, _b); \ - _p = RGB32(_r, _g, _b); - -#define RGB32_RGB16(_r, _g, _b, _p) \ - GetRGB32(_r, _g, _b, _p); \ - RGB_888_565(_r, _g, _b); \ - _p = RGB565(_r, _g, _b); - -#define RGB15_RGB16(_r, _g, _b, _p) \ - GetRGB_555(_r, _g, _b, _p); \ - _g = (_g << 1 & ~0x1) | (_g >> 4); \ - _p = RGB565(_r, _g, _b); - -#define RGB16_RGB15(_r, _g, _b, _p) \ - GetRGB_565(_r, _g, _b, _p); \ - _g = (_g >> 1); \ - _p = RGB555(_r, _g, _b); - -#define CLRCONV_ALPHA 1 -#define CLRCONV_INVERT 2 -/* if defined RGB555 format is used when rendering with a 16-bit frame buffer */ -#define CLRCONV_RGB555 4 - -/* Supported Internal Buffer Formats */ -#define CLRBUF_16BPP 8 -#define CLRBUF_32BPP 32 - -struct _CLRCONV +static const char* GetColorFormatName(UINT32 format) { - int alpha; - int invert; - int rgb555; - rdpPalette* palette; -}; -typedef struct _CLRCONV CLRCONV; -typedef CLRCONV* HCLRCONV; + switch (format) + { + /* 32bpp formats */ + case PIXEL_FORMAT_ARGB32: + return "PIXEL_FORMAT_ARGB32"; -#define IBPP(_bpp) (((_bpp + 1)/ 8) % 5) + case PIXEL_FORMAT_ARGB32_VF: + return "PIXEL_FORMAT_ARGB32_VF"; -typedef BYTE* (*p_freerdp_image_convert)(BYTE* srcData, BYTE* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv); + case PIXEL_FORMAT_XRGB32: + return "PIXEL_FORMAT_XRGB32"; -static INLINE UINT32 RGB32_to_BGR32(UINT32 pixel) -{ - UINT32 temp; + case PIXEL_FORMAT_XRGB32_VF: + return "PIXEL_FORMAT_XRGB32_VF"; - temp = (pixel ^ (pixel >> 16)) & ((1 << 8) - 1); - return (pixel ^ (temp | (temp << 16))); + case PIXEL_FORMAT_ABGR32: + return "PIXEL_FORMAT_ABGR32"; + + case PIXEL_FORMAT_ABGR32_VF: + return "PIXEL_FORMAT_ABGR32_VF"; + + case PIXEL_FORMAT_XBGR32: + return "PIXEL_FORMAT_XBGR32"; + + case PIXEL_FORMAT_XBGR32_VF: + return "PIXEL_FORMAT_XBGR32_VF"; + + case PIXEL_FORMAT_BGRA32: + return "PIXEL_FORMAT_BGRA32"; + + case PIXEL_FORMAT_BGRA32_VF: + return "PIXEL_FORMAT_BGRA32_VF"; + + case PIXEL_FORMAT_BGRX32: + return "PIXEL_FORMAT_BGRX32"; + + case PIXEL_FORMAT_BGRX32_VF: + return "PIXEL_FORMAT_BGRX32_VF"; + + case PIXEL_FORMAT_RGBA32: + return "PIXEL_FORMAT_RGBA32"; + + case PIXEL_FORMAT_RGBA32_VF: + return "PIXEL_FORMAT_RGBA32_VF"; + + case PIXEL_FORMAT_RGBX32: + return "PIXEL_FORMAT_RGBX32"; + + case PIXEL_FORMAT_RGBX32_VF: + return "PIXEL_FORMAT_RGBX32_VF"; + + /* 24bpp formats */ + case PIXEL_FORMAT_RGB24: + return "PIXEL_FORMAT_RGB24"; + + case PIXEL_FORMAT_RGB24_VF: + return "PIXEL_FORMAT_RGB24_VF"; + + case PIXEL_FORMAT_BGR24: + return "PIXEL_FORMAT_BGR24"; + + case PIXEL_FORMAT_BGR24_VF: + return "PIXEL_FORMAT_BGR24_VF"; + + /* 16bpp formats */ + case PIXEL_FORMAT_RGB16: + return "PIXEL_FORMAT_RGB16"; + + case PIXEL_FORMAT_RGB16_VF: + return "PIXEL_FORMAT_RGB16_VF"; + + case PIXEL_FORMAT_BGR16: + return "PIXEL_FORMAT_BGR16"; + + case PIXEL_FORMAT_BGR16_VF: + return "PIXEL_FORMAT_BGR16_VF"; + + case PIXEL_FORMAT_ARGB15: + return "PIXEL_FORMAT_ARGB15"; + + case PIXEL_FORMAT_ARGB15_VF: + return "PIXEL_FORMAT_ARGB15_VF"; + + case PIXEL_FORMAT_RGB15: + return "PIXEL_FORMAT_RGB15"; + + case PIXEL_FORMAT_RGB15_VF: + return "PIXEL_FORMAT_ABGR15"; + + case PIXEL_FORMAT_ABGR15: + return ""; + + case PIXEL_FORMAT_ABGR15_VF: + return "PIXEL_FORMAT_ABGR15_VF"; + + case PIXEL_FORMAT_BGR15: + return "PIXEL_FORMAT_BGR15"; + + case PIXEL_FORMAT_BGR15_VF: + return "PIXEL_FORMAT_BGR15_VF"; + + /* 8bpp formats */ + case PIXEL_FORMAT_RGB8: + return "PIXEL_FORMAT_RGB8"; + + case PIXEL_FORMAT_RGB8_VF: + return "PIXEL_FORMAT_RGB8_VF"; + + /* 4 bpp formats */ + case PIXEL_FORMAT_A4: + return "PIXEL_FORMAT_A4"; + + case PIXEL_FORMAT_A4_VF: + return "PIXEL_FORMAT_A4_VF"; + + /* 1bpp formats */ + case PIXEL_FORMAT_MONO: + return "PIXEL_FORMAT_MONO"; + + case PIXEL_FORMAT_MONO_VF: + return "PIXEL_FORMAT_MONO_VF"; + + default: + return "UNKNOWN"; + } } -FREERDP_API int freerdp_get_pixel(BYTE* data, int x, int y, int width, int height, int bpp); -FREERDP_API void freerdp_set_pixel(BYTE* data, int x, int y, int width, int height, int bpp, int pixel); +static INLINE void SplitColor(UINT32 color, UINT32 format, BYTE* _r, BYTE* _g, + BYTE* _b, BYTE* _a, const UINT32* palette) +{ + UINT32 tmp; -FREERDP_API BYTE* freerdp_image_convert(BYTE* srcData, BYTE *dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API BYTE* freerdp_glyph_convert(int width, int height, BYTE* data); -FREERDP_API void freerdp_bitmap_flip(BYTE * src, BYTE * dst, int scanLineSz, int height); -FREERDP_API BYTE* freerdp_image_flip(BYTE* srcData, BYTE* dstData, int width, int height, int bpp); -FREERDP_API BYTE* freerdp_icon_convert(BYTE* srcData, BYTE* dstData, BYTE* mask, int width, int height, int bpp, HCLRCONV clrconv); -FREERDP_API BYTE* freerdp_mono_image_convert(BYTE* srcData, int width, int height, int srcBpp, int dstBpp, UINT32 bgcolor, UINT32 fgcolor, HCLRCONV clrconv); -FREERDP_API void freerdp_alpha_cursor_convert(BYTE* alphaData, BYTE* xorMask, BYTE* andMask, int width, int height, int bpp, HCLRCONV clrconv); -FREERDP_API void freerdp_image_swap_color_order(BYTE* data, int width, int height); + switch (FREERDP_PIXEL_FORMAT_FLIP_MASKED(format)) + { + /* 32bpp formats */ + case PIXEL_FORMAT_ARGB32: + if (_a) + *_a = color >> 24; -FREERDP_API UINT32 freerdp_color_convert_var(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API UINT32 freerdp_color_convert_rgb(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API UINT32 freerdp_color_convert_bgr(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API UINT32 freerdp_color_convert_rgb_bgr(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API UINT32 freerdp_color_convert_bgr_rgb(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API UINT32 freerdp_color_convert_var_rgb(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API UINT32 freerdp_color_convert_var_bgr(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv); -FREERDP_API UINT32 freerdp_convert_gdi_order_color(UINT32 color, int bpp, UINT32 format, BYTE* palette); + if (_r) + *_r = color >> 16; -FREERDP_API HCLRCONV freerdp_clrconv_new(UINT32 flags); -FREERDP_API void freerdp_clrconv_free(HCLRCONV clrconv); + if (_g) + *_g = color >> 8; -FREERDP_API int freerdp_image_copy_from_monochrome(BYTE* pDstData, UINT32 DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, UINT32 backColor, UINT32 foreColor, BYTE* palette); + if (_b) + *_b = color; -FREERDP_API int freerdp_image_copy_from_pointer_data( - BYTE* pDstData, UINT32 DstFormat, int nDstStep, - int nXDst, int nYDst, int nWidth, int nHeight, BYTE* xorMask, - UINT32 xorMaskLength, BYTE* andMask, UINT32 andMaskLength, - UINT32 xorBpp, BYTE* palette); + break; -FREERDP_API int freerdp_image8_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette); -FREERDP_API int freerdp_image15_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette); -FREERDP_API int freerdp_image16_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette); -FREERDP_API int freerdp_image24_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette); -FREERDP_API int freerdp_image32_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette); + case PIXEL_FORMAT_XRGB32: + if (_r) + *_r = color >> 16; -FREERDP_API int freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette); -FREERDP_API int freerdp_image_move(BYTE* pData, DWORD Format, int nStep, int nXDst, int nYDst, - int nWidth, int nHeight, int nXSrc, int nYSrc); -FREERDP_API int freerdp_image_fill(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, UINT32 color); + if (_g) + *_g = color >> 8; -FREERDP_API int freerdp_image_copy_from_retina(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc); + if (_b) + *_b = color; + + if (_a) + *_a = 0xFF; + + break; + + case PIXEL_FORMAT_ABGR32: + if (_a) + *_a = color >> 24; + + if (_b) + *_b = color >> 16; + + if (_g) + *_g = color >> 8; + + if (_r) + *_r = color; + + break; + + case PIXEL_FORMAT_XBGR32: + if (_b) + *_b = color >> 16; + + if (_g) + *_g = color >> 8; + + if (_r) + *_r = color; + + if (_a) + *_a = 0xFF; + + break; + + case PIXEL_FORMAT_RGBA32: + if (_r) + *_r = color >> 24; + + if (_g) + *_g = color >> 16; + + if (_b) + *_b = color >> 8; + + if (_a) + *_a = color; + + break; + + case PIXEL_FORMAT_RGBX32: + if (_b) + *_b = color >> 24; + + if (_g) + *_g = color >> 16; + + if (_r) + *_r = color >> 8; + + if (_a) + *_a = 0xFF; + + break; + + case PIXEL_FORMAT_BGRA32: + if (_b) + *_b = color >> 24; + + if (_g) + *_g = color >> 16; + + if (_r) + *_r = color >> 8; + + if (_a) + *_a = color; + + break; + + case PIXEL_FORMAT_BGRX32: + if (_b) + *_b = color >> 24; + + if (_g) + *_g = color >> 16; + + if (_r) + *_r = color >> 8; + + if (_a) + *_a = 0xFF; + + break; + + /* 24bpp formats */ + case PIXEL_FORMAT_RGB24: + if (_r) + *_r = color >> 16; + + if (_g) + *_g = color >> 8; + + if (_b) + *_b = color; + + if (_a) + *_a = 0xFF; + + break; + + case PIXEL_FORMAT_BGR24: + if (_b) + *_b = color >> 16; + + if (_g) + *_g = color >> 8; + + if (_r) + *_r = color; + + if (_a) + *_a = 0xFF; + + break; + + /* 16bpp formats */ + case PIXEL_FORMAT_RGB16: + if (_r) + *_r = ((color >> 11) & 0x1F) << 3; + + if (_g) + *_g = ((color >> 5) & 0x3F) << 2; + + if (_b) + *_b = (color & 0x1F) << 3; + + if (_a) + *_a = 0xFF; + + break; + + case PIXEL_FORMAT_BGR16: + if (_b) + *_b = ((color >> 11) & 0x1F) << 3; + + if (_g) + *_g = ((color >> 5) & 0x3F) << 2; + + if (_r) + *_r = (color & 0x1F) << 3; + + if (_a) + *_a = 0xFF; + + break; + + case PIXEL_FORMAT_ARGB15: + if (_r) + *_r = ((color >> 10) & 0x1F) << 3; + + if (_g) + *_g = ((color >> 5) & 0x1F) << 3; + + if (_b) + *_b = (color & 0x1F) << 3; + + if (_a) + *_a = color & 0x8000 ? 0xFF : 0x00; + + break; + + case PIXEL_FORMAT_ABGR15: + if (_b) + *_b = ((color >> 10) & 0x1F) << 3; + + if (_g) + *_g = ((color >> 5) & 0x1F) << 3; + + if (_r) + *_r = (color & 0x1F) << 3; + + if (_a) + *_a = color & 0x8000 ? 0xFF : 0x00; + + break; + + /* 15bpp formats */ + case PIXEL_FORMAT_RGB15: + if (_r) + *_r = ((color >> 10) & 0x1F) << 3; + + if (_g) + *_g = ((color >> 5) & 0x1F) << 3; + + if (_b) + *_b = (color & 0x1F) << 3; + + if (_a) + *_a = 0xFF; + + break; + + case PIXEL_FORMAT_BGR15: + if (_b) + *_b = ((color >> 10) & 0x1F) << 3; + + if (_g) + *_g = ((color >> 5) & 0x1F) << 3; + + if (_r) + *_r = (color & 0x1F) << 3; + + if (_a) + *_a = 0xFF; + + break; + + /* 8bpp formats */ + case PIXEL_FORMAT_RGB8: + tmp = palette[color]; + SplitColor(tmp, PIXEL_FORMAT_ARGB32, _r, _g, _b, _a, NULL); + break; + + /* 4 bpp formats */ + case PIXEL_FORMAT_A4: + + /* 1bpp formats */ + case PIXEL_FORMAT_MONO: + default: + WLog_ERR("xxxxx", "Unsupported format %s", GetColorFormatName(format)); + break; + } +} + +static INLINE UINT32 GetColor(UINT32 format, BYTE r, BYTE g, BYTE b, BYTE a) +{ + UINT32 _r = r; + UINT32 _g = g; + UINT32 _b = b; + UINT32 _a = a; + + switch (FREERDP_PIXEL_FORMAT_FLIP_MASKED(format)) + { + /* 32bpp formats */ + case PIXEL_FORMAT_ARGB32: + return (_a << 24) | (_r << 16) | (_g << 8) | _b; + + case PIXEL_FORMAT_XRGB32: + return (_r << 16) | (_g << 8) | _b; + + case PIXEL_FORMAT_ABGR32: + return (_a << 24) | (_b << 16) | (_g << 8) | _r; + + case PIXEL_FORMAT_XBGR32: + return (_b << 16) | (_g << 8) | _r; + + case PIXEL_FORMAT_RGBA32: + return (_r << 24) | (_g << 16) | (_b << 8) | _a; + + case PIXEL_FORMAT_RGBX32: + return (_r << 24) | (_g << 16) | (_b << 8) | _a; + + case PIXEL_FORMAT_BGRA32: + return (_b << 24) | (_g << 16) | (_r << 8) | _a; + + case PIXEL_FORMAT_BGRX32: + return (_b << 24) | (_g << 16) | (_r << 8) | _a; + + /* 24bpp formats */ + case PIXEL_FORMAT_RGB24: + return (_r << 16) | (_g << 8) | _b; + + case PIXEL_FORMAT_BGR24: + return (_b << 16) | (_g << 8) | _r; + + /* 16bpp formats */ + case PIXEL_FORMAT_RGB16: + return (((_r >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | (( + _b >> 3) & 0x1F); + + case PIXEL_FORMAT_BGR16: + return (((_b >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | (( + _r >> 3) & 0x1F); + + case PIXEL_FORMAT_ARGB15: + return (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( + _b >> 3) & 0x1F); + + case PIXEL_FORMAT_ABGR15: + return (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( + _r >> 3) & 0x1F); + + /* 15bpp formats */ + case PIXEL_FORMAT_RGB15: + return (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( + _b >> 3) & 0x1F); + + case PIXEL_FORMAT_BGR15: + return (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( + _r >> 3) & 0x1F);; + + /* 8bpp formats */ + case PIXEL_FORMAT_RGB8: + + /* 4 bpp formats */ + case PIXEL_FORMAT_A4: + + /* 1bpp formats */ + case PIXEL_FORMAT_MONO: + default: + WLog_ERR("xxxxx", "Unsupported format %s", GetColorFormatName(format)); + return 0; + } +} + +static INLINE UINT32 GetBitsPerPixel(UINT32 format) +{ + return (((format) >> 24) & 0x3F); +} + +static INLINE BOOL ColorHasAlpha(UINT32 format) +{ + UINT32 alpha = (((format) >> 12) & 0x0F); + + if (alpha == 0) + return FALSE; + + return TRUE; +} + +static INLINE UINT32 ReadColor(const BYTE* src, UINT32 format) +{ + UINT32 color; + + switch (GetBitsPerPixel(format)) + { + case 32: + color = ((UINT32)src[0] << 24) | ((UINT32)src[1] << 16) | + ((UINT32)src[2] << 8) | src[3]; + break; + + case 24: + color = ((UINT32)src[0] << 16) | ((UINT32)src[1] << 8) | src[2]; + break; + + case 16: + case 15: + color = ((UINT32)src[1] << 8) | src[0]; + color = ((color >> 11) & 0x1F) | (color & 0x7E0) | ((color & 0x1F) << 11); + break; + + case 8: + color = *src; + break; + + default: + WLog_ERR("xxxxx", "Unsupported format %s", GetColorFormatName(format)); + color = 0; + break; + } + + return color; +} + +static INLINE BOOL WriteColor(BYTE* dst, UINT32 format, UINT32 color) +{ + switch (GetBitsPerPixel(format)) + { + case 32: + dst[0] = color >> 24; + dst[1] = color >> 16; + dst[2] = color >> 8; + dst[3] = color; + break; + + case 24: + dst[0] = color >> 16; + dst[1] = color >> 8; + dst[2] = color; + break; + + case 16: + case 15: + color = ((color >> 11) & 0x1F) | (color & 0x7E0) | ((color & 0x1F) << 11); + dst[1] = color >> 8; + dst[0] = color; + break; + + case 8: + dst[0] = color; + break; + + default: + WLog_ERR("xxxxx", "Unsupported format %s", GetColorFormatName(format)); + return FALSE; + } + + return TRUE; +} + +static INLINE UINT32 ConvertColor(UINT32 color, UINT32 srcFormat, + UINT32 dstFormat, const UINT32* palette) +{ + BYTE r = 0; + BYTE g = 0; + BYTE b = 0; + BYTE a = 0; + SplitColor(color, srcFormat, &r, &g, &b, &a, palette); + return GetColor(dstFormat, r, g, b, a); +} + +static INLINE UINT32 GetBytesPerPixel(UINT32 format) +{ + return (GetBitsPerPixel(format) + 7) / 8; +} + +FREERDP_API BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, + const BYTE* data); + +FREERDP_API int freerdp_image_copy_from_monochrome(BYTE* pDstData, + UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, + UINT32 backColor, UINT32 foreColor, + const UINT32* palette); + +FREERDP_API BOOL freerdp_image_copy_from_pointer_data( + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, + const BYTE* xorMask, UINT32 xorMaskLength, + const BYTE* andMask, UINT32 andMaskLength, + UINT32 xorBpp, const UINT32* palette); + +FREERDP_API BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, + INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, DWORD SrcFormat, + INT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + const UINT32* palette); + +FREERDP_API BOOL freerdp_image_fill(BYTE* pDstData, DWORD DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT32 color); #ifdef __cplusplus } diff --git a/include/freerdp/codec/interleaved.h b/include/freerdp/codec/interleaved.h index 1d75f8663..d30b3c694 100644 --- a/include/freerdp/codec/interleaved.h +++ b/include/freerdp/codec/interleaved.h @@ -42,11 +42,20 @@ struct _BITMAP_INTERLEAVED_CONTEXT extern "C" { #endif -FREERDP_API int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcData, UINT32 SrcSize, int bpp, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, BYTE* palette); +FREERDP_API INT32 interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, + const BYTE* pSrcData, UINT32 SrcSize, + UINT32 bpp, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const UINT32* palette); -FREERDP_API int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData, UINT32* pDstSize, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette, int bpp); +FREERDP_API BOOL interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, + BYTE* pDstData, UINT32* pDstSize, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, UINT32 SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + const UINT32* palette, UINT32 bpp); FREERDP_API BOOL bitmap_interleaved_context_reset(BITMAP_INTERLEAVED_CONTEXT* interleaved); diff --git a/include/freerdp/codec/nsc.h b/include/freerdp/codec/nsc.h index 0439308cb..ab832de5c 100644 --- a/include/freerdp/codec/nsc.h +++ b/include/freerdp/codec/nsc.h @@ -4,6 +4,8 @@ * * Copyright 2011 Samsung, Author Jiten Pathy * Copyright 2012 Vic Lee + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,12 +35,12 @@ extern "C" { struct _NSC_MESSAGE { - int x; - int y; + UINT32 x; + UINT32 y; UINT32 width; UINT32 height; - BYTE* data; - int scanline; + const BYTE* data; + UINT32 scanline; BYTE* PlaneBuffer; UINT32 MaxPlaneSize; BYTE* PlaneBuffers[5]; @@ -60,12 +62,12 @@ typedef struct _NSC_CONTEXT NSC_CONTEXT; struct _NSC_CONTEXT { UINT32 OrgByteCount[4]; - UINT16 bpp; + UINT32 format; UINT16 width; UINT16 height; BYTE* BitmapData; UINT32 BitmapDataLength; - RDP_PIXEL_FORMAT pixel_format; + UINT32 pixel_format; BYTE* Planes; UINT32 PlaneByteCount[4]; @@ -77,23 +79,32 @@ struct _NSC_CONTEXT const BYTE* palette; void (*decode)(NSC_CONTEXT* context); - void (*encode)(NSC_CONTEXT* context, BYTE* BitmapData, int rowstride); + void (*encode)(NSC_CONTEXT* context, const BYTE* BitmapData, + UINT32 rowstride); NSC_CONTEXT_PRIV* priv; }; -FREERDP_API void nsc_context_set_pixel_format(NSC_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format); -FREERDP_API int nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, - UINT16 width, UINT16 height, BYTE* data, UINT32 length); -FREERDP_API void nsc_compose_message(NSC_CONTEXT* context, wStream* s, - BYTE* bmpdata, int width, int height, int rowstride); +FREERDP_API BOOL nsc_context_set_pixel_format(NSC_CONTEXT* context, + UINT32 pixel_format); +FREERDP_API BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, + UINT32 width, UINT32 height, + const BYTE* data, UINT32 length); +FREERDP_API BOOL nsc_compose_message(NSC_CONTEXT* context, wStream* s, + const BYTE* bmpdata, + UINT32 width, UINT32 height, UINT32 rowstride); -FREERDP_API NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, BYTE* data, int x, int y, - int width, int height, int scanline, int* numMessages, int maxDataSize); -FREERDP_API int nsc_write_message(NSC_CONTEXT* context, wStream* s, NSC_MESSAGE* message); -FREERDP_API int nsc_message_free(NSC_CONTEXT* context, NSC_MESSAGE* message); +FREERDP_API NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, + const BYTE* data, + UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 scanline, + UINT32* numMessages, UINT32 maxDataSize); +FREERDP_API BOOL nsc_write_message(NSC_CONTEXT* context, wStream* s, + NSC_MESSAGE* message); +FREERDP_API void nsc_message_free(NSC_CONTEXT* context, NSC_MESSAGE* message); -FREERDP_API BOOL nsc_context_reset(NSC_CONTEXT* context, UINT32 width, UINT32 height); +FREERDP_API BOOL nsc_context_reset(NSC_CONTEXT* context, UINT32 width, + UINT32 height); FREERDP_API NSC_CONTEXT* nsc_context_new(void); FREERDP_API void nsc_context_free(NSC_CONTEXT* context); diff --git a/include/freerdp/codec/planar.h b/include/freerdp/codec/planar.h index 4bc0e24c5..8b9eaed77 100644 --- a/include/freerdp/codec/planar.h +++ b/include/freerdp/codec/planar.h @@ -3,6 +3,8 @@ * RDP6 Planar Codec * * Copyright 2013 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,16 +75,16 @@ typedef struct _RDP6_BITMAP_STREAM RDP6_BITMAP_STREAM; struct _BITMAP_PLANAR_CONTEXT { - int maxWidth; - int maxHeight; - int maxPlaneSize; + UINT32 maxWidth; + UINT32 maxHeight; + UINT32 maxPlaneSize; BOOL AllowSkipAlpha; BOOL AllowRunLengthEncoding; BOOL AllowColorSubsampling; BOOL AllowDynamicColorFidelity; - int ColorLossLevel; + UINT32 ColorLossLevel; BYTE* planes[4]; BYTE* planesBuffer; @@ -92,33 +94,43 @@ struct _BITMAP_PLANAR_CONTEXT BYTE* rlePlanes[4]; BYTE* rlePlanesBuffer; - - UINT32 TempSize; - BYTE* TempBuffer; }; #ifdef __cplusplus - extern "C" { +extern "C" { #endif -FREERDP_API int freerdp_split_color_planes(BYTE* data, UINT32 format, int width, int height, int scanline, BYTE* planes[4]); -FREERDP_API BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* plane, int width, int height, BYTE* outPlane, int* dstSize); -FREERDP_API BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int height, BYTE* outPlane); -FREERDP_API BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes[4]); +FREERDP_API BYTE* freerdp_bitmap_planar_compress_plane_rle( + const BYTE* plane, UINT32 width, UINT32 height, + BYTE* outPlane, UINT32* dstSize); +FREERDP_API BYTE* freerdp_bitmap_planar_delta_encode_plane( + const BYTE* inPlane, UINT32 width, UINT32 height, BYTE* outPlane); +FREERDP_API BOOL freerdp_bitmap_planar_delta_encode_planes( + const BYTE* inPlanes[4], UINT32 width, UINT32 height, + BYTE* outPlanes[4]); -FREERDP_API BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, UINT32 format, - int width, int height, int scanline, BYTE* dstData, int* pDstSize); +FREERDP_API BYTE* freerdp_bitmap_compress_planar( + BITMAP_PLANAR_CONTEXT* context, + const BYTE* data, UINT32 format, + UINT32 width, UINT32 height, UINT32 scanline, + BYTE* dstData, UINT32* pDstSize); -FREERDP_API BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* context); +FREERDP_API BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* + context); -FREERDP_API BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWidth, int maxHeight); -FREERDP_API void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context); +FREERDP_API BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new( + DWORD flags, UINT32 maxWidth, UINT32 maxHeight); +FREERDP_API void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* + context); -FREERDP_API int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, BOOL vFlip); +FREERDP_API INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, + const BYTE* pSrcData, UINT32 SrcSize, + BYTE** ppDstData, UINT32 DstFormat, + INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, BOOL vFlip); #ifdef __cplusplus - } +} #endif #endif /* FREERDP_CODEC_PLANAR_H */ diff --git a/include/freerdp/codec/progressive.h b/include/freerdp/codec/progressive.h index cc2d75c11..c7d9d5839 100644 --- a/include/freerdp/codec/progressive.h +++ b/include/freerdp/codec/progressive.h @@ -116,10 +116,10 @@ struct _RFX_PROGRESSIVE_TILE UINT16 cbLen; UINT16 crLen; UINT16 tailLen; - BYTE* yData; - BYTE* cbData; - BYTE* crData; - BYTE* tailData; + const BYTE* yData; + const BYTE* cbData; + const BYTE* crData; + const BYTE* tailData; UINT16 ySrlLen; UINT16 yRawLen; @@ -127,21 +127,21 @@ struct _RFX_PROGRESSIVE_TILE UINT16 cbRawLen; UINT16 crSrlLen; UINT16 crRawLen; - BYTE* ySrlData; - BYTE* yRawData; - BYTE* cbSrlData; - BYTE* cbRawData; - BYTE* crSrlData; - BYTE* crRawData; + const BYTE* ySrlData; + const BYTE* yRawData; + const BYTE* cbSrlData; + const BYTE* cbRawData; + const BYTE* crSrlData; + const BYTE* crRawData; - int x; - int y; - int width; - int height; + UINT32 x; + UINT32 y; + UINT32 width; + UINT32 height; BYTE* data; BYTE* current; - int pass; + UINT16 pass; BYTE* sign; RFX_COMPONENT_CODEC_QUANT yBitPos; RFX_COMPONENT_CODEC_QUANT cbBitPos; @@ -236,8 +236,11 @@ extern "C" { FREERDP_API int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize); -FREERDP_API int progressive_decompress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, UINT16 surfaceId); +FREERDP_API UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, + const BYTE* pSrcData, UINT32 SrcSize, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT16 surfaceId); FREERDP_API int progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId, UINT32 width, UINT32 height); FREERDP_API int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId); diff --git a/include/freerdp/codec/region.h b/include/freerdp/codec/region.h index 18b947c2c..2a140bd77 100644 --- a/include/freerdp/codec/region.h +++ b/include/freerdp/codec/region.h @@ -79,7 +79,7 @@ FREERDP_API int region16_n_rects(const REGION16 *region); * @param nbRects if non-NULL returns the number of rectangles * @return a pointer on the rectangles */ -FREERDP_API const RECTANGLE_16 *region16_rects(const REGION16 *region, int *nbRects); +FREERDP_API const RECTANGLE_16 *region16_rects(const REGION16 *region, UINT32 *nbRects); /** @return the extents rectangle of this region */ FREERDP_API const RECTANGLE_16 *region16_extents(const REGION16 *region); diff --git a/include/freerdp/codec/rfx.h b/include/freerdp/codec/rfx.h index d9d5a99f8..f817def3d 100644 --- a/include/freerdp/codec/rfx.h +++ b/include/freerdp/codec/rfx.h @@ -3,6 +3,8 @@ * RemoteFX Codec * * Copyright 2011 Vic Lee + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +31,7 @@ typedef struct _RFX_CONTEXT RFX_CONTEXT; #include #include #include +#include #include @@ -55,10 +58,10 @@ struct _RFX_TILE { UINT16 x; UINT16 y; - int width; - int height; + UINT32 width; + UINT32 height; BYTE* data; - int scanline; + UINT32 scanline; BOOL allocated; BYTE quantIdxY; BYTE quantIdxCb; @@ -136,7 +139,7 @@ struct _RFX_CONTEXT UINT32 version; UINT32 codec_id; UINT32 codec_version; - RDP_PIXEL_FORMAT pixel_format; + UINT32 pixel_format; BYTE bits_per_pixel; /* color palette allocated by the application */ @@ -163,11 +166,18 @@ struct _RFX_CONTEXT RFX_CONTEXT_PRIV* priv; }; -FREERDP_API void rfx_context_set_pixel_format(RFX_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format); +FREERDP_API void rfx_context_set_pixel_format(RFX_CONTEXT* context, + UINT32 pixel_format); -FREERDP_API int rfx_rlgr_decode(const BYTE* pSrcData, UINT32 SrcSize, INT16* pDstData, UINT32 DstSize, int mode); +FREERDP_API int rfx_rlgr_decode(const BYTE* pSrcData, UINT32 SrcSize, + INT16* pDstData, UINT32 DstSize, int mode); -FREERDP_API RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length); +FREERDP_API BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, + UINT32 format, UINT32 length, + UINT32 left, UINT32 top, + BYTE* dst, UINT32 dstFormat, + UINT32 dstStride, UINT32 dstHeight, + REGION16* invalidRegion); FREERDP_API UINT16 rfx_message_get_tile_count(RFX_MESSAGE* message); FREERDP_API RFX_TILE* rfx_message_get_tile(RFX_MESSAGE* message, int index); FREERDP_API UINT16 rfx_message_get_rect_count(RFX_MESSAGE* message); @@ -175,15 +185,21 @@ FREERDP_API RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* message, int index); FREERDP_API void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message); FREERDP_API BOOL rfx_compose_message(RFX_CONTEXT* context, wStream* s, - const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height, int rowstride); + const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height, + int rowstride); -FREERDP_API RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, - int numRects, BYTE* data, int width, int height, int scanline); -FREERDP_API RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects, int numRects, - BYTE* data, int width, int height, int scanline, int* numMessages, int maxDataSize); -FREERDP_API BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message); +FREERDP_API RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, + const RFX_RECT* rects, + int numRects, BYTE* data, int width, int height, int scanline); +FREERDP_API RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, + const RFX_RECT* rects, int numRects, + BYTE* data, int width, int height, int scanline, int* numMessages, + int maxDataSize); +FREERDP_API BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, + RFX_MESSAGE* message); -FREERDP_API BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, UINT32 height); +FREERDP_API BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, + UINT32 height); FREERDP_API RFX_CONTEXT* rfx_context_new(BOOL encoder); FREERDP_API void rfx_context_free(RFX_CONTEXT* context); diff --git a/include/freerdp/constants.h b/include/freerdp/constants.h index 24517f7ce..50c3f7aef 100644 --- a/include/freerdp/constants.h +++ b/include/freerdp/constants.h @@ -32,22 +32,6 @@ enum RDP_CODEC_ID RDP_CODEC_ID_IMAGE_REMOTEFX = 0x04 }; -/** - * Pixel format - */ -enum RDP_PIXEL_FORMAT -{ - RDP_PIXEL_FORMAT_B8G8R8A8, - RDP_PIXEL_FORMAT_R8G8B8A8, - RDP_PIXEL_FORMAT_B8G8R8, - RDP_PIXEL_FORMAT_R8G8B8, - RDP_PIXEL_FORMAT_B5G6R5_LE, - RDP_PIXEL_FORMAT_R5G6B5_LE, - RDP_PIXEL_FORMAT_P4_PLANER, - RDP_PIXEL_FORMAT_P8 -}; -typedef enum RDP_PIXEL_FORMAT RDP_PIXEL_FORMAT; - /** * CPU Optimization flags */ diff --git a/include/freerdp/gdi/16bpp.h b/include/freerdp/gdi/16bpp.h deleted file mode 100644 index 8193c86fe..000000000 --- a/include/freerdp/gdi/16bpp.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI 16bpp Internal Buffer Routines - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_GDI_16BPP_H -#define FREERDP_GDI_16BPP_H - -#include -#include -#include - -typedef BOOL (*pLineTo_16bpp)(HGDI_DC hdc, int nXEnd, int nYEnd); - -#ifdef __cplusplus - extern "C" { -#endif - -FREERDP_API UINT16 gdi_get_color_16bpp(HGDI_DC hdc, GDI_COLOR color); - -FREERDP_API BOOL FillRect_16bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr); -FREERDP_API BOOL BitBlt_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop); -FREERDP_API BOOL PatBlt_16bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop); -FREERDP_API BOOL LineTo_16bpp(HGDI_DC hdc, int nXEnd, int nYEnd); - -#ifdef __cplusplus - } -#endif - -#endif /* FREERDP_GDI_16BPP_H */ diff --git a/include/freerdp/gdi/32bpp.h b/include/freerdp/gdi/32bpp.h deleted file mode 100644 index 89a39863c..000000000 --- a/include/freerdp/gdi/32bpp.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI 32bpp Internal Buffer Routines - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_GDI_32BPP_H -#define FREERDP_GDI_32BPP_H - -#include -#include -#include - -typedef BOOL (*pLineTo_32bpp)(HGDI_DC hdc, int nXEnd, int nYEnd); - -#ifdef __cplusplus - extern "C" { -#endif - -FREERDP_API UINT32 gdi_get_color_32bpp(HGDI_DC hdc, GDI_COLOR color); - -FREERDP_API BOOL FillRect_32bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr); -FREERDP_API BOOL BitBlt_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop); -FREERDP_API BOOL PatBlt_32bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop); -FREERDP_API BOOL LineTo_32bpp(HGDI_DC hdc, int nXEnd, int nYEnd); - -#ifdef __cplusplus - } -#endif - -#endif /* FREERDP_GDI_32BPP_H */ diff --git a/include/freerdp/gdi/8bpp.h b/include/freerdp/gdi/8bpp.h deleted file mode 100644 index 52f09bf87..000000000 --- a/include/freerdp/gdi/8bpp.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI 8bpp Internal Buffer Routines - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_GDI_8BPP_H -#define FREERDP_GDI_8BPP_H - -#include -#include -#include - -typedef BOOL (*pLineTo_8bpp)(HGDI_DC hdc, int nXEnd, int nYEnd); - -#ifdef __cplusplus - extern "C" { -#endif - -FREERDP_API BYTE gdi_get_color_8bpp(HGDI_DC hdc, GDI_COLOR color); - -FREERDP_API BOOL FillRect_8bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr); -FREERDP_API BOOL BitBlt_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop); -FREERDP_API BOOL PatBlt_8bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop); -FREERDP_API BOOL LineTo_8bpp(HGDI_DC hdc, int nXEnd, int nYEnd); - -#ifdef __cplusplus - } -#endif - -#endif /* FREERDP_GDI_8BPP_H */ diff --git a/include/freerdp/gdi/bitmap.h b/include/freerdp/gdi/bitmap.h index d1165e0e6..8309ff7ca 100644 --- a/include/freerdp/gdi/bitmap.h +++ b/include/freerdp/gdi/bitmap.h @@ -3,6 +3,8 @@ * GDI Bitmap Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,31 +26,32 @@ #include #ifdef __cplusplus - extern "C" { +extern "C" { #endif -FREERDP_API GDI_COLOR gdi_GetPixel(HGDI_DC hdc, int nXPos, int nYPos); -FREERDP_API GDI_COLOR gdi_SetPixel(HGDI_DC hdc, int X, int Y, GDI_COLOR crColor); -FREERDP_API BYTE gdi_GetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y); -FREERDP_API UINT16 gdi_GetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y); -FREERDP_API UINT32 gdi_GetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y); -FREERDP_API BYTE* gdi_GetPointer_8bpp(HGDI_BITMAP hBmp, int X, int Y); -FREERDP_API UINT16* gdi_GetPointer_16bpp(HGDI_BITMAP hBmp, int X, int Y); -FREERDP_API UINT32* gdi_GetPointer_32bpp(HGDI_BITMAP hBmp, int X, int Y); -FREERDP_API void gdi_SetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y, BYTE pixel); -FREERDP_API void gdi_SetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y, UINT16 pixel); -FREERDP_API void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, UINT32 pixel); -FREERDP_API HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, - BYTE* data); -FREERDP_API HGDI_BITMAP gdi_CreateBitmapEx(int nWidth, int nHeight, int cBitsPerPixel, - BYTE* data, void (*fkt_free)(void*)); -FREERDP_API HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight); -FREERDP_API BOOL gdi_BitBlt(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop); +FREERDP_API UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos); +FREERDP_API UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y, + UINT32 crColor); +FREERDP_API BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y); -typedef BOOL (*p_BitBlt)(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop); +FREERDP_API HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight, + UINT32 format, BYTE* data); +FREERDP_API HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, + UINT32 format, UINT32 stride, + BYTE* data, void (*fkt_free)(void*)); +FREERDP_API HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, + UINT32 nWidth, UINT32 nHeight); + +FREERDP_API BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc, DWORD rop); + +typedef BOOL (*p_BitBlt)(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc, DWORD rop); #ifdef __cplusplus - } +} #endif #endif /* FREERDP_GDI_BITMAP_H */ diff --git a/include/freerdp/gdi/brush.h b/include/freerdp/gdi/brush.h deleted file mode 100644 index 6817c3949..000000000 --- a/include/freerdp/gdi/brush.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI Brush Functions - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_GDI_BRUSH_H -#define FREERDP_GDI_BRUSH_H - -#include -#include - -#ifdef __cplusplus - extern "C" { -#endif - -FREERDP_API HGDI_BRUSH gdi_CreateSolidBrush(GDI_COLOR crColor); -FREERDP_API HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp); -FREERDP_API HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp); -FREERDP_API BOOL gdi_PatBlt(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop); - -#ifdef __cplusplus - } -#endif - -typedef BOOL (*p_PatBlt)(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop); - -#endif /* FREERDP_GDI_BRUSH_H */ diff --git a/include/freerdp/gdi/dc.h b/include/freerdp/gdi/dc.h index ceca9d0b5..f11d65581 100644 --- a/include/freerdp/gdi/dc.h +++ b/include/freerdp/gdi/dc.h @@ -3,6 +3,8 @@ * GDI Device Context Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +30,7 @@ #endif FREERDP_API HGDI_DC gdi_GetDC(void); -FREERDP_API HGDI_DC gdi_CreateDC(UINT32 flags, int bpp); +FREERDP_API HGDI_DC gdi_CreateDC(UINT32 format); FREERDP_API HGDI_DC gdi_CreateCompatibleDC(HGDI_DC hdc); FREERDP_API HGDIOBJECT gdi_SelectObject(HGDI_DC hdc, HGDIOBJECT hgdiobject); FREERDP_API BOOL gdi_DeleteObject(HGDIOBJECT hgdiobject); diff --git a/include/freerdp/gdi/gdi.h b/include/freerdp/gdi/gdi.h index 592c8252a..ee296eacc 100644 --- a/include/freerdp/gdi/gdi.h +++ b/include/freerdp/gdi/gdi.h @@ -3,6 +3,8 @@ * GDI Library * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,17 +144,13 @@ struct _GDIOBJECT typedef struct _GDIOBJECT GDIOBJECT; typedef GDIOBJECT* HGDIOBJECT; -/* RGB encoded as 0x00BBGGRR */ -typedef unsigned int GDI_COLOR; -typedef GDI_COLOR* LPGDI_COLOR; - struct _GDI_RECT { BYTE objectType; - int left; - int top; - int right; - int bottom; + UINT32 left; + UINT32 top; + UINT32 right; + UINT32 bottom; }; typedef struct _GDI_RECT GDI_RECT; typedef GDI_RECT* HGDI_RECT; @@ -160,11 +158,11 @@ typedef GDI_RECT* HGDI_RECT; struct _GDI_RGN { BYTE objectType; - int x; /* left */ - int y; /* top */ - int w; /* width */ - int h; /* height */ - int null; /* null region */ + UINT32 x; /* left */ + UINT32 y; /* top */ + UINT32 w; /* width */ + UINT32 h; /* height */ + BOOL null; /* null region */ }; typedef struct _GDI_RGN GDI_RGN; typedef GDI_RGN* HGDI_RGN; @@ -172,13 +170,12 @@ typedef GDI_RGN* HGDI_RGN; struct _GDI_BITMAP { BYTE objectType; - int bytesPerPixel; - int bitsPerPixel; - int width; - int height; - int scanline; + UINT32 format; + UINT32 width; + UINT32 height; + UINT32 scanline; BYTE* data; - void (*free)(void *); + void (*free)(void*); }; typedef struct _GDI_BITMAP GDI_BITMAP; typedef GDI_BITMAP* HGDI_BITMAP; @@ -186,11 +183,12 @@ typedef GDI_BITMAP* HGDI_BITMAP; struct _GDI_PEN { BYTE objectType; - int style; - int width; - int posX; - int posY; - GDI_COLOR color; + UINT32 style; + UINT32 width; + UINT32 posX; + UINT32 posY; + UINT32 color; + UINT32 format; }; typedef struct _GDI_PEN GDI_PEN; typedef GDI_PEN* HGDI_PEN; @@ -206,15 +204,15 @@ typedef struct _GDI_PALETTEENTRY GDI_PALETTEENTRY; struct _GDI_PALETTE { UINT16 count; - GDI_PALETTEENTRY *entries; + GDI_PALETTEENTRY* entries; }; typedef struct _GDI_PALETTE GDI_PALETTE; typedef GDI_PALETTE* HGDI_PALETTE; struct _GDI_POINT { - int x; - int y; + UINT32 x; + UINT32 y; }; typedef struct _GDI_POINT GDI_POINT; typedef GDI_POINT* HGDI_POINT; @@ -224,17 +222,17 @@ struct _GDI_BRUSH BYTE objectType; int style; HGDI_BITMAP pattern; - GDI_COLOR color; - int nXOrg; - int nYOrg; + UINT32 color; + UINT32 nXOrg; + UINT32 nYOrg; }; typedef struct _GDI_BRUSH GDI_BRUSH; typedef GDI_BRUSH* HGDI_BRUSH; struct _GDI_WND { - int count; - int ninvalid; + UINT32 count; + INT32 ninvalid; HGDI_RGN invalid; HGDI_RGN cinvalid; }; @@ -244,19 +242,15 @@ typedef GDI_WND* HGDI_WND; struct _GDI_DC { HGDIOBJECT selectedObject; - int bytesPerPixel; - int bitsPerPixel; - GDI_COLOR bkColor; - GDI_COLOR textColor; + UINT32 format; + UINT32 bkColor; + UINT32 textColor; HGDI_BRUSH brush; HGDI_RGN clip; HGDI_PEN pen; HGDI_WND hwnd; - int drawMode; - int bkMode; - int alpha; - int invert; - int rgb555; + UINT32 drawMode; + UINT32 bkMode; }; typedef struct _GDI_DC GDI_DC; typedef GDI_DC* HGDI_DC; @@ -285,27 +279,24 @@ struct rdp_gdi { rdpContext* context; - int width; - int height; - int dstBpp; - int srcBpp; - int cursor_x; - int cursor_y; - int bytesPerPixel; + UINT32 width; + UINT32 height; + UINT32 stride; + UINT32 dstFormat; + UINT32 cursor_x; + UINT32 cursor_y; rdpCodecs* codecs; - BOOL invert; HGDI_DC hdc; - UINT32 format; gdiBitmap* primary; gdiBitmap* drawing; UINT32 bitmap_size; BYTE* bitmap_buffer; BYTE* primary_buffer; - GDI_COLOR textColor; - BYTE palette[256 * 4]; - gdiBitmap* tile; + UINT32 textColor; + UINT32 palette[256]; gdiBitmap* image; + void (*free)(void*); BOOL inGfxFrame; BOOL graphicsReset; @@ -322,9 +313,14 @@ FREERDP_API DWORD gdi_rop3_code(BYTE code); FREERDP_API UINT32 gdi_get_pixel_format(UINT32 bitsPerPixel, BOOL vFlip); FREERDP_API BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, int x, int y); FREERDP_API BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, int x, int y); -FREERDP_API BOOL gdi_resize(rdpGdi* gdi, int width, int height); - -FREERDP_API BOOL gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer); +FREERDP_API BOOL gdi_resize(rdpGdi* gdi, UINT32 width, UINT32 height); +FREERDP_API BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, + INT32 stride, INT32 format, BYTE* buffer, + void (*pfree)(void*)); +FREERDP_API BOOL gdi_init(freerdp* instance, UINT32 format); +FREERDP_API BOOL gdi_init_ex(freerdp* instance, UINT32 format, + UINT32 stride, BYTE* buffer, + void (*pfree)(void*)); FREERDP_API void gdi_free(freerdp* instance); #ifdef __cplusplus diff --git a/include/freerdp/gdi/gfx.h b/include/freerdp/gdi/gfx.h index 706608515..a03490e31 100644 --- a/include/freerdp/gdi/gfx.h +++ b/include/freerdp/gdi/gfx.h @@ -29,9 +29,8 @@ struct gdi_gfx_surface rdpCodecs* codecs; UINT32 width; UINT32 height; - BOOL alpha; BYTE* data; - int scanline; + UINT32 scanline; UINT32 format; BOOL outputMapped; UINT32 outputOriginX; @@ -45,9 +44,8 @@ struct gdi_gfx_cache_entry UINT64 cacheKey; UINT32 width; UINT32 height; - BOOL alpha; BYTE* data; - int scanline; + UINT32 scanline; UINT32 format; }; typedef struct gdi_gfx_cache_entry gdiGfxCacheEntry; diff --git a/include/freerdp/gdi/palette.h b/include/freerdp/gdi/palette.h deleted file mode 100644 index bca284977..000000000 --- a/include/freerdp/gdi/palette.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI Palette Functions - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_GDI_PALETTE_H -#define FREERDP_GDI_PALETTE_H - -#include -#include - -#ifdef __cplusplus - extern "C" { -#endif - -FREERDP_API HGDI_PALETTE gdi_CreatePalette(HGDI_PALETTE palette); -FREERDP_API HGDI_PALETTE gdi_GetSystemPalette(void); - -#ifdef __cplusplus - } -#endif - -#endif /* FREERDP_GDI_PALETTE_H */ diff --git a/include/freerdp/gdi/pen.h b/include/freerdp/gdi/pen.h index c4b5a7e59..a1e69d443 100644 --- a/include/freerdp/gdi/pen.h +++ b/include/freerdp/gdi/pen.h @@ -27,10 +27,9 @@ extern "C" { #endif -FREERDP_API HGDI_PEN gdi_CreatePen(int fnPenStyle, int nWidth, int crColor); -FREERDP_API BYTE gdi_GetPenColor_8bpp(HGDI_PEN pen); -FREERDP_API UINT16 gdi_GetPenColor_16bpp(HGDI_PEN pen); -FREERDP_API UINT32 gdi_GetPenColor_32bpp(HGDI_PEN pen); +FREERDP_API HGDI_PEN gdi_CreatePen(UINT32 fnPenStyle, UINT32 nWidth, + UINT32 crColor, UINT32 format); +FREERDP_API UINT32 gdi_GetPenColor(HGDI_PEN pen, UINT32 format); #ifdef __cplusplus } diff --git a/include/freerdp/gdi/region.h b/include/freerdp/gdi/region.h index 8ef56aa8c..26381ef1f 100644 --- a/include/freerdp/gdi/region.h +++ b/include/freerdp/gdi/region.h @@ -3,6 +3,8 @@ * GDI Region Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,24 +29,37 @@ extern "C" { #endif -FREERDP_API HGDI_RGN gdi_CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); -FREERDP_API HGDI_RECT gdi_CreateRect(int xLeft, int yTop, int xRight, int yBottom); +FREERDP_API HGDI_RGN gdi_CreateRectRgn(UINT32 nLeftRect, UINT32 nTopRect, + UINT32 nRightRect, UINT32 nBottomRect); +FREERDP_API HGDI_RECT gdi_CreateRect(UINT32 xLeft, UINT32 yTop, + UINT32 xRight, UINT32 yBottom); FREERDP_API void gdi_RectToRgn(HGDI_RECT rect, HGDI_RGN rgn); -FREERDP_API void gdi_CRectToRgn(int left, int top, int right, int bottom, HGDI_RGN rgn); -FREERDP_API void gdi_RectToCRgn(HGDI_RECT rect, int *x, int *y, int *w, int *h); -FREERDP_API void gdi_CRectToCRgn(int left, int top, int right, int bottom, int *x, int *y, int *w, int *h); +FREERDP_API void gdi_CRectToRgn(UINT32 left, UINT32 top, + UINT32 right, UINT32 bottom, HGDI_RGN rgn); +FREERDP_API void gdi_RectToCRgn(const HGDI_RECT rect, UINT32 *x, UINT32 *y, + UINT32 *w, UINT32 *h); +FREERDP_API void gdi_CRectToCRgn(UINT32 left, UINT32 top, + UINT32 right, UINT32 bottom, + UINT32 *x, UINT32 *y, UINT32 *w, UINT32 *h); FREERDP_API void gdi_RgnToRect(HGDI_RGN rgn, HGDI_RECT rect); -FREERDP_API void gdi_CRgnToRect(int x, int y, int w, int h, HGDI_RECT rect); -FREERDP_API void gdi_RgnToCRect(HGDI_RGN rgn, int *left, int *top, int *right, int *bottom); -FREERDP_API void gdi_CRgnToCRect(int x, int y, int w, int h, int *left, int *top, int *right, int *bottom); -FREERDP_API BOOL gdi_CopyOverlap(int x, int y, int width, int height, int srcx, int srcy); -FREERDP_API BOOL gdi_SetRect(HGDI_RECT rc, int xLeft, int yTop, int xRight, int yBottom); -FREERDP_API BOOL gdi_SetRgn(HGDI_RGN hRgn, int nXLeft, int nYLeft, int nWidth, int nHeight); -FREERDP_API BOOL gdi_SetRectRgn(HGDI_RGN hRgn, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); +FREERDP_API void gdi_CRgnToRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h, HGDI_RECT rect); +FREERDP_API void gdi_RgnToCRect(HGDI_RGN rgn, UINT32 *left, + UINT32 *top, UINT32 *right, UINT32 *bottom); +FREERDP_API void gdi_CRgnToCRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h, + UINT32 *left, UINT32 *top, UINT32 *right, UINT32 *bottom); +FREERDP_API BOOL gdi_CopyOverlap(UINT32 x, UINT32 y, UINT32 width, UINT32 height, + UINT32 srcx, UINT32 srcy); +FREERDP_API BOOL gdi_SetRect(HGDI_RECT rc, UINT32 xLeft, UINT32 yTop, + UINT32 xRight, UINT32 yBottom); +FREERDP_API BOOL gdi_SetRgn(HGDI_RGN hRgn, UINT32 nXLeft, UINT32 nYLeft, + UINT32 nWidth, UINT32 nHeight); +FREERDP_API BOOL gdi_SetRectRgn(HGDI_RGN hRgn, UINT32 nLeftRect, UINT32 nTopRect, + UINT32 nRightRect, UINT32 nBottomRect); FREERDP_API BOOL gdi_EqualRgn(HGDI_RGN hSrcRgn1, HGDI_RGN hSrcRgn2); FREERDP_API BOOL gdi_CopyRect(HGDI_RECT dst, HGDI_RECT src); -FREERDP_API BOOL gdi_PtInRect(HGDI_RECT rc, int x, int y); -FREERDP_API BOOL gdi_InvalidateRegion(HGDI_DC hdc, int x, int y, int w, int h); +FREERDP_API BOOL gdi_PtInRect(HGDI_RECT rc, UINT32 x, UINT32 y); +FREERDP_API BOOL gdi_InvalidateRegion(HGDI_DC hdc, UINT32 x, UINT32 y, + UINT32 w, UINT32 h); #ifdef __cplusplus } diff --git a/include/freerdp/gdi/shape.h b/include/freerdp/gdi/shape.h index 95bbbe567..0f50d52ac 100644 --- a/include/freerdp/gdi/shape.h +++ b/include/freerdp/gdi/shape.h @@ -28,7 +28,7 @@ #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, HGDI_RECT rect, HGDI_BRUSH hbr); +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); diff --git a/include/freerdp/graphics.h b/include/freerdp/graphics.h index 90c22e1c4..14effaa90 100644 --- a/include/freerdp/graphics.h +++ b/include/freerdp/graphics.h @@ -3,6 +3,8 @@ * Graphical Objects * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,40 +36,40 @@ extern "C" { #endif /* Bitmap Class */ - typedef BOOL (*pBitmap_New)(rdpContext* context, rdpBitmap* bitmap); typedef void (*pBitmap_Free)(rdpContext* context, rdpBitmap* bitmap); typedef BOOL (*pBitmap_Paint)(rdpContext* context, rdpBitmap* bitmap); typedef BOOL (*pBitmap_Decompress)(rdpContext* context, rdpBitmap* bitmap, - BYTE* data, int width, int height, int bpp, int length, - BOOL compressed, int codec_id); + const BYTE* data, UINT32 width, UINT32 height, + UINT32 bpp, UINT32 length, BOOL compressed, + UINT32 codec_id); typedef BOOL (*pBitmap_SetSurface)(rdpContext* context, rdpBitmap* bitmap, BOOL primary); struct rdp_bitmap { - size_t size; /* 0 */ - pBitmap_New New; /* 1 */ - pBitmap_Free Free; /* 2 */ - pBitmap_Paint Paint; /* 3 */ - pBitmap_Decompress Decompress; /* 4 */ - pBitmap_SetSurface SetSurface; /* 5 */ - UINT32 paddingA[16 - 6]; /* 6 */ + size_t size; /* 0 */ + pBitmap_New New; /* 1 */ + pBitmap_Free Free; /* 2 */ + pBitmap_Paint Paint; /* 3 */ + pBitmap_Decompress Decompress; /* 4 */ + pBitmap_SetSurface SetSurface; /* 5 */ + UINT32 paddingA[16 - 6]; /* 6 */ - UINT32 left; /* 16 */ - UINT32 top; /* 17 */ - UINT32 right; /* 18 */ - UINT32 bottom; /* 19 */ - UINT32 width; /* 20 */ - UINT32 height; /* 21 */ - UINT32 bpp; /* 22 */ - UINT32 flags; /* 23 */ - UINT32 length; /* 24 */ - BYTE* data; /* 25 */ - UINT32 paddingB[32 - 26]; /* 26 */ + UINT32 left; /* 16 */ + UINT32 top; /* 17 */ + UINT32 right; /* 18 */ + UINT32 bottom; /* 19 */ + UINT32 width; /* 20 */ + UINT32 height; /* 21 */ + UINT32 bpp; /* 22 */ + UINT32 flags; /* 23 */ + UINT32 length; /* 24 */ + BYTE* data; /* 25 */ + UINT32 paddingB[32 - 26]; /* 26 */ - BOOL compressed; /* 32 */ - BOOL ephemeral; /* 33 */ - UINT32 paddingC[64 - 34]; /* 34 */ + BOOL compressed; /* 32 */ + BOOL ephemeral; /* 33 */ + UINT32 paddingC[64 - 34]; /* 34 */ }; FREERDP_API rdpBitmap* Bitmap_Alloc(rdpContext* context); @@ -75,9 +77,9 @@ FREERDP_API BOOL Bitmap_New(rdpContext* context, rdpBitmap* bitmap); FREERDP_API void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap); FREERDP_API BOOL Bitmap_Register(rdpContext* context, rdpBitmap* bitmap); FREERDP_API BOOL Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, - BYTE* data, int width, int height, int bpp, int length, BOOL compressed); + BYTE* data, int width, int height, int bpp, int length, BOOL compressed); FREERDP_API void Bitmap_SetRectangle(rdpContext* context, rdpBitmap* bitmap, - UINT16 left, UINT16 top, UINT16 right, UINT16 bottom); + UINT16 left, UINT16 top, UINT16 right, UINT16 bottom); FREERDP_API void Bitmap_SetDimensions(rdpContext* context, rdpBitmap* bitmap, UINT16 width, UINT16 height); FREERDP_API BOOL Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary); @@ -85,67 +87,69 @@ FREERDP_API BOOL Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL typedef BOOL (*pPointer_New)(rdpContext* context, rdpPointer* pointer); typedef void (*pPointer_Free)(rdpContext* context, rdpPointer* pointer); -typedef BOOL (*pPointer_Set)(rdpContext* context, rdpPointer* pointer); +typedef BOOL (*pPointer_Set)(rdpContext* context, const rdpPointer* pointer); typedef BOOL (*pPointer_SetNull)(rdpContext* context); typedef BOOL (*pPointer_SetDefault)(rdpContext* context); typedef BOOL (*pPointer_SetPosition)(rdpContext* context, UINT32 x, UINT32 y); struct rdp_pointer { - size_t size; /* 0 */ - pPointer_New New; /* 1 */ - pPointer_Free Free; /* 2 */ - pPointer_Set Set; /* 3 */ - pPointer_SetNull SetNull; /* 4*/ - pPointer_SetDefault SetDefault; /* 5 */ - pPointer_SetPosition SetPosition; /* 6 */ - UINT32 paddingA[16 - 7]; /* 7 */ + size_t size; /* 0 */ + pPointer_New New; /* 1 */ + pPointer_Free Free; /* 2 */ + pPointer_Set Set; /* 3 */ + pPointer_SetNull SetNull; /* 4*/ + pPointer_SetDefault SetDefault; /* 5 */ + pPointer_SetPosition SetPosition; /* 6 */ + UINT32 paddingA[16 - 7]; /* 7 */ - UINT32 xPos; /* 16 */ - UINT32 yPos; /* 17 */ - UINT32 width; /* 18 */ - UINT32 height; /* 19 */ - UINT32 xorBpp; /* 20 */ - UINT32 lengthAndMask; /* 21 */ - UINT32 lengthXorMask; /* 22 */ - BYTE* xorMaskData; /* 23 */ - BYTE* andMaskData; /* 24 */ - UINT32 paddingB[32 - 25]; /* 25 */ + UINT32 xPos; /* 16 */ + UINT32 yPos; /* 17 */ + UINT32 width; /* 18 */ + UINT32 height; /* 19 */ + UINT32 xorBpp; /* 20 */ + UINT32 lengthAndMask; /* 21 */ + UINT32 lengthXorMask; /* 22 */ + BYTE* xorMaskData; /* 23 */ + BYTE* andMaskData; /* 24 */ + UINT32 paddingB[32 - 25]; /* 25 */ }; FREERDP_API rdpPointer* Pointer_Alloc(rdpContext* context); FREERDP_API BOOL Pointer_New(rdpContext* context, rdpPointer* pointer); FREERDP_API void Pointer_Free(rdpContext* context, rdpPointer* pointer); -FREERDP_API BOOL Pointer_Set(rdpContext* context, rdpPointer* pointer); +FREERDP_API BOOL Pointer_Set(rdpContext* context, const rdpPointer* pointer); FREERDP_API BOOL Pointer_SetNull(rdpContext* context); FREERDP_API BOOL Pointer_SetDefault(rdpContext* context); FREERDP_API BOOL Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y); /* Glyph Class */ - typedef BOOL (*pGlyph_New)(rdpContext* context, rdpGlyph* glyph); typedef void (*pGlyph_Free)(rdpContext* context, rdpGlyph* glyph); -typedef BOOL (*pGlyph_Draw)(rdpContext* context, rdpGlyph* glyph, int x, int y); -typedef BOOL (*pGlyph_BeginDraw)(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant); -typedef BOOL (*pGlyph_EndDraw)(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor); +typedef BOOL (*pGlyph_Draw)(rdpContext* context, rdpGlyph* glyph, UINT32 x, UINT32 y); +typedef BOOL (*pGlyph_BeginDraw)(rdpContext* context, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 bgcolor, + UINT32 fgcolor, BOOL fOpRedundant); +typedef BOOL (*pGlyph_EndDraw)(rdpContext* context, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 bgcolor, UINT32 fgcolor); struct rdp_glyph { - size_t size; /* 0 */ - pGlyph_New New; /* 1 */ - pGlyph_Free Free; /* 2 */ - pGlyph_Draw Draw; /* 3 */ - pGlyph_BeginDraw BeginDraw; /* 4 */ - pGlyph_EndDraw EndDraw; /* 5 */ - UINT32 paddingA[16 - 6]; /* 6 */ + size_t size; /* 0 */ + pGlyph_New New; /* 1 */ + pGlyph_Free Free; /* 2 */ + pGlyph_Draw Draw; /* 3 */ + pGlyph_BeginDraw BeginDraw; /* 4 */ + pGlyph_EndDraw EndDraw; /* 5 */ + UINT32 paddingA[16 - 6]; /* 6 */ - INT32 x; /* 16 */ - INT32 y; /* 17 */ - UINT32 cx; /* 18 */ - UINT32 cy; /* 19 */ - UINT32 cb; /* 20 */ - BYTE* aj; /* 21 */ - UINT32 paddingB[32 - 22]; /* 22 */ + INT32 x; /* 16 */ + INT32 y; /* 17 */ + UINT32 cx; /* 18 */ + UINT32 cy; /* 19 */ + UINT32 cb; /* 20 */ + BYTE* aj; /* 21 */ + UINT32 paddingB[32 - 22]; /* 22 */ }; FREERDP_API rdpGlyph* Glyph_Alloc(rdpContext* context); @@ -159,11 +163,11 @@ FREERDP_API BOOL Glyph_EndDraw(rdpContext* context, int x, int y, int width, int struct rdp_graphics { - rdpContext* context; /* 0 */ - rdpBitmap* Bitmap_Prototype; /* 1 */ - rdpPointer* Pointer_Prototype; /* 2 */ - rdpGlyph* Glyph_Prototype; /* 3 */ - UINT32 paddingA[16 - 4]; /* 4 */ + rdpContext* context; /* 0 */ + rdpBitmap* Bitmap_Prototype; /* 1 */ + rdpPointer* Pointer_Prototype; /* 2 */ + rdpGlyph* Glyph_Prototype; /* 3 */ + UINT32 paddingA[16 - 4]; /* 4 */ }; FREERDP_API void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap); diff --git a/include/freerdp/pointer.h b/include/freerdp/pointer.h index 65759b4e9..8fc340efb 100644 --- a/include/freerdp/pointer.h +++ b/include/freerdp/pointer.h @@ -71,11 +71,16 @@ struct _POINTER_CACHED_UPDATE }; typedef struct _POINTER_CACHED_UPDATE POINTER_CACHED_UPDATE; -typedef BOOL (*pPointerPosition)(rdpContext* context, POINTER_POSITION_UPDATE* pointer_position); -typedef BOOL (*pPointerSystem)(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer_system); -typedef BOOL (*pPointerColor)(rdpContext* context, POINTER_COLOR_UPDATE* pointer_color); -typedef BOOL (*pPointerNew)(rdpContext* context, POINTER_NEW_UPDATE* pointer_new); -typedef BOOL (*pPointerCached)(rdpContext* context, POINTER_CACHED_UPDATE* pointer_cached); +typedef BOOL (*pPointerPosition)(rdpContext* context, + const POINTER_POSITION_UPDATE* pointer_position); +typedef BOOL (*pPointerSystem)(rdpContext* context, + const POINTER_SYSTEM_UPDATE* pointer_system); +typedef BOOL (*pPointerColor)(rdpContext* context, + const POINTER_COLOR_UPDATE* pointer_color); +typedef BOOL (*pPointerNew)(rdpContext* context, + const POINTER_NEW_UPDATE* pointer_new); +typedef BOOL (*pPointerCached)(rdpContext* context, + const POINTER_CACHED_UPDATE* pointer_cached); struct rdp_pointer_update { diff --git a/include/freerdp/primary.h b/include/freerdp/primary.h index 2897a4d22..78722e545 100644 --- a/include/freerdp/primary.h +++ b/include/freerdp/primary.h @@ -438,28 +438,35 @@ struct _ELLIPSE_CB_ORDER }; typedef struct _ELLIPSE_CB_ORDER ELLIPSE_CB_ORDER; -typedef BOOL (*pDstBlt)(rdpContext* context, DSTBLT_ORDER* dstblt); +typedef BOOL (*pDstBlt)(rdpContext* context, const DSTBLT_ORDER* dstblt); typedef BOOL (*pPatBlt)(rdpContext* context, PATBLT_ORDER* patblt); -typedef BOOL (*pScrBlt)(rdpContext* context, SCRBLT_ORDER* scrblt); -typedef BOOL (*pOpaqueRect)(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect); -typedef BOOL (*pDrawNineGrid)(rdpContext* context, DRAW_NINE_GRID_ORDER* draw_nine_grid); -typedef BOOL (*pMultiDstBlt)(rdpContext* context, MULTI_DSTBLT_ORDER* multi_dstblt); -typedef BOOL (*pMultiPatBlt)(rdpContext* context, MULTI_PATBLT_ORDER* multi_patblt); -typedef BOOL (*pMultiScrBlt)(rdpContext* context, MULTI_SCRBLT_ORDER* multi_scrblt); -typedef BOOL (*pMultiOpaqueRect)(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); -typedef BOOL (*pMultiDrawNineGrid)(rdpContext* context, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); -typedef BOOL (*pLineTo)(rdpContext* context, LINE_TO_ORDER* line_to); -typedef BOOL (*pPolyline)(rdpContext* context, POLYLINE_ORDER* polyline); +typedef BOOL (*pScrBlt)(rdpContext* context, const SCRBLT_ORDER* scrblt); +typedef BOOL (*pOpaqueRect)(rdpContext* context, + const OPAQUE_RECT_ORDER* opaque_rect); +typedef BOOL (*pDrawNineGrid)(rdpContext* context, + const DRAW_NINE_GRID_ORDER* draw_nine_grid); +typedef BOOL (*pMultiDstBlt)(rdpContext* context, + const MULTI_DSTBLT_ORDER* multi_dstblt); +typedef BOOL (*pMultiPatBlt)(rdpContext* context, + const MULTI_PATBLT_ORDER* multi_patblt); +typedef BOOL (*pMultiScrBlt)(rdpContext* context, + const MULTI_SCRBLT_ORDER* multi_scrblt); +typedef BOOL (*pMultiOpaqueRect)(rdpContext* context, + const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); +typedef BOOL (*pMultiDrawNineGrid)(rdpContext* context, + const MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); +typedef BOOL (*pLineTo)(rdpContext* context, const LINE_TO_ORDER* line_to); +typedef BOOL (*pPolyline)(rdpContext* context, const POLYLINE_ORDER* polyline); typedef BOOL (*pMemBlt)(rdpContext* context, MEMBLT_ORDER* memblt); typedef BOOL (*pMem3Blt)(rdpContext* context, MEM3BLT_ORDER* memblt); -typedef BOOL (*pSaveBitmap)(rdpContext* context, SAVE_BITMAP_ORDER* save_bitmap); +typedef BOOL (*pSaveBitmap)(rdpContext* context, const SAVE_BITMAP_ORDER* save_bitmap); typedef BOOL (*pGlyphIndex)(rdpContext* context, GLYPH_INDEX_ORDER* glyph_index); -typedef BOOL (*pFastIndex)(rdpContext* context, FAST_INDEX_ORDER* fast_index); -typedef BOOL (*pFastGlyph)(rdpContext* context, FAST_GLYPH_ORDER* fast_glyph); -typedef BOOL (*pPolygonSC)(rdpContext* context, POLYGON_SC_ORDER* polygon_sc); +typedef BOOL (*pFastIndex)(rdpContext* context, const FAST_INDEX_ORDER* fast_index); +typedef BOOL (*pFastGlyph)(rdpContext* context, const FAST_GLYPH_ORDER* fast_glyph); +typedef BOOL (*pPolygonSC)(rdpContext* context, const POLYGON_SC_ORDER* polygon_sc); typedef BOOL (*pPolygonCB)(rdpContext* context, POLYGON_CB_ORDER* polygon_cb); -typedef BOOL (*pEllipseSC)(rdpContext* context, ELLIPSE_SC_ORDER* ellipse_sc); -typedef BOOL (*pEllipseCB)(rdpContext* context, ELLIPSE_CB_ORDER* ellipse_cb); +typedef BOOL (*pEllipseSC)(rdpContext* context, const ELLIPSE_SC_ORDER* ellipse_sc); +typedef BOOL (*pEllipseCB)(rdpContext* context, const ELLIPSE_CB_ORDER* ellipse_cb); struct rdp_primary_update { diff --git a/include/freerdp/primitives.h b/include/freerdp/primitives.h index c6a9cb345..287c89247 100644 --- a/include/freerdp/primitives.h +++ b/include/freerdp/primitives.h @@ -22,6 +22,7 @@ #include #include +#include #include @@ -64,146 +65,145 @@ typedef struct /* Function prototypes for all of the supported primitives. */ typedef pstatus_t (*__copy_t)( - const void *pSrc, - void *pDst, - INT32 bytes); + const void* pSrc, + void* pDst, + INT32 bytes); typedef pstatus_t (*__copy_8u_t)( - const BYTE *pSrc, - BYTE *pDst, - INT32 len); + const BYTE* pSrc, + BYTE* pDst, + INT32 len); typedef pstatus_t (*__copy_8u_AC4r_t)( - const BYTE *pSrc, - INT32 srcStep, /* bytes */ - BYTE *pDst, - INT32 dstStep, /* bytes */ - INT32 width, INT32 height); /* pixels */ + const BYTE* pSrc, + INT32 srcStep, /* bytes */ + BYTE* pDst, + INT32 dstStep, /* bytes */ + INT32 width, INT32 height); /* pixels */ typedef pstatus_t (*__set_8u_t)( - BYTE val, - BYTE *pDst, - INT32 len); + BYTE val, + BYTE* pDst, + INT32 len); typedef pstatus_t (*__set_32s_t)( - INT32 val, - INT32 *pDst, - INT32 len); + INT32 val, + INT32* pDst, + INT32 len); typedef pstatus_t (*__set_32u_t)( - UINT32 val, - UINT32 *pDst, - INT32 len); + UINT32 val, + UINT32* pDst, + INT32 len); typedef pstatus_t (*__zero_t)( - void *pDst, - size_t bytes); + void* pDst, + size_t bytes); typedef pstatus_t (*__alphaComp_argb_t)( - const BYTE *pSrc1, INT32 src1Step, - const BYTE *pSrc2, INT32 src2Step, - BYTE *pDst, INT32 dstStep, - INT32 width, INT32 height); + const BYTE* pSrc1, INT32 src1Step, + const BYTE* pSrc2, INT32 src2Step, + BYTE* pDst, INT32 dstStep, + INT32 width, INT32 height); typedef pstatus_t (*__add_16s_t)( - const INT16 *pSrc1, - const INT16 *pSrc2, - INT16 *pDst, - INT32 len); + const INT16* pSrc1, + const INT16* pSrc2, + INT16* pDst, + INT32 len); typedef pstatus_t (*__lShiftC_16s_t)( - const INT16 *pSrc, - INT32 val, - INT16 *pSrcDst, - INT32 len); + const INT16* pSrc, + INT32 val, + INT16* pSrcDst, + INT32 len); typedef pstatus_t (*__lShiftC_16u_t)( - const UINT16 *pSrc, - INT32 val, - UINT16 *pSrcDst, - INT32 len); + const UINT16* pSrc, + INT32 val, + UINT16* pSrcDst, + INT32 len); typedef pstatus_t (*__rShiftC_16s_t)( - const INT16 *pSrc, - INT32 val, - INT16 *pSrcDst, - INT32 len); + const INT16* pSrc, + INT32 val, + INT16* pSrcDst, + INT32 len); typedef pstatus_t (*__rShiftC_16u_t)( - const UINT16 *pSrc, - INT32 val, - UINT16 *pSrcDst, - INT32 len); + const UINT16* pSrc, + INT32 val, + UINT16* pSrcDst, + INT32 len); typedef pstatus_t (*__shiftC_16s_t)( - const INT16 *pSrc, - INT32 val, - INT16 *pSrcDst, - INT32 len); + const INT16* pSrc, + INT32 val, + INT16* pSrcDst, + INT32 len); typedef pstatus_t (*__shiftC_16u_t)( - const UINT16 *pSrc, - INT32 val, - UINT16 *pSrcDst, - INT32 len); + const UINT16* pSrc, + INT32 val, + UINT16* pSrcDst, + INT32 len); typedef pstatus_t (*__sign_16s_t)( - const INT16 *pSrc, - INT16 *pDst, - INT32 len); + const INT16* pSrc, + INT16* pDst, + INT32 len); typedef pstatus_t (*__yCbCrToRGB_16s8u_P3AC4R_t)( - const INT16* pSrc[3], INT32 srcStep, - BYTE* pDst, INT32 dstStep, - const prim_size_t* roi); + const INT16* pSrc[3], INT32 srcStep, + BYTE* pDst, INT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi); typedef pstatus_t (*__yCbCrToBGR_16s8u_P3AC4R_t)( - const INT16* pSrc[3], INT32 srcStep, - BYTE* pDst, INT32 dstStep, - const prim_size_t* roi); + const INT16* pSrc[3], INT32 srcStep, + BYTE* pDst, INT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi); typedef pstatus_t (*__yCbCrToRGB_16s16s_P3P3_t)( - const INT16 *pSrc[3], INT32 srcStep, - INT16 *pDst[3], INT32 dstStep, - const prim_size_t *roi); + const INT16* pSrc[3], INT32 srcStep, + INT16* pDst[3], INT32 dstStep, + const prim_size_t* roi); typedef pstatus_t (*__RGBToYCbCr_16s16s_P3P3_t)( - const INT16 *pSrc[3], INT32 srcStep, - INT16 *pDst[3], INT32 dstStep, - const prim_size_t *roi); + const INT16* pSrc[3], INT32 srcStep, + INT16* pDst[3], INT32 dstStep, + const prim_size_t* roi); typedef pstatus_t (*__RGBToRGB_16s8u_P3AC4R_t)( - const INT16 *pSrc[3], INT32 srcStep, - BYTE *pDst, INT32 dstStep, - const prim_size_t *roi); + const INT16* pSrc[3], INT32 srcStep, + BYTE* pDst, INT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi); typedef pstatus_t (*__YCoCgToRGB_8u_AC4R_t)( - const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, - UINT32 width, UINT32 height, - UINT8 shift, - BOOL withAlpha, - BOOL invert); + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, UINT32 DstFormat, INT32 dstStep, + UINT32 width, UINT32 height, + UINT8 shift, + BOOL withAlpha); typedef pstatus_t (*__RGB565ToARGB_16u32u_C3C4_t)( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha, BOOL invert); + const UINT16* pSrc, INT32 srcStep, + UINT32* pDst, INT32 dstStep, + UINT32 width, UINT32 height, + UINT32 format); typedef pstatus_t (*__YUV420ToRGB_8u_P3AC4R_t)( - const BYTE* pSrc[3], const UINT32 srcStep[3], - BYTE* pDst, UINT32 dstStep, - const prim_size_t* roi); + const BYTE* pSrc[3], const UINT32 srcStep[3], + BYTE* pDst, UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi); typedef pstatus_t (*__YUV444ToRGB_8u_P3AC4R_t)( - const BYTE* pSrc[3], const UINT32 srcStep[3], - BYTE* pDst, UINT32 dstStep, - const prim_size_t* roi); + const BYTE* pSrc[3], const UINT32 srcStep[3], + BYTE* pDst, UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi); typedef pstatus_t (*__RGBToYUV420_8u_P3AC4R_t)( - const BYTE* pSrc, UINT32 srcStep, - BYTE* pDst[3], UINT32 dstStep[3], - const prim_size_t* roi); + const BYTE* pSrc, UINT32 srcStep, + BYTE* pDst[3], UINT32 dstStep[3], + const prim_size_t* roi); typedef pstatus_t (*__RGBToYUV444_8u_P3AC4R_t)( - const BYTE* pSrc, UINT32 srcStep, - BYTE* pDst[3], UINT32 dstStep[3], - const prim_size_t* roi); + const BYTE* pSrc, UINT32 srcStep, + BYTE* pDst[3], UINT32 dstStep[3], + const prim_size_t* roi); typedef pstatus_t (*__YUV420CombineToYUV444_t)( - const BYTE* pMainSrc[3], const UINT32 srcMainStep[3], - const BYTE* pAuxSrc[3], const UINT32 srcAuxStep[3], - BYTE* pDst[3], const UINT32 dstStep[3], - const prim_size_t* roi); + const BYTE* pMainSrc[3], const UINT32 srcMainStep[3], + const BYTE* pAuxSrc[3], const UINT32 srcAuxStep[3], + BYTE* pDst[3], const UINT32 dstStep[3], + const prim_size_t* roi); typedef pstatus_t (*__YUV444SplitToYUV420_t)( - const BYTE* pSrc[3], const UINT32 srcStep[3], - BYTE* pMainDst[3], const UINT32 dstMainStep[3], - BYTE* pAuxDst[3], const UINT32 srcAuxStep[3], - const prim_size_t* roi); + const BYTE* pSrc[3], const UINT32 srcStep[3], + BYTE* pMainDst[3], const UINT32 dstMainStep[3], + BYTE* pAuxDst[3], const UINT32 srcAuxStep[3], + const prim_size_t* roi); typedef pstatus_t (*__andC_32u_t)( - const UINT32 *pSrc, - UINT32 val, - UINT32 *pDst, - INT32 len); + const UINT32* pSrc, + UINT32 val, + UINT32* pDst, + INT32 len); typedef pstatus_t (*__orC_32u_t)( - const UINT32 *pSrc, - UINT32 val, - UINT32 *pDst, - INT32 len); + const UINT32* pSrc, + UINT32 val, + UINT32* pDst, + INT32 len); typedef struct { @@ -239,23 +239,20 @@ typedef struct __RGBToYCbCr_16s16s_P3P3_t RGBToYCbCr_16s16s_P3P3; __RGBToRGB_16s8u_P3AC4R_t RGBToRGB_16s8u_P3AC4R; __YCoCgToRGB_8u_AC4R_t YCoCgToRGB_8u_AC4R; - __RGB565ToARGB_16u32u_C3C4_t RGB565ToARGB_16u32u_C3C4; __YUV420ToRGB_8u_P3AC4R_t YUV420ToRGB_8u_P3AC4R; __RGBToYUV420_8u_P3AC4R_t RGBToYUV420_8u_P3AC4R; __RGBToYUV444_8u_P3AC4R_t RGBToYUV444_8u_P3AC4R; __YUV420CombineToYUV444_t YUV420CombineToYUV444; __YUV444SplitToYUV420_t YUV444SplitToYUV420; - __YUV420ToRGB_8u_P3AC4R_t YUV444ToRGB_8u_P3AC4R; + __YUV444ToRGB_8u_P3AC4R_t YUV444ToRGB_8u_P3AC4R; } primitives_t; #ifdef __cplusplus extern "C" { #endif -/* Prototypes for the externally-visible entrypoints. */ -FREERDP_API void primitives_init(void); -FREERDP_API primitives_t *primitives_get(void); -FREERDP_API void primitives_deinit(void); +FREERDP_API primitives_t* primitives_get(void); +FREERDP_API primitives_t* primitives_get_generic(void); #ifdef __cplusplus } diff --git a/include/freerdp/secondary.h b/include/freerdp/secondary.h index f42b21792..f7b3d1ba6 100644 --- a/include/freerdp/secondary.h +++ b/include/freerdp/secondary.h @@ -163,13 +163,20 @@ struct _CACHE_BRUSH_ORDER }; typedef struct _CACHE_BRUSH_ORDER CACHE_BRUSH_ORDER; -typedef BOOL (*pCacheBitmap)(rdpContext* context, CACHE_BITMAP_ORDER* cache_bitmap_order); -typedef BOOL (*pCacheBitmapV2)(rdpContext* context, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order); -typedef BOOL (*pCacheBitmapV3)(rdpContext* context, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order); -typedef BOOL (*pCacheColorTable)(rdpContext* context, CACHE_COLOR_TABLE_ORDER* cache_color_table_order); -typedef BOOL (*pCacheGlyph)(rdpContext* context, CACHE_GLYPH_ORDER* cache_glyph_order); -typedef BOOL (*pCacheGlyphV2)(rdpContext* context, CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order); -typedef BOOL (*pCacheBrush)(rdpContext* context, CACHE_BRUSH_ORDER* cache_brush_order); +typedef BOOL (*pCacheBitmap)(rdpContext* context, + const CACHE_BITMAP_ORDER* cache_bitmap_order); +typedef BOOL (*pCacheBitmapV2)(rdpContext* context, + CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order); +typedef BOOL (*pCacheBitmapV3)(rdpContext* context, + CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order); +typedef BOOL (*pCacheColorTable)(rdpContext* context, + const CACHE_COLOR_TABLE_ORDER* cache_color_table_order); +typedef BOOL (*pCacheGlyph)(rdpContext* context, + const CACHE_GLYPH_ORDER* cache_glyph_order); +typedef BOOL (*pCacheGlyphV2)(rdpContext* context, + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order); +typedef BOOL (*pCacheBrush)(rdpContext* context, + const CACHE_BRUSH_ORDER* cache_brush_order); struct rdp_secondary_update { diff --git a/include/freerdp/update.h b/include/freerdp/update.h index 3847d7ab3..8609284e6 100644 --- a/include/freerdp/update.h +++ b/include/freerdp/update.h @@ -137,23 +137,27 @@ typedef struct rdp_update_proxy rdpUpdateProxy; typedef BOOL (*pBeginPaint)(rdpContext* context); typedef BOOL (*pEndPaint)(rdpContext* context); -typedef BOOL (*pSetBounds)(rdpContext* context, rdpBounds* bounds); +typedef BOOL (*pSetBounds)(rdpContext* context, const rdpBounds* bounds); typedef BOOL (*pSynchronize)(rdpContext* context); typedef BOOL (*pDesktopResize)(rdpContext* context); -typedef BOOL (*pBitmapUpdate)(rdpContext* context, BITMAP_UPDATE* bitmap); -typedef BOOL (*pPalette)(rdpContext* context, PALETTE_UPDATE* palette); -typedef BOOL (*pPlaySound)(rdpContext* context, PLAY_SOUND_UPDATE* play_sound); +typedef BOOL (*pBitmapUpdate)(rdpContext* context, const BITMAP_UPDATE* bitmap); +typedef BOOL (*pPalette)(rdpContext* context, const PALETTE_UPDATE* palette); +typedef BOOL (*pPlaySound)(rdpContext* context, const PLAY_SOUND_UPDATE* play_sound); typedef BOOL (*pSetKeyboardIndicators)(rdpContext* context, UINT16 led_flags); -typedef BOOL (*pRefreshRect)(rdpContext* context, BYTE count, RECTANGLE_16* areas); -typedef BOOL (*pSuppressOutput)(rdpContext* context, BYTE allow, RECTANGLE_16* area); +typedef BOOL (*pRefreshRect)(rdpContext* context, BYTE count, const RECTANGLE_16* areas); +typedef BOOL (*pSuppressOutput)(rdpContext* context, BYTE allow, const RECTANGLE_16* area); typedef BOOL (*pRemoteMonitors)(rdpContext* context, UINT32 count, const MONITOR_DEF *monitors); typedef BOOL (*pSurfaceCommand)(rdpContext* context, wStream* s); -typedef BOOL (*pSurfaceBits)(rdpContext* context, SURFACE_BITS_COMMAND* surfaceBitsCommand); -typedef BOOL (*pSurfaceFrameMarker)(rdpContext* context, SURFACE_FRAME_MARKER* surfaceFrameMarker); -typedef BOOL (*pSurfaceFrameBits)(rdpContext* context, SURFACE_BITS_COMMAND* cmd, BOOL first, BOOL last, UINT32 frameId); +typedef BOOL (*pSurfaceBits)(rdpContext* context, + const SURFACE_BITS_COMMAND* surfaceBitsCommand); +typedef BOOL (*pSurfaceFrameMarker)(rdpContext* context, + const SURFACE_FRAME_MARKER* surfaceFrameMarker); +typedef BOOL (*pSurfaceFrameBits)(rdpContext* context, + const SURFACE_BITS_COMMAND* cmd, BOOL first, + BOOL last, UINT32 frameId); typedef BOOL (*pSurfaceFrameAcknowledge)(rdpContext* context, UINT32 frameId); typedef BOOL (*pSaveSessionInfo)(rdpContext *context, UINT32 type, void *data); diff --git a/libfreerdp/CMakeLists.txt b/libfreerdp/CMakeLists.txt index 48400d3f1..fe4449ac0 100644 --- a/libfreerdp/CMakeLists.txt +++ b/libfreerdp/CMakeLists.txt @@ -195,7 +195,6 @@ endif() # primitives set(PRIMITIVES_SRCS - primitives/prim_16to32bpp.c primitives/prim_add.c primitives/prim_andor.c primitives/prim_alphaComp.c @@ -210,7 +209,6 @@ set(PRIMITIVES_SRCS primitives/prim_internal.h) set(PRIMITIVES_OPT_SRCS - primitives/prim_16to32bpp_opt.c primitives/prim_add_opt.c primitives/prim_andor_opt.c primitives/prim_alphaComp_opt.c diff --git a/libfreerdp/cache/bitmap.c b/libfreerdp/cache/bitmap.c index 14fda44c8..17c716800 100644 --- a/libfreerdp/cache/bitmap.c +++ b/libfreerdp/cache/bitmap.c @@ -34,7 +34,11 @@ #define TAG FREERDP_TAG("cache.bitmap") -BOOL update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) +static rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index); +static void bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index, rdpBitmap* bitmap); + +static BOOL update_gdi_memblt(rdpContext* context, + MEMBLT_ORDER* memblt) { rdpBitmap* bitmap; rdpCache* cache = context->cache; @@ -51,7 +55,8 @@ BOOL update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) return IFCALLRESULT(TRUE, cache->bitmap->MemBlt, context, memblt); } -BOOL update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) +static BOOL update_gdi_mem3blt(rdpContext* context, + MEM3BLT_ORDER* mem3blt) { BYTE style; rdpBitmap* bitmap; @@ -84,7 +89,8 @@ BOOL update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) return ret; } -BOOL update_gdi_cache_bitmap(rdpContext* context, CACHE_BITMAP_ORDER* cacheBitmap) +static BOOL update_gdi_cache_bitmap(rdpContext* context, + const CACHE_BITMAP_ORDER* cacheBitmap) { rdpBitmap* bitmap; rdpBitmap* prevBitmap; @@ -117,7 +123,8 @@ BOOL update_gdi_cache_bitmap(rdpContext* context, CACHE_BITMAP_ORDER* cacheBitma return TRUE; } -BOOL update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cacheBitmapV2) +static BOOL update_gdi_cache_bitmap_v2(rdpContext* context, + CACHE_BITMAP_V2_ORDER* cacheBitmapV2) { rdpBitmap* bitmap; @@ -138,9 +145,13 @@ BOOL update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cach cacheBitmapV2->bitmapBpp = settings->ColorDepth; if (!bitmap->Decompress(context, bitmap, - cacheBitmapV2->bitmapDataStream, cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight, - cacheBitmapV2->bitmapBpp, cacheBitmapV2->bitmapLength, - cacheBitmapV2->compressed, RDP_CODEC_ID_NONE)) + cacheBitmapV2->bitmapDataStream, + cacheBitmapV2->bitmapWidth, + cacheBitmapV2->bitmapHeight, + cacheBitmapV2->bitmapBpp, + cacheBitmapV2->bitmapLength, + cacheBitmapV2->compressed, + RDP_CODEC_ID_NONE)) { Bitmap_Free(context, bitmap); return FALSE; @@ -157,7 +168,8 @@ BOOL update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cach return TRUE; } -BOOL update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cacheBitmapV3) +static BOOL update_gdi_cache_bitmap_v3(rdpContext* context, + CACHE_BITMAP_V3_ORDER* cacheBitmapV3) { rdpBitmap* bitmap; rdpBitmap* prevBitmap; @@ -193,9 +205,10 @@ BOOL update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cach return TRUE; } -BOOL update_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) +static BOOL update_gdi_bitmap_update(rdpContext* context, + const BITMAP_UPDATE* bitmapUpdate) { - int i; + UINT32 i; BOOL reused = TRUE; rdpBitmap* bitmap; BITMAP_DATA* bitmapData; diff --git a/libfreerdp/cache/brush.c b/libfreerdp/cache/brush.c index 448a92d28..a5f3741d6 100644 --- a/libfreerdp/cache/brush.c +++ b/libfreerdp/cache/brush.c @@ -34,12 +34,13 @@ #define TAG FREERDP_TAG("cache.brush") -BOOL update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) +static BOOL update_gdi_patblt(rdpContext* context, + PATBLT_ORDER* patblt) { BYTE style; BOOL ret = TRUE; rdpBrush* brush = &patblt->brush; - rdpCache* cache = context->cache; + const rdpCache* cache = context->cache; style = brush->style; @@ -54,13 +55,15 @@ BOOL update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) return ret; } -BOOL update_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc) +static BOOL update_gdi_polygon_sc(rdpContext* context, + const POLYGON_SC_ORDER* polygon_sc) { rdpCache* cache = context->cache; return IFCALLRESULT(TRUE, cache->brush->PolygonSC, context, polygon_sc); } -BOOL update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) +static BOOL update_gdi_polygon_cb(rdpContext* context, + POLYGON_CB_ORDER* polygon_cb) { BYTE style; rdpBrush* brush = &polygon_cb->brush; @@ -77,12 +80,14 @@ BOOL update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) IFCALLRET(cache->brush->PolygonCB, ret, context, polygon_cb); brush->style = style; + return ret; } -static BOOL update_gdi_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cacheBrush) +static BOOL update_gdi_cache_brush(rdpContext* context, + const CACHE_BRUSH_ORDER* cacheBrush) { - int length; + UINT32 length; void* data = NULL; rdpCache* cache = context->cache; diff --git a/libfreerdp/cache/glyph.c b/libfreerdp/cache/glyph.c index 412c1146c..54784683d 100644 --- a/libfreerdp/cache/glyph.c +++ b/libfreerdp/cache/glyph.c @@ -33,10 +33,18 @@ #define TAG FREERDP_TAG("cache.glyph") -void update_process_glyph(rdpContext* context, BYTE* data, int* index, - int* x, int* y, UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel) + +static rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index); +static void glyph_cache_put(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index, rdpGlyph* entry); + +static void* glyph_cache_fragment_get(rdpGlyphCache* glyph, UINT32 index, UINT32* count); +static void glyph_cache_fragment_put(rdpGlyphCache* glyph, UINT32 index, UINT32 count, void* entry); + +static void update_process_glyph(rdpContext* context, const BYTE* data, + UINT32* index, UINT32* x, UINT32* y, + UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel) { - int offset; + UINT32 offset; rdpGlyph* glyph; UINT32 cacheIndex; rdpGraphics* graphics; @@ -77,14 +85,21 @@ void update_process_glyph(rdpContext* context, BYTE* data, int* index, } } -BOOL update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 length, - UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel, UINT32 bgcolor, UINT32 fgcolor, int x, int y, - int bkX, int bkY, int bkWidth, int bkHeight, int opX, int opY, int opWidth, int opHeight, BOOL fOpRedundant) +static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data, + UINT32 length, UINT32 cacheId, + UINT32 ulCharInc, UINT32 flAccel, + UINT32 bgcolor, UINT32 fgcolor, + UINT32 x, UINT32 y, + UINT32 bkX, UINT32 bkY, + UINT32 bkWidth, UINT32 bkHeight, + UINT32 opX, UINT32 opY, + UINT32 opWidth, UINT32 opHeight, + BOOL fOpRedundant) { - int n; + UINT32 n; UINT32 id; UINT32 size; - int index = 0; + UINT32 index = 0; BYTE* fragments; rdpGraphics* graphics; rdpGlyphCache* glyph_cache; @@ -204,7 +219,8 @@ BOOL update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 leng return Glyph_EndDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor); } -BOOL update_gdi_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyphIndex) +static BOOL update_gdi_glyph_index(rdpContext* context, + GLYPH_INDEX_ORDER* glyphIndex) { rdpGlyphCache* glyph_cache; int bkWidth, bkHeight, opWidth, opHeight; @@ -224,7 +240,8 @@ BOOL update_gdi_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyphIndex) glyphIndex->fOpRedundant); } -BOOL update_gdi_fast_index(rdpContext* context, FAST_INDEX_ORDER* fastIndex) +static BOOL update_gdi_fast_index(rdpContext* context, + const FAST_INDEX_ORDER* fastIndex) { INT32 x, y; INT32 opLeft, opTop; @@ -282,14 +299,15 @@ BOOL update_gdi_fast_index(rdpContext* context, FAST_INDEX_ORDER* fastIndex) FALSE); } -BOOL update_gdi_fast_glyph(rdpContext* context, FAST_GLYPH_ORDER* fastGlyph) +static BOOL update_gdi_fast_glyph(rdpContext* context, + const FAST_GLYPH_ORDER* fastGlyph) { INT32 x, y; rdpGlyph* glyph; BYTE text_data[2]; INT32 opLeft, opTop; INT32 opRight, opBottom; - GLYPH_DATA_V2* glyphData; + const GLYPH_DATA_V2* glyphData; rdpCache* cache = context->cache; opLeft = fastGlyph->opLeft; @@ -373,14 +391,15 @@ error_aj: return FALSE; } -BOOL update_gdi_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cacheGlyph) +static BOOL update_gdi_cache_glyph(rdpContext* context, + const CACHE_GLYPH_ORDER* cacheGlyph) { - int i; + UINT32 i; rdpGlyph* glyph; - GLYPH_DATA* glyph_data; + const GLYPH_DATA* glyph_data; rdpCache* cache = context->cache; - for (i = 0; i < (int) cacheGlyph->cGlyphs; i++) + for (i = 0; i < cacheGlyph->cGlyphs; i++) { glyph_data = &cacheGlyph->glyphData[i]; @@ -405,14 +424,15 @@ BOOL update_gdi_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cacheGlyph) return TRUE; } -BOOL update_gdi_cache_glyph_v2(rdpContext* context, CACHE_GLYPH_V2_ORDER* cacheGlyphV2) +static BOOL update_gdi_cache_glyph_v2(rdpContext* context, + const CACHE_GLYPH_V2_ORDER* cacheGlyphV2) { - int i; + UINT32 i; rdpGlyph* glyph; - GLYPH_DATA_V2* glyphData; + const GLYPH_DATA_V2* glyphData; rdpCache* cache = context->cache; - for (i = 0; i < (int) cacheGlyphV2->cGlyphs; i++) + for (i = 0; i < cacheGlyphV2->cGlyphs; i++) { glyphData = &cacheGlyphV2->glyphData[i]; diff --git a/libfreerdp/cache/nine_grid.c b/libfreerdp/cache/nine_grid.c index 16b174718..fd3bf7d7e 100644 --- a/libfreerdp/cache/nine_grid.c +++ b/libfreerdp/cache/nine_grid.c @@ -35,13 +35,19 @@ #define TAG FREERDP_TAG("cache.nine_grid") -BOOL update_gdi_draw_nine_grid(rdpContext* context, DRAW_NINE_GRID_ORDER* draw_nine_grid) + +static void* nine_grid_cache_get(rdpNineGridCache* nine_grid, UINT32 index); +static void nine_grid_cache_put(rdpNineGridCache* nine_grid, UINT32 index, void* entry); + +static BOOL update_gdi_draw_nine_grid(rdpContext* context, + const DRAW_NINE_GRID_ORDER* draw_nine_grid) { rdpCache* cache = context->cache; return IFCALLRESULT(TRUE, cache->nine_grid->DrawNineGrid, context, draw_nine_grid); } -BOOL update_gdi_multi_draw_nine_grid(rdpContext* context, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) +static BOOL update_gdi_multi_draw_nine_grid(rdpContext* context, + const MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) { rdpCache* cache = context->cache; return IFCALLRESULT(TRUE, cache->nine_grid->MultiDrawNineGrid, context, multi_draw_nine_grid); diff --git a/libfreerdp/cache/offscreen.c b/libfreerdp/cache/offscreen.c index 76765e933..59cff9bae 100644 --- a/libfreerdp/cache/offscreen.c +++ b/libfreerdp/cache/offscreen.c @@ -32,7 +32,11 @@ #define TAG FREERDP_TAG("cache.offscreen") -BOOL update_gdi_create_offscreen_bitmap(rdpContext* context, CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) +static void offscreen_cache_put(rdpOffscreenCache* offscreen_cache, UINT32 index, rdpBitmap* bitmap); +static void offscreen_cache_delete(rdpOffscreenCache* offscreen, UINT32 index); + +static BOOL update_gdi_create_offscreen_bitmap(rdpContext* context, + const CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) { int i; UINT16 index; @@ -66,7 +70,8 @@ BOOL update_gdi_create_offscreen_bitmap(rdpContext* context, CREATE_OFFSCREEN_BI return TRUE; } -BOOL update_gdi_switch_surface(rdpContext* context, SWITCH_SURFACE_ORDER* switchSurface) +static BOOL update_gdi_switch_surface(rdpContext* context, + const SWITCH_SURFACE_ORDER* switchSurface) { rdpCache* cache = context->cache; diff --git a/libfreerdp/cache/palette.c b/libfreerdp/cache/palette.c index 43a2ce26c..c12f30311 100644 --- a/libfreerdp/cache/palette.c +++ b/libfreerdp/cache/palette.c @@ -30,7 +30,11 @@ #define TAG FREERDP_TAG("cache.palette") -static BOOL update_gdi_cache_color_table(rdpContext* context, CACHE_COLOR_TABLE_ORDER* cacheColorTable) +static void* palette_cache_get(rdpPaletteCache* palette, UINT32 index); +static void palette_cache_put(rdpPaletteCache* palette, UINT32 index, void* entry); + +static BOOL update_gdi_cache_color_table(rdpContext* context, + const CACHE_COLOR_TABLE_ORDER* cacheColorTable) { UINT32* colorTable; rdpCache* cache = context->cache; diff --git a/libfreerdp/cache/pointer.c b/libfreerdp/cache/pointer.c index 302204d4b..32812cceb 100644 --- a/libfreerdp/cache/pointer.c +++ b/libfreerdp/cache/pointer.c @@ -33,12 +33,18 @@ #define TAG FREERDP_TAG("cache.pointer") -BOOL update_pointer_position(rdpContext* context, POINTER_POSITION_UPDATE* pointer_position) +static void pointer_cache_put(rdpPointerCache* pointer_cache, UINT32 index, + rdpPointer* pointer); +static const rdpPointer* pointer_cache_get(rdpPointerCache* pointer_cache, UINT32 index); + +static BOOL update_pointer_position(rdpContext* context, + const POINTER_POSITION_UPDATE* pointer_position) { return Pointer_SetPosition(context, pointer_position->xPos, pointer_position->yPos); } -BOOL update_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer_system) +static BOOL update_pointer_system(rdpContext* context, + const POINTER_SYSTEM_UPDATE* pointer_system) { switch (pointer_system->type) { @@ -56,7 +62,8 @@ BOOL update_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer_s return TRUE; } -BOOL update_pointer_color(rdpContext* context, POINTER_COLOR_UPDATE* pointer_color) +static BOOL update_pointer_color(rdpContext* context, + const POINTER_COLOR_UPDATE* pointer_color) { rdpPointer* pointer; rdpCache* cache = context->cache; @@ -103,7 +110,8 @@ out_fail: return FALSE; } -BOOL update_pointer_new(rdpContext* context, POINTER_NEW_UPDATE* pointer_new) +static BOOL update_pointer_new(rdpContext* context, + const POINTER_NEW_UPDATE* pointer_new) { rdpPointer* pointer; rdpCache* cache = context->cache; @@ -148,9 +156,10 @@ out_fail: return FALSE; } -BOOL update_pointer_cached(rdpContext* context, POINTER_CACHED_UPDATE* pointer_cached) +static BOOL update_pointer_cached(rdpContext* context, + const POINTER_CACHED_UPDATE* pointer_cached) { - rdpPointer* pointer; + const rdpPointer* pointer; rdpCache* cache = context->cache; pointer = pointer_cache_get(cache->pointer, pointer_cached->cacheIndex); @@ -163,9 +172,9 @@ BOOL update_pointer_cached(rdpContext* context, POINTER_CACHED_UPDATE* pointer_c return FALSE; } -rdpPointer* pointer_cache_get(rdpPointerCache* pointer_cache, UINT32 index) +const rdpPointer* pointer_cache_get(rdpPointerCache* pointer_cache, UINT32 index) { - rdpPointer* pointer; + const rdpPointer* pointer; if (index >= pointer_cache->cacheSize) { @@ -178,7 +187,8 @@ rdpPointer* pointer_cache_get(rdpPointerCache* pointer_cache, UINT32 index) return pointer; } -void pointer_cache_put(rdpPointerCache* pointer_cache, UINT32 index, rdpPointer* pointer) +void pointer_cache_put(rdpPointerCache* pointer_cache, UINT32 index, + rdpPointer* pointer) { rdpPointer* prevPointer; @@ -233,10 +243,10 @@ void pointer_cache_free(rdpPointerCache* pointer_cache) { if (pointer_cache != NULL) { - int i; + UINT32 i; rdpPointer* pointer; - for (i = 0; i < (int) pointer_cache->cacheSize; i++) + for (i = 0; i < pointer_cache->cacheSize; i++) { pointer = pointer_cache->entries[i]; diff --git a/libfreerdp/codec/clear.c b/libfreerdp/codec/clear.c index c16b04bfb..9f1ece978 100644 --- a/libfreerdp/codec/clear.c +++ b/libfreerdp/codec/clear.c @@ -3,6 +3,8 @@ * ClearCodec Bitmap Compression * * Copyright 2014 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,40 +55,550 @@ static BYTE CLEAR_8BIT_MASKS[9] = 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF }; -int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight) +static void convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat, + UINT32 nXDst, UINT32 nYDst, + const BYTE* src, UINT32 nSrcStep, UINT32 SrcFormat, + UINT32 nWidth, UINT32 nHeight) +{ + UINT32 x, y; + + for (y = 0; y < nHeight; y++) + { + const BYTE* pSrcLine = &src[y * nSrcStep]; + BYTE* pDstLine = &dst[(nYDst + y) * nDstStep]; + + for (x = 0; x < nWidth; x++) + { + const BYTE* pSrcPixel = + &pSrcLine[x * GetBytesPerPixel(SrcFormat)]; + BYTE* pDstPixel = + &pDstLine[(nXDst + x) * GetBytesPerPixel(DstFormat)]; + UINT32 color = ReadColor(pSrcPixel, SrcFormat); + color = ConvertColor(color, SrcFormat, + DstFormat, NULL); + WriteColor(pDstPixel, DstFormat, color); + } + } +} + +static BOOL clear_decompress_nscodec(NSC_CONTEXT* nsc, UINT32 width, + UINT32 height, + const BYTE* bitmapData, UINT32 bitmapDataByteCount, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDstRel, UINT32 nYDstRel) +{ + UINT32 nSrcStep; + + if (nsc_process_message(nsc, 32, width, height, bitmapData, + bitmapDataByteCount) < 0) + return FALSE; + + nSrcStep = width * GetBytesPerPixel(nsc->format); + convert_color(pDstData, nDstStep, DstFormat, + nXDstRel, nYDstRel, + nsc->BitmapData, nSrcStep, nsc->format, + width, height); + return TRUE; +} + +static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData, + UINT32 bitmapDataByteCount, + UINT32 width, UINT32 height, + BYTE* tmpBuffer, UINT32 nTmpBufferSize, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDstRel, UINT32 nYDstRel) { UINT32 i; - BOOL invert; - UINT32 x, y; - UINT32 count = 0; - UINT32 color; - int nXDstRel; - int nYDstRel; - int nSrcStep; + UINT32 SrcFormat = PIXEL_FORMAT_BGR24; + UINT32 pixelCount; + UINT32 nSrcStep; + UINT32 bitmapDataOffset; + UINT32 pixelIndex; + UINT32 numBits; + BYTE startIndex; + BYTE stopIndex; + BYTE suiteIndex; + BYTE suiteDepth; + BYTE paletteCount; + const BYTE* pSrcPixel8; + UINT32 palette[128]; + paletteCount = bitmapData[0]; + pSrcPixel8 = &bitmapData[1]; + bitmapDataOffset = 1 + (paletteCount * 3); + + if (paletteCount > 127) + return -1047; + + for (i = 0; i < paletteCount; i++) + { + UINT32 color = GetColor(SrcFormat, + pSrcPixel8[2], + pSrcPixel8[1], + pSrcPixel8[0], + 0xFF); + palette[i] = color; + pSrcPixel8 += GetBytesPerPixel(SrcFormat); + } + + pixelIndex = 0; + pixelCount = width * height; + numBits = CLEAR_LOG2_FLOOR[paletteCount - 1] + 1; + + while (bitmapDataOffset < bitmapDataByteCount) + { + UINT32 color; + UINT32 runLengthFactor; + + if ((bitmapDataByteCount - bitmapDataOffset) < 2) + return FALSE; + + stopIndex = bitmapData[bitmapDataOffset] & CLEAR_8BIT_MASKS[numBits]; + suiteDepth = (bitmapData[bitmapDataOffset] >> numBits) & CLEAR_8BIT_MASKS[(8 - + numBits)]; + startIndex = stopIndex - suiteDepth; + bitmapDataOffset++; + runLengthFactor = (UINT32) bitmapData[bitmapDataOffset]; + bitmapDataOffset++; + + if (runLengthFactor >= 0xFF) + { + if ((bitmapDataByteCount - bitmapDataOffset) < 2) + return FALSE; + + runLengthFactor = (UINT32) * ((UINT16*) &bitmapData[bitmapDataOffset]); + bitmapDataOffset += 2; + + if (runLengthFactor >= 0xFFFF) + { + if ((bitmapDataByteCount - bitmapDataOffset) < 4) + return FALSE; + + runLengthFactor = *((UINT32*) &bitmapData[bitmapDataOffset]); + bitmapDataOffset += 4; + } + } + + if (startIndex >= paletteCount) + return FALSE; + + if (stopIndex >= paletteCount) + return FALSE; + + suiteIndex = startIndex; + color = palette[suiteIndex]; + + if ((pixelIndex + runLengthFactor) > pixelCount) + return FALSE; + + for (i = 0; i < runLengthFactor; i++) + { + WriteColor(tmpBuffer, SrcFormat, color); + tmpBuffer += GetBytesPerPixel(SrcFormat); + } + + pixelIndex += runLengthFactor; + + if ((pixelIndex + (suiteDepth + 1)) > pixelCount) + return FALSE; + + for (i = 0; i <= suiteDepth; i++) + { + UINT32 color = palette[suiteIndex++]; + WriteColor(tmpBuffer, SrcFormat, color); + tmpBuffer += GetBytesPerPixel(SrcFormat); + } + + pixelIndex += (suiteDepth + 1); + } + + nSrcStep = width * GetBytesPerPixel(SrcFormat); + + if (pixelIndex != pixelCount) + return -1055; + + convert_color(pDstData, nDstStep, DstFormat, + nXDstRel, nYDstRel, + tmpBuffer, nSrcStep, SrcFormat, + width, height); + return TRUE; +} + +static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear, + const BYTE* residualData, + UINT32 residualByteCount, UINT32 SrcSize, + UINT32 nWidth, UINT32 nHeight, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst) +{ + UINT32 i; + UINT32 nSrcStep; + UINT32 suboffset; + BYTE* dstBuffer; + UINT32 pixelIndex; + UINT32 pixelCount; + + if (SrcSize < residualByteCount) + return -1013; + + suboffset = 0; + + if ((nWidth * nHeight * GetBytesPerPixel(clear->format)) > clear->TempSize) + { + clear->TempSize = (nWidth * nHeight * GetBytesPerPixel(clear->format)); + clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize); + + if (!clear->TempBuffer) + return -1014; + } + + pixelIndex = 0; + pixelCount = nWidth * nHeight; + dstBuffer = clear->TempBuffer; + + while (suboffset < residualByteCount) + { + UINT32 runLengthFactor; + UINT32 color; + + if ((residualByteCount - suboffset) < 4) + return -1015; + + color = GetColor(clear->format, residualData[suboffset + 2], + residualData[suboffset + 1], + residualData[suboffset + 0], 0xFF); + suboffset += 3; + runLengthFactor = residualData[suboffset]; + suboffset++; + + if (runLengthFactor >= 0xFF) + { + if ((residualByteCount - suboffset) < 2) + return -1016; + + runLengthFactor = (UINT32) * ((UINT16*) &residualData[suboffset]); + suboffset += 2; + + if (runLengthFactor >= 0xFFFF) + { + if ((residualByteCount - suboffset) < 4) + return -1017; + + runLengthFactor = *((UINT32*) &residualData[suboffset]); + suboffset += 4; + } + } + + if ((pixelIndex + runLengthFactor) > pixelCount) + return -1018; + + for (i = 0; i < runLengthFactor; i++) + { + WriteColor(dstBuffer, clear->format, color); + dstBuffer += GetBytesPerPixel(clear->format); + } + + pixelIndex += runLengthFactor; + } + + nSrcStep = nWidth * GetBytesPerPixel(clear->format); + + if (pixelIndex != pixelCount) + return -1019; + + convert_color(pDstData, nDstStep, DstFormat, + nXDst, nYDst, + clear->TempBuffer, nSrcStep, clear->format, + nWidth, nHeight); + return TRUE; +} + +static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, + const BYTE* bandsData, + UINT32 bandsByteCount, UINT32 SrcSize, + UINT32 nWidth, UINT32 nHeight, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst) +{ + UINT32 i, y; + UINT32 count; + UINT32 suboffset; + UINT32 nXDstRel; + UINT32 nYDstRel; + + if (SrcSize < bandsByteCount) + return -1020; + + suboffset = 0; + + while (suboffset < bandsByteCount) + { + UINT16 xStart; + UINT16 xEnd; + UINT16 yStart; + UINT16 yEnd; + const BYTE* vBar; + BOOL vBarUpdate; + UINT32 colorBkg; + UINT16 vBarHeader; + UINT16 vBarIndex; + UINT16 vBarYOn; + UINT16 vBarYOff; + UINT32 vBarCount; + UINT32 vBarHeight; + UINT32 vBarPixelCount; + UINT32 vBarShortPixelCount; + CLEAR_VBAR_ENTRY* vBarEntry; + CLEAR_VBAR_ENTRY* vBarShortEntry; + + if ((bandsByteCount - suboffset) < 11) + return -1021; + + xStart = *((UINT16*) &bandsData[suboffset]); + xEnd = *((UINT16*) &bandsData[suboffset + 2]); + yStart = *((UINT16*) &bandsData[suboffset + 4]); + yEnd = *((UINT16*) &bandsData[suboffset + 6]); + suboffset += 8; + colorBkg = GetColor(clear->format, bandsData[suboffset + 2], + bandsData[suboffset + 1], + bandsData[suboffset + 0], + 0xFF); + suboffset += 3; + + if (xEnd < xStart) + return -1022; + + if (yEnd < yStart) + return -1023; + + vBarCount = (xEnd - xStart) + 1; + + for (i = 0; i < vBarCount; i++) + { + const BYTE* pSrcPixel; + vBarUpdate = FALSE; + vBar = &bandsData[suboffset]; + + if ((bandsByteCount - suboffset) < 2) + return -1024; + + vBarHeader = *((UINT16*) &vBar[0]); + suboffset += 2; + vBarHeight = (yEnd - yStart + 1); + + if (vBarHeight > 52) + return -1025; + + if ((vBarHeader & 0xC000) == 0x4000) /* SHORT_VBAR_CACHE_HIT */ + { + vBarIndex = (vBarHeader & 0x3FFF); + + if (vBarIndex >= 16384) + return -1026; + + if ((bandsByteCount - suboffset) < 1) + return -1027; + + vBarYOn = vBar[2]; + suboffset += 1; + vBarShortEntry = &(clear->ShortVBarStorage[vBarIndex]); + + if (!vBarShortEntry) + return -1028; + + vBarShortPixelCount = vBarShortEntry->count; + vBarUpdate = TRUE; + } + else if ((vBarHeader & 0xC000) == 0x0000) /* SHORT_VBAR_CACHE_MISS */ + { + const BYTE* pSrcPixel8; + vBarYOn = (vBarHeader & 0xFF); + vBarYOff = ((vBarHeader >> 8) & 0x3F); + + if (vBarYOff < vBarYOn) + return -1029; + + pSrcPixel8 = &vBar[2]; + vBarShortPixelCount = (vBarYOff - vBarYOn); + + if (vBarShortPixelCount > 52) + return -1030; + + if ((bandsByteCount - suboffset) < (vBarShortPixelCount * 3)) + return -1031; + + if (clear->ShortVBarStorageCursor >= 16384) + return -1032; + + vBarShortEntry = &(clear->ShortVBarStorage[clear->ShortVBarStorageCursor]); + vBarShortEntry->count = vBarShortPixelCount; + + if (vBarShortEntry->count > vBarShortEntry->size) + { + BYTE* tmp; + vBarShortEntry->size = vBarShortEntry->count; + tmp = (BYTE*) realloc( + vBarShortEntry->pixels, + vBarShortEntry->count * GetBytesPerPixel(clear->format)); + + if (!tmp) + return -1; + + vBarShortEntry->pixels = tmp; + } + + if (!vBarShortEntry->pixels && vBarShortEntry->size) + return -1033; + + for (y = 0; y < vBarShortPixelCount; y++) + { + BYTE* dstBuffer = + &vBarShortEntry->pixels[y * GetBytesPerPixel(clear->format)]; + UINT32 color = GetColor(clear->format, + pSrcPixel8[2], + pSrcPixel8[1], + pSrcPixel8[0], + 0xFF); + WriteColor(dstBuffer, clear->format, color); + pSrcPixel8 += 3; + } + + suboffset += (vBarShortPixelCount * 3); + vBarShortEntry->count = vBarShortPixelCount; + clear->ShortVBarStorageCursor = (clear->ShortVBarStorageCursor + 1) % 16384; + vBarUpdate = TRUE; + } + else if ((vBarHeader & 0x8000) == 0x8000) /* VBAR_CACHE_HIT */ + { + vBarIndex = (vBarHeader & 0x7FFF); + + if (vBarIndex >= 32768) + return -1034; + + vBarEntry = &(clear->VBarStorage[vBarIndex]); + } + else + { + return -1035; /* invalid vBarHeader */ + } + + if (vBarUpdate) + { + UINT32 x; + BYTE* pSrcPixel; + BYTE* dstBuffer; + + if (clear->VBarStorageCursor >= 32768) + return -1036; + + vBarEntry = &(clear->VBarStorage[clear->VBarStorageCursor]); + vBarPixelCount = vBarHeight; + vBarEntry->count = vBarPixelCount; + + if (vBarEntry->count > vBarEntry->size) + { + BYTE* tmp; + vBarEntry->size = vBarEntry->count; + tmp = (BYTE*) realloc(vBarEntry->pixels, + vBarEntry->count * GetBytesPerPixel(clear->format)); + + if (!tmp) + return -1; + + vBarEntry->pixels = tmp; + } + + if (!vBarEntry->pixels && vBarEntry->size) + return -1037; + + dstBuffer = vBarEntry->pixels; + /* if (y < vBarYOn), use colorBkg */ + y = 0; + count = vBarYOn; + + if ((y + count) > vBarPixelCount) + count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0; + + while (count--) + { + WriteColor(dstBuffer, clear->format, colorBkg); + dstBuffer += GetBytesPerPixel(clear->format); + } + + /* + * if ((y >= vBarYOn) && (y < (vBarYOn + vBarShortPixelCount))), + * use vBarShortPixels at index (y - shortVBarYOn) + */ + y = vBarYOn; + count = vBarShortPixelCount; + + if ((y + count) > vBarPixelCount) + count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0; + + pSrcPixel = &vBarShortEntry->pixels[(y - vBarYOn) * GetBytesPerPixel( + clear->format)]; + + for (x = 0; x < count; x++) + { + UINT32 color; + color = ReadColor(&vBarShortEntry->pixels[x * GetBytesPerPixel(clear->format)], + clear->format); + WriteColor(dstBuffer, clear->format, color); + dstBuffer += GetBytesPerPixel(clear->format); + } + + /* if (y >= (vBarYOn + vBarShortPixelCount)), use colorBkg */ + y = vBarYOn + vBarShortPixelCount; + count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0; + + while (count--) + { + WriteColor(dstBuffer, clear->format, colorBkg); + dstBuffer += GetBytesPerPixel(clear->format); + } + + vBarEntry->count = vBarPixelCount; + clear->VBarStorageCursor = (clear->VBarStorageCursor + 1) % 32768; + } + + nXDstRel = nXDst + xStart; + nYDstRel = nYDst + yStart; + pSrcPixel = vBarEntry->pixels; + count = yEnd - yStart + 1; + + if (vBarEntry->count != count) + return -1038; + + for (y = 0; y < count; y++) + { + BYTE* pDstPixel8 = &pDstData[((nYDstRel + y) * nDstStep) + + ((nXDstRel + i) * GetBytesPerPixel(DstFormat))]; + UINT32 color = ReadColor(pSrcPixel, clear->format); + color = ConvertColor(color, clear->format, + DstFormat, NULL); + WriteColor(pDstPixel8, DstFormat, color); + pSrcPixel += GetBytesPerPixel(clear->format); + } + } + } + + return TRUE; +} + +INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, + UINT32 SrcSize, + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight) +{ BYTE seqNumber; BYTE glyphFlags; BYTE* glyphData; UINT32 offset = 0; UINT16 glyphIndex = 0; - BYTE* pDstData = NULL; UINT32 residualByteCount; UINT32 bandsByteCount; UINT32 subcodecByteCount; - UINT32 runLengthFactor; - UINT32 pixelIndex = 0; - UINT32 pixelCount = 0; - BYTE* pSrcPixel8 = NULL; - BYTE* pDstPixel8 = NULL; - UINT32* pSrcPixel32 = NULL; - UINT32* pDstPixel32 = NULL; CLEAR_GLYPH_ENTRY* glyphEntry; - if (!ppDstData) - return -1001; - - pDstData = *ppDstData; - if (!pDstData) return -1002; @@ -96,8 +608,6 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, if ((nWidth > 0xFFFF) || (nHeight > 0xFFFF)) return -1004; - invert = FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat) ? TRUE : FALSE; - glyphFlags = pSrcData[0]; seqNumber = pSrcData[1]; offset += 2; @@ -116,7 +626,8 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, clear->ShortVBarStorageCursor = 0; } - if ((glyphFlags & CLEARCODEC_FLAG_GLYPH_HIT) && !(glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX)) + if ((glyphFlags & CLEARCODEC_FLAG_GLYPH_HIT) && + !(glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX)) return -1006; if (glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX) @@ -135,6 +646,7 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, if (glyphFlags & CLEARCODEC_FLAG_GLYPH_HIT) { + UINT32 nSrcStep; glyphEntry = &(clear->GlyphCache[glyphIndex]); glyphData = (BYTE*) glyphEntry->pixels; @@ -144,23 +656,16 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, if ((nWidth * nHeight) > (int) glyphEntry->count) return -1011; - nSrcStep = nWidth * 4; - pSrcPixel8 = glyphData; - pDstPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < (UINT32) nHeight; y++) - { - CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep); - pSrcPixel8 += nSrcStep; - pDstPixel8 += nDstStep; - } - + nSrcStep = nWidth * GetBytesPerPixel(clear->format); + convert_color(pDstData, nDstStep, DstFormat, + nXDst, nYDst, + glyphData, nSrcStep, clear->format, + nWidth, nHeight); return 1; /* Finish */ } } /* Read composition payload header parameters */ - if ((SrcSize - offset) < 12) return -1012; @@ -169,357 +674,24 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, subcodecByteCount = *((UINT32*) &pSrcData[offset + 8]); offset += 12; - //WLog_DBG(TAG, "residualByteCount: %d bandsByteCount: %d subcodecByteCount: %d", - // residualByteCount, bandsByteCount, subcodecByteCount); - if (residualByteCount > 0) { - UINT32 suboffset; - BYTE* residualData; - - if ((SrcSize - offset) < residualByteCount) - return -1013; - - suboffset = 0; - residualData = &pSrcData[offset]; - - if ((nWidth * nHeight * 4) > (int) clear->TempSize) - { - clear->TempSize = (nWidth * nHeight * 4); - clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize); - - if (!clear->TempBuffer) - return -1014; - } - - pixelIndex = 0; - pixelCount = nWidth * nHeight; - pDstPixel32 = (UINT32*) clear->TempBuffer; - - while (suboffset < residualByteCount) - { - if ((residualByteCount - suboffset) < 4) - return -1015; - - if (!invert) - color = RGB32(residualData[suboffset + 2], residualData[suboffset + 1], residualData[suboffset + 0]); - else - color = BGR32(residualData[suboffset + 2], residualData[suboffset + 1], residualData[suboffset + 0]); - - suboffset += 3; - - runLengthFactor = (UINT32) residualData[suboffset]; - suboffset++; - - if (runLengthFactor >= 0xFF) - { - if ((residualByteCount - suboffset) < 2) - return -1016; - - runLengthFactor = (UINT32) *((UINT16*) &residualData[suboffset]); - suboffset += 2; - - if (runLengthFactor >= 0xFFFF) - { - if ((residualByteCount - suboffset) < 4) - return -1017; - - runLengthFactor = *((UINT32*) &residualData[suboffset]); - suboffset += 4; - } - } - - if ((pixelIndex + runLengthFactor) > pixelCount) - return -1018; - - for (i = 0; i < runLengthFactor; i++) - { - *pDstPixel32 = color; - pDstPixel32++; - } - - pixelIndex += runLengthFactor; - } - - nSrcStep = nWidth * 4; - pSrcPixel8 = clear->TempBuffer; - pDstPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - if (pixelIndex != pixelCount) - return -1019; - - for (y = 0; y < (UINT32) nHeight; y++) - { - CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep); - pSrcPixel8 += nSrcStep; - pDstPixel8 += nDstStep; - } + if (!clear_decompress_residual_data(clear, + &pSrcData[offset], residualByteCount, + SrcSize - offset, nWidth, nHeight, + pDstData, DstFormat, nDstStep, nXDst, nYDst)) + return -1111; offset += residualByteCount; } if (bandsByteCount > 0) { - BYTE* bandsData; - UINT32 suboffset; - - if ((SrcSize - offset) < bandsByteCount) - return -1020; - - suboffset = 0; - bandsData = &pSrcData[offset]; - - while (suboffset < bandsByteCount) - { - UINT16 xStart; - UINT16 xEnd; - UINT16 yStart; - UINT16 yEnd; - BYTE* vBar; - BOOL vBarUpdate; - UINT32 colorBkg; - UINT16 vBarHeader; - UINT16 vBarIndex; - UINT16 vBarYOn; - UINT16 vBarYOff; - UINT32 vBarCount; - UINT32 vBarHeight; - UINT32 vBarPixelCount; - UINT32 vBarShortPixelCount; - CLEAR_VBAR_ENTRY* vBarEntry = NULL; - CLEAR_VBAR_ENTRY* vBarShortEntry = NULL; - - if ((bandsByteCount - suboffset) < 11) - return -1021; - - xStart = *((UINT16*) &bandsData[suboffset]); - xEnd = *((UINT16*) &bandsData[suboffset + 2]); - yStart = *((UINT16*) &bandsData[suboffset + 4]); - yEnd = *((UINT16*) &bandsData[suboffset + 6]); - suboffset += 8; - - if (!invert) - colorBkg = RGB32(bandsData[suboffset + 2], bandsData[suboffset + 1], bandsData[suboffset + 0]); - else - colorBkg = BGR32(bandsData[suboffset + 2], bandsData[suboffset + 1], bandsData[suboffset + 0]); - - suboffset += 3; - - if (xEnd < xStart) - return -1022; - - if (yEnd < yStart) - return -1023; - - vBarCount = (xEnd - xStart) + 1; - - for (i = 0; i < vBarCount; i++) - { - vBarUpdate = FALSE; - vBar = &bandsData[suboffset]; - - if ((bandsByteCount - suboffset) < 2) - return -1024; - - vBarHeader = *((UINT16*) &vBar[0]); - suboffset += 2; - - vBarHeight = (yEnd - yStart + 1); - - if (vBarHeight > 52) - return -1025; - - if ((vBarHeader & 0xC000) == 0x4000) /* SHORT_VBAR_CACHE_HIT */ - { - vBarIndex = (vBarHeader & 0x3FFF); - - if (vBarIndex >= 16384) - return -1026; - - if ((bandsByteCount - suboffset) < 1) - return -1027; - - vBarYOn = vBar[2]; - suboffset += 1; - - vBarShortEntry = &(clear->ShortVBarStorage[vBarIndex]); - - if (!vBarShortEntry) - return -1028; - - vBarShortPixelCount = vBarShortEntry->count; - - vBarUpdate = TRUE; - } - else if ((vBarHeader & 0xC000) == 0x0000) /* SHORT_VBAR_CACHE_MISS */ - { - vBarYOn = (vBarHeader & 0xFF); - vBarYOff = ((vBarHeader >> 8) & 0x3F); - - if (vBarYOff < vBarYOn) - return -1029; - - pSrcPixel8 = &vBar[2]; - vBarShortPixelCount = (vBarYOff - vBarYOn); - - if (vBarShortPixelCount > 52) - return -1030; - - if ((bandsByteCount - suboffset) < (vBarShortPixelCount * 3)) - return -1031; - - if (clear->ShortVBarStorageCursor >= 16384) - return -1032; - - vBarShortEntry = &(clear->ShortVBarStorage[clear->ShortVBarStorageCursor]); - - vBarShortEntry->count = vBarShortPixelCount; - - if (vBarShortEntry->count > vBarShortEntry->size) - { - UINT32 *tmp; - vBarShortEntry->size = vBarShortEntry->count; - - tmp = (UINT32*) realloc(vBarShortEntry->pixels, vBarShortEntry->count * 4); - if (!tmp) - return -1; - vBarShortEntry->pixels = tmp; - } - - if (!vBarShortEntry->pixels && vBarShortEntry->size) - return -1033; - - pDstPixel32 = vBarShortEntry->pixels; - - if (!invert) - { - for (y = 0; y < vBarShortPixelCount; y++) - { - *pDstPixel32 = RGB32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]); - pSrcPixel8 += 3; - pDstPixel32++; - } - } - else - { - for (y = 0; y < vBarShortPixelCount; y++) - { - *pDstPixel32 = BGR32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]); - pSrcPixel8 += 3; - pDstPixel32++; - } - } - - suboffset += (vBarShortPixelCount * 3); - - vBarShortEntry->count = vBarShortPixelCount; - clear->ShortVBarStorageCursor = (clear->ShortVBarStorageCursor + 1) % 16384; - - vBarUpdate = TRUE; - } - else if ((vBarHeader & 0x8000) == 0x8000) /* VBAR_CACHE_HIT */ - { - vBarIndex = (vBarHeader & 0x7FFF); - - if (vBarIndex >= 32768) - return -1034; - - vBarEntry = &(clear->VBarStorage[vBarIndex]); - } - else - { - return -1035; /* invalid vBarHeader */ - } - - if (vBarUpdate) - { - if (clear->VBarStorageCursor >= 32768) - return -1036; - - vBarEntry = &(clear->VBarStorage[clear->VBarStorageCursor]); - - vBarPixelCount = vBarHeight; - vBarEntry->count = vBarPixelCount; - - if (vBarEntry->count > vBarEntry->size) - { - UINT32 *tmp; - vBarEntry->size = vBarEntry->count; - - tmp = (UINT32*) realloc(vBarEntry->pixels, vBarEntry->count * 4); - if (!tmp) - return -1; - vBarEntry->pixels = tmp; - } - - if (!vBarEntry->pixels && vBarEntry->size) - return -1037; - - pDstPixel32 = vBarEntry->pixels; - - /* if (y < vBarYOn), use colorBkg */ - - y = 0; - count = vBarYOn; - - if ((y + count) > vBarPixelCount) - count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0; - - while (count--) - { - *pDstPixel32 = colorBkg; - pDstPixel32++; - } - - /* - * if ((y >= vBarYOn) && (y < (vBarYOn + vBarShortPixelCount))), - * use vBarShortPixels at index (y - shortVBarYOn) - */ - - y = vBarYOn; - count = vBarShortPixelCount; - - if ((y + count) > vBarPixelCount) - count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0; - - pSrcPixel32 = &(vBarShortEntry->pixels[y - vBarYOn]); - CopyMemory(pDstPixel32, pSrcPixel32, count * 4); - pDstPixel32 += count; - - /* if (y >= (vBarYOn + vBarShortPixelCount)), use colorBkg */ - - y = vBarYOn + vBarShortPixelCount; - count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0; - - while (count--) - { - *pDstPixel32 = colorBkg; - pDstPixel32++; - } - - vBarEntry->count = vBarPixelCount; - clear->VBarStorageCursor = (clear->VBarStorageCursor + 1) % 32768; - } - - nXDstRel = nXDst + xStart; - nYDstRel = nYDst + yStart; - - pSrcPixel32 = vBarEntry->pixels; - pDstPixel8 = &pDstData[(nYDstRel * nDstStep) + ((nXDstRel + i) * 4)]; - - count = yEnd - yStart + 1; - - if (vBarEntry->count != count) - return -1038; - - for (y = 0; y < count; y++) - { - *((UINT32*) pDstPixel8) = *pSrcPixel32; - pDstPixel8 += nDstStep; - pSrcPixel32++; - } - } - } + if (!clear_decompress_bands_data(clear, + &pSrcData[offset], bandsByteCount, + SrcSize - offset, nWidth, nHeight, + pDstData, DstFormat, nDstStep, nXDst, nYDst)) + return FALSE; offset += bandsByteCount; } @@ -530,11 +702,10 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, UINT16 yStart; UINT16 width; UINT16 height; - BYTE* bitmapData; - UINT32 bitmapDataOffset; + const BYTE* bitmapData; UINT32 bitmapDataByteCount; BYTE subcodecId; - BYTE* subcodecs; + const BYTE* subcodecs; UINT32 suboffset; if ((SrcSize - offset) < subcodecByteCount) @@ -545,6 +716,9 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, while (suboffset < subcodecByteCount) { + UINT32 nXDstRel; + UINT32 nYDstRel; + if ((subcodecByteCount - suboffset) < 13) return -1040; @@ -556,9 +730,6 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, subcodecId = subcodecs[suboffset + 12]; suboffset += 13; - //WLog_DBG(TAG, "bitmapDataByteCount: %d subcodecByteCount: %d suboffset: %d subCodecId: %d", - // bitmapDataByteCount, subcodecByteCount, suboffset, subcodecId); - if ((subcodecByteCount - suboffset) < bitmapDataByteCount) return -1041; @@ -571,9 +742,10 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, if (height > nHeight) return -1043; - if (((UINT32) (width * height * 4)) > clear->TempSize) + if (((UINT32)(width * height * GetBytesPerPixel(clear->format))) > + clear->TempSize) { - clear->TempSize = (width * height * 4); + clear->TempSize = (width * height * GetBytesPerPixel(clear->format)); clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize); if (!clear->TempBuffer) @@ -584,195 +756,34 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, if (subcodecId == 0) /* Uncompressed */ { - if (bitmapDataByteCount != (width * height * 3)) + UINT32 nSrcStep = width * height * GetBytesPerPixel(PIXEL_FORMAT_BGR24); + + if (bitmapDataByteCount != nSrcStep) return -1045; - pSrcPixel8 = bitmapData; - - if (!invert) - { - for (y = 0; y < height; y++) - { - pDstPixel32 = (UINT32*) &pDstData[((nYDstRel + y) * nDstStep) + (nXDstRel * 4)]; - - for (x = 0; x < width; x++) - { - *pDstPixel32 = RGB32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]); - pSrcPixel8 += 3; - pDstPixel32++; - } - } - } - else - { - for (y = 0; y < height; y++) - { - pDstPixel32 = (UINT32*) &pDstData[((nYDstRel + y) * nDstStep) + (nXDstRel * 4)]; - - for (x = 0; x < width; x++) - { - *pDstPixel32 = BGR32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]); - pSrcPixel8 += 3; - pDstPixel32++; - } - } - } + convert_color(pDstData, nDstStep, DstFormat, + nXDstRel, nYDstRel, + bitmapData, nSrcStep, + PIXEL_FORMAT_BGR24, + width, height); } else if (subcodecId == 1) /* NSCodec */ { - if (nsc_process_message(clear->nsc, 32, width, height, bitmapData, bitmapDataByteCount) < 0) + if (!clear_decompress_nscodec(clear->nsc, width, height, + bitmapData, bitmapDataByteCount, + pDstData, DstFormat, nDstStep, + nXDstRel, nYDstRel)) return -1046; - - nSrcStep = width * 4; - pSrcPixel8 = clear->nsc->BitmapData; - pDstPixel8 = &pDstData[(nYDstRel * nDstStep) + (nXDstRel * 4)]; - - if (!invert) - { - for (y = 0; y < height; y++) - { - CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep); - pSrcPixel8 += nSrcStep; - pDstPixel8 += nDstStep; - } - } - else - { - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - pDstPixel8[0] = pSrcPixel8[2]; - pDstPixel8[1] = pSrcPixel8[1]; - pDstPixel8[2] = pSrcPixel8[0]; - pDstPixel8[3] = 0xFF; - - pSrcPixel8 += 4; - pDstPixel8 += 4; - } - - pSrcPixel8 += (nSrcStep - (width * 4)); - pDstPixel8 += (nDstStep - (width * 4)); - } - } } else if (subcodecId == 2) /* CLEARCODEC_SUBCODEC_RLEX */ { - UINT32 numBits; - BYTE startIndex; - BYTE stopIndex; - BYTE suiteIndex; - BYTE suiteDepth; - BYTE paletteCount; - UINT32 palette[128]; - - paletteCount = bitmapData[0]; - pSrcPixel8 = &bitmapData[1]; - bitmapDataOffset = 1 + (paletteCount * 3); - - if (paletteCount > 127) + if (!clear_decompress_subcode_rlex(bitmapData, + bitmapDataByteCount, + width, height, + clear->TempBuffer, clear->TempSize, + pDstData, DstFormat, nDstStep, + nXDstRel, nYDstRel)) return -1047; - - if (!invert) - { - for (i = 0; i < paletteCount; i++) - { - palette[i] = RGB32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]); - pSrcPixel8 += 3; - } - } - else - { - for (i = 0; i < paletteCount; i++) - { - palette[i] = BGR32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]); - pSrcPixel8 += 3; - } - } - - pixelIndex = 0; - pixelCount = width * height; - pDstPixel32 = (UINT32*) clear->TempBuffer; - - numBits = CLEAR_LOG2_FLOOR[paletteCount - 1] + 1; - - while (bitmapDataOffset < bitmapDataByteCount) - { - if ((bitmapDataByteCount - bitmapDataOffset) < 2) - return -1048; - - stopIndex = bitmapData[bitmapDataOffset] & CLEAR_8BIT_MASKS[numBits]; - suiteDepth = (bitmapData[bitmapDataOffset] >> numBits) & CLEAR_8BIT_MASKS[(8 - numBits)]; - startIndex = stopIndex - suiteDepth; - bitmapDataOffset++; - - runLengthFactor = (UINT32) bitmapData[bitmapDataOffset]; - bitmapDataOffset++; - - if (runLengthFactor >= 0xFF) - { - if ((bitmapDataByteCount - bitmapDataOffset) < 2) - return -1049; - - runLengthFactor = (UINT32) *((UINT16*) &bitmapData[bitmapDataOffset]); - bitmapDataOffset += 2; - - if (runLengthFactor >= 0xFFFF) - { - if ((bitmapDataByteCount - bitmapDataOffset) < 4) - return -1050; - - runLengthFactor = *((UINT32*) &bitmapData[bitmapDataOffset]); - bitmapDataOffset += 4; - } - } - - if (startIndex >= paletteCount) - return -1051; - - if (stopIndex >= paletteCount) - return -1052; - - suiteIndex = startIndex; - color = palette[suiteIndex]; - - if ((pixelIndex + runLengthFactor) > pixelCount) - return -1053; - - for (i = 0; i < runLengthFactor; i++) - { - *pDstPixel32 = color; - pDstPixel32++; - } - - pixelIndex += runLengthFactor; - - if ((pixelIndex + (suiteDepth + 1)) > pixelCount) - return -1054; - - for (i = 0; i <= suiteDepth; i++) - { - *pDstPixel32 = palette[suiteIndex++]; - pDstPixel32++; - } - - pixelIndex += (suiteDepth + 1); - } - - nSrcStep = width * 4; - pSrcPixel8 = clear->TempBuffer; - pDstPixel8 = &pDstData[(nYDstRel * nDstStep) + (nXDstRel * 4)]; - - if (pixelIndex != pixelCount) - return -1055; - - for (y = 0; y < height; y++) - { - CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep); - pSrcPixel8 += nSrcStep; - pDstPixel8 += nDstStep; - pixelCount -= count; - } } else { @@ -787,18 +798,19 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, if (glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX) { + UINT32 nSrcStep; glyphEntry = &(clear->GlyphCache[glyphIndex]); - glyphEntry->count = nWidth * nHeight; if (glyphEntry->count > glyphEntry->size) { - UINT32 *tmp; + UINT32* tmp; glyphEntry->size = glyphEntry->count; - tmp = (UINT32*) realloc(glyphEntry->pixels, glyphEntry->size * 4); + if (!tmp) return -1; + glyphEntry->pixels = tmp; } @@ -806,17 +818,11 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, return -1057; glyphData = (BYTE*) glyphEntry->pixels; - - nSrcStep = nWidth * 4; - pDstPixel8 = glyphData; - pSrcPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < (UINT32) nHeight; y++) - { - CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep); - pDstPixel8 += nSrcStep; - pSrcPixel8 += nDstStep; - } + nSrcStep = nWidth * GetBytesPerPixel(clear->format); + convert_color(pDstData, nDstStep, DstFormat, + nXDst, nYDst, + glyphData, nSrcStep, clear->format, + nWidth, nHeight); } if (offset != SrcSize) @@ -825,7 +831,8 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, return 1; } -int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize) +int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, + BYTE** ppDstData, UINT32* pDstSize) { return 1; } @@ -838,36 +845,33 @@ BOOL clear_context_reset(CLEAR_CONTEXT* clear) clear->seqNumber = 0; clear->VBarStorageCursor = 0; clear->ShortVBarStorageCursor = 0; - return TRUE; } CLEAR_CONTEXT* clear_context_new(BOOL Compressor) { CLEAR_CONTEXT* clear; - clear = (CLEAR_CONTEXT*) calloc(1, sizeof(CLEAR_CONTEXT)); if (!clear) return NULL; clear->Compressor = Compressor; - clear->nsc = nsc_context_new(); + clear->format = PIXEL_FORMAT_BGRX32; + if (!clear->nsc) goto error_nsc; - nsc_context_set_pixel_format(clear->nsc, RDP_PIXEL_FORMAT_R8G8B8); - + nsc_context_set_pixel_format(clear->nsc, PIXEL_FORMAT_RGB24); clear->TempSize = 512 * 512 * 4; clear->TempBuffer = (BYTE*) malloc(clear->TempSize); + if (!clear->TempBuffer) goto error_temp_buffer; clear_context_reset(clear); - return clear; - error_temp_buffer: nsc_context_free(clear->nsc); error_nsc: @@ -883,7 +887,6 @@ void clear_context_free(CLEAR_CONTEXT* clear) return; nsc_context_free(clear->nsc); - free(clear->TempBuffer); for (i = 0; i < 4000; i++) diff --git a/libfreerdp/codec/color.c b/libfreerdp/codec/color.c index d704698f2..ae72a73fc 100644 --- a/libfreerdp/codec/color.c +++ b/libfreerdp/codec/color.c @@ -3,6 +3,8 @@ * Color Conversion Routines * * Copyright 2010 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,1071 +35,18 @@ #define TAG FREERDP_TAG("color") -int freerdp_get_pixel(BYTE* data, int x, int y, int width, int height, int bpp) +BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, const BYTE* data) { - int start; - int shift; - UINT16* src16; - UINT32* src32; - int red, green, blue; - - switch (bpp) - { - case 1: - width = (width + 7) / 8; - start = (y * width) + x / 8; - shift = x % 8; - return (data[start] & (0x80 >> shift)) != 0; - case 8: - return data[y * width + x]; - case 15: - case 16: - src16 = (UINT16*) data; - return src16[y * width + x]; - case 24: - data += y * width * 3; - data += x * 3; - red = data[0]; - green = data[1]; - blue = data[2]; - return RGB24(red, green, blue); - case 32: - src32 = (UINT32*) data; - return src32[y * width + x]; - default: - break; - } - - return 0; -} - -void freerdp_set_pixel(BYTE* data, int x, int y, int width, int height, int bpp, int pixel) -{ - int start; - int shift; - int *dst32; - - if (bpp == 1) - { - width = (width + 7) / 8; - start = (y * width) + x / 8; - shift = x % 8; - if (pixel) - data[start] = data[start] | (0x80 >> shift); - else - data[start] = data[start] & ~(0x80 >> shift); - } - else if (bpp == 32) - { - dst32 = (int*) data; - dst32[y * width + x] = pixel; - } -} - -static INLINE void freerdp_color_split_rgb(UINT32* color, int bpp, BYTE* red, BYTE* green, BYTE* blue, BYTE* alpha, HCLRCONV clrconv) -{ - *red = *green = *blue = 0; - *alpha = (clrconv->alpha) ? 0xFF : 0x00; - - switch (bpp) - { - case 32: - if (clrconv->alpha) - { - GetARGB32(*alpha, *red, *green, *blue, *color); - } - else - { - GetRGB32(*red, *green, *blue, *color); - } - break; - - case 24: - GetRGB24(*red, *green, *blue, *color); - break; - - case 16: - GetRGB16(*red, *green, *blue, *color); - break; - - case 15: - GetRGB15(*red, *green, *blue, *color); - break; - - case 8: - *color &= 0xFF; - *red = clrconv->palette->entries[*color].red; - *green = clrconv->palette->entries[*color].green; - *blue = clrconv->palette->entries[*color].blue; - break; - - case 1: - if (*color != 0) - { - *red = 0xFF; - *green = 0xFF; - *blue = 0xFF; - } - break; - - default: - break; - } -} - -static INLINE void freerdp_color_split_bgr(UINT32* color, int bpp, BYTE* red, BYTE* green, BYTE* blue, BYTE* alpha, HCLRCONV clrconv) -{ - *red = *green = *blue = 0; - *alpha = (clrconv->alpha) ? 0xFF : 0x00; - - switch (bpp) - { - case 32: - if (clrconv->alpha) - { - GetABGR32(*alpha, *red, *green, *blue, *color); - } - else - { - GetBGR32(*red, *green, *blue, *color); - } - break; - - case 24: - GetBGR24(*red, *green, *blue, *color); - break; - - case 16: - GetBGR16(*red, *green, *blue, *color); - break; - - case 15: - GetBGR15(*red, *green, *blue, *color); - break; - - case 8: - *color &= 0xFF; - *red = clrconv->palette->entries[*color].red; - *green = clrconv->palette->entries[*color].green; - *blue = clrconv->palette->entries[*color].blue; - break; - - case 1: - if (*color != 0) - { - *red = 0xFF; - *green = 0xFF; - *blue = 0xFF; - } - break; - - default: - break; - } -} - -static INLINE void freerdp_color_make_rgb(UINT32* color, int bpp, BYTE* red, BYTE* green, BYTE* blue, BYTE* alpha, HCLRCONV clrconv) -{ - switch (bpp) - { - case 32: - *color = ARGB32(*alpha, *red, *green, *blue); - break; - - case 24: - *color = RGB24(*red, *green, *blue); - break; - - case 16: - if (clrconv->rgb555) - { - *color = RGB15(*red, *green, *blue); - } - else - { - *color = RGB16(*red, *green, *blue); - } - break; - - case 15: - *color = RGB15(*red, *green, *blue); - break; - - case 8: - *color = RGB24(*red, *green, *blue); - break; - - case 1: - if ((*red != 0) || (*green != 0) || (*blue != 0)) - *color = 1; - break; - - default: - break; - } -} - -static INLINE void freerdp_color_make_bgr(UINT32* color, int bpp, BYTE* red, BYTE* green, BYTE* blue, BYTE* alpha, HCLRCONV clrconv) -{ - switch (bpp) - { - case 32: - *color = ABGR32(*alpha, *red, *green, *blue); - break; - - case 24: - *color = BGR24(*red, *green, *blue); - break; - - case 16: - if (clrconv->rgb555) - { - *color = BGR15(*red, *green, *blue); - } - else - { - *color = BGR16(*red, *green, *blue); - } - break; - - case 15: - *color = BGR15(*red, *green, *blue); - break; - - case 8: - *color = BGR24(*red, *green, *blue); - break; - - case 1: - if ((*red != 0) || (*green != 0) || (*blue != 0)) - *color = 1; - break; - - default: - break; - } -} - -UINT32 freerdp_color_convert_rgb(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - BYTE red = 0; - BYTE green = 0; - BYTE blue = 0; - BYTE alpha = 0xFF; - UINT32 dstColor = 0; - - freerdp_color_split_rgb(&srcColor, srcBpp, &red, &green, &blue, &alpha, clrconv); - freerdp_color_make_rgb(&dstColor, dstBpp, &red, &green, &blue, &alpha, clrconv); - - return dstColor; -} - -UINT32 freerdp_color_convert_bgr(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - BYTE red = 0; - BYTE green = 0; - BYTE blue = 0; - BYTE alpha = 0xFF; - UINT32 dstColor = 0; - - freerdp_color_split_bgr(&srcColor, srcBpp, &red, &green, &blue, &alpha, clrconv); - freerdp_color_make_bgr(&dstColor, dstBpp, &red, &green, &blue, &alpha, clrconv); - - return dstColor; -} - -UINT32 freerdp_color_convert_rgb_bgr(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - BYTE red = 0; - BYTE green = 0; - BYTE blue = 0; - BYTE alpha = 0xFF; - UINT32 dstColor = 0; - - freerdp_color_split_rgb(&srcColor, srcBpp, &red, &green, &blue, &alpha, clrconv); - freerdp_color_make_bgr(&dstColor, dstBpp, &red, &green, &blue, &alpha, clrconv); - - return dstColor; -} - -UINT32 freerdp_color_convert_bgr_rgb(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - BYTE red = 0; - BYTE green = 0; - BYTE blue = 0; - BYTE alpha = 0xFF; - UINT32 dstColor = 0; - - freerdp_color_split_bgr(&srcColor, srcBpp, &red, &green, &blue, &alpha, clrconv); - freerdp_color_make_rgb(&dstColor, dstBpp, &red, &green, &blue, &alpha, clrconv); - - return dstColor; -} - -UINT32 freerdp_color_convert_var(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - if (clrconv->invert) - return freerdp_color_convert_var_bgr(srcColor, srcBpp, dstBpp, clrconv); - else - return freerdp_color_convert_var_rgb(srcColor, srcBpp, dstBpp, clrconv); -} - -UINT32 freerdp_color_convert_var_rgb(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - if (srcBpp == 8) - { - BYTE alpha = 0xFF; - UINT32 dstColor = 0; - PALETTE_ENTRY* entry = &clrconv->palette->entries[srcColor & 0xFF]; - - freerdp_color_make_bgr(&dstColor, dstBpp, &entry->red, &entry->green, &entry->blue, &alpha, clrconv); - - return dstColor; - } - - if (srcBpp > 16) - return freerdp_color_convert_bgr_rgb(srcColor, srcBpp, dstBpp, clrconv); - else - return freerdp_color_convert_rgb(srcColor, srcBpp, dstBpp, clrconv); -} - -UINT32 freerdp_color_convert_var_bgr(UINT32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - if (srcBpp == 8) - { - BYTE alpha = 0xFF; - UINT32 dstColor = 0; - PALETTE_ENTRY* entry = &clrconv->palette->entries[srcColor & 0xFF]; - - freerdp_color_make_rgb(&dstColor, dstBpp, &entry->red, &entry->green, &entry->blue, &alpha, clrconv); - - return dstColor; - } - - if (srcBpp > 16) - return freerdp_color_convert_bgr(srcColor, srcBpp, dstBpp, clrconv); - else - return freerdp_color_convert_rgb_bgr(srcColor, srcBpp, dstBpp, clrconv); -} - -UINT32 freerdp_convert_gdi_order_color(UINT32 color, int bpp, UINT32 format, BYTE* palette) -{ - UINT32 r = 0; - UINT32 g = 0; - UINT32 b = 0; - - switch (bpp) - { - case 32: - GetRGB32(r, g, b, color); - break; - - case 24: - GetRGB32(r, g, b, color); - break; - - case 16: - color = (color & (UINT32) 0xFF00) | ((color >> 16) & (UINT32) 0xFF); - GetRGB16(r, g, b, color); - break; - - case 15: - color = (color & (UINT32) 0xFF00) | ((color >> 16) & (UINT32) 0xFF); - GetRGB15(r, g, b, color); - break; - - case 8: - color = (color >> 16) & (UINT32) 0xFF; - if (palette) - { - r = palette[(color * 4) + 2]; - g = palette[(color * 4) + 1]; - b = palette[(color * 4) + 0]; - } - break; - - case 1: - r = g = b = 0; - if (color != 0) - r = g = b = 0xFF; - break; - - default: - return color; - break; - } - - if (FREERDP_PIXEL_FORMAT_TYPE(format) == FREERDP_PIXEL_FORMAT_TYPE_ABGR) - return BGR32(r, g, b); - - return RGB32(r, g, b); -} - -BYTE* freerdp_image_convert_8bpp(BYTE* srcData, BYTE* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - int i; - BYTE red; - BYTE green; - BYTE blue; - UINT32 pixel; - BYTE *src8; - UINT16 *dst16; - UINT32 *dst32; - - if (dstBpp == 8) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height, 16); - - if (!dstData) - return NULL; - - CopyMemory(dstData, srcData, width * height); - - return dstData; - } - else if (dstBpp == 15 || (dstBpp == 16 && clrconv->rgb555)) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 2, 16); - - if (!dstData) - return NULL; - - dst16 = (UINT16*) dstData; - - for (i = width * height; i > 0; i--) - { - pixel = *srcData; - srcData++; - red = clrconv->palette->entries[pixel].red; - green = clrconv->palette->entries[pixel].green; - blue = clrconv->palette->entries[pixel].blue; - pixel = (clrconv->invert) ? BGR15(red, green, blue) : RGB15(red, green, blue); - *dst16 = pixel; - dst16++; - } - - return dstData; - } - else if (dstBpp == 16) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 2, 16); - - if (!dstData) - return NULL; - - dst16 = (UINT16*) dstData; - - for (i = width * height; i > 0; i--) - { - pixel = *srcData; - srcData++; - red = clrconv->palette->entries[pixel].red; - green = clrconv->palette->entries[pixel].green; - blue = clrconv->palette->entries[pixel].blue; - pixel = (clrconv->invert) ? BGR16(red, green, blue) : RGB16(red, green, blue); - *dst16 = pixel; - dst16++; - } - - return dstData; - } - else if (dstBpp == 32) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 4, 16); - - if (!dstData) - return NULL; - - src8 = (BYTE*) srcData; - dst32 = (UINT32*) dstData; - - for (i = width * height; i > 0; i--) - { - pixel = *src8; - src8++; - - red = clrconv->palette->entries[pixel].red; - green = clrconv->palette->entries[pixel].green; - blue = clrconv->palette->entries[pixel].blue; - - if (clrconv->alpha) - { - pixel = (clrconv->invert) ? ABGR32(0xFF, red, green, blue) : ARGB32(0xFF, red, green, blue); - } - else - { - pixel = (clrconv->invert) ? BGR32(red, green, blue) : RGB32(red, green, blue); - } - - *dst32 = pixel; - dst32++; - } - - return dstData; - } - - return srcData; -} - -BYTE* freerdp_image_convert_15bpp(BYTE* srcData, BYTE* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - int i; - BYTE red; - BYTE green; - BYTE blue; - UINT32 pixel; - UINT16 *src16; - UINT16 *dst16; - UINT32 *dst32; - - if (dstBpp == 15 || (dstBpp == 16 && clrconv->rgb555)) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 2, 16); - - if (!dstData) - return NULL; - - CopyMemory(dstData, srcData, width * height * 2); - - return dstData; - } - else if (dstBpp == 32) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 4, 16); - - if (!dstData) - return NULL; - - src16 = (UINT16*) srcData; - dst32 = (UINT32*) dstData; - - for (i = width * height; i > 0; i--) - { - pixel = *src16; - src16++; - GetBGR15(red, green, blue, pixel); - if (clrconv->alpha) - { - pixel = (clrconv->invert) ? ARGB32(0xFF, red, green, blue) : ABGR32(0xFF, red, green, blue); - } - else - { - pixel = (clrconv->invert) ? RGB32(red, green, blue) : BGR32(red, green, blue); - } - *dst32 = pixel; - dst32++; - } - - return dstData; - } - else if (dstBpp == 16) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 2, 16); - - if (!dstData) - return NULL; - - src16 = (UINT16*) srcData; - dst16 = (UINT16*) dstData; - - for (i = width * height; i > 0; i--) - { - pixel = *src16; - src16++; - GetRGB_555(red, green, blue, pixel); - RGB_555_565(red, green, blue); - pixel = (clrconv->invert) ? BGR565(red, green, blue) : RGB565(red, green, blue); - *dst16 = pixel; - dst16++; - } - - return dstData; - } - - return srcData; -} - -BYTE* freerdp_image_convert_16bpp(BYTE* srcData, BYTE* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - if (srcBpp == 15) - return freerdp_image_convert_15bpp(srcData, dstData, width, height, srcBpp, dstBpp, clrconv); - - if (dstBpp == 16) - { - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 2, 16); - - if (!dstData) - return NULL; - - if (clrconv->rgb555) - { - int i; - BYTE red, green, blue; - UINT16* src16 = (UINT16 *) srcData; - UINT16* dst16 = (UINT16 *) dstData; - - for (i = width * height; i > 0; i--) - { - GetRGB_565(red, green, blue, (*src16)); - RGB_565_555(red, green, blue); - (*dst16) = (clrconv->invert) ? BGR555(red, green, blue) : RGB555(red, green, blue); - src16++; - dst16++; - } - } - else - { - CopyMemory(dstData, srcData, width * height * 2); - } - - return dstData; - } - else if (dstBpp == 24) - { - int i; - BYTE *dst8; - UINT16 *src16; - BYTE red, green, blue; - - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 3, 16); - - if (!dstData) - return NULL; - - dst8 = (BYTE*) dstData; - src16 = (UINT16*) srcData; - - for (i = width * height; i > 0; i--) - { - GetBGR16(red, green, blue, *src16); - src16++; - - if (clrconv->invert) - { - *dst8++ = blue; - *dst8++ = green; - *dst8++ = red; - } - else - { - *dst8++ = red; - *dst8++ = green; - *dst8++ = blue; - } - } - - return dstData; - } - else if (dstBpp == 32) - { - primitives_t* prims; - - if (!dstData) - dstData = _aligned_malloc(width * height * sizeof(UINT32), 16); - - if (!dstData) - return NULL; - - prims = primitives_get(); - prims->RGB565ToARGB_16u32u_C3C4( - (const UINT16*) srcData, width * sizeof(UINT16), - (UINT32*) dstData, width * sizeof(UINT32), - width, height, clrconv->alpha, clrconv->invert); - - return dstData; - } - - return srcData; -} - -BYTE* freerdp_image_convert_24bpp(BYTE* srcData, BYTE* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - int i; - - if (dstBpp == 32) - { - UINT32 pixel, alpha_mask, temp; - UINT32* srcp; - UINT32* dstp; - - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 4, 16); - - if (!dstData) - return NULL; - - alpha_mask = clrconv->alpha ? 0xFF000000 : 0; - - srcp = (UINT32*) srcData; - dstp = (UINT32*) dstData; - - if (clrconv->invert) - { - /* Each iteration handles four pixels using 32-bit load and - store operations. */ - for (i = ((width * height) / 4); i > 0; i--) - { - temp = 0; - - pixel = temp; - temp = *srcp++; - pixel |= temp & 0x00FFFFFF; - temp = temp >> 24; - *dstp++ = alpha_mask | RGB32_to_BGR32(pixel); - - pixel = temp; - temp = *srcp++; - pixel |= (temp & 0x0000FFFF) << 8; - temp = temp >> 16; - *dstp++ = alpha_mask | RGB32_to_BGR32(pixel); - - pixel = temp; - temp = *srcp++; - pixel |= (temp & 0x000000FF) << 16; - temp = temp >> 8; - *dstp++ = alpha_mask | RGB32_to_BGR32(pixel); - - *dstp++ = alpha_mask | RGB32_to_BGR32(temp); - } - - /* Handle any remainder. */ - for (i = (width * height) % 4; i > 0; i--) - { - pixel = ABGR32(alpha_mask, srcData[2], srcData[1], srcData[0]); - *dstp++ = pixel; - srcData += 3; - } - } - else - { - for (i = ((width * height) / 4); i > 0; i--) - { - temp = 0; - - pixel = temp; - temp = *srcp++; - pixel |= temp & 0x00FFFFFF; - temp = temp >> 24; - *dstp++ = alpha_mask | pixel; - - pixel = temp; - temp = *srcp++; - pixel |= (temp & 0x0000FFFF) << 8; - temp = temp >> 16; - *dstp++ = alpha_mask | pixel; - - pixel = temp; - temp = *srcp++; - pixel |= (temp & 0x000000FF) << 16; - temp = temp >> 8; - *dstp++ = alpha_mask | pixel; - - *dstp++ = alpha_mask | temp; - } - - for (i = (width * height) % 4; i > 0; i--) - { - pixel = ARGB32(alpha_mask, srcData[2], srcData[1], srcData[0]); - *dstp++ = pixel; - srcData += 3; - } - } - - return dstData; - } - - return srcData; -} - -BYTE* freerdp_image_convert_32bpp(BYTE* srcData, BYTE* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - if (dstBpp == 16) - { - int index; - UINT16 *dst16; - UINT32 *src32; - BYTE red, green, blue; - - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 2, 16); - - if (!dstData) - return NULL; - - dst16 = (UINT16*) dstData; - src32 = (UINT32*) srcData; - - for (index = 0; index < width * height; index++) - { - GetBGR32(blue, green, red, *src32); - *dst16 = (clrconv->invert) ? BGR16(red, green, blue) : RGB16(red, green, blue); - src32++; - dst16++; - } - - return dstData; - } - else if (dstBpp == 24) - { - int index; - BYTE* dstp; - BYTE red, green, blue; - - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 3, 16); - - if (!dstData) - return NULL; - - dstp = dstData; - - for (index = 0; index < width * height; index++) - { - red = *(srcData++); - green = *(srcData++); - blue = *(srcData++); - - if (clrconv->invert) - { - *dstp++ = blue; - *dstp++ = green; - *dstp++ = red; - } - else - { - *dstp++ = red; - *dstp++ = green; - *dstp++ = blue; - } - - srcData++; - } - - return dstData; - } - else if (dstBpp == 32) - { - int i; - UINT32 pixel; - UINT32 alpha_mask; - UINT32* srcp; - UINT32* dstp; - BYTE red, green, blue; - - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * 4, 16); - - if (!dstData) - return NULL; - - alpha_mask = clrconv->alpha ? 0xFF000000 : 0; - - srcp = (UINT32*) srcData; - dstp = (UINT32*) dstData; - - if (clrconv->invert) - { - for (i = width * height; i > 0; i--) - { - pixel = *srcp; - srcp++; - GetRGB32(red, green, blue, pixel); - pixel = alpha_mask | BGR32(red, green, blue); - *dstp = pixel; - dstp++; - } - } - else - { - for (i = width * height; i > 0; i--) - { - pixel = *srcp; - srcp++; - GetRGB32(red, green, blue, pixel); - pixel = alpha_mask | RGB32(red, green, blue); - *dstp = pixel; - dstp++; - } - } - - return dstData; - } - - return srcData; -} - -p_freerdp_image_convert freerdp_image_convert_[5] = -{ - NULL, - freerdp_image_convert_8bpp, - freerdp_image_convert_16bpp, - freerdp_image_convert_24bpp, - freerdp_image_convert_32bpp -}; - -BYTE* freerdp_image_convert(BYTE* srcData, BYTE* dstData, int width, int height, int srcBpp, int dstBpp, HCLRCONV clrconv) -{ - p_freerdp_image_convert _p_freerdp_image_convert = freerdp_image_convert_[IBPP(srcBpp)]; - - if (_p_freerdp_image_convert != NULL) - return _p_freerdp_image_convert(srcData, dstData, width, height, srcBpp, dstBpp, clrconv); - else - return 0; -} - -void freerdp_bitmap_flip(BYTE * src, BYTE * dst, int scanLineSz, int height) -{ - int i; - - BYTE * bottomLine = dst + (scanLineSz * (height - 1)); - BYTE * topLine = src; - - /* Special processing if called for flip-in-place. */ - if (src == dst) - { - /* Allocate a scanline buffer. - * (FIXME: malloc / xfree below should be replaced by "get/put - * scanline buffer from a pool/Q of fixed buffers" to reuse - * fixed size buffers (of max scanline size (or adaptative?) ) - * -- would be much faster). - */ - BYTE* tmpBfr = _aligned_malloc(scanLineSz, 16); - int half = height / 2; - /* Flip buffer in place by line permutations through the temp - * scan line buffer. - * Note that if height has an odd number of line, we don't need - * to move the center scanline anyway. - * Also note that in place flipping takes three memcpy() calls - * to process two scanlines while src to distinct dest would - * only requires two memcpy() calls for two scanlines. - */ - height--; - for (i = 0; i < half ; i++) - { - CopyMemory(tmpBfr, topLine, scanLineSz); - CopyMemory(topLine, bottomLine, scanLineSz); - CopyMemory(bottomLine, tmpBfr, scanLineSz); - topLine += scanLineSz; - bottomLine -= scanLineSz; - height--; - } - _aligned_free(tmpBfr); - } - /* Flip from source buffer to destination buffer. */ - else - { - - for (i = 0; i < height; i++) - { - CopyMemory(bottomLine, topLine, scanLineSz); - topLine += scanLineSz; - bottomLine -= scanLineSz; - } - } - -} - -BYTE* freerdp_image_flip(BYTE* srcData, BYTE* dstData, int width, int height, int bpp) -{ - int scanline; - - scanline = width * ((bpp + 7) / 8); - - if (!dstData) - dstData = (BYTE*) _aligned_malloc(width * height * ((bpp + 7) / 8), 16); - - if (!dstData) - return NULL; - - freerdp_bitmap_flip(srcData, dstData, scanline, height); - - return dstData; -} - -BYTE* freerdp_icon_convert(BYTE* srcData, BYTE* dstData, BYTE* mask, int width, int height, int bpp, HCLRCONV clrconv) -{ - BYTE* data; - BYTE bmask; - UINT32* icon; - int x, y, bit; - int maskIndex; - - if (bpp == 16) - { - /* Server sends 16 bpp field, but data is usually 15-bit 555 */ - bpp = 15; - } - - data = freerdp_image_flip(srcData, dstData, width, height, bpp); - dstData = freerdp_image_convert(data, NULL, width, height, bpp, 32, clrconv); - _aligned_free(data); - - /* Read the AND alpha plane */ - if (bpp < 32) - { - maskIndex = 0; - icon = (UINT32*) dstData; - - for (y = 0; y < height; y++) - { - for (x = 0; x < width-7; x+=8) - { - bmask = mask[maskIndex++]; - - for (bit = 0; bit < 8; bit++) - if ((bmask & (0x80 >> bit)) == 0) - { - UINT32 *tmp = (icon + (height - y - 1) * width + x + bit); - if (tmp) - *tmp |= 0xFF000000; - } - } - - if ((width % 8) != 0) - { - bmask = mask[maskIndex++]; - - for (bit = 0; bit < width % 8; bit++) - if ((bmask & (0x80 >> bit)) == 0) - { - UINT32 *tmp = (icon + (height - y - 1) * width + x + bit); - if (tmp) - *tmp |= 0xFF000000; - } - } - - /* Skip padding */ - if ((width % 32) != 0) - maskIndex += (32 - (width % 32)) / 8; - } - } - - return dstData; -} - -BYTE* freerdp_glyph_convert(int width, int height, BYTE* data) -{ - int x, y; - BYTE* srcp; + UINT32 x, y; + const BYTE* srcp; BYTE* dstp; BYTE* dstData; - int scanline; - + UINT32 scanline; /* * converts a 1-bit-per-pixel glyph to a one-byte-per-pixel glyph: * this approach uses a little more memory, but provides faster * means of accessing individual pixels in blitting operations */ - scanline = (width + 7) / 8; dstData = (BYTE*) _aligned_malloc(width * height, 16); @@ -1115,6 +64,7 @@ BYTE* freerdp_glyph_convert(int width, int height, BYTE* data) { if ((*srcp & (0x80 >> (x % 8))) != 0) *dstp = 0xFF; + dstp++; if (((x + 1) % 8 == 0) && x != 0) @@ -1125,300 +75,75 @@ BYTE* freerdp_glyph_convert(int width, int height, BYTE* data) return dstData; } -BYTE* freerdp_mono_image_convert(BYTE* srcData, int width, int height, int srcBpp, int dstBpp, UINT32 bgcolor, UINT32 fgcolor, HCLRCONV clrconv) +int freerdp_image_copy_from_monochrome(BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, + UINT32 backColor, UINT32 foreColor, + const UINT32* palette) { - int index; - UINT16* dst16; - UINT32* dst32; - BYTE* dstData; - BYTE bitMask; - int bitIndex; - BYTE redBg, greenBg, blueBg; - BYTE redFg, greenFg, blueFg; - - GetRGB32(redBg, greenBg, blueBg, bgcolor); - GetRGB32(redFg, greenFg, blueFg, fgcolor); - - if (dstBpp == 16) - { - dstData = (BYTE*) _aligned_malloc(width * height * 2, 16); - - if (!dstData) - return NULL; - - dst16 = (UINT16*) dstData; - - if (clrconv->rgb555) - { - bgcolor = clrconv->invert ? BGR15(redBg, greenBg, blueBg) : RGB15(redBg, greenBg, blueBg); - fgcolor = clrconv->invert ? BGR15(redFg, greenFg, blueFg) : RGB15(redFg, greenFg, blueFg); - } - else - { - bgcolor = clrconv->invert ? BGR16(redBg, greenBg, blueBg) : RGB16(redBg, greenBg, blueBg); - fgcolor = clrconv->invert ? BGR16(redFg, greenFg, blueFg) : RGB16(redFg, greenFg, blueFg); - } - - for (index = height; index > 0; index--) - { - /* each bit encodes a pixel */ - bitMask = *srcData; - for (bitIndex = 7; bitIndex >= 0; bitIndex--) - { - if ((bitMask >> bitIndex) & 0x01) - { - *dst16 = bgcolor; - } - else - { - *dst16 = fgcolor; - } - dst16++; - } - srcData++; - } - return dstData; - } - else if (dstBpp == 32) - { - dstData = (BYTE*) _aligned_malloc(width * height * 4, 16); - - if (!dstData) - return NULL; - - dst32 = (UINT32*) dstData; - - for (index = height; index > 0; index--) - { - /* each bit encodes a pixel */ - bitMask = *srcData; - - for (bitIndex = 7; bitIndex >= 0; bitIndex--) - { - if ((bitMask >> bitIndex) & 0x01) - { - if (clrconv->alpha) - { - *dst32 = (clrconv->invert) ? ABGR32(0xFF, redBg, greenBg, blueBg) : ARGB32(0xFF, redBg, greenBg, blueBg); - } - else - { - *dst32 = (clrconv->invert) ? BGR32(redBg, greenBg, blueBg) : RGB32(redBg, greenBg, blueBg); - } - } - else - { - if (clrconv->alpha) - { - *dst32 = (clrconv->invert) ? ABGR32(0xFF, redFg, greenFg, blueFg) : ARGB32(0xFF, redFg, greenFg, blueFg); - } - else - { - *dst32 = (clrconv->invert) ? BGR32(redFg, greenFg, blueFg) : RGB32(redFg, greenFg, blueFg); - } - } - dst32++; - } - srcData++; - } - return dstData; - } - - return srcData; -} - -int freerdp_image_copy_from_monochrome(BYTE* pDstData, UINT32 DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, UINT32 backColor, UINT32 foreColor, BYTE* palette) -{ - int x, y; + UINT32 x, y; BOOL vFlip; - BOOL invert; - int srcFlip; - int dstFlip; - int nDstPad; - int monoStep; + UINT32 srcFlip; + UINT32 dstFlip; + UINT32 nDstPad; + UINT32 monoStep; UINT32 monoBit; - BYTE* monoBits; + const BYTE* monoBits; UINT32 monoPixel; - BYTE a, r, g, b; - int dstBitsPerPixel; - int dstBytesPerPixel; - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); + UINT32 dstBitsPerPixel; + UINT32 dstBytesPerPixel; + dstBitsPerPixel = GetBitsPerPixel(DstFormat); + dstBytesPerPixel = GetBytesPerPixel(DstFormat); dstFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat); if (nDstStep < 0) nDstStep = dstBytesPerPixel * nWidth; nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - srcFlip = FREERDP_PIXEL_FLIP_NONE; vFlip = (srcFlip != dstFlip) ? TRUE : FALSE; - - invert = (FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat)) ? TRUE : FALSE; - backColor |= 0xFF000000; foreColor |= 0xFF000000; - + backColor = ConvertColor(backColor, PIXEL_FORMAT_ARGB32, DstFormat, palette); + foreColor = ConvertColor(foreColor, PIXEL_FORMAT_ARGB32, DstFormat, palette); monoStep = (nWidth + 7) / 8; + UINT32* pDstPixel; - if (dstBytesPerPixel == 4) + for (y = 0; y < nHeight; y++) { - UINT32* pDstPixel; + BYTE* pDstLine = &pDstData[((nYDst + y) * nDstStep)]; + monoBit = 0x80; - if (invert) - { - GetARGB32(a, r, g, b, backColor); - backColor = ABGR32(a, r, g, b); - - GetARGB32(a, r, g, b, foreColor); - foreColor = ABGR32(a, r, g, b); - } - - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - monoBit = 0x80; - - if (!vFlip) - monoBits = &pSrcData[monoStep * y]; - else - monoBits = &pSrcData[monoStep * (nHeight - y - 1)]; - - for (x = 0; x < nWidth; x++) - { - monoPixel = (*monoBits & monoBit) ? 1 : 0; - if (!(monoBit >>= 1)) { monoBits++; monoBit = 0x80; } - - if (monoPixel) - *pDstPixel++ = backColor; - else - *pDstPixel++ = foreColor; - } - - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - - return 1; - } - else if (dstBytesPerPixel == 2) - { - UINT16* pDstPixel; - UINT16 backColor16; - UINT16 foreColor16; - - if (!invert) - { - if (dstBitsPerPixel == 15) - { - GetRGB32(r, g, b, backColor); - backColor16 = RGB15(r, g, b); - - GetRGB32(r, g, b, foreColor); - foreColor16 = RGB15(r, g, b); - } - else - { - GetRGB32(r, g, b, backColor); - backColor16 = RGB16(r, g, b); - - GetRGB32(r, g, b, foreColor); - foreColor16 = RGB16(r, g, b); - } - } + if (!vFlip) + monoBits = &pSrcData[monoStep * y]; else + monoBits = &pSrcData[monoStep * (nHeight - y - 1)]; + + for (x = 0; x < nWidth; x++) { - if (dstBitsPerPixel == 15) - { - GetRGB32(r, g, b, backColor); - backColor16 = BGR15(r, g, b); + BYTE* pDstPixel = &pDstLine[((nXDst + x) * GetBytesPerPixel(DstFormat))]; + monoPixel = (*monoBits & monoBit) ? 1 : 0; - GetRGB32(r, g, b, foreColor); - foreColor16 = BGR15(r, g, b); + if (!(monoBit >>= 1)) + { + monoBits++; + monoBit = 0x80; } + + if (monoPixel) + WriteColor(pDstPixel, DstFormat, backColor); else - { - GetRGB32(r, g, b, backColor); - backColor16 = BGR16(r, g, b); - - GetRGB32(r, g, b, foreColor); - foreColor16 = BGR16(r, g, b); - } + WriteColor(pDstPixel, DstFormat, foreColor); } - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - monoBit = 0x80; - - if (!vFlip) - monoBits = &pSrcData[monoStep * y]; - else - monoBits = &pSrcData[monoStep * (nHeight - y - 1)]; - - for (x = 0; x < nWidth; x++) - { - monoPixel = (*monoBits & monoBit) ? 1 : 0; - if (!(monoBit >>= 1)) { monoBits++; monoBit = 0x80; } - - if (monoPixel) - *pDstPixel++ = backColor16; - else - *pDstPixel++ = foreColor16; - } - - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - - return 1; + pDstPixel = (UINT32*) & ((BYTE*) pDstPixel)[nDstPad]; } - WLog_ERR(TAG, "failure: dstBytesPerPixel: %d dstBitsPerPixel: %d", - dstBytesPerPixel, dstBitsPerPixel); - - return -1; + return 1; } -void freerdp_alpha_cursor_convert(BYTE* alphaData, BYTE* xorMask, BYTE* andMask, int width, int height, int bpp, HCLRCONV clrconv) -{ - UINT32 xorPixel; - UINT32 andPixel; - UINT32 x, y, jj; - - for (y = 0; y < height; y++) - { - jj = (bpp == 1) ? y : (height - 1) - y; - - for (x = 0; x < width; x++) - { - xorPixel = freerdp_get_pixel(xorMask, x, jj, width, height, bpp); - xorPixel = freerdp_color_convert_rgb(xorPixel, bpp, 32, clrconv); - andPixel = freerdp_get_pixel(andMask, x, jj, width, height, 1); - - if (andPixel) - { - if ((xorPixel & 0xFFFFFF) == 0xFFFFFF) - { - /* use pattern (not solid black) for xor area */ - xorPixel = (x & 1) == (y & 1); - xorPixel = xorPixel ? 0xFFFFFF : 0; - xorPixel |= 0xFF000000; - } - else if (xorPixel == 0xFF000000) - { - xorPixel = 0; - } - } - - freerdp_set_pixel(alphaData, x, y, width, height, 32, xorPixel); - } - } -} - -static INLINE UINT32 freerdp_image_inverted_pointer_color(int x, int y) +static INLINE UINT32 freerdp_image_inverted_pointer_color(UINT32 x, UINT32 y) { #if 1 /** @@ -1430,7 +155,6 @@ static INLINE UINT32 freerdp_image_inverted_pointer_color(int x, int y) * This function returns either black or white, depending on the * pixel's position. */ - return (x + y) & 1 ? 0xFF000000 : 0xFFFFFFFF; #else return 0xFF000000; @@ -1445,2337 +169,367 @@ static INLINE UINT32 freerdp_image_inverted_pointer_color(int x, int y) * http://msdn.microsoft.com/en-us/library/windows/hardware/ff556138/ */ -int freerdp_image_copy_from_pointer_data(BYTE* pDstData, UINT32 DstFormat, - int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* xorMask, - UINT32 xorMaskLength, BYTE* andMask, - UINT32 andMaskLength, UINT32 xorBpp, - BYTE* palette) +BOOL freerdp_image_copy_from_pointer_data( + BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, + const BYTE* xorMask, UINT32 xorMaskLength, + const BYTE* andMask, UINT32 andMaskLength, + UINT32 xorBpp, const UINT32* palette) { - int x, y; + UINT32 x, y; BOOL vFlip; - BOOL invert; - int srcFlip; - int dstFlip; - int nDstPad; - int xorStep; - int andStep; + UINT32 srcFlip; + UINT32 dstFlip; + UINT32 nDstPad; + UINT32 xorStep; + UINT32 andStep; UINT32 xorBit; UINT32 andBit; - BYTE* xorBits; - BYTE* andBits; + const BYTE* xorBits; + const BYTE* andBits; UINT32 xorPixel; UINT32 andPixel; - int dstBitsPerPixel; - int dstBytesPerPixel; - - xorBits = xorMask; - andBits = andMask; - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); + UINT32 dstBitsPerPixel; + UINT32 dstBytesPerPixel; + dstBitsPerPixel = GetBitsPerPixel(DstFormat); + dstBytesPerPixel = GetBytesPerPixel(DstFormat); dstFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat); + if (FREERDP_PIXEL_FORMAT_FLIP(DstFormat)) + { + WLog_ERR(TAG, "Format %s not supported!", GetColorFormatName(DstFormat)); + } + if (nDstStep < 0) nDstStep = dstBytesPerPixel * nWidth; nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - srcFlip = (xorBpp == 1) ? FREERDP_PIXEL_FLIP_NONE : FREERDP_PIXEL_FLIP_VERTICAL; - vFlip = (srcFlip != dstFlip) ? TRUE : FALSE; - invert = (FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat)) ? TRUE : FALSE; - andStep = (nWidth + 7) / 8; andStep += (andStep % 2); if (!xorMask || (xorMaskLength == 0)) return -1; - if (dstBytesPerPixel == 4) + if (xorBpp == 1) { - UINT32* pDstPixel; + if (!andMask || (andMaskLength == 0)) + return -1; - if (xorBpp == 1) + xorStep = (nWidth + 7) / 8; + xorStep += (xorStep % 2); + + if (xorStep * nHeight > xorMaskLength) + return -1; + + if (andStep * nHeight > andMaskLength) + return -1; + + for (y = 0; y < nHeight; y++) { - if (!andMask || (andMaskLength == 0)) - return -1; + BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + + (nXDst * GetBytesPerPixel(DstFormat))]; + xorBit = andBit = 0x80; - xorStep = (nWidth + 7) / 8; - xorStep += (xorStep % 2); + if (!vFlip) + { + xorBits = &xorMask[xorStep * y]; + andBits = &andMask[andStep * y]; + } + else + { + xorBits = &xorMask[xorStep * (nHeight - y - 1)]; + andBits = &andMask[andStep * (nHeight - y - 1)]; + } - if (xorStep * nHeight > xorMaskLength) - return -1; + for (x = 0; x < nWidth; x++) + { + UINT32 color; + xorPixel = (*xorBits & xorBit) ? 1 : 0; + if (!(xorBit >>= 1)) + { + xorBits++; + xorBit = 0x80; + } + + andPixel = (*andBits & andBit) ? 1 : 0; + + if (!(andBit >>= 1)) + { + andBits++; + andBit = 0x80; + } + + if (!andPixel && !xorPixel) + color = 0xFF000000; /* black */ + else if (!andPixel && xorPixel) + color = 0xFFFFFFFF; /* white */ + else if (andPixel && !xorPixel) + color = 0x00000000; /* transparent */ + else if (andPixel && xorPixel) + color = freerdp_image_inverted_pointer_color(x, y); /* inverted */ + + color = ConvertColor(color, PIXEL_FORMAT_ABGR32, + DstFormat, NULL); + WriteColor(pDstPixel, DstFormat, color); + pDstPixel += GetBytesPerPixel(DstFormat); + } + } + + return 1; + } + else if (xorBpp == 24 || xorBpp == 32 || xorBpp == 16 || xorBpp == 8) + { + UINT32 xorBytesPerPixel = xorBpp >> 3; + xorStep = nWidth * xorBytesPerPixel; + + if (xorBpp == 8 && !palette) + { + WLog_ERR(TAG, "null palette in convertion from %d bpp to %d bpp", + xorBpp, dstBitsPerPixel); + return -1; + } + + if (xorStep * nHeight > xorMaskLength) + return -1; + + if (andMask) + { if (andStep * nHeight > andMaskLength) return -1; - - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - xorBit = andBit = 0x80; - - if (!vFlip) - { - xorBits = &xorMask[xorStep * y]; - andBits = &andMask[andStep * y]; - } - else - { - xorBits = &xorMask[xorStep * (nHeight - y - 1)]; - andBits = &andMask[andStep * (nHeight - y - 1)]; - } - - for (x = 0; x < nWidth; x++) - { - xorPixel = (*xorBits & xorBit) ? 1 : 0; - if (!(xorBit >>= 1)) { xorBits++; xorBit = 0x80; } - - andPixel = (*andBits & andBit) ? 1 : 0; - if (!(andBit >>= 1)) { andBits++; andBit = 0x80; } - - if (!andPixel && !xorPixel) - *pDstPixel++ = 0xFF000000; /* black */ - else if (!andPixel && xorPixel) - *pDstPixel++ = 0xFFFFFFFF; /* white */ - else if (andPixel && !xorPixel) - *pDstPixel++ = 0x00000000; /* transparent */ - else if (andPixel && xorPixel) - *pDstPixel++ = freerdp_image_inverted_pointer_color(x, y); /* inverted */ - } - - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - - return 1; } - else if (xorBpp == 24 || xorBpp == 32 || xorBpp == 16 || xorBpp == 8) + + for (y = 0; y < nHeight; y++) { - int xorBytesPerPixel = xorBpp >> 3; - xorStep = nWidth * xorBytesPerPixel; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; + BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + + (nXDst * GetBytesPerPixel(DstFormat))]; + andBit = 0x80; - if (xorBpp == 8 && !palette) + if (!vFlip) { - WLog_ERR(TAG, "null palette in conversion from %d bpp to %d bpp", - xorBpp, dstBitsPerPixel); - return -1; + if (andMask) + andBits = &andMask[andStep * y]; + + xorBits = &xorMask[xorStep * y]; + } + else + { + if (andMask) + andBits = &andMask[andStep * (nHeight - y - 1)]; + + xorBits = &xorMask[xorStep * (nHeight - y - 1)]; } - if (xorStep * nHeight > xorMaskLength) - return -1; - - if (andMask) + for (x = 0; x < nWidth; x++) { - if (andStep * nHeight > andMaskLength) - return -1; - } + UINT32 color; + BOOL ignoreAndMask = FALSE; - for (y = 0; y < nHeight; y++) - { - andBit = 0x80; - - if (!vFlip) + if (xorBpp == 32) { - if (andMask) - andBits = &andMask[andStep * y]; - xorBits = &xorMask[xorStep * y]; + xorPixel = *((UINT32*) xorBits); + + if (xorPixel & 0xFF000000) + ignoreAndMask = TRUE; + } + else if (xorBpp == 16) + { + xorPixel = ConvertColor(*(UINT16*)xorBits, + PIXEL_FORMAT_RGB16, + PIXEL_FORMAT_ABGR32, + NULL); + } + else if (xorBpp == 8) + { + xorPixel = 0xFF << 24 | ((UINT32*)palette)[xorBits[0]]; } else { - if (andMask) - andBits = &andMask[andStep * (nHeight - y - 1)]; - xorBits = &xorMask[xorStep * (nHeight - y - 1)]; + xorPixel = xorBits[0] | xorBits[1] << 8 | xorBits[2] << 16 | 0xFF << 24; } - for (x = 0; x < nWidth; x++) + xorBits += xorBytesPerPixel; + andPixel = 0; + + if (andMask) { - BOOL ignoreAndMask = FALSE; + andPixel = (*andBits & andBit) ? 1 : 0; - if (xorBpp == 32) + if (!(andBit >>= 1)) { - xorPixel = *((UINT32*) xorBits); - if (xorPixel & 0xFF000000) - ignoreAndMask = TRUE; - } - else if (xorBpp == 16) - { - UINT16 r, g, b; - GetRGB16(r, g, b, *(UINT16*)xorBits); - xorPixel = ARGB32(0xFF, r, g, b); - } - else if (xorBpp == 8) - { - xorPixel = 0xFF << 24 | ((UINT32*)palette)[xorBits[0]]; - } - else - { - xorPixel = xorBits[0] | xorBits[1] << 8 | xorBits[2] << 16 | 0xFF << 24; - } - - xorBits += xorBytesPerPixel; - - andPixel = 0; - if (andMask) - { - andPixel = (*andBits & andBit) ? 1 : 0; - if (!(andBit >>= 1)) { andBits++; andBit = 0x80; } - } - - /* Ignore the AND mask, if the color format already supplies alpha data. */ - if (andPixel && !ignoreAndMask) - { - const UINT32 xorPixelMasked = xorPixel | 0xFF000000; - - if (xorPixelMasked == 0xFF000000) /* black -> transparent */ - *pDstPixel++ = 0x00000000; - else if (xorPixelMasked == 0xFFFFFFFF) /* white -> inverted */ - *pDstPixel++ = freerdp_image_inverted_pointer_color(x, y); - else - *pDstPixel++ = xorPixel; - } - else - { - *pDstPixel++ = xorPixel; + andBits++; + andBit = 0x80; } } - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } + /* Ignore the AND mask, if the color format already supplies alpha data. */ + if (andPixel && !ignoreAndMask) + { + const UINT32 xorPixelMasked = xorPixel | 0xFF000000; - return 1; + if (xorPixelMasked == 0xFF000000) /* black -> transparent */ + color = 0x00000000; + else if (xorPixelMasked == 0xFFFFFFFF) /* white -> inverted */ + color = freerdp_image_inverted_pointer_color(x, y); + else + color = xorPixel; + + color = ConvertColor(color, PIXEL_FORMAT_ABGR32, DstFormat, NULL); + } + else + { + color = ConvertColor(xorPixel, PIXEL_FORMAT_ABGR32, + DstFormat, NULL); + } + + WriteColor(pDstPixel, DstFormat, color); + pDstPixel += GetBytesPerPixel(DstFormat); + } } + + return 1; } WLog_ERR(TAG, "failed to convert from %d bpp to %d bpp", - xorBpp, dstBitsPerPixel); - + xorBpp, dstBitsPerPixel); return -1; } -void freerdp_image_swap_color_order(BYTE* data, int width, int height) + +BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, + INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, DWORD SrcFormat, + INT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + const UINT32* palette) { - int x, y; - UINT32* pixel; - BYTE a, r, g, b; + const UINT32 dstByte = GetBytesPerPixel(DstFormat); + const UINT32 srcByte = GetBytesPerPixel(SrcFormat); + const UINT32 copyDstWidth = nWidth * dstByte; + const UINT32 xSrcOffset = nXSrc * srcByte; + const UINT32 xDstOffset = nXDst * dstByte; + BOOL vSrcVFlip = FALSE; + BOOL vDstVFlip = FALSE; + BOOL vSrcHFlip = FALSE; + BOOL vDstHFlip = FALSE; + UINT32 srcVOffset = 0; + INT32 srcVMultiplier = 1; + UINT32 dstVOffset = 0; + INT32 dstVMultiplier = 1; - pixel = (UINT32*) data; + if (!pDstData || !pSrcData) + return FALSE; - for (y = 0; y < height; y++) + switch (FREERDP_PIXEL_FORMAT_FLIP(SrcFormat)) { - for (x = 0; x < width; x++) - { - GetARGB32(a, r, g, b, *pixel); - *pixel = ABGR32(a, r, g, b); - pixel++; - } - } -} + case FREERDP_PIXEL_FLIP_HORIZONTAL: + vSrcHFlip = TRUE; + return FALSE; -HCLRCONV freerdp_clrconv_new(UINT32 flags) -{ - HCLRCONV clrconv; + case FREERDP_PIXEL_FLIP_VERTICAL: + vSrcVFlip = TRUE; + break; - clrconv = (CLRCONV*) calloc(1, sizeof(CLRCONV)); - - if (!clrconv) - return NULL; - - clrconv->alpha = (flags & CLRCONV_ALPHA) ? TRUE : FALSE; - clrconv->invert = (flags & CLRCONV_INVERT) ? TRUE : FALSE; - clrconv->rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE; - - clrconv->palette = (rdpPalette*) calloc(1, sizeof(rdpPalette)); - - if (!clrconv->palette) - { - free (clrconv); - return NULL; + case FREERDP_PIXEL_FLIP_NONE: + default: + break; } - return clrconv; -} - -void freerdp_clrconv_free(HCLRCONV clrconv) -{ - if (clrconv) + switch (FREERDP_PIXEL_FORMAT_FLIP(DstFormat)) { - free(clrconv->palette); - free(clrconv); + case FREERDP_PIXEL_FLIP_HORIZONTAL: + vDstHFlip = TRUE; + return FALSE; + + case FREERDP_PIXEL_FLIP_VERTICAL: + vDstVFlip = TRUE; + break; + + case FREERDP_PIXEL_FLIP_NONE: + default: + break; } -} - -int freerdp_image1_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - int x, y; - int nSrcPad; - int nDstPad; - int nAlignedWidth; - int dstBitsPerPixel; - int dstBytesPerPixel; - BOOL vFlip = FALSE; - BOOL invert = FALSE; - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - - nAlignedWidth = nWidth + nWidth % 8; - - if (nSrcStep < 0) - nSrcStep = nAlignedWidth / 8; if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nAlignedWidth / 8)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat)) - invert = TRUE; - - if (FREERDP_PIXEL_FORMAT_FLIP(DstFormat) == FREERDP_PIXEL_FLIP_VERTICAL) - vFlip = TRUE; - - if (dstBytesPerPixel == 4) - { - BYTE SrcPixel; - BYTE* pSrcPixel; - UINT32* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[nYSrc * nSrcStep]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth / 8; x++) - { - SrcPixel = *pSrcPixel; - pDstPixel[0] = (SrcPixel & 0x80) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel[1] = (SrcPixel & 0x40) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel[2] = (SrcPixel & 0x20) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel[3] = (SrcPixel & 0x10) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel[4] = (SrcPixel & 0x08) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel[5] = (SrcPixel & 0x04) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel[6] = (SrcPixel & 0x02) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel[7] = (SrcPixel & 0x01) ? 0xFFFFFFFF : 0xFF000000; - pDstPixel += 8; - pSrcPixel++; - } - - if (nWidth % 8) - { - SrcPixel = *pSrcPixel; - - for (x = 0; x < nWidth % 8; x++) - { - *pDstPixel = (SrcPixel & 0x80) ? 0xFFFFFFFF : 0xFF000000; - SrcPixel <<= 1; - pDstPixel++; - } - - pSrcPixel++; - } - - pSrcPixel += nSrcPad; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - - return 1; -} - -int freerdp_image4_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - int x, y; - int nSrcPad; - int nDstPad; - int nAlignedWidth; - int dstBitsPerPixel; - int dstBytesPerPixel; - BOOL vFlip = FALSE; - BOOL invert = FALSE; - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - - nAlignedWidth = nWidth + (nWidth % 2); + nDstStep = nWidth * GetBytesPerPixel(DstFormat); if (nSrcStep < 0) - nSrcStep = nAlignedWidth / 2; + nSrcStep = nWidth * GetBytesPerPixel(SrcFormat); - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nAlignedWidth / 2)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat)) - invert = TRUE; - - if (FREERDP_PIXEL_FORMAT_FLIP(DstFormat) == FREERDP_PIXEL_FLIP_VERTICAL) - vFlip = TRUE; - - if (dstBytesPerPixel == 4) + if (vSrcVFlip) { - BYTE* pSrcPixel; - UINT32* pDstPixel; - UINT32* values = (UINT32*) palette; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[nYSrc * nSrcStep]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth / 2; x++) - { - pDstPixel[0] = values[*pSrcPixel >> 4]; - pDstPixel[1] = values[*pSrcPixel & 0xF]; - pDstPixel += 2; - pSrcPixel++; - } - - if (nWidth % 2) - { - pDstPixel[0] = values[*pSrcPixel >> 4]; - pDstPixel++; - pSrcPixel++; - } - - pSrcPixel += nSrcPad; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; + srcVOffset = (nHeight - 1) * nSrcStep; + srcVMultiplier = -1; } - return 1; -} - -int freerdp_image8_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - BYTE* pe; - int x, y; - int srcFlip; - int dstFlip; - int nSrcPad; - int nDstPad; - int srcBitsPerPixel; - int srcBytesPerPixel; - int dstBitsPerPixel; - int dstBytesPerPixel; - BOOL vFlip = FALSE; - BOOL invert = FALSE; - - if (!palette) - return -1; - - srcBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(SrcFormat); - srcBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(SrcFormat) / 8); - srcFlip = FREERDP_PIXEL_FORMAT_FLIP(SrcFormat); - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - dstFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat); - - if (nSrcStep < 0) - nSrcStep = srcBytesPerPixel * nWidth; - - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nWidth * srcBytesPerPixel)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (srcFlip != dstFlip) - vFlip = TRUE; - - invert = FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat) ? TRUE : FALSE; - - if (dstBytesPerPixel == 4) + if (vDstVFlip) { - if ((dstBitsPerPixel == 32) || (dstBitsPerPixel == 24)) - { - BYTE* pSrcPixel; - UINT32* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + nXSrc]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = RGB32(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + nXSrc]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = RGB32(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + nXSrc]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = BGR32(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + nXSrc]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = BGR32(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - } - else if (dstBytesPerPixel == 3) - { - - } - else if (dstBytesPerPixel == 2) - { - if (dstBitsPerPixel == 16) - { - BYTE* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = RGB16(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = RGB16(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = BGR16(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = BGR16(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - else if (dstBitsPerPixel == 15) - { - BYTE* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = RGB15(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = RGB15(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = BGR15(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + nXSrc]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pe = &palette[*pSrcPixel * 4]; - *pDstPixel++ = BGR15(pe[2], pe[1], pe[0]); - pSrcPixel++; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - } - else if (dstBytesPerPixel == 1) - { - BYTE* pSrcPixel; - BYTE* pDstPixel; - - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + nXSrc]; - pDstPixel = &pDstData[(nYDst * nDstStep) + nXDst]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth); - pSrcPixel = &pSrcPixel[nSrcStep]; - pDstPixel = &pDstPixel[nDstStep]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + nXSrc]; - pDstPixel = &pDstData[(nYDst * nDstStep) + nXDst]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth); - pSrcPixel = &pSrcPixel[-nSrcStep]; - pDstPixel = &pDstPixel[nDstStep]; - } - } - - return 1; + dstVOffset = (nHeight - 1) * nDstStep; + dstVMultiplier = -1; } - return -1; -} - -int freerdp_image15_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - int x, y; - int srcFlip; - int dstFlip; - int nSrcPad; - int nDstPad; - BYTE r, g, b; - int srcBitsPerPixel; - int srcBytesPerPixel; - int dstBitsPerPixel; - int dstBytesPerPixel; - int srcType, dstType; - BOOL vFlip = FALSE; - BOOL invert = FALSE; - - srcBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(SrcFormat); - srcBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(SrcFormat) / 8); - srcFlip = FREERDP_PIXEL_FORMAT_FLIP(SrcFormat); - srcType = FREERDP_PIXEL_FORMAT_TYPE(SrcFormat); - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - dstFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat); - dstType = FREERDP_PIXEL_FORMAT_TYPE(DstFormat); - - if (nSrcStep < 0) - nSrcStep = srcBytesPerPixel * nWidth; - - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nWidth * srcBytesPerPixel)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (srcFlip != dstFlip) - vFlip = TRUE; - - if (srcType != dstType) - invert = TRUE; - - if (dstBytesPerPixel == 4) + if (vSrcHFlip || vDstHFlip) { - if ((dstBitsPerPixel == 32) || (dstBitsPerPixel == 24)) - { - UINT16* pSrcPixel; - UINT32* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = ARGB32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = ARGB32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = ABGR32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = ABGR32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - } - else if (dstBytesPerPixel == 2) - { - if (dstBitsPerPixel == 16) - { - UINT16* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = RGB16(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = RGB16(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = BGR16(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = BGR16(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - else if (dstBitsPerPixel == 15) - { - UINT16* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = RGB15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = RGB15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = BGR15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB15(r, g, b, *pSrcPixel); - *pDstPixel = BGR15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } + WLog_ERR(TAG, "Horizontal flipping not supported! %s %s", + GetColorFormatName(SrcFormat), GetColorFormatName(DstFormat)); + return FALSE; } - return -1; -} - -int freerdp_image16_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - int x, y; - int srcFlip; - int dstFlip; - int nSrcPad; - int nDstPad; - BYTE r, g, b; - int srcBitsPerPixel; - int srcBytesPerPixel; - int dstBitsPerPixel; - int dstBytesPerPixel; - int srcType, dstType; - BOOL vFlip = FALSE; - BOOL invert = FALSE; - - srcBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(SrcFormat); - srcBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(SrcFormat) / 8); - srcFlip = FREERDP_PIXEL_FORMAT_FLIP(SrcFormat); - srcType = FREERDP_PIXEL_FORMAT_TYPE(SrcFormat); - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - dstFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat); - dstType = FREERDP_PIXEL_FORMAT_TYPE(DstFormat); - - if (nSrcStep < 0) - nSrcStep = srcBytesPerPixel * nWidth; - - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nWidth * srcBytesPerPixel)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (srcFlip != dstFlip) - vFlip = TRUE; - - if (srcType != dstType) - invert = TRUE; - - if (dstBytesPerPixel == 4) + if (FREERDP_PIXEL_FORMAT_FLIP_MASKED(SrcFormat) == + FREERDP_PIXEL_FORMAT_FLIP_MASKED(DstFormat)) { - if ((dstBitsPerPixel == 32) || (dstBitsPerPixel == 24)) - { - UINT16* pSrcPixel; - UINT32* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = ARGB32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = ARGB32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = ABGR32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = ABGR32(0xFF, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - } - else if (dstBytesPerPixel == 2) - { - if (dstBitsPerPixel == 16) - { - UINT16* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth * 2); - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcStep]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstStep]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth * 2); - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-nSrcStep]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstStep]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = BGR16(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = BGR16(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - else if (dstBitsPerPixel == 15) - { - UINT16* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = RGB15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = RGB15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = (UINT16*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = BGR15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = (UINT16*) &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 2)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB16(r, g, b, *pSrcPixel); - *pDstPixel = BGR15(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT16*) &((BYTE*) pSrcPixel)[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - } - - return -1; -} - -int freerdp_image24_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - int x, y; - int srcFlip; - int dstFlip; - int nSrcPad; - int nDstPad; - int srcBitsPerPixel; - int srcBytesPerPixel; - int dstBitsPerPixel; - int dstBytesPerPixel; - int srcType, dstType; - BOOL vFlip = FALSE; - BOOL invert = FALSE; - - srcBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(SrcFormat); - srcBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(SrcFormat) / 8); - srcFlip = FREERDP_PIXEL_FORMAT_FLIP(SrcFormat); - srcType = FREERDP_PIXEL_FORMAT_TYPE(SrcFormat); - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - dstFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat); - dstType = FREERDP_PIXEL_FORMAT_TYPE(DstFormat); - - if (nSrcStep < 0) - nSrcStep = srcBytesPerPixel * nWidth; - - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nWidth * srcBytesPerPixel)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (srcFlip != dstFlip) - vFlip = TRUE; - - if (srcType != dstType) - invert = TRUE; - - if (dstBytesPerPixel == 4) - { - if ((dstBitsPerPixel == 32) || (dstBitsPerPixel == 24)) - { - BYTE* pSrcPixel; - BYTE* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = *pSrcPixel++; - *pDstPixel++ = *pSrcPixel++; - *pDstPixel++ = *pSrcPixel++; - *pDstPixel++ = 0xFF; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = *pSrcPixel++; - *pDstPixel++ = *pSrcPixel++; - *pDstPixel++ = *pSrcPixel++; - *pDstPixel++ = 0xFF; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pDstPixel[0] = pSrcPixel[2]; - pDstPixel[1] = pSrcPixel[1]; - pDstPixel[2] = pSrcPixel[0]; - pDstPixel[3] = 0xFF; - - pSrcPixel += 3; - pDstPixel += 4; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pDstPixel[0] = pSrcPixel[2]; - pDstPixel[1] = pSrcPixel[1]; - pDstPixel[2] = pSrcPixel[0]; - pDstPixel[3] = 0xFF; - - pSrcPixel += 3; - pDstPixel += 4; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - } - - return 1; - } - } - else if (dstBytesPerPixel == 3) - { - BYTE* pSrcPixel; - BYTE* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 3)]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth * 3); - pSrcPixel = &pSrcPixel[nSrcStep]; - pDstPixel = &pDstPixel[nDstStep]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 3)]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth * 3); - pSrcPixel = &pSrcPixel[-nSrcStep]; - pDstPixel = &pDstPixel[nDstStep]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 3)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pDstPixel[0] = pSrcPixel[2]; - pDstPixel[1] = pSrcPixel[1]; - pDstPixel[2] = pSrcPixel[0]; - - pSrcPixel += 3; - pDstPixel += 3; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 3)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pDstPixel[0] = pSrcPixel[2]; - pDstPixel[1] = pSrcPixel[1]; - pDstPixel[2] = pSrcPixel[0]; - - pSrcPixel += 3; - pDstPixel += 3; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - } - - return 1; - } - else if (dstBytesPerPixel == 2) - { - if (dstBitsPerPixel == 16) - { - BYTE* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB16(pSrcPixel[2], pSrcPixel[1], pSrcPixel[0]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB16(pSrcPixel[2], pSrcPixel[1], pSrcPixel[0]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB16(pSrcPixel[0], pSrcPixel[1], pSrcPixel[2]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB16(pSrcPixel[0], pSrcPixel[1], pSrcPixel[2]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - else if (dstBitsPerPixel == 15) - { - BYTE* pSrcPixel; - UINT16* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB15(pSrcPixel[2], pSrcPixel[1], pSrcPixel[0]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB15(pSrcPixel[2], pSrcPixel[1], pSrcPixel[0]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB15(pSrcPixel[0], pSrcPixel[1], pSrcPixel[2]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 3)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = RGB15(pSrcPixel[0], pSrcPixel[1], pSrcPixel[2]); - pSrcPixel += 3; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &((UINT16*) pDstPixel)[nDstPad]; - } - } - } - - return 1; - } - } - - return -1; -} - -int freerdp_image32_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - int x, y; - int srcFlip; - int dstFlip; - int nSrcPad; - int nDstPad; - BYTE a, r, g, b; - int srcBitsPerPixel; - int srcBytesPerPixel; - int dstBitsPerPixel; - int dstBytesPerPixel; - int srcType, dstType; - BOOL vFlip = FALSE; - BOOL invert = FALSE; - - srcBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(SrcFormat); - srcBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(SrcFormat) / 8); - srcFlip = FREERDP_PIXEL_FORMAT_FLIP(SrcFormat); - srcType = FREERDP_PIXEL_FORMAT_TYPE(SrcFormat); - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - dstFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat); - dstType = FREERDP_PIXEL_FORMAT_TYPE(DstFormat); - - if (nSrcStep < 0) - nSrcStep = srcBytesPerPixel * nWidth; - - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nWidth * srcBytesPerPixel)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (srcFlip != dstFlip) - vFlip = TRUE; - - if (srcType != dstType) - invert = TRUE; - - if (srcBitsPerPixel == 24) - { - if (dstBytesPerPixel == 4) /* srcBytesPerPixel == dstBytesPerPixel */ - { - if (dstBitsPerPixel == 32) - { - UINT32* pSrcPixel; - UINT32* pDstPixel; - - pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; - pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - if (!invert) - { - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - *pDstPixel++ = *pSrcPixel++; - } - - pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - else - { - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetARGB32(a, r, g, b, *pSrcPixel); - *pDstPixel = ABGR32(a, r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; - } - } - - return 1; - } - else if (dstBitsPerPixel == 24) /* srcBitsPerPixel == dstBitsPerPixel */ - { - BYTE* pSrcPixel; - BYTE* pDstPixel; - - if (!invert) - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - MoveMemory(pDstPixel, pSrcPixel, nWidth * 4); - pSrcPixel = &pSrcPixel[nSrcStep]; - pDstPixel = &pDstPixel[nDstStep]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 4)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - MoveMemory(pDstPixel, pSrcPixel, nWidth * 4); - pSrcPixel = &pSrcPixel[-nSrcStep]; - pDstPixel = &pDstPixel[nDstStep]; - } - } - } - else - { - if (!vFlip) - { - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pDstPixel[0] = pSrcPixel[2]; - pDstPixel[1] = pSrcPixel[1]; - pDstPixel[2] = pSrcPixel[0]; - pDstPixel[3] = 0xFF; - - pSrcPixel += 4; - pDstPixel += 4; - } - - pSrcPixel = &pSrcPixel[nSrcPad]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - else - { - pSrcPixel = &pSrcData[((nYSrc + nHeight - 1) * nSrcStep) + (nXSrc * 4)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - pDstPixel[0] = pSrcPixel[2]; - pDstPixel[1] = pSrcPixel[1]; - pDstPixel[2] = pSrcPixel[0]; - pDstPixel[3] = 0xFF; - - pSrcPixel += 4; - pDstPixel += 4; - } - - pSrcPixel = &pSrcPixel[-((nSrcStep - nSrcPad) + nSrcStep)]; - pDstPixel = &pDstPixel[nDstPad]; - } - } - } - - return 1; - } - } - else if (dstBytesPerPixel == 3) - { - UINT32* pSrcPixel; - BYTE* pDstPixel; - - pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; - pDstPixel = (BYTE*) &pDstData[(nYDst * nDstStep) + (nXDst * 3)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB32(r, g, b, *pSrcPixel); - - *pDstPixel++ = r; - *pDstPixel++ = g; - *pDstPixel++ = b; - - pSrcPixel++; - } - - pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (BYTE*) &((BYTE*) pDstPixel)[nDstPad]; - } - - return 1; - } - else if (dstBytesPerPixel == 2) - { - if (dstBitsPerPixel == 16) - { - UINT32* pSrcPixel; - UINT16* pDstPixel; - - pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB32(r, g, b, *pSrcPixel); - RGB_888_565(r, g, b); - *pDstPixel = RGB565(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - - return 1; - } - else if (dstBitsPerPixel == 15) - { - UINT32* pSrcPixel; - UINT16* pDstPixel; - - pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; - pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * 2)]; - - for (y = 0; y < nHeight; y++) - { - for (x = 0; x < nWidth; x++) - { - GetRGB32(r, g, b, *pSrcPixel); - RGB_888_555(r, g, b); - *pDstPixel = RGB555(r, g, b); - - pSrcPixel++; - pDstPixel++; - } - - pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[nSrcPad]; - pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[nDstPad]; - } - - return 1; - } - } - } - - return -1; -} - -int freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) -{ - int status = -1; - int srcBitsPerPixel; - int srcBytesPerPixel; - - srcBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(SrcFormat); - srcBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(SrcFormat) / 8); - - if (srcBytesPerPixel == 4) - { - status = freerdp_image32_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); - } - else if (srcBytesPerPixel == 3) - { - status = freerdp_image24_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); - } - else if (srcBytesPerPixel == 2) - { - if (srcBitsPerPixel == 16) - { - status = freerdp_image16_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); - } - else if (srcBitsPerPixel == 15) - { - status = freerdp_image15_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); - } - } - else if (srcBytesPerPixel == 1) - { - status = freerdp_image8_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); - } - else if (srcBitsPerPixel == 1) - { - status = freerdp_image1_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); - } - else if (srcBitsPerPixel == 4) - { - status = freerdp_image4_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); - } - - if (status < 0) - { - int dstBitsPerPixel; - int dstBytesPerPixel; - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - - WLog_ERR(TAG, "failure: src: %d/%d dst: %d/%d", - srcBitsPerPixel, srcBytesPerPixel, dstBitsPerPixel, dstBytesPerPixel); - } - - return status; -} - -int freerdp_image_move(BYTE* pData, DWORD Format, int nStep, int nXDst, int nYDst, int nWidth, int nHeight, int nXSrc, int nYSrc) -{ - int y; - BOOL overlap; - BYTE* pSrcPixel; - BYTE* pDstPixel; - int bytesPerPixel; - - bytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(Format) / 8); - - if (nStep < 0) - nStep = nWidth * bytesPerPixel; - - overlap = (((nXDst + nWidth) > nXSrc) && (nXDst < (nXSrc + nWidth)) && - ((nYDst + nHeight) > nYSrc) && (nYDst < (nYSrc + nHeight))) ? TRUE : FALSE; - - if (!overlap) - { - pSrcPixel = &pData[(nYSrc * nStep) + (nXSrc * bytesPerPixel)]; - pDstPixel = &pData[(nYDst * nStep) + (nXDst * bytesPerPixel)]; + UINT32 y; for (y = 0; y < nHeight; y++) { - CopyMemory(pDstPixel, pSrcPixel, nWidth * bytesPerPixel); - pSrcPixel += nStep; - pDstPixel += nStep; - } - - return 1; - } - - if (nYSrc < nYDst) - { - /* copy down */ - - pSrcPixel = &pData[((nYSrc + nHeight - 1) * nStep) + (nXSrc * bytesPerPixel)]; - pDstPixel = &pData[((nYDst + nHeight - 1) * nStep) + (nXDst * bytesPerPixel)]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth * bytesPerPixel); - pSrcPixel -= nStep; - pDstPixel -= nStep; - } - } - else if (nYSrc > nYDst) - { - /* copy up */ - - pSrcPixel = &pData[(nYSrc * nStep) + (nXSrc * bytesPerPixel)]; - pDstPixel = &pData[(nYDst * nStep) + (nXDst * bytesPerPixel)]; - - for (y = 0; y < nHeight; y++) - { - CopyMemory(pDstPixel, pSrcPixel, nWidth * bytesPerPixel); - pSrcPixel += nStep; - pDstPixel += nStep; - } - } - else if (nXSrc > nXDst) - { - /* copy left */ - - pSrcPixel = &pData[(nYSrc * nStep) + (nXSrc * bytesPerPixel)]; - pDstPixel = &pData[(nYDst * nStep) + (nXDst * bytesPerPixel)]; - - for (y = 0; y < nHeight; y++) - { - MoveMemory(pDstPixel, pSrcPixel, nWidth * bytesPerPixel); - pSrcPixel += nStep; - pDstPixel += nStep; + const BYTE* srcLine = &pSrcData[(y + nYSrc) * nSrcStep * srcVMultiplier + + srcVOffset]; + BYTE* dstLine = &pDstData[(y + nYDst) * nDstStep * dstVMultiplier + dstVOffset]; + memcpy(&dstLine[xDstOffset], &srcLine[xSrcOffset], copyDstWidth); } } else { - /* copy right */ - - pSrcPixel = &pData[(nYSrc * nStep) + (nXSrc * bytesPerPixel)]; - pDstPixel = &pData[(nYDst * nStep) + (nXDst * bytesPerPixel)]; + UINT32 x, y; for (y = 0; y < nHeight; y++) { - MoveMemory(pDstPixel, pSrcPixel, nWidth * bytesPerPixel); - pSrcPixel += nStep; - pDstPixel += nStep; - } - } + const BYTE* srcLine = &pSrcData[(y + nYSrc) * nSrcStep * srcVMultiplier + + srcVOffset]; + BYTE* dstLine = &pDstData[(y + nYDst) * nDstStep * dstVMultiplier + dstVOffset]; - return 1; -} - -void* freerdp_image_memset32(UINT32* ptr, UINT32 fill, size_t length) -{ - while (length--) - { - *ptr++ = fill; - } - - return (void*) ptr; -} - -int freerdp_image_fill(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, UINT32 color) -{ - int y; - int dstBitsPerPixel; - int dstBytesPerPixel; - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - - if (dstBytesPerPixel == 4) - { - UINT32* pDstPixel; - - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - for (y = 0; y < nHeight; y++) - { - pDstPixel = (UINT32*) &pDstData[((nYDst + y) * nDstStep) + (nXDst * dstBytesPerPixel)]; - freerdp_image_memset32(pDstPixel, color, nWidth); - } - } - else if (dstBytesPerPixel == 3) - { - - } - else if (dstBytesPerPixel == 2) - { - if (dstBitsPerPixel == 16) - { - - } - else if (dstBitsPerPixel == 15) - { - - } - } - - return 0; -} - -int freerdp_image_copy_from_retina(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, - int nWidth, int nHeight, BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc) -{ - int x, y; - int nSrcPad; - int nDstPad; - int srcBitsPerPixel; - int srcBytesPerPixel; - int dstBitsPerPixel; - int dstBytesPerPixel; - - srcBitsPerPixel = 24; - srcBytesPerPixel = 8; - - if (nSrcStep < 0) - nSrcStep = srcBytesPerPixel * nWidth; - - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - - if (nDstStep < 0) - nDstStep = dstBytesPerPixel * nWidth; - - nSrcPad = (nSrcStep - (nWidth * srcBytesPerPixel)); - nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); - - if (dstBytesPerPixel == 4) - { - UINT32 R, G, B; - BYTE* pSrcPixel; - BYTE* pDstPixel; - - pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; - pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; - - for (y = 0; y < nHeight; y++) - { for (x = 0; x < nWidth; x++) { - /* simple box filter scaling, could be improved with better algorithm */ - - B = pSrcPixel[0] + pSrcPixel[4] + pSrcPixel[nSrcStep + 0] + pSrcPixel[nSrcStep + 4]; - G = pSrcPixel[1] + pSrcPixel[5] + pSrcPixel[nSrcStep + 1] + pSrcPixel[nSrcStep + 5]; - R = pSrcPixel[2] + pSrcPixel[6] + pSrcPixel[nSrcStep + 2] + pSrcPixel[nSrcStep + 6]; - pSrcPixel += 8; - - *pDstPixel++ = (BYTE) (B >> 2); - *pDstPixel++ = (BYTE) (G >> 2); - *pDstPixel++ = (BYTE) (R >> 2); - *pDstPixel++ = 0xFF; + UINT32 dstColor; + UINT32 color = ReadColor(&srcLine[(x + nXSrc) * srcByte], + SrcFormat); + dstColor = ConvertColor(color, SrcFormat, DstFormat, palette); + WriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor); } - - pSrcPixel = &pSrcPixel[nSrcPad + nSrcStep]; - pDstPixel = &pDstPixel[nDstPad]; } } - return 1; + return TRUE; +} + +BOOL freerdp_image_fill(BYTE* pDstData, DWORD DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT32 color) +{ + UINT32 x, y; + + for (y = 0; y < nHeight; y++) + { + BYTE* pDstLine = &pDstData[(y + nYDst) * nDstStep]; + + for (x = 0; x < nWidth; x++) + { + BYTE* pDst = &pDstLine[(x + nXDst) * GetBytesPerPixel(DstFormat)]; + WriteColor(pDst, DstFormat, color); + } + } + + return TRUE; } diff --git a/libfreerdp/codec/h264.c b/libfreerdp/codec/h264.c index 7018e806e..a9b93729f 100644 --- a/libfreerdp/codec/h264.c +++ b/libfreerdp/codec/h264.c @@ -1483,19 +1483,21 @@ static BOOL avc_yuv_to_rgb(H264_CONTEXT* h264, const RECTANGLE_16* regionRects, roi.width = width; roi.height = height; + // TODO: Color format converstion support!!! if (use444) { if (prims->YUV444ToRGB_8u_P3AC4R( - pYUVPoint, iStride, pDstPoint, - nDstStep, &roi) != PRIMITIVES_SUCCESS) + pYUVPoint, iStride, pDstPoint, nDstStep, + DstFormat, &roi) != PRIMITIVES_SUCCESS) { return FALSE; } } else { - if (prims->YUV420ToRGB_8u_P3AC4R(pYUVPoint, iStride, pDstPoint, - nDstStep, &roi) != PRIMITIVES_SUCCESS) + if (prims->YUV420ToRGB_8u_P3AC4R( + pYUVPoint, iStride, pDstPoint, nDstStep, + DstFormat, &roi) != PRIMITIVES_SUCCESS) return FALSE; } } diff --git a/libfreerdp/codec/include/bitmap.c b/libfreerdp/codec/include/bitmap.c index 8e923f151..5e5951e41 100644 --- a/libfreerdp/codec/include/bitmap.c +++ b/libfreerdp/codec/include/bitmap.c @@ -3,6 +3,8 @@ * RLE Compressed Bitmap Stream * * Copyright 2011 Jay Sorg + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -251,11 +253,11 @@ static BYTE* WRITEFIRSTLINEFGBGIMAGE(BYTE* pbDest, BYTE bitmask, /** * Decompress an RLE compressed bitmap. */ -void RLEDECOMPRESS(BYTE* pbSrcBuffer, UINT32 cbSrcBuffer, BYTE* pbDestBuffer, - UINT32 rowDelta, UINT32 width, UINT32 height) +void RLEDECOMPRESS(const BYTE* pbSrcBuffer, UINT32 cbSrcBuffer, BYTE* pbDestBuffer, + UINT32 rowDelta, UINT32 width, UINT32 height) { - BYTE* pbSrc = pbSrcBuffer; - BYTE* pbEnd = pbSrcBuffer + cbSrcBuffer; + const BYTE* pbSrc = pbSrcBuffer; + const BYTE* pbEnd = pbSrcBuffer + cbSrcBuffer; BYTE* pbDest = pbDestBuffer; PIXEL temp; @@ -354,214 +356,214 @@ void RLEDECOMPRESS(BYTE* pbSrcBuffer, UINT32 cbSrcBuffer, BYTE* pbDestBuffer, switch (code) { - /* Handle Foreground Run Orders. */ - case REGULAR_FG_RUN: - case MEGA_MEGA_FG_RUN: - case LITE_SET_FG_FG_RUN: - case MEGA_MEGA_SET_FG_RUN: - runLength = ExtractRunLength(code, pbSrc, &advance); - pbSrc = pbSrc + advance; - if (code == LITE_SET_FG_FG_RUN || code == MEGA_MEGA_SET_FG_RUN) + /* Handle Foreground Run Orders. */ + case REGULAR_FG_RUN: + case MEGA_MEGA_FG_RUN: + case LITE_SET_FG_FG_RUN: + case MEGA_MEGA_SET_FG_RUN: + runLength = ExtractRunLength(code, pbSrc, &advance); + pbSrc = pbSrc + advance; + if (code == LITE_SET_FG_FG_RUN || code == MEGA_MEGA_SET_FG_RUN) + { + SRCREADPIXEL(fgPel, pbSrc); + SRCNEXTPIXEL(pbSrc); + } + if (fFirstLine) + { + while (runLength >= UNROLL_COUNT) { - SRCREADPIXEL(fgPel, pbSrc); - SRCNEXTPIXEL(pbSrc); - } - if (fFirstLine) - { - while (runLength >= UNROLL_COUNT) - { - UNROLL( - DESTWRITEPIXEL(pbDest, fgPel); + UNROLL( + DESTWRITEPIXEL(pbDest, fgPel); DESTNEXTPIXEL(pbDest); ); - runLength = runLength - UNROLL_COUNT; - } - while (runLength > 0) - { - DESTWRITEPIXEL(pbDest, fgPel); - DESTNEXTPIXEL(pbDest); - runLength = runLength - 1; - } + runLength = runLength - UNROLL_COUNT; } - else + while (runLength > 0) { - while (runLength >= UNROLL_COUNT) - { - UNROLL( - DESTREADPIXEL(temp, pbDest - rowDelta); + DESTWRITEPIXEL(pbDest, fgPel); + DESTNEXTPIXEL(pbDest); + runLength = runLength - 1; + } + } + else + { + while (runLength >= UNROLL_COUNT) + { + UNROLL( + DESTREADPIXEL(temp, pbDest - rowDelta); DESTWRITEPIXEL(pbDest, temp ^ fgPel); - DESTNEXTPIXEL(pbDest); ); - runLength = runLength - UNROLL_COUNT; - } - while (runLength > 0) - { - DESTREADPIXEL(temp, pbDest - rowDelta); - DESTWRITEPIXEL(pbDest, temp ^ fgPel); - DESTNEXTPIXEL(pbDest); - runLength = runLength - 1; - } + DESTNEXTPIXEL(pbDest); ); + runLength = runLength - UNROLL_COUNT; } - break; + while (runLength > 0) + { + DESTREADPIXEL(temp, pbDest - rowDelta); + DESTWRITEPIXEL(pbDest, temp ^ fgPel); + DESTNEXTPIXEL(pbDest); + runLength = runLength - 1; + } + } + break; /* Handle Dithered Run Orders. */ - case LITE_DITHERED_RUN: - case MEGA_MEGA_DITHERED_RUN: - runLength = ExtractRunLength(code, pbSrc, &advance); - pbSrc = pbSrc + advance; - SRCREADPIXEL(pixelA, pbSrc); - SRCNEXTPIXEL(pbSrc); - SRCREADPIXEL(pixelB, pbSrc); - SRCNEXTPIXEL(pbSrc); - while (runLength >= UNROLL_COUNT) - { - UNROLL( - DESTWRITEPIXEL(pbDest, pixelA); + case LITE_DITHERED_RUN: + case MEGA_MEGA_DITHERED_RUN: + runLength = ExtractRunLength(code, pbSrc, &advance); + pbSrc = pbSrc + advance; + SRCREADPIXEL(pixelA, pbSrc); + SRCNEXTPIXEL(pbSrc); + SRCREADPIXEL(pixelB, pbSrc); + SRCNEXTPIXEL(pbSrc); + while (runLength >= UNROLL_COUNT) + { + UNROLL( + DESTWRITEPIXEL(pbDest, pixelA); DESTNEXTPIXEL(pbDest); - DESTWRITEPIXEL(pbDest, pixelB); - DESTNEXTPIXEL(pbDest); ); - runLength = runLength - UNROLL_COUNT; - } - while (runLength > 0) - { - DESTWRITEPIXEL(pbDest, pixelA); - DESTNEXTPIXEL(pbDest); - DESTWRITEPIXEL(pbDest, pixelB); - DESTNEXTPIXEL(pbDest); - runLength = runLength - 1; - } - break; + DESTWRITEPIXEL(pbDest, pixelB); + DESTNEXTPIXEL(pbDest); ); + runLength = runLength - UNROLL_COUNT; + } + while (runLength > 0) + { + DESTWRITEPIXEL(pbDest, pixelA); + DESTNEXTPIXEL(pbDest); + DESTWRITEPIXEL(pbDest, pixelB); + DESTNEXTPIXEL(pbDest); + runLength = runLength - 1; + } + break; /* Handle Color Run Orders. */ - case REGULAR_COLOR_RUN: - case MEGA_MEGA_COLOR_RUN: - runLength = ExtractRunLength(code, pbSrc, &advance); - pbSrc = pbSrc + advance; - SRCREADPIXEL(pixelA, pbSrc); - SRCNEXTPIXEL(pbSrc); - while (runLength >= UNROLL_COUNT) - { - UNROLL( - DESTWRITEPIXEL(pbDest, pixelA); + case REGULAR_COLOR_RUN: + case MEGA_MEGA_COLOR_RUN: + runLength = ExtractRunLength(code, pbSrc, &advance); + pbSrc = pbSrc + advance; + SRCREADPIXEL(pixelA, pbSrc); + SRCNEXTPIXEL(pbSrc); + while (runLength >= UNROLL_COUNT) + { + UNROLL( + DESTWRITEPIXEL(pbDest, pixelA); DESTNEXTPIXEL(pbDest); ); - runLength = runLength - UNROLL_COUNT; - } - while (runLength > 0) - { - DESTWRITEPIXEL(pbDest, pixelA); - DESTNEXTPIXEL(pbDest); - runLength = runLength - 1; - } - break; + runLength = runLength - UNROLL_COUNT; + } + while (runLength > 0) + { + DESTWRITEPIXEL(pbDest, pixelA); + DESTNEXTPIXEL(pbDest); + runLength = runLength - 1; + } + break; /* Handle Foreground/Background Image Orders. */ - case REGULAR_FGBG_IMAGE: - case MEGA_MEGA_FGBG_IMAGE: - case LITE_SET_FG_FGBG_IMAGE: - case MEGA_MEGA_SET_FGBG_IMAGE: - runLength = ExtractRunLength(code, pbSrc, &advance); - pbSrc = pbSrc + advance; - if (code == LITE_SET_FG_FGBG_IMAGE || code == MEGA_MEGA_SET_FGBG_IMAGE) - { - SRCREADPIXEL(fgPel, pbSrc); - SRCNEXTPIXEL(pbSrc); - } - if (fFirstLine) - { - while (runLength > 8) - { - bitmask = *pbSrc; - pbSrc = pbSrc + 1; - pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, bitmask, fgPel, 8); - runLength = runLength - 8; - } - } - else - { - while (runLength > 8) - { - bitmask = *pbSrc; - pbSrc = pbSrc + 1; - pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, bitmask, fgPel, 8); - runLength = runLength - 8; - } - } - if (runLength > 0) + case REGULAR_FGBG_IMAGE: + case MEGA_MEGA_FGBG_IMAGE: + case LITE_SET_FG_FGBG_IMAGE: + case MEGA_MEGA_SET_FGBG_IMAGE: + runLength = ExtractRunLength(code, pbSrc, &advance); + pbSrc = pbSrc + advance; + if (code == LITE_SET_FG_FGBG_IMAGE || code == MEGA_MEGA_SET_FGBG_IMAGE) + { + SRCREADPIXEL(fgPel, pbSrc); + SRCNEXTPIXEL(pbSrc); + } + if (fFirstLine) + { + while (runLength > 8) { bitmask = *pbSrc; pbSrc = pbSrc + 1; - if (fFirstLine) - { - pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, bitmask, fgPel, runLength); - } - else - { - pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, bitmask, fgPel, runLength); - } + pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, bitmask, fgPel, 8); + runLength = runLength - 8; } - break; + } + else + { + while (runLength > 8) + { + bitmask = *pbSrc; + pbSrc = pbSrc + 1; + pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, bitmask, fgPel, 8); + runLength = runLength - 8; + } + } + if (runLength > 0) + { + bitmask = *pbSrc; + pbSrc = pbSrc + 1; + if (fFirstLine) + { + pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, bitmask, fgPel, runLength); + } + else + { + pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, bitmask, fgPel, runLength); + } + } + break; /* Handle Color Image Orders. */ - case REGULAR_COLOR_IMAGE: - case MEGA_MEGA_COLOR_IMAGE: - runLength = ExtractRunLength(code, pbSrc, &advance); - pbSrc = pbSrc + advance; - while (runLength >= UNROLL_COUNT) - { - UNROLL( - SRCREADPIXEL(temp, pbSrc); + case REGULAR_COLOR_IMAGE: + case MEGA_MEGA_COLOR_IMAGE: + runLength = ExtractRunLength(code, pbSrc, &advance); + pbSrc = pbSrc + advance; + while (runLength >= UNROLL_COUNT) + { + UNROLL( + SRCREADPIXEL(temp, pbSrc); SRCNEXTPIXEL(pbSrc); - DESTWRITEPIXEL(pbDest, temp); - DESTNEXTPIXEL(pbDest); ); - runLength = runLength - UNROLL_COUNT; - } - while (runLength > 0) - { - SRCREADPIXEL(temp, pbSrc); - SRCNEXTPIXEL(pbSrc); - DESTWRITEPIXEL(pbDest, temp); - DESTNEXTPIXEL(pbDest); - runLength = runLength - 1; - } - break; + DESTWRITEPIXEL(pbDest, temp); + DESTNEXTPIXEL(pbDest); ); + runLength = runLength - UNROLL_COUNT; + } + while (runLength > 0) + { + SRCREADPIXEL(temp, pbSrc); + SRCNEXTPIXEL(pbSrc); + DESTWRITEPIXEL(pbDest, temp); + DESTNEXTPIXEL(pbDest); + runLength = runLength - 1; + } + break; /* Handle Special Order 1. */ - case SPECIAL_FGBG_1: - pbSrc = pbSrc + 1; - if (fFirstLine) - { - pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, g_MaskSpecialFgBg1, fgPel, 8); - } - else - { - pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, g_MaskSpecialFgBg1, fgPel, 8); - } - break; + case SPECIAL_FGBG_1: + pbSrc = pbSrc + 1; + if (fFirstLine) + { + pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, g_MaskSpecialFgBg1, fgPel, 8); + } + else + { + pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, g_MaskSpecialFgBg1, fgPel, 8); + } + break; /* Handle Special Order 2. */ - case SPECIAL_FGBG_2: - pbSrc = pbSrc + 1; - if (fFirstLine) - { - pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, g_MaskSpecialFgBg2, fgPel, 8); - } - else - { - pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, g_MaskSpecialFgBg2, fgPel, 8); - } - break; + case SPECIAL_FGBG_2: + pbSrc = pbSrc + 1; + if (fFirstLine) + { + pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, g_MaskSpecialFgBg2, fgPel, 8); + } + else + { + pbDest = WRITEFGBGIMAGE(pbDest, rowDelta, g_MaskSpecialFgBg2, fgPel, 8); + } + break; - /* Handle White Order. */ - case SPECIAL_WHITE: - pbSrc = pbSrc + 1; - DESTWRITEPIXEL(pbDest, WHITE_PIXEL); - DESTNEXTPIXEL(pbDest); - break; + /* Handle White Order. */ + case SPECIAL_WHITE: + pbSrc = pbSrc + 1; + DESTWRITEPIXEL(pbDest, WHITE_PIXEL); + DESTNEXTPIXEL(pbDest); + break; /* Handle Black Order. */ - case SPECIAL_BLACK: - pbSrc = pbSrc + 1; - DESTWRITEPIXEL(pbDest, BLACK_PIXEL); - DESTNEXTPIXEL(pbDest); - break; + case SPECIAL_BLACK: + pbSrc = pbSrc + 1; + DESTWRITEPIXEL(pbDest, BLACK_PIXEL); + DESTNEXTPIXEL(pbDest); + break; } } } diff --git a/libfreerdp/codec/interleaved.c b/libfreerdp/codec/interleaved.c index ea269d834..1fc9bf452 100644 --- a/libfreerdp/codec/interleaved.c +++ b/libfreerdp/codec/interleaved.c @@ -5,6 +5,8 @@ * Copyright 2014 Marc-Andre Moreau * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -103,7 +105,7 @@ static INLINE UINT32 ExtractCodeId(BYTE bOrderHdr) /** * Extract the run length of a compression order. */ -static INLINE UINT32 ExtractRunLength(UINT32 code, BYTE* pbOrderHdr, UINT32* advance) +static INLINE UINT32 ExtractRunLength(UINT32 code, const BYTE* pbOrderHdr, UINT32* advance) { UINT32 runLength; UINT32 ladvance; @@ -112,63 +114,63 @@ static INLINE UINT32 ExtractRunLength(UINT32 code, BYTE* pbOrderHdr, UINT32* adv runLength = 0; switch (code) { - case REGULAR_FGBG_IMAGE: - runLength = (*pbOrderHdr) & g_MaskRegularRunLength; - if (runLength == 0) - { - runLength = (*(pbOrderHdr + 1)) + 1; - ladvance += 1; - } - else - { - runLength = runLength * 8; - } - break; - case LITE_SET_FG_FGBG_IMAGE: - runLength = (*pbOrderHdr) & g_MaskLiteRunLength; - if (runLength == 0) - { - runLength = (*(pbOrderHdr + 1)) + 1; - ladvance += 1; - } - else - { - runLength = runLength * 8; - } - break; - case REGULAR_BG_RUN: - case REGULAR_FG_RUN: - case REGULAR_COLOR_RUN: - case REGULAR_COLOR_IMAGE: - runLength = (*pbOrderHdr) & g_MaskRegularRunLength; - if (runLength == 0) - { - /* An extended (MEGA) run. */ - runLength = (*(pbOrderHdr + 1)) + 32; - ladvance += 1; - } - break; - case LITE_SET_FG_FG_RUN: - case LITE_DITHERED_RUN: - runLength = (*pbOrderHdr) & g_MaskLiteRunLength; - if (runLength == 0) - { - /* An extended (MEGA) run. */ - runLength = (*(pbOrderHdr + 1)) + 16; - ladvance += 1; - } - break; - case MEGA_MEGA_BG_RUN: - case MEGA_MEGA_FG_RUN: - case MEGA_MEGA_SET_FG_RUN: - case MEGA_MEGA_DITHERED_RUN: - case MEGA_MEGA_COLOR_RUN: - case MEGA_MEGA_FGBG_IMAGE: - case MEGA_MEGA_SET_FGBG_IMAGE: - case MEGA_MEGA_COLOR_IMAGE: - runLength = ((UINT16) pbOrderHdr[1]) | ((UINT16) (pbOrderHdr[2] << 8)); - ladvance += 2; - break; + case REGULAR_FGBG_IMAGE: + runLength = (*pbOrderHdr) & g_MaskRegularRunLength; + if (runLength == 0) + { + runLength = (*(pbOrderHdr + 1)) + 1; + ladvance += 1; + } + else + { + runLength = runLength * 8; + } + break; + case LITE_SET_FG_FGBG_IMAGE: + runLength = (*pbOrderHdr) & g_MaskLiteRunLength; + if (runLength == 0) + { + runLength = (*(pbOrderHdr + 1)) + 1; + ladvance += 1; + } + else + { + runLength = runLength * 8; + } + break; + case REGULAR_BG_RUN: + case REGULAR_FG_RUN: + case REGULAR_COLOR_RUN: + case REGULAR_COLOR_IMAGE: + runLength = (*pbOrderHdr) & g_MaskRegularRunLength; + if (runLength == 0) + { + /* An extended (MEGA) run. */ + runLength = (*(pbOrderHdr + 1)) + 32; + ladvance += 1; + } + break; + case LITE_SET_FG_FG_RUN: + case LITE_DITHERED_RUN: + runLength = (*pbOrderHdr) & g_MaskLiteRunLength; + if (runLength == 0) + { + /* An extended (MEGA) run. */ + runLength = (*(pbOrderHdr + 1)) + 16; + ladvance += 1; + } + break; + case MEGA_MEGA_BG_RUN: + case MEGA_MEGA_FG_RUN: + case MEGA_MEGA_SET_FG_RUN: + case MEGA_MEGA_DITHERED_RUN: + case MEGA_MEGA_COLOR_RUN: + case MEGA_MEGA_FGBG_IMAGE: + case MEGA_MEGA_SET_FGBG_IMAGE: + case MEGA_MEGA_COLOR_IMAGE: + runLength = ((UINT16) pbOrderHdr[1]) | ((UINT16) (pbOrderHdr[2] << 8)); + ladvance += 2; + break; } *advance = ladvance; return runLength; @@ -231,11 +233,11 @@ static INLINE UINT32 ExtractRunLength(UINT32 code, BYTE* pbOrderHdr, UINT32* adv #undef RLEDECOMPRESS #undef RLEEXTRA #define DESTWRITEPIXEL(_buf, _pix) do { (_buf)[0] = (BYTE)(_pix); \ - (_buf)[1] = (BYTE)((_pix) >> 8); (_buf)[2] = (BYTE)((_pix) >> 16); } while (0) + (_buf)[1] = (BYTE)((_pix) >> 8); (_buf)[2] = (BYTE)((_pix) >> 16); } while (0) #define DESTREADPIXEL(_pix, _buf) _pix = (_buf)[0] | ((_buf)[1] << 8) | \ - ((_buf)[2] << 16) + ((_buf)[2] << 16) #define SRCREADPIXEL(_pix, _buf) _pix = (_buf)[0] | ((_buf)[1] << 8) | \ - ((_buf)[2] << 16) + ((_buf)[2] << 16) #define DESTNEXTPIXEL(_buf) _buf += 3 #define SRCNEXTPIXEL(_buf) _buf += 3 #define WRITEFGBGIMAGE WriteFgBgImage24to24 @@ -244,22 +246,23 @@ static INLINE UINT32 ExtractRunLength(UINT32 code, BYTE* pbOrderHdr, UINT32* adv #define RLEEXTRA #include "include/bitmap.c" -int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcData, UINT32 SrcSize, int bpp, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, BYTE* palette) +INT32 interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, + const BYTE* pSrcData, UINT32 SrcSize, + UINT32 bpp, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const UINT32* palette) { - int status; - BOOL vFlip; - int scanline; - BYTE* pDstData; + INT32 status; + UINT32 scanline; UINT32 SrcFormat; UINT32 BufferSize; - int dstBitsPerPixel; - int dstBytesPerPixel; + UINT32 dstBitsPerPixel; + UINT32 dstBytesPerPixel; - pDstData = *ppDstData; - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); - vFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat) ? TRUE : FALSE; + dstBitsPerPixel = GetBitsPerPixel(DstFormat); + dstBytesPerPixel = GetBytesPerPixel(DstFormat); if (!interleaved) return -1; @@ -274,14 +277,6 @@ int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcDa SrcFormat = PIXEL_FORMAT_RGB24_VF; -#if 0 - if ((SrcFormat == DstFormat) && !nXDst && !nYDst && (scanline == nDstStep)) - { - RleDecompress24to24(pSrcData, SrcSize, pDstData, scanline, nWidth, nHeight); - return 1; - } -#endif - if (BufferSize > interleaved->TempSize) { interleaved->TempBuffer = _aligned_realloc(interleaved->TempBuffer, BufferSize, 16); @@ -294,7 +289,8 @@ int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcDa RleDecompress24to24(pSrcData, SrcSize, interleaved->TempBuffer, scanline, nWidth, nHeight); status = freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, interleaved->TempBuffer, SrcFormat, scanline, 0, 0, palette); + nWidth, nHeight, interleaved->TempBuffer, + SrcFormat, scanline, 0, 0, palette); } else if ((bpp == 16) || (bpp == 15)) { @@ -303,14 +299,6 @@ int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcDa SrcFormat = (bpp == 16) ? PIXEL_FORMAT_RGB16_VF : PIXEL_FORMAT_RGB15_VF; -#if 0 - if ((SrcFormat == DstFormat) && !nXDst && !nYDst && (scanline == nDstStep)) - { - RleDecompress16to16(pSrcData, SrcSize, pDstData, scanline, nWidth, nHeight); - return 1; - } -#endif - if (BufferSize > interleaved->TempSize) { interleaved->TempBuffer = _aligned_realloc(interleaved->TempBuffer, BufferSize, 16); @@ -322,8 +310,10 @@ int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcDa RleDecompress16to16(pSrcData, SrcSize, interleaved->TempBuffer, scanline, nWidth, nHeight); - status = freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, interleaved->TempBuffer, SrcFormat, scanline, 0, 0, palette); + status = freerdp_image_copy(pDstData, DstFormat, nDstStep, + nXDst, nYDst, nWidth, nHeight, + interleaved->TempBuffer, SrcFormat, + scanline, 0, 0, palette); } else if (bpp == 8) { @@ -332,14 +322,6 @@ int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcDa SrcFormat = PIXEL_FORMAT_RGB8_VF; -#if 0 - if ((SrcFormat == DstFormat) && !nXDst && !nYDst && (scanline == nDstStep)) - { - RleDecompress8to8(pSrcData, SrcSize, pDstData, scanline, nWidth, nHeight); - return 1; - } -#endif - if (BufferSize > interleaved->TempSize) { interleaved->TempBuffer = _aligned_realloc(interleaved->TempBuffer, BufferSize, 16); @@ -352,7 +334,8 @@ int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcDa RleDecompress8to8(pSrcData, SrcSize, interleaved->TempBuffer, scanline, nWidth, nHeight); status = freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, - nWidth, nHeight, interleaved->TempBuffer, SrcFormat, scanline, 0, 0, palette); + nWidth, nHeight, interleaved->TempBuffer, + SrcFormat, scanline, 0, 0, palette); } else { @@ -362,8 +345,12 @@ int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pSrcDa return 1; } -int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData, UINT32* pDstSize, - int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette, int bpp) +BOOL interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, + BYTE* pDstData, UINT32* pDstSize, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, UINT32 SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + const UINT32* palette, UINT32 bpp) { int status; wStream* s; @@ -373,13 +360,13 @@ int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData if (nWidth % 4) { WLog_ERR(TAG, "interleaved_compress: width is not a multiple of 4"); - return -1; + return FALSE; } if ((nWidth > 64) || (nHeight > 64)) { WLog_ERR(TAG, "interleaved_compress: width (%d) or height (%d) is greater than 64", nWidth, nHeight); - return -1; + return FALSE; } if (bpp == 24) @@ -392,18 +379,18 @@ int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData DstFormat = PIXEL_FORMAT_RGB8; if (!DstFormat) - return -1; + return FALSE; status = freerdp_image_copy(interleaved->TempBuffer, DstFormat, -1, 0, 0, nWidth, nHeight, - pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); + pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette); s = Stream_New(pDstData, maxSize); if (!s) - return -1; + return FALSE; status = freerdp_bitmap_compress((char*) interleaved->TempBuffer, nWidth, nHeight, - s, bpp, maxSize, nHeight - 1, interleaved->bts, 0); + s, bpp, maxSize, nHeight - 1, interleaved->bts, 0); Stream_SealLength(s); *pDstSize = (UINT32) Stream_Length(s); diff --git a/libfreerdp/codec/nsc.c b/libfreerdp/codec/nsc.c index 9d78d786a..e566389d8 100644 --- a/libfreerdp/codec/nsc.c +++ b/libfreerdp/codec/nsc.c @@ -4,6 +4,8 @@ * * Copyright 2011 Samsung, Author Jiten Pathy * Copyright 2012 Vic Lee + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +31,7 @@ #include #include +#include #include "nsc_types.h" #include "nsc_encode.h" @@ -56,21 +59,22 @@ static void nsc_decode(NSC_CONTEXT* context) INT16 g_val; INT16 b_val; BYTE* bmpdata; - bmpdata = context->BitmapData; rw = ROUND_UP_TO(context->width, 8); shift = context->ColorLossLevel - 1; /* colorloss recovery + YCoCg shift */ - - WLog_Print(context->priv->log, WLOG_DEBUG, "NscDecode: width: %d height: %d ChromaSubsamplingLevel: %d", - context->width, context->height, context->ChromaSubsamplingLevel); + WLog_Print(context->priv->log, WLOG_DEBUG, + "NscDecode: width: %d height: %d ChromaSubsamplingLevel: %d", + context->width, context->height, context->ChromaSubsamplingLevel); for (y = 0; y < context->height; y++) { if (context->ChromaSubsamplingLevel) { yplane = context->priv->PlaneBuffers[0] + y * rw; /* Y */ - coplane = context->priv->PlaneBuffers[1] + (y >> 1) * (rw >> 1); /* Co, supersampled */ - cgplane = context->priv->PlaneBuffers[2] + (y >> 1) * (rw >> 1); /* Cg, supersampled */ + coplane = context->priv->PlaneBuffers[1] + (y >> 1) * (rw >> + 1); /* Co, supersampled */ + cgplane = context->priv->PlaneBuffers[2] + (y >> 1) * (rw >> + 1); /* Cg, supersampled */ } else { @@ -83,9 +87,9 @@ static void nsc_decode(NSC_CONTEXT* context) for (x = 0; x < context->width; x++) { - y_val = (INT16) *yplane; - co_val = (INT16) (INT8) (*coplane << shift); - cg_val = (INT16) (INT8) (*cgplane << shift); + y_val = (INT16) * yplane; + co_val = (INT16)(INT8)(*coplane << shift); + cg_val = (INT16)(INT8)(*cgplane << shift); r_val = y_val + co_val - cg_val; g_val = y_val + cg_val; b_val = y_val - co_val - cg_val; @@ -106,7 +110,6 @@ static void nsc_rle_decode(BYTE* in, BYTE* out, UINT32 originalSize) UINT32 len; UINT32 left; BYTE value; - left = originalSize; while (left > 4) @@ -124,7 +127,7 @@ static void nsc_rle_decode(BYTE* in, BYTE* out, UINT32 originalSize) if (*in < 0xFF) { - len = (UINT32) *in++; + len = (UINT32) * in++; len += 2; } else @@ -154,7 +157,6 @@ static void nsc_rle_decompress_data(NSC_CONTEXT* context) BYTE* rle; UINT32 planeSize; UINT32 originalSize; - rle = context->Planes; for (i = 0; i < 4; i++) @@ -184,9 +186,9 @@ static BOOL nsc_stream_initialize(NSC_CONTEXT* context, wStream* s) Stream_Read_UINT32(s, context->PlaneByteCount[i]); Stream_Read_UINT8(s, context->ColorLossLevel); /* ColorLossLevel (1 byte) */ - Stream_Read_UINT8(s, context->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */ + Stream_Read_UINT8(s, + context->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */ Stream_Seek(s, 2); /* Reserved (2 bytes) */ - context->Planes = Stream_Pointer(s); return TRUE; } @@ -200,11 +202,13 @@ static BOOL nsc_context_initialize(NSC_CONTEXT* context, wStream* s) if (!nsc_stream_initialize(context, s)) return FALSE; + length = context->width * context->height * 4; if (!context->BitmapData) { context->BitmapData = calloc(1, length + 16); + if (!context->BitmapData) return FALSE; @@ -212,17 +216,18 @@ static BOOL nsc_context_initialize(NSC_CONTEXT* context, wStream* s) } else if (length > context->BitmapDataLength) { - void *tmp; + void* tmp; tmp = realloc(context->BitmapData, length + 16); + if (!tmp) return FALSE; + context->BitmapData = tmp; context->BitmapDataLength = length; } tempWidth = ROUND_UP_TO(context->width, 8); tempHeight = ROUND_UP_TO(context->height, 2); - /* The maximum length a decoded plane can reach in all cases */ length = tempWidth * tempHeight; @@ -230,9 +235,11 @@ static BOOL nsc_context_initialize(NSC_CONTEXT* context, wStream* s) { for (i = 0; i < 4; i++) { - void * tmp = (BYTE*) realloc(context->priv->PlaneBuffers[i], length); + void* tmp = (BYTE*) realloc(context->priv->PlaneBuffers[i], length); + if (!tmp) return FALSE; + context->priv->PlaneBuffers[i] = tmp; } @@ -257,12 +264,10 @@ static BOOL nsc_context_initialize(NSC_CONTEXT* context, wStream* s) static void nsc_profiler_print(NSC_CONTEXT* context) { PROFILER_PRINT_HEADER; - PROFILER_PRINT(context->priv->prof_nsc_rle_decompress_data); PROFILER_PRINT(context->priv->prof_nsc_decode); PROFILER_PRINT(context->priv->prof_nsc_rle_compress_data); PROFILER_PRINT(context->priv->prof_nsc_encode); - PROFILER_PRINT_FOOTER; } @@ -273,51 +278,45 @@ BOOL nsc_context_reset(NSC_CONTEXT* context, UINT32 width, UINT32 height) context->width = width; context->height = height; - return TRUE; } NSC_CONTEXT* nsc_context_new(void) { NSC_CONTEXT* context; - context = (NSC_CONTEXT*) calloc(1, sizeof(NSC_CONTEXT)); + if (!context) return NULL; context->priv = (NSC_CONTEXT_PRIV*) calloc(1, sizeof(NSC_CONTEXT_PRIV)); + if (!context->priv) goto error_priv; WLog_Init(); - context->priv->log = WLog_Get("com.freerdp.codec.nsc"); WLog_OpenAppender(context->priv->log); - - context->BitmapData = NULL; - context->decode = nsc_decode; context->encode = nsc_encode; - context->priv->PlanePool = BufferPool_New(TRUE, 0, 16); + if (!context->priv->PlanePool) goto error_PlanePool; - PROFILER_CREATE(context->priv->prof_nsc_rle_decompress_data, "nsc_rle_decompress_data"); + PROFILER_CREATE(context->priv->prof_nsc_rle_decompress_data, + "nsc_rle_decompress_data"); PROFILER_CREATE(context->priv->prof_nsc_decode, "nsc_decode"); - PROFILER_CREATE(context->priv->prof_nsc_rle_compress_data, "nsc_rle_compress_data"); + PROFILER_CREATE(context->priv->prof_nsc_rle_compress_data, + "nsc_rle_compress_data"); PROFILER_CREATE(context->priv->prof_nsc_encode, "nsc_encode"); - /* Default encoding parameters */ context->ColorLossLevel = 3; context->ChromaSubsamplingLevel = 1; - /* init optimized methods */ NSC_INIT_SIMD(context); - return context; - error_PlanePool: free(context->priv); error_priv: @@ -339,83 +338,75 @@ void nsc_context_free(NSC_CONTEXT* context) } free(context->BitmapData); - BufferPool_Free(context->priv->PlanePool); - nsc_profiler_print(context); PROFILER_FREE(context->priv->prof_nsc_rle_decompress_data); PROFILER_FREE(context->priv->prof_nsc_decode); PROFILER_FREE(context->priv->prof_nsc_rle_compress_data); PROFILER_FREE(context->priv->prof_nsc_encode); - free(context->priv); free(context); } -void nsc_context_set_pixel_format(NSC_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format) +BOOL nsc_context_set_pixel_format(NSC_CONTEXT* context, UINT32 pixel_format) { context->pixel_format = pixel_format; - - switch (pixel_format) - { - case RDP_PIXEL_FORMAT_B8G8R8A8: - case RDP_PIXEL_FORMAT_R8G8B8A8: - context->bpp = 32; - break; - - case RDP_PIXEL_FORMAT_B8G8R8: - case RDP_PIXEL_FORMAT_R8G8B8: - context->bpp = 24; - break; - - case RDP_PIXEL_FORMAT_B5G6R5_LE: - case RDP_PIXEL_FORMAT_R5G6B5_LE: - context->bpp = 16; - break; - - case RDP_PIXEL_FORMAT_P4_PLANER: - context->bpp = 4; - break; - - case RDP_PIXEL_FORMAT_P8: - context->bpp = 8; - break; - - default: - context->bpp = 0; - break; - } + context->format = pixel_format; + return TRUE; } -int nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, UINT16 width, UINT16 height, BYTE* data, UINT32 length) +BOOL nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, + UINT32 width, UINT32 height, const BYTE* data, + UINT32 length) { wStream* s; BOOL ret; - - s = Stream_New(data, length); + s = Stream_New((BYTE*)data, length); if (!s) - return -1; + return FALSE; + + switch (bpp) + { + case 32: + context->format = PIXEL_FORMAT_BGRA32; + break; + + case 24: + context->format = PIXEL_FORMAT_BGR24; + break; + + case 16: + context->format = PIXEL_FORMAT_BGR16; + break; + + case 8: + context->format = PIXEL_FORMAT_RGB8; + break; + + case 4: + context->format = PIXEL_FORMAT_A4; + break; + + default: + return FALSE; + } - context->bpp = bpp; context->width = width; context->height = height; - ret = nsc_context_initialize(context, s); Stream_Free(s, FALSE); if (!ret) - return -1; + return FALSE; /* RLE decode */ PROFILER_ENTER(context->priv->prof_nsc_rle_decompress_data); nsc_rle_decompress_data(context); PROFILER_EXIT(context->priv->prof_nsc_rle_decompress_data); - /* Colorloss recover, Chroma supersample and AYCoCg to ARGB Conversion in one step */ PROFILER_ENTER(context->priv->prof_nsc_decode); context->decode(context); PROFILER_EXIT(context->priv->prof_nsc_decode); - - return 1; + return TRUE; } diff --git a/libfreerdp/codec/nsc_encode.c b/libfreerdp/codec/nsc_encode.c index 2477c6552..48a649c8b 100644 --- a/libfreerdp/codec/nsc_encode.c +++ b/libfreerdp/codec/nsc_encode.c @@ -3,6 +3,8 @@ * NSCodec Encoder * * Copyright 2012 Vic Lee + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +30,7 @@ #include #include +#include #include "nsc_types.h" #include "nsc_encode.h" @@ -38,17 +41,16 @@ static void nsc_context_initialize_encode(NSC_CONTEXT* context) UINT32 length; UINT32 tempWidth; UINT32 tempHeight; - tempWidth = ROUND_UP_TO(context->width, 8); tempHeight = ROUND_UP_TO(context->height, 2); - /* The maximum length a decoded plane can reach in all cases */ length = tempWidth * tempHeight + 16; if (length > context->priv->PlaneBuffersLength) { for (i = 0; i < 5; i++) - context->priv->PlaneBuffers[i] = (BYTE*) realloc(context->priv->PlaneBuffers[i], length); + context->priv->PlaneBuffers[i] = (BYTE*) realloc(context->priv->PlaneBuffers[i], + length); context->priv->PlaneBuffersLength = length; } @@ -69,13 +71,14 @@ static void nsc_context_initialize_encode(NSC_CONTEXT* context) } } -static void nsc_encode_argb_to_aycocg(NSC_CONTEXT* context, BYTE* data, int scanline) +static void nsc_encode_argb_to_aycocg(NSC_CONTEXT* context, const BYTE* data, + UINT32 scanline) { UINT16 x; UINT16 y; UINT16 rw; BYTE ccl; - BYTE* src; + const BYTE* src; BYTE* yplane; BYTE* coplane; BYTE* cgplane; @@ -86,7 +89,6 @@ static void nsc_encode_argb_to_aycocg(NSC_CONTEXT* context, BYTE* data, int scan BYTE a_val; UINT32 tempWidth; UINT32 tempHeight; - tempWidth = ROUND_UP_TO(context->width, 8); tempHeight = ROUND_UP_TO(context->height, 2); rw = (context->ChromaSubsamplingLevel ? tempWidth : context->width); @@ -108,55 +110,54 @@ static void nsc_encode_argb_to_aycocg(NSC_CONTEXT* context, BYTE* data, int scan { switch (context->pixel_format) { - case RDP_PIXEL_FORMAT_B8G8R8A8: + case PIXEL_FORMAT_BGRA32: b_val = *src++; g_val = *src++; r_val = *src++; a_val = *src++; break; - case RDP_PIXEL_FORMAT_R8G8B8A8: + case PIXEL_FORMAT_RGBA32: r_val = *src++; g_val = *src++; b_val = *src++; a_val = *src++; break; - case RDP_PIXEL_FORMAT_B8G8R8: + case PIXEL_FORMAT_BGR24: b_val = *src++; g_val = *src++; r_val = *src++; a_val = 0xFF; break; - case RDP_PIXEL_FORMAT_R8G8B8: + case PIXEL_FORMAT_RGB24: r_val = *src++; g_val = *src++; b_val = *src++; a_val = 0xFF; break; - case RDP_PIXEL_FORMAT_B5G6R5_LE: - b_val = (INT16) (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); - g_val = (INT16) ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); - r_val = (INT16) ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); + case PIXEL_FORMAT_BGR16: + b_val = (INT16)(((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); + g_val = (INT16)((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); + r_val = (INT16)((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); a_val = 0xFF; src += 2; break; - case RDP_PIXEL_FORMAT_R5G6B5_LE: - r_val = (INT16) (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); - g_val = (INT16) ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); - b_val = (INT16) ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); + case PIXEL_FORMAT_RGB16: + r_val = (INT16)(((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); + g_val = (INT16)((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); + b_val = (INT16)((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); a_val = 0xFF; src += 2; break; - case RDP_PIXEL_FORMAT_P4_PLANER: + case PIXEL_FORMAT_A4: { int shift; BYTE idx; - shift = (7 - (x % 8)); idx = ((*src) >> shift) & 1; idx |= (((*(src + 1)) >> shift) & 1) << 1; @@ -166,21 +167,23 @@ static void nsc_encode_argb_to_aycocg(NSC_CONTEXT* context, BYTE* data, int scan r_val = (INT16) context->palette[idx]; g_val = (INT16) context->palette[idx + 1]; b_val = (INT16) context->palette[idx + 2]; + if (shift == 0) src += 4; } + a_val = 0xFF; break; - case RDP_PIXEL_FORMAT_P8: + case PIXEL_FORMAT_RGB8: { int idx = (*src) * 3; - r_val = (INT16) context->palette[idx]; g_val = (INT16) context->palette[idx + 1]; b_val = (INT16) context->palette[idx + 2]; src++; } + a_val = 0xFF; break; @@ -189,11 +192,10 @@ static void nsc_encode_argb_to_aycocg(NSC_CONTEXT* context, BYTE* data, int scan break; } - *yplane++ = (BYTE) ((r_val >> 2) + (g_val >> 1) + (b_val >> 2)); - + *yplane++ = (BYTE)((r_val >> 2) + (g_val >> 1) + (b_val >> 2)); /* Perform color loss reduction here */ - *coplane++ = (BYTE) ((r_val - b_val) >> ccl); - *cgplane++ = (BYTE) ((-(r_val >> 1) + g_val - (b_val >> 1)) >> ccl); + *coplane++ = (BYTE)((r_val - b_val) >> ccl); + *cgplane++ = (BYTE)((-(r_val >> 1) + g_val - (b_val >> 1)) >> ccl); *aplane++ = a_val; } @@ -225,7 +227,6 @@ static void nsc_encode_subsampling(NSC_CONTEXT* context) INT8* cg_src1; UINT32 tempWidth; UINT32 tempHeight; - tempWidth = ROUND_UP_TO(context->width, 8); tempHeight = ROUND_UP_TO(context->height, 2); @@ -240,10 +241,10 @@ static void nsc_encode_subsampling(NSC_CONTEXT* context) for (x = 0; x < tempWidth >> 1; x++) { - *co_dst++ = (BYTE) (((INT16) *co_src0 + (INT16) *(co_src0 + 1) + - (INT16) *co_src1 + (INT16) *(co_src1 + 1)) >> 2); - *cg_dst++ = (BYTE) (((INT16) *cg_src0 + (INT16) *(cg_src0 + 1) + - (INT16) *cg_src1 + (INT16) *(cg_src1 + 1)) >> 2); + *co_dst++ = (BYTE)(((INT16) * co_src0 + (INT16) * (co_src0 + 1) + + (INT16) * co_src1 + (INT16) * (co_src1 + 1)) >> 2); + *cg_dst++ = (BYTE)(((INT16) * cg_src0 + (INT16) * (cg_src0 + 1) + + (INT16) * cg_src1 + (INT16) * (cg_src1 + 1)) >> 2); co_src0 += 2; co_src1 += 2; cg_src0 += 2; @@ -252,7 +253,7 @@ static void nsc_encode_subsampling(NSC_CONTEXT* context) } } -void nsc_encode(NSC_CONTEXT* context, BYTE* bmpdata, int rowstride) +void nsc_encode(NSC_CONTEXT* context, const BYTE* bmpdata, UINT32 rowstride) { nsc_encode_argb_to_aycocg(context, bmpdata, rowstride); @@ -267,8 +268,8 @@ static UINT32 nsc_rle_encode(BYTE* in, BYTE* out, UINT32 originalSize) UINT32 left; UINT32 runlength = 1; UINT32 planeSize = 0; - left = originalSize; + /** * We quit the loop if the running compressed size is larger than the original. * In such cases data will be sent uncompressed. @@ -304,6 +305,7 @@ static UINT32 nsc_rle_encode(BYTE* in, BYTE* out, UINT32 originalSize) runlength = 1; planeSize += 7; } + in++; left--; } @@ -312,7 +314,6 @@ static UINT32 nsc_rle_encode(BYTE* in, BYTE* out, UINT32 originalSize) CopyMemory(out, in, 4); planeSize += 4; - return planeSize; } @@ -332,10 +333,12 @@ static void nsc_rle_compress_data(NSC_CONTEXT* context) } else { - planeSize = nsc_rle_encode(context->priv->PlaneBuffers[i], context->priv->PlaneBuffers[4], originalSize); + planeSize = nsc_rle_encode(context->priv->PlaneBuffers[i], + context->priv->PlaneBuffers[4], originalSize); if (planeSize < originalSize) - CopyMemory(context->priv->PlaneBuffers[i], context->priv->PlaneBuffers[4], planeSize); + CopyMemory(context->priv->PlaneBuffers[i], context->priv->PlaneBuffers[4], + planeSize); else planeSize = originalSize; } @@ -344,15 +347,14 @@ static void nsc_rle_compress_data(NSC_CONTEXT* context) } } -UINT32 nsc_compute_byte_count(NSC_CONTEXT* context, UINT32* ByteCount, UINT32 width, UINT32 height) +UINT32 nsc_compute_byte_count(NSC_CONTEXT* context, UINT32* ByteCount, + UINT32 width, UINT32 height) { UINT32 tempWidth; UINT32 tempHeight; UINT32 maxPlaneSize; - tempWidth = ROUND_UP_TO(width, 8); tempHeight = ROUND_UP_TO(height, 2); - maxPlaneSize = tempWidth * tempHeight + 16; if (context->ChromaSubsamplingLevel) @@ -373,35 +375,34 @@ UINT32 nsc_compute_byte_count(NSC_CONTEXT* context, UINT32* ByteCount, UINT32 wi return maxPlaneSize; } -NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, BYTE* data, int x, int y, - int width, int height, int scanline, int* numMessages, int maxDataSize) +NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, const BYTE* data, + UINT32 x, UINT32 y, UINT32 width, UINT32 height, + UINT32 scanline, UINT32* numMessages, + UINT32 maxDataSize) { - int i, j, k; - int dataOffset; - int rows, cols; - int BytesPerPixel; - int MaxRegionWidth; - int MaxRegionHeight; + UINT32 i, j, k; + UINT32 dataOffset; + UINT32 rows, cols; + UINT32 BytesPerPixel; + UINT32 MaxRegionWidth; + UINT32 MaxRegionHeight; UINT32 ByteCount[4]; UINT32 MaxPlaneSize; UINT32 MaxMessageSize; NSC_MESSAGE* messages; UINT32 PaddedMaxPlaneSize; - k = 0; MaxRegionWidth = 64 * 4; MaxRegionHeight = 64 * 2; - BytesPerPixel = (context->bpp / 8); - + BytesPerPixel = GetBytesPerPixel(context->format); rows = (width + (MaxRegionWidth - (width % MaxRegionWidth))) / MaxRegionWidth; - cols = (height + (MaxRegionHeight - (height % MaxRegionHeight))) / MaxRegionHeight; + cols = (height + (MaxRegionHeight - (height % MaxRegionHeight))) / + MaxRegionHeight; *numMessages = rows * cols; - - MaxPlaneSize = nsc_compute_byte_count(context, (UINT32*) ByteCount, width, height); + MaxPlaneSize = nsc_compute_byte_count(context, (UINT32*) ByteCount, width, + height); MaxMessageSize = ByteCount[0] + ByteCount[1] + ByteCount[2] + ByteCount[3] + 20; - maxDataSize -= 1024; /* reserve enough space for headers */ - messages = (NSC_MESSAGE*) calloc(*numMessages, sizeof(NSC_MESSAGE)); if (!messages) @@ -413,14 +414,14 @@ NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, BYTE* data, int x, int y, { messages[k].x = x + (i * MaxRegionWidth); messages[k].y = y + (j * MaxRegionHeight); - messages[k].width = (i < (rows - 1)) ? MaxRegionWidth : width - (i * MaxRegionWidth); - messages[k].height = (j < (cols - 1)) ? MaxRegionHeight : height - (j * MaxRegionHeight); + messages[k].width = (i < (rows - 1)) ? MaxRegionWidth : width - + (i * MaxRegionWidth); + messages[k].height = (j < (cols - 1)) ? MaxRegionHeight : height - + (j * MaxRegionHeight); messages[k].data = data; messages[k].scanline = scanline; - messages[k].MaxPlaneSize = nsc_compute_byte_count(context, - (UINT32*) messages[k].OrgByteCount, messages[k].width, messages[k].height); - + (UINT32*) messages[k].OrgByteCount, messages[k].width, messages[k].height); k++; } } @@ -430,14 +431,18 @@ NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, BYTE* data, int x, int y, for (i = 0; i < *numMessages; i++) { PaddedMaxPlaneSize = messages[i].MaxPlaneSize + 32; - - messages[i].PlaneBuffer = (BYTE*) BufferPool_Take(context->priv->PlanePool, PaddedMaxPlaneSize * 5); - - messages[i].PlaneBuffers[0] = (BYTE*) &(messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 0) + 16]); - messages[i].PlaneBuffers[1] = (BYTE*) &(messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 1) + 16]); - messages[i].PlaneBuffers[2] = (BYTE*) &(messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 2) + 16]); - messages[i].PlaneBuffers[3] = (BYTE*) &(messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 3) + 16]); - messages[i].PlaneBuffers[4] = (BYTE*) &(messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 4) + 16]); + messages[i].PlaneBuffer = (BYTE*) BufferPool_Take(context->priv->PlanePool, + PaddedMaxPlaneSize * 5); + messages[i].PlaneBuffers[0] = (BYTE*) & + (messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 0) + 16]); + messages[i].PlaneBuffers[1] = (BYTE*) & + (messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 1) + 16]); + messages[i].PlaneBuffers[2] = (BYTE*) & + (messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 2) + 16]); + messages[i].PlaneBuffers[3] = (BYTE*) & + (messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 3) + 16]); + messages[i].PlaneBuffers[4] = (BYTE*) & + (messages[i].PlaneBuffer[(PaddedMaxPlaneSize * 4) + 16]); } for (i = 0; i < *numMessages; i++) @@ -454,17 +459,14 @@ NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, BYTE* data, int x, int y, context->priv->PlaneBuffers[2] = messages[i].PlaneBuffers[2]; context->priv->PlaneBuffers[3] = messages[i].PlaneBuffers[3]; context->priv->PlaneBuffers[4] = messages[i].PlaneBuffers[4]; - - dataOffset = (messages[i].y * messages[i].scanline) + (messages[i].x * BytesPerPixel); - + dataOffset = (messages[i].y * messages[i].scanline) + (messages[i].x * + BytesPerPixel); PROFILER_ENTER(context->priv->prof_nsc_encode); context->encode(context, &data[dataOffset], scanline); PROFILER_EXIT(context->priv->prof_nsc_encode); - PROFILER_ENTER(context->priv->prof_nsc_rle_compress_data); nsc_rle_compress_data(context); PROFILER_EXIT(context->priv->prof_nsc_rle_compress_data); - messages[i].LumaPlaneByteCount = context->PlaneByteCount[0]; messages[i].OrangeChromaPlaneByteCount = context->PlaneByteCount[1]; messages[i].GreenChromaPlaneByteCount = context->PlaneByteCount[2]; @@ -478,78 +480,81 @@ NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, BYTE* data, int x, int y, context->priv->PlaneBuffers[2] = NULL; context->priv->PlaneBuffers[3] = NULL; context->priv->PlaneBuffers[4] = NULL; - return messages; } -int nsc_write_message(NSC_CONTEXT* context, wStream* s, NSC_MESSAGE* message) +BOOL nsc_write_message(NSC_CONTEXT* context, wStream* s, NSC_MESSAGE* message) { UINT32 totalPlaneByteCount; - - totalPlaneByteCount = message->LumaPlaneByteCount + message->OrangeChromaPlaneByteCount + - message->GreenChromaPlaneByteCount + message->AlphaPlaneByteCount; + totalPlaneByteCount = message->LumaPlaneByteCount + + message->OrangeChromaPlaneByteCount + + message->GreenChromaPlaneByteCount + message->AlphaPlaneByteCount; if (!Stream_EnsureRemainingCapacity(s, 20 + totalPlaneByteCount)) return -1; - Stream_Write_UINT32(s, message->LumaPlaneByteCount); /* LumaPlaneByteCount (4 bytes) */ - Stream_Write_UINT32(s, message->OrangeChromaPlaneByteCount); /* OrangeChromaPlaneByteCount (4 bytes) */ - Stream_Write_UINT32(s, message->GreenChromaPlaneByteCount); /* GreenChromaPlaneByteCount (4 bytes) */ - Stream_Write_UINT32(s, message->AlphaPlaneByteCount); /* AlphaPlaneByteCount (4 bytes) */ + + Stream_Write_UINT32(s, + message->LumaPlaneByteCount); /* LumaPlaneByteCount (4 bytes) */ + Stream_Write_UINT32(s, + message->OrangeChromaPlaneByteCount); /* OrangeChromaPlaneByteCount (4 bytes) */ + Stream_Write_UINT32(s, + message->GreenChromaPlaneByteCount); /* GreenChromaPlaneByteCount (4 bytes) */ + Stream_Write_UINT32(s, + message->AlphaPlaneByteCount); /* AlphaPlaneByteCount (4 bytes) */ Stream_Write_UINT8(s, message->ColorLossLevel); /* ColorLossLevel (1 byte) */ - Stream_Write_UINT8(s, message->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */ + Stream_Write_UINT8(s, + message->ChromaSubsamplingLevel); /* ChromaSubsamplingLevel (1 byte) */ Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ if (message->LumaPlaneByteCount) - Stream_Write(s, message->PlaneBuffers[0], message->LumaPlaneByteCount); /* LumaPlane */ + Stream_Write(s, message->PlaneBuffers[0], + message->LumaPlaneByteCount); /* LumaPlane */ if (message->OrangeChromaPlaneByteCount) - Stream_Write(s, message->PlaneBuffers[1], message->OrangeChromaPlaneByteCount); /* OrangeChromaPlane */ + Stream_Write(s, message->PlaneBuffers[1], + message->OrangeChromaPlaneByteCount); /* OrangeChromaPlane */ if (message->GreenChromaPlaneByteCount) - Stream_Write(s, message->PlaneBuffers[2], message->GreenChromaPlaneByteCount); /* GreenChromaPlane */ + Stream_Write(s, message->PlaneBuffers[2], + message->GreenChromaPlaneByteCount); /* GreenChromaPlane */ if (message->AlphaPlaneByteCount) - Stream_Write(s, message->PlaneBuffers[3], message->AlphaPlaneByteCount); /* AlphaPlane */ + Stream_Write(s, message->PlaneBuffers[3], + message->AlphaPlaneByteCount); /* AlphaPlane */ - return 0; + return TRUE; } -int nsc_message_free(NSC_CONTEXT* context, NSC_MESSAGE* message) +void nsc_message_free(NSC_CONTEXT* context, NSC_MESSAGE* message) { BufferPool_Return(context->priv->PlanePool, message->PlaneBuffer); - return 0; } -void nsc_compose_message(NSC_CONTEXT* context, wStream* s, BYTE* data, int width, int height, int scanline) +BOOL nsc_compose_message(NSC_CONTEXT* context, wStream* s, const BYTE* data, + UINT32 width, UINT32 height, UINT32 scanline) { NSC_MESSAGE s_message = { 0 }; NSC_MESSAGE* message = &s_message; - context->width = width; context->height = height; nsc_context_initialize_encode(context); - /* ARGB to AYCoCg conversion, chroma subsampling and colorloss reduction */ PROFILER_ENTER(context->priv->prof_nsc_encode); context->encode(context, data, scanline); PROFILER_EXIT(context->priv->prof_nsc_encode); - /* RLE encode */ PROFILER_ENTER(context->priv->prof_nsc_rle_compress_data); nsc_rle_compress_data(context); PROFILER_EXIT(context->priv->prof_nsc_rle_compress_data); - message->PlaneBuffers[0] = context->priv->PlaneBuffers[0]; message->PlaneBuffers[1] = context->priv->PlaneBuffers[1]; message->PlaneBuffers[2] = context->priv->PlaneBuffers[2]; message->PlaneBuffers[3] = context->priv->PlaneBuffers[3]; - message->LumaPlaneByteCount = context->PlaneByteCount[0]; message->OrangeChromaPlaneByteCount = context->PlaneByteCount[1]; message->GreenChromaPlaneByteCount = context->PlaneByteCount[2]; message->AlphaPlaneByteCount = context->PlaneByteCount[3]; message->ColorLossLevel = context->ColorLossLevel; message->ChromaSubsamplingLevel = context->ChromaSubsamplingLevel; - - nsc_write_message(context, s, message); + return nsc_write_message(context, s, message); } diff --git a/libfreerdp/codec/nsc_encode.h b/libfreerdp/codec/nsc_encode.h index f4c320197..c14099533 100644 --- a/libfreerdp/codec/nsc_encode.h +++ b/libfreerdp/codec/nsc_encode.h @@ -3,6 +3,8 @@ * NSCodec Encoder * * Copyright 2012 Vic Lee + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +22,6 @@ #ifndef __NSC_ENCODE_H #define __NSC_ENCODE_H -void nsc_encode(NSC_CONTEXT* context, BYTE* bmpdata, int rowstride); +void nsc_encode(NSC_CONTEXT* context, const BYTE* bmpdata, UINT32 rowstride); #endif diff --git a/libfreerdp/codec/nsc_sse2.c b/libfreerdp/codec/nsc_sse2.c index 1a9be3633..2e8e37ac5 100644 --- a/libfreerdp/codec/nsc_sse2.c +++ b/libfreerdp/codec/nsc_sse2.c @@ -28,18 +28,20 @@ #include #include +#include #include #include "nsc_types.h" #include "nsc_sse2.h" -static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, BYTE* data, int scanline) +static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, + const BYTE* data, UINT32 scanline) { UINT16 x; UINT16 y; UINT16 rw; BYTE ccl; - BYTE* src; + const BYTE* src; BYTE* yplane; BYTE* coplane; BYTE* cgplane; @@ -53,7 +55,6 @@ static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, BYTE* data, int __m128i cg_val; UINT32 tempWidth; UINT32 tempHeight; - tempWidth = ROUND_UP_TO(context->width, 8); tempHeight = ROUND_UP_TO(context->height, 2); rw = (context->ChromaSubsamplingLevel > 0 ? tempWidth : context->width); @@ -75,103 +76,117 @@ static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, BYTE* data, int { switch (context->pixel_format) { - case RDP_PIXEL_FORMAT_B8G8R8A8: - b_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), *(src + 8), *(src + 4), *src); - g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), *(src + 9), *(src + 5), *(src + 1)); - r_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), *(src + 10), *(src + 6), *(src + 2)); - a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15), *(src + 11), *(src + 7), *(src + 3)); + case PIXEL_FORMAT_BGRA32: + b_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), + *(src + 12), *(src + 8), *(src + 4), *src); + g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), + *(src + 13), *(src + 9), *(src + 5), *(src + 1)); + r_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), + *(src + 14), *(src + 10), *(src + 6), *(src + 2)); + a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), + *(src + 15), *(src + 11), *(src + 7), *(src + 3)); src += 32; break; - case RDP_PIXEL_FORMAT_R8G8B8A8: - r_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), *(src + 8), *(src + 4), *src); - g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), *(src + 9), *(src + 5), *(src + 1)); - b_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), *(src + 10), *(src + 6), *(src + 2)); - a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15), *(src + 11), *(src + 7), *(src + 3)); + case PIXEL_FORMAT_RGBA32: + r_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), + *(src + 12), *(src + 8), *(src + 4), *src); + g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), + *(src + 13), *(src + 9), *(src + 5), *(src + 1)); + b_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), + *(src + 14), *(src + 10), *(src + 6), *(src + 2)); + a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), + *(src + 15), *(src + 11), *(src + 7), *(src + 3)); src += 32; break; - case RDP_PIXEL_FORMAT_B8G8R8: - b_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9), *(src + 6), *(src + 3), *src); - g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10), *(src + 7), *(src + 4), *(src + 1)); - r_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11), *(src + 8), *(src + 5), *(src + 2)); + case PIXEL_FORMAT_BGR24: + b_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), + *(src + 9), *(src + 6), *(src + 3), *src); + g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), + *(src + 10), *(src + 7), *(src + 4), *(src + 1)); + r_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), + *(src + 11), *(src + 8), *(src + 5), *(src + 2)); a_val = _mm_set1_epi16(0xFF); src += 24; break; - case RDP_PIXEL_FORMAT_R8G8B8: - r_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9), *(src + 6), *(src + 3), *src); - g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10), *(src + 7), *(src + 4), *(src + 1)); - b_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11), *(src + 8), *(src + 5), *(src + 2)); + case PIXEL_FORMAT_RGB24: + r_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), + *(src + 9), *(src + 6), *(src + 3), *src); + g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), + *(src + 10), *(src + 7), *(src + 4), *(src + 1)); + b_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), + *(src + 11), *(src + 8), *(src + 5), *(src + 2)); a_val = _mm_set1_epi16(0xFF); src += 24; break; - case RDP_PIXEL_FORMAT_B5G6R5_LE: + case PIXEL_FORMAT_BGR16: b_val = _mm_set_epi16( - (((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)), - (((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)), - (((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)), - (((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)), - (((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)), - (((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)), - (((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)), - (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5))); + (((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)), + (((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)), + (((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)), + (((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)), + (((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)), + (((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)), + (((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)), + (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5))); g_val = _mm_set_epi16( - ((((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)), - ((((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)), - ((((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)), - ((((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)), - ((((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)), - ((((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)), - ((((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)), - ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3))); + ((((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)), + ((((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)), + ((((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)), + ((((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)), + ((((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)), + ((((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)), + ((((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)), + ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3))); r_val = _mm_set_epi16( - ((((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)), - ((((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)), - ((((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)), - ((((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)), - ((((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)), - ((((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)), - ((((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)), - ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07))); + ((((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)), + ((((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)), + ((((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)), + ((((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)), + ((((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)), + ((((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)), + ((((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)), + ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07))); a_val = _mm_set1_epi16(0xFF); src += 16; break; - case RDP_PIXEL_FORMAT_R5G6B5_LE: + case PIXEL_FORMAT_RGB16: r_val = _mm_set_epi16( - (((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)), - (((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)), - (((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)), - (((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)), - (((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)), - (((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)), - (((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)), - (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5))); + (((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)), + (((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)), + (((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)), + (((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)), + (((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)), + (((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)), + (((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)), + (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5))); g_val = _mm_set_epi16( - ((((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)), - ((((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)), - ((((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)), - ((((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)), - ((((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)), - ((((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)), - ((((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)), - ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3))); + ((((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)), + ((((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)), + ((((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)), + ((((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)), + ((((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)), + ((((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)), + ((((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)), + ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3))); b_val = _mm_set_epi16( - ((((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)), - ((((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)), - ((((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)), - ((((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)), - ((((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)), - ((((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)), - ((((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)), - ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07))); + ((((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)), + ((((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)), + ((((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)), + ((((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)), + ((((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)), + ((((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)), + ((((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)), + ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07))); a_val = _mm_set1_epi16(0xFF); src += 16; break; - case RDP_PIXEL_FORMAT_P4_PLANER: + case PIXEL_FORMAT_A4: { int shift; BYTE idx[8]; @@ -184,69 +199,72 @@ static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, BYTE* data, int idx[shift] |= (((*(src + 3)) >> shift) & 1) << 3; idx[shift] *= 3; } + r_val = _mm_set_epi16( - context->palette[idx[0]], - context->palette[idx[1]], - context->palette[idx[2]], - context->palette[idx[3]], - context->palette[idx[4]], - context->palette[idx[5]], - context->palette[idx[6]], - context->palette[idx[7]]); + context->palette[idx[0]], + context->palette[idx[1]], + context->palette[idx[2]], + context->palette[idx[3]], + context->palette[idx[4]], + context->palette[idx[5]], + context->palette[idx[6]], + context->palette[idx[7]]); g_val = _mm_set_epi16( - context->palette[idx[0] + 1], - context->palette[idx[1] + 1], - context->palette[idx[2] + 1], - context->palette[idx[3] + 1], - context->palette[idx[4] + 1], - context->palette[idx[5] + 1], - context->palette[idx[6] + 1], - context->palette[idx[7] + 1]); + context->palette[idx[0] + 1], + context->palette[idx[1] + 1], + context->palette[idx[2] + 1], + context->palette[idx[3] + 1], + context->palette[idx[4] + 1], + context->palette[idx[5] + 1], + context->palette[idx[6] + 1], + context->palette[idx[7] + 1]); b_val = _mm_set_epi16( - context->palette[idx[0] + 2], - context->palette[idx[1] + 2], - context->palette[idx[2] + 2], - context->palette[idx[3] + 2], - context->palette[idx[4] + 2], - context->palette[idx[5] + 2], - context->palette[idx[6] + 2], - context->palette[idx[7] + 2]); + context->palette[idx[0] + 2], + context->palette[idx[1] + 2], + context->palette[idx[2] + 2], + context->palette[idx[3] + 2], + context->palette[idx[4] + 2], + context->palette[idx[5] + 2], + context->palette[idx[6] + 2], + context->palette[idx[7] + 2]); src += 4; } + a_val = _mm_set1_epi16(0xFF); break; - case RDP_PIXEL_FORMAT_P8: + case PIXEL_FORMAT_RGB8: { r_val = _mm_set_epi16( - context->palette[(*(src + 7)) * 3], - context->palette[(*(src + 6)) * 3], - context->palette[(*(src + 5)) * 3], - context->palette[(*(src + 4)) * 3], - context->palette[(*(src + 3)) * 3], - context->palette[(*(src + 2)) * 3], - context->palette[(*(src + 1)) * 3], - context->palette[(*src) * 3]); + context->palette[(*(src + 7)) * 3], + context->palette[(*(src + 6)) * 3], + context->palette[(*(src + 5)) * 3], + context->palette[(*(src + 4)) * 3], + context->palette[(*(src + 3)) * 3], + context->palette[(*(src + 2)) * 3], + context->palette[(*(src + 1)) * 3], + context->palette[(*src) * 3]); g_val = _mm_set_epi16( - context->palette[(*(src + 7)) * 3 + 1], - context->palette[(*(src + 6)) * 3 + 1], - context->palette[(*(src + 5)) * 3 + 1], - context->palette[(*(src + 4)) * 3 + 1], - context->palette[(*(src + 3)) * 3 + 1], - context->palette[(*(src + 2)) * 3 + 1], - context->palette[(*(src + 1)) * 3 + 1], - context->palette[(*src) * 3 + 1]); + context->palette[(*(src + 7)) * 3 + 1], + context->palette[(*(src + 6)) * 3 + 1], + context->palette[(*(src + 5)) * 3 + 1], + context->palette[(*(src + 4)) * 3 + 1], + context->palette[(*(src + 3)) * 3 + 1], + context->palette[(*(src + 2)) * 3 + 1], + context->palette[(*(src + 1)) * 3 + 1], + context->palette[(*src) * 3 + 1]); b_val = _mm_set_epi16( - context->palette[(*(src + 7)) * 3 + 2], - context->palette[(*(src + 6)) * 3 + 2], - context->palette[(*(src + 5)) * 3 + 2], - context->palette[(*(src + 4)) * 3 + 2], - context->palette[(*(src + 3)) * 3 + 2], - context->palette[(*(src + 2)) * 3 + 2], - context->palette[(*(src + 1)) * 3 + 2], - context->palette[(*src) * 3 + 2]); + context->palette[(*(src + 7)) * 3 + 2], + context->palette[(*(src + 6)) * 3 + 2], + context->palette[(*(src + 5)) * 3 + 2], + context->palette[(*(src + 4)) * 3 + 2], + context->palette[(*(src + 3)) * 3 + 2], + context->palette[(*(src + 2)) * 3 + 2], + context->palette[(*(src + 1)) * 3 + 2], + context->palette[(*src) * 3 + 2]); src += 8; } + a_val = _mm_set1_epi16(0xFF); break; @@ -263,7 +281,6 @@ static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, BYTE* data, int cg_val = _mm_sub_epi16(g_val, _mm_srai_epi16(r_val, 1)); cg_val = _mm_sub_epi16(cg_val, _mm_srai_epi16(b_val, 1)); cg_val = _mm_srai_epi16(cg_val, ccl); - y_val = _mm_packus_epi16(y_val, y_val); _mm_storeu_si128((__m128i*) yplane, y_val); co_val = _mm_packs_epi16(co_val, co_val); @@ -280,9 +297,12 @@ static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, BYTE* data, int if (context->ChromaSubsamplingLevel > 0 && (context->width % 2) == 1) { - context->priv->PlaneBuffers[0][y * rw + context->width] = context->priv->PlaneBuffers[0][y * rw + context->width - 1]; - context->priv->PlaneBuffers[1][y * rw + context->width] = context->priv->PlaneBuffers[1][y * rw + context->width - 1]; - context->priv->PlaneBuffers[2][y * rw + context->width] = context->priv->PlaneBuffers[2][y * rw + context->width - 1]; + context->priv->PlaneBuffers[0][y * rw + context->width] = + context->priv->PlaneBuffers[0][y * rw + context->width - 1]; + context->priv->PlaneBuffers[1][y * rw + context->width] = + context->priv->PlaneBuffers[1][y * rw + context->width - 1]; + context->priv->PlaneBuffers[2][y * rw + context->width] = + context->priv->PlaneBuffers[2][y * rw + context->width - 1]; } } @@ -309,7 +329,6 @@ static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context) __m128i t; __m128i val; __m128i mask = _mm_set1_epi16(0xFF); - tempWidth = ROUND_UP_TO(context->width, 8); tempHeight = ROUND_UP_TO(context->height, 2); @@ -333,7 +352,6 @@ static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context) co_dst += 8; co_src0 += 16; co_src1 += 16; - t = _mm_loadu_si128((__m128i*) cg_src0); t = _mm_avg_epu8(t, _mm_loadu_si128((__m128i*) cg_src1)); val = _mm_and_si128(_mm_srli_si128(t, 1), mask); @@ -347,7 +365,8 @@ static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context) } } -static void nsc_encode_sse2(NSC_CONTEXT* context, BYTE* data, int scanline) +static void nsc_encode_sse2(NSC_CONTEXT* context, const BYTE* data, + UINT32 scanline) { nsc_encode_argb_to_aycocg_sse2(context, data, scanline); @@ -360,6 +379,5 @@ static void nsc_encode_sse2(NSC_CONTEXT* context, BYTE* data, int scanline) void nsc_init_sse2(NSC_CONTEXT* context) { IF_PROFILER(context->priv->prof_nsc_encode->name = "nsc_encode_sse2"); - context->encode = nsc_encode_sse2; } diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index 9b874b085..836a220b0 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -3,6 +3,8 @@ * RDP6 Planar Codec * * Copyright 2013 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +33,8 @@ #define TAG FREERDP_TAG("codec") -static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, int nWidth, int nHeight) +static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, + int nWidth, int nHeight) { int x, y; int cRawBytes; @@ -42,13 +45,12 @@ static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, int nWidt for (y = 0; y < nHeight; y++) { - for (x = 0; x < nWidth; ) + for (x = 0; x < nWidth;) { if (pRLE >= pEnd) return -1; controlByte = *pRLE++; - nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte); cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte); @@ -66,7 +68,6 @@ static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, int nWidt pRLE += cRawBytes; x += cRawBytes; cRawBytes = 0; - x += nRunLength; nRunLength = 0; @@ -78,24 +79,26 @@ static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, int nWidt } } - return (int) (pRLE - pSrcData); + return (int)(pRLE - pSrcData); } -static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, BYTE* pDstData, - int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, int nChannel, BOOL vFlip) +static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, + BYTE* pDstData, INT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + UINT32 nChannel, BOOL vFlip) { - int x, y; + UINT32 x, y; BYTE* dstp; UINT32 pixel; - int cRawBytes; - int nRunLength; - int deltaValue; - int beg, end, inc; + UINT32 cRawBytes; + UINT32 nRunLength; + INT32 deltaValue; + UINT32 beg, end, inc; BYTE controlByte; BYTE* currentScanline; BYTE* previousScanline; const BYTE* srcp = pSrcData; - dstp = pDstData; previousScanline = NULL; @@ -115,11 +118,10 @@ static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, BYT for (y = beg; y != end; y += inc) { dstp = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4) + nChannel]; - pixel = 0; currentScanline = dstp; - for (x = 0; x < nWidth; ) + for (x = 0; x < nWidth;) { controlByte = *srcp; srcp++; @@ -153,12 +155,10 @@ static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, BYT if (!previousScanline) { /* first scanline, absolute values */ - while (cRawBytes > 0) { pixel = *srcp; srcp++; - *dstp = pixel; dstp += 4; x++; @@ -176,7 +176,6 @@ static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, BYT else { /* delta values relative to previous scanline */ - while (cRawBytes > 0) { deltaValue = *srcp; @@ -215,15 +214,16 @@ static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize, BYT previousScanline = currentScanline; } - return (int) (srcp - pSrcData); + return (int)(srcp - pSrcData); } -static int planar_decompress_planes_raw(const BYTE* pSrcData[4], int nSrcStep, BYTE* pDstData, - int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, BOOL alpha, BOOL vFlip) +static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, + BOOL alpha, BOOL vFlip) { - int x, y; - int beg, end, inc; - BYTE* pRGB = pDstData; + INT32 x, y; + INT32 beg, end, inc; const BYTE* pR = pSrcData[0]; const BYTE* pG = pSrcData[1]; const BYTE* pB = pSrcData[2]; @@ -246,14 +246,14 @@ static int planar_decompress_planes_raw(const BYTE* pSrcData[4], int nSrcStep, B { for (y = beg; y != end; y += inc) { - pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)]; + BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel( + DstFormat))]; for (x = 0; x < nWidth; x++) { - *pRGB++ = *pB++; - *pRGB++ = *pG++; - *pRGB++ = *pR++; - *pRGB++ = *pA++; + UINT32 color = GetColor(DstFormat, *pR++, *pG++, *pB++, *pA++); + WriteColor(pRGB, DstFormat, color); + pRGB += GetBytesPerPixel(DstFormat); } } } @@ -261,43 +261,45 @@ static int planar_decompress_planes_raw(const BYTE* pSrcData[4], int nSrcStep, B { for (y = beg; y != end; y += inc) { - pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)]; + BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel( + DstFormat))]; for (x = 0; x < nWidth; x++) { - *pRGB++ = *pB++; - *pRGB++ = *pG++; - *pRGB++ = *pR++; - *pRGB++ = 0xFF; + UINT32 color = GetColor(DstFormat, *pR++, *pG++, *pB++, 0xFF); + WriteColor(pRGB, DstFormat, color); + pRGB += GetBytesPerPixel(DstFormat); } } } - return 1; + return TRUE; } -int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, BOOL vFlip) +INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar, + const BYTE* pSrcData, UINT32 SrcSize, + BYTE** ppDstData, UINT32 DstFormat, + INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, BOOL vFlip) { BOOL cs; BOOL rle; UINT32 cll; BOOL alpha; - int status; - BYTE* srcp; - int subSize; - int subWidth; - int subHeight; - int planeSize; + INT32 status; + const BYTE* srcp; + UINT32 subSize; + UINT32 subWidth; + UINT32 subHeight; + UINT32 planeSize; BYTE* pDstData; - int rleSizes[4]; - int rawSizes[4]; - int rawWidths[4]; - int rawHeights[4]; + UINT32 rleSizes[4]; + UINT32 rawSizes[4]; + UINT32 rawWidths[4]; + UINT32 rawHeights[4]; BYTE FormatHeader; - BOOL useTempBuffer; - int dstBitsPerPixel; - int dstBytesPerPixel; + UINT32 dstBitsPerPixel; + UINT32 dstBytesPerPixel; const BYTE* planes[4]; UINT32 UncompressedSize; const primitives_t* prims = primitives_get(); @@ -305,15 +307,14 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS if ((nWidth < 0) || (nHeight < 0)) return -1; - dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); - dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); + dstBitsPerPixel = GetBitsPerPixel(DstFormat); + dstBytesPerPixel = GetBytesPerPixel(DstFormat); if (nDstStep < 0) - nDstStep = nWidth * 4; + nDstStep = nWidth * GetBytesPerPixel(DstFormat); srcp = pSrcData; - UncompressedSize = nWidth * nHeight * 4; - + UncompressedSize = nWidth * nHeight * GetBytesPerPixel(DstFormat); pDstData = *ppDstData; if (!pDstData) @@ -326,24 +327,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS *ppDstData = pDstData; } - useTempBuffer = (dstBytesPerPixel != 4) ? TRUE : FALSE; - - if (useTempBuffer) - { - if (UncompressedSize > planar->TempSize) - { - planar->TempBuffer = _aligned_realloc(planar->TempBuffer, UncompressedSize, 16); - planar->TempSize = UncompressedSize; - } - - if (!planar->TempBuffer) - return -1; - - pDstData = planar->TempBuffer; - } - FormatHeader = *srcp++; - cll = (FormatHeader & PLANAR_FORMAT_HEADER_CLL_MASK); cs = (FormatHeader & PLANAR_FORMAT_HEADER_CS) ? TRUE : FALSE; rle = (FormatHeader & PLANAR_FORMAT_HEADER_RLE) ? TRUE : FALSE; @@ -356,7 +340,6 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS subWidth = (nWidth / 2) + (nWidth % 2); subHeight = (nHeight / 2) + (nHeight % 2); - planeSize = nWidth * nHeight; subSize = subWidth * subHeight; @@ -365,15 +348,12 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS rawSizes[0] = planeSize; /* LumaOrRedPlane */ rawWidths[0] = nWidth; rawHeights[0] = nHeight; - rawSizes[1] = planeSize; /* OrangeChromaOrGreenPlane */ rawWidths[1] = nWidth; rawHeights[1] = nHeight; - rawSizes[2] = planeSize; /* GreenChromaOrBluePlane */ rawWidths[2] = nWidth; rawHeights[2] = nHeight; - rawSizes[3] = planeSize; /* AlphaPlane */ rawWidths[3] = nWidth; rawHeights[3] = nHeight; @@ -383,15 +363,12 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS rawSizes[0] = planeSize; /* LumaOrRedPlane */ rawWidths[0] = nWidth; rawHeights[0] = nHeight; - rawSizes[1] = subSize; /* OrangeChromaOrGreenPlane */ rawWidths[1] = subWidth; rawHeights[1] = subHeight; - rawSizes[2] = subSize; /* GreenChromaOrBluePlane */ rawWidths[2] = subWidth; rawHeights[2] = subHeight; - rawSizes[3] = planeSize; /* AlphaPlane */ rawWidths[3] = nWidth; rawHeights[3] = nHeight; @@ -428,28 +405,28 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS { planes[3] = srcp; rleSizes[3] = planar_skip_plane_rle(planes[3], SrcSize - (planes[3] - pSrcData), - rawWidths[3], rawHeights[3]); /* AlphaPlane */ + rawWidths[3], rawHeights[3]); /* AlphaPlane */ if (rleSizes[3] < 0) return -1; planes[0] = planes[3] + rleSizes[3]; rleSizes[0] = planar_skip_plane_rle(planes[0], SrcSize - (planes[0] - pSrcData), - rawWidths[0], rawHeights[0]); /* RedPlane */ + rawWidths[0], rawHeights[0]); /* RedPlane */ if (rleSizes[0] < 0) return -1; planes[1] = planes[0] + rleSizes[0]; rleSizes[1] = planar_skip_plane_rle(planes[1], SrcSize - (planes[1] - pSrcData), - rawWidths[1], rawHeights[1]); /* GreenPlane */ + rawWidths[1], rawHeights[1]); /* GreenPlane */ if (rleSizes[1] < 1) return -1; planes[2] = planes[1] + rleSizes[1]; rleSizes[2] = planar_skip_plane_rle(planes[2], SrcSize - (planes[2] - pSrcData), - rawWidths[2], rawHeights[2]); /* BluePlane */ + rawWidths[2], rawHeights[2]); /* BluePlane */ if (rleSizes[2] < 1) return -1; @@ -458,21 +435,21 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS { planes[0] = srcp; rleSizes[0] = planar_skip_plane_rle(planes[0], SrcSize - (planes[0] - pSrcData), - rawWidths[0], rawHeights[0]); /* RedPlane */ + rawWidths[0], rawHeights[0]); /* RedPlane */ if (rleSizes[0] < 0) return -1; planes[1] = planes[0] + rleSizes[0]; rleSizes[1] = planar_skip_plane_rle(planes[1], SrcSize - (planes[1] - pSrcData), - rawWidths[1], rawHeights[1]); /* GreenPlane */ + rawWidths[1], rawHeights[1]); /* GreenPlane */ if (rleSizes[1] < 1) return -1; planes[2] = planes[1] + rleSizes[1]; rleSizes[2] = planar_skip_plane_rle(planes[2], SrcSize - (planes[2] - pSrcData), - rawWidths[2], rawHeights[2]); /* BluePlane */ + rawWidths[2], rawHeights[2]); /* BluePlane */ if (rleSizes[2] < 1) return -1; @@ -485,16 +462,14 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS { if (alpha) { - planar_decompress_planes_raw(planes, nWidth, pDstData, nDstStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); - + planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep, + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3]; } else /* NoAlpha */ { - planar_decompress_planes_raw(planes, nWidth, pDstData, nDstStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); - + planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep, + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2]; } @@ -503,42 +478,71 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS } else /* RLE */ { + UINT32 TempFormat = PIXEL_FORMAT_ARGB32; + BYTE* pTempData = pDstData; + UINT32 nTempStep = nDstStep; + + if (DstFormat != TempFormat) + { + pTempData = malloc(nWidth * nHeight * 4); + + if (!pTempData) + return -1; + } + if (alpha) { status = planar_decompress_plane_rle(planes[3], rleSizes[3], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 3, vFlip); /* AlphaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3, + vFlip); /* AlphaPlane */ status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2, vFlip); /* RedPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* RedPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1, vFlip); /* GreenPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* GreenPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0, vFlip); /* BluePlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* BluePlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2] + rleSizes[3]; } else /* NoAlpha */ { status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2, vFlip); /* RedPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* RedPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1, vFlip); /* GreenPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* GreenPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0, vFlip); /* BluePlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* BluePlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2]; } + + if (pTempData != pDstData) + { + freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, + pTempData, + TempFormat, nTempStep, nXDst, nYDst, NULL); + free(pTempData); + } } } else /* YCoCg */ { + BYTE* pTempData; + UINT32 nTempStep = nDstStep; + UINT32 TempFormat = PIXEL_FORMAT_RGBA32; + pTempData = malloc(UncompressedSize); + + if (!pTempData) + return -1; + if (cs) { WLog_ERR(TAG, "Chroma subsampling unimplemented"); + free(pTempData); return -1; } @@ -546,16 +550,14 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS { if (alpha) { - planar_decompress_planes_raw(planes, nWidth, pDstData, nDstStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); - + planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3]; } else /* NoAlpha */ { - planar_decompress_planes_raw(planes, nWidth, pDstData, nDstStep, - nXDst, nYDst, nWidth, nHeight, alpha, vFlip); - + planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, + nXDst, nYDst, nWidth, nHeight, alpha, vFlip); srcp += rawSizes[0] + rawSizes[1] + rawSizes[2]; } @@ -567,109 +569,75 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS if (alpha) { status = planar_decompress_plane_rle(planes[3], rleSizes[3], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 3, vFlip); /* AlphaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3, + vFlip); /* AlphaPlane */ status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2, vFlip); /* LumaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* LumaPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1, vFlip); /* OrangeChromaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* OrangeChromaPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0, vFlip); /* GreenChromaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* GreenChromaPlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2] + rleSizes[3]; } else /* NoAlpha */ { status = planar_decompress_plane_rle(planes[0], rleSizes[0], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2, vFlip); /* LumaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2, + vFlip); /* LumaPlane */ status = planar_decompress_plane_rle(planes[1], rleSizes[1], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1, vFlip); /* OrangeChromaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1, + vFlip); /* OrangeChromaPlane */ status = planar_decompress_plane_rle(planes[2], rleSizes[2], - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0, vFlip); /* GreenChromaPlane */ - + pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0, + vFlip); /* GreenChromaPlane */ srcp += rleSizes[0] + rleSizes[1] + rleSizes[2]; } } - prims->YCoCgToRGB_8u_AC4R(pDstData, nDstStep, pDstData, nDstStep, nWidth, nHeight, cll, alpha, FALSE); + prims->YCoCgToRGB_8u_AC4R(pTempData, nTempStep, pDstData, DstFormat, nDstStep, + nWidth, nHeight, cll, alpha); + free(pTempData); } status = (SrcSize == (srcp - pSrcData)) ? 1 : -1; - - if (status < 0) - return status; - - if (useTempBuffer) - { - pDstData = *ppDstData; - - status = freerdp_image_copy(pDstData, DstFormat, -1, 0, 0, nWidth, nHeight, - planar->TempBuffer, PIXEL_FORMAT_XRGB32, -1, 0, 0, NULL); - } - return status; } -int freerdp_split_color_planes(BYTE* data, UINT32 format, int width, int height, int scanline, BYTE* planes[4]) +static BOOL freerdp_split_color_planes(const BYTE* data, UINT32 format, + UINT32 width, UINT32 height, + UINT32 scanline, BYTE** planes) { - int bpp; - int i, j, k; - + INT32 i, j, k; + UINT32* pixel; k = 0; - bpp = FREERDP_PIXEL_FORMAT_BPP(format); - if (bpp == 32) + for (i = height - 1; i >= 0; i--) { - UINT32* pixel; + pixel = (UINT32*) &data[scanline * i]; - for (i = height - 1; i >= 0; i--) + for (j = 0; j < width; j++) { - pixel = (UINT32*) &data[scanline * i]; - - for (j = 0; j < width; j++) - { - GetARGB32(planes[0][k], planes[1][k], planes[2][k], planes[3][k], *pixel); - pixel++; - k++; - } + *pixel = GetColor(format, planes[1][k], planes[2][k], + planes[3][k], planes[0][k]); + pixel++; + k++; } } - else if (bpp == 24) - { - UINT32* pixel; - for (i = height - 1; i >= 0; i--) - { - pixel = (UINT32*) &data[scanline * i]; - - for (j = 0; j < width; j++) - { - GetRGB32(planes[1][k], planes[2][k], planes[3][k], *pixel); - planes[0][k] = 0xFF; /* A */ - pixel++; - k++; - } - } - } - else - { - return -1; - } - - return 0; + return TRUE; } -int freerdp_bitmap_planar_write_rle_bytes(BYTE* pInBuffer, int cRawBytes, int nRunLength, BYTE* pOutBuffer, int outBufferSize) +static UINT32 freerdp_bitmap_planar_write_rle_bytes( + const BYTE* pInBuffer, UINT32 cRawBytes, UINT32 nRunLength, + BYTE* pOutBuffer, UINT32 outBufferSize) { - BYTE* pInput; + const BYTE* pInput; BYTE* pOutput; BYTE controlByte; - int nBytesToWrite; - + UINT32 nBytesToWrite; pInput = pInBuffer; pOutput = pOutBuffer; @@ -718,11 +686,9 @@ int freerdp_bitmap_planar_write_rle_bytes(BYTE* pInBuffer, int cRawBytes, int nR return 0; outBufferSize--; - *pOutput = controlByte; pOutput++; - - nBytesToWrite = (int) (controlByte >> 4); + nBytesToWrite = (int)(controlByte >> 4); if (nBytesToWrite) { @@ -778,18 +744,20 @@ int freerdp_bitmap_planar_write_rle_bytes(BYTE* pInBuffer, int cRawBytes, int nR return (pOutput - pOutBuffer); } -int freerdp_bitmap_planar_encode_rle_bytes(BYTE* pInBuffer, int inBufferSize, BYTE* pOutBuffer, int outBufferSize) +static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer, + UINT32 inBufferSize, + BYTE* pOutBuffer, + UINT32 outBufferSize) { BYTE symbol; - BYTE* pInput; + const BYTE* pInput; BYTE* pOutput; - BYTE* pBytes; - int cRawBytes; - int nRunLength; - int bSymbolMatch; - int nBytesWritten; - int nTotalBytesWritten; - + const BYTE* pBytes; + UINT32 cRawBytes; + UINT32 nRunLength; + UINT32 bSymbolMatch; + UINT32 nBytesWritten; + UINT32 nTotalBytesWritten; symbol = 0; cRawBytes = 0; nRunLength = 0; @@ -820,10 +788,10 @@ int freerdp_bitmap_planar_encode_rle_bytes(BYTE* pInBuffer, int inBufferSize, BY else { pBytes = pInput - (cRawBytes + nRunLength + 1); - - nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes, - cRawBytes, nRunLength, pOutput, outBufferSize); - + nBytesWritten = freerdp_bitmap_planar_write_rle_bytes( + pBytes, cRawBytes, + nRunLength, pOutput, + outBufferSize); nRunLength = 0; if (!nBytesWritten || (nBytesWritten > outBufferSize)) @@ -844,9 +812,8 @@ int freerdp_bitmap_planar_encode_rle_bytes(BYTE* pInBuffer, int inBufferSize, BY if (cRawBytes || nRunLength) { pBytes = pInput - (cRawBytes + nRunLength); - nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes, - cRawBytes, nRunLength, pOutput, outBufferSize); + cRawBytes, nRunLength, pOutput, outBufferSize); if (!nBytesWritten) return 0; @@ -860,19 +827,22 @@ int freerdp_bitmap_planar_encode_rle_bytes(BYTE* pInBuffer, int inBufferSize, BY return nTotalBytesWritten; } -BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int height, BYTE* outPlane, int* dstSize) +BYTE* freerdp_bitmap_planar_compress_plane_rle(const BYTE* inPlane, + UINT32 width, UINT32 height, + BYTE* outPlane, UINT32* dstSize) { - int index; - BYTE* pInput; + UINT32 index; + const BYTE* pInput; BYTE* pOutput; - int outBufferSize; - int nBytesWritten; - int nTotalBytesWritten; + UINT32 outBufferSize; + UINT32 nBytesWritten; + UINT32 nTotalBytesWritten; if (!outPlane) { outBufferSize = width * height; outPlane = malloc(outBufferSize); + if (!outPlane) return NULL; } @@ -888,7 +858,8 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int hei while (outBufferSize) { - nBytesWritten = freerdp_bitmap_planar_encode_rle_bytes(pInput, width, pOutput, outBufferSize); + nBytesWritten = freerdp_bitmap_planar_encode_rle_bytes( + pInput, width, pOutput, outBufferSize); if ((!nBytesWritten) || (nBytesWritten > outBufferSize)) return NULL; @@ -904,16 +875,16 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int hei } *dstSize = nTotalBytesWritten; - return outPlane; } -int freerdp_bitmap_planar_compress_planes_rle(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes, int* dstSizes, BOOL skipAlpha) +static UINT32 freerdp_bitmap_planar_compress_planes_rle( + const BYTE** inPlanes, UINT32 width, UINT32 height, + BYTE* outPlanes, UINT32* dstSizes, BOOL skipAlpha) { - int outPlanesSize = width * height * 4; + UINT32 outPlanesSize = width * height * 4; /* AlphaPlane */ - if (skipAlpha) { dstSizes[0] = 0; @@ -922,7 +893,8 @@ int freerdp_bitmap_planar_compress_planes_rle(BYTE* inPlanes[4], int width, int { dstSizes[0] = outPlanesSize; - if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[0], width, height, outPlanes, &dstSizes[0])) + if (!freerdp_bitmap_planar_compress_plane_rle( + inPlanes[0], width, height, outPlanes, &dstSizes[0])) return 0; outPlanes += dstSizes[0]; @@ -930,44 +902,44 @@ int freerdp_bitmap_planar_compress_planes_rle(BYTE* inPlanes[4], int width, int } /* LumaOrRedPlane */ - dstSizes[1] = outPlanesSize; - if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[1], width, height, outPlanes, &dstSizes[1])) + if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[1], width, height, + outPlanes, &dstSizes[1])) return 0; outPlanes += dstSizes[1]; outPlanesSize -= dstSizes[1]; - /* OrangeChromaOrGreenPlane */ - dstSizes[2] = outPlanesSize; - if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[2], width, height, outPlanes, &dstSizes[2])) + if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[2], width, height, + outPlanes, &dstSizes[2])) return 0; outPlanes += dstSizes[2]; outPlanesSize -= dstSizes[2]; - /* GreenChromeOrBluePlane */ - dstSizes[3] = outPlanesSize; - if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[3], width, height, outPlanes, &dstSizes[3])) + if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[3], width, height, + outPlanes, &dstSizes[3])) return 0; outPlanes += dstSizes[3]; outPlanesSize -= dstSizes[3]; - return 1; } -BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int height, BYTE* outPlane) +BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* inPlane, + UINT32 width, UINT32 height, + BYTE* outPlane) { char s2c; - int delta; - int y, x; - BYTE *outPtr, *srcPtr, *prevLinePtr; + INT32 delta; + UINT32 y, x; + BYTE* outPtr; + const BYTE* srcPtr, *prevLinePtr; if (!outPlane) { @@ -977,7 +949,6 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int hei // first line is copied as is CopyMemory(outPlane, inPlane, width); - outPtr = outPlane + width; srcPtr = inPlane + width; prevLinePtr = inPlane; @@ -987,11 +958,8 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int hei for (x = 0; x < width; x++, outPtr++, srcPtr++, prevLinePtr++) { delta = *srcPtr - *prevLinePtr; - - s2c = (delta >= 0) ? (char) delta : (char) (~((BYTE) (-delta)) + 1); - - s2c = (s2c >= 0) ? (s2c << 1) : (char) (((~((BYTE) s2c) + 1) << 1) - 1); - + s2c = (delta >= 0) ? (char) delta : (char)(~((BYTE)(-delta)) + 1); + s2c = (s2c >= 0) ? (s2c << 1) : (char)(((~((BYTE) s2c) + 1) << 1) - 1); *outPtr = (BYTE)s2c; } } @@ -999,13 +967,17 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int hei return outPlane; } -BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes[4]) +BOOL freerdp_bitmap_planar_delta_encode_planes(const BYTE** inPlanes, + UINT32 width, UINT32 height, + BYTE* outPlanes[4]) { - int i; + UINT32 i; for (i = 0; i < 4; i++) { - outPlanes[i] = freerdp_bitmap_planar_delta_encode_plane(inPlanes[i], width, height, outPlanes[i]); + outPlanes[i] = freerdp_bitmap_planar_delta_encode_plane( + inPlanes[i], width, height, outPlanes[i]); + if (!outPlanes[i]) return FALSE; } @@ -1013,13 +985,15 @@ BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int return TRUE; } -BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, UINT32 format, - int width, int height, int scanline, BYTE* dstData, int* pDstSize) +BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, + const BYTE* data, UINT32 format, + UINT32 width, UINT32 height, UINT32 scanline, + BYTE* dstData, UINT32* pDstSize) { - int size; + UINT32 size; BYTE* dstp; - int planeSize; - int dstSizes[4]; + UINT32 planeSize; + UINT32 dstSizes[4]; BYTE FormatHeader = 0; if (context->AllowSkipAlpha) @@ -1027,32 +1001,30 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, planeSize = width * height; - if (freerdp_split_color_planes(data, format, width, height, scanline, context->planes) < 0) - { + if (!freerdp_split_color_planes(data, format, width, height, scanline, + context->planes)) return NULL; - } if (context->AllowRunLengthEncoding) { - if (!freerdp_bitmap_planar_delta_encode_planes(context->planes, width, height, context->deltaPlanes)) + if (!freerdp_bitmap_planar_delta_encode_planes( + (const BYTE**)context->planes, width, height, + context->deltaPlanes)) return NULL;; - if (freerdp_bitmap_planar_compress_planes_rle(context->deltaPlanes, width, height, - context->rlePlanesBuffer, (int*) &dstSizes, context->AllowSkipAlpha) > 0) + if (freerdp_bitmap_planar_compress_planes_rle( + (const BYTE**)context->deltaPlanes, width, height, + context->rlePlanesBuffer, dstSizes, + context->AllowSkipAlpha) > 0) { int offset = 0; - FormatHeader |= PLANAR_FORMAT_HEADER_RLE; - context->rlePlanes[0] = &context->rlePlanesBuffer[offset]; offset += dstSizes[0]; - context->rlePlanes[1] = &context->rlePlanesBuffer[offset]; offset += dstSizes[1]; - context->rlePlanes[2] = &context->rlePlanesBuffer[offset]; offset += dstSizes[2]; - context->rlePlanes[3] = &context->rlePlanesBuffer[offset]; offset += dstSizes[3]; //WLog_DBG(TAG, "R: [%d/%d] G: [%d/%d] B: [%d/%d]", @@ -1081,13 +1053,14 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, size++; dstData = malloc(size); + if (!dstData) return NULL; + *pDstSize = size; } dstp = dstData; - *dstp = FormatHeader; /* FormatHeader */ dstp++; @@ -1156,7 +1129,6 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, size = (dstp - dstData); *pDstSize = size; - return dstData; } @@ -1168,11 +1140,12 @@ BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* context) return TRUE; } -BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWidth, int maxHeight) +BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new( + DWORD flags, UINT32 maxWidth, UINT32 maxHeight) { BITMAP_PLANAR_CONTEXT* context; - context = (BITMAP_PLANAR_CONTEXT*) calloc(1, sizeof(BITMAP_PLANAR_CONTEXT)); + if (!context) return NULL; @@ -1193,29 +1166,34 @@ BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWid context->maxWidth = maxWidth; context->maxHeight = maxHeight; context->maxPlaneSize = context->maxWidth * context->maxHeight; - context->planesBuffer = malloc(context->maxPlaneSize * 4); + if (!context->planesBuffer) goto error_planesBuffer; + context->planes[0] = &context->planesBuffer[context->maxPlaneSize * 0]; context->planes[1] = &context->planesBuffer[context->maxPlaneSize * 1]; context->planes[2] = &context->planesBuffer[context->maxPlaneSize * 2]; context->planes[3] = &context->planesBuffer[context->maxPlaneSize * 3]; - context->deltaPlanesBuffer = malloc(context->maxPlaneSize * 4); + if (!context->deltaPlanesBuffer) goto error_deltaPlanesBuffer; - context->deltaPlanes[0] = &context->deltaPlanesBuffer[context->maxPlaneSize * 0]; - context->deltaPlanes[1] = &context->deltaPlanesBuffer[context->maxPlaneSize * 1]; - context->deltaPlanes[2] = &context->deltaPlanesBuffer[context->maxPlaneSize * 2]; - context->deltaPlanes[3] = &context->deltaPlanesBuffer[context->maxPlaneSize * 3]; + context->deltaPlanes[0] = &context->deltaPlanesBuffer[context->maxPlaneSize * + 0]; + context->deltaPlanes[1] = &context->deltaPlanesBuffer[context->maxPlaneSize * + 1]; + context->deltaPlanes[2] = &context->deltaPlanesBuffer[context->maxPlaneSize * + 2]; + context->deltaPlanes[3] = &context->deltaPlanesBuffer[context->maxPlaneSize * + 3]; context->rlePlanesBuffer = malloc(context->maxPlaneSize * 4); + if (!context->rlePlanesBuffer) goto error_rlePlanesBuffer; return context; - error_rlePlanesBuffer: free(context->deltaPlanesBuffer); error_deltaPlanesBuffer: @@ -1233,6 +1211,5 @@ void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context) free(context->planesBuffer); free(context->deltaPlanesBuffer); free(context->rlePlanesBuffer); - free(context); } diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index 3bb5b0413..105327f52 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "rfx_differential.h" @@ -35,7 +36,7 @@ #define TAG FREERDP_TAG("codec.progressive") -const char* progressive_get_block_type_string(UINT16 blockType) +static const char* progressive_get_block_type_string(UINT16 blockType) { switch (blockType) { @@ -79,7 +80,8 @@ const char* progressive_get_block_type_string(UINT16 blockType) return "PROGRESSIVE_WBT_UNKNOWN"; } -void progressive_component_codec_quant_read(BYTE* block, RFX_COMPONENT_CODEC_QUANT* quantVal) +static void progressive_component_codec_quant_read(const BYTE* block, + RFX_COMPONENT_CODEC_QUANT* quantVal) { quantVal->LL3 = block[0] & 0x0F; quantVal->HL3 = block[0] >> 4; @@ -93,7 +95,7 @@ void progressive_component_codec_quant_read(BYTE* block, RFX_COMPONENT_CODEC_QUA quantVal->HH1 = block[4] >> 4; } -void progressive_rfx_quant_ladd(RFX_COMPONENT_CODEC_QUANT* q, int val) +static void progressive_rfx_quant_ladd(RFX_COMPONENT_CODEC_QUANT* q, int val) { q->HL1 += val; /* HL1 */ q->LH1 += val; /* LH1 */ @@ -107,7 +109,9 @@ void progressive_rfx_quant_ladd(RFX_COMPONENT_CODEC_QUANT* q, int val) q->LL3 += val; /* LL3 */ } -void progressive_rfx_quant_add(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODEC_QUANT* q2, RFX_COMPONENT_CODEC_QUANT* dst) +static void progressive_rfx_quant_add(RFX_COMPONENT_CODEC_QUANT* q1, + RFX_COMPONENT_CODEC_QUANT* q2, + RFX_COMPONENT_CODEC_QUANT* dst) { dst->HL1 = q1->HL1 + q2->HL1; /* HL1 */ dst->LH1 = q1->LH1 + q2->LH1; /* LH1 */ @@ -121,7 +125,7 @@ void progressive_rfx_quant_add(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODE dst->LL3 = q1->LL3 + q2->LL3; /* LL3 */ } -void progressive_rfx_quant_lsub(RFX_COMPONENT_CODEC_QUANT* q, int val) +static void progressive_rfx_quant_lsub(RFX_COMPONENT_CODEC_QUANT* q, int val) { q->HL1 -= val; /* HL1 */ q->LH1 -= val; /* LH1 */ @@ -135,7 +139,9 @@ void progressive_rfx_quant_lsub(RFX_COMPONENT_CODEC_QUANT* q, int val) q->LL3 -= val; /* LL3 */ } -void progressive_rfx_quant_sub(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODEC_QUANT* q2, RFX_COMPONENT_CODEC_QUANT* dst) +static void progressive_rfx_quant_sub(RFX_COMPONENT_CODEC_QUANT* q1, + RFX_COMPONENT_CODEC_QUANT* q2, + RFX_COMPONENT_CODEC_QUANT* dst) { dst->HL1 = q1->HL1 - q2->HL1; /* HL1 */ dst->LH1 = q1->LH1 - q2->LH1; /* LH1 */ @@ -149,7 +155,8 @@ void progressive_rfx_quant_sub(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODE dst->LL3 = q1->LL3 - q2->LL3; /* LL3 */ } -BOOL progressive_rfx_quant_lcmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q, int val) +static BOOL progressive_rfx_quant_lcmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q, + int val) { if (q->HL1 > val) return FALSE; /* HL1 */ if (q->LH1 > val) return FALSE; /* LH1 */ @@ -164,7 +171,8 @@ BOOL progressive_rfx_quant_lcmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q, int val return TRUE; } -BOOL progressive_rfx_quant_cmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODEC_QUANT* q2) +static BOOL progressive_rfx_quant_cmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q1, + RFX_COMPONENT_CODEC_QUANT* q2) { if (q1->HL1 > q2->HL1) return FALSE; /* HL1 */ if (q1->LH1 > q2->LH1) return FALSE; /* LH1 */ @@ -179,7 +187,8 @@ BOOL progressive_rfx_quant_cmp_less_equal(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COM return TRUE; } -BOOL progressive_rfx_quant_lcmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q, int val) +static BOOL progressive_rfx_quant_lcmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q, + int val) { if (q->HL1 < val) return FALSE; /* HL1 */ if (q->LH1 < val) return FALSE; /* LH1 */ @@ -194,7 +203,8 @@ BOOL progressive_rfx_quant_lcmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q, int return TRUE; } -BOOL progressive_rfx_quant_cmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODEC_QUANT* q2) +static BOOL progressive_rfx_quant_cmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q1, + RFX_COMPONENT_CODEC_QUANT* q2) { if (q1->HL1 < q2->HL1) return FALSE; /* HL1 */ if (q1->LH1 < q2->LH1) return FALSE; /* LH1 */ @@ -209,7 +219,8 @@ BOOL progressive_rfx_quant_cmp_greater_equal(RFX_COMPONENT_CODEC_QUANT* q1, RFX_ return TRUE; } -BOOL progressive_rfx_quant_cmp_equal(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONENT_CODEC_QUANT* q2) +static BOOL progressive_rfx_quant_cmp_equal(RFX_COMPONENT_CODEC_QUANT* q1, + RFX_COMPONENT_CODEC_QUANT* q2) { if (q1->HL1 != q2->HL1) return FALSE; /* HL1 */ if (q1->LH1 != q2->LH1) return FALSE; /* LH1 */ @@ -224,13 +235,15 @@ BOOL progressive_rfx_quant_cmp_equal(RFX_COMPONENT_CODEC_QUANT* q1, RFX_COMPONEN return TRUE; } -void progressive_rfx_quant_print(RFX_COMPONENT_CODEC_QUANT* q, const char* name) +static void progressive_rfx_quant_print(RFX_COMPONENT_CODEC_QUANT* q, + const char* name) { fprintf(stderr, "%s: HL1: %d LH1: %d HH1: %d HL2: %d LH2: %d HH2: %d HL3: %d LH3: %d HH3: %d LL3: %d\n", name, q->HL1, q->LH1, q->HH1, q->HL2, q->LH2, q->HH2, q->HL3, q->LH3, q->HH3, q->LL3); } -int progressive_set_surface_data(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId, void* pData) +static int progressive_set_surface_data(PROGRESSIVE_CONTEXT* progressive, + UINT16 surfaceId, void* pData) { ULONG_PTR key; @@ -244,7 +257,8 @@ int progressive_set_surface_data(PROGRESSIVE_CONTEXT* progressive, UINT16 surfac return 1; } -void* progressive_get_surface_data(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId) +static void* progressive_get_surface_data(PROGRESSIVE_CONTEXT* progressive, + UINT16 surfaceId) { ULONG_PTR key; void* pData = NULL; @@ -256,11 +270,13 @@ void* progressive_get_surface_data(PROGRESSIVE_CONTEXT* progressive, UINT16 surf return pData; } -PROGRESSIVE_SURFACE_CONTEXT* progressive_surface_context_new(UINT16 surfaceId, UINT32 width, UINT32 height) +static PROGRESSIVE_SURFACE_CONTEXT* progressive_surface_context_new( + UINT16 surfaceId, UINT32 width, UINT32 height) { PROGRESSIVE_SURFACE_CONTEXT* surface; - surface = (PROGRESSIVE_SURFACE_CONTEXT*) calloc(1, sizeof(PROGRESSIVE_SURFACE_CONTEXT)); + surface = (PROGRESSIVE_SURFACE_CONTEXT*) calloc( + 1, sizeof(PROGRESSIVE_SURFACE_CONTEXT)); if (!surface) return NULL; @@ -272,7 +288,8 @@ PROGRESSIVE_SURFACE_CONTEXT* progressive_surface_context_new(UINT16 surfaceId, U surface->gridHeight = (height + (64 - height % 64)) / 64; surface->gridSize = surface->gridWidth * surface->gridHeight; - surface->tiles = (RFX_PROGRESSIVE_TILE*) calloc(surface->gridSize, sizeof(RFX_PROGRESSIVE_TILE)); + surface->tiles = (RFX_PROGRESSIVE_TILE*) calloc( + surface->gridSize, sizeof(RFX_PROGRESSIVE_TILE)); if (!surface->tiles) { @@ -283,7 +300,7 @@ PROGRESSIVE_SURFACE_CONTEXT* progressive_surface_context_new(UINT16 surfaceId, U return surface; } -void progressive_surface_context_free(PROGRESSIVE_SURFACE_CONTEXT* surface) +static void progressive_surface_context_free(PROGRESSIVE_SURFACE_CONTEXT* surface) { UINT32 index; RFX_PROGRESSIVE_TILE* tile; @@ -306,11 +323,13 @@ void progressive_surface_context_free(PROGRESSIVE_SURFACE_CONTEXT* surface) free(surface); } -int progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId, UINT32 width, UINT32 height) +int progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, + UINT16 surfaceId, UINT32 width, UINT32 height) { PROGRESSIVE_SURFACE_CONTEXT* surface; - surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data(progressive, surfaceId); + surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data( + progressive, surfaceId); if (!surface) { @@ -329,7 +348,8 @@ int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 { PROGRESSIVE_SURFACE_CONTEXT* surface; - surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data(progressive, surfaceId); + surface = (PROGRESSIVE_SURFACE_CONTEXT*) progressive_get_surface_data( + progressive, surfaceId); if (surface) { @@ -358,8 +378,9 @@ int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 * LL3 4015 9x9 81 */ -static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBand, int nHighStep, - INT16* pDstBand, int nDstStep, int nLowCount, int nHighCount, int nDstCount) +static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBand, + int nHighStep, INT16* pDstBand, int nDstStep, + int nLowCount, int nHighCount, int nDstCount) { int i, j; INT16 L0; @@ -443,8 +464,9 @@ static void progressive_rfx_idwt_x(INT16* pLowBand, int nLowStep, INT16* pHighBa } } -static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, INT16* pHighBand, int nHighStep, - INT16* pDstBand, int nDstStep, int nLowCount, int nHighCount, int nDstCount) +static void progressive_rfx_idwt_y(INT16* pLowBand, int nLowStep, INT16* pHighBand, + int nHighStep, INT16* pDstBand, int nDstStep, + int nLowCount, int nHighCount, int nDstCount) { int i, j; INT16 L0; @@ -650,7 +672,8 @@ static void progressive_rfx_dwt_2d_decode_block(INT16* buffer, INT16* temp, int progressive_rfx_idwt_y(pLowBand[2], nLowStep[2], pHighBand[2], nHighStep[2], pDstBand[2], nDstStep[2], nLowCount[2], nHighCount[2], nDstCount[2]); } -void progressive_rfx_dwt_2d_decode(INT16* buffer, INT16* temp, INT16* current, INT16* sign, BOOL diff) +static void progressive_rfx_dwt_2d_decode(INT16* buffer, INT16* temp, + INT16* current, INT16* sign, BOOL diff) { const primitives_t* prims = primitives_get(); @@ -664,7 +687,8 @@ void progressive_rfx_dwt_2d_decode(INT16* buffer, INT16* temp, INT16* current, I progressive_rfx_dwt_2d_decode_block(&buffer[0], temp, 1); } -void progressive_rfx_decode_block(const primitives_t* prims, INT16* buffer, int length, UINT32 shift) +static void progressive_rfx_decode_block(const primitives_t* prims, INT16* buffer, + int length, UINT32 shift) { if (!shift) return; @@ -672,8 +696,11 @@ void progressive_rfx_decode_block(const primitives_t* prims, INT16* buffer, int prims->lShiftC_16s(buffer, shift, buffer, length); } -int progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* progressive, RFX_COMPONENT_CODEC_QUANT* shift, - const BYTE* data, int length, INT16* buffer, INT16* current, INT16* sign, BOOL diff) +static int progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* progressive, + RFX_COMPONENT_CODEC_QUANT* shift, + const BYTE* data, int length, + INT16* buffer, INT16* current, + INT16* sign, BOOL diff) { int status; INT16* temp; @@ -708,7 +735,8 @@ int progressive_rfx_decode_component(PROGRESSIVE_CONTEXT* progressive, RFX_COMPO return 1; } -int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, RFX_PROGRESSIVE_TILE* tile) +static int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, + RFX_PROGRESSIVE_TILE* tile) { BOOL diff; BYTE* pBuffer; @@ -735,7 +763,9 @@ int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, RFX_PROG WLog_DBG(TAG, "ProgressiveTile%s: quantIdx Y: %d Cb: %d Cr: %d xIdx: %d yIdx: %d flags: 0x%02X quality: %d yLen: %d cbLen: %d crLen: %d tailLen: %d", (tile->blockType == PROGRESSIVE_WBT_TILE_FIRST) ? "First" : "Simple", - tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, tile->xIdx, tile->yIdx, tile->flags, tile->quality, tile->yLen, tile->cbLen, tile->crLen, tile->tailLen); + tile->quantIdxY, tile->quantIdxCb, tile->quantIdxCr, + tile->xIdx, tile->yIdx, tile->flags, tile->quality, tile->yLen, + tile->cbLen, tile->crLen, tile->tailLen); region = &(progressive->region); @@ -819,14 +849,21 @@ int progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* progressive, RFX_PROG pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* Cb/G buffer */ pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* Cr/B buffer */ - progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, pSrcDst[0], pCurrent[0], pSign[0], diff); /* Y */ - progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen, pSrcDst[1], pCurrent[1], pSign[1], diff); /* Cb */ - progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen, pSrcDst[2], pCurrent[2], pSign[2], diff); /* Cr */ + progressive_rfx_decode_component(progressive, &shiftY, tile->yData, tile->yLen, + pSrcDst[0], pCurrent[0], pSign[0], diff); /* Y */ + progressive_rfx_decode_component(progressive, &shiftCb, tile->cbData, tile->cbLen, + pSrcDst[1], pCurrent[1], pSign[1], diff); /* Cb */ + progressive_rfx_decode_component(progressive, &shiftCr, tile->crData, tile->crLen, + pSrcDst[2], pCurrent[2], pSign[2], diff); /* Cr */ if (!progressive->invert) - prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, tile->data, 64 * 4, &roi_64x64); + prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); else - prims->yCbCrToBGR_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, tile->data, 64 * 4, &roi_64x64); + prims->yCbCrToBGR_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); BufferPool_Return(progressive->bufferPool, pBuffer); @@ -847,7 +884,8 @@ struct _RFX_PROGRESSIVE_UPGRADE_STATE }; typedef struct _RFX_PROGRESSIVE_UPGRADE_STATE RFX_PROGRESSIVE_UPGRADE_STATE; -INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, UINT32 numBits) +static INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, + UINT32 numBits) { int k; UINT32 bit; @@ -941,7 +979,7 @@ INT16 progressive_rfx_srl_read(RFX_PROGRESSIVE_UPGRADE_STATE* state, UINT32 numB return sign ? -1 * mag : mag; } -int progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* state) +static int progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* state) { int pad; wBitStream* srl; @@ -968,8 +1006,9 @@ int progressive_rfx_upgrade_state_finish(RFX_PROGRESSIVE_UPGRADE_STATE* state) return 1; } -int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, INT16* buffer, - INT16* sign, int length, UINT32 shift, UINT32 bitPos, UINT32 numBits) +static int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, + INT16* buffer, INT16* sign, UINT32 length, + UINT32 shift, UINT32 bitPos, UINT32 numBits) { int index; INT16 input; @@ -1031,13 +1070,19 @@ int progressive_rfx_upgrade_block(RFX_PROGRESSIVE_UPGRADE_STATE* state, INT16* b return 1; } -int progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* progressive, RFX_COMPONENT_CODEC_QUANT* shift, - RFX_COMPONENT_CODEC_QUANT* bitPos, RFX_COMPONENT_CODEC_QUANT* numBits, INT16* buffer, - INT16* current, INT16* sign, const BYTE* srlData, int srlLen, const BYTE* rawData, int rawLen) +static int progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* progressive, + RFX_COMPONENT_CODEC_QUANT* shift, + RFX_COMPONENT_CODEC_QUANT* bitPos, + RFX_COMPONENT_CODEC_QUANT* numBits, + INT16* buffer, + INT16* current, INT16* sign, + const BYTE* srlData, + UINT32 srlLen, const BYTE* rawData, + UINT32 rawLen) { INT16* temp; - int aRawLen; - int aSrlLen; + UINT32 aRawLen; + UINT32 aSrlLen; wBitStream s_srl; wBitStream s_raw; RFX_PROGRESSIVE_UPGRADE_STATE state; @@ -1108,7 +1153,8 @@ int progressive_rfx_upgrade_component(PROGRESSIVE_CONTEXT* progressive, RFX_COMP return 1; } -int progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* progressive, RFX_PROGRESSIVE_TILE* tile) +static int progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* progressive, + RFX_PROGRESSIVE_TILE* tile) { int status; BYTE* pBuffer; @@ -1241,19 +1287,25 @@ int progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* progressive, RFX_PR return -1; if (!progressive->invert) - prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, tile->data, 64 * 4, &roi_64x64); + prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); else - prims->yCbCrToBGR_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, tile->data, 64 * 4, &roi_64x64); + prims->yCbCrToBGR_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, + tile->data, PIXEL_FORMAT_BGRX32, + 64 * 4, &roi_64x64); BufferPool_Return(progressive->bufferPool, pBuffer); return 1; } -int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, BYTE* blocks, UINT32 blocksLen, PROGRESSIVE_SURFACE_CONTEXT* surface) +static int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, + const BYTE* blocks, UINT32 blocksLen, + const PROGRESSIVE_SURFACE_CONTEXT* surface) { int status = -1; - BYTE* block; + const BYTE* block; UINT16 xIdx; UINT16 yIdx; UINT16 zIdx; @@ -1534,12 +1586,16 @@ int progressive_process_tiles(PROGRESSIVE_CONTEXT* progressive, BYTE* blocks, UI return (int) offset; } -int progressive_decompress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize, - BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, UINT16 surfaceId) +UINT progressive_decompress(PROGRESSIVE_CONTEXT* progressive, + const BYTE* pSrcData, UINT32 SrcSize, + BYTE* pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT16 surfaceId) { - int status; - BYTE* block; - BYTE* blocks; + UINT status; + const BYTE* block; + const BYTE* blocks; + UINT16 i, j; UINT16 index; UINT16 boxLeft; UINT16 boxTop; @@ -1556,6 +1612,7 @@ int progressive_decompress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UIN UINT32 count = 0; UINT32 offset = 0; RFX_RECT* rect = NULL; + REGION16 clippingRects, updateRegion; PROGRESSIVE_BLOCK_SYNC sync; PROGRESSIVE_BLOCK_REGION* region; PROGRESSIVE_BLOCK_CONTEXT context; @@ -1872,10 +1929,64 @@ int progressive_decompress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UIN if (offset != blocksLen) return -1041; + region = &(progressive->region); + + region16_init(&clippingRects); + + for (i = 0; i < region->numRects; i++) + { + RECTANGLE_16 clippingRect; + RFX_RECT* rect = &(region->rects[i]); + + clippingRect.left = nXDst + rect->x; + clippingRect.top = nYDst + rect->y; + clippingRect.right = clippingRect.left + rect->width; + clippingRect.bottom = clippingRect.top + rect->height; + + region16_union_rect(&clippingRects, &clippingRects, &clippingRect); + } + + for (i = 0; i < region->numTiles; i++) + { + UINT32 nbUpdateRects; + const RECTANGLE_16* updateRects; + RECTANGLE_16 updateRect; + RFX_PROGRESSIVE_TILE* tile = region->tiles[i]; + + updateRect.left = nXDst + tile->x; + updateRect.top = nYDst + tile->y; + updateRect.right = updateRect.left + 64; + updateRect.bottom = updateRect.top + 64; + + region16_init(&updateRegion); + region16_intersect_rect(&updateRegion, &clippingRects, &updateRect); + updateRects = region16_rects(&updateRegion, &nbUpdateRects); + + for (j = 0; j < nbUpdateRects; j++) + { + UINT32 nXSrc; + UINT32 nYSrc; + nWidth = updateRects[j].right - updateRects[j].left; + nHeight = updateRects[j].bottom - updateRects[j].top; + + nXSrc = updateRects[j].left - (nXDst + tile->x); + nYSrc = updateRects[j].top - (nYDst + tile->y); + + freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, + nWidth, nHeight, tile->data, PIXEL_FORMAT_XRGB32, + 64 * 4, nXSrc, nYSrc, NULL); + } + + region16_uninit(&updateRegion); + } + + region16_uninit(&clippingRects); + return 1; } -int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize) +int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, + UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize) { return 1; } diff --git a/libfreerdp/codec/region.c b/libfreerdp/codec/region.c index b3f32af76..8e9b6c5ac 100644 --- a/libfreerdp/codec/region.c +++ b/libfreerdp/codec/region.c @@ -89,7 +89,7 @@ int region16_n_rects(const REGION16 *region) return region->data->nbRects; } -const RECTANGLE_16 *region16_rects(const REGION16 *region, int *nbRects) +const RECTANGLE_16 *region16_rects(const REGION16 *region, UINT32 *nbRects) { REGION16_DATA *data; @@ -232,7 +232,7 @@ BOOL region16_copy(REGION16 *dst, const REGION16 *src) void region16_print(const REGION16 *region) { const RECTANGLE_16 *rects; - int nbRects, i; + UINT32 nbRects, i; int currentBandY = -1; rects = region16_rects(region, &nbRects); @@ -250,11 +250,11 @@ void region16_print(const REGION16 *region) } } -void region16_copy_band_with_union(RECTANGLE_16 *dst, +static void region16_copy_band_with_union(RECTANGLE_16 *dst, const RECTANGLE_16 *src, const RECTANGLE_16 *end, UINT16 newTop, UINT16 newBottom, const RECTANGLE_16 *unionRect, - int *dstCounter, + UINT32 *dstCounter, const RECTANGLE_16 **srcPtr, RECTANGLE_16 **dstPtr) { UINT16 refY = src->top; @@ -486,7 +486,7 @@ BOOL region16_union_rect(REGION16 *dst, const REGION16 *src, const RECTANGLE_16 const RECTANGLE_16 *currentBand, *endSrcRect, *nextBand; REGION16_DATA* newItems = NULL; RECTANGLE_16* dstRect = NULL; - int usedRects, srcNbRects; + UINT32 usedRects, srcNbRects; UINT16 topInterBand; assert(src); @@ -552,7 +552,7 @@ BOOL region16_union_rect(REGION16 *dst, const REGION16 *src, const RECTANGLE_16 +----+ ================= - band of srcRect + band of srcRect ================= +----+ | | rect (case 2) @@ -569,17 +569,17 @@ BOOL region16_union_rect(REGION16 *dst, const REGION16 *src, const RECTANGLE_16 { /* rect overlaps the band: - | | | | - ====^=================| |==| |=========================== band - | top split | | | | - v | 1 | | 2 | - ^ | | | | +----+ +----+ - | merge zone | | | | | | | 4 | - v +----+ | | | | +----+ - ^ | | | 3 | - | bottom split | | | | - ====v=========================| |==| |=================== - | | | | + | | | | + ====^=================| |==| |=========================== band + | top split | | | | + v | 1 | | 2 | + ^ | | | | +----+ +----+ + | merge zone | | | | | | | 4 | + v +----+ | | | | +----+ + ^ | | | 3 | + | bottom split | | | | + ====v=========================| |==| |=================== + | | | | possible cases: 1) no top split, merge zone then a bottom split. The band will be splitted @@ -691,7 +691,7 @@ BOOL region16_union_rect(REGION16 *dst, const REGION16 *src, const RECTANGLE_16 BOOL region16_intersects_rect(const REGION16 *src, const RECTANGLE_16 *arg2) { const RECTANGLE_16 *rect, *endPtr, *srcExtents; - int nbRects; + UINT32 nbRects; assert(src); assert(src->data); @@ -725,7 +725,7 @@ BOOL region16_intersect_rect(REGION16 *dst, const REGION16 *src, const RECTANGLE REGION16_DATA *newItems; const RECTANGLE_16 *srcPtr, *endPtr, *srcExtents; RECTANGLE_16 *dstPtr; - int nbRects, usedRects; + UINT32 nbRects, usedRects; RECTANGLE_16 common, newExtents; assert(src); @@ -775,8 +775,8 @@ BOOL region16_intersect_rect(REGION16 *dst, const REGION16 *src, const RECTANGLE if (rectangle_is_empty(&newExtents)) { - /* Check if the existing newExtents is empty. If it is empty, use - * new common directly. We do not need to check common rectangle + /* Check if the existing newExtents is empty. If it is empty, use + * new common directly. We do not need to check common rectangle * because the rectangles_intersection() ensures that it is not empty. */ newExtents = common; diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 6a108b22d..c411be8f7 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "rfx_constants.h" #include "rfx_types.h" @@ -59,7 +60,7 @@ #endif #define RFX_KEY "Software\\"FREERDP_VENDOR_STRING"\\" \ - FREERDP_PRODUCT_STRING"\\RemoteFX" + FREERDP_PRODUCT_STRING"\\RemoteFX" /** * The quantization values control the compression rate and quality. The value @@ -81,22 +82,29 @@ static const UINT32 rfx_default_quantization_values[] = static void rfx_profiler_create(RFX_CONTEXT* context) { PROFILER_CREATE(context->priv->prof_rfx_decode_rgb, "rfx_decode_rgb"); - PROFILER_CREATE(context->priv->prof_rfx_decode_component, "rfx_decode_component"); + PROFILER_CREATE(context->priv->prof_rfx_decode_component, + "rfx_decode_component"); PROFILER_CREATE(context->priv->prof_rfx_rlgr_decode, "rfx_rlgr_decode"); - PROFILER_CREATE(context->priv->prof_rfx_differential_decode, "rfx_differential_decode"); - PROFILER_CREATE(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode"); + PROFILER_CREATE(context->priv->prof_rfx_differential_decode, + "rfx_differential_decode"); + PROFILER_CREATE(context->priv->prof_rfx_quantization_decode, + "rfx_quantization_decode"); PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode"); PROFILER_CREATE(context->priv->prof_rfx_ycbcr_to_rgb, "prims->yCbCrToRGB"); - PROFILER_CREATE(context->priv->prof_rfx_decode_format_rgb, "rfx_decode_format_rgb"); - + PROFILER_CREATE(context->priv->prof_rfx_decode_format_rgb, + "rfx_decode_format_rgb"); PROFILER_CREATE(context->priv->prof_rfx_encode_rgb, "rfx_encode_rgb"); - PROFILER_CREATE(context->priv->prof_rfx_encode_component, "rfx_encode_component"); + PROFILER_CREATE(context->priv->prof_rfx_encode_component, + "rfx_encode_component"); PROFILER_CREATE(context->priv->prof_rfx_rlgr_encode, "rfx_rlgr_encode"); - PROFILER_CREATE(context->priv->prof_rfx_differential_encode, "rfx_differential_encode"); - PROFILER_CREATE(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode"); + PROFILER_CREATE(context->priv->prof_rfx_differential_encode, + "rfx_differential_encode"); + PROFILER_CREATE(context->priv->prof_rfx_quantization_encode, + "rfx_quantization_encode"); PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode"); PROFILER_CREATE(context->priv->prof_rfx_rgb_to_ycbcr, "prims->RGBToYCbCr"); - PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb, "rfx_encode_format_rgb"); + PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb, + "rfx_encode_format_rgb"); } static void rfx_profiler_free(RFX_CONTEXT* context) @@ -109,7 +117,6 @@ static void rfx_profiler_free(RFX_CONTEXT* context) PROFILER_FREE(context->priv->prof_rfx_dwt_2d_decode); PROFILER_FREE(context->priv->prof_rfx_ycbcr_to_rgb); PROFILER_FREE(context->priv->prof_rfx_decode_format_rgb); - PROFILER_FREE(context->priv->prof_rfx_encode_rgb); PROFILER_FREE(context->priv->prof_rfx_encode_component); PROFILER_FREE(context->priv->prof_rfx_rlgr_encode); @@ -123,7 +130,6 @@ static void rfx_profiler_free(RFX_CONTEXT* context) static void rfx_profiler_print(RFX_CONTEXT* context) { PROFILER_PRINT_HEADER; - PROFILER_PRINT(context->priv->prof_rfx_decode_rgb); PROFILER_PRINT(context->priv->prof_rfx_decode_component); PROFILER_PRINT(context->priv->prof_rfx_rlgr_decode); @@ -132,7 +138,6 @@ static void rfx_profiler_print(RFX_CONTEXT* context) PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_decode); PROFILER_PRINT(context->priv->prof_rfx_ycbcr_to_rgb); PROFILER_PRINT(context->priv->prof_rfx_decode_format_rgb); - PROFILER_PRINT(context->priv->prof_rfx_encode_rgb); PROFILER_PRINT(context->priv->prof_rfx_encode_component); PROFILER_PRINT(context->priv->prof_rfx_rlgr_encode); @@ -141,7 +146,6 @@ static void rfx_profiler_print(RFX_CONTEXT* context) PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_encode); PROFILER_PRINT(context->priv->prof_rfx_rgb_to_ycbcr); PROFILER_PRINT(context->priv->prof_rfx_encode_format_rgb); - PROFILER_PRINT_FOOTER; } @@ -167,13 +171,13 @@ RFX_TILE* rfx_decoder_tile_new() if (!(tile = (RFX_TILE*) calloc(1, sizeof(RFX_TILE)))) return NULL; - if (!(tile->data = (BYTE*) malloc(4 * 64 * 64))) { + if (!(tile->data = (BYTE*) malloc(4 * 64 * 64))) + { free(tile); return NULL; } tile->allocated = TRUE; - return tile; } @@ -183,13 +187,14 @@ void rfx_decoder_tile_free(RFX_TILE* tile) { if (tile->allocated) free(tile->data); + free(tile); } } RFX_TILE* rfx_encoder_tile_new() { - return (RFX_TILE *)calloc(1, sizeof(RFX_TILE)); + return (RFX_TILE*)calloc(1, sizeof(RFX_TILE)); } void rfx_encoder_tile_free(RFX_TILE* tile) @@ -206,30 +211,30 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) DWORD dwValue; SYSTEM_INFO sysinfo; RFX_CONTEXT* context; - wObject *pool; - RFX_CONTEXT_PRIV *priv; - + wObject* pool; + RFX_CONTEXT_PRIV* priv; context = (RFX_CONTEXT*)calloc(1, sizeof(RFX_CONTEXT)); + if (!context) return NULL; context->encoder = encoder; - context->priv = priv = (RFX_CONTEXT_PRIV *)calloc(1, sizeof(RFX_CONTEXT_PRIV) ); + context->priv = priv = (RFX_CONTEXT_PRIV*)calloc(1, sizeof(RFX_CONTEXT_PRIV)); + if (!priv) goto error_priv; WLog_Init(); - priv->log = WLog_Get("com.freerdp.codec.rfx"); WLog_OpenAppender(priv->log); - #ifdef WITH_DEBUG_RFX WLog_SetLogLevel(priv->log, WLOG_DEBUG); #endif - priv->TilePool = ObjectPool_New(TRUE); + if (!priv->TilePool) goto error_tilePool; + pool = ObjectPool_Object(priv->TilePool); pool->fnObjectInit = (OBJECT_INIT_FN) rfx_tile_init; @@ -257,8 +262,8 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) * * We then multiply by 3 to use a single, partioned buffer for all 3 channels. */ - priv->BufferPool = BufferPool_New(TRUE, (8192 + 32) * 3, 16); + if (!priv->BufferPool) goto error_BufferPool; @@ -266,37 +271,36 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) { BOOL isVistaOrLater; OSVERSIONINFOA verinfo; - ZeroMemory(&verinfo, sizeof(OSVERSIONINFOA)); verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); - GetVersionExA(&verinfo); - isVistaOrLater = ((verinfo.dwMajorVersion >= 6) && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE; - + isVistaOrLater = ((verinfo.dwMajorVersion >= 6) + && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE; priv->UseThreads = isVistaOrLater; } #else priv->UseThreads = TRUE; #endif - GetNativeSystemInfo(&sysinfo); - priv->MinThreadCount = sysinfo.dwNumberOfProcessors; priv->MaxThreadCount = 0; - - status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, RFX_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey); + status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, RFX_KEY, 0, + KEY_READ | KEY_WOW64_64KEY, &hKey); if (status == ERROR_SUCCESS) { dwSize = sizeof(dwValue); - if (RegQueryValueEx(hKey, _T("UseThreads"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) + if (RegQueryValueEx(hKey, _T("UseThreads"), NULL, &dwType, (BYTE*) &dwValue, + &dwSize) == ERROR_SUCCESS) priv->UseThreads = dwValue ? 1 : 0; - if (RegQueryValueEx(hKey, _T("MinThreadCount"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) + if (RegQueryValueEx(hKey, _T("MinThreadCount"), NULL, &dwType, (BYTE*) &dwValue, + &dwSize) == ERROR_SUCCESS) priv->MinThreadCount = dwValue; - if (RegQueryValueEx(hKey, _T("MaxThreadCount"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) + if (RegQueryValueEx(hKey, _T("MaxThreadCount"), NULL, &dwType, (BYTE*) &dwValue, + &dwSize) == ERROR_SUCCESS) priv->MaxThreadCount = dwValue; RegCloseKey(hKey); @@ -308,10 +312,11 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) /* from multiple threads. This call will initialize all function pointers correctly */ /* before any decoding threads are started */ primitives_get(); - priv->ThreadPool = CreateThreadpool(NULL); + if (!priv->ThreadPool) goto error_threadPool; + InitializeThreadpoolEnvironment(&priv->ThreadPoolEnv); SetThreadpoolCallbackPool(&priv->ThreadPoolEnv, priv->ThreadPool); @@ -324,22 +329,17 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) } /* initialize the default pixel format */ - rfx_context_set_pixel_format(context, RDP_PIXEL_FORMAT_B8G8R8A8); - + rfx_context_set_pixel_format(context, PIXEL_FORMAT_BGRX32); /* create profilers for default decoding routines */ rfx_profiler_create(context); - /* set up default routines */ context->quantization_decode = rfx_quantization_decode; context->quantization_encode = rfx_quantization_encode; context->dwt_2d_decode = rfx_dwt_2d_decode; context->dwt_2d_encode = rfx_dwt_2d_encode; - RFX_INIT_SIMD(context); - context->state = RFX_STATE_SEND_HEADERS; return context; - error_threadPool_minimum: CloseThreadpool(priv->ThreadPool); error_threadPool: @@ -355,7 +355,7 @@ error_priv: void rfx_context_free(RFX_CONTEXT* context) { - RFX_CONTEXT_PRIV *priv; + RFX_CONTEXT_PRIV* priv; if (!context) return; @@ -364,12 +364,9 @@ void rfx_context_free(RFX_CONTEXT* context) assert(NULL != context->priv); assert(NULL != context->priv->TilePool); assert(NULL != context->priv->BufferPool); - priv = context->priv; free(context->quants); - ObjectPool_Free(priv->TilePool); - rfx_profiler_print(context); rfx_profiler_free(context); @@ -377,49 +374,23 @@ void rfx_context_free(RFX_CONTEXT* context) { CloseThreadpool(context->priv->ThreadPool); DestroyThreadpoolEnvironment(&context->priv->ThreadPoolEnv); - free(priv->workObjects); free(priv->tileWorkParams); - #ifdef WITH_PROFILER - WLog_VRB(TAG, "WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!"); + WLog_VRB(TAG, + "WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!"); #endif } BufferPool_Free(context->priv->BufferPool); - free(context->priv); free(context); } -void rfx_context_set_pixel_format(RFX_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format) +void rfx_context_set_pixel_format(RFX_CONTEXT* context, UINT32 pixel_format) { context->pixel_format = pixel_format; - - switch (pixel_format) - { - case RDP_PIXEL_FORMAT_B8G8R8A8: - case RDP_PIXEL_FORMAT_R8G8B8A8: - context->bits_per_pixel = 32; - break; - case RDP_PIXEL_FORMAT_B8G8R8: - case RDP_PIXEL_FORMAT_R8G8B8: - context->bits_per_pixel = 24; - break; - case RDP_PIXEL_FORMAT_B5G6R5_LE: - case RDP_PIXEL_FORMAT_R5G6B5_LE: - context->bits_per_pixel = 16; - break; - case RDP_PIXEL_FORMAT_P4_PLANER: - context->bits_per_pixel = 4; - break; - case RDP_PIXEL_FORMAT_P8: - context->bits_per_pixel = 8; - break; - default: - context->bits_per_pixel = 0; - break; - } + context->bits_per_pixel = GetBitsPerPixel(pixel_format); } BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, UINT32 height) @@ -431,14 +402,12 @@ BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, UINT32 height) context->height = height; context->state = RFX_STATE_SEND_HEADERS; context->frameIdx = 0; - return TRUE; } static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s) { UINT32 magic; - context->decodedHeaderBlocks &= ~_RFX_DECODED_SYNC; /* RFX_SYNC */ @@ -447,6 +416,7 @@ static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s) WLog_ERR(TAG, "RfxSync packet too small"); return FALSE; } + Stream_Read_UINT32(s, magic); /* magic (4 bytes), 0xCACCACCA */ if (magic != WF_MAGIC) @@ -455,7 +425,8 @@ static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s) return FALSE; } - Stream_Read_UINT16(s, context->version); /* version (2 bytes), WF_VERSION_1_0 (0x0100) */ + Stream_Read_UINT16(s, + context->version); /* version (2 bytes), WF_VERSION_1_0 (0x0100) */ if (context->version != WF_VERSION_1_0) { @@ -464,7 +435,6 @@ static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s) } WLog_Print(context->priv->log, WLOG_DEBUG, "version 0x%X", context->version); - context->decodedHeaderBlocks |= _RFX_DECODED_SYNC; return TRUE; } @@ -472,7 +442,6 @@ static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s) static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, wStream* s) { BYTE numCodecs; - context->decodedHeaderBlocks &= ~_RFX_DECODED_VERSIONS; if (Stream_GetRemainingLength(s) < 4) @@ -482,8 +451,10 @@ static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, wStream* s) } Stream_Read_UINT8(s, numCodecs); /* numCodecs (1 byte), must be set to 0x01 */ - Stream_Read_UINT8(s, context->codec_id); /* codecId (1 byte), must be set to 0x01 */ - Stream_Read_UINT16(s, context->codec_version); /* version (2 bytes), must be set to WF_VERSION_1_0 (0x0100) */ + Stream_Read_UINT8(s, + context->codec_id); /* codecId (1 byte), must be set to 0x01 */ + Stream_Read_UINT16(s, + context->codec_version); /* version (2 bytes), must be set to WF_VERSION_1_0 (0x0100) */ if (numCodecs != 1) { @@ -499,12 +470,13 @@ static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, wStream* s) if (context->codec_version != WF_VERSION_1_0) { - WLog_ERR(TAG, "%s: invalid codec version (0x%04X)", __FUNCTION__, context->codec_version); + WLog_ERR(TAG, "%s: invalid codec version (0x%04X)", __FUNCTION__, + context->codec_version); return FALSE; } - WLog_Print(context->priv->log, WLOG_DEBUG, "id %d version 0x%X.", context->codec_id, context->codec_version); - + WLog_Print(context->priv->log, WLOG_DEBUG, "id %d version 0x%X.", + context->codec_id, context->codec_version); context->decodedHeaderBlocks |= _RFX_DECODED_VERSIONS; return TRUE; } @@ -513,7 +485,6 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s) { BYTE channelId; BYTE numChannels; - context->decodedHeaderBlocks &= ~_RFX_DECODED_CHANNELS; if (Stream_GetRemainingLength(s) < 1) @@ -522,7 +493,8 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s) return FALSE; } - Stream_Read_UINT8(s, numChannels); /* numChannels (1 byte), must bet set to 0x01 */ + Stream_Read_UINT8(s, + numChannels); /* numChannels (1 byte), must bet set to 0x01 */ /* In RDVH sessions, numChannels will represent the number of virtual monitors * configured and does not always be set to 0x01 as [MS-RDPRFX] said. @@ -533,14 +505,16 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s) return FALSE; } - if (Stream_GetRemainingLength(s) < (size_t) (numChannels * 5)) + if (Stream_GetRemainingLength(s) < (size_t)(numChannels * 5)) { - WLog_ERR(TAG, "RfxMessageChannels packet too small for numChannels=%d", numChannels); + WLog_ERR(TAG, "RfxMessageChannels packet too small for numChannels=%d", + numChannels); return FALSE; } /* RFX_CHANNELT */ Stream_Read_UINT8(s, channelId); /* channelId (1 byte), must be set to 0x00 */ + if (channelId != 0x00) { WLog_ERR(TAG, "channelId:0x%02X, expected:0x00", channelId); @@ -552,16 +526,15 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s) if (!context->width || !context->height) { - WLog_ERR(TAG, "%s: invalid channel with/height: %ux%u", __FUNCTION__, context->width, context->height); + WLog_ERR(TAG, "%s: invalid channel with/height: %ux%u", __FUNCTION__, + context->width, context->height); return FALSE; } /* Now, only the first monitor can be used, therefore the other channels will be ignored. */ Stream_Seek(s, 5 * (numChannels - 1)); - WLog_Print(context->priv->log, WLOG_DEBUG, "numChannels %d id %d, %dx%d.", - numChannels, channelId, context->width, context->height); - + numChannels, channelId, context->width, context->height); context->decodedHeaderBlocks |= _RFX_DECODED_CHANNELS; return TRUE; } @@ -571,7 +544,6 @@ static BOOL rfx_process_message_context(RFX_CONTEXT* context, wStream* s) BYTE ctxId; UINT16 tileSize; UINT16 properties; - context->decodedHeaderBlocks &= ~_RFX_DECODED_CONTEXT; if (Stream_GetRemainingLength(s) < 5) @@ -581,12 +553,12 @@ static BOOL rfx_process_message_context(RFX_CONTEXT* context, wStream* s) } Stream_Read_UINT8(s, ctxId); /* ctxId (1 byte), must be set to 0x00 */ - Stream_Read_UINT16(s, tileSize); /* tileSize (2 bytes), must be set to CT_TILE_64x64 (0x0040) */ + Stream_Read_UINT16(s, + tileSize); /* tileSize (2 bytes), must be set to CT_TILE_64x64 (0x0040) */ Stream_Read_UINT16(s, properties); /* properties (2 bytes) */ - - WLog_Print(context->priv->log, WLOG_DEBUG, "ctxId %d tileSize %d properties 0x%X.", - ctxId, tileSize, properties); - + WLog_Print(context->priv->log, WLOG_DEBUG, + "ctxId %d tileSize %d properties 0x%X.", + ctxId, tileSize, properties); context->properties = properties; context->flags = (properties & 0x0007); @@ -620,7 +592,8 @@ static BOOL rfx_process_message_context(RFX_CONTEXT* context, wStream* s) return TRUE; } -static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType) +static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, + RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType) { UINT32 frameIdx; UINT16 numRegions; @@ -630,6 +603,7 @@ static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* m WLog_ERR(TAG, "%s: message unexpeced", __FUNCTION__); return FALSE; } + *pExpectedBlockType = WBT_REGION; if (Stream_GetRemainingLength(s) < 6) @@ -638,28 +612,30 @@ static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* m return FALSE; } - Stream_Read_UINT32(s, frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */ + Stream_Read_UINT32(s, + frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */ Stream_Read_UINT16(s, numRegions); /* numRegions (2 bytes) */ - - WLog_Print(context->priv->log, WLOG_DEBUG, "RFX_FRAME_BEGIN: frameIdx: %d numRegions: %d", frameIdx, numRegions); - + WLog_Print(context->priv->log, WLOG_DEBUG, + "RFX_FRAME_BEGIN: frameIdx: %d numRegions: %d", frameIdx, numRegions); return TRUE; } -static BOOL rfx_process_message_frame_end(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType) +static BOOL rfx_process_message_frame_end(RFX_CONTEXT* context, + RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType) { if (*pExpectedBlockType != WBT_FRAME_END) { WLog_ERR(TAG, "%s: message unexpeced", __FUNCTION__); return FALSE; } - *pExpectedBlockType = WBT_FRAME_BEGIN; + *pExpectedBlockType = WBT_FRAME_BEGIN; WLog_Print(context->priv->log, WLOG_DEBUG, "RFX_FRAME_END"); return TRUE; } -static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType) +static BOOL rfx_process_message_region(RFX_CONTEXT* context, + RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType) { int i; UINT16 regionType; @@ -670,6 +646,7 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag WLog_ERR(TAG, "%s: message unexpeced", __FUNCTION__); return FALSE; } + *pExpectedBlockType = WBT_EXTENSION; if (Stream_GetRemainingLength(s) < 3) @@ -689,7 +666,6 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag See [MS-RDPRFX] (revision >= 17.0) 2.2.2.3.3 TS_RFX_REGION https://msdn.microsoft.com/en-us/library/ff635233.aspx */ - if (!(message->rects = (RFX_RECT*) malloc(sizeof(RFX_RECT)))) return FALSE; @@ -698,13 +674,13 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag message->rects->y = 0; message->rects->width = context->width; message->rects->height = context->height; - return TRUE; } - if (Stream_GetRemainingLength(s) < (size_t) (8 * message->numRects)) + if (Stream_GetRemainingLength(s) < (size_t)(8 * message->numRects)) { - WLog_ERR(TAG, "%s: packet too small for num_rects=%d", __FUNCTION__, message->numRects); + WLog_ERR(TAG, "%s: packet too small for num_rects=%d", __FUNCTION__, + message->numRects); return FALSE; } @@ -719,10 +695,9 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag Stream_Read_UINT16(s, message->rects[i].y); /* y (2 bytes) */ Stream_Read_UINT16(s, message->rects[i].width); /* width (2 bytes) */ Stream_Read_UINT16(s, message->rects[i].height); /* height (2 bytes) */ - WLog_Print(context->priv->log, WLOG_DEBUG, "rect %d (x,y=%d,%d w,h=%d %d).", i, - message->rects[i].x, message->rects[i].y, - message->rects[i].width, message->rects[i].height); + message->rects[i].x, message->rects[i].y, + message->rects[i].width, message->rects[i].height); } if (Stream_GetRemainingLength(s) < 4) @@ -731,8 +706,10 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag return FALSE; } - Stream_Read_UINT16(s, regionType); /* regionType (2 bytes): MUST be set to CBT_REGION (0xCAC1) */ - Stream_Read_UINT16(s, numTileSets); /* numTilesets (2 bytes): MUST be set to 0x0001. */ + Stream_Read_UINT16(s, + regionType); /* regionType (2 bytes): MUST be set to CBT_REGION (0xCAC1) */ + Stream_Read_UINT16(s, + numTileSets); /* numTilesets (2 bytes): MUST be set to 0x0001. */ if (regionType != CBT_REGION) { @@ -756,13 +733,15 @@ struct _RFX_TILE_PROCESS_WORK_PARAM }; typedef struct _RFX_TILE_PROCESS_WORK_PARAM RFX_TILE_PROCESS_WORK_PARAM; -void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work) +void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE + instance, void* context, PTP_WORK work) { RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*) context; rfx_decode_rgb(param->context, param->tile, param->tile->data, 64 * 4); } -static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s, UINT16* pExpecedBlockType) +static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, + RFX_MESSAGE* message, wStream* s, UINT16* pExpecedBlockType) { BOOL rc; int i, close_cnt; @@ -776,13 +755,14 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa UINT32 tilesDataSize; PTP_WORK* work_objects = NULL; RFX_TILE_PROCESS_WORK_PARAM* params = NULL; - void *pmem; + void* pmem; if (*pExpecedBlockType != WBT_EXTENSION) { WLog_ERR(TAG, "%s: message unexpeced", __FUNCTION__); return FALSE; } + *pExpecedBlockType = WBT_FRAME_END; if (Stream_GetRemainingLength(s) < 14) @@ -791,7 +771,8 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa return FALSE; } - Stream_Read_UINT16(s, subtype); /* subtype (2 bytes) must be set to CBT_TILESET (0xCAC2) */ + Stream_Read_UINT16(s, + subtype); /* subtype (2 bytes) must be set to CBT_TILESET (0xCAC2) */ if (subtype != CBT_TILESET) { @@ -801,7 +782,6 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa Stream_Seek_UINT16(s); /* idx (2 bytes), must be set to 0x0000 */ Stream_Seek_UINT16(s); /* properties (2 bytes) */ - Stream_Read_UINT8(s, context->numQuant); /* numQuant (1 byte) */ Stream_Seek_UINT8(s); /* tileSize (1 byte), must be set to 0x40 */ @@ -821,15 +801,17 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa Stream_Read_UINT32(s, tilesDataSize); /* tilesDataSize (4 bytes) */ - if (!(pmem = realloc((void*) context->quants, context->numQuant * 10 * sizeof(UINT32)))) + if (!(pmem = realloc((void*) context->quants, + context->numQuant * 10 * sizeof(UINT32)))) return FALSE; quants = context->quants = (UINT32*) pmem; /* quantVals */ - if (Stream_GetRemainingLength(s) < (size_t) (context->numQuant * 5)) + if (Stream_GetRemainingLength(s) < (size_t)(context->numQuant * 5)) { - WLog_ERR(TAG, "RfxMessageTileSet packet too small for num_quants=%d", context->numQuant); + WLog_ERR(TAG, "RfxMessageTileSet packet too small for num_quants=%d", + context->numQuant); return FALSE; } @@ -851,16 +833,17 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa Stream_Read_UINT8(s, quant); *quants++ = (quant & 0x0F); *quants++ = (quant >> 4); - - WLog_Print(context->priv->log, WLOG_DEBUG, "quant %d (%d %d %d %d %d %d %d %d %d %d).", - i, context->quants[i * 10], context->quants[i * 10 + 1], - context->quants[i * 10 + 2], context->quants[i * 10 + 3], - context->quants[i * 10 + 4], context->quants[i * 10 + 5], - context->quants[i * 10 + 6], context->quants[i * 10 + 7], - context->quants[i * 10 + 8], context->quants[i * 10 + 9]); + WLog_Print(context->priv->log, WLOG_DEBUG, + "quant %d (%d %d %d %d %d %d %d %d %d %d).", + i, context->quants[i * 10], context->quants[i * 10 + 1], + context->quants[i * 10 + 2], context->quants[i * 10 + 3], + context->quants[i * 10 + 4], context->quants[i * 10 + 5], + context->quants[i * 10 + 6], context->quants[i * 10 + 7], + context->quants[i * 10 + 8], context->quants[i * 10 + 9]); } - if (!(message->tiles = (RFX_TILE**) calloc(message->numTiles, sizeof(RFX_TILE*)))) + if (!(message->tiles = (RFX_TILE**) calloc(message->numTiles, + sizeof(RFX_TILE*)))) { message->numTiles = 0; return FALSE; @@ -869,7 +852,8 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa if (context->priv->UseThreads) { work_objects = (PTP_WORK*) calloc(message->numTiles, sizeof(PTP_WORK)); - params = (RFX_TILE_PROCESS_WORK_PARAM*) calloc(message->numTiles, sizeof(RFX_TILE_PROCESS_WORK_PARAM)); + params = (RFX_TILE_PROCESS_WORK_PARAM*) calloc(message->numTiles, + sizeof(RFX_TILE_PROCESS_WORK_PARAM)); if (!work_objects) { @@ -887,6 +871,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa /* tiles */ close_cnt = 0; rc = TRUE; + for (i = 0; i < message->numTiles; i++) { if (!(tile = (RFX_TILE*) ObjectPool_Take(context->priv->TilePool))) @@ -901,18 +886,21 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa /* RFX_TILE */ if (Stream_GetRemainingLength(s) < 6) { - WLog_ERR(TAG, "RfxMessageTileSet packet too small to read tile %d/%d", i, message->numTiles); + WLog_ERR(TAG, "RfxMessageTileSet packet too small to read tile %d/%d", i, + message->numTiles); rc = FALSE; break; } - Stream_Read_UINT16(s, blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */ + Stream_Read_UINT16(s, + blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */ Stream_Read_UINT32(s, blockLen); /* blockLen (4 bytes) */ if (Stream_GetRemainingLength(s) < blockLen - 6) { - WLog_ERR(TAG, "RfxMessageTileSet not enough bytes to read tile %d/%d with blocklen=%d", - i, message->numTiles, blockLen); + WLog_ERR(TAG, + "RfxMessageTileSet not enough bytes to read tile %d/%d with blocklen=%d", + i, message->numTiles, blockLen); rc = FALSE; break; } @@ -921,7 +909,8 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa if (blockType != CBT_TILE) { - WLog_ERR(TAG, "unknown block type 0x%X, expected CBT_TILE (0xCAC3).", blockType); + WLog_ERR(TAG, "unknown block type 0x%X, expected CBT_TILE (0xCAC3).", + blockType); rc = FALSE; break; } @@ -934,26 +923,24 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa Stream_Read_UINT16(s, tile->YLen); /* YLen (2 bytes) */ Stream_Read_UINT16(s, tile->CbLen); /* CbLen (2 bytes) */ Stream_Read_UINT16(s, tile->CrLen); /* CrLen (2 bytes) */ - Stream_GetPointer(s, tile->YData); Stream_Seek(s, tile->YLen); Stream_GetPointer(s, tile->CbData); Stream_Seek(s, tile->CbLen); Stream_GetPointer(s, tile->CrData); Stream_Seek(s, tile->CrLen); - tile->x = tile->xIdx * 64; tile->y = tile->yIdx * 64; if (context->priv->UseThreads) { assert(params); - params[i].context = context; params[i].tile = message->tiles[i]; - if (!(work_objects[i] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_process_message_tile_work_callback, - (void*) ¶ms[i], &context->priv->ThreadPoolEnv))) + if (!(work_objects[i] = CreateThreadpoolWork((PTP_WORK_CALLBACK) + rfx_process_message_tile_work_callback, + (void*) ¶ms[i], &context->priv->ThreadPoolEnv))) { WLog_ERR(TAG, "CreateThreadpoolWork failed."); rc = FALSE; @@ -979,6 +966,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa CloseThreadpoolWork(work_objects[i]); } } + free(work_objects); free(params); @@ -986,6 +974,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa { if (!(tile = message->tiles[i])) continue; + tile->YLen = tile->CbLen = tile->CrLen = 0; tile->YData = tile->CbData = tile->CrData = NULL; } @@ -993,7 +982,12 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa return rc; } -RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length) +BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, + UINT32 format, UINT32 length, + UINT32 left, UINT32 top, + BYTE* dst, UINT32 dstFormat, + UINT32 dstStride, UINT32 dstHeight, + REGION16* invalidRegion) { int pos; UINT32 blockLen; @@ -1006,7 +1000,7 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length if (!context || !data || !length) goto fail; - if (!(s = Stream_New(data, length))) + if (!(s = Stream_New((BYTE*)data, length))) goto fail; if (!(message = (RFX_MESSAGE*) calloc(1, sizeof(RFX_MESSAGE)))) @@ -1019,8 +1013,8 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length /* RFX_BLOCKT */ Stream_Read_UINT16(s, blockType); /* blockType (2 bytes) */ Stream_Read_UINT32(s, blockLen); /* blockLen (4 bytes) */ - - WLog_Print(context->priv->log, WLOG_DEBUG, "blockType 0x%X blockLen %d", blockType, blockLen); + WLog_Print(context->priv->log, WLOG_DEBUG, "blockType 0x%X blockLen %d", + blockType, blockLen); if (blockLen == 0) { @@ -1036,7 +1030,8 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length pos = Stream_GetPosition(s) - 6 + blockLen; - if (blockType > WBT_CONTEXT && context->decodedHeaderBlocks != _RFX_DECODED_HEADERS) + if (blockType > WBT_CONTEXT + && context->decodedHeaderBlocks != _RFX_DECODED_HEADERS) { WLog_ERR(TAG, "%s: incomplete header blocks processing", __FUNCTION__); goto fail; @@ -1052,7 +1047,8 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length goto fail; Stream_Read_UINT8(s, codecId); /* codecId (1 byte) must be set to 0x01 */ - Stream_Read_UINT8(s, channelId); /* channelId (1 byte) 0xFF or 0x00, see below */ + Stream_Read_UINT8(s, + channelId); /* channelId (1 byte) 0xFF or 0x00, see below */ if (codecId != 0x01) { @@ -1065,7 +1061,8 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length /* If the blockType is set to WBT_CONTEXT, then channelId MUST be set to 0xFF.*/ if (channelId != 0xFF) { - WLog_ERR(TAG, "%s: invalid channelId 0x%02X for blockType 0x%04X", __FUNCTION__, channelId, blockType); + WLog_ERR(TAG, "%s: invalid channelId 0x%02X for blockType 0x%04X", __FUNCTION__, + channelId, blockType); goto fail; } } @@ -1074,20 +1071,19 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length /* For all other values of blockType, channelId MUST be set to 0x00. */ if (channelId != 0x00) { - WLog_ERR(TAG, "%s: invalid channelId 0x%02X for blockType WBT_CONTEXT", __FUNCTION__, channelId); + WLog_ERR(TAG, "%s: invalid channelId 0x%02X for blockType WBT_CONTEXT", + __FUNCTION__, channelId); goto fail; } } } - switch (blockType) { /* Header messages: * The stream MUST start with the header messages and any of these headers can appear * in the stream at a later stage. The header messages can be repeated. */ - case WBT_SYNC: ok = rfx_process_message_sync(context, s); break; @@ -1112,7 +1108,8 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length */ case WBT_FRAME_BEGIN: - ok = rfx_process_message_frame_begin(context, message, s, &expectedDataBlockType); + ok = rfx_process_message_frame_begin(context, message, s, + &expectedDataBlockType); break; case WBT_REGION: @@ -1137,15 +1134,63 @@ RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length if (ok) { + UINT32 i, j; + UINT32 nbUpdateRects; + REGION16 updateRegion; + REGION16 clippingRects; + const RECTANGLE_16* updateRects; Stream_Free(s, FALSE); - return message; + region16_init(&clippingRects); + + for (i = 0; i < message->numRects; i++) + { + RECTANGLE_16 clippingRect; + const RFX_RECT* rect = &(message->rects[i]); + clippingRect.left = left + rect->x; + clippingRect.top = top + rect->y; + clippingRect.right = clippingRect.left + rect->width; + clippingRect.bottom = clippingRect.top + rect->height; + region16_union_rect(&clippingRects, &clippingRects, &clippingRect); + } + + for (i = 0; i < message->numTiles; i++) + { + RECTANGLE_16 updateRect; + const RFX_TILE* tile = message->tiles[i]; + updateRect.left = left + tile->x; + updateRect.top = top + tile->y; + updateRect.right = updateRect.left + 64; + updateRect.bottom = updateRect.top + 64; + region16_init(&updateRegion); + region16_intersect_rect(&updateRegion, &clippingRects, &updateRect); + updateRects = region16_rects(&updateRegion, &nbUpdateRects); + + for (j = 0; j < nbUpdateRects; j++) + { + UINT32 nXDst = updateRects[j].left; + UINT32 nYDst = updateRects[j].top; + UINT32 nWidth = updateRects[j].right - updateRects[j].left; + UINT32 nHeight = updateRects[j].bottom - updateRects[j].top; + freerdp_image_copy(dst, dstFormat, dstStride, + nXDst, nYDst, nWidth, nHeight, + tile->data, format, 64 * 4, 0, 0, NULL); + + if (invalidRegion) + region16_union_rect(invalidRegion, invalidRegion, &updateRects[j]); + } + + region16_uninit(&updateRegion); + } + + region16_uninit(&clippingRects); + rfx_message_free(context, message); + return TRUE; } fail: Stream_Free(s, FALSE); rfx_message_free(context, message); - - return NULL; + return FALSE; } UINT16 rfx_message_get_tile_count(RFX_MESSAGE* message) @@ -1207,15 +1252,14 @@ void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message) static void rfx_update_context_properties(RFX_CONTEXT* context) { UINT16 properties; - /* properties in tilesets: note that this has different format from the one in TS_RFX_CONTEXT */ properties = 1; /* lt */ properties |= (context->flags << 1); /* flags */ properties |= (COL_CONV_ICT << 4); /* cct */ properties |= (CLW_XFORM_DWT_53_A << 6); /* xft */ - properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 10); /* et */ + properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) + << 10); /* et */ properties |= (SCALAR_QUANTIZATION << 14); /* qt */ - context->properties = properties; } @@ -1249,22 +1293,20 @@ static void rfx_write_message_channels(RFX_CONTEXT* context, wStream* s) static void rfx_write_message_context(RFX_CONTEXT* context, wStream* s) { UINT16 properties; - Stream_Write_UINT16(s, WBT_CONTEXT); /* CodecChannelT.blockType (2 bytes) */ Stream_Write_UINT32(s, 13); /* CodecChannelT.blockLen (4 bytes) */ Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId (1 byte) */ Stream_Write_UINT8(s, 0xFF); /* CodecChannelT.channelId (1 byte) */ Stream_Write_UINT8(s, 0); /* ctxId (1 byte) */ Stream_Write_UINT16(s, CT_TILE_64x64); /* tileSize (2 bytes) */ - /* properties */ properties = context->flags; /* flags */ properties |= (COL_CONV_ICT << 3); /* cct */ properties |= (CLW_XFORM_DWT_53_A << 5); /* xft */ - properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 9); /* et */ + properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) + << 9); /* et */ properties |= (SCALAR_QUANTIZATION << 13); /* qt */ Stream_Write_UINT16(s, properties); /* properties (2 bytes) */ - rfx_update_context_properties(context); } @@ -1277,7 +1319,6 @@ static BOOL rfx_compose_message_header(RFX_CONTEXT* context, wStream* s) rfx_write_message_context(context, s); rfx_write_message_codec_versions(context, s); rfx_write_message_channels(context, s); - return TRUE; } @@ -1289,8 +1330,8 @@ static int rfx_tile_length(RFX_TILE* tile) static BOOL rfx_write_tile(RFX_CONTEXT* context, wStream* s, RFX_TILE* tile) { UINT32 blockLen; - blockLen = rfx_tile_length(tile); + if (!Stream_EnsureRemainingCapacity(s, blockLen)) return FALSE; @@ -1307,7 +1348,6 @@ static BOOL rfx_write_tile(RFX_CONTEXT* context, wStream* s, RFX_TILE* tile) Stream_Write(s, tile->YData, tile->YLen); /* YData */ Stream_Write(s, tile->CbData, tile->CbLen); /* CbData */ Stream_Write(s, tile->CrData, tile->CrLen); /* CrData */ - return TRUE; } @@ -1317,22 +1357,24 @@ struct _RFX_TILE_COMPOSE_WORK_PARAM RFX_CONTEXT* context; }; -void CALLBACK rfx_compose_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work) +void CALLBACK rfx_compose_message_tile_work_callback(PTP_CALLBACK_INSTANCE + instance, void* context, PTP_WORK work) { RFX_TILE_COMPOSE_WORK_PARAM* param = (RFX_TILE_COMPOSE_WORK_PARAM*) context; rfx_encode_rgb(param->context, param->tile); } -static BOOL computeRegion(const RFX_RECT* rects, int numRects, REGION16 *region, int width, int height) +static BOOL computeRegion(const RFX_RECT* rects, int numRects, REGION16* region, + int width, int height) { int i; - const RFX_RECT *rect = rects; + const RFX_RECT* rect = rects; const RECTANGLE_16 mainRect = { 0, 0, width, height }; - for(i = 0; i < numRects; i++, rect++) { + for (i = 0; i < numRects; i++, rect++) + { RECTANGLE_16 rect16; - rect16.left = rect->x; rect16.top = rect->y; rect16.right = rect->x + rect->width; @@ -1347,9 +1389,9 @@ static BOOL computeRegion(const RFX_RECT* rects, int numRects, REGION16 *region, #define TILE_NO(v) ((v) / 64) -BOOL setupWorkers(RFX_CONTEXT *context, int nbTiles) +BOOL setupWorkers(RFX_CONTEXT* context, int nbTiles) { - RFX_CONTEXT_PRIV *priv = context->priv; + RFX_CONTEXT_PRIV* priv = context->priv; void* pmem; if (!context->priv->UseThreads) @@ -1360,32 +1402,31 @@ BOOL setupWorkers(RFX_CONTEXT *context, int nbTiles) priv->workObjects = (PTP_WORK*) pmem; - if (!(pmem = realloc((void*) priv->tileWorkParams, sizeof(RFX_TILE_COMPOSE_WORK_PARAM) * nbTiles))) + if (!(pmem = realloc((void*) priv->tileWorkParams, + sizeof(RFX_TILE_COMPOSE_WORK_PARAM) * nbTiles))) return FALSE; priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*) pmem; - return TRUE; } -RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int numRects, - BYTE* data, int width, int height, int scanline) +RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, + int numRects, + BYTE* data, int width, int height, int scanline) { - int i, maxNbTiles, maxTilesX, maxTilesY; - int xIdx, yIdx, regionNbRects; - int gridRelX, gridRelY, ax, ay, bytesPerPixel; + UINT32 i, maxNbTiles, maxTilesX, maxTilesY; + UINT32 xIdx, yIdx, regionNbRects; + UINT32 gridRelX, gridRelY, ax, ay, bytesPerPixel; RFX_TILE* tile; RFX_RECT* rfxRect; RFX_MESSAGE* message = NULL; PTP_WORK* workObject = NULL; - RFX_TILE_COMPOSE_WORK_PARAM *workParam = NULL; + RFX_TILE_COMPOSE_WORK_PARAM* workParam = NULL; BOOL success = FALSE; - REGION16 rectsRegion, tilesRegion; RECTANGLE_16 currentTileRect; - const RECTANGLE_16 *regionRect; - const RECTANGLE_16 *extents; - + const RECTANGLE_16* regionRect; + const RECTANGLE_16* extents; assert(data); assert(rects); assert(numRects > 0); @@ -1406,10 +1447,12 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int if (!context->numQuant) { - if (!(context->quants = (UINT32*) malloc(sizeof(rfx_default_quantization_values)))) + if (!(context->quants = (UINT32*) malloc(sizeof( + rfx_default_quantization_values)))) goto skip_encoding_loop; - CopyMemory(context->quants, &rfx_default_quantization_values, sizeof(rfx_default_quantization_values)); + CopyMemory(context->quants, &rfx_default_quantization_values, + sizeof(rfx_default_quantization_values)); context->numQuant = 1; context->quantIdxY = 0; context->quantIdxCb = 0; @@ -1418,7 +1461,6 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int message->numQuant = context->numQuant; message->quantVals = context->quants; - bytesPerPixel = (context->bits_per_pixel / 8); if (!computeRegion(rects, numRects, &rectsRegion, width, height)) @@ -1427,7 +1469,6 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int extents = region16_extents(&rectsRegion); assert(extents->right - extents->left > 0); assert(extents->bottom - extents->top > 0); - maxTilesX = 1 + TILE_NO(extents->right - 1) - TILE_NO(extents->left); maxTilesY = 1 + TILE_NO(extents->bottom - 1) - TILE_NO(extents->top); maxNbTiles = maxTilesX * maxTilesY; @@ -1451,21 +1492,20 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int message->numRects = regionNbRects; - for (i = 0, rfxRect = message->rects; i < regionNbRects; i++, regionRect++, rfxRect++) + for (i = 0, rfxRect = message->rects; i < regionNbRects; + i++, regionRect++, rfxRect++) { int startTileX = regionRect->left / 64; int endTileX = (regionRect->right - 1) / 64; - int startTileY = regionRect->top / 64; int endTileY = (regionRect->bottom - 1) / 64; - rfxRect->x = regionRect->left; rfxRect->y = regionRect->top; rfxRect->width = (regionRect->right - regionRect->left); rfxRect->height = (regionRect->bottom - regionRect->top); - - for (yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY; yIdx++, gridRelY += 64 ) + for (yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY; + yIdx++, gridRelY += 64) { int tileHeight = 64; @@ -1475,7 +1515,8 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int currentTileRect.top = gridRelY; currentTileRect.bottom = gridRelY + tileHeight; - for (xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX; xIdx++, gridRelX += 64) + for (xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX; + xIdx++, gridRelX += 64) { int tileWidth = 64; @@ -1499,7 +1540,6 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int tile->scanline = scanline; tile->width = tileWidth; tile->height = tileHeight; - ax = gridRelX; ay = gridRelY; @@ -1508,21 +1548,19 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int free(tile->data); tile->allocated = FALSE; } - tile->data = &data[(ay * scanline) + (ax * bytesPerPixel)]; + tile->data = &data[(ay * scanline) + (ax * bytesPerPixel)]; tile->quantIdxY = context->quantIdxY; tile->quantIdxCb = context->quantIdxCb; tile->quantIdxCr = context->quantIdxCr; - tile->YLen = tile->CbLen = tile->CrLen = 0; - if (!(tile->YCbCrData = (BYTE *)BufferPool_Take(context->priv->BufferPool, -1))) + if (!(tile->YCbCrData = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1))) goto skip_encoding_loop; - tile->YData = (BYTE*) &(tile->YCbCrData[((8192 + 32) * 0) + 16]); - tile->CbData = (BYTE*) &(tile->YCbCrData[((8192 + 32) * 1) + 16]); - tile->CrData = (BYTE*) &(tile->YCbCrData[((8192 + 32) * 2) + 16]); - + tile->YData = (BYTE*) & (tile->YCbCrData[((8192 + 32) * 0) + 16]); + tile->CbData = (BYTE*) & (tile->YCbCrData[((8192 + 32) * 1) + 16]); + tile->CrData = (BYTE*) & (tile->YCbCrData[((8192 + 32) * 2) + 16]); message->tiles[message->numTiles] = tile; message->numTiles++; @@ -1532,15 +1570,14 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int workParam->tile = tile; if (!(*workObject = CreateThreadpoolWork( - (PTP_WORK_CALLBACK)rfx_compose_message_tile_work_callback, - (void*) workParam, - &context->priv->ThreadPoolEnv))) + (PTP_WORK_CALLBACK)rfx_compose_message_tile_work_callback, + (void*) workParam, + &context->priv->ThreadPoolEnv))) { goto skip_encoding_loop; } SubmitThreadpoolWork(*workObject); - workObject++; workParam++; } @@ -1556,14 +1593,14 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int } /* rects */ success = TRUE; - skip_encoding_loop: if (success && message->numTiles != maxNbTiles) { if (message->numTiles > 0) { - void* pmem = realloc((void*) message->tiles, sizeof(RFX_TILE*) * message->numTiles); + void* pmem = realloc((void*) message->tiles, + sizeof(RFX_TILE*) * message->numTiles); if (pmem) message->tiles = (RFX_TILE**) pmem; @@ -1584,6 +1621,7 @@ skip_encoding_loop: for (i = 0; i < message->numTiles; i++) { tile = message->tiles[i]; + if (context->priv->UseThreads) { if (*workObject) @@ -1591,6 +1629,7 @@ skip_encoding_loop: WaitForThreadpoolWorkCallbacks(*workObject, FALSE); CloseThreadpoolWork(*workObject); } + workObject++; } @@ -1604,20 +1643,18 @@ skip_encoding_loop: return message; WLog_ERR(TAG, "%s: failed", __FUNCTION__); - message->freeRects = TRUE; rfx_message_free(context, message); return NULL; } -RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message, int* numMessages, int maxDataSize) +RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message, + int* numMessages, int maxDataSize) { int i, j; UINT32 tileDataSize; RFX_MESSAGE* messages; - maxDataSize -= 1024; /* reserve enough space for headers */ - *numMessages = ((message->tilesDataSize + maxDataSize) / maxDataSize) * 4; if (!(messages = (RFX_MESSAGE*) calloc((*numMessages), sizeof(RFX_MESSAGE)))) @@ -1641,7 +1678,9 @@ RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message, int* messages[j].rects = message->rects; messages[j].freeRects = FALSE; messages[j].freeArray = TRUE; - if (!(messages[j].tiles = (RFX_TILE**) calloc(message->numTiles, sizeof(RFX_TILE*)))) + + if (!(messages[j].tiles = (RFX_TILE**) calloc(message->numTiles, + sizeof(RFX_TILE*)))) goto free_messages; } @@ -1653,28 +1692,30 @@ RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message, int* *numMessages = j + 1; context->frameIdx += j; message->numTiles = 0; - return messages; - free_messages: + for (i = 0; i < j; i++) free(messages[i].tiles); free(messages); - return NULL; } -RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects, int numRects, - BYTE* data, int width, int height, int scanline, int* numMessages, int maxDataSize) +RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects, + int numRects, + BYTE* data, int width, int height, int scanline, int* numMessages, + int maxDataSize) { RFX_MESSAGE* message; RFX_MESSAGE* messageList; - if (!(message = rfx_encode_message(context, rects, numRects, data, width, height, scanline))) + if (!(message = rfx_encode_message(context, rects, numRects, data, width, + height, scanline))) return NULL; - if (!(messageList = rfx_split_message(context, message, numMessages, maxDataSize))) + if (!(messageList = rfx_split_message(context, message, numMessages, + maxDataSize))) { message->freeRects = TRUE; rfx_message_free(context, message); @@ -1685,14 +1726,15 @@ RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects, in return messageList; } -static BOOL rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message) +static BOOL rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s, + RFX_MESSAGE* message) { int i; RFX_TILE* tile; UINT32 blockLen; UINT32* quantVals; - blockLen = 22 + (message->numQuant * 5) + message->tilesDataSize; + if (!Stream_EnsureRemainingCapacity(s, blockLen)) return FALSE; @@ -1707,7 +1749,6 @@ static BOOL rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s, RFX_MESS Stream_Write_UINT8(s, 0x40); /* tileSize (1 byte) */ Stream_Write_UINT16(s, message->numTiles); /* numTiles (2 bytes) */ Stream_Write_UINT32(s, message->tilesDataSize); /* tilesDataSize (4 bytes) */ - quantVals = message->quantVals; for (i = 0; i < message->numQuant * 5; i++) @@ -1720,19 +1761,21 @@ static BOOL rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s, RFX_MESS { if (!(tile = message->tiles[i])) return FALSE; + if (!rfx_write_tile(context, s, tile)) return FALSE; } #ifdef WITH_DEBUG_RFX - WLog_Print(context->priv->log, WLOG_DEBUG, "numQuant: %d numTiles: %d tilesDataSize: %d", - message->numQuant, message->numTiles, message->tilesDataSize); + WLog_Print(context->priv->log, WLOG_DEBUG, + "numQuant: %d numTiles: %d tilesDataSize: %d", + message->numQuant, message->numTiles, message->tilesDataSize); #endif - return TRUE; } -BOOL rfx_write_message_frame_begin(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message) +BOOL rfx_write_message_frame_begin(RFX_CONTEXT* context, wStream* s, + RFX_MESSAGE* message) { if (!Stream_EnsureRemainingCapacity(s, 14)) return FALSE; @@ -1743,16 +1786,16 @@ BOOL rfx_write_message_frame_begin(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE Stream_Write_UINT8(s, 0); /* CodecChannelT.channelId */ Stream_Write_UINT32(s, message->frameIdx); /* frameIdx */ Stream_Write_UINT16(s, 1); /* numRegions */ - return TRUE; } -BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message) +BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s, + RFX_MESSAGE* message) { int i; UINT32 blockLen; - blockLen = 15 + (message->numRects * 8); + if (!Stream_EnsureRemainingCapacity(s, blockLen)) return FALSE; @@ -1766,7 +1809,6 @@ BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* mes for (i = 0; i < message->numRects; i++) { /* Clipping rectangles are relative to destLeft, destTop */ - Stream_Write_UINT16(s, message->rects[i].x); /* x (2 bytes) */ Stream_Write_UINT16(s, message->rects[i].y); /* y (2 bytes) */ Stream_Write_UINT16(s, message->rects[i].width); /* width (2 bytes) */ @@ -1775,11 +1817,11 @@ BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* mes Stream_Write_UINT16(s, CBT_REGION); /* regionType (2 bytes) */ Stream_Write_UINT16(s, 1); /* numTilesets (2 bytes) */ - return TRUE; } -BOOL rfx_write_message_frame_end(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message) +BOOL rfx_write_message_frame_end(RFX_CONTEXT* context, wStream* s, + RFX_MESSAGE* message) { if (!Stream_EnsureRemainingCapacity(s, 8)) return FALSE; @@ -1788,7 +1830,6 @@ BOOL rfx_write_message_frame_end(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* Stream_Write_UINT32(s, 8); /* CodecChannelT.blockLen */ Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId */ Stream_Write_UINT8(s, 0); /* CodecChannelT.channelId */ - return TRUE; } @@ -1798,13 +1839,14 @@ BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message) { if (!rfx_compose_message_header(context, s)) return FALSE; + context->state = RFX_STATE_SEND_FRAME_DATA; } if (!rfx_write_message_frame_begin(context, s, message) || - !rfx_write_message_region(context, s, message) || - !rfx_write_message_tileset(context, s, message) || - !rfx_write_message_frame_end(context, s, message)) + !rfx_write_message_region(context, s, message) || + !rfx_write_message_tileset(context, s, message) || + !rfx_write_message_frame_end(context, s, message)) { return FALSE; } @@ -1813,18 +1855,18 @@ BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message) } BOOL rfx_compose_message(RFX_CONTEXT* context, wStream* s, - const RFX_RECT* rects, int numRects, BYTE* data, int width, int height, int scanline) + const RFX_RECT* rects, int numRects, BYTE* data, int width, int height, + int scanline) { RFX_MESSAGE* message; BOOL ret = TRUE; - if (!(message = rfx_encode_message(context, rects, numRects, data, width, height, scanline))) + if (!(message = rfx_encode_message(context, rects, numRects, data, width, + height, scanline))) return FALSE; ret = rfx_write_message(context, s, message); - message->freeRects = TRUE; rfx_message_free(context, message); - return ret; } diff --git a/libfreerdp/codec/rfx_decode.c b/libfreerdp/codec/rfx_decode.c index d14aff8a2..21a290bca 100644 --- a/libfreerdp/codec/rfx_decode.c +++ b/libfreerdp/codec/rfx_decode.c @@ -38,130 +38,85 @@ #include "rfx_decode.h" /* stride is bytes between rows in the output buffer. */ -void rfx_decode_format_rgb(INT16* r_buf, INT16* g_buf, INT16* b_buf, - RDP_PIXEL_FORMAT pixel_format, BYTE* dst_buf, int stride) +static void rfx_decode_format_rgb(const INT16* r_buf, const INT16* g_buf, + const INT16* b_buf, UINT32 pixel_format, + BYTE* dst_buf, UINT32 stride) { - primitives_t *prims = primitives_get(); - INT16* r = r_buf; - INT16* g = g_buf; - INT16* b = b_buf; - INT16* pSrc[3]; + primitives_t* prims = primitives_get(); + const INT16* r = r_buf; + const INT16* g = g_buf; + const INT16* b = b_buf; + const INT16* pSrc[3]; static const prim_size_t roi_64x64 = { 64, 64 }; BYTE* dst = dst_buf; - int x, y; - - switch (pixel_format) - { - case RDP_PIXEL_FORMAT_B8G8R8A8: - pSrc[0] = r; pSrc[1] = g; pSrc[2] = b; - prims->RGBToRGB_16s8u_P3AC4R( - (const INT16 **) pSrc, 64*sizeof(INT16), - dst, stride, &roi_64x64); - break; - case RDP_PIXEL_FORMAT_R8G8B8A8: - pSrc[0] = b; pSrc[1] = g; pSrc[2] = r; - prims->RGBToRGB_16s8u_P3AC4R( - (const INT16 **) pSrc, 64*sizeof(INT16), - dst, stride, &roi_64x64); - break; - case RDP_PIXEL_FORMAT_B8G8R8: - for (y=0; y<64; y++) - { - for (x=0; x<64; x++) - { - *dst++ = (BYTE) (*b++); - *dst++ = (BYTE) (*g++); - *dst++ = (BYTE) (*r++); - } - dst += stride - (64*3); - } - break; - case RDP_PIXEL_FORMAT_R8G8B8: - for (y=0; y<64; y++) - { - for (x=0; x<64; x++) - { - *dst++ = (BYTE) (*r++); - *dst++ = (BYTE) (*g++); - *dst++ = (BYTE) (*b++); - } - dst += stride - (64*3); - } - break; - default: - break; - } + pSrc[0] = r; + pSrc[1] = g; + pSrc[2] = b; + prims->RGBToRGB_16s8u_P3AC4R( + (const INT16**) pSrc, 64 * sizeof(INT16), + dst, stride, pixel_format, &roi_64x64); } -static void rfx_decode_component(RFX_CONTEXT* context, const UINT32* quantization_values, - const BYTE* data, int size, INT16* buffer) +static void rfx_decode_component(RFX_CONTEXT* context, + const UINT32* quantization_values, + const BYTE* data, int size, INT16* buffer) { INT16* dwt_buffer; - dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */ - PROFILER_ENTER(context->priv->prof_rfx_decode_component); - PROFILER_ENTER(context->priv->prof_rfx_rlgr_decode); - rfx_rlgr_decode(data, size, buffer, 4096, (context->mode == RLGR1) ? 1 : 3); + rfx_rlgr_decode(data, size, buffer, 4096, (context->mode == RLGR1) ? 1 : 3); PROFILER_EXIT(context->priv->prof_rfx_rlgr_decode); - PROFILER_ENTER(context->priv->prof_rfx_differential_decode); - rfx_differential_decode(buffer + 4032, 64); + rfx_differential_decode(buffer + 4032, 64); PROFILER_EXIT(context->priv->prof_rfx_differential_decode); - PROFILER_ENTER(context->priv->prof_rfx_quantization_decode); - context->quantization_decode(buffer, quantization_values); + context->quantization_decode(buffer, quantization_values); PROFILER_EXIT(context->priv->prof_rfx_quantization_decode); - PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_decode); - context->dwt_2d_decode(buffer, dwt_buffer); + context->dwt_2d_decode(buffer, dwt_buffer); PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_decode); - PROFILER_EXIT(context->priv->prof_rfx_decode_component); - BufferPool_Return(context->priv->BufferPool, dwt_buffer); } /* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */ /* stride is bytes between rows in the output buffer. */ -BOOL rfx_decode_rgb(RFX_CONTEXT* context, RFX_TILE* tile, BYTE* rgb_buffer, int stride) +BOOL rfx_decode_rgb(RFX_CONTEXT* context, RFX_TILE* tile, BYTE* rgb_buffer, + int stride) { BYTE* pBuffer; INT16* pSrcDst[3]; - UINT32 *y_quants, *cb_quants, *cr_quants; + UINT32* y_quants, *cb_quants, *cr_quants; static const prim_size_t roi_64x64 = { 64, 64 }; - const primitives_t *prims = primitives_get(); - + const primitives_t* prims = primitives_get(); PROFILER_ENTER(context->priv->prof_rfx_decode_rgb); - y_quants = context->quants + (tile->quantIdxY * 10); cb_quants = context->quants + (tile->quantIdxCb * 10); cr_quants = context->quants + (tile->quantIdxCr * 10); - pBuffer = (BYTE*) BufferPool_Take(context->priv->BufferPool, -1); - pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* y_r_buffer */ - pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* cb_g_buffer */ - pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* cr_b_buffer */ - - rfx_decode_component(context, y_quants, tile->YData, tile->YLen, pSrcDst[0]); /* YData */ - rfx_decode_component(context, cb_quants, tile->CbData, tile->CbLen, pSrcDst[1]); /* CbData */ - rfx_decode_component(context, cr_quants, tile->CrData, tile->CrLen, pSrcDst[2]); /* CrData */ - + pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + + 16])); /* y_r_buffer */ + pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* cb_g_buffer */ + pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* cr_b_buffer */ + rfx_decode_component(context, y_quants, tile->YData, tile->YLen, + pSrcDst[0]); /* YData */ + rfx_decode_component(context, cb_quants, tile->CbData, tile->CbLen, + pSrcDst[1]); /* CbData */ + rfx_decode_component(context, cr_quants, tile->CrData, tile->CrLen, + pSrcDst[2]); /* CrData */ PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb); prims->yCbCrToRGB_16s16s_P3P3((const INT16**) pSrcDst, 64 * sizeof(INT16), - pSrcDst, 64 * sizeof(INT16), &roi_64x64); + pSrcDst, 64 * sizeof(INT16), &roi_64x64); PROFILER_EXIT(context->priv->prof_rfx_ycbcr_to_rgb); - PROFILER_ENTER(context->priv->prof_rfx_decode_format_rgb); - rfx_decode_format_rgb(pSrcDst[0], pSrcDst[1], pSrcDst[2], - context->pixel_format, rgb_buffer, stride); + rfx_decode_format_rgb(pSrcDst[0], pSrcDst[1], pSrcDst[2], + context->pixel_format, rgb_buffer, stride); PROFILER_EXIT(context->priv->prof_rfx_decode_format_rgb); - PROFILER_EXIT(context->priv->prof_rfx_decode_rgb); - BufferPool_Return(context->priv->BufferPool, pBuffer); - return TRUE; } diff --git a/libfreerdp/codec/rfx_encode.c b/libfreerdp/codec/rfx_encode.c index 499cedc6c..3b6c0fe25 100644 --- a/libfreerdp/codec/rfx_encode.c +++ b/libfreerdp/codec/rfx_encode.c @@ -41,16 +41,17 @@ #define MINMAX(_v,_l,_h) ((_v) < (_l) ? (_l) : ((_v) > (_h) ? (_h) : (_v))) -static void rfx_encode_format_rgb(const BYTE* rgb_data, int width, int height, int rowstride, - RDP_PIXEL_FORMAT pixel_format, const BYTE* palette, INT16* r_buf, INT16* g_buf, INT16* b_buf) +static void rfx_encode_format_rgb(const BYTE* rgb_data, int width, int height, + int rowstride, + UINT32 pixel_format, const BYTE* palette, INT16* r_buf, INT16* g_buf, + INT16* b_buf) { int x, y; int x_exceed; int y_exceed; const BYTE* src; INT16 r, g, b; - INT16 *r_last, *g_last, *b_last; - + INT16* r_last, *g_last, *b_last; x_exceed = 64 - width; y_exceed = 64 - height; @@ -60,66 +61,78 @@ static void rfx_encode_format_rgb(const BYTE* rgb_data, int width, int height, i switch (pixel_format) { - case RDP_PIXEL_FORMAT_B8G8R8A8: + case PIXEL_FORMAT_BGRA32: for (x = 0; x < width; x++) { - *b_buf++ = (INT16) (*src++); - *g_buf++ = (INT16) (*src++); - *r_buf++ = (INT16) (*src++); + *b_buf++ = (INT16)(*src++); + *g_buf++ = (INT16)(*src++); + *r_buf++ = (INT16)(*src++); src++; } + break; - case RDP_PIXEL_FORMAT_R8G8B8A8: + + case PIXEL_FORMAT_RGBA32: for (x = 0; x < width; x++) { - *r_buf++ = (INT16) (*src++); - *g_buf++ = (INT16) (*src++); - *b_buf++ = (INT16) (*src++); + *r_buf++ = (INT16)(*src++); + *g_buf++ = (INT16)(*src++); + *b_buf++ = (INT16)(*src++); src++; } + break; - case RDP_PIXEL_FORMAT_B8G8R8: + + case PIXEL_FORMAT_BGR24: for (x = 0; x < width; x++) { - *b_buf++ = (INT16) (*src++); - *g_buf++ = (INT16) (*src++); - *r_buf++ = (INT16) (*src++); + *b_buf++ = (INT16)(*src++); + *g_buf++ = (INT16)(*src++); + *r_buf++ = (INT16)(*src++); } + break; - case RDP_PIXEL_FORMAT_R8G8B8: + + case PIXEL_FORMAT_RGB24: for (x = 0; x < width; x++) { - *r_buf++ = (INT16) (*src++); - *g_buf++ = (INT16) (*src++); - *b_buf++ = (INT16) (*src++); + *r_buf++ = (INT16)(*src++); + *g_buf++ = (INT16)(*src++); + *b_buf++ = (INT16)(*src++); } + break; - case RDP_PIXEL_FORMAT_B5G6R5_LE: + + case PIXEL_FORMAT_BGR16: for (x = 0; x < width; x++) { - *b_buf++ = (INT16) (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); - *g_buf++ = (INT16) ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); - *r_buf++ = (INT16) ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); + *b_buf++ = (INT16)(((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); + *g_buf++ = (INT16)((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); + *r_buf++ = (INT16)((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); src += 2; } + break; - case RDP_PIXEL_FORMAT_R5G6B5_LE: + + case PIXEL_FORMAT_RGB16: for (x = 0; x < width; x++) { - *r_buf++ = (INT16) (((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); - *g_buf++ = (INT16) ((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); - *b_buf++ = (INT16) ((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); + *r_buf++ = (INT16)(((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)); + *g_buf++ = (INT16)((((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)); + *b_buf++ = (INT16)((((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)); src += 2; } + break; - case RDP_PIXEL_FORMAT_P4_PLANER: + + case PIXEL_FORMAT_RGB8: if (!palette) break; + for (x = 0; x < width; x++) { int shift; BYTE idx; - shift = (7 - (x % 8)); idx = ((*src) >> shift) & 1; idx |= (((*(src + 1)) >> shift) & 1) << 1; @@ -129,26 +142,32 @@ static void rfx_encode_format_rgb(const BYTE* rgb_data, int width, int height, i *r_buf++ = (INT16) palette[idx]; *g_buf++ = (INT16) palette[idx + 1]; *b_buf++ = (INT16) palette[idx + 2]; + if (shift == 0) src += 4; } + break; - case RDP_PIXEL_FORMAT_P8: + + case PIXEL_FORMAT_A4: if (!palette) break; + for (x = 0; x < width; x++) { int idx = (*src) * 3; - *r_buf++ = (INT16) palette[idx]; *g_buf++ = (INT16) palette[idx + 1]; *b_buf++ = (INT16) palette[idx + 2]; src++; } + break; + default: break; } + /* Fill the horizontal region outside of 64x64 tile size with the right-most pixel for best quality */ if (x_exceed > 0) { @@ -187,33 +206,26 @@ static void rfx_encode_format_rgb(const BYTE* rgb_data, int width, int height, i /* rfx_encode_rgb_to_ycbcr code now resides in the primitives library. */ -static void rfx_encode_component(RFX_CONTEXT* context, const UINT32* quantization_values, - INT16* data, BYTE* buffer, int buffer_size, int* size) +static void rfx_encode_component(RFX_CONTEXT* context, + const UINT32* quantization_values, + INT16* data, BYTE* buffer, int buffer_size, int* size) { INT16* dwt_buffer; - dwt_buffer = BufferPool_Take(context->priv->BufferPool, -1); /* dwt_buffer */ - PROFILER_ENTER(context->priv->prof_rfx_encode_component); - PROFILER_ENTER(context->priv->prof_rfx_dwt_2d_encode); - context->dwt_2d_encode(data, dwt_buffer); + context->dwt_2d_encode(data, dwt_buffer); PROFILER_EXIT(context->priv->prof_rfx_dwt_2d_encode); - PROFILER_ENTER(context->priv->prof_rfx_quantization_encode); - context->quantization_encode(data, quantization_values); + context->quantization_encode(data, quantization_values); PROFILER_EXIT(context->priv->prof_rfx_quantization_encode); - PROFILER_ENTER(context->priv->prof_rfx_differential_encode); - rfx_differential_encode(data + 4032, 64); + rfx_differential_encode(data + 4032, 64); PROFILER_EXIT(context->priv->prof_rfx_differential_encode); - PROFILER_ENTER(context->priv->prof_rfx_rlgr_encode); - *size = rfx_rlgr_encode(context->mode, data, 4096, buffer, buffer_size); + *size = rfx_rlgr_encode(context->mode, data, 4096, buffer, buffer_size); PROFILER_EXIT(context->priv->prof_rfx_rlgr_encode); - PROFILER_EXIT(context->priv->prof_rfx_encode_component); - BufferPool_Return(context->priv->BufferPool, dwt_buffer); } @@ -222,7 +234,7 @@ void rfx_encode_rgb(RFX_CONTEXT* context, RFX_TILE* tile) BYTE* pBuffer; INT16* pSrcDst[3]; int YLen, CbLen, CrLen; - UINT32 *YQuant, *CbQuant, *CrQuant; + UINT32* YQuant, *CbQuant, *CrQuant; primitives_t* prims = primitives_get(); static const prim_size_t roi_64x64 = { 64, 64 }; @@ -233,41 +245,34 @@ void rfx_encode_rgb(RFX_CONTEXT* context, RFX_TILE* tile) YQuant = context->quants + (tile->quantIdxY * 10); CbQuant = context->quants + (tile->quantIdxCb * 10); CrQuant = context->quants + (tile->quantIdxCr * 10); - - pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + 16])); /* y_r_buffer */ - pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + 16])); /* cb_g_buffer */ - pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + 16])); /* cr_b_buffer */ - + pSrcDst[0] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 0) + + 16])); /* y_r_buffer */ + pSrcDst[1] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 1) + + 16])); /* cb_g_buffer */ + pSrcDst[2] = (INT16*)((BYTE*)(&pBuffer[((8192 + 32) * 2) + + 16])); /* cr_b_buffer */ PROFILER_ENTER(context->priv->prof_rfx_encode_rgb); - PROFILER_ENTER(context->priv->prof_rfx_encode_format_rgb); - rfx_encode_format_rgb(tile->data, tile->width, tile->height, tile->scanline, - context->pixel_format, context->palette, pSrcDst[0], pSrcDst[1], pSrcDst[2]); + rfx_encode_format_rgb(tile->data, tile->width, tile->height, tile->scanline, + context->pixel_format, context->palette, pSrcDst[0], pSrcDst[1], pSrcDst[2]); PROFILER_EXIT(context->priv->prof_rfx_encode_format_rgb); - PROFILER_ENTER(context->priv->prof_rfx_rgb_to_ycbcr); - prims->RGBToYCbCr_16s16s_P3P3((const INT16**) pSrcDst, 64 * sizeof(INT16), - pSrcDst, 64 * sizeof(INT16), &roi_64x64); + prims->RGBToYCbCr_16s16s_P3P3((const INT16**) pSrcDst, 64 * sizeof(INT16), + pSrcDst, 64 * sizeof(INT16), &roi_64x64); PROFILER_EXIT(context->priv->prof_rfx_rgb_to_ycbcr); - /** * We need to clear the buffers as the RLGR encoder expects it to be initialized to zero. * This allows simplifying and improving the performance of the encoding process. */ - ZeroMemory(tile->YData, 4096); ZeroMemory(tile->CbData, 4096); ZeroMemory(tile->CrData, 4096); - rfx_encode_component(context, YQuant, pSrcDst[0], tile->YData, 4096, &YLen); rfx_encode_component(context, CbQuant, pSrcDst[1], tile->CbData, 4096, &CbLen); rfx_encode_component(context, CrQuant, pSrcDst[2], tile->CrData, 4096, &CrLen); - tile->YLen = (UINT16) YLen; tile->CbLen = (UINT16) CbLen; tile->CrLen = (UINT16) CrLen; - PROFILER_EXIT(context->priv->prof_rfx_encode_rgb); - BufferPool_Return(context->priv->BufferPool, pBuffer); } diff --git a/libfreerdp/codec/test/TestFreeRDPCodecClear.c b/libfreerdp/codec/test/TestFreeRDPCodecClear.c index f6225e437..3d6110780 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecClear.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecClear.c @@ -37,7 +37,7 @@ static BYTE TEST_CLEAR_EXAMPLE_4[] = "\xb6\xff\xff\xff\xff\xff\xff\xff\xff\xff\x46\x91\x47\x91\x48\x91" "\x49\x91\x4a\x91\x1b\x91"; -int test_ClearDecompressExample1() +static int test_ClearDecompressExample1(void) { int status; BYTE* pSrcData; @@ -50,16 +50,16 @@ int test_ClearDecompressExample1() SrcSize = sizeof(TEST_CLEAR_EXAMPLE_1) - 1; pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_1; - status = clear_decompress(clear, pSrcData, SrcSize, &pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); + status = clear_decompress(clear, pSrcData, SrcSize, pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); printf("clear_decompress example 1 status: %d\n", status); clear_context_free(clear); - return 1; + return status; } -int test_ClearDecompressExample2() +static int test_ClearDecompressExample2(void) { int status; BYTE* pSrcData; @@ -72,16 +72,16 @@ int test_ClearDecompressExample2() SrcSize = sizeof(TEST_CLEAR_EXAMPLE_2) - 1; pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_2; - status = clear_decompress(clear, pSrcData, SrcSize, &pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); + status = clear_decompress(clear, pSrcData, SrcSize, pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); printf("clear_decompress example 2 status: %d\n", status); clear_context_free(clear); - return 1; + return status; } -int test_ClearDecompressExample3() +static int test_ClearDecompressExample3(void) { int status; BYTE* pSrcData; @@ -94,16 +94,16 @@ int test_ClearDecompressExample3() SrcSize = sizeof(TEST_CLEAR_EXAMPLE_3) - 1; pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_3; - status = clear_decompress(clear, pSrcData, SrcSize, &pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); + status = clear_decompress(clear, pSrcData, SrcSize, pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); printf("clear_decompress example 3 status: %d\n", status); clear_context_free(clear); - return 1; + return status; } -int test_ClearDecompressExample4() +static int test_ClearDecompressExample4(void) { int status; BYTE* pSrcData; @@ -116,24 +116,26 @@ int test_ClearDecompressExample4() SrcSize = sizeof(TEST_CLEAR_EXAMPLE_4) - 1; pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_4; - status = clear_decompress(clear, pSrcData, SrcSize, &pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); + status = clear_decompress(clear, pSrcData, SrcSize, pDstData, + PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0); printf("clear_decompress example 4 status: %d\n", status); clear_context_free(clear); - return 1; + return status; } int TestFreeRDPCodecClear(int argc, char* argv[]) { - //test_ClearDecompressExample1(); - - //test_ClearDecompressExample2(); - - //test_ClearDecompressExample3(); - - test_ClearDecompressExample4(); + if (test_ClearDecompressExample1()) + return -1; + if (test_ClearDecompressExample2()) + return -1; + if (test_ClearDecompressExample3()) + return -1; + if (test_ClearDecompressExample4()) + return -1; return 0; } diff --git a/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c b/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c index 11e15a842..9d7ef8971 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c @@ -11,7 +11,7 @@ * Experimental Case 01: 64x64 (32bpp) */ -static BYTE TEST_RLE_BITMAP_EXPERIMENTAL_01[16384] = +static const BYTE TEST_RLE_BITMAP_EXPERIMENTAL_01[16384] = "\x1B\x1A\x16\xFF\x1C\x1A\x16\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF\x18\x16\x12\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF" "\x1D\x1C\x17\xFF\x1D\x1B\x17\xFF\x1C\x1B\x17\xFF\x1B\x1A\x16\xFF\x1A\x19\x15\xFF\x1A\x19\x15\xFF\x18\x17\x13\xFF\x1A\x19\x15\xFF" "\x1B\x1A\x16\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF\x18\x16\x14\xFF\x1C\x1A\x16\xFF\x1A\x18\x14\xFF\x1B\x1A\x16\xFF\x19\x17\x13\xFF" @@ -530,7 +530,7 @@ static BYTE TEST_RLE_BITMAP_EXPERIMENTAL_01[16384] = * Experimental Case 02: 64x64 (32bpp) */ -static BYTE TEST_RLE_BITMAP_EXPERIMENTAL_02[16384] = +static const BYTE TEST_RLE_BITMAP_EXPERIMENTAL_02[16384] = "\x1C\x1C\x17\xFF\x1D\x1B\x18\xFF\x1B\x19\x15\xFF\x19\x18\x13\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF\x17\x17\x13\xFF\x19\x17\x14\xFF" "\x15\x14\x11\xFF\x13\x13\x10\xFF\x4F\x4B\x3E\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x22\x21\x1B\xFF\x21\x21\x1A\xFF" "\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x21\x20\x1A\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x22\x20\x1A\xFF\x21\x20\x1A\xFF" @@ -1048,7 +1048,7 @@ static BYTE TEST_RLE_BITMAP_EXPERIMENTAL_02[16384] = * Experimental Case 03: 64x64 (32bpp) */ -static BYTE TEST_RLE_BITMAP_EXPERIMENTAL_03[16384] = +static const BYTE TEST_RLE_BITMAP_EXPERIMENTAL_03[16384] = "\x27\x2A\x23\xFF\x23\x25\x1F\xFF\x23\x23\x1E\xFF\x24\x23\x1D\xFF\x25\x23\x1D\xFF\x25\x23\x1E\xFF\x25\x23\x1D\xFF\x25\x24\x1F\xFF" "\x28\x2B\x23\xFF\x37\x60\x4A\xFF\x4A\xA2\x78\xFF\x47\x97\x71\xFF\x41\x84\x64\xFF\x3D\x75\x58\xFF\x38\x62\x4B\xFF\x33\x50\x3E\xFF" "\x2E\x3C\x30\xFF\x2A\x34\x29\xFF\x28\x30\x26\xFF\x27\x2C\x24\xFF\x26\x29\x22\xFF\x27\x28\x21\xFF\x27\x26\x20\xFF\x27\x25\x20\xFF" @@ -2663,7 +2663,7 @@ BYTE TEST_64X64_BLUE_PLANE_RLE[3724] = * [MS-RDPEGDI] Test Bitmap 32x32 (16bpp) */ -const BYTE TEST_RLE_UNCOMPRESSED_BITMAP_16BPP[2048] = +static const BYTE TEST_RLE_UNCOMPRESSED_BITMAP_16BPP[2048] = "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00" @@ -2797,7 +2797,7 @@ const BYTE TEST_RLE_UNCOMPRESSED_BITMAP_16BPP[2048] = * [MS-RDPEGDI] Test Bitmap 32x32 (RLE Encoded, not RDP6) */ -const BYTE TEST_RLE_COMPRESSED_BITMAP[220] = +static const BYTE TEST_RLE_COMPRESSED_BITMAP[220] = "\x85\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x06\x8B\x99\xD6\x99" "\xD6\x99\xD6\x10\x84\x08\x42\x08\x42\x10\x84\x99\xD6\x99\xD6\x99" "\xD6\x99\xD6\x06\x84\x99\xD6\x99\xD6\x99\xD6\xFF\xFF\x16\x69\x99" @@ -2813,7 +2813,7 @@ const BYTE TEST_RLE_COMPRESSED_BITMAP[220] = "\xC3\x80\x61\x00\x00\x00\x00\x00\xCC\x89\x52\x03\x6E\xFF\xFF\x02" "\xCB\x18\xC6\x84\x08\x42\x08\x42\x08\x42\xFF\xFF"; -const BYTE TEST_RLE_SCANLINE_UNCOMPRESSED[12] = +static const BYTE TEST_RLE_SCANLINE_UNCOMPRESSED[12] = "AAAABBCCCCCD"; /** @@ -2822,7 +2822,7 @@ const BYTE TEST_RLE_SCANLINE_UNCOMPRESSED[12] = /* Scanline Absolute Values */ -const BYTE TEST_RDP6_SCANLINES_ABSOLUTE[3][6] = +static const BYTE TEST_RDP6_SCANLINES_ABSOLUTE[3][6] = { { 255, 255, 255, 255, 254, 253 }, { 254, 192, 132, 96, 75, 25 }, @@ -2830,8 +2830,7 @@ const BYTE TEST_RDP6_SCANLINES_ABSOLUTE[3][6] = }; /* Scanline Delta Values */ - -const int TEST_RDP6_SCANLINES_DELTA[3][6] = +static const int TEST_RDP6_SCANLINES_DELTA[3][6] = { { 255, 255, 255, 255, 254, 253 }, { -1, -63, -123, -159, -179, -228 }, @@ -2840,7 +2839,7 @@ const int TEST_RDP6_SCANLINES_DELTA[3][6] = /* Scanline Delta Values (1-byte two's complement) */ -const char TEST_RDP6_SCANLINES_DELTA_2C[3][6] = +static const BYTE TEST_RDP6_SCANLINES_DELTA_2C[3][6] = { { -1, -1, -1, -1, -2, -3 }, { -1, -63, -123, 97, 77, 28 }, @@ -2849,7 +2848,7 @@ const char TEST_RDP6_SCANLINES_DELTA_2C[3][6] = /* Scanline Delta Values (1-byte two's complement, encoded) */ -const char TEST_RDP6_SCANLINES_DELTA_2C_ENCODED[3][6] = +static const BYTE TEST_RDP6_SCANLINES_DELTA_2C_ENCODED[3][6] = { { -1, -1, -1, -1, -2, -3 }, { -1, 125, 11, -62, -102, 56 }, @@ -2858,7 +2857,7 @@ const char TEST_RDP6_SCANLINES_DELTA_2C_ENCODED[3][6] = /* Scanline Delta Values (1-byte two's complement, encoded, unsigned) */ -const BYTE TEST_RDP6_SCANLINES_DELTA_2C_ENCODED_UNSIGNED[3][6] = +static const BYTE TEST_RDP6_SCANLINES_DELTA_2C_ENCODED_UNSIGNED[3][6] = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFD }, { 0x01, 0x7D, 0xF5, 0xC2, 0x9A, 0x38 }, @@ -2880,7 +2879,7 @@ static void fill_bitmap_alpha_channel(BYTE* data, int width, int height, BYTE va } } -void fill_bitmap_red_channel(BYTE* data, int width, int height, BYTE value) +static void fill_bitmap_red_channel(BYTE* data, int width, int height, BYTE value) { int i, j; UINT32* pixel; @@ -2895,7 +2894,7 @@ void fill_bitmap_red_channel(BYTE* data, int width, int height, BYTE value) } } -void fill_bitmap_green_channel(BYTE* data, int width, int height, BYTE value) +static void fill_bitmap_green_channel(BYTE* data, int width, int height, BYTE value) { int i, j; UINT32* pixel; @@ -2910,7 +2909,7 @@ void fill_bitmap_green_channel(BYTE* data, int width, int height, BYTE value) } } -void fill_bitmap_blue_channel(BYTE* data, int width, int height, BYTE value) +static void fill_bitmap_blue_channel(BYTE* data, int width, int height, BYTE value) { int i, j; UINT32* pixel; @@ -2925,7 +2924,7 @@ void fill_bitmap_blue_channel(BYTE* data, int width, int height, BYTE value) } } -void dump_color_channel(BYTE* data, int width, int height) +static void dump_color_channel(BYTE* data, int width, int height) { int i, j; @@ -2940,14 +2939,14 @@ void dump_color_channel(BYTE* data, int width, int height) } } -int test_individual_planes_encoding_rle() +static int test_individual_planes_encoding_rle(void) { - int width; - int height; + UINT32 width; + UINT32 height; BYTE* pOutput; int planeSize; int compareSize; - int dstSizes[4]; + UINT32 dstSizes[4]; int availableSize; DWORD planarFlags; BITMAP_PLANAR_CONTEXT* planar; @@ -3073,10 +3072,9 @@ int test_individual_planes_encoding_rle() int TestFreeRDPCodecPlanar(int argc, char* argv[]) { int i; - int dstSize; + UINT32 dstSize; UINT32 format; BYTE* pDstData; - HCLRCONV clrconv; DWORD planarFlags; BYTE* srcBitmap32; BYTE* srcBitmap16; @@ -3089,10 +3087,20 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[]) planarFlags = PLANAR_FORMAT_HEADER_NA; planarFlags |= PLANAR_FORMAT_HEADER_RLE; planar = freerdp_bitmap_planar_context_new(planarFlags, 64, 64); - clrconv = freerdp_clrconv_new(0); srcBitmap16 = (BYTE*) TEST_RLE_UNCOMPRESSED_BITMAP_16BPP; - srcBitmap32 = freerdp_image_convert(srcBitmap16, NULL, 32, 32, 16, 32, clrconv); + format = PIXEL_FORMAT_ARGB32; + pDstData = calloc(32*32, GetBytesPerPixel(format)); + if (!pDstData) + return -1; + + if (freerdp_image_copy(pDstData, format, + 32 * GetBytesPerPixel(format), + 0, 0, 32, 32, srcBitmap16, PIXEL_FORMAT_RGB16, + 32 * GetBytesPerPixel(PIXEL_FORMAT_RGB16), + 0, 0, NULL)) + return -1; + #if 0 freerdp_bitmap_compress_planar(planar, srcBitmap32, format, 32, 32, 32 * 4, NULL, &dstSize); freerdp_bitmap_planar_compress_plane_rle((BYTE*) TEST_RLE_SCANLINE_UNCOMPRESSED, 12, 1, NULL, &dstSize); @@ -3309,7 +3317,6 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[]) free(compressedBitmap); free(decompressedBitmap); - freerdp_clrconv_free(clrconv); _aligned_free(srcBitmap32); freerdp_bitmap_planar_context_free(planar); return 0; diff --git a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c index 60d3b34cf..917645522 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c @@ -844,7 +844,7 @@ static int test_memcmp_count(const BYTE* mem1, const BYTE* mem2, int size, int m return count; } -int test_progressive_decode(PROGRESSIVE_CONTEXT* progressive, EGFX_SAMPLE_FILE files[4], EGFX_SAMPLE_FILE bitmaps[4], int quarter, int count) +static int test_progressive_decode(PROGRESSIVE_CONTEXT* progressive, EGFX_SAMPLE_FILE files[4], EGFX_SAMPLE_FILE bitmaps[4], int quarter, int count) { int cnt; int pass; @@ -868,7 +868,7 @@ int test_progressive_decode(PROGRESSIVE_CONTEXT* progressive, EGFX_SAMPLE_FILE f for (pass = 0; pass < count; pass++) { status = progressive_decompress(progressive, files[pass].buffer, files[pass].size, - &g_DstData, PIXEL_FORMAT_XRGB32, g_DstStep, 0, 0, g_Width, g_Height, 0); + g_DstData, PIXEL_FORMAT_XRGB32, g_DstStep, 0, 0, g_Width, g_Height, 0); printf("ProgressiveDecompress: status: %d pass: %d\n", status, pass + 1); @@ -948,7 +948,7 @@ int test_progressive_decode(PROGRESSIVE_CONTEXT* progressive, EGFX_SAMPLE_FILE f return 1; } -int test_progressive_ms_sample(char* ms_sample_path) +static int test_progressive_ms_sample(char* ms_sample_path) { int i, j, k; int count; diff --git a/libfreerdp/codec/test/TestFreeRDPRegion.c b/libfreerdp/codec/test/TestFreeRDPRegion.c index 5530d96bf..70d7e77fc 100644 --- a/libfreerdp/codec/test/TestFreeRDPRegion.c +++ b/libfreerdp/codec/test/TestFreeRDPRegion.c @@ -41,11 +41,11 @@ static BOOL compareRectangles(const RECTANGLE_16 *src1, const RECTANGLE_16 *src2 } -static int test_basic() { +static int test_basic(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; /* R1 + R2 ==> disjointed rects */ RECTANGLE_16 r1 = { 0, 101, 200, 201}; @@ -85,11 +85,11 @@ out: } -static int test_r1_r3() { +static int test_r1_r3(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r3 = {150, 151, 250, 251}; @@ -139,11 +139,11 @@ out: } -static int test_r9_r10() { +static int test_r9_r10(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; /* * +=============================================================== @@ -155,8 +155,8 @@ static int test_r9_r10() { * || | | | =====> | | * || | | | | | * || | | | | | - * |+--| |-+ +--+---+-+ - * | +---+ +---+ + * |+--| |-+ +--+---+-+ + * | +---+ +---+ */ RECTANGLE_16 r9 = { 0, 100, 400, 200}; RECTANGLE_16 r10 = {200, 0, 300, 300}; @@ -182,11 +182,11 @@ out: } -static int test_r1_r5() { +static int test_r1_r5(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r5 = {150, 121, 300, 131}; @@ -207,9 +207,9 @@ static int test_r1_r5() { * || | r5 | =====> | | * || +-------+ +--------+----+ * || | | | - * |+--------+ +--------+ - * | - * + * |+--------+ +--------+ + * | + * */ if (!region16_union_rect(®ion, ®ion, &r1)) goto out; @@ -226,11 +226,11 @@ out: return retCode; } -static int test_r1_r6() { +static int test_r1_r6(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r6 = {150, 121, 170, 131}; @@ -245,8 +245,8 @@ static int test_r1_r6() { * || |r6| | =====> | | * || +--+ | | | * || | | | - * |+--------+ +--------+ - * | + * |+--------+ +--------+ + * | */ region16_clear(®ion); if (!region16_union_rect(®ion, ®ion, &r1)) @@ -264,11 +264,11 @@ out: } -static int test_r1_r2_r4() { +static int test_r1_r2_r4(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r2 = {150, 301, 250, 401}; RECTANGLE_16 r4 = {150, 251, 250, 301}; @@ -312,11 +312,11 @@ out: } -static int test_r1_r7_r8() { +static int test_r1_r7_r8(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r7 = {300, 101, 500, 201}; RECTANGLE_16 r8 = {150, 121, 400, 131}; @@ -338,8 +338,8 @@ static int test_r1_r7_r8() { * || | r8 | | =====> | | * || +------------+ | +--------+---+--------+ * || | | | | | | | - * |+--------+ +--------+ +--------+ +--------+ - * | + * |+--------+ +--------+ +--------+ +--------+ + * | */ region16_init(®ion); if (!region16_union_rect(®ion, ®ion, &r1)) @@ -381,11 +381,11 @@ out: } -static int test_r1_r2_r3_r4() { +static int test_r1_r2_r3_r4(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r2 = {150, 301, 250, 401}; RECTANGLE_16 r3 = {150, 151, 250, 251}; @@ -435,7 +435,7 @@ static int test_r1_r2_r3_r4() { * | * |+-----+ +-----+ * || | | | - * |+-----+--------+ +-----+--------+ + * |+-----+--------+ +-----+--------+ * || | ==> | | * |+-----+--------+ +-----+--------+ * | | | | | @@ -459,7 +459,7 @@ out: } -static int test_from_weston() +static int test_from_weston(void) { /* * 0: 0,0 -> 640,32 (w=640 h=32) @@ -469,7 +469,7 @@ static int test_from_weston() REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 0, 640, 32}; RECTANGLE_16 r2 = {236, 169, 268, 201}; RECTANGLE_16 r3 = {246, 258, 278, 290}; @@ -513,11 +513,11 @@ out: return retCode; } -static int test_r1_inter_r3() { +static int test_r1_inter_r3(void) { REGION16 region, intersection; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r3 = {150, 151, 250, 251}; @@ -557,11 +557,11 @@ out: return retCode; } -static int test_r1_r3_inter_r11() { +static int test_r1_r3_inter_r11(void) { REGION16 region, intersection; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects; + UINT32 nbRects; RECTANGLE_16 r1 = { 0, 101, 200, 201}; RECTANGLE_16 r3 = {150, 151, 250, 251}; RECTANGLE_16 r11 ={170, 151, 600, 301}; @@ -614,11 +614,11 @@ out: return retCode; } -static int test_norbert_case() { +static int test_norbert_case(void) { REGION16 region, intersection; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects, i; + UINT32 nbRects, i; RECTANGLE_16 inRectangles[5] = { {1680, 0, 1920, 242}, @@ -654,14 +654,14 @@ static int test_norbert_case() { * | | | * | | R[3]| * 1036 | | +------+ - * 1040 | +----+ + * 1040 | +----+ * | |R[4]| Union of R[0-4]| * 1078 | +----+ - - - - - - - -+ - * 1080 | - * - * + * 1080 | + * + * * The result is union of R[0] - R[4]. - * After intersected with the full screen rect, the + * After intersected with the full screen rect, the * result should keep the same. */ for (i = 0; i < 5; i++) @@ -689,11 +689,11 @@ out: return retCode; } -static int test_norbert2_case() { +static int test_norbert2_case(void) { REGION16 region; int retCode = -1; const RECTANGLE_16 *rects; - int nbRects = 0; + UINT32 nbRects = 0; RECTANGLE_16 rect1 = { 464, 696, 476, 709 }; RECTANGLE_16 rect2 = { 0, 0, 1024, 32 }; @@ -750,7 +750,7 @@ out: return retCode; } -static int test_empty_rectangle() { +static int test_empty_rectangle(void) { REGION16 region, intersection; int retCode = -1; int i; @@ -768,7 +768,7 @@ static int test_empty_rectangle() { 100, 100, 200, 200 }; RECTANGLE_16 expected_inter_extents = { - 0, 0, 0, 0 + 0, 0, 0, 0 }; region16_init(®ion); @@ -808,13 +808,13 @@ out: return retCode; } -typedef int (*TestFunction)(); +typedef int (*TestFunction)(void); struct UnitaryTest { const char *name; TestFunction func; }; -struct UnitaryTest tests[] = { +static struct UnitaryTest tests[] = { {"Basic trivial tests", test_basic}, {"R1+R3 and R3+R1", test_r1_r3}, {"R1+R5", test_r1_r5}, diff --git a/libfreerdp/core/graphics.c b/libfreerdp/core/graphics.c index 27fe50adf..d6e6607f2 100644 --- a/libfreerdp/core/graphics.c +++ b/libfreerdp/core/graphics.c @@ -31,7 +31,6 @@ rdpBitmap* Bitmap_Alloc(rdpContext* context) { rdpBitmap* bitmap; rdpGraphics* graphics; - graphics = context->graphics; bitmap = (rdpBitmap*) calloc(1, graphics->Bitmap_Prototype->size); @@ -62,7 +61,8 @@ void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap) } } -void Bitmap_SetRectangle(rdpContext* context, rdpBitmap* bitmap, UINT16 left, UINT16 top, UINT16 right, UINT16 bottom) +void Bitmap_SetRectangle(rdpContext* context, rdpBitmap* bitmap, UINT16 left, + UINT16 top, UINT16 right, UINT16 bottom) { bitmap->left = left; bitmap->top = top; @@ -70,7 +70,8 @@ void Bitmap_SetRectangle(rdpContext* context, rdpBitmap* bitmap, UINT16 left, UI bitmap->bottom = bottom; } -void Bitmap_SetDimensions(rdpContext* context, rdpBitmap* bitmap, UINT16 width, UINT16 height) +void Bitmap_SetDimensions(rdpContext* context, rdpBitmap* bitmap, UINT16 width, + UINT16 height) { bitmap->width = width; bitmap->height = height; @@ -79,7 +80,8 @@ void Bitmap_SetDimensions(rdpContext* context, rdpBitmap* bitmap, UINT16 width, /* static method */ BOOL Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) { - return context->graphics->Bitmap_Prototype->SetSurface(context, bitmap, primary); + return context->graphics->Bitmap_Prototype->SetSurface(context, bitmap, + primary); } void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap) @@ -88,12 +90,10 @@ void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap) } /* Pointer Class */ - rdpPointer* Pointer_Alloc(rdpContext* context) { rdpPointer* pointer; rdpGraphics* graphics; - graphics = context->graphics; pointer = (rdpPointer*) calloc(1, graphics->Pointer_Prototype->size); @@ -133,7 +133,7 @@ void Pointer_Free(rdpContext* context, rdpPointer* pointer) } /* static method */ -BOOL Pointer_Set(rdpContext* context, rdpPointer* pointer) +BOOL Pointer_Set(rdpContext* context, const rdpPointer* pointer) { return context->graphics->Pointer_Prototype->Set(context, pointer); } @@ -150,7 +150,8 @@ BOOL Pointer_SetDefault(rdpContext* context) BOOL Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y) { - return IFCALLRESULT(TRUE, context->graphics->Pointer_Prototype->SetPosition, context, x, y); + return IFCALLRESULT(TRUE, context->graphics->Pointer_Prototype->SetPosition, + context, x, y); } void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer) @@ -164,7 +165,6 @@ rdpGlyph* Glyph_Alloc(rdpContext* context) { rdpGlyph* glyph; rdpGraphics* graphics; - graphics = context->graphics; glyph = (rdpGlyph*) calloc(1, graphics->Glyph_Prototype->size); @@ -191,14 +191,18 @@ BOOL Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y) return context->graphics->Glyph_Prototype->Draw(context, glyph, x, y); } -BOOL Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant) +BOOL Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, + UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant) { - return context->graphics->Glyph_Prototype->BeginDraw(context, x, y, width, height, bgcolor, fgcolor, fOpRedundant); + return context->graphics->Glyph_Prototype->BeginDraw(context, x, y, width, + height, bgcolor, fgcolor, fOpRedundant); } -BOOL Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor) +BOOL Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, + UINT32 bgcolor, UINT32 fgcolor) { - return context->graphics->Glyph_Prototype->EndDraw(context, x, y, width, height, bgcolor, fgcolor); + return context->graphics->Glyph_Prototype->EndDraw(context, x, y, width, height, + bgcolor, fgcolor); } void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph) @@ -211,45 +215,41 @@ void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph) rdpGraphics* graphics_new(rdpContext* context) { rdpGraphics* graphics; - graphics = (rdpGraphics*) calloc(1, sizeof(rdpGraphics)); if (graphics) { graphics->context = context; - graphics->Bitmap_Prototype = (rdpBitmap*) calloc(1, sizeof(rdpBitmap)); if (!graphics->Bitmap_Prototype) { - free (graphics); + free(graphics); return NULL; } graphics->Bitmap_Prototype->size = sizeof(rdpBitmap); graphics->Bitmap_Prototype->New = Bitmap_New; graphics->Bitmap_Prototype->Free = Bitmap_Free; - graphics->Pointer_Prototype = (rdpPointer*) calloc(1, sizeof(rdpPointer)); if (!graphics->Pointer_Prototype) { - free (graphics->Bitmap_Prototype); - free (graphics); + free(graphics->Bitmap_Prototype); + free(graphics); return NULL; } graphics->Pointer_Prototype->size = sizeof(rdpPointer); graphics->Pointer_Prototype->New = Pointer_New; graphics->Pointer_Prototype->Free = Pointer_Free; - graphics->Glyph_Prototype = (rdpGlyph*) calloc(1, sizeof(rdpGlyph)); if (!graphics->Glyph_Prototype) { - free (graphics->Pointer_Prototype); - free (graphics->Bitmap_Prototype); - free (graphics); + free(graphics->Pointer_Prototype); + free(graphics->Bitmap_Prototype); + free(graphics); return NULL; } diff --git a/libfreerdp/core/message.c b/libfreerdp/core/message.c index a56d1b58d..c22498123 100644 --- a/libfreerdp/core/message.c +++ b/libfreerdp/core/message.c @@ -51,7 +51,8 @@ static BOOL update_message_EndPaint(rdpContext* context) MakeMessageId(Update, EndPaint), NULL, NULL); } -static BOOL update_message_SetBounds(rdpContext* context, rdpBounds* bounds) +static BOOL update_message_SetBounds(rdpContext* context, + const rdpBounds* bounds) { rdpBounds* wParam = NULL; @@ -79,7 +80,8 @@ static BOOL update_message_DesktopResize(rdpContext* context) MakeMessageId(Update, DesktopResize), NULL, NULL); } -static BOOL update_message_BitmapUpdate(rdpContext* context, BITMAP_UPDATE* bitmap) +static BOOL update_message_BitmapUpdate(rdpContext* context, + const BITMAP_UPDATE* bitmap) { UINT32 index; BITMAP_UPDATE* wParam; @@ -123,7 +125,8 @@ static BOOL update_message_BitmapUpdate(rdpContext* context, BITMAP_UPDATE* bitm MakeMessageId(Update, BitmapUpdate), (void*) wParam, NULL); } -static BOOL update_message_Palette(rdpContext* context, PALETTE_UPDATE* palette) +static BOOL update_message_Palette(rdpContext* context, + const PALETTE_UPDATE* palette) { PALETTE_UPDATE* wParam; @@ -136,7 +139,8 @@ static BOOL update_message_Palette(rdpContext* context, PALETTE_UPDATE* palette) MakeMessageId(Update, Palette), (void*) wParam, NULL); } -static BOOL update_message_PlaySound(rdpContext* context, PLAY_SOUND_UPDATE* playSound) +static BOOL update_message_PlaySound(rdpContext* context, + const PLAY_SOUND_UPDATE* playSound) { PLAY_SOUND_UPDATE* wParam; @@ -155,7 +159,8 @@ static BOOL update_message_SetKeyboardIndicators(rdpContext* context, UINT16 led MakeMessageId(Update, SetKeyboardIndicators), (void*)(size_t)led_flags, NULL); } -static BOOL update_message_RefreshRect(rdpContext* context, BYTE count, RECTANGLE_16* areas) +static BOOL update_message_RefreshRect(rdpContext* context, BYTE count, + const RECTANGLE_16* areas) { RECTANGLE_16* lParam; @@ -168,7 +173,8 @@ static BOOL update_message_RefreshRect(rdpContext* context, BYTE count, RECTANGL MakeMessageId(Update, RefreshRect), (void*) (size_t) count, (void*) lParam); } -static BOOL update_message_SuppressOutput(rdpContext* context, BYTE allow, RECTANGLE_16* area) +static BOOL update_message_SuppressOutput(rdpContext* context, BYTE allow, + const RECTANGLE_16* area) { RECTANGLE_16* lParam = NULL; @@ -199,7 +205,8 @@ static BOOL update_message_SurfaceCommand(rdpContext* context, wStream* s) MakeMessageId(Update, SurfaceCommand), (void*) wParam, NULL); } -static BOOL update_message_SurfaceBits(rdpContext* context, SURFACE_BITS_COMMAND* surfaceBitsCommand) +static BOOL update_message_SurfaceBits(rdpContext* context, + const SURFACE_BITS_COMMAND* surfaceBitsCommand) { SURFACE_BITS_COMMAND* wParam; @@ -224,7 +231,8 @@ static BOOL update_message_SurfaceBits(rdpContext* context, SURFACE_BITS_COMMAND MakeMessageId(Update, SurfaceBits), (void*) wParam, NULL); } -static BOOL update_message_SurfaceFrameMarker(rdpContext* context, SURFACE_FRAME_MARKER* surfaceFrameMarker) +static BOOL update_message_SurfaceFrameMarker(rdpContext* context, + const SURFACE_FRAME_MARKER* surfaceFrameMarker) { SURFACE_FRAME_MARKER* wParam; @@ -245,7 +253,7 @@ static BOOL update_message_SurfaceFrameAcknowledge(rdpContext* context, UINT32 f /* Primary Update */ -static BOOL update_message_DstBlt(rdpContext* context, DSTBLT_ORDER* dstBlt) +static BOOL update_message_DstBlt(rdpContext* context, const DSTBLT_ORDER* dstBlt) { DSTBLT_ORDER* wParam; @@ -273,7 +281,8 @@ static BOOL update_message_PatBlt(rdpContext* context, PATBLT_ORDER* patBlt) MakeMessageId(PrimaryUpdate, PatBlt), (void*) wParam, NULL); } -static BOOL update_message_ScrBlt(rdpContext* context, SCRBLT_ORDER* scrBlt) +static BOOL update_message_ScrBlt(rdpContext* context, + const SCRBLT_ORDER* scrBlt) { SCRBLT_ORDER* wParam; @@ -286,7 +295,9 @@ static BOOL update_message_ScrBlt(rdpContext* context, SCRBLT_ORDER* scrBlt) MakeMessageId(PrimaryUpdate, ScrBlt), (void*) wParam, NULL); } -static BOOL update_message_OpaqueRect(rdpContext* context, OPAQUE_RECT_ORDER* opaqueRect) +static BOOL update_message_OpaqueRect( + rdpContext* context, + const OPAQUE_RECT_ORDER* opaqueRect) { OPAQUE_RECT_ORDER* wParam; @@ -299,7 +310,9 @@ static BOOL update_message_OpaqueRect(rdpContext* context, OPAQUE_RECT_ORDER* op MakeMessageId(PrimaryUpdate, OpaqueRect), (void*) wParam, NULL); } -static BOOL update_message_DrawNineGrid(rdpContext* context, DRAW_NINE_GRID_ORDER* drawNineGrid) +static BOOL update_message_DrawNineGrid( + rdpContext* context, + const DRAW_NINE_GRID_ORDER* drawNineGrid) { DRAW_NINE_GRID_ORDER* wParam; @@ -312,7 +325,8 @@ static BOOL update_message_DrawNineGrid(rdpContext* context, DRAW_NINE_GRID_ORDE MakeMessageId(PrimaryUpdate, DrawNineGrid), (void*) wParam, NULL); } -static BOOL update_message_MultiDstBlt(rdpContext* context, MULTI_DSTBLT_ORDER* multiDstBlt) +static BOOL update_message_MultiDstBlt(rdpContext* context, + const MULTI_DSTBLT_ORDER* multiDstBlt) { MULTI_DSTBLT_ORDER* wParam; @@ -325,7 +339,8 @@ static BOOL update_message_MultiDstBlt(rdpContext* context, MULTI_DSTBLT_ORDER* MakeMessageId(PrimaryUpdate, MultiDstBlt), (void*) wParam, NULL); } -static BOOL update_message_MultiPatBlt(rdpContext* context, MULTI_PATBLT_ORDER* multiPatBlt) +static BOOL update_message_MultiPatBlt(rdpContext* context, + const MULTI_PATBLT_ORDER* multiPatBlt) { MULTI_PATBLT_ORDER* wParam; @@ -340,7 +355,8 @@ static BOOL update_message_MultiPatBlt(rdpContext* context, MULTI_PATBLT_ORDER* MakeMessageId(PrimaryUpdate, MultiPatBlt), (void*) wParam, NULL); } -static BOOL update_message_MultiScrBlt(rdpContext* context, MULTI_SCRBLT_ORDER* multiScrBlt) +static BOOL update_message_MultiScrBlt(rdpContext* context, + const MULTI_SCRBLT_ORDER* multiScrBlt) { MULTI_SCRBLT_ORDER* wParam; @@ -353,7 +369,9 @@ static BOOL update_message_MultiScrBlt(rdpContext* context, MULTI_SCRBLT_ORDER* MakeMessageId(PrimaryUpdate, MultiScrBlt), (void*) wParam, NULL); } -static BOOL update_message_MultiOpaqueRect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* multiOpaqueRect) +static BOOL update_message_MultiOpaqueRect( + rdpContext* context, + const MULTI_OPAQUE_RECT_ORDER* multiOpaqueRect) { MULTI_OPAQUE_RECT_ORDER* wParam; @@ -366,7 +384,8 @@ static BOOL update_message_MultiOpaqueRect(rdpContext* context, MULTI_OPAQUE_REC MakeMessageId(PrimaryUpdate, MultiOpaqueRect), (void*) wParam, NULL); } -static BOOL update_message_MultiDrawNineGrid(rdpContext* context, MULTI_DRAW_NINE_GRID_ORDER* multiDrawNineGrid) +static BOOL update_message_MultiDrawNineGrid(rdpContext* context, + const MULTI_DRAW_NINE_GRID_ORDER* multiDrawNineGrid) { MULTI_DRAW_NINE_GRID_ORDER* wParam; @@ -381,7 +400,8 @@ static BOOL update_message_MultiDrawNineGrid(rdpContext* context, MULTI_DRAW_NIN MakeMessageId(PrimaryUpdate, MultiDrawNineGrid), (void*) wParam, NULL); } -static BOOL update_message_LineTo(rdpContext* context, LINE_TO_ORDER* lineTo) +static BOOL update_message_LineTo(rdpContext* context, + const LINE_TO_ORDER* lineTo) { LINE_TO_ORDER* wParam; @@ -394,7 +414,8 @@ static BOOL update_message_LineTo(rdpContext* context, LINE_TO_ORDER* lineTo) MakeMessageId(PrimaryUpdate, LineTo), (void*) wParam, NULL); } -static BOOL update_message_Polyline(rdpContext* context, POLYLINE_ORDER* polyline) +static BOOL update_message_Polyline(rdpContext* context, + const POLYLINE_ORDER* polyline) { POLYLINE_ORDER* wParam; @@ -443,7 +464,8 @@ static BOOL update_message_Mem3Blt(rdpContext* context, MEM3BLT_ORDER* mem3Blt) MakeMessageId(PrimaryUpdate, Mem3Blt), (void*) wParam, NULL); } -static BOOL update_message_SaveBitmap(rdpContext* context, SAVE_BITMAP_ORDER* saveBitmap) +static BOOL update_message_SaveBitmap(rdpContext* context, + const SAVE_BITMAP_ORDER* saveBitmap) { SAVE_BITMAP_ORDER* wParam; @@ -456,7 +478,8 @@ static BOOL update_message_SaveBitmap(rdpContext* context, SAVE_BITMAP_ORDER* sa MakeMessageId(PrimaryUpdate, SaveBitmap), (void*) wParam, NULL); } -static BOOL update_message_GlyphIndex(rdpContext* context, GLYPH_INDEX_ORDER* glyphIndex) +static BOOL update_message_GlyphIndex(rdpContext* context, + GLYPH_INDEX_ORDER* glyphIndex) { GLYPH_INDEX_ORDER* wParam; @@ -471,7 +494,8 @@ static BOOL update_message_GlyphIndex(rdpContext* context, GLYPH_INDEX_ORDER* gl MakeMessageId(PrimaryUpdate, GlyphIndex), (void*) wParam, NULL); } -static BOOL update_message_FastIndex(rdpContext* context, FAST_INDEX_ORDER* fastIndex) +static BOOL update_message_FastIndex(rdpContext* context, + const FAST_INDEX_ORDER* fastIndex) { FAST_INDEX_ORDER* wParam; @@ -484,7 +508,8 @@ static BOOL update_message_FastIndex(rdpContext* context, FAST_INDEX_ORDER* fast MakeMessageId(PrimaryUpdate, FastIndex), (void*) wParam, NULL); } -static BOOL update_message_FastGlyph(rdpContext* context, FAST_GLYPH_ORDER* fastGlyph) +static BOOL update_message_FastGlyph(rdpContext* context, + const FAST_GLYPH_ORDER* fastGlyph) { FAST_GLYPH_ORDER* wParam; @@ -512,7 +537,8 @@ static BOOL update_message_FastGlyph(rdpContext* context, FAST_GLYPH_ORDER* fast MakeMessageId(PrimaryUpdate, FastGlyph), (void*) wParam, NULL); } -static BOOL update_message_PolygonSC(rdpContext* context, POLYGON_SC_ORDER* polygonSC) +static BOOL update_message_PolygonSC(rdpContext* context, + const POLYGON_SC_ORDER* polygonSC) { POLYGON_SC_ORDER* wParam; @@ -556,7 +582,8 @@ static BOOL update_message_PolygonCB(rdpContext* context, POLYGON_CB_ORDER* poly MakeMessageId(PrimaryUpdate, PolygonCB), (void*) wParam, NULL); } -static BOOL update_message_EllipseSC(rdpContext* context, ELLIPSE_SC_ORDER* ellipseSC) +static BOOL update_message_EllipseSC(rdpContext* context, + const ELLIPSE_SC_ORDER* ellipseSC) { ELLIPSE_SC_ORDER* wParam; @@ -569,7 +596,8 @@ static BOOL update_message_EllipseSC(rdpContext* context, ELLIPSE_SC_ORDER* elli MakeMessageId(PrimaryUpdate, EllipseSC), (void*) wParam, NULL); } -static BOOL update_message_EllipseCB(rdpContext* context, ELLIPSE_CB_ORDER* ellipseCB) +static BOOL update_message_EllipseCB(rdpContext* context, + const ELLIPSE_CB_ORDER* ellipseCB) { ELLIPSE_CB_ORDER* wParam; @@ -586,7 +614,8 @@ static BOOL update_message_EllipseCB(rdpContext* context, ELLIPSE_CB_ORDER* elli /* Secondary Update */ -static BOOL update_message_CacheBitmap(rdpContext* context, CACHE_BITMAP_ORDER* cacheBitmapOrder) +static BOOL update_message_CacheBitmap(rdpContext* context, + const CACHE_BITMAP_ORDER* cacheBitmapOrder) { CACHE_BITMAP_ORDER* wParam; @@ -649,7 +678,9 @@ static BOOL update_message_CacheBitmapV3(rdpContext* context, CACHE_BITMAP_V3_OR MakeMessageId(SecondaryUpdate, CacheBitmapV3), (void*) wParam, NULL); } -static BOOL update_message_CacheColorTable(rdpContext* context, CACHE_COLOR_TABLE_ORDER* cacheColorTableOrder) +static BOOL update_message_CacheColorTable( + rdpContext* context, + const CACHE_COLOR_TABLE_ORDER* cacheColorTableOrder) { CACHE_COLOR_TABLE_ORDER* wParam; @@ -662,7 +693,9 @@ static BOOL update_message_CacheColorTable(rdpContext* context, CACHE_COLOR_TABL MakeMessageId(SecondaryUpdate, CacheColorTable), (void*) wParam, NULL); } -static BOOL update_message_CacheGlyph(rdpContext* context, CACHE_GLYPH_ORDER* cacheGlyphOrder) +static BOOL update_message_CacheGlyph( + rdpContext* context, + const CACHE_GLYPH_ORDER* cacheGlyphOrder) { CACHE_GLYPH_ORDER* wParam; @@ -675,7 +708,9 @@ static BOOL update_message_CacheGlyph(rdpContext* context, CACHE_GLYPH_ORDER* ca MakeMessageId(SecondaryUpdate, CacheGlyph), (void*) wParam, NULL); } -static BOOL update_message_CacheGlyphV2(rdpContext* context, CACHE_GLYPH_V2_ORDER* cacheGlyphV2Order) +static BOOL update_message_CacheGlyphV2( + rdpContext* context, + const CACHE_GLYPH_V2_ORDER* cacheGlyphV2Order) { CACHE_GLYPH_V2_ORDER* wParam; @@ -688,7 +723,9 @@ static BOOL update_message_CacheGlyphV2(rdpContext* context, CACHE_GLYPH_V2_ORDE MakeMessageId(SecondaryUpdate, CacheGlyphV2), (void*) wParam, NULL); } -static BOOL update_message_CacheBrush(rdpContext* context, CACHE_BRUSH_ORDER* cacheBrushOrder) +static BOOL update_message_CacheBrush( + rdpContext* context, + const CACHE_BRUSH_ORDER* cacheBrushOrder) { CACHE_BRUSH_ORDER* wParam; @@ -703,7 +740,9 @@ static BOOL update_message_CacheBrush(rdpContext* context, CACHE_BRUSH_ORDER* ca /* Alternate Secondary Update */ -static BOOL update_message_CreateOffscreenBitmap(rdpContext* context, CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) +static BOOL update_message_CreateOffscreenBitmap( + rdpContext* context, + const CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) { CREATE_OFFSCREEN_BITMAP_ORDER* wParam; @@ -726,7 +765,9 @@ static BOOL update_message_CreateOffscreenBitmap(rdpContext* context, CREATE_OFF MakeMessageId(AltSecUpdate, CreateOffscreenBitmap), (void*) wParam, NULL); } -static BOOL update_message_SwitchSurface(rdpContext* context, SWITCH_SURFACE_ORDER* switchSurface) +static BOOL update_message_SwitchSurface( + rdpContext* context, + const SWITCH_SURFACE_ORDER* switchSurface) { SWITCH_SURFACE_ORDER* wParam; @@ -739,7 +780,9 @@ static BOOL update_message_SwitchSurface(rdpContext* context, SWITCH_SURFACE_ORD MakeMessageId(AltSecUpdate, SwitchSurface), (void*) wParam, NULL); } -static BOOL update_message_CreateNineGridBitmap(rdpContext* context, CREATE_NINE_GRID_BITMAP_ORDER* createNineGridBitmap) +static BOOL update_message_CreateNineGridBitmap( + rdpContext* context, + const CREATE_NINE_GRID_BITMAP_ORDER* createNineGridBitmap) { CREATE_NINE_GRID_BITMAP_ORDER* wParam; @@ -752,7 +795,9 @@ static BOOL update_message_CreateNineGridBitmap(rdpContext* context, CREATE_NINE MakeMessageId(AltSecUpdate, CreateNineGridBitmap), (void*) wParam, NULL); } -static BOOL update_message_FrameMarker(rdpContext* context, FRAME_MARKER_ORDER* frameMarker) +static BOOL update_message_FrameMarker( + rdpContext* context, + const FRAME_MARKER_ORDER* frameMarker) { FRAME_MARKER_ORDER* wParam; @@ -765,7 +810,9 @@ static BOOL update_message_FrameMarker(rdpContext* context, FRAME_MARKER_ORDER* MakeMessageId(AltSecUpdate, FrameMarker), (void*) wParam, NULL); } -static BOOL update_message_StreamBitmapFirst(rdpContext* context, STREAM_BITMAP_FIRST_ORDER* streamBitmapFirst) +static BOOL update_message_StreamBitmapFirst( + rdpContext* context, + const STREAM_BITMAP_FIRST_ORDER* streamBitmapFirst) { STREAM_BITMAP_FIRST_ORDER* wParam; @@ -780,7 +827,9 @@ static BOOL update_message_StreamBitmapFirst(rdpContext* context, STREAM_BITMAP_ MakeMessageId(AltSecUpdate, StreamBitmapFirst), (void*) wParam, NULL); } -static BOOL update_message_StreamBitmapNext(rdpContext* context, STREAM_BITMAP_NEXT_ORDER* streamBitmapNext) +static BOOL update_message_StreamBitmapNext( + rdpContext* context, + const STREAM_BITMAP_NEXT_ORDER* streamBitmapNext) { STREAM_BITMAP_NEXT_ORDER* wParam; @@ -795,7 +844,9 @@ static BOOL update_message_StreamBitmapNext(rdpContext* context, STREAM_BITMAP_N MakeMessageId(AltSecUpdate, StreamBitmapNext), (void*) wParam, NULL); } -static BOOL update_message_DrawGdiPlusFirst(rdpContext* context, DRAW_GDIPLUS_FIRST_ORDER* drawGdiPlusFirst) +static BOOL update_message_DrawGdiPlusFirst( + rdpContext* context, + const DRAW_GDIPLUS_FIRST_ORDER* drawGdiPlusFirst) { DRAW_GDIPLUS_FIRST_ORDER* wParam; @@ -810,7 +861,9 @@ static BOOL update_message_DrawGdiPlusFirst(rdpContext* context, DRAW_GDIPLUS_FI MakeMessageId(AltSecUpdate, DrawGdiPlusFirst), (void*) wParam, NULL); } -static BOOL update_message_DrawGdiPlusNext(rdpContext* context, DRAW_GDIPLUS_NEXT_ORDER* drawGdiPlusNext) +static BOOL update_message_DrawGdiPlusNext( + rdpContext* context, + const DRAW_GDIPLUS_NEXT_ORDER* drawGdiPlusNext) { DRAW_GDIPLUS_NEXT_ORDER* wParam; @@ -825,7 +878,9 @@ static BOOL update_message_DrawGdiPlusNext(rdpContext* context, DRAW_GDIPLUS_NEX MakeMessageId(AltSecUpdate, DrawGdiPlusNext), (void*) wParam, NULL); } -static BOOL update_message_DrawGdiPlusEnd(rdpContext* context, DRAW_GDIPLUS_END_ORDER* drawGdiPlusEnd) +static BOOL update_message_DrawGdiPlusEnd( + rdpContext* context, + const DRAW_GDIPLUS_END_ORDER* drawGdiPlusEnd) { DRAW_GDIPLUS_END_ORDER* wParam; @@ -840,7 +895,9 @@ static BOOL update_message_DrawGdiPlusEnd(rdpContext* context, DRAW_GDIPLUS_END_ MakeMessageId(AltSecUpdate, DrawGdiPlusEnd), (void*) wParam, NULL); } -static BOOL update_message_DrawGdiPlusCacheFirst(rdpContext* context, DRAW_GDIPLUS_CACHE_FIRST_ORDER* drawGdiPlusCacheFirst) +static BOOL update_message_DrawGdiPlusCacheFirst( + rdpContext* context, + const DRAW_GDIPLUS_CACHE_FIRST_ORDER* drawGdiPlusCacheFirst) { DRAW_GDIPLUS_CACHE_FIRST_ORDER* wParam; @@ -855,7 +912,9 @@ static BOOL update_message_DrawGdiPlusCacheFirst(rdpContext* context, DRAW_GDIPL MakeMessageId(AltSecUpdate, DrawGdiPlusCacheFirst), (void*) wParam, NULL); } -static BOOL update_message_DrawGdiPlusCacheNext(rdpContext* context, DRAW_GDIPLUS_CACHE_NEXT_ORDER* drawGdiPlusCacheNext) +static BOOL update_message_DrawGdiPlusCacheNext( + rdpContext* context, + const DRAW_GDIPLUS_CACHE_NEXT_ORDER* drawGdiPlusCacheNext) { DRAW_GDIPLUS_CACHE_NEXT_ORDER* wParam; @@ -870,7 +929,9 @@ static BOOL update_message_DrawGdiPlusCacheNext(rdpContext* context, DRAW_GDIPLU MakeMessageId(AltSecUpdate, DrawGdiPlusCacheNext), (void*) wParam, NULL); } -static BOOL update_message_DrawGdiPlusCacheEnd(rdpContext* context, DRAW_GDIPLUS_CACHE_END_ORDER* drawGdiPlusCacheEnd) +static BOOL update_message_DrawGdiPlusCacheEnd( + rdpContext* context, + const DRAW_GDIPLUS_CACHE_END_ORDER* drawGdiPlusCacheEnd) { DRAW_GDIPLUS_CACHE_END_ORDER* wParam; @@ -1125,7 +1186,8 @@ static BOOL update_message_NonMonitoredDesktop(rdpContext* context, WINDOW_ORDER /* Pointer Update */ -static BOOL update_message_PointerPosition(rdpContext* context, POINTER_POSITION_UPDATE* pointerPosition) +static BOOL update_message_PointerPosition(rdpContext* context, + const POINTER_POSITION_UPDATE* pointerPosition) { POINTER_POSITION_UPDATE* wParam; @@ -1138,7 +1200,8 @@ static BOOL update_message_PointerPosition(rdpContext* context, POINTER_POSITION MakeMessageId(PointerUpdate, PointerPosition), (void*) wParam, NULL); } -static BOOL update_message_PointerSystem(rdpContext* context, POINTER_SYSTEM_UPDATE* pointerSystem) +static BOOL update_message_PointerSystem(rdpContext* context, + const POINTER_SYSTEM_UPDATE* pointerSystem) { POINTER_SYSTEM_UPDATE* wParam; @@ -1151,7 +1214,8 @@ static BOOL update_message_PointerSystem(rdpContext* context, POINTER_SYSTEM_UPD MakeMessageId(PointerUpdate, PointerSystem), (void*) wParam, NULL); } -static BOOL update_message_PointerColor(rdpContext* context, POINTER_COLOR_UPDATE* pointerColor) +static BOOL update_message_PointerColor(rdpContext* context, + const POINTER_COLOR_UPDATE* pointerColor) { POINTER_COLOR_UPDATE* wParam; @@ -1188,7 +1252,8 @@ out_fail: return FALSE; } -static BOOL update_message_PointerNew(rdpContext* context, POINTER_NEW_UPDATE* pointerNew) +static BOOL update_message_PointerNew(rdpContext* context, + const POINTER_NEW_UPDATE* pointerNew) { POINTER_NEW_UPDATE* wParam; @@ -1225,7 +1290,8 @@ out_fail: return FALSE; } -static BOOL update_message_PointerCached(rdpContext* context, POINTER_CACHED_UPDATE* pointerCached) +static BOOL update_message_PointerCached(rdpContext* context, + const POINTER_CACHED_UPDATE* pointerCached) { POINTER_CACHED_UPDATE* wParam; diff --git a/libfreerdp/core/orders.c b/libfreerdp/core/orders.c index 49df89add..f41e83a23 100644 --- a/libfreerdp/core/orders.c +++ b/libfreerdp/core/orders.c @@ -3,6 +3,8 @@ * Drawing Orders * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -611,7 +613,8 @@ static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, BYTE fieldFlag return TRUE; } -static INLINE BOOL update_write_brush(wStream* s, rdpBrush* brush, BYTE fieldFlags) +static INLINE BOOL update_write_brush(wStream* s, rdpBrush* brush, + BYTE fieldFlags) { if (fieldFlags & ORDER_FIELD_01) { @@ -840,8 +843,7 @@ static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, int } while(0) /* Primary Drawing Orders */ - -BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt) +static BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt) { ORDER_FIELD_COORD(1, dstblt->nLeftRect); ORDER_FIELD_COORD(2, dstblt->nTopRect); @@ -851,12 +853,14 @@ BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* d return TRUE; } -int update_approximate_dstblt_order(ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt) +int update_approximate_dstblt_order(ORDER_INFO* orderInfo, + const DSTBLT_ORDER* dstblt) { return 32; } -BOOL update_write_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt) +BOOL update_write_dstblt_order(wStream* s, ORDER_INFO* orderInfo, + const DSTBLT_ORDER* dstblt) { if (!Stream_EnsureRemainingCapacity(s, update_approximate_dstblt_order(orderInfo, dstblt))) @@ -882,7 +886,7 @@ BOOL update_write_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* return TRUE; } -BOOL update_read_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt) +static BOOL update_read_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt) { ORDER_FIELD_COORD(1, patblt->nLeftRect); ORDER_FIELD_COORD(2, patblt->nTopRect); @@ -938,7 +942,8 @@ BOOL update_write_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* return TRUE; } -BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt) +static BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, + SCRBLT_ORDER* scrblt) { ORDER_FIELD_COORD(1, scrblt->nLeftRect); ORDER_FIELD_COORD(2, scrblt->nTopRect); @@ -951,12 +956,14 @@ BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* s return TRUE; } -int update_approximate_scrblt_order(ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt) +int update_approximate_scrblt_order(ORDER_INFO* orderInfo, + const SCRBLT_ORDER* scrblt) { return 32; } -BOOL update_write_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt) +BOOL update_write_scrblt_order(wStream* s, ORDER_INFO* orderInfo, + const SCRBLT_ORDER* scrblt) { if (!Stream_EnsureRemainingCapacity(s, update_approximate_scrblt_order(orderInfo, scrblt))) @@ -988,7 +995,8 @@ BOOL update_write_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* return TRUE; } -BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect) +static BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, + OPAQUE_RECT_ORDER* opaque_rect) { BYTE byte; @@ -1027,16 +1035,19 @@ BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_REC return TRUE; } -int update_approximate_opaque_rect_order(ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect) +int update_approximate_opaque_rect_order(ORDER_INFO* orderInfo, + const OPAQUE_RECT_ORDER* opaque_rect) { return 32; } -BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect) +BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, + const OPAQUE_RECT_ORDER* opaque_rect) { BYTE byte; + int inf = update_approximate_opaque_rect_order(orderInfo, opaque_rect); - if (!Stream_EnsureRemainingCapacity(s, update_approximate_opaque_rect_order(orderInfo, opaque_rect))) + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; orderInfo->fieldFlags = 0; @@ -1065,7 +1076,8 @@ BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_RE return TRUE; } -BOOL update_read_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid) +static BOOL update_read_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, + DRAW_NINE_GRID_ORDER* draw_nine_grid) { ORDER_FIELD_COORD(1, draw_nine_grid->srcLeft); ORDER_FIELD_COORD(2, draw_nine_grid->srcTop); @@ -1076,17 +1088,8 @@ BOOL update_read_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, DRAW_NI return TRUE; } -int update_approximate_draw_nine_grid_order(ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid) -{ - return 32; -} - -BOOL update_write_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid) -{ - return TRUE; -} - -BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt) +static BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, + MULTI_DSTBLT_ORDER* multi_dstblt) { ORDER_FIELD_COORD(1, multi_dstblt->nLeftRect); ORDER_FIELD_COORD(2, multi_dstblt->nTopRect); @@ -1108,17 +1111,8 @@ BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DST return TRUE; } -int update_approximate_multi_dstblt_order(ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt) -{ - return 32; -} - -BOOL update_write_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt) -{ - return TRUE; -} - -BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt) +static BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, + MULTI_PATBLT_ORDER* multi_patblt) { ORDER_FIELD_COORD(1, multi_patblt->nLeftRect); ORDER_FIELD_COORD(2, multi_patblt->nTopRect); @@ -1146,17 +1140,8 @@ BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_PAT return TRUE; } -int update_approximate_multi_patblt_order(ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt) -{ - return 32; -} - -BOOL update_write_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt) -{ - return TRUE; -} - -BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt) +static BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, + MULTI_SCRBLT_ORDER* multi_scrblt) { ORDER_FIELD_COORD(1, multi_scrblt->nLeftRect); ORDER_FIELD_COORD(2, multi_scrblt->nTopRect); @@ -1178,17 +1163,9 @@ BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCR return TRUE; } -int update_approximate_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt) -{ - return 32; -} - -BOOL update_write_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt) -{ - return TRUE; -} - -BOOL update_read_multi_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) +static BOOL update_read_multi_opaque_rect_order(wStream* s, + ORDER_INFO* orderInfo, + MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) { BYTE byte; @@ -1237,17 +1214,9 @@ BOOL update_read_multi_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, MULT return TRUE; } -int update_approximate_multi_opaque_rect_order(ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) -{ - return 32; -} - -BOOL update_write_multi_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) -{ - return TRUE; -} - -BOOL update_read_multi_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) +static BOOL update_read_multi_draw_nine_grid_order(wStream* s, + ORDER_INFO* orderInfo, + MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) { ORDER_FIELD_COORD(1, multi_draw_nine_grid->srcLeft); ORDER_FIELD_COORD(2, multi_draw_nine_grid->srcTop); @@ -1264,17 +1233,8 @@ BOOL update_read_multi_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, M return TRUE; } -int update_approximate_multi_draw_nine_grid_order(ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) -{ - return 32; -} - -BOOL update_write_multi_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) -{ - return TRUE; -} - -BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to) +static BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, + LINE_TO_ORDER* line_to) { ORDER_FIELD_UINT16(1, line_to->backMode); ORDER_FIELD_COORD(2, line_to->nXStart); @@ -1289,12 +1249,14 @@ BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* return TRUE; } -int update_approximate_line_to_order(ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to) +int update_approximate_line_to_order(ORDER_INFO* orderInfo, + const LINE_TO_ORDER* line_to) { return 32; } -BOOL update_write_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to) +BOOL update_write_line_to_order(wStream* s, ORDER_INFO* orderInfo, + const LINE_TO_ORDER* line_to) { if (!Stream_EnsureRemainingCapacity(s, update_approximate_line_to_order(orderInfo, line_to))) return FALSE; @@ -1334,7 +1296,8 @@ BOOL update_write_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER return TRUE; } -BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline) +static BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, + POLYLINE_ORDER* polyline) { UINT16 word; UINT32 new_num = polyline->numDeltaEntries; @@ -1372,17 +1335,8 @@ BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDE return TRUE; } -int update_approximate_polyline_order(ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline) -{ - return 32; -} - -BOOL update_write_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline) -{ - return TRUE; -} - -BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt) +static BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, + MEMBLT_ORDER* memblt) { ORDER_FIELD_UINT16(1, memblt->cacheId); ORDER_FIELD_COORD(2, memblt->nLeftRect); @@ -1401,12 +1355,14 @@ BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* m return TRUE; } -int update_approximate_memblt_order(ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt) +int update_approximate_memblt_order(ORDER_INFO* orderInfo, + const MEMBLT_ORDER* memblt) { return 64; } -BOOL update_write_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt) +BOOL update_write_memblt_order(wStream* s, ORDER_INFO* orderInfo, + const MEMBLT_ORDER* memblt) { UINT16 cacheId; @@ -1445,7 +1401,8 @@ BOOL update_write_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* return TRUE; } -BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt) +static BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, + MEM3BLT_ORDER* mem3blt) { ORDER_FIELD_UINT16(1, mem3blt->cacheId); ORDER_FIELD_COORD(2, mem3blt->nLeftRect); @@ -1469,17 +1426,8 @@ BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* return TRUE; } -int update_approximate_mem3blt_order(ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt) -{ - return 32; -} - -BOOL update_write_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt) -{ - return TRUE; -} - -BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap) +static BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, + SAVE_BITMAP_ORDER* save_bitmap) { ORDER_FIELD_UINT32(1, save_bitmap->savedBitmapPosition); ORDER_FIELD_COORD(2, save_bitmap->nLeftRect); @@ -1490,17 +1438,8 @@ BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, SAVE_BITMA return TRUE; } -int update_approximate_save_bitmap_order(ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap) -{ - return 32; -} - -BOOL update_write_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap) -{ - return TRUE; -} - -BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index) +static BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, + GLYPH_INDEX_ORDER* glyph_index) { ORDER_FIELD_BYTE(1, glyph_index->cacheId); ORDER_FIELD_BYTE(2, glyph_index->flAccel); @@ -1540,15 +1479,18 @@ BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_INDE return TRUE; } -int update_approximate_glyph_index_order(ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index) +int update_approximate_glyph_index_order(ORDER_INFO* orderInfo, + const GLYPH_INDEX_ORDER* glyph_index) { return 64; } -BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index) +BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, + GLYPH_INDEX_ORDER* glyph_index) { + int inf = update_approximate_glyph_index_order(orderInfo, glyph_index); - if (!Stream_EnsureRemainingCapacity(s, update_approximate_glyph_index_order(orderInfo, glyph_index))) + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; orderInfo->fieldFlags = 0; @@ -1615,7 +1557,8 @@ BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_IND return TRUE; } -BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index) +static BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, + FAST_INDEX_ORDER* fast_index) { ORDER_FIELD_BYTE(1, fast_index->cacheId); ORDER_FIELD_2BYTE(2, fast_index->ulCharInc, fast_index->flAccel); @@ -1649,17 +1592,8 @@ BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, FAST_INDEX_ return TRUE; } -int update_approximate_fast_index_order(ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index) -{ - return 32; -} - -BOOL update_write_fast_index_order(wStream* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index) -{ - return TRUE; -} - -BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fastGlyph) +static BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, + FAST_GLYPH_ORDER* fastGlyph) { BYTE* phold; GLYPH_DATA_V2* glyph = &fastGlyph->glyphData; @@ -1734,17 +1668,8 @@ BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, FAST_GLYPH_ return TRUE; } -int update_approximate_fast_glyph_order(ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph) -{ - return 32; -} - -BOOL update_write_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph) -{ - return TRUE; -} - -BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc) +static BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, + POLYGON_SC_ORDER* polygon_sc) { UINT32 num = polygon_sc->numPoints; @@ -1777,17 +1702,8 @@ BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_SC_ return TRUE; } -int update_approximate_polygon_sc_order(ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc) -{ - return 32; -} - -BOOL update_write_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc) -{ - return TRUE; -} - -BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb) +static BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, + POLYGON_CB_ORDER* polygon_cb) { UINT32 num = polygon_cb->numPoints; @@ -1828,17 +1744,8 @@ BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_CB_ return TRUE; } -int update_approximate_polygon_cb_order(ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb) -{ - return 32; -} - -BOOL update_write_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb) -{ - return TRUE; -} - -BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc) +static BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, + ELLIPSE_SC_ORDER* ellipse_sc) { ORDER_FIELD_COORD(1, ellipse_sc->leftRect); ORDER_FIELD_COORD(2, ellipse_sc->topRect); @@ -1850,17 +1757,8 @@ BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ return TRUE; } -int update_approximate_ellipse_sc_order(ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc) -{ - return 32; -} - -BOOL update_write_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc) -{ - return TRUE; -} - -BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb) +static BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, + ELLIPSE_CB_ORDER* ellipse_cb) { ORDER_FIELD_COORD(1, ellipse_cb->leftRect); ORDER_FIELD_COORD(2, ellipse_cb->topRect); @@ -1873,19 +1771,9 @@ BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ return update_read_brush(s, &ellipse_cb->brush, orderInfo->fieldFlags >> 8); } -int update_approximate_ellipse_cb_order(ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb) -{ - return 32; -} - -BOOL update_write_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb) -{ - return TRUE; -} - /* Secondary Drawing Orders */ - -BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap, BOOL compressed, UINT16 flags) +static BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap, + BOOL compressed, UINT16 flags) { if (Stream_GetRemainingLength(s) < 9) return FALSE; @@ -1936,28 +1824,32 @@ BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap return TRUE; } -int update_approximate_cache_bitmap_order(CACHE_BITMAP_ORDER* cache_bitmap, BOOL compressed, UINT16* flags) +int update_approximate_cache_bitmap_order(const CACHE_BITMAP_ORDER* cache_bitmap, + BOOL compressed, UINT16* flags) { return 64 + cache_bitmap->bitmapLength; } -BOOL update_write_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap, BOOL compressed, UINT16* flags) +BOOL update_write_cache_bitmap_order(wStream* s, + const CACHE_BITMAP_ORDER* cache_bitmap, + BOOL compressed, UINT16* flags) { - - if (!Stream_EnsureRemainingCapacity(s, update_approximate_cache_bitmap_order(cache_bitmap, compressed, flags))) + UINT32 bitmapLength = cache_bitmap->bitmapLength; + int inf = update_approximate_cache_bitmap_order(cache_bitmap, compressed, flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; *flags = NO_BITMAP_COMPRESSION_HDR; if ((*flags & NO_BITMAP_COMPRESSION_HDR) == 0) - cache_bitmap->bitmapLength += 8; + bitmapLength += 8; Stream_Write_UINT8(s, cache_bitmap->cacheId); /* cacheId (1 byte) */ Stream_Write_UINT8(s, 0); /* pad1Octet (1 byte) */ Stream_Write_UINT8(s, cache_bitmap->bitmapWidth); /* bitmapWidth (1 byte) */ Stream_Write_UINT8(s, cache_bitmap->bitmapHeight); /* bitmapHeight (1 byte) */ Stream_Write_UINT8(s, cache_bitmap->bitmapBpp); /* bitmapBpp (1 byte) */ - Stream_Write_UINT16(s, cache_bitmap->bitmapLength); /* bitmapLength (2 bytes) */ + Stream_Write_UINT16(s, bitmapLength); /* bitmapLength (2 bytes) */ Stream_Write_UINT16(s, cache_bitmap->cacheIndex); /* cacheIndex (2 bytes) */ if (compressed) @@ -1966,20 +1858,22 @@ BOOL update_write_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitma { BYTE* bitmapComprHdr = (BYTE*) &(cache_bitmap->bitmapComprHdr); Stream_Write(s, bitmapComprHdr, 8); /* bitmapComprHdr (8 bytes) */ - cache_bitmap->bitmapLength -= 8; + bitmapLength -= 8; } - Stream_Write(s, cache_bitmap->bitmapDataStream, cache_bitmap->bitmapLength); + Stream_Write(s, cache_bitmap->bitmapDataStream, bitmapLength); } else { - Stream_Write(s, cache_bitmap->bitmapDataStream, cache_bitmap->bitmapLength); + Stream_Write(s, cache_bitmap->bitmapDataStream, bitmapLength); } return TRUE; } -BOOL update_read_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, BOOL compressed, UINT16 flags) +static BOOL update_read_cache_bitmap_v2_order(wStream* s, + CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, + BOOL compressed, UINT16 flags) { BYTE bitsPerPixelId; @@ -2122,7 +2016,9 @@ BOOL update_write_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache return TRUE; } -BOOL update_read_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, UINT16 flags) +static BOOL update_read_cache_bitmap_v3_order(wStream* s, + CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, + UINT16 flags) { BYTE bitsPerPixelId; BITMAP_DATA_EX* bitmapData; @@ -2208,7 +2104,9 @@ BOOL update_write_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache return TRUE; } -BOOL update_read_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* cache_color_table, UINT16 flags) +static BOOL update_read_cache_color_table_order(wStream* s, + CACHE_COLOR_TABLE_ORDER* cache_color_table, + UINT16 flags) { int i; UINT32* colorTable; @@ -2238,20 +2136,24 @@ BOOL update_read_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* ca return TRUE; } -int update_approximate_cache_color_table_order(CACHE_COLOR_TABLE_ORDER* cache_color_table, UINT16* flags) +int update_approximate_cache_color_table_order( + const CACHE_COLOR_TABLE_ORDER* cache_color_table, UINT16* flags) { return 16 + (256 * 4); } -BOOL update_write_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* cache_color_table, UINT16* flags) +BOOL update_write_cache_color_table_order(wStream* s, + const CACHE_COLOR_TABLE_ORDER* cache_color_table, + UINT16* flags) { - int i; + int i, inf; UINT32* colorTable; if (cache_color_table->numberColors != 256) return FALSE; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_cache_color_table_order(cache_color_table, flags))) + inf = update_approximate_cache_color_table_order(cache_color_table, flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; Stream_Write_UINT8(s, cache_color_table->cacheIndex); /* cacheIndex (1 byte) */ @@ -2267,7 +2169,9 @@ BOOL update_write_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* c return TRUE; } -BOOL update_read_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph_order, UINT16 flags) +static BOOL update_read_cache_glyph_order(wStream* s, + CACHE_GLYPH_ORDER* cache_glyph_order, + UINT16 flags) { int i; INT16 lsi16; @@ -2314,18 +2218,22 @@ BOOL update_read_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph_or return TRUE; } -int update_approximate_cache_glyph_order(CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags) +int update_approximate_cache_glyph_order( + const CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags) { return 2 + cache_glyph->cGlyphs * 32; } -BOOL update_write_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags) +BOOL update_write_cache_glyph_order(wStream* s, + const CACHE_GLYPH_ORDER* cache_glyph, + UINT16* flags) { - int i; + int i, inf; INT16 lsi16; - GLYPH_DATA* glyph; + const GLYPH_DATA* glyph; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_cache_glyph_order(cache_glyph, flags))) + inf = update_approximate_cache_glyph_order(cache_glyph, flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; Stream_Write_UINT8(s, cache_glyph->cacheId); /* cacheId (1 byte) */ @@ -2333,6 +2241,8 @@ BOOL update_write_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph, for (i = 0; i < (int) cache_glyph->cGlyphs; i++) { + UINT32 cb; + glyph = &cache_glyph->glyphData[i]; Stream_Write_UINT16(s, glyph->cacheIndex); /* cacheIndex (2 bytes) */ @@ -2346,10 +2256,10 @@ BOOL update_write_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph, Stream_Write_UINT16(s, glyph->cx); /* cx (2 bytes) */ Stream_Write_UINT16(s, glyph->cy); /* cy (2 bytes) */ - glyph->cb = ((glyph->cx + 7) / 8) * glyph->cy; - glyph->cb += ((glyph->cb % 4) > 0) ? 4 - (glyph->cb % 4) : 0; + cb = ((glyph->cx + 7) / 8) * glyph->cy; + cb += ((cb % 4) > 0) ? 4 - (cb % 4) : 0; - Stream_Write(s, glyph->aj, glyph->cb); + Stream_Write(s, glyph->aj, cb); } if (*flags & CG_GLYPH_UNICODE_PRESENT) @@ -2360,7 +2270,9 @@ BOOL update_write_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph, return TRUE; } -BOOL update_read_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16 flags) +static BOOL update_read_cache_glyph_v2_order(wStream* s, + CACHE_GLYPH_V2_ORDER* cache_glyph_v2, + UINT16 flags) { int i; GLYPH_DATA_V2* glyph; @@ -2406,17 +2318,20 @@ BOOL update_read_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_gl return TRUE; } -int update_approximate_cache_glyph_v2_order(CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16* flags) +int update_approximate_cache_glyph_v2_order( + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16* flags) { return 8 + cache_glyph_v2->cGlyphs * 32; } -BOOL update_write_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16* flags) +BOOL update_write_cache_glyph_v2_order(wStream* s, + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, + UINT16* flags) { - int i; - GLYPH_DATA_V2* glyph; + int i, inf; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_cache_glyph_v2_order(cache_glyph_v2, flags))) + inf = update_approximate_cache_glyph_v2_order(cache_glyph_v2, flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; *flags = (cache_glyph_v2->cacheId & 0x000F) | @@ -2425,7 +2340,8 @@ BOOL update_write_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_g for (i = 0; i < (int) cache_glyph_v2->cGlyphs; i++) { - glyph = &cache_glyph_v2->glyphData[i]; + UINT32 cb; + const GLYPH_DATA_V2* glyph = &cache_glyph_v2->glyphData[i]; Stream_Write_UINT8(s, glyph->cacheIndex); @@ -2437,9 +2353,9 @@ BOOL update_write_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_g return FALSE; } - glyph->cb = ((glyph->cx + 7) / 8) * glyph->cy; - glyph->cb += ((glyph->cb % 4) > 0) ? 4 - (glyph->cb % 4) : 0; - Stream_Write(s, glyph->aj, glyph->cb); + cb = ((glyph->cx + 7) / 8) * glyph->cy; + cb += ((cb % 4) > 0) ? 4 - (cb % 4) : 0; + Stream_Write(s, glyph->aj, cb); } if (*flags & CG_GLYPH_UNICODE_PRESENT) @@ -2450,7 +2366,7 @@ BOOL update_write_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_g return TRUE; } -BOOL update_decompress_brush(wStream* s, BYTE* output, BYTE bpp) +static BOOL update_decompress_brush(wStream* s, BYTE* output, BYTE bpp) { int index; int x, y, k; @@ -2483,12 +2399,14 @@ BOOL update_decompress_brush(wStream* s, BYTE* output, BYTE bpp) return TRUE; } -BOOL update_compress_brush(wStream* s, BYTE* input, BYTE bpp) +static BOOL update_compress_brush(wStream* s, const BYTE* input, BYTE bpp) { return FALSE; } -BOOL update_read_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush, UINT16 flags) +static BOOL update_read_cache_brush_order(wStream* s, + CACHE_BRUSH_ORDER* cache_brush, + UINT16 flags) { int i; int size; @@ -2563,12 +2481,15 @@ BOOL update_read_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush, U return TRUE; } -int update_approximate_cache_brush_order(CACHE_BRUSH_ORDER* cache_brush, UINT16* flags) +int update_approximate_cache_brush_order( + const CACHE_BRUSH_ORDER* cache_brush, UINT16* flags) { return 64; } -BOOL update_write_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush, UINT16* flags) +BOOL update_write_cache_brush_order(wStream* s, + const CACHE_BRUSH_ORDER* cache_brush, + UINT16* flags) { int i; int size; @@ -2637,8 +2558,8 @@ BOOL update_write_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush, } /* Alternate Secondary Drawing Orders */ - -BOOL update_read_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) +static BOOL update_read_create_offscreen_bitmap_order(wStream* s, + CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { UINT16 flags; BOOL deleteListPresent; @@ -2693,17 +2614,20 @@ BOOL update_read_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BITM return TRUE; } -int update_approximate_create_offscreen_bitmap_order(CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) +int update_approximate_create_offscreen_bitmap_order( + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { - OFFSCREEN_DELETE_LIST* deleteList = &(create_offscreen_bitmap->deleteList); + const OFFSCREEN_DELETE_LIST* deleteList = &(create_offscreen_bitmap->deleteList); return 32 + deleteList->cIndices * 2; } -BOOL update_write_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) +BOOL update_write_create_offscreen_bitmap_order( + wStream* s, + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { UINT16 flags; BOOL deleteListPresent; - OFFSCREEN_DELETE_LIST* deleteList; + const OFFSCREEN_DELETE_LIST* deleteList; if (!Stream_EnsureRemainingCapacity(s, update_approximate_create_offscreen_bitmap_order(create_offscreen_bitmap))) return FALSE; @@ -2737,7 +2661,8 @@ BOOL update_write_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BIT return TRUE; } -BOOL update_read_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_surface) +static BOOL update_read_switch_surface_order(wStream* s, + SWITCH_SURFACE_ORDER* switch_surface) { if (Stream_GetRemainingLength(s) < 2) return FALSE; @@ -2747,14 +2672,17 @@ BOOL update_read_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_s return TRUE; } -int update_approximate_switch_surface_order(SWITCH_SURFACE_ORDER* switch_surface) +int update_approximate_switch_surface_order( + const SWITCH_SURFACE_ORDER* switch_surface) { return 2; } -BOOL update_write_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_surface) +BOOL update_write_switch_surface_order( + wStream* s, const SWITCH_SURFACE_ORDER* switch_surface) { - if (!Stream_EnsureRemainingCapacity(s, update_approximate_switch_surface_order(switch_surface))) + int inf = update_approximate_switch_surface_order(switch_surface); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; Stream_Write_UINT16(s, switch_surface->bitmapId); /* bitmapId (2 bytes) */ @@ -2762,7 +2690,9 @@ BOOL update_write_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_ return TRUE; } -BOOL update_read_create_nine_grid_bitmap_order(wStream* s, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap) +static BOOL update_read_create_nine_grid_bitmap_order( + wStream* s, + CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap) { NINE_GRID_BITMAP_INFO* nineGridInfo; @@ -2788,7 +2718,8 @@ BOOL update_read_create_nine_grid_bitmap_order(wStream* s, CREATE_NINE_GRID_BITM return TRUE; } -BOOL update_read_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker) +static BOOL update_read_frame_marker_order(wStream* s, + FRAME_MARKER_ORDER* frame_marker) { if (Stream_GetRemainingLength(s) < 4) return FALSE; @@ -2798,12 +2729,8 @@ BOOL update_read_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker return TRUE; } -BOOL update_write_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker) -{ - return TRUE; -} - -BOOL update_read_stream_bitmap_first_order(wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first) +static BOOL update_read_stream_bitmap_first_order( + wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first) { if (Stream_GetRemainingLength(s) < 10) // 8 + 2 at least return FALSE; @@ -2840,12 +2767,8 @@ BOOL update_read_stream_bitmap_first_order(wStream* s, STREAM_BITMAP_FIRST_ORDER return TRUE; } -BOOL update_write_stream_bitmap_first_order(wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first) -{ - return TRUE; -} - -BOOL update_read_stream_bitmap_next_order(wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next) +static BOOL update_read_stream_bitmap_next_order( + wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next) { if (Stream_GetRemainingLength(s) < 5) return FALSE; @@ -2857,12 +2780,8 @@ BOOL update_read_stream_bitmap_next_order(wStream* s, STREAM_BITMAP_NEXT_ORDER* return TRUE; } -BOOL update_write_stream_bitmap_next_order(wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next) -{ - return TRUE; -} - -BOOL update_read_draw_gdiplus_first_order(wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first) +static BOOL update_read_draw_gdiplus_first_order( + wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first) { if (Stream_GetRemainingLength(s) < 11) return FALSE; @@ -2875,12 +2794,8 @@ BOOL update_read_draw_gdiplus_first_order(wStream* s, DRAW_GDIPLUS_FIRST_ORDER* return Stream_SafeSeek(s, draw_gdiplus_first->cbSize); /* emfRecords */ } -BOOL update_write_draw_gdiplus_first_order(wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first) -{ - return TRUE; -} - -BOOL update_read_draw_gdiplus_next_order(wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next) +static BOOL update_read_draw_gdiplus_next_order( + wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next) { if (Stream_GetRemainingLength(s) < 3) return FALSE; @@ -2891,12 +2806,8 @@ BOOL update_read_draw_gdiplus_next_order(wStream* s, DRAW_GDIPLUS_NEXT_ORDER* dr return TRUE; } -BOOL update_write_draw_gdiplus_next_order(wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next) -{ - return TRUE; -} - -BOOL update_read_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end) +static BOOL update_read_draw_gdiplus_end_order( + wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end) { if (Stream_GetRemainingLength(s) < 11) return FALSE; @@ -2909,12 +2820,8 @@ BOOL update_read_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw return Stream_SafeSeek(s, draw_gdiplus_end->cbSize); /* emfRecords */ } -BOOL update_write_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end) -{ - return TRUE; -} - -BOOL update_read_draw_gdiplus_cache_first_order(wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first) +static BOOL update_read_draw_gdiplus_cache_first_order( + wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first) { if (Stream_GetRemainingLength(s) < 11) return FALSE; @@ -2928,12 +2835,8 @@ BOOL update_read_draw_gdiplus_cache_first_order(wStream* s, DRAW_GDIPLUS_CACHE_F return Stream_SafeSeek(s, draw_gdiplus_cache_first->cbSize); /* emfRecords */ } -BOOL update_write_draw_gdiplus_cache_first_order(wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first) -{ - return TRUE; -} - -BOOL update_read_draw_gdiplus_cache_next_order(wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next) +static BOOL update_read_draw_gdiplus_cache_next_order( + wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next) { if (Stream_GetRemainingLength(s) < 7) return FALSE; @@ -2946,12 +2849,8 @@ BOOL update_read_draw_gdiplus_cache_next_order(wStream* s, DRAW_GDIPLUS_CACHE_NE return TRUE; } -BOOL update_write_draw_gdiplus_cache_next_order(wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next) -{ - return TRUE; -} - -BOOL update_read_draw_gdiplus_cache_end_order(wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end) +static BOOL update_read_draw_gdiplus_cache_end_order( + wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end) { if (Stream_GetRemainingLength(s) < 11) return FALSE; @@ -2965,12 +2864,7 @@ BOOL update_read_draw_gdiplus_cache_end_order(wStream* s, DRAW_GDIPLUS_CACHE_END return Stream_SafeSeek(s, draw_gdiplus_cache_end->cbSize); /* emfRecords */ } -BOOL update_write_draw_gdiplus_cache_end_order(wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end) -{ - return TRUE; -} - -BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, BYTE fieldBytes) +static BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, BYTE fieldBytes) { int i; BYTE byte; @@ -3032,7 +2926,7 @@ BOOL update_write_field_flags(wStream* s, UINT32 fieldFlags, BYTE flags, BYTE fi return TRUE; } -BOOL update_read_bounds(wStream* s, rdpBounds* bounds) +static BOOL update_read_bounds(wStream* s, rdpBounds* bounds) { BYTE flags; diff --git a/libfreerdp/core/orders.h b/libfreerdp/core/orders.h index d4d161b8b..73a0ed64f 100644 --- a/libfreerdp/core/orders.h +++ b/libfreerdp/core/orders.h @@ -3,6 +3,8 @@ * Drawing Orders * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -186,166 +188,104 @@ #define CG_GLYPH_UNICODE_PRESENT 0x0010 +extern const BYTE PRIMARY_DRAWING_ORDER_FIELD_BYTES[]; + BOOL update_recv_order(rdpUpdate* update, wStream* s); -BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, BYTE fieldBytes); -BOOL update_write_field_flags(wStream* s, UINT32 fieldFlags, BYTE flags, BYTE fieldBytes); +BOOL update_write_field_flags(wStream* s, UINT32 fieldFlags, BYTE flags, + BYTE fieldBytes); -BOOL update_read_bounds(wStream* s, rdpBounds* bounds); BOOL update_write_bounds(wStream* s, ORDER_INFO* orderInfo); -BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt); -int update_approximate_dstblt_order(ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt); -BOOL update_write_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt); +int update_approximate_dstblt_order(ORDER_INFO* orderInfo, + const DSTBLT_ORDER* dstblt); +BOOL update_write_dstblt_order(wStream* s, ORDER_INFO* orderInfo, + const DSTBLT_ORDER* dstblt); -BOOL update_read_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt); -int update_approximate_patblt_order(ORDER_INFO* orderInfo, PATBLT_ORDER* patblt); -BOOL update_write_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt); +int update_approximate_patblt_order(ORDER_INFO* orderInfo, + PATBLT_ORDER* patblt); +BOOL update_write_patblt_order(wStream* s, ORDER_INFO* orderInfo, + PATBLT_ORDER* patblt); -BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt); -int update_approximate_scrblt_order(ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt); -BOOL update_write_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt); +int update_approximate_scrblt_order(ORDER_INFO* orderInfo, + const SCRBLT_ORDER* scrblt); +BOOL update_write_scrblt_order(wStream* s, ORDER_INFO* orderInfo, + const SCRBLT_ORDER* scrblt); -BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect); -int update_approximate_opaque_rect_order(ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect); -BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect); +int update_approximate_opaque_rect_order(ORDER_INFO* orderInfo, + const OPAQUE_RECT_ORDER* opaque_rect); +BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, + const OPAQUE_RECT_ORDER* opaque_rect); -BOOL update_read_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid); -int update_approximate_draw_nine_grid_order(ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid); -BOOL update_write_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid); +int update_approximate_line_to_order(ORDER_INFO* orderInfo, + const LINE_TO_ORDER* line_to); +BOOL update_write_line_to_order(wStream* s, ORDER_INFO* orderInfo, + const LINE_TO_ORDER* line_to); -BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt); -int update_approximate_multi_dstblt_order(ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt); -BOOL update_write_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt); +int update_approximate_memblt_order(ORDER_INFO* orderInfo, + const MEMBLT_ORDER* memblt); +BOOL update_write_memblt_order(wStream* s, ORDER_INFO* orderInfo, + const MEMBLT_ORDER* memblt); -BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt); -int update_approximate_multi_patblt_order(ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt); -BOOL update_write_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt); +int update_approximate_glyph_index_order(ORDER_INFO* orderInfo, + const GLYPH_INDEX_ORDER* glyph_index); +BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, + GLYPH_INDEX_ORDER* glyph_index); -BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt); -int update_approximate_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt); -BOOL update_write_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt); +int update_approximate_cache_bitmap_order(const CACHE_BITMAP_ORDER* cache_bitmap, + BOOL compressed, UINT16* flags); +BOOL update_write_cache_bitmap_order(wStream* s, const CACHE_BITMAP_ORDER* cache_bitmap_order, + BOOL compressed, UINT16* flags); -BOOL update_read_multi_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); -int update_approximate_multi_opaque_rect_order(ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); -BOOL update_write_multi_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); +int update_approximate_cache_bitmap_v2_order(CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, + BOOL compressed, UINT16* flags); +BOOL update_write_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order, + BOOL compressed, UINT16* flags); -BOOL update_read_multi_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); -int update_approximate_multi_draw_nine_grid_order(ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); -BOOL update_write_multi_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); +int update_approximate_cache_bitmap_v3_order(CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, + UINT16* flags); +BOOL update_write_cache_bitmap_v3_order(wStream* s, + CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order, + UINT16* flags); -BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to); -int update_approximate_line_to_order(ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to); -BOOL update_write_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to); +int update_approximate_cache_color_table_order(const CACHE_COLOR_TABLE_ORDER* cache_color_table, + UINT16* flags); +BOOL update_write_cache_color_table_order(wStream* s, + const CACHE_COLOR_TABLE_ORDER* cache_color_table_order, + UINT16* flags); -BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline); -int update_approximate_polyline_order(ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline); -BOOL update_write_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline); +int update_approximate_cache_glyph_order(const CACHE_GLYPH_ORDER* cache_glyph, + UINT16* flags); +BOOL update_write_cache_glyph_order(wStream* s, + const CACHE_GLYPH_ORDER* cache_glyph_order, + UINT16* flags); -BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt); -int update_approximate_memblt_order(ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt); -BOOL update_write_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt); +int update_approximate_cache_glyph_v2_order( + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, + UINT16* flags); +BOOL update_write_cache_glyph_v2_order( + wStream* s, + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, + UINT16* flags); -BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt); -int update_approximate_mem3blt_order(ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt); -BOOL update_write_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt); +int update_approximate_cache_brush_order( + const CACHE_BRUSH_ORDER* cache_brush, + UINT16* flags); +BOOL update_write_cache_brush_order( + wStream* s, + const CACHE_BRUSH_ORDER* cache_brush_order, + UINT16* flags); -BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap); -int update_approximate_save_bitmap_order(ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap); -BOOL update_write_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap); +int update_approximate_create_offscreen_bitmap_order( + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); +BOOL update_write_create_offscreen_bitmap_order( + wStream* s, + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); -BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index); -int update_approximate_glyph_index_order(ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index); -BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index); - -BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index); -int update_approximate_fast_index_order(ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index); -BOOL update_write_fast_index_order(wStream* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index); - -BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph); -int update_approximate_fast_glyph_order(ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph); -BOOL update_write_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph); - -BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc); -int update_approximate_polygon_sc_order(ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc); -BOOL update_write_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc); - -BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb); -int update_approximate_polygon_cb_order(ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb); -BOOL update_write_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb); - -BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc); -int update_approximate_ellipse_sc_order(ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc); -BOOL update_write_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc); - -BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb); -int update_approximate_ellipse_cb_order(ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb); -BOOL update_write_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb); - -BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap_order, BOOL compressed, UINT16 flags); -int update_approximate_cache_bitmap_order(CACHE_BITMAP_ORDER* cache_bitmap, BOOL compressed, UINT16* flags); -BOOL update_write_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap_order, BOOL compressed, UINT16* flags); - -BOOL update_read_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order, BOOL compressed, UINT16 flags); -int update_approximate_cache_bitmap_v2_order(CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, BOOL compressed, UINT16* flags); -BOOL update_write_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order, BOOL compressed, UINT16* flags); - -BOOL update_read_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order, UINT16 flags); -int update_approximate_cache_bitmap_v3_order(CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, UINT16* flags); -BOOL update_write_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order, UINT16* flags); - -BOOL update_read_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* cache_color_table_order, UINT16 flags); -int update_approximate_cache_color_table_order(CACHE_COLOR_TABLE_ORDER* cache_color_table, UINT16* flags); -BOOL update_write_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* cache_color_table_order, UINT16* flags); - -BOOL update_read_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph_order, UINT16 flags); -int update_approximate_cache_glyph_order(CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags); -BOOL update_write_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph_order, UINT16* flags); - -BOOL update_read_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order, UINT16 flags); -int update_approximate_cache_glyph_v2_order(CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16* flags); -BOOL update_write_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16* flags); - -BOOL update_read_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush_order, UINT16 flags); -int update_approximate_cache_brush_order(CACHE_BRUSH_ORDER* cache_brush, UINT16* flags); -BOOL update_write_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush_order, UINT16* flags); - -BOOL update_read_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); -int update_approximate_create_offscreen_bitmap_order(CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); -BOOL update_write_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); - -BOOL update_read_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_surface); -int update_approximate_switch_surface_order(SWITCH_SURFACE_ORDER* switch_surface); -BOOL update_write_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_surface); - -BOOL update_read_create_nine_grid_bitmap_order(wStream* s, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap); -BOOL update_write_create_nine_grid_bitmap_order(wStream* s, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap); - -BOOL update_read_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker); -BOOL update_write_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker); - -BOOL update_read_stream_bitmap_first_order(wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first); -BOOL update_write_stream_bitmap_first_order(wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first); - -BOOL update_read_stream_bitmap_next_order(wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next); -BOOL update_write_stream_bitmap_next_order(wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next); - -BOOL update_read_draw_gdiplus_first_order(wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first); -BOOL update_write_draw_gdiplus_first_order(wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first); - -BOOL update_read_draw_gdiplus_next_order(wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next); -BOOL update_write_draw_gdiplus_next_order(wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next); - -BOOL update_read_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end); -BOOL update_write_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end); - -BOOL update_read_draw_gdiplus_cache_first_order(wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first); -BOOL update_write_draw_gdiplus_cache_first_order(wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first); - -BOOL update_read_draw_gdiplus_cache_next_order(wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next); -BOOL update_write_draw_gdiplus_cache_next_order(wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next); - -BOOL update_read_draw_gdiplus_cache_end_order(wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end); -BOOL update_write_draw_gdiplus_cache_end_order(wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end); +int update_approximate_switch_surface_order( + const SWITCH_SURFACE_ORDER* switch_surface); +BOOL update_write_switch_surface_order( + wStream* s, + const SWITCH_SURFACE_ORDER* switch_surface); #endif /* __ORDERS_H */ diff --git a/libfreerdp/core/surface.c b/libfreerdp/core/surface.c index c568fe005..8c26e8b8f 100644 --- a/libfreerdp/core/surface.c +++ b/libfreerdp/core/surface.c @@ -137,7 +137,8 @@ int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s) return 0; } -BOOL update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd) +BOOL update_write_surfcmd_surface_bits_header(wStream* s, + const SURFACE_BITS_COMMAND* cmd) { if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH)) return FALSE; diff --git a/libfreerdp/core/surface.h b/libfreerdp/core/surface.h index 610b6a4ff..a2a0b0e69 100644 --- a/libfreerdp/core/surface.h +++ b/libfreerdp/core/surface.h @@ -36,7 +36,8 @@ enum SURFCMD_CMDTYPE int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s); -BOOL update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd); +BOOL update_write_surfcmd_surface_bits_header(wStream* s, + const SURFACE_BITS_COMMAND* cmd); BOOL update_write_surfcmd_frame_marker(wStream* s, UINT16 frameAction, UINT32 frameId); #endif /* __SURFACE */ diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index f8b2dad02..2746903e7 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -3,6 +3,8 @@ * Update Data PDUs * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +49,6 @@ const char* const UPDATE_TYPE_STRINGS[] = "Synchronize" }; -extern const BYTE PRIMARY_DRAWING_ORDER_FIELD_BYTES[]; - BOOL update_recv_orders(rdpUpdate* update, wStream* s) { UINT16 numberOrders; @@ -207,7 +207,8 @@ BOOL update_read_bitmap_update(rdpUpdate* update, wStream* s, BITMAP_UPDATE* bit return TRUE; } -BOOL update_write_bitmap_update(rdpUpdate* update, wStream* s, BITMAP_UPDATE* bitmapUpdate) +static BOOL update_write_bitmap_update(rdpUpdate* update, wStream* s, + const BITMAP_UPDATE* bitmapUpdate) { int i; @@ -709,7 +710,8 @@ static BOOL update_check_flush(rdpContext* context, int size) return FALSE; } -static BOOL update_set_bounds(rdpContext* context, rdpBounds* bounds) +static BOOL update_set_bounds(rdpContext* context, + const rdpBounds* bounds) { rdpUpdate* update = context->update; @@ -793,7 +795,8 @@ int update_prepare_bounds(rdpContext* context, ORDER_INFO* orderInfo) return length; } -int update_prepare_order_info(rdpContext* context, ORDER_INFO* orderInfo, UINT32 orderType) +static int update_prepare_order_info(rdpContext* context, + ORDER_INFO* orderInfo, UINT32 orderType) { int length = 1; @@ -812,7 +815,8 @@ int update_prepare_order_info(rdpContext* context, ORDER_INFO* orderInfo, UINT32 return length; } -int update_write_order_info(rdpContext* context, wStream* s, ORDER_INFO* orderInfo, int offset) +int update_write_order_info(rdpContext* context, wStream* s, + ORDER_INFO* orderInfo, int offset) { int position; @@ -834,7 +838,8 @@ int update_write_order_info(rdpContext* context, wStream* s, ORDER_INFO* orderIn return 0; } -static void update_write_refresh_rect(wStream* s, BYTE count, RECTANGLE_16* areas) +static void update_write_refresh_rect(wStream* s, BYTE count, + const RECTANGLE_16* areas) { int i; @@ -850,7 +855,8 @@ static void update_write_refresh_rect(wStream* s, BYTE count, RECTANGLE_16* area } } -static BOOL update_send_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) +static BOOL update_send_refresh_rect(rdpContext* context, BYTE count, + const RECTANGLE_16* areas) { wStream* s; rdpRdp* rdp = context->rdp; @@ -870,7 +876,8 @@ static BOOL update_send_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_ return TRUE; } -static void update_write_suppress_output(wStream* s, BYTE allow, RECTANGLE_16* area) +static void update_write_suppress_output(wStream* s, BYTE allow, + const RECTANGLE_16* area) { Stream_Write_UINT8(s, allow); /* allowDisplayUpdates (1 byte) */ /* Use zeros for padding (like mstsc) for compatibility with legacy servers */ @@ -885,7 +892,8 @@ static void update_write_suppress_output(wStream* s, BYTE allow, RECTANGLE_16* a } } -static BOOL update_send_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area) +static BOOL update_send_suppress_output(rdpContext* context, BYTE allow, + const RECTANGLE_16* area) { wStream* s; rdpRdp* rdp = context->rdp; @@ -927,7 +935,8 @@ out: return ret; } -static BOOL update_send_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surfaceBitsCommand) +static BOOL update_send_surface_bits(rdpContext* context, + const SURFACE_BITS_COMMAND* surfaceBitsCommand) { wStream* s; rdpRdp* rdp = context->rdp; @@ -956,7 +965,8 @@ out_fail: return ret; } -static BOOL update_send_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surfaceFrameMarker) +static BOOL update_send_surface_frame_marker(rdpContext* context, + const SURFACE_FRAME_MARKER* surfaceFrameMarker) { wStream* s; rdpRdp* rdp = context->rdp; @@ -980,7 +990,9 @@ out_fail: return ret; } -static BOOL update_send_surface_frame_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd, BOOL first, BOOL last, UINT32 frameId) +static BOOL update_send_surface_frame_bits(rdpContext* context, + const SURFACE_BITS_COMMAND* cmd, + BOOL first, BOOL last, UINT32 frameId) { wStream* s; rdpRdp* rdp = context->rdp; @@ -1059,7 +1071,8 @@ static BOOL update_send_desktop_resize(rdpContext* context) return rdp_server_reactivate(context->rdp); } -static BOOL update_send_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) +static BOOL update_send_bitmap_update(rdpContext* context, + const BITMAP_UPDATE* bitmapUpdate) { wStream* s; rdpRdp* rdp = context->rdp; @@ -1085,7 +1098,8 @@ out_fail: return ret; } -static BOOL update_send_play_sound(rdpContext* context, PLAY_SOUND_UPDATE* play_sound) +static BOOL update_send_play_sound(rdpContext* context, + const PLAY_SOUND_UPDATE* play_sound) { wStream* s; rdpRdp* rdp = context->rdp; @@ -1107,17 +1121,20 @@ static BOOL update_send_play_sound(rdpContext* context, PLAY_SOUND_UPDATE* play_ * Primary Drawing Orders */ -static BOOL update_send_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) +static BOOL update_send_dstblt(rdpContext* context, + const DSTBLT_ORDER* dstblt) { wStream* s; - int offset; - int headerLength; + UINT32 offset; + UINT32 headerLength; ORDER_INFO orderInfo; + int inf; rdpUpdate* update = context->update; headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_DSTBLT); - update_check_flush(context, headerLength + update_approximate_dstblt_order(&orderInfo, dstblt)); + inf = update_approximate_dstblt_order(&orderInfo, dstblt); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1164,17 +1181,19 @@ static BOOL update_send_patblt(rdpContext* context, PATBLT_ORDER* patblt) return TRUE; } -static BOOL update_send_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) +static BOOL update_send_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt) { wStream* s; - int offset; - int headerLength; + UINT32 offset; + UINT32 headerLength; ORDER_INFO orderInfo; + int inf; rdpUpdate* update = context->update; headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_SCRBLT); - update_check_flush(context, headerLength + update_approximate_scrblt_order(&orderInfo, scrblt)); + inf = update_approximate_scrblt_order(&orderInfo, scrblt); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1192,7 +1211,8 @@ static BOOL update_send_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) return TRUE; } -static BOOL update_send_opaque_rect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect) +static BOOL update_send_opaque_rect(rdpContext* context, + const OPAQUE_RECT_ORDER* opaque_rect) { wStream* s; int offset; @@ -1220,17 +1240,20 @@ static BOOL update_send_opaque_rect(rdpContext* context, OPAQUE_RECT_ORDER* opaq return TRUE; } -static BOOL update_send_line_to(rdpContext* context, LINE_TO_ORDER* line_to) +static BOOL update_send_line_to(rdpContext* context, + const LINE_TO_ORDER* line_to) { wStream* s; int offset; int headerLength; ORDER_INFO orderInfo; + int inf; rdpUpdate* update = context->update; headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_LINE_TO); - update_check_flush(context, headerLength + update_approximate_line_to_order(&orderInfo, line_to)); + inf = update_approximate_line_to_order(&orderInfo, line_to); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1276,17 +1299,20 @@ static BOOL update_send_memblt(rdpContext* context, MEMBLT_ORDER* memblt) return TRUE; } -static BOOL update_send_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyph_index) +static BOOL update_send_glyph_index(rdpContext* context, + GLYPH_INDEX_ORDER* glyph_index) { wStream* s; int offset; int headerLength; + int inf; ORDER_INFO orderInfo; rdpUpdate* update = context->update; headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_GLYPH_INDEX); - update_check_flush(context, headerLength + update_approximate_glyph_index_order(&orderInfo, glyph_index)); + inf = update_approximate_glyph_index_order(&orderInfo, glyph_index); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1308,12 +1334,14 @@ static BOOL update_send_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyp * Secondary Drawing Orders */ -static BOOL update_send_cache_bitmap(rdpContext* context, CACHE_BITMAP_ORDER* cache_bitmap) +static BOOL update_send_cache_bitmap(rdpContext* context, + const CACHE_BITMAP_ORDER* cache_bitmap) { wStream* s; int bm, em; BYTE orderType; int headerLength; + int inf; UINT16 extraFlags; INT16 orderLength; rdpUpdate* update = context->update; @@ -1324,7 +1352,10 @@ static BOOL update_send_cache_bitmap(rdpContext* context, CACHE_BITMAP_ORDER* ca orderType = cache_bitmap->compressed ? ORDER_TYPE_CACHE_BITMAP_COMPRESSED : ORDER_TYPE_BITMAP_UNCOMPRESSED; - update_check_flush(context, headerLength + update_approximate_cache_bitmap_order(cache_bitmap, cache_bitmap->compressed, &extraFlags)); + inf = update_approximate_cache_bitmap_order(cache_bitmap, + cache_bitmap->compressed, + &extraFlags); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1450,11 +1481,12 @@ static BOOL update_send_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORD return TRUE; } -static BOOL update_send_cache_color_table(rdpContext* context, CACHE_COLOR_TABLE_ORDER* cache_color_table) +static BOOL update_send_cache_color_table(rdpContext* context, + const CACHE_COLOR_TABLE_ORDER* cache_color_table) { wStream* s; UINT16 flags; - int bm, em; + int bm, em, inf; int headerLength; INT16 orderLength; rdpUpdate* update = context->update; @@ -1462,7 +1494,8 @@ static BOOL update_send_cache_color_table(rdpContext* context, CACHE_COLOR_TABLE flags = 0; headerLength = 6; - update_check_flush(context, headerLength + update_approximate_cache_color_table_order(cache_color_table, &flags)); + inf = update_approximate_cache_color_table_order(cache_color_table, &flags); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1493,11 +1526,12 @@ static BOOL update_send_cache_color_table(rdpContext* context, CACHE_COLOR_TABLE return TRUE; } -static BOOL update_send_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cache_glyph) +static BOOL update_send_cache_glyph(rdpContext* context, + const CACHE_GLYPH_ORDER* cache_glyph) { wStream* s; UINT16 flags; - int bm, em; + int bm, em, inf; int headerLength; INT16 orderLength; rdpUpdate* update = context->update; @@ -1505,7 +1539,8 @@ static BOOL update_send_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cach flags = 0; headerLength = 6; - update_check_flush(context, headerLength + update_approximate_cache_glyph_order(cache_glyph, &flags)); + inf = update_approximate_cache_glyph_order(cache_glyph, &flags); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1535,11 +1570,12 @@ static BOOL update_send_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cach return TRUE; } -static BOOL update_send_cache_glyph_v2(rdpContext* context, CACHE_GLYPH_V2_ORDER* cache_glyph_v2) +static BOOL update_send_cache_glyph_v2(rdpContext* context, + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2) { wStream* s; UINT16 flags; - int bm, em; + int bm, em, inf; int headerLength; INT16 orderLength; rdpUpdate* update = context->update; @@ -1547,7 +1583,8 @@ static BOOL update_send_cache_glyph_v2(rdpContext* context, CACHE_GLYPH_V2_ORDER flags = 0; headerLength = 6; - update_check_flush(context, headerLength + update_approximate_cache_glyph_v2_order(cache_glyph_v2, &flags)); + inf = update_approximate_cache_glyph_v2_order(cache_glyph_v2, &flags); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1577,11 +1614,12 @@ static BOOL update_send_cache_glyph_v2(rdpContext* context, CACHE_GLYPH_V2_ORDER return TRUE; } -static BOOL update_send_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cache_brush) +static BOOL update_send_cache_brush(rdpContext* context, + const CACHE_BRUSH_ORDER* cache_brush) { wStream* s; UINT16 flags; - int bm, em; + int bm, em, inf; int headerLength; INT16 orderLength; rdpUpdate* update = context->update; @@ -1589,7 +1627,8 @@ static BOOL update_send_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cach flags = 0; headerLength = 6; - update_check_flush(context, headerLength + update_approximate_cache_brush_order(cache_brush, &flags)); + inf = update_approximate_cache_brush_order(cache_brush, &flags); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1622,10 +1661,12 @@ static BOOL update_send_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cach * Alternate Secondary Drawing Orders */ -static BOOL update_send_create_offscreen_bitmap_order(rdpContext* context, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) +static BOOL update_send_create_offscreen_bitmap_order( + rdpContext* context, + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { wStream* s; - int bm, em; + int bm, em, inf; BYTE orderType; BYTE controlFlags; int headerLength; @@ -1635,7 +1676,8 @@ static BOOL update_send_create_offscreen_bitmap_order(rdpContext* context, CREAT orderType = ORDER_TYPE_CREATE_OFFSCREEN_BITMAP; controlFlags = ORDER_SECONDARY | (orderType << 2); - update_check_flush(context, headerLength + 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) @@ -1658,10 +1700,12 @@ static BOOL update_send_create_offscreen_bitmap_order(rdpContext* context, CREAT return TRUE; } -static BOOL update_send_switch_surface_order(rdpContext* context, SWITCH_SURFACE_ORDER* switch_surface) +static BOOL update_send_switch_surface_order( + rdpContext* context, + const SWITCH_SURFACE_ORDER* switch_surface) { wStream* s; - int bm, em; + int bm, em, inf; BYTE orderType; BYTE controlFlags; int headerLength; @@ -1671,7 +1715,8 @@ static BOOL update_send_switch_surface_order(rdpContext* context, SWITCH_SURFACE orderType = ORDER_TYPE_SWITCH_SURFACE; controlFlags = ORDER_SECONDARY | (orderType << 2); - update_check_flush(context, headerLength + update_approximate_switch_surface_order(switch_surface)); + inf = update_approximate_switch_surface_order(switch_surface); + update_check_flush(context, headerLength + inf); s = update->us; if (!s) @@ -1694,7 +1739,8 @@ static BOOL update_send_switch_surface_order(rdpContext* context, SWITCH_SURFACE return TRUE; } -static BOOL update_send_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer_system) +static BOOL update_send_pointer_system(rdpContext* context, + const POINTER_SYSTEM_UPDATE* pointer_system) { wStream* s; BYTE updateCode; @@ -1715,7 +1761,8 @@ static BOOL update_send_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDAT return ret; } -static BOOL update_send_pointer_position(rdpContext* context, POINTER_POSITION_UPDATE* pointerPosition) +static BOOL update_send_pointer_position(rdpContext* context, + const POINTER_POSITION_UPDATE* pointerPosition) { wStream* s; rdpRdp* rdp = context->rdp; @@ -1737,9 +1784,10 @@ out_fail: return ret; } -static BOOL update_write_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color) +static BOOL update_write_pointer_color(wStream* s, + const POINTER_COLOR_UPDATE* pointer_color) { - if (!Stream_EnsureRemainingCapacity(s, 32 + (int) pointer_color->lengthAndMask + (int) pointer_color->lengthXorMask)) + if (!Stream_EnsureRemainingCapacity(s, 32 + pointer_color->lengthAndMask + pointer_color->lengthXorMask)) return FALSE; Stream_Write_UINT16(s, pointer_color->cacheIndex); @@ -1760,7 +1808,8 @@ static BOOL update_write_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer return TRUE; } -static BOOL update_send_pointer_color(rdpContext* context, POINTER_COLOR_UPDATE* pointer_color) +static BOOL update_send_pointer_color(rdpContext* context, + const POINTER_COLOR_UPDATE* pointer_color) { wStream* s; rdpRdp* rdp = context->rdp; @@ -1780,7 +1829,8 @@ out_fail: return ret; } -static BOOL update_send_pointer_new(rdpContext* context, POINTER_NEW_UPDATE* pointer_new) +static BOOL update_send_pointer_new(rdpContext* context, + const POINTER_NEW_UPDATE* pointer_new) { wStream* s; rdpRdp* rdp = context->rdp; @@ -1794,7 +1844,7 @@ static BOOL update_send_pointer_new(rdpContext* context, POINTER_NEW_UPDATE* poi goto out_fail; Stream_Write_UINT16(s, pointer_new->xorBpp); /* xorBpp (2 bytes) */ - update_write_pointer_color(s, &pointer_new->colorPtrAttr); + update_write_pointer_color(s, &pointer_new->colorPtrAttr); ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_POINTER, s, FALSE); @@ -1803,7 +1853,8 @@ out_fail: return ret; } -static BOOL update_send_pointer_cached(rdpContext* context, POINTER_CACHED_UPDATE* pointer_cached) +static BOOL update_send_pointer_cached(rdpContext* context, + const POINTER_CACHED_UPDATE* pointer_cached) { wStream* s; rdpRdp* rdp = context->rdp; diff --git a/libfreerdp/gdi/16bpp.c b/libfreerdp/gdi/16bpp.c deleted file mode 100644 index 858056aee..000000000 --- a/libfreerdp/gdi/16bpp.c +++ /dev/null @@ -1,1152 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI 16bpp Internal Buffer Routines - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#define TAG FREERDP_TAG("gdi") - -UINT16 gdi_get_color_16bpp(HGDI_DC hdc, GDI_COLOR color) -{ - BYTE r, g, b; - UINT16 color16; - - GetRGB32(r, g, b, color); - - if (hdc->rgb555) - { - if (hdc->invert) - { - color16 = BGR15(r, g, b); - } - else - { - color16 = RGB15(r, g, b); - } - } - else - { - if (hdc->invert) - { - color16 = BGR16(r, g, b); - } - else - { - color16 = RGB16(r, g, b); - } - } - - return color16; -} - -BOOL FillRect_16bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr) -{ - int x, y; - UINT16 *dstp; - int nXDest, nYDest; - int nWidth, nHeight; - - UINT16 color16; - - gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); - - if (!gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - - color16 = gdi_get_color_16bpp(hdc, hbr->color); - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = color16; - dstp++; - } - } - } - - if (!gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight)) - return FALSE; - - return TRUE; -} - -static BOOL BitBlt_BLACKNESS_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - memset(dstp, 0, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; -} - -static BOOL BitBlt_WHITENESS_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - memset(dstp, 0xFF, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; -} - -static BOOL BitBlt_SRCCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - if ((hdcDest->selectedObject != hdcSrc->selectedObject) || - !gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc)) - { - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; - } - - if (nYSrc < nYDest) - { - /* copy down (bottom to top) */ - for (y = nHeight - 1; y >= 0; y--) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - else if (nYSrc > nYDest || nXSrc > nXDest) - { - /* copy up or left (top top bottom) */ - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - else - { - /* copy straight right */ - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - - return TRUE; -} - -static BOOL BitBlt_NOTSRCCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSTINVERT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT16* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*dstp); - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCERASE_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = *srcp & ~(*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_NOTSRCERASE_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) & ~(*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCINVERT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp ^= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCAND_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp &= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCPAINT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp |= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSPDxax_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - UINT16* dstp; - UINT16 src16; - UINT16 color16; - HGDI_BITMAP hSrcBmp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - /* D = (S & P) | (~S & D) */ - /* DSPDxax, used to draw glyphs */ - - color16 = gdi_get_color_16bpp(hdcDest, hdcDest->textColor); - - hSrcBmp = (HGDI_BITMAP) hdcSrc->selectedObject; - - if (hdcSrc->bytesPerPixel != 1) - { - WLog_ERR(TAG, "BitBlt_DSPDxax expects 1 bpp, unimplemented for %d", - hdcSrc->bytesPerPixel); - return FALSE; - } - - for (y = 0; y < nHeight; y++) - { - srcp = (BYTE*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - src16 = (*srcp << 8) | *srcp; - *dstp = (src16 & color16) | (~src16 & *dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PSDPxax_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - UINT16* patp; - UINT16 color16; - - if (!hdcSrc || !hdcDest) - return FALSE; - - /* D = (S & D) | (~S & P) */ - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color16 = gdi_get_color_16bpp(hdcDest, hdcDest->brush->color); - patp = (UINT16*) &color16; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); - srcp++; - dstp++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); - srcp++; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SPna_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - UINT16* patp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *srcp & ~(*patp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DPa_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT16* dstp; - UINT16* patp; - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *dstp & *patp; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PDxn_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT16* dstp; - UINT16* patp; - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *dstp ^ ~(*patp); - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSna_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) & (*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - - -static BOOL BitBlt_MERGECOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - UINT16* patp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *srcp & *patp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_MERGEPAINT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) | *dstp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y, xOffset, yOffset; - UINT16* dstp; - UINT16* patp; - UINT16 color16; - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color16 = gdi_get_color_16bpp(hdcDest, hdcDest->brush->color); - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = color16; - dstp++; - } - } - } - } - else - { - if (hdcDest->brush->style == GDI_BS_HATCHED) - { - xOffset = 0; - yOffset = 2; // +2 added after comparison to mstsc - } - else - { - xOffset = 0; - yOffset = 0; - } - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x + xOffset, nYDest + y + yOffset); - *dstp = *patp; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATINVERT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT16* dstp; - UINT16* patp; - UINT16 color16; - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color16 = gdi_get_color_16bpp(hdcDest, hdcDest->brush->color); - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp ^= color16; - dstp++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *patp ^ *dstp; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATPAINT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT16* srcp; - UINT16* dstp; - UINT16* patp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT16*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT16*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *dstp | (*patp | ~(*srcp)); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -BOOL BitBlt_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop) -{ - if (!hdcDest) - return FALSE; - - if (hdcSrc != NULL) - { - if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc)) - return TRUE; - } - else - { - if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - } - - if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight)) - return FALSE; - - switch (rop) - { - case GDI_BLACKNESS: - return BitBlt_BLACKNESS_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_WHITENESS: - return BitBlt_WHITENESS_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_SRCCOPY: - return BitBlt_SRCCOPY_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SPna: - return BitBlt_SPna_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSna: - return BitBlt_DSna_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSPDxax: - return BitBlt_DSPDxax_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_PSDPxax: - return BitBlt_PSDPxax_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_NOTSRCCOPY: - return BitBlt_NOTSRCCOPY_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSTINVERT: - return BitBlt_DSTINVERT_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_SRCERASE: - return BitBlt_SRCERASE_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_NOTSRCERASE: - return BitBlt_NOTSRCERASE_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCINVERT: - return BitBlt_SRCINVERT_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCAND: - return BitBlt_SRCAND_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCPAINT: - return BitBlt_SRCPAINT_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_MERGECOPY: - return BitBlt_MERGECOPY_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_MERGEPAINT: - return BitBlt_MERGEPAINT_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_PATCOPY: - return BitBlt_PATCOPY_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_PATINVERT: - return BitBlt_PATINVERT_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_PATPAINT: - return BitBlt_PATPAINT_16bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - } - - WLog_ERR(TAG, "BitBlt: unknown rop: 0x%08X", rop); - return FALSE; -} - -BOOL PatBlt_16bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop) -{ - if (!gdi_ClipCoords(hdc, &nXLeft, &nYLeft, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - - if (!gdi_InvalidateRegion(hdc, nXLeft, nYLeft, nWidth, nHeight)) - return FALSE; - - switch (rop) - { - case GDI_PATCOPY: - return BitBlt_PATCOPY_16bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_PATINVERT: - return BitBlt_PATINVERT_16bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_DSTINVERT: - return BitBlt_DSTINVERT_16bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_BLACKNESS: - return BitBlt_BLACKNESS_16bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_WHITENESS: - return BitBlt_WHITENESS_16bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_DPa: - return BitBlt_DPa_16bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_PDxn: - return BitBlt_PDxn_16bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - default: - break; - } - - WLog_ERR(TAG, "PatBlt: unknown rop: 0x%08X", rop); - return FALSE; -} - -static INLINE void SetPixel_BLACK_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = 0 */ - *pixel = 0; -} - -static INLINE void SetPixel_NOTMERGEPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = ~(D | P) */ - *pixel = ~(*pixel | *pen); -} - -static INLINE void SetPixel_MASKNOTPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = D & ~P */ - *pixel &= ~(*pen); -} - -static INLINE void SetPixel_NOTCOPYPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = ~P */ - *pixel = ~(*pen); -} - -static INLINE void SetPixel_MASKPENNOT_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = P & ~D */ - *pixel = *pen & ~*pixel; -} - -static INLINE void SetPixel_NOT_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = ~D */ - *pixel = ~(*pixel); -} - -static INLINE void SetPixel_XORPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = D ^ P */ - *pixel = *pixel ^ *pen; -} - -static INLINE void SetPixel_NOTMASKPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = ~(D & P) */ - *pixel = ~(*pixel & *pen); -} - -static INLINE void SetPixel_MASKPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = D & P */ - *pixel &= *pen; -} - -static INLINE void SetPixel_NOTXORPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = ~(D ^ P) */ - *pixel = ~(*pixel ^ *pen); -} - -static INLINE void SetPixel_NOP_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = D */ -} - -static INLINE void SetPixel_MERGENOTPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = D | ~P */ - *pixel |= ~(*pen); -} - -static INLINE void SetPixel_COPYPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = P */ - *pixel = *pen; -} - -static INLINE void SetPixel_MERGEPENNOT_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = P | ~D */ - *pixel = *pen | ~(*pixel); -} - -static INLINE void SetPixel_MERGEPEN_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = P | D */ - *pixel |= *pen; -} - -static INLINE void SetPixel_WHITE_16bpp(UINT16 *pixel, UINT16 *pen) -{ - /* D = 1 */ - *pixel = 0xFFFF; -} - -#define PIXEL_TYPE UINT16 -#define GDI_GET_POINTER gdi_GetPointer_16bpp -#define GDI_GET_PEN_COLOR gdi_GetPenColor_16bpp - -#define LINE_TO LineTo_BLACK_16bpp -#define SET_PIXEL_ROP2 SetPixel_BLACK_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTMERGEPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_NOTMERGEPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKNOTPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_MASKNOTPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTCOPYPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_NOTCOPYPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKPENNOT_16bpp -#define SET_PIXEL_ROP2 SetPixel_MASKPENNOT_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOT_16bpp -#define SET_PIXEL_ROP2 SetPixel_NOT_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_XORPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_XORPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTMASKPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_NOTMASKPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_MASKPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTXORPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_NOTXORPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOP_16bpp -#define SET_PIXEL_ROP2 SetPixel_NOP_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGENOTPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_MERGENOTPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_COPYPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_COPYPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGEPENNOT_16bpp -#define SET_PIXEL_ROP2 SetPixel_MERGEPENNOT_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGEPEN_16bpp -#define SET_PIXEL_ROP2 SetPixel_MERGEPEN_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_WHITE_16bpp -#define SET_PIXEL_ROP2 SetPixel_WHITE_16bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#undef PIXEL_TYPE -#undef GDI_GET_POINTER -#undef GDI_GET_PEN_COLOR - -pLineTo_16bpp LineTo_ROP2_16bpp[32] = -{ - LineTo_BLACK_16bpp, - LineTo_NOTMERGEPEN_16bpp, - LineTo_MASKNOTPEN_16bpp, - LineTo_NOTCOPYPEN_16bpp, - LineTo_MASKPENNOT_16bpp, - LineTo_NOT_16bpp, - LineTo_XORPEN_16bpp, - LineTo_NOTMASKPEN_16bpp, - LineTo_MASKPEN_16bpp, - LineTo_NOTXORPEN_16bpp, - LineTo_NOP_16bpp, - LineTo_MERGENOTPEN_16bpp, - LineTo_COPYPEN_16bpp, - LineTo_MERGEPENNOT_16bpp, - LineTo_MERGEPEN_16bpp, - LineTo_WHITE_16bpp -}; - -BOOL LineTo_16bpp(HGDI_DC hdc, int nXEnd, int nYEnd) -{ - pLineTo_16bpp _LineTo; - int rop2 = gdi_GetROP2(hdc) - 1; - - _LineTo = LineTo_ROP2_16bpp[rop2]; - - if (_LineTo == NULL) - return FALSE; - - return _LineTo(hdc, nXEnd, nYEnd); -} diff --git a/libfreerdp/gdi/32bpp.c b/libfreerdp/gdi/32bpp.c deleted file mode 100644 index 74d1b8065..000000000 --- a/libfreerdp/gdi/32bpp.c +++ /dev/null @@ -1,1253 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI 32bpp Internal Buffer Routines - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#define TAG FREERDP_TAG("gdi") - -UINT32 gdi_get_color_32bpp(HGDI_DC hdc, GDI_COLOR color) -{ - UINT32 color32; - BYTE a, r, g, b; - - a = 0xFF; - GetRGB32(r, g, b, color); - - if (hdc->invert) - { - color32 = ABGR32(a, r, g, b); - } - else - { - color32 = ARGB32(a, r, g, b); - } - - return color32; -} - -BOOL FillRect_32bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr) -{ - int x, y; - UINT32 *dstp; - UINT32 color32; - int nXDest, nYDest; - int nWidth, nHeight; - - gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); - - if (!gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - - color32 = gdi_get_color_32bpp(hdc, hbr->color); - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = color32; - dstp++; - } - } - } - - if (!gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight)) - return FALSE; - - return TRUE; -} - -static BOOL BitBlt_BLACKNESS_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - if (hdcDest->alpha) - { - int x, y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = 0; - dstp++; - - *dstp = 0; - dstp++; - - *dstp = 0; - dstp++; - - *dstp = 0xFF; - dstp++; - } - } - } - } - else - { - int y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - memset(dstp, 0, nWidth * hdcDest->bytesPerPixel); - } - } - - return TRUE; -} - -static BOOL BitBlt_WHITENESS_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - memset(dstp, 0xFF, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; -} - -static BOOL BitBlt_SRCCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - if ((hdcDest->selectedObject != hdcSrc->selectedObject) || - !gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc)) - { - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; - } - - if (nYSrc < nYDest) - { - /* copy down (bottom to top) */ - for (y = nHeight - 1; y >= 0; y--) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - else if (nYSrc > nYDest || nXSrc > nXDest) - { - /* copy up or left (top top bottom) */ - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - else - { - /* copy straight right */ - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - - return TRUE; -} - -static BOOL BitBlt_NOTSRCCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSTINVERT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT32* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*dstp); - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCERASE_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = *srcp & ~(*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_NOTSRCERASE_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) & ~(*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCINVERT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp ^= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCAND_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp &= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCPAINT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp |= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSPDxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - UINT32* patp; - BYTE* srcp8; - UINT32 src32; - UINT32 color32; - HGDI_BITMAP hSrcBmp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - /* D = (S & P) | (~S & D) */ - - color32 = gdi_get_color_32bpp(hdcDest, hdcDest->textColor); - - patp = (UINT32*) &color32; - hSrcBmp = (HGDI_BITMAP) hdcSrc->selectedObject; - - if (hdcSrc->bytesPerPixel == 1) - { - /* DSPDxax, used to draw glyphs */ - - srcp = (UINT32*) & src32; - - for (y = 0; y < nHeight; y++) - { - srcp8 = (BYTE*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *srcp = ((*srcp8) | (*srcp8 << 8) | (*srcp8 << 16) | (*srcp8 << 24)); - - *dstp = (*srcp & *patp) | (~(*srcp) & *dstp); - dstp++; - - srcp8++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = (*srcp & *patp) | (~(*srcp) & *dstp); - srcp++; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PSDPxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - UINT32* patp; - UINT32 color32; - - if (!hdcDest || !hdcSrc) - return FALSE; - - /* D = (S & D) | (~S & P) */ - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color32 = gdi_get_color_32bpp(hdcDest, hdcDest->brush->color); - patp = (UINT32*) &color32; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); - srcp++; - dstp++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); - srcp++; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SPDSxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - UINT32* patp; - UINT32 color32; - - if (!hdcDest || !hdcSrc) - return FALSE; - - /* D = S ^ (P & (D ^ S)) */ - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color32 = gdi_get_color_32bpp(hdcDest, hdcDest->brush->color); - patp = (UINT32*) &color32; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = *srcp ^ (*patp & (*dstp ^ *srcp)); - srcp++; - dstp++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *srcp ^ (*patp & (*dstp ^ *srcp)); - srcp++; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SPna_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - UINT32* patp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *srcp & ~(*patp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSna_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) & (*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DPa_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT32* dstp; - UINT32* patp; - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *dstp & *patp; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PDxn_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT32* dstp; - UINT32* patp; - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *dstp ^ ~(*patp); - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_MERGECOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - UINT32* patp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *srcp & *patp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_MERGEPAINT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) | *dstp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y, xOffset, yOffset; - UINT32* dstp; - UINT32* patp; - UINT32 color32; - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color32 = gdi_get_color_32bpp(hdcDest, hdcDest->brush->color); - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = color32; - dstp++; - } - } - } - } - else - { - if (hdcDest->brush->style == GDI_BS_HATCHED) - { - xOffset = 0; - yOffset = 2; // +2 added after comparison to mstsc - } - else - { - xOffset = 0; - yOffset = 0; - } - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x + xOffset, nYDest + y + yOffset); - *dstp = *patp; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATINVERT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - UINT32* dstp; - UINT32* patp; - UINT32 color32; - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color32 = gdi_get_color_32bpp(hdcDest, hdcDest->brush->color); - - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp ^= color32; - dstp++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *patp ^ *dstp; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATPAINT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - UINT32* srcp; - UINT32* dstp; - UINT32* patp; - - if (!hdcDest || !hdcSrc) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (UINT32*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (UINT32*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = *dstp | (*patp | ~(*srcp)); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -BOOL BitBlt_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop) -{ - if (!hdcDest) - return FALSE; - - if (hdcSrc != NULL) - { - if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc)) - return TRUE; - } - else - { - if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - } - - if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight)) - return FALSE; - - switch (rop) - { - case GDI_BLACKNESS: - return BitBlt_BLACKNESS_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_WHITENESS: - return BitBlt_WHITENESS_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_SRCCOPY: - return BitBlt_SRCCOPY_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SPna: - return BitBlt_SPna_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSna: - return BitBlt_DSna_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSPDxax: - return BitBlt_DSPDxax_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_PSDPxax: - return BitBlt_PSDPxax_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SPDSxax: - return BitBlt_SPDSxax_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_NOTSRCCOPY: - return BitBlt_NOTSRCCOPY_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSTINVERT: - return BitBlt_DSTINVERT_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_SRCERASE: - return BitBlt_SRCERASE_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_NOTSRCERASE: - return BitBlt_NOTSRCERASE_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCINVERT: - return BitBlt_SRCINVERT_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCAND: - return BitBlt_SRCAND_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCPAINT: - return BitBlt_SRCPAINT_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_MERGECOPY: - return BitBlt_MERGECOPY_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_MERGEPAINT: - return BitBlt_MERGEPAINT_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_PATCOPY: - return BitBlt_PATCOPY_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_PATINVERT: - return BitBlt_PATINVERT_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_PATPAINT: - return BitBlt_PATPAINT_32bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - } - - WLog_ERR(TAG, "BitBlt: unknown rop: 0x%08X", rop); - return FALSE; -} - -BOOL PatBlt_32bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop) -{ - if (!gdi_ClipCoords(hdc, &nXLeft, &nYLeft, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - - if (!gdi_InvalidateRegion(hdc, nXLeft, nYLeft, nWidth, nHeight)) - return FALSE; - - switch (rop) - { - case GDI_PATCOPY: - return BitBlt_PATCOPY_32bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_PATINVERT: - return BitBlt_PATINVERT_32bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_DSTINVERT: - return BitBlt_DSTINVERT_32bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_BLACKNESS: - return BitBlt_BLACKNESS_32bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_WHITENESS: - return BitBlt_WHITENESS_32bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_DPa: - return BitBlt_DPa_32bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_PDxn: - return BitBlt_PDxn_32bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - default: - break; - } - - WLog_ERR(TAG, "PatBlt: unknown rop: 0x%08X", rop); - return FALSE; -} - -static INLINE void SetPixel_BLACK_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = 0 */ - *pixel = 0; -} - -static INLINE void SetPixel_NOTMERGEPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = ~(D | P) */ - *pixel = ~(*pixel | *pen); -} - -static INLINE void SetPixel_MASKNOTPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = D & ~P */ - *pixel &= ~(*pen); -} - -static INLINE void SetPixel_NOTCOPYPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = ~P */ - *pixel = ~(*pen); -} - -static INLINE void SetPixel_MASKPENNOT_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = P & ~D */ - *pixel = *pen & ~*pixel; -} - -static INLINE void SetPixel_NOT_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = ~D */ - *pixel = ~(*pixel); -} - -static INLINE void SetPixel_XORPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = D ^ P */ - *pixel = *pixel ^ *pen; -} - -static INLINE void SetPixel_NOTMASKPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = ~(D & P) */ - *pixel = ~(*pixel & *pen); -} - -static INLINE void SetPixel_MASKPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = D & P */ - *pixel &= *pen; -} - -static INLINE void SetPixel_NOTXORPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = ~(D ^ P) */ - *pixel = ~(*pixel ^ *pen); -} - -static INLINE void SetPixel_NOP_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = D */ -} - -static INLINE void SetPixel_MERGENOTPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = D | ~P */ - *pixel |= ~(*pen); -} - -static INLINE void SetPixel_COPYPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = P */ - *pixel = *pen; -} - -static INLINE void SetPixel_MERGEPENNOT_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = P | ~D */ - *pixel = *pen | ~(*pixel); -} - -static INLINE void SetPixel_MERGEPEN_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = P | D */ - *pixel |= *pen; -} - -static INLINE void SetPixel_WHITE_32bpp(UINT32* pixel, UINT32* pen) -{ - /* D = 1 */ - *pixel = 0xFFFFFF; -} - -#define PIXEL_TYPE UINT32 -#define GDI_GET_POINTER gdi_GetPointer_32bpp -#define GDI_GET_PEN_COLOR gdi_GetPenColor_32bpp - -#define LINE_TO LineTo_BLACK_32bpp -#define SET_PIXEL_ROP2 SetPixel_BLACK_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTMERGEPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_NOTMERGEPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKNOTPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_MASKNOTPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTCOPYPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_NOTCOPYPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKPENNOT_32bpp -#define SET_PIXEL_ROP2 SetPixel_MASKPENNOT_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOT_32bpp -#define SET_PIXEL_ROP2 SetPixel_NOT_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_XORPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_XORPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTMASKPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_NOTMASKPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_MASKPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTXORPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_NOTXORPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOP_32bpp -#define SET_PIXEL_ROP2 SetPixel_NOP_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGENOTPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_MERGENOTPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_COPYPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_COPYPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGEPENNOT_32bpp -#define SET_PIXEL_ROP2 SetPixel_MERGEPENNOT_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGEPEN_32bpp -#define SET_PIXEL_ROP2 SetPixel_MERGEPEN_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_WHITE_32bpp -#define SET_PIXEL_ROP2 SetPixel_WHITE_32bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#undef PIXEL_TYPE -#undef GDI_GET_POINTER -#undef GDI_GET_PEN_COLOR - -pLineTo_32bpp LineTo_ROP2_32bpp[32] = -{ - LineTo_BLACK_32bpp, - LineTo_NOTMERGEPEN_32bpp, - LineTo_MASKNOTPEN_32bpp, - LineTo_NOTCOPYPEN_32bpp, - LineTo_MASKPENNOT_32bpp, - LineTo_NOT_32bpp, - LineTo_XORPEN_32bpp, - LineTo_NOTMASKPEN_32bpp, - LineTo_MASKPEN_32bpp, - LineTo_NOTXORPEN_32bpp, - LineTo_NOP_32bpp, - LineTo_MERGENOTPEN_32bpp, - LineTo_COPYPEN_32bpp, - LineTo_MERGEPENNOT_32bpp, - LineTo_MERGEPEN_32bpp, - LineTo_WHITE_32bpp -}; - -BOOL LineTo_32bpp(HGDI_DC hdc, int nXEnd, int nYEnd) -{ - pLineTo_32bpp _LineTo; - int rop2 = gdi_GetROP2(hdc) - 1; - - _LineTo = LineTo_ROP2_32bpp[rop2]; - - if (_LineTo == NULL) - return FALSE; - - return _LineTo(hdc, nXEnd, nYEnd); -} diff --git a/libfreerdp/gdi/8bpp.c b/libfreerdp/gdi/8bpp.c deleted file mode 100644 index 1f90b60c4..000000000 --- a/libfreerdp/gdi/8bpp.c +++ /dev/null @@ -1,1068 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI 8bpp Internal Buffer Routines - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#define TAG FREERDP_TAG("gdi") - -BYTE gdi_get_color_8bpp(HGDI_DC hdc, GDI_COLOR color) -{ - /* TODO: Implement 8bpp gdi_get_color_8bpp() */ - WLog_ERR(TAG, "%s: not implemented", __FUNCTION__); - return 1; -} - -BOOL FillRect_8bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr) -{ - /* TODO: Implement 8bpp FillRect() */ - WLog_ERR(TAG, "%s: not implemented", __FUNCTION__); - return TRUE; -} - -static BOOL BitBlt_BLACKNESS_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - memset(dstp, 0, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; -} - -static BOOL BitBlt_WHITENESS_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - memset(dstp, 0xFF, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; -} - -static BOOL BitBlt_SRCCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - if ((hdcDest->selectedObject != hdcSrc->selectedObject) || - !gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc)) - { - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - - return TRUE; - } - - if (nYSrc < nYDest) - { - /* copy down (bottom to top) */ - for (y = nHeight - 1; y >= 0; y--) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - else if (nYSrc > nYDest || nXSrc > nXDest) - { - /* copy up or left (top top bottom) */ - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - else - { - /* copy straight right */ - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (srcp != 0 && dstp != 0) - memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel); - } - } - - return TRUE; -} - -static BOOL BitBlt_NOTSRCCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSTINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - BYTE* dstp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*dstp); - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCERASE_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = *srcp & ~(*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_NOTSRCERASE_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) & ~(*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp ^= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCAND_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp &= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SRCPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp |= *srcp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSPDxax_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - if (!hdcSrc || !hdcDest) - return FALSE; - - /* TODO: Implement 8bpp DSPDxax BitBlt */ - WLog_ERR(TAG, "%s: not implemented", __FUNCTION__); - return TRUE; -} - -static BOOL BitBlt_PSDPxax_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - BYTE* patp; - BYTE color8; - - if (!hdcSrc || !hdcDest) - return FALSE; - - /* D = (S & D) | (~S & P) */ - - if (hdcDest->brush->style == GDI_BS_SOLID) - { - color8 = gdi_get_color_8bpp(hdcDest, hdcDest->brush->color); - patp = (BYTE*) &color8; - - for (y = 0; y < nHeight; y++) - { - srcp = (BYTE*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (BYTE*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); - srcp++; - dstp++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - srcp = (BYTE*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = (BYTE*) gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = (BYTE*) gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - *dstp = (*srcp & *dstp) | (~(*srcp) & *patp); - srcp++; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_SPna_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - BYTE* patp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *srcp & ~(*patp); - patp++; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DPa_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - BYTE* dstp; - BYTE* patp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *dstp & *patp; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PDxn_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - BYTE* dstp; - BYTE* patp; - - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *dstp ^ ~(*patp); - patp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_DSna_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) & (*dstp); - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_MERGECOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - BYTE* patp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *srcp & *patp; - patp++; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_MERGEPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = ~(*srcp) | *dstp; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y, xOffset, yOffset; - BYTE* dstp; - BYTE* patp; - BYTE palIndex; - - if(hdcDest->brush->style == GDI_BS_SOLID) - { - palIndex = ((hdcDest->brush->color >> 16) & 0xFF); - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp = palIndex; - dstp++; - } - } - } - } - else - { - if (hdcDest->brush->style == GDI_BS_HATCHED) - { - xOffset = 0; - yOffset = 2; // +2 added after comparison to mstsc - } - else - { - xOffset = 0; - yOffset = 0; - } - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = gdi_get_brush_pointer(hdcDest, nXDest + x + xOffset, nYDest + y + yOffset); - - *dstp = *patp; - patp++; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) -{ - int x, y; - BYTE* dstp; - BYTE* patp; - BYTE palIndex; - - if(hdcDest->brush->style == GDI_BS_SOLID) - { - palIndex = ((hdcDest->brush->color >> 16) & 0xFF); - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - *dstp ^= palIndex; - dstp++; - } - } - } - } - else - { - for (y = 0; y < nHeight; y++) - { - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *patp ^ *dstp; - patp++; - dstp++; - } - } - } - } - - return TRUE; -} - -static BOOL BitBlt_PATPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc) -{ - int x, y; - BYTE* srcp; - BYTE* dstp; - BYTE* patp; - - if (!hdcSrc || !hdcDest) - return FALSE; - - for (y = 0; y < nHeight; y++) - { - srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); - dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); - - if (dstp != 0) - { - for (x = 0; x < nWidth; x++) - { - patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); - - *dstp = *dstp | (*patp | ~(*srcp)); - patp++; - srcp++; - dstp++; - } - } - } - - return TRUE; -} - -BOOL BitBlt_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop) -{ - if (!hdcDest) - return FALSE; - - if (hdcSrc != NULL) - { - if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc)) - return TRUE; - } - else - { - if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - } - - if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight)) - return FALSE; - - switch (rop) - { - case GDI_BLACKNESS: - return BitBlt_BLACKNESS_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_WHITENESS: - return BitBlt_WHITENESS_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_SRCCOPY: - return BitBlt_SRCCOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SPna: - return BitBlt_SPna_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSna: - return BitBlt_DSna_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSPDxax: - return BitBlt_DSPDxax_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_PSDPxax: - return BitBlt_PSDPxax_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_NOTSRCCOPY: - return BitBlt_NOTSRCCOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_DSTINVERT: - return BitBlt_DSTINVERT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_SRCERASE: - return BitBlt_SRCERASE_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_NOTSRCERASE: - return BitBlt_NOTSRCERASE_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCINVERT: - return BitBlt_SRCINVERT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCAND: - return BitBlt_SRCAND_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_SRCPAINT: - return BitBlt_SRCPAINT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_MERGECOPY: - return BitBlt_MERGECOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_MERGEPAINT: - return BitBlt_MERGEPAINT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - - case GDI_PATCOPY: - return BitBlt_PATCOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_PATINVERT: - return BitBlt_PATINVERT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight); - - case GDI_PATPAINT: - return BitBlt_PATPAINT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); - } - - WLog_ERR(TAG, "BitBlt: unknown rop: 0x%08X", rop); - return FALSE; -} - -BOOL PatBlt_8bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop) -{ - if (!gdi_ClipCoords(hdc, &nXLeft, &nYLeft, &nWidth, &nHeight, NULL, NULL)) - return TRUE; - - if (!gdi_InvalidateRegion(hdc, nXLeft, nYLeft, nWidth, nHeight)) - return FALSE; - - switch (rop) - { - case GDI_PATCOPY: - return BitBlt_PATCOPY_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_PATINVERT: - return BitBlt_PATINVERT_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_DSTINVERT: - return BitBlt_DSTINVERT_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_BLACKNESS: - return BitBlt_BLACKNESS_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_WHITENESS: - return BitBlt_WHITENESS_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_DPa: - return BitBlt_DPa_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - case GDI_PDxn: - return BitBlt_PDxn_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight); - - default: - break; - } - - WLog_ERR(TAG, "PatBlt: unknown rop: 0x%08X", rop); - return 1; -} - -static INLINE void SetPixel_BLACK_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = 0 */ - *pixel = 0; -} - -static INLINE void SetPixel_NOTMERGEPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = ~(D | P) */ - *pixel = ~(*pixel | *pen); -} - -static INLINE void SetPixel_MASKNOTPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = D & ~P */ - *pixel &= ~(*pen); -} - -static INLINE void SetPixel_NOTCOPYPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = ~P */ - *pixel = ~(*pen); -} - -static INLINE void SetPixel_MASKPENNOT_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = P & ~D */ - *pixel = *pen & ~*pixel; -} - -static INLINE void SetPixel_NOT_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = ~D */ - *pixel = ~(*pixel); -} - -static INLINE void SetPixel_XORPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = D ^ P */ - *pixel = *pixel ^ *pen; -} - -static INLINE void SetPixel_NOTMASKPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = ~(D & P) */ - *pixel = ~(*pixel & *pen); -} - -static INLINE void SetPixel_MASKPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = D & P */ - *pixel &= *pen; -} - -static INLINE void SetPixel_NOTXORPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = ~(D ^ P) */ - *pixel = ~(*pixel ^ *pen); -} - -static INLINE void SetPixel_NOP_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = D */ -} - -static INLINE void SetPixel_MERGENOTPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = D | ~P */ - *pixel |= ~(*pen); -} - -static INLINE void SetPixel_COPYPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = P */ - *pixel = *pen; -} - -static INLINE void SetPixel_MERGEPENNOT_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = P | ~D */ - *pixel = *pen | ~(*pixel); -} - -static INLINE void SetPixel_MERGEPEN_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = P | D */ - *pixel |= *pen; -} - -static INLINE void SetPixel_WHITE_8bpp(BYTE* pixel, BYTE* pen) -{ - /* D = 1 */ - *pixel = 0xFF; -} - -#define PIXEL_TYPE BYTE -#define GDI_GET_POINTER gdi_GetPointer_8bpp -#define GDI_GET_PEN_COLOR gdi_GetPenColor_8bpp - -#define LINE_TO LineTo_BLACK_8bpp -#define SET_PIXEL_ROP2 SetPixel_BLACK_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTMERGEPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_NOTMERGEPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKNOTPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_MASKNOTPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTCOPYPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_NOTCOPYPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKPENNOT_8bpp -#define SET_PIXEL_ROP2 SetPixel_MASKPENNOT_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOT_8bpp -#define SET_PIXEL_ROP2 SetPixel_NOT_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_XORPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_XORPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTMASKPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_NOTMASKPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MASKPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_MASKPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOTXORPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_NOTXORPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_NOP_8bpp -#define SET_PIXEL_ROP2 SetPixel_NOP_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGENOTPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_MERGENOTPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_COPYPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_COPYPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGEPENNOT_8bpp -#define SET_PIXEL_ROP2 SetPixel_MERGEPENNOT_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_MERGEPEN_8bpp -#define SET_PIXEL_ROP2 SetPixel_MERGEPEN_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#define LINE_TO LineTo_WHITE_8bpp -#define SET_PIXEL_ROP2 SetPixel_WHITE_8bpp -#include "include/line.c" -#undef LINE_TO -#undef SET_PIXEL_ROP2 - -#undef PIXEL_TYPE -#undef GDI_GET_POINTER -#undef GDI_GET_PEN_COLOR - -pLineTo_8bpp LineTo_ROP2_8bpp[32] = -{ - LineTo_BLACK_8bpp, - LineTo_NOTMERGEPEN_8bpp, - LineTo_MASKNOTPEN_8bpp, - LineTo_NOTCOPYPEN_8bpp, - LineTo_MASKPENNOT_8bpp, - LineTo_NOT_8bpp, - LineTo_XORPEN_8bpp, - LineTo_NOTMASKPEN_8bpp, - LineTo_MASKPEN_8bpp, - LineTo_NOTXORPEN_8bpp, - LineTo_NOP_8bpp, - LineTo_MERGENOTPEN_8bpp, - LineTo_COPYPEN_8bpp, - LineTo_MERGEPENNOT_8bpp, - LineTo_MERGEPEN_8bpp, - LineTo_WHITE_8bpp -}; - -BOOL LineTo_8bpp(HGDI_DC hdc, int nXEnd, int nYEnd) -{ - pLineTo_8bpp _LineTo; - int rop2 = gdi_GetROP2(hdc) - 1; - - _LineTo = LineTo_ROP2_8bpp[rop2]; - - if (_LineTo == NULL) - return FALSE; - - return _LineTo(hdc, nXEnd, nYEnd); -} diff --git a/libfreerdp/gdi/CMakeLists.txt b/libfreerdp/gdi/CMakeLists.txt index c64979a2c..0bdc3423c 100644 --- a/libfreerdp/gdi/CMakeLists.txt +++ b/libfreerdp/gdi/CMakeLists.txt @@ -21,16 +21,12 @@ set(MODULE_PREFIX "FREERDP_GDI") include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(${MODULE_PREFIX}_SRCS - 8bpp.c - 16bpp.c - 32bpp.c bitmap.c brush.c clipping.c dc.c drawing.c line.c - palette.c pen.c region.c shape.c @@ -43,6 +39,6 @@ set(${MODULE_PREFIX}_SRCS freerdp_module_add(${${MODULE_PREFIX}_SRCS}) if(BUILD_TESTING) - add_subdirectory(test) +# add_subdirectory(test) endif() diff --git a/libfreerdp/gdi/bitmap.c b/libfreerdp/gdi/bitmap.c index 03486d8f6..16a697a04 100644 --- a/libfreerdp/gdi/bitmap.c +++ b/libfreerdp/gdi/bitmap.c @@ -3,6 +3,8 @@ * GDI Bitmap Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,20 +32,14 @@ #include #include -#include -#include -#include - +#include #include +#include -p_BitBlt BitBlt_[5] = -{ - NULL, - BitBlt_8bpp, - BitBlt_16bpp, - NULL, - BitBlt_32bpp -}; +#include "brush.h" +#include "clipping.h" + +#define TAG FREERDP_TAG("gdi.bitmap") /** * Get pixel at the given coordinates.\n @@ -54,41 +50,18 @@ p_BitBlt BitBlt_[5] = * @return pixel color */ -INLINE GDI_COLOR gdi_GetPixel(HGDI_DC hdc, int nXPos, int nYPos) +INLINE UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos) { HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject; - GDI_COLOR* colorp = (GDI_COLOR*)&(hBmp->data[(nYPos * hBmp->width * hdc->bytesPerPixel) + nXPos * hdc->bytesPerPixel]); - return (GDI_COLOR) *colorp; + BYTE* data = &(hBmp->data[(nYPos * hBmp->scanline) + nXPos * GetBytesPerPixel( + hBmp->format)]); + return ReadColor(data, hBmp->format); } -INLINE BYTE gdi_GetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y) +INLINE BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y) { - return *((BYTE*)&(hBmp->data[(Y * hBmp->width) + X])); -} - -INLINE UINT16 gdi_GetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y) -{ - return *((UINT16*)&(hBmp->data[(Y * hBmp->width * 2) + X * 2])); -} - -INLINE UINT32 gdi_GetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y) -{ - return *((UINT32*)&(hBmp->data[(Y * hBmp->width * 4) + X * 4])); -} - -INLINE BYTE* gdi_GetPointer_8bpp(HGDI_BITMAP hBmp, int X, int Y) -{ - return ((BYTE*)&(hBmp->data[(Y * hBmp->width) + X])); -} - -INLINE UINT16* gdi_GetPointer_16bpp(HGDI_BITMAP hBmp, int X, int Y) -{ - return ((UINT16*)&(hBmp->data[(Y * hBmp->width * 2) + X * 2])); -} - -INLINE UINT32* gdi_GetPointer_32bpp(HGDI_BITMAP hBmp, int X, int Y) -{ - return ((UINT32*)&(hBmp->data[(Y * hBmp->width * 4) + X * 4])); + UINT32 bpp = GetBytesPerPixel(hBmp->format); + return &hBmp->data[(Y * hBmp->width * bpp) + X * bpp]; } /** @@ -101,26 +74,19 @@ INLINE UINT32* gdi_GetPointer_32bpp(HGDI_BITMAP hBmp, int X, int Y) * @return */ -INLINE GDI_COLOR gdi_SetPixel(HGDI_DC hdc, int X, int Y, GDI_COLOR crColor) +static INLINE UINT32 gdi_SetPixelBmp(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y, + UINT32 crColor) { - HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject; - *((GDI_COLOR*)&(hBmp->data[(Y * hBmp->width * hdc->bytesPerPixel) + X * hdc->bytesPerPixel])) = crColor; + BYTE* p = &hBmp->data[(Y * hBmp->scanline) + X * GetBytesPerPixel( + hBmp->format)]; + WriteColor(p, hBmp->format, crColor); return crColor; } -INLINE void gdi_SetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y, BYTE pixel) +INLINE UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y, UINT32 crColor) { - *((BYTE*)&(hBmp->data[(Y * hBmp->width) + X])) = pixel; -} - -INLINE void gdi_SetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y, UINT16 pixel) -{ - *((UINT16*)&(hBmp->data[(Y * hBmp->width * 2) + X * 2])) = pixel; -} - -INLINE void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, UINT32 pixel) -{ - *((UINT32*)&(hBmp->data[(Y * hBmp->width * 4) + X * 4])) = pixel; + HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject; + return gdi_SetPixelBmp(hBmp, X, Y, crColor); } /** @@ -134,13 +100,14 @@ INLINE void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, UINT32 pixel) * @return new bitmap */ -HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data) +HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight, UINT32 format, + BYTE* data) { - return gdi_CreateBitmapEx(nWidth, nHeight, cBitsPerPixel, data, _aligned_free); + return gdi_CreateBitmapEx(nWidth, nHeight, format, 0, data, _aligned_free); } -HGDI_BITMAP gdi_CreateBitmapEx(int nWidth, int nHeight, int cBitsPerPixel, BYTE* data, - void (*fkt_free)(void*)) +HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format, + UINT32 stride, BYTE* data, void (*fkt_free)(void*)) { HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP)); @@ -148,14 +115,17 @@ HGDI_BITMAP gdi_CreateBitmapEx(int nWidth, int nHeight, int cBitsPerPixel, BYTE* return NULL; hBitmap->objectType = GDIOBJECT_BITMAP; - hBitmap->bitsPerPixel = cBitsPerPixel; - hBitmap->bytesPerPixel = (cBitsPerPixel + 1) / 8; - hBitmap->scanline = nWidth * hBitmap->bytesPerPixel; + hBitmap->format = format; + + if (stride > 0) + hBitmap->scanline = stride; + else + hBitmap->scanline = nWidth * GetBytesPerPixel(hBitmap->format); + hBitmap->width = nWidth; hBitmap->height = nHeight; hBitmap->data = data; hBitmap->free = fkt_free; - return hBitmap; } @@ -168,7 +138,8 @@ HGDI_BITMAP gdi_CreateBitmapEx(int nWidth, int nHeight, int cBitsPerPixel, BYTE* * @return new bitmap */ -HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight) +HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth, + UINT32 nHeight) { HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP)); @@ -176,22 +147,629 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight) return NULL; hBitmap->objectType = GDIOBJECT_BITMAP; - hBitmap->bytesPerPixel = hdc->bytesPerPixel; - hBitmap->bitsPerPixel = hdc->bitsPerPixel; + hBitmap->format = hdc->format; hBitmap->width = nWidth; hBitmap->height = nHeight; - hBitmap->data = _aligned_malloc(nWidth * nHeight * hBitmap->bytesPerPixel, 16); + hBitmap->data = _aligned_malloc(nWidth * nHeight * GetBytesPerPixel( + hBitmap->format), 16); hBitmap->free = _aligned_free; + if (!hBitmap->data) { free(hBitmap); return NULL; } - hBitmap->scanline = nWidth * hBitmap->bytesPerPixel; + hBitmap->scanline = nWidth * GetBytesPerPixel(hBitmap->format); return hBitmap; } +static BOOL BitBlt_SRCCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 y; + BYTE* srcp; + BYTE* dstp; + + if (!hdcDest || !hdcSrc) + return FALSE; + + if (hdcDest->format != hdcSrc->format) + { + WLog_ERR(TAG, "Function does not support color conversion!"); + return FALSE; + } + + if ((nHeight == 0) || (nWidth == 0)) + return TRUE; + + if ((hdcDest->selectedObject != hdcSrc->selectedObject) || + !gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc)) + { + for (y = 0; y < nHeight; y++) + { + srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); + dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); + + if (srcp != 0 && dstp != 0) + memmove(dstp, srcp, nWidth * GetBytesPerPixel(hdcDest->format)); + } + + return TRUE; + } + + if (nYSrc < nYDest) + { + /* copy down (bottom to top) */ + for (y = nHeight - 1; y >= 0; y--) + { + srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); + dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); + + if (srcp != 0 && dstp != 0) + memmove(dstp, srcp, nWidth * GetBytesPerPixel(hdcDest->format)); + } + } + else if (nYSrc > nYDest || nXSrc > nXDest) + { + /* copy up or left (top top bottom) */ + for (y = 0; y < nHeight; y++) + { + srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); + dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); + + if (srcp != 0 && dstp != 0) + memmove(dstp, srcp, nWidth * GetBytesPerPixel(hdcDest->format)); + } + } + else + { + /* copy straight right */ + for (y = 0; y < nHeight; y++) + { + srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); + dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); + + if (srcp != 0 && dstp != 0) + memmove(dstp, srcp, nWidth * GetBytesPerPixel(hdcDest->format)); + } + } + + return TRUE; +} + +static BOOL BitBlt_NOTSRCCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (srcp && dstp) + { + UINT32 color = ReadColor(srcp, hdcSrc->format); + color = ConvertColor(color, hdcSrc->format, hdcDest->format, NULL); + color = ~color; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_SRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (srcp && dstp) + { + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + UINT32 color; + + colorA = ConvertColor(colorA, hdcSrc->format, hdcDest->format, NULL); + color = colorA & ~colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_NOTSRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (srcp && dstp) + { + UINT32 color; + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = ~colorA & ~colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_SRCINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (srcp && dstp) + { + UINT32 color; + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = colorA ^ colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_SRCAND(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (srcp && dstp) + { + UINT32 color; + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = colorA & colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_SRCPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (srcp && dstp) + { + UINT32 color; + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = colorA | colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_DSPDxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + UINT32 color; + + if (!hdcDest || !hdcSrc) + return FALSE; + + /* D = (S & P) | (~S & D) */ + color = hdcDest->textColor; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; xformat); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = (colorA & color) | (~colorA & colorB); + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_PSDPxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + /* D = (S & D) | (~S & P) */ + if (hdcDest->brush->style == GDI_BS_SOLID) + { + UINT32 colorC = hdcDest->brush->color; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; xformat); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = (colorA & colorB) | (~colorA & colorC); + WriteColor(dstp, hdcDest->format, color); + } + } + } + } + else + { + for (y = 0; y < nHeight; y++) + { + for (x = 0; xformat); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + UINT32 colorC = ReadColor(patp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = (colorA & colorB) | (~colorA & colorC); + WriteColor(dstp, hdcDest->format, color); + } + } + } + } + + return TRUE; +} + +static BOOL BitBlt_SPDSxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + /* D = S ^ (P & (D ^ S)) */ + if (hdcDest->brush->style == GDI_BS_SOLID) + { + UINT32 color = hdcDest->brush->color; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; xformat); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + colorD = colorA ^ (color & (colorB ^ colorA)); + WriteColor(dstp, hdcDest->format, color); + } + } + } + } + else + { + for (y = 0; y < nHeight; y++) + { + for (x = 0; xformat); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + UINT32 color = ReadColor(patp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + colorD = colorA ^ (color & (colorB ^ colorA)); + WriteColor(dstp, hdcDest->format, color); + } + } + } + } + + return TRUE; +} + +static BOOL BitBlt_SPna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc + x, nYSrc + y); + const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (srcp && patp && dstp) + { + UINT32 color; + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(patp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + color = colorA & ~colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_DSna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + if (srcp && dstp) + { + UINT32 color; + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + + color = ~colorA & colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + + + +static BOOL BitBlt_MERGECOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer( + hdcSrc, nXSrc + x, nYSrc + y); + const BYTE* patp = gdi_get_brush_pointer( + hdcDest, nXDest + x, nYDest + y); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (srcp && patp && dstp) + { + UINT32 color; + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(patp, hdcDest->format); + + colorA = ConvertColor(colorA, hdcSrc->format, + hdcDest->format, NULL); + color = colorA & colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_MERGEPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) + return FALSE; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc + x, nYSrc + y); + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (srcp && dstp) + { + UINT32 colorA = ReadColor(srcp, hdcSrc->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + UINT32 color; + + colorA = ConvertColor(colorA, hdcSrc->format, hdcDest->format, NULL); + color = ~colorA | colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + /** * Perform a bit blit operation on the given pixel buffers.\n * @msdn{dd183370} @@ -206,13 +784,90 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight) * @param rop raster operation code * @return 0 on failure, non-zero otherwise */ - -BOOL gdi_BitBlt(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, DWORD rop) +BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc, DWORD rop) { - p_BitBlt _BitBlt = BitBlt_[IBPP(hdcDest->bitsPerPixel)]; - - if (_BitBlt == NULL) + if (!hdcDest) return FALSE; - return _BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, rop); + if (hdcSrc != NULL) + { + if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc)) + return TRUE; + } + else + { + if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) + return TRUE; + } + + if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight)) + return FALSE; + + switch (rop) + { + case GDI_BLACKNESS: + return BitBlt_BLACKNESS(hdcDest, nXDest, nYDest, nWidth, nHeight); + + case GDI_WHITENESS: + return BitBlt_WHITENESS(hdcDest, nXDest, nYDest, nWidth, nHeight); + + case GDI_SRCCOPY: + return BitBlt_SRCCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_SPna: + return BitBlt_SPna(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_DSna: + return BitBlt_DSna(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_DSPDxax: + return BitBlt_DSPDxax(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_PSDPxax: + return BitBlt_PSDPxax(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_SPDSxax: + return BitBlt_SPDSxax(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_NOTSRCCOPY: + return BitBlt_NOTSRCCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_DSTINVERT: + return BitBlt_DSTINVERT(hdcDest, nXDest, nYDest, nWidth, nHeight); + + case GDI_SRCERASE: + return BitBlt_SRCERASE(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_NOTSRCERASE: + return BitBlt_NOTSRCERASE(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_SRCINVERT: + return BitBlt_SRCINVERT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_SRCAND: + return BitBlt_SRCAND(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_SRCPAINT: + return BitBlt_SRCPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_MERGECOPY: + return BitBlt_MERGECOPY(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_MERGEPAINT: + return BitBlt_MERGEPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + + case GDI_PATCOPY: + return BitBlt_PATCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight); + + case GDI_PATINVERT: + return BitBlt_PATINVERT(hdcDest, nXDest, nYDest, nWidth, nHeight); + + case GDI_PATPAINT: + return BitBlt_PATPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc); + } + + WLog_ERR(TAG, "BitBlt: unknown rop: 0x%08X", rop); + return FALSE; } diff --git a/libfreerdp/gdi/brush.c b/libfreerdp/gdi/brush.c index 4a83e043c..b1e5814a7 100644 --- a/libfreerdp/gdi/brush.c +++ b/libfreerdp/gdi/brush.c @@ -3,6 +3,8 @@ * GDI Brush Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,21 +30,12 @@ #include #include +#include +#include -#include -#include -#include +#include "clipping.h" -#include - -p_PatBlt PatBlt_[5] = -{ - NULL, - PatBlt_8bpp, - PatBlt_16bpp, - NULL, - PatBlt_32bpp -}; +#define TAG FREERDP_TAG("gdi.brush") /** * Create a new solid brush.\n @@ -51,11 +44,13 @@ p_PatBlt PatBlt_[5] = * @return new brush */ -HGDI_BRUSH gdi_CreateSolidBrush(GDI_COLOR crColor) +HGDI_BRUSH gdi_CreateSolidBrush(UINT32 crColor) { HGDI_BRUSH hBrush = (HGDI_BRUSH) calloc(1, sizeof(GDI_BRUSH)); + if (!hBrush) return NULL; + hBrush->objectType = GDIOBJECT_BRUSH; hBrush->style = GDI_BS_SOLID; hBrush->color = crColor; @@ -72,8 +67,10 @@ HGDI_BRUSH gdi_CreateSolidBrush(GDI_COLOR crColor) HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp) { HGDI_BRUSH hBrush = (HGDI_BRUSH) calloc(1, sizeof(GDI_BRUSH)); + if (!hBrush) return NULL; + hBrush->objectType = GDIOBJECT_BRUSH; hBrush->style = GDI_BS_PATTERN; hBrush->pattern = hbmp; @@ -83,8 +80,10 @@ HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp) HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp) { HGDI_BRUSH hBrush = (HGDI_BRUSH) calloc(1, sizeof(GDI_BRUSH)); + if (!hBrush) return NULL; + hBrush->objectType = GDIOBJECT_BRUSH; hBrush->style = GDI_BS_HATCHED; hBrush->pattern = hbmp; @@ -102,13 +101,288 @@ HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp) * @param rop raster operation code * @return nonzero if successful, 0 otherwise */ - -BOOL gdi_PatBlt(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD rop) +static BOOL BitBlt_DPa(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight) { - p_PatBlt _PatBlt = PatBlt_[IBPP(hdc->bitsPerPixel)]; + UINT32 x, y; - if (_PatBlt == NULL) + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (dstp && patp) + { + UINT32 color = ReadColor(patp, hdcDest->format); + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +static BOOL BitBlt_PDxn(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight) +{ + UINT32 x, y; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (dstp && patp) + { + UINT32 colorA = ReadColor(dstp, hdcDest->format); + UINT32 colorB = ReadColor(patp, hdcDest->format); + UINT32 color = colorA ^ ~colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +BOOL BitBlt_PATINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight) +{ + UINT32 x, y; + + if (hdcDest->brush->style == GDI_BS_SOLID) + { + UINT32 color = hdcDest->brush->color; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (dstp) + { + color ^= color; + WriteColor(dstp, hdcDest->format, color); + } + } + } + } + else + { + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (patp && dstp) + { + UINT32 colorA = ReadColor(patp, hdcDest->format); + UINT32 colorB = ReadColor(dstp, hdcDest->format); + UINT32 color = colorA ^ colorB; + WriteColor(dstp, hdcDest->format, color); + } + } + } + } + + return TRUE; +} + +BOOL BitBlt_PATPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc) +{ + UINT32 x, y; + + if (!hdcDest || !hdcSrc) return FALSE; - return _PatBlt(hdc, nXLeft, nYLeft, nWidth, nHeight, rop); + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc + x, nYSrc + y); + const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (srcp && patp && dstp) + { + UINT32 colorA = ReadColor(dstp, hdcDest->format); + UINT32 colorB = ReadColor(patp, hdcDest->format); + UINT32 colorC = ReadColor(srcp, hdcDest->format); + UINT32 color = colorA | colorB | ~colorC; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +BOOL BitBlt_PATCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight) +{ + UINT32 x, y, xOffset, yOffset; + + if (hdcDest->brush->style == GDI_BS_SOLID) + { + UINT32 color = hdcDest->brush->color; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (dstp) + WriteColor(dstp, hdcDest->format, color); + } + } + } + else + { + if (hdcDest->brush->style == GDI_BS_HATCHED) + { + xOffset = 0; + yOffset = 2; /* +2 added after comparison to mstsc */ + } + else + { + xOffset = 0; + yOffset = 0; + } + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + const BYTE* patp = gdi_get_brush_pointer( + hdcDest, nXDest + x + xOffset, + nYDest + y + yOffset); + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, + nYDest + y); + + if (patp && dstp) + { + UINT32 color = ReadColor(patp, hdcDest->format); + WriteColor(dstp, hdcDest->format, color); + } + } + } + } + + return TRUE; +} + +BOOL BitBlt_DSTINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight) +{ + UINT32 x, y; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + BYTE* dstp = gdi_get_bitmap_pointer( + hdcDest, nXDest + x, nYDest + y); + + if (dstp) + { + UINT32 color = ReadColor(dstp, hdcDest->format); + color = ~color; + WriteColor(dstp, hdcDest->format, color); + } + } + } + + return TRUE; +} + +BOOL BitBlt_BLACKNESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight) +{ + UINT32 x, y; + UINT32 color = GetColor(hdcDest->format, 0, 0, 0, 0xFF); + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (dstp) + WriteColor(dstp, hdcDest->format, color); + } + } + + return TRUE; +} + +BOOL BitBlt_WHITENESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight) +{ + UINT32 x, y; + UINT32 color = GetColor(hdcDest->format, 0, 0, 0, 0); + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y); + + if (dstp) + WriteColor(dstp, hdcDest->format, color); + } + } + + return TRUE; +} + +BOOL gdi_PatBlt(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft, + UINT32 nWidth, UINT32 nHeight, DWORD rop) +{ + if (!gdi_ClipCoords(hdc, &nXLeft, &nYLeft, &nWidth, &nHeight, NULL, NULL)) + return TRUE; + + if (!gdi_InvalidateRegion(hdc, nXLeft, nYLeft, nWidth, nHeight)) + return FALSE; + + switch (rop) + { + case GDI_PATCOPY: + return BitBlt_PATCOPY(hdc, nXLeft, nYLeft, nWidth, nHeight); + + case GDI_PATINVERT: + return BitBlt_PATINVERT(hdc, nXLeft, nYLeft, nWidth, nHeight); + + case GDI_DSTINVERT: + return BitBlt_DSTINVERT(hdc, nXLeft, nYLeft, nWidth, nHeight); + + case GDI_BLACKNESS: + return BitBlt_BLACKNESS(hdc, nXLeft, nYLeft, nWidth, nHeight); + + case GDI_WHITENESS: + return BitBlt_WHITENESS(hdc, nXLeft, nYLeft, nWidth, nHeight); + + case GDI_DPa: + return BitBlt_DPa(hdc, nXLeft, nYLeft, nWidth, nHeight); + + case GDI_PDxn: + return BitBlt_PDxn(hdc, nXLeft, nYLeft, nWidth, nHeight); + + default: + break; + } + + WLog_ERR(TAG, "PatBlt: unknown rop: 0x%08X", rop); + return FALSE; } diff --git a/libfreerdp/gdi/brush.h b/libfreerdp/gdi/brush.h new file mode 100644 index 000000000..df1d33f08 --- /dev/null +++ b/libfreerdp/gdi/brush.h @@ -0,0 +1,59 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Brush Functions + * + * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_BRUSH_H +#define FREERDP_GDI_BRUSH_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +HGDI_BRUSH gdi_CreateSolidBrush(UINT32 crColor); +HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp); +HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp); +BOOL gdi_PatBlt(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft, + UINT32 nWidth, UINT32 nHeight, DWORD rop); + +BOOL BitBlt_PATPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, + UINT32 nXSrc, UINT32 nYSrc); +BOOL BitBlt_PATINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight); +BOOL BitBlt_BLACKNESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight); +BOOL BitBlt_WHITENESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight); +BOOL BitBlt_PATCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight); +BOOL BitBlt_DSTINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, + UINT32 nWidth, UINT32 nHeight); + +#ifdef __cplusplus +} +#endif + +typedef BOOL (*p_PatBlt)(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft, + UINT32 nWidth, UINT32 nHeight, DWORD rop); + +#endif /* FREERDP_GDI_BRUSH_H */ diff --git a/libfreerdp/gdi/clipping.c b/libfreerdp/gdi/clipping.c index 74b259820..53ac51301 100644 --- a/libfreerdp/gdi/clipping.c +++ b/libfreerdp/gdi/clipping.c @@ -3,6 +3,8 @@ * GDI Clipping Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +32,9 @@ #include -#include +#include "clipping.h" -BOOL gdi_SetClipRgn(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight) +BOOL gdi_SetClipRgn(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft, UINT32 nWidth, UINT32 nHeight) { return gdi_SetRgn(hdc->clip, nXLeft, nYLeft, nWidth, nHeight); } @@ -74,7 +76,8 @@ BOOL gdi_SetNullClipRgn(HGDI_DC hdc) * @return nonzero if there is something to draw, 0 otherwise */ -BOOL gdi_ClipCoords(HGDI_DC hdc, int *x, int *y, int *w, int *h, int *srcx, int *srcy) +BOOL gdi_ClipCoords(HGDI_DC hdc, UINT32 *x, UINT32 *y, UINT32 *w, UINT32 *h, + UINT32 *srcx, UINT32 *srcy) { GDI_RECT bmp; GDI_RECT clip; diff --git a/include/freerdp/gdi/clipping.h b/libfreerdp/gdi/clipping.h similarity index 71% rename from include/freerdp/gdi/clipping.h rename to libfreerdp/gdi/clipping.h index eb8dec39f..9bd1093cd 100644 --- a/include/freerdp/gdi/clipping.h +++ b/libfreerdp/gdi/clipping.h @@ -3,6 +3,8 @@ * GDI Clipping Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,10 +29,11 @@ extern "C" { #endif -FREERDP_API BOOL gdi_SetClipRgn(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight); -FREERDP_API HGDI_RGN gdi_GetClipRgn(HGDI_DC hdc); -FREERDP_API BOOL gdi_SetNullClipRgn(HGDI_DC hdc); -FREERDP_API BOOL gdi_ClipCoords(HGDI_DC hdc, int *x, int *y, int *w, int *h, int *srcx, int *srcy); +BOOL gdi_SetClipRgn(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft, UINT32 nWidth, UINT32 nHeight); +HGDI_RGN gdi_GetClipRgn(HGDI_DC hdc); +BOOL gdi_SetNullClipRgn(HGDI_DC hdc); +BOOL gdi_ClipCoords(HGDI_DC hdc, UINT32 *x, UINT32 *y, + UINT32 *w, UINT32 *h, UINT32 *srcx, UINT32 *srcy); #ifdef __cplusplus } diff --git a/libfreerdp/gdi/dc.c b/libfreerdp/gdi/dc.c index f1032bef8..ea2ac3479 100644 --- a/libfreerdp/gdi/dc.c +++ b/libfreerdp/gdi/dc.c @@ -3,6 +3,8 @@ * GDI Device Context Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,14 +41,13 @@ * @return current device context */ -HGDI_DC gdi_GetDC() +HGDI_DC gdi_GetDC(void) { - HGDI_DC hDC = (HGDI_DC) malloc(sizeof(GDI_DC)); + HGDI_DC hDC = (HGDI_DC) calloc(1, sizeof(GDI_DC)); if (!hDC) return NULL; - hDC->bytesPerPixel = 4; - hDC->bitsPerPixel = 32; + hDC->format = PIXEL_FORMAT_XRGB32; hDC->drawMode = GDI_R2_BLACK; hDC->clip = gdi_CreateRectRgn(0, 0, 0, 0); if (!hDC->clip) @@ -65,7 +66,7 @@ HGDI_DC gdi_GetDC() * @return new device context */ -HGDI_DC gdi_CreateDC(UINT32 flags, int bpp) +HGDI_DC gdi_CreateDC(UINT32 format) { HGDI_DC hDC; @@ -80,12 +81,7 @@ HGDI_DC gdi_CreateDC(UINT32 flags, int bpp) hDC->clip->null = 1; hDC->hwnd = NULL; - hDC->bitsPerPixel = bpp; - hDC->bytesPerPixel = bpp / 8; - - hDC->alpha = (flags & CLRCONV_ALPHA) ? TRUE : FALSE; - hDC->invert = (flags & CLRCONV_INVERT) ? TRUE : FALSE; - hDC->rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE; + hDC->format = format; if (!(hDC->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND)))) goto fail; @@ -117,7 +113,7 @@ fail: HGDI_DC gdi_CreateCompatibleDC(HGDI_DC hdc) { - HGDI_DC hDC = (HGDI_DC) malloc(sizeof(GDI_DC)); + HGDI_DC hDC = (HGDI_DC) calloc(1, sizeof(GDI_DC)); if (!hDC) return NULL; @@ -127,13 +123,9 @@ HGDI_DC gdi_CreateCompatibleDC(HGDI_DC hdc) return NULL; } hDC->clip->null = 1; - hDC->bytesPerPixel = hdc->bytesPerPixel; - hDC->bitsPerPixel = hdc->bitsPerPixel; + hDC->format = hdc->format; hDC->drawMode = hdc->drawMode; hDC->hwnd = NULL; - hDC->alpha = hdc->alpha; - hDC->invert = hdc->invert; - hDC->rgb555 = hdc->rgb555; return hDC; } diff --git a/libfreerdp/gdi/drawing.c b/libfreerdp/gdi/drawing.c index 1e1475dc7..fe642006c 100644 --- a/libfreerdp/gdi/drawing.c +++ b/libfreerdp/gdi/drawing.c @@ -3,6 +3,8 @@ * GDI Drawing Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +33,7 @@ #include #include -#include +#include "drawing.h" /** * Set current foreground draw mode.\n @@ -40,7 +42,7 @@ * @return draw mode */ -int gdi_GetROP2(HGDI_DC hdc) +UINT32 gdi_GetROP2(HGDI_DC hdc) { return hdc->drawMode; } @@ -53,9 +55,9 @@ int gdi_GetROP2(HGDI_DC hdc) * @return previous draw mode */ -int gdi_SetROP2(HGDI_DC hdc, int fnDrawMode) +UINT32 gdi_SetROP2(HGDI_DC hdc, int fnDrawMode) { - int prevDrawMode = hdc->drawMode; + UINT32 prevDrawMode = hdc->drawMode; if (fnDrawMode > 0 && fnDrawMode <= 16) hdc->drawMode = fnDrawMode; @@ -70,7 +72,7 @@ int gdi_SetROP2(HGDI_DC hdc, int fnDrawMode) * @return background color */ -GDI_COLOR gdi_GetBkColor(HGDI_DC hdc) +UINT32 gdi_GetBkColor(HGDI_DC hdc) { return hdc->bkColor; } @@ -83,9 +85,9 @@ GDI_COLOR gdi_GetBkColor(HGDI_DC hdc) * @return previous background color */ -GDI_COLOR gdi_SetBkColor(HGDI_DC hdc, GDI_COLOR crColor) +UINT32 gdi_SetBkColor(HGDI_DC hdc, UINT32 crColor) { - GDI_COLOR previousBkColor = hdc->bkColor; + UINT32 previousBkColor = hdc->bkColor; hdc->bkColor = crColor; return previousBkColor; } @@ -97,7 +99,7 @@ GDI_COLOR gdi_SetBkColor(HGDI_DC hdc, GDI_COLOR crColor) * @return background mode */ -int gdi_GetBkMode(HGDI_DC hdc) +UINT32 gdi_GetBkMode(HGDI_DC hdc) { return hdc->bkMode; } @@ -110,7 +112,8 @@ int gdi_GetBkMode(HGDI_DC hdc) * @return previous background mode on success, 0 on failure */ -int gdi_SetBkMode(HGDI_DC hdc, int iBkMode) + +BOOL gdi_SetBkMode(HGDI_DC hdc, int iBkMode) { if (iBkMode == GDI_OPAQUE || iBkMode == GDI_TRANSPARENT) { @@ -118,7 +121,8 @@ int gdi_SetBkMode(HGDI_DC hdc, int iBkMode) hdc->bkMode = iBkMode; return previousBkMode; } - return 0; + + return TRUE; } /** @@ -129,9 +133,9 @@ int gdi_SetBkMode(HGDI_DC hdc, int iBkMode) * @return previous text color */ -GDI_COLOR gdi_SetTextColor(HGDI_DC hdc, GDI_COLOR crColor) +UINT32 gdi_SetTextColor(HGDI_DC hdc, UINT32 crColor) { - GDI_COLOR previousTextColor = hdc->textColor; + UINT32 previousTextColor = hdc->textColor; hdc->textColor = crColor; return previousTextColor; } diff --git a/include/freerdp/gdi/drawing.h b/libfreerdp/gdi/drawing.h similarity index 68% rename from include/freerdp/gdi/drawing.h rename to libfreerdp/gdi/drawing.h index 536ea3053..740070ade 100644 --- a/include/freerdp/gdi/drawing.h +++ b/libfreerdp/gdi/drawing.h @@ -3,6 +3,8 @@ * GDI Drawing Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,19 +26,19 @@ #include #ifdef __cplusplus - extern "C" { +extern "C" { #endif -FREERDP_API int gdi_GetROP2(HGDI_DC hdc); -FREERDP_API int gdi_SetROP2(HGDI_DC hdc, int fnDrawMode); -FREERDP_API GDI_COLOR gdi_GetBkColor(HGDI_DC hdc); -FREERDP_API GDI_COLOR gdi_SetBkColor(HGDI_DC hdc, GDI_COLOR crColor); -FREERDP_API int gdi_GetBkMode(HGDI_DC hdc); -FREERDP_API int gdi_SetBkMode(HGDI_DC hdc, int iBkMode); -FREERDP_API GDI_COLOR gdi_SetTextColor(HGDI_DC hdc, GDI_COLOR crColor); +UINT32 gdi_GetROP2(HGDI_DC hdc); +UINT32 gdi_SetROP2(HGDI_DC hdc, int fnDrawMode); +UINT32 gdi_GetBkColor(HGDI_DC hdc); +UINT32 gdi_SetBkColor(HGDI_DC hdc, UINT32 crColor); +UINT32 gdi_GetBkMode(HGDI_DC hdc); +BOOL gdi_SetBkMode(HGDI_DC hdc, int iBkMode); +UINT32 gdi_SetTextColor(HGDI_DC hdc, UINT32 crColor); #ifdef __cplusplus - } +} #endif #endif /* FREERDP_GDI_DRAWING_H */ diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 05226548f..e8568fad9 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -3,6 +3,8 @@ * GDI Library * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,14 +34,14 @@ #include #include -#include #include -#include #include #include -#include -#include +#include "drawing.h" +#include "clipping.h" +#include "brush.h" +#include "line.h" #include "gdi.h" #define TAG FREERDP_TAG("gdi") @@ -325,12 +327,12 @@ INLINE DWORD gdi_rop3_code(BYTE code) UINT32 gdi_get_pixel_format(UINT32 bitsPerPixel, BOOL vFlip) { - UINT32 format = PIXEL_FORMAT_XRGB32_VF; + UINT32 format = PIXEL_FORMAT_XBGR32_VF; switch (bitsPerPixel) { case 32: - format = vFlip ? PIXEL_FORMAT_XRGB32_VF : PIXEL_FORMAT_XRGB32; + format = vFlip ? PIXEL_FORMAT_XBGR32_VF : PIXEL_FORMAT_XBGR32; break; case 24: @@ -357,16 +359,17 @@ INLINE BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, int x, int y) { BYTE* p; HGDI_BITMAP hBmp = (HGDI_BITMAP) hdcBmp->selectedObject; - + if (x >= 0 && x < hBmp->width && y >= 0 && y < hBmp->height) { - p = hBmp->data + (y * hBmp->width * hdcBmp->bytesPerPixel) + (x * hdcBmp->bytesPerPixel); + p = hBmp->data + (y * hBmp->scanline) + (x * GetBytesPerPixel(hdcBmp->format)); return p; } else { - WLog_ERR(TAG, "gdi_get_bitmap_pointer: requesting invalid pointer: (%d,%d) in %dx%d", - x, y, hBmp->width, hBmp->height); + WLog_ERR(TAG, + "gdi_get_bitmap_pointer: requesting invalid pointer: (%d,%d) in %dx%d", + x, y, hBmp->width, hBmp->height); return 0; } } @@ -380,36 +383,40 @@ INLINE BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, int x, int y) */ INLINE BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, int x, int y) { - BYTE * p; + BYTE* p; if (hdcBrush->brush != NULL) { - if ((hdcBrush->brush->style == GDI_BS_PATTERN) || (hdcBrush->brush->style == GDI_BS_HATCHED)) + if ((hdcBrush->brush->style == GDI_BS_PATTERN) + || (hdcBrush->brush->style == GDI_BS_HATCHED)) { HGDI_BITMAP hBmpBrush = hdcBrush->brush->pattern; - + /* According to @msdn{dd183396}, the system always positions a brush bitmap * at the brush origin and copy across the client area. * Calculate the offset of the mapped pixel in the brush bitmap according to * brush origin and dest coordinates */ if (x >= 0 && y >= 0) { - x = (x + hBmpBrush->width - (hdcBrush->brush->nXOrg % hBmpBrush->width)) % hBmpBrush->width; - y = (y + hBmpBrush->height - (hdcBrush->brush->nYOrg % hBmpBrush->height)) % hBmpBrush->height; - p = hBmpBrush->data + (y * hBmpBrush->scanline) + (x * hBmpBrush->bytesPerPixel); + x = (x + hBmpBrush->width - (hdcBrush->brush->nXOrg % hBmpBrush->width)) % + hBmpBrush->width; + y = (y + hBmpBrush->height - (hdcBrush->brush->nYOrg % hBmpBrush->height)) % + hBmpBrush->height; + p = hBmpBrush->data + (y * hBmpBrush->scanline) + (x * GetBytesPerPixel( + hBmpBrush->format)); return p; } } } - p = (BYTE*) &(hdcBrush->textColor); + p = (BYTE*) & (hdcBrush->textColor); return p; } -gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data) +gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, + BYTE* data) { gdiBitmap* bitmap; - bitmap = (gdiBitmap*) calloc(1, sizeof(gdiBitmap)); if (!bitmap) @@ -430,9 +437,7 @@ gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* gdi_SelectObject(bitmap->hdc, (HGDIOBJECT) bitmap->bitmap); bitmap->org_bitmap = NULL; - return bitmap; - fail_bitmap_bitmap: gdi_DeleteDC(bitmap->hdc); fail_hdc: @@ -452,23 +457,23 @@ void gdi_bitmap_free_ex(gdiBitmap* bitmap) } } -static BOOL gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) +static BOOL gdi_bitmap_update(rdpContext* context, + const BITMAP_UPDATE* bitmapUpdate) { int status; - int nXDst; - int nYDst; - int nXSrc; - int nYSrc; - int nWidth; - int nHeight; - int nSrcStep; - int nDstStep; + UINT32 nXDst; + UINT32 nYDst; + UINT32 nXSrc; + UINT32 nYSrc; + UINT32 nWidth; + UINT32 nHeight; + UINT32 nSrcStep; + UINT32 nDstStep; UINT32 index; BYTE* pSrcData; BYTE* pDstData; UINT32 SrcSize; BOOL compressed; - UINT32 SrcFormat; UINT32 bitsPerPixel; BITMAP_DATA* bitmap; rdpGdi* gdi = context->gdi; @@ -477,26 +482,22 @@ static BOOL gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) for (index = 0; index < bitmapUpdate->number; index++) { 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; - if (gdi->bitmap_size < (UINT32) (nWidth * nHeight * 4)) + if (gdi->bitmap_size < (UINT32)(nWidth * nHeight * 4)) { gdi->bitmap_size = nWidth * nHeight * 4; - gdi->bitmap_buffer = (BYTE*) _aligned_realloc(gdi->bitmap_buffer, gdi->bitmap_size, 16); + gdi->bitmap_buffer = (BYTE*) _aligned_realloc(gdi->bitmap_buffer, + gdi->bitmap_size, 16); if (!gdi->bitmap_buffer) return FALSE; @@ -512,8 +513,14 @@ static BOOL gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) gdi->width, gdi->height)) return FALSE; - status = interleaved_decompress(codecs->interleaved, pSrcData, SrcSize, bitsPerPixel, - &pDstData, gdi->format, -1, 0, 0, nWidth, nHeight, gdi->palette); + status = interleaved_decompress(codecs->interleaved, + pSrcData, SrcSize, + bitsPerPixel, + pDstData, + gdi->dstFormat, + -1, 0, 0, + nWidth, nHeight, + gdi->palette); } else { @@ -522,7 +529,7 @@ static BOOL gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) return FALSE; status = planar_decompress(codecs->planar, pSrcData, SrcSize, &pDstData, - gdi->format, -1, 0, 0, nWidth, nHeight, TRUE); + gdi->dstFormat, -1, 0, 0, nWidth, nHeight, TRUE); } if (status < 0) @@ -533,104 +540,99 @@ static BOOL gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) pSrcData = gdi->bitmap_buffer; } - else - { - pDstData = gdi->bitmap_buffer; - SrcFormat = gdi_get_pixel_format(bitsPerPixel, TRUE); - - status = freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, - nWidth, nHeight, pSrcData, SrcFormat, -1, 0, 0, gdi->palette); - - pSrcData = gdi->bitmap_buffer; - } - - nSrcStep = nWidth * gdi->bytesPerPixel; + nSrcStep = nWidth * GetBytesPerPixel(gdi->dstFormat); pDstData = gdi->primary_buffer; - nDstStep = gdi->width * gdi->bytesPerPixel; - - nWidth = MIN(bitmap->destRight, gdi->width - 1) - bitmap->destLeft + 1; /* clip width */ - nHeight = MIN(bitmap->destBottom, gdi->height - 1) - bitmap->destTop + 1; /* clip height */ + nDstStep = gdi->stride; + 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 (nWidth <= 0 || nHeight <= 0) { /* Empty bitmap */ continue; } - status = freerdp_image_copy(pDstData, gdi->format, nDstStep, nXDst, nYDst, - nWidth, nHeight, pSrcData, gdi->format, nSrcStep, nXSrc, nYSrc, gdi->palette); + + status = freerdp_image_copy(pDstData, gdi->dstFormat, nDstStep, nXDst, nYDst, + nWidth, nHeight, pSrcData, gdi->dstFormat, nSrcStep, nXSrc, nYSrc, + gdi->palette); if (!gdi_InvalidateRegion(gdi->primary->hdc, nXDst, nYDst, nWidth, nHeight)) return FALSE; } + return TRUE; } -static BOOL gdi_palette_update(rdpContext* context, PALETTE_UPDATE* palette) +static BOOL gdi_palette_update(rdpContext* context, + const PALETTE_UPDATE* palette) { int index; - PALETTE_ENTRY* pe; + const PALETTE_ENTRY* pe; UINT32* palette32; rdpGdi* gdi = context->gdi; - palette32 = (UINT32*) gdi->palette; for (index = 0; index < (int) palette->number; index++) { pe = &(palette->entries[index]); - palette32[index] = RGB32(pe->red, pe->green, pe->blue); + palette32[index] = GetColor(gdi->dstFormat, pe->red, pe->green, pe->blue, + 0xFF); } + return TRUE; } -static BOOL gdi_set_bounds(rdpContext* context, rdpBounds* bounds) +static BOOL gdi_set_bounds(rdpContext* context, const rdpBounds* bounds) { rdpGdi* gdi = context->gdi; if (bounds) { gdi_SetClipRgn(gdi->drawing->hdc, bounds->left, bounds->top, - bounds->right - bounds->left + 1, bounds->bottom - bounds->top + 1); + bounds->right - bounds->left + 1, bounds->bottom - bounds->top + 1); } else { gdi_SetNullClipRgn(gdi->drawing->hdc); } + return TRUE; } -static BOOL gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) +static BOOL gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt) { rdpGdi* gdi = context->gdi; - return gdi_BitBlt(gdi->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect, - dstblt->nWidth, dstblt->nHeight, NULL, 0, 0, - gdi_rop3_code(dstblt->bRop)); + dstblt->nWidth, dstblt->nHeight, NULL, 0, 0, + gdi_rop3_code(dstblt->bRop)); } static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { BYTE* data; - rdpBrush* brush; + const rdpBrush* brush; UINT32 foreColor; UINT32 backColor; - GDI_COLOR originalColor; + UINT32 originalColor; HGDI_BRUSH originalBrush; rdpGdi* gdi = context->gdi; BOOL ret = TRUE; - + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); brush = &patblt->brush; - - foreColor = freerdp_convert_gdi_order_color(patblt->foreColor, gdi->srcBpp, gdi->format, gdi->palette); - backColor = freerdp_convert_gdi_order_color(patblt->backColor, gdi->srcBpp, gdi->format, gdi->palette); - + foreColor = ConvertColor(patblt->foreColor, SrcFormat, + gdi->dstFormat, gdi->palette); + backColor = ConvertColor(patblt->backColor, SrcFormat, + gdi->dstFormat, gdi->palette); originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor); if (brush->style == GDI_BS_SOLID) { originalBrush = gdi->drawing->hdc->brush; - gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor); + if (!gdi->drawing->hdc->brush) { ret = FALSE; @@ -638,7 +640,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) } if (!gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, - patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) + patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) { ret = FALSE; } @@ -650,8 +652,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { BYTE* hatched; HGDI_BITMAP hBmp; + data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16); - data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16); if (!data) { ret = FALSE; @@ -659,11 +661,10 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) } hatched = GDI_BS_HATCHED_PATTERNS + (8 * brush->hatch); + freerdp_image_copy_from_monochrome(data, gdi->dstFormat, -1, 0, 0, 8, 8, + hatched, backColor, foreColor, gdi->palette); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data); - freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8, - hatched, backColor, foreColor, gdi->palette); - - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); if (!hBmp) { _aligned_free(data); @@ -673,17 +674,19 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) originalBrush = gdi->drawing->hdc->brush; gdi->drawing->hdc->brush = gdi_CreateHatchBrush(hBmp); + if (!gdi->drawing->hdc->brush) { _aligned_free(data); ret = FALSE; goto out_error; } + gdi->drawing->hdc->brush->nXOrg = brush->x; gdi->drawing->hdc->brush->nYOrg = brush->y; if (!gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, - patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) + patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) { ret = FALSE; } @@ -699,31 +702,33 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) if (brush->bpp > 1) { brushFormat = gdi_get_pixel_format(brush->bpp, FALSE); + data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16); - data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16); if (!data) { ret = FALSE; goto out_error; } - freerdp_image_copy(data, gdi->format, -1, 0, 0, - 8, 8, brush->data, brushFormat, -1, 0, 0, gdi->palette); + freerdp_image_copy(data, gdi->dstFormat, -1, 0, 0, + 8, 8, brush->data, brushFormat, -1, 0, 0, gdi->palette); } else { - data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16); + data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16); + if (!data) { ret = FALSE; goto out_error; } - freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8, - brush->data, backColor, foreColor, gdi->palette); + freerdp_image_copy_from_monochrome(data, gdi->dstFormat, -1, 0, 0, 8, 8, + brush->data, backColor, foreColor, gdi->palette); } - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data); + if (!hBmp) { _aligned_free(data); @@ -733,17 +738,19 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) originalBrush = gdi->drawing->hdc->brush; gdi->drawing->hdc->brush = gdi_CreatePatternBrush(hBmp); + if (!gdi->drawing->hdc->brush) { _aligned_free(data); ret = FALSE; goto out_error; } + gdi->drawing->hdc->brush->nXOrg = brush->x; gdi->drawing->hdc->brush->nYOrg = brush->y; if (!gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, - patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) + patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop))) { ret = FALSE; } @@ -761,111 +768,112 @@ out_error: return ret; } -static BOOL gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) +static BOOL gdi_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt) { rdpGdi* gdi = context->gdi; - return gdi_BitBlt(gdi->drawing->hdc, scrblt->nLeftRect, scrblt->nTopRect, - scrblt->nWidth, scrblt->nHeight, gdi->primary->hdc, - scrblt->nXSrc, scrblt->nYSrc, gdi_rop3_code(scrblt->bRop)); + scrblt->nWidth, scrblt->nHeight, gdi->primary->hdc, + scrblt->nXSrc, scrblt->nYSrc, gdi_rop3_code(scrblt->bRop)); } -static BOOL gdi_opaque_rect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect) +static BOOL gdi_opaque_rect(rdpContext* context, + const OPAQUE_RECT_ORDER* opaque_rect) { GDI_RECT rect; HGDI_BRUSH hBrush; UINT32 brush_color; rdpGdi* gdi = context->gdi; BOOL ret; - + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); gdi_CRgnToRect(opaque_rect->nLeftRect, opaque_rect->nTopRect, - opaque_rect->nWidth, opaque_rect->nHeight, &rect); - - brush_color = freerdp_convert_gdi_order_color(opaque_rect->color, gdi->srcBpp, gdi->format, gdi->palette); + opaque_rect->nWidth, opaque_rect->nHeight, &rect); + brush_color = ConvertColor(opaque_rect->color, SrcFormat, + gdi->dstFormat, gdi->palette); if (!(hBrush = gdi_CreateSolidBrush(brush_color))) return FALSE; ret = gdi_FillRect(gdi->drawing->hdc, &rect, hBrush); gdi_DeleteObject((HGDIOBJECT) hBrush); - return ret; } -static BOOL gdi_multi_opaque_rect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) +static BOOL gdi_multi_opaque_rect(rdpContext* context, + const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) { - int i; + UINT32 i; GDI_RECT rect; HGDI_BRUSH hBrush; UINT32 brush_color; - DELTA_RECT* rectangle; + const DELTA_RECT* rectangle; rdpGdi* gdi = context->gdi; + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); BOOL ret = TRUE; - for (i = 1; i < (int) multi_opaque_rect->numRectangles + 1; i++) + for (i = 1; i < multi_opaque_rect->numRectangles + 1; i++) { rectangle = &multi_opaque_rect->rectangles[i]; - gdi_CRgnToRect(rectangle->left, rectangle->top, - rectangle->width, rectangle->height, &rect); - - brush_color = freerdp_convert_gdi_order_color(multi_opaque_rect->color, gdi->srcBpp, gdi->format, gdi->palette); - + rectangle->width, rectangle->height, &rect); + brush_color = ConvertColor(multi_opaque_rect->color, SrcFormat, + gdi->dstFormat, gdi->palette); hBrush = gdi_CreateSolidBrush(brush_color); + if (!hBrush) { ret = FALSE; break; } - gdi_FillRect(gdi->drawing->hdc, &rect, hBrush); + gdi_FillRect(gdi->drawing->hdc, &rect, hBrush); gdi_DeleteObject((HGDIOBJECT) hBrush); } + return ret; } -static BOOL gdi_line_to(rdpContext* context, LINE_TO_ORDER* lineTo) +static BOOL gdi_line_to(rdpContext* context, const LINE_TO_ORDER* lineTo) { UINT32 color; HGDI_PEN hPen; rdpGdi* gdi = context->gdi; + color = lineTo->penColor; + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); - color = freerdp_convert_gdi_order_color(lineTo->penColor, gdi->srcBpp, gdi->format, gdi->palette); - if (!(hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, (GDI_COLOR) color))) + if (!(hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, color, + SrcFormat))) return FALSE; gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen); gdi_SetROP2(gdi->drawing->hdc, lineTo->bRop2); - gdi_MoveToEx(gdi->drawing->hdc, lineTo->nXStart, lineTo->nYStart, NULL); gdi_LineTo(gdi->drawing->hdc, lineTo->nXEnd, lineTo->nYEnd); - gdi_DeleteObject((HGDIOBJECT) hPen); return TRUE; } -static BOOL gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) +static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline) { - int i; + UINT32 i; INT32 x; INT32 y; UINT32 color; HGDI_PEN hPen; DELTA_POINT* points; rdpGdi* gdi = context->gdi; + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); + color = polyline->penColor; - color = freerdp_convert_gdi_order_color(polyline->penColor, gdi->srcBpp, gdi->format, gdi->palette); - if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, (GDI_COLOR) color))) + if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, color, SrcFormat))) return FALSE; gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen); gdi_SetROP2(gdi->drawing->hdc, polyline->bRop2); - x = polyline->xStart; y = polyline->yStart; gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL); - points = polyline->points; + for (i = 0; i < (int) polyline->numDeltaEntries; i++) { x += points[i].x; @@ -882,38 +890,37 @@ static BOOL gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { gdiBitmap* bitmap; rdpGdi* gdi = context->gdi; - bitmap = (gdiBitmap*) memblt->bitmap; - return gdi_BitBlt(gdi->drawing->hdc, memblt->nLeftRect, memblt->nTopRect, - memblt->nWidth, memblt->nHeight, bitmap->hdc, - memblt->nXSrc, memblt->nYSrc, gdi_rop3_code(memblt->bRop)); + memblt->nWidth, memblt->nHeight, bitmap->hdc, + memblt->nXSrc, memblt->nYSrc, gdi_rop3_code(memblt->bRop)); } static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) { BYTE* data; - rdpBrush* brush; + const rdpBrush* brush; UINT32 foreColor; UINT32 backColor; gdiBitmap* bitmap; - GDI_COLOR originalColor; + UINT32 originalColor; HGDI_BRUSH originalBrush; rdpGdi* gdi = context->gdi; BOOL ret = TRUE; - + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); brush = &mem3blt->brush; bitmap = (gdiBitmap*) mem3blt->bitmap; - - foreColor = freerdp_convert_gdi_order_color(mem3blt->foreColor, gdi->srcBpp, gdi->format, gdi->palette); - backColor = freerdp_convert_gdi_order_color(mem3blt->backColor, gdi->srcBpp, gdi->format, gdi->palette); - + foreColor = ConvertColor(mem3blt->foreColor, SrcFormat, + gdi->dstFormat, gdi->palette); + backColor = ConvertColor(mem3blt->backColor, SrcFormat, + gdi->dstFormat, gdi->palette); originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor); if (brush->style == GDI_BS_SOLID) { originalBrush = gdi->drawing->hdc->brush; gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor); + if (!gdi->drawing->hdc->brush) { ret = FALSE; @@ -921,9 +928,8 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) } gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, - mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, - mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop)); - + mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, + mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop)); gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush); gdi->drawing->hdc->brush = originalBrush; } @@ -935,31 +941,33 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) if (brush->bpp > 1) { brushFormat = gdi_get_pixel_format(brush->bpp, FALSE); + data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16); - data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16); if (!data) { ret = FALSE; goto out_fail; } - freerdp_image_copy(data, gdi->format, -1, 0, 0, - 8, 8, brush->data, brushFormat, -1, 0, 0, gdi->palette); + freerdp_image_copy(data, gdi->dstFormat, -1, 0, 0, + 8, 8, brush->data, brushFormat, -1, 0, 0, gdi->palette); } else { - data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16); + data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16); + if (!data) { ret = FALSE; goto out_fail; } - freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8, - brush->data, backColor, foreColor, gdi->palette); + freerdp_image_copy_from_monochrome(data, gdi->dstFormat, -1, 0, 0, 8, 8, + brush->data, backColor, foreColor, gdi->palette); } - hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data); + hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data); + if (!hBmp) { _aligned_free(data); @@ -969,18 +977,18 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) originalBrush = gdi->drawing->hdc->brush; gdi->drawing->hdc->brush = gdi_CreatePatternBrush(hBmp); + if (!gdi->drawing->hdc->brush) { gdi_DeleteObject((HGDIOBJECT) hBmp); goto out_fail; } + gdi->drawing->hdc->brush->nXOrg = brush->x; gdi->drawing->hdc->brush->nYOrg = brush->y; - gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, - mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, - mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop)); - + mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, + mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop)); gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush); gdi->drawing->hdc->brush = originalBrush; } @@ -994,7 +1002,8 @@ out_fail: return ret; } -static BOOL gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc) +static BOOL gdi_polygon_sc(rdpContext* context, + const POLYGON_SC_ORDER* polygon_sc) { WLog_VRB(TAG, "%s: not implemented", __FUNCTION__); return TRUE; @@ -1006,28 +1015,32 @@ static BOOL gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) return TRUE; } -static BOOL gdi_ellipse_sc(rdpContext* context, ELLIPSE_SC_ORDER* ellipse_sc) +static BOOL gdi_ellipse_sc(rdpContext* context, + const ELLIPSE_SC_ORDER* ellipse_sc) { WLog_VRB(TAG, "%s: not implemented", __FUNCTION__); return TRUE; } -static BOOL gdi_ellipse_cb(rdpContext* context, ELLIPSE_CB_ORDER* ellipse_cb) +static BOOL gdi_ellipse_cb(rdpContext* context, + const ELLIPSE_CB_ORDER* ellipse_cb) { WLog_VRB(TAG, "%s: not implemented", __FUNCTION__); return TRUE; } -static BOOL gdi_frame_marker(rdpContext* context, FRAME_MARKER_ORDER* frameMarker) +static BOOL gdi_frame_marker(rdpContext* context, + const FRAME_MARKER_ORDER* frameMarker) { return TRUE; } -BOOL gdi_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surfaceFrameMarker) +BOOL gdi_surface_frame_marker(rdpContext* context, + const SURFACE_FRAME_MARKER* surfaceFrameMarker) { DEBUG_GDI("frameId %d frameAction %d", - surfaceFrameMarker->frameId, - surfaceFrameMarker->frameAction); + surfaceFrameMarker->frameId, + surfaceFrameMarker->frameAction); switch (surfaceFrameMarker->frameAction) { @@ -1037,26 +1050,36 @@ BOOL gdi_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surface case SURFACECMD_FRAMEACTION_END: if (context->settings->FrameAcknowledge > 0) { - IFCALL(context->update->SurfaceFrameAcknowledge, context, surfaceFrameMarker->frameId); + IFCALL(context->update->SurfaceFrameAcknowledge, context, + surfaceFrameMarker->frameId); } + break; } + return TRUE; } -static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) +static BOOL gdi_surface_bits(rdpContext* context, + const SURFACE_BITS_COMMAND* cmd) { - int i, j; - int tx, ty; BYTE* pSrcData; BYTE* pDstData; - RFX_MESSAGE* message; rdpGdi* gdi = context->gdi; - DEBUG_GDI("destLeft %d destTop %d destRight %d destBottom %d " - "bpp %d codecID %d width %d height %d length %d", - cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom, - cmd->bpp, cmd->codecID, cmd->width, cmd->height, cmd->bitmapDataLength); + "bpp %d codecID %d width %d height %d length %d", + cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom, + cmd->bpp, cmd->codecID, cmd->width, cmd->height, cmd->bitmapDataLength); + + if (gdi->bitmap_size < (cmd->width * cmd->height * 4)) + { + gdi->bitmap_size = cmd->width * cmd->height * 4; + gdi->bitmap_buffer = (BYTE*) _aligned_realloc(gdi->bitmap_buffer, + gdi->bitmap_size, 16); + + if (!gdi->bitmap_buffer) + return FALSE; + } if (cmd->codecID == RDP_CODEC_ID_REMOTEFX) { @@ -1064,46 +1087,18 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) gdi->width, gdi->height)) return FALSE; - if (!(message = rfx_process_message(gdi->codecs->rfx, cmd->bitmapData, cmd->bitmapDataLength))) + pDstData = gdi->bitmap_buffer; + + if (!rfx_process_message(gdi->codecs->rfx, cmd->bitmapData, + PIXEL_FORMAT_BGRX32, + cmd->bitmapDataLength, + cmd->destLeft, cmd->destTop, + pDstData, gdi->dstFormat, + gdi->width, gdi->height, NULL)) { WLog_ERR(TAG, "Failed to process RemoteFX message"); return FALSE; } - - /* blit each tile */ - for (i = 0; i < message->numTiles; i++) - { - tx = message->tiles[i]->x + cmd->destLeft; - ty = message->tiles[i]->y + cmd->destTop; - - pSrcData = message->tiles[i]->data; - pDstData = gdi->tile->bitmap->data; - - if (!gdi->invert && (gdi->dstBpp == 32)) - { - gdi->tile->bitmap->data = pSrcData; - } - else - { - freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, - 64, 64, pSrcData, PIXEL_FORMAT_XRGB32, -1, 0, 0, gdi->palette); - } - - for (j = 0; j < message->numRects; j++) - { - gdi_SetClipRgn(gdi->primary->hdc, - cmd->destLeft + message->rects[j].x, - cmd->destTop + message->rects[j].y, - message->rects[j].width, message->rects[j].height); - - gdi_BitBlt(gdi->primary->hdc, tx, ty, 64, 64, gdi->tile->hdc, 0, 0, GDI_SRCCOPY); - } - - gdi->tile->bitmap->data = pDstData; - } - - gdi_SetNullClipRgn(gdi->primary->hdc); - rfx_message_free(gdi->codecs->rfx, message); } else if (cmd->codecID == RDP_CODEC_ID_NSCODEC) { @@ -1111,56 +1106,43 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) gdi->width, gdi->height)) return FALSE; - nsc_process_message(gdi->codecs->nsc, cmd->bpp, cmd->width, cmd->height, cmd->bitmapData, cmd->bitmapDataLength); - - if (gdi->bitmap_size < (cmd->width * cmd->height * 4)) - { - gdi->bitmap_size = cmd->width * cmd->height * 4; - gdi->bitmap_buffer = (BYTE*) _aligned_realloc(gdi->bitmap_buffer, gdi->bitmap_size, 16); - - if (!gdi->bitmap_buffer) - return FALSE; - } - + nsc_process_message(gdi->codecs->nsc, cmd->bpp, cmd->width, + cmd->height, cmd->bitmapData, + cmd->bitmapDataLength); pDstData = gdi->bitmap_buffer; pSrcData = gdi->codecs->nsc->BitmapData; - - freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, - cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); - + freerdp_image_copy(pDstData, gdi->dstFormat, -1, 0, 0, + cmd->width, cmd->height, pSrcData, + PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); gdi_DeleteObject((HGDIOBJECT)gdi->image->bitmap); - gdi->image->bitmap = gdi_CreateBitmapEx(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); + gdi->image->bitmap = gdi_CreateBitmapEx(cmd->width, cmd->height, + gdi->dstFormat, 0, + pDstData, NULL); gdi_SelectObject(gdi->image->hdc, (HGDIOBJECT) gdi->image->bitmap); - - gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); - } + gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, + cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); + } else if (cmd->codecID == RDP_CODEC_ID_NONE) { - if (gdi->bitmap_size < (cmd->width * cmd->height * 4)) - { - gdi->bitmap_size = cmd->width * cmd->height * 4; - gdi->bitmap_buffer = (BYTE*) _aligned_realloc(gdi->bitmap_buffer, gdi->bitmap_size, 16); - - if (!gdi->bitmap_buffer) - return FALSE; - } - pDstData = gdi->bitmap_buffer; pSrcData = cmd->bitmapData; - - freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, - cmd->width, cmd->height, pSrcData, PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); - + freerdp_image_copy(pDstData, gdi->dstFormat, -1, 0, 0, + cmd->width, cmd->height, pSrcData, + PIXEL_FORMAT_XRGB32_VF, -1, 0, 0, gdi->palette); gdi_DeleteObject((HGDIOBJECT)gdi->image->bitmap); - gdi->image->bitmap = gdi_CreateBitmapEx(cmd->width, cmd->height, cmd->bpp, gdi->bitmap_buffer, NULL); + gdi->image->bitmap = gdi_CreateBitmapEx(cmd->width, cmd->height, + gdi->dstFormat, + 0, + pDstData, NULL); gdi_SelectObject(gdi->image->hdc, (HGDIOBJECT) gdi->image->bitmap); - - gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); + gdi_BitBlt(gdi->primary->hdc, cmd->destLeft, cmd->destTop, + cmd->width, cmd->height, gdi->image->hdc, 0, 0, GDI_SRCCOPY); } else { WLog_ERR(TAG, "Unsupported codecID %d", cmd->codecID); } + return TRUE; } @@ -1173,10 +1155,8 @@ static BOOL gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* cmd) void gdi_register_update_callbacks(rdpUpdate* update) { rdpPrimaryUpdate* primary = update->primary; - update->Palette = gdi_palette_update; update->SetBounds = gdi_set_bounds; - primary->DstBlt = gdi_dstblt; primary->PatBlt = gdi_patblt; primary->ScrBlt = gdi_scrblt; @@ -1199,14 +1179,13 @@ void gdi_register_update_callbacks(rdpUpdate* update) primary->PolygonCB = gdi_polygon_cb; primary->EllipseSC = gdi_ellipse_sc; primary->EllipseCB = gdi_ellipse_cb; - update->SurfaceBits = gdi_surface_bits; update->SurfaceFrameMarker = gdi_surface_frame_marker; - update->altsec->FrameMarker = gdi_frame_marker; } -BOOL gdi_init_primary(rdpGdi* gdi) +static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, BYTE* buffer, + void (*pfree)(void*)) { gdi->primary = (gdiBitmap*) calloc(1, sizeof(gdiBitmap)); @@ -1216,36 +1195,47 @@ BOOL gdi_init_primary(rdpGdi* gdi) if (!(gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc))) goto fail_hdc; - if (!gdi->primary_buffer) - gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height); + if (!buffer) + { + gdi->primary->bitmap = gdi_CreateCompatibleBitmap( + gdi->hdc, gdi->width, gdi->height); + } else - gdi->primary->bitmap = gdi_CreateBitmapEx(gdi->width, gdi->height, gdi->dstBpp, - gdi->primary_buffer, NULL); + { + gdi->primary->bitmap = gdi_CreateBitmapEx(gdi->width, gdi->height, + gdi->dstFormat, + gdi->stride, + gdi->primary_buffer, pfree); + } + + gdi->stride = gdi->primary->bitmap->scanline; if (!gdi->primary->bitmap) goto fail_bitmap; gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT) gdi->primary->bitmap); gdi->primary->org_bitmap = NULL; - gdi->primary_buffer = gdi->primary->bitmap->data; if (!(gdi->primary->hdc->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND)))) goto fail_hwnd; + if (!(gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0))) goto fail_hwnd; - gdi->primary->hdc->hwnd->invalid->null = 1; + gdi->primary->hdc->hwnd->invalid->null = 1; gdi->primary->hdc->hwnd->count = 32; - if (!(gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) calloc(gdi->primary->hdc->hwnd->count, sizeof(GDI_RGN)))) + + if (!(gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) calloc( + gdi->primary->hdc->hwnd->count, sizeof(GDI_RGN)))) goto fail_hwnd; + gdi->primary->hdc->hwnd->ninvalid = 0; if (!gdi->drawing) gdi->drawing = gdi->primary; return TRUE; - fail_hwnd: gdi_DeleteObject((HGDIOBJECT) gdi->primary->bitmap); fail_bitmap: @@ -1257,7 +1247,14 @@ fail_primary: return FALSE; } -BOOL gdi_resize(rdpGdi* gdi, int width, int height) +BOOL gdi_resize(rdpGdi* gdi, UINT32 width, UINT32 height) +{ + return gdi_resize_ex(gdi, width, height, -1, -1, NULL, NULL); +} + +BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, + INT32 stride, INT32 format, BYTE* buffer, + void (*pfree)(void*)) { if (!gdi || !gdi->primary) return FALSE; @@ -1271,11 +1268,9 @@ BOOL gdi_resize(rdpGdi* gdi, int width, int height) gdi->width = width; gdi->height = height; gdi_bitmap_free_ex(gdi->primary); - gdi->primary = NULL; gdi->primary_buffer = NULL; - - return gdi_init_primary(gdi); + return gdi_init_primary(gdi, stride, buffer, pfree); } /** @@ -1283,13 +1278,17 @@ BOOL gdi_resize(rdpGdi* gdi, int width, int height) * @param inst current instance * @return */ - -BOOL gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer) +BOOL gdi_init(freerdp* instance, UINT32 format) +{ + return gdi_init_ex(instance, format, 0, NULL, _aligned_free); +} + +BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer, + void (*pfree)(void*)) { - BOOL rgb555; rdpGdi* gdi; rdpCache* cache = NULL; - + UINT32 SrcFormat = gdi_get_pixel_format(instance->settings->ColorDepth, FALSE); gdi = (rdpGdi*) calloc(1, sizeof(rdpGdi)); if (!gdi) @@ -1300,80 +1299,21 @@ BOOL gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer) gdi->codecs = instance->context->codecs; gdi->width = instance->settings->DesktopWidth; gdi->height = instance->settings->DesktopHeight; - gdi->srcBpp = instance->settings->ColorDepth; - gdi->primary_buffer = buffer; - + gdi->dstFormat = format; /* default internal buffer format */ - gdi->dstBpp = 32; - gdi->bytesPerPixel = 4; - gdi->format = PIXEL_FORMAT_XRGB32; - - if (flags & CLRCONV_INVERT) - gdi->invert = TRUE; - - rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE; - - if (gdi->srcBpp > 16) - { - if (flags & CLRBUF_32BPP) - { - gdi->dstBpp = 32; - gdi->bytesPerPixel = 4; - } - else if (flags & CLRBUF_16BPP) - { - gdi->dstBpp = rgb555 ? 15 : 16; - gdi->bytesPerPixel = 2; - } - } - else - { - if (flags & CLRBUF_16BPP) - { - gdi->dstBpp = rgb555 ? 15 : 16; - gdi->bytesPerPixel = 2; - } - else if (flags & CLRBUF_32BPP) - { - gdi->dstBpp = 32; - gdi->bytesPerPixel = 4; - } - } - - if (!gdi->invert) - { - if (gdi->bytesPerPixel == 4) - gdi->format = PIXEL_FORMAT_XRGB32; - else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 16)) - gdi->format = PIXEL_FORMAT_RGB565; - else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 15)) - gdi->format = PIXEL_FORMAT_RGB555; - } - else - { - if (gdi->bytesPerPixel == 4) - gdi->format = PIXEL_FORMAT_XBGR32; - else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 16)) - gdi->format = PIXEL_FORMAT_BGR565; - else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 15)) - gdi->format = PIXEL_FORMAT_BGR555; - } + WLog_INFO(TAG, "Local framebuffer format %s", + GetColorFormatName(gdi->dstFormat)); + WLog_INFO(TAG, "Remote framebuffer format %s", + GetColorFormatName(SrcFormat)); if (!(gdi->hdc = gdi_GetDC())) goto fail_get_hdc; - gdi->hdc->bitsPerPixel = gdi->dstBpp; - gdi->hdc->bytesPerPixel = gdi->bytesPerPixel; + gdi->hdc->format = gdi->dstFormat; - gdi->hdc->alpha = (flags & CLRCONV_ALPHA) ? TRUE : FALSE; - gdi->hdc->invert = (flags & CLRCONV_INVERT) ? TRUE : FALSE; - gdi->hdc->rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE; - - if (!gdi_init_primary(gdi)) + if (!gdi_init_primary(gdi, stride, buffer, pfree)) goto fail_init_primary; - if (!(gdi->tile = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL))) - goto fail_tile_bitmap; if (!(gdi->image = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL))) goto fail_image_bitmap; @@ -1386,7 +1326,6 @@ BOOL gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer) } gdi_register_update_callbacks(instance->update); - brush_cache_register_callbacks(instance->update); glyph_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); @@ -1397,20 +1336,18 @@ BOOL gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer) goto fail_register_graphics; instance->update->BitmapUpdate = gdi_bitmap_update; - return TRUE; - fail_register_graphics: + if (cache) { instance->context->cache = NULL; free(cache); } + fail_cache: gdi_bitmap_free_ex(gdi->image); fail_image_bitmap: - gdi_bitmap_free_ex(gdi->tile); -fail_tile_bitmap: gdi_bitmap_free_ex(gdi->primary); fail_init_primary: gdi_DeleteDC(gdi->hdc); @@ -1428,13 +1365,12 @@ void gdi_free(freerdp* instance) if (gdi) { gdi_bitmap_free_ex(gdi->primary); - gdi_bitmap_free_ex(gdi->tile); gdi_bitmap_free_ex(gdi->image); gdi_DeleteDC(gdi->hdc); _aligned_free(gdi->bitmap_buffer); free(gdi); } - + instance->context->gdi = (rdpGdi*) NULL; } diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index 100dc241a..f0f46b06b 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -77,7 +77,8 @@ UINT gdi_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* free(pSurfaceIds); - if (!freerdp_client_codecs_reset(gdi->codecs, FREERDP_CODEC_ALL, gdi->width, gdi->height)) + if (!freerdp_client_codecs_reset(gdi->codecs, FREERDP_CODEC_ALL, + gdi->width, gdi->height)) return ERROR_INTERNAL_ERROR; gdi->graphicsReset = TRUE; @@ -310,8 +311,7 @@ UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context, RDPG if (!surface) return ERROR_INTERNAL_ERROR; - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_REMOTEFX, - surface->width, surface->height)) + if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_REMOTEFX)) return ERROR_INTERNAL_ERROR; if (!(message = rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length))) @@ -391,8 +391,7 @@ UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context, RD if (!surface) return ERROR_INTERNAL_ERROR; - if (!freerdp_client_codecs_prepare(gdi->codecs, FREERDP_CODEC_CLEARCODEC, - gdi->width, gdi->height)) + if (!freerdp_client_codecs_prepare(gdi->codecs, FREERDP_CODEC_CLEARCODEC)) return ERROR_INTERNAL_ERROR; DstData = surface->data; @@ -436,8 +435,7 @@ UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX if (!surface) return ERROR_INTERNAL_ERROR; - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PLANAR, - surface->width, surface->height)) + if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PLANAR)) return ERROR_INTERNAL_ERROR; DstData = surface->data; @@ -476,8 +474,7 @@ static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context, if (!surface) return ERROR_INTERNAL_ERROR; - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_AVC420, - surface->width, surface->height)) + if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_AVC420)) return ERROR_INTERNAL_ERROR; bs = (RDPGFX_AVC420_BITMAP_STREAM*) cmd->extra; @@ -532,8 +529,7 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, if (!surface) return ERROR_INTERNAL_ERROR; - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_AVC444, - surface->width, surface->height)) + if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_AVC444)) return ERROR_INTERNAL_ERROR; bs = (RDPGFX_AVC444_BITMAP_STREAM*) cmd->extra; @@ -598,8 +594,7 @@ UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_ if (!surface) return ERROR_INTERNAL_ERROR; - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_ALPHACODEC, - surface->width, surface->height)) + if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_ALPHACODEC)) return ERROR_INTERNAL_ERROR; WLog_DBG(TAG, "gdi_SurfaceCommand_Alpha: status: %d", status); @@ -651,8 +646,7 @@ UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context, R if (!surface) return ERROR_INTERNAL_ERROR; - if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PROGRESSIVE, - surface->width, surface->height)) + if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PROGRESSIVE)) return ERROR_INTERNAL_ERROR; progressive_create_surface_context(surface->codecs->progressive, cmd->surfaceId, surface->width, surface->height); @@ -814,6 +808,13 @@ UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* return CHANNEL_RC_NO_MEMORY; } + if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL, + createSurface->width, createSurface->height)) + { + free (surface); + return ERROR_INTERNAL_ERROR; + } + surface->surfaceId = createSurface->surfaceId; surface->width = (UINT32) createSurface->width; surface->height = (UINT32) createSurface->height; diff --git a/libfreerdp/gdi/graphics.c b/libfreerdp/gdi/graphics.c index 9010977e2..9464dcefd 100644 --- a/libfreerdp/gdi/graphics.c +++ b/libfreerdp/gdi/graphics.c @@ -3,6 +3,8 @@ * Graphical Objects * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,92 +27,95 @@ #include #include -#include #include #include #include -#include +#include "drawing.h" +#include "brush.h" #include "graphics.h" #define TAG FREERDP_TAG("gdi") /* Bitmap Class */ -HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, int nWidth, int nHeight, int bpp, BYTE* data) +HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight, + UINT32 SrcFormat, BYTE* data) { - int nSrcStep; - int nDstStep; + UINT32 nSrcStep; + UINT32 nDstStep; BYTE* pSrcData; BYTE* pDstData; - UINT32 SrcFormat; - int bytesPerPixel; HGDI_BITMAP bitmap; - - nDstStep = nWidth * gdi->bytesPerPixel; + nDstStep = nWidth * GetBytesPerPixel(gdi->dstFormat); pDstData = _aligned_malloc(nHeight * nDstStep, 16); if (!pDstData) return NULL; pSrcData = data; - - switch (bpp) - { - case 32: - bytesPerPixel = 4; - SrcFormat = PIXEL_FORMAT_XRGB32; - break; - - case 24: - bytesPerPixel = 3; - SrcFormat = PIXEL_FORMAT_RGB24; - break; - - case 16: - bytesPerPixel = 2; - SrcFormat = PIXEL_FORMAT_RGB565; - break; - - case 15: - bytesPerPixel = 2; - SrcFormat = PIXEL_FORMAT_RGB555; - break; - - case 8: - bytesPerPixel = 1; - SrcFormat = PIXEL_FORMAT_RGB8; - break; - - default: - SrcFormat = PIXEL_FORMAT_RGB565; - bytesPerPixel = 2; - break; - } - - nSrcStep = nWidth * bytesPerPixel; - - freerdp_image_copy(pDstData, gdi->format, nDstStep, 0, 0, - nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0, gdi->palette); - - bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstBpp, pDstData); - + nSrcStep = nWidth * GetBytesPerPixel(SrcFormat); + freerdp_image_copy(pDstData, gdi->dstFormat, nDstStep, 0, 0, + nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0, gdi->palette); + bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstFormat, pDstData); return bitmap; } -BOOL gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) +static BOOL gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) { gdiBitmap* gdi_bitmap; rdpGdi* gdi = context->gdi; - gdi_bitmap = (gdiBitmap*) bitmap; gdi_bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc); + if (!gdi_bitmap->hdc) return FALSE; if (!bitmap->data) - gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, bitmap->width, bitmap->height); + gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap( + gdi->hdc, bitmap->width, + bitmap->height); else - gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data); + { + UINT32 format; + + switch (bitmap->bpp) + { + case 32: + format = PIXEL_FORMAT_RGBX32; + break; + + case 24: + format = PIXEL_FORMAT_RGB24; + break; + + case 16: + format = PIXEL_FORMAT_RGB16; + break; + + case 15: + format = PIXEL_FORMAT_RGB15; + break; + + case 8: + format = PIXEL_FORMAT_RGB8; + break; + + case 4: + format = PIXEL_FORMAT_A4; + break; + + case 1: + format = PIXEL_FORMAT_MONO; + break; + + default: + return FALSE; + } + + gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width, + bitmap->height, + format, bitmap->data); + } if (!gdi_bitmap->bitmap) { @@ -123,7 +128,7 @@ BOOL gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) return TRUE; } -void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap) +static void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap) { gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap; @@ -135,36 +140,32 @@ void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap) } } -BOOL gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) +static BOOL gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) { int width, height; gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap; - width = bitmap->right - bitmap->left + 1; height = bitmap->bottom - bitmap->top + 1; - return gdi_BitBlt(context->gdi->primary->hdc, bitmap->left, bitmap->top, - width, height, gdi_bitmap->hdc, 0, 0, GDI_SRCCOPY); + width, height, gdi_bitmap->hdc, 0, 0, GDI_SRCCOPY); } -BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, - BYTE* data, int width, int height, int bpp, int length, - BOOL compressed, int codecId) +static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, + const BYTE* data, UINT32 width, UINT32 height, + UINT32 bpp, UINT32 length, BOOL compressed, + UINT32 codecId) { int status; UINT16 size; - BYTE* pSrcData; + const BYTE* pSrcData; BYTE* pDstData; UINT32 SrcSize; UINT32 SrcFormat; UINT32 bytesPerPixel; rdpGdi* gdi = context->gdi; - bytesPerPixel = (bpp + 7) / 8; size = width * height * 4; - bitmap->data = (BYTE*) _aligned_malloc(size, 16); - pSrcData = data; SrcSize = (UINT32) length; pDstData = bitmap->data; @@ -177,8 +178,12 @@ BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, gdi->width, gdi->height)) return FALSE; - status = interleaved_decompress(gdi->codecs->interleaved, pSrcData, SrcSize, bpp, - &pDstData, gdi->format, -1, 0, 0, width, height, gdi->palette); + status = interleaved_decompress(gdi->codecs->interleaved, + pSrcData, SrcSize, + bpp, + pDstData, gdi->dstFormat, + -1, 0, 0, width, height, + gdi->palette); } else { @@ -187,7 +192,7 @@ BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, return FALSE; status = planar_decompress(gdi->codecs->planar, pSrcData, SrcSize, &pDstData, - gdi->format, -1, 0, 0, width, height, TRUE); + gdi->dstFormat, -1, 0, 0, width, height, TRUE); } if (status < 0) @@ -199,18 +204,18 @@ BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, else { SrcFormat = gdi_get_pixel_format(bpp, TRUE); - - status = freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, - width, height, pSrcData, SrcFormat, -1, 0, 0, gdi->palette); + status = freerdp_image_copy(pDstData, gdi->dstFormat, -1, 0, 0, + width, height, pSrcData, SrcFormat, -1, 0, 0, gdi->palette); } bitmap->compressed = FALSE; bitmap->length = size; - bitmap->bpp = gdi->dstBpp; + bitmap->bpp = GetBitsPerPixel(gdi->dstFormat); return TRUE; } -BOOL gdi_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) +static BOOL gdi_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, + BOOL primary) { rdpGdi* gdi = context->gdi; @@ -223,45 +228,44 @@ BOOL gdi_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) } /* Glyph Class */ - -BOOL gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph) +static BOOL gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph) { BYTE* data; gdiGlyph* gdi_glyph; - gdi_glyph = (gdiGlyph*) glyph; - gdi_glyph->hdc = gdi_GetDC(); + if (!gdi_glyph->hdc) return FALSE; - gdi_glyph->hdc->bytesPerPixel = 1; - gdi_glyph->hdc->bitsPerPixel = 1; + gdi_glyph->hdc->format = PIXEL_FORMAT_MONO; data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj); + if (!data) { gdi_DeleteDC(gdi_glyph->hdc); return FALSE; } - gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data); + + gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, PIXEL_FORMAT_MONO, + data); + if (!gdi_glyph->bitmap) { gdi_DeleteDC(gdi_glyph->hdc); _aligned_free(data); return FALSE; } - gdi_glyph->bitmap->bytesPerPixel = 1; - gdi_glyph->bitmap->bitsPerPixel = 1; + gdi_glyph->bitmap->format = PIXEL_FORMAT_MONO; gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap); gdi_glyph->org_bitmap = NULL; return TRUE; } -void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph) +static void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph) { gdiGlyph* gdi_glyph; - gdi_glyph = (gdiGlyph*) glyph; if (gdi_glyph) @@ -272,28 +276,28 @@ void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph) } } -BOOL gdi_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y) +static BOOL gdi_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, UINT32 x, + UINT32 y) { gdiGlyph* gdi_glyph; rdpGdi* gdi = context->gdi; - gdi_glyph = (gdiGlyph*) glyph; - return gdi_BitBlt(gdi->drawing->hdc, x, y, gdi_glyph->bitmap->width, - gdi_glyph->bitmap->height, gdi_glyph->hdc, 0, 0, GDI_DSPDxax); + gdi_glyph->bitmap->height, gdi_glyph->hdc, 0, 0, GDI_DSPDxax); } -BOOL gdi_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant) +static BOOL gdi_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 bgcolor, + UINT32 fgcolor, BOOL fOpRedundant) { GDI_RECT rect; HGDI_BRUSH brush; rdpGdi* gdi = context->gdi; BOOL ret = FALSE; - + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); /* TODO: handle fOpRedundant! See xf_Glyph_BeginDraw() */ - - bgcolor = freerdp_convert_gdi_order_color(bgcolor, gdi->srcBpp, gdi->format, gdi->palette); - fgcolor = freerdp_convert_gdi_order_color(fgcolor, gdi->srcBpp, gdi->format, gdi->palette); + bgcolor = ConvertColor(bgcolor, SrcFormat, gdi->dstFormat, gdi->palette); + fgcolor = ConvertColor(fgcolor, SrcFormat, gdi->dstFormat, gdi->palette); if (!(brush = gdi_CreateSolidBrush(fgcolor))) goto out; @@ -301,17 +305,18 @@ BOOL gdi_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int heigh gdi_CRgnToRect(x, y, width, height, &rect); ret = gdi_FillRect(gdi->drawing->hdc, &rect, brush); gdi_DeleteObject((HGDIOBJECT) brush); - out: gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor); return ret; } -BOOL gdi_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor) +static BOOL gdi_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 bgcolor, UINT32 fgcolor) { rdpGdi* gdi = context->gdi; - - bgcolor = freerdp_convert_gdi_order_color(bgcolor, gdi->srcBpp, gdi->format, gdi->palette); + UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); + bgcolor = ConvertColor(bgcolor, SrcFormat, + gdi->dstFormat, gdi->palette); gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor); return TRUE; } @@ -322,36 +327,30 @@ BOOL gdi_register_graphics(rdpGraphics* graphics) { rdpBitmap* bitmap; rdpGlyph* glyph; - bitmap = (rdpBitmap*) calloc(1, sizeof(rdpBitmap)); if (!bitmap) return FALSE; bitmap->size = sizeof(gdiBitmap); - bitmap->New = gdi_Bitmap_New; bitmap->Free = gdi_Bitmap_Free; bitmap->Paint = gdi_Bitmap_Paint; bitmap->Decompress = gdi_Bitmap_Decompress; bitmap->SetSurface = gdi_Bitmap_SetSurface; - graphics_register_bitmap(graphics, bitmap); free(bitmap); - glyph = (rdpGlyph*) calloc(1, sizeof(rdpGlyph)); if (!glyph) return FALSE; glyph->size = sizeof(gdiGlyph); - glyph->New = gdi_Glyph_New; glyph->Free = gdi_Glyph_Free; glyph->Draw = gdi_Glyph_Draw; glyph->BeginDraw = gdi_Glyph_BeginDraw; glyph->EndDraw = gdi_Glyph_EndDraw; - graphics_register_glyph(graphics, glyph); free(glyph); return TRUE; diff --git a/libfreerdp/gdi/graphics.h b/libfreerdp/gdi/graphics.h index dc219914f..0e21dd687 100644 --- a/libfreerdp/gdi/graphics.h +++ b/libfreerdp/gdi/graphics.h @@ -3,6 +3,8 @@ * Graphical Objects * * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,13 +25,9 @@ #include #include -HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, int width, int height, int bpp, BYTE* data); +HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 width, UINT32 height, + UINT32 format, BYTE* data); -BOOL gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap); -void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap); -BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, - BYTE* data, int width, int height, int bpp, int length, - BOOL compressed, int codec_id); BOOL gdi_register_graphics(rdpGraphics* graphics); #endif /* __GDI_GRAPHICS_H */ diff --git a/libfreerdp/gdi/include/line.c b/libfreerdp/gdi/include/line.c deleted file mode 100644 index 2df68c1c6..000000000 --- a/libfreerdp/gdi/include/line.c +++ /dev/null @@ -1,118 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI LineTo - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* do not include this file directly! */ - -BOOL LINE_TO(HGDI_DC hdc, int nXEnd, int nYEnd) -{ - int x, y; - int x1, y1; - int x2, y2; - int e, e2; - int dx, dy; - int sx, sy; - int bx1, by1; - int bx2, by2; - PIXEL_TYPE pen; - PIXEL_TYPE* pixel; - HGDI_BITMAP bmp; - - 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) - { - bx1 = (x1 < x2) ? x1 : x2; - by1 = (y1 < y2) ? y1 : y2; - bx2 = (x1 > x2) ? x1 : x2; - by2 = (y1 > y2) ? y1 : y2; - } - else - { - bx1 = hdc->clip->x; - by1 = hdc->clip->y; - bx2 = bx1 + hdc->clip->w - 1; - by2 = by1 + hdc->clip->h - 1; - } - - bx1 = MAX(bx1, 0); - by1 = MAX(by1, 0); - bx2 = MIN(bx2, bmp->width - 1); - by2 = MIN(by2, bmp->height - 1); - - if (!gdi_InvalidateRegion(hdc, bx1, by1, bx2 - bx1 + 1, by2 - by1 + 1)) - return FALSE; - - pen = GDI_GET_PEN_COLOR(hdc->pen); - - while (1) - { - if (!(x == x2 && y == y2)) - { - if ((x >= bx1 && x <= bx2) && (y >= by1 && y <= by2)) - { - pixel = GDI_GET_POINTER(bmp, x, y); - SET_PIXEL_ROP2(pixel, &pen); - } - } - else - { - break; - } - - e2 = 2 * e; - - if (e2 > -dy) - { - e -= dy; - x += sx; - } - - if (e2 < dx) - { - e += dx; - y += sy; - } - } - - return TRUE; -} - -/* -#undef LINE_TO -#undef PIXEL_TYPE -#undef SET_PIXEL_ROP2 -#undef GDI_GET_POINTER -#undef GDI_GET_PEN_COLOR -*/ diff --git a/libfreerdp/gdi/line.c b/libfreerdp/gdi/line.c index 9d1b4248a..9a4a12767 100644 --- a/libfreerdp/gdi/line.c +++ b/libfreerdp/gdi/line.c @@ -3,6 +3,8 @@ * GDI Line Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,21 +29,13 @@ #include #include +#include +#include +#include -#include -#include -#include - -#include - -p_LineTo LineTo_[5] = -{ - NULL, - LineTo_8bpp, - LineTo_16bpp, - NULL, - LineTo_32bpp -}; +#include "drawing.h" +#include "clipping.h" +#include "line.h" /** * Draw a line from the current position to the given position.\n @@ -51,15 +45,157 @@ p_LineTo LineTo_[5] = * @param nYEnd ending y position * @return nonzero if successful, 0 otherwise */ - -BOOL gdi_LineTo(HGDI_DC hdc, int nXEnd, int nYEnd) +static BOOL gdi_rop_color(UINT32 rop, BYTE* pixelPtr, UINT32 pen, UINT32 format) { - p_LineTo _LineTo = LineTo_[IBPP(hdc->bitsPerPixel)]; + UINT32 pixel = ReadColor(pixelPtr, format); - if (_LineTo == NULL) + switch(rop) + { + case 1: /* LineTo_BLACK */ + pixel = GetColor(format, 0, 0, 0, 0xFF); + break; + case 2: /* LineTo_NOTMERGEPEN */ + pixel = ~(pixel | pen); + break; + case 3: /* LineTo_MASKNOTPEN */ + pixel &= ~pen; + break; + case 4: /* LineTo_NOTCOPYPEN */ + pixel = ~pen; + break; + case 5: /* LineTo_MASKPENNOT */ + pixel = pen & ~pixel; + break; + case 6: /* LineTo_NOT */ + pixel = ~pixel; + break; + case 7: /* LineTo_XORPEN */ + pixel = pixel ^ pen; + break; + case 8: /* LineTo_NOTMASKPEN */ + pixel = ~(pixel & pen); + break; + case 9: /* LineTo_MASKPEN */ + pixel &= pen; + break; + case 10: /* LineTo_NOTXORPEN */ + pixel = ~(pixel ^ pen); + break; + case 11: /* LineTo_NOP */ + break; + case 12: /* LineTo_MERGENOTPEN */ + pixel |= ~pen; + break; + case 13: /* LineTo_COPYPEN */ + pixel = pen; + break; + case 14: /* LineTo_MERGEPENNOT */ + pixel = pixel | ~pen; + break; + case 15: /* LineTo_MERGEPEN */ + pixel = pixel | pen; + break; + case 16: /* LineTo_WHITE */ + pixel = GetColor(format, 0, 0, 0, 0); + break; + + default: + return FALSE; + } + + WriteColor(pixelPtr, format, pixel); + + return TRUE; +} + +BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd) +{ + UINT32 x, y; + UINT32 x1, y1; + UINT32 x2, y2; + UINT32 e, e2; + INT32 dx, dy; + INT32 sx, sy; + INT32 bx1, by1; + INT32 bx2, by2; + HGDI_BITMAP bmp; + UINT32 pen; + UINT32 rop2 = gdi_GetROP2(hdc); + + 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) + { + bx1 = (x1 < x2) ? x1 : x2; + by1 = (y1 < y2) ? y1 : y2; + bx2 = (x1 > x2) ? x1 : x2; + by2 = (y1 > y2) ? y1 : y2; + } + else + { + bx1 = hdc->clip->x; + by1 = hdc->clip->y; + bx2 = bx1 + hdc->clip->w - 1; + by2 = by1 + hdc->clip->h - 1; + } + + bx1 = MAX(bx1, 0); + by1 = MAX(by1, 0); + bx2 = MIN(bx2, bmp->width - 1); + by2 = MIN(by2, bmp->height - 1); + + if (!gdi_InvalidateRegion(hdc, bx1, by1, bx2 - bx1 + 1, by2 - by1 + 1)) return FALSE; - return _LineTo(hdc, nXEnd, nYEnd); + pen = gdi_GetPenColor(hdc->pen, bmp->format); + + while (1) + { + if (!(x == x2 && y == y2)) + { + if ((x >= bx1 && x <= bx2) && (y >= by1 && y <= by2)) + { + BYTE* pixel = gdi_GetPointer(bmp, x, y); + gdi_rop_color(rop2, pixel, pen, bmp->format); + } + } + else + { + break; + } + + e2 = 2 * e; + + if (e2 > -dy) + { + e -= dy; + x += sx; + } + + if (e2 < dx) + { + e += dx; + y += sy; + } + } + + return TRUE; } /** @@ -91,11 +227,11 @@ BOOL gdi_PolylineTo(HGDI_DC hdc, GDI_POINT *lppt, DWORD cCount) * @param cPoints number of points * @return nonzero on success, 0 otherwise */ -BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT *lppt, int cPoints) +BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT *lppt, UINT32 cPoints) { if (cPoints > 0) { - int i; + UINT32 i; GDI_POINT pt; if (!gdi_MoveToEx(hdc, lppt[0].x, lppt[0].y, &pt)) @@ -124,9 +260,9 @@ BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT *lppt, int cPoints) * @param cCount count of entries in lpdwPolyPoints * @return nonzero on success, 0 otherwise */ -BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT *lppt, int *lpdwPolyPoints, DWORD cCount) +BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT *lppt, UINT32 *lpdwPolyPoints, DWORD cCount) { - int cPoints; + UINT32 cPoints; DWORD i, j = 0; for (i = 0; i < cCount; i++) @@ -148,7 +284,7 @@ BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT *lppt, int *lpdwPolyPoints, DWORD c * @return nonzero on success, 0 otherwise */ -BOOL gdi_MoveToEx(HGDI_DC hdc, int X, int Y, HGDI_POINT lpPoint) +BOOL gdi_MoveToEx(HGDI_DC hdc, UINT32 X, UINT32 Y, HGDI_POINT lpPoint) { if (lpPoint != NULL) { diff --git a/include/freerdp/gdi/line.h b/libfreerdp/gdi/line.h similarity index 67% rename from include/freerdp/gdi/line.h rename to libfreerdp/gdi/line.h index daf8b8b59..37e085df3 100644 --- a/include/freerdp/gdi/line.h +++ b/libfreerdp/gdi/line.h @@ -3,6 +3,8 @@ * GDI Line Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,16 +29,14 @@ extern "C" { #endif -FREERDP_API BOOL gdi_LineTo(HGDI_DC hdc, int nXEnd, int nYEnd); -FREERDP_API BOOL gdi_PolylineTo(HGDI_DC hdc, GDI_POINT *lppt, DWORD cCount); -FREERDP_API BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT *lppt, int cPoints); -FREERDP_API BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT *lppt, int *lpdwPolyPoints, DWORD cCount); -FREERDP_API BOOL gdi_MoveToEx(HGDI_DC hdc, int X, int Y, HGDI_POINT lpPoint); +BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd); +BOOL gdi_PolylineTo(HGDI_DC hdc, GDI_POINT *lppt, DWORD cCount); +BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT *lppt, UINT32 cPoints); +BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT *lppt, UINT32 *lpdwPolyPoints, DWORD cCount); +BOOL gdi_MoveToEx(HGDI_DC hdc, UINT32 X, UINT32 Y, HGDI_POINT lpPoint); #ifdef __cplusplus } #endif -typedef BOOL (*p_LineTo)(HGDI_DC hdc, int nXEnd, int nYEnd); - #endif /* FREERDP_GDI_LINE_H */ diff --git a/libfreerdp/gdi/palette.c b/libfreerdp/gdi/palette.c deleted file mode 100644 index ed4bf913d..000000000 --- a/libfreerdp/gdi/palette.c +++ /dev/null @@ -1,130 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * GDI Palette Functions - * - * Copyright 2010-2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* GDI Palette Functions: http://msdn.microsoft.com/en-us/library/dd183454/ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include -#include - -#include - -static HGDI_PALETTE hSystemPalette = NULL; - -static const GDI_PALETTEENTRY default_system_palette[20] = -{ - /* First 10 entries */ - { 0x00, 0x00, 0x00 }, - { 0x80, 0x00, 0x00 }, - { 0x00, 0x80, 0x00 }, - { 0x80, 0x80, 0x00 }, - { 0x00, 0x00, 0x80 }, - { 0x80, 0x00, 0x80 }, - { 0x00, 0x80, 0x80 }, - { 0xC0, 0xC0, 0xC0 }, - { 0xC0, 0xDC, 0xC0 }, - { 0xA6, 0xCA, 0xF0 }, - - /* Last 10 entries */ - { 0xFF, 0xFB, 0xF0 }, - { 0xA0, 0xA0, 0xA4 }, - { 0x80, 0x80, 0x80 }, - { 0xFF, 0x00, 0x00 }, - { 0x00, 0xFF, 0x00 }, - { 0xFF, 0xFF, 0x00 }, - { 0x00, 0x00, 0xFF }, - { 0xFF, 0x00, 0xFF }, - { 0x00, 0xFF, 0xFF }, - { 0xFF, 0xFF, 0xFF } -}; - -/** - * Create a new palette.\n - * @msdn{dd183507} - * @param original palette - * @return new palette - */ - -HGDI_PALETTE gdi_CreatePalette(HGDI_PALETTE palette) -{ - HGDI_PALETTE hPalette = (HGDI_PALETTE) calloc(1, sizeof(GDI_PALETTE)); - - if (!hPalette) - return NULL; - - hPalette->count = palette->count; - hPalette->entries = (GDI_PALETTEENTRY*) calloc(hPalette->count, sizeof(GDI_PALETTEENTRY)); - - if (!hPalette->entries) - { - free(hPalette); - return NULL; - } - - CopyMemory(hPalette->entries, palette->entries, sizeof(GDI_PALETTEENTRY) * hPalette->count); - - return hPalette; -} - -/** - * Create system palette\n - * @return system palette - */ - -HGDI_PALETTE CreateSystemPalette() -{ - HGDI_PALETTE palette = (HGDI_PALETTE) calloc(1, sizeof(GDI_PALETTE)); - - if (!palette) - return NULL; - - palette->count = 256; - palette->entries = (GDI_PALETTEENTRY*) calloc(256, sizeof(GDI_PALETTEENTRY)); - - if (!palette->entries) - { - free(palette); - return NULL; - } - - CopyMemory(&palette->entries[0], &default_system_palette[0], 10 * sizeof(GDI_PALETTEENTRY)); - CopyMemory(&palette->entries[256 - 10], &default_system_palette[10], 10 * sizeof(GDI_PALETTEENTRY)); - - return palette; -} - -/** - * Get system palette\n - * @return system palette - */ - -HGDI_PALETTE gdi_GetSystemPalette() -{ - if (!hSystemPalette) - hSystemPalette = CreateSystemPalette(); - - return hSystemPalette; -} diff --git a/libfreerdp/gdi/pen.c b/libfreerdp/gdi/pen.c index 345a9a945..db99f33a7 100644 --- a/libfreerdp/gdi/pen.c +++ b/libfreerdp/gdi/pen.c @@ -41,35 +41,21 @@ * @return new pen */ -HGDI_PEN gdi_CreatePen(int fnPenStyle, int nWidth, int crColor) +HGDI_PEN gdi_CreatePen(UINT32 fnPenStyle, UINT32 nWidth, UINT32 crColor, + UINT32 format) { - HGDI_PEN hPen = (HGDI_PEN) malloc(sizeof(GDI_PEN)); + HGDI_PEN hPen = (HGDI_PEN) calloc(1, sizeof(GDI_PEN)); if (!hPen) return NULL; hPen->objectType = GDIOBJECT_PEN; hPen->style = fnPenStyle; hPen->color = crColor; hPen->width = nWidth; + hPen->format = format; return hPen; } -INLINE BYTE gdi_GetPenColor_8bpp(HGDI_PEN pen) +INLINE UINT32 gdi_GetPenColor(HGDI_PEN pen, UINT32 format) { - /* TODO: implement conversion using palette */ - return 0xFF; -} - -INLINE UINT16 gdi_GetPenColor_16bpp(HGDI_PEN pen) -{ - UINT16 p; - int r, g, b; - GetRGB32(r, g, b, pen->color); - RGB_888_565(r, g, b); - p = RGB16(r, g, b); - return p; -} - -INLINE UINT32 gdi_GetPenColor_32bpp(HGDI_PEN pen) -{ - return pen->color; + return ConvertColor(pen->color, pen->format, format, NULL); } diff --git a/libfreerdp/gdi/region.c b/libfreerdp/gdi/region.c index a749320ad..6f8bed3c6 100644 --- a/libfreerdp/gdi/region.c +++ b/libfreerdp/gdi/region.c @@ -3,6 +3,8 @@ * GDI Region Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,9 +43,10 @@ * @return new region */ -HGDI_RGN gdi_CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) +HGDI_RGN gdi_CreateRectRgn(UINT32 nLeftRect, UINT32 nTopRect, + UINT32 nRightRect, UINT32 nBottomRect) { - HGDI_RGN hRgn = (HGDI_RGN) malloc(sizeof(GDI_RGN)); + HGDI_RGN hRgn = (HGDI_RGN) calloc(1, sizeof(GDI_RGN)); if (!hRgn) return NULL; @@ -65,9 +68,10 @@ HGDI_RGN gdi_CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBot * @return new rectangle */ -HGDI_RECT gdi_CreateRect(int xLeft, int yTop, int xRight, int yBottom) +HGDI_RECT gdi_CreateRect(UINT32 xLeft, UINT32 yTop, + UINT32 xRight, UINT32 yBottom) { - HGDI_RECT hRect = (HGDI_RECT) malloc(sizeof(GDI_RECT)); + HGDI_RECT hRect = (HGDI_RECT) calloc(1, sizeof(GDI_RECT)); if (!hRect) return NULL; @@ -102,7 +106,8 @@ INLINE void gdi_RectToRgn(HGDI_RECT rect, HGDI_RGN rgn) * @param rgn destination region */ -INLINE void gdi_CRectToRgn(int left, int top, int right, int bottom, HGDI_RGN rgn) +INLINE void gdi_CRectToRgn(UINT32 left, UINT32 top, + UINT32 right, UINT32 bottom, HGDI_RGN rgn) { rgn->x = left; rgn->y = top; @@ -119,7 +124,8 @@ INLINE void gdi_CRectToRgn(int left, int top, int right, int bottom, HGDI_RGN rg * @param h height */ -INLINE void gdi_RectToCRgn(HGDI_RECT rect, int *x, int *y, int *w, int *h) +INLINE void gdi_RectToCRgn(const HGDI_RECT rect, UINT32 *x, UINT32 *y, + UINT32 *w, UINT32 *h) { *x = rect->left; *y = rect->top; @@ -139,7 +145,8 @@ INLINE void gdi_RectToCRgn(HGDI_RECT rect, int *x, int *y, int *w, int *h) * @param h height */ -INLINE void gdi_CRectToCRgn(int left, int top, int right, int bottom, int *x, int *y, int *w, int *h) +INLINE void gdi_CRectToCRgn(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom, + UINT32 *x, UINT32 *y, UINT32 *w, UINT32 *h) { *x = left; *y = top; @@ -170,7 +177,7 @@ INLINE void gdi_RgnToRect(HGDI_RGN rgn, HGDI_RECT rect) * @param rect destination rectangle */ -INLINE void gdi_CRgnToRect(int x, int y, int w, int h, HGDI_RECT rect) +INLINE void gdi_CRgnToRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h, HGDI_RECT rect) { rect->left = x; rect->top = y; @@ -187,7 +194,8 @@ INLINE void gdi_CRgnToRect(int x, int y, int w, int h, HGDI_RECT rect) * @param bottom y2 */ -INLINE void gdi_RgnToCRect(HGDI_RGN rgn, int *left, int *top, int *right, int *bottom) +INLINE void gdi_RgnToCRect(HGDI_RGN rgn, UINT32 *left, UINT32 *top, + UINT32 *right, UINT32 *bottom) { *left = rgn->x; *top = rgn->y; @@ -207,7 +215,8 @@ INLINE void gdi_RgnToCRect(HGDI_RGN rgn, int *left, int *top, int *right, int *b * @param bottom y2 */ -INLINE void gdi_CRgnToCRect(int x, int y, int w, int h, int *left, int *top, int *right, int *bottom) +INLINE void gdi_CRgnToCRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h, + UINT32 *left, UINT32 *top, UINT32 *right, UINT32 *bottom) { *left = x; *top = y; @@ -226,7 +235,8 @@ INLINE void gdi_CRgnToCRect(int x, int y, int w, int h, int *left, int *top, int * @return nonzero if there is an overlap, 0 otherwise */ -INLINE BOOL gdi_CopyOverlap(int x, int y, int width, int height, int srcx, int srcy) +INLINE BOOL gdi_CopyOverlap(UINT32 x, UINT32 y, UINT32 width, UINT32 height, + UINT32 srcx, UINT32 srcy) { GDI_RECT dst; GDI_RECT src; @@ -249,7 +259,8 @@ INLINE BOOL gdi_CopyOverlap(int x, int y, int width, int height, int srcx, int s * @return nonzero if successful, 0 otherwise */ -INLINE BOOL gdi_SetRect(HGDI_RECT rc, int xLeft, int yTop, int xRight, int yBottom) +INLINE BOOL gdi_SetRect(HGDI_RECT rc, UINT32 xLeft, UINT32 yTop, + UINT32 xRight, UINT32 yBottom) { rc->left = xLeft; rc->top = yTop; @@ -268,7 +279,8 @@ INLINE BOOL gdi_SetRect(HGDI_RECT rc, int xLeft, int yTop, int xRight, int yBott * @return nonzero if successful, 0 otherwise */ -INLINE BOOL gdi_SetRgn(HGDI_RGN hRgn, int nXLeft, int nYLeft, int nWidth, int nHeight) +INLINE BOOL gdi_SetRgn(HGDI_RGN hRgn, UINT32 nXLeft, UINT32 nYLeft, + UINT32 nWidth, UINT32 nHeight) { hRgn->x = nXLeft; hRgn->y = nYLeft; @@ -288,7 +300,8 @@ INLINE BOOL gdi_SetRgn(HGDI_RGN hRgn, int nXLeft, int nYLeft, int nWidth, int nH * @return nonzero if successful, 0 otherwise */ -INLINE BOOL gdi_SetRectRgn(HGDI_RGN hRgn, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) +INLINE BOOL gdi_SetRectRgn(HGDI_RGN hRgn, UINT32 nLeftRect, UINT32 nTopRect, + UINT32 nRightRect, UINT32 nBottomRect) { gdi_CRectToRgn(nLeftRect, nTopRect, nRightRect, nBottomRect, hRgn); hRgn->null = 0; @@ -342,7 +355,7 @@ INLINE BOOL gdi_CopyRect(HGDI_RECT dst, HGDI_RECT src) * @return nonzero if the point is inside, 0 otherwise */ -INLINE BOOL gdi_PtInRect(HGDI_RECT rc, int x, int y) +INLINE BOOL gdi_PtInRect(HGDI_RECT rc, UINT32 x, UINT32 y) { /* * points on the left and top sides are considered in, @@ -371,7 +384,7 @@ INLINE BOOL gdi_PtInRect(HGDI_RECT rc, int x, int y) * @return nonzero on success, 0 otherwise */ -INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, int x, int y, int w, int h) +INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, UINT32 x, UINT32 y, UINT32 w, UINT32 h) { GDI_RECT inv; GDI_RECT rgn; diff --git a/libfreerdp/gdi/shape.c b/libfreerdp/gdi/shape.c index fc7d61908..e969830eb 100644 --- a/libfreerdp/gdi/shape.c +++ b/libfreerdp/gdi/shape.c @@ -3,6 +3,8 @@ * GDI Shape Functions * * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,34 +30,21 @@ #include #include -#include -#include -#include #include - +#include #include -p_FillRect FillRect_[5] = -{ - NULL, - FillRect_8bpp, - FillRect_16bpp, - NULL, - FillRect_32bpp -}; +#include + +#include "clipping.h" + +#define TAG FREERDP_TAG("gdi.shape") static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2) { - int i; - long e, e2; - long dx, dy; - int a, b, c; - - HGDI_BITMAP bmp; - BYTE pixel8; - UINT16 pixel16; - UINT32 pixel32; - int bpp = hdc->bitsPerPixel; + INT32 e, e2; + INT32 dx, dy; + INT32 a, b, c; a = (x1 < x2) ? x2 - x1 : x1 - x2; b = (y1 < y2) ? y2 - y1 : y1 - y2; @@ -80,41 +69,12 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2) a *= 8 * a; c = 8 * b * b; - pixel8 = 0; - pixel16 = 0; - pixel32 = 0; - bmp = (HGDI_BITMAP) hdc->selectedObject; - do { - if (bpp == 32) - { - gdi_SetPixel_32bpp(bmp, x2, y1, pixel32); - gdi_SetPixel_32bpp(bmp, x1, y1, pixel32); - gdi_SetPixel_32bpp(bmp, x1, y2, pixel32); - gdi_SetPixel_32bpp(bmp, x2, y2, pixel32); - } - else if (bpp == 16) - { - gdi_SetPixel_16bpp(bmp, x2, y1, pixel16); - gdi_SetPixel_16bpp(bmp, x1, y1, pixel16); - gdi_SetPixel_16bpp(bmp, x1, y2, pixel16); - gdi_SetPixel_16bpp(bmp, x2, y2, pixel16); - } - else if (bpp == 8) - { - for (i = x1; i < x2; i++) - { - gdi_SetPixel_8bpp(bmp, i, y1, pixel8); - gdi_SetPixel_8bpp(bmp, i, y2, pixel8); - } - - for (i = y1; i < y2; i++) - { - gdi_SetPixel_8bpp(bmp, x1, i, pixel8); - gdi_SetPixel_8bpp(bmp, x2, i, pixel8); - } - } + gdi_SetPixel(hdc, x2, y1, 0); + gdi_SetPixel(hdc, x1, y1, 0); + gdi_SetPixel(hdc, x1, y2, 0); + gdi_SetPixel(hdc, x2, y2, 0); e2 = 2 * e; @@ -136,21 +96,8 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2) while (y1 - y2 < b) { - if (bpp == 32) - { - gdi_SetPixel_32bpp(bmp, x1 - 1, ++y1, pixel32); - gdi_SetPixel_32bpp(bmp, x1 - 1, --y2, pixel32); - } - else if (bpp == 16) - { - gdi_SetPixel_16bpp(bmp, x1 - 1, ++y1, pixel16); - gdi_SetPixel_16bpp(bmp, x1 - 1, --y2, pixel16); - } - else if (bpp == 8) - { - gdi_SetPixel_8bpp(bmp, x1 - 1, ++y1, pixel8); - gdi_SetPixel_8bpp(bmp, x1 - 1, --y2, pixel8); - } + gdi_SetPixel(hdc, x1 - 1, ++y1, 0); + gdi_SetPixel(hdc, x1 - 1, --y2, 0); } } @@ -179,16 +126,38 @@ BOOL gdi_Ellipse(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int n * @return nonzero if successful, 0 otherwise */ -BOOL gdi_FillRect(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr) +BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr) { - p_FillRect _FillRect = FillRect_[IBPP(hdc->bitsPerPixel)]; + UINT32 x, y; + UINT32 color; + UINT32 nXDest, nYDest; + UINT32 nWidth, nHeight; - if (_FillRect == NULL) + gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); + + if (!gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) + return TRUE; + + color = ConvertColor(hbr->color, hbr->pattern->format, hdc->format, NULL); + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth; x++) + { + BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x, + nYDest + y); + if (dstp) + WriteColor(dstp, hdc->format, color); + } + } + + if (!gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight)) return FALSE; - return _FillRect(hdc, rect, hbr); + return TRUE; } + /** * Draw a polygon * @msdn{dd162814} @@ -199,7 +168,8 @@ BOOL gdi_FillRect(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr) */ BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINT *lpPoints, int nCount) { - return TRUE; + WLog_ERR(TAG, "Not implemented!"); + return FALSE; } /** @@ -213,7 +183,8 @@ BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINT *lpPoints, int nCount) */ BOOL gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT *lpPoints, int *lpPolyCounts, int nCount) { - return TRUE; + WLog_ERR(TAG, "Not implemented!"); + return FALSE; } /** @@ -228,5 +199,6 @@ BOOL gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT *lpPoints, int *lpPolyCounts, int nC */ BOOL gdi_Rectangle(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) { - return TRUE; + WLog_ERR(TAG, "Not implemented!"); + return FALSE; } diff --git a/libfreerdp/gdi/test/TestGdiBitBlt.c b/libfreerdp/gdi/test/TestGdiBitBlt.c index d9f51d79a..956be8032 100644 --- a/libfreerdp/gdi/test/TestGdiBitBlt.c +++ b/libfreerdp/gdi/test/TestGdiBitBlt.c @@ -3,19 +3,19 @@ #include #include -#include -#include #include #include -#include #include #include +#include "line.h" +#include "brush.h" + /* BitBlt() Test Data */ /* source bitmap (16x16) */ -BYTE bmp_SRC[256] = +static BYTE bmp_SRC[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -36,7 +36,7 @@ BYTE bmp_SRC[256] = }; /* destination bitmap (16x16) */ -BYTE bmp_DST[256] = +static BYTE bmp_DST[256] = { "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -57,7 +57,7 @@ BYTE bmp_DST[256] = }; /* pattern bitmap (8x8) */ -BYTE bmp_PAT[64] = +static BYTE bmp_PAT[64] = { "\xFF\xFF\x00\x00\xFF\xFF\x00\x00" "\xFF\xFF\x00\x00\xFF\xFF\x00\x00" @@ -70,7 +70,7 @@ BYTE bmp_PAT[64] = }; /* SRCCOPY (0x00CC0020) */ -BYTE bmp_SRCCOPY[256] = +static BYTE bmp_SRCCOPY[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -91,7 +91,7 @@ BYTE bmp_SRCCOPY[256] = }; /* BLACKNESS (0x00000042) */ -BYTE bmp_BLACKNESS[256] = +static BYTE bmp_BLACKNESS[256] = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" @@ -112,7 +112,7 @@ BYTE bmp_BLACKNESS[256] = }; /* WHITENESS (0x00FF0062) */ -BYTE bmp_WHITENESS[256] = +static BYTE bmp_WHITENESS[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -133,7 +133,7 @@ BYTE bmp_WHITENESS[256] = }; /* SRCAND (0x008800C6) */ -BYTE bmp_SRCAND[256] = +static BYTE bmp_SRCAND[256] = { "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -154,7 +154,7 @@ BYTE bmp_SRCAND[256] = }; /* SRCPAINT (0x00EE0086) */ -BYTE bmp_SRCPAINT[256] = +static BYTE bmp_SRCPAINT[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -175,7 +175,7 @@ BYTE bmp_SRCPAINT[256] = }; /* SRCINVERT (0x00660046) */ -BYTE bmp_SRCINVERT[256] = +static BYTE bmp_SRCINVERT[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" @@ -196,7 +196,7 @@ BYTE bmp_SRCINVERT[256] = }; /* SRCERASE (0x00440328) */ -BYTE bmp_SRCERASE[256] = +static BYTE bmp_SRCERASE[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" @@ -217,7 +217,7 @@ BYTE bmp_SRCERASE[256] = }; /* NOTSRCCOPY (0x00330008) */ -BYTE bmp_NOTSRCCOPY[256] = +static BYTE bmp_NOTSRCCOPY[256] = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" @@ -238,7 +238,7 @@ BYTE bmp_NOTSRCCOPY[256] = }; /* NOTSRCERASE (0x001100A6) */ -BYTE bmp_NOTSRCERASE[256] = +static BYTE bmp_NOTSRCERASE[256] = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" @@ -259,7 +259,7 @@ BYTE bmp_NOTSRCERASE[256] = }; /* DSTINVERT (0x00550009) */ -BYTE bmp_DSTINVERT[256] = +static BYTE bmp_DSTINVERT[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" @@ -280,7 +280,7 @@ BYTE bmp_DSTINVERT[256] = }; /* SPna (0x000C0324) */ -BYTE bmp_SPna[256] = +static BYTE bmp_SPna[256] = { "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" @@ -301,7 +301,7 @@ BYTE bmp_SPna[256] = }; /* MERGEPAINT (0x00BB0226) */ -BYTE bmp_MERGEPAINT[256] = +static BYTE bmp_MERGEPAINT[256] = { "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -322,7 +322,7 @@ BYTE bmp_MERGEPAINT[256] = }; /* MERGECOPY (0x00C000CA) */ -BYTE bmp_MERGECOPY[256] = +static BYTE bmp_MERGECOPY[256] = { "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" @@ -343,7 +343,7 @@ BYTE bmp_MERGECOPY[256] = }; /* PATPAINT (0x00FB0A09) */ -BYTE bmp_PATPAINT[256] = +static BYTE bmp_PATPAINT[256] = { "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -364,7 +364,7 @@ BYTE bmp_PATPAINT[256] = }; /* PATCOPY (0x00F00021) */ -BYTE bmp_PATCOPY[256] = +static BYTE bmp_PATCOPY[256] = { "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" @@ -385,7 +385,7 @@ BYTE bmp_PATCOPY[256] = }; /* PATINVERT (0x005A0049) */ -BYTE bmp_PATINVERT[256] = +static BYTE bmp_PATINVERT[256] = { "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" @@ -405,73 +405,29 @@ BYTE bmp_PATINVERT[256] = "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" }; -int CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2) +static int CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2) { - int bpp; - int x, y; + UINT32 x, y; BYTE *p1, *p2; - int minw = (hBmp1->width < hBmp2->width) ? hBmp1->width : hBmp2->width; - int minh = (hBmp1->height < hBmp2->height) ? hBmp1->height : hBmp2->height; + UINT32 minw = (hBmp1->width < hBmp2->width) ? hBmp1->width : hBmp2->width; + UINT32 minh = (hBmp1->height < hBmp2->height) ? hBmp1->height : hBmp2->height; - if (hBmp1->bitsPerPixel == hBmp2->bitsPerPixel) + if (hBmp1->format == hBmp2->format) { + UINT32 colorA, colorB; p1 = hBmp1->data; p2 = hBmp2->data; - bpp = hBmp1->bitsPerPixel; - if (bpp == 32) + for (y = 0; y < minh; y++) { - for (y = 0; y < minh; y++) + for (x = 0; x < minw; x++) { - for (x = 0; x < minw; x++) - { - if (*p1 != *p2) - return 0; - p1++; - p2++; + colorA = ReadColor(p1, hBmp1->format); + colorB = ReadColor(p2, hBmp2->format); - if (*p1 != *p2) - return 0; - p1++; - p2++; - - if (*p1 != *p2) - return 0; - p1 += 2; - p2 += 2; - } - } - } - else if (bpp == 16) - { - for (y = 0; y < minh; y++) - { - for (x = 0; x < minw; x++) - { - if (*p1 != *p2) - return 0; - p1++; - p2++; - - if (*p1 != *p2) - return 0; - p1++; - p2++; - } - } - } - else if (bpp == 8) - { - for (y = 0; y < minh; y++) - { - for (x = 0; x < minw; x++) - { - if (*p1 != *p2) - return 0; - p1++; - p2++; - } + p1 += GetBytesPerPixel(hBmp1->format); + p2 += GetBytesPerPixel(hBmp2->format); } } } @@ -483,7 +439,7 @@ int CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2) return 1; } -void test_dump_data(unsigned char* p, int len, int width, const char* name) +static void test_dump_data(unsigned char* p, int len, int width, const char* name) { unsigned char *line = p; int i, thisline, offset = 0; @@ -511,9 +467,11 @@ void test_dump_data(unsigned char* p, int len, int width, const char* name) printf("\n"); } -void test_dump_bitmap(HGDI_BITMAP hBmp, const char* name) +static void test_dump_bitmap(HGDI_BITMAP hBmp, const char* name) { - test_dump_data(hBmp->data, hBmp->width * hBmp->height * hBmp->bytesPerPixel, hBmp->width * hBmp->bytesPerPixel, name); + UINT32 stride = hBmp->width * GetBytesPerPixel(hBmp->format); + + test_dump_data(hBmp->data, hBmp->height * stride, stride, name); } int test_assert_bitmaps_equal(HGDI_BITMAP hBmpActual, HGDI_BITMAP hBmpExpected, const char* name) @@ -559,94 +517,84 @@ int test_gdi_BitBlt_32bpp(void) HGDI_BITMAP hBmp_PATPAINT; HGDI_BITMAP hBmp_PATINVERT; HGDI_BITMAP hBmpDstOriginal; - rdpPalette* hPalette; - HCLRCONV clrconv; - - int bytesPerPixel = 4; - int bitsPerPixel = 32; + UINT32* hPalette; + const UINT32 format = PIXEL_FORMAT_XRGB32; if (!(hdcSrc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } - hdcSrc->bytesPerPixel = bytesPerPixel; - hdcSrc->bitsPerPixel = bitsPerPixel; + hdcSrc->format = format; if (!(hdcDst = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } - hdcDst->bytesPerPixel = bytesPerPixel; - hdcDst->bitsPerPixel = bitsPerPixel; + hdcDst->format = format; - hPalette = (rdpPalette*) gdi_GetSystemPalette(); + hPalette = NULL; // TODO: Get a real palette! - clrconv = (HCLRCONV) calloc(1, sizeof(CLRCONV)); - clrconv->alpha = 0; - clrconv->invert = 0; - clrconv->palette = hPalette; + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, format, hPalette); + hBmpSrc = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, format, hPalette); + hBmpDst = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, format, hPalette); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, format, hPalette); + hBmpPat = gdi_CreateBitmap(8, 8, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, format, hPalette); + hBmp_SPna = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, format, hPalette); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, format, hPalette); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, format, hPalette); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, format, hPalette); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, format, hPalette); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, format, hPalette); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); - - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, format, hPalette); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, format, data); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); @@ -982,10 +930,7 @@ int test_gdi_BitBlt_16bpp(void) HGDI_BITMAP hBmp_PATINVERT; HGDI_BITMAP hBmpDstOriginal; rdpPalette* hPalette; - HCLRCONV clrconv; - - int bytesPerPixel = 2; - int bitsPerPixel = 16; + const UINT32 format = PIXEL_FORMAT_XRGB32; if (!(hdcSrc = gdi_GetDC())) { @@ -993,8 +938,7 @@ int test_gdi_BitBlt_16bpp(void) return -1; } - hdcSrc->bytesPerPixel = bytesPerPixel; - hdcSrc->bitsPerPixel = bitsPerPixel; + hdcSrc->format = format; if (!(hdcDst = gdi_GetDC())) { @@ -1002,75 +946,69 @@ int test_gdi_BitBlt_16bpp(void) return -1; } - hdcDst->bytesPerPixel = bytesPerPixel; - hdcDst->bitsPerPixel = bitsPerPixel; + hdcDst->format = format; hPalette = (rdpPalette*) gdi_GetSystemPalette(); - clrconv = (HCLRCONV) malloc(sizeof(CLRCONV)); - clrconv->alpha = 1; - clrconv->invert = 0; - clrconv->palette = hPalette; + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, format, hPalette); + hBmpSrc = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, format, hPalette); + hBmpDst = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, format, hPalette); + hBmpDstOriginal = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, format, hPalette); + hBmpPat = gdi_CreateBitmap(8, 8, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, format, hPalette); + hBmp_SPna = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, format, hPalette); + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, format, hPalette); + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCAND = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, format, hPalette); + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, format, hPalette); + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, format, hPalette); + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, format, hPalette); + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, format, hPalette); + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, format, hPalette); + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); - - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, format, hPalette); + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, format, data); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); @@ -1403,11 +1341,8 @@ int test_gdi_BitBlt_8bpp(void) HGDI_BITMAP hBmp_PATPAINT; HGDI_BITMAP hBmp_PATINVERT; HGDI_BITMAP hBmpDstOriginal; - rdpPalette* hPalette; - HCLRCONV clrconv; - - int bytesPerPixel = 1; - int bitsPerPixel = 8; + DWORD* hPalette; + const UINT32 format = PIXEL_FORMAT_XRGB32; if (!(hdcSrc = gdi_GetDC())) { @@ -1415,8 +1350,11 @@ int test_gdi_BitBlt_8bpp(void) return -1; } - hdcSrc->bytesPerPixel = bytesPerPixel; - hdcSrc->bitsPerPixel = bitsPerPixel; + hdcSrc->format = format; + + data = calloc(1024, 1024); + if (!data) + return -1; if (!(hdcDst = gdi_GetDC())) { @@ -1424,75 +1362,109 @@ int test_gdi_BitBlt_8bpp(void) return -1; } - hdcDst->bytesPerPixel = bytesPerPixel; - hdcDst->bitsPerPixel = bitsPerPixel; + hdcDst->format = format; - hPalette = (rdpPalette*) gdi_GetSystemPalette(); + hPalette = NULL; // TODO - clrconv = (HCLRCONV) malloc(sizeof(CLRCONV)); - clrconv->alpha = 1; - clrconv->invert = 0; - clrconv->palette = hPalette; + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_SRC, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmpSrc = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRC, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpSrc = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_DST, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmpDst = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDst = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_DST, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmpDstOriginal = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DST, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmpDstOriginal = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 8, 8, + bmp_DST, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmpPat = gdi_CreateBitmap(8, 8, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PAT, NULL, 8, 8, 8, bitsPerPixel, clrconv); - hBmpPat = gdi_CreateBitmap(8, 8, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_SRCCOPY, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_SPna, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_SPna = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SPna, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SPna = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_BLACKNESS, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_BLACKNESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_BLACKNESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_WHITENESS, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_WHITENESS = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_WHITENESS, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_WHITENESS = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_SRCAND, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_SRCAND = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCAND, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCAND = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_SRCPAINT, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_SRCINVERT, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_SRCERASE, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_SRCERASE = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_SRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_SRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_NOTSRCCOPY, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_NOTSRCERASE, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_NOTSRCERASE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_NOTSRCERASE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_DSTINVERT, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_DSTINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_DSTINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_MERGECOPY, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGECOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGECOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_MERGEPAINT, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_MERGEPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_MERGEPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_PATCOPY, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_PATCOPY = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATCOPY, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATCOPY = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_PATPAINT, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_PATPAINT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATPAINT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATPAINT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); - - data = (BYTE*) freerdp_image_convert((BYTE*) bmp_PATINVERT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_PATINVERT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + if (!freerdp_image_copy(data, format, -1, 0, 0, 16, 16, + bmp_PATINVERT, PIXEL_FORMAT_RGB8, -1, 0, 0, hPalette)) + return -1; + hBmp_PATINVERT = gdi_CreateBitmap(16, 16, format, data); gdi_SelectObject(hdcSrc, (HGDIOBJECT) hBmpSrc); gdi_SelectObject(hdcDst, (HGDIOBJECT) hBmpDst); diff --git a/libfreerdp/gdi/test/TestGdiClip.c b/libfreerdp/gdi/test/TestGdiClip.c index 627d36919..b3b390a69 100644 --- a/libfreerdp/gdi/test/TestGdiClip.c +++ b/libfreerdp/gdi/test/TestGdiClip.c @@ -3,22 +3,24 @@ #include #include -#include -#include #include #include #include -#include #include -int test_gdi_ClipCoords(void) +#include "line.h" +#include "brush.h" +#include "clipping.h" + +static int test_gdi_ClipCoords(void) { BOOL draw; HGDI_DC hdc; HGDI_RGN rgn1; HGDI_RGN rgn2; HGDI_BITMAP bmp; + const UINT32 format = PIXEL_FORMAT_ARGB32; if (!(hdc = gdi_GetDC())) { @@ -26,9 +28,8 @@ int test_gdi_ClipCoords(void) return -1; } - hdc->bytesPerPixel = 4; - hdc->bitsPerPixel = 32; - bmp = gdi_CreateBitmapEx(1024, 768, 4, NULL, NULL); + hdc->format = format; + bmp = gdi_CreateBitmapEx(1024, 768, PIXEL_FORMAT_XRGB32, 0, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); @@ -170,13 +171,14 @@ int test_gdi_ClipCoords(void) return 0; } -int test_gdi_InvalidateRegion(void) +static int test_gdi_InvalidateRegion(void) { HGDI_DC hdc; HGDI_RGN rgn1; HGDI_RGN rgn2; HGDI_RGN invalid; - HGDI_BITMAP bmp; + HGDI_BITMAP bmp; + const UINT32 format = PIXEL_FORMAT_XRGB32; if (!(hdc = gdi_GetDC())) { @@ -184,9 +186,8 @@ int test_gdi_InvalidateRegion(void) return -1; } - hdc->bytesPerPixel = 4; - hdc->bitsPerPixel = 32; - bmp = gdi_CreateBitmapEx(1024, 768, 4, NULL, NULL); + hdc->format = format; + bmp = gdi_CreateBitmapEx(1024, 768, PIXEL_FORMAT_XRGB32, 0, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); diff --git a/libfreerdp/gdi/test/TestGdiCreate.c b/libfreerdp/gdi/test/TestGdiCreate.c index 584d68362..7994abd7b 100644 --- a/libfreerdp/gdi/test/TestGdiCreate.c +++ b/libfreerdp/gdi/test/TestGdiCreate.c @@ -3,15 +3,16 @@ #include #include -#include -#include #include #include #include #include -int test_gdi_GetDC(void) +#include "line.h" +#include "brush.h" + +static int test_gdi_GetDC(void) { HGDI_DC hdc; @@ -21,10 +22,7 @@ int test_gdi_GetDC(void) return -1; } - if (hdc->bytesPerPixel != 4) - return -1; - - if (hdc->bitsPerPixel != 32) + if (hdc->format != PIXEL_FORMAT_XRGB32) return -1; if (hdc->drawMode != GDI_R2_BLACK) @@ -33,7 +31,7 @@ int test_gdi_GetDC(void) return 0; } -int test_gdi_CreateCompatibleDC(void) +static int test_gdi_CreateCompatibleDC(void) { HGDI_DC hdc; HGDI_DC chdc; @@ -44,8 +42,7 @@ int test_gdi_CreateCompatibleDC(void) return -1; } - hdc->bytesPerPixel = 2; - hdc->bitsPerPixel = 16; + hdc->format = PIXEL_FORMAT_RGB16; hdc->drawMode = GDI_R2_XORPEN; if (!(chdc = gdi_CreateCompatibleDC(hdc))) @@ -54,10 +51,7 @@ int test_gdi_CreateCompatibleDC(void) return -1; } - if (chdc->bytesPerPixel != hdc->bytesPerPixel) - return -1; - - if (chdc->bitsPerPixel != hdc->bitsPerPixel) + if (chdc->format != hdc->format) return -1; if (chdc->drawMode != hdc->drawMode) @@ -66,15 +60,14 @@ int test_gdi_CreateCompatibleDC(void) return 0; } -int test_gdi_CreateBitmap(void) +static int test_gdi_CreateBitmap(void) { - int bpp; - int width; - int height; + UINT32 format = PIXEL_FORMAT_ARGB32; + UINT32 width; + UINT32 height; BYTE* data; HGDI_BITMAP hBitmap; - bpp = 32; width = 32; height = 16; if (!(data = (BYTE*) _aligned_malloc(width * height * 4, 16))) @@ -83,7 +76,7 @@ int test_gdi_CreateBitmap(void) return -1; } - if (!(hBitmap = gdi_CreateBitmap(width, height, bpp, data))) + if (!(hBitmap = gdi_CreateBitmap(width, height, format, data))) { printf("gdi_CreateBitmap failed\n"); return -1; @@ -92,7 +85,7 @@ int test_gdi_CreateBitmap(void) if (hBitmap->objectType != GDIOBJECT_BITMAP) return -1; - if (hBitmap->bitsPerPixel != bpp) + if (hBitmap->format != format) return -1; if (hBitmap->width != width) @@ -109,11 +102,11 @@ int test_gdi_CreateBitmap(void) return 0; } -int test_gdi_CreateCompatibleBitmap(void) +static int test_gdi_CreateCompatibleBitmap(void) { HGDI_DC hdc; - int width; - int height; + UINT32 width; + UINT32 height; HGDI_BITMAP hBitmap; if (!(hdc = gdi_GetDC())) @@ -122,8 +115,7 @@ int test_gdi_CreateCompatibleBitmap(void) return -1; } - hdc->bytesPerPixel = 4; - hdc->bitsPerPixel = 32; + hdc->format = PIXEL_FORMAT_ARGB32; width = 32; height = 16; @@ -132,10 +124,7 @@ int test_gdi_CreateCompatibleBitmap(void) if (hBitmap->objectType != GDIOBJECT_BITMAP) return -1; - if (hBitmap->bytesPerPixel != hdc->bytesPerPixel) - return -1; - - if (hBitmap->bitsPerPixel != hdc->bitsPerPixel) + if (hBitmap->format != hdc->format) return -1; if (hBitmap->width != width) @@ -152,7 +141,7 @@ int test_gdi_CreateCompatibleBitmap(void) return 0; } -int test_gdi_CreatePen(void) +static int test_gdi_CreatePen(void) { HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD); @@ -176,7 +165,7 @@ int test_gdi_CreatePen(void) return 0; } -int test_gdi_CreateSolidBrush(void) +static int test_gdi_CreateSolidBrush(void) { HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD); @@ -194,7 +183,7 @@ int test_gdi_CreateSolidBrush(void) return 0; } -int test_gdi_CreatePatternBrush(void) +static int test_gdi_CreatePatternBrush(void) { HGDI_BRUSH hBrush; HGDI_BITMAP hBitmap; @@ -216,7 +205,7 @@ int test_gdi_CreatePatternBrush(void) return 0; } -int test_gdi_CreateRectRgn(void) +static int test_gdi_CreateRectRgn(void) { int x1 = 32; int y1 = 64; @@ -248,7 +237,7 @@ int test_gdi_CreateRectRgn(void) return 0; } -int test_gdi_CreateRect(void) +static int test_gdi_CreateRect(void) { HGDI_RECT hRect; int x1 = 32; @@ -282,7 +271,7 @@ int test_gdi_CreateRect(void) return 0; } -int test_gdi_GetPixel(void) +static int test_gdi_GetPixel(void) { HGDI_DC hdc; int width = 128; @@ -295,8 +284,7 @@ int test_gdi_GetPixel(void) return -1; } - hdc->bytesPerPixel = 4; - hdc->bitsPerPixel = 32; + hdc->format = PIXEL_FORMAT_ARGB32; hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap); @@ -314,11 +302,11 @@ int test_gdi_GetPixel(void) return 0; } -int test_gdi_SetPixel(void) +static int test_gdi_SetPixel(void) { HGDI_DC hdc; - int width = 128; - int height = 64; + UINT32 width = 128; + UINT32 height = 64; HGDI_BITMAP hBitmap; if (!(hdc = gdi_GetDC())) @@ -327,8 +315,7 @@ int test_gdi_SetPixel(void) return -1; } - hdc->bytesPerPixel = 4; - hdc->bitsPerPixel = 32; + hdc->format = PIXEL_FORMAT_ARGB32; hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap); @@ -348,7 +335,7 @@ int test_gdi_SetPixel(void) return 0; } -int test_gdi_SetROP2(void) +static int test_gdi_SetROP2(void) { HGDI_DC hdc; @@ -366,7 +353,7 @@ int test_gdi_SetROP2(void) return 0; } -int test_gdi_MoveToEx(void) +static int test_gdi_MoveToEx(void) { HGDI_DC hdc; HGDI_PEN hPen; diff --git a/libfreerdp/gdi/test/TestGdiEllipse.c b/libfreerdp/gdi/test/TestGdiEllipse.c index 7d3b107e6..c32640e12 100644 --- a/libfreerdp/gdi/test/TestGdiEllipse.c +++ b/libfreerdp/gdi/test/TestGdiEllipse.c @@ -3,21 +3,21 @@ #include #include -#include #include -#include #include #include #include -#include -#include #include #include +#include "line.h" +#include "brush.h" +#include "clipping.h" + /* Ellipse() Test Data */ -BYTE ellipse_case_1[256] = +static BYTE ellipse_case_1[256] = { "\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF" @@ -37,7 +37,7 @@ BYTE ellipse_case_1[256] = "\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF" }; -BYTE ellipse_case_2[256] = +static BYTE ellipse_case_2[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF" @@ -57,7 +57,7 @@ BYTE ellipse_case_2[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE ellipse_case_3[256] = +static BYTE ellipse_case_3[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -87,9 +87,7 @@ int TestGdiEllipse(int argc, char* argv[]) HGDI_BITMAP hBmp_Ellipse_2; HGDI_BITMAP hBmp_Ellipse_3; rdpPalette* hPalette; - HCLRCONV clrconv; - int bitsPerPixel = 8; - int bytesPerPixel = 1; + const UINT32 format = PIXEL_FORMAT_RGB8; if (!(hdc = gdi_GetDC())) { @@ -97,8 +95,7 @@ int TestGdiEllipse(int argc, char* argv[]) return -1; } - hdc->bitsPerPixel = bitsPerPixel; - hdc->bytesPerPixel = bytesPerPixel; + hdc->format = format; gdi_SetNullClipRgn(hdc); if (!(pen = gdi_CreatePen(1, 1, 0))) @@ -114,19 +111,14 @@ int TestGdiEllipse(int argc, char* argv[]) hPalette = (rdpPalette*) gdi_GetSystemPalette(); - clrconv = (HCLRCONV) malloc(sizeof(CLRCONV)); - clrconv->alpha = 1; - clrconv->invert = 0; - clrconv->palette = hPalette; + data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_1, NULL, 16, 16, 8, format, hPalette); + hBmp_Ellipse_1 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_2, NULL, 16, 16, 8, format, hPalette); + hBmp_Ellipse_2 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); - - data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_Ellipse_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_3, NULL, 16, 16, 8, format, hPalette); + hBmp_Ellipse_3 = gdi_CreateBitmap(16, 16, format, data); /* Test Case 1: (0,0) -> (16, 16) */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS)) diff --git a/libfreerdp/gdi/test/TestGdiLine.c b/libfreerdp/gdi/test/TestGdiLine.c index 1ae64a030..aadc1cff7 100644 --- a/libfreerdp/gdi/test/TestGdiLine.c +++ b/libfreerdp/gdi/test/TestGdiLine.c @@ -3,20 +3,19 @@ #include #include -#include -#include #include #include #include -#include -#include #include #include +#include "line.h" +#include "brush.h" +#include "clipping.h" + /* LineTo() Test Data */ - -BYTE line_to_case_1[256] = +static BYTE line_to_case_1[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -36,7 +35,7 @@ BYTE line_to_case_1[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_2[256] = +static BYTE line_to_case_2[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -56,7 +55,7 @@ BYTE line_to_case_2[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_case_3[256] = +static BYTE line_to_case_3[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF" @@ -76,7 +75,7 @@ BYTE line_to_case_3[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_4[256] = +static BYTE line_to_case_4[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF" @@ -96,7 +95,7 @@ BYTE line_to_case_4[256] = "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_5[256] = +static BYTE line_to_case_5[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -116,7 +115,7 @@ BYTE line_to_case_5[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_6[256] = +static BYTE line_to_case_6[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -136,7 +135,7 @@ BYTE line_to_case_6[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_7[256] = +static BYTE line_to_case_7[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -156,7 +155,7 @@ BYTE line_to_case_7[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_8[256] = +static BYTE line_to_case_8[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -176,7 +175,7 @@ BYTE line_to_case_8[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_9[256] = +static BYTE line_to_case_9[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -196,7 +195,7 @@ BYTE line_to_case_9[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_10[256] = +static BYTE line_to_case_10[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -216,7 +215,7 @@ BYTE line_to_case_10[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_case_11[256] = +static BYTE line_to_case_11[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -236,7 +235,7 @@ BYTE line_to_case_11[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_BLACK[256] = +static BYTE line_to_R2_BLACK[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -256,7 +255,7 @@ BYTE line_to_R2_BLACK[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_NOTMERGEPEN[256] = +static BYTE line_to_R2_NOTMERGEPEN[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -276,7 +275,7 @@ BYTE line_to_R2_NOTMERGEPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_MASKNOTPEN[256] = +static BYTE line_to_R2_MASKNOTPEN[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -296,7 +295,7 @@ BYTE line_to_R2_MASKNOTPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_NOTCOPYPEN[256] = +static BYTE line_to_R2_NOTCOPYPEN[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -316,7 +315,7 @@ BYTE line_to_R2_NOTCOPYPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_MASKPENNOT[256] = +static BYTE line_to_R2_MASKPENNOT[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -336,7 +335,7 @@ BYTE line_to_R2_MASKPENNOT[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_NOT[256] = +static BYTE line_to_R2_NOT[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -356,7 +355,7 @@ BYTE line_to_R2_NOT[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_XORPEN[256] = +static BYTE line_to_R2_XORPEN[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -376,7 +375,7 @@ BYTE line_to_R2_XORPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_NOTMASKPEN[256] = +static BYTE line_to_R2_NOTMASKPEN[256] = { "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -396,7 +395,7 @@ BYTE line_to_R2_NOTMASKPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00" }; -BYTE line_to_R2_MASKPEN[256] = +static BYTE line_to_R2_MASKPEN[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -416,7 +415,7 @@ BYTE line_to_R2_MASKPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_R2_NOTXORPEN[256] = +static BYTE line_to_R2_NOTXORPEN[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -436,7 +435,7 @@ BYTE line_to_R2_NOTXORPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_R2_NOP[256] = +static BYTE line_to_R2_NOP[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -456,7 +455,7 @@ BYTE line_to_R2_NOP[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_R2_MERGENOTPEN[256] = +static BYTE line_to_R2_MERGENOTPEN[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -476,7 +475,7 @@ BYTE line_to_R2_MERGENOTPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_R2_COPYPEN[256] = +static BYTE line_to_R2_COPYPEN[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -496,7 +495,7 @@ BYTE line_to_R2_COPYPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_R2_MERGEPENNOT[256] = +static BYTE line_to_R2_MERGEPENNOT[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -516,7 +515,7 @@ BYTE line_to_R2_MERGEPENNOT[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_R2_MERGEPEN[256] = +static BYTE line_to_R2_MERGEPEN[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -536,7 +535,7 @@ BYTE line_to_R2_MERGEPEN[256] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" }; -BYTE line_to_R2_WHITE[256] = +static BYTE line_to_R2_WHITE[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -558,7 +557,7 @@ BYTE line_to_R2_WHITE[256] = /* PolylineTo() Test Data */ -BYTE polyline_to_case_1[256] = +static BYTE polyline_to_case_1[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -578,7 +577,7 @@ BYTE polyline_to_case_1[256] = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; -BYTE polyline_to_case_2[256] = +static BYTE polyline_to_case_2[256] = { "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" @@ -634,9 +633,7 @@ int TestGdiLine(int argc, char* argv[]) HGDI_BITMAP hBmp_LineTo_R2_MERGEPEN; HGDI_BITMAP hBmp_LineTo_R2_WHITE; rdpPalette* hPalette; - HCLRCONV clrconv; - int bitsPerPixel = 8; - int bytesPerPixel = 1; + const UINT32 format = PIXEL_FORMAT_ARGB32; if (!(hdc = gdi_GetDC())) { @@ -644,8 +641,7 @@ int TestGdiLine(int argc, char* argv[]) return -1; } - hdc->bitsPerPixel = bitsPerPixel; - hdc->bytesPerPixel = bytesPerPixel; + hdc->format = format; gdi_SetNullClipRgn(hdc); if (!(pen = gdi_CreatePen(1, 1, 0))) @@ -661,94 +657,89 @@ int TestGdiLine(int argc, char* argv[]) hPalette = (rdpPalette*) gdi_GetSystemPalette(); - clrconv = (HCLRCONV) malloc(sizeof(CLRCONV)); - clrconv->alpha = 1; - clrconv->invert = 0; - clrconv->palette = hPalette; + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_1, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_2, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_3, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_4, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_4, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_6, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_6, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_7, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_7, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_8, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_8, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_9, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_9, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_10, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_10, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_11, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_11, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_BLACK, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_BLACK, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMERGEPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKNOTPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKNOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTCOPYPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTCOPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPENNOT, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOT, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_XORPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_XORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMASKPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTXORPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTXORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOP, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOP, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGENOTPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGENOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_COPYPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_COPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPENNOT, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPEN, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, format, data); - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); - - data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_WHITE, NULL, 16, 16, 8, bitsPerPixel, clrconv); - hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); + data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_WHITE, NULL, 16, 16, 8, format, hPalette); + hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, format, data); /* Test Case 1: (0,0) -> (15, 15) */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS)) diff --git a/libfreerdp/gdi/test/TestGdiRect.c b/libfreerdp/gdi/test/TestGdiRect.c index e653e8608..2acbabdcf 100644 --- a/libfreerdp/gdi/test/TestGdiRect.c +++ b/libfreerdp/gdi/test/TestGdiRect.c @@ -3,19 +3,19 @@ #include #include -#include #include -#include #include #include #include -#include -#include -#include #include #include +#include "line.h" +#include "brush.h" +#include "clipping.h" +#include "32bpp.h" + int test_gdi_PtInRect(void) { HGDI_RECT hRect; @@ -66,16 +66,14 @@ int test_gdi_FillRect(void) HGDI_RECT hRect; HGDI_BRUSH hBrush; HGDI_BITMAP hBitmap; - GDI_COLOR color; - GDI_COLOR pixel; - GDI_COLOR rawPixel; - + UINT32 color; + UINT32 pixel; + UINT32 rawPixel; int x, y; int badPixels; int goodPixels; int width = 200; int height = 300; - int left = 20; int top = 40; int right = 60; @@ -87,8 +85,7 @@ int test_gdi_FillRect(void) return -1; } - hdc->bytesPerPixel = 4; - hdc->bitsPerPixel = 32; + hdc->format = PIXEL_FORMAT_XRGB32; if (!(hRect = gdi_CreateRect(left, top, right, bottom))) { @@ -97,14 +94,11 @@ int test_gdi_FillRect(void) } hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); - ZeroMemory(hBitmap->data, width * height * hdc->bytesPerPixel); + ZeroMemory(hBitmap->data, width * height * GetBytesPerPixel(hdc->format)); gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap); - - color = (GDI_COLOR) ARGB32(0xFF, 0xAA, 0xBB, 0xCC); + color = GetColor(PIXEL_FORMAT_ARGB32, 0xAA, 0xBB, 0xCC, 0xFF); hBrush = gdi_CreateSolidBrush(color); - gdi_FillRect(hdc, hRect, hBrush); - badPixels = 0; goodPixels = 0; @@ -113,24 +107,28 @@ int test_gdi_FillRect(void) for (y = 0; y < height; y++) { rawPixel = gdi_GetPixel(hdc, x, y); - pixel = gdi_get_color_32bpp(hdc, rawPixel); + pixel = ConvertColor(rawPixel, hdc->format, PIXEL_FORMAT_ARGB32, NULL); if (gdi_PtInRect(hRect, x, y)) { - if (pixel == color) { + if (pixel == color) + { goodPixels++; } - else { + else + { printf("actual:%04X expected:%04X\n", gdi_GetPixel(hdc, x, y), color); badPixels++; } } else { - if (pixel == color) { + if (pixel == color) + { badPixels++; } - else { + else + { goodPixels++; } } @@ -145,7 +143,6 @@ int test_gdi_FillRect(void) gdi_DeleteObject((HGDIOBJECT) hBrush); gdi_DeleteObject((HGDIOBJECT) hBitmap); - return 0; } diff --git a/libfreerdp/primitives/prim_16to32bpp.c b/libfreerdp/primitives/prim_16to32bpp.c deleted file mode 100644 index a9110558b..000000000 --- a/libfreerdp/primitives/prim_16to32bpp.c +++ /dev/null @@ -1,137 +0,0 @@ -/* prim_16to32bpp.c - * 16-bit to 32-bit color conversion (widely used) - * vi:ts=4 sw=4: - * - * The general routine was leveraged from freerdp/codec/color.c. - * - * Copyright 2010 Marc-Andre Moreau - * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "prim_internal.h" -#include "prim_16to32bpp.h" - -/* ------------------------------------------------------------------------- */ -pstatus_t general_RGB565ToARGB_16u32u_C3C4( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha, BOOL invert) -{ - const UINT16* src16; - UINT32* dst32; - int x,y; - int srcRowBump, dstRowBump; - BYTE red, green, blue; - - src16 = pSrc; - dst32 = pDst; - srcRowBump = (srcStep - (width * sizeof(UINT16))) / sizeof(UINT16); - dstRowBump = (dstStep - (width * sizeof(UINT32))) / sizeof(UINT32); - - /* Loops are separated so if-decisions are not made in the loop. */ - if (alpha) - { - if (invert) - { - for (y=0; yRGB565ToARGB_16u32u_C3C4 = general_RGB565ToARGB_16u32u_C3C4; - - primitives_init_16to32bpp_opt(prims); -} - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_16to32bpp( - primitives_t *prims) -{ - /* Nothing to do. */ -} diff --git a/libfreerdp/primitives/prim_16to32bpp.h b/libfreerdp/primitives/prim_16to32bpp.h deleted file mode 100644 index 80a3cd735..000000000 --- a/libfreerdp/primitives/prim_16to32bpp.h +++ /dev/null @@ -1,36 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * 16-bit to 32-bit color conversions - * vi:ts=4 sw=4 - * - * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_16TO32BPP_H_INCLUDED__ -#define __PRIM_16TO32BPP_H_INCLUDED__ - -#include - -extern pstatus_t general_RGB565ToARGB_16u32u_C3C4( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha, BOOL invert); -extern void primitives_init_16to32bpp_opt(primitives_t* prims); - -#endif /* !__PRIM_16TO32BPP_H_INCLUDED__ */ diff --git a/libfreerdp/primitives/prim_16to32bpp_opt.c b/libfreerdp/primitives/prim_16to32bpp_opt.c deleted file mode 100644 index a37e3e3f8..000000000 --- a/libfreerdp/primitives/prim_16to32bpp_opt.c +++ /dev/null @@ -1,280 +0,0 @@ -/* prim_16to32bpp_opt.c - * 16-bit to 32-bit color conversion via SSE/Neon - * vi:ts=4 sw=4: - * - * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifdef WITH_SSE2 -#include -#include -/* #elif defined(WITH_NEON) */ -/* #include */ -#endif /* WITH_SSE2 */ - -#include "prim_internal.h" -#include "prim_16to32bpp.h" - -#ifdef WITH_SSE2 -/* ------------------------------------------------------------------------- */ -/* Note: _no_invert and _invert could be coded with variables as shift - * amounts and a single routine, but tests showed that was much slower. - */ -static pstatus_t sse3_RGB565ToARGB_16u32u_C3C4_no_invert( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha) -{ - const BYTE *src = (const BYTE *) pSrc; - BYTE *dst = (BYTE *) pDst; - int h; - int srcRowBump = srcStep - (width * sizeof(UINT16)); - int dstRowBump = dstStep - (width * sizeof(UINT32)); - __m128i R0, R1, R2, R_FC00, R_0300, R_00F8, R_0007, R_alpha; - - R_FC00 = _mm_set1_epi16(0xFC00); - R_0300 = _mm_set1_epi16(0x0300); - R_00F8 = _mm_set1_epi16(0x00F8); - R_0007 = _mm_set1_epi16(0x0007); - if (alpha) R_alpha = _mm_set1_epi32(0xFF00FF00U); - else R_alpha = _mm_set1_epi32(0x00000000U); - - for (h=0; h width) startup = width; - general_RGB565ToARGB_16u32u_C3C4((const UINT16*) src, srcStep, - (UINT32*) dst, dstStep, startup, 1, alpha, FALSE); - src += startup * sizeof(UINT16); - dst += startup * sizeof(UINT32); - w -= startup; - } - - /* The main loop handles eight pixels at a time. */ - while (w >= 8) - { - /* If off-stride, use the slower load. */ - if ((ULONG_PTR) src & 0x0f) - R0 = _mm_lddqu_si128((__m128i *) src); - else - R0 = _mm_load_si128((__m128i *) src); - src += (128/8); - - /* Do the lower two colors, which end up in the lower two bytes. */ - /* G = ((P<<5) & 0xFC00) | ((P>>1) & 0x0300) */ - R2 = _mm_slli_epi16(R0, 5); - R2 = _mm_and_si128(R_FC00, R2); - - R1 = _mm_srli_epi16(R0, 1); - R1 = _mm_and_si128(R_0300, R1); - R2 = _mm_or_si128(R1, R2); - - /* R = ((P<<3) & 0x00F8) | ((P>>2) & 0x0007) */ - R1 = _mm_slli_epi16(R0, 3); - R1 = _mm_and_si128(R_00F8, R1); - R2 = _mm_or_si128(R1, R2); - - R1 = _mm_srli_epi16(R0, 2); - R1 = _mm_and_si128(R_0007, R1); - R2 = _mm_or_si128(R1, R2); /* R2 = lowers */ - - /* Handle the upper color. */ - /* B = ((P<<8) & 0x00F8) | ((P<<13) & 0x0007) */ - R1 = _mm_srli_epi16(R0, 8); - R1 = _mm_and_si128(R_00F8, R1); - - R0 = _mm_srli_epi16(R0, 13); - R0 = _mm_and_si128(R_0007, R0); - R1 = _mm_or_si128(R0, R1); /* R1 = uppers */ - - /* Add alpha (or zero) . */ - R1 = _mm_or_si128(R_alpha, R1); /* + alpha */ - - /* Unpack to intermix the AB and GR pieces. */ - R0 = _mm_unpackhi_epi16(R2, R1); - R2 = _mm_unpacklo_epi16(R2, R1); - - /* Store the results. */ - _mm_store_si128((__m128i *) dst, R2); dst += (128/8); - _mm_store_si128((__m128i *) dst, R0); dst += (128/8); - w -= 8; - } - - /* Handle any remainder. */ - if (w > 0) - { - general_RGB565ToARGB_16u32u_C3C4((const UINT16*) src, srcStep, - (UINT32*) dst, dstStep, w, 1, alpha, FALSE); - src += w * sizeof(UINT16); - dst += w * sizeof(UINT32); - } - - /* Bump to the start of the next row. */ - src += srcRowBump; - dst += dstRowBump; - } - - return PRIMITIVES_SUCCESS; -} - -/* ------------------------------------------------------------------------- */ -static pstatus_t sse3_RGB565ToARGB_16u32u_C3C4_invert( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha) -{ - const BYTE *src = (const BYTE *) pSrc; - BYTE *dst = (BYTE *) pDst; - int h; - int srcRowBump = srcStep - (width * sizeof(UINT16)); - int dstRowBump = dstStep - (width * sizeof(UINT32)); - __m128i R0, R1, R2, R_FC00, R_0300, R_00F8, R_0007, R_alpha; - - R_FC00 = _mm_set1_epi16(0xFC00); - R_0300 = _mm_set1_epi16(0x0300); - R_00F8 = _mm_set1_epi16(0x00F8); - R_0007 = _mm_set1_epi16(0x0007); - if (alpha) R_alpha = _mm_set1_epi32(0xFF00FF00U); - else R_alpha = _mm_set1_epi32(0x00000000U); - - for (h=0; h width) startup = width; - general_RGB565ToARGB_16u32u_C3C4((const UINT16*) src, srcStep, - (UINT32*) dst, dstStep, startup, 1, alpha, TRUE); - src += startup * sizeof(UINT16); - dst += startup * sizeof(UINT32); - w -= startup; - } - - /* The main loop handles eight pixels at a time. */ - while (w >= 8) - { - /* Off-stride, slower load. */ - if ((ULONG_PTR) src & 0x0f) - R0 = _mm_lddqu_si128((__m128i *) src); - else - R0 = _mm_load_si128((__m128i *) src); - src += (128/8); - - /* Do the lower two colors, which end up in the lower two bytes. */ - /* G = ((P<<5) & 0xFC00) | ((P>>1) & 0x0300) */ - R2 = _mm_slli_epi16(R0, 5); - R2 = _mm_and_si128(R_FC00, R2); - - R1 = _mm_srli_epi16(R0, 1); - R1 = _mm_and_si128(R_0300, R1); - R2 = _mm_or_si128(R1, R2); - - /* B = ((P>>8) & 0x00F8) | ((P>>13) & 0x0007) */ - R1 = _mm_srli_epi16(R0, 8); - R1 = _mm_and_si128(R_00F8, R1); - R2 = _mm_or_si128(R1, R2); - - R1 = _mm_srli_epi16(R0, 13); - R1 = _mm_and_si128(R_0007, R1); - R2 = _mm_or_si128(R1, R2); /* R2 = lowers */ - - /* Handle the upper color. */ - /* R = ((P<<3) & 0x00F8) | ((P>>13) & 0x0007) */ - R1 = _mm_slli_epi16(R0, 3); - R1 = _mm_and_si128(R_00F8, R1); - - R0 = _mm_srli_epi16(R0, 2); - R0 = _mm_and_si128(R_0007, R0); - R1 = _mm_or_si128(R0, R1); /* R1 = uppers */ - - /* Add alpha (or zero) . */ - R1 = _mm_or_si128(R_alpha, R1); /* + alpha */ - - /* Unpack to intermix the AR and GB pieces. */ - R0 = _mm_unpackhi_epi16(R2, R1); - R2 = _mm_unpacklo_epi16(R2, R1); - - /* Store the results. */ - _mm_store_si128((__m128i *) dst, R2); dst += (128/8); - _mm_store_si128((__m128i *) dst, R0); dst += (128/8); - w -= 8; - } - - /* Handle any remainder. */ - if (w > 0) - { - general_RGB565ToARGB_16u32u_C3C4((const UINT16*) src, srcStep, - (UINT32*) dst, dstStep, w, 1, alpha, TRUE); - src += w * sizeof(UINT16); - dst += w * sizeof(UINT32); - } - - /* Bump to the start of the next row. */ - src += srcRowBump; - dst += dstRowBump; - } - - return PRIMITIVES_SUCCESS; -} - -/* ------------------------------------------------------------------------- */ -pstatus_t sse3_RGB565ToARGB_16u32u_C3C4( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha, BOOL invert) -{ - if (invert) - { - return sse3_RGB565ToARGB_16u32u_C3C4_invert(pSrc, srcStep, - pDst, dstStep, width, height, alpha); - } - else - { - return sse3_RGB565ToARGB_16u32u_C3C4_no_invert(pSrc, srcStep, - pDst, dstStep, width, height, alpha); - } -} -#endif /* WITH_SSE2 */ - -/* ------------------------------------------------------------------------- */ -void primitives_init_16to32bpp_opt( - primitives_t *prims) -{ -#ifdef WITH_SSE2 - if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) - { - prims->RGB565ToARGB_16u32u_C3C4 = sse3_RGB565ToARGB_16u32u_C3C4; - } -#endif -} diff --git a/libfreerdp/primitives/prim_YCoCg.c b/libfreerdp/primitives/prim_YCoCg.c index ca6484795..0b264d22f 100644 --- a/libfreerdp/primitives/prim_YCoCg.c +++ b/libfreerdp/primitives/prim_YCoCg.c @@ -25,7 +25,6 @@ #include #include "prim_internal.h" -#include "prim_YCoCg.h" #ifndef MINMAX #define MINMAX(_v_, _l_, _h_) \ @@ -33,84 +32,47 @@ #endif /* !MINMAX */ /* ------------------------------------------------------------------------- */ -pstatus_t general_YCoCgToRGB_8u_AC4R( - const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, - UINT32 width, UINT32 height, - UINT8 shift, - BOOL withAlpha, - BOOL invert) +static pstatus_t general_YCoCgToRGB_8u_AC4R( + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, UINT32 DstFormat, INT32 dstStep, + UINT32 width, UINT32 height, + UINT8 shift, + BOOL withAlpha) { BYTE A; - int x, y; - BYTE *dptr = pDst; - const BYTE *sptr = pSrc; + UINT32 x, y; + BYTE* dptr = pDst; + const BYTE* sptr = pSrc; INT16 Cg, Co, Y, T, R, G, B; int cll = shift - 1; /* -1 builds in the /2's */ - int srcPad = srcStep - (width * 4); - int dstPad = dstStep - (width * 4); + UINT32 srcPad = srcStep - (width * 4); + UINT32 dstPad = dstStep - (width * GetBytesPerPixel(DstFormat)); - if (invert) + for (y = 0; y < height; y++) { - for (y = 0; y < height; y++) + for (x = 0; x < width; x++) { - for (x = 0; x < width; x++) - { - /* Note: shifts must be done before sign-conversion. */ - Cg = (INT16) ((INT8) ((*sptr++) << cll)); - Co = (INT16) ((INT8) ((*sptr++) << cll)); - Y = (INT16) (*sptr++); /* UINT8->INT16 */ + UINT32 color; + /* Note: shifts must be done before sign-conversion. */ + Cg = (INT16)((INT8)((*sptr++) << cll)); + Co = (INT16)((INT8)((*sptr++) << cll)); + Y = (INT16)(*sptr++); /* UINT8->INT16 */ + A = *sptr++; - A = *sptr++; + if (!withAlpha) + A = 0xFFU; - if (!withAlpha) - A = 0xFFU; - - T = Y - Cg; - R = T + Co; - G = Y + Cg; - B = T - Co; - - *dptr++ = (BYTE) MINMAX(R, 0, 255); - *dptr++ = (BYTE) MINMAX(G, 0, 255); - *dptr++ = (BYTE) MINMAX(B, 0, 255); - *dptr++ = A; - } - - sptr += srcPad; - dptr += dstPad; + T = Y - Cg; + R = T + Co; + G = Y + Cg; + B = T - Co; + color = GetColor(DstFormat, MINMAX(R, 0, 255), MINMAX(G, 0, 255), MINMAX(B, 0, + 255), A); + dptr += GetBytesPerPixel(DstFormat); } - } - else - { - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - /* Note: shifts must be done before sign-conversion. */ - Cg = (INT16) ((INT8) ((*sptr++) << cll)); - Co = (INT16) ((INT8) ((*sptr++) << cll)); - Y = (INT16) (*sptr++); /* UINT8->INT16 */ - A = *sptr++; - - if (!withAlpha) - A = 0xFFU; - - T = Y - Cg; - R = T + Co; - G = Y + Cg; - B = T - Co; - - *dptr++ = (BYTE) MINMAX(B, 0, 255); - *dptr++ = (BYTE) MINMAX(G, 0, 255); - *dptr++ = (BYTE) MINMAX(R, 0, 255); - *dptr++ = A; - } - - sptr += srcPad; - dptr += dstPad; - } + sptr += srcPad; + dptr += dstPad; } return PRIMITIVES_SUCCESS; @@ -120,12 +82,4 @@ pstatus_t general_YCoCgToRGB_8u_AC4R( void primitives_init_YCoCg(primitives_t* prims) { prims->YCoCgToRGB_8u_AC4R = general_YCoCgToRGB_8u_AC4R; - - primitives_init_YCoCg_opt(prims); -} - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_YCoCg(primitives_t* prims) -{ - /* Nothing to do. */ } diff --git a/libfreerdp/primitives/prim_YCoCg.h b/libfreerdp/primitives/prim_YCoCg.h deleted file mode 100644 index c03715bda..000000000 --- a/libfreerdp/primitives/prim_YCoCg.h +++ /dev/null @@ -1,31 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * YCoCg<->RGB color conversion operations. - * vi:ts=4 sw=4 - * - * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_YCOCG_H_INCLUDED__ -#define __PRIM_YCOCG_H_INCLUDED__ - -pstatus_t general_YCoCgToRGB_8u_AC4R(const BYTE *pSrc, INT32 srcStep, BYTE *pDst, INT32 dstStep, UINT32 width, UINT32 height, UINT8 shift, BOOL withAlpha, BOOL invert); - -void primitives_init_YCoCg_opt(primitives_t* prims); - -#endif /* !__PRIM_YCOCG_H_INCLUDED__ */ diff --git a/libfreerdp/primitives/prim_YCoCg_opt.c b/libfreerdp/primitives/prim_YCoCg_opt.c index e022662b3..93cddb56e 100644 --- a/libfreerdp/primitives/prim_YCoCg_opt.c +++ b/libfreerdp/primitives/prim_YCoCg_opt.c @@ -34,28 +34,28 @@ #include "prim_internal.h" #include "prim_templates.h" -#include "prim_YCoCg.h" + +static primitives_t* generic = NULL; #ifdef WITH_SSE2 - /* ------------------------------------------------------------------------- */ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_invert( - const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, - UINT32 width, UINT32 height, - UINT8 shift, - BOOL withAlpha) + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, INT32 dstStep, + UINT32 width, UINT32 height, + UINT8 shift, + BOOL withAlpha) { - const BYTE *sptr = pSrc; - BYTE *dptr = (BYTE *) pDst; - int sRowBump = srcStep - width*sizeof(UINT32); - int dRowBump = dstStep - width*sizeof(UINT32); + const BYTE* sptr = pSrc; + BYTE* dptr = (BYTE*) pDst; + int sRowBump = srcStep - width * sizeof(UINT32); + int dRowBump = dstStep - width * sizeof(UINT32); int h; /* Shift left by "shift" and divide by two is the same as shift * left by "shift-1". */ int dataShift = shift - 1; - BYTE mask = (BYTE) (0xFFU << dataShift); + BYTE mask = (BYTE)(0xFFU << dataShift); /* Let's say the data is of the form: * y0y0o0g0 a1y1o1g1 a2y2o2g2... @@ -69,11 +69,12 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_invert( if ((width < 8) || (ULONG_PTR) dptr & 0x03) { /* Too small, or we'll never hit a 16-byte boundary. Punt. */ - return general_YCoCgToRGB_8u_AC4R(pSrc, srcStep, - pDst, dstStep, width, height, shift, withAlpha, TRUE); + return generic->YCoCgToRGB_8u_AC4R( + pSrc, srcStep, pDst, dstStep, + width, height, shift, withAlpha, TRUE); } - for (h=0; h width) startup = width; - general_YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, - startup, 1, shift, withAlpha, TRUE); + + generic->YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, + startup, 1, shift, withAlpha, TRUE); sptr += startup * sizeof(UINT32); dptr += startup * sizeof(UINT32); w -= startup; @@ -92,42 +95,50 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_invert( /* Each loop handles eight pixels at a time. */ onStride = (((ULONG_PTR) sptr & 0x0f) == 0) ? TRUE : FALSE; + while (w >= 8) { __m128i R0, R1, R2, R3, R4, R5, R6, R7; + if (onStride) { /* The faster path, 16-byte aligned load. */ - R0 = _mm_load_si128((__m128i *) sptr); sptr += (128/8); - R1 = _mm_load_si128((__m128i *) sptr); sptr += (128/8); + R0 = _mm_load_si128((__m128i*) sptr); + sptr += (128 / 8); + R1 = _mm_load_si128((__m128i*) sptr); + sptr += (128 / 8); } else { /* Off-stride, slower LDDQU load. */ - R0 = _mm_lddqu_si128((__m128i *) sptr); sptr += (128/8); - R1 = _mm_lddqu_si128((__m128i *) sptr); sptr += (128/8); + R0 = _mm_lddqu_si128((__m128i*) sptr); + sptr += (128 / 8); + R1 = _mm_lddqu_si128((__m128i*) sptr); + sptr += (128 / 8); } - /* R0 = a3y3o3g3 a2y2o2g2 a1y1o1g1 a0y0o0g0 */ - /* R1 = a7y7o7g7 a6y6o6g6 a5y5o5g5 a4y4o4g4 */ + /* R0 = a3y3o3g3 a2y2o2g2 a1y1o1g1 a0y0o0g0 */ + /* R1 = a7y7o7g7 a6y6o6g6 a5y5o5g5 a4y4o4g4 */ /* Shuffle to pack all the like types together. */ R2 = _mm_set_epi32(0x0f0b0703, 0x0e0a0602, 0x0d090501, 0x0c080400); R3 = _mm_shuffle_epi8(R0, R2); R4 = _mm_shuffle_epi8(R1, R2); - /* R3 = a3a2a1a0 y3y2y1y0 o3o2o1o0 g3g2g1g0 */ - /* R4 = a7a6a5a4 y7y6y5y4 o7o6o5o4 g7g6g5g4 */ + /* R3 = a3a2a1a0 y3y2y1y0 o3o2o1o0 g3g2g1g0 */ + /* R4 = a7a6a5a4 y7y6y5y4 o7o6o5o4 g7g6g5g4 */ R5 = _mm_unpackhi_epi32(R3, R4); R6 = _mm_unpacklo_epi32(R3, R4); - /* R5 = a7a6a5a4 a3a2a1a0 y7y6y5y4 y3y2y1y0 */ - /* R6 = o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + + /* R5 = a7a6a5a4 a3a2a1a0 y7y6y5y4 y3y2y1y0 */ + /* R6 = o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ /* Save alphas aside */ if (withAlpha) R7 = _mm_unpackhi_epi64(R5, R5); else R7 = _mm_set1_epi32(0xFFFFFFFFU); - /* R7 = a7a6a5a4 a3a2a1a0 a7a6a5a4 a3a2a1a0 */ + + /* R7 = a7a6a5a4 a3a2a1a0 a7a6a5a4 a3a2a1a0 */ /* Expand Y's from 8-bit unsigned to 16-bit signed. */ R1 = _mm_set1_epi32(0); R0 = _mm_unpacklo_epi8(R5, R1); - /* R0 = 00y700y6 00y500y4 00y300y2 00y100y0 */ + /* R0 = 00y700y6 00y500y4 00y300y2 00y100y0 */ /* Shift Co's and Cg's by (shift-1). -1 covers division by two. * Note: this must be done before sign-conversion. * Note also there is no slli_epi8, so we have to use a 16-bit @@ -136,57 +147,56 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_invert( R6 = _mm_slli_epi16(R6, dataShift); R1 = _mm_set1_epi8(mask); R6 = _mm_and_si128(R6, R1); - /* R6 = shifted o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + /* R6 = shifted o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ /* Expand Co's from 8-bit signed to 16-bit signed */ R1 = _mm_unpackhi_epi8(R6, R6); R1 = _mm_srai_epi16(R1, 8); - /* R1 = xxo7xxo6 xxo5xxo4 xxo3xxo2 xxo1xxo0 */ + /* R1 = xxo7xxo6 xxo5xxo4 xxo3xxo2 xxo1xxo0 */ /* Expand Cg's form 8-bit signed to 16-bit signed */ R2 = _mm_unpacklo_epi8(R6, R6); R2 = _mm_srai_epi16(R2, 8); - /* R2 = xxg7xxg6 xxg5xxg4 xxg3xxg2 xxg1xxg0 */ + /* R2 = xxg7xxg6 xxg5xxg4 xxg3xxg2 xxg1xxg0 */ /* Get Y - halfCg and save */ R6 = _mm_subs_epi16(R0, R2); - /* R = (Y-halfCg) + halfCo */ R3 = _mm_adds_epi16(R6, R1); - /* R3 = xxR7xxR6 xxR5xxR4 xxR3xxR2 xxR1xxR0 */ + /* R3 = xxR7xxR6 xxR5xxR4 xxR3xxR2 xxR1xxR0 */ /* G = Y + Cg(/2) */ R4 = _mm_adds_epi16(R0, R2); - /* R4 = xxG7xxG6 xxG5xxG4 xxG3xxG2 xxG1xxG0 */ + /* R4 = xxG7xxG6 xxG5xxG4 xxG3xxG2 xxG1xxG0 */ /* B = (Y-halfCg) - Co(/2) */ R5 = _mm_subs_epi16(R6, R1); - /* R5 = xxB7xxB6 xxB5xxB4 xxB3xxB2 xxB1xxB0 */ - + /* R5 = xxB7xxB6 xxB5xxB4 xxB3xxB2 xxB1xxB0 */ /* Repack R's & B's. */ R0 = _mm_packus_epi16(R3, R5); - /* R0 = R7R6R5R4 R3R2R1R0 B7B6B5B4 B3B2B1B0 */ + /* R0 = R7R6R5R4 R3R2R1R0 B7B6B5B4 B3B2B1B0 */ /* Repack G's. */ R1 = _mm_packus_epi16(R4, R4); - /* R1 = G7G6G6G4 G3G2G1G0 G7G6G6G4 G3G2G1G0 */ + /* R1 = G7G6G6G4 G3G2G1G0 G7G6G6G4 G3G2G1G0 */ /* And add the A's. */ R1 = _mm_unpackhi_epi64(R1, R7); - /* R1 = A7A6A6A4 A3A2A1A0 G7G6G6G4 G3G2G1G0 */ - + /* R1 = A7A6A6A4 A3A2A1A0 G7G6G6G4 G3G2G1G0 */ /* Now do interleaving again. */ R2 = _mm_unpacklo_epi8(R0, R1); - /* R2 = G7B7G6B6 G5B5G4B4 G3B3G2B2 G1B1G0B0 */ + /* R2 = G7B7G6B6 G5B5G4B4 G3B3G2B2 G1B1G0B0 */ R3 = _mm_unpackhi_epi8(R0, R1); - /* R3 = A7R7A6R6 A5R5A4R4 A3R3A2R2 A1R1A0R0 */ + /* R3 = A7R7A6R6 A5R5A4R4 A3R3A2R2 A1R1A0R0 */ R4 = _mm_unpacklo_epi16(R2, R3); - /* R4 = A3R3G3B3 A2R2G2B2 A1R1G1B1 A0R0G0B0 */ + /* R4 = A3R3G3B3 A2R2G2B2 A1R1G1B1 A0R0G0B0 */ R5 = _mm_unpackhi_epi16(R2, R3); - /* R5 = A7R7G7B7 A6R6G6B6 A5R6G5B5 A4R4G4B4 */ - - _mm_store_si128((__m128i *) dptr, R4); dptr += (128/8); - _mm_store_si128((__m128i *) dptr, R5); dptr += (128/8); + /* R5 = A7R7G7B7 A6R6G6B6 A5R6G5B5 A4R4G4B4 */ + _mm_store_si128((__m128i*) dptr, R4); + dptr += (128 / 8); + _mm_store_si128((__m128i*) dptr, R5); + dptr += (128 / 8); w -= 8; } /* Handle any remainder pixels. */ - if (w > 0) { - general_YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, - w, 1, shift, withAlpha, TRUE); + if (w > 0) + { + generic->YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, + w, 1, shift, withAlpha, TRUE); sptr += w * sizeof(UINT32); dptr += w * sizeof(UINT32); } @@ -194,27 +204,28 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_invert( sptr += sRowBump; dptr += dRowBump; } + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_no_invert( - const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, - UINT32 width, UINT32 height, - UINT8 shift, - BOOL withAlpha) + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, INT32 dstStep, + UINT32 width, UINT32 height, + UINT8 shift, + BOOL withAlpha) { - const BYTE *sptr = pSrc; - BYTE *dptr = (BYTE *) pDst; - int sRowBump = srcStep - width*sizeof(UINT32); - int dRowBump = dstStep - width*sizeof(UINT32); + const BYTE* sptr = pSrc; + BYTE* dptr = (BYTE*) pDst; + int sRowBump = srcStep - width * sizeof(UINT32); + int dRowBump = dstStep - width * sizeof(UINT32); int h; /* Shift left by "shift" and divide by two is the same as shift * left by "shift-1". */ int dataShift = shift - 1; - BYTE mask = (BYTE) (0xFFU << dataShift); + BYTE mask = (BYTE)(0xFFU << dataShift); /* Let's say the data is of the form: * y0y0o0g0 a1y1o1g1 a2y2o2g2... @@ -228,11 +239,13 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_no_invert( if ((width < 8) || (ULONG_PTR) dptr & 0x03) { /* Too small, or we'll never hit a 16-byte boundary. Punt. */ - return general_YCoCgToRGB_8u_AC4R(pSrc, srcStep, - pDst, dstStep, width, height, shift, withAlpha, FALSE); + return generic->YCoCgToRGB_8u_AC4R( + pSrc, srcStep, + pDst, dstStep, width, height, shift, + withAlpha, FALSE); } - for (h=0; h width) startup = width; - general_YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, - startup, 1, shift, withAlpha, FALSE); + + generic->YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, + startup, 1, shift, withAlpha, FALSE); sptr += startup * sizeof(UINT32); dptr += startup * sizeof(UINT32); w -= startup; @@ -251,42 +266,50 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_no_invert( /* Each loop handles eight pixels at a time. */ onStride = (((ULONG_PTR) sptr & 0x0f) == 0) ? TRUE : FALSE; + while (w >= 8) { __m128i R0, R1, R2, R3, R4, R5, R6, R7; + if (onStride) { /* The faster path, 16-byte aligned load. */ - R0 = _mm_load_si128((__m128i *) sptr); sptr += (128/8); - R1 = _mm_load_si128((__m128i *) sptr); sptr += (128/8); + R0 = _mm_load_si128((__m128i*) sptr); + sptr += (128 / 8); + R1 = _mm_load_si128((__m128i*) sptr); + sptr += (128 / 8); } else { /* Off-stride, slower LDDQU load. */ - R0 = _mm_lddqu_si128((__m128i *) sptr); sptr += (128/8); - R1 = _mm_lddqu_si128((__m128i *) sptr); sptr += (128/8); + R0 = _mm_lddqu_si128((__m128i*) sptr); + sptr += (128 / 8); + R1 = _mm_lddqu_si128((__m128i*) sptr); + sptr += (128 / 8); } - /* R0 = a3y3o3g3 a2y2o2g2 a1y1o1g1 a0y0o0g0 */ - /* R1 = a7y7o7g7 a6y6o6g6 a5y5o5g5 a4y4o4g4 */ + /* R0 = a3y3o3g3 a2y2o2g2 a1y1o1g1 a0y0o0g0 */ + /* R1 = a7y7o7g7 a6y6o6g6 a5y5o5g5 a4y4o4g4 */ /* Shuffle to pack all the like types together. */ R2 = _mm_set_epi32(0x0f0b0703, 0x0e0a0602, 0x0d090501, 0x0c080400); R3 = _mm_shuffle_epi8(R0, R2); R4 = _mm_shuffle_epi8(R1, R2); - /* R3 = a3a2a1a0 y3y2y1y0 o3o2o1o0 g3g2g1g0 */ - /* R4 = a7a6a5a4 y7y6y5y4 o7o6o5o4 g7g6g5g4 */ + /* R3 = a3a2a1a0 y3y2y1y0 o3o2o1o0 g3g2g1g0 */ + /* R4 = a7a6a5a4 y7y6y5y4 o7o6o5o4 g7g6g5g4 */ R5 = _mm_unpackhi_epi32(R3, R4); R6 = _mm_unpacklo_epi32(R3, R4); - /* R5 = a7a6a5a4 a3a2a1a0 y7y6y5y4 y3y2y1y0 */ - /* R6 = o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + + /* R5 = a7a6a5a4 a3a2a1a0 y7y6y5y4 y3y2y1y0 */ + /* R6 = o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ /* Save alphas aside */ if (withAlpha) R7 = _mm_unpackhi_epi64(R5, R5); else R7 = _mm_set1_epi32(0xFFFFFFFFU); - /* R7 = a7a6a5a4 a3a2a1a0 a7a6a5a4 a3a2a1a0 */ + + /* R7 = a7a6a5a4 a3a2a1a0 a7a6a5a4 a3a2a1a0 */ /* Expand Y's from 8-bit unsigned to 16-bit signed. */ R1 = _mm_set1_epi32(0); R0 = _mm_unpacklo_epi8(R5, R1); - /* R0 = 00y700y6 00y500y4 00y300y2 00y100y0 */ + /* R0 = 00y700y6 00y500y4 00y300y2 00y100y0 */ /* Shift Co's and Cg's by (shift-1). -1 covers division by two. * Note: this must be done before sign-conversion. * Note also there is no slli_epi8, so we have to use a 16-bit @@ -295,61 +318,60 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_no_invert( R6 = _mm_slli_epi16(R6, dataShift); R1 = _mm_set1_epi8(mask); R6 = _mm_and_si128(R6, R1); - /* R6 = shifted o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + /* R6 = shifted o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ /* Expand Co's from 8-bit signed to 16-bit signed */ R1 = _mm_unpackhi_epi8(R6, R6); R1 = _mm_srai_epi16(R1, 8); - /* R1 = xxo7xxo6 xxo5xxo4 xxo3xxo2 xxo1xxo0 */ + /* R1 = xxo7xxo6 xxo5xxo4 xxo3xxo2 xxo1xxo0 */ /* Expand Cg's form 8-bit signed to 16-bit signed */ R2 = _mm_unpacklo_epi8(R6, R6); R2 = _mm_srai_epi16(R2, 8); - /* R2 = xxg7xxg6 xxg5xxg4 xxg3xxg2 xxg1xxg0 */ + /* R2 = xxg7xxg6 xxg5xxg4 xxg3xxg2 xxg1xxg0 */ /* Get Y - halfCg and save */ R6 = _mm_subs_epi16(R0, R2); - /* R = (Y-halfCg) + halfCo */ R3 = _mm_adds_epi16(R6, R1); - /* R3 = xxR7xxR6 xxR5xxR4 xxR3xxR2 xxR1xxR0 */ + /* R3 = xxR7xxR6 xxR5xxR4 xxR3xxR2 xxR1xxR0 */ /* G = Y + Cg(/2) */ R4 = _mm_adds_epi16(R0, R2); - /* R4 = xxG7xxG6 xxG5xxG4 xxG3xxG2 xxG1xxG0 */ + /* R4 = xxG7xxG6 xxG5xxG4 xxG3xxG2 xxG1xxG0 */ /* B = (Y-halfCg) - Co(/2) */ R5 = _mm_subs_epi16(R6, R1); - /* R5 = xxB7xxB6 xxB5xxB4 xxB3xxB2 xxB1xxB0 */ - + /* R5 = xxB7xxB6 xxB5xxB4 xxB3xxB2 xxB1xxB0 */ /* Repack R's & B's. */ /* This line is the only diff between inverted and non-inverted. - * Unfortunately, it would be expensive to check "inverted" + * Unfortunately, it would be expensive to check "inverted" * every time through this loop. */ R0 = _mm_packus_epi16(R5, R3); - /* R0 = B7B6B5B4 B3B2B1B0 R7R6R5R4 R3R2R1R0 */ + /* R0 = B7B6B5B4 B3B2B1B0 R7R6R5R4 R3R2R1R0 */ /* Repack G's. */ R1 = _mm_packus_epi16(R4, R4); - /* R1 = G7G6G6G4 G3G2G1G0 G7G6G6G4 G3G2G1G0 */ + /* R1 = G7G6G6G4 G3G2G1G0 G7G6G6G4 G3G2G1G0 */ /* And add the A's. */ R1 = _mm_unpackhi_epi64(R1, R7); - /* R1 = A7A6A6A4 A3A2A1A0 G7G6G6G4 G3G2G1G0 */ - + /* R1 = A7A6A6A4 A3A2A1A0 G7G6G6G4 G3G2G1G0 */ /* Now do interleaving again. */ R2 = _mm_unpacklo_epi8(R0, R1); - /* R2 = G7B7G6B6 G5B5G4B4 G3B3G2B2 G1B1G0B0 */ + /* R2 = G7B7G6B6 G5B5G4B4 G3B3G2B2 G1B1G0B0 */ R3 = _mm_unpackhi_epi8(R0, R1); - /* R3 = A7R7A6R6 A5R5A4R4 A3R3A2R2 A1R1A0R0 */ + /* R3 = A7R7A6R6 A5R5A4R4 A3R3A2R2 A1R1A0R0 */ R4 = _mm_unpacklo_epi16(R2, R3); - /* R4 = A3R3G3B3 A2R2G2B2 A1R1G1B1 A0R0G0B0 */ + /* R4 = A3R3G3B3 A2R2G2B2 A1R1G1B1 A0R0G0B0 */ R5 = _mm_unpackhi_epi16(R2, R3); - /* R5 = A7R7G7B7 A6R6G6B6 A5R6G5B5 A4R4G4B4 */ - - _mm_store_si128((__m128i *) dptr, R4); dptr += (128/8); - _mm_store_si128((__m128i *) dptr, R5); dptr += (128/8); + /* R5 = A7R7G7B7 A6R6G6B6 A5R6G5B5 A4R4G4B4 */ + _mm_store_si128((__m128i*) dptr, R4); + dptr += (128 / 8); + _mm_store_si128((__m128i*) dptr, R5); + dptr += (128 / 8); w -= 8; } /* Handle any remainder pixels. */ - if (w > 0) { - general_YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, - w, 1, shift, withAlpha, FALSE); + if (w > 0) + { + generic->YCoCgToRGB_8u_AC4R(sptr, srcStep, dptr, dstStep, + w, 1, shift, withAlpha, FALSE); sptr += w * sizeof(UINT32); dptr += w * sizeof(UINT32); } @@ -357,27 +379,30 @@ static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_no_invert( sptr += sRowBump; dptr += dRowBump; } + return PRIMITIVES_SUCCESS; } #endif /* WITH_SSE2 */ #ifdef WITH_SSE2 /* ------------------------------------------------------------------------- */ -pstatus_t ssse3_YCoCgRToRGB_8u_AC4R( - const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, - UINT32 width, UINT32 height, - UINT8 shift, - BOOL withAlpha, - BOOL invert) +static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R( + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, INT32 dstStep, + UINT32 width, UINT32 height, + UINT8 shift, + BOOL withAlpha, + BOOL invert) { - if (invert) { + if (invert) + { return ssse3_YCoCgRToRGB_8u_AC4R_invert(pSrc, srcStep, pDst, dstStep, - width, height, shift, withAlpha); + width, height, shift, withAlpha); } - else { + else + { return ssse3_YCoCgRToRGB_8u_AC4R_no_invert(pSrc, srcStep, pDst, dstStep, - width, height, shift, withAlpha); + width, height, shift, withAlpha); } } #endif /* WITH_SSE2 */ @@ -385,15 +410,19 @@ pstatus_t ssse3_YCoCgRToRGB_8u_AC4R( /* ------------------------------------------------------------------------- */ void primitives_init_YCoCg_opt(primitives_t* prims) { -/* While IPP acknowledges the existence of YCoCg-R, it doesn't currently - * include any routines to work with it, especially with variable shift - * width. - */ + generic = primitives_get_generic(); + primitives_init_YCoCg(prims); + /* While IPP acknowledges the existence of YCoCg-R, it doesn't currently + * include any routines to work with it, especially with variable shift + * width. + */ #if defined(WITH_SSE2) + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3) - && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) { prims->YCoCgToRGB_8u_AC4R = ssse3_YCoCgRToRGB_8u_AC4R; } + #endif /* WITH_SSE2 */ } diff --git a/libfreerdp/primitives/prim_YUV.c b/libfreerdp/primitives/prim_YUV.c index 9e8b293ed..bb32f341c 100644 --- a/libfreerdp/primitives/prim_YUV.c +++ b/libfreerdp/primitives/prim_YUV.c @@ -24,14 +24,14 @@ #include #include -#include "prim_YUV.h" - static INLINE BYTE CLIP(INT32 X) { if (X > 255L) return 255L; + if (X < 0L) return 0L; + return X; } @@ -49,10 +49,10 @@ static INLINE BYTE CLIP(INT32 X) * @return PRIMITIVES_SUCCESS on success, an error code otherwise. */ static pstatus_t general_YUV420CombineToYUV444( - const BYTE* pMainSrc[3], const UINT32 srcMainStep[3], - const BYTE* pAuxSrc[3], const UINT32 srcAuxStep[3], - BYTE* pDst[3], const UINT32 dstStep[3], - const prim_size_t* roi) + const BYTE* pMainSrc[3], const UINT32 srcMainStep[3], + const BYTE* pAuxSrc[3], const UINT32 srcAuxStep[3], + BYTE* pDst[3], const UINT32 dstStep[3], + const prim_size_t* roi) { const UINT32 mod = 16; UINT32 uY = 0; @@ -64,31 +64,28 @@ static pstatus_t general_YUV420CombineToYUV444( const UINT32 evenY = 0; const UINT32 oddX = 1; const UINT32 evenX = 0; - /* The auxilary frame is aligned to multiples of 16x16. * We need the padded height for B4 and B5 conversion. */ const UINT32 padHeigth = roi->height + 16 - roi->height % 16; - nWidth = roi->width; nHeight = roi->height; - halfWidth = (nWidth ) / 2; + halfWidth = (nWidth) / 2; halfHeight = (nHeight) / 2; if (pMainSrc) { /* Y data is already here... */ /* B1 */ - for (y=0; y= nHeight) continue; + pX = pDst[1] + dstStep[1] * pos; } else { const UINT32 pos = (2 * vY++ + oddY); + if (pos >= nHeight) continue; + pX = pDst[2] + dstStep[2] * pos; } @@ -145,7 +145,7 @@ static pstatus_t general_YUV420CombineToYUV444( } /* B6 and B7 */ - for (y=0; y nHeight) continue; - for (x=0; xheight + 16 - roi->height % 16; - halfWidth = (roi->width + 1) / 2; halfHeight = (roi->height + 1) / 2; /* B1 */ - for (y=0; yheight; y++) + for (y = 0; y < roi->height; y++) { const BYTE* pSrcY = pSrc[0] + y * srcStep[0]; BYTE* pY = pMainDst[0] + y * dstMainStep[0]; @@ -222,7 +219,7 @@ static pstatus_t general_YUV444SplitToYUV420( } /* B2 and B3 */ - for (y=0; y= roi->height) continue; + memcpy(pY, pSrcU, roi->width); } else { const UINT32 pos = (2 * vY++ + 1); const BYTE* pSrcV = pSrc[2] + pos * srcStep[2]; + if (pos >= roi->height) continue; + memcpy(pY, pSrcV, roi->width); } } /* B6 and B7 */ - for (y=0; y> 8L; return CLIP(r8); } static INLINE BYTE YUV2G(INT32 Y, INT32 U, INT32 V) { - const INT32 g = ( 256L * C(Y) - 48L * D(U) - 120L * E(V)); + const INT32 g = (256L * C(Y) - 48L * D(U) - 120L * E(V)); const INT32 g8 = g >> 8L; return CLIP(g8); } static INLINE BYTE YUV2B(INT32 Y, INT32 U, INT32 V) { - const INT32 b = ( 256L * C(Y) + 475L * D(U) + 0L * E(V)); + const INT32 b = (256L * C(Y) + 475L * D(U) + 0L * E(V)); const INT32 b8 = b >> 8L; return CLIP(b8); } +static INLINE BYTE* writePixel(BYTE* dst, UINT32 format, BYTE Y, BYTE U, BYTE V) +{ + const BYTE r = YUV2R(Y, U, V); + const BYTE g = YUV2G(Y, U, V); + const BYTE b = YUV2B(Y, U, V); + UINT32 color = GetColor(format, r, g, b, 0); + WriteColor(dst, format, color); + return dst + GetBytesPerPixel(format); +} + static pstatus_t general_YUV444ToRGB_8u_P3AC4R( - const BYTE* pSrc[3], const UINT32 srcStep[3], - BYTE* pDst, UINT32 dstStep, const prim_size_t* roi) + const BYTE* pSrc[3], const UINT32 srcStep[3], + BYTE* pDst, UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi) { UINT32 x, y; UINT32 nWidth, nHeight; - nWidth = roi->width; nHeight = roi->height; @@ -347,11 +358,7 @@ static pstatus_t general_YUV444ToRGB_8u_P3AC4R( const BYTE Y = pY[x]; const INT32 U = pU[x]; const INT32 V = pV[x]; - - pRGB[4*x+0] = YUV2B(Y, U, V); - pRGB[4*x+1] = YUV2G(Y, U, V); - pRGB[4*x+2] = YUV2R(Y, U, V); - pRGB[4*x+3] = 0xFF; + pRGB = writePixel(pRGB, DstFormat, Y, U, V); } } @@ -363,10 +370,10 @@ static pstatus_t general_YUV444ToRGB_8u_P3AC4R( * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 * | B | ( | 256 475 0 | | V - 128 | ) */ - static pstatus_t general_YUV420ToRGB_8u_P3AC4R( - const BYTE* pSrc[3], const UINT32 srcStep[3], - BYTE* pDst, UINT32 dstStep, const prim_size_t* roi) + const BYTE* pSrc[3], const UINT32 srcStep[3], + BYTE* pDst, UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi) { UINT32 x, y; UINT32 dstPad; @@ -380,61 +387,46 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R( BYTE* pRGB = pDst; UINT32 nWidth, nHeight; UINT32 lastRow, lastCol; - pY = pSrc[0]; pU = pSrc[1]; pV = pSrc[2]; - lastCol = roi->width & 0x01; lastRow = roi->height & 0x01; - nWidth = (roi->width + 1) & ~0x0001; nHeight = (roi->height + 1) & ~0x0001; - halfWidth = nWidth / 2; halfHeight = nHeight / 2; - srcPad[0] = (srcStep[0] - nWidth); srcPad[1] = (srcStep[1] - halfWidth); srcPad[2] = (srcStep[2] - halfWidth); - dstPad = (dstStep - (nWidth * 4)); - for (y = 0; y < halfHeight; ) + for (y = 0; y < halfHeight;) { if (++y == halfHeight) lastRow <<= 1; - for (x = 0; x < halfWidth; ) + for (x = 0; x < halfWidth;) { if (++x == halfWidth) lastCol <<= 1; U = *pU++; V = *pV++; - /* 1st pixel */ Y = *pY++; - - *pRGB++ = YUV2B(Y, U, V); - *pRGB++ = YUV2G(Y, U, V); - *pRGB++ = YUV2R(Y, U, V); - *pRGB++ = 0xFF; + pRGB = writePixel(pRGB, DstFormat, Y, U, V); /* 2nd pixel */ if (!(lastCol & 0x02)) { Y = *pY++; - - *pRGB++ = YUV2B(Y, U, V); - *pRGB++ = YUV2G(Y, U, V); - *pRGB++ = YUV2R(Y, U, V); - *pRGB++ = 0xFF; + pRGB = writePixel(pRGB, DstFormat, Y, U, V); } else { pY++; - pRGB += 4; + pRGB += GetBytesPerPixel(DstFormat); lastCol >>= 1; } } @@ -447,36 +439,27 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R( if (lastRow & 0x02) break; - for (x = 0; x < halfWidth; ) + for (x = 0; x < halfWidth;) { if (++x == halfWidth) lastCol <<= 1; U = *pU++; V = *pV++; - /* 3rd pixel */ Y = *pY++; - - *pRGB++ = YUV2B(Y, U, V); - *pRGB++ = YUV2G(Y, U, V); - *pRGB++ = YUV2R(Y, U, V); - *pRGB++ = 0xFF; + pRGB = writePixel(pRGB, DstFormat, Y, U, V); /* 4th pixel */ if (!(lastCol & 0x02)) { Y = *pY++; - - *pRGB++ = YUV2B(Y, U, V); - *pRGB++ = YUV2G(Y, U, V); - *pRGB++ = YUV2R(Y, U, V); - *pRGB++ = 0xFF; + pRGB = writePixel(pRGB, DstFormat, Y, U, V); } else { pY++; - pRGB += 4; + pRGB += GetBytesPerPixel(DstFormat); lastCol >>= 1; } } @@ -497,52 +480,46 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R( */ static INLINE BYTE RGB2Y(INT32 R, INT32 G, INT32 B) { - const INT32 y = ( 54L * (R) + 183L * (G) + 18L * (B)); + const INT32 y = (54L * (R) + 183L * (G) + 18L * (B)); const INT32 y8 = (y >> 8L); - return CLIP(y8); } static INLINE BYTE RGB2U(INT32 R, INT32 G, INT32 B) { - const INT32 u = ( -29L * (R) - 99L * (G) + 128L * (B)); + const INT32 u = (-29L * (R) - 99L * (G) + 128L * (B)); const INT32 u8 = (u >> 8L) + 128L; - return CLIP(u8); } static INLINE BYTE RGB2V(INT32 R, INT32 G, INT32 B) { - const INT32 v = ( 128L * (R) - 116L * (G) - 12L * (B)); + const INT32 v = (128L * (R) - 116L * (G) - 12L * (B)); const INT32 v8 = (v >> 8L) + 128L; - return CLIP(v8); } static pstatus_t general_RGBToYUV444_8u_P3AC4R( - const BYTE* pSrc, const UINT32 srcStep, - BYTE* pDst[3], UINT32 dstStep[3], const prim_size_t* roi) + const BYTE* pSrc, const UINT32 srcStep, + BYTE* pDst[3], UINT32 dstStep[3], const prim_size_t* roi) { UINT32 x, y; UINT32 nWidth, nHeight; - nWidth = roi->width; nHeight = roi->height; - for (y=0; ywidth + roi->width % 2; nHeight = roi->height + roi->height % 2; - halfWidth = (nWidth + nWidth % 2) / 2; halfHeight = (nHeight + nHeight % 2) / 2; @@ -573,7 +548,6 @@ static pstatus_t general_RGBToYUV420_8u_P3AC4R( const UINT32 val2y1 = val2y + 1; const BYTE* pRGB = pSrc + val2y * srcStep; const BYTE* pRGB1 = pSrc + val2y1 * srcStep; - BYTE* pY = pDst[0] + val2y * dstStep[0]; BYTE* pY1 = pDst[0] + val2y1 * dstStep[0]; BYTE* pU = pDst[1] + y * dstStep[1]; @@ -585,7 +559,6 @@ static pstatus_t general_RGBToYUV420_8u_P3AC4R( INT32 Ra, Ga, Ba; const UINT32 val2x = (x * 2); const UINT32 val2x1 = val2x + 1; - /* 1st pixel */ Ba = B = pRGB[val2x * 4 + 0]; Ga = G = pRGB[val2x * 4 + 1]; @@ -622,7 +595,6 @@ static pstatus_t general_RGBToYUV420_8u_P3AC4R( Ba >>= 2; Ga >>= 2; Ra >>= 2; - pU[x] = RGB2U(Ra, Ga, Ba); pV[x] = RGB2V(Ra, Ga, Ba); } @@ -639,11 +611,5 @@ void primitives_init_YUV(primitives_t* prims) prims->RGBToYUV444_8u_P3AC4R = general_RGBToYUV444_8u_P3AC4R; prims->YUV420CombineToYUV444 = general_YUV420CombineToYUV444; prims->YUV444SplitToYUV420 = general_YUV444SplitToYUV420; - - primitives_init_YUV_opt(prims); } -void primitives_deinit_YUV(primitives_t* prims) -{ - -} diff --git a/libfreerdp/primitives/prim_YUV.h b/libfreerdp/primitives/prim_YUV.h deleted file mode 100644 index 99428ada6..000000000 --- a/libfreerdp/primitives/prim_YUV.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * - * Copyright 2014 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_PRIMITIVES_YUV_H -#define FREERDP_PRIMITIVES_YUV_H - -pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, BYTE* pDst, int dstStep, const prim_size_t* roi); - -void primitives_init_YUV(primitives_t* prims); -void primitives_init_YUV_opt(primitives_t* prims); -void primitives_deinit_YUV(primitives_t* prims); - -#endif /* FREERDP_PRIMITIVES_YUV_H */ diff --git a/libfreerdp/primitives/prim_YUV_opt.c b/libfreerdp/primitives/prim_YUV_opt.c index 45688df55..36c31d69b 100644 --- a/libfreerdp/primitives/prim_YUV_opt.c +++ b/libfreerdp/primitives/prim_YUV_opt.c @@ -16,30 +16,31 @@ #include #include +#include "prim_internal.h" + +static primitives_t* generic = NULL; #ifdef WITH_SSE2 #include #include -pstatus_t ssse3_YUV420ToRGB_8u_P3AC4R(const BYTE **pSrc, const UINT32 *srcStep, - BYTE *pDst, UINT32 dstStep, const prim_size_t *roi) +static pstatus_t ssse3_YUV420ToRGB_8u_P3AC4R( + const BYTE** pSrc, const UINT32* srcStep, + BYTE* pDst, UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi) { UINT32 lastRow, lastCol; - BYTE *UData,*VData,*YData; - UINT32 i,nWidth,nHeight,VaddDst,VaddY,VaddU,VaddV; - __m128i r0,r1,r2,r3,r4,r5,r6,r7; - __m128i *buffer; - + BYTE* UData, *VData, *YData; + UINT32 i, nWidth, nHeight, VaddDst, VaddY, VaddU, VaddV; + __m128i r0, r1, r2, r3, r4, r5, r6, r7; + __m128i* buffer; /* last_line: if the last (U,V doubled) line should be skipped, set to 10B * last_column: if it's the last column in a line, set to 10B (for handling line-endings not multiple by four) */ - buffer = _aligned_malloc(4 * 16, 16); - YData = (BYTE*) pSrc[0]; UData = (BYTE*) pSrc[1]; VData = (BYTE*) pSrc[2]; - nWidth = roi->width; nHeight = roi->height; @@ -48,29 +49,27 @@ pstatus_t ssse3_YUV420ToRGB_8u_P3AC4R(const BYTE **pSrc, const UINT32 *srcStep, switch (lastCol) { case 1: - r7 = _mm_set_epi32(0,0,0,0xFFFFFFFF); + r7 = _mm_set_epi32(0, 0, 0, 0xFFFFFFFF); break; case 2: - r7 = _mm_set_epi32(0,0,0xFFFFFFFF,0xFFFFFFFF); + r7 = _mm_set_epi32(0, 0, 0xFFFFFFFF, 0xFFFFFFFF); break; case 3: - r7 = _mm_set_epi32(0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); + r7 = _mm_set_epi32(0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); break; } - _mm_store_si128(buffer+3,r7); + _mm_store_si128(buffer + 3, r7); lastCol = 1; } nWidth += 3; nWidth = nWidth >> 2; - lastRow = nHeight & 1; nHeight++; nHeight = nHeight >> 1; - VaddDst = (dstStep << 1) - (nWidth << 4); VaddY = (srcStep[0] << 1) - (nWidth << 2); VaddU = srcStep[1] - (((nWidth << 1) + 2) & 0xFFFC); @@ -87,284 +86,254 @@ pstatus_t ssse3_YUV420ToRGB_8u_P3AC4R(const BYTE **pSrc, const UINT32 *srcStep, { if (!(i & 0x01)) { - /* Y-, U- and V-data is stored in different arrays. - * We start with processing U-data. - * - * at first we fetch four U-values from its array and shuffle them like this: - * 0d0d 0c0c 0b0b 0a0a - * we've done two things: converting the values to signed words and duplicating - * each value, because always two pixel "share" the same U- (and V-) data */ - r0 = _mm_cvtsi32_si128(*(UINT32 *)UData); - r5 = _mm_set_epi32(0x80038003,0x80028002,0x80018001,0x80008000); - r0 = _mm_shuffle_epi8(r0,r5); - + /* Y-, U- and V-data is stored in different arrays. + * We start with processing U-data. + * + * at first we fetch four U-values from its array and shuffle them like this: + * 0d0d 0c0c 0b0b 0a0a + * we've done two things: converting the values to signed words and duplicating + * each value, because always two pixel "share" the same U- (and V-) data */ + r0 = _mm_cvtsi32_si128(*(UINT32*)UData); + r5 = _mm_set_epi32(0x80038003, 0x80028002, 0x80018001, 0x80008000); + r0 = _mm_shuffle_epi8(r0, r5); UData += 4; - - /* then we subtract 128 from each value, so we get D */ - r3 = _mm_set_epi16(128,128,128,128,128,128,128,128); - r0 = _mm_subs_epi16(r0,r3); - - /* we need to do two things with our D, so let's store it for later use */ + /* then we subtract 128 from each value, so we get D */ + r3 = _mm_set_epi16(128, 128, 128, 128, 128, 128, 128, 128); + r0 = _mm_subs_epi16(r0, r3); + /* we need to do two things with our D, so let's store it for later use */ r2 = r0; - - /* now we can multiply our D with 48 and unpack it to xmm4:xmm0 - * this is what we need to get G data later on */ + /* now we can multiply our D with 48 and unpack it to xmm4:xmm0 + * this is what we need to get G data later on */ r4 = r0; - r7 = _mm_set_epi16(48,48,48,48,48,48,48,48); - r0 = _mm_mullo_epi16(r0,r7); - r4 = _mm_mulhi_epi16(r4,r7); + r7 = _mm_set_epi16(48, 48, 48, 48, 48, 48, 48, 48); + r0 = _mm_mullo_epi16(r0, r7); + r4 = _mm_mulhi_epi16(r4, r7); r7 = r0; - r0 = _mm_unpacklo_epi16(r0,r4); - r4 = _mm_unpackhi_epi16(r7,r4); - - /* to get B data, we need to prepare a second value, D*475 */ + r0 = _mm_unpacklo_epi16(r0, r4); + r4 = _mm_unpackhi_epi16(r7, r4); + /* to get B data, we need to prepare a second value, D*475 */ r1 = r2; - r7 = _mm_set_epi16(475,475,475,475,475,475,475,475); - r1 = _mm_mullo_epi16(r1,r7); - r2 = _mm_mulhi_epi16(r2,r7); + r7 = _mm_set_epi16(475, 475, 475, 475, 475, 475, 475, 475); + r1 = _mm_mullo_epi16(r1, r7); + r2 = _mm_mulhi_epi16(r2, r7); r7 = r1; - r1 = _mm_unpacklo_epi16(r1,r2); - r7 = _mm_unpackhi_epi16(r7,r2); - - /* so we got something like this: xmm7:xmm1 - * this pair contains values for 16 pixel: - * aabbccdd - * aabbccdd, but we can only work on four pixel at once, so we need to save upper values */ - _mm_store_si128(buffer+1,r7); - - /* Now we've prepared U-data. Preparing V-data is actually the same, just with other coefficients */ - r2 = _mm_cvtsi32_si128(*(UINT32 *)VData); - r2 = _mm_shuffle_epi8(r2,r5); - + r1 = _mm_unpacklo_epi16(r1, r2); + r7 = _mm_unpackhi_epi16(r7, r2); + /* so we got something like this: xmm7:xmm1 + * this pair contains values for 16 pixel: + * aabbccdd + * aabbccdd, but we can only work on four pixel at once, so we need to save upper values */ + _mm_store_si128(buffer + 1, r7); + /* Now we've prepared U-data. Preparing V-data is actually the same, just with other coefficients */ + r2 = _mm_cvtsi32_si128(*(UINT32*)VData); + r2 = _mm_shuffle_epi8(r2, r5); VData += 4; - - r2 = _mm_subs_epi16(r2,r3); - + r2 = _mm_subs_epi16(r2, r3); r5 = r2; - - /* this is also known as E*403, we need it to convert R data */ + /* this is also known as E*403, we need it to convert R data */ r3 = r2; - r7 = _mm_set_epi16(403,403,403,403,403,403,403,403); - r2 = _mm_mullo_epi16(r2,r7); - r3 = _mm_mulhi_epi16(r3,r7); + r7 = _mm_set_epi16(403, 403, 403, 403, 403, 403, 403, 403); + r2 = _mm_mullo_epi16(r2, r7); + r3 = _mm_mulhi_epi16(r3, r7); r7 = r2; - r2 = _mm_unpacklo_epi16(r2,r3); - r7 = _mm_unpackhi_epi16(r7,r3); - - /* and preserve upper four values for future ... */ - _mm_store_si128(buffer+2,r7); - - /* doing this step: E*120 */ + r2 = _mm_unpacklo_epi16(r2, r3); + r7 = _mm_unpackhi_epi16(r7, r3); + /* and preserve upper four values for future ... */ + _mm_store_si128(buffer + 2, r7); + /* doing this step: E*120 */ r3 = r5; - r7 = _mm_set_epi16(120,120,120,120,120,120,120,120); - r3 = _mm_mullo_epi16(r3,r7); - r5 = _mm_mulhi_epi16(r5,r7); + r7 = _mm_set_epi16(120, 120, 120, 120, 120, 120, 120, 120); + r3 = _mm_mullo_epi16(r3, r7); + r5 = _mm_mulhi_epi16(r5, r7); r7 = r3; - r3 = _mm_unpacklo_epi16(r3,r5); - r7 = _mm_unpackhi_epi16(r7,r5); - - /* now we complete what we've begun above: - * (48*D) + (120*E) = (48*D +120*E) */ - r0 = _mm_add_epi32(r0,r3); - r4 = _mm_add_epi32(r4,r7); - - /* and store to memory ! */ - _mm_store_si128(buffer,r4); + r3 = _mm_unpacklo_epi16(r3, r5); + r7 = _mm_unpackhi_epi16(r7, r5); + /* now we complete what we've begun above: + * (48*D) + (120*E) = (48*D +120*E) */ + r0 = _mm_add_epi32(r0, r3); + r4 = _mm_add_epi32(r4, r7); + /* and store to memory ! */ + _mm_store_si128(buffer, r4); } else { - /* maybe you've wondered about the conditional above ? - * Well, we prepared UV data for eight pixel in each line, but can only process four - * per loop. So we need to load the upper four pixel data from memory each secound loop! */ - r1 = _mm_load_si128(buffer+1); - r2 = _mm_load_si128(buffer+2); + /* maybe you've wondered about the conditional above ? + * Well, we prepared UV data for eight pixel in each line, but can only process four + * per loop. So we need to load the upper four pixel data from memory each secound loop! */ + r1 = _mm_load_si128(buffer + 1); + r2 = _mm_load_si128(buffer + 2); r0 = _mm_load_si128(buffer); } if (++i == nWidth) lastCol <<= 1; - /* We didn't produce any output yet, so let's do so! - * Ok, fetch four pixel from the Y-data array and shuffle them like this: - * 00d0 00c0 00b0 00a0, to get signed dwords and multiply by 256 */ - r4 = _mm_cvtsi32_si128(*(UINT32 *)YData); - r7 = _mm_set_epi32(0x80800380,0x80800280,0x80800180,0x80800080); - r4 = _mm_shuffle_epi8(r4,r7); - + /* We didn't produce any output yet, so let's do so! + * Ok, fetch four pixel from the Y-data array and shuffle them like this: + * 00d0 00c0 00b0 00a0, to get signed dwords and multiply by 256 */ + r4 = _mm_cvtsi32_si128(*(UINT32*)YData); + r7 = _mm_set_epi32(0x80800380, 0x80800280, 0x80800180, 0x80800080); + r4 = _mm_shuffle_epi8(r4, r7); r5 = r4; r6 = r4; - - /* no we can perform the "real" conversion itself and produce output! */ - r4 = _mm_add_epi32(r4,r2); - r5 = _mm_sub_epi32(r5,r0); - r6 = _mm_add_epi32(r6,r1); - - /* in the end, we only need bytes for RGB values. - * So, what do we do? right! shifting left makes values bigger and thats always good. - * before we had dwords of data, and by shifting left and treating the result - * as packed words, we get not only signed words, but do also divide by 256 - * imagine, data is now ordered this way: ddx0 ccx0 bbx0 aax0, and x is the least - * significant byte, that we don't need anymore, because we've done some rounding */ - r4 = _mm_slli_epi32(r4,8); - r5 = _mm_slli_epi32(r5,8); - r6 = _mm_slli_epi32(r6,8); - - /* one thing we still have to face is the clip() function ... - * we have still signed words, and there are those min/max instructions in SSE2 ... - * the max instruction takes always the bigger of the two operands and stores it in the first one, - * and it operates with signs ! - * if we feed it with our values and zeros, it takes the zeros if our values are smaller than - * zero and otherwise our values */ - r7 = _mm_set_epi32(0,0,0,0); - r4 = _mm_max_epi16(r4,r7); - r5 = _mm_max_epi16(r5,r7); - r6 = _mm_max_epi16(r6,r7); - - /* the same thing just completely different can be used to limit our values to 255, - * but now using the min instruction and 255s */ - r7 = _mm_set_epi32(0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000); - r4 = _mm_min_epi16(r4,r7); - r5 = _mm_min_epi16(r5,r7); - r6 = _mm_min_epi16(r6,r7); - - /* Now we got our bytes. - * the moment has come to assemble the three channels R,G and B to the xrgb dwords - * on Red channel we just have to and each futural dword with 00FF0000H */ + /* no we can perform the "real" conversion itself and produce output! */ + r4 = _mm_add_epi32(r4, r2); + r5 = _mm_sub_epi32(r5, r0); + r6 = _mm_add_epi32(r6, r1); + /* in the end, we only need bytes for RGB values. + * So, what do we do? right! shifting left makes values bigger and thats always good. + * before we had dwords of data, and by shifting left and treating the result + * as packed words, we get not only signed words, but do also divide by 256 + * imagine, data is now ordered this way: ddx0 ccx0 bbx0 aax0, and x is the least + * significant byte, that we don't need anymore, because we've done some rounding */ + r4 = _mm_slli_epi32(r4, 8); + r5 = _mm_slli_epi32(r5, 8); + r6 = _mm_slli_epi32(r6, 8); + /* one thing we still have to face is the clip() function ... + * we have still signed words, and there are those min/max instructions in SSE2 ... + * the max instruction takes always the bigger of the two operands and stores it in the first one, + * and it operates with signs ! + * if we feed it with our values and zeros, it takes the zeros if our values are smaller than + * zero and otherwise our values */ + r7 = _mm_set_epi32(0, 0, 0, 0); + r4 = _mm_max_epi16(r4, r7); + r5 = _mm_max_epi16(r5, r7); + r6 = _mm_max_epi16(r6, r7); + /* the same thing just completely different can be used to limit our values to 255, + * but now using the min instruction and 255s */ + r7 = _mm_set_epi32(0x00FF0000, 0x00FF0000, 0x00FF0000, 0x00FF0000); + r4 = _mm_min_epi16(r4, r7); + r5 = _mm_min_epi16(r5, r7); + r6 = _mm_min_epi16(r6, r7); + /* Now we got our bytes. + * the moment has come to assemble the three channels R,G and B to the xrgb dwords + * on Red channel we just have to and each futural dword with 00FF0000H */ //r7=_mm_set_epi32(0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000); - r4 = _mm_and_si128(r4,r7); + r4 = _mm_and_si128(r4, r7); + /* on Green channel we have to shuffle somehow, so we get something like this: + * 00d0 00c0 00b0 00a0 */ + r7 = _mm_set_epi32(0x80800E80, 0x80800A80, 0x80800680, 0x80800280); + r5 = _mm_shuffle_epi8(r5, r7); + /* and on Blue channel that one: + * 000d 000c 000b 000a */ + r7 = _mm_set_epi32(0x8080800E, 0x8080800A, 0x80808006, 0x80808002); + r6 = _mm_shuffle_epi8(r6, r7); + /* and at last we or it together and get this one: + * xrgb xrgb xrgb xrgb */ + r4 = _mm_or_si128(r4, r5); + r4 = _mm_or_si128(r4, r6); - /* on Green channel we have to shuffle somehow, so we get something like this: - * 00d0 00c0 00b0 00a0 */ - r7 = _mm_set_epi32(0x80800E80,0x80800A80,0x80800680,0x80800280); - r5 = _mm_shuffle_epi8(r5,r7); - - /* and on Blue channel that one: - * 000d 000c 000b 000a */ - r7 = _mm_set_epi32(0x8080800E,0x8080800A,0x80808006,0x80808002); - r6 = _mm_shuffle_epi8(r6,r7); - - /* and at last we or it together and get this one: - * xrgb xrgb xrgb xrgb */ - r4 = _mm_or_si128(r4,r5); - r4 = _mm_or_si128(r4,r6); - - /* Only thing to do know is writing data to memory, but this gets a bit more - * complicated if the width is not a multiple of four and it is the last column in line. */ + /* Only thing to do know is writing data to memory, but this gets a bit more + * complicated if the width is not a multiple of four and it is the last column in line. */ if (lastCol & 0x02) { - /* let's say, we need to only convert six pixel in width - * Ok, the first 4 pixel will be converted just like every 4 pixel else, but - * if it's the last loop in line, last_column is shifted left by one (curious? have a look above), - * and we land here. Through initialisation a mask was prepared. In this case it looks like - * 0000FFFFH 0000FFFFH 0000FFFFH 0000FFFFH */ - r6 = _mm_load_si128(buffer+3); - /* we and our output data with this mask to get only the valid pixel */ - r4 = _mm_and_si128(r4,r6); - /* then we fetch memory from the destination array ... */ - r5 = _mm_lddqu_si128((__m128i *)pDst); - /* ... and and it with the inverse mask. We get only those pixel, which should not be updated */ - r6 = _mm_andnot_si128(r6,r5); - /* we only have to or the two values together and write it back to the destination array, - * and only the pixel that should be updated really get changed. */ - r4 = _mm_or_si128(r4,r6); + /* let's say, we need to only convert six pixel in width + * Ok, the first 4 pixel will be converted just like every 4 pixel else, but + * if it's the last loop in line, last_column is shifted left by one (curious? have a look above), + * and we land here. Through initialisation a mask was prepared. In this case it looks like + * 0000FFFFH 0000FFFFH 0000FFFFH 0000FFFFH */ + r6 = _mm_load_si128(buffer + 3); + /* we and our output data with this mask to get only the valid pixel */ + r4 = _mm_and_si128(r4, r6); + /* then we fetch memory from the destination array ... */ + r5 = _mm_lddqu_si128((__m128i*)pDst); + /* ... and and it with the inverse mask. We get only those pixel, which should not be updated */ + r6 = _mm_andnot_si128(r6, r5); + /* we only have to or the two values together and write it back to the destination array, + * and only the pixel that should be updated really get changed. */ + r4 = _mm_or_si128(r4, r6); } - _mm_storeu_si128((__m128i *)pDst,r4); + + _mm_storeu_si128((__m128i*)pDst, r4); if (!(lastRow & 0x02)) { - /* Because UV data is the same for two lines, we can process the secound line just here, - * in the same loop. Only thing we need to do is to add some offsets to the Y- and destination - * pointer. These offsets are iStride[0] and the target scanline. - * But if we don't need to process the secound line, like if we are in the last line of processing nine lines, - * we just skip all this. */ - r4 = _mm_cvtsi32_si128(*(UINT32 *)(YData+srcStep[0])); - r7 = _mm_set_epi32(0x80800380,0x80800280,0x80800180,0x80800080); - r4 = _mm_shuffle_epi8(r4,r7); - + /* Because UV data is the same for two lines, we can process the secound line just here, + * in the same loop. Only thing we need to do is to add some offsets to the Y- and destination + * pointer. These offsets are iStride[0] and the target scanline. + * But if we don't need to process the secound line, like if we are in the last line of processing nine lines, + * we just skip all this. */ + r4 = _mm_cvtsi32_si128(*(UINT32*)(YData + srcStep[0])); + r7 = _mm_set_epi32(0x80800380, 0x80800280, 0x80800180, 0x80800080); + r4 = _mm_shuffle_epi8(r4, r7); r5 = r4; r6 = r4; - - r4 = _mm_add_epi32(r4,r2); - r5 = _mm_sub_epi32(r5,r0); - r6 = _mm_add_epi32(r6,r1); - - r4 = _mm_slli_epi32(r4,8); - r5 = _mm_slli_epi32(r5,8); - r6 = _mm_slli_epi32(r6,8); - - r7 = _mm_set_epi32(0,0,0,0); - r4 = _mm_max_epi16(r4,r7); - r5 = _mm_max_epi16(r5,r7); - r6 = _mm_max_epi16(r6,r7); - - r7 = _mm_set_epi32(0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000); - r4 = _mm_min_epi16(r4,r7); - r5 = _mm_min_epi16(r5,r7); - r6 = _mm_min_epi16(r6,r7); - - r7 = _mm_set_epi32(0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000); - r4 = _mm_and_si128(r4,r7); - - r7 = _mm_set_epi32(0x80800E80,0x80800A80,0x80800680,0x80800280); - r5 = _mm_shuffle_epi8(r5,r7); - - r7 = _mm_set_epi32(0x8080800E,0x8080800A,0x80808006,0x80808002); - r6 = _mm_shuffle_epi8(r6,r7); - - r4 = _mm_or_si128(r4,r5); - r4 = _mm_or_si128(r4,r6); + r4 = _mm_add_epi32(r4, r2); + r5 = _mm_sub_epi32(r5, r0); + r6 = _mm_add_epi32(r6, r1); + r4 = _mm_slli_epi32(r4, 8); + r5 = _mm_slli_epi32(r5, 8); + r6 = _mm_slli_epi32(r6, 8); + r7 = _mm_set_epi32(0, 0, 0, 0); + r4 = _mm_max_epi16(r4, r7); + r5 = _mm_max_epi16(r5, r7); + r6 = _mm_max_epi16(r6, r7); + r7 = _mm_set_epi32(0x00FF0000, 0x00FF0000, 0x00FF0000, 0x00FF0000); + r4 = _mm_min_epi16(r4, r7); + r5 = _mm_min_epi16(r5, r7); + r6 = _mm_min_epi16(r6, r7); + r7 = _mm_set_epi32(0x00FF0000, 0x00FF0000, 0x00FF0000, 0x00FF0000); + r4 = _mm_and_si128(r4, r7); + r7 = _mm_set_epi32(0x80800E80, 0x80800A80, 0x80800680, 0x80800280); + r5 = _mm_shuffle_epi8(r5, r7); + r7 = _mm_set_epi32(0x8080800E, 0x8080800A, 0x80808006, 0x80808002); + r6 = _mm_shuffle_epi8(r6, r7); + r4 = _mm_or_si128(r4, r5); + r4 = _mm_or_si128(r4, r6); if (lastCol & 0x02) { - r6 = _mm_load_si128(buffer+3); - r4 = _mm_and_si128(r4,r6); - r5 = _mm_lddqu_si128((__m128i *)(pDst+dstStep)); - r6 = _mm_andnot_si128(r6,r5); - r4 = _mm_or_si128(r4,r6); - - /* only thing is, we should shift [rbp-42] back here, because we have processed the last column, - * and this "special condition" can be released */ + r6 = _mm_load_si128(buffer + 3); + r4 = _mm_and_si128(r4, r6); + r5 = _mm_lddqu_si128((__m128i*)(pDst + dstStep)); + r6 = _mm_andnot_si128(r6, r5); + r4 = _mm_or_si128(r4, r6); + /* only thing is, we should shift [rbp-42] back here, because we have processed the last column, + * and this "special condition" can be released */ lastCol >>= 1; } - _mm_storeu_si128((__m128i *)(pDst+dstStep),r4); + + _mm_storeu_si128((__m128i*)(pDst + dstStep), r4); } - /* after all we have to increase the destination- and Y-data pointer by four pixel */ + /* after all we have to increase the destination- and Y-data pointer by four pixel */ pDst += 16; YData += 4; } while (i < nWidth); - /* after each line we have to add the scanline to the destination pointer, because - * we are processing two lines at once, but only increasing the destination pointer - * in the first line. Well, we only have one pointer, so it's the easiest way to access - * the secound line with the one pointer and an offset (scanline) - * if we're not converting the full width of the scanline, like only 64 pixel, but the - * output buffer was "designed" for 1920p HD, we have to add the remaining length for each line, - * to get into the next line. */ + /* after each line we have to add the scanline to the destination pointer, because + * we are processing two lines at once, but only increasing the destination pointer + * in the first line. Well, we only have one pointer, so it's the easiest way to access + * the secound line with the one pointer and an offset (scanline) + * if we're not converting the full width of the scanline, like only 64 pixel, but the + * output buffer was "designed" for 1920p HD, we have to add the remaining length for each line, + * to get into the next line. */ pDst += VaddDst; - - /* same thing has to be done for Y-data, but with iStride[0] instead of the target scanline */ + /* same thing has to be done for Y-data, but with iStride[0] instead of the target scanline */ YData += VaddY; - - /* and again for UV data, but here it's enough to add the remaining length, because - * UV data is the same for two lines and there exists only one "UV line" on two "real lines" */ + /* and again for UV data, but here it's enough to add the remaining length, because + * UV data is the same for two lines and there exists only one "UV line" on two "real lines" */ UData += VaddU; VData += VaddV; } _aligned_free(buffer); - return PRIMITIVES_SUCCESS; } #endif -void primitives_init_YUV_opt(primitives_t *prims) +void primitives_init_YUV_opt(primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_YUV(prims); #ifdef WITH_SSE2 - if (IsProcessorFeaturePresentEx(PF_EX_SSSE3) && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3) + && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) { prims->YUV420ToRGB_8u_P3AC4R = ssse3_YUV420ToRGB_8u_P3AC4R; } + #endif } diff --git a/libfreerdp/primitives/prim_add.c b/libfreerdp/primitives/prim_add.c index 4d5525bdc..598440281 100644 --- a/libfreerdp/primitives/prim_add.c +++ b/libfreerdp/primitives/prim_add.c @@ -11,7 +11,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing * permissions and limitations under the License. - * + * */ #ifdef HAVE_CONFIG_H @@ -22,22 +22,22 @@ #include #include "prim_internal.h" -#include "prim_add.h" /* ---------------------------------------------------------------------------- * 16-bit signed add with saturation (under and over). */ -pstatus_t general_add_16s( - const INT16 *pSrc1, - const INT16 *pSrc2, - INT16 *pDst, - INT32 len) +static pstatus_t general_add_16s( + const INT16* pSrc1, + const INT16* pSrc2, + INT16* pDst, + INT32 len) { while (len--) { - INT32 k = (INT32) (*pSrc1++) + (INT32) (*pSrc2++); + INT32 k = (INT32)(*pSrc1++) + (INT32)(*pSrc2++); + if (k > 32767) *pDst++ = ((INT16) 32767); - else if (k < -32768) *pDst++ = ((INT16) -32768); + else if (k < -32768) *pDst++ = ((INT16) - 32768); else *pDst++ = (INT16) k; } @@ -46,16 +46,7 @@ pstatus_t general_add_16s( /* ------------------------------------------------------------------------- */ void primitives_init_add( - primitives_t *prims) + primitives_t* prims) { prims->add_16s = general_add_16s; - - primitives_init_add_opt(prims); -} - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_add( - primitives_t *prims) -{ - /* Nothing to do. */ } diff --git a/libfreerdp/primitives/prim_add.h b/libfreerdp/primitives/prim_add.h deleted file mode 100644 index f1e143cd1..000000000 --- a/libfreerdp/primitives/prim_add.h +++ /dev/null @@ -1,30 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * Add operations. - * vi:ts=4 sw=4 - * - * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. Algorithms used by - * this code may be covered by patents by HP, Microsoft, or other parties. - * - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_ADD_H_INCLUDED__ -#define __PRIM_ADD_H_INCLUDED__ - -pstatus_t general_add_16s(const INT16 *pSrc1, const INT16 *pSrc2, INT16 *pDst, INT32 len); - -void primitives_init_add_opt(primitives_t *prims); - -#endif /* !__PRIM_ADD_H_INCLUDED__ */ - diff --git a/libfreerdp/primitives/prim_add_opt.c b/libfreerdp/primitives/prim_add_opt.c index 0741cdc0c..d49d63445 100644 --- a/libfreerdp/primitives/prim_add_opt.c +++ b/libfreerdp/primitives/prim_add_opt.c @@ -11,7 +11,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing * permissions and limitations under the License. - * + * */ #ifdef HAVE_CONFIG_H @@ -33,28 +33,32 @@ #include "prim_internal.h" #include "prim_templates.h" -#include "prim_add.h" +static primitives_t* generic = NULL; #ifdef WITH_SSE2 # if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) /* ------------------------------------------------------------------------- */ -SSE3_SSD_ROUTINE(sse3_add_16s, INT16, general_add_16s, - _mm_adds_epi16, general_add_16s(sptr1++, sptr2++, dptr++, 1)) +SSE3_SSD_ROUTINE(sse3_add_16s, INT16, generic->add_16s, + _mm_adds_epi16, generic->add_16s(sptr1++, sptr2++, dptr++, 1)) # endif /* !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) */ #endif /* ------------------------------------------------------------------------- */ void primitives_init_add_opt( - primitives_t *prims) + primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_add(prims); #ifdef WITH_IPP prims->add_16s = (__add_16s_t) ippsAdd_16s; #elif defined(WITH_SSE2) + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) - && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) /* for LDDQU */ + && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) /* for LDDQU */ { prims->add_16s = sse3_add_16s; } + #endif } diff --git a/libfreerdp/primitives/prim_alphaComp.c b/libfreerdp/primitives/prim_alphaComp.c index e48ce9d61..a306b9cd0 100644 --- a/libfreerdp/primitives/prim_alphaComp.c +++ b/libfreerdp/primitives/prim_alphaComp.c @@ -28,7 +28,6 @@ #include #include "prim_internal.h" -#include "prim_alphaComp.h" #define ALPHA(_k_) (((_k_) & 0xFF000000U) >> 24) #define RED(_k_) (((_k_) & 0x00FF0000U) >> 16) @@ -36,29 +35,31 @@ #define BLU(_k_) (((_k_) & 0x000000FFU)) /* ------------------------------------------------------------------------- */ -pstatus_t general_alphaComp_argb( - const BYTE *pSrc1, INT32 src1Step, - const BYTE *pSrc2, INT32 src2Step, - BYTE *pDst, INT32 dstStep, - INT32 width, INT32 height) +static pstatus_t general_alphaComp_argb( + const BYTE* pSrc1, INT32 src1Step, + const BYTE* pSrc2, INT32 src2Step, + BYTE* pDst, INT32 dstStep, + INT32 width, INT32 height) { - const UINT32 *sptr1 = (const UINT32 *) pSrc1; - const UINT32 *sptr2 = (const UINT32 *) pSrc2; - UINT32 *dptr = (UINT32 *) pDst; + const UINT32* sptr1 = (const UINT32*) pSrc1; + const UINT32* sptr2 = (const UINT32*) pSrc2; + UINT32* dptr = (UINT32*) pDst; int linebytes = width * sizeof(UINT32); int src1Jump = (src1Step - linebytes) / sizeof(UINT32); int src2Jump = (src2Step - linebytes) / sizeof(UINT32); int dstJump = (dstStep - linebytes) / sizeof(UINT32); - int y; - for (y=0; y> 8) & 0x00FF00FFU; UINT32 s1rb = src1 & 0x00FF00FFU; UINT32 s1ag = (src1 >> 8) & 0x00FF00FFU; - UINT32 drb = s1rb - s2rb; UINT32 dag = s1ag - s2ag; drb *= alpha; dag *= alpha; - - rb = ((drb >> 8) + s2rb) & 0x00FF00FFU; + rb = ((drb >> 8) + s2rb) & 0x00FF00FFU; ag = (((dag >> 8) + s2ag) << 8) & 0xFF00FF00U; *dptr++ = rb | ag; } } + sptr1 += src1Jump; sptr2 += src2Jump; dptr += dstJump; - } + } return PRIMITIVES_SUCCESS; } @@ -105,13 +105,5 @@ pstatus_t general_alphaComp_argb( void primitives_init_alphaComp(primitives_t* prims) { prims->alphaComp_argb = general_alphaComp_argb; - - primitives_init_alphaComp_opt(prims); -} - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_alphaComp(primitives_t *prims) -{ - /* Nothing to do. */ } diff --git a/libfreerdp/primitives/prim_alphaComp.h b/libfreerdp/primitives/prim_alphaComp.h deleted file mode 100644 index a16335711..000000000 --- a/libfreerdp/primitives/prim_alphaComp.h +++ /dev/null @@ -1,30 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * Alpha blending routines. - * vi:ts=4 sw=4 - * - * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. Algorithms used by - * this code may be covered by patents by HP, Microsoft, or other parties. - * - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_ALPHACOMP_H_INCLUDED__ -#define __PRIM_ALPHACOMP_H_INCLUDED__ - -pstatus_t general_alphaComp_argb(const BYTE *pSrc1, INT32 src1Step, const BYTE *pSrc2, INT32 src2Step, BYTE *pDst, INT32 dstStep, INT32 width, INT32 height); - -void primitives_init_alphaComp_opt(primitives_t* prims); - -#endif /* !__PRIM_ALPHACOMP_H_INCLUDED__ */ - diff --git a/libfreerdp/primitives/prim_alphaComp_opt.c b/libfreerdp/primitives/prim_alphaComp_opt.c index 57901bb08..d0f974476 100644 --- a/libfreerdp/primitives/prim_alphaComp_opt.c +++ b/libfreerdp/primitives/prim_alphaComp_opt.c @@ -38,22 +38,22 @@ #endif /* WITH_IPP */ #include "prim_internal.h" -#include "prim_alphaComp.h" +static primitives_t* generic = NULL; /* ------------------------------------------------------------------------- */ #ifdef WITH_SSE2 #if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) pstatus_t sse2_alphaComp_argb( - const BYTE *pSrc1, INT32 src1Step, - const BYTE *pSrc2, INT32 src2Step, - BYTE *pDst, INT32 dstStep, - INT32 width, INT32 height) + const BYTE* pSrc1, INT32 src1Step, + const BYTE* pSrc2, INT32 src2Step, + BYTE* pDst, INT32 dstStep, + INT32 width, INT32 height) { - const UINT32 *sptr1 = (const UINT32 *) pSrc1; - const UINT32 *sptr2 = (const UINT32 *) pSrc2; - UINT32 *dptr; + const UINT32* sptr1 = (const UINT32*) pSrc1; + const UINT32* sptr2 = (const UINT32*) pSrc2; + UINT32* dptr; int linebytes, src1Jump, src2Jump, dstJump, y; __m128i xmm0, xmm1; @@ -61,39 +61,43 @@ pstatus_t sse2_alphaComp_argb( if (width < 4) /* pointless if too small */ { - return general_alphaComp_argb(pSrc1, src1Step, pSrc2, src2Step, - pDst, dstStep, width, height); + return generic->alphaComp_argb(pSrc1, src1Step, pSrc2, src2Step, + pDst, dstStep, width, height); } - dptr = (UINT32 *) pDst; + + dptr = (UINT32*) pDst; linebytes = width * sizeof(UINT32); src1Jump = (src1Step - linebytes) / sizeof(UINT32); src2Jump = (src2Step - linebytes) / sizeof(UINT32); dstJump = (dstStep - linebytes) / sizeof(UINT32); - xmm0 = _mm_set1_epi32(0); xmm1 = _mm_set1_epi16(1); - for (y=0; yalphaComp_argb((const BYTE*) sptr1, + src1Step, (const BYTE*) sptr2, src2Step, + (BYTE*) dptr, dstStep, leadIn, 1); sptr1 += leadIn; sptr2 += leadIn; dptr += leadIn; @@ -115,13 +120,16 @@ pstatus_t sse2_alphaComp_argb( /* Use SSE registers to do 4 pixels at a time. */ count = pixels >> 2; pixels -= count << 2; + while (count--) { __m128i xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; /* BdGdRdAdBcGcRcAcBbGbRbAbBaGaRaAa */ - xmm2 = LOAD_SI128(sptr1); sptr1 += 4; + xmm2 = LOAD_SI128(sptr1); + sptr1 += 4; /* BhGhRhAhBgGgRgAgBfGfRfAfBeGeReAe */ - xmm3 = LOAD_SI128(sptr2); sptr2 += 4; + xmm3 = LOAD_SI128(sptr2); + sptr2 += 4; /* 00Bb00Gb00Rb00Ab00Ba00Ga00Ra00Aa */ xmm4 = _mm_unpackhi_epi8(xmm2, xmm0); /* 00Bf00Gf00Bf00Af00Be00Ge00Re00Ae */ @@ -141,7 +149,6 @@ pstatus_t sse2_alphaComp_argb( /* Add xmm5 */ xmm4 = _mm_adds_epi16(xmm4, xmm5); /* 00Bj00Gj00Rj00Aj00Bi00Gi00Ri00Ai */ - /* 00Bd00Gd00Rd00Ad00Bc00Gc00Rc00Ac */ xmm5 = _mm_unpacklo_epi8(xmm2, xmm0); /* 00Bh00Gh00Rh00Ah00Bg00Gg00Rg00Ag */ @@ -161,23 +168,22 @@ pstatus_t sse2_alphaComp_argb( /* Add xmm6 */ xmm5 = _mm_adds_epi16(xmm5, xmm6); /* 00Bl00Gl00Rl00Al00Bk00Gk00Rk0ABk */ - /* Must mask off remainders or pack gets confused */ xmm3 = _mm_set1_epi16(0x00ffU); xmm4 = _mm_and_si128(xmm4, xmm3); xmm5 = _mm_and_si128(xmm5, xmm3); - /* BlGlRlAlBkGkRkAkBjGjRjAjBiGiRiAi */ xmm5 = _mm_packus_epi16(xmm5, xmm4); - _mm_store_si128((__m128i *) dptr, xmm5); dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm5); + dptr += 4; } /* Finish off the remainder. */ if (pixels) { - general_alphaComp_argb((const BYTE *) sptr1, src1Step, - (const BYTE *) sptr2, src2Step, - (BYTE *) dptr, dstStep, pixels, 1); + generic->alphaComp_argb((const BYTE*) sptr1, src1Step, + (const BYTE*) sptr2, src2Step, + (BYTE*) dptr, dstStep, pixels, 1); sptr1 += pixels; sptr2 += pixels; dptr += pixels; @@ -196,31 +202,35 @@ pstatus_t sse2_alphaComp_argb( #ifdef WITH_IPP /* ------------------------------------------------------------------------- */ -pstatus_t ipp_alphaComp_argb( - const BYTE *pSrc1, INT32 src1Step, - const BYTE *pSrc2, INT32 src2Step, - BYTE *pDst, INT32 dstStep, - INT32 width, INT32 height) +static pstatus_t ipp_alphaComp_argb( + const BYTE* pSrc1, INT32 src1Step, + const BYTE* pSrc2, INT32 src2Step, + BYTE* pDst, INT32 dstStep, + INT32 width, INT32 height) { IppiSize sz; sz.width = width; sz.height = height; return ippiAlphaComp_8u_AC4R(pSrc1, src1Step, pSrc2, src2Step, - pDst, dstStep, sz, ippAlphaOver); + pDst, dstStep, sz, ippAlphaOver); } #endif /* ------------------------------------------------------------------------- */ void primitives_init_alphaComp_opt(primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_alphaComp(prims); #ifdef WITH_IPP prims->alphaComp_argb = ipp_alphaComp_argb; #elif defined(WITH_SSE2) + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) - && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) /* for LDDQU */ + && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) /* for LDDQU */ { prims->alphaComp_argb = sse2_alphaComp_argb; } + #endif } diff --git a/libfreerdp/primitives/prim_andor.c b/libfreerdp/primitives/prim_andor.c index 4c1923f46..25aee8ea5 100644 --- a/libfreerdp/primitives/prim_andor.c +++ b/libfreerdp/primitives/prim_andor.c @@ -21,16 +21,15 @@ #include #include "prim_internal.h" -#include "prim_andor.h" /* ---------------------------------------------------------------------------- * 32-bit AND with a constant. */ -pstatus_t general_andC_32u( - const UINT32 *pSrc, - UINT32 val, - UINT32 *pDst, - INT32 len) +static pstatus_t general_andC_32u( + const UINT32* pSrc, + UINT32 val, + UINT32* pDst, + INT32 len) { if (val == 0) return PRIMITIVES_SUCCESS; @@ -44,11 +43,11 @@ pstatus_t general_andC_32u( /* ---------------------------------------------------------------------------- * 32-bit OR with a constant. */ -pstatus_t general_orC_32u( - const UINT32 *pSrc, - UINT32 val, - UINT32 *pDst, - INT32 len) +static pstatus_t general_orC_32u( + const UINT32* pSrc, + UINT32 val, + UINT32* pDst, + INT32 len) { if (val == 0) return PRIMITIVES_SUCCESS; @@ -61,19 +60,9 @@ pstatus_t general_orC_32u( /* ------------------------------------------------------------------------- */ void primitives_init_andor( - primitives_t *prims) + primitives_t* prims) { /* Start with the default. */ prims->andC_32u = general_andC_32u; prims->orC_32u = general_orC_32u; - - primitives_init_andor_opt(prims); } - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_andor( - primitives_t *prims) -{ - /* Nothing to do. */ -} - diff --git a/libfreerdp/primitives/prim_andor.h b/libfreerdp/primitives/prim_andor.h deleted file mode 100644 index 9762f22aa..000000000 --- a/libfreerdp/primitives/prim_andor.h +++ /dev/null @@ -1,31 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * Logical operations. - * vi:ts=4 sw=4 - * - * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. Algorithms used by - * this code may be covered by patents by HP, Microsoft, or other parties. - * - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_ANDOR_H_INCLUDED__ -#define __PRIM_ANDOR_H_INCLUDED__ - -pstatus_t general_andC_32u(const UINT32 *pSrc, UINT32 val, UINT32 *pDst, INT32 len); -pstatus_t general_orC_32u(const UINT32 *pSrc, UINT32 val, UINT32 *pDst, INT32 len); - -void primitives_init_andor_opt(primitives_t *prims); - -#endif /* !__PRIM_ANDOR_H_INCLUDED__ */ - diff --git a/libfreerdp/primitives/prim_andor_opt.c b/libfreerdp/primitives/prim_andor_opt.c index a98d85f0a..0ed52731d 100644 --- a/libfreerdp/primitives/prim_andor_opt.c +++ b/libfreerdp/primitives/prim_andor_opt.c @@ -32,32 +32,37 @@ #include "prim_internal.h" #include "prim_templates.h" -#include "prim_andor.h" + +static primitives_t* generic = NULL; #ifdef WITH_SSE2 # if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) /* ------------------------------------------------------------------------- */ -SSE3_SCD_PRE_ROUTINE(sse3_andC_32u, UINT32, general_andC_32u, - _mm_and_si128, *dptr++ = *sptr++ & val) -SSE3_SCD_PRE_ROUTINE(sse3_orC_32u, UINT32, general_orC_32u, - _mm_or_si128, *dptr++ = *sptr++ | val) +SSE3_SCD_PRE_ROUTINE(sse3_andC_32u, UINT32, generic->andC_32u, + _mm_and_si128, *dptr++ = *sptr++ & val) +SSE3_SCD_PRE_ROUTINE(sse3_orC_32u, UINT32, generic->orC_32u, + _mm_or_si128, *dptr++ = *sptr++ | val) # endif /* !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) */ #endif /* ------------------------------------------------------------------------- */ -void primitives_init_andor_opt(primitives_t *prims) +void primitives_init_andor_opt(primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_andor(prims); #if defined(WITH_IPP) prims->andC_32u = (__andC_32u_t) ippsAndC_32u; prims->orC_32u = (__orC_32u_t) ippsOrC_32u; #elif defined(WITH_SSE2) + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) - && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) { prims->andC_32u = sse3_andC_32u; prims->orC_32u = sse3_orC_32u; } + #endif } diff --git a/libfreerdp/primitives/prim_colors.c b/libfreerdp/primitives/prim_colors.c index 46c18642a..30bc13151 100644 --- a/libfreerdp/primitives/prim_colors.c +++ b/libfreerdp/primitives/prim_colors.c @@ -23,9 +23,9 @@ #include #include +#include #include "prim_internal.h" -#include "prim_colors.h" #ifndef MINMAX #define MINMAX(_v_, _l_, _h_) \ @@ -33,11 +33,20 @@ #endif /* !MINMAX */ /* ------------------------------------------------------------------------- */ - -pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, - BYTE* pDst, int dstStep, const prim_size_t* roi) +static INLINE BYTE* writePixel(BYTE* dst, UINT32 format, BYTE r, BYTE g, BYTE b) { - int x, y; + UINT32 color = GetColor(format, r, g, b, 0); + WriteColor(dst, format, color); + return dst + GetBytesPerPixel(format); +} + + +static pstatus_t general_yCbCrToRGB_16s8u_P3AC4R( + const INT16* pSrc[3], INT32 srcStep, + BYTE* pDst, INT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi) +{ + UINT32 x, y; INT16 R, G, B; float Y, Cb, Cr; BYTE* pRGB = pDst; @@ -51,13 +60,12 @@ pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, { for (x = 0; x < roi->width; x++) { - Y = (float) (pY[0] + 4096); - Cb = (float) (pCb[0]); - Cr = (float) (pCr[0]); - - R = ((INT16) (((Cr * 1.402525f) + Y + 16.0f)) >> 5); - G = ((INT16) ((Y - (Cb * 0.343730f) - (Cr * 0.714401f) + 16.0f)) >> 5); - B = ((INT16) (((Cb * 1.769905f) + Y + 16.0f)) >> 5); + Y = (float)(pY[0] + 4096); + Cb = (float)(pCb[0]); + Cr = (float)(pCr[0]); + R = ((INT16)(((Cr * 1.402525f) + Y + 16.0f)) >> 5); + G = ((INT16)((Y - (Cb * 0.343730f) - (Cr * 0.714401f) + 16.0f)) >> 5); + B = ((INT16)(((Cb * 1.769905f) + Y + 16.0f)) >> 5); if (R < 0) R = 0; @@ -74,11 +82,7 @@ pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, else if (B > 255) B = 255; - *pRGB++ = (BYTE) B; - *pRGB++ = (BYTE) G; - *pRGB++ = (BYTE) R; - *pRGB++ = 0xFF; - + pRGB = writePixel(pRGB, DstFormat, R, G, B); pY++; pCb++; pCr++; @@ -93,30 +97,31 @@ pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, return PRIMITIVES_SUCCESS; } -pstatus_t general_yCbCrToBGR_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, - BYTE* pDst, int dstStep, const prim_size_t* roi) +static pstatus_t general_yCbCrToBGR_16s8u_P3AC4R( + const INT16* pSrc[3], INT32 srcStep, + BYTE* pDst, INT32 dstStep, UINT32 DstFormat, + const prim_size_t* roi) { - int x, y; + UINT32 x, y; INT16 R, G, B; float Y, Cb, Cr; BYTE* pRGB = pDst; const INT16* pY = pSrc[0]; const INT16* pCb = pSrc[1]; const INT16* pCr = pSrc[2]; - int srcPad = (srcStep - (roi->width * 2)) / 2; - int dstPad = (dstStep - (roi->width * 4)) / 4; + UINT32 srcPad = (srcStep - (roi->width * 2)) / 2; + UINT32 dstPad = (dstStep - (roi->width * 4)) / 4; for (y = 0; y < roi->height; y++) { for (x = 0; x < roi->width; x++) { - Y = (float) (pY[0] + 4096); - Cb = (float) (pCb[0]); - Cr = (float) (pCr[0]); - - R = ((INT16) (((Cr * 1.402525f) + Y + 16.0f)) >> 5); - G = ((INT16) ((Y - (Cb * 0.343730f) - (Cr * 0.714401f) + 16.0f)) >> 5); - B = ((INT16) (((Cb * 1.769905f) + Y + 16.0f)) >> 5); + Y = (float)(pY[0] + 4096); + Cb = (float)(pCb[0]); + Cr = (float)(pCr[0]); + R = ((INT16)(((Cr * 1.402525f) + Y + 16.0f)) >> 5); + G = ((INT16)((Y - (Cb * 0.343730f) - (Cr * 0.714401f) + 16.0f)) >> 5); + B = ((INT16)(((Cb * 1.769905f) + Y + 16.0f)) >> 5); if (R < 0) R = 0; @@ -133,11 +138,7 @@ pstatus_t general_yCbCrToBGR_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, else if (B > 255) B = 255; - *pRGB++ = (BYTE) R; - *pRGB++ = (BYTE) G; - *pRGB++ = (BYTE) B; - *pRGB++ = 0xFF; - + pRGB = writePixel(pRGB, DstFormat, R, G, B); pY++; pCb++; pCr++; @@ -154,10 +155,10 @@ pstatus_t general_yCbCrToBGR_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, /* ------------------------------------------------------------------------- */ -pstatus_t general_yCbCrToRGB_16s16s_P3P3( - const INT16 *pSrc[3], INT32 srcStep, - INT16 *pDst[3], INT32 dstStep, - const prim_size_t *roi) /* region of interest */ +static pstatus_t general_yCbCrToRGB_16s16s_P3P3( + const INT16* pSrc[3], INT32 srcStep, + INT16* pDst[3], INT32 dstStep, + const prim_size_t* roi) /* region of interest */ { /** * The decoded YCbCr coeffectients are represented as 11.5 fixed-point @@ -170,29 +171,29 @@ pstatus_t general_yCbCrToRGB_16s16s_P3P3( * by << 5 when interpreted as INT16. * It was scaled in the quantization phase, so we must scale it back here. */ - const INT16 *yptr = pSrc[0]; - const INT16 *cbptr = pSrc[1]; - const INT16 *crptr = pSrc[2]; - INT16 *rptr = pDst[0]; - INT16 *gptr = pDst[1]; - INT16 *bptr = pDst[2]; - int srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); - int dstbump = (dstStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); - int y; + const INT16* yptr = pSrc[0]; + const INT16* cbptr = pSrc[1]; + const INT16* crptr = pSrc[2]; + INT16* rptr = pDst[0]; + INT16* gptr = pDst[1]; + INT16* bptr = pDst[2]; + UINT32 srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + UINT32 dstbump = (dstStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + UINT32 y; - for (y=0; yheight; y++) + for (y = 0; y < roi->height; y++) { - int x; - for (x=0; xwidth; ++x) + UINT32 x; + + for (x = 0; x < roi->width; ++x) { /* INT32 is used intentionally because we calculate * with shifted factors! */ - INT32 y = (INT32) (*yptr++); - INT32 cb = (INT32) (*cbptr++); - INT32 cr = (INT32) (*crptr++); - INT32 r,g,b; - + INT32 y = (INT32)(*yptr++); + INT32 cb = (INT32)(*cbptr++); + INT32 cr = (INT32)(*crptr++); + INT32 r, g, b; /* * This is the slow floating point version kept here for reference. * y = y + 4096; // 128<<5=4096 so that we can scale the sum by>>5 @@ -203,7 +204,6 @@ pstatus_t general_yCbCrToRGB_16s16s_P3P3( * cb_g_buf[i] = MINMAX(g>>5, 0, 255); * cr_b_buf[i] = MINMAX(b>>5, 0, 255); */ - /* * We scale the factors by << 16 into 32-bit integers in order to * avoid slower floating point multiplications. Since the final @@ -214,16 +214,15 @@ pstatus_t general_yCbCrToRGB_16s16s_P3P3( * G: 0.344 << 16 = 22544, 0.714 << 16 = 46792 * B: 1.770 << 16 = 115998 */ - y = (y+4096)<<16; - - r = y + cr*91947; - g = y - cb*22544 - cr*46792; - b = y + cb*115998; - - *rptr++ = MINMAX(r>>21, 0, 255); - *gptr++ = MINMAX(g>>21, 0, 255); - *bptr++ = MINMAX(b>>21, 0, 255); + y = (y + 4096) << 16; + r = y + cr * 91947; + g = y - cb * 22544 - cr * 46792; + b = y + cb * 115998; + *rptr++ = MINMAX(r >> 21, 0, 255); + *gptr++ = MINMAX(g >> 21, 0, 255); + *bptr++ = MINMAX(b >> 21, 0, 255); } + yptr += srcbump; cbptr += srcbump; crptr += srcbump; @@ -231,14 +230,15 @@ pstatus_t general_yCbCrToRGB_16s16s_P3P3( gptr += dstbump; bptr += dstbump; } + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_RGBToYCbCr_16s16s_P3P3( - const INT16 *pSrc[3], INT32 srcStep, - INT16 *pDst[3], INT32 dstStep, - const prim_size_t *roi) /* region of interest */ +static pstatus_t general_RGBToYCbCr_16s16s_P3P3( + const INT16* pSrc[3], INT32 srcStep, + INT16* pDst[3], INT32 dstStep, + const prim_size_t* roi) /* region of interest */ { /* The encoded YCbCr coefficients are represented as 11.5 fixed-point * numbers: @@ -250,36 +250,36 @@ pstatus_t general_RGBToYCbCr_16s16s_P3P3( * is scaled by << 5 when interpreted as INT16. * It will be scaled down to original during the quantization phase. */ - const INT16 *rptr = pSrc[0]; - const INT16 *gptr = pSrc[1]; - const INT16 *bptr = pSrc[2]; - INT16 *yptr = pDst[0]; - INT16 *cbptr = pDst[1]; - INT16 *crptr = pDst[2]; - int srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); - int dstbump = (dstStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); - int y; + const INT16* rptr = pSrc[0]; + const INT16* gptr = pSrc[1]; + const INT16* bptr = pSrc[2]; + INT16* yptr = pDst[0]; + INT16* cbptr = pDst[1]; + INT16* crptr = pDst[2]; + UINT32 srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + UINT32 dstbump = (dstStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + UINT32 y; - for (y=0; yheight; y++) + for (y = 0; y < roi->height; y++) { int x; - for (x=0; xwidth; ++x) + + for (x = 0; x < roi->width; ++x) { /* INT32 is used intentionally because we calculate with * shifted factors! */ - INT32 r = (INT32) (*rptr++); - INT32 g = (INT32) (*gptr++); - INT32 b = (INT32) (*bptr++); - + INT32 r = (INT32)(*rptr++); + INT32 g = (INT32)(*gptr++); + INT32 b = (INT32)(*bptr++); /* We scale the factors by << 15 into 32-bit integers in order * to avoid slower floating point multiplications. Since the * terms need to be scaled by << 5 we simply scale the final * sum by >> 10 * - * Y: 0.299000 << 15 = 9798, 0.587000 << 15 = 19235, + * Y: 0.299000 << 15 = 9798, 0.587000 << 15 = 19235, * 0.114000 << 15 = 3735 - * Cb: 0.168935 << 15 = 5535, 0.331665 << 15 = 10868, + * Cb: 0.168935 << 15 = 5535, 0.331665 << 15 = 10868, * 0.500590 << 15 = 16403 * Cr: 0.499813 << 15 = 16377, 0.418531 << 15 = 13714, * 0.081282 << 15 = 2663 @@ -287,11 +287,11 @@ pstatus_t general_RGBToYCbCr_16s16s_P3P3( INT32 y = (r * 9798 + g * 19235 + b * 3735) >> 10; INT32 cb = (r * -5535 + g * -10868 + b * 16403) >> 10; INT32 cr = (r * 16377 + g * -13714 + b * -2663) >> 10; - *yptr++ = (INT16) MINMAX(y - 4096, -4096, 4095); *cbptr++ = (INT16) MINMAX(cb, -4096, 4095); *crptr++ = (INT16) MINMAX(cr, -4096, 4095); } + yptr += srcbump; cbptr += srcbump; crptr += srcbump; @@ -299,39 +299,38 @@ pstatus_t general_RGBToYCbCr_16s16s_P3P3( gptr += dstbump; bptr += dstbump; } + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_RGBToRGB_16s8u_P3AC4R( - const INT16 *pSrc[3], /* 16-bit R,G, and B arrays */ - int srcStep, /* bytes between rows in source data */ - BYTE *pDst, /* 32-bit interleaved ARGB (ABGR?) data */ - int dstStep, /* bytes between rows in dest data */ - const prim_size_t *roi) /* region of interest */ +static pstatus_t general_RGBToRGB_16s8u_P3AC4R( + const INT16* pSrc[3], /* 16-bit R,G, and B arrays */ + INT32 srcStep, /* bytes between rows in source data */ + BYTE* pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + INT32 dstStep, /* bytes between rows in dest data */ + UINT32 DstFormat, + const prim_size_t* roi) /* region of interest */ { - const INT16 *r = pSrc[0]; - const INT16 *g = pSrc[1]; - const INT16 *b = pSrc[2]; - BYTE *dst = pDst; - int x,y; - int srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); - int dstbump = (dstStep - (roi->width * sizeof(UINT32))); + const INT16* r = pSrc[0]; + const INT16* g = pSrc[1]; + const INT16* b = pSrc[2]; + BYTE* dst = pDst; + UINT32 x, y; + UINT32 srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + UINT32 dstbump = (dstStep - (roi->width * sizeof(UINT32))); - for (y=0; yheight; ++y) + for (y = 0; y < roi->height; ++y) { - for (x=0; xwidth; ++x) - { - *dst++ = (BYTE) (*b++); - *dst++ = (BYTE) (*g++); - *dst++ = (BYTE) (*r++); - *dst++ = ((BYTE) (0xFFU)); - } + for (x = 0; x < roi->width; ++x) + dst = writePixel(dst, DstFormat, *r++, *g++, *b++); + dst += dstbump; r += srcbump; g += srcbump; b += srcbump; } + return PRIMITIVES_SUCCESS; } @@ -343,13 +342,4 @@ void primitives_init_colors(primitives_t* prims) prims->yCbCrToRGB_16s16s_P3P3 = general_yCbCrToRGB_16s16s_P3P3; prims->RGBToYCbCr_16s16s_P3P3 = general_RGBToYCbCr_16s16s_P3P3; prims->RGBToRGB_16s8u_P3AC4R = general_RGBToRGB_16s8u_P3AC4R; - - primitives_init_colors_opt(prims); } - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_colors(primitives_t* prims) -{ - /* Nothing to do. */ -} - diff --git a/libfreerdp/primitives/prim_colors.h b/libfreerdp/primitives/prim_colors.h deleted file mode 100644 index 773bbaeeb..000000000 --- a/libfreerdp/primitives/prim_colors.h +++ /dev/null @@ -1,33 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * Color conversion operations. - * vi:ts=4 sw=4 - * - * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. Algorithms used by - * this code may be covered by patents by HP, Microsoft, or other parties. - * - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_COLORS_H_INCLUDED__ -#define __PRIM_COLORS_H_INCLUDED__ - -pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(const INT16* pSrc[3], int srcStep, BYTE* pDst, int dstStep, const prim_size_t* roi); -pstatus_t general_yCbCrToRGB_16s16s_P3P3(const INT16 *pSrc[3], INT32 srcStep, INT16 *pDst[3], INT32 dstStep, const prim_size_t *roi); -pstatus_t general_RGBToYCbCr_16s16s_P3P3(const INT16 *pSrc[3], INT32 srcStep, INT16 *pDst[3], INT32 dstStep, const prim_size_t *roi); -pstatus_t general_RGBToRGB_16s8u_P3AC4R(const INT16 *pSrc[3], int srcStep, BYTE *pDst, int dstStep, const prim_size_t *roi); - -void primitives_init_colors_opt(primitives_t* prims); - -#endif /* !__PRIM_COLORS_H_INCLUDED__ */ - diff --git a/libfreerdp/primitives/prim_colors_opt.c b/libfreerdp/primitives/prim_colors_opt.c index e9505dab7..ac5c6622b 100644 --- a/libfreerdp/primitives/prim_colors_opt.c +++ b/libfreerdp/primitives/prim_colors_opt.c @@ -33,7 +33,8 @@ #include "prim_internal.h" #include "prim_templates.h" -#include "prim_colors.h" + +static primitives_t* generic = NULL; #ifdef WITH_SSE2 @@ -52,13 +53,14 @@ #ifdef DO_PREFETCH /*---------------------------------------------------------------------------*/ static inline void GNU_INLINE _mm_prefetch_buffer( - char * buffer, - int num_bytes) + char* buffer, + int num_bytes) { - __m128i * buf = (__m128i*) buffer; + __m128i* buf = (__m128i*) buffer; unsigned int i; - for (i = 0; i < (num_bytes / sizeof(__m128i)); - i+=(CACHE_LINE_BYTES / sizeof(__m128i))) + + for (i = 0; i < (num_bytes / sizeof(__m128i)); + i += (CACHE_LINE_BYTES / sizeof(__m128i))) { _mm_prefetch((char*)(&buf[i]), _MM_HINT_NTA); } @@ -66,42 +68,40 @@ static inline void GNU_INLINE _mm_prefetch_buffer( #endif /* DO_PREFETCH */ /*---------------------------------------------------------------------------*/ -pstatus_t sse2_yCbCrToRGB_16s16s_P3P3( - const INT16 *pSrc[3], - int srcStep, - INT16 *pDst[3], - int dstStep, - const prim_size_t *roi) /* region of interest */ +static pstatus_t sse2_yCbCrToRGB_16s16s_P3P3( + const INT16* pSrc[3], + int srcStep, + INT16* pDst[3], + int dstStep, + const prim_size_t* roi) /* region of interest */ { __m128i zero, max, r_cr, g_cb, g_cr, b_cb, c4096; - __m128i *y_buf, *cb_buf, *cr_buf, *r_buf, *g_buf, *b_buf; + __m128i* y_buf, *cb_buf, *cr_buf, *r_buf, *g_buf, *b_buf; int srcbump, dstbump, yp, imax; - if (((ULONG_PTR) (pSrc[0]) & 0x0f) - || ((ULONG_PTR) (pSrc[1]) & 0x0f) - || ((ULONG_PTR) (pSrc[2]) & 0x0f) - || ((ULONG_PTR) (pDst[0]) & 0x0f) - || ((ULONG_PTR) (pDst[1]) & 0x0f) - || ((ULONG_PTR) (pDst[2]) & 0x0f) - || (roi->width & 0x07) - || (srcStep & 127) - || (dstStep & 127)) + if (((ULONG_PTR)(pSrc[0]) & 0x0f) + || ((ULONG_PTR)(pSrc[1]) & 0x0f) + || ((ULONG_PTR)(pSrc[2]) & 0x0f) + || ((ULONG_PTR)(pDst[0]) & 0x0f) + || ((ULONG_PTR)(pDst[1]) & 0x0f) + || ((ULONG_PTR)(pDst[2]) & 0x0f) + || (roi->width & 0x07) + || (srcStep & 127) + || (dstStep & 127)) { /* We can't maintain 16-byte alignment. */ - return general_yCbCrToRGB_16s16s_P3P3(pSrc, srcStep, - pDst, dstStep, roi); + return generic->yCbCrToRGB_16s16s_P3P3(pSrc, srcStep, + pDst, dstStep, roi); } zero = _mm_setzero_si128(); max = _mm_set1_epi16(255); - - y_buf = (__m128i*) (pSrc[0]); - cb_buf = (__m128i*) (pSrc[1]); - cr_buf = (__m128i*) (pSrc[2]); - r_buf = (__m128i*) (pDst[0]); - g_buf = (__m128i*) (pDst[1]); - b_buf = (__m128i*) (pDst[2]); - + y_buf = (__m128i*)(pSrc[0]); + cb_buf = (__m128i*)(pSrc[1]); + cr_buf = (__m128i*)(pSrc[2]); + r_buf = (__m128i*)(pDst[0]); + g_buf = (__m128i*)(pDst[1]); + b_buf = (__m128i*)(pDst[2]); r_cr = _mm_set1_epi16(22986); /* 1.403 << 14 */ g_cb = _mm_set1_epi16(-5636); /* -0.344 << 14 */ g_cr = _mm_set1_epi16(-11698); /* -0.714 << 14 */ @@ -109,33 +109,37 @@ pstatus_t sse2_yCbCrToRGB_16s16s_P3P3( c4096 = _mm_set1_epi16(4096); srcbump = srcStep / sizeof(__m128i); dstbump = dstStep / sizeof(__m128i); - #ifdef DO_PREFETCH + /* Prefetch Y's, Cb's, and Cr's. */ - for (yp=0; ypheight; yp++) + for (yp = 0; yp < roi->height; yp++) { int i; - for (i=0; iwidth * sizeof(INT16) / sizeof(__m128i); - i += (CACHE_LINE_BYTES / sizeof(__m128i))) + + for (i = 0; i < roi->width * sizeof(INT16) / sizeof(__m128i); + i += (CACHE_LINE_BYTES / sizeof(__m128i))) { _mm_prefetch((char*)(&y_buf[i]), _MM_HINT_NTA); _mm_prefetch((char*)(&cb_buf[i]), _MM_HINT_NTA); _mm_prefetch((char*)(&cr_buf[i]), _MM_HINT_NTA); } + y_buf += srcbump; cb_buf += srcbump; cr_buf += srcbump; } - y_buf = (__m128i*) (pSrc[0]); - cb_buf = (__m128i*) (pSrc[1]); - cr_buf = (__m128i*) (pSrc[2]); -#endif /* DO_PREFETCH */ + y_buf = (__m128i*)(pSrc[0]); + cb_buf = (__m128i*)(pSrc[1]); + cr_buf = (__m128i*)(pSrc[2]); +#endif /* DO_PREFETCH */ imax = roi->width * sizeof(INT16) / sizeof(__m128i); - for (yp=0; ypheight; ++yp) + + for (yp = 0; yp < roi->height; ++yp) { int i; - for (i=0; i>5 + (HIWORD(cr*22986)<<2)>>5 // simplification * r = ((y+4096)>>2 + HIWORD(cr*22986)) >> 3 */ - /* y = (y_r_buf[i] + 4096) >> 2 */ __m128i y, cb, cr, r, g, b; y = _mm_load_si128(y_buf + i); @@ -166,24 +169,19 @@ pstatus_t sse2_yCbCrToRGB_16s16s_P3P3( cb = _mm_load_si128(cb_buf + i); /* cr = cr_b_buf[i]; */ cr = _mm_load_si128(cr_buf + i); - /* (y + HIWORD(cr*22986)) >> 3 */ r = _mm_add_epi16(y, _mm_mulhi_epi16(cr, r_cr)); r = _mm_srai_epi16(r, 3); - /* r_buf[i] = MINMAX(r, 0, 255); */ _mm_between_epi16(r, zero, max); _mm_store_si128(r_buf + i, r); - /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ g = _mm_add_epi16(y, _mm_mulhi_epi16(cb, g_cb)); g = _mm_add_epi16(g, _mm_mulhi_epi16(cr, g_cr)); g = _mm_srai_epi16(g, 3); - /* g_buf[i] = MINMAX(g, 0, 255); */ _mm_between_epi16(g, zero, max); _mm_store_si128(g_buf + i, g); - /* (y + HIWORD(cb*28999)) >> 3 */ b = _mm_add_epi16(y, _mm_mulhi_epi16(cb, b_cb)); b = _mm_srai_epi16(b, 3); @@ -191,6 +189,7 @@ pstatus_t sse2_yCbCrToRGB_16s16s_P3P3( _mm_between_epi16(b, zero, max); _mm_store_si128(b_buf + i, b); } + y_buf += srcbump; cb_buf += srcbump; cr_buf += srcbump; @@ -206,42 +205,40 @@ pstatus_t sse2_yCbCrToRGB_16s16s_P3P3( /* The encodec YCbCr coeffectients are represented as 11.5 fixed-point * numbers. See the general code above. */ -pstatus_t sse2_RGBToYCbCr_16s16s_P3P3( - const INT16 *pSrc[3], - int srcStep, - INT16 *pDst[3], - int dstStep, - const prim_size_t *roi) /* region of interest */ +static pstatus_t sse2_RGBToYCbCr_16s16s_P3P3( + const INT16* pSrc[3], + int srcStep, + INT16* pDst[3], + int dstStep, + const prim_size_t* roi) /* region of interest */ { __m128i min, max, y_r, y_g, y_b, cb_r, cb_g, cb_b, cr_r, cr_g, cr_b; - __m128i *r_buf, *g_buf, *b_buf, *y_buf, *cb_buf, *cr_buf; + __m128i* r_buf, *g_buf, *b_buf, *y_buf, *cb_buf, *cr_buf; int srcbump, dstbump, yp, imax; - if (((ULONG_PTR) (pSrc[0]) & 0x0f) - || ((ULONG_PTR) (pSrc[1]) & 0x0f) - || ((ULONG_PTR) (pSrc[2]) & 0x0f) - || ((ULONG_PTR) (pDst[0]) & 0x0f) - || ((ULONG_PTR) (pDst[1]) & 0x0f) - || ((ULONG_PTR) (pDst[2]) & 0x0f) - || (roi->width & 0x07) - || (srcStep & 127) - || (dstStep & 127)) + if (((ULONG_PTR)(pSrc[0]) & 0x0f) + || ((ULONG_PTR)(pSrc[1]) & 0x0f) + || ((ULONG_PTR)(pSrc[2]) & 0x0f) + || ((ULONG_PTR)(pDst[0]) & 0x0f) + || ((ULONG_PTR)(pDst[1]) & 0x0f) + || ((ULONG_PTR)(pDst[2]) & 0x0f) + || (roi->width & 0x07) + || (srcStep & 127) + || (dstStep & 127)) { /* We can't maintain 16-byte alignment. */ - return general_RGBToYCbCr_16s16s_P3P3(pSrc, srcStep, - pDst, dstStep, roi); + return generic->RGBToYCbCr_16s16s_P3P3(pSrc, srcStep, + pDst, dstStep, roi); } min = _mm_set1_epi16(-128 * 32); max = _mm_set1_epi16(127 * 32); - - r_buf = (__m128i*) (pSrc[0]); - g_buf = (__m128i*) (pSrc[1]); - b_buf = (__m128i*) (pSrc[2]); - y_buf = (__m128i*) (pDst[0]); - cb_buf = (__m128i*) (pDst[1]); - cr_buf = (__m128i*) (pDst[2]); - + r_buf = (__m128i*)(pSrc[0]); + g_buf = (__m128i*)(pSrc[1]); + b_buf = (__m128i*)(pSrc[2]); + y_buf = (__m128i*)(pDst[0]); + cb_buf = (__m128i*)(pDst[1]); + cr_buf = (__m128i*)(pDst[2]); y_r = _mm_set1_epi16(9798); /* 0.299000 << 15 */ y_g = _mm_set1_epi16(19235); /* 0.587000 << 15 */ y_b = _mm_set1_epi16(3735); /* 0.114000 << 15 */ @@ -251,36 +248,39 @@ pstatus_t sse2_RGBToYCbCr_16s16s_P3P3( cr_r = _mm_set1_epi16(16377); /* 0.499813 << 15 */ cr_g = _mm_set1_epi16(-13714); /* -0.418531 << 15 */ cr_b = _mm_set1_epi16(-2663); /* -0.081282 << 15 */ - srcbump = srcStep / sizeof(__m128i); dstbump = dstStep / sizeof(__m128i); - #ifdef DO_PREFETCH + /* Prefetch RGB's. */ - for (yp=0; ypheight; yp++) + for (yp = 0; yp < roi->height; yp++) { int i; - for (i=0; iwidth * sizeof(INT16) / sizeof(__m128i); - i += (CACHE_LINE_BYTES / sizeof(__m128i))) + + for (i = 0; i < roi->width * sizeof(INT16) / sizeof(__m128i); + i += (CACHE_LINE_BYTES / sizeof(__m128i))) { _mm_prefetch((char*)(&r_buf[i]), _MM_HINT_NTA); _mm_prefetch((char*)(&g_buf[i]), _MM_HINT_NTA); _mm_prefetch((char*)(&b_buf[i]), _MM_HINT_NTA); } + r_buf += srcbump; g_buf += srcbump; b_buf += srcbump; } - r_buf = (__m128i*) (pSrc[0]); - g_buf = (__m128i*) (pSrc[1]); - b_buf = (__m128i*) (pSrc[2]); -#endif /* DO_PREFETCH */ + r_buf = (__m128i*)(pSrc[0]); + g_buf = (__m128i*)(pSrc[1]); + b_buf = (__m128i*)(pSrc[2]); +#endif /* DO_PREFETCH */ imax = roi->width * sizeof(INT16) / sizeof(__m128i); - for (yp=0; ypheight; ++yp) + + for (yp = 0; yp < roi->height; ++yp) { int i; - for (i=0; iwidth & 0x0f) - || (srcStep & 0x0f) - || (dstStep & 0x0f)) + if ((((ULONG_PTR)(pSrc[0]) & 0x0f) != 0) + || (((ULONG_PTR)(pSrc[1]) & 0x0f) != 0) + || (((ULONG_PTR)(pSrc[2]) & 0x0f) != 0) + || (((ULONG_PTR) pDst & 0x0f) != 0) + || (roi->width & 0x0f) + || (srcStep & 0x0f) + || (dstStep & 0x0f)) { - return general_RGBToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, dstStep, roi); + return generic->RGBToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, + dstStep, DstFormat, roi); } - out = (BYTE *) pDst; + out = (BYTE*) pDst; srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); dstbump = (dstStep - (roi->width * sizeof(UINT32))); - for (y=0; yheight; ++y) + for (y = 0; y < roi->height; ++y) { int width = roi->width; - do { + + do + { __m128i R0, R1, R2, R3, R4; /* The comments below pretend these are 8-byte registers * rather than 16-byte, for readability. */ - R0 = LOAD128(b); b += 8; /* R0 = 00B300B200B100B0 */ - R1 = LOAD128(b); b += 8; /* R1 = 00B700B600B500B4 */ - PACKUSWB(R0,R1); /* R0 = B7B6B5B4B3B2B1B0 */ - R1 = LOAD128(g); g += 8; /* R1 = 00G300G200G100G0 */ - R2 = LOAD128(g); g += 8; /* R2 = 00G700G600G500G4 */ - PACKUSWB(R1,R2); /* R1 = G7G6G5G4G3G2G1G0 */ + R0 = LOAD128(b); + b += 8; /* R0 = 00B300B200B100B0 */ + R1 = LOAD128(b); + b += 8; /* R1 = 00B700B600B500B4 */ + PACKUSWB(R0, R1); /* R0 = B7B6B5B4B3B2B1B0 */ + R1 = LOAD128(g); + g += 8; /* R1 = 00G300G200G100G0 */ + R2 = LOAD128(g); + g += 8; /* R2 = 00G700G600G500G4 */ + PACKUSWB(R1, R2); /* R1 = G7G6G5G4G3G2G1G0 */ R2 = R1; /* R2 = G7G6G5G4G3G2G1G0 */ - PUNPCKLBW(R2,R0); /* R2 = G3B3G2B2G1B1G0B0 */ - PUNPCKHBW(R1,R0); /* R1 = G7B7G6B7G5B5G4B4 */ - R0 = LOAD128(r); r += 8; /* R0 = 00R300R200R100R0 */ - R3 = LOAD128(r); r += 8; /* R3 = 00R700R600R500R4 */ - PACKUSWB(R0,R3); /* R0 = R7R6R5R4R3R2R1R0 */ + PUNPCKLBW(R2, R0); /* R2 = G3B3G2B2G1B1G0B0 */ + PUNPCKHBW(R1, R0); /* R1 = G7B7G6B7G5B5G4B4 */ + R0 = LOAD128(r); + r += 8; /* R0 = 00R300R200R100R0 */ + R3 = LOAD128(r); + r += 8; /* R3 = 00R700R600R500R4 */ + PACKUSWB(R0, R3); /* R0 = R7R6R5R4R3R2R1R0 */ R3 = XMM_ALL_ONES; /* R3 = FFFFFFFFFFFFFFFF */ R4 = R3; /* R4 = FFFFFFFFFFFFFFFF */ - PUNPCKLBW(R4,R0); /* R4 = FFR3FFR2FFR1FFR0 */ - PUNPCKHBW(R3,R0); /* R3 = FFR7FFR6FFR5FFR4 */ + PUNPCKLBW(R4, R0); /* R4 = FFR3FFR2FFR1FFR0 */ + PUNPCKHBW(R3, R0); /* R3 = FFR7FFR6FFR5FFR4 */ R0 = R4; /* R0 = R4 */ - PUNPCKLWD(R0,R2); /* R0 = FFR1G1B1FFR0G0B0 */ - PUNPCKHWD(R4,R2); /* R4 = FFR3G3B3FFR2G2B2 */ + PUNPCKLWD(R0, R2); /* R0 = FFR1G1B1FFR0G0B0 */ + PUNPCKHWD(R4, R2); /* R4 = FFR3G3B3FFR2G2B2 */ R2 = R3; /* R2 = R3 */ - PUNPCKLWD(R2,R1); /* R2 = FFR5G5B5FFR4G4B4 */ - PUNPCKHWD(R3,R1); /* R3 = FFR7G7B7FFR6G6B6 */ - STORE128(out, R0); out += 16; /* FFR1G1B1FFR0G0B0 */ - STORE128(out, R4); out += 16; /* FFR3G3B3FFR2G2B2 */ - STORE128(out, R2); out += 16; /* FFR5G5B5FFR4G4B4 */ - STORE128(out, R3); out += 16; /* FFR7G7B7FFR6G6B6 */ - } while (width -= 16); + PUNPCKLWD(R2, R1); /* R2 = FFR5G5B5FFR4G4B4 */ + PUNPCKHWD(R3, R1); /* R3 = FFR7G7B7FFR6G6B6 */ + STORE128(out, R0); + out += 16; /* FFR1G1B1FFR0G0B0 */ + STORE128(out, R4); + out += 16; /* FFR3G3B3FFR2G2B2 */ + STORE128(out, R2); + out += 16; /* FFR5G5B5FFR4G4B4 */ + STORE128(out, R3); + out += 16; /* FFR7G7B7FFR6G6B6 */ + } + while (width -= 16); + /* Jump to next row. */ r += srcbump; g += srcbump; b += srcbump; out += dstbump; } + return PRIMITIVES_SUCCESS; } #endif /* WITH_SSE2 */ /*---------------------------------------------------------------------------*/ #ifdef WITH_NEON -pstatus_t neon_yCbCrToRGB_16s16s_P3P3( - const INT16 *pSrc[3], - int srcStep, - INT16 *pDst[3], - int dstStep, - const prim_size_t *roi) /* region of interest */ +static pstatus_t neon_yCbCrToRGB_16s16s_P3P3( + const INT16* pSrc[3], + int srcStep, + INT16* pDst[3], + int dstStep, + const prim_size_t* roi) /* region of interest */ { /* TODO: If necessary, check alignments and call the general version. */ - int16x8_t zero = vdupq_n_s16(0); int16x8_t max = vdupq_n_s16(255); - int16x8_t r_cr = vdupq_n_s16(22986); // 1.403 << 14 int16x8_t g_cb = vdupq_n_s16(-5636); // -0.344 << 14 int16x8_t g_cr = vdupq_n_s16(-11698); // -0.714 << 14 int16x8_t b_cb = vdupq_n_s16(28999); // 1.770 << 14 int16x8_t c4096 = vdupq_n_s16(4096); - int16x8_t* y_buf = (int16x8_t*) pSrc[0]; int16x8_t* cb_buf = (int16x8_t*) pSrc[1]; int16x8_t* cr_buf = (int16x8_t*) pSrc[2]; int16x8_t* r_buf = (int16x8_t*) pDst[0]; int16x8_t* g_buf = (int16x8_t*) pDst[1]; int16x8_t* b_buf = (int16x8_t*) pDst[2]; - int srcbump = srcStep / sizeof(int16x8_t); int dstbump = dstStep / sizeof(int16x8_t); int yp; - int imax = roi->width * sizeof(INT16) / sizeof(int16x8_t); - for (yp=0; ypheight; ++yp) + + for (yp = 0; yp < roi->height; ++yp) { int i; - for (i=0; i>5 + (HIWORD(cr*22986)<<2)>>5 // simplification r = ((y+4096)>>2 + HIWORD(cr*22986)) >> 3 */ - /* y = (y_buf[i] + 4096) >> 2 */ int16x8_t y = vld1q_s16((INT16*) &y_buf[i]); y = vaddq_s16(y, c4096); @@ -501,14 +511,12 @@ pstatus_t neon_yCbCrToRGB_16s16s_P3P3( int16x8_t cb = vld1q_s16((INT16*)&cb_buf[i]); /* cr = cr_buf[i]; */ int16x8_t cr = vld1q_s16((INT16*) &cr_buf[i]); - /* (y + HIWORD(cr*22986)) >> 3 */ int16x8_t r = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cr, r_cr), 1)); r = vshrq_n_s16(r, 3); /* r_buf[i] = MINMAX(r, 0, 255); */ r = vminq_s16(vmaxq_s16(r, zero), max); vst1q_s16((INT16*)&r_buf[i], r); - /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ int16x8_t g = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cb, g_cb), 1)); g = vaddq_s16(g, vshrq_n_s16(vqdmulhq_s16(cr, g_cr), 1)); @@ -516,7 +524,6 @@ pstatus_t neon_yCbCrToRGB_16s16s_P3P3( /* g_buf[i] = MINMAX(g, 0, 255); */ g = vminq_s16(vmaxq_s16(g, zero), max); vst1q_s16((INT16*)&g_buf[i], g); - /* (y + HIWORD(cb*28999)) >> 3 */ int16x8_t b = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cb, b_cb), 1)); b = vshrq_n_s16(b, 3); @@ -532,6 +539,7 @@ pstatus_t neon_yCbCrToRGB_16s16s_P3P3( g_buf += dstbump; b_buf += dstbump; } + return PRIMITIVES_SUCCESS; } #endif /* WITH_NEON */ @@ -545,18 +553,24 @@ pstatus_t neon_yCbCrToRGB_16s16s_P3P3( /* ------------------------------------------------------------------------- */ void primitives_init_colors_opt(primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_colors(prims); #if defined(WITH_SSE2) + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) { prims->RGBToRGB_16s8u_P3AC4R = sse2_RGBToRGB_16s8u_P3AC4R; prims->yCbCrToRGB_16s16s_P3P3 = sse2_yCbCrToRGB_16s16s_P3P3; prims->RGBToYCbCr_16s16s_P3P3 = sse2_RGBToYCbCr_16s16s_P3P3; } + #elif defined(WITH_NEON) + if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) { prims->yCbCrToRGB_16s16s_P3P3 = neon_yCbCrToRGB_16s16s_P3P3; } + #endif /* WITH_SSE2 */ } diff --git a/libfreerdp/primitives/prim_copy.c b/libfreerdp/primitives/prim_copy.c index 95755a09c..cdccf4b38 100644 --- a/libfreerdp/primitives/prim_copy.c +++ b/libfreerdp/primitives/prim_copy.c @@ -26,15 +26,18 @@ #endif /* WITH_IPP */ #include "prim_internal.h" +static primitives_t* generic = NULL; + /* ------------------------------------------------------------------------- */ /*static inline BOOL memory_regions_overlap_1d(*/ static BOOL memory_regions_overlap_1d( - const BYTE *p1, - const BYTE *p2, - size_t bytes) + const BYTE* p1, + const BYTE* p2, + size_t bytes) { const ULONG_PTR p1m = (const ULONG_PTR) p1; const ULONG_PTR p2m = (const ULONG_PTR) p2; + if (p1m <= p2m) { if (p1m + bytes > p2m) return TRUE; @@ -43,6 +46,7 @@ static BOOL memory_regions_overlap_1d( { if (p2m + bytes > p1m) return TRUE; } + /* else */ return FALSE; } @@ -50,40 +54,43 @@ static BOOL memory_regions_overlap_1d( /* ------------------------------------------------------------------------- */ /*static inline BOOL memory_regions_overlap_2d( */ static BOOL memory_regions_overlap_2d( - const BYTE *p1, int p1Step, int p1Size, - const BYTE *p2, int p2Step, int p2Size, - int width, int height) + const BYTE* p1, int p1Step, int p1Size, + const BYTE* p2, int p2Step, int p2Size, + int width, int height) { ULONG_PTR p1m = (ULONG_PTR) p1; ULONG_PTR p2m = (ULONG_PTR) p2; if (p1m <= p2m) { - ULONG_PTR p1mEnd = p1m + (height-1)*p1Step + width*p1Size; + ULONG_PTR p1mEnd = p1m + (height - 1) * p1Step + width * p1Size; + if (p1mEnd > p2m) return TRUE; } else { - ULONG_PTR p2mEnd = p2m + (height-1)*p2Step + width*p2Size; + ULONG_PTR p2mEnd = p2m + (height - 1) * p2Step + width * p2Size; + if (p2mEnd > p1m) return TRUE; } + /* else */ return FALSE; } /* ------------------------------------------------------------------------- */ -pstatus_t general_copy_8u( - const BYTE *pSrc, - BYTE *pDst, - INT32 len) +static pstatus_t general_copy_8u( + const BYTE* pSrc, + BYTE* pDst, + INT32 len) { if (memory_regions_overlap_1d(pSrc, pDst, (size_t) len)) { - memmove((void *) pDst, (const void *) pSrc, (size_t) len); + memmove((void*) pDst, (const void*) pSrc, (size_t) len); } else { - memcpy((void *) pDst, (const void *) pSrc, (size_t) len); + memcpy((void*) pDst, (const void*) pSrc, (size_t) len); } return PRIMITIVES_SUCCESS; @@ -94,38 +101,41 @@ pstatus_t general_copy_8u( * The addresses are assumed to have been already offset to the upper-left * corners of the source and destination region of interest. */ -pstatus_t general_copy_8u_AC4r( - const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, - INT32 width, INT32 height) +static pstatus_t general_copy_8u_AC4r( + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, INT32 dstStep, + INT32 width, INT32 height) { - primitives_t *prims = primitives_get(); - const BYTE *src = (const BYTE *) pSrc; - BYTE *dst = (BYTE *) pDst; + const BYTE* src = (const BYTE*) pSrc; + BYTE* dst = (BYTE*) pDst; int rowbytes = width * sizeof(UINT32); if ((width == 0) || (height == 0)) return PRIMITIVES_SUCCESS; if (memory_regions_overlap_2d(pSrc, srcStep, sizeof(UINT32), - pDst, dstStep, sizeof(UINT32), width, height)) + pDst, dstStep, sizeof(UINT32), width, height)) { - do { - prims->copy(src, dst, rowbytes); + do + { + generic->copy(src, dst, rowbytes); src += srcStep; dst += dstStep; - } while (--height); + } + while (--height); } else { /* TODO: do it in one operation when the rowdata is adjacent. */ - do { + do + { /* If we find a replacement for memcpy that is consistently * faster, this could be replaced with that. */ memcpy(dst, src, rowbytes); src += srcStep; dst += dstStep; - } while (--height); + } + while (--height); } return PRIMITIVES_SUCCESS; @@ -135,9 +145,9 @@ pstatus_t general_copy_8u_AC4r( /* ------------------------------------------------------------------------- */ /* This is just ippiCopy_8u_AC4R without the IppiSize structure parameter. */ static pstatus_t ippiCopy_8u_AC4r( - const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, - INT32 width, INT32 height) + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, INT32 dstStep, + INT32 width, INT32 height) { IppiSize roi; roi.width = width; @@ -148,32 +158,32 @@ static pstatus_t ippiCopy_8u_AC4r( /* ------------------------------------------------------------------------- */ void primitives_init_copy( - primitives_t *prims) + primitives_t* prims) { /* Start with the default. */ prims->copy_8u = general_copy_8u; prims->copy_8u_AC4r = general_copy_8u_AC4r; + /* This is just an alias with void* parameters */ + prims->copy = (__copy_t)(prims->copy_8u); +} +void primitives_init_copy_opt( + primitives_t* prims) +{ + generic = primitives_get_generic(); + primitives_init_copy(prims); /* Pick tuned versions if possible. */ #ifdef WITH_IPP prims->copy_8u = (__copy_8u_t) ippsCopy_8u; prims->copy_8u_AC4r = (__copy_8u_AC4r_t) ippiCopy_8u_AC4r; #endif /* Performance with an SSE2 version with no prefetch seemed to be - * all over the map vs. memcpy. + * all over the map vs. memcpy. * Sometimes it was significantly faster, sometimes dreadfully slower, * and it seemed to vary a lot depending on block size and processor. * Hence, no SSE version is used here unless once can be written that * is consistently faster than memcpy. */ - /* This is just an alias with void* parameters */ - prims->copy = (__copy_t) (prims->copy_8u); -} - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_copy( - primitives_t *prims) -{ - /* Nothing to do. */ + prims->copy = (__copy_t)(prims->copy_8u); } diff --git a/libfreerdp/primitives/prim_internal.h b/libfreerdp/primitives/prim_internal.h index 04c830a1c..4f7b3619d 100644 --- a/libfreerdp/primitives/prim_internal.h +++ b/libfreerdp/primitives/prim_internal.h @@ -31,41 +31,30 @@ /* Use lddqu for unaligned; load for 16-byte aligned. */ #define LOAD_SI128(_ptr_) \ (((ULONG_PTR) (_ptr_) & 0x0f) \ - ? _mm_lddqu_si128((__m128i *) (_ptr_)) \ - : _mm_load_si128((__m128i *) (_ptr_))) + ? _mm_lddqu_si128((__m128i *) (_ptr_)) \ + : _mm_load_si128((__m128i *) (_ptr_))) /* Function prototypes for all the init/deinit routines. */ -extern void primitives_init_copy(primitives_t *prims); -extern void primitives_deinit_copy(primitives_t *prims); +extern void primitives_init_copy(primitives_t* prims); +extern void primitives_init_set(primitives_t* prims); +extern void primitives_init_add(primitives_t* prims); +extern void primitives_init_andor(primitives_t* prims); +extern void primitives_init_shift(primitives_t* prims); +extern void primitives_init_sign(primitives_t* prims); +extern void primitives_init_alphaComp(primitives_t* prims); +extern void primitives_init_colors(primitives_t* prims); +extern void primitives_init_YCoCg(primitives_t* prims); +extern void primitives_init_YUV(primitives_t* prims); -extern void primitives_init_set(primitives_t *prims); -extern void primitives_deinit_set(primitives_t *prims); - -extern void primitives_init_add(primitives_t *prims); -extern void primitives_deinit_add(primitives_t *prims); - -extern void primitives_init_andor(primitives_t *prims); -extern void primitives_deinit_andor(primitives_t *prims); - -extern void primitives_init_shift(primitives_t *prims); -extern void primitives_deinit_shift(primitives_t *prims); - -extern void primitives_init_sign(primitives_t *prims); -extern void primitives_deinit_sign(primitives_t *prims); - -extern void primitives_init_alphaComp(primitives_t *prims); -extern void primitives_deinit_alphaComp(primitives_t *prims); - -extern void primitives_init_colors(primitives_t *prims); -extern void primitives_deinit_colors(primitives_t *prims); - -extern void primitives_init_YCoCg(primitives_t *prims); -extern void primitives_deinit_YCoCg(primitives_t *prims); - -extern void primitives_init_YUV(primitives_t *prims); -extern void primitives_deinit_YUV(primitives_t *prims); - -extern void primitives_init_16to32bpp(primitives_t *prims); -extern void primitives_deinit_16to32bpp(primitives_t *prims); +extern void primitives_init_copy_opt(primitives_t* prims); +extern void primitives_init_set_opt(primitives_t* prims); +extern void primitives_init_add_opt(primitives_t* prims); +extern void primitives_init_andor_opt(primitives_t* prims); +extern void primitives_init_shift_opt(primitives_t* prims); +extern void primitives_init_sign_opt(primitives_t* prims); +extern void primitives_init_alphaComp_opt(primitives_t* prims); +extern void primitives_init_colors_opt(primitives_t* prims); +extern void primitives_init_YCoCg_opt(primitives_t* prims); +extern void primitives_init_YUV_opt(primitives_t* prims); #endif /* !__PRIM_INTERNAL_H_INCLUDED__ */ diff --git a/libfreerdp/primitives/prim_set.c b/libfreerdp/primitives/prim_set.c index 967df7b33..3770e50ad 100644 --- a/libfreerdp/primitives/prim_set.c +++ b/libfreerdp/primitives/prim_set.c @@ -24,40 +24,40 @@ #include #include "prim_internal.h" -#include "prim_set.h" /* ========================================================================= */ -pstatus_t general_set_8u( - BYTE val, - BYTE *pDst, - INT32 len) +static pstatus_t general_set_8u( + BYTE val, + BYTE* pDst, + INT32 len) { - memset((void *) pDst, (int) val, (size_t) len); + memset((void*) pDst, (int) val, (size_t) len); return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_zero( - void *pDst, - size_t len) +static pstatus_t general_zero( + void* pDst, + size_t len) { memset(pDst, 0, len); return PRIMITIVES_SUCCESS; } /* ========================================================================= */ -pstatus_t general_set_32s( - INT32 val, - INT32 *pDst, - INT32 len) +static pstatus_t general_set_32s( + INT32 val, + INT32* pDst, + INT32 len) { - INT32 *dptr = (INT32 *) pDst; + INT32* dptr = (INT32*) pDst; size_t span, remaining; - primitives_t *prims; + primitives_t* prims; if (len < 256) { while (len--) *dptr++ = val; + return PRIMITIVES_SUCCESS; } @@ -66,30 +66,35 @@ pstatus_t general_set_32s( *dptr = val; remaining = len - 1; prims = primitives_get(); + while (remaining) { size_t thiswidth = span; + if (thiswidth > remaining) thiswidth = remaining; - prims->copy_8u((BYTE *) dptr, (BYTE *) (dptr + span), thiswidth<<2); + + prims->copy_8u((BYTE*) dptr, (BYTE*)(dptr + span), thiswidth << 2); remaining -= thiswidth; span <<= 1; } + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_set_32u( - UINT32 val, - UINT32 *pDst, - INT32 len) +static pstatus_t general_set_32u( + UINT32 val, + UINT32* pDst, + INT32 len) { - UINT32 *dptr = (UINT32 *) pDst; + UINT32* dptr = (UINT32*) pDst; size_t span, remaining; - primitives_t *prims; + primitives_t* prims; if (len < 256) { while (len--) *dptr++ = val; + return PRIMITIVES_SUCCESS; } @@ -98,34 +103,29 @@ pstatus_t general_set_32u( *dptr = val; remaining = len - 1; prims = primitives_get(); + while (remaining) { size_t thiswidth = span; + if (thiswidth > remaining) thiswidth = remaining; - prims->copy_8u((BYTE *) dptr, (BYTE *) (dptr + span), thiswidth<<2); + + prims->copy_8u((BYTE*) dptr, (BYTE*)(dptr + span), thiswidth << 2); remaining -= thiswidth; span <<= 1; } + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ void primitives_init_set( - primitives_t *prims) + primitives_t* prims) { /* Start with the default. */ prims->set_8u = general_set_8u; prims->set_32s = general_set_32s; prims->set_32u = general_set_32u; prims->zero = general_zero; - - primitives_init_set_opt(prims); -} - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_set( - primitives_t *prims) -{ - /* Nothing to do. */ } diff --git a/libfreerdp/primitives/prim_set.h b/libfreerdp/primitives/prim_set.h deleted file mode 100644 index 0e2be1ea7..000000000 --- a/libfreerdp/primitives/prim_set.h +++ /dev/null @@ -1,34 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * Routines to set a chunk of memory to a constant. - * vi:ts=4 sw=4 - * - * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. Algorithms used by - * this code may be covered by patents by HP, Microsoft, or other parties. - * - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_SET_H_INCLUDED__ -#define __PRIM_SET_H_INCLUDED__ - -pstatus_t general_set_8u(BYTE val, BYTE *pDst, INT32 len); -pstatus_t general_zero(void *pDst, size_t len); -pstatus_t general_set_32s(INT32 val, INT32 *pDst, INT32 len); -pstatus_t general_set_32u(UINT32 val, UINT32 *pDst, INT32 len); - - -void primitives_init_set_opt(primitives_t *prims); - -#endif /* !__PRIM_SET_H_INCLUDED__ */ - diff --git a/libfreerdp/primitives/prim_set_opt.c b/libfreerdp/primitives/prim_set_opt.c index 41c6f6f18..a5f11c3e1 100644 --- a/libfreerdp/primitives/prim_set_opt.c +++ b/libfreerdp/primitives/prim_set_opt.c @@ -31,65 +31,85 @@ #endif /* WITH_IPP */ #include "prim_internal.h" -#include "prim_set.h" + +static primitives_t* generic = NULL; /* ========================================================================= */ #ifdef WITH_SSE2 # if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) -pstatus_t sse2_set_8u( - BYTE val, - BYTE *pDst, - INT32 len) +static pstatus_t sse2_set_8u( + BYTE val, + BYTE* pDst, + INT32 len) { BYTE byte, *dptr; __m128i xmm0; size_t count; - if (len < 16) return general_set_8u(val, pDst, len); + if (len < 16) return generic->set_8u(val, pDst, len); byte = val; - dptr = (BYTE *) pDst; + dptr = (BYTE*) pDst; /* Seek 16-byte alignment. */ while ((ULONG_PTR) dptr & 0x0f) { *dptr++ = byte; + if (--len == 0) return PRIMITIVES_SUCCESS; } xmm0 = _mm_set1_epi8(byte); - /* Cover 256-byte chunks via SSE register stores. */ count = len >> 8; len -= count << 8; + /* Do 256-byte chunks using one XMM register. */ while (count--) { - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; } /* Cover 16-byte chunks via SSE register stores. */ count = len >> 4; len -= count << 4; + /* Do 16-byte chunks using one XMM register. */ while (count--) { - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 16; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 16; } /* Do leftover bytes. */ @@ -103,12 +123,13 @@ pstatus_t sse2_set_8u( /* ------------------------------------------------------------------------- */ #ifdef WITH_SSE2 # if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) -pstatus_t sse2_set_32u( - UINT32 val, - UINT32 *pDst, - INT32 len) +static pstatus_t sse2_set_32u( + UINT32 val, + UINT32* pDst, + INT32 len) { - UINT32 *dptr = (UINT32 *) pDst; + const primitives_t* prim = primitives_get_generic(); + UINT32* dptr = (UINT32*) pDst; __m128i xmm0; size_t count; @@ -116,55 +137,75 @@ pstatus_t sse2_set_32u( if (len < 32) { while (len--) *dptr++ = val; + return PRIMITIVES_SUCCESS; } /* Assure we can reach 16-byte alignment. */ if (((ULONG_PTR) dptr & 0x03) != 0) { - return general_set_32u(val, pDst, len); + return prim->set_32u(val, pDst, len); } /* Seek 16-byte alignment. */ while ((ULONG_PTR) dptr & 0x0f) { *dptr++ = val; + if (--len == 0) return PRIMITIVES_SUCCESS; } xmm0 = _mm_set1_epi32(val); - /* Cover 256-byte chunks via SSE register stores. */ count = len >> 6; len -= count << 6; + /* Do 256-byte chunks using one XMM register. */ while (count--) { - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; } /* Cover 16-byte chunks via SSE register stores. */ count = len >> 2; len -= count << 2; + /* Do 16-byte chunks using one XMM register. */ while (count--) { - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 4; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 4; } /* Do leftover bytes. */ @@ -174,33 +215,35 @@ pstatus_t sse2_set_32u( } /* ------------------------------------------------------------------------- */ -pstatus_t sse2_set_32s( - INT32 val, - INT32 *pDst, - INT32 len) +static pstatus_t sse2_set_32s( + INT32 val, + INT32* pDst, + INT32 len) { - UINT32 uval = *((UINT32 *) &val); - return sse2_set_32u(uval, (UINT32 *) pDst, len); + UINT32 uval = *((UINT32*) &val); + return sse2_set_32u(uval, (UINT32*) pDst, len); } # endif /* !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) */ #endif /* WITH_SSE2 */ #ifdef WITH_IPP /* ------------------------------------------------------------------------- */ -pstatus_t ipp_wrapper_set_32u( - UINT32 val, - UINT32 *pDst, - INT32 len) +static pstatus_t ipp_wrapper_set_32u( + UINT32 val, + UINT32* pDst, + INT32 len) { /* A little type conversion, then use the signed version. */ - INT32 sval = *((INT32 *) &val); - return ippsSet_32s(sval, (INT32 *) pDst, len); + INT32 sval = *((INT32*) &val); + return ippsSet_32s(sval, (INT32*) pDst, len); } #endif /* ------------------------------------------------------------------------- */ -void primitives_init_set_opt(primitives_t *prims) +void primitives_init_set_opt(primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_set(prims); /* Pick tuned versions if possible. */ #ifdef WITH_IPP prims->set_8u = (__set_8u_t) ippsSet_8u; @@ -208,12 +251,14 @@ void primitives_init_set_opt(primitives_t *prims) prims->set_32u = (__set_32u_t) ipp_wrapper_set_32u; prims->zero = (__zero_t) ippsZero_8u; #elif defined(WITH_SSE2) + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) { prims->set_8u = sse2_set_8u; prims->set_32s = sse2_set_32s; prims->set_32u = sse2_set_32u; } + #endif } diff --git a/libfreerdp/primitives/prim_shift.c b/libfreerdp/primitives/prim_shift.c index e89b2e086..20d9e2e20 100644 --- a/libfreerdp/primitives/prim_shift.c +++ b/libfreerdp/primitives/prim_shift.c @@ -21,107 +21,98 @@ #include #include "prim_internal.h" -#include "prim_shift.h" - - /* ------------------------------------------------------------------------- */ -pstatus_t general_lShiftC_16s( - const INT16 *pSrc, - INT32 val, - INT16 *pDst, - INT32 len) +static pstatus_t general_lShiftC_16s( + const INT16* pSrc, + INT32 val, + INT16* pDst, + INT32 len) { if (val == 0) return PRIMITIVES_SUCCESS; + while (len--) *pDst++ = *pSrc++ << val; + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_rShiftC_16s( - const INT16 *pSrc, - INT32 val, - INT16 *pDst, - INT32 len) +static pstatus_t general_rShiftC_16s( + const INT16* pSrc, + INT32 val, + INT16* pDst, + INT32 len) { if (val == 0) return PRIMITIVES_SUCCESS; + while (len--) *pDst++ = *pSrc++ >> val; + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_lShiftC_16u( - const UINT16 *pSrc, - INT32 val, - UINT16 *pDst, - INT32 len) +static pstatus_t general_lShiftC_16u( + const UINT16* pSrc, + INT32 val, + UINT16* pDst, + INT32 len) { if (val == 0) return PRIMITIVES_SUCCESS; + while (len--) *pDst++ = *pSrc++ << val; + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_rShiftC_16u( - const UINT16 *pSrc, - INT32 val, - UINT16 *pDst, - INT32 len) +static pstatus_t general_rShiftC_16u( + const UINT16* pSrc, + INT32 val, + UINT16* pDst, + INT32 len) { if (val == 0) return PRIMITIVES_SUCCESS; + while (len--) *pDst++ = *pSrc++ >> val; + return PRIMITIVES_SUCCESS; } /* ------------------------------------------------------------------------- */ -pstatus_t general_shiftC_16s( - const INT16 *pSrc, - INT32 val, - INT16 *pDst, - INT32 len) +static pstatus_t general_shiftC_16s( + const INT16* pSrc, + INT32 val, + INT16* pDst, + INT32 len) { - primitives_t *prims; - if (val == 0) return PRIMITIVES_SUCCESS; - prims = primitives_get(); - if (val < 0) return prims->rShiftC_16s(pSrc, -val, pDst, len); - else return prims->lShiftC_16s(pSrc, val, pDst, len); + + if (val < 0) return general_rShiftC_16s(pSrc, -val, pDst, len); + else return general_lShiftC_16s(pSrc, val, pDst, len); } /* ------------------------------------------------------------------------- */ -pstatus_t general_shiftC_16u( - const UINT16 *pSrc, - INT32 val, - UINT16 *pDst, - INT32 len) +static pstatus_t general_shiftC_16u( + const UINT16* pSrc, + INT32 val, + UINT16* pDst, + INT32 len) { - primitives_t *prims; - if (val == 0) return PRIMITIVES_SUCCESS; - prims = primitives_get(); - if (val < 0) return prims->rShiftC_16u(pSrc, -val, pDst, len); - else return prims->lShiftC_16u(pSrc, val, pDst, len); + + if (val < 0) return general_rShiftC_16u(pSrc, -val, pDst, len); + else return general_lShiftC_16u(pSrc, val, pDst, len); } /* ------------------------------------------------------------------------- */ void primitives_init_shift( - primitives_t *prims) + primitives_t* prims) { /* Start with the default. */ prims->lShiftC_16s = general_lShiftC_16s; prims->rShiftC_16s = general_rShiftC_16s; prims->lShiftC_16u = general_lShiftC_16u; prims->rShiftC_16u = general_rShiftC_16u; - /* Wrappers */ prims->shiftC_16s = general_shiftC_16s; prims->shiftC_16u = general_shiftC_16u; - - primitives_init_shift_opt(prims); -} - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_shift( - primitives_t *prims) -{ - /* Nothing to do. */ } diff --git a/libfreerdp/primitives/prim_shift.h b/libfreerdp/primitives/prim_shift.h deleted file mode 100644 index a26a5037c..000000000 --- a/libfreerdp/primitives/prim_shift.h +++ /dev/null @@ -1,35 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * Shift operations. - * vi:ts=4 sw=4 - * - * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. Algorithms used by - * this code may be covered by patents by HP, Microsoft, or other parties. - * - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_SHIFT_H_INCLUDED__ -#define __PRIM_SHIFT_H_INCLUDED__ - -pstatus_t general_lShiftC_16s(const INT16 *pSrc, INT32 val, INT16 *pDst, INT32 len); -pstatus_t general_rShiftC_16s(const INT16 *pSrc, INT32 val, INT16 *pDst, INT32 len); -pstatus_t general_lShiftC_16u(const UINT16 *pSrc, INT32 val, UINT16 *pDst, INT32 len); -pstatus_t general_rShiftC_16u(const UINT16 *pSrc, INT32 val, UINT16 *pDst, INT32 len); -pstatus_t general_shiftC_16s(const INT16 *pSrc, INT32 val, INT16 *pDst, INT32 len); -pstatus_t general_shiftC_16u(const UINT16 *pSrc, INT32 val, UINT16 *pDst, INT32 len); - -void primitives_init_shift_opt(primitives_t *prims); - -#endif /* !__PRIM_SHIFT_H_INCLUDED__ */ - diff --git a/libfreerdp/primitives/prim_shift_opt.c b/libfreerdp/primitives/prim_shift_opt.c index 3f4d8acb6..df0fe2b04 100644 --- a/libfreerdp/primitives/prim_shift_opt.c +++ b/libfreerdp/primitives/prim_shift_opt.c @@ -32,23 +32,23 @@ #include "prim_internal.h" #include "prim_templates.h" -#include "prim_shift.h" +static primitives_t* generic = NULL; #ifdef WITH_SSE2 # if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) /* ------------------------------------------------------------------------- */ -SSE3_SCD_ROUTINE(sse2_lShiftC_16s, INT16, general_lShiftC_16s, - _mm_slli_epi16, *dptr++ = *sptr++ << val) +SSE3_SCD_ROUTINE(sse2_lShiftC_16s, INT16, generic->lShiftC_16s, + _mm_slli_epi16, *dptr++ = *sptr++ << val) /* ------------------------------------------------------------------------- */ -SSE3_SCD_ROUTINE(sse2_rShiftC_16s, INT16, general_rShiftC_16s, - _mm_srai_epi16, *dptr++ = *sptr++ >> val) +SSE3_SCD_ROUTINE(sse2_rShiftC_16s, INT16, generic->rShiftC_16s, + _mm_srai_epi16, *dptr++ = *sptr++ >> val) /* ------------------------------------------------------------------------- */ -SSE3_SCD_ROUTINE(sse2_lShiftC_16u, UINT16, general_lShiftC_16u, - _mm_slli_epi16, *dptr++ = *sptr++ << val) +SSE3_SCD_ROUTINE(sse2_lShiftC_16u, UINT16, generic->lShiftC_16u, + _mm_slli_epi16, *dptr++ = *sptr++ << val) /* ------------------------------------------------------------------------- */ -SSE3_SCD_ROUTINE(sse2_rShiftC_16u, UINT16, general_rShiftC_16u, - _mm_srli_epi16, *dptr++ = *sptr++ >> val) +SSE3_SCD_ROUTINE(sse2_rShiftC_16u, UINT16, generic->rShiftC_16u, + _mm_srli_epi16, *dptr++ = *sptr++ >> val) # endif /* !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) */ #endif @@ -59,22 +59,26 @@ SSE3_SCD_ROUTINE(sse2_rShiftC_16u, UINT16, general_rShiftC_16u, */ /* ------------------------------------------------------------------------- */ -void primitives_init_shift_opt(primitives_t *prims) +void primitives_init_shift_opt(primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_shift(prims); #if defined(WITH_IPP) prims->lShiftC_16s = (__lShiftC_16s_t) ippsLShiftC_16s; prims->rShiftC_16s = (__rShiftC_16s_t) ippsRShiftC_16s; prims->lShiftC_16u = (__lShiftC_16u_t) ippsLShiftC_16u; prims->rShiftC_16u = (__rShiftC_16u_t) ippsRShiftC_16u; #elif defined(WITH_SSE2) + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) - && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) { prims->lShiftC_16s = sse2_lShiftC_16s; prims->rShiftC_16s = sse2_rShiftC_16s; prims->lShiftC_16u = sse2_lShiftC_16u; prims->rShiftC_16u = sse2_rShiftC_16u; } + #endif } diff --git a/libfreerdp/primitives/prim_sign.c b/libfreerdp/primitives/prim_sign.c index 8b2bfa974..b64b297e4 100644 --- a/libfreerdp/primitives/prim_sign.c +++ b/libfreerdp/primitives/prim_sign.c @@ -21,15 +21,14 @@ #include #include "prim_internal.h" -#include "prim_sign.h" /* ---------------------------------------------------------------------------- * Set pDst to the sign-value of the 16-bit values in pSrc (-1, 0, or 1). */ -pstatus_t general_sign_16s( - const INT16 *pSrc, - INT16 *pDst, - INT32 len) +static pstatus_t general_sign_16s( + const INT16* pSrc, + INT16* pDst, + INT32 len) { while (len--) { @@ -42,18 +41,8 @@ pstatus_t general_sign_16s( /* ------------------------------------------------------------------------- */ void primitives_init_sign( - primitives_t *prims) + primitives_t* prims) { /* Start with the default. */ prims->sign_16s = general_sign_16s; - - primitives_init_sign_opt(prims); } - -/* ------------------------------------------------------------------------- */ -void primitives_deinit_sign( - primitives_t *prims) -{ - /* Nothing to do. */ -} - diff --git a/libfreerdp/primitives/prim_sign.h b/libfreerdp/primitives/prim_sign.h deleted file mode 100644 index f43eca24c..000000000 --- a/libfreerdp/primitives/prim_sign.h +++ /dev/null @@ -1,30 +0,0 @@ -/* FreeRDP: A Remote Desktop Protocol Client - * Sign operations. - * vi:ts=4 sw=4 - * - * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. Algorithms used by - * this code may be covered by patents by HP, Microsoft, or other parties. - * - */ - -#ifdef __GNUC__ -# pragma once -#endif - -#ifndef __PRIM_SIGN_H_INCLUDED__ -#define __PRIM_SIGN_H_INCLUDED__ - -pstatus_t general_sign_16s(const INT16 *pSrc, INT16 *pDst, INT32 len); - -void primitives_init_sign_opt(primitives_t *prims); - -#endif /* !__PRIM_SIGN_H_INCLUDED__ */ - diff --git a/libfreerdp/primitives/prim_sign_opt.c b/libfreerdp/primitives/prim_sign_opt.c index 635208f26..e9b03731f 100644 --- a/libfreerdp/primitives/prim_sign_opt.c +++ b/libfreerdp/primitives/prim_sign_opt.c @@ -27,29 +27,29 @@ #endif /* WITH_SSE2 */ #include "prim_internal.h" -#include "prim_sign.h" +static primitives_t* generic = NULL; #ifdef WITH_SSE2 /* ------------------------------------------------------------------------- */ -pstatus_t ssse3_sign_16s( - const INT16 *pSrc, - INT16 *pDst, - INT32 len) +static pstatus_t ssse3_sign_16s( + const INT16* pSrc, + INT16* pDst, + INT32 len) { - const INT16 *sptr = (const INT16 *) pSrc; - INT16 *dptr = (INT16 *) pDst; + const INT16* sptr = (const INT16*) pSrc; + INT16* dptr = (INT16*) pDst; size_t count; if (len < 16) { - return general_sign_16s(pSrc, pDst, len); + return generic->sign_16s(pSrc, pDst, len); } /* Check for 16-byte alignment (eventually). */ if ((ULONG_PTR) pDst & 0x01) { - return general_sign_16s(pSrc, pDst, len); + return generic->sign_16s(pSrc, pDst, len); } /* Seek 16-byte alignment. */ @@ -57,12 +57,14 @@ pstatus_t ssse3_sign_16s( { INT16 src = *sptr++; *dptr++ = (src < 0) ? (-1) : ((src > 0) ? 1 : 0); + if (--len == 0) return PRIMITIVES_SUCCESS; } /* Do 32-short chunks using 8 XMM registers. */ count = len >> 5; /* / 32 */ len -= count << 5; /* * 32 */ + if ((ULONG_PTR) sptr & 0x0f) { /* Unaligned */ @@ -73,18 +75,26 @@ pstatus_t ssse3_sign_16s( xmm1 = _mm_set1_epi16(0x0001U); xmm2 = _mm_set1_epi16(0x0001U); xmm3 = _mm_set1_epi16(0x0001U); - xmm4 = _mm_lddqu_si128((__m128i *) sptr); sptr += 8; - xmm5 = _mm_lddqu_si128((__m128i *) sptr); sptr += 8; - xmm6 = _mm_lddqu_si128((__m128i *) sptr); sptr += 8; - xmm7 = _mm_lddqu_si128((__m128i *) sptr); sptr += 8; + xmm4 = _mm_lddqu_si128((__m128i*) sptr); + sptr += 8; + xmm5 = _mm_lddqu_si128((__m128i*) sptr); + sptr += 8; + xmm6 = _mm_lddqu_si128((__m128i*) sptr); + sptr += 8; + xmm7 = _mm_lddqu_si128((__m128i*) sptr); + sptr += 8; xmm0 = _mm_sign_epi16(xmm0, xmm4); xmm1 = _mm_sign_epi16(xmm1, xmm5); xmm2 = _mm_sign_epi16(xmm2, xmm6); xmm3 = _mm_sign_epi16(xmm3, xmm7); - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 8; - _mm_store_si128((__m128i *) dptr, xmm1); dptr += 8; - _mm_store_si128((__m128i *) dptr, xmm2); dptr += 8; - _mm_store_si128((__m128i *) dptr, xmm3); dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm1); + dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm2); + dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm3); + dptr += 8; } } else @@ -97,30 +107,41 @@ pstatus_t ssse3_sign_16s( xmm1 = _mm_set1_epi16(0x0001U); xmm2 = _mm_set1_epi16(0x0001U); xmm3 = _mm_set1_epi16(0x0001U); - xmm4 = _mm_load_si128((__m128i *) sptr); sptr += 8; - xmm5 = _mm_load_si128((__m128i *) sptr); sptr += 8; - xmm6 = _mm_load_si128((__m128i *) sptr); sptr += 8; - xmm7 = _mm_load_si128((__m128i *) sptr); sptr += 8; + xmm4 = _mm_load_si128((__m128i*) sptr); + sptr += 8; + xmm5 = _mm_load_si128((__m128i*) sptr); + sptr += 8; + xmm6 = _mm_load_si128((__m128i*) sptr); + sptr += 8; + xmm7 = _mm_load_si128((__m128i*) sptr); + sptr += 8; xmm0 = _mm_sign_epi16(xmm0, xmm4); xmm1 = _mm_sign_epi16(xmm1, xmm5); xmm2 = _mm_sign_epi16(xmm2, xmm6); xmm3 = _mm_sign_epi16(xmm3, xmm7); - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 8; - _mm_store_si128((__m128i *) dptr, xmm1); dptr += 8; - _mm_store_si128((__m128i *) dptr, xmm2); dptr += 8; - _mm_store_si128((__m128i *) dptr, xmm3); dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm1); + dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm2); + dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm3); + dptr += 8; } } /* Do 8-short chunks using two XMM registers. */ count = len >> 3; len -= count << 3; + while (count--) { __m128i xmm0 = _mm_set1_epi16(0x0001U); - __m128i xmm1 = LOAD_SI128(sptr); sptr += 8; + __m128i xmm1 = LOAD_SI128(sptr); + sptr += 8; xmm0 = _mm_sign_epi16(xmm0, xmm1); - _mm_store_si128((__m128i *) dptr, xmm0); dptr += 8; + _mm_store_si128((__m128i*) dptr, xmm0); + dptr += 8; } /* Do leftovers. */ @@ -135,16 +156,20 @@ pstatus_t ssse3_sign_16s( #endif /* WITH_SSE2 */ /* ------------------------------------------------------------------------- */ -void primitives_init_sign_opt(primitives_t *prims) +void primitives_init_sign_opt(primitives_t* prims) { + generic = primitives_get_generic(); + primitives_init_sign(prims); /* Pick tuned versions if possible. */ /* I didn't spot an IPP version of this. */ #if defined(WITH_SSE2) + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3) - && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + && IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) { prims->sign_16s = ssse3_sign_16s; } + #endif } diff --git a/libfreerdp/primitives/prim_templates.h b/libfreerdp/primitives/prim_templates.h index b530637b7..b58266d08 100644 --- a/libfreerdp/primitives/prim_templates.h +++ b/libfreerdp/primitives/prim_templates.h @@ -20,7 +20,7 @@ #ifndef __PRIM_TEMPLATES_H_INCLUDED__ #define __PRIM_TEMPLATES_H_INCLUDED__ -/* These are prototypes for SSE (potentially NEON) routines that do a +/* These are prototypes for SSE (potentially NEON) routines that do a * simple SSE operation over an array of data. Since so much of this * code is shared except for the operation itself, these prototypes are * used rather than duplicating code. The naming convention depends on @@ -31,7 +31,7 @@ /* SSE3 note: If someone needs to support an SSE2 version of these without * SSE3 support, an alternative version could be added that merely checks - * that 16-byte alignment on both destination and source(s) can be + * that 16-byte alignment on both destination and source(s) can be * achieved, rather than use LDDQU for unaligned reads. */ @@ -44,373 +44,373 @@ * SCD = Source, Constant, Destination */ #define SSE3_SCD_ROUTINE(_name_, _type_, _fallback_, _op_, _slowWay_) \ -pstatus_t _name_(const _type_ *pSrc, INT32 val, _type_ *pDst, INT32 len) \ -{ \ - int shifts; \ - UINT32 offBeatMask; \ - const _type_ *sptr = pSrc; \ - _type_ *dptr = pDst; \ - size_t count; \ - if (len < 16) /* pointless if too small */ \ - { \ - return _fallback_(pSrc, val, pDst, len); \ - } \ - if (sizeof(_type_) == 1) shifts = 1; \ - else if (sizeof(_type_) == 2) shifts = 2; \ - else if (sizeof(_type_) == 4) shifts = 3; \ - else if (sizeof(_type_) == 8) shifts = 4; \ - offBeatMask = (1 << (shifts - 1)) - 1; \ - if ((ULONG_PTR) pDst & offBeatMask) \ - { \ - /* Incrementing the pointer skips over 16-byte boundary. */ \ - return _fallback_(pSrc, val, pDst, len); \ - } \ - /* Get to the 16-byte boundary now. */ \ - while ((ULONG_PTR) dptr & 0x0f) \ - { \ - _slowWay_; \ - if (--len == 0) return PRIMITIVES_SUCCESS; \ - } \ - /* Use 8 128-bit SSE registers. */ \ - count = len >> (8-shifts); \ - len -= count << (8-shifts); \ - if ((ULONG_PTR) sptr & 0x0f) \ + static pstatus_t _name_(const _type_ *pSrc, INT32 val, _type_ *pDst, INT32 len) \ { \ + INT32 shifts; \ + UINT32 offBeatMask; \ + const _type_ *sptr = pSrc; \ + _type_ *dptr = pDst; \ + size_t count; \ + if (len < 16) /* pointless if too small */ \ + { \ + return _fallback_(pSrc, val, pDst, len); \ + } \ + if (sizeof(_type_) == 1) shifts = 1; \ + else if (sizeof(_type_) == 2) shifts = 2; \ + else if (sizeof(_type_) == 4) shifts = 3; \ + else if (sizeof(_type_) == 8) shifts = 4; \ + offBeatMask = (1 << (shifts - 1)) - 1; \ + if ((ULONG_PTR) pDst & offBeatMask) \ + { \ + /* Incrementing the pointer skips over 16-byte boundary. */ \ + return _fallback_(pSrc, val, pDst, len); \ + } \ + /* Get to the 16-byte boundary now. */ \ + while ((ULONG_PTR) dptr & 0x0f) \ + { \ + _slowWay_; \ + if (--len == 0) return PRIMITIVES_SUCCESS; \ + } \ + /* Use 8 128-bit SSE registers. */ \ + count = len >> (8-shifts); \ + len -= count << (8-shifts); \ + if ((ULONG_PTR) sptr & 0x0f) \ + { \ + while (count--) \ + { \ + __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ + xmm0 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm1 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm2 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm3 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm4 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm5 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm6 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm7 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm0 = _op_(xmm0, val); \ + xmm1 = _op_(xmm1, val); \ + xmm2 = _op_(xmm2, val); \ + xmm3 = _op_(xmm3, val); \ + xmm4 = _op_(xmm4, val); \ + xmm5 = _op_(xmm5, val); \ + xmm6 = _op_(xmm6, val); \ + xmm7 = _op_(xmm7, val); \ + _mm_store_si128((__m128i *) dptr, xmm0); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm1); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm2); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm3); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm4); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm5); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm6); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm7); \ + dptr += (16/sizeof(_type_)); \ + } \ + } \ + else \ + { \ + while (count--) \ + { \ + __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ + xmm0 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm1 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm2 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm3 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm4 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm5 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm6 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm7 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm0 = _op_(xmm0, val); \ + xmm1 = _op_(xmm1, val); \ + xmm2 = _op_(xmm2, val); \ + xmm3 = _op_(xmm3, val); \ + xmm4 = _op_(xmm4, val); \ + xmm5 = _op_(xmm5, val); \ + xmm6 = _op_(xmm6, val); \ + xmm7 = _op_(xmm7, val); \ + _mm_store_si128((__m128i *) dptr, xmm0); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm1); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm2); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm3); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm4); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm5); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm6); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm7); \ + dptr += (16/sizeof(_type_)); \ + } \ + } \ + /* Use a single 128-bit SSE register. */ \ + count = len >> (5-shifts); \ + len -= count << (5-shifts); \ while (count--) \ { \ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ - xmm0 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm1 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm2 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm3 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm4 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm5 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm6 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm7 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ + __m128i xmm0 = LOAD_SI128(sptr); sptr += (16/sizeof(_type_)); \ xmm0 = _op_(xmm0, val); \ - xmm1 = _op_(xmm1, val); \ - xmm2 = _op_(xmm2, val); \ - xmm3 = _op_(xmm3, val); \ - xmm4 = _op_(xmm4, val); \ - xmm5 = _op_(xmm5, val); \ - xmm6 = _op_(xmm6, val); \ - xmm7 = _op_(xmm7, val); \ _mm_store_si128((__m128i *) dptr, xmm0); \ dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm1); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm2); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm3); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm4); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm5); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm6); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm7); \ - dptr += (16/sizeof(_type_)); \ } \ - } \ - else \ - { \ - while (count--) \ - { \ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ - xmm0 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm1 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm2 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm3 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm4 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm5 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm6 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm7 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm0 = _op_(xmm0, val); \ - xmm1 = _op_(xmm1, val); \ - xmm2 = _op_(xmm2, val); \ - xmm3 = _op_(xmm3, val); \ - xmm4 = _op_(xmm4, val); \ - xmm5 = _op_(xmm5, val); \ - xmm6 = _op_(xmm6, val); \ - xmm7 = _op_(xmm7, val); \ - _mm_store_si128((__m128i *) dptr, xmm0); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm1); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm2); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm3); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm4); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm5); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm6); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm7); \ - dptr += (16/sizeof(_type_)); \ - } \ - } \ - /* Use a single 128-bit SSE register. */ \ - count = len >> (5-shifts); \ - len -= count << (5-shifts); \ - while (count--) \ - { \ - __m128i xmm0 = LOAD_SI128(sptr); sptr += (16/sizeof(_type_)); \ - xmm0 = _op_(xmm0, val); \ - _mm_store_si128((__m128i *) dptr, xmm0); \ - dptr += (16/sizeof(_type_)); \ - } \ - /* Finish off the remainder. */ \ - while (len--) { _slowWay_; } \ - return PRIMITIVES_SUCCESS; \ -} + /* Finish off the remainder. */ \ + while (len--) { _slowWay_; } \ + return PRIMITIVES_SUCCESS; \ + } /* ---------------------------------------------------------------------------- * SCD = Source, Constant, Destination * PRE = preload xmm0 with the constant. */ #define SSE3_SCD_PRE_ROUTINE(_name_, _type_, _fallback_, _op_, _slowWay_) \ -pstatus_t _name_(const _type_ *pSrc, _type_ val, _type_ *pDst, INT32 len) \ -{ \ - int shifts; \ - UINT32 offBeatMask; \ - const _type_ *sptr = pSrc; \ - _type_ *dptr = pDst; \ - size_t count; \ - __m128i xmm0; \ - if (len < 16) /* pointless if too small */ \ - { \ - return _fallback_(pSrc, val, pDst, len); \ - } \ - if (sizeof(_type_) == 1) shifts = 1; \ - else if (sizeof(_type_) == 2) shifts = 2; \ - else if (sizeof(_type_) == 4) shifts = 3; \ - else if (sizeof(_type_) == 8) shifts = 4; \ - offBeatMask = (1 << (shifts - 1)) - 1; \ - if ((ULONG_PTR) pDst & offBeatMask) \ - { \ - /* Incrementing the pointer skips over 16-byte boundary. */ \ - return _fallback_(pSrc, val, pDst, len); \ - } \ - /* Get to the 16-byte boundary now. */ \ - while ((ULONG_PTR) dptr & 0x0f) \ - { \ - _slowWay_; \ - if (--len == 0) return PRIMITIVES_SUCCESS; \ - } \ - /* Use 4 128-bit SSE registers. */ \ - count = len >> (7-shifts); \ - len -= count << (7-shifts); \ - xmm0 = _mm_set1_epi32(val); \ - if ((ULONG_PTR) sptr & 0x0f) \ + pstatus_t _name_(const _type_ *pSrc, _type_ val, _type_ *pDst, INT32 len) \ { \ + int shifts; \ + UINT32 offBeatMask; \ + const _type_ *sptr = pSrc; \ + _type_ *dptr = pDst; \ + size_t count; \ + __m128i xmm0; \ + if (len < 16) /* pointless if too small */ \ + { \ + return _fallback_(pSrc, val, pDst, len); \ + } \ + if (sizeof(_type_) == 1) shifts = 1; \ + else if (sizeof(_type_) == 2) shifts = 2; \ + else if (sizeof(_type_) == 4) shifts = 3; \ + else if (sizeof(_type_) == 8) shifts = 4; \ + offBeatMask = (1 << (shifts - 1)) - 1; \ + if ((ULONG_PTR) pDst & offBeatMask) \ + { \ + /* Incrementing the pointer skips over 16-byte boundary. */ \ + return _fallback_(pSrc, val, pDst, len); \ + } \ + /* Get to the 16-byte boundary now. */ \ + while ((ULONG_PTR) dptr & 0x0f) \ + { \ + _slowWay_; \ + if (--len == 0) return PRIMITIVES_SUCCESS; \ + } \ + /* Use 4 128-bit SSE registers. */ \ + count = len >> (7-shifts); \ + len -= count << (7-shifts); \ + xmm0 = _mm_set1_epi32(val); \ + if ((ULONG_PTR) sptr & 0x0f) \ + { \ + while (count--) \ + { \ + __m128i xmm1, xmm2, xmm3, xmm4; \ + xmm1 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm2 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm3 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm4 = _mm_lddqu_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm1 = _op_(xmm1, xmm0); \ + xmm2 = _op_(xmm2, xmm0); \ + xmm3 = _op_(xmm3, xmm0); \ + xmm4 = _op_(xmm4, xmm0); \ + _mm_store_si128((__m128i *) dptr, xmm1); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm2); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm3); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm4); \ + dptr += (16/sizeof(_type_)); \ + } \ + } \ + else \ + { \ + while (count--) \ + { \ + __m128i xmm1, xmm2, xmm3, xmm4; \ + xmm1 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm2 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm3 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm4 = _mm_load_si128((__m128i *) sptr); \ + sptr += (16/sizeof(_type_)); \ + xmm1 = _op_(xmm1, xmm0); \ + xmm2 = _op_(xmm2, xmm0); \ + xmm3 = _op_(xmm3, xmm0); \ + xmm4 = _op_(xmm4, xmm0); \ + _mm_store_si128((__m128i *) dptr, xmm1); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm2); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm3); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm4); \ + dptr += (16/sizeof(_type_)); \ + } \ + } \ + /* Use a single 128-bit SSE register. */ \ + count = len >> (5-shifts); \ + len -= count << (5-shifts); \ while (count--) \ { \ - __m128i xmm1, xmm2, xmm3, xmm4; \ - xmm1 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm2 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm3 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm4 = _mm_lddqu_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ + __m128i xmm1 = LOAD_SI128(sptr); sptr += (16/sizeof(_type_)); \ xmm1 = _op_(xmm1, xmm0); \ - xmm2 = _op_(xmm2, xmm0); \ - xmm3 = _op_(xmm3, xmm0); \ - xmm4 = _op_(xmm4, xmm0); \ _mm_store_si128((__m128i *) dptr, xmm1); \ dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm2); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm3); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm4); \ - dptr += (16/sizeof(_type_)); \ } \ - } \ - else \ - { \ - while (count--) \ - { \ - __m128i xmm1, xmm2, xmm3, xmm4; \ - xmm1 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm2 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm3 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm4 = _mm_load_si128((__m128i *) sptr); \ - sptr += (16/sizeof(_type_)); \ - xmm1 = _op_(xmm1, xmm0); \ - xmm2 = _op_(xmm2, xmm0); \ - xmm3 = _op_(xmm3, xmm0); \ - xmm4 = _op_(xmm4, xmm0); \ - _mm_store_si128((__m128i *) dptr, xmm1); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm2); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm3); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm4); \ - dptr += (16/sizeof(_type_)); \ - } \ - } \ - /* Use a single 128-bit SSE register. */ \ - count = len >> (5-shifts); \ - len -= count << (5-shifts); \ - while (count--) \ - { \ - __m128i xmm1 = LOAD_SI128(sptr); sptr += (16/sizeof(_type_)); \ - xmm1 = _op_(xmm1, xmm0); \ - _mm_store_si128((__m128i *) dptr, xmm1); \ - dptr += (16/sizeof(_type_)); \ - } \ - /* Finish off the remainder. */ \ - while (len--) { _slowWay_; } \ - return PRIMITIVES_SUCCESS; \ -} + /* Finish off the remainder. */ \ + while (len--) { _slowWay_; } \ + return PRIMITIVES_SUCCESS; \ + } /* ---------------------------------------------------------------------------- * SSD = Source1, Source2, Destination */ #define SSE3_SSD_ROUTINE(_name_, _type_, _fallback_, _op_, _slowWay_) \ -pstatus_t _name_(const _type_ *pSrc1, const _type_ *pSrc2, _type_ *pDst, INT32 len) \ -{ \ - int shifts; \ - UINT32 offBeatMask; \ - const _type_ *sptr1 = pSrc1; \ - const _type_ *sptr2 = pSrc2; \ - _type_ *dptr = pDst; \ - size_t count; \ - if (len < 16) /* pointless if too small */ \ + pstatus_t _name_(const _type_ *pSrc1, const _type_ *pSrc2, _type_ *pDst, INT32 len) \ { \ - return _fallback_(pSrc1, pSrc2, pDst, len); \ - } \ - if (sizeof(_type_) == 1) shifts = 1; \ - else if (sizeof(_type_) == 2) shifts = 2; \ - else if (sizeof(_type_) == 4) shifts = 3; \ - else if (sizeof(_type_) == 8) shifts = 4; \ - offBeatMask = (1 << (shifts - 1)) - 1; \ - if ((ULONG_PTR) pDst & offBeatMask) \ - { \ - /* Incrementing the pointer skips over 16-byte boundary. */ \ - return _fallback_(pSrc1, pSrc2, pDst, len); \ - } \ - /* Get to the 16-byte boundary now. */ \ - while ((ULONG_PTR) dptr & 0x0f) \ - { \ - _slowWay_; \ - if (--len == 0) return PRIMITIVES_SUCCESS; \ - } \ - /* Use 4 128-bit SSE registers. */ \ - count = len >> (7-shifts); \ - len -= count << (7-shifts); \ - if (((ULONG_PTR) sptr1 & 0x0f) || ((ULONG_PTR) sptr2 & 0x0f)) \ - { \ - /* Unaligned loads */ \ + int shifts; \ + UINT32 offBeatMask; \ + const _type_ *sptr1 = pSrc1; \ + const _type_ *sptr2 = pSrc2; \ + _type_ *dptr = pDst; \ + size_t count; \ + if (len < 16) /* pointless if too small */ \ + { \ + return _fallback_(pSrc1, pSrc2, pDst, len); \ + } \ + if (sizeof(_type_) == 1) shifts = 1; \ + else if (sizeof(_type_) == 2) shifts = 2; \ + else if (sizeof(_type_) == 4) shifts = 3; \ + else if (sizeof(_type_) == 8) shifts = 4; \ + offBeatMask = (1 << (shifts - 1)) - 1; \ + if ((ULONG_PTR) pDst & offBeatMask) \ + { \ + /* Incrementing the pointer skips over 16-byte boundary. */ \ + return _fallback_(pSrc1, pSrc2, pDst, len); \ + } \ + /* Get to the 16-byte boundary now. */ \ + while ((ULONG_PTR) dptr & 0x0f) \ + { \ + _slowWay_; \ + if (--len == 0) return PRIMITIVES_SUCCESS; \ + } \ + /* Use 4 128-bit SSE registers. */ \ + count = len >> (7-shifts); \ + len -= count << (7-shifts); \ + if (((ULONG_PTR) sptr1 & 0x0f) || ((ULONG_PTR) sptr2 & 0x0f)) \ + { \ + /* Unaligned loads */ \ + while (count--) \ + { \ + __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ + xmm0 = _mm_lddqu_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm1 = _mm_lddqu_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm2 = _mm_lddqu_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm3 = _mm_lddqu_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm4 = _mm_lddqu_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm5 = _mm_lddqu_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm6 = _mm_lddqu_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm7 = _mm_lddqu_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm0 = _op_(xmm0, xmm4); \ + xmm1 = _op_(xmm1, xmm5); \ + xmm2 = _op_(xmm2, xmm6); \ + xmm3 = _op_(xmm3, xmm7); \ + _mm_store_si128((__m128i *) dptr, xmm0); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm1); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm2); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm3); \ + dptr += (16/sizeof(_type_)); \ + } \ + } \ + else \ + { \ + /* Aligned loads */ \ + while (count--) \ + { \ + __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ + xmm0 = _mm_load_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm1 = _mm_load_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm2 = _mm_load_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm3 = _mm_load_si128((__m128i *) sptr1); \ + sptr1 += (16/sizeof(_type_)); \ + xmm4 = _mm_load_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm5 = _mm_load_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm6 = _mm_load_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm7 = _mm_load_si128((__m128i *) sptr2); \ + sptr2 += (16/sizeof(_type_)); \ + xmm0 = _op_(xmm0, xmm4); \ + xmm1 = _op_(xmm1, xmm5); \ + xmm2 = _op_(xmm2, xmm6); \ + xmm3 = _op_(xmm3, xmm7); \ + _mm_store_si128((__m128i *) dptr, xmm0); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm1); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm2); \ + dptr += (16/sizeof(_type_)); \ + _mm_store_si128((__m128i *) dptr, xmm3); \ + dptr += (16/sizeof(_type_)); \ + } \ + } \ + /* Use a single 128-bit SSE register. */ \ + count = len >> (5-shifts); \ + len -= count << (5-shifts); \ while (count--) \ { \ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ - xmm0 = _mm_lddqu_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm1 = _mm_lddqu_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm2 = _mm_lddqu_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm3 = _mm_lddqu_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm4 = _mm_lddqu_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm5 = _mm_lddqu_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm6 = _mm_lddqu_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm7 = _mm_lddqu_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm0 = _op_(xmm0, xmm4); \ - xmm1 = _op_(xmm1, xmm5); \ - xmm2 = _op_(xmm2, xmm6); \ - xmm3 = _op_(xmm3, xmm7); \ + __m128i xmm0, xmm1; \ + xmm0 = LOAD_SI128(sptr1); sptr1 += (16/sizeof(_type_)); \ + xmm1 = LOAD_SI128(sptr2); sptr2 += (16/sizeof(_type_)); \ + xmm0 = _op_(xmm0, xmm1); \ _mm_store_si128((__m128i *) dptr, xmm0); \ dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm1); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm2); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm3); \ - dptr += (16/sizeof(_type_)); \ } \ - } \ - else \ - { \ - /* Aligned loads */ \ - while (count--) \ - { \ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; \ - xmm0 = _mm_load_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm1 = _mm_load_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm2 = _mm_load_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm3 = _mm_load_si128((__m128i *) sptr1); \ - sptr1 += (16/sizeof(_type_)); \ - xmm4 = _mm_load_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm5 = _mm_load_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm6 = _mm_load_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm7 = _mm_load_si128((__m128i *) sptr2); \ - sptr2 += (16/sizeof(_type_)); \ - xmm0 = _op_(xmm0, xmm4); \ - xmm1 = _op_(xmm1, xmm5); \ - xmm2 = _op_(xmm2, xmm6); \ - xmm3 = _op_(xmm3, xmm7); \ - _mm_store_si128((__m128i *) dptr, xmm0); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm1); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm2); \ - dptr += (16/sizeof(_type_)); \ - _mm_store_si128((__m128i *) dptr, xmm3); \ - dptr += (16/sizeof(_type_)); \ - } \ - } \ - /* Use a single 128-bit SSE register. */ \ - count = len >> (5-shifts); \ - len -= count << (5-shifts); \ - while (count--) \ - { \ - __m128i xmm0, xmm1; \ - xmm0 = LOAD_SI128(sptr1); sptr1 += (16/sizeof(_type_)); \ - xmm1 = LOAD_SI128(sptr2); sptr2 += (16/sizeof(_type_)); \ - xmm0 = _op_(xmm0, xmm1); \ - _mm_store_si128((__m128i *) dptr, xmm0); \ - dptr += (16/sizeof(_type_)); \ - } \ - /* Finish off the remainder. */ \ - while (len--) { _slowWay_; } \ - return PRIMITIVES_SUCCESS; \ -} + /* Finish off the remainder. */ \ + while (len--) { _slowWay_; } \ + return PRIMITIVES_SUCCESS; \ + } #endif /* !__PRIM_TEMPLATES_H_INCLUDED__ */ diff --git a/libfreerdp/primitives/primitives.c b/libfreerdp/primitives/primitives.c index dcdd5941a..3b803a676 100644 --- a/libfreerdp/primitives/primitives.c +++ b/libfreerdp/primitives/primitives.c @@ -27,61 +27,60 @@ #include "prim_internal.h" /* Singleton pointer used throughout the program when requested. */ -static primitives_t* pPrimitives = NULL; +static primitives_t pPrimitives = { 0 }; +static primitives_t pPrimitivesGeneric = { 0 }; +static BOOL pPrimitivesInitialized = FALSE; +static BOOL pPrimitivesGenericInitialized = FALSE; /* ------------------------------------------------------------------------- */ -void primitives_init(void) +static void primitives_init_generic(void) { - if (!pPrimitives) - { - pPrimitives = calloc(1, sizeof(primitives_t)); - - if (!pPrimitives) - return; - } + primitives_init_add(&pPrimitivesGeneric); + primitives_init_andor(&pPrimitivesGeneric); + primitives_init_alphaComp(&pPrimitivesGeneric); + primitives_init_copy(&pPrimitivesGeneric); + primitives_init_set(&pPrimitivesGeneric); + primitives_init_shift(&pPrimitivesGeneric); + primitives_init_sign(&pPrimitivesGeneric); + primitives_init_colors(&pPrimitivesGeneric); + primitives_init_YCoCg(&pPrimitivesGeneric); + primitives_init_YUV(&pPrimitivesGeneric); + pPrimitivesGenericInitialized = TRUE; +} +static void primitives_init(void) +{ /* Now call each section's initialization routine. */ - primitives_init_add(pPrimitives); - primitives_init_andor(pPrimitives); - primitives_init_alphaComp(pPrimitives); - primitives_init_copy(pPrimitives); - primitives_init_set(pPrimitives); - primitives_init_shift(pPrimitives); - primitives_init_sign(pPrimitives); - primitives_init_colors(pPrimitives); - primitives_init_YCoCg(pPrimitives); - primitives_init_YUV(pPrimitives); - primitives_init_16to32bpp(pPrimitives); + primitives_init_add_opt(&pPrimitives); + primitives_init_andor_opt(&pPrimitives); + primitives_init_alphaComp_opt(&pPrimitives); + primitives_init_copy_opt(&pPrimitives); + primitives_init_set_opt(&pPrimitives); + primitives_init_shift_opt(&pPrimitives); + primitives_init_sign_opt(&pPrimitives); + primitives_init_colors_opt(&pPrimitives); + primitives_init_YCoCg_opt(&pPrimitives); + primitives_init_YUV_opt(&pPrimitives); + pPrimitivesInitialized = TRUE; } /* ------------------------------------------------------------------------- */ primitives_t* primitives_get(void) { - if (!pPrimitives) + if (!pPrimitivesGenericInitialized) + primitives_init_generic(); + + if (!pPrimitivesInitialized) primitives_init(); - return pPrimitives; + return &pPrimitives; } -/* ------------------------------------------------------------------------- */ -void primitives_deinit(void) +primitives_t* primitives_get_generic(void) { - if (!pPrimitives) - return; + if (!pPrimitivesGenericInitialized) + primitives_init_generic(); - /* Call each section's de-initialization routine. */ - primitives_deinit_add(pPrimitives); - primitives_deinit_andor(pPrimitives); - primitives_deinit_alphaComp(pPrimitives); - primitives_deinit_copy(pPrimitives); - primitives_deinit_set(pPrimitives); - primitives_deinit_shift(pPrimitives); - primitives_deinit_sign(pPrimitives); - primitives_deinit_colors(pPrimitives); - primitives_deinit_YCoCg(pPrimitives); - primitives_deinit_YUV(pPrimitives); - primitives_deinit_16to32bpp(pPrimitives); - - free((void*) pPrimitives); - pPrimitives = NULL; + return &pPrimitives; } + diff --git a/libfreerdp/primitives/test/CMakeLists.txt b/libfreerdp/primitives/test/CMakeLists.txt index caf651bc5..f3b7b72e9 100644 --- a/libfreerdp/primitives/test/CMakeLists.txt +++ b/libfreerdp/primitives/test/CMakeLists.txt @@ -5,7 +5,6 @@ set(MODULE_PREFIX "TEST_FREERDP_PRIMITIVES") set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c) set(${MODULE_PREFIX}_TESTS - TestPrimitives16to32bpp.c TestPrimitivesAdd.c TestPrimitivesAlphaComp.c TestPrimitivesAndOr.c diff --git a/libfreerdp/primitives/test/TestPrimitives16to32bpp.c b/libfreerdp/primitives/test/TestPrimitives16to32bpp.c deleted file mode 100644 index ed985bdef..000000000 --- a/libfreerdp/primitives/test/TestPrimitives16to32bpp.c +++ /dev/null @@ -1,211 +0,0 @@ -/* test_colors.c - * vi:ts=4 sw=4 - * - * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "prim_test.h" - -static const int RGB_TRIAL_ITERATIONS = 1000; -static const float TEST_TIME = 4.0; - -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_RGB565ToARGB_16u32u_C3C4( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha, BOOL invert); -extern pstatus_t sse3_RGB565ToARGB_16u32u_C3C4( - const UINT16* pSrc, INT32 srcStep, - UINT32* pDst, INT32 dstStep, - UINT32 width, UINT32 height, - BOOL alpha, BOOL invert); - -/* ------------------------------------------------------------------------- */ -static BOOL try_16To32( - const UINT16 *data16, - int sOffset, - int dOffset, - int width, int height) -{ - BOOL success; - const char *sAligned = "sAlign"; - const char *sUnaligned = "s!Align"; - const char *dAligned = "dAlign"; - const char *dUnaligned = "d!Align"; - const char *sAlignStr, *dAlignStr; - const UINT16 *src; - UINT32 ALIGN(outNN1[4096+3]), ALIGN(outAN1[4096+3]), - ALIGN(outNI1[4096+3]), ALIGN(outAI1[4096+3]); -#ifdef WITH_SSE2 - UINT32 ALIGN(outNN2[4096+3]), ALIGN(outAN2[4096+3]), - ALIGN(outNI2[4096+3]), ALIGN(outAI2[4096+3]); -#endif - - assert(sOffset < 4); - assert(dOffset < 4); - assert(width*height <= 4096); - - success = TRUE; - src = data16 + sOffset; - sAlignStr = (sOffset == 0) ? sAligned : sUnaligned; - dAlignStr = (dOffset == 0) ? dAligned : dUnaligned; - - general_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outNN1+dOffset, width*sizeof(UINT32), width, height, FALSE, FALSE); - general_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outAN1+dOffset, width*sizeof(UINT32), width, height, TRUE, FALSE); - general_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outNI1+dOffset, width*sizeof(UINT32), width, height, FALSE, TRUE); - general_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outAI1+dOffset, width*sizeof(UINT32), width, height, TRUE, TRUE); - -#ifdef WITH_SSE2 - printf(" Testing 16-to-32bpp SSE3 version (%s, %s, %dx%d)\n", - sAlignStr, dAlignStr, width, height); - if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) - { - int i; - - sse3_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outNN2+dOffset, width*sizeof(UINT32), width, height, FALSE, FALSE); - sse3_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outAN2+dOffset, width*sizeof(UINT32), width, height, TRUE, FALSE); - sse3_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outNI2+dOffset, width*sizeof(UINT32), width, height, FALSE, TRUE); - sse3_RGB565ToARGB_16u32u_C3C4(src, width*sizeof(UINT16), - outAI2+dOffset, width*sizeof(UINT32), width, height, TRUE, TRUE); - for (i=0; i 0x%08x rather than 0x%08x\n", - sAlignStr, dAlignStr, data16[s], outNN2[d], outNN1[d]); - success = FALSE; - } - if (outAN1[d] != outAN2[d]) - { - printf("16To32bpp-SSE FAIL (%s, %s, alpha, !invert)" - " 0x%04x -> 0x%08x rather than 0x%08x\n", - sAlignStr, dAlignStr, data16[s], outAN2[d], outAN1[d]); - success = FALSE; - } - if (outNI1[d] != outNI2[d]) - { - printf("16To32bpp-SSE FAIL (%s, %s, !alpha, invert)" - " 0x%04x -> 0x%08x rather than 0x%08x\n", - sAlignStr, dAlignStr, data16[s], outNI2[d], outNI1[d]); - success = FALSE; - } - if (outAI1[d] != outAI2[d]) - { - printf("16To32bpp-SSE FAIL (%s, %s, alpha, invert)" - " 0x%04x -> 0x%08x rather than 0x%08x\n", - sAlignStr, dAlignStr, data16[s], outAI2[d], outNI1[d]); - success = FALSE; - } - } - } -#endif /* WITH_SSE2 */ - - return success; -} - - -/* ------------------------------------------------------------------------- */ -int test_RGB565ToARGB_16u32u_C3C4_func(void) -{ - UINT16 ALIGN(data16[4096+3]); - BOOL success; - - success = TRUE; - get_random_data(data16, sizeof(data16)); - - /* Source aligned, dest aligned, 64x64 */ - success &= try_16To32(data16, 0, 0, 64, 64); - /* Source !aligned, dest aligned, 64x64 */ - success &= try_16To32(data16, 1, 0, 64, 64); - /* Source aligned, dest !aligned, 64x64 */ - success &= try_16To32(data16, 0, 1, 64, 64); - /* Source !aligned, dest !aligned, 64x64 */ - success &= try_16To32(data16, 1, 1, 64, 64); - /* Odd size */ - success &= try_16To32(data16, 0, 0, 17, 53); - - if (success) printf("All RGB565ToARGB_16u32u_C3C4 tests passed.\n"); - return success ? SUCCESS : FAILURE; -} - -/* ------------------------------------------------------------------------- */ -STD_SPEED_TEST( - test16to32_speed, UINT16, UINT32, PRIM_NOP, - TRUE, general_RGB565ToARGB_16u32u_C3C4( - (const UINT16 *) src1, 64*2, (UINT32 *) dst, 64*4, - 64,64, TRUE, TRUE), -#ifdef WITH_SSE2 - TRUE, sse3_RGB565ToARGB_16u32u_C3C4( - (const UINT16 *) src1, 64*2, (UINT32 *) dst, 64*4, - 64,64, TRUE, TRUE), - PF_SSE3_INSTRUCTIONS_AVAILABLE, FALSE, -#else - FALSE, PRIM_NOP, 0, FALSE, -#endif - FALSE, PRIM_NOP); - -/* ------------------------------------------------------------------------- */ -int test_RGB565ToARGB_16u32u_C3C4_speed(void) -{ - UINT16 ALIGN(src[4096]); - UINT32 ALIGN(dst[4096]); - int size_array[] = { 64 }; - - get_random_data(src, sizeof(src)); - - test16to32_speed("16-to-32bpp", "aligned", - (const UINT16 *) src, 0, 0, (UINT32 *) dst, - size_array, 1, RGB_TRIAL_ITERATIONS, TEST_TIME); - return SUCCESS; -} - -int TestPrimitives16to32bpp(int argc, char* argv[]) -{ - int status; - - status = test_RGB565ToARGB_16u32u_C3C4_func(); - - if (status != SUCCESS) - return 1; - - if (g_TestPrimitivesPerformance) - { - status = test_RGB565ToARGB_16u32u_C3C4_speed(); - - if (status != SUCCESS) - return 1; - } - - return 0; -} diff --git a/libfreerdp/primitives/test/TestPrimitivesAdd.c b/libfreerdp/primitives/test/TestPrimitivesAdd.c index 08ab41ff4..ade6f49f8 100644 --- a/libfreerdp/primitives/test/TestPrimitivesAdd.c +++ b/libfreerdp/primitives/test/TestPrimitivesAdd.c @@ -20,117 +20,60 @@ #include "prim_test.h" #define FUNC_TEST_SIZE 65536 -static const int ADD16S_PRETEST_ITERATIONS = 300000*64; -static const int TEST_TIME = 2.0; // seconds - -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_add_16s( - const INT16 *pSrc1, const INT16 *pSrc2, INT16 *pDst, int len); -extern pstatus_t sse3_add_16s( - const INT16 *pSrc1, const INT16 *pSrc2, INT16 *pDst, int len); - /* ========================================================================= */ -int test_add16s_func(void) +static BOOL test_add16s_func(void) { - INT16 ALIGN(src1[FUNC_TEST_SIZE+3]), ALIGN(src2[FUNC_TEST_SIZE+3]), - ALIGN(d1[FUNC_TEST_SIZE+3]), ALIGN(d2[FUNC_TEST_SIZE+3]); - int failed = 0; -#if defined(WITH_SSE2) || defined(WITH_IPP) - int i; -#endif - char testStr[256]; + pstatus_t status; + INT16 ALIGN(src1[FUNC_TEST_SIZE + 3]), ALIGN(src2[FUNC_TEST_SIZE + 3]), + ALIGN(d1[FUNC_TEST_SIZE + 3]), ALIGN(d2[FUNC_TEST_SIZE + 3]); + + char testStr[256]; testStr[0] = '\0'; - get_random_data(src1, sizeof(src1)); - get_random_data(src2, sizeof(src2)); + winpr_RAND((BYTE*)src1, sizeof(src1)); + winpr_RAND((BYTE*)src2, sizeof(src2)); memset(d1, 0, sizeof(d1)); memset(d2, 0, sizeof(d2)); - general_add_16s(src1+1, src2+1, d1+1, FUNC_TEST_SIZE); -#ifdef WITH_SSE2 - if(IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) - { - strcat(testStr, " SSE3"); - /* Aligned */ - sse3_add_16s(src1+1, src2+1, d2+1, FUNC_TEST_SIZE); - for (i=1; i 0) ? FAILURE : SUCCESS; -} - -/* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(add16s_speed_test, INT16, INT16, dst=dst, - TRUE, general_add_16s(src1, src2, dst, size), -#ifdef WITH_SSE2 - TRUE, sse3_add_16s(src1, src2, dst, size), PF_SSE3_INSTRUCTIONS_AVAILABLE, FALSE, -#else - FALSE, PRIM_NOP, 0, FALSE, -#endif - TRUE, ippsAdd_16s(src1, src2, dst, size)); + status = generic->add_16s(src1 + 1, src2 + 1, d1 + 1, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; -int test_add16s_speed(void) + /* Unaligned */ + status = optimized->add_16s(src1 + 1, src2 + 1, d2 + 2, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_add16s_speed(void) { - INT16 ALIGN(src1[MAX_TEST_SIZE+3]), ALIGN(src2[MAX_TEST_SIZE+3]), - ALIGN(dst[MAX_TEST_SIZE+3]); - get_random_data(src1, sizeof(src1)); - get_random_data(src2, sizeof(src2)); - add16s_speed_test("add16s", "aligned", src1, src2, 0, dst, - test_sizes, NUM_TEST_SIZES, ADD16S_PRETEST_ITERATIONS, TEST_TIME); - add16s_speed_test("add16s", "unaligned", src1+1, src2+2, 0, dst, - test_sizes, NUM_TEST_SIZES, ADD16S_PRETEST_ITERATIONS, TEST_TIME); - return SUCCESS; + BYTE ALIGN(src1[MAX_TEST_SIZE + 3]), ALIGN(src2[MAX_TEST_SIZE + 3]), + ALIGN(dst[MAX_TEST_SIZE + 3]); + + if (!g_TestPrimitivesPerformance) + return TRUE; + + winpr_RAND(src1, sizeof(src1)); + winpr_RAND(src2, sizeof(src2)); + + if (!speed_test("add16s", "aligned", g_Iterations, + generic->add_16s, optimized->add_16s, + src1, src2, dst, FUNC_TEST_SIZE)) + return FALSE; + + return TRUE; } int TestPrimitivesAdd(int argc, char* argv[]) { - int status; + prim_test_setup(FALSE); + if (!test_add16s_func()) + return -1; - status = test_add16s_func(); - - if (status != SUCCESS) - return 1; - - if (g_TestPrimitivesPerformance) - { - status = test_add16s_speed(); - - if (status != SUCCESS) - return 1; - } + if (!test_add16s_speed()) + return -1; return 0; } diff --git a/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c b/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c index 18332dcb5..9919c0c4d 100644 --- a/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c +++ b/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c @@ -22,29 +22,11 @@ static const int ALPHA_PRETEST_ITERATIONS = 5000000; static const float TEST_TIME = 5.0; -extern BOOL g_TestPrimitivesPerformance; - static const int block_size[] = { 4, 64, 256 }; #define NUM_BLOCK_SIZES (sizeof(block_size)/sizeof(int)) #define MAX_BLOCK_SIZE 256 #define SIZE_SQUARED (MAX_BLOCK_SIZE*MAX_BLOCK_SIZE) -extern pstatus_t general_alphaComp_argb( - const BYTE *pSrc1, int src1Step, - const BYTE *pSrc2, int src2Step, - BYTE *pDst, int dstStep, - int width, int height); -extern pstatus_t sse2_alphaComp_argb( - const BYTE *pSrc1, int src1Step, - const BYTE *pSrc2, int src2Step, - BYTE *pDst, int dstStep, - int width, int height); -extern pstatus_t ipp_alphaComp_argb( - const BYTE *pSrc1, int src1Step, - const BYTE *pSrc2, int src2Step, - BYTE *pDst, int dstStep, - int width, int height); - /* ========================================================================= */ #define ALF(_c_) (((_c_) & 0xFF000000U) >> 24) #define RED(_c_) (((_c_) & 0x00FF0000U) >> 16) @@ -52,7 +34,7 @@ extern pstatus_t ipp_alphaComp_argb( #define BLU(_c_) ((_c_) & 0x000000FFU) #define TOLERANCE 1 #define PIXEL(_addr_, _bytes_, _x_, _y_) \ - ((UINT32 *) (((BYTE *) (_addr_)) + (_x_)*4 + (_y_)*(_bytes_))) + ((UINT32 *) (((BYTE *) (_addr_)) + (_x_)*4 + (_y_)*(_bytes_))) #define SRC1_WIDTH 6 #define SRC1_HEIGHT 6 #define SRC2_WIDTH 7 @@ -64,194 +46,165 @@ extern pstatus_t ipp_alphaComp_argb( /* ------------------------------------------------------------------------- */ static UINT32 alpha_add( - UINT32 c1, - UINT32 c2) + UINT32 c1, + UINT32 c2) { UINT32 a1 = ALF(c1); UINT32 r1 = RED(c1); UINT32 g1 = GRN(c1); UINT32 b1 = BLU(c1); - UINT32 a2 = ALF(c2); UINT32 r2 = RED(c2); UINT32 g2 = GRN(c2); UINT32 b2 = BLU(c2); - - UINT32 a3 = ((a1 * a1 + (255-a1) * a2) / 255) & 0xff; - UINT32 r3 = ((a1 * r1 + (255-a1) * r2) / 255) & 0xff; - UINT32 g3 = ((a1 * g1 + (255-a1) * g2) / 255) & 0xff; - UINT32 b3 = ((a1 * b1 + (255-a1) * b2) / 255) & 0xff; - + UINT32 a3 = ((a1 * a1 + (255 - a1) * a2) / 255) & 0xff; + UINT32 r3 = ((a1 * r1 + (255 - a1) * r2) / 255) & 0xff; + UINT32 g3 = ((a1 * g1 + (255 - a1) * g2) / 255) & 0xff; + UINT32 b3 = ((a1 * b1 + (255 - a1) * b2) / 255) & 0xff; return (a3 << 24) | (r3 << 16) | (g3 << 8) | b3; } /* ------------------------------------------------------------------------- */ static UINT32 colordist( - UINT32 c1, - UINT32 c2) + UINT32 c1, + UINT32 c2) { int d, maxd = 0; - d = ABS(ALF(c1) - ALF(c2)); + if (d > maxd) maxd = d; + d = ABS(RED(c1) - RED(c2)); + if (d > maxd) maxd = d; + d = ABS(GRN(c1) - GRN(c2)); + if (d > maxd) maxd = d; + d = ABS(BLU(c1) - BLU(c2)); + if (d > maxd) maxd = d; + return maxd; } /* ------------------------------------------------------------------------- */ -int test_alphaComp_func(void) +static BOOL check(const BYTE* pSrc1, INT32 src1Step, + const BYTE* pSrc2, INT32 src2Step, + BYTE* pDst, INT32 dstStep, + INT32 width, INT32 height) { - UINT32 ALIGN(src1[SRC1_WIDTH*SRC1_HEIGHT]); - UINT32 ALIGN(src2[SRC2_WIDTH*SRC2_HEIGHT]); - UINT32 ALIGN(dst1[DST_WIDTH*DST_HEIGHT]); - UINT32 ALIGN(dst2a[DST_WIDTH*DST_HEIGHT]); - UINT32 ALIGN(dst2u[DST_WIDTH*DST_HEIGHT+1]); - UINT32 ALIGN(dst3[DST_WIDTH*DST_HEIGHT]); - int error = 0; - char testStr[256]; - UINT32 *ptr; - int i, x, y; + UINT32 x, y; + for (y = 0; y < height; ++y) + { + for (x = 0; x < width; ++x) + { + UINT32 s1 = *PIXEL(pSrc1, src1Step, x, y); + UINT32 s2 = *PIXEL(pSrc2, src2Step, x, y); + UINT32 c0 = alpha_add(s1, s2); + UINT32 c1 = *PIXEL(pDst, dstStep, x, y); + if (colordist(c0, c1) > TOLERANCE) + { + printf("alphaComp-general: [%d,%d] 0x%08x+0x%08x=0x%08x, got 0x%08x\n", + x, y, s1, s2, c0, c1); + return FALSE; + } + } + } + + return TRUE; +} + +static BOOL test_alphaComp_func(void) +{ + pstatus_t status; + BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]); + BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]); + BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]); + char testStr[256]; + UINT32* ptr; + UINT32 i; testStr[0] = '\0'; - get_random_data(src1, sizeof(src1)); + winpr_RAND((BYTE*)src1, sizeof(src1)); /* Special-case the first two values */ src1[0] &= 0x00FFFFFFU; src1[1] |= 0xFF000000U; - get_random_data(src2, sizeof(src2)); + winpr_RAND((BYTE*)src2, sizeof(src2)); + /* Set the second operand to fully-opaque. */ - ptr = src2; - for (i=0; ialphaComp_argb(src1, 4 * SRC1_WIDTH, + src2, 4 * SRC2_WIDTH, + dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT); + if (status != PRIMITIVES_SUCCESS) + return FALSE; - for (y=0; y TOLERANCE) - { - printf("alphaComp-general: [%d,%d] 0x%08x+0x%08x=0x%08x, got 0x%08x\n", - x, y, s1, s2, c0, c1); - error = 1; - } -#ifdef WITH_SSE2 - if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) - { - UINT32 c2 = *PIXEL(dst2a, 4*DST_WIDTH, x, y); - if (colordist(c0, c2) > TOLERANCE) - { - printf("alphaComp-SSE-aligned: [%d,%d] 0x%08x+0x%08x=0x%08x, got 0x%08x\n", - x, y, s1, s2, c0, c2); - error = 1; - } - c2 = *PIXEL(dst2u+1, 4*DST_WIDTH, x, y); - if (colordist(c0, c2) > TOLERANCE) - { - printf("alphaComp-SSE-unaligned: [%d,%d] 0x%08x+0x%08x=0x%08x, got 0x%08x\n", - x, y, s1, s2, c0, c2); - error = 1; - } - } -#endif /* i386 */ -#ifdef WITH_IPP - { - UINT32 c3 = *PIXEL(dst3, 4*DST_WIDTH, x, y); - if (colordist(c0, c3) > TOLERANCE) - { - printf("alphaComp-IPP: [%d,%d] 0x%08x+0x%08x=0x%08x, got 0x%08x\n", - x, y, s1, s2, c0, c3); - error = 1; - } - } -#endif - } - } - if (!error) printf("All alphaComp tests passed (%s).\n", testStr); - return (error > 0) ? FAILURE : SUCCESS; + if (!check(src1, 4 * SRC1_WIDTH, + src2, 4 * SRC2_WIDTH, + dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT)) + return FALSE; + + status = optimized->alphaComp_argb((const BYTE*) src1, 4 * SRC1_WIDTH, + (const BYTE*) src2, 4 * SRC2_WIDTH, + (BYTE*) dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check(src1, 4 * SRC1_WIDTH, + src2, 4 * SRC2_WIDTH, + dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT)) + return FALSE; + + return TRUE; } - -/* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(alphaComp_speed, BYTE, BYTE, int bytes __attribute__((unused)) = size*4, - TRUE, general_alphaComp_argb(src1, bytes, src2, bytes, dst, bytes, - size, size), -#ifdef WITH_SSE2 - TRUE, sse2_alphaComp_argb(src1, bytes, src2, bytes, dst, bytes, - size, size), PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, -#else - FALSE, PRIM_NOP, 0, FALSE, -#endif - TRUE, ipp_alphaComp_argb(src1, bytes, src2, bytes, dst, bytes, - size, size)); - -int test_alphaComp_speed(void) +static int test_alphaComp_speed(void) { - INT32 ALIGN(src1[MAX_BLOCK_SIZE*(MAX_BLOCK_SIZE+1)]), - ALIGN(src2[SIZE_SQUARED]), - ALIGN(dst[SIZE_SQUARED]); + BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]); + BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]); + BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]); + char testStr[256]; + UINT32* ptr; + UINT32 i; + testStr[0] = '\0'; + winpr_RAND((BYTE*)src1, sizeof(src1)); + /* Special-case the first two values */ + src1[0] &= 0x00FFFFFFU; + src1[1] |= 0xFF000000U; + winpr_RAND((BYTE*)src2, sizeof(src2)); - get_random_data(src1, sizeof(src1)); - get_random_data(src2, sizeof(src2)); + /* Set the second operand to fully-opaque. */ + ptr = (UINT32*)src2; - alphaComp_speed("alphaComp", "aligned", - (BYTE *) src1, (BYTE *) src2, 0, (BYTE *) dst, - block_size, NUM_BLOCK_SIZES, ALPHA_PRETEST_ITERATIONS, TEST_TIME); - alphaComp_speed("alphaComp", "unaligned", - (BYTE *) src1+1, (BYTE *) src2, 0, (BYTE *) dst, - block_size, NUM_BLOCK_SIZES, ALPHA_PRETEST_ITERATIONS, TEST_TIME); + for (i = 0; i < sizeof(src2) / 4; ++i) *ptr++ |= 0xFF000000U; - return SUCCESS; + memset(dst1, 0, sizeof(dst1)); + + if (!speed_test("add16s", "aligned", g_Iterations, + generic->alphaComp_argb, optimized->alphaComp_argb, + src1, 4 * SRC1_WIDTH, + src2, 4 * SRC2_WIDTH, + dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT)) + return FALSE; + + return TRUE; } int TestPrimitivesAlphaComp(int argc, char* argv[]) { - int status; + prim_test_setup(FALSE); + if (!test_alphaComp_func()) + return -1; - status = test_alphaComp_func(); - - if (status != SUCCESS) - return 1; - - if (g_TestPrimitivesPerformance) - { - status = test_alphaComp_speed(); - - if (status != SUCCESS) - return 1; - } + if (!test_alphaComp_speed()) + return -1; return 0; } diff --git a/libfreerdp/primitives/test/TestPrimitivesAndOr.c b/libfreerdp/primitives/test/TestPrimitivesAndOr.c index 24d73d43a..bf16d269d 100644 --- a/libfreerdp/primitives/test/TestPrimitivesAndOr.c +++ b/libfreerdp/primitives/test/TestPrimitivesAndOr.c @@ -23,200 +23,158 @@ static const int ANDOR_PRETEST_ITERATIONS = 100000; static const int TEST_TIME = 2.0; // seconds -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_andC_32u(const UINT32 *pSrc, UINT32 val, - UINT32 *pDst, int len); -extern pstatus_t sse3_andC_32u(const UINT32 *pSrc, UINT32 val, - UINT32 *pDst, int len); -extern pstatus_t general_orC_32u(const UINT32 *pSrc, UINT32 val, - UINT32 *pDst, int len); -extern pstatus_t sse3_orC_32u(const UINT32 *pSrc, UINT32 val, - UINT32 *pDst, int len); - #define VALUE (0xA5A5A5A5U) /* ========================================================================= */ -int test_and_32u_func(void) +static BOOL test_and_32u_func(void) { - UINT32 ALIGN(src[FUNC_TEST_SIZE+3]), ALIGN(dst[FUNC_TEST_SIZE+3]); + UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]); int failed = 0; int i; char testStr[256]; - testStr[0] = '\0'; - get_random_data(src, sizeof(src)); - general_andC_32u(src+1, VALUE, dst+1, FUNC_TEST_SIZE); + winpr_RAND(src, sizeof(src)); + generic->andC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE); strcat(testStr, " general"); - for (i=1; i<=FUNC_TEST_SIZE; ++i) + + for (i = 1; i <= FUNC_TEST_SIZE; ++i) { if (dst[i] != (src[i] & VALUE)) - { - printf("AND-general FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", - i, src[i], VALUE, src[i] & VALUE, dst[i]); + { + printf("AND-general FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", + i, src[i], VALUE, src[i] & VALUE, dst[i]); ++failed; } } + #ifdef WITH_SSE2 + if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) { strcat(testStr, " SSE3"); /* Aligned */ memset(dst, 0, sizeof(dst)); - sse3_andC_32u(src+1, VALUE, dst+1, FUNC_TEST_SIZE); - for (i=1; i<=FUNC_TEST_SIZE; ++i) + sse3_andC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE); + + for (i = 1; i <= FUNC_TEST_SIZE; ++i) { if (dst[i] != (src[i] & VALUE)) - { - printf("AND-SSE-aligned FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", - i, src[i], VALUE, src[i] & VALUE, dst[i]); + { + printf("AND-SSE-aligned FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", + i, src[i], VALUE, src[i] & VALUE, dst[i]); ++failed; } } + /* Unaligned */ memset(dst, 0, sizeof(dst)); - sse3_andC_32u(src+1, VALUE, dst+2, FUNC_TEST_SIZE); - for (i=1; i<=FUNC_TEST_SIZE; ++i) + sse3_andC_32u(src + 1, VALUE, dst + 2, FUNC_TEST_SIZE); + + for (i = 1; i <= FUNC_TEST_SIZE; ++i) { - if (dst[i+1] != (src[i] & VALUE)) - { - printf("AND-SSE-unaligned FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", - i, src[i], VALUE, src[i] & VALUE, dst[i+1]); + if (dst[i + 1] != (src[i] & VALUE)) + { + printf("AND-SSE-unaligned FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", + i, src[i], VALUE, src[i] & VALUE, dst[i + 1]); ++failed; } } } + #endif /* i386 */ + if (!failed) printf("All and_32u tests passed (%s).\n", testStr); + return (failed > 0) ? FAILURE : SUCCESS; } /* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(andC_32u_speed_test, UINT32, UINT32, dst=dst, - TRUE, general_andC_32u(src1, constant, dst, size), -#ifdef WITH_SSE2 - TRUE, sse3_andC_32u(src1, constant, dst, size), PF_SSE3_INSTRUCTIONS_AVAILABLE, FALSE, -#else - FALSE, PRIM_NOP, 0, FALSE, -#endif - TRUE, ippsAndC_32u(src1, constant, dst, size)) - -int test_and_32u_speed(void) +static BOOL test_and_32u_speed(void) { - UINT32 ALIGN(src[MAX_TEST_SIZE+3]), ALIGN(dst[MAX_TEST_SIZE+3]); - get_random_data(src, sizeof(src)); + UINT32 ALIGN(src[MAX_TEST_SIZE + 3]), ALIGN(dst[MAX_TEST_SIZE + 3]); + winpr_RAND(src, sizeof(src)); andC_32u_speed_test("and32u", "aligned", src, NULL, VALUE, dst, - test_sizes, NUM_TEST_SIZES, ANDOR_PRETEST_ITERATIONS, TEST_TIME); - andC_32u_speed_test("and32u", "unaligned", src+1, NULL, VALUE, dst, - test_sizes, NUM_TEST_SIZES, ANDOR_PRETEST_ITERATIONS, TEST_TIME); + test_sizes, NUM_TEST_SIZES, ANDOR_PRETEST_ITERATIONS, TEST_TIME); + andC_32u_speed_test("and32u", "unaligned", src + 1, NULL, VALUE, dst, + test_sizes, NUM_TEST_SIZES, ANDOR_PRETEST_ITERATIONS, TEST_TIME); return SUCCESS; } /* ========================================================================= */ -int test_or_32u_func(void) +static BOOL check(const UINT32* src, const UINT32* dst, UINT32 size, UINT32 value) { - UINT32 ALIGN(src[FUNC_TEST_SIZE+3]), ALIGN(dst[FUNC_TEST_SIZE+3]); - int failed = 0; - int i; - char testStr[256]; + UINT32 i; + UINT32 failed = 0; - testStr[0] = '\0'; - get_random_data(src, sizeof(src)); - general_orC_32u(src+1, VALUE, dst+1, FUNC_TEST_SIZE); - strcat(testStr, " general"); - for (i=1; i<=FUNC_TEST_SIZE; ++i) + for (i = 1; i <= size; ++i) { - if (dst[i] != (src[i] | VALUE)) - { - printf("OR-general general FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", - i, src[i], VALUE, src[i] | VALUE, dst[i]); - ++failed; + if (dst[i] != (src[i] | value)) + { + printf("OR-general general FAIL[%d] 0x%08x&0x%08x=0x%08x, got 0x%08x\n", + i, src[i], value, src[i] | value, dst[i]); + ++failed; } } -#ifdef WITH_SSE2 - if(IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) - { - strcat(testStr, " SSE3"); - /* Aligned */ - memset(dst, 0, sizeof(dst)); - sse3_orC_32u(src+1, VALUE, dst+1, FUNC_TEST_SIZE); - for (i=1; i 0) ? FAILURE : SUCCESS; + + return TRUE; } - -/* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(orC_32u_speed_test, UINT32, UINT32, dst=dst, - TRUE, general_orC_32u(src1, constant, dst, size), -#ifdef WITH_SSE2 - TRUE, sse3_orC_32u(src1, constant, dst, size), PF_SSE3_INSTRUCTIONS_AVAILABLE, FALSE, -#else - FALSE, PRIM_NOP, 0, FALSE, -#endif - TRUE, ippsOrC_32u(src1, constant, dst, size)) -int test_or_32u_speed(void) +static BOOL test_or_32u_func(void) { - UINT32 ALIGN(src[MAX_TEST_SIZE+3]), ALIGN(dst[MAX_TEST_SIZE+3]); - get_random_data(src, sizeof(src)); - orC_32u_speed_test("or32u", "aligned", src, NULL, VALUE, dst, - test_sizes, NUM_TEST_SIZES, ANDOR_PRETEST_ITERATIONS, TEST_TIME); - orC_32u_speed_test("or32u", "unaligned", src+1, NULL, VALUE, dst, - test_sizes, NUM_TEST_SIZES, ANDOR_PRETEST_ITERATIONS, TEST_TIME); - return SUCCESS; + pstatus_t status; + UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]); + char testStr[256]; + testStr[0] = '\0'; + winpr_RAND((BYTE*)src, sizeof(src)); + + status = generic->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE)) + return FALSE; + + status = optimized->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE)) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_or_32u_speed(void) +{ + UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]); + char testStr[256]; + testStr[0] = '\0'; + winpr_RAND((BYTE*)src, sizeof(src)); + + if (!speed_test("add16s", "aligned", g_Iterations, + generic->orC_32u, optimized->orC_32u, + src + 1, VALUE, dst + 1, FUNC_TEST_SIZE)) + return FALSE; + + return TRUE; } int TestPrimitivesAndOr(int argc, char* argv[]) { - int status; + prim_test_setup(FALSE); - status = test_and_32u_func(); + if (!test_and_32u_func()) + return -1; - if (status != SUCCESS) - return 1; + if (!test_and_32u_speed()) + return -1; - if (g_TestPrimitivesPerformance) - { - status = test_and_32u_speed(); + if (!test_or_32u_func()) + return -1; - if (status != SUCCESS) - return 1; - } - - status = test_or_32u_func(); - - if (status != SUCCESS) - return 1; - - if (g_TestPrimitivesPerformance) - { - status = test_or_32u_speed(); - - if (status != SUCCESS) - return 1; - } + if (!test_or_32u_speed()) + return -1; return 0; } diff --git a/libfreerdp/primitives/test/TestPrimitivesColors.c b/libfreerdp/primitives/test/TestPrimitivesColors.c index 717328246..e6c520927 100644 --- a/libfreerdp/primitives/test/TestPrimitivesColors.c +++ b/libfreerdp/primitives/test/TestPrimitivesColors.c @@ -23,19 +23,6 @@ static const int RGB_TRIAL_ITERATIONS = 1000; static const int YCBCR_TRIAL_ITERATIONS = 1000; static const float TEST_TIME = 4.0; -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_RGBToRGB_16s8u_P3AC4R(const INT16 *pSrc[3], - int srcStep, BYTE *pDst, int dstStep, const prim_size_t *roi); -extern pstatus_t sse2_RGBToRGB_16s8u_P3AC4R(const INT16 *pSrc[3], - int srcStep, BYTE *pDst, int dstStep, const prim_size_t *roi); -extern pstatus_t general_yCbCrToRGB_16s16s_P3P3(const INT16 *pSrc[3], - int srcStep, INT16 *pDst[3], int dstStep, const prim_size_t *roi); -extern pstatus_t sse2_yCbCrToRGB_16s16s_P3P3(const INT16 *pSrc[3], - int srcStep, INT16 *pDst[3], int dstStep, const prim_size_t *roi); -extern pstatus_t neon_yCbCrToRGB_16s16s_P3P3(const INT16 *pSrc[3], - int srcStep, INT16 *pDst[3], int dstStep, const prim_size_t *roi); - /* ------------------------------------------------------------------------- */ int test_RGBToRGB_16s8u_P3AC4R_func(void) { @@ -47,15 +34,15 @@ int test_RGBToRGB_16s8u_P3AC4R_func(void) int i; int failed = 0; char testStr[256]; - INT16 *ptrs[3]; + INT16* ptrs[3]; prim_size_t roi = { 64, 64 }; - testStr[0] = '\0'; - get_random_data(r, sizeof(r)); - get_random_data(g, sizeof(g)); - get_random_data(b, sizeof(b)); + winpr_RAND((BYTE*)r, sizeof(r)); + winpr_RAND((BYTE*)g, sizeof(g)); + winpr_RAND((BYTE*)b, sizeof(b)); + /* clear upper bytes */ - for (i=0; i<4096; ++i) + for (i = 0; i < 4096; ++i) { r[i] &= 0x00FFU; g[i] &= 0x00FFU; @@ -65,58 +52,62 @@ int test_RGBToRGB_16s8u_P3AC4R_func(void) ptrs[0] = r; ptrs[1] = g; ptrs[2] = b; - - general_RGBToRGB_16s8u_P3AC4R((const INT16 **) ptrs, 64*2, - (BYTE *) out1, 64*4, &roi); + generic->RGBToRGB_16s8u_P3AC4R((const INT16**) ptrs, 64 * 2, + (BYTE*) out1, 64 * 4, &roi); #ifdef WITH_SSE2 + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) { strcat(testStr, " SSE2"); - sse2_RGBToRGB_16s8u_P3AC4R((const INT16 **) ptrs, 64*2, - (BYTE *) out2, 64*4, &roi); - for (i=0; i<4096; ++i) + sse2_RGBToRGB_16s8u_P3AC4R((const INT16**) ptrs, 64 * 2, + (BYTE*) out2, 64 * 4, &roi); + + for (i = 0; i < 4096; ++i) { if (out1[i] != out2[i]) { printf("RGBToRGB-SSE FAIL: out1[%d]=0x%08x out2[%d]=0x%08x\n", - i, out1[i], i, out2[i]); + i, out1[i], i, out2[i]); failed = 1; } } } + #endif /* i386 */ + if (!failed) printf("All RGBToRGB_16s8u_P3AC4R tests passed (%s).\n", testStr); + return (failed > 0) ? FAILURE : SUCCESS; } /* ------------------------------------------------------------------------- */ static const prim_size_t roi64x64 = { 64, 64 }; STD_SPEED_TEST( - rgb_to_argb_speed, INT16*, UINT32, dst=dst, - TRUE, general_RGBToRGB_16s8u_P3AC4R( - (const INT16 **) src1, 64*2, (BYTE *) dst, 64*4, &roi64x64), + rgb_to_argb_speed, INT16*, UINT32, dst = dst, + TRUE, generic->RGBToRGB_16s8u_P3AC4R( + (const INT16**) src1, 64 * 2, (BYTE*) dst, 64 * 4, &roi64x64), #ifdef WITH_SSE2 - TRUE, sse2_RGBToRGB_16s8u_P3AC4R( - (const INT16 **) src1, 64*2, (BYTE *) dst, 64*4, &roi64x64), - PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, + TRUE, sse2_RGBToRGB_16s8u_P3AC4R( + (const INT16**) src1, 64 * 2, (BYTE*) dst, 64 * 4, &roi64x64), + PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - FALSE, dst=dst); + FALSE, dst = dst); int test_RGBToRGB_16s8u_P3AC4R_speed(void) { INT16 ALIGN(r[4096]), ALIGN(g[4096]), ALIGN(b[4096]); UINT32 ALIGN(dst[4096]); int i; - INT16 *ptrs[3]; + INT16* ptrs[3]; int size_array[] = { 64 }; + winpr_RAND((BYTE*)r, sizeof(r)); + winpr_RAND((BYTE*)g, sizeof(g)); + winpr_RAND((BYTE*)b, sizeof(b)); - get_random_data(r, sizeof(r)); - get_random_data(g, sizeof(g)); - get_random_data(b, sizeof(b)); /* clear upper bytes */ - for (i=0; i<4096; ++i) + for (i = 0; i < 4096; ++i) { r[i] &= 0x00FFU; g[i] &= 0x00FFU; @@ -126,10 +117,9 @@ int test_RGBToRGB_16s8u_P3AC4R_speed(void) ptrs[0] = r; ptrs[1] = g; ptrs[2] = b; - - rgb_to_argb_speed("RGBToARGB", "aligned", - (const INT16 **) ptrs, NULL, 0, dst, - size_array, 1, RGB_TRIAL_ITERATIONS, TEST_TIME); + rgb_to_argb_speed("RGBToARGB", "aligned", + (const INT16**) ptrs, NULL, 0, dst, + size_array, 1, RGB_TRIAL_ITERATIONS, TEST_TIME); return SUCCESS; } @@ -142,29 +132,29 @@ int test_yCbCrToRGB_16s16s_P3P3_func(void) int i; int failed = 0; char testStr[256]; - const INT16 *in[3]; - INT16 *out1[3]; - INT16 *out2[3]; + const INT16* in[3]; + INT16* out1[3]; + INT16* out2[3]; prim_size_t roi = { 64, 64 }; - testStr[0] = '\0'; - get_random_data(y, sizeof(y)); - get_random_data(cb, sizeof(cb)); - get_random_data(cr, sizeof(cr)); + winpr_RAND((BYTE*)y, sizeof(y)); + winpr_RAND((BYTE*)cb, sizeof(cb)); + winpr_RAND((BYTE*)cr, sizeof(cr)); + /* Normalize to 11.5 fixed radix */ - for (i=0; i<4096; ++i) + for (i = 0; i < 4096; ++i) { y[i] &= 0x1FE0U; cb[i] &= 0x1FE0U; cr[i] &= 0x1FE0U; } + memset(r1, 0, sizeof(r1)); memset(g1, 0, sizeof(g1)); memset(b1, 0, sizeof(b1)); memset(r2, 0, sizeof(r2)); memset(g2, 0, sizeof(g2)); memset(b2, 0, sizeof(b2)); - in[0] = y; in[1] = cb; in[2] = cr; @@ -174,58 +164,63 @@ int test_yCbCrToRGB_16s16s_P3P3_func(void) out2[0] = r2; out2[1] = g2; out2[2] = b2; - - general_yCbCrToRGB_16s16s_P3P3(in, 64*2, out1, 64*2, &roi); + generic->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out1, 64 * 2, &roi); #ifdef WITH_SSE2 + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) { strcat(testStr, " SSE2"); - sse2_yCbCrToRGB_16s16s_P3P3(in, 64*2, out2, 64*2, &roi); - for (i=0; i<4096; ++i) + sse2_yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out2, 64 * 2, &roi); + + for (i = 0; i < 4096; ++i) { - if ((ABS(r1[i]-r2[i]) > 1) - || (ABS(g1[i]-g2[i]) > 1) - || (ABS(b1[i]-b2[i]) > 1)) { + if ((ABS(r1[i] - r2[i]) > 1) + || (ABS(g1[i] - g2[i]) > 1) + || (ABS(b1[i] - b2[i]) > 1)) + { printf("YCbCrToRGB-SSE FAIL[%d]: %d,%d,%d vs %d,%d,%d\n", i, - r1[i],g1[i],b1[i], r2[i],g2[i],b2[i]); + r1[i], g1[i], b1[i], r2[i], g2[i], b2[i]); failed = 1; } } } + #endif /* i386 */ + if (!failed) printf("All yCbCrToRGB_16s16s_P3P3 tests passed (%s).\n", testStr); + return (failed > 0) ? FAILURE : SUCCESS; } /* ------------------------------------------------------------------------- */ STD_SPEED_TEST( - ycbcr_to_rgb_speed, INT16*, INT16*, dst=dst, - TRUE, general_yCbCrToRGB_16s16s_P3P3(src1, 64*2, dst, 64*2, &roi64x64), + ycbcr_to_rgb_speed, INT16*, INT16*, dst = dst, + TRUE, generic->yCbCrToRGB_16s16s_P3P3(src1, 64 * 2, dst, 64 * 2, &roi64x64), #ifdef WITH_SSE2 - TRUE, sse2_yCbCrToRGB_16s16s_P3P3(src1, 64*2, dst, 64*2, &roi64x64), - PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, + TRUE, sse2_yCbCrToRGB_16s16s_P3P3(src1, 64 * 2, dst, 64 * 2, &roi64x64), + PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, #elif defined(WITH_NEON) - TRUE, neon_yCbCrToRGB_16s16s_P3P3(src1, 64*2, dst, 64*2, &roi64x64), - PF_ARM_NEON_INSTRUCTIONS_AVAILABLE, FALSE, + TRUE, neon_yCbCrToRGB_16s16s_P3P3(src1, 64 * 2, dst, 64 * 2, &roi64x64), + PF_ARM_NEON_INSTRUCTIONS_AVAILABLE, FALSE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - FALSE, dst=dst); + FALSE, dst = dst); -int test_yCbCrToRGB_16s16s_P3P3_speed(void) +static int test_yCbCrToRGB_16s16s_P3P3_speed(void) { INT16 ALIGN(y[4096]), ALIGN(cb[4096]), ALIGN(cr[4096]); INT16 ALIGN(r[4096]), ALIGN(g[4096]), ALIGN(b[4096]); int i; - const INT16 *input[3]; - INT16 *output[3]; + const INT16* input[3]; + INT16* output[3]; int size_array[] = { 64 }; + winpr_RAND((BYTE*)y, sizeof(y)); + winpr_RAND((BYTE*)cb, sizeof(cb)); + winpr_RAND((BYTE*)cr, sizeof(cr)); - get_random_data(y, sizeof(y)); - get_random_data(cb, sizeof(cb)); - get_random_data(cr, sizeof(cr)); /* Normalize to 11.5 fixed radix */ - for (i=0; i<4096; ++i) + for (i = 0; i < 4096; ++i) { y[i] &= 0x1FE0U; cb[i] &= 0x1FE0U; @@ -238,16 +233,14 @@ int test_yCbCrToRGB_16s16s_P3P3_speed(void) output[0] = r; output[1] = g; output[2] = b; - ycbcr_to_rgb_speed("yCbCrToRGB", "aligned", input, NULL, NULL, output, - size_array, 1, YCBCR_TRIAL_ITERATIONS, TEST_TIME); + size_array, 1, YCBCR_TRIAL_ITERATIONS, TEST_TIME); return SUCCESS; } int TestPrimitivesColors(int argc, char* argv[]) { int status; - status = test_RGBToRGB_16s8u_P3AC4R_func(); if (status != SUCCESS) diff --git a/libfreerdp/primitives/test/TestPrimitivesCopy.c b/libfreerdp/primitives/test/TestPrimitivesCopy.c index 189969d7c..9220efea7 100644 --- a/libfreerdp/primitives/test/TestPrimitivesCopy.c +++ b/libfreerdp/primitives/test/TestPrimitivesCopy.c @@ -22,75 +22,73 @@ static const int MEMCPY_PRETEST_ITERATIONS = 1000000; static const int TEST_TIME = 1.0; // seconds #define COPY_TESTSIZE (256*2+16*2+15+15) -#if 0 -extern pstatus_t sse3_copy_8u(const BYTE *pSrc, BYTE *pDst, int len); -#endif - -extern BOOL g_TestPrimitivesPerformance; /* ------------------------------------------------------------------------- */ -int test_copy8u_func(void) +static int test_copy8u_func(void) { - primitives_t *prims = primitives_get(); - BYTE ALIGN(data[COPY_TESTSIZE+15]); + primitives_t* prims = primitives_get(); + BYTE ALIGN(data[COPY_TESTSIZE + 15]); int i, soff; int failed = 0; char testStr[256]; - BYTE ALIGN(dest[COPY_TESTSIZE+15]); - + BYTE ALIGN(dest[COPY_TESTSIZE + 15]); testStr[0] = '\0'; - get_random_data(data, sizeof(data)); - + winpr_RAND(data, sizeof(data)); strcat(testStr, " ptr"); - for (soff=0; soff<16; ++soff) + + for (soff = 0; soff < 16; ++soff) { int doff; - for (doff=0; doff<16; ++doff) + + for (doff = 0; doff < 16; ++doff) { int length; - for (length=1; length<=COPY_TESTSIZE-doff; ++length) + + for (length = 1; length <= COPY_TESTSIZE - doff; ++length) { memset(dest, 0, sizeof(dest)); - prims->copy_8u(data+soff, dest+doff, length); - for (i=0; icopy_8u(data + soff, dest + doff, length); + + for (i = 0; i < length; ++i) { - if (dest[i+doff] != data[i+soff]) + if (dest[i + doff] != data[i + soff]) { printf("COPY8U FAIL: off=%d len=%d, dest[%d]=0x%02x" - "data[%d]=0x%02x\n", - doff, length, i+doff, dest[i+doff], - i+soff, data[i+soff]); + "data[%d]=0x%02x\n", + doff, length, i + doff, dest[i + doff], + i + soff, data[i + soff]); failed = 1; } } } } } + if (!failed) printf("All copy8 tests passed (%s).\n", testStr); + return (failed > 0) ? FAILURE : SUCCESS; } /* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(copy8u_speed_test, BYTE, BYTE, dst=dst, - TRUE, memcpy(dst, src1, size), - FALSE, PRIM_NOP, 0, FALSE, - TRUE, ippsCopy_8u(src1, dst, size)); +STD_SPEED_TEST(copy8u_speed_test, BYTE, BYTE, dst = dst, + TRUE, memcpy(dst, src1, size), + FALSE, PRIM_NOP, 0, FALSE, + TRUE, ippsCopy_8u(src1, dst, size)); int test_copy8u_speed(void) { - BYTE ALIGN(src[MAX_TEST_SIZE+4]); - BYTE ALIGN(dst[MAX_TEST_SIZE+4]); + BYTE ALIGN(src[MAX_TEST_SIZE + 4]); + BYTE ALIGN(dst[MAX_TEST_SIZE + 4]); copy8u_speed_test("copy8u", "aligned", src, NULL, 0, dst, - test_sizes, NUM_TEST_SIZES, MEMCPY_PRETEST_ITERATIONS, TEST_TIME); - copy8u_speed_test("copy8u", "unaligned", src+1, NULL, 0, dst, - test_sizes, NUM_TEST_SIZES, MEMCPY_PRETEST_ITERATIONS, TEST_TIME); + test_sizes, NUM_TEST_SIZES, MEMCPY_PRETEST_ITERATIONS, TEST_TIME); + copy8u_speed_test("copy8u", "unaligned", src + 1, NULL, 0, dst, + test_sizes, NUM_TEST_SIZES, MEMCPY_PRETEST_ITERATIONS, TEST_TIME); return SUCCESS; } int TestPrimitivesCopy(int argc, char* argv[]) { int status; - status = test_copy8u_func(); if (status != SUCCESS) diff --git a/libfreerdp/primitives/test/TestPrimitivesSet.c b/libfreerdp/primitives/test/TestPrimitivesSet.c index 2111d65c3..208e11e6e 100644 --- a/libfreerdp/primitives/test/TestPrimitivesSet.c +++ b/libfreerdp/primitives/test/TestPrimitivesSet.c @@ -23,331 +23,263 @@ static const int MEMSET8_PRETEST_ITERATIONS = 100000000; static const int MEMSET32_PRETEST_ITERATIONS = 40000000; static const float TEST_TIME = 1.0; -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_set_8u(BYTE val, BYTE *pDst, int len); -extern pstatus_t sse2_set_8u(BYTE val, BYTE *pDst, int len); -extern pstatus_t general_set_32s(INT32 val, INT32 *pDst, int len); -extern pstatus_t sse2_set_32s(INT32 val, INT32 *pDst, int len); -extern pstatus_t general_set_32u(UINT32 val, UINT32 *pDst, int len); -extern pstatus_t sse2_set_32u(UINT32 val, UINT32 *pDst, int len); -extern pstatus_t ipp_wrapper_set_32u(UINT32 val, UINT32 *pDst, int len); - static const int set_sizes[] = { 1, 4, 16, 32, 64, 256, 1024, 4096 }; #define NUM_SET_SIZES (sizeof(set_sizes)/sizeof(int)) /* ------------------------------------------------------------------------- */ -int test_set8u_func(void) +static BOOL check8(const BYTE* src, UINT32 length, UINT32 offset, BYTE value) { -#if defined(WITH_SSE2) || defined(WITH_IPP) - BYTE ALIGN(dest[48]); - int off; -#endif - int failed = 0; - char testStr[256]; - testStr[0] = '\0'; - -#ifdef WITH_SSE2 - /* Test SSE under various alignments */ - if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) + UINT32 i; + for (i = 0; i < length; ++i) { - strcat(testStr, " SSE2"); - for (off=0; off<16; ++off) + if (src[offset + i] != value) { - int len; - for (len=1; len<48-off; ++len) - { - int i; - memset(dest, 0, sizeof(dest)); - sse2_set_8u(0xa5, dest+off, len); - for (i=0; iset_8u(0xa5, dest + off, len); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check8(dest, len, off, 0xa8)) + return FALSE; } } -#endif /* WITH_IPP */ - if (!failed) printf("All set8u tests passed (%s).\n", testStr); - return (failed > 0) ? FAILURE : SUCCESS; -} - -/* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(set8u_speed_test, BYTE, BYTE, dst=dst, - TRUE, memset(dst, constant, size), - FALSE, PRIM_NOP, 0, FALSE, - TRUE, ippsSet_8u(constant, dst, size)); - -int test_set8u_speed(void) -{ - BYTE ALIGN(dst[MAX_TEST_SIZE]); - set8u_speed_test("set8u", "aligned", NULL, NULL, 0xA5, dst, - set_sizes, NUM_SET_SIZES, MEMSET8_PRETEST_ITERATIONS, TEST_TIME); - return SUCCESS; -} - -/* ------------------------------------------------------------------------- */ -int test_set32s_func(void) -{ -#if defined(WITH_SSE2) || defined(WITH_IPP) - INT32 ALIGN(dest[512]); - int off; -#endif - int failed = 0; - char testStr[256]; - testStr[0] = '\0'; - -#ifdef WITH_SSE2 - /* Test SSE under various alignments */ - if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) + for (off = 0; off < 16; ++off) { - strcat(testStr, " SSE2"); - for (off=0; off<16; ++off) { - int len; - for (len=1; len<512-off; ++len) - { - int i; - memset(dest, 0, sizeof(dest)); - sse2_set_32s(0xdeadbeef, dest+off, len); - for (i=0; iset_8u(0xa5, dest + off, len); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check8(dest, len, off, 0xa8)) + return FALSE; } } -#endif /* WITH_IPP */ - if (!failed) printf("All set32s tests passed (%s).\n", testStr); - return (failed > 0) ? FAILURE : SUCCESS; + return TRUE; } /* ------------------------------------------------------------------------- */ -int test_set32u_func(void) +static BOOL test_set8u_speed(void) { -#if defined(WITH_SSE2) || defined(WITH_IPP) - UINT32 ALIGN(dest[512]); - int off; -#endif - int failed = 0; - char testStr[256]; - testStr[0] = '\0'; + BYTE dest[1024]; + BYTE value; + UINT32 x; -#ifdef WITH_SSE2 - /* Test SSE under various alignments */ - if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) + for (x=0; x<16; x++) { - strcat(testStr, " SSE2"); - for (off=0; off<16; ++off) { - int len; - for (len=1; len<512-off; ++len) - { - int i; - memset(dest, 0, sizeof(dest)); - sse2_set_32u(0xdeadbeefU, dest+off, len); - for (i=0; iset_8u, optimized->set_8u, + value, dest + x, len)) + return FALSE; } -#endif /* i386 */ -#ifdef WITH_IPP - strcat(testStr, " IPP"); - for (off=0; off<16; ++off) { - int len; - for (len=1; len<512-off; ++len) + return TRUE; +} + +static BOOL check32s(const INT32* src, UINT32 length, UINT32 offset, INT32 value) +{ + UINT32 i; + for (i = 0; i < length; ++i) + { + if (src[offset + i] != value) { - int i; - memset(dest, 0, sizeof(dest)); - ipp_wrapper_set_32u(0xdeadbeefU, dest+off, len); - for (i=0; i 0) ? FAILURE : SUCCESS; + return TRUE; } /* ------------------------------------------------------------------------- */ -static INLINE void memset32u_naive( - UINT32 val, - UINT32 *dst, - size_t count) +static BOOL test_set32s_func(void) { - while (count--) *dst++ = val; + pstatus_t status; + UINT32 off; + INT32 dest[1024]; + const INT32 value = -0x12345678; + + for (off = 0; off < 16; ++off) + { + UINT32 len; + + memset(dest, 0, sizeof(dest)); + for (len = 1; len < 48 - off; ++len) + { + status = generic->set_32s(value, dest + off, len); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32s(dest, len, off, value)) + return FALSE; + } + } + + for (off = 0; off < 16; ++off) + { + UINT32 len; + + memset(dest, 0, sizeof(dest)); + for (len = 1; len < 48 - off; ++len) + { + status = optimized->set_32s(value, dest + off, len); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32s(dest, len, off, value)) + return FALSE; + } + } + + return TRUE; +} + +static BOOL check32u(const UINT32* src, UINT32 length, UINT32 offset, UINT32 value) +{ + UINT32 i; + for (i = 0; i < length; ++i) + { + if (src[offset + i] != value) + { + printf("SET8U FAILED: off=%d len=%d dest[%d]=0x%08x\n", + offset, length, i + offset, src[i + offset]); + return FALSE; + } + } + + return TRUE; } /* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(set32u_speed_test, UINT32, UINT32, dst=dst, - TRUE, memset32u_naive(constant, dst, size), -#ifdef WITH_SSE2 - TRUE, sse2_set_32u(constant, dst, size), PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, -#else - FALSE, PRIM_NOP, 0, FALSE, -#endif - TRUE, ipp_wrapper_set_32u(constant, dst, size)); - -int test_set32u_speed(void) +static BOOL test_set32u_func(void) { - UINT32 ALIGN(dst[MAX_TEST_SIZE+1]); - set32u_speed_test("set32u", "aligned", NULL, NULL, 0xdeadbeef, dst, - set_sizes, NUM_SET_SIZES, MEMSET32_PRETEST_ITERATIONS, TEST_TIME); -#if 0 - /* Not really necessary; should be almost as fast. */ - set32u_speed_test("set32u", "unaligned", NULL, NULL, dst+1, - set_sizes, NUM_SET_SIZES, MEMSET32_PRETEST_ITERATIONS, TEST_TIME); -#endif - return SUCCESS; + pstatus_t status; + UINT32 off; + UINT32 dest[1024]; + const UINT32 value = 0xABCDEF12; + + for (off = 0; off < 16; ++off) + { + UINT32 len; + + memset(dest, 0, sizeof(dest)); + for (len = 1; len < 48 - off; ++len) + { + status = generic->set_32u(value, dest + off, len); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32u(dest, len, off, value)) + return FALSE; + } + } + + for (off = 0; off < 16; ++off) + { + UINT32 len; + + memset(dest, 0, sizeof(dest)); + for (len = 1; len < 48 - off; ++len) + { + status = optimized->set_32u(value, dest + off, len); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32u(dest, len, off, value)) + return FALSE; + } + } + + return TRUE; } /* ------------------------------------------------------------------------- */ -static INLINE void memset32s_naive( - INT32 val, - INT32 *dst, - size_t count) +static BOOL test_set32u_speed(void) { - while (count--) *dst++ = val; + UINT32 dest[1024]; + BYTE value; + UINT32 x; + + for (x=0; x<16; x++) + { + winpr_RAND(&value, sizeof(value)); + if (!speed_test("set_32u", "", g_Iterations, + generic->set_32u, optimized->set_32u, + value, dest + x, len)) + return FALSE; + } + + return TRUE; } /* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(set32s_speed_test, INT32, INT32, dst=dst, - TRUE, memset32s_naive(constant, dst, size), -#ifdef WITH_SSE2 - TRUE, sse2_set_32s(constant, dst, size), PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, -#else - FALSE, PRIM_NOP, 0, FALSE, -#endif - TRUE, ippsSet_32s(constant, dst, size)); - -int test_set32s_speed(void) +static BOOL test_set32s_speed(void) { - INT32 ALIGN(dst[MAX_TEST_SIZE+1]); - set32s_speed_test("set32s", "aligned", NULL, NULL, 0xdeadbeef, dst, - set_sizes, NUM_SET_SIZES, MEMSET32_PRETEST_ITERATIONS, TEST_TIME); -#if 0 - /* Not really necessary; should be almost as fast. */ - set32s_speed_test("set32s", "unaligned", NULL, NULL, dst+1, - set_sizes, NUM_SET_SIZES, MEMSET32_PRETEST_ITERATIONS, TEST_TIME); -#endif - return SUCCESS; + INT32 dest[1024]; + BYTE value; + UINT32 x; + + for (x=0; x<16; x++) + { + winpr_RAND(&value, sizeof(value)); + if (!speed_test("set_32s", "", g_Iterations, + generic->set_32s, optimized->set_32s, + value, dest + x, len)) + return FALSE; + } + + return TRUE; } int TestPrimitivesSet(int argc, char* argv[]) { - int status; + prim_test_setup(FALSE); - status = test_set8u_func(); + if (!test_set8u_func()) + return -1; - if (status != SUCCESS) - return 1; + if (!test_set8u_speed()) + return -1; - if (g_TestPrimitivesPerformance) - { - status = test_set8u_speed(); + if (!test_set32s_func()) + return -1; - if (status != SUCCESS) - return 1; - } + if (!test_set32s_speed()) + return -1; - status = test_set32s_func(); + if (!test_set32u_func()) + return -1; - if (status != SUCCESS) - return 1; - - if (g_TestPrimitivesPerformance) - { - status = test_set32s_speed(); - - if (status != SUCCESS) - return 1; - } - - status = test_set32u_func(); - - if (status != SUCCESS) - return 1; - - if (g_TestPrimitivesPerformance) - { - status = test_set32u_speed(); - - if (status != SUCCESS) - return 1; - } + if (!test_set32u_speed()) + return -1; return 0; } diff --git a/libfreerdp/primitives/test/TestPrimitivesShift.c b/libfreerdp/primitives/test/TestPrimitivesShift.c index 693c12b34..4316cadf6 100644 --- a/libfreerdp/primitives/test/TestPrimitivesShift.c +++ b/libfreerdp/primitives/test/TestPrimitivesShift.c @@ -23,177 +23,153 @@ static const int SHIFT_PRETEST_ITERATIONS = 50000; static const float TEST_TIME = 1.0; -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_lShiftC_16s( - const INT16 *pSrc, int val, INT16 *pDst, int len); -extern pstatus_t general_rShiftC_16s( - const INT16 *pSrc, int val, INT16 *pDst, int len); -extern pstatus_t general_shiftC_16s( - const INT16 *pSrc, int val, INT16 *pDst, int len); -extern pstatus_t general_lShiftC_16u( - const UINT16 *pSrc, int val, UINT16 *pDst, int len); -extern pstatus_t general_rShiftC_16u( - const UINT16 *pSrc, int val, UINT16 *pDst, int len); -extern pstatus_t general_shiftC_16u( - const UINT16 *pSrc, int val, UINT16 *pDst, int len); -extern pstatus_t sse2_lShiftC_16s( - const INT16 *pSrc, int val, INT16 *pDst, int len); -extern pstatus_t sse2_rShiftC_16s( - const INT16 *pSrc, int val, INT16 *pDst, int len); -extern pstatus_t sse2_shiftC_16s( - const INT16 *pSrc, int val, INT16 *pDst, int len); -extern pstatus_t sse2_lShiftC_16u( - const UINT16 *pSrc, int val, UINT16 *pDst, int len); -extern pstatus_t sse2_rShiftC_16u( - const UINT16 *pSrc, int val, UINT16 *pDst, int len); -extern pstatus_t sse2_shiftC_16u( - const UINT16 *pSrc, int val, UINT16 *pDst, int len); - #ifdef WITH_SSE2 #define SHIFT_TEST_FUNC(_name_, _type_, _str_, _f1_, _f2_) \ -int _name_(void) \ -{ \ - _type_ ALIGN(src[FUNC_TEST_SIZE+3]), \ - ALIGN(d1[FUNC_TEST_SIZE+3]), ALIGN(d2[FUNC_TEST_SIZE+3]); \ - int failed = 0; \ - int i; \ - char testStr[256]; \ - testStr[0] = '\0'; \ - get_random_data(src, sizeof(src)); \ - _f1_(src+1, 3, d1+1, FUNC_TEST_SIZE); \ - if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) \ + int _name_(void) \ { \ - strcat(testStr, " SSE3"); \ - /* Aligned */ \ - _f2_(src+1, 3, d2+1, FUNC_TEST_SIZE); \ - for (i=1; i<=FUNC_TEST_SIZE; ++i) \ + _type_ ALIGN(src[FUNC_TEST_SIZE+3]), \ + ALIGN(d1[FUNC_TEST_SIZE+3]), ALIGN(d2[FUNC_TEST_SIZE+3]); \ + int failed = 0; \ + int i; \ + char testStr[256]; \ + testStr[0] = '\0'; \ + get_random_data(src, sizeof(src)); \ + _f1_(src+1, 3, d1+1, FUNC_TEST_SIZE); \ + if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) \ { \ - if (d1[i] != d2[i]) \ - { \ - printf("%s-SSE-aligned FAIL[%d]: 0x%x>>3=0x%x, got 0x%x\n", \ - _str_, i, src[i], d1[i], d2[i]); \ - ++failed; \ + strcat(testStr, " SSE3"); \ + /* Aligned */ \ + _f2_(src+1, 3, d2+1, FUNC_TEST_SIZE); \ + for (i=1; i<=FUNC_TEST_SIZE; ++i) \ + { \ + if (d1[i] != d2[i]) \ + { \ + printf("%s-SSE-aligned FAIL[%d]: 0x%x>>3=0x%x, got 0x%x\n", \ + _str_, i, src[i], d1[i], d2[i]); \ + ++failed; \ + } \ + } \ + /* Unaligned */ \ + _f2_(src+1, 3, d2+2, FUNC_TEST_SIZE); \ + for (i=1; i<=FUNC_TEST_SIZE; ++i) \ + { \ + if (d1[i] != d2[i+1]) \ + { \ + printf("%s-SSE-unaligned FAIL[%d]: 0x%x>>3=0x%x, got 0x%x\n", \ + _str_, i, src[i], d1[i], d2[i+1]); \ + ++failed; \ + } \ } \ } \ - /* Unaligned */ \ - _f2_(src+1, 3, d2+2, FUNC_TEST_SIZE); \ - for (i=1; i<=FUNC_TEST_SIZE; ++i) \ - { \ - if (d1[i] != d2[i+1]) \ - { \ - printf("%s-SSE-unaligned FAIL[%d]: 0x%x>>3=0x%x, got 0x%x\n", \ - _str_, i, src[i], d1[i], d2[i+1]); \ - ++failed; \ - } \ - } \ - } \ - if (!failed) printf("All %s tests passed (%s).\n", _str_, testStr); \ - return (failed > 0) ? FAILURE : SUCCESS; \ -} + if (!failed) printf("All %s tests passed (%s).\n", _str_, testStr); \ + return (failed > 0) ? FAILURE : SUCCESS; \ + } #else #define SHIFT_TEST_FUNC(_name_, _type_, _str_, _f1_, _f2_) \ -int _name_(void) \ -{ \ - return SUCCESS; \ -} + int _name_(void) \ + { \ + return SUCCESS; \ + } #endif /* i386 */ SHIFT_TEST_FUNC(test_lShift_16s_func, INT16, "lshift_16s", general_lShiftC_16s, - sse2_lShiftC_16s) + sse2_lShiftC_16s) SHIFT_TEST_FUNC(test_lShift_16u_func, UINT16, "lshift_16u", general_lShiftC_16u, - sse2_lShiftC_16u) + sse2_lShiftC_16u) SHIFT_TEST_FUNC(test_rShift_16s_func, INT16, "rshift_16s", general_rShiftC_16s, - sse2_rShiftC_16s) + sse2_rShiftC_16s) SHIFT_TEST_FUNC(test_rShift_16u_func, UINT16, "rshift_16u", general_rShiftC_16u, - sse2_rShiftC_16u) + sse2_rShiftC_16u) /* ========================================================================= */ -STD_SPEED_TEST(speed_lShift_16s, INT16, INT16, dst=dst, - TRUE, general_lShiftC_16s(src1, constant, dst, size), +STD_SPEED_TEST(speed_lShift_16s, INT16, INT16, dst = dst, + TRUE, general_lShiftC_16s(src1, constant, dst, size), #ifdef WITH_SSE2 - TRUE, sse2_lShiftC_16s(src1, constant, dst, size), PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, + TRUE, sse2_lShiftC_16s(src1, constant, dst, size), + PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - TRUE, ippsLShiftC_16s(src1, constant, dst, size)); -STD_SPEED_TEST(speed_lShift_16u, UINT16, UINT16, dst=dst, - TRUE, general_lShiftC_16u(src1, constant, dst, size), + TRUE, ippsLShiftC_16s(src1, constant, dst, size)); +STD_SPEED_TEST(speed_lShift_16u, UINT16, UINT16, dst = dst, + TRUE, general_lShiftC_16u(src1, constant, dst, size), #ifdef WITH_SSE2 - TRUE, sse2_lShiftC_16u(src1, constant, dst, size), PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, + TRUE, sse2_lShiftC_16u(src1, constant, dst, size), + PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - TRUE, ippsLShiftC_16u(src1, constant, dst, size)); -STD_SPEED_TEST(speed_rShift_16s, INT16, INT16, dst=dst, - TRUE, general_rShiftC_16s(src1, constant, dst, size), + TRUE, ippsLShiftC_16u(src1, constant, dst, size)); +STD_SPEED_TEST(speed_rShift_16s, INT16, INT16, dst = dst, + TRUE, general_rShiftC_16s(src1, constant, dst, size), #ifdef WITH_SSE2 - TRUE, sse2_rShiftC_16s(src1, constant, dst, size), PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, + TRUE, sse2_rShiftC_16s(src1, constant, dst, size), + PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - TRUE, ippsRShiftC_16s(src1, constant, dst, size)); -STD_SPEED_TEST(speed_rShift_16u, UINT16, UINT16, dst=dst, - TRUE, general_rShiftC_16u(src1, constant, dst, size), + TRUE, ippsRShiftC_16s(src1, constant, dst, size)); +STD_SPEED_TEST(speed_rShift_16u, UINT16, UINT16, dst = dst, + TRUE, general_rShiftC_16u(src1, constant, dst, size), #ifdef WITH_SSE2 - TRUE, sse2_rShiftC_16u(src1, constant, dst, size), PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, + TRUE, sse2_rShiftC_16u(src1, constant, dst, size), + PF_SSE2_INSTRUCTIONS_AVAILABLE, FALSE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - TRUE, ippsRShiftC_16u(src1, constant, dst, size)); + TRUE, ippsRShiftC_16u(src1, constant, dst, size)); /* ------------------------------------------------------------------------- */ int test_lShift_16s_speed(void) { - INT16 ALIGN(src[MAX_TEST_SIZE+1]), ALIGN(dst[MAX_TEST_SIZE+1]); - get_random_data(src, sizeof(src)); + INT16 ALIGN(src[MAX_TEST_SIZE + 1]), ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(src, sizeof(src)); speed_lShift_16s("lShift_16s", "aligned", src, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); - speed_lShift_16s("lShift_16s", "unaligned", src+1, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + speed_lShift_16s("lShift_16s", "unaligned", src + 1, NULL, 3, dst, + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); return SUCCESS; } /* ------------------------------------------------------------------------- */ int test_lShift_16u_speed(void) { - UINT16 ALIGN(src[MAX_TEST_SIZE+1]), ALIGN(dst[MAX_TEST_SIZE+1]); - get_random_data(src, sizeof(src)); + UINT16 ALIGN(src[MAX_TEST_SIZE + 1]), ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(src, sizeof(src)); speed_lShift_16u("lShift_16u", "aligned", src, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); - speed_lShift_16u("lShift_16u", "unaligned", src+1, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + speed_lShift_16u("lShift_16u", "unaligned", src + 1, NULL, 3, dst, + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); return SUCCESS; } /* ------------------------------------------------------------------------- */ int test_rShift_16s_speed(void) { - INT16 ALIGN(src[MAX_TEST_SIZE+1]), ALIGN(dst[MAX_TEST_SIZE+1]); - get_random_data(src, sizeof(src)); + INT16 ALIGN(src[MAX_TEST_SIZE + 1]), ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(src, sizeof(src)); speed_rShift_16s("rShift_16s", "aligned", src, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); - speed_rShift_16s("rShift_16s", "unaligned", src+1, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + speed_rShift_16s("rShift_16s", "unaligned", src + 1, NULL, 3, dst, + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); return SUCCESS; } /* ------------------------------------------------------------------------- */ int test_rShift_16u_speed(void) { - UINT16 ALIGN(src[MAX_TEST_SIZE+1]), ALIGN(dst[MAX_TEST_SIZE+1]); - get_random_data(src, sizeof(src)); + UINT16 ALIGN(src[MAX_TEST_SIZE + 1]), ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(src, sizeof(src)); speed_rShift_16u("rShift_16u", "aligned", src, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); - speed_rShift_16u("rShift_16u", "unaligned", src+1, NULL, 3, dst, - test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); + speed_rShift_16u("rShift_16u", "unaligned", src + 1, NULL, 3, dst, + test_sizes, NUM_TEST_SIZES, SHIFT_PRETEST_ITERATIONS, TEST_TIME); return SUCCESS; } int TestPrimitivesShift(int argc, char* argv[]) { int status; - status = test_lShift_16s_func(); if (status != SUCCESS) diff --git a/libfreerdp/primitives/test/TestPrimitivesSign.c b/libfreerdp/primitives/test/TestPrimitivesSign.c index 0d06d64bc..0496283e7 100644 --- a/libfreerdp/primitives/test/TestPrimitivesSign.c +++ b/libfreerdp/primitives/test/TestPrimitivesSign.c @@ -22,15 +22,8 @@ static const int SIGN_PRETEST_ITERATIONS = 100000; static const float TEST_TIME = 1.0; -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_sign_16s(const INT16 *pSrc, INT16 *pDst, int len); -#ifdef WITH_SSE2 -extern pstatus_t ssse3_sign_16s(const INT16 *pSrc, INT16 *pDst, int len); -#endif - /* ------------------------------------------------------------------------- */ -int test_sign16s_func(void) +static int test_sign16s_func(void) { INT16 ALIGN(src[65535]), ALIGN(d1[65535]); #ifdef WITH_SSE2 @@ -39,75 +32,80 @@ int test_sign16s_func(void) #endif int failed = 0; char testStr[256]; - /* Test when we can reach 16-byte alignment */ testStr[0] = '\0'; - get_random_data(src, sizeof(src)); - general_sign_16s(src+1, d1+1, 65535); + winpr_RAND(src, sizeof(src)); + general_sign_16s(src + 1, d1 + 1, 65535); #ifdef WITH_SSE2 + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3)) { strcat(testStr, " SSSE3"); - ssse3_sign_16s(src+1, d2+1, 65535); - for (i=1; i<65535; ++i) + ssse3_sign_16s(src + 1, d2 + 1, 65535); + + for (i = 1; i < 65535; ++i) { if (d1[i] != d2[i]) - { - printf("SIGN16s-SSE-aligned FAIL[%d] of %d: want %d, got %d\n", - i, src[i], d1[i], d2[i]); + { + printf("SIGN16s-SSE-aligned FAIL[%d] of %d: want %d, got %d\n", + i, src[i], d1[i], d2[i]); ++failed; } } } -#endif /* i386 */ +#endif /* i386 */ /* Test when we cannot reach 16-byte alignment */ - get_random_data(src, sizeof(src)); - general_sign_16s(src+1, d1+2, 65535); + winpr_RAND(src, sizeof(src)); + general_sign_16s(src + 1, d1 + 2, 65535); #ifdef WITH_SSE2 + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3)) { - ssse3_sign_16s(src+1, d2+2, 65535); - for (i=2; i<65535; ++i) + ssse3_sign_16s(src + 1, d2 + 2, 65535); + + for (i = 2; i < 65535; ++i) { if (d1[i] != d2[i]) - { - printf("SIGN16s-SSE-unaligned FAIL[%d] of %d: want %d, got %d\n", - i, src[i-1], d1[i], d2[i]); + { + printf("SIGN16s-SSE-unaligned FAIL[%d] of %d: want %d, got %d\n", + i, src[i - 1], d1[i], d2[i]); ++failed; } } } + #endif /* i386 */ + if (!failed) printf("All sign16s tests passed (%s).\n", testStr); + return (failed > 0) ? FAILURE : SUCCESS; } /* ------------------------------------------------------------------------- */ -STD_SPEED_TEST(sign16s_speed_test, INT16, INT16, dst=dst, - TRUE, general_sign_16s(src1, dst, size), +STD_SPEED_TEST(sign16s_speed_test, INT16, INT16, dst = dst, + TRUE, general_sign_16s(src1, dst, size), #ifdef WITH_SSE2 - TRUE, ssse3_sign_16s(src1, dst, size), PF_EX_SSSE3, TRUE, + TRUE, ssse3_sign_16s(src1, dst, size), PF_EX_SSSE3, TRUE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - FALSE, dst=dst); + FALSE, dst = dst); -int test_sign16s_speed(void) +static int test_sign16s_speed(void) { - INT16 ALIGN(src[MAX_TEST_SIZE+3]), ALIGN(dst[MAX_TEST_SIZE+3]); - get_random_data(src, sizeof(src)); + INT16 ALIGN(src[MAX_TEST_SIZE + 3]), ALIGN(dst[MAX_TEST_SIZE + 3]); + winpr_RAND(src, sizeof(src)); sign16s_speed_test("sign16s", "aligned", src, NULL, 0, dst, - test_sizes, NUM_TEST_SIZES, SIGN_PRETEST_ITERATIONS, TEST_TIME); - sign16s_speed_test("sign16s", "unaligned", src+1, NULL, 0, dst, - test_sizes, NUM_TEST_SIZES, SIGN_PRETEST_ITERATIONS, TEST_TIME); + test_sizes, NUM_TEST_SIZES, SIGN_PRETEST_ITERATIONS, TEST_TIME); + sign16s_speed_test("sign16s", "unaligned", src + 1, NULL, 0, dst, + test_sizes, NUM_TEST_SIZES, SIGN_PRETEST_ITERATIONS, TEST_TIME); return SUCCESS; } int TestPrimitivesSign(int argc, char* argv[]) { int status; - status = test_sign16s_func(); if (status != SUCCESS) diff --git a/libfreerdp/primitives/test/TestPrimitivesYCbCr.c b/libfreerdp/primitives/test/TestPrimitivesYCbCr.c index c9f24b9a2..7aead8493 100644 --- a/libfreerdp/primitives/test/TestPrimitivesYCbCr.c +++ b/libfreerdp/primitives/test/TestPrimitivesYCbCr.c @@ -2079,12 +2079,12 @@ static UINT32 TEST_XRGB_IMAGE[4096] = 0xFF169ff8, 0xFF159ef7, 0xFF149df7, 0xFF139cf6, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5 }; -static int test_bmp_cmp_count(const BYTE* mem1, const BYTE* mem2, int size, int channel, int margin) +static int test_bmp_cmp_count(const BYTE* mem1, const BYTE* mem2, int size, + int channel, int margin) { int error; int count = 0; int index = 0; - size /= 4; mem1 += channel; mem2 += channel; @@ -2106,17 +2106,18 @@ static int test_bmp_cmp_count(const BYTE* mem1, const BYTE* mem2, int size, int return count; } -static int test_bmp_cmp_dump(const BYTE* actual, const BYTE* expected, int size, int channel, int margin) +static int test_bmp_cmp_dump(const BYTE* actual, const BYTE* expected, int size, + int channel, int margin) { int x, y; int error[3]; - UINT32 pixel; + UINT32 pixel = 0; int count = 0; int index = 0; BYTE R, G, B; BYTE eR, eG, eB; INT16 Y, Cb, Cr; - + R = G = B = eR = eG = eB = 0; size /= 4; actual += channel; expected += channel; @@ -2126,18 +2127,14 @@ static int test_bmp_cmp_dump(const BYTE* actual, const BYTE* expected, int size, if (*actual != *expected) { pixel = *((UINT32*) &actual[-channel]); - GetRGB32(R, G, B, pixel); - + pixel = GetColor(PIXEL_FORMAT_XRGB32, R, G, B, 0xff); pixel = *((UINT32*) &expected[-channel]); - GetRGB32(eR, eG, eB, pixel); - + pixel = GetColor(PIXEL_FORMAT_XRGB32, eR, eG, eB, 0xFF); Y = TEST_Y_COMPONENT[index]; Cb = TEST_CB_COMPONENT[index]; Cr = TEST_CR_COMPONENT[index]; - x = index % 64; y = (index - x) / 64; - error[0] = (R > eR) ? R - eR : eR - R; error[1] = (G > eG) ? G - eG : eG - G; error[2] = (B > eB) ? B - eB : eB - B; @@ -2145,7 +2142,7 @@ static int test_bmp_cmp_dump(const BYTE* actual, const BYTE* expected, int size, if ((error[0] > margin) || (error[1] > margin) || (error[2] > margin)) { printf("(%2d,%2d) Y: %+5d Cb: %+5d Cr: %+5d R: %03d/%03d G: %03d/%03d B: %03d/%03d %d %d %d\n", - x, y, Y, Cb, Cr, R, eR, G, eG, B, eB, R - eR, G - eG, B - eB); + x, y, Y, Cb, Cr, R, eR, G, eG, B, eB, R - eR, G - eG, B - eB); count++; } } @@ -2157,11 +2154,11 @@ static int test_bmp_cmp_dump(const BYTE* actual, const BYTE* expected, int size, return count; } -static void test_fill_bitmap_channel(BYTE* data, int width, int height, BYTE value, int nChannel) +static void test_fill_bitmap_channel(BYTE* data, int width, int height, + BYTE value, int nChannel) { int x, y; BYTE* pChannel; - pChannel = data + nChannel; for (y = 0; y < height; y++) @@ -2195,40 +2192,30 @@ int test_YCbCr_fp(TEST_FP_TYPE coeffs[4], INT16 YCbCr[3], BYTE RGB[3]) TEST_FP_TYPE Y, Cb, Cr; TEST_FP_TYPE fR, fG, fB; TEST_FP_TYPE fR1, fR2; - - Y = (TEST_FP_TYPE) (YCbCr[0] + 4096); - Cb = (TEST_FP_TYPE) (YCbCr[1]); - Cr = (TEST_FP_TYPE) (YCbCr[2]); - + Y = (TEST_FP_TYPE)(YCbCr[0] + 4096); + Cb = (TEST_FP_TYPE)(YCbCr[1]); + Cr = (TEST_FP_TYPE)(YCbCr[2]); #if 1 fR1 = Cr * coeffs[0]; fR2 = fR1 + Y + 16.0f; - fR = ((Cr * coeffs[0]) + Y + 16.0f); fG = (Y - (Cb * coeffs[1]) - (Cr * coeffs[2]) + 16.0f); fB = ((Cb * coeffs[3]) + Y + 16.0f); - printf("fR: %f fG: %f fB: %f fY: %f\n", fR, fG, fB, Y); - R = (INT16) fR; G = (INT16) fG; B = (INT16) fB; - printf("mR: %d mG: %d mB: %d\n", - (R - 16) % 32, (G - 16) % 32, (B - 16) % 32); - + (R - 16) % 32, (G - 16) % 32, (B - 16) % 32); printf("iR: %d iG: %d iB: %d\n", R, G, B); - R >>= 5; G >>= 5; B >>= 5; - printf("R5: %d G5: %d B5: %d\n", R, G, B); - #else - R = ((INT16) (((Cr * coeffs[0]) + Y + 16.0f)) >> 5); - G = ((INT16) ((Y - (Cb * coeffs[1]) - (Cr * coeffs[2]) + 16.0f)) >> 5); - B = ((INT16) (((Cb * coeffs[3]) + Y + 16.0f)) >> 5); + R = ((INT16)(((Cr * coeffs[0]) + Y + 16.0f)) >> 5); + G = ((INT16)((Y - (Cb * coeffs[1]) - (Cr * coeffs[2]) + 16.0f)) >> 5); + B = ((INT16)(((Cb * coeffs[3]) + Y + 16.0f)) >> 5); #endif if (R < 0) @@ -2256,7 +2243,6 @@ int test_YCbCr_fp(TEST_FP_TYPE coeffs[4], INT16 YCbCr[3], BYTE RGB[3]) //printf("[2]: %20.20lf\n", coeffs[2]); //printf("[3]: %20.20lf\n", coeffs[3]); printf("--------------------------------\n\n"); - return 0; } @@ -2297,11 +2283,8 @@ int TestPrimitivesYCbCr(int argc, char* argv[]) INT16* pYCbCr[3]; const primitives_t* prims = primitives_get(); static const prim_size_t roi_64x64 = { 64, 64 }; - //return test_YCbCr_pixels(); - expected = (BYTE*) TEST_XRGB_IMAGE; - size = 64 * 64 * 4; actual = _aligned_malloc(size, 16); @@ -2309,7 +2292,6 @@ int TestPrimitivesYCbCr(int argc, char* argv[]) return 1; ZeroMemory(actual, size); - pYCbCr[0] = TEST_Y_COMPONENT; pYCbCr[1] = TEST_CB_COMPONENT; pYCbCr[2] = TEST_CR_COMPONENT; @@ -2317,26 +2299,21 @@ int TestPrimitivesYCbCr(int argc, char* argv[]) if (1) { prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**) pYCbCr, 64 * 2, - actual, 64 * 4, &roi_64x64); + actual, 64 * 4, PIXEL_FORMAT_BGRA32, &roi_64x64); } else { INT16* pSrcDst[3]; - pSrcDst[0] = _aligned_malloc(4096 * 2, 16); pSrcDst[1] = _aligned_malloc(4096 * 2, 16); pSrcDst[2] = _aligned_malloc(4096 * 2, 16); - CopyMemory(pSrcDst[0], pYCbCr[0], 4096 * 2); CopyMemory(pSrcDst[1], pYCbCr[1], 4096 * 2); CopyMemory(pSrcDst[2], pYCbCr[2], 4096 * 2); - prims->yCbCrToRGB_16s16s_P3P3((const INT16**) pSrcDst, 64 * 2, - pSrcDst, 64 * 2, &roi_64x64); - + pSrcDst, 64 * 2, &roi_64x64); prims->RGBToRGB_16s8u_P3AC4R((const INT16**) pSrcDst, 64 * 2, - actual, 64 * 4, &roi_64x64); - + actual, 64 * 4, PIXEL_FORMAT_BGRA32, &roi_64x64); _aligned_free(pSrcDst[0]); _aligned_free(pSrcDst[1]); _aligned_free(pSrcDst[2]); @@ -2362,10 +2339,8 @@ int TestPrimitivesYCbCr(int argc, char* argv[]) cnt[2] = test_bmp_cmp_count(actual, expected, size, 2, margin); /* red */ err[2] = ((float) cnt[2]) / ((float) size / 4) * 100.0f; - cnt[1] = test_bmp_cmp_count(actual, expected, size, 1, margin); /* green */ err[1] = ((float) cnt[1]) / ((float) size / 4) * 100.0f; - cnt[0] = test_bmp_cmp_count(actual, expected, size, 0, margin); /* blue */ err[0] = ((float) cnt[0]) / ((float) size / 4) * 100.0f; @@ -2373,20 +2348,16 @@ int TestPrimitivesYCbCr(int argc, char* argv[]) { printf("Red Error Dump:\n"); test_bmp_cmp_dump(actual, expected, size, 2, margin); /* red */ - printf("Green Error Dump:\n"); test_bmp_cmp_dump(actual, expected, size, 1, margin); /* green */ - printf("Blue Error Dump:\n"); test_bmp_cmp_dump(actual, expected, size, 0, margin); /* blue */ - printf("R: diff: %d (%f%%)\n", cnt[2], err[2]); printf("G: diff: %d (%f%%)\n", cnt[1], err[1]); printf("B: diff: %d (%f%%)\n", cnt[0], err[0]); } _aligned_free(actual); - return 0; } diff --git a/libfreerdp/primitives/test/TestPrimitivesYCoCg.c b/libfreerdp/primitives/test/TestPrimitivesYCoCg.c index 9fb0fd326..2dd36e97e 100644 --- a/libfreerdp/primitives/test/TestPrimitivesYCoCg.c +++ b/libfreerdp/primitives/test/TestPrimitivesYCoCg.c @@ -26,15 +26,6 @@ static const int YCOCG_TRIAL_ITERATIONS = 20000; static const float TEST_TIME = 4.0; -extern BOOL g_TestPrimitivesPerformance; - -extern pstatus_t general_YCoCgToRGB_8u_AC4R(const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, UINT32 width, UINT32 height, - UINT8 shift, BOOL withAlpha, BOOL invert); -extern pstatus_t ssse3_YCoCgRToRGB_8u_AC4R(const BYTE *pSrc, INT32 srcStep, - BYTE *pDst, INT32 dstStep, UINT32 width, UINT32 height, - UINT8 shift, BOOL withAlpha, BOOL invert); - /* ------------------------------------------------------------------------- */ int test_YCoCgRToRGB_8u_AC4R_func(void) { @@ -46,75 +37,81 @@ int test_YCoCgRToRGB_8u_AC4R_func(void) INT32 ALIGN(out_c[4098]), ALIGN(out_c_inv[4098]); char testStr[256]; BOOL failed = FALSE; - testStr[0] = '\0'; - get_random_data(in, sizeof(in)); - - general_YCoCgToRGB_8u_AC4R((const BYTE *) (in+1), 63*4, - (BYTE *) out_c, 63*4, 63, 61, 2, TRUE, FALSE); - general_YCoCgToRGB_8u_AC4R((const BYTE *) (in+1), 63*4, - (BYTE *) out_c_inv, 63*4, 63, 61, 2, TRUE, TRUE); + winpr_RAND(in, sizeof(in)); + general_YCoCgToRGB_8u_AC4R((const BYTE*)(in + 1), 63 * 4, + (BYTE*) out_c, 63 * 4, 63, 61, 2, TRUE, FALSE); + general_YCoCgToRGB_8u_AC4R((const BYTE*)(in + 1), 63 * 4, + (BYTE*) out_c_inv, 63 * 4, 63, 61, 2, TRUE, TRUE); #ifdef WITH_SSE2 + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3)) { strcat(testStr, " SSSE3"); - ssse3_YCoCgRToRGB_8u_AC4R((const BYTE *) (in+1), 63*4, - (BYTE *) out_sse, 63*4, 63, 61, 2, TRUE, FALSE); + ssse3_YCoCgRToRGB_8u_AC4R((const BYTE*)(in + 1), 63 * 4, + (BYTE*) out_sse, 63 * 4, 63, 61, 2, TRUE, FALSE); - for (i=0; i<63*61; ++i) + for (i = 0; i < 63 * 61; ++i) { - if (out_c[i] != out_sse[i]) { + if (out_c[i] != out_sse[i]) + { printf("YCoCgRToRGB-SSE FAIL[%d]: 0x%08x -> C 0x%08x vs SSE 0x%08x\n", i, - in[i+1], out_c[i], out_sse[i]); + in[i + 1], out_c[i], out_sse[i]); failed = TRUE; } } - ssse3_YCoCgRToRGB_8u_AC4R((const BYTE *) (in+1), 63*4, - (BYTE *) out_sse_inv, 63*4, 63, 61, 2, TRUE, TRUE); - for (i=0; i<63*61; ++i) + + ssse3_YCoCgRToRGB_8u_AC4R((const BYTE*)(in + 1), 63 * 4, + (BYTE*) out_sse_inv, 63 * 4, 63, 61, 2, TRUE, TRUE); + + for (i = 0; i < 63 * 61; ++i) { - if (out_c_inv[i] != out_sse_inv[i]) { - printf("YCoCgRToRGB-SSE inverted FAIL[%d]: 0x%08x -> C 0x%08x vs SSE 0x%08x\n", i, - in[i+1], out_c_inv[i], out_sse_inv[i]); + if (out_c_inv[i] != out_sse_inv[i]) + { + printf("YCoCgRToRGB-SSE inverted FAIL[%d]: 0x%08x -> C 0x%08x vs SSE 0x%08x\n", + i, + in[i + 1], out_c_inv[i], out_sse_inv[i]); failed = TRUE; } } } + #endif /* i386 */ + if (!failed) printf("All YCoCgRToRGB_8u_AC4R tests passed (%s).\n", testStr); + return (failed > 0) ? FAILURE : SUCCESS; } /* ------------------------------------------------------------------------- */ STD_SPEED_TEST( - ycocg_to_rgb_speed, BYTE, BYTE, PRIM_NOP, - TRUE, general_YCoCgToRGB_8u_AC4R(src1, 64*4, dst, 64*4, 64, 64, 2, FALSE, FALSE), + ycocg_to_rgb_speed, BYTE, BYTE, PRIM_NOP, + TRUE, general_YCoCgToRGB_8u_AC4R(src1, 64 * 4, dst, 64 * 4, 64, 64, 2, FALSE, + FALSE), #ifdef WITH_SSE2 - TRUE, ssse3_YCoCgRToRGB_8u_AC4R(src1, 64*4, dst, 64*4, 64, 64, 2, FALSE, FALSE), - PF_EX_SSSE3, TRUE, + TRUE, ssse3_YCoCgRToRGB_8u_AC4R(src1, 64 * 4, dst, 64 * 4, 64, 64, 2, FALSE, + FALSE), + PF_EX_SSSE3, TRUE, #else - FALSE, PRIM_NOP, 0, FALSE, + FALSE, PRIM_NOP, 0, FALSE, #endif - FALSE, PRIM_NOP); + FALSE, PRIM_NOP); -int test_YCoCgRToRGB_8u_AC4R_speed(void) +static int test_YCoCgRToRGB_8u_AC4R_speed(void) { INT32 ALIGN(in[4096]); INT32 ALIGN(out[4096]); int size_array[] = { 64 }; - - get_random_data(in, sizeof(in)); - - ycocg_to_rgb_speed("YCoCgToRGB", "aligned", (const BYTE *) in, - 0, 0, (BYTE *) out, - size_array, 1, YCOCG_TRIAL_ITERATIONS, TEST_TIME); + winpr_RAND(in, sizeof(in)); + ycocg_to_rgb_speed("YCoCgToRGB", "aligned", (const BYTE*) in, + 0, 0, (BYTE*) out, + size_array, 1, YCOCG_TRIAL_ITERATIONS, TEST_TIME); return SUCCESS; } int TestPrimitivesYCoCg(int argc, char* argv[]) { int status; - status = test_YCoCgRToRGB_8u_AC4R_func(); if (status != SUCCESS) diff --git a/libfreerdp/primitives/test/TestPrimitivesYUV.c b/libfreerdp/primitives/test/TestPrimitivesYUV.c index 910010059..72817632d 100644 --- a/libfreerdp/primitives/test/TestPrimitivesYUV.c +++ b/libfreerdp/primitives/test/TestPrimitivesYUV.c @@ -17,7 +17,7 @@ static BOOL similar(const BYTE* src, const BYTE* dst, size_t size) { size_t x; - for (x=0; xYUV420CombineToYUV444) goto fail; - for (x=0; x<3; x++) + for (x = 0; x < 3; x++) { - size_t halfStride = ((x>0)?awidth/2:awidth); + size_t halfStride = ((x > 0) ? awidth / 2 : awidth); size_t size = aheight * awidth; - size_t halfSize = ((x>0)?halfStride*aheight/2:awidth*aheight); - + size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight); yuvStride[x] = awidth; + if (!(yuv[x] = set_padding(size, padding))) goto fail; lumaStride[x] = halfStride; + if (!(luma[x] = set_padding(halfSize, padding))) goto fail; @@ -162,67 +169,76 @@ static BOOL TestPrimitiveYUVCombine(void) goto fail; chromaStride[x] = halfStride; + if (!(chroma[x] = set_padding(halfSize, padding))) goto fail; if (!(paux[x] = set_padding(halfSize, padding))) goto fail; - memset(luma[x], 0xAB + 3*x, halfSize); - memset(chroma[x], 0x80 + 2*x, halfSize); + memset(luma[x], 0xAB + 3 * x, halfSize); + memset(chroma[x], 0x80 + 2 * x, halfSize); if (!check_padding(luma[x], halfSize, padding, "luma")) goto fail; + if (!check_padding(chroma[x], halfSize, padding, "chroma")) goto fail; + if (!check_padding(pmain[x], halfSize, padding, "main")) goto fail; + if (!check_padding(paux[x], halfSize, padding, "aux")) goto fail; + if (!check_padding(yuv[x], size, padding, "yuv")) goto fail; } if (prims->YUV420CombineToYUV444((const BYTE**)luma, lumaStride, - (const BYTE**) chroma, chromaStride, + (const BYTE**)chroma, chromaStride, yuv, yuvStride, &roi) != PRIMITIVES_SUCCESS) goto fail; - for (x=0; x<3; x++) + for (x = 0; x < 3; x++) { - size_t halfStride = ((x>0)?awidth/2:awidth); + size_t halfStride = ((x > 0) ? awidth / 2 : awidth); size_t size = aheight * awidth; - size_t halfSize = ((x>0)?halfStride*aheight/2:awidth*aheight); + size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight); if (!check_padding(luma[x], halfSize, padding, "luma")) goto fail; + if (!check_padding(chroma[x], halfSize, padding, "chroma")) goto fail; + if (!check_padding(yuv[x], size, padding, "yuv")) goto fail; } - if (prims->YUV444SplitToYUV420(yuv, yuvStride, pmain, lumaStride, + if (prims->YUV444SplitToYUV420((const BYTE**)yuv, yuvStride, pmain, lumaStride, paux, chromaStride, &roi) != PRIMITIVES_SUCCESS) goto fail; - for (x=0; x<3; x++) + for (x = 0; x < 3; x++) { - size_t halfStride = ((x>0)?awidth/2:awidth); + size_t halfStride = ((x > 0) ? awidth / 2 : awidth); size_t size = aheight * awidth; - size_t halfSize = ((x>0)?halfStride*aheight/2:awidth*aheight); + size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight); if (!check_padding(pmain[x], halfSize, padding, "main")) goto fail; + if (!check_padding(paux[x], halfSize, padding, "aux")) goto fail; + if (!check_padding(yuv[x], size, padding, "yuv")) goto fail; } - for (i=0; i<3; i++) + for (i = 0; i < 3; i++) { - for (y=0; y 0) { - w = (roi.width+3) / 4; - if (roi.height > (roi.height+1)/2) + w = (roi.width + 3) / 4; + + if (roi.height > (roi.height + 1) / 2) continue; } @@ -249,6 +266,7 @@ static BOOL TestPrimitiveYUVCombine(void) * include the last V lines packed to the Y * frame. */ UINT32 rem = roi.height % 16; + if (y > roi.height - rem) continue; } @@ -262,7 +280,8 @@ static BOOL TestPrimitiveYUVCombine(void) rc = TRUE; fail: - for (x=0; x<3; x++) + + for (x = 0; x < 3; x++) { free_padding(yuv[x], padding); free_padding(luma[x], padding); @@ -289,19 +308,18 @@ static BOOL TestPrimitiveYUV(BOOL use444) size_t uvsize, uvwidth; size_t padding = 10000; size_t stride; - get_size(&roi.width, &roi.height); - /* Buffers need to be 16x16 aligned. */ awidth = roi.width + 16 - roi.width % 16; aheight = roi.height + 16 - roi.height % 16; - stride = awidth * sizeof(UINT32); size = awidth * aheight; + if (use444) { uvwidth = awidth; uvsize = size; + if (!prims || !prims->RGBToYUV444_8u_P3AC4R || !prims->YUV444ToRGB_8u_P3AC4R) return FALSE; } @@ -309,12 +327,13 @@ static BOOL TestPrimitiveYUV(BOOL use444) { uvwidth = (awidth + 1) / 2; uvsize = (aheight + 1) / 2 * uvwidth; + if (!prims || !prims->RGBToYUV420_8u_P3AC4R || !prims->YUV420ToRGB_8u_P3AC4R) return FALSE; } fprintf(stderr, "Running AVC%s on frame size %lux%lu\n", use444 ? "444" : "420", - roi.width, roi.height); + roi.width, roi.height); /* Test RGB to YUV444 conversion and vice versa */ if (!(rgb = set_padding(size * sizeof(UINT32), padding))) @@ -332,15 +351,16 @@ static BOOL TestPrimitiveYUV(BOOL use444) if (!(yuv[2] = set_padding(uvsize, padding))) goto fail; - for (y=0; yRGBToYUV444_8u_P3AC4R(rgb, stride, yuv, yuv_step, &roi) != PRIMITIVES_SUCCESS) + if (prims->RGBToYUV444_8u_P3AC4R(rgb, stride, yuv, yuv_step, + &roi) != PRIMITIVES_SUCCESS) goto fail; } - else if (prims->RGBToYUV420_8u_P3AC4R(rgb, stride, yuv, yuv_step, &roi) != PRIMITIVES_SUCCESS) + else if (prims->RGBToYUV420_8u_P3AC4R(rgb, stride, yuv, yuv_step, + &roi) != PRIMITIVES_SUCCESS) goto fail; if (!check_padding(rgb, size * sizeof(UINT32), padding, "rgb")) goto fail; if ((!check_padding(yuv[0], size, padding, "Y")) || - (!check_padding(yuv[1], uvsize, padding, "U")) || - (!check_padding(yuv[2], uvsize, padding, "V"))) + (!check_padding(yuv[1], uvsize, padding, "U")) || + (!check_padding(yuv[2], uvsize, padding, "V"))) goto fail; if (use444) { - if (prims->YUV444ToRGB_8u_P3AC4R((const BYTE**)yuv, yuv_step, rgb_dst, stride, &roi) != PRIMITIVES_SUCCESS) + if (prims->YUV444ToRGB_8u_P3AC4R((const BYTE**)yuv, yuv_step, rgb_dst, stride, + PIXEL_FORMAT_BGRA32, + &roi) != PRIMITIVES_SUCCESS) goto fail; } - else if (prims->YUV420ToRGB_8u_P3AC4R((const BYTE**)yuv, yuv_step, rgb_dst, stride, &roi) != PRIMITIVES_SUCCESS) + else if (prims->YUV420ToRGB_8u_P3AC4R((const BYTE**)yuv, yuv_step, rgb_dst, + stride, PIXEL_FORMAT_BGRA32, &roi) != PRIMITIVES_SUCCESS) goto fail; if (!check_padding(rgb_dst, size * sizeof(UINT32), padding, "rgb dst")) goto fail; if ((!check_padding(yuv[0], size, padding, "Y")) || - (!check_padding(yuv[1], uvsize, padding, "U")) || - (!check_padding(yuv[2], uvsize, padding, "V"))) + (!check_padding(yuv[1], uvsize, padding, "U")) || + (!check_padding(yuv[2], uvsize, padding, "V"))) goto fail; - for (y=0; y #define PROFILER_START(_prefix_) \ - do { \ + do { \ char _path[PATH_MAX]; \ sprintf(_path, "./%s.prof", (_prefix_)); \ ProfilerStart(_path); \ - } while (0); + } while (0); # define PROFILER_STOP \ - do { \ + do { \ ProfilerStop(); \ - } while (0); + } while (0); #else #define PROFILER_START(_prefix_) #define PROFILER_STOP #endif // GOOGLE_PROFILER -extern float _delta_time(const struct timespec *t0, const struct timespec *t1); -extern void _floatprint(float t, char *output); +extern float _delta_time(const struct timespec* t0, const struct timespec* t1); +extern void _floatprint(float t, char* output); #ifndef CLOCK_MONOTONIC_RAW #define CLOCK_MONOTONIC_RAW 4 #endif // !CLOCK_MONOTONIC_RAW #define MEASURE_LOOP_START(_prefix_, _count_) \ -{ struct timespec _start, _stop; \ - char *_prefix; \ - int _count = (_count_); \ - int _loop; \ - float _delta; \ - char _str1[32], _str2[32]; \ - _prefix = strdup(_prefix_); \ - _str1[0] = '\0'; _str2[0] = '\0'; \ - clock_gettime(CLOCK_MONOTONIC_RAW, &_start); \ - PROFILER_START(_prefix); \ - _loop = (_count); \ - do { + { struct timespec _start, _stop; \ + char *_prefix; \ + int _count = (_count_); \ + int _loop; \ + float _delta; \ + char _str1[32], _str2[32]; \ + _prefix = strdup(_prefix_); \ + _str1[0] = '\0'; _str2[0] = '\0'; \ + clock_gettime(CLOCK_MONOTONIC_RAW, &_start); \ + PROFILER_START(_prefix); \ + _loop = (_count); \ + do { #define MEASURE_LOOP_STOP \ - } while (--_loop); + } while (--_loop); #define MEASURE_GET_RESULTS(_result_) \ - PROFILER_STOP; \ - clock_gettime(CLOCK_MONOTONIC_RAW, &_stop); \ - _delta = _delta_time(&_start, &_stop); \ - (_result_) = (float) _count / _delta; \ - free(_prefix); \ -} + PROFILER_STOP; \ + clock_gettime(CLOCK_MONOTONIC_RAW, &_stop); \ + _delta = _delta_time(&_start, &_stop); \ + (_result_) = (float) _count / _delta; \ + free(_prefix); \ + } #define MEASURE_SHOW_RESULTS(_result_) \ - PROFILER_STOP; \ - clock_gettime(CLOCK_MONOTONIC_RAW, &_stop); \ - _delta = _delta_time(&_start, &_stop); \ - (_result_) = (float) _count / _delta; \ - _floatprint((float) _count / _delta, _str1); \ - printf("%s: %9d iterations in %5.1f seconds = %s/s \n", \ - _prefix, _count, _delta, _str1); \ - free(_prefix); \ -} + PROFILER_STOP; \ + clock_gettime(CLOCK_MONOTONIC_RAW, &_stop); \ + _delta = _delta_time(&_start, &_stop); \ + (_result_) = (float) _count / _delta; \ + _floatprint((float) _count / _delta, _str1); \ + printf("%s: %9d iterations in %5.1f seconds = %s/s \n", \ + _prefix, _count, _delta, _str1); \ + free(_prefix); \ + } #define MEASURE_SHOW_RESULTS_SCALED(_scale_, _label_) \ - PROFILER_STOP; \ - clock_gettime(CLOCK_MONOTONIC_RAW, &_stop); \ - _delta = _delta_time(&_start, &_stop); \ - _floatprint((float) _count / _delta, _str1); \ - _floatprint((float) _count / _delta * (_scale_), _str2); \ - printf("%s: %9d iterations in %5.1f seconds = %s/s = %s%s \n", \ - _prefix, _count, _delta, _str1, _str2, _label_); \ - free(_prefix); \ -} + PROFILER_STOP; \ + clock_gettime(CLOCK_MONOTONIC_RAW, &_stop); \ + _delta = _delta_time(&_start, &_stop); \ + _floatprint((float) _count / _delta, _str1); \ + _floatprint((float) _count / _delta * (_scale_), _str2); \ + printf("%s: %9d iterations in %5.1f seconds = %s/s = %s%s \n", \ + _prefix, _count, _delta, _str1, _str2, _label_); \ + free(_prefix); \ + } #define MEASURE_TIMED(_label_, _init_iter_, _test_time_, _result_, _call_) \ -{ float _r; \ - MEASURE_LOOP_START(_label_, _init_iter_); \ - _call_; \ - MEASURE_LOOP_STOP; \ - MEASURE_GET_RESULTS(_r); \ - MEASURE_LOOP_START(_label_, _r * _test_time_); \ - _call_; \ - MEASURE_LOOP_STOP; \ - MEASURE_SHOW_RESULTS(_result_); \ -} + { float _r; \ + MEASURE_LOOP_START(_label_, _init_iter_); \ + _call_; \ + MEASURE_LOOP_STOP; \ + MEASURE_GET_RESULTS(_r); \ + MEASURE_LOOP_START(_label_, _r * _test_time_); \ + _call_; \ + MEASURE_LOOP_STOP; \ + MEASURE_SHOW_RESULTS(_result_); \ + } #endif diff --git a/libfreerdp/primitives/test/prim_test.c b/libfreerdp/primitives/test/prim_test.c index b9757ac05..25cc37443 100644 --- a/libfreerdp/primitives/test/prim_test.c +++ b/libfreerdp/primitives/test/prim_test.c @@ -26,72 +26,30 @@ #include #include +#include #ifdef HAVE_UNISTD_H #include #endif +primitives_t* generic = NULL; +primitives_t* optimized = NULL; BOOL g_TestPrimitivesPerformance = FALSE; +UINT32 g_Iterations = 1000; + int test_sizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; -/* ------------------------------------------------------------------------- */ -static void get_random_data_lrand(void *buffer, size_t size) -{ - static int seeded = 0; - long int *ptr = (long int *) buffer; - unsigned char *cptr; - - if (!seeded) - { - seeded = 1; - srand48(time(NULL)); - } - /* This isn't the perfect random number generator, but that's okay. */ - while (size >= sizeof(long int)) - { - *ptr++ = lrand48(); - size -= sizeof(long int); - } - cptr = (unsigned char *) ptr; - while (size > 0) - { - *cptr++ = lrand48() & 0xff; - --size; - } -} - -/* ------------------------------------------------------------------------- */ -void get_random_data(void *buffer, size_t size) -{ -#ifdef __linux__ - size_t offset = 0; - int fd = open("/dev/urandom", O_RDONLY); - if (fd < 0) - { - get_random_data_lrand(buffer, size); - return; - } - - while (size > 0) - { - ssize_t count = read(fd, buffer+offset, size); - size -= count; - offset += count; - } - close(fd); -#else - get_random_data_lrand(buffer, size); -#endif -} - /* ------------------------------------------------------------------------- */ #ifdef _WIN32 -float _delta_time(const struct timespec *t0, const struct timespec *t1) { return 0.0f; } -#else -float _delta_time(const struct timespec *t0, const struct timespec *t1) +float _delta_time(const struct timespec* t0, const struct timespec* t1) { - INT64 secs = (INT64) (t1->tv_sec) - (INT64) (t0->tv_sec); + return 0.0f; +} +#else +float _delta_time(const struct timespec* t0, const struct timespec* t1) +{ + INT64 secs = (INT64)(t1->tv_sec) - (INT64)(t0->tv_sec); long nsecs = t1->tv_nsec - t0->tv_nsec; double retval; @@ -107,22 +65,49 @@ float _delta_time(const struct timespec *t0, const struct timespec *t1) #endif /* ------------------------------------------------------------------------- */ -void _floatprint(float t, char *output) +void _floatprint(float t, char* output) { /* I don't want to link against -lm, so avoid log,exp,... */ float f = 10.0; int i; + while (t > f) f *= 10.0; + f /= 1000.0; - i = ((int) (t/f+0.5)) * (int) f; + i = ((int)(t / f + 0.5)) * (int) f; + if (t < 0.0) sprintf(output, "%f", t); - else if (i == 0) sprintf(output, "%d", (int) (t+0.5)); + else if (i == 0) sprintf(output, "%d", (int)(t + 0.5)); else if (t < 1e+3) sprintf(output, "%3d", i); else if (t < 1e+6) sprintf(output, "%3d,%03d", - i/1000, i % 1000); + i / 1000, i % 1000); else if (t < 1e+9) sprintf(output, "%3d,%03d,000", - i/1000000, (i % 1000000) / 1000); + i / 1000000, (i % 1000000) / 1000); else if (t < 1e+12) sprintf(output, "%3d,%03d,000,000", - i/1000000000, (i % 1000000000) / 1000000); + i / 1000000000, (i % 1000000000) / 1000000); else sprintf(output, "%f", t); } + + +void prim_test_setup(BOOL performance) { + generic = primitives_get_generic(); + optimized = primitives_get(); + g_TestPrimitivesPerformance = performance; +} + + +BOOL speed_test(const char* name, const char* dsc, UINT32 iterations, + pstatus_t(*generic)(), pstatus_t(*optimised)(), ...) +{ + UINT32 i; + + if (!name || !generic || !optimised || (iterations == 0)) + return FALSE; + + for (i=0; i #include #include +#include #include @@ -42,8 +43,6 @@ extern int test_sizes[]; #define NUM_TEST_SIZES 10 -extern void get_random_data(void *buffer, size_t size); - #ifndef SUCCESS #define SUCCESS 0 #endif @@ -51,191 +50,16 @@ extern void get_random_data(void *buffer, size_t size); #define FAILURE 1 #endif -extern int test_copy8u_func(void); -extern int test_copy8u_speed(void); +extern BOOL g_TestPrimitivesPerformance; +extern UINT32 g_Iterations; -extern int test_set8u_func(void); -extern int test_set32s_func(void); -extern int test_set32u_func(void); -extern int test_set8u_speed(void); -extern int test_set32s_speed(void); -extern int test_set32u_speed(void); +extern primitives_t* generic; +extern primitives_t* optimized; -extern int test_sign16s_func(void); -extern int test_sign16s_speed(void); +void prim_test_setup(BOOL performance); -extern int test_add16s_func(void); -extern int test_add16s_speed(void); - -extern int test_lShift_16s_func(void); -extern int test_lShift_16u_func(void); -extern int test_rShift_16s_func(void); -extern int test_rShift_16u_func(void); -extern int test_lShift_16s_speed(void); -extern int test_lShift_16u_speed(void); -extern int test_rShift_16s_speed(void); -extern int test_rShift_16u_speed(void); - -extern int test_RGBToRGB_16s8u_P3AC4R_func(void); -extern int test_RGBToRGB_16s8u_P3AC4R_speed(void); -extern int test_yCbCrToRGB_16s16s_P3P3_func(void); -extern int test_yCbCrToRGB_16s16s_P3P3_speed(void); -extern int test_YCoCgRToRGB_8u_AC4R_func(void); -extern int test_YCoCgRToRGB_8u_AC4R_speed(void); - -extern int test_RGB565ToARGB_16u32u_C3C4_func(void); -extern int test_RGB565ToARGB_16u32u_C3C4_speed(void); - -extern int test_alphaComp_func(void); -extern int test_alphaComp_speed(void); - -extern int test_and_32u_func(void); -extern int test_and_32u_speed(void); -extern int test_or_32u_func(void); -extern int test_or_32u_speed(void); - -/* Since so much of this code is repeated, define a macro to build - * functions to do speed tests. - */ -#ifdef _M_ARM -#define SIMD_TYPE "Neon" -#else -#define SIMD_TYPE "SSE" -#endif - -#define DO_NORMAL_MEASUREMENTS(_funcNormal_, _prework_) \ - do { \ - for (s=0; s 0.0) _floatprint(resultNormal[s], sN); \ - if (resultOpt[s] > 0.0) \ - { \ - _floatprint(resultOpt[s], sSN); \ - if (resultNormal[s] > 0.0) \ - { \ - sprintf(sSNp, "%d%%", \ - (int) (resultOpt[s] / resultNormal[s] * 100.0 + 0.5)); \ - } \ - } \ - if (resultIPP[s] > 0.0) \ - { \ - _floatprint(resultIPP[s], sIPP); \ - if (resultNormal[s] > 0.0) \ - { \ - sprintf(sIPPp, "%d%%", \ - (int) (resultIPP[s] / resultNormal[s] * 100.0 + 0.5)); \ - } \ - } \ - printf("%8d: %15s %15s %5s %15s %5s\n", \ - size_array[s], sN, sSN, sSNp, sIPP, sIPPp); \ - } \ - free(resultNormal); free(resultOpt); free(resultIPP); \ -} -#endif +BOOL speed_test(const char* name, const char* dsc, UINT32 iterations, + pstatus_t (*generic)(), pstatus_t (*optimised)(), + ...); #endif // !__PRIMTEST_H_INCLUDED__ diff --git a/scripts/LECHash.c b/scripts/LECHash.c index 285205ff2..6a9942ae8 100644 --- a/scripts/LECHash.c +++ b/scripts/LECHash.c @@ -1,28 +1,30 @@ #include typedef unsigned short UINT16; -static UINT16 HuffCodeLEC[] = { - 0x0004, 0x0024, 0x0014, 0x0011, 0x0051, 0x0031, 0x0071, 0x0009, 0x0049, 0x0029, 0x0069, 0x0015, 0x0095, -0x0055, 0x00d5, 0x0035, 0x00b5, 0x0075, 0x001d, 0x00f5, 0x011d, 0x009d, 0x019d, 0x005d, 0x000d, 0x008d, 0x015d, -0x00dd, 0x01dd, 0x003d, 0x013d, 0x00bd, 0x004d, 0x01bd, 0x007d, 0x006b, 0x017d, 0x00fd, 0x01fd, 0x0003, 0x0103, -0x0083, 0x0183, 0x026b, 0x0043, 0x016b, 0x036b, 0x00eb, 0x0143, 0x00c3, 0x02eb, 0x01c3, 0x01eb, 0x0023, 0x03eb, -0x0123, 0x00a3, 0x01a3, 0x001b, 0x021b, 0x0063, 0x011b, 0x0163, 0x00e3, 0x00cd, 0x01e3, 0x0013, 0x0113, 0x0093, -0x031b, 0x009b, 0x029b, 0x0193, 0x0053, 0x019b, 0x039b, 0x005b, 0x025b, 0x015b, 0x035b, 0x0153, 0x00d3, 0x00db, -0x02db, 0x01db, 0x03db, 0x003b, 0x023b, 0x013b, 0x01d3, 0x033b, 0x00bb, 0x02bb, 0x01bb, 0x03bb, 0x007b, 0x002d, -0x027b, 0x017b, 0x037b, 0x00fb, 0x02fb, 0x01fb, 0x03fb, 0x0007, 0x0207, 0x0107, 0x0307, 0x0087, 0x0287, 0x0187, -0x0387, 0x0033, 0x0047, 0x0247, 0x0147, 0x0347, 0x00c7, 0x02c7, 0x01c7, 0x0133, 0x03c7, 0x0027, 0x0227, 0x0127, -0x0327, 0x00a7, 0x00b3, 0x0019, 0x01b3, 0x0073, 0x02a7, 0x0173, 0x01a7, 0x03a7, 0x0067, 0x00f3, 0x0267, 0x0167, -0x0367, 0x00e7, 0x02e7, 0x01e7, 0x03e7, 0x01f3, 0x0017, 0x0217, 0x0117, 0x0317, 0x0097, 0x0297, 0x0197, 0x0397, -0x0057, 0x0257, 0x0157, 0x0357, 0x00d7, 0x02d7, 0x01d7, 0x03d7, 0x0037, 0x0237, 0x0137, 0x0337, 0x00b7, 0x02b7, -0x01b7, 0x03b7, 0x0077, 0x0277, 0x07ff, 0x0177, 0x0377, 0x00f7, 0x02f7, 0x01f7, 0x03f7, 0x03ff, 0x000f, 0x020f, -0x010f, 0x030f, 0x008f, 0x028f, 0x018f, 0x038f, 0x004f, 0x024f, 0x014f, 0x034f, 0x00cf, 0x000b, 0x02cf, 0x01cf, -0x03cf, 0x002f, 0x022f, 0x010b, 0x012f, 0x032f, 0x00af, 0x02af, 0x01af, 0x008b, 0x03af, 0x006f, 0x026f, 0x018b, -0x016f, 0x036f, 0x00ef, 0x02ef, 0x01ef, 0x03ef, 0x001f, 0x021f, 0x011f, 0x031f, 0x009f, 0x029f, 0x019f, 0x039f, -0x005f, 0x004b, 0x025f, 0x015f, 0x035f, 0x00df, 0x02df, 0x01df, 0x03df, 0x003f, 0x023f, 0x013f, 0x033f, 0x00bf, -0x02bf, 0x014b, 0x01bf, 0x00ad, 0x00cb, 0x01cb, 0x03bf, 0x002b, 0x007f, 0x027f, 0x017f, 0x012b, 0x037f, 0x00ff, -0x02ff, 0x00ab, 0x01ab, 0x006d, 0x0059, 0x17ff, 0x0fff, 0x0039, 0x0079, 0x01ff, 0x0005, 0x0045, 0x0034, 0x000c, -0x002c, 0x001c, 0x0000, 0x003c, 0x0002, 0x0022, 0x0010, 0x0012, 0x0008, 0x0032, 0x000a, 0x002a, 0x001a, 0x003a, -0x0006, 0x0026, 0x0016, 0x0036, 0x000e, 0x002e, 0x001e, 0x003e, 0x0001, 0x00ed, 0x0018, 0x0021, 0x0025, 0x0065 }; +static UINT16 HuffCodeLEC[] = +{ + 0x0004, 0x0024, 0x0014, 0x0011, 0x0051, 0x0031, 0x0071, 0x0009, 0x0049, 0x0029, 0x0069, 0x0015, 0x0095, + 0x0055, 0x00d5, 0x0035, 0x00b5, 0x0075, 0x001d, 0x00f5, 0x011d, 0x009d, 0x019d, 0x005d, 0x000d, 0x008d, 0x015d, + 0x00dd, 0x01dd, 0x003d, 0x013d, 0x00bd, 0x004d, 0x01bd, 0x007d, 0x006b, 0x017d, 0x00fd, 0x01fd, 0x0003, 0x0103, + 0x0083, 0x0183, 0x026b, 0x0043, 0x016b, 0x036b, 0x00eb, 0x0143, 0x00c3, 0x02eb, 0x01c3, 0x01eb, 0x0023, 0x03eb, + 0x0123, 0x00a3, 0x01a3, 0x001b, 0x021b, 0x0063, 0x011b, 0x0163, 0x00e3, 0x00cd, 0x01e3, 0x0013, 0x0113, 0x0093, + 0x031b, 0x009b, 0x029b, 0x0193, 0x0053, 0x019b, 0x039b, 0x005b, 0x025b, 0x015b, 0x035b, 0x0153, 0x00d3, 0x00db, + 0x02db, 0x01db, 0x03db, 0x003b, 0x023b, 0x013b, 0x01d3, 0x033b, 0x00bb, 0x02bb, 0x01bb, 0x03bb, 0x007b, 0x002d, + 0x027b, 0x017b, 0x037b, 0x00fb, 0x02fb, 0x01fb, 0x03fb, 0x0007, 0x0207, 0x0107, 0x0307, 0x0087, 0x0287, 0x0187, + 0x0387, 0x0033, 0x0047, 0x0247, 0x0147, 0x0347, 0x00c7, 0x02c7, 0x01c7, 0x0133, 0x03c7, 0x0027, 0x0227, 0x0127, + 0x0327, 0x00a7, 0x00b3, 0x0019, 0x01b3, 0x0073, 0x02a7, 0x0173, 0x01a7, 0x03a7, 0x0067, 0x00f3, 0x0267, 0x0167, + 0x0367, 0x00e7, 0x02e7, 0x01e7, 0x03e7, 0x01f3, 0x0017, 0x0217, 0x0117, 0x0317, 0x0097, 0x0297, 0x0197, 0x0397, + 0x0057, 0x0257, 0x0157, 0x0357, 0x00d7, 0x02d7, 0x01d7, 0x03d7, 0x0037, 0x0237, 0x0137, 0x0337, 0x00b7, 0x02b7, + 0x01b7, 0x03b7, 0x0077, 0x0277, 0x07ff, 0x0177, 0x0377, 0x00f7, 0x02f7, 0x01f7, 0x03f7, 0x03ff, 0x000f, 0x020f, + 0x010f, 0x030f, 0x008f, 0x028f, 0x018f, 0x038f, 0x004f, 0x024f, 0x014f, 0x034f, 0x00cf, 0x000b, 0x02cf, 0x01cf, + 0x03cf, 0x002f, 0x022f, 0x010b, 0x012f, 0x032f, 0x00af, 0x02af, 0x01af, 0x008b, 0x03af, 0x006f, 0x026f, 0x018b, + 0x016f, 0x036f, 0x00ef, 0x02ef, 0x01ef, 0x03ef, 0x001f, 0x021f, 0x011f, 0x031f, 0x009f, 0x029f, 0x019f, 0x039f, + 0x005f, 0x004b, 0x025f, 0x015f, 0x035f, 0x00df, 0x02df, 0x01df, 0x03df, 0x003f, 0x023f, 0x013f, 0x033f, 0x00bf, + 0x02bf, 0x014b, 0x01bf, 0x00ad, 0x00cb, 0x01cb, 0x03bf, 0x002b, 0x007f, 0x027f, 0x017f, 0x012b, 0x037f, 0x00ff, + 0x02ff, 0x00ab, 0x01ab, 0x006d, 0x0059, 0x17ff, 0x0fff, 0x0039, 0x0079, 0x01ff, 0x0005, 0x0045, 0x0034, 0x000c, + 0x002c, 0x001c, 0x0000, 0x003c, 0x0002, 0x0022, 0x0010, 0x0012, 0x0008, 0x0032, 0x000a, 0x002a, 0x001a, 0x003a, + 0x0006, 0x0026, 0x0016, 0x0036, 0x000e, 0x002e, 0x001e, 0x003e, 0x0001, 0x00ed, 0x0018, 0x0021, 0x0025, 0x0065 +}; UINT16 HashTable[512] = { [0 ... 511] = 0xffff }; @@ -30,63 +32,71 @@ static UINT16 tab[8] = {511, 0, 508, 448, 494, 347, 486, 482}; UINT16 hash(UINT16 key) { - UINT16 h; - h = (key & 0x1ff) ^ (key >> 9) ^ (key >> 4) ^ (key >> 7); - return h; + UINT16 h; + h = (key & 0x1ff) ^ (key >> 9) ^ (key >> 4) ^ (key >> 7); + return h; } UINT16 minihash(UINT16 key) { - UINT16 h; - h = ((((key >> 8) ^ (key & 0xff)) >> 2) & 0xf); - if(key >> 9) - h = ~h; - return (h % 12); + UINT16 h; + h = ((((key >> 8) ^ (key & 0xff)) >> 2) & 0xf); + + if (key >> 9) + h = ~h; + + return (h % 12); } void buildhashtable(void) { - int i,j; - UINT16 h; - for(i=0;i<293;i++) - { - h=hash(HuffCodeLEC[i]); - if(HashTable[h]!=0xffff) - { - HashTable[h] ^= (HuffCodeLEC[i] & 0xfe00) ^ 0xfe00; - HashTable[tab[minihash(HuffCodeLEC[i])]] = i; - } - else - { - HashTable[h] = i; - HashTable[h] ^= 0xfe00; - } - } + int i, j; + UINT16 h; + + for (i = 0; i < 293; i++) + { + h = hash(HuffCodeLEC[i]); + + if (HashTable[h] != 0xffff) + { + HashTable[h] ^= (HuffCodeLEC[i] & 0xfe00) ^ 0xfe00; + HashTable[tab[minihash(HuffCodeLEC[i])]] = i; + } + else + { + HashTable[h] = i; + HashTable[h] ^= 0xfe00; + } + } } UINT16 getvalue(UINT16 huff) { - UINT16 h = HashTable[hash(huff)]; - if((h ^ huff) >> 9) - return h & 0x1ff; - else - return HashTable[tab[minihash(huff)]]; + UINT16 h = HashTable[hash(huff)]; + + if ((h ^ huff) >> 9) + return h & 0x1ff; + else + return HashTable[tab[minihash(huff)]]; } main() { - int i; - buildhashtable(); - printf("static UINT16 HuffIndexLEC[512] = {\n"); - for(i=0;i<512;i++) - { - if(i == 511) - printf("0x%04x };\n",HashTable[i]); - else - printf("0x%04x, ",HashTable[i]); - } - for(i=0;i<293;i++) - if(i != getvalue(HuffCodeLEC[i])) - printf("Fail :( at %d : 0x%04x\n",i,HuffCodeLEC[i]); - return 0; + int i; + buildhashtable(); + printf("static UINT16 HuffIndexLEC[512] = {\n"); + + for (i = 0; i < 512; i++) + { + if (i == 511) + printf("0x%04x };\n", HashTable[i]); + else + printf("0x%04x, ", HashTable[i]); + } + + for (i = 0; i < 293; i++) + if (i != getvalue(HuffCodeLEC[i])) + printf("Fail :( at %d : 0x%04x\n", i, HuffCodeLEC[i]); + + return 0; } diff --git a/scripts/LOMHash.c b/scripts/LOMHash.c index c1d4e36ea..cbcaa51db 100644 --- a/scripts/LOMHash.c +++ b/scripts/LOMHash.c @@ -1,10 +1,12 @@ #include typedef unsigned short UINT16; typedef unsigned char BYTE; -static UINT16 HuffCodeLOM[] = { - 0x0001, 0x0000, 0x0002, 0x0009, 0x0006, 0x0005, 0x000d, 0x000b, 0x0003, 0x001b, 0x0007, 0x0017, 0x0037, -0x000f, 0x004f, 0x006f, 0x002f, 0x00ef, 0x001f, 0x005f, 0x015f, 0x009f, 0x00df, 0x01df, 0x003f, 0x013f, 0x00bf, -0x01bf, 0x007f, 0x017f, 0x00ff, 0x01ff }; +static UINT16 HuffCodeLOM[] = +{ + 0x0001, 0x0000, 0x0002, 0x0009, 0x0006, 0x0005, 0x000d, 0x000b, 0x0003, 0x001b, 0x0007, 0x0017, 0x0037, + 0x000f, 0x004f, 0x006f, 0x002f, 0x00ef, 0x001f, 0x005f, 0x015f, 0x009f, 0x00df, 0x01df, 0x003f, 0x013f, 0x00bf, + 0x01bf, 0x007f, 0x017f, 0x00ff, 0x01ff +}; UINT16 HashTable[32] = { [0 ... 31] = 0xffff }; @@ -12,62 +14,70 @@ BYTE tab[4] = { 0, 4, 10, 19 }; UINT16 hash(UINT16 key) { - return ((key & 0x1f) ^ (key >> 5) ^ (key >> 9)); + return ((key & 0x1f) ^ (key >> 5) ^ (key >> 9)); } BYTE minihash(UINT16 key) { - BYTE h; - h = (key >> 4) & 0xf; - return ((h ^ (h >> 2) ^ (h >> 3)) & 0x3); + BYTE h; + h = (key >> 4) & 0xf; + return ((h ^ (h >> 2) ^ (h >> 3)) & 0x3); } void buildhashtable(void) { - int i,j; - UINT16 h; - for(i=0;i<32;i++) - { - h=hash(HuffCodeLOM[i]); - if(HashTable[h]!=0xffff) - { - HashTable[h] ^= (HuffCodeLOM[i] & 0xfe0) ^ 0xfe0; - HashTable[tab[minihash(HuffCodeLOM[i])]] = i; - } - else - { - HashTable[h] = i; - HashTable[h] ^= 0xfe0; - } - printf("at %d %d=0x%hhx\n",i,h,HashTable[h]); - } + int i, j; + UINT16 h; + + for (i = 0; i < 32; i++) + { + h = hash(HuffCodeLOM[i]); + + if (HashTable[h] != 0xffff) + { + HashTable[h] ^= (HuffCodeLOM[i] & 0xfe0) ^ 0xfe0; + HashTable[tab[minihash(HuffCodeLOM[i])]] = i; + } + else + { + HashTable[h] = i; + HashTable[h] ^= 0xfe0; + } + + printf("at %d %d=0x%hhx\n", i, h, HashTable[h]); + } } BYTE getvalue(UINT16 huff) { - UINT16 h = HashTable[hash(huff)]; - if((h ^ huff) >> 5) - { - return h & 0x1f; - } - else - return HashTable[tab[minihash(huff)]]; + UINT16 h = HashTable[hash(huff)]; + + if ((h ^ huff) >> 5) + { + return h & 0x1f; + } + else + return HashTable[tab[minihash(huff)]]; } main() { - int i; - buildhashtable(); - printf("static UINT16 HuffIndexLOM[32] = {\n"); - for(i=0;i<32;i++) - { - if(i == 31) - printf("0x%hx };\n",HashTable[i]); - else - printf("0x%hx, ",HashTable[i]); - } - for(i=0;i<32;i++) - if(i != getvalue(HuffCodeLOM[i])) - printf("Fail :( at %d : 0x%04x got %d\n",i,HuffCodeLOM[i],getvalue(HuffCodeLOM[i])); - return 0; + int i; + buildhashtable(); + printf("static UINT16 HuffIndexLOM[32] = {\n"); + + for (i = 0; i < 32; i++) + { + if (i == 31) + printf("0x%hx };\n", HashTable[i]); + else + printf("0x%hx, ", HashTable[i]); + } + + for (i = 0; i < 32; i++) + if (i != getvalue(HuffCodeLOM[i])) + printf("Fail :( at %d : 0x%04x got %d\n", i, HuffCodeLOM[i], + getvalue(HuffCodeLOM[i])); + + return 0; } diff --git a/scripts/autoformat.sh b/scripts/autoformat.sh index 4598975ca..f93733fb0 100755 --- a/scripts/autoformat.sh +++ b/scripts/autoformat.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized CHANGESET=`git status | cut -d ':' -f 2 | grep -vE "#|no" | grep -E "*\.h|*\.c"` # get filenames from git status diff --git a/scripts/format_code.sh b/scripts/format_code.sh index 9ea3fbf95..99272f021 100755 --- a/scripts/format_code.sh +++ b/scripts/format_code.sh @@ -9,7 +9,7 @@ fi # Need at least astyle 2.03 due to bugs in older versions # indenting headers with extern "C" -STR_VERSION=$(($ASTYLE --version) 2>&1) +STR_VERSION=$($ASTYLE --version 2>&1) VERSION=$(echo $STR_VERSION | cut -d ' ' -f4) MAJOR_VERSION=$(echo $VERSION | cut -d'.' -f1) MINOR_VERSION=$(echo $VERSION | cut -d'.' -f2) @@ -30,9 +30,10 @@ if [ $# -le 0 ]; then exit 2 fi -$ASTYLE --lineend=linux --mode=c --indent=force-tab=4 --brackets=linux --pad-header \ - --indent-switches --indent-cases --indent-preprocessor \ +$ASTYLE --lineend=linux --mode=c --indent=tab=4 --pad-header --pad-oper --style=allman --min-conditional-indent=0 \ + --indent-switches --indent-cases --indent-preprocessor -k1 --max-code-length=80 \ --indent-col1-comments --delete-empty-lines --break-closing-brackets \ - --align-pointer=type --indent-labels --brackets=break \ + --align-pointer=type --indent-labels -xe \ --unpad-paren --break-blocks $@ - exit $? + +exit $? diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 7e3394760..563cfe35e 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -60,31 +60,28 @@ BOOL test_peer_context_new(freerdp_peer* client, testPeerContext* context) goto fail_rfx_context; if (!rfx_context_reset(context->rfx_context, SAMPLE_SERVER_DEFAULT_WIDTH, - SAMPLE_SERVER_DEFAULT_HEIGHT)) + SAMPLE_SERVER_DEFAULT_HEIGHT)) goto fail_rfx_context; context->rfx_context->mode = RLGR3; - - rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_R8G8B8); + rfx_context_set_pixel_format(context->rfx_context, PIXEL_FORMAT_RGB24); if (!(context->nsc_context = nsc_context_new())) goto fail_nsc_context; - nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8); + nsc_context_set_pixel_format(context->nsc_context, PIXEL_FORMAT_RGB24); if (!(context->s = Stream_New(NULL, 65536))) goto fail_stream_new; context->icon_x = -1; context->icon_y = -1; - context->vcm = WTSOpenServerA((LPSTR) client->context); if (!context->vcm || context->vcm == INVALID_HANDLE_VALUE) goto fail_open_server; return TRUE; - fail_open_server: context->vcm = NULL; Stream_Free(context->s, TRUE); @@ -113,7 +110,6 @@ void test_peer_context_free(freerdp_peer* client, testPeerContext* context) Stream_Free(context->s, TRUE); free(context->icon_data); free(context->bg_data); - rfx_context_free(context->rfx_context); nsc_context_free(context->nsc_context); @@ -153,7 +149,6 @@ static void test_peer_begin_frame(freerdp_peer* client) rdpUpdate* update = client->update; SURFACE_FRAME_MARKER* fm = &update->surface_frame_marker; testPeerContext* context = (testPeerContext*) client->context; - fm->frameAction = SURFACECMD_FRAMEACTION_BEGIN; fm->frameId = context->frame_id; update->SurfaceFrameMarker(update->context, fm); @@ -164,11 +159,9 @@ static void test_peer_end_frame(freerdp_peer* client) rdpUpdate* update = client->update; SURFACE_FRAME_MARKER* fm = &update->surface_frame_marker; testPeerContext* context = (testPeerContext*) client->context; - fm->frameAction = SURFACECMD_FRAMEACTION_END; fm->frameId = context->frame_id; update->SurfaceFrameMarker(update->context, fm); - context->frame_id++; } @@ -181,19 +174,18 @@ static BOOL test_peer_draw_background(freerdp_peer* client) rdpUpdate* update = client->update; SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command; testPeerContext* context = (testPeerContext*) client->context; - BOOL ret= FALSE; + BOOL ret = FALSE; if (!client->settings->RemoteFxCodec && !client->settings->NSCodec) return FALSE; s = test_peer_stream_init(context); - rect.x = 0; rect.y = 0; rect.width = client->settings->DesktopWidth; rect.height = client->settings->DesktopHeight; - size = rect.width * rect.height * 3; + if (!(rgb_data = malloc(size))) { WLog_ERR(TAG, "Problem allocating memory"); @@ -205,16 +197,17 @@ static BOOL test_peer_draw_background(freerdp_peer* client) if (client->settings->RemoteFxCodec) { if (!rfx_compose_message(context->rfx_context, s, - &rect, 1, rgb_data, rect.width, rect.height, rect.width * 3)) + &rect, 1, rgb_data, rect.width, rect.height, rect.width * 3)) { goto out; } + cmd->codecID = client->settings->RemoteFxCodecId; } else { nsc_compose_message(context->nsc_context, s, - rgb_data, rect.width, rect.height, rect.width * 3); + rgb_data, rect.width, rect.height, rect.width * 3); cmd->codecID = client->settings->NSCodecId; } @@ -227,11 +220,9 @@ static BOOL test_peer_draw_background(freerdp_peer* client) cmd->height = rect.height; cmd->bitmapDataLength = Stream_GetPosition(s); cmd->bitmapData = Stream_Buffer(s); - test_peer_begin_frame(client); update->SurfaceBits(update->context, cmd); test_peer_end_frame(client); - ret = TRUE; out: free(rgb_data); @@ -265,11 +256,13 @@ static BOOL test_peer_load_icon(freerdp_peer* client) fgets(line, sizeof(line), fp); /* width height */ fgets(line, sizeof(line), fp); + if (sscanf(line, "%d %d", &context->icon_width, &context->icon_height) < 2) { WLog_ERR(TAG, "Problem while extracting width/height from the icon file"); goto out_fail; } + /* Max */ fgets(line, sizeof(line), fp); @@ -284,16 +277,15 @@ static BOOL test_peer_load_icon(freerdp_peer* client) rgb_data[i] = (BYTE)c; } - /* background with same size, which will be used to erase the icon from old position */ - if (!(context->bg_data = malloc(context->icon_width * context->icon_height * 3))) + if (!(context->bg_data = malloc(context->icon_width * context->icon_height * + 3))) goto out_fail; + memset(context->bg_data, 0xA0, context->icon_width * context->icon_height * 3); context->icon_data = rgb_data; - fclose(fp); return TRUE; - out_fail: free(rgb_data); context->bg_data = NULL; @@ -319,7 +311,6 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y) return; test_peer_begin_frame(client); - rect.x = 0; rect.y = 0; rect.width = context->icon_width; @@ -328,16 +319,17 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y) if (context->icon_x >= 0) { s = test_peer_stream_init(context); + if (client->settings->RemoteFxCodec) { rfx_compose_message(context->rfx_context, s, - &rect, 1, context->bg_data, rect.width, rect.height, rect.width * 3); + &rect, 1, context->bg_data, rect.width, rect.height, rect.width * 3); cmd->codecID = client->settings->RemoteFxCodecId; } else { nsc_compose_message(context->nsc_context, s, - context->bg_data, rect.width, rect.height, rect.width * 3); + context->bg_data, rect.width, rect.height, rect.width * 3); cmd->codecID = client->settings->NSCodecId; } @@ -358,13 +350,13 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y) if (client->settings->RemoteFxCodec) { rfx_compose_message(context->rfx_context, s, - &rect, 1, context->icon_data, rect.width, rect.height, rect.width * 3); + &rect, 1, context->icon_data, rect.width, rect.height, rect.width * 3); cmd->codecID = client->settings->RemoteFxCodecId; } else { nsc_compose_message(context->nsc_context, s, - context->icon_data, rect.width, rect.height, rect.width * 3); + context->icon_data, rect.width, rect.height, rect.width * 3); cmd->codecID = client->settings->NSCodecId; } @@ -378,14 +370,13 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y) cmd->bitmapDataLength = Stream_GetPosition(s); cmd->bitmapData = Stream_Buffer(s); update->SurfaceBits(update->context, cmd); - context->icon_x = x; context->icon_y = y; - test_peer_end_frame(client); } -static BOOL test_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec, UINT32 new_usec) +static BOOL test_sleep_tsdiff(UINT32* old_sec, UINT32* old_usec, UINT32 new_sec, + UINT32 new_usec) { INT32 sec, usec; @@ -431,12 +422,13 @@ BOOL tf_peer_dump_rfx(freerdp_peer* client) rdpUpdate* update; rdpPcap* pcap_rfx; pcap_record record; - s = Stream_New(NULL, 512); + if (!s) return FALSE; update = client->update; + if (!(pcap_rfx = pcap_open(test_pcap_file, FALSE))) return FALSE; @@ -451,11 +443,12 @@ BOOL tf_peer_dump_rfx(freerdp_peer* client) break; record.data = Stream_Buffer(s); - pcap_get_next_record_content(pcap_rfx, &record); Stream_SetPointer(s, Stream_Buffer(s) + Stream_Capacity(s)); - if (test_dump_rfx_realtime && test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, record.header.ts_usec) == FALSE) + if (test_dump_rfx_realtime + && test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, + record.header.ts_usec) == FALSE) break; update->SurfaceCommand(update->context, s); @@ -464,7 +457,6 @@ BOOL tf_peer_dump_rfx(freerdp_peer* client) break; } - Stream_Free(s, TRUE); pcap_close(pcap_rfx); return TRUE; @@ -479,7 +471,8 @@ static void* tf_debug_channel_thread_func(void* arg) ULONG written; testPeerContext* context = (testPeerContext*) arg; - if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer, &BytesReturned) == TRUE) + if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, + &buffer, &BytesReturned) == TRUE) { fd = *((void**) buffer); WTSFreeMemory(buffer); @@ -489,7 +482,6 @@ static void* tf_debug_channel_thread_func(void* arg) } s = Stream_New(NULL, 4096); - WTSVirtualChannelWrite(context->debug_channel, (PCHAR) "test1", 5, &written); while (1) @@ -502,7 +494,7 @@ static void* tf_debug_channel_thread_func(void* arg) Stream_SetPosition(s, 0); if (WTSVirtualChannelRead(context->debug_channel, 0, (PCHAR) Stream_Buffer(s), - Stream_Capacity(s), &BytesReturned) == FALSE) + Stream_Capacity(s), &BytesReturned) == FALSE) { if (BytesReturned == 0) break; @@ -510,7 +502,7 @@ static void* tf_debug_channel_thread_func(void* arg) Stream_EnsureRemainingCapacity(s, BytesReturned); if (WTSVirtualChannelRead(context->debug_channel, 0, (PCHAR) Stream_Buffer(s), - Stream_Capacity(s), &BytesReturned) == FALSE) + Stream_Capacity(s), &BytesReturned) == FALSE) { /* should not happen */ break; @@ -522,45 +514,46 @@ static void* tf_debug_channel_thread_func(void* arg) } Stream_Free(s, TRUE); - return 0; } BOOL tf_peer_post_connect(freerdp_peer* client) { testPeerContext* context = (testPeerContext*) client->context; - /** * This callback is called when the entire connection sequence is done, i.e. we've received the * Font List PDU from the client and sent out the Font Map PDU. * The server may start sending graphics output and receiving keyboard/mouse input after this * callback returns. */ - WLog_DBG(TAG, "Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname, - client->settings->OsMajorType, client->settings->OsMinorType); + WLog_DBG(TAG, "Client %s is activated (osMajorType %d osMinorType %d)", + client->local ? "(local)" : client->hostname, + client->settings->OsMajorType, client->settings->OsMinorType); if (client->settings->AutoLogonEnabled) { WLog_DBG(TAG, " and wants to login automatically as %s\\%s", - client->settings->Domain ? client->settings->Domain : "", - client->settings->Username); + client->settings->Domain ? client->settings->Domain : "", + client->settings->Username); /* A real server may perform OS login here if NLA is not executed previously. */ } WLog_DBG(TAG, ""); WLog_DBG(TAG, "Client requested desktop: %dx%dx%d", - client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth); - + client->settings->DesktopWidth, client->settings->DesktopHeight, + client->settings->ColorDepth); #if (SAMPLE_SERVER_USE_CLIENT_RESOLUTION == 1) + if (!rfx_context_reset(context->rfx_context, client->settings->DesktopWidth, - client->settings->DesktopHeight)) + client->settings->DesktopHeight)) return FALSE; WLog_DBG(TAG, "Using resolution requested by client."); #else client->settings->DesktopWidth = context->rfx_context->width; client->settings->DesktopHeight = context->rfx_context->height; - WLog_DBG(TAG, "Resizing client to %dx%d", client->settings->DesktopWidth, client->settings->DesktopHeight); + WLog_DBG(TAG, "Resizing client to %dx%d", client->settings->DesktopWidth, + client->settings->DesktopHeight); client->update->DesktopResize(client->update->context); #endif @@ -571,14 +564,15 @@ BOOL tf_peer_post_connect(freerdp_peer* client) return FALSE; } - if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpdbg")) { - context->debug_channel = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpdbg"); + context->debug_channel = WTSVirtualChannelOpen(context->vcm, + WTS_CURRENT_SESSION, "rdpdbg"); if (context->debug_channel != NULL) { WLog_DBG(TAG, "Open channel rdpdbg."); + if (!(context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) { WLog_ERR(TAG, "Failed to create stop event"); @@ -586,7 +580,8 @@ BOOL tf_peer_post_connect(freerdp_peer* client) } if (!(context->debug_channel_thread = CreateThread(NULL, 0, - (LPTHREAD_START_ROUTINE) tf_debug_channel_thread_func, (void*) context, 0, NULL))) + (LPTHREAD_START_ROUTINE) tf_debug_channel_thread_func, (void*) context, 0, + NULL))) { WLog_ERR(TAG, "Failed to create debug channel thread"); CloseHandle(context->stopEvent); @@ -607,20 +602,15 @@ BOOL tf_peer_post_connect(freerdp_peer* client) } /* Dynamic Virtual Channels */ - sf_peer_audin_init(context); /* Audio Input */ - /* Return FALSE here would stop the execution of the peer main loop. */ - return TRUE; } BOOL tf_peer_activate(freerdp_peer* client) { testPeerContext* context = (testPeerContext*) client->context; - context->activated = TRUE; - //client->settings->CompressionLevel = PACKET_COMPR_TYPE_8K; //client->settings->CompressionLevel = PACKET_COMPR_TYPE_64K; //client->settings->CompressionLevel = PACKET_COMPR_TYPE_RDP6; @@ -629,6 +619,7 @@ BOOL tf_peer_activate(freerdp_peer* client) if (test_pcap_file != NULL) { client->update->dump_rfx = TRUE; + if (!tf_peer_dump_rfx(client)) return FALSE; } @@ -649,7 +640,8 @@ BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) freerdp_peer* client = input->context->peer; rdpUpdate* update = client->update; testPeerContext* context = (testPeerContext*) input->context; - WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%X code:0x%X)", flags, code); + WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%X code:0x%X)", flags, + code); if ((flags & 0x4000) && code == 0x22) /* 'g' key */ { @@ -663,8 +655,9 @@ BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) client->settings->DesktopWidth = SAMPLE_SERVER_DEFAULT_WIDTH; client->settings->DesktopHeight = SAMPLE_SERVER_DEFAULT_HEIGHT; } + if (!rfx_context_reset(context->rfx_context, client->settings->DesktopWidth, - client->settings->DesktopHeight)) + client->settings->DesktopHeight)) return FALSE; update->DesktopResize(update->context); @@ -697,14 +690,15 @@ BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) } else if ((flags & 0x4000) && code == 0x1F) /* 's' key */ { - } + return TRUE; } BOOL tf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - WLog_DBG(TAG, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)", flags, code); + WLog_DBG(TAG, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)", + flags, code); return TRUE; } @@ -715,34 +709,41 @@ BOOL tf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) return TRUE; } -BOOL tf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) +BOOL tf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, + UINT16 y) { //WLog_DBG(TAG, "Client sent an extended mouse event (flags:0x%X pos:%d,%d)", flags, x, y); return TRUE; } -static BOOL tf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) +static BOOL tf_peer_refresh_rect(rdpContext* context, BYTE count, + const RECTANGLE_16* areas) { BYTE i; WLog_DBG(TAG, "Client requested to refresh:"); for (i = 0; i < count; i++) { - WLog_DBG(TAG, " (%d, %d) (%d, %d)", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); + WLog_DBG(TAG, " (%d, %d) (%d, %d)", areas[i].left, areas[i].top, + areas[i].right, areas[i].bottom); } + return TRUE; } -static BOOL tf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area) +static BOOL tf_peer_suppress_output(rdpContext* context, BYTE allow, + const RECTANGLE_16* area) { if (allow > 0) { - WLog_DBG(TAG, "Client restore output (%d, %d) (%d, %d).", area->left, area->top, area->right, area->bottom); + WLog_DBG(TAG, "Client restore output (%d, %d) (%d, %d).", area->left, area->top, + area->right, area->bottom); } else { WLog_DBG(TAG, "Client minimized and suppress output."); } + return TRUE; } @@ -764,12 +765,15 @@ static void* test_peer_mainloop(void* arg) client->settings->CertificateFile = _strdup("server.crt"); client->settings->PrivateKeyFile = _strdup("server.key"); client->settings->RdpKeyFile = _strdup("server.key"); - if (!client->settings->CertificateFile || !client->settings->PrivateKeyFile || !client->settings->RdpKeyFile) + + if (!client->settings->CertificateFile || !client->settings->PrivateKeyFile + || !client->settings->RdpKeyFile) { WLog_ERR(TAG, "Memory allocation failed (strdup)"); freerdp_peer_free(client); return NULL; } + client->settings->RdpSecurity = TRUE; client->settings->TlsSecurity = TRUE; client->settings->NlaSecurity = FALSE; @@ -777,36 +781,30 @@ static void* test_peer_mainloop(void* arg) /* client->settings->EncryptionLevel = ENCRYPTION_LEVEL_HIGH; */ /* client->settings->EncryptionLevel = ENCRYPTION_LEVEL_LOW; */ /* client->settings->EncryptionLevel = ENCRYPTION_LEVEL_FIPS; */ - client->settings->RemoteFxCodec = TRUE; client->settings->ColorDepth = 32; client->settings->SuppressOutput = TRUE; client->settings->RefreshRect = TRUE; - client->PostConnect = tf_peer_post_connect; client->Activate = tf_peer_activate; - client->input->SynchronizeEvent = tf_peer_synchronize_event; client->input->KeyboardEvent = tf_peer_keyboard_event; client->input->UnicodeKeyboardEvent = tf_peer_unicode_keyboard_event; client->input->MouseEvent = tf_peer_mouse_event; client->input->ExtendedMouseEvent = tf_peer_extended_mouse_event; - client->update->RefreshRect = tf_peer_refresh_rect; client->update->SuppressOutput = tf_peer_suppress_output; - client->settings->MultifragMaxRequestSize = 0xFFFFFF; /* FIXME */ - client->Initialize(client); context = (testPeerContext*) client->context; - WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname); + WLog_INFO(TAG, "We've got a client %s", + client->local ? "(local)" : client->hostname); while (1) { count = 0; handles[count++] = client->GetEventHandle(client); handles[count++] = WTSVirtualChannelManagerGetEventHandle(context->vcm); - status = WaitForMultipleObjects(count, handles, FALSE, INFINITE); if (status == WAIT_FAILED) @@ -822,11 +820,11 @@ static void* test_peer_mainloop(void* arg) break; } - WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname); + WLog_INFO(TAG, "Client %s disconnected.", + client->local ? "(local)" : client->hostname); client->Disconnect(client); freerdp_peer_context_free(client); freerdp_peer_free(client); - return NULL; } @@ -834,7 +832,8 @@ static BOOL test_peer_accepted(freerdp_listener* instance, freerdp_peer* client) { HANDLE hThread; - if (!(hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_peer_mainloop, (void*) client, 0, NULL))) + if (!(hThread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) test_peer_mainloop, (void*) client, 0, NULL))) return FALSE; CloseHandle(hThread); @@ -850,6 +849,7 @@ static void test_server_mainloop(freerdp_listener* instance) while (1) { count = instance->GetEventHandles(instance, handles, 32); + if (0 == count) { WLog_ERR(TAG, "Failed to get FreeRDP event handles"); @@ -882,7 +882,7 @@ int main(int argc, char* argv[]) char name[MAX_PATH]; int port = 3389, i; - for (i=1; i 0xFFFF)) return -1; } @@ -904,6 +906,7 @@ int main(int argc, char* argv[]) WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi()); instance = freerdp_listener_new(); + if (!instance) return -1; @@ -918,6 +921,7 @@ int main(int argc, char* argv[]) /* Open the server socket and start listening. */ sprintf_s(name, sizeof(name), "tfreerdp-server.%d", port); file = GetKnownSubPath(KNOWN_PATH_TEMP, name); + if (!file) { freerdp_listener_free(instance); @@ -926,17 +930,15 @@ int main(int argc, char* argv[]) } if (instance->Open(instance, NULL, port) && - instance->OpenLocal(instance, file)) + instance->OpenLocal(instance, file)) { /* Entering the server main loop. In a real server the listener can be run in its own thread. */ test_server_mainloop(instance); } - free (file); + free(file); freerdp_listener_free(instance); - WSACleanup(); - return 0; } diff --git a/server/shadow/shadow_encoder.c b/server/shadow/shadow_encoder.c index 44fb3ac16..12b6c9fc3 100644 --- a/server/shadow/shadow_encoder.c +++ b/server/shadow/shadow_encoder.c @@ -141,7 +141,7 @@ int shadow_encoder_init_rfx(rdpShadowEncoder* encoder) encoder->rfx->mode = encoder->server->rfxMode; - rfx_context_set_pixel_format(encoder->rfx, RDP_PIXEL_FORMAT_B8G8R8A8); + rfx_context_set_pixel_format(encoder->rfx, PIXEL_FORMAT_BGR24); encoder->codecs |= FREERDP_CODEC_REMOTEFX; diff --git a/uwac/libuwac/uwac-window.c b/uwac/libuwac/uwac-window.c index b3fd370ad..fcc408fef 100644 --- a/uwac/libuwac/uwac-window.c +++ b/uwac/libuwac/uwac-window.c @@ -507,7 +507,7 @@ static const struct wl_callback_listener frame_listener = { static void UwacSubmitBufferPtr(UwacWindow *window, UwacBuffer *buffer) { - int nrects, i; + UINT32 nrects, i; #ifdef HAVE_PIXMAN_REGION const pixman_box32_t *box; #else