From 0cc2f09e89c5a82d2b4baeb855d2cfe4e0face14 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Wed, 24 Feb 2010 06:08:26 +0000 Subject: Avoid casting warnings from GCC. --- win32/PlatWin.cxx | 66 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'win32/PlatWin.cxx') diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 71a968541..65e05f9db 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -617,6 +617,18 @@ static void AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD va #define AC_SRC_ALPHA 0x01 #endif +static DWORD dwordFromBGRA(byte b, byte g, byte r, byte a) { + union { + byte pixVal[4]; + DWORD val; + } converter; + converter.pixVal[0] = b; + converter.pixVal[1] = g; + converter.pixVal[2] = r; + converter.pixVal[3] = a; + return converter.val; +} + void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill, ColourAllocated outline, int alphaOutline, int /* flags*/ ) { if (AlphaBlendFn && rc.Width() > 0) { @@ -632,18 +644,17 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated HBITMAP hbmOld = SelectBitmap(hMemDC, hbmMem); - byte pixVal[4] = {0}; - DWORD valEmpty = *(reinterpret_cast(pixVal)); - pixVal[0] = static_cast(GetBValue(fill.AsLong()) * alphaFill / 255); - pixVal[1] = static_cast(GetGValue(fill.AsLong()) * alphaFill / 255); - pixVal[2] = static_cast(GetRValue(fill.AsLong()) * alphaFill / 255); - pixVal[3] = static_cast(alphaFill); - DWORD valFill = *(reinterpret_cast(pixVal)); - pixVal[0] = static_cast(GetBValue(outline.AsLong()) * alphaOutline / 255); - pixVal[1] = static_cast(GetGValue(outline.AsLong()) * alphaOutline / 255); - pixVal[2] = static_cast(GetRValue(outline.AsLong()) * alphaOutline / 255); - pixVal[3] = static_cast(alphaOutline); - DWORD valOutline = *(reinterpret_cast(pixVal)); + DWORD valEmpty = dwordFromBGRA(0,0,0,0); + DWORD valFill = dwordFromBGRA( + static_cast(GetBValue(fill.AsLong()) * alphaFill / 255), + static_cast(GetGValue(fill.AsLong()) * alphaFill / 255), + static_cast(GetRValue(fill.AsLong()) * alphaFill / 255), + static_cast(alphaFill)); + DWORD valOutline = dwordFromBGRA( + static_cast(GetBValue(outline.AsLong()) * alphaOutline / 255), + static_cast(GetGValue(outline.AsLong()) * alphaOutline / 255), + static_cast(GetRValue(outline.AsLong()) * alphaOutline / 255), + static_cast(alphaOutline)); DWORD *pixels = reinterpret_cast(image); for (int y=0; y(lParam); - *reinterpret_cast(&minMax->ptMaxTrackSize) = MaxTrackSize(); - *reinterpret_cast(&minMax->ptMinTrackSize) = MinTrackSize(); + minMax->ptMaxTrackSize = MaxTrackSize(); + minMax->ptMinTrackSize = MinTrackSize(); } break; @@ -2115,8 +2128,13 @@ public: // Use GetProcAddress to get a pointer to the relevant function. virtual Function FindFunction(const char *name) { if (h != NULL) { - return static_cast( - (void *)(::GetProcAddress(h, name))); + // C++ standard doesn't like casts betwen function pointers and void pointers so use a union + union { + FARPROC fp; + Function f; + } fnConv; + fnConv.fp = ::GetProcAddress(h, name); + return fnConv.f; } else return NULL; } -- cgit v1.2.3