From 0ae88cfd66f8762f18a7d9e5fdfc72573b2e4256 Mon Sep 17 00:00:00 2001 From: weolar <405360001@qq.com> Date: Wed, 14 Oct 2020 09:49:12 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8D=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E4=B8=8D=E4=BA=86canvas.fillStyle("#ffff0000");=20=E8=BF=99?= =?UTF-8?q?=E7=A7=8D=E5=9B=9B=E4=B8=AA=E5=AD=97=E8=8A=82=E7=9A=84=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=A0=BC=E5=BC=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebKit/Source/platform/graphics/Color.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/third_party/WebKit/Source/platform/graphics/Color.cpp b/third_party/WebKit/Source/platform/graphics/Color.cpp index 195e7f60fa..824f3af58a 100644 --- a/third_party/WebKit/Source/platform/graphics/Color.cpp +++ b/third_party/WebKit/Source/platform/graphics/Color.cpp @@ -119,7 +119,7 @@ RGBA32 makeRGBAFromCMYKA(float c, float m, float y, float k, float a) template static inline bool parseHexColorInternal(const CharacterType* name, unsigned length, RGBA32& rgb) { - if (length != 3 && length != 6) + if (length != 3 && length != 4 && length != 6 && length != 8) return false; unsigned value = 0; for (unsigned i = 0; i < length; ++i) { @@ -132,11 +132,23 @@ static inline bool parseHexColorInternal(const CharacterType* name, unsigned len rgb = 0xFF000000 | value; return true; } + if (length == 8) { + // We parsed the values into RGBA order, but the RGBA32 type + // expects them to be in ARGB order, so we right rotate eight bits. + rgb = value << 24 | value >> 8; + return true; + } + if (length == 4) { + // #abcd converts to ddaabbcc in RGBA32. + rgb = (value & 0xF) << 28 | (value & 0xF) << 24 | (value & 0xF000) << 8 | + (value & 0xF000) << 4 | (value & 0xF00) << 4 | (value & 0xF00) | + (value & 0xF0) | (value & 0xF0) >> 4; + return true; + } // #abc converts to #aabbcc - rgb = 0xFF000000 - | (value & 0xF00) << 12 | (value & 0xF00) << 8 - | (value & 0xF0) << 8 | (value & 0xF0) << 4 - | (value & 0xF) << 4 | (value & 0xF); + rgb = 0xFF000000 | (value & 0xF00) << 12 | (value & 0xF00) << 8 | + (value & 0xF0) << 8 | (value & 0xF0) << 4 | (value & 0xF) << 4 | + (value & 0xF); return true; }