Skip to content

Instantly share code, notes, and snippets.

@PowerX-NOT
Last active May 29, 2024 20:06
Show Gist options
  • Save PowerX-NOT/0f23e7133768f04ccc15d5dc3d2aa2c1 to your computer and use it in GitHub Desktop.
Save PowerX-NOT/0f23e7133768f04ccc15d5dc3d2aa2c1 to your computer and use it in GitHub Desktop.
import math
def calculate_backlight_ratio(max_backlight, nits_with_hbm, nits_without_hbm):
ratio = (max_backlight * nits_with_hbm) / nits_without_hbm
return ratio
# Get user input for backlight parameters
lut_type = input("Do you want LUT for FrameworkDimming or KernelDimming FD/KD?: ").strip().upper()
if lut_type not in ['FD', 'KD']:
print("Invalid LUT type. Please choose 'FD' for FrameworkDimming or 'KD' for KernelDimming.")
exit()
max_backlight = float(input("Enter the maximal backlight value: "))
nits_with_hbm = float(input("Enter the nits with HBM: "))
nits_without_hbm = float(input("Enter the nits without HBM: "))
gamma_factor = float(input("Enter the Gamma factor: "))
# Choose A2 values based on max_backlight
if max_backlight == 2047:
A2_values = [0, 3, 13, 31, 58, 96, 143, 200, 269, 348, 439, 551, 667, 794, 934, 1086, 1250, 1427, 1618, 1821, 2047]
dc_threshold = 610 # Set dc_threshold for max_backlight == 2047
dc_A2_values = [0, 1, 4, 9, 18, 29, 43, 60, 81, 106, 132, 163, 198, 237, 277, 323, 373, 428, 481, 544, 610]
elif max_backlight == 4095:
A2_values = [0, 6, 26, 62, 116, 192, 286, 400, 538, 696, 878, 1102, 1334, 1588, 1868, 2172, 2500, 2854, 3236, 3642, 4095]
dc_threshold = 1220 # Set dc_threshold for max_backlight == 4095
dc_A2_values = [0, 2, 8, 18, 36, 58, 86, 120, 162, 212, 264, 326, 396, 474, 554, 646, 746, 856, 962, 1088, 1220]
elif max_backlight == 1023:
A2_values = [0, 1, 16, 33, 48, 97, 146, 194, 243, 292, 341, 389, 438, 487, 535, 584, 633, 682, 730, 779, 828, 876, 925, 974, 1023]
dc_threshold = 320 # Set dc_threshold for max_backlight == 1023
dc_A2_values = [0, 1, 3, 5, 9, 15, 22, 32, 43, 56, 69, 86, 104, 124, 145, 169, 196, 224, 253, 285, 320]
else:
print("Invalid max_backlight value. Please choose 1023, 2047, or 4095.")
exit()
# Calculate backlight ratio
backlight_ratio = calculate_backlight_ratio(max_backlight, nits_with_hbm, nits_without_hbm)
print(f"The backlight ratio is: {backlight_ratio}")
if lut_type == 'KD':
# Print results for qcom,disp-fod-dim-lut
print("qcom,disp-fod-dim-lut = <")
print("\t/* brightness, alpha */")
for A2 in A2_values:
result = (1 - math.pow(A2 / backlight_ratio, 1/gamma_factor)) * 255
hex_result = hex(int(result)).upper()
print(f"\t{A2}\t{hex_result}")
print(">;")
# Print results for qcom,disp-dc-dim-lut
print("qcom,disp-dc-dim-lut = <")
print("\t/* brightness, alpha */")
for A2 in dc_A2_values:
result = (1 - math.pow(A2 / dc_threshold, 1/gamma_factor)) * 255
hex_result = hex(int(result)).upper()
print(f"\t{A2}\t{hex_result}")
print(">;")
elif lut_type == 'FD':
# Print for framework dimming
print("Array of brightness-alpha LUT for framework dimming:")
for A2 in A2_values:
result = (1 - math.pow(A2 / backlight_ratio, 1/gamma_factor)) * 255
int_result = int(result)
print(f"<item>{A2},{int_result}</item>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment