fix(skin-preview): smoother chessboard background contrast

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers
2025-12-19 16:53:31 -07:00
parent 877b824c3b
commit 42b72d676c

View File

@@ -23,6 +23,7 @@
#include <QVector2D>
#include <QVector3D>
#include <QtMath>
#include <functional>
#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);
}
}