Skip to content

Commit 7256024

Browse files
fix: Selectively round up and down depending on the color saturation, to ensure values near 0 and 100% are visually distinct
1 parent f494e52 commit 7256024

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,26 @@ public static boolean useLotteLaunchSplashScreen(boolean original) {
9595
return original;
9696
}
9797

98+
private static int colorChannelTo3Bits(int channel8Bits) {
99+
final float channel3Bits = channel8Bits * 7 / 255f;
100+
101+
// If a color channel is near zero, then allow rounding up so values between
102+
// 0x12 and 0x23 will show as 0x24. This ensures color channels that are
103+
// close to zero (but not zero) still show some color.
104+
//
105+
// But always round down when the channel is near full saturation, otherwise rounding
106+
// to nearest will cause all values between 0xEC and 0xFE to always show as 0xFF.
107+
return channel3Bits < 1
108+
? Math.round(channel3Bits)
109+
: (int) channel3Bits;
110+
}
111+
98112
private static String get9BitStyleIdentifier(int color24Bit) {
99-
// Convert to nearest 9-bit color (3 bits per color channel).
100-
final int r3 = Color.red(color24Bit) * 7 / 255;
101-
final int g3 = Color.green(color24Bit) * 7 / 255;
102-
final int b3 = Color.blue(color24Bit) * 7 / 255;
113+
final int rInt = colorChannelTo3Bits(Color.red(color24Bit));
114+
final int gInt = colorChannelTo3Bits(Color.green(color24Bit));
115+
final int bInt = colorChannelTo3Bits(Color.blue(color24Bit));
103116

104-
return String.format(Locale.US, "splash_seekbar_color_style_%d_%d_%d", r3, g3, b3);
117+
return String.format(Locale.US, "splash_seekbar_color_style_%d_%d_%d", rInt, gInt, bInt);
105118
}
106119

107120
/**

0 commit comments

Comments
 (0)