fix(skin-preview): smoother chessboard background contrast (#4534)
Some checks failed
CodeQL Code Scanning / CodeQL (push) Waiting to run
Flatpak / Build (${{ matrix.arch }}) (aarch64, ubuntu-22.04-arm) (push) Waiting to run
Flatpak / Build (${{ matrix.arch }}) (x86_64, ubuntu-22.04) (push) Waiting to run
Nix / Build (${{ matrix.system }}) (macos-14, aarch64-darwin) (push) Waiting to run
Nix / Build (${{ matrix.system }}) (macos-15-intel, x86_64-darwin) (push) Waiting to run
Nix / Build (${{ matrix.system }}) (ubuntu-22.04, x86_64-linux) (push) Waiting to run
Nix / Build (${{ matrix.system }}) (ubuntu-22.04-arm, aarch64-linux) (push) Waiting to run
Update Flake Lockfile / update-flake (push) Has been cancelled
Stale / Label issues and PRs (push) Has been cancelled

This commit is contained in:
Alexandru Ionut Tripon 2025-12-20 18:51:04 +02:00 committed by GitHub
commit d3f59a8a43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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);
}
}