Added brush helper function to retrieve style.
authorArmin Novak <armin.novak@thincast.com>
Tue, 2 Aug 2016 06:43:26 +0000 (08:43 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 6 Oct 2016 11:43:05 +0000 (13:43 +0200)
libfreerdp/gdi/bitmap.c
libfreerdp/gdi/brush.c
libfreerdp/gdi/brush.h
libfreerdp/gdi/dc.c
libfreerdp/gdi/gdi.c

index f899290..7105528 100644 (file)
@@ -402,62 +402,67 @@ static BOOL BitBlt_DSPDxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                            UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
+       UINT32 color;
 
        if (!hdcDest || !hdcSrc)
                return FALSE;
 
-       if (hdcDest->brush->style == GDI_BS_SOLID)
+       switch (gdi_GetBrushStyle(hdcDest))
        {
-               UINT32 color = hdcDest->brush->color;
+               case GDI_BS_SOLID:
+                       color = hdcDest->brush->color;
 
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 dstColor;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       dstColor = (colorB ^ colorA) & (color ^ colorB);
-                                       WriteColor(dstp, hdcDest->format, dstColor);
+                                       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 dstColor;
+                                               UINT32 colorA = ReadColor(srcp, hdcSrc->format);
+                                               UINT32 colorB = ReadColor(dstp, hdcDest->format);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               dstColor = (colorB ^ colorA) & (color ^ colorB);
+                                               WriteColor(dstp, hdcDest->format, dstColor);
+                                       }
                                }
                        }
-               }
-       }
-       else
-       {
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+
+                       break;
+
+               default:
+                       for (y = 0; y < nHeight; y++)
                        {
-                               const BYTE* patp = gdi_get_brush_pointer(
-                                                      hdcDest, nXDest + x, nYDest + y);
-                               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)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 dstColor;
-                                       UINT32 color = ReadColor(patp, hdcDest->format);
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       dstColor = (colorB ^ colorA) & (color ^ colorB);
-                                       WriteColor(dstp, hdcDest->format, dstColor);
+                                       const BYTE* patp = gdi_get_brush_pointer(
+                                                              hdcDest, nXDest + x, nYDest + y);
+                                       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 dstColor;
+                                               UINT32 color = ReadColor(patp, hdcDest->format);
+                                               UINT32 colorA = ReadColor(srcp, hdcSrc->format);
+                                               UINT32 colorB = ReadColor(dstp, hdcDest->format);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               dstColor = (colorB ^ colorA) & (color ^ colorB);
+                                               WriteColor(dstp, hdcDest->format, dstColor);
+                                       }
                                }
                        }
-               }
+
+                       break;
        }
 
        return TRUE;
@@ -467,63 +472,67 @@ static BOOL BitBlt_DSPDxox(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                            UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
                            UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
-       UINT32 x, y;
+       UINT32 x, y, color;
 
        if (!hdcDest || !hdcSrc)
                return FALSE;
 
-       if (hdcDest->brush->style == GDI_BS_SOLID)
+       switch (gdi_GetBrushStyle(hdcDest))
        {
-               UINT32 color = hdcDest->textColor;
+               case GDI_BS_SOLID:
+                       color = hdcDest->textColor;
 
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 dstColor;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       dstColor = (colorA ^ colorB) | (color ^ colorB);
-                                       WriteColor(dstp, hdcDest->format, dstColor);
+                                       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 dstColor;
+                                               UINT32 colorA = ReadColor(srcp, hdcSrc->format);
+                                               UINT32 colorB = ReadColor(dstp, hdcDest->format);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               dstColor = (colorA ^ colorB) | (color ^ colorB);
+                                               WriteColor(dstp, hdcDest->format, dstColor);
+                                       }
                                }
                        }
-               }
-       }
-       else
-       {
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+
+                       break;
+
+               default:
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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 && dstp)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 color;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       UINT32 colorC = ReadColor(patp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       color = (colorA ^ colorB) | (colorB ^ colorC);
-                                       WriteColor(dstp, hdcDest->format, color);
+                                       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 && dstp)
+                                       {
+                                               UINT32 color;
+                                               UINT32 colorA = ReadColor(srcp, hdcSrc->format);
+                                               UINT32 colorB = ReadColor(dstp, hdcDest->format);
+                                               UINT32 colorC = ReadColor(patp, hdcDest->format);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               color = (colorA ^ colorB) | (colorB ^ colorC);
+                                               WriteColor(dstp, hdcDest->format, color);
+                                       }
                                }
                        }
-               }
+
+                       break;
        }
 
        return TRUE;
@@ -533,63 +542,67 @@ static BOOL BitBlt_PSDPxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                            UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
                            UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
-       UINT32 x, y;
+       UINT32 x, y, colorC;
 
        if (!hdcDest || !hdcSrc)
                return FALSE;
 
-       if (hdcDest->brush->style == GDI_BS_SOLID)
+       switch (gdi_GetBrushStyle(hdcDest))
        {
-               UINT32 colorC = hdcDest->brush->color;
+               case GDI_BS_SOLID:
+                       colorC = hdcDest->brush->color;
 
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 color;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       color = (colorA ^ colorC) & (colorB ^ colorC);
-                                       WriteColor(dstp, hdcDest->format, color);
+                                       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, palette);
+                                               color = (colorA ^ colorC) & (colorB ^ colorC);
+                                               WriteColor(dstp, hdcDest->format, color);
+                                       }
                                }
                        }
-               }
-       }
-       else
-       {
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+
+                       break;
+
+               default:
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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 && dstp)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 color;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       UINT32 colorC = ReadColor(patp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       color = (colorA ^ colorC) & (colorB ^ colorC);
-                                       WriteColor(dstp, hdcDest->format, color);
+                                       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 && dstp)
+                                       {
+                                               UINT32 color;
+                                               UINT32 colorA = ReadColor(srcp, hdcSrc->format);
+                                               UINT32 colorB = ReadColor(dstp, hdcDest->format);
+                                               UINT32 colorC = ReadColor(patp, hdcDest->format);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               color = (colorA ^ colorC) & (colorB ^ colorC);
+                                               WriteColor(dstp, hdcDest->format, color);
+                                       }
                                }
                        }
-               }
+
+                       break;
        }
 
        return TRUE;
@@ -599,64 +612,68 @@ static BOOL BitBlt_SPDSxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                            UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
                            UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
-       UINT32 x, y;
+       UINT32 x, y, color;
 
        if (!hdcDest || !hdcSrc)
                return FALSE;
 
        /* D = S ^ (P & (D ^ S)) */
-       if (hdcDest->brush->style == GDI_BS_SOLID)
+       switch (gdi_GetBrushStyle(hdcDest))
        {
-               UINT32 color = hdcDest->brush->color;
+               case GDI_BS_SOLID:
+                       color = hdcDest->brush->color;
 
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 colorD;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       colorD = (colorA ^ color) & (colorB ^ colorA);
-                                       WriteColor(dstp, hdcDest->format, colorD);
+                                       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 colorD;
+                                               UINT32 colorA = ReadColor(srcp, hdcSrc->format);
+                                               UINT32 colorB = ReadColor(dstp, hdcDest->format);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               colorD = (colorA ^ color) & (colorB ^ colorA);
+                                               WriteColor(dstp, hdcDest->format, colorD);
+                                       }
                                }
                        }
-               }
-       }
-       else
-       {
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+
+                       break;
+
+               default:
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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 && dstp)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 colorD;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       UINT32 color = ReadColor(patp, hdcDest->format);
-                                       colorA = ConvertColor(colorA, hdcSrc->format,
-                                                             hdcDest->format, palette);
-                                       colorD = (colorA ^ color) & (colorB ^ colorA);
-                                       WriteColor(dstp, hdcDest->format, colorD);
+                                       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 && dstp)
+                                       {
+                                               UINT32 colorD;
+                                               UINT32 colorA = ReadColor(srcp, hdcSrc->format);
+                                               UINT32 colorB = ReadColor(dstp, hdcDest->format);
+                                               UINT32 color = ReadColor(patp, hdcDest->format);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               colorD = (colorA ^ color) & (colorB ^ colorA);
+                                               WriteColor(dstp, hdcDest->format, colorD);
+                                       }
                                }
                        }
-               }
+
+                       break;
        }
 
        return TRUE;
@@ -666,58 +683,61 @@ static BOOL BitBlt_SPna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                         UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
                         UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
-       UINT32 x, y;
+       UINT32 x, y, colorB;
 
        if (!hdcDest || !hdcSrc)
                return FALSE;
 
-       if (hdcDest->brush->style == GDI_BS_SOLID)
+       switch (gdi_GetBrushStyle(hdcDest))
        {
-               UINT32 colorB = hdcDest->brush->color;
+               case GDI_BS_SOLID:
+                       colorB = hdcDest->brush->color;
 
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 color;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       colorB = ConvertColor(colorB, hdcDest->format,
-                                                             hdcSrc->format, palette);
-                                       color = ~colorA & colorB;
-                                       color = ConvertColor(color, hdcSrc->format, hdcDest->format, palette);
-                                       WriteColor(dstp, hdcDest->format, color);
+                                       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);
+                                               colorA = ConvertColor(colorA, hdcSrc->format,
+                                                                     hdcDest->format, palette);
+                                               color = ~colorA & colorB;
+                                               color = ConvertColor(color, hdcSrc->format, hdcDest->format, palette);
+                                               WriteColor(dstp, hdcDest->format, color);
+                                       }
                                }
                        }
-               }
-       }
-       else
-       {
-               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)
+                       break;
+
+               default:
+                       for (y = 0; y < nHeight; y++)
+                       {
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 color;
-                                       UINT32 colorA = ReadColor(srcp, hdcSrc->format);
-                                       UINT32 colorB = ReadColor(patp, hdcDest->format);
-                                       colorB = ConvertColor(colorB, hdcDest->format,
-                                                             hdcSrc->format, palette);
-                                       color = ~colorA & colorB;
-                                       color = ConvertColor(color, hdcSrc->format, hdcDest->format, palette);
-                                       WriteColor(dstp, hdcDest->format, color);
+                                       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, palette);
+                                               color = ~colorA & colorB;
+                                               WriteColor(dstp, hdcDest->format, color);
+                                       }
                                }
                        }
-               }
+
+                       break;
        }
 
        return TRUE;
index 7fee455..0de152e 100644 (file)
@@ -322,6 +322,14 @@ HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp)
        return hBrush;
 }
 
+UINT32 gdi_GetBrushStyle(HGDI_DC hdc)
+{
+       if (!hdc || !hdc->brush)
+               return GDI_BS_NULL;
+
+       return hdc->brush->style;
+}
+
 /**
  * Perform a pattern blit operation on the given pixel buffer.\n
  * @msdn{dd162778}
@@ -387,45 +395,50 @@ static BOOL BitBlt_PATINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                              UINT32 nWidth, UINT32 nHeight)
 {
        UINT32 x, y;
+       UINT32 color;
 
        /* DPx */
-       if (hdcDest->brush->style == GDI_BS_SOLID)
+       switch (gdi_GetBrushStyle(hdcDest))
        {
-               UINT32 color = hdcDest->brush->color;
+               case GDI_BS_SOLID:
+                       color = hdcDest->brush->color;
 
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+                       for (y = 0; y < nHeight; y++)
                        {
-                               BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y);
-
-                               if (dstp)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 dstColor = ReadColor(dstp, hdcDest->format);
-                                       dstColor ^= color;
-                                       WriteColor(dstp, hdcDest->format, dstColor);
+                                       BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, nXDest + x, nYDest + y);
+
+                                       if (dstp)
+                                       {
+                                               UINT32 dstColor = ReadColor(dstp, hdcDest->format);
+                                               dstColor ^= color;
+                                               WriteColor(dstp, hdcDest->format, dstColor);
+                                       }
                                }
                        }
-               }
-       }
-       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)
+                       break;
+
+               default:
+                       for (y = 0; y < nHeight; y++)
+                       {
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 colorA = ReadColor(patp, hdcDest->format);
-                                       UINT32 colorB = ReadColor(dstp, hdcDest->format);
-                                       UINT32 color = colorA ^ colorB;
-                                       WriteColor(dstp, hdcDest->format, color);
+                                       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);
+                                       }
                                }
                        }
-               }
+
+                       break;
        }
 
        return TRUE;
@@ -466,56 +479,53 @@ static BOOL BitBlt_PATPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 static BOOL BitBlt_PATCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                            UINT32 nWidth, UINT32 nHeight)
 {
-       UINT32 x, y, xOffset, yOffset;
+       UINT32 x, y, xOffset = 0, yOffset = 0, color;
 
        /* P */
-       if (hdcDest->brush->style == GDI_BS_SOLID)
+       switch (gdi_GetBrushStyle(hdcDest))
        {
-               UINT32 color = hdcDest->brush->color;
+               case GDI_BS_SOLID:
+                       color = hdcDest->brush->color;
 
-               for (y = 0; y < nHeight; y++)
-               {
-                       for (x = 0; x < nWidth; x++)
+                       for (y = 0; y < nHeight; y++)
                        {
-                               BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + 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);
+                                       if (dstp)
+                                               WriteColor(dstp, hdcDest->format, color);
+                               }
                        }
-               }
-       }
-       else
-       {
-               if (hdcDest->brush->style == GDI_BS_HATCHED)
-               {
+
+                       break;
+
+               case 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++)
+               default:
+                       for (y = 0; y < nHeight; y++)
                        {
-                               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)
+                               for (x = 0; x < nWidth; x++)
                                {
-                                       UINT32 color = ReadColor(patp, hdcDest->format);
-                                       WriteColor(dstp, hdcDest->format, color);
+                                       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);
+                                       }
                                }
                        }
-               }
+
+                       break;
        }
 
        return TRUE;
index a34883d..5a2c273 100644 (file)
@@ -34,6 +34,7 @@ const char* gdi_rop_to_string(UINT32 code);
 HGDI_BRUSH gdi_CreateSolidBrush(UINT32 crColor);
 HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp);
 HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp);
+UINT32 gdi_GetBrushStyle(HGDI_DC hdc);
 BOOL gdi_PatBlt(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft,
                 UINT32 nWidth, UINT32 nHeight, DWORD rop,
                 HGDI_DC hdcSrc, UINT32 nXSRc, UINT32 nYSrc);
index c3f9cd1..5ab59a0 100644 (file)
 HGDI_DC gdi_GetDC(void)
 {
        HGDI_DC hDC = (HGDI_DC) calloc(1, sizeof(GDI_DC));
+
        if (!hDC)
                return NULL;
 
        hDC->format = PIXEL_FORMAT_XRGB32;
        hDC->drawMode = GDI_R2_BLACK;
        hDC->clip = gdi_CreateRectRgn(0, 0, 0, 0);
+
        if (!hDC->clip)
        {
                free(hDC);
                return NULL;
        }
+
        hDC->clip->null = 1;
        hDC->hwnd = NULL;
        return hDC;
@@ -80,7 +83,6 @@ HGDI_DC gdi_CreateDC(UINT32 format)
 
        hDC->clip->null = 1;
        hDC->hwnd = NULL;
-
        hDC->format = format;
 
        if (!(hDC->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND))))
@@ -90,15 +92,14 @@ HGDI_DC gdi_CreateDC(UINT32 format)
                goto fail;
 
        hDC->hwnd->invalid->null = 1;
-
        hDC->hwnd->count = 32;
-       if (!(hDC->hwnd->cinvalid = (HGDI_RGN) calloc(hDC->hwnd->count, sizeof(GDI_RGN))))
+
+       if (!(hDC->hwnd->cinvalid = (HGDI_RGN) calloc(hDC->hwnd->count,
+                                   sizeof(GDI_RGN))))
                goto fail;
 
        hDC->hwnd->ninvalid = 0;
-
        return hDC;
-
 fail:
        gdi_DeleteDC(hDC);
        return NULL;
@@ -114,6 +115,7 @@ fail:
 HGDI_DC gdi_CreateCompatibleDC(HGDI_DC hdc)
 {
        HGDI_DC hDC = (HGDI_DC) calloc(1, sizeof(GDI_DC));
+
        if (!hDC)
                return NULL;
 
@@ -122,6 +124,7 @@ HGDI_DC gdi_CreateCompatibleDC(HGDI_DC hdc)
                free(hDC);
                return NULL;
        }
+
        hDC->clip->null = 1;
        hDC->format = hdc->format;
        hDC->drawMode = hdc->drawMode;
@@ -210,10 +213,20 @@ BOOL gdi_DeleteObject(HGDIOBJECT hgdiobject)
        {
                HGDI_BRUSH hBrush = (HGDI_BRUSH) hgdiobject;
 
-               if (hBrush->style == GDI_BS_PATTERN || hBrush->style == GDI_BS_HATCHED)
+               if (hBrush)
                {
-                       if (hBrush->pattern != NULL)
-                               gdi_DeleteObject((HGDIOBJECT) hBrush->pattern);
+                       switch (hBrush->style)
+                       {
+                               case GDI_BS_PATTERN:
+                               case GDI_BS_HATCHED:
+                                       if (hBrush->pattern != NULL)
+                                               gdi_DeleteObject((HGDIOBJECT) hBrush->pattern);
+
+                                       break;
+
+                               default:
+                                       break;
+                       }
                }
 
                free(hBrush);
@@ -254,6 +267,7 @@ BOOL gdi_DeleteDC(HGDI_DC hdc)
                        free(hdc->hwnd->invalid);
                        free(hdc->hwnd);
                }
+
                free(hdc->clip);
                free(hdc);
        }
index 5c97fee..2173eee 100644 (file)
@@ -397,25 +397,30 @@ BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, UINT32 x, UINT32 y)
 BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y)
 {
        BYTE* p;
+       UINT32 brushStyle = gdi_GetBrushStyle(hdcBrush);
 
-       if (hdcBrush->brush != NULL)
+       switch (brushStyle)
        {
-               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 */
-                       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;
-               }
+               case GDI_BS_PATTERN:
+               case 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 */
+                               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;
+                       }
+                       break;
+
+               default:
+                       break;
        }
 
        p = (BYTE*) & (hdcBrush->textColor);