Skip to content

Commit

Permalink
fix: Selectively round up and down depending on the color saturation,…
Browse files Browse the repository at this point in the history
… to ensure values near 0 and 100% are visually distinct
  • Loading branch information
LisoUseInAIKyrios committed Nov 24, 2024
1 parent f494e52 commit 4cf741d
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4cf741d

Please sign in to comment.