3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Update closest color conversion (#1057)

ViaVersion altered their color conversion to fix an issue and this just copies those changes
Dieser Commit ist enthalten in:
rtm516 2020-07-30 21:09:53 +01:00 committet von GitHub
Ursprung 427cb69a14
Commit 50346a95cd
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -400,13 +400,16 @@ public class MessageUtils {
int testB = testColor.getValue() & 0xFF; int testB = testColor.getValue() & 0xFF;
// Check by the greatest diff of the 3 values // Check by the greatest diff of the 3 values
int rDiff = Math.abs(testR - r); int rAverage = (testR + r) / 2;
int gDiff = Math.abs(testG - g); int rDiff = testR - r;
int bDiff = Math.abs(testB - b); int gDiff = testG - g;
int maxDiff = Math.max(Math.max(rDiff, gDiff), bDiff); int bDiff = testB - b;
if (closest == null || maxDiff < smallestDiff) { int diff = ((2 + (rAverage >> 8)) * rDiff * rDiff)
+ (4 * gDiff * gDiff)
+ ((2 + ((255 - rAverage) >> 8)) * bDiff * bDiff);
if (closest == null || diff < smallestDiff) {
closest = testColor.getKey(); closest = testColor.getKey();
smallestDiff = maxDiff; smallestDiff = diff;
} }
} }