9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-21 07:59:26 +00:00
Files
Leaf/patches/api/0010-Paper-PR-Optimise-color-distance-check-in-MapPalette.patch
Dreeam 5365c49680 Updated Upstream (Gale)
Upstream has released updates that appear to apply and compile correctly

Gale Changes:
Dreeam-qwq/Gale@1e0ebad Clean up
Dreeam-qwq/Gale@9ce20fa throw MissingPaletteEntryException for null entries in hash palette
Dreeam-qwq/Gale@751637d Final clean up imports
2024-11-10 17:20:40 -05:00

41 lines
1.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Barnaby <22575741+barnabwhy@users.noreply.github.com>
Date: Sat, 29 Jun 2024 12:04:48 +0100
Subject: [PATCH] Paper PR: Optimise color distance check in MapPalette by
removing floating point math
Original license: GPLv3
Original project: https://github.com/PaperMC/Paper
Paper pull request: https://github.com/PaperMC/Paper/pull/11000
diff --git a/src/main/java/org/bukkit/map/MapPalette.java b/src/main/java/org/bukkit/map/MapPalette.java
index 8a12bac4f9b0c5798ea1bd7d7aa10ad5d7ced579..a4cd1c4dc937c9905e91739e6760bf0bc772cabe 100644
--- a/src/main/java/org/bukkit/map/MapPalette.java
+++ b/src/main/java/org/bukkit/map/MapPalette.java
@@ -29,14 +29,19 @@ public final class MapPalette {
}
private static double getDistance(@NotNull Color c1, @NotNull Color c2) {
- double rmean = (c1.getRed() + c2.getRed()) / 2.0;
- double r = c1.getRed() - c2.getRed();
- double g = c1.getGreen() - c2.getGreen();
+ // Paper start - Optimize color distance calculation by removing floating point math
+ int rsum = c1.getRed() + c2.getRed(); // Use sum instead of mean for no division
+ int r = c1.getRed() - c2.getRed();
+ int g = c1.getGreen() - c2.getGreen();
int b = c1.getBlue() - c2.getBlue();
- double weightR = 2 + rmean / 256.0;
- double weightG = 4.0;
- double weightB = 2 + (255 - rmean) / 256.0;
+ // All weights are 512x their original to avoid floating point division
+ int weightR = 1024 + rsum;
+ int weightG = 2048;
+ int weightB = 1024 + (255*2 - rsum);
+
+ // Division by 256 here is unnecessary as this won't change the result of the sort
return weightR * r * r + weightG * g * g + weightB * b * b;
+ // Paper end
}
@NotNull