From 2e6405c333d8daae4e3edaa6b48f5ac5a8d7675b Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 20 Mar 2018 15:25:57 +0000 Subject: Change ArgbToColorRef() to ArgbToAlphaAndColorRef(). Since that is what it really returns. Add a replacement ArgbToColorRef() that only returns a FX_COLORREF, and remove a duplicate implementation. Then update callers and only use ArgbToAlphaAndColorRef() where appropriate. Also update comments to explain what FX_COLORREF is. Change-Id: I5ed3d71683898dc2b3a66395dea0ec2562c14a68 Reviewed-on: https://pdfium-review.googlesource.com/28575 Reviewed-by: dsinclair Commit-Queue: dsinclair --- core/fxge/dib/fx_dib_main.cpp | 9 ++++++--- core/fxge/fx_dib.h | 19 +++++++++++++------ core/fxge/win32/fx_win32_device.cpp | 27 +++++++++++---------------- core/fxge/win32/fx_win32_print.cpp | 6 ++---- 4 files changed, 32 insertions(+), 29 deletions(-) (limited to 'core/fxge') diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index 161d2bd32e..5d7b585979 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -79,9 +79,12 @@ std::tuple ArgbDecode(FX_ARGB argb) { FXARGB_B(argb)); } -std::pair ArgbToColorRef(FX_ARGB argb) { - return {FXARGB_A(argb), - FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb))}; +std::pair ArgbToAlphaAndColorRef(FX_ARGB argb) { + return {FXARGB_A(argb), ArgbToColorRef(argb)}; +} + +FX_COLORREF ArgbToColorRef(FX_ARGB argb) { + return FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); } uint32_t ArgbEncode(int a, FX_COLORREF bgr) { diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h index 8134c5066d..5dcfac4962 100644 --- a/core/fxge/fx_dib.h +++ b/core/fxge/fx_dib.h @@ -37,9 +37,13 @@ struct PixelWeight { int m_Weights[1]; }; -typedef uint32_t FX_ARGB; -typedef uint32_t FX_COLORREF; -typedef uint32_t FX_CMYK; +using FX_ARGB = uint32_t; + +// FX_COLORREF, like win32 COLORREF, is BGR. +using FX_COLORREF = uint32_t; + +using FX_CMYK = uint32_t; + class CFX_ClipRgn; class CFX_DIBSource; class CStretchEngine; @@ -86,11 +90,14 @@ inline FX_CMYK CmykEncode(int c, int m, int y, int k) { return (c << 24) | (m << 16) | (y << 8) | k; } -// Returns tuple a, r, g, b +// Returns (a, r, g, b) std::tuple ArgbDecode(FX_ARGB argb); -// Returns pair a, rgb -std::pair ArgbToColorRef(FX_ARGB argb); +// Returns (a, FX_COLORREF) +std::pair ArgbToAlphaAndColorRef(FX_ARGB argb); + +// Returns FX_COLORREF. +FX_COLORREF ArgbToColorRef(FX_ARGB argb); inline FX_ARGB ArgbEncode(int a, int r, int g, int b) { return (a << 24) | (r << 16) | (g << 8) | b; diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 673593cdda..b857dde91b 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -132,11 +132,9 @@ HPEN CreateExtPen(const CFX_GraphStateData* pGraphState, break; } - int a; - FX_COLORREF bgr; - std::tie(a, bgr) = ArgbToColorRef(argb); + FX_COLORREF colorref = ArgbToColorRef(argb); LOGBRUSH lb; - lb.lbColor = bgr; + lb.lbColor = colorref; lb.lbStyle = BS_SOLID; lb.lbHatch = 0; std::vector dashes; @@ -155,10 +153,7 @@ HPEN CreateExtPen(const CFX_GraphStateData* pGraphState, } HBRUSH CreateBrush(uint32_t argb) { - int a; - FX_COLORREF bgr; - std::tie(a, bgr) = ArgbToColorRef(argb); - return CreateSolidBrush(bgr); + return CreateSolidBrush(ArgbToColorRef(argb)); } void SetPathToDC(HDC hDC, @@ -1073,15 +1068,15 @@ bool CGdiDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, return false; int alpha; - FX_COLORREF bgr; - std::tie(alpha, bgr) = ArgbToColorRef(fill_color); + FX_COLORREF colorref; + std::tie(alpha, colorref) = ArgbToAlphaAndColorRef(fill_color); if (alpha == 0) return true; if (alpha < 255) return false; - HBRUSH hBrush = CreateSolidBrush(bgr); + HBRUSH hBrush = CreateSolidBrush(colorref); ::FillRect(m_hDC, (RECT*)pRect, hBrush); DeleteObject(hBrush); return true; @@ -1126,13 +1121,13 @@ bool CGdiDeviceDriver::DrawCosmeticLine(const CFX_PointF& ptMoveTo, if (blend_type != FXDIB_BLEND_NORMAL) return false; - int a; - FX_COLORREF bgr; - std::tie(a, bgr) = ArgbToColorRef(color); - if (a == 0) + int alpha; + FX_COLORREF colorref; + std::tie(alpha, colorref) = ArgbToAlphaAndColorRef(color); + if (alpha == 0) return true; - HPEN hPen = CreatePen(PS_SOLID, 1, bgr); + HPEN hPen = CreatePen(PS_SOLID, 1, colorref); hPen = (HPEN)SelectObject(m_hDC, hPen); MoveToEx(m_hDC, FXSYS_round(ptMoveTo.x), FXSYS_round(ptMoveTo.y), nullptr); LineTo(m_hDC, FXSYS_round(ptLineTo.x), FXSYS_round(ptLineTo.y)); diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index f2ae8a726e..66fbdd9b02 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -280,10 +280,8 @@ bool CGdiPrinterDriver::DrawDeviceText(int nChars, ModifyWorldTransform(m_hDC, &xform, MWT_LEFTMULTIPLY); // Color - int iUnusedAlpha; - FX_COLORREF bgr; - std::tie(iUnusedAlpha, bgr) = ArgbToColorRef(color); - SetTextColor(m_hDC, bgr); + FX_COLORREF colorref = ArgbToColorRef(color); + SetTextColor(m_hDC, colorref); SetBkMode(m_hDC, TRANSPARENT); // Text -- cgit v1.2.3