From a546388063a723771e3a6d588d428028536aed91 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 20 Sep 2023 08:53:01 +0200 Subject: [PATCH] [gdi,line] clean up line functions * Simplify CMake source detection * Clean up code in line.c, add assertions --- libfreerdp/gdi/CMakeLists.txt | 22 +++-------- libfreerdp/gdi/line.c | 73 ++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/libfreerdp/gdi/CMakeLists.txt b/libfreerdp/gdi/CMakeLists.txt index 891e74338..97e1d27f9 100644 --- a/libfreerdp/gdi/CMakeLists.txt +++ b/libfreerdp/gdi/CMakeLists.txt @@ -20,22 +20,12 @@ set(MODULE_PREFIX "FREERDP_GDI") include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -set(${MODULE_PREFIX}_SRCS - bitmap.c - brush.c - clipping.c - dc.c - drawing.c - line.c - pen.c - region.c - shape.c - graphics.c - graphics.h - gfx.c - video.c - gdi.c - gdi.h) +file(GLOB ${MODULE_PREFIX}_SRCS + LIST_DIRECTORIES false + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + CONFIGURE_DEPENDS + "*.[ch]" +) freerdp_module_add(${${MODULE_PREFIX}_SRCS}) diff --git a/libfreerdp/gdi/line.c b/libfreerdp/gdi/line.c index ce3d5b2b4..7c600dc1f 100644 --- a/libfreerdp/gdi/line.c +++ b/libfreerdp/gdi/line.c @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -37,6 +39,7 @@ static BOOL gdi_rop_color(UINT32 rop, BYTE* pixelPtr, UINT32 pen, UINT32 format) { + WINPR_ASSERT(pixelPtr); const UINT32 srcPixel = FreeRDPReadColor(pixelPtr, format); UINT32 dstPixel; @@ -115,30 +118,26 @@ static BOOL gdi_rop_color(UINT32 rop, BYTE* pixelPtr, UINT32 pen, UINT32 format) BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd) { - INT32 x, y; - INT32 x1, y1; - INT32 x2, y2; - INT32 e, e2; - INT32 dx, dy; - INT32 sx, sy; - INT32 bx1, by1; - INT32 bx2, by2; - HGDI_BITMAP bmp; + INT32 e2; UINT32 pen; - INT32 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; + WINPR_ASSERT(hdc); + const INT32 rop2 = gdi_GetROP2(hdc); + + const INT32 x1 = hdc->pen->posX; + const INT32 y1 = hdc->pen->posY; + const INT32 x2 = nXEnd; + const INT32 y2 = nYEnd; + const INT32 dx = (x1 > x2) ? x1 - x2 : x2 - x1; + const INT32 dy = (y1 > y2) ? y1 - y2 : y2 - y1; + const INT32 sx = (x1 < x2) ? 1 : -1; + const INT32 sy = (y1 < y2) ? 1 : -1; + INT32 e = dx - dy; + INT32 x = x1; + INT32 y = y1; + + WINPR_ASSERT(hdc->clip); + INT32 bx1, by1, bx2, by2; if (hdc->clip->null) { bx1 = (x1 < x2) ? x1 : x2; @@ -154,6 +153,9 @@ BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd) by2 = by1 + hdc->clip->h - 1; } + HGDI_BITMAP bmp = (HGDI_BITMAP)hdc->selectedObject; + WINPR_ASSERT(bmp); + bx1 = MAX(bx1, 0); by1 = MAX(by1, 0); bx2 = MIN(bx2, bmp->width - 1); @@ -171,6 +173,7 @@ BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd) if ((x >= bx1 && x <= bx2) && (y >= by1 && y <= by2)) { BYTE* pixel = gdi_GetPointer(bmp, x, y); + WINPR_ASSERT(pixel); gdi_rop_color(rop2, pixel, pen, bmp->format); } } @@ -206,9 +209,10 @@ BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd) */ BOOL gdi_PolylineTo(HGDI_DC hdc, GDI_POINT* lppt, DWORD cCount) { - DWORD i; + WINPR_ASSERT(hdc); + WINPR_ASSERT(lppt || (cCount == 0)); - for (i = 0; i < cCount; i++) + for (DWORD i = 0; i < cCount; i++) { if (!gdi_LineTo(hdc, lppt[i].x, lppt[i].y)) return FALSE; @@ -229,15 +233,17 @@ BOOL gdi_PolylineTo(HGDI_DC hdc, GDI_POINT* lppt, DWORD cCount) */ BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT* lppt, UINT32 cPoints) { + WINPR_ASSERT(hdc); + WINPR_ASSERT(lppt || (cPoints == 0)); + if (cPoints > 0) { - UINT32 i; - GDI_POINT pt; + GDI_POINT pt = { 0 }; if (!gdi_MoveToEx(hdc, lppt[0].x, lppt[0].y, &pt)) return FALSE; - for (i = 0; i < cPoints; i++) + for (UINT32 i = 0; i < cPoints; i++) { if (!gdi_LineTo(hdc, lppt[i].x, lppt[i].y)) return FALSE; @@ -263,12 +269,15 @@ BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT* lppt, UINT32 cPoints) */ BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT* lppt, UINT32* lpdwPolyPoints, DWORD cCount) { - UINT32 cPoints; - DWORD i, j = 0; + DWORD j = 0; - for (i = 0; i < cCount; i++) + WINPR_ASSERT(hdc); + WINPR_ASSERT(lppt || (cCount == 0)); + WINPR_ASSERT(lpdwPolyPoints || (cCount == 0)); + + for (DWORD i = 0; i < cCount; i++) { - cPoints = lpdwPolyPoints[i]; + const UINT32 cPoints = lpdwPolyPoints[i]; if (!gdi_Polyline(hdc, &lppt[j], cPoints)) return FALSE; @@ -289,6 +298,8 @@ BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT* lppt, UINT32* lpdwPolyPoints, DWOR BOOL gdi_MoveToEx(HGDI_DC hdc, UINT32 X, UINT32 Y, HGDI_POINT lpPoint) { + WINPR_ASSERT(hdc); + if (lpPoint != NULL) { lpPoint->x = hdc->pen->posX;