diff --git a/Telegram/SourceFiles/ui/chat/chat_theme.cpp b/Telegram/SourceFiles/ui/chat/chat_theme.cpp
index a01be5a7d..87f3a3cb1 100644
--- a/Telegram/SourceFiles/ui/chat/chat_theme.cpp
+++ b/Telegram/SourceFiles/ui/chat/chat_theme.cpp
@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/ui_utility.h"
 #include "ui/chat/message_bubble.h"
 #include "ui/chat/chat_style.h"
+#include "ui/color_contrast.h"
 #include "ui/style/style_core_palette.h"
 #include "ui/style/style_palette_colorizer.h"
 
@@ -158,25 +159,6 @@ constexpr auto kMinAcceptableContrast = 1.14;// 4.5;
 	return Images::GenerateLinearGradient(QSize(kSize, kSize), data.colors);
 }
 
-// https://stackoverflow.com/a/9733420
-[[nodiscard]] float64 CountContrast(const QColor &a, const QColor &b) {
-	const auto luminance = [](const QColor &c) {
-		const auto map = [](double value) {
-			return (value <= 0.03928)
-				? (value / 12.92)
-				: std::pow((value + 0.055) / 1.055, 2.4);
-		};
-		return map(c.redF()) * 0.2126
-			+ map(c.greenF()) * 0.7152
-			+ map(c.blueF()) * 0.0722;
-	};
-	const auto luminance1 = luminance(a);
-	const auto luminance2 = luminance(b);
-	const auto brightest = std::max(luminance1, luminance2);
-	const auto darkest = std::min(luminance1, luminance2);
-	return (brightest + 0.05) / (darkest + 0.05);
-}
-
 } // namespace
 
 bool operator==(const ChatThemeBackground &a, const ChatThemeBackground &b) {
@@ -350,7 +332,7 @@ void ChatTheme::adjustPalette(const ChatThemeDescriptor &descriptor) {
 	const auto minimal = [&](const QColor &with) {
 		auto result = kMaxContrastValue;
 		for (const auto &color : colors) {
-			result = std::min(result, CountContrast(color->c, with));
+			result = std::min(result, Ui::CountContrast(color->c, with));
 		}
 		return result;
 	};
@@ -363,7 +345,7 @@ void ChatTheme::adjustPalette(const ChatThemeDescriptor &descriptor) {
 	};
 	//const auto singleWithBg = [&](const QColor &c) {
 	//	return withBg([&](const QColor &with) {
-	//		return CountContrast(c, with);
+	//		return Ui::CountContrast(c, with);
 	//	});
 	//};
 	if (withBg(minimal) < kMinAcceptableContrast) {
diff --git a/Telegram/SourceFiles/ui/color_contrast.cpp b/Telegram/SourceFiles/ui/color_contrast.cpp
new file mode 100644
index 000000000..ea3f9d0be
--- /dev/null
+++ b/Telegram/SourceFiles/ui/color_contrast.cpp
@@ -0,0 +1,31 @@
+/*
+This file is part of Telegram Desktop,
+the official desktop application for the Telegram messaging service.
+
+For license and copyright information please follow this link:
+https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
+*/
+#include "ui/color_contrast.h"
+
+namespace Ui {
+
+// https://stackoverflow.com/a/9733420
+float64 CountContrast(const QColor &a, const QColor &b) {
+	const auto luminance = [](const QColor &c) {
+		const auto map = [](double value) {
+			return (value <= 0.03928)
+				? (value / 12.92)
+				: std::pow((value + 0.055) / 1.055, 2.4);
+		};
+		return map(c.redF()) * 0.2126
+			+ map(c.greenF()) * 0.7152
+			+ map(c.blueF()) * 0.0722;
+	};
+	const auto luminance1 = luminance(a);
+	const auto luminance2 = luminance(b);
+	const auto brightest = std::max(luminance1, luminance2);
+	const auto darkest = std::min(luminance1, luminance2);
+	return (brightest + 0.05) / (darkest + 0.05);
+}
+
+} // namespace Ui
diff --git a/Telegram/SourceFiles/ui/color_contrast.h b/Telegram/SourceFiles/ui/color_contrast.h
new file mode 100644
index 000000000..485d50c19
--- /dev/null
+++ b/Telegram/SourceFiles/ui/color_contrast.h
@@ -0,0 +1,16 @@
+/*
+This file is part of Telegram Desktop,
+the official desktop application for the Telegram messaging service.
+
+For license and copyright information please follow this link:
+https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
+*/
+#pragma once
+
+class QColor;
+
+namespace Ui {
+
+[[nodiscard]] float64 CountContrast(const QColor &a, const QColor &b);
+
+} // namespace Ui
diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake
index d51cc3c45..48c00977d 100644
--- a/Telegram/cmake/td_ui.cmake
+++ b/Telegram/cmake/td_ui.cmake
@@ -264,6 +264,8 @@ PRIVATE
 
     ui/cached_round_corners.cpp
     ui/cached_round_corners.h
+    ui/color_contrast.cpp
+    ui/color_contrast.h
     ui/grouped_layout.cpp
     ui/grouped_layout.h
     ui/widgets/fields/special_fields.cpp