MCPcopy Create free account
hub / github.com/TranslucentTB/TranslucentTB / GetCheckerPixelColor

Function GetCheckerPixelColor

Xaml/Controls/colorpickerrendering.hpp:7–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "util/color.hpp"
6
7constexpr Util::Color GetCheckerPixelColor(int32_t x, int32_t y, Util::Color checkerColor, double renderScale, bool invert = false) noexcept
8{
9 constexpr int32_t CHECKER_SIZE_PRE_SCALE = 4;
10 const int32_t checkerSize = static_cast<int32_t>(CHECKER_SIZE_PRE_SCALE * renderScale);
11
12 // We want the checkered pattern to alternate both vertically and horizontally.
13 // In order to achieve that, we'll toggle visibility of the current pixel on or off
14 // depending on both its x- and its y-position. If x == CheckerSize, we'll turn visibility off,
15 // but then if y == CheckerSize, we'll turn it back on.
16 // The below is a shorthand for the above intent.
17 bool pixelShouldBeBlank = (x / checkerSize + y / checkerSize) % 2 == 0 ? 255 : 0;
18
19 if (invert)
20 {
21 pixelShouldBeBlank = !pixelShouldBeBlank;
22 }
23
24 if (pixelShouldBeBlank)
25 {
26 return { };
27 }
28 else
29 {
30 return checkerColor.Premultiply();
31 }
32}
33
34constexpr Util::Color CompositeColors(Util::Color bottom, Util::Color top) noexcept
35{

Callers 2

FillChannelBitmapFunction · 0.85
FillCheckeredBitmapFunction · 0.85

Calls 1

PremultiplyMethod · 0.80

Tested by

no test coverage detected