From 4cf741df7b1c5062c4f7ce31464e740918c2c6ac Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:12:29 +0400 Subject: [PATCH] fix: Selectively round up and down depending on the color saturation, to ensure values near 0 and 100% are visually distinct --- .../patches/theme/SeekbarColorPatch.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java index ea2bcfc3a3..1ca34076d0 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java @@ -95,11 +95,24 @@ public static boolean useLotteLaunchSplashScreen(boolean original) { return original; } + private static int colorChannelTo3Bits(int channel8Bits) { + final float channel3Bits = channel8Bits * 7 / 255f; + + // If a color channel is near zero, then allow rounding up so values between + // 0x12 and 0x23 will show as 0x24. This ensures color channels that are + // close to zero (but not zero) still show some color. + // + // But always round down when the channel is near full saturation, otherwise rounding + // to nearest will cause all values between 0xEC and 0xFE to always show as 0xFF. + return channel3Bits < 1 + ? Math.round(channel3Bits) + : (int) channel3Bits; + } + private static String get9BitStyleIdentifier(int color24Bit) { - // Convert to nearest 9-bit color (3 bits per color channel). - final int r3 = Color.red(color24Bit) * 7 / 255; - final int g3 = Color.green(color24Bit) * 7 / 255; - final int b3 = Color.blue(color24Bit) * 7 / 255; + final int r3 = colorChannelTo3Bits(Color.red(color24Bit)); + final int g3 = colorChannelTo3Bits(Color.green(color24Bit)); + final int b3 = colorChannelTo3Bits(Color.blue(color24Bit)); return String.format(Locale.US, "splash_seekbar_color_style_%d_%d_%d", r3, g3, b3); }