Created
January 22, 2023 02:30
-
-
Save pwnrazr/b03159a47cb7637f587675256d6c69f9 to your computer and use it in GitHub Desktop.
Quick C program to calculate brightness to alpha pairs based on exposure adjustment driver (raphael values). Pretty sure there's an easier way but this was the only thing I thought of in the middle of the night
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Online C compiler to run C program online | |
// https://www.programiz.com/c-programming/online-compiler/ | |
#include <stdio.h> | |
int main() { | |
// Formula to map value from A to B is (value - A_min) * (B_max - B_min) / (A_max - A_min) + B_min | |
// A is coeffs 768 32768 | |
// B is dimming range 0 255 | |
// Below alues got from exposure adjustment driver | |
// https://github.com/pwnrazr/kernel_raphael_sm8150/blob/715623fc27a33ac072603e9eb27c517aee663139/drivers/gpu/drm/msm/dsi-staging/exposure_adjustment.c | |
#define ELVSS_OFF_THRESHOLD 420 // Constant backlight value | |
#define EXPOSURE_ADJUSTMENT_MIN 768 | |
/* PCC coefficient when exposure is 255 */ | |
#define EXPOSURE_ADJUSTMENT_MAX 32768 | |
/* Scale for the PCC coefficient with elvss backlight range */ | |
#define PCC_BACKLIGHT_SCALE \ | |
(EXPOSURE_ADJUSTMENT_MAX - EXPOSURE_ADJUSTMENT_MIN) / ELVSS_OFF_THRESHOLD | |
#define min_dc_dimming_brightness 4 | |
// Device values(?) | |
#define max_brightness 2047 | |
#define min_brightness 1 | |
#define step 1 | |
#define max_dim_range 255 | |
#define min_dim_range 0 | |
#define length 22 | |
int coeffs[max_brightness]; | |
int coeffs_remap[max_brightness]; | |
int coeffs_remap_invert[max_brightness]; | |
int bl_lvl, ea_coeff, min_step_num, max_step_num = 0; | |
// Convert brightness level to coefficient | |
for ( bl_lvl = 0; bl_lvl < max_brightness; bl_lvl = bl_lvl + step) | |
{ | |
coeffs[bl_lvl] = bl_lvl * PCC_BACKLIGHT_SCALE + EXPOSURE_ADJUSTMENT_MIN; | |
if(coeffs[bl_lvl] > EXPOSURE_ADJUSTMENT_MAX) { | |
max_step_num = bl_lvl - min_brightness; | |
printf("Max brightness before no DC Dim: %d\n", max_step_num); | |
break; | |
} | |
} | |
//remap coefficients to dim values | |
for ( int i = min_step_num; i < max_step_num; i = i + step){ | |
coeffs_remap[i] = (coeffs[i] - EXPOSURE_ADJUSTMENT_MIN) * (max_dim_range - min_dim_range) / (EXPOSURE_ADJUSTMENT_MAX - EXPOSURE_ADJUSTMENT_MIN) + min_dim_range; | |
} | |
//Invert coeffs in array | |
for (int i = 0; i < max_step_num; i++) { | |
coeffs_remap_invert[i] = coeffs_remap[max_step_num - i - 1]; | |
} | |
// Print values | |
printf("brightness, alpha\n"); | |
for( int i = 0; i != length; i++ ) | |
{ | |
int brightness = i * (max_step_num - min_brightness) / (length - 1) + min_brightness; | |
printf("%d %d\n", brightness, coeffs_remap_invert[brightness]); | |
} | |
printf("Min DC Dimming brightness pair:\n"); | |
printf("%d %d\n", min_dc_dimming_brightness, coeffs_remap_invert[min_dc_dimming_brightness]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment