fix(skin-preview): smoother chessboard background contrast (#4534)
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include <QVector2D>
|
#include <QVector2D>
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "minecraft/skins/SkinModel.h"
|
#include "minecraft/skins/SkinModel.h"
|
||||||
#include "rainbow.h"
|
#include "rainbow.h"
|
||||||
@@ -270,11 +271,12 @@ void SkinOpenGLWindow::updateCape(const QImage& cape)
|
|||||||
|
|
||||||
QColor calculateContrastingColor(const QColor& color)
|
QColor calculateContrastingColor(const QColor& color)
|
||||||
{
|
{
|
||||||
constexpr float contrast = 0.2;
|
|
||||||
auto luma = Rainbow::luma(color);
|
auto luma = Rainbow::luma(color);
|
||||||
if (luma < 0.5) {
|
if (luma < 0.5) {
|
||||||
|
constexpr float contrast = 0.05;
|
||||||
return Rainbow::lighten(color, contrast);
|
return Rainbow::lighten(color, contrast);
|
||||||
} else {
|
} else {
|
||||||
|
constexpr float contrast = 0.2;
|
||||||
return Rainbow::darken(color, contrast);
|
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 generateChessboardImage(int width, int height, int tileSize, QColor baseColor)
|
||||||
{
|
{
|
||||||
QImage image(width, height, QImage::Format_RGB888);
|
QImage image(width, height, QImage::Format_RGB888);
|
||||||
auto white = baseColor;
|
bool isDarkBase = Rainbow::luma(baseColor) < 0.5;
|
||||||
auto black = calculateContrastingColor(baseColor);
|
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 y = 0; y < height; ++y) {
|
||||||
for (int x = 0; x < width; ++x) {
|
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);
|
image.setPixelColor(x, y, isWhite ? white : black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user