70 return IM_COL32((rgb >> 16U) & 0xFFU, (rgb >> 8U) & 0xFFU, rgb & 0xFFU, 255);
92 const auto scale = [factor](ImU32 value,
int shift)
95 static_cast<float>((value >> shift) & 0xFFU) * factor + 0.5f;
96 float bounded = scaled;
99 else if (scaled > 255.0f)
101 return static_cast<ImU32
>(bounded) << shift;
103 return scale(color, IM_COL32_R_SHIFT) | scale(color, IM_COL32_G_SHIFT) |
104 scale(color, IM_COL32_B_SHIFT) | (color & IM_COL32_A_MASK);
108inline ImU32
mixColor(ImU32 first, ImU32 second,
float t)
110 const auto blend = [t](ImU32 a, ImU32 b,
int shift)
112 const auto from =
static_cast<float>((a >> shift) & 0xFFU);
113 const auto to =
static_cast<float>((b >> shift) & 0xFFU);
114 return static_cast<ImU32
>(std::lerp(from, to, t) + 0.5f) << shift;
116 return blend(first, second, IM_COL32_R_SHIFT) |
117 blend(first, second, IM_COL32_G_SHIFT) |
118 blend(first, second, IM_COL32_B_SHIFT) |
119 blend(first, second, IM_COL32_A_SHIFT);
126constexpr ImU32
mixColor256(ImU32 first, ImU32 second, std::uint32_t t256)
128 const std::uint32_t keep = 256U - t256;
129 const std::uint32_t evenChannels =
130 (((first & 0x00FF00FFU) * keep + (second & 0x00FF00FFU) * t256) >> 8U) &
132 const std::uint32_t oddChannels = ((((first >> 8U) & 0x00FF00FFU) * keep +
133 ((second >> 8U) & 0x00FF00FFU) * t256) >>
136 return evenChannels | (oddChannels << 8U);
141 const auto channel = [&](
int shift)
143 const std::uint32_t value = (((color >> shift) & 0xFFU) * factor256) >> 8U;
144 return (value > 255U ? 255U : value) << shift;
146 return channel(IM_COL32_R_SHIFT) | channel(IM_COL32_G_SHIFT) |
147 channel(IM_COL32_B_SHIFT) | (color & IM_COL32_A_MASK);
151constexpr ImU32
withAlpha(ImU32 color, std::uint8_t alpha)
153 return (color & ~IM_COL32_A_MASK) |
154 (
static_cast<ImU32
>(alpha) << IM_COL32_A_SHIFT);
160 value ^= value >> 16;
161 value *= 0x7feb352dU;
162 value ^= value >> 15;
163 value *= 0x846ca68bU;
164 value ^= value >> 16;
float kitColorDistance(ImU32 first, ImU32 second)
Definition match_kit_colors.cpp:115
constexpr ImU32 withAlpha(ImU32 color, std::uint8_t alpha)
Definition match_kit_colors.h:151
constexpr float KIT_CLASH_DISTANCE
Definition match_kit_colors.h:77
MatchKits chooseMatchKits(TeamID homeTeam, TeamID awayTeam)
Definition match_kit_colors.cpp:161
constexpr ImU32 shadeColor256(ImU32 color, std::uint32_t factor256)
Definition match_kit_colors.h:139
const ClubIdentity * findClubIdentity(TeamID team)
Definition match_kit_colors.cpp:108
constexpr std::uint32_t cosmeticHash(std::uint32_t value)
Definition match_kit_colors.h:158
ImU32 mixColor(ImU32 first, ImU32 second, float t)
Definition match_kit_colors.h:108
constexpr ImU32 kitColorFromRgb(std::uint32_t rgb)
Definition match_kit_colors.h:68
ImU32 goalkeeperGloveColor(const KitColors &kit)
Definition match_kit_colors.cpp:142
constexpr ImU32 mixColor256(ImU32 first, ImU32 second, std::uint32_t t256)
Definition match_kit_colors.h:126
ImU32 shadeColor(ImU32 color, float factor)
Definition match_kit_colors.h:90
ImU32 kitNumberColor(const KitColors &kit)
Definition match_kit_colors.cpp:131
Definition match_kit_colors.h:40
ImU32 primary
Definition match_kit_colors.h:41
ImU32 secondary
Definition match_kit_colors.h:42
Descriptive club data read from the team files of the data pack.
Definition datagenerator.h:29
Definition match_kit_colors.h:22
ImU32 shorts
Definition match_kit_colors.h:25
ImU32 trim
Definition match_kit_colors.h:24
ImU32 socks
Definition match_kit_colors.h:26
ImU32 shirt
Definition match_kit_colors.h:23
Definition match_kit_colors.h:31
KitColors away
Definition match_kit_colors.h:33
KitColors homeGoalkeeper
Definition match_kit_colors.h:34
KitColors home
Definition match_kit_colors.h:32
KitColors awayGoalkeeper
Definition match_kit_colors.h:35
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18