Color.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Assertions.h>
  8. #include <AK/Format.h>
  9. #include <AK/Forward.h>
  10. #include <AK/Math.h>
  11. #include <AK/SIMD.h>
  12. #include <AK/StdLibExtras.h>
  13. #include <LibIPC/Forward.h>
  14. #include <math.h>
  15. namespace Gfx {
  16. enum class ColorRole;
  17. typedef u32 ARGB32;
  18. struct HSV {
  19. double hue { 0 };
  20. double saturation { 0 };
  21. double value { 0 };
  22. };
  23. struct YUV {
  24. float y { 0 };
  25. float u { 0 };
  26. float v { 0 };
  27. };
  28. struct Oklab {
  29. float L { 0 };
  30. float a { 0 };
  31. float b { 0 };
  32. };
  33. class Color {
  34. public:
  35. enum NamedColor {
  36. Transparent,
  37. Black,
  38. White,
  39. Red,
  40. Green,
  41. Cyan,
  42. Blue,
  43. Yellow,
  44. Magenta,
  45. DarkGray,
  46. MidGray,
  47. LightGray,
  48. WarmGray,
  49. DarkCyan,
  50. DarkGreen,
  51. DarkBlue,
  52. DarkRed,
  53. MidCyan,
  54. MidGreen,
  55. MidRed,
  56. MidBlue,
  57. MidMagenta,
  58. LightBlue,
  59. };
  60. constexpr Color() = default;
  61. constexpr Color(NamedColor);
  62. constexpr Color(u8 r, u8 g, u8 b)
  63. : m_value(0xff000000 | (r << 16) | (g << 8) | b)
  64. {
  65. }
  66. constexpr Color(u8 r, u8 g, u8 b, u8 a)
  67. : m_value((a << 24) | (r << 16) | (g << 8) | b)
  68. {
  69. }
  70. static constexpr Color from_rgb(unsigned rgb) { return Color(rgb | 0xff000000); }
  71. static constexpr Color from_argb(unsigned argb) { return Color(argb); }
  72. static constexpr Color from_yuv(YUV const& yuv) { return from_yuv(yuv.y, yuv.u, yuv.v); }
  73. static constexpr Color from_yuv(float y, float u, float v)
  74. {
  75. // https://www.itu.int/rec/R-REC-BT.1700-0-200502-I/en Table 4, Items 8 and 9 arithmetically inverted
  76. float r = y + v / 0.877f;
  77. float b = y + u / 0.493f;
  78. float g = (y - 0.299f * r - 0.114f * b) / 0.587f;
  79. r = clamp(r, 0.0f, 1.0f);
  80. g = clamp(g, 0.0f, 1.0f);
  81. b = clamp(b, 0.0f, 1.0f);
  82. return { static_cast<u8>(floorf(r * 255.0f)), static_cast<u8>(floorf(g * 255.0f)), static_cast<u8>(floorf(b * 255.0f)) };
  83. }
  84. // https://www.itu.int/rec/R-REC-BT.1700-0-200502-I/en Table 4
  85. constexpr YUV to_yuv() const
  86. {
  87. float r = red() / 255.0f;
  88. float g = green() / 255.0f;
  89. float b = blue() / 255.0f;
  90. // Item 8
  91. float y = 0.299f * r + 0.587f * g + 0.114f * b;
  92. // Item 9
  93. float u = 0.493f * (b - y);
  94. float v = 0.877f * (r - y);
  95. y = clamp(y, 0.0f, 1.0f);
  96. u = clamp(u, -1.0f, 1.0f);
  97. v = clamp(v, -1.0f, 1.0f);
  98. return { y, u, v };
  99. }
  100. static constexpr Color from_hsl(float h_degrees, float s, float l) { return from_hsla(h_degrees, s, l, 1.0); }
  101. static constexpr Color from_hsla(float h_degrees, float s, float l, float a)
  102. {
  103. // Algorithm from https://www.w3.org/TR/css-color-3/#hsl-color
  104. float h = clamp(h_degrees / 360.0f, 0.0f, 1.0f);
  105. s = clamp(s, 0.0f, 1.0f);
  106. l = clamp(l, 0.0f, 1.0f);
  107. a = clamp(a, 0.0f, 1.0f);
  108. // HOW TO RETURN hue.to.rgb(m1, m2, h):
  109. auto hue_to_rgb = [](float m1, float m2, float h) -> float {
  110. // IF h<0: PUT h+1 IN h
  111. if (h < 0.0f)
  112. h = h + 1.0f;
  113. // IF h>1: PUT h-1 IN h
  114. if (h > 1.0f)
  115. h = h - 1.0f;
  116. // IF h*6<1: RETURN m1+(m2-m1)*h*6
  117. if (h * 6.0f < 1.0f)
  118. return m1 + (m2 - m1) * h * 6.0f;
  119. // IF h*2<1: RETURN m2
  120. if (h * 2.0f < 1.0f)
  121. return m2;
  122. // IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
  123. if (h * 3.0f < 2.0f)
  124. return m1 + (m2 - m1) * (2.0f / 3.0f - h) * 6.0f;
  125. // RETURN m1
  126. return m1;
  127. };
  128. // SELECT:
  129. // l<=0.5: PUT l*(s+1) IN m2
  130. float m2;
  131. if (l <= 0.5f)
  132. m2 = l * (s + 1.0f);
  133. // ELSE: PUT l+s-l*s IN m2
  134. else
  135. m2 = l + s - l * s;
  136. // PUT l*2-m2 IN m1
  137. float m1 = l * 2.0f - m2;
  138. // PUT hue.to.rgb(m1, m2, h+1/3) IN r
  139. float r = hue_to_rgb(m1, m2, h + 1.0f / 3.0f);
  140. // PUT hue.to.rgb(m1, m2, h ) IN g
  141. float g = hue_to_rgb(m1, m2, h);
  142. // PUT hue.to.rgb(m1, m2, h-1/3) IN b
  143. float b = hue_to_rgb(m1, m2, h - 1.0f / 3.0f);
  144. // RETURN (r, g, b)
  145. u8 r_u8 = clamp(lroundf(r * 255.0f), 0, 255);
  146. u8 g_u8 = clamp(lroundf(g * 255.0f), 0, 255);
  147. u8 b_u8 = clamp(lroundf(b * 255.0f), 0, 255);
  148. u8 a_u8 = clamp(lroundf(a * 255.0f), 0, 255);
  149. return Color(r_u8, g_u8, b_u8, a_u8);
  150. }
  151. // https://bottosson.github.io/posts/oklab/
  152. static constexpr Color from_oklab(float L, float a, float b, float alpha = 1.0f)
  153. {
  154. auto linear_to_srgb = [](float c) {
  155. return c >= 0.0031308f ? 1.055f * pow(c, 0.4166666f) - 0.055f : 12.92f * c;
  156. };
  157. float l = L + 0.3963377774f * a + 0.2158037573f * b;
  158. float m = L - 0.1055613458f * a - 0.0638541728f * b;
  159. float s = L - 0.0894841775f * a - 1.2914855480f * b;
  160. l = l * l * l;
  161. m = m * m * m;
  162. s = s * s * s;
  163. float red = 4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s;
  164. float green = -1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s;
  165. float blue = -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s;
  166. red = linear_to_srgb(red) * 255.f;
  167. green = linear_to_srgb(green) * 255.f;
  168. blue = linear_to_srgb(blue) * 255.f;
  169. return Color(
  170. clamp(lroundf(red), 0, 255),
  171. clamp(lroundf(green), 0, 255),
  172. clamp(lroundf(blue), 0, 255),
  173. clamp(lroundf(alpha * 255.f), 0, 255));
  174. }
  175. // https://bottosson.github.io/posts/oklab/
  176. constexpr Oklab to_oklab()
  177. {
  178. auto srgb_to_linear = [](float c) {
  179. return c >= 0.04045f ? pow((c + 0.055f) / 1.055f, 2.4f) : c / 12.92f;
  180. };
  181. float r = srgb_to_linear(red() / 255.f);
  182. float g = srgb_to_linear(green() / 255.f);
  183. float b = srgb_to_linear(blue() / 255.f);
  184. float l = cbrtf(0.4122214708f * r + 0.5363325363f * g + 0.0514459929f * b);
  185. float m = cbrtf(0.2119034982f * r + 0.6806995451f * g + 0.1073969566f * b);
  186. float s = cbrtf(0.0883024619f * r + 0.2817188376f * g + 0.6299787005f * b);
  187. return {
  188. 0.2104542553f * l + 0.7936177850f * m - 0.0040720468f * s,
  189. 1.9779984951f * l - 2.4285922050f * m + 0.4505937099f * s,
  190. 0.0259040371f * l + 0.7827717662f * m - 0.8086757660f * s,
  191. };
  192. }
  193. constexpr u8 red() const { return (m_value >> 16) & 0xff; }
  194. constexpr u8 green() const { return (m_value >> 8) & 0xff; }
  195. constexpr u8 blue() const { return m_value & 0xff; }
  196. constexpr u8 alpha() const { return (m_value >> 24) & 0xff; }
  197. constexpr void set_alpha(u8 value)
  198. {
  199. m_value &= 0x00ffffff;
  200. m_value |= value << 24;
  201. }
  202. constexpr void set_red(u8 value)
  203. {
  204. m_value &= 0xff00ffff;
  205. m_value |= value << 16;
  206. }
  207. constexpr void set_green(u8 value)
  208. {
  209. m_value &= 0xffff00ff;
  210. m_value |= value << 8;
  211. }
  212. constexpr void set_blue(u8 value)
  213. {
  214. m_value &= 0xffffff00;
  215. m_value |= value;
  216. }
  217. constexpr Color with_alpha(u8 alpha) const
  218. {
  219. return Color((m_value & 0x00ffffff) | alpha << 24);
  220. }
  221. constexpr Color blend(Color source) const
  222. {
  223. if (alpha() == 0 || source.alpha() == 255)
  224. return source;
  225. if (source.alpha() == 0)
  226. return *this;
  227. int const d = 255 * (alpha() + source.alpha()) - alpha() * source.alpha();
  228. u8 r = (red() * alpha() * (255 - source.alpha()) + source.red() * 255 * source.alpha()) / d;
  229. u8 g = (green() * alpha() * (255 - source.alpha()) + source.green() * 255 * source.alpha()) / d;
  230. u8 b = (blue() * alpha() * (255 - source.alpha()) + source.blue() * 255 * source.alpha()) / d;
  231. u8 a = d / 255;
  232. return Color(r, g, b, a);
  233. }
  234. ALWAYS_INLINE Color mixed_with(Color other, float weight) const
  235. {
  236. if (alpha() == other.alpha() || with_alpha(0) == other.with_alpha(0))
  237. return interpolate(other, weight);
  238. // Fallback to slower, but more visually pleasing premultiplied alpha mix.
  239. // This is needed for linear-gradient()s in LibWeb.
  240. auto mixed_alpha = mix<float>(alpha(), other.alpha(), weight);
  241. auto premultiplied_mix_channel = [&](float channel, float other_channel, float weight) {
  242. return round_to<u8>(mix<float>(channel * alpha(), other_channel * other.alpha(), weight) / mixed_alpha);
  243. };
  244. return Gfx::Color {
  245. premultiplied_mix_channel(red(), other.red(), weight),
  246. premultiplied_mix_channel(green(), other.green(), weight),
  247. premultiplied_mix_channel(blue(), other.blue(), weight),
  248. round_to<u8>(mixed_alpha),
  249. };
  250. }
  251. ALWAYS_INLINE Color interpolate(Color other, float weight) const noexcept
  252. {
  253. return Gfx::Color {
  254. round_to<u8>(mix<float>(red(), other.red(), weight)),
  255. round_to<u8>(mix<float>(green(), other.green(), weight)),
  256. round_to<u8>(mix<float>(blue(), other.blue(), weight)),
  257. round_to<u8>(mix<float>(alpha(), other.alpha(), weight)),
  258. };
  259. }
  260. constexpr Color multiply(Color other) const
  261. {
  262. return Color(
  263. red() * other.red() / 255,
  264. green() * other.green() / 255,
  265. blue() * other.blue() / 255,
  266. alpha() * other.alpha() / 255);
  267. }
  268. constexpr float distance_squared_to(Color other) const
  269. {
  270. int delta_red = other.red() - red();
  271. int delta_green = other.green() - green();
  272. int delta_blue = other.blue() - blue();
  273. int delta_alpha = other.alpha() - alpha();
  274. auto rgb_distance = (delta_red * delta_red + delta_green * delta_green + delta_blue * delta_blue) / (3.0f * 255 * 255);
  275. return delta_alpha * delta_alpha / (2.0f * 255 * 255) + rgb_distance * alpha() * other.alpha() / (255 * 255);
  276. }
  277. constexpr u8 luminosity() const
  278. {
  279. return (red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f);
  280. }
  281. constexpr float contrast_ratio(Color other)
  282. {
  283. auto l1 = luminosity();
  284. auto l2 = other.luminosity();
  285. auto darkest = min(l1, l2) / 255.;
  286. auto brightest = max(l1, l2) / 255.;
  287. return (brightest + 0.05) / (darkest + 0.05);
  288. }
  289. constexpr Color to_grayscale() const
  290. {
  291. auto gray = luminosity();
  292. return Color(gray, gray, gray, alpha());
  293. }
  294. constexpr Color sepia(float amount = 1.0f) const
  295. {
  296. auto blend_factor = 1.0f - amount;
  297. auto r1 = 0.393f + 0.607f * blend_factor;
  298. auto r2 = 0.769f - 0.769f * blend_factor;
  299. auto r3 = 0.189f - 0.189f * blend_factor;
  300. auto g1 = 0.349f - 0.349f * blend_factor;
  301. auto g2 = 0.686f + 0.314f * blend_factor;
  302. auto g3 = 0.168f - 0.168f * blend_factor;
  303. auto b1 = 0.272f - 0.272f * blend_factor;
  304. auto b2 = 0.534f - 0.534f * blend_factor;
  305. auto b3 = 0.131f + 0.869f * blend_factor;
  306. auto r = red();
  307. auto g = green();
  308. auto b = blue();
  309. return Color(
  310. clamp(lroundf(r * r1 + g * r2 + b * r3), 0, 255),
  311. clamp(lroundf(r * g1 + g * g2 + b * g3), 0, 255),
  312. clamp(lroundf(r * b1 + g * b2 + b * b3), 0, 255),
  313. alpha());
  314. }
  315. constexpr Color with_opacity(float opacity) const
  316. {
  317. return with_alpha(alpha() * opacity);
  318. }
  319. constexpr Color darkened(float amount = 0.5f) const
  320. {
  321. return Color(red() * amount, green() * amount, blue() * amount, alpha());
  322. }
  323. constexpr Color lightened(float amount = 1.2f) const
  324. {
  325. return Color(min(255, (int)((float)red() * amount)), min(255, (int)((float)green() * amount)), min(255, (int)((float)blue() * amount)), alpha());
  326. }
  327. Vector<Color> shades(u32 steps, float max = 1.f) const;
  328. Vector<Color> tints(u32 steps, float max = 1.f) const;
  329. constexpr Color saturated_to(float saturation) const
  330. {
  331. auto hsv = to_hsv();
  332. auto alpha = this->alpha();
  333. auto color = Color::from_hsv(hsv.hue, static_cast<double>(saturation), hsv.value);
  334. color.set_alpha(alpha);
  335. return color;
  336. }
  337. constexpr Color inverted() const
  338. {
  339. return Color(~red(), ~green(), ~blue(), alpha());
  340. }
  341. constexpr Color xored(Color other) const
  342. {
  343. return Color(((other.m_value ^ m_value) & 0x00ffffff) | (m_value & 0xff000000));
  344. }
  345. constexpr ARGB32 value() const { return m_value; }
  346. constexpr bool operator==(Color other) const
  347. {
  348. return m_value == other.m_value;
  349. }
  350. String to_string() const;
  351. String to_string_without_alpha() const;
  352. ByteString to_byte_string() const;
  353. ByteString to_byte_string_without_alpha() const;
  354. static Optional<Color> from_string(StringView);
  355. static Optional<Color> from_named_css_color_string(StringView);
  356. constexpr HSV to_hsv() const
  357. {
  358. HSV hsv;
  359. double r = static_cast<double>(red()) / 255.0;
  360. double g = static_cast<double>(green()) / 255.0;
  361. double b = static_cast<double>(blue()) / 255.0;
  362. double max = AK::max(AK::max(r, g), b);
  363. double min = AK::min(AK::min(r, g), b);
  364. double chroma = max - min;
  365. if (!chroma)
  366. hsv.hue = 0.0;
  367. else if (max == r)
  368. hsv.hue = (60.0 * ((g - b) / chroma)) + 360.0;
  369. else if (max == g)
  370. hsv.hue = (60.0 * ((b - r) / chroma)) + 120.0;
  371. else
  372. hsv.hue = (60.0 * ((r - g) / chroma)) + 240.0;
  373. if (hsv.hue >= 360.0)
  374. hsv.hue -= 360.0;
  375. if (!max)
  376. hsv.saturation = 0;
  377. else
  378. hsv.saturation = chroma / max;
  379. hsv.value = max;
  380. VERIFY(hsv.hue >= 0.0 && hsv.hue < 360.0);
  381. VERIFY(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
  382. VERIFY(hsv.value >= 0.0 && hsv.value <= 1.0);
  383. return hsv;
  384. }
  385. static constexpr Color from_hsv(double hue, double saturation, double value)
  386. {
  387. return from_hsv({ hue, saturation, value });
  388. }
  389. static constexpr Color from_hsv(HSV const& hsv)
  390. {
  391. VERIFY(hsv.hue >= 0.0 && hsv.hue < 360.0);
  392. VERIFY(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
  393. VERIFY(hsv.value >= 0.0 && hsv.value <= 1.0);
  394. double hue = hsv.hue;
  395. double saturation = hsv.saturation;
  396. double value = hsv.value;
  397. int high = static_cast<int>(hue / 60.0) % 6;
  398. double f = (hue / 60.0) - high;
  399. double c1 = value * (1.0 - saturation);
  400. double c2 = value * (1.0 - saturation * f);
  401. double c3 = value * (1.0 - saturation * (1.0 - f));
  402. double r = 0;
  403. double g = 0;
  404. double b = 0;
  405. switch (high) {
  406. case 0:
  407. r = value;
  408. g = c3;
  409. b = c1;
  410. break;
  411. case 1:
  412. r = c2;
  413. g = value;
  414. b = c1;
  415. break;
  416. case 2:
  417. r = c1;
  418. g = value;
  419. b = c3;
  420. break;
  421. case 3:
  422. r = c1;
  423. g = c2;
  424. b = value;
  425. break;
  426. case 4:
  427. r = c3;
  428. g = c1;
  429. b = value;
  430. break;
  431. case 5:
  432. r = value;
  433. g = c1;
  434. b = c2;
  435. break;
  436. }
  437. u8 out_r = (u8)(r * 255);
  438. u8 out_g = (u8)(g * 255);
  439. u8 out_b = (u8)(b * 255);
  440. return Color(out_r, out_g, out_b);
  441. }
  442. constexpr Color suggested_foreground_color() const
  443. {
  444. return luminosity() < 128 ? Color::White : Color::Black;
  445. }
  446. private:
  447. constexpr explicit Color(ARGB32 argb)
  448. : m_value(argb)
  449. {
  450. }
  451. ARGB32 m_value { 0 };
  452. };
  453. constexpr Color::Color(NamedColor named)
  454. {
  455. if (named == Transparent) {
  456. m_value = 0;
  457. return;
  458. }
  459. struct {
  460. u8 r;
  461. u8 g;
  462. u8 b;
  463. } rgb;
  464. switch (named) {
  465. case Black:
  466. rgb = { 0, 0, 0 };
  467. break;
  468. case White:
  469. rgb = { 255, 255, 255 };
  470. break;
  471. case Red:
  472. rgb = { 255, 0, 0 };
  473. break;
  474. case Green:
  475. rgb = { 0, 255, 0 };
  476. break;
  477. case Cyan:
  478. rgb = { 0, 255, 255 };
  479. break;
  480. case DarkCyan:
  481. rgb = { 0, 127, 127 };
  482. break;
  483. case MidCyan:
  484. rgb = { 0, 192, 192 };
  485. break;
  486. case Blue:
  487. rgb = { 0, 0, 255 };
  488. break;
  489. case Yellow:
  490. rgb = { 255, 255, 0 };
  491. break;
  492. case Magenta:
  493. rgb = { 255, 0, 255 };
  494. break;
  495. case DarkGray:
  496. rgb = { 64, 64, 64 };
  497. break;
  498. case MidGray:
  499. rgb = { 127, 127, 127 };
  500. break;
  501. case LightGray:
  502. rgb = { 192, 192, 192 };
  503. break;
  504. case MidGreen:
  505. rgb = { 0, 192, 0 };
  506. break;
  507. case MidBlue:
  508. rgb = { 0, 0, 192 };
  509. break;
  510. case MidRed:
  511. rgb = { 192, 0, 0 };
  512. break;
  513. case MidMagenta:
  514. rgb = { 192, 0, 192 };
  515. break;
  516. case DarkGreen:
  517. rgb = { 0, 128, 0 };
  518. break;
  519. case DarkBlue:
  520. rgb = { 0, 0, 128 };
  521. break;
  522. case DarkRed:
  523. rgb = { 128, 0, 0 };
  524. break;
  525. case WarmGray:
  526. rgb = { 212, 208, 200 };
  527. break;
  528. case LightBlue:
  529. rgb = { 173, 216, 230 };
  530. break;
  531. default:
  532. VERIFY_NOT_REACHED();
  533. break;
  534. }
  535. m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b;
  536. }
  537. }
  538. using Gfx::Color;
  539. namespace AK {
  540. template<>
  541. struct Formatter<Gfx::Color> : public Formatter<StringView> {
  542. ErrorOr<void> format(FormatBuilder&, Gfx::Color);
  543. };
  544. template<>
  545. struct Formatter<Gfx::YUV> : public Formatter<FormatString> {
  546. ErrorOr<void> format(FormatBuilder&, Gfx::YUV);
  547. };
  548. template<>
  549. struct Formatter<Gfx::HSV> : public Formatter<FormatString> {
  550. ErrorOr<void> format(FormatBuilder&, Gfx::HSV);
  551. };
  552. template<>
  553. struct Formatter<Gfx::Oklab> : public Formatter<FormatString> {
  554. ErrorOr<void> format(FormatBuilder&, Gfx::Oklab);
  555. };
  556. }
  557. namespace IPC {
  558. template<>
  559. ErrorOr<void> encode(Encoder&, Gfx::Color const&);
  560. template<>
  561. ErrorOr<Gfx::Color> decode(Decoder&);
  562. }