From 42b72d676c8603c105f6122ca5e09501d48fecb3 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Fri, 19 Dec 2025 16:53:31 -0700 Subject: [PATCH] fix(skin-preview): smoother chessboard background contrast Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/ui/dialogs/skins/draw/SkinOpenGLWindow.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/launcher/ui/dialogs/skins/draw/SkinOpenGLWindow.cpp b/launcher/ui/dialogs/skins/draw/SkinOpenGLWindow.cpp index 169d33819..e4d1eae8d 100644 --- a/launcher/ui/dialogs/skins/draw/SkinOpenGLWindow.cpp +++ b/launcher/ui/dialogs/skins/draw/SkinOpenGLWindow.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "minecraft/skins/SkinModel.h" #include "rainbow.h" @@ -270,11 +271,12 @@ void SkinOpenGLWindow::updateCape(const QImage& cape) QColor calculateContrastingColor(const QColor& color) { - constexpr float contrast = 0.2; auto luma = Rainbow::luma(color); if (luma < 0.5) { + constexpr float contrast = 0.05; return Rainbow::lighten(color, contrast); } else { + constexpr float contrast = 0.2; return Rainbow::darken(color, contrast); } } @@ -282,11 +284,14 @@ QColor calculateContrastingColor(const QColor& color) QImage generateChessboardImage(int width, int height, int tileSize, QColor baseColor) { QImage image(width, height, QImage::Format_RGB888); - auto white = baseColor; - auto black = calculateContrastingColor(baseColor); + bool isDarkBase = Rainbow::luma(baseColor) < 0.5; + float contrast = isDarkBase ? 0.05 : 0.45; + auto contrastFunc = std::bind(isDarkBase ? Rainbow::lighten : Rainbow::darken, std::placeholders::_1, contrast, 1.0); + auto white = contrastFunc(baseColor); + auto black = contrastFunc(calculateContrastingColor(baseColor)); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { - bool isWhite = ((x / tileSize) % 2) == ((y / tileSize) % 2); + bool isWhite = ((x / tileSize) + (y / tileSize)) % 2 == 0; image.setPixelColor(x, y, isWhite ? white : black); } }