From eabf26b56ebb274c606a810d8ee42bf8fde40463 Mon Sep 17 00:00:00 2001 From: "wenfeng.guo" Date: Wed, 7 Mar 2018 19:34:52 +0800 Subject: [PATCH] amvecm: modify dnlp algorithm PD#161646: amvecm: modify dnlp algorithm 1. separate dnlp algorithm to dnlp_cal.c 2. modify dnlp algorithm 3. add dnlp curve debug interface Change-Id: Ic5dd20f606b6cd612897c30ec09c6f0535ffefca Signed-off-by: wenfeng.guo --- .../amlogic/media/enhancement/amvecm/Makefile | 2 +- .../amlogic/media/enhancement/amvecm/amve.c | 3648 +-------------- .../amlogic/media/enhancement/amvecm/amve.h | 17 +- .../amlogic/media/enhancement/amvecm/amvecm.c | 586 ++- .../media/enhancement/amvecm/dnlp_cal.c | 3939 +++++++++++++++++ .../media/enhancement/amvecm/dnlp_cal.h | 108 + include/linux/amlogic/media/amvecm/amvecm.h | 3 +- include/linux/amlogic/media/amvecm/ve.h | 175 +- 8 files changed, 4580 insertions(+), 3898 deletions(-) create mode 100644 drivers/amlogic/media/enhancement/amvecm/dnlp_cal.c create mode 100644 drivers/amlogic/media/enhancement/amvecm/dnlp_cal.h diff --git a/drivers/amlogic/media/enhancement/amvecm/Makefile b/drivers/amlogic/media/enhancement/amvecm/Makefile index 2edf28b48b05..a24b8a38a1b8 100644 --- a/drivers/amlogic/media/enhancement/amvecm/Makefile +++ b/drivers/amlogic/media/enhancement/amvecm/Makefile @@ -3,5 +3,5 @@ # obj-$(CONFIG_AMLOGIC_MEDIA_ENHANCEMENT_VECM) += am_vecm.o -am_vecm-objs := amve.o amcm.o amcsc.o amvecm.o keystone_correction.o bitdepth.o set_hdr2_v0.o +am_vecm-objs := amve.o amcm.o amcsc.o amvecm.o keystone_correction.o bitdepth.o set_hdr2_v0.o dnlp_cal.o diff --git a/drivers/amlogic/media/enhancement/amvecm/amve.c b/drivers/amlogic/media/enhancement/amvecm/amve.c index 2a6ac3c1ff7a..7ad9811829b0 100644 --- a/drivers/amlogic/media/enhancement/amvecm/amve.c +++ b/drivers/amlogic/media/enhancement/amvecm/amve.c @@ -35,10 +35,11 @@ #include "amve_gamma_table.h" #include "amvecm_vlock_regmap.h" #include +#include "dnlp_cal.h" #define pr_amve_dbg(fmt, args...)\ do {\ - if (dnlp_debug&0x1)\ + if (amve_debug&0x1)\ pr_info("AMVE: " fmt, ## args);\ } while (0)\ /* #define pr_amve_error(fmt, args...) */ @@ -61,38 +62,14 @@ module_param(dnlp_sel, int, 0664); MODULE_PARM_DESC(dnlp_sel, "dnlp_sel"); /* #endif */ +static int amve_debug; +module_param(amve_debug, int, 0664); +MODULE_PARM_DESC(amve_debug, "amve_debug"); + struct ve_hist_s video_ve_hist; -static unsigned char ve_dnlp_tgt[64]; -bool ve_en; -unsigned int ve_dnlp_white_factor; -unsigned int ve_dnlp_rt; -unsigned int ve_dnlp_rl; -unsigned int ve_dnlp_black; -unsigned int ve_dnlp_white; -unsigned int ve_dnlp_luma_sum; -static ulong ve_dnlp_lpf[64], ve_dnlp_reg[16]; -static ulong ve_dnlp_reg_def[16] = { - 0x0b070400, 0x1915120e, 0x2723201c, 0x35312e2a, - 0x47423d38, 0x5b56514c, 0x6f6a6560, 0x837e7974, - 0x97928d88, 0xaba6a19c, 0xbfbab5b0, 0xcfccc9c4, - 0xdad7d5d2, 0xe6e3e0dd, 0xf2efece9, 0xfdfaf7f4 -}; - -/*static bool frame_lock_nosm = 1;*/ -static int ve_dnlp_waist_h = 128; -static int ve_dnlp_waist_l = 128; -static int ve_dnlp_ankle = 16; -static int ve_dnlp_strength = 255; unsigned int vpp_log[128][10]; -struct ve_dnlp_s am_ve_dnlp; -struct ve_dnlp_table_s am_ve_new_dnlp; -#if 0 -static unsigned int lock_range_50hz_fast = 7; /* <= 14 */ -static unsigned int lock_range_50hz_slow = 7; /* <= 14 */ -static unsigned int lock_range_60hz_fast = 5; /* <= 4 */ -static unsigned int lock_range_60hz_slow = 2; /* <= 10 */ -#endif + struct tcon_gamma_table_s video_gamma_table_r; struct tcon_gamma_table_s video_gamma_table_g; struct tcon_gamma_table_s video_gamma_table_b; @@ -138,96 +115,6 @@ static int amvecm_hiu_reg_write_bits(unsigned int reg, unsigned int value, return 0; } - -module_param(ve_dnlp_waist_h, int, 0664); -MODULE_PARM_DESC(ve_dnlp_waist_h, "ve_dnlp_waist_h"); -module_param(ve_dnlp_waist_l, int, 0664); -MODULE_PARM_DESC(ve_dnlp_waist_l, "ve_dnlp_waist_l"); -module_param(ve_dnlp_ankle, int, 0664); -MODULE_PARM_DESC(ve_dnlp_ankle, "ve_dnlp_ankle"); -module_param(ve_dnlp_strength, int, 0664); -MODULE_PARM_DESC(ve_dnlp_strength, "ve_dnlp_strength"); - -/*static int debug_add_curve_en;*/ -int glb_scurve[65]; -int glb_clash_curve[65]; -/*static int glb_scurve_bld_rate;*/ -/*static int glb_clash_curve_bld_rate;*/ -int glb_pst_gamma[65]; -/*static int glb_pst_gamma_bld_rate;*/ - -static int debug_add_curve_en; -module_param(debug_add_curve_en, int, 0664); -MODULE_PARM_DESC(debug_add_curve_en, "debug_add_curve_en"); - -static int ve_usr_defined_test_s_mode; -module_param(ve_usr_defined_test_s_mode, int, 0664); -MODULE_PARM_DESC(ve_usr_defined_test_s_mode, "ve_usr_defined_test_s_mode"); - -static int ve_usr_defined_test_c_mode; -module_param(ve_usr_defined_test_c_mode, int, 0664); -MODULE_PARM_DESC(ve_usr_defined_test_c_mode, "ve_usr_defined_test_c_mode"); - -static int ve_usr_defined_test_g_mode; -module_param(ve_usr_defined_test_g_mode, int, 0664); -MODULE_PARM_DESC(ve_usr_defined_test_g_mode, "ve_usr_defined_test_g_mode"); - -static int glb_scurve_bld_rate; -module_param(glb_scurve_bld_rate, int, 0664); -MODULE_PARM_DESC(glb_scurve_bld_rate, "glb_scurve_bld_rate"); - -static int glb_clash_curve_bld_rate; -module_param(glb_clash_curve_bld_rate, int, 0664); -MODULE_PARM_DESC(glb_clash_curve_bld_rate, "glb_clash_curve_bld_rate"); - -static int glb_pst_gamma_bld_rate; -module_param(glb_pst_gamma_bld_rate, int, 0664); -MODULE_PARM_DESC(glb_pst_gamma_bld_rate, "glb_pst_gamma_bld_rate"); - -static int dnlp_respond; -module_param(dnlp_respond, int, 0664); -MODULE_PARM_DESC(dnlp_respond, "dnlp_respond"); - -static int dnlp_debug; -module_param(dnlp_debug, int, 0664); -MODULE_PARM_DESC(dnlp_debug, "dnlp_debug"); - -static int ve_dnlp_method; -module_param(ve_dnlp_method, int, 0664); -MODULE_PARM_DESC(ve_dnlp_method, "ve_dnlp_method"); - -static int ve_dnlp_cliprate = 6; -module_param(ve_dnlp_cliprate, int, 0664); -MODULE_PARM_DESC(ve_dnlp_cliprate, "ve_dnlp_cliprate"); - -static int ve_dnlp_lowrange = 18; -module_param(ve_dnlp_lowrange, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lowrange, "ve_dnlp_lowrange"); - -static int ve_dnlp_hghrange = 18; -module_param(ve_dnlp_hghrange, int, 0664); -MODULE_PARM_DESC(ve_dnlp_hghrange, "ve_dnlp_hghrange"); - -static int ve_dnlp_auto_rng; -module_param(ve_dnlp_auto_rng, int, 0664); -MODULE_PARM_DESC(ve_dnlp_auto_rng, "ve_dnlp_auto_rng"); - -static int ve_dnlp_lowalpha = 24; -module_param(ve_dnlp_lowalpha, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lowalpha, "ve_dnlp_lowalpha"); - -static int ve_dnlp_midalpha = 24; -module_param(ve_dnlp_midalpha, int, 0664); -MODULE_PARM_DESC(ve_dnlp_midalpha, "ve_dnlp_midalpha"); - -static int ve_dnlp_hghalpha = 24; -module_param(ve_dnlp_hghalpha, int, 0664); -MODULE_PARM_DESC(ve_dnlp_hghalpha, "ve_dnlp_hghalpha"); - -static int dnlp_adj_level = 6; -module_param(dnlp_adj_level, int, 0664); -MODULE_PARM_DESC(dnlp_adj_level, "dnlp_adj_level"); - int dnlp_en;/* 0:disabel;1:enable */ module_param(dnlp_en, int, 0664); MODULE_PARM_DESC(dnlp_en, "\n enable or disable dnlp\n"); @@ -253,468 +140,7 @@ MODULE_PARM_DESC(video_rgb_ogo_xvy_mtx, int video_rgb_ogo_xvy_mtx_latch = 1; -static int ve_dnlp_adj_level = 6; -module_param(ve_dnlp_adj_level, int, 0664); -MODULE_PARM_DESC(ve_dnlp_adj_level, - "ve_dnlp_adj_level"); - -/* new dnlp start */ -/* larger -> slower */ -static int ve_dnlp_mvreflsh = 6; -module_param(ve_dnlp_mvreflsh, int, 0664); -MODULE_PARM_DESC(ve_dnlp_mvreflsh, - "ve_dnlp_mvreflsh"); - -static int ve_dnlp_gmma_rate = 82; -module_param(ve_dnlp_gmma_rate, int, 0664); -MODULE_PARM_DESC(ve_dnlp_gmma_rate, - "ve_dnlp_gmma_rate"); - -static int ve_dnlp_lowalpha_new = 40; -module_param(ve_dnlp_lowalpha_new, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lowalpha_new, - "ve_dnlp_lowalpha_new"); - -static int ve_dnlp_hghalpha_new = 28; -module_param(ve_dnlp_hghalpha_new, int, 0664); -MODULE_PARM_DESC(ve_dnlp_hghalpha_new, - "ve_dnlp_hghalpha_new"); - -static int ve_dnlp_cliprate_new = 36; -module_param(ve_dnlp_cliprate_new, int, 0664); -MODULE_PARM_DESC(ve_dnlp_cliprate_new, - "ve_dnlp_cliprate_new"); - -int ve_dnlp_sbgnbnd; -module_param(ve_dnlp_sbgnbnd, int, 0664); -MODULE_PARM_DESC(ve_dnlp_sbgnbnd, "ve_dnlp_sbgnbnd"); - -static int ve_dnlp_sendbnd; -module_param(ve_dnlp_sendbnd, int, 0664); -MODULE_PARM_DESC(ve_dnlp_sendbnd, "ve_dnlp_sendbnd"); - -int ve_dnlp_clashBgn; -module_param(ve_dnlp_clashBgn, int, 0664); -MODULE_PARM_DESC(ve_dnlp_clashBgn, "ve_dnlp_clashBgn"); - -static int ve_dnlp_clashEnd = 15; -module_param(ve_dnlp_clashEnd, int, 0664); -MODULE_PARM_DESC(ve_dnlp_clashEnd, "ve_dnlp_clashEnd"); - -static int ve_mtdbld_rate = 53; -module_param(ve_mtdbld_rate, int, 0664); -MODULE_PARM_DESC(ve_mtdbld_rate, "ve_mtdbld_rate"); - -static int ve_dnlp_pst_gmarat = 65; -module_param(ve_dnlp_pst_gmarat, int, 0664); -MODULE_PARM_DESC(ve_dnlp_pst_gmarat, "ve_dnlp_pst_gmarat"); - -/*dnlp method = 3, use this flag or no use*/ -bool ve_dnlp_respond_flag; -module_param(ve_dnlp_respond_flag, bool, 0664); -MODULE_PARM_DESC(ve_dnlp_respond_flag, - "ve_dnlp_respond_flag"); - -/*dnlp method = 3, check the same histogram*/ -bool ve_dnlp_smhist_ck; -module_param(ve_dnlp_smhist_ck, bool, 0664); -MODULE_PARM_DESC(ve_dnlp_smhist_ck, - "ve_dnlp_smhist_ck"); - -bool ve_dnlp_dbg_adjavg; -module_param(ve_dnlp_dbg_adjavg, bool, 0664); -MODULE_PARM_DESC(ve_dnlp_dbg_adjavg, - "ve_dnlp_dbg_adjavg"); - -int ve_dnlp_dbg_i2r = 255; -module_param(ve_dnlp_dbg_i2r, int, 0664); -MODULE_PARM_DESC(ve_dnlp_dbg_i2r, - "ve_dnlp_dbg_i2r"); - -/* light -pattern 1 */ -int ve_dnlp_slow_end = 2; -module_param(ve_dnlp_slow_end, int, 0664); -MODULE_PARM_DESC(ve_dnlp_slow_end, - "ve_dnlp_slow_end"); - -/*concentration*/ -static int ve_dnlp_blk_cctr = 8; -module_param(ve_dnlp_blk_cctr, int, 0664); -MODULE_PARM_DESC(ve_dnlp_blk_cctr, "dnlp low luma concenration"); - -/*the center to be brighter*/ -static int ve_dnlp_brgt_ctrl = 48; -module_param(ve_dnlp_brgt_ctrl, int, 0664); -MODULE_PARM_DESC(ve_dnlp_brgt_ctrl, "dnlp center to be brighter"); - -/*brighter range*/ -static int ve_dnlp_brgt_range = 16; -module_param(ve_dnlp_brgt_range, int, 0664); -MODULE_PARM_DESC(ve_dnlp_brgt_range, "dnlp brighter range"); - -/*yout=yin+ve_dnlp_brght_add*/ -/* 32 => 0, brght_add range = [0,64] => [-32,+32] */ -static int ve_dnlp_brght_add = 32; -module_param(ve_dnlp_brght_add, int, 0664); -MODULE_PARM_DESC(ve_dnlp_brght_add, "dnlp brightness up absolute"); - -/*yout=yin+ve_dnlp_brght_add + ve_dnlp_brght_max*rate*/ -static int ve_dnlp_brght_max; -module_param(ve_dnlp_brght_max, int, 0664); -MODULE_PARM_DESC(ve_dnlp_brght_max, "dnlp brightness up maximum"); - -/* define the black or white scence */ -static int ve_dnlp_almst_wht = 63; -module_param(ve_dnlp_almst_wht, int, 0664); -MODULE_PARM_DESC(ve_dnlp_almst_wht, "define the white scence"); - -/* global setting clip rate */ -static bool ve_dnlp_glb_crate = 1; -module_param(ve_dnlp_glb_crate, bool, 0664); -MODULE_PARM_DESC(ve_dnlp_glb_crate, "global clash rate"); - -/* define it high bins: hist > hghbin*tAvg/64 */ -static int ve_dnlp_hghbin = 51; -module_param(ve_dnlp_hghbin, int, 0664); -MODULE_PARM_DESC(ve_dnlp_hghbin, "high bins"); - -/* the number of bins with the largest histogram */ -static int ve_dnlp_hghnum = 4; -module_param(ve_dnlp_hghnum, int, 0664); -MODULE_PARM_DESC(ve_dnlp_hghnum, "the number of high bins"); - -/* define it low bins: hist < lowbin*tAvg/64 */ -static int ve_dnlp_lowbin = 4; -module_param(ve_dnlp_lowbin, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lowbin, "define it low bins"); - -/* the number of bins with the lowest histogram */ -static int ve_dnlp_lownum = 4; -module_param(ve_dnlp_lownum, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lownum, "the number of low bins"); - -/* black gamma end point setting */ -static int ve_dnlp_bkgend; -module_param(ve_dnlp_bkgend, int, 0664); -MODULE_PARM_DESC(ve_dnlp_bkgend, "black gamma end point setting"); - -/* black gamma end point rate */ -static int ve_dnlp_bkgert = 64; -module_param(ve_dnlp_bkgert, int, 0664); -MODULE_PARM_DESC(ve_dnlp_bkgert, "black gamma end point rate"); - -static int ve_dnlp_pstgma_brghtrate = 8; -module_param(ve_dnlp_pstgma_brghtrate, int, 0664); -MODULE_PARM_DESC(ve_dnlp_pstgma_brghtrate, "ve_dnlp_pstgma_brghtrate"); - -static int ve_dnlp_pstgma_brghtrat1 = 15; -module_param(ve_dnlp_pstgma_brghtrat1, int, 0664); -MODULE_PARM_DESC(ve_dnlp_pstgma_brghtrat1, "ve_dnlp_pstgma_brghtrat1"); - -/* black extension when sum(hist) < (ext*tAvg>>6) */ -static int ve_dnlp_blkext = 4; -module_param(ve_dnlp_blkext, int, 0664); -MODULE_PARM_DESC(ve_dnlp_blkext, "black extension: sum()"); - -/* white extension when sum(hist) < (ext*tAvg>>6) */ -static int ve_dnlp_whtext = 4; -module_param(ve_dnlp_whtext, int, 0664); -MODULE_PARM_DESC(ve_dnlp_whtext, "white extension: sum()"); - -/* black extension maximum bins */ -static int ve_dnlp_bextmx = 4; -module_param(ve_dnlp_bextmx, int, 0664); -MODULE_PARM_DESC(ve_dnlp_bextmx, "black extension bins"); - -/* white extension maximum bins */ -static int ve_dnlp_wextmx = 32; -module_param(ve_dnlp_wextmx, int, 0664); -MODULE_PARM_DESC(ve_dnlp_wextmx, "white extension bins"); - -static int ve_dnlp_wext_autorat = 16; -module_param(ve_dnlp_wext_autorat, int, 0664); -MODULE_PARM_DESC(ve_dnlp_wext_autorat, "ve_dnlp_wext_autorat"); - -/* adpative mtdrate low band */ -/* default=0 */ -static int ve_dnlp_adpmtd_lbnd = 19; -module_param(ve_dnlp_adpmtd_lbnd, int, 0664); -MODULE_PARM_DESC(ve_dnlp_adpmtd_lbnd, "ve_dnlp_adpmtd_lbnd"); - -/* adpative mtdrate high band */ -/* default=0 */ -static int ve_dnlp_adpmtd_hbnd = 20; -module_param(ve_dnlp_adpmtd_hbnd, int, 0664); -MODULE_PARM_DESC(ve_dnlp_adpmtd_hbnd, "ve_dnlp_adpmtd_hbnd"); - -static int ve_dnlp_adpalpha_lrate = 32; -module_param(ve_dnlp_adpalpha_lrate, int, 0664); -MODULE_PARM_DESC(ve_dnlp_adpalpha_lrate, "ve_dnlp_adpalpha_lrate"); - -static int ve_dnlp_adpalpha_hrate = 32; -module_param(ve_dnlp_adpalpha_hrate, int, 0664); -MODULE_PARM_DESC(ve_dnlp_adpalpha_hrate, "ve_dnlp_adpalpha_hrate"); - -static int ve_dnlp_set_bext; -module_param(ve_dnlp_set_bext, int, 0664); -MODULE_PARM_DESC(ve_dnlp_set_bext, "ve_dnlp_set_bext"); - -static int ve_dnlp_set_wext; -module_param(ve_dnlp_set_wext, int, 0664); -MODULE_PARM_DESC(ve_dnlp_set_wext, "ve_dnlp_set_wext"); - -static int ve_dnlp_satur_rat = 30; -module_param(ve_dnlp_satur_rat, int, 0664); -MODULE_PARM_DESC(ve_dnlp_satur_rat, "ve_dnlp_satur_rat"); - -static int ve_dnlp_satur_max = 40; -module_param(ve_dnlp_satur_max, int, 0664); -MODULE_PARM_DESC(ve_dnlp_satur_max, "ve_dnlp_satur_max"); - -static int ve_blk_prct_rng = 2; -module_param(ve_blk_prct_rng, int, 0664); -MODULE_PARM_DESC(ve_blk_prct_rng, "ve_blk_prct_rng"); - -static int ve_blk_prct_max = 16; -module_param(ve_blk_prct_max, int, 0664); -MODULE_PARM_DESC(ve_blk_prct_max, "ve_blk_prct_max"); - -static unsigned int ve_dnlp_set_saturtn; -module_param(ve_dnlp_set_saturtn, uint, 0664); -MODULE_PARM_DESC(ve_dnlp_set_saturtn, "ve_dnlp_set_saturtn"); - -static int ve_dnlp_bin0_absmax = 16; -module_param(ve_dnlp_bin0_absmax, int, 0664); -MODULE_PARM_DESC(ve_dnlp_bin0_absmax, "ve_dnlp_bin0_absmax"); - -static int ve_dnlp_bin0_sbtmax = 128; -module_param(ve_dnlp_bin0_sbtmax, int, 0664); -MODULE_PARM_DESC(ve_dnlp_bin0_sbtmax, "ve_dnlp_bin0_sbtmax"); - -static int ve_dnlp_lrate00 = 32; -module_param(ve_dnlp_lrate00, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate00, "Clash Local Clip rate 00"); - -static int ve_dnlp_lrate02 = 33; -module_param(ve_dnlp_lrate02, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate02, "Clash Local Clip rate 02"); - -static int ve_dnlp_lrate04 = 34; -module_param(ve_dnlp_lrate04, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate04, "Clash Local Clip rate 04"); - -static int ve_dnlp_lrate06 = 35; -module_param(ve_dnlp_lrate06, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate06, "Clash Local Clip rate 06"); - -static int ve_dnlp_lrate08 = 36; -module_param(ve_dnlp_lrate08, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate08, "Clash Local Clip rate 08"); - -static int ve_dnlp_lrate10 = 37; -module_param(ve_dnlp_lrate10, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate10, "Clash Local Clip rate 10"); - -static int ve_dnlp_lrate12 = 38; -module_param(ve_dnlp_lrate12, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate12, "Clash Local Clip rate 12"); - -static int ve_dnlp_lrate14 = 39; -module_param(ve_dnlp_lrate14, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate14, "Clash Local Clip rate 14"); - -static int ve_dnlp_lrate16 = 40; -module_param(ve_dnlp_lrate16, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate16, "Clash Local Clip rate 16"); - -static int ve_dnlp_lrate18 = 41; -module_param(ve_dnlp_lrate18, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate18, "Clash Local Clip rate 18"); - -static int ve_dnlp_lrate20 = 42; -module_param(ve_dnlp_lrate20, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate20, "Clash Local Clip rate 20"); - -static int ve_dnlp_lrate22 = 43; -module_param(ve_dnlp_lrate22, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate22, "Clash Local Clip rate 22"); - -static int ve_dnlp_lrate24 = 44; -module_param(ve_dnlp_lrate24, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate24, "Clash Local Clip rate 24"); - -static int ve_dnlp_lrate26 = 45; -module_param(ve_dnlp_lrate26, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate26, "Clash Local Clip rate 26"); - -static int ve_dnlp_lrate28 = 46; -module_param(ve_dnlp_lrate28, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate28, "Clash Local Clip rate 28"); - -static int ve_dnlp_lrate30 = 47; -module_param(ve_dnlp_lrate30, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate30, "Clash Local Clip rate 30"); - -static int ve_dnlp_lrate32 = 48; -module_param(ve_dnlp_lrate32, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate32, "Clash Local Clip rate 32"); - -static int ve_dnlp_lrate34 = 49; -module_param(ve_dnlp_lrate34, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate34, "Clash Local Clip rate 34"); - -static int ve_dnlp_lrate36 = 50; -module_param(ve_dnlp_lrate36, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate36, "Clash Local Clip rate 36"); - -static int ve_dnlp_lrate38 = 51; -module_param(ve_dnlp_lrate38, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate38, "Clash Local Clip rate 38"); - -static int ve_dnlp_lrate40 = 52; -module_param(ve_dnlp_lrate40, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate40, "Clash Local Clip rate 40"); - -static int ve_dnlp_lrate42 = 53; -module_param(ve_dnlp_lrate42, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate42, "Clash Local Clip rate 42"); - -static int ve_dnlp_lrate44 = 54; -module_param(ve_dnlp_lrate44, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate44, "Clash Local Clip rate 44"); - -static int ve_dnlp_lrate46 = 55; -module_param(ve_dnlp_lrate46, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate46, "Clash Local Clip rate 46"); - -static int ve_dnlp_lrate48 = 56; -module_param(ve_dnlp_lrate48, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate48, "Clash Local Clip rate 48"); - -static int ve_dnlp_lrate50 = 57; -module_param(ve_dnlp_lrate50, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate50, "Clash Local Clip rate 50"); - -static int ve_dnlp_lrate52 = 58; -module_param(ve_dnlp_lrate52, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate52, "Clash Local Clip rate 52"); - -static int ve_dnlp_lrate54 = 59; -module_param(ve_dnlp_lrate54, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate54, "Clash Local Clip rate 54"); - -static int ve_dnlp_lrate56 = 60; -module_param(ve_dnlp_lrate56, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate56, "Clash Local Clip rate 56"); - -static int ve_dnlp_lrate58 = 61; -module_param(ve_dnlp_lrate58, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate58, "Clash Local Clip rate 58"); - -static int ve_dnlp_lrate60 = 62; -module_param(ve_dnlp_lrate60, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate60, "Clash Local Clip rate 60"); - -static int ve_dnlp_lrate62 = 63; -module_param(ve_dnlp_lrate62, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lrate62, "Clash Local Clip rate 62"); -/* Local clip rate */ - -/*the maximum bins > x/256*/ -static int ve_dnlp_lgst_bin = 100; -module_param(ve_dnlp_lgst_bin, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lgst_bin, "dnlp: define it maximum bin"); - -/*two maximum bins' distance*/ -static int ve_dnlp_lgst_dst = 30; -module_param(ve_dnlp_lgst_dst, int, 0664); -MODULE_PARM_DESC(ve_dnlp_lgst_dst, "dnlp: two maximum bins' distance"); - -/* hd /fhd maybe set different value */ -static int ve_dnlp_pavg_btsft = 5; -module_param(ve_dnlp_pavg_btsft, int, 0664); -MODULE_PARM_DESC(ve_dnlp_pavg_btsft, "ve_dnlp_pavg_btsft"); - -/* limit range */ -static bool ve_dnlp_limit_rng = 1; -module_param(ve_dnlp_limit_rng, bool, 0664); -MODULE_PARM_DESC(ve_dnlp_limit_rng, "input limit range"); - -static bool ve_dnlp_range_det; -module_param(ve_dnlp_range_det, bool, 0664); -MODULE_PARM_DESC(ve_dnlp_range_det, -"input limit or full range detection"); - -/* scene change: avg - dif shif */ -static int ve_dnlp_schg_sft = 1; -module_param(ve_dnlp_schg_sft, int, 0664); -MODULE_PARM_DESC(ve_dnlp_schg_sft, - "ve_dnlp_schg_sft"); - -/* curveblend minimmum level */ -static int ve_dnlp_cuvbld_min = 2; -module_param(ve_dnlp_cuvbld_min, int, 0664); -MODULE_PARM_DESC(ve_dnlp_cuvbld_min, - "ve_dnlp_cuvbld_min"); - -/* curveblend minimmum level */ -static int ve_dnlp_cuvbld_max = 17; -module_param(ve_dnlp_cuvbld_max, int, 0664); -MODULE_PARM_DESC(ve_dnlp_cuvbld_max, - "ve_dnlp_cuvbld_max"); - -/* debug difference level */ -static int ve_dnlp_dbg_diflvl; -module_param(ve_dnlp_dbg_diflvl, int, 0664); -MODULE_PARM_DESC(ve_dnlp_dbg_diflvl, - "ve_dnlp_dbg_diflvl"); - -/* output the mapping curve */ -static int ve_dnlp_dbg_map; -module_param(ve_dnlp_dbg_map, int, 0664); -MODULE_PARM_DESC(ve_dnlp_dbg_map, - "ve_dnlp_dbg_map"); - -static int ve_dnlp_scv_dbg; -module_param(ve_dnlp_scv_dbg, int, 0664); -MODULE_PARM_DESC(ve_dnlp_scv_dbg, - "ve_dnlp_scv_dbg"); - -static int ve_dnlp_cliprate_min = 19; -module_param(ve_dnlp_cliprate_min, int, 0664); -MODULE_PARM_DESC(ve_dnlp_cliprate_min, - "ve_dnlp_cliprate_min"); - -static int ve_dnlp_adpcrat_lbnd = 10; -module_param(ve_dnlp_adpcrat_lbnd, int, 0664); -MODULE_PARM_DESC(ve_dnlp_adpcrat_lbnd, - "ve_dnlp_adpcrat_lbnd"); - -static int ve_dnlp_adpcrat_hbnd = 20; -module_param(ve_dnlp_adpcrat_hbnd, int, 0664); -MODULE_PARM_DESC(ve_dnlp_adpcrat_hbnd, - "ve_dnlp_adpcrat_hbnd"); - -/* print log once */ -static int ve_dnlp_ponce = 1; -module_param(ve_dnlp_ponce, int, 0664); -MODULE_PARM_DESC(ve_dnlp_ponce, "ve_dnlp_ponce"); - -/* global variable */ -unsigned int iRgnBgn; /* i>=iRgnBgn */ -unsigned int iRgnEnd = 64;/* ivpp , 0->vdin*/ -module_param(hist_sel, bool, 0664); -MODULE_PARM_DESC(hist_sel, "hist_sel"); - static unsigned int assist_cnt;/* ASSIST_SPARE8_REG1; */ -static unsigned int assist_cnt2;/* ASSIST_SPARE8_REG2; */ /* video lock */ /* 0:enc;1:pll;2:manual pll */ @@ -801,17 +227,6 @@ MODULE_PARM_DESC(sr_adapt_level, "\n sr_adapt_level\n"); /* *********************************************************************** */ /* *** VPP_FIQ-oriented functions **************************************** */ /* *********************************************************************** */ -static void ve_dnlp_add_cm(unsigned int value) -{ - unsigned int reg_value; - - VSYNC_WR_MPEG_REG(VPP_CHROMA_ADDR_PORT, 0x207); - reg_value = VSYNC_RD_MPEG_REG(VPP_CHROMA_DATA_PORT); - reg_value = (reg_value & 0xf000ffff) | (value << 16); - VSYNC_WR_MPEG_REG(VPP_CHROMA_ADDR_PORT, 0x207); - VSYNC_WR_MPEG_REG(VPP_CHROMA_DATA_PORT, reg_value); -} - static void ve_hist_gamma_tgt(struct vframe_s *vf) { int ave_luma; @@ -834,2749 +249,10 @@ static void ve_hist_gamma_tgt(struct vframe_s *vf) } } -static void ve_dnlp_calculate_tgt_ext(struct vframe_s *vf) -{ - struct vframe_prop_s *p = &vf->prop; - static unsigned int sum_b = 0, sum_c; - ulong i = 0, j = 0, sum = 0, ave = 0, ankle = 0, - waist = 0, peak = 0, start = 0; - ulong qty_h = 0, qty_l = 0, ratio_h = 0, ratio_l = 0; - ulong div1 = 0, div2 = 0, step_h = 0, step_l = 0; - ulong data[55]; - bool flag[55], previous_state_high = false; - /* READ_VPP_REG(ASSIST_SPARE8_REG1); */ - unsigned int cnt = assist_cnt; - /* old historic luma sum */ - sum_b = sum_c; - sum_c = ve_dnlp_luma_sum; - /* new historic luma sum */ - ve_dnlp_luma_sum = p->hist.luma_sum; - pr_amve_dbg("ve_dnlp_luma_sum=%x,sum_b=%x,sum_c=%x\n", - ve_dnlp_luma_sum, sum_b, sum_c); - /* picture mode: freeze dnlp curve */ - if (dnlp_respond) { - /* new luma sum is 0, something is wrong, freeze dnlp curve */ - if (!ve_dnlp_luma_sum) - return; - } else { - /* new luma sum is 0, something is wrong, freeze dnlp curve */ - if ((!ve_dnlp_luma_sum) || - /* new luma sum is closed to old one (1 +/- 1/64),*/ - /* picture mode, freeze curve */ - ((ve_dnlp_luma_sum < - sum_b + (sum_b >> dnlp_adj_level)) && - (ve_dnlp_luma_sum > - sum_b - (sum_b >> dnlp_adj_level)))) - return; - } - /* calculate ave (55 times of ave & data[] for accuracy) */ - /* ave 22-bit */ - /* data[] 22-bit */ - ave = 0; - for (i = 0; i < 55; i++) { - data[i] = (ulong)p->hist.gamma[i + 4]; - ave += data[i]; - data[i] *= 55; - flag[i] = false; - } - /* calculate ankle */ - /* ankle 22-bit */ - /* waist 22-bit */ - /* qty_h 6-bit */ - ankle = (ave * ve_dnlp_ankle + 128) >> 8; - /* scan data[] to find out waist pulses */ - qty_h = 0; - previous_state_high = false; - for (i = 0; i < 55; i++) { - if (data[i] >= ankle) { - /* ankle pulses start */ - if (!previous_state_high) { - previous_state_high = true; - start = i; - peak = 0; - } - /* normal maintenance */ - if (peak < data[i]) - peak = data[i]; - } else { - /* ankle pulses end + 1 */ - if (previous_state_high) { - previous_state_high = false; - /* calculate waist of high area pulses */ - if (peak >= ave) - waist = ((peak - ankle) * - ve_dnlp_waist_h + 128) >> 8; - /* calculate waist of high area pulses */ - else - waist = ((peak - ankle) * - ve_dnlp_waist_l + 128) >> 8; - /* find out waist pulses */ - for (j = start; j < i; j++) { - if (data[j] >= waist) { - flag[j] = true; - qty_h++; - } - } - } - } - } - /* calculate ratio_h and ratio_l */ - /* (div2 = 512*H*L times of value for accuracy) */ - /* averaged duty > 1/3 */ - /* qty_l 6-bit */ - /* div1 20-bit */ - /* div2 21-bit */ - /* ratio_h 22-bit */ - /* ratio_l 21-bit */ - qty_l = 55 - qty_h; - if ((!qty_h) || (!qty_l)) { - for (i = 5; i <= 58; i++) - ve_dnlp_tgt[i] = i << 2; - } else { - div1 = 256 * qty_h * qty_l; - div2 = 512 * qty_h * qty_l; - if (qty_h > 18) { - /* [1.0 ~ 2.0) */ - ratio_h = div2 + ve_dnlp_strength * qty_l * qty_l; - /* [0.5 ~ 1.0] */ - ratio_l = div2 - ve_dnlp_strength * qty_h * qty_l; - } - /* averaged duty < 1/3 */ - /* [1.0 ~ 2.0] */ - ratio_h = div2 + (ve_dnlp_strength << 1) * qty_h * qty_l; - /* (0.5 ~ 1.0] */ - ratio_l = div2 - (ve_dnlp_strength << 1) * qty_h * qty_h; - /* distribute ratio_h & ratio_l to */ - /* ve_dnlp_tgt[5] ~ ve_dnlp_tgt[58] */ - /* sum 29-bit */ - /* step_h 24-bit */ - /* step_l 23-bit */ - sum = div2 << 4; /* start from 16 */ - step_h = ratio_h << 2; - step_l = ratio_l << 2; - for (i = 5; i <= 58; i++) { - /* high phase */ - if (flag[i - 5]) - sum += step_h; - /* low phase */ - else - sum += step_l; - ve_dnlp_tgt[i] = (sum + div1) / div2; - } - if (cnt) { - for (i = 0; i < 64; i++) - pr_amve_dbg(" ve_dnlp_tgte[%ld]=%d\n", - i, ve_dnlp_tgt[i]); - /* WRITE_VPP_REG(ASSIST_SPARE8_REG1, 0); */ - assist_cnt = 0; - } - } -} -void GetWgtLst(ulong *iHst, ulong tAvg, ulong nLen, ulong alpha) -{ - ulong iMax = 0; - ulong iMin = 0; - ulong iPxl = 0; - ulong iT = 0; - for (iT = 0; iT < nLen; iT++) { - iPxl = iHst[iT]; - if (iPxl > tAvg) { - iMax = iPxl; - iMin = tAvg; - } else { - iMax = tAvg; - iMin = iPxl; - } - if (alpha < 16) { - iPxl = ((16-alpha)*iMin+8)>>4; - iPxl += alpha*iMin; - } else if (alpha < 32) { - iPxl = (32-alpha)*iMin; - iPxl += (alpha-16)*iMax; - } else { - iPxl = (48-alpha)+4*(alpha-32); - iPxl *= iMax; - } - iPxl = (iPxl+8)>>4; - iHst[iT] = iPxl < 1 ? 1 : iPxl; - } -} - -static void ve_dnlp_calculate_tgtx(struct vframe_s *vf) -{ - struct vframe_prop_s *p = &vf->prop; - ulong iHst[64]; - ulong oHst[64]; - static unsigned int sum_b = 0, sum_c; - ulong i = 0, j = 0, sum = 0, max = 0; - ulong cLmt = 0, nStp = 0, stp = 0, uLmt = 0; - long nExc = 0; - unsigned int cnt = assist_cnt;/* READ_VPP_REG(ASSIST_SPARE8_REG1); */ - unsigned int cnt2 = assist_cnt2;/* READ_VPP_REG(ASSIST_SPARE8_REG2); */ - unsigned int clip_rate = ve_dnlp_cliprate; /* 8bit */ - unsigned int low_range = ve_dnlp_lowrange;/* 18; //6bit [0-54] */ - unsigned int hgh_range = ve_dnlp_hghrange;/* 18; //6bit [0-54] */ - unsigned int low_alpha = ve_dnlp_lowalpha;/* 24; //6bit [0--48] */ - unsigned int mid_alpha = ve_dnlp_midalpha;/* 24; //6bit [0--48] */ - unsigned int hgh_alpha = ve_dnlp_hghalpha;/* 24; //6bit [0--48] */ - /* ------------------------------------------------- */ - ulong tAvg = 0; - ulong nPnt = 0; - ulong mRng = 0; - /* old historic luma sum */ - sum_b = sum_c; - sum_c = ve_dnlp_luma_sum; - /* new historic luma sum */ - ve_dnlp_luma_sum = p->hist.luma_sum; - pr_amve_dbg("ve_dnlp_luma_sum=%x,sum_b=%x,sum_c=%x\n", - ve_dnlp_luma_sum, sum_b, sum_c); - /* picture mode: freeze dnlp curve */ - if (dnlp_respond) { - /* new luma sum is 0, something is wrong, freeze dnlp curve */ - if (!ve_dnlp_luma_sum) - return; - } else { - /* new luma sum is 0, something is wrong, freeze dnlp curve */ - if ((!ve_dnlp_luma_sum) || - /* new luma sum is closed to old one (1 +/- 1/64), */ - /* picture mode, freeze curve */ - ((ve_dnlp_luma_sum < - sum_b + (sum_b >> dnlp_adj_level)) && - (ve_dnlp_luma_sum > - sum_b - (sum_b >> dnlp_adj_level)))) - return; - } - /* 64 bins, max, ave */ - for (i = 0; i < 64; i++) { - iHst[i] = (ulong)p->hist.gamma[i]; - if (i >= 4 && i <= 58) { - oHst[i] = iHst[i]; - if (max < iHst[i]) - max = iHst[i]; - sum += iHst[i]; - } else { - oHst[i] = 0; - } - } - cLmt = (clip_rate*sum)>>8; - tAvg = sum/55; - /* invalid histgram: freeze dnlp curve */ - if (max <= 55) - return; - /* get 1st 4 points */ - for (i = 4; i <= 58; i++) { - if (iHst[i] > cLmt) - nExc += (iHst[i]-cLmt); - } - nStp = (nExc+28)/55; - uLmt = cLmt-nStp; - if (cnt2) { - pr_amve_dbg(" ve_dnlp_tgtx:cLmt=%ld,nStp=%ld,uLmt=%ld\n", - cLmt, nStp, uLmt); - /* WRITE_VPP_REG(ASSIST_SPARE8_REG2, 0); */ - assist_cnt2 = 0; - } - if (clip_rate <= 4 || tAvg <= 2) { - cLmt = (sum+28)/55; - sum = cLmt*55; - for (i = 4; i <= 58; i++) - oHst[i] = cLmt; - } else if (nStp != 0) { - for (i = 4; i <= 58; i++) { - if (iHst[i] >= cLmt) - oHst[i] = cLmt; - else { - if (iHst[i] > uLmt) { - oHst[i] = cLmt; - nExc -= cLmt-iHst[i]; - } else { - oHst[i] = iHst[i]+nStp; - nExc -= nStp; - } - if (nExc < 0) - nExc = 0; - } - } - j = 4; - while (nExc > 0) { - if (nExc >= 55) { - nStp = 1; - stp = nExc/55; - } else { - nStp = 55/nExc; - stp = 1; - } - for (i = j; i <= 58; i += nStp) { - if (oHst[i] < cLmt) { - oHst[i] += stp; - nExc -= stp; - } - if (nExc <= 0) - break; - } - j += 1; - if (j > 58) - break; - } - } - if (low_range == 0 && hgh_range == 0) - nPnt = 0; - else { - if (low_range == 0 || hgh_range == 0) { - nPnt = 1; - mRng = (hgh_range > low_range ? hgh_range : low_range); - } else if (low_range+hgh_range >= 54) { - nPnt = 1; - mRng = (hgh_range < low_range ? hgh_range : low_range); - } else - nPnt = 2; - } - if (nPnt == 0 && low_alpha >= 16 && low_alpha <= 32) { - sum = 0; - for (i = 5; i <= 59; i++) { - j = oHst[i]*(32-low_alpha)+tAvg*(low_alpha-16); - j = (j+8)>>4; - oHst[i] = j; - sum += j; - } - } else if (nPnt == 1) { - GetWgtLst(oHst+4, tAvg, mRng, low_alpha); - GetWgtLst(oHst+4+mRng, tAvg, 54-mRng, hgh_alpha); - } else if (nPnt == 2) { - mRng = 55-(low_range+hgh_range); - GetWgtLst(oHst+4, tAvg, low_range, low_alpha); - GetWgtLst(oHst+4+low_range, tAvg, mRng, mid_alpha); - GetWgtLst(oHst+4+mRng+low_range, tAvg, hgh_range, hgh_alpha); - } - sum = 0; - for (i = 4; i <= 58; i++) { - if (oHst[i] > cLmt) - oHst[i] = cLmt; - sum += oHst[i]; - } - nStp = 0; - /* sum -= oHst[4]; */ - for (i = 5; i <= 59; i++) { - nStp += oHst[i-1]; - /* nStp += oHst[i]; */ - j = (236-16)*nStp; - j += (sum>>1); - j /= sum; - ve_dnlp_tgt[i] = j + 16; - } - if (cnt) { - for (i = 0; i < 64; i++) - pr_amve_dbg(" ve_dnlp_tgtx[%ld]=%d\n", - i, ve_dnlp_tgt[i]); - /* WRITE_VPP_REG(ASSIST_SPARE8_REG1, 0); */ - assist_cnt = 0; - } -} - -static unsigned int pre_1_gamma[65]; -static unsigned int pre_0_gamma[65]; - -/* more 2-bit */ -static unsigned int pst_0_gamma[65]; - -bool dnlp_scn_chg; /* scene change */ -int dnlp_bld_lvl; /* blend level */ -int RBASE = 1; - -/*rGmIn[0:64] ==>0:4:256, gamma*/ -/*rGmOt[0:pwdth]==>0-0, 0~1024*/ -void GetSubCurve(unsigned int *rGmOt, - unsigned int *rGmIn, unsigned int pwdth) -{ - int nT0 = 0; - unsigned int BASE = 64; - - unsigned int plft = 0; - unsigned int prto = 0; - unsigned int rst = 0; - - unsigned int idx1 = 0; - unsigned int idx2 = 0; - - if (pwdth == 0) - pwdth = 1; - - for (nT0 = 0; nT0 <= pwdth; nT0++) { - plft = nT0*64/pwdth; - prto = (BASE*(nT0*BASE-plft*pwdth) + pwdth/2)/pwdth; - - idx1 = plft; - idx2 = plft+1; - if (idx1 > 64) - idx1 = 64; - if (idx2 > 64) - idx2 = 64; - - rst = rGmIn[idx1]*(BASE-prto) + rGmIn[idx2]*prto; - rst = (rst + BASE/2)*4*pwdth/BASE; - /* rst = ((rst + 128)>>8); */ - rst = ((rst + 32)>>6); - - if (nT0 == 0) - rst = rGmIn[0]; - if (rst > (pwdth << 4)) - rst = (pwdth << 4); - - rGmOt[nT0] = rst; - } -} - -/*rGmOt[0:64]*/ -/*rGmIn[0:64]*/ -/* 0~1024 */ -void GetGmBlkCvs(unsigned int *rGmOt, unsigned int *rGmIn, - unsigned int Bgn, unsigned int End) -{ - static unsigned int pgmma0[65]; - int nT0 = 0; - int pwdth = End - Bgn; /* 64 */ - int pLst[65]; - int i = 0; - int nTmp0 = 0; - - if (!ve_dnlp_luma_sum) { - for (nT0 = 0; nT0 < 65; nT0++) - pgmma0[nT0] = (nT0 << 4); /* 0 ~1024 */ - } - - GetSubCurve(pLst, rGmIn, pwdth); /*0~1024*/ - - for (nT0 = 0; nT0 < 65; nT0++) { - if (nT0 < Bgn) - rGmOt[nT0] = (nT0 << 4); - else if (nT0 >= End) - rGmOt[nT0] = (nT0 << 4); - else { - if (ve_dnlp_pst_gmarat > 64) - rGmOt[nT0] = (Bgn << 4) + - (1024 - pLst[64 + Bgn - nT0]); - else - rGmOt[nT0] = (Bgn << 4) + pLst[nT0 - Bgn]; - } - } - - if (!dnlp_scn_chg) - for (i = 0; i < 65; i++) { - nTmp0 = dnlp_bld_lvl * rGmOt[i] + (RBASE >> 1); - nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma0[i]; - nTmp0 = (nTmp0 >> ve_dnlp_mvreflsh); /* 0 ~1024 */ - - rGmOt[i] = nTmp0; - } - - for (i = 0; i < 65; i++) - pgmma0[i] = rGmOt[i]; -} - - -/*rGmOt[0:64]*/ -/*rGmIn[0:64]*/ -/* 0 ~1024 */ -void GetGmCurves2(unsigned int *rGmOt, unsigned int *rGmIn, - unsigned int pval, unsigned int BgnBnd, unsigned int EndBnd) -{ - int nT0 = 0; - /*unsigned int rst=0;*/ - int pwdth = 0; - unsigned int pLst[65]; - int nT1 = 0; - bool prt_flg = ((dnlp_printk >> 11) & 0x1); - - if (pval >= ve_dnlp_almst_wht) { - for (nT0 = 0; nT0 < 65; nT0++) - rGmOt[nT0] = rGmIn[nT0] << 2; - return; - } - - if (BgnBnd > 10) - BgnBnd = 10; - if (EndBnd > 10) - EndBnd = 10; - - if (pval < ve_dnlp_slow_end) - pval = ve_dnlp_slow_end; - - if (pval <= BgnBnd) - pval = BgnBnd + 1; - - /* fuck here */ - if (pval + EndBnd > 64) - pval = 63 - EndBnd; - - for (nT0 = 0; nT0 < 65; nT0++) - rGmOt[nT0] = (nT0<<4); /* 0~1024 */ - - if (pval > BgnBnd) { - pwdth = pval - BgnBnd; - GetSubCurve(pLst, rGmIn, pwdth); /* 0~1024 */ - for (nT0 = BgnBnd; nT0 <= pval; nT0++) { - nT1 = pLst[nT0 - BgnBnd] + (BgnBnd<<4); - rGmOt[nT0] = nT1; - } - } - - if ((pval + EndBnd) < 64) { - pwdth = 64 - pval - EndBnd; - GetSubCurve(pLst, rGmIn, pwdth); - for (nT0 = pval; nT0 <= 64 - EndBnd; nT0++) { - nT1 = (1024 - (EndBnd<<4) - - pLst[pwdth - (nT0 - pval)]); - rGmOt[nT0] = nT1; /* 0~1024 */ - } - } - - if (prt_flg) { - pr_info("#GmCvs2: %d %d %d\n", BgnBnd, pval, EndBnd); - for (nT1 = 0; nT1 < 65; nT1++) - pr_info("[%02d] => %4d\n", nT1, rGmOt[nT1]); - pr_info("\n"); - } -} - -void GetGmCurves(unsigned int *rGmOt, unsigned int *rGmIn, - unsigned int lsft_avg, unsigned int BgnBnd, unsigned int EndBnd) -{ - int pval1 = (lsft_avg >> (2 + ve_dnlp_pavg_btsft)); - int pval2 = pval1 + 1; - int BASE = (1 << (2 + ve_dnlp_pavg_btsft)); - int nRzn = lsft_avg - (pval1 << (2 + ve_dnlp_pavg_btsft)); - unsigned int pLst1[65]; - unsigned int pLst2[65]; - int i = 0; - - if (pval2 > ve_dnlp_almst_wht) - pval2 = ve_dnlp_almst_wht; - - GetGmCurves2(pLst1, rGmIn, pval1, BgnBnd, EndBnd); - GetGmCurves2(pLst2, rGmIn, pval2, BgnBnd, EndBnd); - - for (i = 0; i < 65; i++) { - pval2 = pLst1[i] * (BASE - nRzn) + pLst2[i] * nRzn; - - pval2 = (pval2 + (BASE >> 1)); - pval2 = (pval2 >> (2 + ve_dnlp_pavg_btsft)); - - if (pval2 < 0) - pval2 = 0; - else if (pval2 > 1023) - pval2 = 1023; - rGmOt[i] = pval2; - } -} - -unsigned int cal_hist_avg(unsigned int pval) -{ - static unsigned int ppval; - - if (!dnlp_scn_chg) { - pval = dnlp_bld_lvl * pval + (RBASE >> 1); - pval = pval + (RBASE - dnlp_bld_lvl) * ppval; - pval = (pval >> ve_dnlp_mvreflsh); - } - ppval = pval; - - return pval; -} - -/* history */ -unsigned int cal_hst_shft_avg(unsigned int pval) -{ - static unsigned int ppval; - - if (!dnlp_scn_chg) { - pval = dnlp_bld_lvl * pval + (RBASE >> 1); - pval = pval + (RBASE - dnlp_bld_lvl) * ppval; - pval = (pval >> ve_dnlp_mvreflsh); - } - ppval = pval; - - return pval; -} - -/* mtdrate: mtdrate in the mid-tone*/ -/* luma_avg: 0~64 */ -static int dnlp_adp_mtdrate(int mtdrate, int luma_avg) -{ - int np = 0; - int nt = mtdrate; - - if (ve_dnlp_adpmtd_lbnd > 0 && - luma_avg < ve_dnlp_adpmtd_lbnd) { - nt = mtdrate * luma_avg + (ve_dnlp_adpmtd_lbnd >> 1); - nt /= ve_dnlp_adpmtd_lbnd; - - np = 4 * (ve_dnlp_adpmtd_lbnd - luma_avg); - if (np < mtdrate) - np = mtdrate - np; - else - np = 0; - - if (np > nt) - nt = np; - } else if (ve_dnlp_adpmtd_hbnd > 0 && - (luma_avg > 64 - ve_dnlp_adpmtd_hbnd)) { - nt = mtdrate * (64 - luma_avg); - nt += (ve_dnlp_adpmtd_hbnd >> 1); - nt /= ve_dnlp_adpmtd_hbnd; - - np = luma_avg - (64 - ve_dnlp_adpmtd_hbnd); - np = 4 * np; - if (np < mtdrate) - np = mtdrate - np; - else - np = 0; - - if (np > nt) - nt = np; - } - - return nt; -} - -unsigned int AdjHistAvg(unsigned int pval, unsigned int ihstEnd) -{ - unsigned int pEXT = 224; - unsigned int pMid = 128; - unsigned int pMAX = 236; - - if (ihstEnd > 59) - pMAX = ihstEnd << 2; - - if (pval > pMid) { - pval = pMid + (pMAX - pMid)*(pval - pMid)/(pEXT - pMid); - if (pval > pMAX) - pval = pMAX; - } - - return pval; -} - -int blk_wht_extsn(int *blk_wht_ext, unsigned int *iHst, - int hstSum, unsigned int luma_avg) -{ - int tAvg = ((hstSum + 32) >> 6); - int nStp = 0; - int nT0 = 0; - int nT1 = 0; - int i = 0; - int dnlp_wextmx = ve_dnlp_wextmx; - - /* black / white extension */ - static int pblk_wht_ext[2]; - - /* black extension */ - nStp = tAvg * ve_dnlp_blkext + 32; - nStp = (nStp >> 6); - blk_wht_ext[0] = 0; - nT0 = 0; - for (i = 0; i < (iRgnBgn + ve_dnlp_bextmx); i++) { - nT0 += iHst[i]; - if (nT0 > nStp) - break; - else if (i >= iRgnBgn) - blk_wht_ext[0] = ((i + 1 - iRgnBgn) << 4); - } - - /* white extension */ - nStp = tAvg * ve_dnlp_whtext + 32; - nStp = (nStp >> 6); - - if (ve_dnlp_wext_autorat > 0) - dnlp_wextmx = iRgnEnd - 1; - else - dnlp_wextmx = ve_dnlp_wextmx; - - nT0 = 0; - nT1 = 0; - for (i = 0; i < dnlp_wextmx; i++) { - nT0 += iHst[iRgnEnd - 1 - i]; - if (nT0 > nStp) - break; - else if (i >= (64 - iRgnEnd)) - nT1 = (i + iRgnEnd - 63); - } - - if (ve_dnlp_wext_autorat > 0) { - if (luma_avg > 32) /* baby face */ - nT1 = 0; - else { - nT1 = (32 - luma_avg) * nT1 * ve_dnlp_wext_autorat; - nT1 = ((nT1 + 512) >> 10); - if (nT1 > ve_dnlp_wextmx) - nT1 = ve_dnlp_wextmx; - } - } - blk_wht_ext[1] = (nT1 << 4); - - if (!dnlp_scn_chg) { - nT0 = dnlp_bld_lvl * blk_wht_ext[0] + (RBASE >> 1); - nT0 = nT0 + (RBASE - dnlp_bld_lvl) * pblk_wht_ext[0]; - blk_wht_ext[0] = (nT0 >> ve_dnlp_mvreflsh); - - nT1 = dnlp_bld_lvl * blk_wht_ext[1] + (RBASE >> 1); - nT1 = nT1 + (RBASE - dnlp_bld_lvl) * pblk_wht_ext[1]; - blk_wht_ext[1] = (nT1 >> ve_dnlp_mvreflsh); - } - - pblk_wht_ext[0] = blk_wht_ext[0]; - pblk_wht_ext[1] = blk_wht_ext[1]; - - return 0; -} - -static unsigned int dnlp_adp_cliprate(unsigned int clip_rate, - unsigned int clip_rmin, unsigned int luma_avg) -{ - unsigned int nt = clip_rate; - - if (luma_avg < ve_dnlp_adpcrat_lbnd) { - nt = clip_rate * (ve_dnlp_adpcrat_lbnd - luma_avg) + - luma_avg * clip_rmin; - - nt = (nt << 4) + (ve_dnlp_adpcrat_lbnd >> 1); - nt /= ve_dnlp_adpcrat_lbnd; - } else if (luma_avg > 64 - ve_dnlp_adpcrat_hbnd) { - nt = clip_rmin * (64 - luma_avg) + - clip_rate * (luma_avg + ve_dnlp_adpcrat_hbnd - 64); - nt += (nt << 4) + (ve_dnlp_adpcrat_hbnd >> 1); - nt /= ve_dnlp_adpcrat_hbnd; - } else - nt = (clip_rmin << 4); - - return nt; -} - -int old_dnlp_lrate[32]; - -/*iHst[0:63]: [0,4)->iHst[0], [252,256)->iHst[63]*/ -/*oMap[0:64]:0:16:1024*/ -void clash_fun(unsigned int *oMap, unsigned int *iHst, - unsigned int hstBgn, unsigned int hstEnd) -{ - unsigned int i = 0, j = 0; - unsigned int tmax = 0; - unsigned int tsum = 0; - unsigned int oHst[64]; - unsigned int cLmt = 0; - unsigned int tLen = (hstEnd - hstBgn); - unsigned int tAvg = 0; - unsigned int lAvg4 = 0; - unsigned int lAvg1 = 0; - unsigned int nStp = 0; - /*unsigned int uLmt = 0;*/ - /*unsigned int stp = 0;*/ - unsigned int idx[64]; - unsigned int tHst[64]; - unsigned int nT0 = 0; - unsigned int clip_rate = ve_dnlp_cliprate_new; - unsigned int clip_rmin = ve_dnlp_cliprate_min; - unsigned int adp_crate = clip_rate; - - int nNum = 0; - int nExc = 0; - int tExc = 0; - bool prt_flg = 0; - - /* local limit 64-bin*/ - unsigned int lcl_lmt[64]; - - if (clip_rmin > clip_rate) - clip_rmin = clip_rate; - if (ve_dnlp_adpcrat_lbnd < 2) - ve_dnlp_adpcrat_lbnd = 2; - else if (ve_dnlp_adpcrat_lbnd > 30) - ve_dnlp_adpcrat_lbnd = 30; - - if (ve_dnlp_adpcrat_hbnd < 2) - ve_dnlp_adpcrat_hbnd = 2; - else if (ve_dnlp_adpcrat_hbnd > 30) - ve_dnlp_adpcrat_hbnd = 30; - - if (hstBgn > 16) - hstBgn = 16; - - if (hstEnd > 64) - hstEnd = 64; - else if (hstEnd < 48) - hstEnd = 48; - - oMap[64] = 1024; /* 0~1024 */ - /*64 bins, max, ave*/ - lAvg4 = 0; - lAvg1 = 0; - for (i = 0; i < 64; i++) { - oHst[i] = iHst[i]; - oMap[i] = (i << 4); /* 0~1024 */ - - tHst[i] = iHst[i]; - idx[i] = i; - - if (i >= hstBgn && i <= hstEnd-1) { - if (tmax < iHst[i]) - tmax = iHst[i]; - tsum += iHst[i]; - lAvg4 += (iHst[i] * i); - } else { - oHst[i] = 0; - } - - lcl_lmt[i] = old_dnlp_lrate[(i>>1)]; - } - lAvg4 = (lAvg4 << 2) + tsum / 2; - lAvg4 = lAvg4 / tsum; - lAvg1 = (lAvg4 + 2) >> 2; - - /* << 4 */ - adp_crate = dnlp_adp_cliprate(clip_rate, clip_rmin, lAvg1); - - prt_flg = ((dnlp_printk >> 9) & 0x1); - if (prt_flg) - pr_info("#CL: Range[%02d ~ %02d] lAvg4=%d(%d), (crate << 4)=%d\n", - hstBgn, hstEnd, lAvg4, lAvg1, adp_crate); - - for (i = 1; i <= 61; i += 2) - lcl_lmt[i] = ((lcl_lmt[i-1] + lcl_lmt[i+1] + 1)>>1); - - if (hstEnd <= hstBgn) - return; - - cLmt = (adp_crate * tsum) >> 2; - cLmt = (cLmt + 2048) >> 12; - - tAvg = (tsum + tLen/2)/tLen; - - /* sort histogram */ - for (i = hstBgn; i < hstEnd; i++) { - for (j = hstBgn; j < (hstEnd - i - 1); j++) { - if (tHst[j] < tHst[j+1]) { - nExc = tHst[j]; - tHst[j] = tHst[j+1]; - tHst[j+1] = nExc; - - nNum = idx[j]; - idx[j] = idx[j+1]; - idx[j+1] = nNum; - } - } - } - - /* local clip rate */ - if (ve_dnlp_glb_crate == 0) { - for (i = 0; i < 64; i++) - lcl_lmt[i] = ((lcl_lmt[i]*cLmt+32) >> 6); - } else { - for (i = 0; i < 64; i++) - lcl_lmt[i] = cLmt; - } - /* the largest bins should be improved */ - nStp = tAvg * ve_dnlp_hghbin + 32; - nStp = (nStp >> 6); - for (j = 0; j < ve_dnlp_hghnum; j++) { - i = idx[j]; - - if (lcl_lmt[i] < nStp) - lcl_lmt[i] = nStp; - } - - /* the lowest bins */ - nStp = tAvg * ve_dnlp_lowbin + 32; - nStp = (nStp >> 6); - for (j = 0; j < ve_dnlp_lownum; j++) { - i = idx[tLen - 1 - j]; - - /* max */ - nT0 = (nStp > tHst[i]) ? nStp : tHst[i]; - - if (lcl_lmt[i] > nT0) - lcl_lmt[i] = nT0; - } - - /* black protect */ - nStp = tAvg * ve_blk_prct_max + 4; - nStp = (nStp >> 3); - for (i = 0; i < ve_blk_prct_rng; i++) { - nT0 = (ve_blk_prct_rng - i); - if (iHst[i] > nStp) - nT0 = nT0 * (iHst[i] - nStp); - else - nT0 = 0; - - if (lcl_lmt[i] > (nT0 + tAvg)) - nT0 = lcl_lmt[i] - nT0; - else - nT0 = tAvg; - - if (nT0 < tAvg) - nT0 = tAvg; - - if (prt_flg) - pr_info("clmt[%d]: %4d -> %4d\n", - i, lcl_lmt[i], nT0); - } /* black protect */ - - nExc = 0; - nNum = 0; - for (i = hstBgn; i < hstEnd; i++) { - if (iHst[i] > lcl_lmt[i]) { - nExc += (iHst[i] - lcl_lmt[i]); - oHst[i] = lcl_lmt[i]; - } else { - nNum++; - oHst[i] = iHst[i]; - } - } - - if (clip_rate <= 8 || tAvg <= 2) { - cLmt = (tsum + tLen/2)/tLen; - tsum = cLmt*tLen; - for (i = hstBgn; i < hstEnd; i++) - oHst[i] = cLmt; - - } else { - while ((nNum > 0) && (nExc > 0)) { - nStp = (nExc+nNum/2)/nNum; - - tExc = nExc; - - for (j = 0; j < 64; j++) { - i = idx[j]; - if ((i < hstBgn) || (i > hstEnd-1)) - continue; - - if ((oHst[i] + nStp) < lcl_lmt[i]) { - oHst[i] = oHst[i] + nStp; - nExc = nExc - nStp; - } else if (lcl_lmt[i] > oHst[i]) { - oHst[i] = lcl_lmt[i]; - nExc = nExc - (lcl_lmt[i] - oHst[i]); - nNum = nNum - 1; - } - - if ((nNum <= 0) || (nExc <= 0)) - break; - } - - if (nExc == tExc) - break; - } /* end while */ - - if (nNum == 0 && tExc > 0 && nExc > tLen) { - nStp = (nExc + tLen/2)/tLen; - for (i = hstBgn; i < hstEnd; i++) - oHst[i] = oHst[i] + nStp; - } - } - - /*hstBgn:hstEnd-1*/ - tsum = 0; - for (i = hstBgn; i < hstEnd; i++) { - /*if(oHst[i]>cLmt)*/ - /*oHst[i] = cLmt;*/ - tsum += oHst[i]; - } - - nStp = 0; - /*sum -= oHst[4];*/ - for (i = hstBgn; i < hstEnd; i++) { - nStp += oHst[i]; - - j = ((hstEnd - hstBgn)*nStp << 4); - j += (tsum>>1); - j /= tsum; - oMap[i+1] = j + (hstBgn << 4); - } - - if (debug_add_curve_en) { - for (i = 0; i < 65; i++) { - oMap[i] = ((128 - glb_clash_curve_bld_rate) * oMap[i] + - glb_clash_curve_bld_rate * (glb_clash_curve[i] << 2) + - 64) >> 7; - } - } - - - if (prt_flg) - for (i = hstBgn; i < hstEnd; i++) - pr_info("#CL: [%02d: %5d]: %4d => %4d]\n", - i, iHst[i], i << 4, oMap[i]); -} - -/*xhu*/ -int old_dnlp_mvreflsh; -int old_dnlp_gmma_rate; -int old_dnlp_lowalpha_new; -int old_dnlp_hghalpha_new; -int old_dnlp_sbgnbnd; -int old_dnlp_sendbnd; -int old_dnlp_cliprate_new; -int old_dnlp_clashBgn; -int old_dnlp_clashEnd; -int old_mtdbld_rate; -int old_dnlp_pst_gmarat; -int old_dnlp_blk_cctr; -int old_dnlp_brgt_ctrl; -int old_dnlp_brgt_range; -int old_dnlp_brght_add; -int old_dnlp_brght_max; -int old_dnlp_lgst_bin; -int old_dnlp_lgst_dst; -int old_dnlp_almst_wht; -int old_dnlp_hghbin; -int old_dnlp_hghnum; -int old_dnlp_lowbin; -int old_dnlp_lownum; -int old_dnlp_bkgend; -int old_dnlp_bkgert; -int old_dnlp_pstgma_brghtrate; -int old_dnlp_pstgma_brghtrat1; -int old_dnlp_blkext; -int old_dnlp_whtext; -int old_dnlp_bextmx; -int old_dnlp_wextmx; -int old_dnlp_wext_autorat; -int old_dnlp_lavg_cum; -int old_dnlp_schg_sft; -bool old_dnlp_smhist_ck; -bool old_dnlp_glb_crate; -int old_dnlp_cuvbld_min; -int old_dnlp_cuvbld_max; -int old_dnlp_dbg_map; -bool old_dnlp_dbg_adjavg; -int old_dnlp_dbg_i2r; -int old_dnlp_slow_end; -int old_dnlp_pavg_btsft; -int old_dnlp_dbg0331; -int old_dnlp_cliprate_min; -int old_dnlp_adpcrat_lbnd; -int old_dnlp_adpcrat_hbnd; -int old_dnlp_adpmtd_lbnd; -int old_dnlp_adpmtd_hbnd; -int old_dnlp_set_bext; -int old_dnlp_set_wext; - -int old_dnlp_satur_rat; -int old_dnlp_satur_max; -int old_blk_prct_rng; -int old_blk_prct_max; - -int old_dnlp_lowrange; -int old_dnlp_hghrange; -int old_dnlp_auto_rng; - -int old_dnlp_bin0_absmax; -int old_dnlp_bin0_sbtmax; - -int old_dnlp_adpalpha_lrate; -int old_dnlp_adpalpha_hrate; - -static int cal_brght_plus(int luma_avg4, int low_lavg4) -{ - int avg_dif = 0; - int dif_rat = 0; - - int low_rng = 0; - int low_rat = 0; - - int dnlp_brightness = 0; - static int pbrtness; - - if (luma_avg4 > low_lavg4) - avg_dif = luma_avg4 - low_lavg4; - - if (avg_dif < ve_dnlp_blk_cctr) - dif_rat = ve_dnlp_blk_cctr - avg_dif; - - if (luma_avg4 > ve_dnlp_brgt_ctrl) - low_rng = luma_avg4 - ve_dnlp_brgt_ctrl; - else - low_rng = ve_dnlp_brgt_ctrl - luma_avg4; - - if (low_rng < ve_dnlp_brgt_range) - low_rat = ve_dnlp_brgt_range - low_rng; - - /* <<2 */ - dnlp_brightness = (ve_dnlp_brght_max*dif_rat*low_rat + 16)>>5; - /* add=32 => add 0 */ - dnlp_brightness += ((ve_dnlp_brght_add - 32) << 2); - - if (!dnlp_scn_chg) { - dnlp_brightness = dnlp_bld_lvl * dnlp_brightness + (RBASE >> 1); - dnlp_brightness = dnlp_brightness + - (RBASE - dnlp_bld_lvl) * pbrtness; - dnlp_brightness = (dnlp_brightness >> ve_dnlp_mvreflsh); - } - pbrtness = dnlp_brightness; - - return dnlp_brightness; /* 0 ~ 1024 */ -} - -int gma_scurve0[65]; /* gamma0 s-curve */ -int gma_scurve1[65]; /* gamma1 s-curve */ -int gma_scurvet[65]; /* gmma0+gamm1 s-curve */ -int clash_curve[65]; /* clash curve */ -int clsh_scvbld[65]; /* clash + s-curve blend */ - -int blk_gma_crv[65]; /* black gamma curve */ -int blk_gma_bld[65]; /* blending with black gamma */ - -int blkwht_ebld[65]; /* black white extension */ - -/*xhu*/ -/* only for debug */ -static unsigned int premap0[64]; - -static int pcurves[8][64]; - -static void clash_blend(void) -{ - int i = 0; - int nTmp0 = 0; - static unsigned int pgmma[65]; - - if (!ve_dnlp_luma_sum) { - for (i = 0; i < 65; i++) - pgmma[i] = (i << 4); /* 0 ~1024 */ - } - - if (!dnlp_scn_chg && ((ve_dnlp_dbg_i2r >> 3) & 0x1)) - for (i = 0; i < 65; i++) { - nTmp0 = dnlp_bld_lvl * clash_curve[i] + (RBASE >> 1); - nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma[i]; - nTmp0 = (nTmp0 >> ve_dnlp_mvreflsh); - clash_curve[i] = nTmp0; - } - - for (i = 0; i < 65; i++) - pgmma[i] = clash_curve[i]; -} - -int curve_rfrsh_chk(int hstSum, int rbase) -{ - static unsigned int tLumAvg[30]; - static unsigned int tAvgDif[30]; - bool prt_flg = 0; - int lSby = 0; - int bld_lvl = 0; - int i = 0; - - for (i = 0; i < 29; i++) { - tLumAvg[i] = tLumAvg[i+1]; - tAvgDif[i] = tAvgDif[i+1]; - } - - tLumAvg[29] = (ve_dnlp_luma_sum + (hstSum >> 1)) / hstSum; - tLumAvg[29] = ((tLumAvg[29] + 4) >> 3); - tAvgDif[29] = (tLumAvg[29] > tLumAvg[28]) ? - (tLumAvg[29] - tLumAvg[28]) : (tLumAvg[28] - tLumAvg[29]); - - /* prt_flg = ((dnlp_printk >> 7) & 0x1); */ - prt_flg = (dnlp_printk & 0x1); - - lSby = 0; - for (i = 0; i < 8; i++) - lSby = lSby + tAvgDif[28 - i]; - lSby = ((lSby + 4) >> 3); - - if (tAvgDif[29] > tAvgDif[28]) - bld_lvl = tAvgDif[29] - tAvgDif[28]; - else - bld_lvl = tAvgDif[28] - tAvgDif[29]; - - bld_lvl = (bld_lvl << ve_dnlp_schg_sft); - - if (prt_flg) - pr_info("bld_lvl=%02d\n", bld_lvl); - - /* play station: return with black scene intersection */ - if (tAvgDif[29] > bld_lvl) - bld_lvl = tAvgDif[29]; - - if (bld_lvl > rbase) - bld_lvl = rbase; - else if (bld_lvl < ve_dnlp_cuvbld_min) - bld_lvl = ve_dnlp_cuvbld_min; - else if (bld_lvl > ve_dnlp_cuvbld_max) - bld_lvl = ve_dnlp_cuvbld_max; - - if (prt_flg) { - pr_info("bld_lvl=%02d, lSby=%02d\n", - bld_lvl, lSby); - - for (i = 0; i < 10; i++) - pr_info("tLumAvg[%d]: = %d\n", - i, tLumAvg[29 - i]); - - for (i = 0; i < 10; i++) - pr_info("tAvgDif[%d]: = %d\n", - i, tAvgDif[29 - i]); - } - return bld_lvl; -} - -static void dnlp3_param_refrsh(void) -{ - if (dnlp_respond) { - if ((old_dnlp_mvreflsh != ve_dnlp_mvreflsh) || - (old_dnlp_gmma_rate != ve_dnlp_gmma_rate) || - (old_dnlp_lowalpha_new != ve_dnlp_lowalpha_new) || - (old_dnlp_hghalpha_new != ve_dnlp_hghalpha_new) || - (old_dnlp_sbgnbnd != ve_dnlp_sbgnbnd) || - (old_dnlp_sendbnd != ve_dnlp_sendbnd) || - (old_dnlp_cliprate_new != ve_dnlp_cliprate_new) || - (old_dnlp_clashBgn != ve_dnlp_clashBgn) || - (old_dnlp_clashEnd != ve_dnlp_clashEnd) || - (old_mtdbld_rate != ve_mtdbld_rate) || - (old_dnlp_pst_gmarat != ve_dnlp_pst_gmarat) || - (old_dnlp_blk_cctr != ve_dnlp_blk_cctr) || - (old_dnlp_brgt_ctrl != ve_dnlp_brgt_ctrl) || - (old_dnlp_brgt_range != ve_dnlp_brgt_range) || - (old_dnlp_brght_add != ve_dnlp_brght_add) || - (old_dnlp_brght_max != ve_dnlp_brght_max) || - (old_dnlp_lgst_bin != ve_dnlp_lgst_bin) || - (old_dnlp_lgst_dst != ve_dnlp_lgst_dst) || - (old_dnlp_almst_wht != ve_dnlp_almst_wht) || - (old_dnlp_glb_crate != ve_dnlp_glb_crate) || - (old_dnlp_lrate[0] != ve_dnlp_lrate00) || - (old_dnlp_lrate[1] != ve_dnlp_lrate02) || - (old_dnlp_lrate[2] != ve_dnlp_lrate04) || - (old_dnlp_lrate[3] != ve_dnlp_lrate06) || - (old_dnlp_lrate[4] != ve_dnlp_lrate08) || - (old_dnlp_lrate[5] != ve_dnlp_lrate10) || - (old_dnlp_lrate[6] != ve_dnlp_lrate12) || - (old_dnlp_lrate[7] != ve_dnlp_lrate14) || - (old_dnlp_lrate[8] != ve_dnlp_lrate16) || - (old_dnlp_lrate[9] != ve_dnlp_lrate18) || - (old_dnlp_lrate[10] != ve_dnlp_lrate20) || - (old_dnlp_lrate[11] != ve_dnlp_lrate22) || - (old_dnlp_lrate[12] != ve_dnlp_lrate24) || - (old_dnlp_lrate[13] != ve_dnlp_lrate26) || - (old_dnlp_lrate[14] != ve_dnlp_lrate28) || - (old_dnlp_lrate[15] != ve_dnlp_lrate30) || - (old_dnlp_lrate[16] != ve_dnlp_lrate32) || - (old_dnlp_lrate[17] != ve_dnlp_lrate34) || - (old_dnlp_lrate[18] != ve_dnlp_lrate36) || - (old_dnlp_lrate[19] != ve_dnlp_lrate38) || - (old_dnlp_lrate[20] != ve_dnlp_lrate40) || - (old_dnlp_lrate[21] != ve_dnlp_lrate42) || - (old_dnlp_lrate[22] != ve_dnlp_lrate44) || - (old_dnlp_lrate[23] != ve_dnlp_lrate46) || - (old_dnlp_lrate[24] != ve_dnlp_lrate48) || - (old_dnlp_lrate[25] != ve_dnlp_lrate50) || - (old_dnlp_lrate[26] != ve_dnlp_lrate52) || - (old_dnlp_lrate[27] != ve_dnlp_lrate54) || - (old_dnlp_lrate[28] != ve_dnlp_lrate56) || - (old_dnlp_lrate[29] != ve_dnlp_lrate58) || - (old_dnlp_lrate[30] != ve_dnlp_lrate60) || - (old_dnlp_lrate[31] != ve_dnlp_lrate62) || - (old_dnlp_hghbin != ve_dnlp_hghbin) || - (old_dnlp_hghnum != ve_dnlp_hghnum) || - (old_dnlp_lowbin != ve_dnlp_lowbin) || - (old_dnlp_lownum != ve_dnlp_lownum) || - (old_dnlp_bkgend != ve_dnlp_bkgend) || - (old_dnlp_bkgert != ve_dnlp_bkgert) || - (old_dnlp_pstgma_brghtrate != - ve_dnlp_pstgma_brghtrate) || - (old_dnlp_pstgma_brghtrat1 != - ve_dnlp_pstgma_brghtrat1) || - (old_dnlp_blkext != ve_dnlp_blkext) || - (old_dnlp_whtext != ve_dnlp_whtext) || - (old_dnlp_bextmx != ve_dnlp_bextmx) || - (old_dnlp_wextmx != ve_dnlp_wextmx) || - (old_dnlp_wext_autorat != ve_dnlp_wext_autorat) || - (old_dnlp_schg_sft != ve_dnlp_schg_sft) || - (old_dnlp_smhist_ck != ve_dnlp_smhist_ck) || - (old_dnlp_cuvbld_min != ve_dnlp_cuvbld_min) || - (old_dnlp_cuvbld_max != ve_dnlp_cuvbld_max) || - (old_dnlp_dbg_map != ve_dnlp_dbg_map) || - (old_dnlp_dbg_adjavg != ve_dnlp_dbg_adjavg) || - (old_dnlp_dbg_i2r != ve_dnlp_dbg_i2r) || - (old_dnlp_slow_end != ve_dnlp_slow_end) || - (old_dnlp_pavg_btsft != ve_dnlp_pavg_btsft) || - (old_dnlp_cliprate_min != ve_dnlp_cliprate_min) || - (old_dnlp_adpcrat_lbnd != ve_dnlp_adpcrat_lbnd) || - (old_dnlp_adpcrat_hbnd != ve_dnlp_adpcrat_hbnd) || - (old_dnlp_adpmtd_lbnd != ve_dnlp_adpmtd_lbnd) || - (old_dnlp_adpmtd_hbnd != ve_dnlp_adpmtd_hbnd) || - (old_dnlp_set_bext != ve_dnlp_set_bext) || - (old_dnlp_set_wext != ve_dnlp_set_wext) || - (old_dnlp_satur_rat != ve_dnlp_satur_rat) || - (old_dnlp_satur_max != ve_dnlp_satur_max) || - (old_blk_prct_rng != ve_blk_prct_rng) || - (old_blk_prct_max != ve_blk_prct_max) || - (old_dnlp_lowrange != ve_dnlp_lowrange) || - (old_dnlp_hghrange != ve_dnlp_hghrange) || - (old_dnlp_auto_rng != ve_dnlp_auto_rng) || - (old_dnlp_bin0_absmax != ve_dnlp_bin0_absmax) || - (old_dnlp_bin0_sbtmax != ve_dnlp_bin0_sbtmax) || - (old_dnlp_adpalpha_lrate != ve_dnlp_adpalpha_lrate) || - (old_dnlp_adpalpha_hrate != ve_dnlp_adpalpha_hrate)) - ve_dnlp_respond_flag = 1; - else - ve_dnlp_respond_flag = 0; - } - - old_dnlp_mvreflsh = ve_dnlp_mvreflsh; - old_dnlp_gmma_rate = ve_dnlp_gmma_rate; - old_dnlp_lowalpha_new = ve_dnlp_lowalpha_new; - old_dnlp_hghalpha_new = ve_dnlp_hghalpha_new; - old_dnlp_sbgnbnd = ve_dnlp_sbgnbnd; - old_dnlp_sendbnd = ve_dnlp_sendbnd; - old_dnlp_cliprate_new = ve_dnlp_cliprate_new; - old_dnlp_clashBgn = ve_dnlp_clashBgn; - old_dnlp_clashEnd = ve_dnlp_clashEnd; - old_mtdbld_rate = ve_mtdbld_rate; - old_dnlp_pst_gmarat = ve_dnlp_pst_gmarat; - old_dnlp_blk_cctr = ve_dnlp_blk_cctr; - old_dnlp_brgt_ctrl = ve_dnlp_brgt_ctrl; - old_dnlp_brgt_range = ve_dnlp_brgt_range; - old_dnlp_brght_add = ve_dnlp_brght_add; - old_dnlp_brght_max = ve_dnlp_brght_max; - old_dnlp_lgst_bin = ve_dnlp_lgst_bin; - old_dnlp_lgst_dst = ve_dnlp_lgst_dst; - old_dnlp_almst_wht = ve_dnlp_almst_wht; - old_dnlp_glb_crate = ve_dnlp_glb_crate; - old_dnlp_lrate[0] = ve_dnlp_lrate00; - old_dnlp_lrate[1] = ve_dnlp_lrate02; - old_dnlp_lrate[2] = ve_dnlp_lrate04; - old_dnlp_lrate[3] = ve_dnlp_lrate06; - old_dnlp_lrate[4] = ve_dnlp_lrate08; - old_dnlp_lrate[5] = ve_dnlp_lrate10; - old_dnlp_lrate[6] = ve_dnlp_lrate12; - old_dnlp_lrate[7] = ve_dnlp_lrate14; - old_dnlp_lrate[8] = ve_dnlp_lrate16; - old_dnlp_lrate[9] = ve_dnlp_lrate18; - old_dnlp_lrate[10] = ve_dnlp_lrate20; - old_dnlp_lrate[11] = ve_dnlp_lrate22; - old_dnlp_lrate[12] = ve_dnlp_lrate24; - old_dnlp_lrate[13] = ve_dnlp_lrate26; - old_dnlp_lrate[14] = ve_dnlp_lrate28; - old_dnlp_lrate[15] = ve_dnlp_lrate30; - old_dnlp_lrate[16] = ve_dnlp_lrate32; - old_dnlp_lrate[17] = ve_dnlp_lrate34; - old_dnlp_lrate[18] = ve_dnlp_lrate36; - old_dnlp_lrate[19] = ve_dnlp_lrate38; - old_dnlp_lrate[20] = ve_dnlp_lrate40; - old_dnlp_lrate[21] = ve_dnlp_lrate42; - old_dnlp_lrate[22] = ve_dnlp_lrate44; - old_dnlp_lrate[23] = ve_dnlp_lrate46; - old_dnlp_lrate[24] = ve_dnlp_lrate48; - old_dnlp_lrate[25] = ve_dnlp_lrate50; - old_dnlp_lrate[26] = ve_dnlp_lrate52; - old_dnlp_lrate[27] = ve_dnlp_lrate54; - old_dnlp_lrate[28] = ve_dnlp_lrate56; - old_dnlp_lrate[29] = ve_dnlp_lrate58; - old_dnlp_lrate[30] = ve_dnlp_lrate60; - old_dnlp_lrate[31] = ve_dnlp_lrate62; - old_dnlp_hghbin = ve_dnlp_hghbin; - old_dnlp_hghnum = ve_dnlp_hghnum; - old_dnlp_lowbin = ve_dnlp_lowbin; - old_dnlp_lownum = ve_dnlp_lownum; - - old_dnlp_bkgend = ve_dnlp_bkgend; - old_dnlp_bkgert = ve_dnlp_bkgert; - old_dnlp_pstgma_brghtrate = ve_dnlp_pstgma_brghtrate; - old_dnlp_pstgma_brghtrat1 = ve_dnlp_pstgma_brghtrat1; - - old_dnlp_blkext = ve_dnlp_blkext; - old_dnlp_whtext = ve_dnlp_whtext; - old_dnlp_bextmx = ve_dnlp_bextmx; - old_dnlp_wextmx = ve_dnlp_wextmx; - old_dnlp_wext_autorat = ve_dnlp_wext_autorat; - - old_dnlp_schg_sft = ve_dnlp_schg_sft; - - old_dnlp_smhist_ck = ve_dnlp_smhist_ck; - old_dnlp_cuvbld_min = ve_dnlp_cuvbld_min; - old_dnlp_cuvbld_max = ve_dnlp_cuvbld_max; - old_dnlp_dbg_map = ve_dnlp_dbg_map; - old_dnlp_dbg_adjavg = ve_dnlp_dbg_adjavg; - old_dnlp_dbg_i2r = ve_dnlp_dbg_i2r; - old_dnlp_slow_end = ve_dnlp_slow_end; - old_dnlp_pavg_btsft = ve_dnlp_pavg_btsft; - old_dnlp_pavg_btsft = ve_dnlp_pavg_btsft; - old_dnlp_cliprate_min = ve_dnlp_cliprate_min; - old_dnlp_adpcrat_lbnd = ve_dnlp_adpcrat_lbnd; - old_dnlp_adpcrat_hbnd = ve_dnlp_adpcrat_hbnd; - - old_dnlp_adpmtd_lbnd = ve_dnlp_adpmtd_lbnd; - old_dnlp_adpmtd_hbnd = ve_dnlp_adpmtd_hbnd; - old_dnlp_set_bext = ve_dnlp_set_bext; - old_dnlp_set_wext = ve_dnlp_set_wext; - - old_dnlp_satur_rat = ve_dnlp_satur_rat; - old_dnlp_satur_max = ve_dnlp_satur_max; - old_blk_prct_rng = ve_blk_prct_rng; - old_blk_prct_max = ve_blk_prct_max; - - old_dnlp_lowrange = ve_dnlp_lowrange; - old_dnlp_hghrange = ve_dnlp_hghrange; - old_dnlp_auto_rng = ve_dnlp_auto_rng; - - old_dnlp_bin0_absmax = ve_dnlp_bin0_absmax; - old_dnlp_bin0_sbtmax = ve_dnlp_bin0_sbtmax; - old_dnlp_adpalpha_hrate = ve_dnlp_adpalpha_hrate; - old_dnlp_adpalpha_lrate = ve_dnlp_adpalpha_lrate; -} - -static void dnlp_rfrsh_subgmma(void) -{ - int i = 0; - static unsigned int pgmma0[65]; /* 0~4096*/ - static unsigned int pgmma1[65]; - - if (!ve_dnlp_luma_sum) { - for (i = 0; i < 65; i++) { - pgmma0[i] = (i << 6); /* 0 ~4096 */ - pgmma1[i] = (i << 6); /* 0 ~4096 */ - } - } - - if (!dnlp_scn_chg) - for (i = 0; i < 65; i++) { - gma_scurve0[i] = dnlp_bld_lvl * - (gma_scurve0[i] << 2) + (RBASE >> 1); - gma_scurve1[i] = dnlp_bld_lvl * - (gma_scurve1[i] << 2) + (RBASE >> 1); - - gma_scurve0[i] = gma_scurve0[i] + - (RBASE - dnlp_bld_lvl) * pgmma0[i]; - gma_scurve1[i] = gma_scurve1[i] + - (RBASE - dnlp_bld_lvl) * pgmma1[i]; - - gma_scurve0[i] = (gma_scurve0[i] >> ve_dnlp_mvreflsh); - gma_scurve1[i] = (gma_scurve1[i] >> ve_dnlp_mvreflsh); - - pgmma0[i] = gma_scurve0[i]; /* 0~ 4095 */ - pgmma1[i] = gma_scurve1[i]; /* 0~ 4095 */ - - gma_scurve0[i] = (gma_scurve0[i] + 2) >> 2; /* 1023 */ - gma_scurve1[i] = (gma_scurve1[i] + 2) >> 2; /* 1023 */ - } - else - for (i = 0; i < 65; i++) { - pgmma0[i] = (gma_scurve0[i] << 2); - pgmma1[i] = (gma_scurve1[i] << 2); - } -} - -static void dnlp_inhist_lpf(void) -{ - int i = 0; - int nTmp = 0; - static unsigned int pgmma0[65]; - static unsigned int luma_sum; - - if (!dnlp_scn_chg && (ve_dnlp_dbg_i2r & 0x1)) { - for (i = 0; i < 65; i++) { - nTmp = dnlp_bld_lvl * pre_0_gamma[i] + (RBASE >> 1); - nTmp = nTmp + (RBASE - dnlp_bld_lvl) * pgmma0[i]; - nTmp = (nTmp >> ve_dnlp_mvreflsh); - pre_0_gamma[i] = nTmp; - } - - nTmp = dnlp_bld_lvl * ve_dnlp_luma_sum + (RBASE >> 1); - nTmp = nTmp + (RBASE - dnlp_bld_lvl) * luma_sum; - nTmp = (nTmp >> ve_dnlp_mvreflsh); - ve_dnlp_luma_sum = nTmp; - } - - for (i = 0; i < 65; i++) - pgmma0[i] = pre_0_gamma[i]; - luma_sum = ve_dnlp_luma_sum; -} - - -/*0 ~ 65*/ -static void dnlp_gmma_cuvs(unsigned int gmma_rate, - unsigned int low_alpha, unsigned int hgh_alpha, - unsigned int lsft_avg) -{ - int i = 0; - int nTmp = 0; - unsigned int luma_avg4 = (lsft_avg >> ve_dnlp_pavg_btsft); - - static unsigned int pgmma[65]; - bool prt_flg = ((dnlp_printk >> 10) & 0x1); - - if (!ve_dnlp_luma_sum) { - for (i = 0; i < 65; i++) - pgmma[i] = (i << 6); /* 0 ~4096 */ - } - - /* refresh sub gamma */ - if ((ve_dnlp_dbg_i2r >> 1) & 0x1) - dnlp_rfrsh_subgmma(); - - if (prt_flg) - pr_info("gmma_cuvs: %3d %3d %3d %3d\n", - gmma_rate, low_alpha, hgh_alpha, luma_avg4); - - for (i = 0; i < 65; i++) { - nTmp = (((256 - gmma_rate)*gma_scurve0[i] + - gma_scurve1[i]*gmma_rate + 128) >> 8); /* 0 ~1023 */ - - if (nTmp <= (luma_avg4<<2)) - nTmp = (nTmp*(64 - low_alpha) + - (low_alpha*i<<4) + 8)>>4; /*4096*/ - else - nTmp = (nTmp*(64 - hgh_alpha) + - (hgh_alpha*i<<4) + 8)>>4; - - if (debug_add_curve_en) { - nTmp = ((128 - glb_scurve_bld_rate) * nTmp + - glb_scurve_bld_rate * (glb_scurve[i] << 4) + 64) >> 7; - } - - if (nTmp < 0) - nTmp = 0; - else if (nTmp > 4095) - nTmp = 4095; - gma_scurvet[i] = nTmp; - - if (prt_flg) - pr_info("gmma_cuvs: [%02d] %4d %4d => %4d\n", - i, gma_scurve0[i], gma_scurve1[i], - gma_scurvet[i]); - } - - if (!dnlp_scn_chg && ((ve_dnlp_dbg_i2r >> 2) & 0x1)) - for (i = 0; i < 65; i++) { - nTmp = dnlp_bld_lvl * gma_scurvet[i] + (RBASE >> 1); - nTmp = nTmp + (RBASE - dnlp_bld_lvl) * pgmma[i]; - nTmp = (nTmp >> ve_dnlp_mvreflsh); - - gma_scurvet[i] = nTmp; /* 4095 */ - } - - for (i = 0; i < 65; i++) - pgmma[i] = gma_scurvet[i]; /* 4095 */ - - for (i = 0; i < 65; i++) - gma_scurvet[i] = ((gma_scurvet[i] + 2) >> 2); /*1023*/ -} - -/* clsh_scvbld = clash_curve + gma_scurvet */ -static void dnlp_clsh_sbld(unsigned int mtdbld_rate) -{ - int i = 0; - int nTmp0 = 0; - - static unsigned int pgmma[65]; - - if (!ve_dnlp_luma_sum) { - for (i = 0; i < 65; i++) - pgmma[i] = (i << 4); /* 0 ~1024 */ - } - - for (i = 0; i < 65; i++) { - nTmp0 = gma_scurvet[i]; /* 0 ~1024 */ - nTmp0 = nTmp0*mtdbld_rate + clash_curve[i]*(64 - mtdbld_rate); - nTmp0 = (nTmp0 + 32)>>6; /* 0~1024 */ - clsh_scvbld[i] = nTmp0; - } - - if (!dnlp_scn_chg && ((ve_dnlp_dbg_i2r >> 4) & 0x1)) - for (i = 0; i < 65; i++) { - nTmp0 = dnlp_bld_lvl * clsh_scvbld[i] + (RBASE >> 1); - nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma[i]; - nTmp0 = (nTmp0 >> ve_dnlp_mvreflsh); - - clsh_scvbld[i] = nTmp0; - } - - for (i = 0; i < 65; i++) - pgmma[i] = clsh_scvbld[i]; /* 1023 */ -} - -/* blk_gma_rat[64] */ -/* blk_gma_bld = blk_gma_crv + clsh_scvbld */ -static void dnlp_blkgma_bld(unsigned int *blk_gma_rat) -{ - int nT1 = 0; - int nTmp0 = 0; - int i = 0; - static unsigned int pgmma[65]; - - if (!ve_dnlp_luma_sum) { - for (i = 0; i < 65; i++) - pgmma[i] = (i << 4); /* 0 ~1024 */ - } - - for (i = 0; i < 64; i++) { - nT1 = blk_gma_rat[i]; - nTmp0 = clsh_scvbld[i]; - - nTmp0 = blk_gma_crv[i]*nT1 + nTmp0*(64 - nT1); - nTmp0 = (nTmp0+32)>>6; /* 0~1024 */ - blk_gma_bld[i] = nTmp0; - - if (debug_add_curve_en) { - blk_gma_bld[i] = - ((128 - glb_pst_gamma_bld_rate) * blk_gma_bld[i] + - glb_pst_gamma_bld_rate * - (glb_pst_gamma[i] << 2) + 64) >> 7; - } - - if ((dnlp_printk >> 2) & 0x1) - pr_info("sc%04d, gm%04d * rat%04d => %04d\n", - clsh_scvbld[i], blk_gma_crv[i], nT1, nTmp0); - } - blk_gma_bld[64] = 1023; - - if (!dnlp_scn_chg && ((ve_dnlp_dbg_i2r >> 5) & 0x1)) - for (i = 0; i < 65; i++) { - nTmp0 = dnlp_bld_lvl * blk_gma_bld[i] + (RBASE >> 1); - nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma[i]; - nTmp0 = (nTmp0 >> ve_dnlp_mvreflsh); - - blk_gma_bld[i] = nTmp0; - } - - for (i = 0; i < 65; i++) - pgmma[i] = blk_gma_bld[i]; /* 1023 */ -} - -/* blkwht_ebld = blk_gma_bld + extension */ -static void dnlp_blkwht_bld(int *blk_wht_ext, int bright, - unsigned int luma_avg4, unsigned int luma_avg, - unsigned int iRgnBgn, unsigned int iRgnEnd) -{ - int nT0 = 0; - int nT1 = 0; - int nTmp0 = 0; - int i = 0; - static unsigned int pgmma[65]; - - if (!ve_dnlp_luma_sum) { - for (i = 0; i < 65; i++) - pgmma[i] = (i << 4); /* 0 ~1024 */ - } - - /* black / white extension */ - for (i = 0; i < 64; i++) { - nTmp0 = blk_gma_bld[i]; - if ((luma_avg4 > (iRgnBgn << 2)) && (i <= luma_avg)) { - nT0 = (luma_avg4 - 4*iRgnBgn); - nT1 = blk_wht_ext[0] * (luma_avg4 - 4*i); - nT1 += (nT0 >> 1); - nT1 = nT1 / nT0; - - nT0 = nTmp0 - nT1; - } else if ((luma_avg4 < 4*(iRgnEnd - 1)) && (i >= luma_avg)) { - nT0 = 4*(iRgnEnd - 1) - luma_avg4; - nT1 = blk_wht_ext[1] * (4*i - luma_avg4) + (nT0 >> 1); - nT1 = nT1 / nT0; - - nT0 = nTmp0 + nT1; - } else - nT0 = nTmp0; - - - /* nTmp += dnlp_brightness; */ - nT0 = bright + nT0; - if (nT0 < 0) - nTmp0 = 0; - else if (nT0 > 1023) - nTmp0 = 1023; - else - nTmp0 = nT0; - - blkwht_ebld[i] = nT0; - } - blkwht_ebld[0] = 0; - blkwht_ebld[64] = 1023; - - if (!dnlp_scn_chg && ((ve_dnlp_dbg_i2r >> 6) & 0x1)) - for (i = 0; i < 65; i++) { - nTmp0 = dnlp_bld_lvl * blkwht_ebld[i] + (RBASE >> 1); - nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma[i]; - nTmp0 = (nTmp0 >> ve_dnlp_mvreflsh); - - blkwht_ebld[i] = nTmp0; - } - - for (i = 0; i < 65; i++) - pgmma[i] = blkwht_ebld[i]; /* 1023 */ -} - -static void dnlp_params_hist(unsigned int *gmma_rate, - unsigned int *low_alpha, unsigned int *hgh_alpha, - unsigned int *mtdbld_rate, - unsigned int luma_avg, unsigned int luma_avg4) -{ - static unsigned int pgmma0[4][7]; - int nTmp = 0; - int i = 0; - int trate = *gmma_rate; - int tlowa = *low_alpha; - int thgha = *hgh_alpha; - int tmrat = *mtdbld_rate; - - nTmp = (luma_avg > 31) ? luma_avg-31 : 31-luma_avg; - nTmp = (32 - nTmp + 2) >> 2; - - trate = trate + nTmp; - if (trate > 255) - trate = 255; - - if (luma_avg4 <= 32) - tlowa = tlowa + (32 - luma_avg4); - - if (luma_avg4 >= 224) { - if (tlowa < (luma_avg4 - 224)) - tlowa = 0; - else - tlowa = tlowa - (luma_avg4 - 224); - } - - if (!dnlp_scn_chg) { - for (i = 0; i < 7; i++) { - trate += pgmma0[0][i]; - tlowa += pgmma0[1][i]; - thgha += pgmma0[2][i]; - tmrat += pgmma0[3][i]; - } - trate = ((trate + 4)>>3); - tlowa = ((tlowa + 4)>>3); - thgha = ((thgha + 4)>>3); - tmrat = ((tmrat + 4)>>3); - - for (i = 0; i < 6; i++) { - pgmma0[0][i] = pgmma0[0][i + 1]; - pgmma0[1][i] = pgmma0[1][i + 1]; - pgmma0[2][i] = pgmma0[2][i + 1]; - pgmma0[3][i] = pgmma0[3][i + 1]; - } - pgmma0[0][6] = trate; - pgmma0[1][6] = tlowa; - pgmma0[2][6] = thgha; - pgmma0[3][6] = tmrat; - } else - for (i = 0; i < 7; i++) { - pgmma0[0][i] = trate; - pgmma0[1][i] = tlowa; - pgmma0[2][i] = thgha; - pgmma0[3][i] = tmrat; - } - *gmma_rate = trate; - *low_alpha = tlowa; - *hgh_alpha = thgha; - *mtdbld_rate = tmrat; -} - -/* black bord detection, and histogram clipping */ -static void dnlp_refine_bin0(int hstSum) -{ - static unsigned int tmp_sum[7]; - unsigned int nTmp = 0; - unsigned int nTmp0 = 0; - unsigned int nsum = 0; - int j = 0; - - nTmp = (hstSum * ve_dnlp_bin0_absmax + 128) >> 8; - nTmp0 = pre_0_gamma[1] + pre_0_gamma[2]; - if (nTmp0 > nTmp) - nTmp = nTmp0; - - if (pre_0_gamma[0] > nTmp) { - if (pre_0_gamma[1] > nTmp) - nTmp = pre_0_gamma[1]; - if (pre_0_gamma[2] > nTmp) - nTmp = pre_0_gamma[2]; - - nsum = pre_0_gamma[0] - nTmp; - - nTmp = (hstSum * ve_dnlp_bin0_sbtmax + 128) >> 8; - if (nsum > nTmp) - nsum = nTmp; - } - - if (!dnlp_scn_chg) { - for (j = 0; j < 7; j++) - nsum += tmp_sum[j]; - nsum = ((nsum + 4) >> 3); - - for (j = 0; j < 6; j++) - tmp_sum[j] = tmp_sum[j + 1]; - tmp_sum[6] = nsum; - } else { - for (j = 0; j < 7; j++) - tmp_sum[j] = nsum; - } - - if (dnlp_printk & 0x1) - pr_info("Bin0 Refine: -%4d\n", nsum); - - if (nsum >= pre_0_gamma[0]) - pre_0_gamma[0] = 0; - else - pre_0_gamma[0] = pre_0_gamma[0] - nsum; -} - -static void dnlp_adp_alpharate(unsigned int *lmh_avg, - unsigned int *low_alpha, unsigned int *hgh_alpha, - unsigned int *pst_gmarat, - unsigned int dnlp_lowrange, unsigned int dnlp_hghrange) -{ - int nTmp = 0; - int ndif = 0; - int nlap = 0; - int nbrt0 = 0; - int nbrt1 = 0; - - if ((dnlp_lowrange + lmh_avg[3]) < 64) { /* decrease low alpha */ - nTmp = 64 - (dnlp_lowrange + lmh_avg[3]); - nTmp = (ve_dnlp_adpalpha_lrate * nTmp + 16) >> 5; - if (*low_alpha < nTmp) - *low_alpha = 0; - else - *low_alpha = *low_alpha - nTmp; - - if (dnlp_printk) - pr_info("low alpha-- (%3d) -> %2d\n", nTmp, *low_alpha); - } else if (lmh_avg[3] > 64) { /* increase low alpha */ - ndif = lmh_avg[3] - 64; - nlap = (ve_dnlp_adpalpha_lrate * ndif + 16) >> 5; - if ((nlap + *low_alpha) > 64) - *low_alpha = 64; - else - *low_alpha += nlap; - - if (lmh_avg[4] < 16) { - nbrt0 = ve_dnlp_pstgma_brghtrat1 * (16 - lmh_avg[4]); - nbrt0 = (nbrt0 + 8) >> 4; - } - nbrt1 = (ve_dnlp_pstgma_brghtrate * ndif + 16) >> 6; - - nTmp = nbrt0 + nbrt1; - - if ((*pst_gmarat + nTmp) > 64) - *pst_gmarat = 64; - else - *pst_gmarat += nTmp; - - if (dnlp_printk) - pr_info("low alpha++ (%3d) -> %2d pstgma(+%2d +%2d)(%2d)\n", - nlap, *low_alpha, nbrt0, nbrt1, *pst_gmarat); - } - - if (lmh_avg[2] < 64 - dnlp_hghrange) { /* decrease hgh alpha */ - nTmp = 64 - dnlp_hghrange - lmh_avg[2]; - nTmp = (ve_dnlp_adpalpha_hrate * nTmp + 16) >> 5; - if (*hgh_alpha < nTmp) - *hgh_alpha = 0; - else - *hgh_alpha = *hgh_alpha - nTmp; - if (dnlp_printk) - pr_info("hgh alpha-- (%3d) -> %2d\n", nTmp, *hgh_alpha); - } else if (lmh_avg[2] > 63) { /* increase hgh alpha */ - nTmp = lmh_avg[2] - 63; - nTmp = (ve_dnlp_adpalpha_hrate * nTmp + 16) >> 5; - if ((nTmp + *hgh_alpha) > 64) - *hgh_alpha = 64; - else - *hgh_alpha += nTmp; - - if (dnlp_printk) - pr_info("hgh alpha++ (%3d) -> %2d\n", nTmp, *hgh_alpha); - } - -} - -static int PreTstDat[28]; -static int CrtTstDat[28]; - -static void dnlp_tgt_sort(void) -{ - int i = 0; - int j = 0; - unsigned char t = 0; - int chk = 0; - /* unsigned char ve_dnlp_tgt[64]; */ - for (j = 0; j < 63; j++) { - chk = 0; - for (i = 0; i < (63 - i); i++) { - if (ve_dnlp_tgt[i] > ve_dnlp_tgt[i+1]) { - t = ve_dnlp_tgt[i]; - ve_dnlp_tgt[i] = ve_dnlp_tgt[i+1]; - ve_dnlp_tgt[i+1] = t; - chk = chk+1; - } - } - if (chk == 0) - break; - } -} - -static void ve_dnlp_calculate_tgtx_new(struct vframe_s *vf) -{ - struct vframe_prop_s *p = &vf->prop; - - int hstSum = 0; - - /* Black gamma rate: global -> auto local */ - unsigned int blk_gma_rat[64]; - - static unsigned int nTstCnt; - - int i = 0; - /*static unsigned int sum_b;*/ - unsigned int sum = 0, max = 0; - unsigned int nTmp = 0; - int nT0 = 0, nT1 = 0; - int nTmp0 = 0; - - int dnlp_brightness = 0; - unsigned int mMaxLst[4]; - unsigned int mMaxIdx[4]; - int blk_wht_ext[2] = {0, 0}; - static unsigned int pre_stur; - unsigned int dnlp_auto_rng = 0; - - /*u4[0-8] smooth moving,reflesh the curve,0-refresh one frame*/ - /*u8larger-->near to gamma1.8, smaller->gamma1.2 [0-256]dft60*/ - unsigned int gmma_rate = (unsigned int) ve_dnlp_gmma_rate; - /* u6[0-64]dft20*/ - unsigned int low_alpha = (unsigned int) ve_dnlp_lowalpha_new; - - /* u6[0-64]dft28*/ - unsigned int hgh_alpha = (unsigned int) ve_dnlp_hghalpha_new; - - /*u4s-curve begin band [0-16]dft0*/ - unsigned int sBgnBnd = (unsigned int) ve_dnlp_sbgnbnd; - - /*u4s-curve begin band [0-16]dft5*/ - unsigned int sEndBnd = (unsigned int) ve_dnlp_sendbnd; - - /*u4clash hist begin point [0-16] dft0*/ - unsigned int clashBgn = (unsigned int) ve_dnlp_clashBgn; - - /*u4 clash hist end point [0~15] dft10*/ - unsigned int clashEnd = (unsigned int) ve_dnlp_clashEnd+49; - - /*please add the parameters*/ - /*u6method blending rate (0~64) dft32*/ - unsigned int mtdbld_rate = (unsigned int) ve_mtdbld_rate; - - /*u6 dft32*/ - unsigned int dnlp_pst_gmarat = (unsigned int) ve_dnlp_pst_gmarat; - - unsigned int dnlp_lowrange = (unsigned int) ve_dnlp_lowrange; - unsigned int dnlp_hghrange = (unsigned int) ve_dnlp_hghrange; - unsigned int dnlp_bkgert = (unsigned int) ve_dnlp_bkgert; - - /*-------------------------------------------------*/ - unsigned int lsft_avg = 0; /*luma shift average */ - unsigned int luma_avg = 0; - unsigned int luma_avg4 = 0; - unsigned int low_lavg4 = 0; /*low luma average*/ - unsigned int lmh_avg[5] = {0, 0, 0, 0, 0}; - /* low/mid/hgh tone average */ - - unsigned int ihstBgn = 0; - unsigned int ihstEnd = 0; - bool prt_flg = 0; - - unsigned int rGm1p2[] = {0, 2, 4, 7, 9, 12, 15, - 18, 21, 24, 28, 31, 34, - 38, 41, 45, 49, 52, 56, - 60, 63, 67, 71, 75, 79, - 83, 87, 91, 95, 99, 103, - 107, 111, 116, 120, 124, - 128, 133, 137, 141, 146, - 150, 154, 159, 163, 168, - 172, 177, 181, 186, 190, - 195, 200, 204, 209, 213, - 218, 223, 227, 232, 237, - 242, 246, 251, 255}; - - /* 2.0 for full range */ - unsigned int rGm1p8[] = {0, 0, 0, 1, 1, 2, 2, 3, - 4, 5, 6, 8, 9, 11, 12, 14, - 16, 18, 20, 23, 25, 28, 30, 33, - 36, 39, 42, 46, 49, 53, 56, 60, - 64, 68, 72, 77, 81, 86, 90, 95, - 100, 105, 110, 116, 121, 127, 132, 138, - 144, 150, 156, 163, - 169, 176, 182, 189, - 196, 203, 210, 218, - 225, 233, 240, 248, 255}; - - if (ve_dnlp_mvreflsh < 1) - ve_dnlp_mvreflsh = 1; - - RBASE = (1 << ve_dnlp_mvreflsh); - - /* parameters refresh */ - dnlp3_param_refrsh(); - dnlp_scn_chg = 0; - - if (low_alpha > 64) - low_alpha = 64; - if (hgh_alpha > 64) - hgh_alpha = 64; - if (clashBgn > 16) - clashBgn = 16; - if (clashEnd > 64) - clashEnd = 64; - if (clashEnd < 49) - clashEnd = 49; - - /* old historic luma sum*/ - /*sum_b = ve_dnlp_luma_sum;*/ - /* new historic luma sum*/ - if (hist_sel) - ve_dnlp_luma_sum = p->hist.vpp_luma_sum; - else - ve_dnlp_luma_sum = p->hist.luma_sum; - - /* counter the calling function */ - nTstCnt++; - if (nTstCnt > 240) - nTstCnt = 0; - - nT0 = 0; /* counter the same histogram */ - hstSum = 0; - for (i = 0; i < 64; i++) { - pre_1_gamma[i] = pre_0_gamma[i]; - if (hist_sel) - pre_0_gamma[i] = (unsigned int)p->hist.vpp_gamma[i]; - else - pre_0_gamma[i] = (unsigned int)p->hist.gamma[i]; - - /* counter the same histogram */ - if (pre_1_gamma[i] == pre_0_gamma[i]) - nT0++; - else if (pre_1_gamma[i] > pre_0_gamma[i]) - nT1 = (pre_1_gamma[i] - pre_0_gamma[i]); - else - nT1 = (pre_0_gamma[i] - pre_1_gamma[i]); - - hstSum += pre_0_gamma[i]; - } - - if (dnlp_printk) - pr_info("\nRflsh%03d: %02d same bins hstSum(%d)\n", - nTstCnt, nT0, hstSum); - - if (!ve_dnlp_luma_sum) { - /*new luma sum is 0,something is wrong,freeze dnlp curve*/ - dnlp_scn_chg = 1; - return; - } - - for (i = 0; i < 28; i++) - PreTstDat[i] = CrtTstDat[i]; - - dnlp_bld_lvl = curve_rfrsh_chk(hstSum, RBASE); - CrtTstDat[0] = dnlp_bld_lvl; - - if (ve_dnlp_respond_flag) { - dnlp_bld_lvl = RBASE; - dnlp_scn_chg = 1; - } else if (dnlp_bld_lvl >= RBASE) { - dnlp_bld_lvl = RBASE; - dnlp_scn_chg = 1; - } - - CrtTstDat[1] = dnlp_bld_lvl; - - /* black bord detection, and histogram clipping */ - dnlp_refine_bin0(hstSum); - - /* histogram and luma_sum filters */ - dnlp_inhist_lpf(); - - hstSum = 0; - for (i = 0; i < 64; i++) { - if (pre_0_gamma[i] != 0) { - if (ihstBgn == 0 && pre_0_gamma[0] == 0) - ihstBgn = i; - if (ihstEnd != 64) - ihstEnd = i+1; - } - clash_curve[i] = (i<<4); /* 0~1024 */ - - hstSum += pre_0_gamma[i]; - } - clash_curve[64] = 1024; - - if (ve_dnlp_limit_rng) { - iRgnBgn = 4; /* i=ihstBgn, i= 59) - iRgnEnd = ihstEnd; - } - CrtTstDat[8] = iRgnBgn; - CrtTstDat[9] = iRgnEnd; - - /* all the same */ - if (nT0 == 64 && ve_dnlp_smhist_ck && (!ve_dnlp_respond_flag)) - return; - - sum = 0; - max = 0; - luma_avg = 0; - - /*Get the maximum4*/ - mMaxLst[0] = 0; - mMaxLst[1] = 0; - mMaxLst[2] = 0; - mMaxLst[3] = 0; - mMaxIdx[0] = 0; - mMaxIdx[1] = 0; - mMaxIdx[2] = 0; - mMaxIdx[3] = 0; - nT0 = 0; - for (i = iRgnBgn; i < iRgnEnd; i++) { - nTmp = pre_0_gamma[i]; - - sum += nTmp; - - if (max < nTmp) - max = nTmp; - - /*lower extension [0-63]*/ - nTmp0 = nTmp*i; - luma_avg += nTmp0; - - if (i == 31) - low_lavg4 = luma_avg; /*low luma average*/ - - /*Get the maximum4*/ - for (nT0 = 0; nT0 < 4; nT0++) { - if (nTmp >= mMaxLst[nT0]) { - for (nT1 = 3; nT1 >= nT0+1; nT1--) { - mMaxLst[nT1] = mMaxLst[nT1-1]; - mMaxIdx[nT1] = mMaxIdx[nT1-1]; - } - - mMaxLst[nT0] = nTmp; - mMaxIdx[nT0] = i; - break; - } - } - } - - if (dnlp_printk & 0x1) { - pr_info("#Bins: Pre-hist => Crt-Hist\n"); - for (i = 0; i < 64; i++) - pr_info("[%03d,%03d): %05d => %05d\n", - 4*i, 4*(i+1), pre_1_gamma[i], - pre_0_gamma[i]); - /* new historic luma sum*/ - pr_info("luma s=%x, hist-sum=%d max=%d\n", - ve_dnlp_luma_sum, sum, max); - } - - /*invalid histgram: freeze dnlp curve*/ - if ((max <= 55 || sum == 0) && (!ve_dnlp_respond_flag)) - return; - - lsft_avg = (luma_avg << (2 + ve_dnlp_pavg_btsft)); - lsft_avg = (lsft_avg + (sum >> 1)) / sum; - luma_avg4 = (lsft_avg >> ve_dnlp_pavg_btsft); - luma_avg = (luma_avg4>>2); - - if (mMaxIdx[0] == 0) - nTmp = (mMaxIdx[1] * 2) + mMaxIdx[2] + mMaxIdx[3]; - else { - if (mMaxIdx[1] == 0) - nTmp = mMaxIdx[0] + mMaxIdx[2] + mMaxIdx[3]; - else if (mMaxIdx[2] == 0) - nTmp = mMaxIdx[0] + mMaxIdx[1] + mMaxIdx[3]; - else if (mMaxIdx[3] == 0) - nTmp = mMaxIdx[0] + mMaxIdx[1] + mMaxIdx[2]; - else - nTmp = mMaxIdx[1] + mMaxIdx[2] + mMaxIdx[3]; - - nTmp += mMaxIdx[0]; - } - lmh_avg[4] = nTmp; - - prt_flg = (dnlp_printk & 0x1); - if (prt_flg) { - pr_info("Max: %04d(%d) > %04d(%d) > %04d(%d) > %04d(%d) => %d\n", - mMaxLst[0], mMaxIdx[0], mMaxLst[1], mMaxIdx[1], - mMaxLst[2], mMaxIdx[2], mMaxLst[3], mMaxIdx[3], nTmp); - pr_info("%d => %d (%d)\n", luma_avg, lsft_avg, luma_avg4); - } - - CrtTstDat[10] = lsft_avg; - CrtTstDat[11] = luma_avg4; - - low_lavg4 = 4*low_lavg4/sum; - if (dnlp_printk) - pr_info("[avg1]= (%02d %02d) (%4d) (%3d, %3d)\n", - luma_avg, luma_avg4, lsft_avg, - gmma_rate, low_alpha); - - dnlp_brightness = cal_brght_plus(luma_avg4, low_lavg4); - - CrtTstDat[12] = low_lavg4; - CrtTstDat[14] = dnlp_brightness; - - /*150918 for 32-step luma pattern*/ - if (ve_dnlp_dbg_adjavg) - luma_avg4 = AdjHistAvg(luma_avg4, ihstEnd); - - luma_avg4 = cal_hist_avg(luma_avg4); - luma_avg = (luma_avg4>>2); - - if (luma_avg < ve_dnlp_auto_rng) - dnlp_auto_rng = luma_avg; - else if ((luma_avg + ve_dnlp_auto_rng) > 64) - dnlp_auto_rng = 64 - luma_avg; - else - dnlp_auto_rng = ve_dnlp_auto_rng; - - if (dnlp_auto_rng < 2) - dnlp_auto_rng = 2; - else if (dnlp_auto_rng > 10) - dnlp_auto_rng = 10; - - if (ve_dnlp_auto_rng > 0) { - if (luma_avg <= dnlp_auto_rng + 2) { - dnlp_lowrange = 2; - dnlp_hghrange = 64 - (luma_avg + dnlp_auto_rng); - } else if (luma_avg >= 61 - dnlp_auto_rng) { - dnlp_lowrange = luma_avg - dnlp_auto_rng; - dnlp_hghrange = 2; - } else { - dnlp_lowrange = luma_avg - dnlp_auto_rng; - dnlp_hghrange = (63 - (luma_avg + dnlp_auto_rng)); - } - } else { - dnlp_lowrange = ve_dnlp_lowrange; - dnlp_hghrange = ve_dnlp_hghrange; - } - if (dnlp_lowrange > 31) - dnlp_lowrange = 31; - else if (dnlp_lowrange < 2) - dnlp_lowrange = 2; - if (dnlp_hghrange > 31) - dnlp_hghrange = 31; - else if (dnlp_hghrange < 2) - dnlp_hghrange = 2; - - for (i = iRgnBgn; i < iRgnEnd; i++) { - nTmp0 = pre_0_gamma[i] * i; - - if (i < dnlp_lowrange) {/* low tone */ - lmh_avg[0] += nTmp0; - lmh_avg[3] += pre_0_gamma[i] * (64 - i); - } else if (i > (63 - dnlp_hghrange)) /* hgh tone */ - lmh_avg[2] += nTmp0; - else /* mid tone */ - lmh_avg[1] += nTmp0; - } - - /* low/mid/high tone average */ - lmh_avg[0] = (lmh_avg[0] << 6) / dnlp_lowrange; - lmh_avg[3] = (lmh_avg[3] << 6) / dnlp_lowrange; - lmh_avg[1] = (lmh_avg[1] << 6) / (64 - dnlp_lowrange - dnlp_hghrange); - lmh_avg[2] = (lmh_avg[2] << 6) / dnlp_hghrange; - - lmh_avg[0] = (lmh_avg[0] + (sum >> 1)) / (sum + 1); - lmh_avg[3] = (lmh_avg[3] + (sum >> 1)) / (sum + 1); - lmh_avg[1] = (lmh_avg[1] + (sum >> 1)) / (sum + 1); - lmh_avg[2] = (lmh_avg[2] + (sum >> 1)) / (sum + 1); - /*lmh_avg[3] = 64 - lmh_avg[3];*/ - - /* adaptive method rate */ - if (dnlp_printk) - pr_info("Adp Mtd/PostGm Rate: %d %d gm(%d)", - luma_avg, mtdbld_rate, dnlp_pst_gmarat); - - mtdbld_rate = dnlp_adp_mtdrate(mtdbld_rate, luma_avg); - - /* post gamma rate: global -> auto local */ - if (ve_dnlp_pst_gmarat > 64) - dnlp_pst_gmarat = ve_dnlp_pst_gmarat - 64; - else - dnlp_pst_gmarat = 64 - ve_dnlp_pst_gmarat; - - dnlp_adp_alpharate(lmh_avg, &low_alpha, &hgh_alpha, - &dnlp_pst_gmarat, dnlp_lowrange, dnlp_hghrange); - - if (ve_dnlp_pst_gmarat < 64) /* no adp dnlp_pst_gmarat */ - dnlp_pst_gmarat = 64 - ve_dnlp_pst_gmarat; - - if (dnlp_printk) { - pr_info("mtdbld: %2d (%2d %2d) => %2d (%2d %2d)\n", - ve_mtdbld_rate, ve_dnlp_lowalpha_new, - ve_dnlp_hghalpha_new, - mtdbld_rate, low_alpha, hgh_alpha); - pr_info("avg: l[ 0~%2d]=%2d(%2d) m=%2d h[%2d~63]=%2d\n", - dnlp_lowrange - 1, lmh_avg[0], - 64 - lmh_avg[3], lmh_avg[1], - 64 - dnlp_hghrange, lmh_avg[2]); - } - - CrtTstDat[2] = clashBgn; - CrtTstDat[3] = clashEnd; - clash_fun(clash_curve, pre_0_gamma, clashBgn, clashEnd); /* 0~1024 */ - clash_blend(); - - blk_wht_extsn(blk_wht_ext, pre_0_gamma, hstSum, luma_avg); /* 0~1024 */ - CrtTstDat[4] = blk_wht_ext[0]; - CrtTstDat[5] = blk_wht_ext[1]; - - if (dnlp_printk) - pr_info("BlkWhtExt: (%d %d), bldlvl=%02d\n", - blk_wht_ext[0], blk_wht_ext[1], dnlp_bld_lvl); - - /*patch for black+white stripe*/ - if (mMaxIdx[1] > mMaxIdx[0]) { - nT0 = mMaxIdx[0]; - nT1 = 63 - mMaxIdx[1]; - } else { - nT0 = mMaxIdx[1]; - nT1 = 63 - mMaxIdx[0]; - } - nTmp = (nT0 < nT1) ? nT0 : nT1; - nTmp = (nTmp > 16) ? 16 : nTmp; - - if ((mMaxLst[1] > (ve_dnlp_lgst_bin*sum>>8)) && - ((mMaxIdx[1] > (mMaxIdx[0] + ve_dnlp_lgst_dst)) || - (mMaxIdx[0] > (mMaxIdx[1] + ve_dnlp_lgst_dst)))) { - gmma_rate += (nTmp*(255 - gmma_rate)>>4); - low_alpha -= (low_alpha*nTmp>>4); - hgh_alpha -= (hgh_alpha*nTmp>>4); - mtdbld_rate += (nTmp*(64 - mtdbld_rate)>>4); - - if (dnlp_printk) - pr_info("special case: %d %d %d %d\n", - gmma_rate, low_alpha, hgh_alpha, mtdbld_rate); - } - /* print the parameters */ - - lsft_avg = cal_hst_shft_avg(lsft_avg); - dnlp_params_hist(&gmma_rate, &low_alpha, &hgh_alpha, - &mtdbld_rate, luma_avg, luma_avg4); - - if (dnlp_printk & 0x1) - pr_info("[avg2]= (%3d %3d) (%3d %3d) (%3d %3d)\n", - luma_avg, luma_avg4, gmma_rate, mtdbld_rate, - low_alpha, hgh_alpha); - - CrtTstDat[15] = luma_avg4; - CrtTstDat[16] = luma_avg; - CrtTstDat[17] = lsft_avg; - CrtTstDat[18] = gmma_rate; - CrtTstDat[19] = low_alpha; - - prt_flg = (dnlp_printk & 0x1); - if (prt_flg) { - pr_info("Rflsh-check: %03u\n", nTstCnt); - pr_info("BldLvl= %02d\n", dnlp_bld_lvl); - } - - if (dnlp_bkgert > dnlp_pst_gmarat) - dnlp_bkgert = dnlp_pst_gmarat; - - for (i = 0; i < 64; i++) { - nT1 = dnlp_pst_gmarat; - - if (i > ve_dnlp_bkgend) - nT1 = dnlp_bkgert; - else if (ve_dnlp_bkgend > 0) { - nT1 = dnlp_pst_gmarat - dnlp_bkgert; - nT1 = nT1 * i + (ve_dnlp_bkgend >> 1); - nT1 = nT1 / ve_dnlp_bkgend; - nT1 = dnlp_pst_gmarat - nT1; - } - - if (ve_dnlp_limit_rng && (i <= 4)) { - nT1 = i * dnlp_pst_gmarat; - nT1 = ((nT1 + 2) >> 2); - } - - if (nT1 < 0) - nT1 = 0; - else if (nT1 > 64) - nT1 = 64; - - blk_gma_rat[i] = nT1; - } - - /* 0~1024 */ - if (dnlp_printk & 0x1) - pr_info("[avg3]= %02d %02d => %4d\n", - luma_avg, luma_avg4, lsft_avg); - - if (ve_dnlp_scv_dbg != 0) { - nTmp0 = lsft_avg + 16 * ve_dnlp_scv_dbg; - if (nTmp0 < 0) - lsft_avg = 0; - else - lsft_avg = nTmp0; - } - GetGmCurves(gma_scurve0, rGm1p2, lsft_avg, sBgnBnd, sEndBnd); - GetGmCurves(gma_scurve1, rGm1p8, lsft_avg, sBgnBnd, sEndBnd); - GetGmBlkCvs(blk_gma_crv, rGm1p8, sBgnBnd, iRgnEnd); - - CrtTstDat[20] = sBgnBnd; - CrtTstDat[21] = sEndBnd; - CrtTstDat[22] = lsft_avg; - CrtTstDat[23] = iRgnEnd; - - prt_flg = (dnlp_printk & 0x1); - if (prt_flg) { - pr_info("paramets: %d %d %d %d %d\n", - luma_avg, gmma_rate, low_alpha, hgh_alpha, mtdbld_rate); - } - - /*=========================================================*/ - if (dnlp_printk & 0x1) { - pr_info("dnlp blend curve:\n"); - pr_info("[luma_sum] = %d\n", ve_dnlp_luma_sum); - } - - dnlp_gmma_cuvs(gmma_rate, low_alpha, hgh_alpha, lsft_avg); - CrtTstDat[24] = gmma_rate; - CrtTstDat[25] = low_alpha; - CrtTstDat[26] = hgh_alpha; - CrtTstDat[27] = lsft_avg; - - for (i = 0; i < 64; i++) { - pcurves[0][i] = gma_scurve0[i]; /* gamma0 s-curve */ - pcurves[1][i] = gma_scurve1[i]; /* gamma1 s-curve */ - pcurves[2][i] = gma_scurvet[i]; /* gmma0+gamm1 s-curve */ - pcurves[3][i] = clash_curve[i]; /* clash curve */ - pcurves[4][i] = clsh_scvbld[i]; /* clash + s-curve blend */ - pcurves[5][i] = blk_gma_crv[i]; /* black gamma curve */ - pcurves[6][i] = blk_gma_bld[i]; /* blending with black gamma */ - pcurves[7][i] = blkwht_ebld[i]; /* black white extension */ - } - - /* clsh_scvbld = clash_curve + gma_scurvet */ - dnlp_clsh_sbld(mtdbld_rate); /* clash + s-curve */ - - /* blk_gma_bld = blk_gma_crv + clsh_scvbld */ - dnlp_blkgma_bld(blk_gma_rat); - - /* blkwht_ebld = blk_gma_bld + extension */ - blk_wht_ext[0] += (ve_dnlp_set_bext << 4); - blk_wht_ext[1] += (ve_dnlp_set_wext << 4); - dnlp_blkwht_bld(blk_wht_ext, dnlp_brightness, - luma_avg4, luma_avg, iRgnBgn, iRgnEnd); - - if (prt_flg) { - pr_info("blk/wht ext: [%d %d] + %d\n", - blk_wht_ext[0], blk_wht_ext[1], - dnlp_brightness); - } - - prt_flg = ((dnlp_printk >> 2) & 0x1); - for (i = 0; i < 64; i++) { - premap0[i] = ve_dnlp_tgt[i]; - - if (ve_dnlp_dbg_map == 1) - nTmp0 = gma_scurve0[i]; - else if (ve_dnlp_dbg_map == 2) - nTmp0 = gma_scurve1[i]; - else if (ve_dnlp_dbg_map == 3) - nTmp0 = gma_scurvet[i]; - else if (ve_dnlp_dbg_map == 4) - nTmp0 = clash_curve[i]; - else if (ve_dnlp_dbg_map == 5) - nTmp0 = clsh_scvbld[i]; - else if (ve_dnlp_dbg_map == 6) - nTmp0 = blk_gma_crv[i]; - else if (ve_dnlp_dbg_map == 7) - nTmp0 = blk_gma_bld[i]; - else if (ve_dnlp_dbg_map == 8) - nTmp0 = blkwht_ebld[i]; /* 1023 */ - else - nTmp0 = blkwht_ebld[i]; - - nTmp0 = dnlp_bld_lvl * nTmp0 + (RBASE >> 1); /* 1024 */ - nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pst_0_gamma[i]; - nTmp0 = (nTmp0 >> ve_dnlp_mvreflsh); /* 0~4096 */ - - if (nTmp0 < 0) - nTmp0 = 0; - else if (nTmp0 > 1023) - nTmp0 = 1023; - - pst_0_gamma[i] = nTmp0; - - nTmp0 = ((nTmp0 + 2) >> 2); - - if (nTmp0 > 255) - nTmp0 = 255; - else if (nTmp0 < 0) - nTmp0 = 0; - - if (prt_flg) - pr_info("[%02d]: (%4d %4d)%4d c%4d cs%4d gm%4d-%4d %4d => %3d\n", - i, gma_scurve0[i], gma_scurve1[i], - gma_scurvet[i], clash_curve[i], - clsh_scvbld[i], blk_gma_crv[i], - blk_gma_bld[i], blkwht_ebld[i], - nTmp0); - - ve_dnlp_tgt[i] = nTmp0; - } - - /* 0~255 sort */ - dnlp_tgt_sort(); - - prt_flg = ((dnlp_printk >> 3) & 0x1); - if (prt_flg) { - for (i = 0; i < 64; i++) { - nT0 = ve_dnlp_tgt[i] - 4*i; - pr_info("%02d: %03d=>%03d (%3d)\n", - i, 4*i, ve_dnlp_tgt[i], nT0); - } - pr_info("\n"); - } - - nT0 = 0; - nT1 = 0; - for (i = 1; i < 64; i++) { - if (ve_dnlp_tgt[i] > 4*i) { - nT0 += (ve_dnlp_tgt[i] - 4*i) * (65 - i); - nT1 += (65 - i); - } - } - nTmp0 = nT0 * ve_dnlp_satur_rat + (nT1 >> 1); - nTmp0 = nTmp0 / (nT1 + 1); - nTmp0 = ((nTmp0 + 4) >> 3); - - nTmp = (ve_dnlp_satur_max << 3); - if (nTmp0 < nTmp) - nTmp = nTmp0; - - if (dnlp_printk) - pr_info("#Statu: pre(%3d) => %5d / %3d => %3d cur(%3d)\n", - pre_stur, nT0, nT1, nTmp0, nTmp); - - if (ve_dnlp_set_saturtn == 0) { - if (nTmp != pre_stur) { - ve_dnlp_add_cm(nTmp + 512); - pre_stur = nTmp; - } - } else { - if (pre_stur != ve_dnlp_set_saturtn) { - if (ve_dnlp_set_saturtn < 512) - ve_dnlp_add_cm(ve_dnlp_set_saturtn + 512); - else - ve_dnlp_add_cm(ve_dnlp_set_saturtn); - pre_stur = ve_dnlp_set_saturtn; - } - } - - if (dnlp_printk) - pr_info("#Dbg: [%02d < %02d(%03d) < %02d] %03d\n", - iRgnBgn, luma_avg, luma_avg4, - iRgnEnd, dnlp_brightness); - - nT0 = 0; - prt_flg = ((dnlp_printk >> 3) & 0x1); - if (prt_flg) { - for (i = 0; i < 64; i++) - nT0 += ((premap0[i] > ve_dnlp_tgt[i]) ? - (premap0[i] - ve_dnlp_tgt[i]) : - (ve_dnlp_tgt[i] - premap0[i])); - - pr_info("map dif= %d\n", nT0); - - if (nT0 > ve_dnlp_dbg_diflvl) { - pr_info("#mrate=%02d brt=%02d\n", - mtdbld_rate, dnlp_brightness); - for (i = 0; i < 64; i++) - if (premap0[i] != ve_dnlp_tgt[i]) - pr_info("[%02d]%5d=>%5d:(%4d=>%4d)\n", - i, - pre_1_gamma[i], pre_0_gamma[i], - premap0[i], ve_dnlp_tgt[i]); - - for (i = 0; i < 28; i++) - if (PreTstDat[i] != CrtTstDat[i]) - pr_info("[%02d] %5d=>%5d\n", - i, PreTstDat[i], CrtTstDat[i]); - pr_info("\n"); - - if (ve_dnlp_ponce >= 2) - ve_dnlp_ponce--; - else - ve_dnlp_ponce = 1; - } - } - - prt_flg = ((dnlp_printk >> 8) & 0x1); - if (ve_dnlp_dbg_map && prt_flg) - for (i = 0; i < 64; i++) - pr_info("[%02d] %5d=>%5d\n", - i, pre_0_gamma[i], ve_dnlp_tgt[i]); - - /* print debug log once */ - if (ve_dnlp_ponce == 1 && dnlp_printk) - dnlp_printk = 0; - -} - -static void ve_dnlp_calculate_tgt(struct vframe_s *vf) -{ - struct vframe_prop_s *p = &vf->prop; - ulong data[5]; - static unsigned int sum_b = 0, sum_c; - ulong i = 0, j = 0, ave = 0, max = 0, div = 0; - unsigned int cnt = assist_cnt;/* READ_VPP_REG(ASSIST_SPARE8_REG1); */ - /* old historic luma sum */ - sum_b = sum_c; - sum_c = ve_dnlp_luma_sum; - /* new historic luma sum */ - ve_dnlp_luma_sum = p->hist.luma_sum; - pr_amve_dbg("ve_dnlp_luma_sum=%x,sum_b=%x,sum_c=%x\n", - ve_dnlp_luma_sum, sum_b, sum_c); - /* picture mode: freeze dnlp curve */ - if (dnlp_respond) { - /* new luma sum is 0, something is wrong, freeze dnlp curve */ - if (!ve_dnlp_luma_sum) - return; - } else { - /* new luma sum is 0, something is wrong, freeze dnlp curve */ - if ((!ve_dnlp_luma_sum) || - /* new luma sum is closed to old one (1 +/- 1/64), */ - /* picture mode, freeze curve *//* 5 *//* 5 */ - ((ve_dnlp_luma_sum < - sum_b + (sum_b >> dnlp_adj_level)) && - (ve_dnlp_luma_sum > - sum_b - (sum_b >> dnlp_adj_level)))) - return; - } - /* get 5 regions */ - for (i = 0; i < 5; i++) { - j = 4 + 11 * i; - data[i] = (ulong)p->hist.gamma[j] + - (ulong)p->hist.gamma[j + 1] + - (ulong)p->hist.gamma[j + 2] + - (ulong)p->hist.gamma[j + 3] + - (ulong)p->hist.gamma[j + 4] + - (ulong)p->hist.gamma[j + 5] + - (ulong)p->hist.gamma[j + 6] + - (ulong)p->hist.gamma[j + 7] + - (ulong)p->hist.gamma[j + 8] + - (ulong)p->hist.gamma[j + 9] + - (ulong)p->hist.gamma[j + 10]; - } - /* get max, ave, div */ - for (i = 0; i < 5; i++) { - if (max < data[i]) - max = data[i]; - ave += data[i]; - data[i] *= 5; - } - max *= 5; - div = (max - ave > ave) ? max - ave : ave; - /* invalid histgram: freeze dnlp curve */ - if (!max) - return; - /* get 1st 4 points */ - for (i = 0; i < 4; i++) { - if (data[i] > ave) - data[i] = 64 + (((data[i] - ave) << 1) + div) * - ve_dnlp_rl / (div << 1); - else if (data[i] < ave) - data[i] = 64 - (((ave - data[i]) << 1) + div) * - ve_dnlp_rl / (div << 1); - else - data[i] = 64; - ve_dnlp_tgt[4 + 11 * (i + 1)] = ve_dnlp_tgt[4 + 11 * i] + - ((44 * data[i] + 32) >> 6); - } - /* fill in region 0 with black extension */ - data[0] = ve_dnlp_black; - if (data[0] > 16) - data[0] = 16; - data[0] = - (ve_dnlp_tgt[15] - ve_dnlp_tgt[4]) * (16 - data[0]); - for (j = 1; j <= 6; j++) - ve_dnlp_tgt[4 + j] = - ve_dnlp_tgt[4] + (data[0] * j + 88) / 176; - data[0] = (ve_dnlp_tgt[15] - ve_dnlp_tgt[10]) << 1; - for (j = 1; j <= 4; j++) - ve_dnlp_tgt[10 + j] = - ve_dnlp_tgt[10] + (data[0] * j + 5) / 10; - /* fill in regions 1~3 */ - for (i = 1; i <= 3; i++) { - data[i] = - (ve_dnlp_tgt[11 * i + 15] - ve_dnlp_tgt[11 * i + 4]) << 1; - for (j = 1; j <= 10; j++) - ve_dnlp_tgt[11 * i + 4 + j] = ve_dnlp_tgt[11 * i + 4] + - (data[i] * j + 11) / 22; - } - /* fill in region 4 with white extension */ - data[4] /= 20; - data[4] = (ve_dnlp_white * - ((ave << 4) - data[4] * ve_dnlp_white_factor) - + (ave << 3)) / (ave << 4); - if (data[4] > 16) - data[4] = 16; - data[4] = (ve_dnlp_tgt[59] - ve_dnlp_tgt[48]) * (16 - data[4]); - for (j = 1; j <= 6; j++) - ve_dnlp_tgt[59 - j] = ve_dnlp_tgt[59] - - (data[4] * j + 88) / 176; - data[4] = (ve_dnlp_tgt[53] - ve_dnlp_tgt[48]) << 1; - for (j = 1; j <= 4; j++) - ve_dnlp_tgt[53 - j] = ve_dnlp_tgt[53] - (data[4] * j + 5) / 10; - if (cnt) { - for (i = 0; i < 64; i++) - pr_amve_dbg(" ve_dnlp_tgt[%ld]=%d\n", - i, ve_dnlp_tgt[i]); - /* WRITE_VPP_REG(ASSIST_SPARE8_REG1, 0); */ - assist_cnt = 0; - } -} - /* lpf[0] is always 0 & no need calculation */ -static void ve_dnlp_calculate_lpf(void) -{ - ulong i = 0; - - for (i = 0; i < 64; i++) - ve_dnlp_lpf[i] = ve_dnlp_lpf[i] - - (ve_dnlp_lpf[i] >> ve_dnlp_rt) + ve_dnlp_tgt[i]; -} - -static void ve_dnlp_calculate_reg(void) -{ - ulong i = 0, j = 0, cur = 0, data = 0, - offset = ve_dnlp_rt ? (1 << (ve_dnlp_rt - 1)) : 0; - for (i = 0; i < 16; i++) { - ve_dnlp_reg[i] = 0; - cur = i << 2; - for (j = 0; j < 4; j++) { - data = (ve_dnlp_lpf[cur + j] + offset) >> ve_dnlp_rt; - if (data > 255) - data = 255; - ve_dnlp_reg[i] |= data << (j << 3); - } - } -} - -static void ve_dnlp_load_reg(void) +void ve_dnlp_load_reg(void) { if (dnlp_sel == NEW_DNLP_IN_SHARPNESS) { if (is_meson_gxlx_cpu() || is_meson_txlx_cpu()) { @@ -3698,16 +374,7 @@ void ve_on_vs(struct vframe_s *vf) if (dnlp_en_2 || ve_en) { /* calculate dnlp target data */ - if (ve_dnlp_method == 0) - ve_dnlp_calculate_tgt(vf); - else if (ve_dnlp_method == 1) - ve_dnlp_calculate_tgtx(vf); - else if (ve_dnlp_method == 2) - ve_dnlp_calculate_tgt_ext(vf); - else if (ve_dnlp_method == 3) - ve_dnlp_calculate_tgtx_new(vf); - else - ve_dnlp_calculate_tgt(vf); + ve_dnlp_calculate_tgtx_v3(vf); /* calculate dnlp low-pass-filter data */ ve_dnlp_calculate_lpf(); /* calculate dnlp reg data */ @@ -4001,49 +668,9 @@ void ve_disable_dnlp(void) 0, DNLP_EN_BIT, DNLP_EN_WID); } -void ve_set_dnlp(struct ve_dnlp_s *p) -{ - ulong i = 0; - /* get command parameters */ - ve_en = p->en; - ve_dnlp_white_factor = (p->rt >> 4) & 0xf; - ve_dnlp_rt = p->rt & 0xf; - ve_dnlp_rl = p->rl; - ve_dnlp_black = p->black; - ve_dnlp_white = p->white; - if (ve_en) { - /* clear historic luma sum */ - ve_dnlp_luma_sum = 0; - /* init tgt & lpf */ - for (i = 0; i < 64; i++) { - ve_dnlp_tgt[i] = i << 2; - ve_dnlp_lpf[i] = ve_dnlp_tgt[i] << ve_dnlp_rt; - } - /* calculate dnlp reg data */ - ve_dnlp_calculate_reg(); - /* load dnlp reg data */ - ve_dnlp_load_reg(); - /* enable dnlp */ - ve_enable_dnlp(); - } else { - /* disable dnlp */ - ve_disable_dnlp(); - } -} - void ve_set_dnlp_2(void) { ulong i = 0; - /* get command parameters */ - if (is_meson_gxbb_cpu()) { - ve_dnlp_method = 1; - ve_dnlp_cliprate = 6; - ve_dnlp_hghrange = 14; - ve_dnlp_lowrange = 18; - ve_dnlp_hghalpha = 26; - ve_dnlp_midalpha = 28; - ve_dnlp_lowalpha = 18; - } /* clear historic luma sum */ ve_dnlp_luma_sum = 0; /* init tgt & lpf */ @@ -4058,127 +685,6 @@ void ve_set_dnlp_2(void) ve_dnlp_load_def_reg(); } -void ve_set_new_dnlp(struct ve_dnlp_table_s *p) -{ - ulong i = 0; - /* get command parameters */ - ve_en = p->en; - ve_dnlp_method = p->method; - ve_dnlp_cliprate = p->cliprate; - ve_dnlp_hghrange = p->hghrange; - ve_dnlp_lowrange = p->lowrange; - ve_dnlp_hghalpha = p->hghalpha; - ve_dnlp_midalpha = p->midalpha; - ve_dnlp_lowalpha = p->lowalpha; - - ve_dnlp_mvreflsh = p->new_mvreflsh; - ve_dnlp_gmma_rate = p->new_gmma_rate; - ve_dnlp_lowalpha_new = p->new_lowalpha; - ve_dnlp_hghalpha_new = p->new_hghalpha; - ve_dnlp_sbgnbnd = p->new_sbgnbnd; - ve_dnlp_sendbnd = p->new_sendbnd; - ve_dnlp_cliprate_new = p->new_cliprate; - ve_dnlp_clashBgn = p->new_clashBgn; - ve_dnlp_clashEnd = p->new_clashEnd; - ve_mtdbld_rate = p->new_mtdbld_rate; - ve_dnlp_pst_gmarat = p->new_dnlp_pst_gmarat; - - dnlp_sel = p->dnlp_sel; - ve_dnlp_blk_cctr = p->dnlp_blk_cctr; - ve_dnlp_brgt_ctrl = p->dnlp_brgt_ctrl; - ve_dnlp_brgt_range = p->dnlp_brgt_range; - ve_dnlp_brght_add = p->dnlp_brght_add; - ve_dnlp_brght_max = p->dnlp_brght_max; - ve_dnlp_almst_wht = p->dnlp_almst_wht; - - ve_dnlp_hghbin = p->dnlp_hghbin; - ve_dnlp_hghnum = p->dnlp_hghnum; - ve_dnlp_lowbin = p->dnlp_lowbin; - ve_dnlp_lownum = p->dnlp_lownum; - ve_dnlp_bkgend = p->dnlp_bkgend; - ve_dnlp_bkgert = p->dnlp_bkgert; - ve_dnlp_blkext = p->dnlp_blkext; - ve_dnlp_whtext = p->dnlp_whtext; - ve_dnlp_bextmx = p->dnlp_bextmx; - ve_dnlp_wextmx = p->dnlp_wextmx; - ve_dnlp_smhist_ck = p->dnlp_smhist_ck; - ve_dnlp_glb_crate = p->dnlp_glb_crate; - - ve_dnlp_pstgma_brghtrate = p->dnlp_pstgma_brghtrate; - ve_dnlp_pstgma_brghtrat1 = p->dnlp_pstgma_brghtrat1; - ve_dnlp_wext_autorat = p->dnlp_wext_autorat; - ve_dnlp_cliprate_min = p->dnlp_cliprate_min; - ve_dnlp_adpcrat_lbnd = p->dnlp_adpcrat_lbnd; - ve_dnlp_adpcrat_hbnd = p->dnlp_adpcrat_hbnd; - ve_dnlp_adpmtd_lbnd = p->dnlp_adpmtd_lbnd; - ve_dnlp_adpmtd_hbnd = p->dnlp_adpmtd_hbnd; - ve_dnlp_set_bext = p->dnlp_set_bext; - ve_dnlp_set_wext = p->dnlp_set_wext; - ve_dnlp_satur_rat = p->dnlp_satur_rat; - ve_dnlp_satur_max = p->dnlp_satur_max; - ve_blk_prct_rng = p->blk_prct_rng; - ve_blk_prct_max = p->blk_prct_max; - ve_dnlp_lowrange = p->dnlp_lowrange; - ve_dnlp_hghrange = p->dnlp_hghrange; - ve_dnlp_auto_rng = p->dnlp_auto_rng; - ve_dnlp_bin0_absmax = p->dnlp_bin0_absmax; - ve_dnlp_bin0_sbtmax = p->dnlp_bin0_sbtmax; - ve_dnlp_adpalpha_lrate = p->dnlp_adpalpha_lrate; - ve_dnlp_adpalpha_hrate = p->dnlp_adpalpha_hrate; - - ve_dnlp_lrate00 = p->dnlp_lrate00; - ve_dnlp_lrate02 = p->dnlp_lrate02; - ve_dnlp_lrate04 = p->dnlp_lrate04; - ve_dnlp_lrate06 = p->dnlp_lrate06; - ve_dnlp_lrate08 = p->dnlp_lrate08; - ve_dnlp_lrate10 = p->dnlp_lrate10; - ve_dnlp_lrate12 = p->dnlp_lrate12; - ve_dnlp_lrate14 = p->dnlp_lrate14; - ve_dnlp_lrate16 = p->dnlp_lrate16; - ve_dnlp_lrate18 = p->dnlp_lrate18; - ve_dnlp_lrate20 = p->dnlp_lrate20; - ve_dnlp_lrate22 = p->dnlp_lrate22; - ve_dnlp_lrate24 = p->dnlp_lrate24; - ve_dnlp_lrate26 = p->dnlp_lrate26; - ve_dnlp_lrate28 = p->dnlp_lrate28; - ve_dnlp_lrate30 = p->dnlp_lrate30; - ve_dnlp_lrate32 = p->dnlp_lrate32; - ve_dnlp_lrate34 = p->dnlp_lrate34; - ve_dnlp_lrate36 = p->dnlp_lrate36; - ve_dnlp_lrate38 = p->dnlp_lrate38; - ve_dnlp_lrate40 = p->dnlp_lrate40; - ve_dnlp_lrate42 = p->dnlp_lrate42; - ve_dnlp_lrate44 = p->dnlp_lrate44; - ve_dnlp_lrate46 = p->dnlp_lrate46; - ve_dnlp_lrate48 = p->dnlp_lrate48; - ve_dnlp_lrate50 = p->dnlp_lrate50; - ve_dnlp_lrate52 = p->dnlp_lrate52; - ve_dnlp_lrate54 = p->dnlp_lrate54; - ve_dnlp_lrate56 = p->dnlp_lrate56; - ve_dnlp_lrate58 = p->dnlp_lrate58; - ve_dnlp_lrate60 = p->dnlp_lrate60; - ve_dnlp_lrate62 = p->dnlp_lrate62; - - if (ve_en) { - /* clear historic luma sum */ - ve_dnlp_luma_sum = 0; - /* init tgt & lpf */ - for (i = 0; i < 64; i++) { - ve_dnlp_tgt[i] = i << 2; - ve_dnlp_lpf[i] = ve_dnlp_tgt[i] << ve_dnlp_rt; - } - /* calculate dnlp reg data */ - ve_dnlp_calculate_reg(); - /* load dnlp reg data */ - ve_dnlp_load_reg(); - /* enable dnlp */ - ve_enable_dnlp(); - } else { - /* disable dnlp */ - ve_disable_dnlp(); - } -} - unsigned int ve_get_vs_cnt(void) { return READ_VPP_REG(VPP_VDO_MEAS_VS_COUNT_LO); @@ -4267,11 +773,11 @@ void ve_dnlp_latch_process(void) { if (vecm_latch_flag & FLAG_VE_DNLP) { vecm_latch_flag &= ~FLAG_VE_DNLP; - ve_set_dnlp(&am_ve_dnlp); + /*ve_set_dnlp(&am_ve_dnlp);*/ } if (vecm_latch_flag & FLAG_VE_NEW_DNLP) { vecm_latch_flag &= ~FLAG_VE_NEW_DNLP; - ve_set_new_dnlp(&am_ve_new_dnlp); + ve_set_v3_dnlp(&dnlp_curve_param_load); } if (vecm_latch_flag & FLAG_VE_DNLP_EN) { vecm_latch_flag &= ~FLAG_VE_DNLP_EN; @@ -4389,140 +895,14 @@ void lvds_freq_process(void) void ve_dnlp_param_update(void) { - if (am_ve_dnlp.en > 1) - am_ve_dnlp.en = 1; - if (am_ve_dnlp.black > 16) - am_ve_dnlp.black = 16; - if (am_ve_dnlp.white > 16) - am_ve_dnlp.white = 16; vecm_latch_flag |= FLAG_VE_DNLP; } void ve_new_dnlp_param_update(void) { - if (am_ve_new_dnlp.en > 1) - am_ve_new_dnlp.en = 1; - if (am_ve_new_dnlp.cliprate > 256) - am_ve_new_dnlp.cliprate = 256; - if (am_ve_new_dnlp.lowrange > 54) - am_ve_new_dnlp.lowrange = 54; - if (am_ve_new_dnlp.hghrange > 54) - am_ve_new_dnlp.hghrange = 54; - if (am_ve_new_dnlp.lowalpha > 48) - am_ve_new_dnlp.lowalpha = 48; - if (am_ve_new_dnlp.midalpha > 48) - am_ve_new_dnlp.midalpha = 48; - if (am_ve_new_dnlp.hghalpha > 48) - am_ve_new_dnlp.hghalpha = 48; - - if (am_ve_new_dnlp.dnlp_blk_cctr > 64) - am_ve_new_dnlp.dnlp_blk_cctr = 64; - if (am_ve_new_dnlp.dnlp_brgt_ctrl > 64) - am_ve_new_dnlp.dnlp_brgt_ctrl = 64; - if (am_ve_new_dnlp.dnlp_brgt_range > 64) - am_ve_new_dnlp.dnlp_brgt_range = 64; - if (am_ve_new_dnlp.dnlp_brght_add > 64) - am_ve_new_dnlp.dnlp_brght_add = 64; - if (am_ve_new_dnlp.dnlp_brght_max > 64) - am_ve_new_dnlp.dnlp_brght_max = 64; - if (am_ve_new_dnlp.dnlp_almst_wht > 64) - am_ve_new_dnlp.dnlp_almst_wht = 64; - - if (am_ve_new_dnlp.dnlp_hghbin > 64) - am_ve_new_dnlp.dnlp_hghbin = 64; - if (am_ve_new_dnlp.dnlp_hghnum > 64) - am_ve_new_dnlp.dnlp_hghnum = 64; - if (am_ve_new_dnlp.dnlp_lowbin > 64) - am_ve_new_dnlp.dnlp_lowbin = 64; - if (am_ve_new_dnlp.dnlp_lownum > 64) - am_ve_new_dnlp.dnlp_lownum = 64; - if (am_ve_new_dnlp.dnlp_bkgend > 64) - am_ve_new_dnlp.dnlp_bkgend = 64; - if (am_ve_new_dnlp.dnlp_bkgert > 64) - am_ve_new_dnlp.dnlp_bkgert = 64; - if (am_ve_new_dnlp.dnlp_blkext > 64) - am_ve_new_dnlp.dnlp_blkext = 64; - if (am_ve_new_dnlp.dnlp_whtext > 64) - am_ve_new_dnlp.dnlp_whtext = 64; - if (am_ve_new_dnlp.dnlp_bextmx > 64) - am_ve_new_dnlp.dnlp_bextmx = 64; - if (am_ve_new_dnlp.dnlp_wextmx > 64) - am_ve_new_dnlp.dnlp_wextmx = 64; - if (am_ve_new_dnlp.dnlp_smhist_ck > 1) - am_ve_new_dnlp.dnlp_smhist_ck = 1; - if (am_ve_new_dnlp.dnlp_glb_crate > 1) - am_ve_new_dnlp.dnlp_glb_crate = 1; - - if (am_ve_new_dnlp.dnlp_lrate00 > 64) - am_ve_new_dnlp.dnlp_lrate00 = 64; - if (am_ve_new_dnlp.dnlp_lrate02 > 64) - am_ve_new_dnlp.dnlp_lrate02 = 64; - if (am_ve_new_dnlp.dnlp_lrate04 > 64) - am_ve_new_dnlp.dnlp_lrate04 = 64; - if (am_ve_new_dnlp.dnlp_lrate06 > 64) - am_ve_new_dnlp.dnlp_lrate06 = 64; - if (am_ve_new_dnlp.dnlp_lrate08 > 64) - am_ve_new_dnlp.dnlp_lrate08 = 64; - if (am_ve_new_dnlp.dnlp_lrate10 > 64) - am_ve_new_dnlp.dnlp_lrate10 = 64; - if (am_ve_new_dnlp.dnlp_lrate12 > 64) - am_ve_new_dnlp.dnlp_lrate12 = 64; - if (am_ve_new_dnlp.dnlp_lrate14 > 64) - am_ve_new_dnlp.dnlp_lrate14 = 64; - if (am_ve_new_dnlp.dnlp_lrate16 > 64) - am_ve_new_dnlp.dnlp_lrate16 = 64; - if (am_ve_new_dnlp.dnlp_lrate18 > 64) - am_ve_new_dnlp.dnlp_lrate18 = 64; - if (am_ve_new_dnlp.dnlp_lrate20 > 64) - am_ve_new_dnlp.dnlp_lrate20 = 64; - if (am_ve_new_dnlp.dnlp_lrate22 > 64) - am_ve_new_dnlp.dnlp_lrate22 = 64; - if (am_ve_new_dnlp.dnlp_lrate24 > 64) - am_ve_new_dnlp.dnlp_lrate24 = 64; - if (am_ve_new_dnlp.dnlp_lrate26 > 64) - am_ve_new_dnlp.dnlp_lrate26 = 64; - if (am_ve_new_dnlp.dnlp_lrate28 > 64) - am_ve_new_dnlp.dnlp_lrate28 = 64; - if (am_ve_new_dnlp.dnlp_lrate30 > 64) - am_ve_new_dnlp.dnlp_lrate30 = 64; - if (am_ve_new_dnlp.dnlp_lrate32 > 64) - am_ve_new_dnlp.dnlp_lrate32 = 64; - if (am_ve_new_dnlp.dnlp_lrate34 > 64) - am_ve_new_dnlp.dnlp_lrate34 = 64; - if (am_ve_new_dnlp.dnlp_lrate36 > 64) - am_ve_new_dnlp.dnlp_lrate36 = 64; - if (am_ve_new_dnlp.dnlp_lrate38 > 64) - am_ve_new_dnlp.dnlp_lrate38 = 64; - if (am_ve_new_dnlp.dnlp_lrate40 > 64) - am_ve_new_dnlp.dnlp_lrate40 = 64; - if (am_ve_new_dnlp.dnlp_lrate42 > 64) - am_ve_new_dnlp.dnlp_lrate42 = 64; - if (am_ve_new_dnlp.dnlp_lrate44 > 64) - am_ve_new_dnlp.dnlp_lrate44 = 64; - if (am_ve_new_dnlp.dnlp_lrate46 > 64) - am_ve_new_dnlp.dnlp_lrate46 = 64; - if (am_ve_new_dnlp.dnlp_lrate48 > 64) - am_ve_new_dnlp.dnlp_lrate48 = 64; - if (am_ve_new_dnlp.dnlp_lrate50 > 64) - am_ve_new_dnlp.dnlp_lrate50 = 64; - if (am_ve_new_dnlp.dnlp_lrate52 > 64) - am_ve_new_dnlp.dnlp_lrate52 = 64; - if (am_ve_new_dnlp.dnlp_lrate54 > 64) - am_ve_new_dnlp.dnlp_lrate54 = 64; - if (am_ve_new_dnlp.dnlp_lrate56 > 64) - am_ve_new_dnlp.dnlp_lrate56 = 64; - if (am_ve_new_dnlp.dnlp_lrate58 > 64) - am_ve_new_dnlp.dnlp_lrate58 = 64; - if (am_ve_new_dnlp.dnlp_lrate60 > 64) - am_ve_new_dnlp.dnlp_lrate60 = 64; - if (am_ve_new_dnlp.dnlp_lrate62 > 64) - am_ve_new_dnlp.dnlp_lrate62 = 64; - vecm_latch_flag |= FLAG_VE_NEW_DNLP; } - - static void video_data_limitation(int *val) { if (*val > 1023) @@ -5457,7 +1837,7 @@ void amvecm_bricon_process(signed int bri_val, vecm_latch_flag &= ~FLAG_VADJ1_BRI; vpp_vd_adj1_brightness(bri_val, vf); pr_amve_dbg("\n[amve..] set vd1_brightness OK!!!\n"); - if (dnlp_debug&0x100) + if (amve_debug&0x100) pr_info("\n[amve..]%s :brightness:%d!!!\n", __func__, bri_val); } @@ -5469,7 +1849,7 @@ void amvecm_bricon_process(signed int bri_val, else vpp_vd_adj1_contrast(cont_val, vf); pr_amve_dbg("\n[amve..] set vd1_contrast OK!!!\n"); - if (dnlp_debug&0x100) + if (amve_debug&0x100) pr_info("\n[amve..]%s :contrast:%d!!!\n", __func__, cont_val); } @@ -5488,7 +1868,7 @@ void amvecm_color_process(signed int sat_val, if (vecm_latch_flag & FLAG_VADJ1_COLOR) { vecm_latch_flag &= ~FLAG_VADJ1_COLOR; vpp_vd_adj1_saturation_hue(sat_val, hue_val, vf); - if (dnlp_debug&0x100) + if (amve_debug&0x100) pr_info("\n[amve..]%s :saturation:%d,hue:%d!!!\n", __func__, sat_val, hue_val); } diff --git a/drivers/amlogic/media/enhancement/amvecm/amve.h b/drivers/amlogic/media/enhancement/amvecm/amve.h index 2e0402ff352d..060d74bf6cc4 100644 --- a/drivers/amlogic/media/enhancement/amvecm/amve.h +++ b/drivers/amlogic/media/enhancement/amvecm/amve.h @@ -73,7 +73,6 @@ enum vlock_param_e { extern struct ve_hist_s video_ve_hist; extern unsigned int ve_size; extern struct ve_dnlp_s am_ve_dnlp; -extern struct ve_dnlp_table_s am_ve_new_dnlp; extern struct tcon_gamma_table_s video_gamma_table_r; extern struct tcon_gamma_table_s video_gamma_table_g; extern struct tcon_gamma_table_s video_gamma_table_b; @@ -82,19 +81,6 @@ extern struct tcon_gamma_table_s video_gamma_table_g_adj; extern struct tcon_gamma_table_s video_gamma_table_b_adj; extern struct tcon_rgb_ogo_s video_rgb_ogo; -extern int glb_scurve[65]; -extern int glb_clash_curve[65]; -extern int glb_pst_gamma[65]; - -extern int gma_scurve0[65]; -extern int gma_scurve1[65]; -extern int gma_scurvet[65]; -extern int clash_curve[65]; -extern int clsh_scvbld[65]; -extern int blk_gma_crv[65]; -extern int blk_gma_bld[65]; -extern int blkwht_ebld[65]; - extern spinlock_t vpp_lcd_gamma_lock; @@ -102,7 +88,6 @@ void ve_on_vs(struct vframe_s *vf); void ve_set_bext(struct ve_bext_s *p); void ve_set_dnlp(struct ve_dnlp_s *p); -void ve_set_new_dnlp(struct ve_dnlp_table_s *p); void ve_set_dnlp_2(void); void ve_set_hsvs(struct ve_hsvs_s *p); void ve_set_ccor(struct ve_ccor_s *p); @@ -194,6 +179,8 @@ extern int video_rgb_ogo_xvy_mtx; /* 0:enc;1:pll;2:manual pll */ extern unsigned int vlock_mode; extern unsigned int vlock_en; +extern unsigned int dnlp_sel; +extern void ve_dnlp_load_reg(void); /*gxlx sr adaptive setting*/ extern void amve_sharpness_adaptive_setting(struct vframe_s *vf, diff --git a/drivers/amlogic/media/enhancement/amvecm/amvecm.c b/drivers/amlogic/media/enhancement/amvecm/amvecm.c index 1f8f633f8afe..7b4a802552b9 100644 --- a/drivers/amlogic/media/enhancement/amvecm/amvecm.c +++ b/drivers/amlogic/media/enhancement/amvecm/amvecm.c @@ -56,6 +56,7 @@ #include "keystone_correction.h" #include "bitdepth.h" #include +#include "dnlp_cal.h" #define pr_amvecm_dbg(fmt, args...)\ do {\ @@ -1032,21 +1033,16 @@ static long amvecm_ioctl(struct file *file, case AMVECM_IOC_VE_DNLP_DIS: vecm_latch_flag |= FLAG_VE_DNLP_DIS; break; - case AMVECM_IOC_VE_DNLP: - if (copy_from_user(&am_ve_dnlp, - (void __user *)arg, - sizeof(struct ve_dnlp_s))) - ret = -EFAULT; - else - ve_dnlp_param_update(); - break; case AMVECM_IOC_VE_NEW_DNLP: - if (copy_from_user(&am_ve_new_dnlp, - (void __user *)arg, - sizeof(struct ve_dnlp_table_s))) + if (copy_from_user(&dnlp_curve_param_load, + (void __user *)arg, + sizeof(struct ve_dnlp_curve_param_s))) { + pr_amvecm_dbg("dnlp load fail\n"); ret = -EFAULT; - else - ve_new_dnlp_param_update(); + } else { + ve_new_dnlp_param_update(); + pr_amvecm_dbg("dnlp load success\n"); + } break; case AMVECM_IOC_G_HIST_AVG: argp = (void __user *)arg; @@ -1171,156 +1167,443 @@ static long amvecm_compat_ioctl(struct file *file, unsigned int cmd, } #endif -static ssize_t amvecm_dnlp_curve_show(struct class *cla, +static ssize_t amvecm_dnlp_debug_show(struct class *cla, struct class_attribute *attr, char *buf) { - pr_info("echo gma_scurve0 > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo gma_scurve1 > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo gma_scurvet > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo clash_curve > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo clsh_scvbld > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo blk_gma_crv > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo blk_gma_bld > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo blkwht_ebld > /sys/class/amvecm/dnlp_curve\n"); - - pr_info("echo wv glb_scurve idx value > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo wv glb_clash_curve idx value > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo wv glb_pst_gamma idx value > /sys/class/amvecm/dnlp_curve\n"); - - pr_info("echo glb_scurve > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo glb_clash_curve > /sys/class/amvecm/dnlp_curve\n"); - pr_info("echo glb_pst_gamma > /sys/class/amvecm/dnlp_curve\n"); return 0; } -static ssize_t amvecm_dnlp_curve_store(struct class *cla, +static void str_sapr_to_d(char *s, int *d, int n) +{ + int i, j, count; + long value; + char des[9] = {0}; + + count = (strlen(s) + n - 2) / (n - 1); + for (i = 0; i < count; i++) { + for (j = 0; j < n - 1; j++) + des[j] = s[j + i * (n - 1)]; + des[n - 1] = '\0'; + if (kstrtol(des, 10, &value) < 0) + return; + d[i] = value; + } +} + +static void d_convert_str(int num, + int num_num, char cur_s[], int char_bit) +{ + char buf[9] = {0}; + int i, count; + + snprintf(buf, sizeof(buf), "%d", num); + count = strlen(buf); + for (i = 0; i < count; i++) + buf[i + char_bit] = buf[i]; + for (i = 0; i < char_bit; i++) + buf[i] = '0'; + count = strlen(buf); + for (i = 0; i < char_bit; i++) + buf[i] = buf[count - char_bit + i]; + if (num_num > 0) { + for (i = 0; i < char_bit; i++) + cur_s[i + num_num * char_bit] = + buf[i]; + } else { + for (i = 0; i < char_bit; i++) + cur_s[i] = buf[i]; + } +} + +static ssize_t amvecm_dnlp_debug_store(struct class *cla, struct class_attribute *attr, const char *buf, size_t count) { int i; long val = 0; - unsigned int idx, value; + unsigned int num; char *buf_orig, *parm[8] = {NULL}; - + int curve_val[65] = {0}; + char *stemp = NULL; if (!buf) return count; + + stemp = kmalloc(400, GFP_KERNEL); + if (!stemp) + return 0; buf_orig = kstrdup(buf, GFP_KERNEL); parse_param_amvecm(buf_orig, (char **)&parm); - if (!strncmp(parm[0], "wv", 2)) { - if (!strncmp(parm[1], "glb_scurve", 10)) { - if (kstrtoul(parm[2], 10, &val) < 0) - return -EINVAL; - idx = val; - if (kstrtoul(parm[3], 10, &val) < 0) - return -EINVAL; - value = val; - if (idx > 0 && idx < 66) { - glb_scurve[idx-1] = value; - pr_amvecm_dbg("idx = %d, value = %d\n", - idx, value); - } - } else if (!strncmp(parm[1], "glb_clash_curve", 15)) { - if (kstrtoul(parm[2], 10, &val) < 0) - return -EINVAL; - idx = val; - if (kstrtoul(parm[3], 10, &val) < 0) - return -EINVAL; - value = val; - if (idx > 0 && idx < 66) { - glb_clash_curve[idx-1] = value; - pr_amvecm_dbg("idx = %d, value = %d\n", - idx, value); - } - } else if (!strncmp(parm[1], "glb_pst_gamma", 13)) { - if (kstrtoul(parm[2], 10, &val) < 0) - return -EINVAL; - idx = val; - if (kstrtoul(parm[3], 10, &val) < 0) - return -EINVAL; - value = val; - if (idx > 0 && idx < 66) { - glb_pst_gamma[idx-1] = value; - pr_amvecm_dbg("idx = %d, value = %d\n", - idx, value); + if (!strcmp(parm[0], "r")) {/*read param*/ + if (!strcmp(parm[1], "param")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; + dnlp_parse_cmd[i].value; i++) { + pr_info("%d ", + *(dnlp_parse_cmd[i].value)); + } + pr_info("\n"); + } else + pr_info("error cmd\n"); + } else { + for (i = 0; + dnlp_parse_cmd[i].value; i++) { + if (!strcmp(parm[1], + dnlp_parse_cmd[i].parse_string)) { + pr_info("%d\n", + *(dnlp_parse_cmd[i].value)); + break; + } } } + } else if (!strcmp(parm[0], "w")) {/*write param*/ + for (i = 0; dnlp_parse_cmd[i].value; i++) { + if (!strcmp(parm[1], + dnlp_parse_cmd[i].parse_string)) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + *(dnlp_parse_cmd[i].value) = val; + pr_amvecm_dbg(" %s: %d\n", + dnlp_parse_cmd[i].parse_string, + *(dnlp_parse_cmd[i].value)); + break; + } + } + } else if (!strcmp(parm[0], "rc")) {/*read curve*/ + if (!strcmp(parm[1], "scurv_low")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(dnlp_scurv_low[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((val > 64) || (val < 0)) + pr_info("error cmd\n"); + else + pr_info("%d\n", dnlp_scurv_low[val]); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "scurv_mid1")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(dnlp_scurv_mid1[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((val > 64) || (val < 0)) + pr_info("error cmd\n"); + else + pr_info("%d\n", dnlp_scurv_mid1[val]); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "scurv_mid2")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(dnlp_scurv_mid2[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((val > 64) || (val < 0)) + pr_info("error cmd\n"); + else + pr_info("%d\n", dnlp_scurv_mid2[val]); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "scurv_hgh1")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(dnlp_scurv_hgh1[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((val > 64) || (val < 0)) + pr_info("error cmd\n"); + else + pr_info("%d\n", dnlp_scurv_hgh1[val]); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "scurv_hgh2")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(dnlp_scurv_hgh2[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((val > 64) || (val < 0)) + pr_info("error cmd\n"); + else + pr_info("%d\n", dnlp_scurv_hgh2[val]); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "gain_var_lut49")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 49; i++) + d_convert_str(gain_var_lut49[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((val > 48) || (val < 0)) + pr_info("error cmd\n"); + else + pr_info("%d\n", gain_var_lut49[val]); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "wext_gain")) { + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 48; i++) + d_convert_str(wext_gain[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((val > 47) || (val < 0)) + pr_info("error cmd\n"); + else + pr_info("%d\n", wext_gain[val]); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "ve_dnlp_tgt")) { + /*read only curve*/ + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(ve_dnlp_tgt[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "GmScurve")) { + /*read only curve*/ + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(GmScurve[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "clash_curve")) { + /*read only curve*/ + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(clash_curve[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "clsh_scvbld")) { + /*read only curve*/ + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(clsh_scvbld[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "blkwht_ebld")) { + /*read only curve*/ + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 65; i++) + d_convert_str(blkwht_ebld[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else + pr_info("error cmd\n"); + } else if (!strcmp(parm[1], "vpp_histgram")) { + /*read only curve*/ + if (!strcmp(parm[2], "all")) { + for (i = 0; i < 64; i++) + d_convert_str( + vpp_hist_param.vpp_histgram[i], + i, stemp, 4); + pr_info("%s\n", stemp); + } else + pr_info("error cmd\n"); + } + } else if (!strcmp(parm[0], "wc")) {/*write curve*/ + if (!strcmp(parm[1], "scurv_low")) { + if (!strcmp(parm[2], "all")) { + str_sapr_to_d(parm[3], curve_val, 5); + for (i = 0; i < 65; i++) + dnlp_scurv_low[i] = curve_val[i]; + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + num = val; + if (kstrtoul(parm[3], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((num > 64) || (num < 0)) + pr_info("error cmd\n"); + else + dnlp_scurv_low[num] = val; + } + } else if (!strcmp(parm[1], "scurv_mid1")) { + if (!strcmp(parm[2], "all")) { + str_sapr_to_d(parm[3], curve_val, 5); + for (i = 0; i < 65; i++) + dnlp_scurv_mid1[i] = curve_val[i]; + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + num = val; + if (kstrtoul(parm[3], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((num > 64) || (num < 0)) + pr_info("error cmd\n"); + else + dnlp_scurv_mid1[num] = val; + } + } else if (!strcmp(parm[1], "scurv_mid2")) { + if (!strcmp(parm[2], "all")) { + str_sapr_to_d(parm[3], curve_val, 5); + for (i = 0; i < 65; i++) + dnlp_scurv_mid2[i] = curve_val[i]; + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + num = val; + if (kstrtoul(parm[3], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((num > 64) || (num < 0)) + pr_info("error cmd\n"); + else + dnlp_scurv_mid2[num] = val; + } + } else if (!strcmp(parm[1], "scurv_hgh1")) { + if (!strcmp(parm[2], "all")) { + str_sapr_to_d(parm[3], curve_val, 5); + for (i = 0; i < 65; i++) + dnlp_scurv_hgh1[i] = curve_val[i]; + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + num = val; + if (kstrtoul(parm[3], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((num > 64) || (num < 0)) + pr_info("error cmd\n"); + else + dnlp_scurv_hgh1[num] = val; + } + } else if (!strcmp(parm[1], "scurv_hgh2")) { + if (!strcmp(parm[2], "all")) { + str_sapr_to_d(parm[3], curve_val, 5); + for (i = 0; i < 65; i++) + dnlp_scurv_hgh2[i] = curve_val[i]; + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + num = val; + if (kstrtoul(parm[3], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((num > 64) || (num < 0)) + pr_info("error cmd\n"); + else + dnlp_scurv_hgh2[num] = val; + } + } else if (!strcmp(parm[1], "gain_var_lut49")) { + if (!strcmp(parm[2], "all")) { + str_sapr_to_d(parm[3], curve_val, 5); + for (i = 0; i < 49; i++) + gain_var_lut49[i] = curve_val[i]; + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + num = val; + if (kstrtoul(parm[3], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((num > 48) || (num < 0)) + pr_info("error cmd\n"); + else + gain_var_lut49[num] = val; + } + } else if (!strcmp(parm[1], "wext_gain")) { + if (!strcmp(parm[2], "all")) { + str_sapr_to_d(parm[3], curve_val, 5); + for (i = 0; i < 48; i++) + wext_gain[i] = curve_val[i]; + } else if (parm[2] != NULL) { + if (kstrtoul(parm[2], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + num = val; + if (kstrtoul(parm[3], 10, &val) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if ((num > 47) || (num < 0)) + pr_info("error cmd\n"); + else + wext_gain[num] = val; + } + } + } else if (!strcmp(parm[0], "ro")) { + if (!strcmp(parm[1], "luma_avg4")) + pr_info("%d\n", ro_luma_avg4); + else if (!strcmp(parm[1], "var_d8")) + pr_info("%d\n", ro_var_d8); + else if (!strcmp(parm[1], "scurv_gain")) + pr_info("%d\n", ro_scurv_gain); + else if (!strcmp(parm[1], "blk_wht_ext0")) + pr_info("%d\n", ro_blk_wht_ext0); + else if (!strcmp(parm[1], "blk_wht_ext1")) + pr_info("%d\n", ro_blk_wht_ext1); + else if (!strcmp(parm[1], "dnlp_brightness")) + pr_info("%d\n", ro_dnlp_brightness); + else + pr_info("error cmd\n"); } - - if (!strncmp(parm[0], "gma_scurve0", 11)) { - for (i = 0; i < 64; i++) - pr_info("gma_scurve0[%d] = %d\n", i, gma_scurve0[i]); - } else if (!strncmp(parm[0], "gma_scurve1", 11)) { - for (i = 0; i < 64; i++) - pr_info("gma_scurve1[%d] = %d\n", i, gma_scurve1[i]); - } else if (!strncmp(parm[0], "gma_scurvet", 11)) { - for (i = 0; i < 64; i++) - pr_info("gma_scurvet[%d] = %d\n", i, gma_scurvet[i]); - } else if (!strncmp(parm[0], "clash_curve", 11)) { - for (i = 0; i < 64; i++) - pr_info("clash_curve[%d] = %d\n", i, clash_curve[i]); - } else if (!strncmp(parm[0], "clsh_scvbld", 11)) { - for (i = 0; i < 64; i++) - pr_info("clsh_scvbld[%d] = %d\n", i, clsh_scvbld[i]); - } else if (!strncmp(parm[0], "blk_gma_crv", 11)) { - for (i = 0; i < 64; i++) - pr_info("blk_gma_crv[%d] = %d\n", i, blk_gma_crv[i]); - } else if (!strncmp(parm[0], "blk_gma_bld", 11)) { - for (i = 0; i < 64; i++) - pr_info("blk_gma_bld[%d] = %d\n", i, blk_gma_bld[i]); - } else if (!strncmp(parm[0], "blkwht_ebld", 11)) { - for (i = 0; i < 64; i++) - pr_info("blkwht_ebld[%d] = %d\n", i, blkwht_ebld[i]); - } else if (!strncmp(parm[0], "glb_scurve", 10)) { - for (i = 0; i < 64; i++) - pr_info("glb_scurve[%d] = %d\n", i, glb_scurve[i]); - } else if (!strncmp(parm[0], "glb_clash_curve", 15)) { - for (i = 0; i < 64; i++) - pr_info("glb_clash_curve[%d] = %d\n", - i, glb_clash_curve[i]); - } else if (!strncmp(parm[0], "glb_pst_gamma", 13)) { - for (i = 0; i < 64; i++) - pr_info("glb_pst_gamma[%d] = %d\n", - i, glb_pst_gamma[i]); - } - kfree(buf_orig); - return count; -} -static ssize_t amvecm_dnlp_show(struct class *cla, - struct class_attribute *attr, char *buf) -{ - return sprintf(buf, "0x%x\n", - (am_ve_dnlp.en << 28) | (am_ve_dnlp.rt << 24) | - (am_ve_dnlp.rl << 16) | (am_ve_dnlp.black << 8) | - (am_ve_dnlp.white << 0)); -} -/* [ 28] en 0~1 */ -/* [27:20] rt 0~16 */ -/* [19:16] rl-1 0~15 */ -/* [15: 8] black 0~16 */ -/* [ 7: 0] white 0~16 */ -static ssize_t amvecm_dnlp_store(struct class *cla, - struct class_attribute *attr, - const char *buf, size_t count) -{ - size_t r; - s32 val; - - r = sscanf(buf, "0x%x", &val); - if ((r != 1) || (vecm_latch_flag & FLAG_VE_DNLP)) - return -EINVAL; - am_ve_dnlp.en = (val & 0xf0000000) >> 28; - am_ve_dnlp.rt = (val & 0x0f000000) >> 24; - am_ve_dnlp.rl = (val & 0x00ff0000) >> 16; - am_ve_dnlp.black = (val & 0x0000ff00) >> 8; - am_ve_dnlp.white = (val & 0x000000ff) >> 0; - if (am_ve_dnlp.en > 1) - am_ve_dnlp.en = 1; - if (am_ve_dnlp.rl > 64) - am_ve_dnlp.rl = 64; - if (am_ve_dnlp.black > 16) - am_ve_dnlp.black = 16; - if (am_ve_dnlp.white > 16) - am_ve_dnlp.white = 16; - vecm_latch_flag |= FLAG_VE_DNLP; + kfree(stemp); return count; } @@ -3867,6 +4150,9 @@ void init_pq_setting(void) } if (is_meson_gxlx_cpu()) amve_sharpness_init(); + + /*dnlp alg parameters init*/ + dnlp_alg_param_init(); } /* #endif*/ @@ -3961,11 +4247,9 @@ static void amvecm_wb_init(bool en) static struct class_attribute amvecm_class_attrs[] = { __ATTR(debug, 0644, amvecm_debug_show, amvecm_debug_store), - __ATTR(dnlp, 0644, - amvecm_dnlp_show, amvecm_dnlp_store), - __ATTR(dnlp_curve, 0644, - amvecm_dnlp_curve_show, - amvecm_dnlp_curve_store), + __ATTR(dnlp_debug, 0644, + amvecm_dnlp_debug_show, + amvecm_dnlp_debug_store), __ATTR(brightness, 0644, amvecm_brightness_show, amvecm_brightness_store), __ATTR(contrast, 0644, diff --git a/drivers/amlogic/media/enhancement/amvecm/dnlp_cal.c b/drivers/amlogic/media/enhancement/amvecm/dnlp_cal.c new file mode 100644 index 000000000000..a01474787f4f --- /dev/null +++ b/drivers/amlogic/media/enhancement/amvecm/dnlp_cal.c @@ -0,0 +1,3939 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "dnlp_cal.h" +#include "amve.h" +#include "arch/vpp_regs.h" +#include + +unsigned char ve_dnlp_tgt[65]; +bool ve_en; +static bool menu_chg_en; +module_param(menu_chg_en, bool, 0664); +MODULE_PARM_DESC(menu_chg_en, "menu_chg_en"); + +unsigned int ve_dnlp_rt; +unsigned int ve_dnlp_luma_sum; +ulong ve_dnlp_lpf[64], ve_dnlp_reg[16]; +ulong ve_dnlp_reg_def[16] = { + 0x0b070400, 0x1915120e, 0x2723201c, 0x35312e2a, + 0x47423d38, 0x5b56514c, 0x6f6a6560, 0x837e7974, + 0x97928d88, 0xaba6a19c, 0xbfbab5b0, 0xcfccc9c4, + 0xdad7d5d2, 0xe6e3e0dd, 0xf2efece9, 0xfdfaf7f4 +}; + +int glb_scurve[65]; +int glb_clash_curve[65]; +int glb_pst_gamma[65]; + +/*for read some params in calculating progress*/ +int ro_luma_avg4;/*0~1024*/ +int ro_var_d8;/*1024*/ +int ro_scurv_gain;/*1024*/ +int ro_blk_wht_ext0;/*1024*/ +int ro_blk_wht_ext1;/*1024*/ +int ro_dnlp_brightness;/*1024*/ + +/* pre-defined 5 s curve, for outside setting */ +int dnlp_scurv_low[65] = {0, 14, 26, 37, 48, + 60, 74, 91, 112, 138, + 166, 196, 224, 249, 271, + 292, 312, 332, 352, 372, + 392, 412, 433, 453, 472, + 491, 509, 527, 544, 561, + 578, 594, 608, 621, 633, + 644, 656, 669, 683, 697, + 712, 727, 741, 755, 768, + 781, 793, 805, 816, 827, + 839, 851, 864, 878, 892, + 906, 920, 933, 945, 956, + 968, 980, 993, 1008, + 1024}; +int dnlp_scurv_mid1[65] = {0, 12, 22, 31, 40, + 49, 58, 68, 80, 94, 110, + 127, 144, 162, 180, 198, + 216, 235, 254, 274, 296, + 319, 343, 368, 392, 416, + 440, 464, 488, 513, 537, + 561, 584, 605, 624, 642, + 660, 677, 695, 712, 728, + 744, 760, 776, 792, 809, + 825, 841, 856, 869, 881, + 893, 904, 916, 928, 940, + 952, 963, 973, 983, 992, + 1001, 1009, 1016, 1024 + }; +int dnlp_scurv_mid2[65] = {0, 6, 11, 17, 24, + 32, 41, 51, 64, 79, + 95, 112, 128, 143, 157, + 171, 184, 198, 213, 229, + 248, 269, 293, 318, 344, + 370, 396, 422, 448, 475, + 501, 527, 552, 576, 598, + 620, 640, 660, 678, 696, + 712, 727, 740, 754, 768, + 783, 800, 816, 832, 847, + 861, 874, 888, 902, 916, + 930, 944, 957, 970, 981, + 992, 1002, 1010, 1018, + 1024}; +int dnlp_scurv_hgh1[65] = {0, 11, 23, 35, 48, + 61, 75, 89, 104, 120, + 136, 152, 168, 184, 200, + 216, 232, 248, 265, 281, + 296, 310, 323, 337, 352, + 368, 386, 403, 420, 436, + 451, 465, 480, 495, 511, + 528, 544, 560, 576, 592, + 608, 624, 640, 656, 672, + 688, 704, 720, 736, 752, + 768, 784, 800, 816, 831, + 847, 864, 882, 900, 920, + 940, 961, 982, 1003, + 1024}; +int dnlp_scurv_hgh2[65] = {0, 4, 10, 20, 32, + 46, 61, 76, 92, 108, + 123, 138, 152, 166, 179, + 193, 208, 224, 240, 256, + 272, 286, 300, 314, 328, + 343, 359, 376, 392, 408, + 424, 440, 456, 472, 488, + 504, 520, 536, 552, 568, + 584, 600, 616, 632, 648, + 665, 681, 697, 712, 726, + 739, 753, 768, 784, 802, + 821, 840, 859, 879, 899, + 920, 943, 967, 994, + 1024}; +/* NOTE: put the gain-var LUT in tunning tool, */ +/* and get the var/8 as read-only for the image */ + +int gain_var_lut49[49] = { + 16, 64, 128, 192, 256, 320, 384, 384, + 384, 384, 384, 384, 384, 384, 384, 384, + 384, 384, 384, 384, 384, 384, 384, 384, + 384, 368, 352, 352, 336, 320, 304, 288, + 272, 256, 240, 224, 208, 192, 176, 160, + 144, 128, 112, 96, 96, 96, 96, 96, 96 +}; +int wext_gain[48] = { + 256, 256, 256, 256, 256, 256, 256, 256, + 248, 240, 232, 224, 216, 208, 200, 192, + 184, 176, 168, 160, 152, 144, 136, 128, + 124, 120, 116, 112, 108, 104, 100, 96, + 92, 88, 84, 80, 76, 72, 68, 64, + 60, 56, 52, 48, 44, 40, 36, 32 +}; + +static int debug_add_curve_en; +module_param(debug_add_curve_en, int, 0664); +MODULE_PARM_DESC(debug_add_curve_en, "debug_add_curve_en"); + +static int glb_scurve_bld_rate; +module_param(glb_scurve_bld_rate, int, 0664); +MODULE_PARM_DESC(glb_scurve_bld_rate, "glb_scurve_bld_rate"); + +static int glb_clash_curve_bld_rate; +module_param(glb_clash_curve_bld_rate, int, 0664); +MODULE_PARM_DESC(glb_clash_curve_bld_rate, "glb_clash_curve_bld_rate"); + +static int glb_pst_gamma_bld_rate; +module_param(glb_pst_gamma_bld_rate, int, 0664); +MODULE_PARM_DESC(glb_pst_gamma_bld_rate, "glb_pst_gamma_bld_rate"); + +static int ve_dnlp_gmma_rate = 82; +module_param(ve_dnlp_gmma_rate, int, 0664); +MODULE_PARM_DESC(ve_dnlp_gmma_rate, + "ve_dnlp_gmma_rate"); + +static int ve_dnlp_lowalpha_v3 = 40; +module_param(ve_dnlp_lowalpha_v3, int, 0664); +MODULE_PARM_DESC(ve_dnlp_lowalpha_v3, + "ve_dnlp_lowalpha_v3"); + +static int ve_dnlp_hghalpha_v3 = 28; +module_param(ve_dnlp_hghalpha_v3, int, 0664); +MODULE_PARM_DESC(ve_dnlp_hghalpha_v3, + "ve_dnlp_hghalpha_v3"); + +static int ve_dnlp_pst_gmarat = 64; +module_param(ve_dnlp_pst_gmarat, int, 0664); +MODULE_PARM_DESC(ve_dnlp_pst_gmarat, "ve_dnlp_pst_gmarat"); + +/* light -pattern 1 */ +int ve_dnlp_slow_end = 2; +module_param(ve_dnlp_slow_end, int, 0664); +MODULE_PARM_DESC(ve_dnlp_slow_end, + "ve_dnlp_slow_end"); + +/* define the black or white scence */ +static int ve_dnlp_almst_wht = 63; +module_param(ve_dnlp_almst_wht, int, 0664); +MODULE_PARM_DESC(ve_dnlp_almst_wht, "define the white scence"); + +/* black gamma end point setting */ +static int ve_dnlp_pstgma_end; +module_param(ve_dnlp_pstgma_end, int, 0664); +MODULE_PARM_DESC(ve_dnlp_pstgma_end, "black gamma end point bin num"); + +/* black gamma end point rate */ +static int ve_dnlp_pstgma_ratio; +module_param(ve_dnlp_pstgma_ratio, int, 0664); +MODULE_PARM_DESC(ve_dnlp_pstgma_ratio, "black gamma end point rate"); + +static int ve_dnlp_pstgma_brghtrate = 8; +module_param(ve_dnlp_pstgma_brghtrate, int, 0664); +MODULE_PARM_DESC(ve_dnlp_pstgma_brghtrate, "ve_dnlp_pstgma_brghtrate"); + +static int ve_dnlp_pstgma_brghtrat1 = 15; +module_param(ve_dnlp_pstgma_brghtrat1, int, 0664); +MODULE_PARM_DESC(ve_dnlp_pstgma_brghtrat1, "ve_dnlp_pstgma_brghtrat1"); + +static int ve_dnlp_adpalpha_lrate = 32; +module_param(ve_dnlp_adpalpha_lrate, int, 0664); +MODULE_PARM_DESC(ve_dnlp_adpalpha_lrate, "ve_dnlp_adpalpha_lrate"); + +static int ve_dnlp_adpalpha_hrate = 32; +module_param(ve_dnlp_adpalpha_hrate, int, 0664); +MODULE_PARM_DESC(ve_dnlp_adpalpha_hrate, "ve_dnlp_adpalpha_hrate"); + +/*the maximum bins > x/256*/ +static int ve_dnlp_lgst_ratio = 100; +module_param(ve_dnlp_lgst_ratio, int, 0664); +MODULE_PARM_DESC(ve_dnlp_lgst_ratio, "dnlp: define it ratio to larget bin num for th to 2nd bin"); + +/*two maximum bins' distance*/ +static int ve_dnlp_lgst_dst = 30; +module_param(ve_dnlp_lgst_dst, int, 0664); +MODULE_PARM_DESC(ve_dnlp_lgst_dst, "dnlp: two maximum bins' distance"); + +/* debug difference level */ +static int ve_dnlp_dbg_diflvl; +module_param(ve_dnlp_dbg_diflvl, int, 0664); +MODULE_PARM_DESC(ve_dnlp_dbg_diflvl, + "ve_dnlp_dbg_diflvl"); + +static int ve_dnlp_scv_dbg; +module_param(ve_dnlp_scv_dbg, int, 0664); +MODULE_PARM_DESC(ve_dnlp_scv_dbg, + "ve_dnlp_scv_dbg"); + +/* print log once */ +static int ve_dnlp_ponce = 1; +module_param(ve_dnlp_ponce, int, 0664); +MODULE_PARM_DESC(ve_dnlp_ponce, "ve_dnlp_ponce"); + + +unsigned int dnlp_printk; +module_param(dnlp_printk, uint, 0664); +MODULE_PARM_DESC(dnlp_printk, "dnlp_printk"); +/*v3 dnlp end */ + +static bool hist_sel = 1; /*1->vpp , 0->vdin*/ +module_param(hist_sel, bool, 0664); +MODULE_PARM_DESC(hist_sel, "hist_sel"); + +static int PreTstDat[28]; +static int CrtTstDat[28]; +/* last frame status */ +int prev_dnlp_mvreflsh; +int prev_dnlp_final_gain; +int prev_dnlp_clahe_gain_neg; +int prev_dnlp_clahe_gain_pos; +int prev_dnlp_gmma_rate; +int prev_dnlp_lowalpha_v3; +int prev_dnlp_hghalpha_v3; +int prev_dnlp_sbgnbnd; +int prev_dnlp_sendbnd; +int prev_dnlp_cliprate_v3; +int prev_dnlp_clashBgn; +int prev_dnlp_clashEnd; +int prev_dnlp_mtdbld_rate; +int prev_dnlp_pst_gmarat; +int prev_dnlp_blk_cctr; +int prev_dnlp_brgt_ctrl; +int prev_dnlp_brgt_range; +int prev_dnlp_brght_add; +int prev_dnlp_brght_max; +int prev_dnlp_lgst_ratio; +int prev_dnlp_lgst_dst; +int prev_dnlp_almst_wht; +int prev_dnlp_pstgma_end; +int prev_dnlp_pstgma_ratio; +int prev_dnlp_pstgma_brghtrate; +int prev_dnlp_pstgma_brghtrat1; +int prev_dnlp_blkext_rate; +int prev_dnlp_whtext_rate; +int prev_dnlp_blkext_ofst; +int prev_dnlp_whtext_ofst; +int prev_dnlp_bwext_div4x_min; +int prev_dnlp_lavg_cum; +int prev_dnlp_schg_sft; +bool prev_dnlp_smhist_ck; +int prev_dnlp_cuvbld_min; +int prev_dnlp_cuvbld_max; +int prev_dnlp_dbg_map; +bool prev_dnlp_dbg_adjavg; +int prev_dnlp_dbg_i2r; +int prev_dnlp_slow_end; +int prev_dnlp_pavg_btsft; +int prev_dnlp_dbg0331; +int prev_dnlp_cliprate_min; +int prev_dnlp_adpcrat_lbnd; +int prev_dnlp_adpcrat_hbnd; +int prev_dnlp_adpmtd_lbnd; +int prev_dnlp_adpmtd_hbnd; +int prev_dnlp_satur_rat; +int prev_dnlp_satur_max; +int prev_dnlp_set_saturtn; +int prev_dnlp_lowrange; +int prev_dnlp_hghrange; +int prev_dnlp_auto_rng; +int prev_dnlp_bbd_ratio_low; +int prev_dnlp_bbd_ratio_hig; +int prev_dnlp_adpalpha_lrate; +int prev_dnlp_adpalpha_hrate; + + +static unsigned int pre_1_gamma[65]; +static unsigned int pre_0_gamma[65]; +/* more 2-bit */ + +/* why here? */ +bool dnlp_scn_chg; /* scene change */ +int dnlp_bld_lvl; /* blend level */ +int RBASE = 1; + +int gma_scurve0[65]; /* gamma0 s-curve */ +int gma_scurve1[65]; /* gamma1 s-curve */ +int gma_scurvet[65]; /* gmma0+gamm1 s-curve */ +int GmScurve[65];/*pre-defined s curve,0~1024*/ +int clash_curve[65]; /* clash curve */ +int clsh_scvbld[65]; /* clash + s-curve blend */ +int blk_gma_crv[65]; /* black gamma curve */ +int blk_gma_bld[65]; /* blending with black gamma */ +int blkwht_ebld[65]; /* black white extension */ + +/* only for debug */ +static unsigned int premap0[65]; +struct dnlp_alg_param_s dnlp_alg_param; +struct ve_dnlp_curve_param_s dnlp_curve_param_load; +struct dnlp_parse_cmd_s dnlp_parse_cmd[] = { + {"alg_enable", &(dnlp_alg_param.dnlp_alg_enable)}, + {"respond", &(dnlp_alg_param.dnlp_respond)}, + {"sel", &(dnlp_alg_param.dnlp_sel)}, + {"respond_flag", &(dnlp_alg_param.dnlp_respond_flag)}, + {"smhist_ck", &(dnlp_alg_param.dnlp_smhist_ck)}, + {"mvreflsh", &(dnlp_alg_param.dnlp_mvreflsh)}, + {"pavg_btsft", &(dnlp_alg_param.dnlp_pavg_btsft)}, + {"dbg_i2r", &(dnlp_alg_param.dnlp_dbg_i2r)}, + {"cuvbld_min", &(dnlp_alg_param.dnlp_cuvbld_min)}, + {"cuvbld_max", &(dnlp_alg_param.dnlp_cuvbld_max)}, + {"schg_sft", &(dnlp_alg_param.dnlp_schg_sft)}, + {"bbd_ratio_low", &(dnlp_alg_param.dnlp_bbd_ratio_low)}, + {"bbd_ratio_hig", &(dnlp_alg_param.dnlp_bbd_ratio_hig)}, + {"limit_rng", &(dnlp_alg_param.dnlp_limit_rng)}, + {"range_det", &(dnlp_alg_param.dnlp_range_det)}, + {"blk_cctr", &(dnlp_alg_param.dnlp_blk_cctr)}, + {"brgt_ctrl", &(dnlp_alg_param.dnlp_brgt_ctrl)}, + {"brgt_range", &(dnlp_alg_param.dnlp_brgt_range)}, + {"brght_add", &(dnlp_alg_param.dnlp_brght_add)}, + {"brght_max", &(dnlp_alg_param.dnlp_brght_max)}, + {"dbg_adjavg", &(dnlp_alg_param.dnlp_dbg_adjavg)}, + {"auto_rng", &(dnlp_alg_param.dnlp_auto_rng)}, + {"lowrange", &(dnlp_alg_param.dnlp_lowrange)}, + {"hghrange", &(dnlp_alg_param.dnlp_hghrange)}, + {"satur_rat", &(dnlp_alg_param.dnlp_satur_rat)}, + {"satur_max", &(dnlp_alg_param.dnlp_satur_max)}, + {"set_saturtn", &(dnlp_alg_param.dnlp_set_saturtn)}, + {"sbgnbnd", &(dnlp_alg_param.dnlp_sbgnbnd)}, + {"sendbnd", &(dnlp_alg_param.dnlp_sendbnd)}, + {"clashBgn", &(dnlp_alg_param.dnlp_clashBgn)}, + {"clashEnd", &(dnlp_alg_param.dnlp_clashEnd)}, + {"var_th", &(dnlp_alg_param.dnlp_var_th)}, + {"clahe_gain_neg", &(dnlp_alg_param.dnlp_clahe_gain_neg)}, + {"clahe_gain_pos", &(dnlp_alg_param.dnlp_clahe_gain_pos)}, + {"clahe_gain_delta", &(dnlp_alg_param.dnlp_clahe_gain_delta)}, + {"mtdbld_rate", &(dnlp_alg_param.dnlp_mtdbld_rate)}, + {"adpmtd_lbnd", &(dnlp_alg_param.dnlp_adpmtd_lbnd)}, + {"adpmtd_hbnd", &(dnlp_alg_param.dnlp_adpmtd_hbnd)}, + {"blkext_ofst", &(dnlp_alg_param.dnlp_blkext_ofst)}, + {"whtext_ofst", &(dnlp_alg_param.dnlp_whtext_ofst)}, + {"blkext_rate", &(dnlp_alg_param.dnlp_blkext_rate)}, + {"whtext_rate", &(dnlp_alg_param.dnlp_whtext_rate)}, + {"bwext_div4x_min", &(dnlp_alg_param.dnlp_bwext_div4x_min)}, + {"iRgnBgn", &(dnlp_alg_param.dnlp_iRgnBgn)}, + {"iRgnEnd", &(dnlp_alg_param.dnlp_iRgnEnd)}, + {"dbg_map", &(dnlp_alg_param.dnlp_dbg_map)}, + {"final_gain", &(dnlp_alg_param.dnlp_final_gain)}, + {"cliprate_v3", &(dnlp_alg_param.dnlp_cliprate_v3)}, + {"cliprate_min", &(dnlp_alg_param.dnlp_cliprate_min)}, + {"adpcrat_lbnd", &(dnlp_alg_param.dnlp_adpcrat_lbnd)}, + {"adpcrat_hbnd", &(dnlp_alg_param.dnlp_adpcrat_hbnd)}, + {"scurv_low_th", &(dnlp_alg_param.dnlp_scurv_low_th)}, + {"scurv_mid1_th", &(dnlp_alg_param.dnlp_scurv_mid1_th)}, + {"scurv_mid2_th", &(dnlp_alg_param.dnlp_scurv_mid2_th)}, + {"scurv_hgh1_th", &(dnlp_alg_param.dnlp_scurv_hgh1_th)}, + {"scurv_hgh2_th", &(dnlp_alg_param.dnlp_scurv_hgh2_th)}, + {"mtdrate_adp_en", &(dnlp_alg_param.dnlp_mtdrate_adp_en)}, + {"", NULL} +}; + +#if 0 +static int ve_dnlp_lowrange = 18; +static int ve_dnlp_hghrange = 18; +static int ve_dnlp_auto_rng; +/* v3 dnlp start */ +/* larger -> slower */ +static int ve_dnlp_mvreflsh = 6; +/* gain to DCE strength, normalized 8 to "1",* + * old -- ve_dnlp_adj_level + */ +static int ve_dnlp_final_gain = 8; +/* threshold to decide var is small,* + *need tuning to decide its value.1219.2017 + */ +static int ve_dnlp_var_th = 16; +/* delta add to ve_dnlp_clahe_gain_neg/ve_dnlp_clahe_gain_pos,* + * when var is small(C curve weight more) + */ +/* need test to decide value according to actual pq test */ +static int ve_dnlp_clahe_gain_delta = 32; +/* gain to CLAHE, normalized 32 to "1",old */ +static int ve_dnlp_clahe_gain_neg = 36; +/* gain to CLAHE, normalized 32 to "1",old */ +static int ve_dnlp_clahe_gain_pos = 24; +int ve_dnlp_sbgnbnd = 4; +static int ve_dnlp_sendbnd = 4; +int ve_dnlp_clashBgn; +static int ve_dnlp_clashEnd = 15; +/* origin 53 coef of blending clashe and gma_scurvet */ +static int ve_dnlp_mtdbld_rate; +/*dnlp method = 3, use this flag or no use*/ +bool ve_dnlp_respond_flag; +/*dnlp method = 3, check the same histogram*/ +bool ve_dnlp_smhist_ck; +bool ve_dnlp_dbg_adjavg; +int ve_dnlp_dbg_i2r = 255; +/*concentration*/ +static int ve_dnlp_blk_cctr = 8; +/*the center to be brighter*/ +static int ve_dnlp_brgt_ctrl = 48; +/*brighter range*/ +static int ve_dnlp_brgt_range = 16; +/*yout=yin+ve_dnlp_brght_add*/ +/* 32 => 0, brght_add range = [0,64] => [-32,+32] */ +static int ve_dnlp_brght_add = 32; +/*yout=yin+ve_dnlp_brght_add + ve_dnlp_brght_max*rate*/ +static int ve_dnlp_brght_max; +/* black extension norm to 32 as 1 */ +static int ve_dnlp_blkext_rate = 32; /* 32 robin */ +/* white extension norm to 32 as 1 */ +static int ve_dnlp_whtext_rate = 32;/* //32 robin */ +/* black extension maximum bins */ +static int ve_dnlp_blkext_ofst = 2; +/* white extension maximum bins */ +static int ve_dnlp_whtext_ofst = 2;/* robin 2 */ +static int ve_dnlp_bwext_div4x_min = 16; +/* adpative mtdrate low band */ +/* default=0 */ +static int ve_dnlp_adpmtd_lbnd = 19; +/* adpative mtdrate high band */ +/* default=0 */ +static int ve_dnlp_adpmtd_hbnd = 20; +static int ve_dnlp_satur_rat = 30;/* robin 30 */ +static int ve_dnlp_satur_max = 40; +static unsigned int ve_dnlp_set_saturtn; +static int ve_dnlp_bbd_ratio_low = 16; +static int ve_dnlp_bbd_ratio_hig = 128; +/* hd /fhd maybe set different value */ +static int ve_dnlp_pavg_btsft = 5; +/* limit range */ +static bool ve_dnlp_limit_rng = 1; +static bool ve_dnlp_range_det; +/* scene change: avg - dif shif */ +static int ve_dnlp_schg_sft = 1; +/* curveblend minimmum level */ +static int ve_dnlp_cuvbld_min = 2; +/* curveblend minimmum level */ +static int ve_dnlp_cuvbld_max = 17; +/* output the mapping curve */ +static int ve_dnlp_dbg_map; +/* global variable */ +unsigned int iRgnBgn; /* i>=iRgnBgn */ +unsigned int iRgnEnd = 64;/* i tAvg) { + iMax = iPxl; + iMin = tAvg; + } else { + iMax = tAvg; + iMin = iPxl; + } + if (alpha < 16) { + iPxl = ((16-alpha)*iMin+8)>>4; + iPxl += alpha*iMin; + } else if (alpha < 32) { + iPxl = (32-alpha)*iMin; + iPxl += (alpha-16)*iMax; + } else { + iPxl = (48-alpha)+4*(alpha-32); + iPxl *= iMax; + } + iPxl = (iPxl+8)>>4; + iHst[iT] = iPxl < 1 ? 1 : iPxl; + } +} + +/*rGmIn[0:64] ==>0:4:256, gamma*/ +/*rGmOt[0:pwdth]==>0-0, 0~1024*/ +void GetSubCurve(unsigned int *rGmOt, + unsigned int *rGmIn, unsigned int pwdth) +{ + int nT0 = 0; + unsigned int BASE = 64; + + unsigned int plft = 0; + unsigned int prto = 0; + unsigned int rst = 0; + + unsigned int idx1 = 0; + unsigned int idx2 = 0; + + if (pwdth == 0) + pwdth = 1; + + for (nT0 = 0; nT0 <= pwdth; nT0++) { + plft = nT0*64/pwdth; + prto = (BASE*(nT0*BASE-plft*pwdth) + pwdth/2)/pwdth; + + idx1 = plft; + idx2 = plft+1; + if (idx1 > 64) + idx1 = 64; + if (idx2 > 64) + idx2 = 64; + + rst = rGmIn[idx1]*(BASE-prto) + rGmIn[idx2]*prto; + rst = (rst + BASE/2)*4*pwdth/BASE; + /* rst = ((rst + 128)>>8); */ + rst = ((rst + 32)>>6); + + if (nT0 == 0) + rst = rGmIn[0]; + if (rst > (pwdth << 4)) + rst = (pwdth << 4); + + rGmOt[nT0] = rst; + } +} + +/*rGmOt[0:64]*/ +/*rGmIn[0:64]*/ +/* 0~1024 */ +void GetGmBlkCvs(unsigned int *rGmOt, unsigned int *rGmIn, + unsigned int Bgn, unsigned int End) +{ + static unsigned int pgmma0[65]; + int nT0 = 0; + int pwdth = End - Bgn; /* 64 */ + int pLst[65]; + int i = 0; + int j = 0; + int nTmp0 = 0; + /* bool prt_flg = ((dnlp_printk >> 1) & 0x1); */ + + if (!ve_dnlp_luma_sum) { + for (nT0 = 0; nT0 < 65; nT0++) + pgmma0[nT0] = (nT0 << 4); /* 0 ~1024 */ + } + + GetSubCurve(pLst, rGmIn, pwdth); /*0~1024*/ + + for (nT0 = 0; nT0 < 65; nT0++) { + if (nT0 < Bgn) + rGmOt[nT0] = (nT0 << 4); + else if (nT0 >= End) + rGmOt[nT0] = (nT0 << 4); + else { + if (ve_dnlp_pst_gmarat > 64) + rGmOt[nT0] = (Bgn << 4) + + (1024 - pLst[64 + Bgn - nT0]); + else + rGmOt[nT0] = (Bgn << 4) + pLst[nT0 - Bgn]; + } + } + + if (!dnlp_scn_chg) + for (i = 0; i < 65; i++) { + nTmp0 = dnlp_bld_lvl * rGmOt[i] + (RBASE >> 1); + nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma0[i]; + nTmp0 = (nTmp0 >> dnlp_alg_param.dnlp_mvreflsh); + /* 0 ~1024 */ + + rGmOt[i] = nTmp0; + } + + for (i = 0; i < 65; i++) + pgmma0[i] = rGmOt[i]; + + if ((dnlp_printk>>13) & 0x1) { + /* iHst */ + pr_info("\n=====blk_gma: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d\n" + "%d,%d,%d,%d,%d,%d,%d,%d\n", + rGmOt[i], rGmOt[i+1], + rGmOt[i+2], rGmOt[i+3], + rGmOt[i+4], rGmOt[i+5], + rGmOt[i+6], rGmOt[i+7], + rGmOt[i+8], rGmOt[i+9], + rGmOt[i+10], rGmOt[i+11], + rGmOt[i+12], rGmOt[i+13], + rGmOt[i+14], rGmOt[i+15]); + } + pr_info("%d ]\n", rGmOt[64]); + } +} + + +/*rGmOt[0:64]*/ +/*rGmIn[0:64]*/ +/* 0 ~1024 */ +void GetGmCurves2(unsigned int *rGmOt, unsigned int *rGmIn, + unsigned int pval, unsigned int BgnBnd, unsigned int EndBnd) +{ + int nT0 = 0; + /*unsigned int rst=0;*/ + int pwdth = 0; + unsigned int pLst[65]; + int nT1 = 0; + bool prt_flg = ((dnlp_printk >> 1) & 0x1); + + if (pval >= ve_dnlp_almst_wht) { + /*almost white scene, do not S_curve*/ + for (nT0 = 0; nT0 < 65; nT0++) + rGmOt[nT0] = rGmIn[nT0] << 2; + return; + } + + if (BgnBnd > 10) + BgnBnd = 10; /* 4 */ + if (EndBnd > 10) + EndBnd = 10; /* 4 */ + + if (pval < ve_dnlp_slow_end) + pval = ve_dnlp_slow_end; + + if (pval <= BgnBnd) + pval = BgnBnd + 1;/* very black */ + + if (pval + EndBnd > 64) + pval = 63 - EndBnd; /* close wht */ + + for (nT0 = 0; nT0 < 65; nT0++) + rGmOt[nT0] = (nT0<<4); /* 0~1024 */ /* init 45 dgree line */ + + if (pval > BgnBnd) { + pwdth = pval - BgnBnd; + + GetSubCurve(pLst, rGmIn, pwdth); /* 0~1024 */ + if (prt_flg) { + pr_info("\n#---GetSubCurve(down): pwdth= %d\n", pwdth); + pr_info("[index] => Down_curve(45line)\n"); + for (nT1 = 0; nT1 < pwdth; nT1++) + pr_info("[%02d] => %4d(%4d)\n", + nT1, pLst[nT1], nT1<<4); + pr_info("\n"); + } + + for (nT0 = BgnBnd; nT0 <= pval; nT0++) { + /* (down_cur) %4d(%4d)\n", + nT0, pLst[nT0 - BgnBnd], nT1, nT0<<4); + } + } + + if (pval + EndBnd < 64) { + pwdth = 64 - pval - EndBnd; + GetSubCurve(pLst, rGmIn, pwdth); + if (prt_flg) { + pr_info("\n#---GetSubCurve(up): pwdth= %d\n", pwdth); + pr_info("[index] => up_curve(45line)\n"); + for (nT1 = 0; nT1 < pwdth; nT1++) + pr_info("[%02d] => %4d(%4d)\n", + nT1, pLst[nT1], nT1<<4); + pr_info("\n"); + } + + for (nT0 = pval; nT0 <= 64 - EndBnd; nT0++) { + nT1 = (1024 - (EndBnd<<4) + - pLst[pwdth - (nT0 - pval)]); + rGmOt[nT0] = nT1; /* 0~1024 */ + /* >luma_avg band curve,arch up */ + + if (prt_flg) + pr_info("\n#***up_cur::(index)%02d:\n" + "(pLst) %4d => (up_cur) %4d(%4d)\n", + nT0, pLst[pwdth - (nT0 - pval)], nT1, nT0<<4); + + } + } + + if (prt_flg) { + pr_info("\n#---GmCvs2: BgnBnd(%d) pval(%d,luma_avg) EndBnd(%d)\n", + BgnBnd, pval, EndBnd); + pr_info("[index] => curve(45line)\n"); + for (nT1 = 0; nT1 < 65; nT1++) + pr_info("[%02d] => %4d(%4d)\n", + nT1, rGmOt[nT1], nT1<<4); + pr_info("\n"); + } +} + +/* in: rGmIn,lsft_avg,BgnBnd,EndBnd*/ +/* out: rGmOt */ +void GetGmCurves(unsigned int *rGmOt, unsigned int *rGmIn, + unsigned int lsft_avg, unsigned int BgnBnd, unsigned int EndBnd) +{ + /* luma_avg4, */ + int pval1 = (lsft_avg >> (2 + dnlp_alg_param.dnlp_pavg_btsft)); + int pval2 = pval1 + 1; + int BASE = (1 << (2 + dnlp_alg_param.dnlp_pavg_btsft)); + /* = 0; what for ? */ + int nRzn = lsft_avg - (pval1 << (2 + dnlp_alg_param.dnlp_pavg_btsft)); + unsigned int pLst1[65]; + unsigned int pLst2[65]; + int i = 0; + int j = 0; + bool prt_flg = ((dnlp_printk >> 1) & 0x1); + + if (pval2 > ve_dnlp_almst_wht) + pval2 = ve_dnlp_almst_wht; + + GetGmCurves2(pLst1, rGmIn, pval1, BgnBnd, EndBnd); + GetGmCurves2(pLst2, rGmIn, pval2, BgnBnd, EndBnd); + if (prt_flg) + pr_info("GetGmCurves 0/1: pval1=%d, pval2=%d\n", + pval1, pval2); + + for (i = 0; i < 65; i++) { + /* pLst1, pLst2 blend:blend level nRzn(0) */ + pval2 = pLst1[i] * (BASE - nRzn) + pLst2[i] * nRzn; + pval2 = (pval2 + (BASE >> 1)); + pval2 = (pval2 >> (2 + dnlp_alg_param.dnlp_pavg_btsft)); + + if (pval2 < 0) + pval2 = 0; + else if (pval2 > 1023) + pval2 = 1023; + rGmOt[i] = pval2; + } + + if ((dnlp_printk >> 13) & 0x1) { + /* iHst */ + pr_info("\n=====gma_s: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d\n" + "%d,%d,%d,%d,%d,%d,%d,%d,%d\n", + rGmOt[i], rGmOt[i+1], + rGmOt[i+2], rGmOt[i+3], + rGmOt[i+4], rGmOt[i+5], + rGmOt[i+6], rGmOt[i+7], + rGmOt[i+8], rGmOt[i+9], + rGmOt[i+10], rGmOt[i+11], + rGmOt[i+12], rGmOt[i+13], + rGmOt[i+14], rGmOt[i+15]); + } + pr_info("%d ]\n", rGmOt[64]); + } + +} + + +/* + *function: choose pre-defined s curve based on APL(luma_avg4) + *in : luma_avg(0~255),sBgnBnd,sEndBnd + *out : the chosen s curve + */ +void GetGmScurve_apl_var(unsigned int *rGmOt, unsigned int luma_avg4, + int var, unsigned int sBgnBnd, unsigned int sEndBnd) +{ + int nTmp, nFrac, i, j; + static unsigned int pre_scurve[65]; + int scurv_gain, left, right, var_d8, frac, norm, idx; + + /* typical histo <==> var <==> var/8 */ + /*1-bin 0 0 */ + /*3-bin 8 1 */ + /*5-bin 16 2 */ + /*7-bin 32 4 */ + /*9-bin 52 7 */ + /*13-bin 112 15 */ + /*11-bin 83 11 */ + /*16-bin 204 25 */ + /*32-bin 748 93.5 */ + /*ramp 2500 325*/ + /* BW50% 8192 1024 */ + nTmp = 0; + + /* get the scurv_gain from lut via the var/8, piece wised */ + var_d8 = (var>>3); + /*for read on tools*/ + ro_var_d8 = var_d8; + frac = 0; + nFrac = 0; + if (var < 128) { + idx = var_d8; + nFrac = var - 0; + frac = nFrac - ((nFrac >> 3) << 3); + norm = 3; + } else if (var < 640) { + idx = 16 + ((var_d8 - 16) >> 2); + nFrac = var - 128; + frac = nFrac - ((nFrac >> 5) << 5); + norm = 5; + } else if (var < 2560) { + idx = 32 + ((var_d8 - 80) >> 4); + nFrac = var - 640; + frac = nFrac - ((nFrac >> 7) << 7); + norm = 7; + } else { + idx = 47; + frac = 0; + norm = 7; + } + left = gain_var_lut49[idx]; + right = gain_var_lut49[idx + 1]; + scurv_gain = (left * ((1 << norm) - frac) + + right*frac + (1 << (norm - 1))) >> (norm); + /*for read on tools*/ + ro_scurv_gain = scurv_gain; + + if ((dnlp_printk >> 14) & 0x1) + pr_info("@@@ GetGmScurve()--in: hist_var = %d\n" + "luma_avg4(255) = %d, sBgn_Bnd,end = [%d %d]\n\n", + var, luma_avg4, sBgnBnd, sEndBnd); + if ((dnlp_printk >> 14) & 0x1) + pr_info("@@@ GetGmScurve()--scurv_gain: nFrac = %d,frac = %d\n" + "idx= %d, left,right= [%d %d] => scurv_gain = %d\n\n", + nFrac, frac, idx, left, right, scurv_gain); + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) + pre_scurve[i] = (i << 4); /* 0 ~1024 */ + } + + if (luma_avg4 < 0) + luma_avg4 = 0; + else if (luma_avg4 > 255) + luma_avg4 = 255;/* luma_avg = 0~255 */ + + + /* choose s curve base on luma_avg */ + for (i = 0; i < 65; i++) { + if (i <= sBgnBnd) + nTmp = i << 4; + else if (i >= (64 - sBgnBnd)) + nTmp = i << 4; + else{ + if (luma_avg4 < dnlp_alg_param.dnlp_scurv_low_th) + nTmp = dnlp_scurv_low[i]; + else if (luma_avg4 >= dnlp_alg_param.dnlp_scurv_hgh2_th) + nTmp = dnlp_scurv_hgh2[i]; + /* linear interpolations */ + else { + if (luma_avg4 < + dnlp_alg_param.dnlp_scurv_mid1_th) { + left = dnlp_scurv_low[i]; + right = dnlp_scurv_mid1[i]; + frac = luma_avg4 - + dnlp_alg_param.dnlp_scurv_low_th; + norm = dnlp_alg_param.dnlp_scurv_mid1_th + - dnlp_alg_param.dnlp_scurv_low_th; + } else if (luma_avg4 < + dnlp_alg_param.dnlp_scurv_mid2_th) { + left = dnlp_scurv_mid1[i]; + right = dnlp_scurv_mid2[i]; + frac = luma_avg4 - + dnlp_alg_param.dnlp_scurv_mid1_th; + norm = dnlp_alg_param.dnlp_scurv_mid2_th + - dnlp_alg_param.dnlp_scurv_mid1_th; + } else if (luma_avg4 < + dnlp_alg_param.dnlp_scurv_hgh1_th) { + left = dnlp_scurv_mid2[i]; + right = dnlp_scurv_hgh1[i]; + frac = luma_avg4 - + dnlp_alg_param.dnlp_scurv_mid2_th; + norm = + dnlp_alg_param.dnlp_scurv_hgh1_th + - dnlp_alg_param.dnlp_scurv_mid2_th; + } else { + left = dnlp_scurv_hgh1[i]; + right = dnlp_scurv_hgh2[i]; + frac = luma_avg4 - + dnlp_alg_param.dnlp_scurv_hgh1_th; + norm = dnlp_alg_param.dnlp_scurv_hgh2_th + - dnlp_alg_param.dnlp_scurv_hgh1_th; + } + /* linear blending base on APL (Double check) */ + nTmp = (left*(norm - frac) + + right*frac + (norm>>1))/norm; + + } + } + + /* apply a gain based on hist variance,*/ + /* norm 256 to "1" */ + nTmp = (i << 4) + + ((nTmp - (i << 4)) * scurv_gain + 128)/256; + + /* clip */ + if (nTmp < 0) + nTmp = 0; + else if (nTmp > 1023) + nTmp = 1023; + + /* output */ + rGmOt[i] = nTmp; + } + + if (!dnlp_scn_chg) + for (i = 0; i < 65; i++) { + nTmp = dnlp_bld_lvl * rGmOt[i] + (RBASE >> 1); /*1024 */ + nTmp = nTmp + (RBASE - dnlp_bld_lvl) * pre_scurve[i]; + nTmp = (nTmp >> dnlp_alg_param.dnlp_mvreflsh); + + if (nTmp < 0) + nTmp = 0; + else if (nTmp > 1023) + nTmp = 1023; + + if ((dnlp_printk >> 14) & 0x1) + pr_info("\n@@@ apl_var(iir): %d, rGmOt[i]=%d, pre_scurve=%d => crt=%d\n", + i, rGmOt[i], pre_scurve[i], nTmp); + + rGmOt[i] = nTmp; + } + + for (i = 0; i < 65; i++) + pre_scurve[i] = rGmOt[i]; + + if ((dnlp_printk >> 14) & 0x1) { + /* iHst */ + pr_info("@@@ GetGmScurve()--out,chosen curve: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + rGmOt[i], rGmOt[i+1], + rGmOt[i+2], rGmOt[i+3], + rGmOt[i+4], rGmOt[i+5], + rGmOt[i+6], rGmOt[i+7], + rGmOt[i+8], rGmOt[i+9], + rGmOt[i+10], rGmOt[i+11], + rGmOt[i+12], rGmOt[i+13], + rGmOt[i+14], rGmOt[i+15]); + } + pr_info("%d ]\n", rGmOt[64]); + } +} + + +unsigned int cal_hist_avg(unsigned int pval) +{ + static int ppval; + int ipval = (int) pval; + int tmp = ipval; + + if (!dnlp_scn_chg) { + tmp = dnlp_bld_lvl * ipval + (RBASE >> 1); + tmp = tmp + (RBASE - dnlp_bld_lvl) * ppval; + tmp = (tmp >> dnlp_alg_param.dnlp_mvreflsh); + } + ppval = tmp; + + return (unsigned int)tmp; +} + + +/* history */ +unsigned int cal_hst_shft_avg(unsigned int pval) +{ + static int ppval; + int ipval = (int)pval; + int tmp = ipval; + + if (!dnlp_scn_chg) { + tmp = dnlp_bld_lvl * ipval + (RBASE >> 1); + tmp = tmp + (RBASE - dnlp_bld_lvl) * ppval; + tmp = (tmp >> dnlp_alg_param.dnlp_mvreflsh); + } + ppval = tmp; + return (unsigned int)tmp; +} + + +/* in : mtdrate, luma_avg(0~64)*/ +/* return: mtdrate-- mtdrate in the mid-tone*/ +static int dnlp_adp_mtdrate(int mtdrate, int luma_avg) +{ + int np = 0; + int nt = mtdrate; + bool prt_flg = ((dnlp_printk >> 5) & 0x1); + + if (dnlp_alg_param.dnlp_mtdrate_adp_en) { + if (dnlp_alg_param.dnlp_adpmtd_lbnd > 0 && + luma_avg < dnlp_alg_param.dnlp_adpmtd_lbnd) { + nt = mtdrate * luma_avg + + (dnlp_alg_param.dnlp_adpmtd_lbnd >> 1); + nt /= dnlp_alg_param.dnlp_adpmtd_lbnd; + + np = 4 * (dnlp_alg_param.dnlp_adpmtd_lbnd - luma_avg); + if (np < mtdrate) + np = mtdrate - np; + else + np = 0; + + if (np > nt) + nt = np; + } else if (dnlp_alg_param.dnlp_adpmtd_hbnd > 0 && + (luma_avg > 64 - dnlp_alg_param.dnlp_adpmtd_hbnd)) { + nt = mtdrate * (64 - luma_avg); + nt += (dnlp_alg_param.dnlp_adpmtd_hbnd >> 1); + nt /= dnlp_alg_param.dnlp_adpmtd_hbnd; + + np = luma_avg - (64 - dnlp_alg_param.dnlp_adpmtd_hbnd); + np = 4 * np; + if (np < mtdrate) + np = mtdrate - np; + else + np = 0; + + if (np > nt) + nt = np; + } + if (prt_flg) + pr_info("Step C-2.y: adp_mtdrate: imtdrate=%d, luma_avg=%d,\n" + " ve_adpmtd_bnd=[%d %d], nt(mtdrate)=%d (np=%d)\n ", + mtdrate, luma_avg, dnlp_alg_param.dnlp_adpmtd_lbnd, + dnlp_alg_param.dnlp_adpmtd_hbnd, nt, np); + } else + nt = dnlp_alg_param.dnlp_mtdbld_rate; + + return nt; +} + + +unsigned int AdjHistAvg(unsigned int pval, unsigned int ihstEnd) +{ + unsigned int pEXT = 224; + unsigned int pMid = 128; + unsigned int pMAX = 236; + + if (ihstEnd > 59) + pMAX = ihstEnd << 2; + + if (pval > pMid) { + pval = pMid + (pMAX - pMid)*(pval - pMid)/(pEXT - pMid); + if (pval > pMAX) + pval = pMAX; + } + + return pval; +} + +/*function: black white extension parameter calculation */ +/* in: iHstBgn,iHstEnd,hstSum,lmh_lavg */ +/* out : blk_wht_ext[0],blk_wht_ext[1] */ +/* [0]: black level in u10 (0~1023) */ +/* [1]: white level in u10 (0~1023) */ +void cal_bwext_param(int *blk_wht_ext, unsigned int iHstBgn, + unsigned int iHstEnd, int hstSum, unsigned int *lmh_lavg) +{ + /* black / white extension, for IIR*/ + static int pblk_wht_extx16[2]; + int nT0, nT1; + + /* black extension */ + if (dnlp_alg_param.dnlp_blkext_rate > 0) { + blk_wht_ext[0] = (iHstBgn < lmh_lavg[0]) ? iHstBgn:lmh_lavg[0]; + blk_wht_ext[0] = (blk_wht_ext[0] > 16) ? 16 : + (blk_wht_ext[0] < 0) ? 0 : blk_wht_ext[0]; + } else + blk_wht_ext[0] = 63; + /* white extension */ + if (dnlp_alg_param.dnlp_whtext_rate > 0) { + blk_wht_ext[1] = (iHstEnd > lmh_lavg[2]) ? iHstEnd:lmh_lavg[2]; + blk_wht_ext[1] = (blk_wht_ext[1] < 48) ? 48 : + (blk_wht_ext[1] > 63) ? 63 : blk_wht_ext[1]; + } else + blk_wht_ext[1] = 63; + + /* do IIR if no scene change to keep it stable */ + if (!dnlp_scn_chg) { + nT0 = dnlp_bld_lvl * (blk_wht_ext[0]<<4) + (RBASE >> 1); + nT0 = nT0 + (RBASE - dnlp_bld_lvl) * pblk_wht_extx16[0]; + pblk_wht_extx16[0] = (nT0 >> dnlp_alg_param.dnlp_mvreflsh); + + nT1 = dnlp_bld_lvl * (blk_wht_ext[1]<<4) + (RBASE >> 1); + nT1 = nT1 + (RBASE - dnlp_bld_lvl) * pblk_wht_extx16[1]; + pblk_wht_extx16[1] = (nT1 >> dnlp_alg_param.dnlp_mvreflsh); + } + + /* output, plus fixed offset */ + blk_wht_ext[0] = (pblk_wht_extx16[0]);/* u10 */ + blk_wht_ext[1] = (pblk_wht_extx16[1]);/* u10 */ + + /* for debug */ + CrtTstDat[4] = blk_wht_ext[0]; + CrtTstDat[5] = blk_wht_ext[1]; + + if ((dnlp_printk >> 3) & 0x1) + pr_info("#step B-4.x.1(in cal_bwext_param()): iHstBgn=%d\n" + "iHstEnd=%d, lmh_lavg=[%d %d %d], bw_ext=[%d %d]\n" + "from [%d %d]\n", + iHstBgn, iHstEnd, lmh_lavg[0], + lmh_lavg[1], lmh_lavg[2], + blk_wht_ext[0], blk_wht_ext[1], + pblk_wht_extx16[0], + pblk_wht_extx16[1]); +} + + +static unsigned int dnlp_adp_cliprate(unsigned int clip_rate, + unsigned int clip_rmin, unsigned int luma_avg) +{ + unsigned int nt = clip_rate; + /* luma_avg is very low */ + if (luma_avg < dnlp_alg_param.dnlp_adpcrat_lbnd) { + /* clip_rate blend clip_rmin, blend level:luma_avg */ + nt = clip_rate * (dnlp_alg_param.dnlp_adpcrat_lbnd - luma_avg) + + clip_rmin * luma_avg; + nt = (nt << 4) + (dnlp_alg_param.dnlp_adpcrat_lbnd >> 1); + nt /= dnlp_alg_param.dnlp_adpcrat_lbnd; + } else if (luma_avg > 64 - dnlp_alg_param.dnlp_adpcrat_hbnd) { + nt = clip_rmin * (64 - luma_avg) + clip_rate * + (luma_avg + dnlp_alg_param.dnlp_adpcrat_hbnd - 64); + nt += (nt << 4) + (dnlp_alg_param.dnlp_adpcrat_hbnd >> 1); + nt /= dnlp_alg_param.dnlp_adpcrat_hbnd; + } else + nt = (clip_rmin << 4); + + return nt; +} + + +/*iHst[0:63]: [0,4)->iHst[0], [252,256)->iHst[63]*/ +/*oMap[0:64]:0:16:1024*/ +void get_clahe_curve(unsigned int *oMap, unsigned int *olAvg4, + unsigned int *iHst, int var, unsigned int hstBgn, + unsigned int hstEnd) +{ + int i = 0, j = 0, tmp, tmp1, tmp2; + unsigned int tmax = 0; + unsigned int tsum = 0, sum_clip = 0; + unsigned int oHst[64], Hst_clip[64]; + unsigned int cLmt = 0; + unsigned int tLen = (hstEnd - hstBgn); + unsigned int tAvg = 0; + unsigned int lAvg4 = 0; + unsigned int lAvg1 = 0; + unsigned int tbin, tbin_clip = 0, norm14; + int sumshft, dlt_acc[64]; + /*unsigned int uLmt = 0;*/ + /*unsigned int stp = 0;*/ + unsigned int tHst[64]; + unsigned int clip_rate = dnlp_alg_param.dnlp_cliprate_v3; + unsigned int clip_rmin = dnlp_alg_param.dnlp_cliprate_min; + unsigned int adp_crate = clip_rate;/* u8 */ + int clahe_gain_neg; + int clahe_gain_pos; + + bool prt_flg = ((dnlp_printk >> 4) & 0x1); + + if (clip_rmin > clip_rate) + clip_rmin = clip_rate; + if (dnlp_alg_param.dnlp_adpcrat_lbnd < 2) + dnlp_alg_param.dnlp_adpcrat_lbnd = 2; + else if (dnlp_alg_param.dnlp_adpcrat_lbnd > 30) + dnlp_alg_param.dnlp_adpcrat_lbnd = 30; + + if (dnlp_alg_param.dnlp_adpcrat_hbnd < 2) + dnlp_alg_param.dnlp_adpcrat_hbnd = 2; + else if (dnlp_alg_param.dnlp_adpcrat_hbnd > 30) + dnlp_alg_param.dnlp_adpcrat_hbnd = 30; + + if (hstBgn > 16) + hstBgn = 16; + + if (hstEnd > 64) + hstEnd = 64; + else if (hstEnd < 48) + hstEnd = 48; + + if (prt_flg) + pr_info("step B-2.x( get_clahe_curve): hstBgn = %d,hstEnd = %d\n", + hstBgn, hstEnd); + + oMap[64] = 1024; /* 0~1024 */ + /*4.1: loop hist 64 bins to get: max, avg, sum of hist*/ + lAvg4 = 0; + lAvg1 = 0; + for (i = 0; i < 64; i++) { + oMap[i] = (i << 4); /* 0~1024, 45 degree initialization */ + + /* limited range [4,59] */ + if (i >= hstBgn && i <= hstEnd) { + /* boundary bin use in-bound bin if it is */ + /* larger to avoid BB/WB peaks */ + tbin = (i == hstBgn && iHst[i] > iHst[i+1]) ? + iHst[i+1] : + (i == (hstEnd-1) && iHst[i] > iHst[i-1]) ? + iHst[i-1] : iHst[i]; + if (tmax < tbin) + /* max hist num within range (but not use) */ + tmax = tbin; + /* num of pixels within range */ + tsum += tbin; + /* lum sum of pixels within range */ + lAvg4 += (tbin * i); + } else + tbin = 0; + + oHst[i] = tbin; + tHst[i] = tbin;/* for clipping */ + } + if (hstEnd <= hstBgn) + return;/* set to oMap as 45 degree map */ + + lAvg4 = (lAvg4 << 2) + tsum / 2; + lAvg4 = lAvg4 / tsum;/*luminance avgerage (0~255)*/ + lAvg1 = (lAvg4 + 2) >> 2;/* bin num of average (0~63)*/ + + if (prt_flg)/* echo 4 */ + pr_info("#Step B-2.x:within range luma_avg4 = %d, max_hst(tmax) =%d\n", + lAvg4, tmax); + + /*4.2 get the adptive clip rate, << 4 */ + /* <<4, norm to 4096 as "1" */ + adp_crate = dnlp_adp_cliprate(clip_rate, clip_rmin, lAvg1); + + /* clip bin num for each bin ;max pixel num in each bin */ + cLmt = (adp_crate * tsum + 2048) >> 12; + + /*4.3 clip the histo to Hst_clip */ + sum_clip = 0; + for (i = 0; i < 64; i++) { + if (i >= hstBgn && i <= hstEnd) { + if (tHst[i] > cLmt) { + Hst_clip[i] = cLmt; + sum_clip += (tHst[i] - cLmt); + } else + Hst_clip[i] = tHst[i]; + } else + Hst_clip[i] = 0; + } + /* + *hstBgn = 0; + *hstEnd = 64; + *tLen = 64; + */ + tLen = hstEnd - hstBgn + 1; + /* clipped portion distribute to each valid bin amount */ + tAvg = (sum_clip + tLen / 2) / tLen; + + /*4.4 get the hist accum to ge delta curve*/ + /* 4.4.1 normalization gain for the histo, normlized to u14 */ + sumshft = (tsum >= (1 << 24)) ? 8 : (tsum >= (1 << 22)) ? + 6 : (tsum >= (1 << 20)) ? 4 : (tsum >= (1 << 18)) ? 2 : + (tsum >= (1<<16)) ? 0 : (tsum >= (1 << 14)) ? + -2 : (tsum >= (1 << 12)) ? -4 : (tsum >= (1 << 10)) ? + -6 : (tsum >= (1 << 8)) ? -8 : (tsum >= (1 << 6)) ? + -10 : (tsum >= (1 << 4)) ? -12 : -16; + if (sumshft >= 0) + norm14 = (1 << 30) / (tsum >> sumshft); + else if (sumshft > -16) + norm14 = (1 << (30 + sumshft)) / tsum; + else { + norm14 = 0; + return; + } + + if (prt_flg) + pr_info("# stepB-(get_clahe)CL:\n Range[hstBgn %02d ~ hstEnd %02d] lAvg4=%d(%d),\n" + "(crate /4096)=%d, tsum=%5d, cLmt=%3d, tAvg=%4d, sumshft=%d, norm14=%d\n", + hstBgn, hstEnd, lAvg4, lAvg1, adp_crate, + tsum, cLmt, tAvg, sumshft, norm14); + /* hstBgn, hstEnd must[0,64] */ + + /* hstBgn=0; */ + /* hstEnd=64; */ + sum_clip = 0; + tmp1 = 0; + clahe_gain_neg = 0; + clahe_gain_pos = 0; + for (i = 0; i < 64; i++) { + /* 4.4.3 calculate the accu and get the delta */ + if (i >= hstBgn && i <= hstEnd) { + + tbin_clip = (Hst_clip[i] + tAvg); + /*4.4.2 normalization bins to 2^16 */ + if (sumshft >= 0) + tbin_clip = ((tbin_clip >> sumshft) * norm14 + + (1 << 13)) >> 14; + else/* if (sumshft<0) */ + tbin_clip = + ((tbin_clip << (-sumshft)) * norm14 + + (1 << 13)) >> 14; + + /* acc */ + sum_clip += tbin_clip; /* 2^16 as "1" ---cdf */ + j = (i-hstBgn+1); + tmp1 = (j<<10); + /* signed dif to 45 degree line,*/ + /* normalized to u16 precision */ + dlt_acc[i] = ((int)sum_clip - tmp1); + } else + dlt_acc[i] = 0; + + tmp2 = dlt_acc[i]; + /* 4.4.3 gain to delta */ + /* if hist var is small,use clahe curve more */ + if (var < dnlp_alg_param.dnlp_var_th) { + clahe_gain_neg = + (int)dnlp_alg_param.dnlp_clahe_gain_neg + + dnlp_alg_param.dnlp_clahe_gain_delta; + clahe_gain_pos = + (int)dnlp_alg_param.dnlp_clahe_gain_pos + + dnlp_alg_param.dnlp_clahe_gain_delta; + } else { + clahe_gain_neg = dnlp_alg_param.dnlp_clahe_gain_neg; + clahe_gain_pos = dnlp_alg_param.dnlp_clahe_gain_pos; + } + + if (dlt_acc[i] < 0) + /* apply the gain of CLAHE, */ + dlt_acc[i] = (dlt_acc[i] * (int)clahe_gain_neg + 128) + / 256; + else + dlt_acc[i] = (dlt_acc[i] * (int)clahe_gain_pos + 128) + / 256; + + /* get the omap and clip to range */ + tmp = (i << 10) + (dlt_acc[i]); /* normalized to u16 */ + tmp = (tmp < 0) ? 0 : tmp; + tmp = (tmp + 32) >> 6; + oMap[i] = (tmp > 1023) ? 1023 : tmp; + + if (prt_flg)/* echo 4 */ + pr_info("StepB-2.x:CLASHE:\n[%02d:iHst=%5d,Hclip=%5d,bin_clip=%5d]:[sum_clp=%5d,j=%2d,tmp1=%6d,tmp2=%6d]%4d(45lin)+%5d(dlt_acc)=>%4d(C)],\n", + i, iHst[i], Hst_clip[i], + tbin_clip, sum_clip, j, + tmp1, tmp2, i<<4, + dlt_acc[i]/64, oMap[i]); + } + + /* 4.5 output the *olAvg4 */ + *olAvg4 = lAvg4; + + if (debug_add_curve_en) { + for (i = 0; i < 65; i++) { + oMap[i] = ((128 - glb_clash_curve_bld_rate) * oMap[i] + + glb_clash_curve_bld_rate * + (glb_clash_curve[i]<<2) + + 64) >> 7; + } + } + /* debug */ + CrtTstDat[2] = hstBgn; + CrtTstDat[3] = hstEnd; + + if ((dnlp_printk >> 14) & 0x1) + pr_info("\n@@@get_clahe_curve(): clahe_gain_neg = %d,clahe_gain_pos = %d\n ", + clahe_gain_neg, clahe_gain_pos); + + if (prt_flg) + for (i = hstBgn; i < hstEnd; i++) + pr_info("Step B-2.x #clsh: [(index)%02d: (iHst)%5d]:(45line) %4d => (clsh) %4d],\n", + i, iHst[i], i << 4, oMap[i]); + + if ((dnlp_printk >> 14) & 0x1) { + /* iHst */ + pr_info("\n=====pre_0_gma: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + iHst[i], iHst[i+1], + iHst[i+2], iHst[i+3], + iHst[i+4], iHst[i+5], + iHst[i+6], iHst[i+7], + iHst[i+8], iHst[i+9], + iHst[i+10], iHst[i+11], + iHst[i+12], iHst[i+13], + iHst[i+14], iHst[i+15]); + } + pr_info("]\n"); + + /* clip_Hst */ + pr_info("\n=====clipped pre_0_gma: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + Hst_clip[i] + tAvg, Hst_clip[i+1] + tAvg, + Hst_clip[i+2] + tAvg, Hst_clip[i+3] + tAvg, + Hst_clip[i+4] + tAvg, Hst_clip[i+5] + tAvg, + Hst_clip[i+6] + tAvg, Hst_clip[i+7] + tAvg, + Hst_clip[i+8] + tAvg, Hst_clip[i+9] + tAvg, + Hst_clip[i+10] + tAvg, Hst_clip[i+11] + tAvg, + Hst_clip[i+12] + tAvg, Hst_clip[i+13] + tAvg, + Hst_clip[i+14] + tAvg, Hst_clip[i+15] + tAvg); + } + pr_info("]\n"); + + /* clash_curve */ + pr_info("\n=====clash_curve: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + oMap[i], oMap[i+1], oMap[i+2], oMap[i+3], + oMap[i+4], oMap[i+5], oMap[i+6], oMap[i+7], + oMap[i+8], oMap[i+9], oMap[i+10], oMap[i+11], + oMap[i+12], oMap[i+13], oMap[i+14], oMap[i+15]); + } + pr_info("]\n"); + } +} + + +/*functon: brightness calculated baed on luma_avg and low_lavg4, + *IIR filtered;for black white extension + *in: luma_avg4,low_lavg4 + *(return)out: dnlp_brightness + */ +/* TBC: how it works? */ +static int cal_brght_plus(int luma_avg4, int low_lavg4) +{ + int avg_dif = 0; + int dif_rat = 0; + int low_rng = 0; + int low_rat = 0; + + int dnlp_brightness = 0; + static int pbrtness; + + if (luma_avg4 > low_lavg4) + avg_dif = luma_avg4 - low_lavg4; + + if (avg_dif < dnlp_alg_param.dnlp_blk_cctr) + dif_rat = dnlp_alg_param.dnlp_blk_cctr - avg_dif; + + if (luma_avg4 > dnlp_alg_param.dnlp_brgt_ctrl) + low_rng = luma_avg4 - dnlp_alg_param.dnlp_brgt_ctrl; + else + low_rng = dnlp_alg_param.dnlp_brgt_ctrl - luma_avg4; + + if (low_rng < dnlp_alg_param.dnlp_brgt_range) + low_rat = dnlp_alg_param.dnlp_brgt_range - low_rng; + + /* <<2 */ + dnlp_brightness = + (dnlp_alg_param.dnlp_brght_max*dif_rat*low_rat + 16) >> 5; + /* add=32 => add 0 */ + dnlp_brightness += ((dnlp_alg_param.dnlp_brght_add - 32) << 2); + + if (!dnlp_scn_chg) { + dnlp_brightness = dnlp_bld_lvl * dnlp_brightness + (RBASE >> 1); + dnlp_brightness = dnlp_brightness + + (RBASE - dnlp_bld_lvl) * pbrtness; + dnlp_brightness = + (dnlp_brightness >> dnlp_alg_param.dnlp_mvreflsh); + } + pbrtness = dnlp_brightness; + + /* debug */ + CrtTstDat[12] = low_lavg4; + CrtTstDat[14] = dnlp_brightness; + + return dnlp_brightness; /* 0 ~ 1024 */ +} + + +static void clahe_tiir(void) +{ + int i = 0; + int nTmp0 = 0; + static unsigned int pgmma[65]; + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) + pgmma[i] = (i << 4); /* 0 ~1024 */ + } + + if (!dnlp_scn_chg && ((dnlp_alg_param.dnlp_dbg_i2r >> 3) & 0x1)) + for (i = 0; i < 65; i++) { + nTmp0 = dnlp_bld_lvl * clash_curve[i] + (RBASE >> 1); + nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma[i]; + nTmp0 = (nTmp0 >> dnlp_alg_param.dnlp_mvreflsh); + clash_curve[i] = nTmp0; + } + + for (i = 0; i < 65; i++) + pgmma[i] = clash_curve[i]; +} + +/*function:iir filter coef cal base on the luma_avg change in time domain */ +/* in : hstSum, rbase */ +/* out: */ +/* return: bld_lvl (tiir coefs) */ +int curve_rfrsh_chk(int hstSum, int rbase) +{ + static unsigned int tLumAvg[30]; + static unsigned int tAvgDif[30]; + bool prt_flg = 0; + int lSby = 0; + int bld_lvl = 0; + int i = 0; + + for (i = 0; i < 29; i++) { + tLumAvg[i] = tLumAvg[i+1]; + tAvgDif[i] = tAvgDif[i+1]; + } + + tLumAvg[29] = (ve_dnlp_luma_sum + (hstSum >> 1)) / hstSum; + tLumAvg[29] = ((tLumAvg[29] + 4) >> 3); + tAvgDif[29] = (tLumAvg[29] > tLumAvg[28]) ? + (tLumAvg[29] - tLumAvg[28]) : (tLumAvg[28] - tLumAvg[29]); + + /* prt_flg = ((dnlp_printk >> 7) & 0x1); */ + prt_flg = (dnlp_printk & 0x1); + + lSby = 0; + for (i = 0; i < 8; i++) + lSby = lSby + tAvgDif[28 - i]; + lSby = ((lSby + 4) >> 3); + + if (tAvgDif[29] > tAvgDif[28]) + bld_lvl = tAvgDif[29] - tAvgDif[28]; + else + bld_lvl = tAvgDif[28] - tAvgDif[29]; + + bld_lvl = (bld_lvl << dnlp_alg_param.dnlp_schg_sft); + + if (prt_flg) + pr_info("step 0.2.0: bld_lvl=%02d\n", bld_lvl); + + /* play station: return with black scene intersection */ + if (tAvgDif[29] > bld_lvl) + bld_lvl = tAvgDif[29]; + + if (bld_lvl > rbase) + bld_lvl = rbase; + else if (bld_lvl < dnlp_alg_param.dnlp_cuvbld_min) + bld_lvl = dnlp_alg_param.dnlp_cuvbld_min; + else if (bld_lvl > dnlp_alg_param.dnlp_cuvbld_max) + bld_lvl = dnlp_alg_param.dnlp_cuvbld_max; + + /* print the logs */ + if (prt_flg) { + pr_info("step 0.2.1: bld_lvl=%02d, lSby=%02d\n", + bld_lvl, lSby); + for (i = 0; i < 10; i++) + pr_info("tLumAvg[%d]: = %d\n", + i, tLumAvg[29 - i]); + for (i = 0; i < 10; i++) + pr_info("tAvgDif[%d]: = %d\n", + i, tAvgDif[29 - i]); + } + + CrtTstDat[0] = bld_lvl; + /* post processing */ + if (dnlp_alg_param.dnlp_respond_flag) { + bld_lvl = RBASE; + dnlp_scn_chg = 1; + } else if (bld_lvl >= RBASE) { + bld_lvl = RBASE; + dnlp_scn_chg = 1; + } + CrtTstDat[1] = bld_lvl; + + return bld_lvl; /* tiir coefs */ +} + + +static void dnlp3_param_refrsh(void) +{ + if (dnlp_alg_param.dnlp_respond) { + if ((prev_dnlp_mvreflsh != dnlp_alg_param.dnlp_mvreflsh) || + (prev_dnlp_final_gain != + dnlp_alg_param.dnlp_final_gain) || + (prev_dnlp_clahe_gain_neg != + dnlp_alg_param.dnlp_clahe_gain_neg) || + (prev_dnlp_clahe_gain_pos != + dnlp_alg_param.dnlp_clahe_gain_pos) || + + (prev_dnlp_gmma_rate != ve_dnlp_gmma_rate) || + (prev_dnlp_lowalpha_v3 != ve_dnlp_lowalpha_v3) || + (prev_dnlp_hghalpha_v3 != ve_dnlp_hghalpha_v3) || + (prev_dnlp_sbgnbnd != dnlp_alg_param.dnlp_sbgnbnd) || + (prev_dnlp_sendbnd != dnlp_alg_param.dnlp_sendbnd) || + (prev_dnlp_cliprate_v3 != + dnlp_alg_param.dnlp_cliprate_v3) || + (prev_dnlp_clashBgn != dnlp_alg_param.dnlp_clashBgn) || + (prev_dnlp_clashEnd != dnlp_alg_param.dnlp_clashEnd) || + (prev_dnlp_mtdbld_rate != + dnlp_alg_param.dnlp_mtdbld_rate) || + (prev_dnlp_pst_gmarat != ve_dnlp_pst_gmarat) || + (prev_dnlp_blk_cctr != + dnlp_alg_param.dnlp_blk_cctr) || + (prev_dnlp_brgt_ctrl != + dnlp_alg_param.dnlp_brgt_ctrl) || + (prev_dnlp_brgt_range != + dnlp_alg_param.dnlp_brgt_range) || + (prev_dnlp_brght_add != + dnlp_alg_param.dnlp_brght_add) || + (prev_dnlp_brght_max != + dnlp_alg_param.dnlp_brght_max) || + (prev_dnlp_lgst_ratio != ve_dnlp_lgst_ratio) || + (prev_dnlp_lgst_dst != ve_dnlp_lgst_dst) || + (prev_dnlp_almst_wht != ve_dnlp_almst_wht) || + (prev_dnlp_pstgma_end != ve_dnlp_pstgma_end) || + (prev_dnlp_pstgma_ratio != ve_dnlp_pstgma_ratio) || + (prev_dnlp_pstgma_brghtrate != + ve_dnlp_pstgma_brghtrate) || + (prev_dnlp_pstgma_brghtrat1 != + ve_dnlp_pstgma_brghtrat1) || + (prev_dnlp_blkext_rate != + dnlp_alg_param.dnlp_blkext_rate) || + (prev_dnlp_whtext_rate != + dnlp_alg_param.dnlp_whtext_rate) || + (prev_dnlp_blkext_ofst != + dnlp_alg_param.dnlp_blkext_ofst) || + (prev_dnlp_whtext_ofst != + dnlp_alg_param.dnlp_whtext_ofst) || + (prev_dnlp_bwext_div4x_min != + dnlp_alg_param.dnlp_bwext_div4x_min) || + (prev_dnlp_schg_sft != + dnlp_alg_param.dnlp_schg_sft) || + (prev_dnlp_smhist_ck != + dnlp_alg_param.dnlp_smhist_ck) || + (prev_dnlp_cuvbld_min != + dnlp_alg_param.dnlp_cuvbld_min) || + (prev_dnlp_cuvbld_max != + dnlp_alg_param.dnlp_cuvbld_max) || + (prev_dnlp_dbg_map != + dnlp_alg_param.dnlp_dbg_map) || + (prev_dnlp_dbg_adjavg != + dnlp_alg_param.dnlp_dbg_adjavg) || + (prev_dnlp_dbg_i2r != + dnlp_alg_param.dnlp_dbg_i2r) || + (prev_dnlp_slow_end != ve_dnlp_slow_end) || + (prev_dnlp_pavg_btsft != + dnlp_alg_param.dnlp_pavg_btsft) || + (prev_dnlp_cliprate_min != + dnlp_alg_param.dnlp_cliprate_min) || + (prev_dnlp_adpcrat_lbnd != + dnlp_alg_param.dnlp_adpcrat_lbnd) || + (prev_dnlp_adpcrat_hbnd != + dnlp_alg_param.dnlp_adpcrat_hbnd) || + (prev_dnlp_adpmtd_lbnd != + dnlp_alg_param.dnlp_adpmtd_lbnd) || + (prev_dnlp_adpmtd_hbnd != + dnlp_alg_param.dnlp_adpmtd_hbnd) || + (prev_dnlp_satur_rat != + dnlp_alg_param.dnlp_satur_rat) || + (prev_dnlp_satur_max != + dnlp_alg_param.dnlp_satur_max) || + (prev_dnlp_set_saturtn != + dnlp_alg_param.dnlp_set_saturtn) || + + (prev_dnlp_lowrange != dnlp_alg_param.dnlp_lowrange) || + (prev_dnlp_hghrange != dnlp_alg_param.dnlp_hghrange) || + (prev_dnlp_auto_rng != dnlp_alg_param.dnlp_auto_rng) || + (prev_dnlp_bbd_ratio_low != + dnlp_alg_param.dnlp_bbd_ratio_low) || + (prev_dnlp_bbd_ratio_hig != + dnlp_alg_param.dnlp_bbd_ratio_hig) || + (prev_dnlp_adpalpha_lrate != + ve_dnlp_adpalpha_lrate) || + (prev_dnlp_adpalpha_hrate != + ve_dnlp_adpalpha_hrate)) + dnlp_alg_param.dnlp_respond_flag = 1; + else + dnlp_alg_param.dnlp_respond_flag = 0; + } + + prev_dnlp_mvreflsh = dnlp_alg_param.dnlp_mvreflsh; + prev_dnlp_final_gain = dnlp_alg_param.dnlp_final_gain; + prev_dnlp_clahe_gain_neg = + dnlp_alg_param.dnlp_clahe_gain_neg; /* clahe_gain */ + prev_dnlp_clahe_gain_pos = + dnlp_alg_param.dnlp_clahe_gain_pos; /* clahe_gain */ + prev_dnlp_gmma_rate = ve_dnlp_gmma_rate; + prev_dnlp_lowalpha_v3 = ve_dnlp_lowalpha_v3; + prev_dnlp_hghalpha_v3 = ve_dnlp_hghalpha_v3; + prev_dnlp_sbgnbnd = dnlp_alg_param.dnlp_sbgnbnd; + prev_dnlp_sendbnd = dnlp_alg_param.dnlp_sendbnd; + prev_dnlp_cliprate_v3 = dnlp_alg_param.dnlp_cliprate_v3; + prev_dnlp_clashBgn = dnlp_alg_param.dnlp_clashBgn; + prev_dnlp_clashEnd = dnlp_alg_param.dnlp_clashEnd; + prev_dnlp_mtdbld_rate = dnlp_alg_param.dnlp_mtdbld_rate; + prev_dnlp_pst_gmarat = ve_dnlp_pst_gmarat; + prev_dnlp_blk_cctr = dnlp_alg_param.dnlp_blk_cctr; + prev_dnlp_brgt_ctrl = dnlp_alg_param.dnlp_brgt_ctrl; + prev_dnlp_brgt_range = dnlp_alg_param.dnlp_brgt_range; + prev_dnlp_brght_add = dnlp_alg_param.dnlp_brght_add; + prev_dnlp_brght_max = dnlp_alg_param.dnlp_brght_max; + prev_dnlp_lgst_ratio = ve_dnlp_lgst_ratio; + prev_dnlp_lgst_dst = ve_dnlp_lgst_dst; + prev_dnlp_almst_wht = ve_dnlp_almst_wht; + + prev_dnlp_pstgma_end = ve_dnlp_pstgma_end; + prev_dnlp_pstgma_ratio = ve_dnlp_pstgma_ratio; + prev_dnlp_pstgma_brghtrate = ve_dnlp_pstgma_brghtrate; + prev_dnlp_pstgma_brghtrat1 = ve_dnlp_pstgma_brghtrat1; + + prev_dnlp_blkext_rate = dnlp_alg_param.dnlp_blkext_rate; + prev_dnlp_whtext_rate = dnlp_alg_param.dnlp_whtext_rate; + prev_dnlp_blkext_ofst = dnlp_alg_param.dnlp_blkext_ofst; + prev_dnlp_whtext_ofst = dnlp_alg_param.dnlp_whtext_ofst; + prev_dnlp_bwext_div4x_min = dnlp_alg_param.dnlp_bwext_div4x_min; + + prev_dnlp_schg_sft = dnlp_alg_param.dnlp_schg_sft; + + prev_dnlp_smhist_ck = dnlp_alg_param.dnlp_smhist_ck; + prev_dnlp_cuvbld_min = dnlp_alg_param.dnlp_cuvbld_min; + prev_dnlp_cuvbld_max = dnlp_alg_param.dnlp_cuvbld_max; + prev_dnlp_dbg_map = dnlp_alg_param.dnlp_dbg_map; + prev_dnlp_dbg_adjavg = dnlp_alg_param.dnlp_dbg_adjavg; + prev_dnlp_dbg_i2r = dnlp_alg_param.dnlp_dbg_i2r; + prev_dnlp_slow_end = ve_dnlp_slow_end; + prev_dnlp_pavg_btsft = dnlp_alg_param.dnlp_pavg_btsft; + prev_dnlp_pavg_btsft = dnlp_alg_param.dnlp_pavg_btsft; + prev_dnlp_cliprate_min = dnlp_alg_param.dnlp_cliprate_min; + prev_dnlp_adpcrat_lbnd = dnlp_alg_param.dnlp_adpcrat_lbnd; + prev_dnlp_adpcrat_hbnd = dnlp_alg_param.dnlp_adpcrat_hbnd; + + prev_dnlp_adpmtd_lbnd = dnlp_alg_param.dnlp_adpmtd_lbnd; + prev_dnlp_adpmtd_hbnd = dnlp_alg_param.dnlp_adpmtd_hbnd; + + prev_dnlp_satur_rat = dnlp_alg_param.dnlp_satur_rat; + prev_dnlp_satur_max = dnlp_alg_param.dnlp_satur_max; + prev_dnlp_set_saturtn = dnlp_alg_param.dnlp_set_saturtn; + + prev_dnlp_lowrange = dnlp_alg_param.dnlp_lowrange; + prev_dnlp_hghrange = dnlp_alg_param.dnlp_hghrange; + prev_dnlp_auto_rng = dnlp_alg_param.dnlp_auto_rng; + + prev_dnlp_bbd_ratio_low = dnlp_alg_param.dnlp_bbd_ratio_low; + prev_dnlp_bbd_ratio_hig = dnlp_alg_param.dnlp_bbd_ratio_hig; + prev_dnlp_adpalpha_hrate = ve_dnlp_adpalpha_hrate; + prev_dnlp_adpalpha_lrate = ve_dnlp_adpalpha_lrate; +} + + +static void dnlp_rfrsh_subgmma(void) +{ + int i = 0; + static unsigned int pgmma0[65]; /* 0~4096*/ + static unsigned int pgmma1[65]; + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) { + pgmma0[i] = (i << 6); /* 0 ~4096 */ + pgmma1[i] = (i << 6); /* 0 ~4096 */ + } + } + + if (!dnlp_scn_chg) + for (i = 0; i < 65; i++) { + gma_scurve0[i] = dnlp_bld_lvl * + (gma_scurve0[i] << 2) + (RBASE >> 1); + gma_scurve1[i] = dnlp_bld_lvl * + (gma_scurve1[i] << 2) + (RBASE >> 1); + + gma_scurve0[i] = gma_scurve0[i] + + (RBASE - dnlp_bld_lvl) * pgmma0[i]; + gma_scurve1[i] = gma_scurve1[i] + + (RBASE - dnlp_bld_lvl) * pgmma1[i]; + + gma_scurve0[i] = (gma_scurve0[i] >> + dnlp_alg_param.dnlp_mvreflsh); + gma_scurve1[i] = (gma_scurve1[i] >> + dnlp_alg_param.dnlp_mvreflsh); + + pgmma0[i] = gma_scurve0[i]; /* 0~ 4095 */ + pgmma1[i] = gma_scurve1[i]; /* 0~ 4095 */ + + gma_scurve0[i] = (gma_scurve0[i] + 2) >> 2; /* 1023 */ + gma_scurve1[i] = (gma_scurve1[i] + 2) >> 2; /* 1023 */ + } + else + for (i = 0; i < 65; i++) { + pgmma0[i] = (gma_scurve0[i] << 2); + pgmma1[i] = (gma_scurve1[i] << 2); + } +} + + +/* function: IIR filter (time domain) on the input histogram and luma__sum*/ +/* in&out: pre_0_gamma, luma_sum (ve_luma_sum)*/ +static void dnlp_inhist_tiir(void) +{ + int i = 0; + int nTmp = 0; + static unsigned int pgmma0[65]; + /* local static variables for IIR filter */ + static unsigned int luma_sum; + + if (!dnlp_scn_chg && (dnlp_alg_param.dnlp_dbg_i2r & 0x1)) { + for (i = 0; i < 65; i++) { + nTmp = dnlp_bld_lvl * pre_0_gamma[i] + (RBASE >> 1); + nTmp = nTmp + (RBASE - dnlp_bld_lvl) * pgmma0[i]; + nTmp = (nTmp >> dnlp_alg_param.dnlp_mvreflsh); + pre_0_gamma[i] = nTmp; + } + + nTmp = dnlp_bld_lvl * ve_dnlp_luma_sum + (RBASE >> 1); + nTmp = nTmp + (RBASE - dnlp_bld_lvl) * luma_sum; + nTmp = (nTmp >> dnlp_alg_param.dnlp_mvreflsh); + ve_dnlp_luma_sum = nTmp; + } + + for (i = 0; i < 65; i++) + pgmma0[i] = pre_0_gamma[i]; + luma_sum = ve_dnlp_luma_sum; +} + +/*0 ~ 65*/ +/* in : gmma_rate, low_alpha, hgh_alpha (from dnlp_params_hist()),*/ +/* lsft_avg(from cal_hst_shft_avf() )*/ +/* out: gma_scurvet (0~65) */ +static void dnlp_gmma_cuvs(unsigned int gmma_rate, + unsigned int low_alpha, unsigned int hgh_alpha, + unsigned int lsft_avg) +{ + int i = 0; + int j = 0; + int nTmp = 0; + unsigned int luma_avg4 = (lsft_avg >> dnlp_alg_param.dnlp_pavg_btsft); + + static unsigned int pgmma[65]; + bool prt_flg = ((dnlp_printk >> 3) & 0x1); + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) + pgmma[i] = (i << 6); /* 0 ~4096 */ + } + + /* refresh sub gamma */ + if ((dnlp_alg_param.dnlp_dbg_i2r >> 1) & 0x1) + dnlp_rfrsh_subgmma(); + + + for (i = 0; i < 65; i++) { + nTmp = (((256 - gmma_rate)*gma_scurve0[i] + + gma_scurve1[i]*gmma_rate + 128) >> 8); /* 0 ~1023 */ + + if (nTmp <= (luma_avg4<<2)) + nTmp = (nTmp*(64 - low_alpha) + + (low_alpha*i<<4) + 8)>>4; /*4096*/ + else + nTmp = (nTmp*(64 - hgh_alpha) + + (hgh_alpha*i<<4) + 8)>>4; + + if (debug_add_curve_en) { + nTmp = ((128 - glb_scurve_bld_rate)*nTmp + + glb_scurve_bld_rate*(glb_scurve[i]<<4) + 64)>>7; + } + + if (nTmp < 0) + nTmp = 0; + else if (nTmp > 4095) + nTmp = 4095; + gma_scurvet[i] = nTmp; + + if (prt_flg) + pr_info("Step D-1.z: gmma_cuvs_bld: [%02d] (s0)%4d (s1)%4d => (s)%4d\n", + i, gma_scurve0[i], gma_scurve1[i], + gma_scurvet[i]); + } + + if (!dnlp_scn_chg && ((dnlp_alg_param.dnlp_dbg_i2r >> 2) & 0x1)) + for (i = 0; i < 65; i++) { + nTmp = dnlp_bld_lvl * gma_scurvet[i] + (RBASE >> 1); + nTmp = nTmp + (RBASE - dnlp_bld_lvl) * pgmma[i]; + nTmp = (nTmp >> dnlp_alg_param.dnlp_mvreflsh); + + gma_scurvet[i] = nTmp; /* 4095 */ + } + + for (i = 0; i < 65; i++) + pgmma[i] = gma_scurvet[i]; /* 4095 */ + + for (i = 0; i < 65; i++) + gma_scurvet[i] = ((gma_scurvet[i] + 2) >> 2); /*1023*/ + + /* for debug */ + CrtTstDat[24] = gmma_rate; + CrtTstDat[25] = low_alpha; + CrtTstDat[26] = hgh_alpha; + CrtTstDat[27] = lsft_avg; + if (prt_flg) { + pr_info("Step D-1.z: gmma_cuvs_bld: gma_scurvet cal paramets: lsft_avg=%d gmma_rate=%d low_alpha%d hgh_alpha=%d\n", + lsft_avg, gmma_rate, low_alpha, hgh_alpha); + } + + + /* --draw curve */ + if ((dnlp_printk>>14) & 0x1) { + pr_info("\n#### gma_s_bld: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + gma_scurvet[i], + gma_scurvet[i+1], + gma_scurvet[i+2], + gma_scurvet[i+3], + gma_scurvet[i+4], + gma_scurvet[i+5], + gma_scurvet[i+6], + gma_scurvet[i+7], + gma_scurvet[i+8], + gma_scurvet[i+9], + gma_scurvet[i+10], + gma_scurvet[i+11], + gma_scurvet[i+12], + gma_scurvet[i+13], + gma_scurvet[i+14], + gma_scurvet[i+15]); + } + pr_info(" %d ]\n", gma_scurvet[64]); + + } + +} + + +/* clsh_scvbld = clash_curve + gma_scurvet */ +/* in : mtdbld_rate(from dnlp_adp_alpharate() )*/ +/* out: clsh_scvbld */ +static void dnlp_clsh_sbld(unsigned int mtdbld_rate) +{ + int i = 0; + int j = 0; + int nTmp0 = 0; + + static unsigned int pgmma[65]; + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) + pgmma[i] = (i << 4); /* 0 ~1024 */ + } + + for (i = 0; i < 65; i++) { + /* nTmp0 = gma_scurvet[i];*/ /* 0 ~1024 */ + nTmp0 = GmScurve[i];/* GmScurve,new s_curve 2017.12.23 */ + nTmp0 = nTmp0*mtdbld_rate + clash_curve[i]*(64 - mtdbld_rate); + nTmp0 = (nTmp0 + 32)>>6; /* 0~1024 */ + clsh_scvbld[i] = nTmp0; + + if ((dnlp_printk>>5) & 0x1) + pr_info("Step D-2.z: clsh_sbld_bld(curvs): GmScurve=%d, clash_curve=%d => clsh_scvbld=%d\n", + GmScurve[i], clash_curve[i], clsh_scvbld[i]); + } + if ((dnlp_printk>>14) & 0x1) + pr_info(" @@@ in dnlp_clsh_sbld(before use): mtdbld_rate=%d, dnlp_bld_lvl=%d, dbg_i2r=%d, scn_chg=%d\n", + mtdbld_rate, dnlp_bld_lvl, + dnlp_alg_param.dnlp_dbg_i2r, dnlp_scn_chg); + + if (!dnlp_scn_chg && ((dnlp_alg_param.dnlp_dbg_i2r >> 4) & 0x1)) + for (i = 0; i < 65; i++) { + nTmp0 = dnlp_bld_lvl * clsh_scvbld[i] + (RBASE >> 1); + nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma[i]; + nTmp0 = (nTmp0 >> dnlp_alg_param.dnlp_mvreflsh); + if ((dnlp_printk>>5) & 0x1) + pr_info("Step D-2.z: clsh_sbld_iir: clsh_scvbld=%d, pre=%d => crt=%d\n", + clsh_scvbld[i], pgmma[i], nTmp0); + clsh_scvbld[i] = nTmp0; + } + + for (i = 0; i < 65; i++) + pgmma[i] = clsh_scvbld[i]; /* 1023 */ + + /* --draw curve */ + if ((dnlp_printk>>14) & 0x1) { + pr_info("\n#### clsh_scv_bld: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + clsh_scvbld[i], clsh_scvbld[i+1], + clsh_scvbld[i+2], clsh_scvbld[i+3], + clsh_scvbld[i+4], clsh_scvbld[i+5], + clsh_scvbld[i+6], clsh_scvbld[i+7], + clsh_scvbld[i+8], clsh_scvbld[i+9], + clsh_scvbld[i+10], clsh_scvbld[i+11], + clsh_scvbld[i+12], clsh_scvbld[i+13], + clsh_scvbld[i+14], clsh_scvbld[i+15]); + } + pr_info(" %d ]\n", clsh_scvbld[64]); + + } + + + +} + + +/* in : blk_gma_rat[64] (from get_blk_gma_rat() ) */ +/* out : blk_gma_bld = blk_gma_crv + clsh_scvbld */ +static void dnlp_blkgma_bld(unsigned int *blk_gma_rat) +{ + int nT1 = 0; + int nTmp0 = 0; + int i = 0; + int j = 0; + static unsigned int pgmma[65]; + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) + pgmma[i] = (i << 4); /* 0 ~1024 */ + } + if (dnlp_printk & 0x1) { + pr_info("\n****blk_gma_rat[64] in dnlp_blkgma_bld() before use:\n "); + for (i = 0; i < 64; i++) + pr_info("%4d, ", blk_gma_rat[i]); + } + + for (i = 0; i < 64; i++) { + nT1 = blk_gma_rat[i]; + nTmp0 = clsh_scvbld[i]; + + nTmp0 = blk_gma_crv[i]*nT1 + nTmp0*(64 - nT1); + nTmp0 = (nTmp0+32)>>6; /* 0~1024 */ + blk_gma_bld[i] = nTmp0; + + if (debug_add_curve_en) { + blk_gma_bld[i] = + ((128 - glb_pst_gamma_bld_rate)*blk_gma_bld[i] + + glb_pst_gamma_bld_rate*(glb_pst_gamma[i]<<2) + 64)>>7; + } + + if ((dnlp_printk >> 7) & 0x1) + pr_info("Step D-3.z: (clsh_scvbld)%04d, (blk_gma_crv)%04d * (blk_gma_rat)%04d => (blk_gma_bld)%04d\n", + clsh_scvbld[i], blk_gma_crv[i], nT1, nTmp0); + } + blk_gma_bld[64] = 1023; + + if (!dnlp_scn_chg && ((dnlp_alg_param.dnlp_dbg_i2r >> 5) & 0x1)) + for (i = 0; i < 65; i++) { + nTmp0 = dnlp_bld_lvl * blk_gma_bld[i] + (RBASE >> 1); + nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pgmma[i]; + nTmp0 = (nTmp0 >> dnlp_alg_param.dnlp_mvreflsh); + + blk_gma_bld[i] = nTmp0; + } + + for (i = 0; i < 65; i++) + pgmma[i] = blk_gma_bld[i]; /* 1023 */ + +/* --draw curve */ + if ((dnlp_printk>>14) & 0x1) { + pr_info("\n#### blk_gma_bld: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + blk_gma_bld[i], blk_gma_bld[i+1], + blk_gma_bld[i+2], blk_gma_bld[i+3], + blk_gma_bld[i+4], blk_gma_bld[i+5], + blk_gma_bld[i+6], blk_gma_bld[i+7], + blk_gma_bld[i+8], blk_gma_bld[i+9], + blk_gma_bld[i+10], blk_gma_bld[i+11], + blk_gma_bld[i+12], blk_gma_bld[i+13], + blk_gma_bld[i+14], blk_gma_bld[i+15]); + } + pr_info(" %d ]\n", blk_gma_bld[64]); + + } + + +} + + +/* blkwht_ebld = blk_gma_bld + extension */ +/* input: blk_gma_bld[] , blk_wht_ext(from cal_bwext_param() ), + * dnlp_brightness (from cal_brght_plus() ), luma_avg4,luma_avg, + * iRgnBgn,iRgnEnd + */ +/* output: blkwht_ebld[] */ +static void dnlp_blkwht_bld(int *o_curv, int *i_curv, + int *blk_wht_ext, int bright, + unsigned int luma_avg4, unsigned int luma_avg, + unsigned int iRgnBgn, unsigned int iRgnEnd) +{ + int i, j, i4; + int tmp0, tmp1, margin_wht64x, margin_blk64x; + int div4x[4], dist4, mid4, lft4, rgh4, divd; + int margin64x, delta, st, ed, whtext_gain; + /* local of bw extension */ + static unsigned int bwext_curv[65]; + /* get it parametered */ + int min_div4x = dnlp_alg_param.dnlp_bwext_div4x_min; + int prt_flg = ((dnlp_printk >> 9) & 0x1); + + /* adaptive calc on bin st and ed. */ + st = iRgnBgn - dnlp_alg_param.dnlp_blkext_ofst; if (st < 0) st = 0; + ed = iRgnEnd + dnlp_alg_param.dnlp_whtext_ofst; if (ed > 63) ed = 63; + if (prt_flg) { + pr_info("stepD-4.z: blk/wht ext: blk_wht_ext[%d %d] + bright%d, Rgn=[%d %d], sted[%d %d]\n", + blk_wht_ext[0], blk_wht_ext[1], + bright, iRgnBgn, iRgnEnd, st, ed); + } + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) + bwext_curv[i] = (i << 4); /* 0 ~1024 */ + } + + /* get the maximum margin for BW extension */ + tmp0 = (luma_avg < 48) ? luma_avg:47; + /* norm to 256 as 1, white region will + * not apply strong white extension + */ + whtext_gain = wext_gain[tmp0]; + whtext_gain = (whtext_gain*dnlp_alg_param.dnlp_whtext_rate)>>8; + + margin_blk64x = (i_curv[blk_wht_ext[0]>>4]-(st<<4)); + if (margin_blk64x < 0) + margin_blk64x = 0; + margin_wht64x = ((ed<<4) - i_curv[blk_wht_ext[1]>>4]); + if (margin_wht64x < 0) + margin_wht64x = 0; + margin_blk64x = margin_blk64x*dnlp_alg_param.dnlp_blkext_rate;/* 32 */ + margin_wht64x = margin_wht64x*whtext_gain; + + /* get the mid point blk and wht to the luma_avg */ + lft4 = (blk_wht_ext[0]>>2); + rgh4 = (blk_wht_ext[1]>>2); + if (luma_avg4 < lft4) + mid4 = (lft4); + else if (luma_avg4 > rgh4) + mid4 = (rgh4); + else + mid4 = luma_avg4; + + div4x[0] = mid4 - (lft4); + if (div4x[0] < min_div4x) + div4x[0] = min_div4x; + div4x[1] = (rgh4) - mid4; + if (div4x[1] < min_div4x) + div4x[1] = min_div4x; + div4x[2] = (lft4) - (st<<2); + if (div4x[2] < min_div4x) + div4x[2] = min_div4x; + div4x[3] = (ed<<2) - (rgh4); + if (div4x[3] < min_div4x) + div4x[3] = min_div4x; + + if (prt_flg) + pr_info("bwext: lft4=%04d, mid4=%04d, rgh4=%4d, div4x=[%4d %4d %4d %4d]\n", + lft4, mid4, rgh4, div4x[0], + div4x[1], div4x[2], div4x[3]); + + /* black / white extension */ + for (i = 0; i < 64; i++) { + i4 = (i<<2); + if (i4 <= lft4) { + dist4 = i4 - (st<<2); + divd = div4x[2]; + margin64x = -margin_blk64x; + } else if (i4 < mid4) { + dist4 = (mid4 - i4); + divd = div4x[0]; + margin64x = -margin_blk64x; + } else if (i4 < rgh4) { + dist4 = (i4 - mid4); + divd = div4x[1]; + margin64x = margin_wht64x; + } else { + dist4 = ((ed<<2) - i4); + divd = div4x[3]; + margin64x = margin_wht64x; + } + + /* calculate the delta */ + if (dist4 > 0) { + delta = margin64x*dist4/divd; + delta = (delta > 0) ? (delta>>6) : + (delta < 0) ? (-((-delta)>>6)) : 0; + } else + delta = 0; + + /* nTmp += dnlp_brightness; */ + tmp0 = bright + delta + (int)i_curv[i]; + if (tmp0 < 0) + tmp0 = 0; + else if (tmp0 > 1023) + tmp0 = 1023; + else + tmp0 = tmp0; + + /* IIR filter */ + if (!dnlp_scn_chg && ((dnlp_alg_param.dnlp_dbg_i2r >> 6) + & 0x1)) { + tmp1 = dnlp_bld_lvl * tmp0 + (RBASE >> 1); + tmp1 = tmp1 + (RBASE - dnlp_bld_lvl) * bwext_curv[i]; + tmp1 = (tmp1 >> dnlp_alg_param.dnlp_mvreflsh); + + o_curv[i] = tmp1; + } else + o_curv[i] = tmp0; + /* for next frame */ + bwext_curv[i] = o_curv[i]; + + if (prt_flg) + pr_info("Step D-4.z: bwext[%3d]: dst4=%04d, divd=%04d, mg64x=%4d, delt(%4d)+ icurv(%4d) + brght(%4d) => blkwht_ebld(%04d ) iir(%4d)\n", + i, dist4, divd, margin64x, delta, + i_curv[i], bright, tmp0, o_curv[i]); + + } + /* o_curv[64] = 1023; */ + o_curv[0] = 0; + o_curv[64] = 1023; /* output */ + + if ((dnlp_printk>>14) & 0x1) { + pr_info("\n#### BW_extent: [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + o_curv[i], o_curv[i+1], + o_curv[i+2], o_curv[i+3], + o_curv[i+4], o_curv[i+5], + o_curv[i+6], o_curv[i+7], + o_curv[i+8], o_curv[i+9], + o_curv[i+10], o_curv[i+11], + o_curv[i+12], o_curv[i+13], + o_curv[i+14], o_curv[i+15]); + } + pr_info("]\n"); + } + + +} + + +/* patch for black+white stripe */ +/* in: mMaxLst,mMaxIdx, iir_hstSum */ +/* out: *gmma_rate,*low_alpha,*hgh_alpha,*mtdbld_rate */ +void patch_blk_wht(unsigned int *mMaxLst, unsigned int *mMaxIdx, + unsigned int *gmma_rate, unsigned int *low_alpha, + unsigned int *hgh_alpha, unsigned int *mtdbld_rate, + unsigned int iir_hstSum) +{ + int nTmp = 0, nT0 = 0, nT1 = 0; + + if (mMaxIdx[1] > mMaxIdx[0]) { + nT0 = mMaxIdx[0]; + nT1 = 63 - mMaxIdx[1]; + } else { + nT0 = mMaxIdx[1]; + nT1 = 63 - mMaxIdx[0]; + } + nTmp = (nT0 < nT1) ? nT0 : nT1; + nTmp = (nTmp > 16) ? 16 : nTmp; + + if ((mMaxLst[1] > (ve_dnlp_lgst_ratio*iir_hstSum>>8)) && + ((mMaxIdx[1] > (mMaxIdx[0] + ve_dnlp_lgst_dst)) || + (mMaxIdx[0] > (mMaxIdx[1] + ve_dnlp_lgst_dst)))) { + *gmma_rate += (nTmp*(255 - *gmma_rate)>>4); + *low_alpha -= (*low_alpha*nTmp>>4); + *hgh_alpha -= (*hgh_alpha*nTmp>>4); + *mtdbld_rate += (nTmp*(64 - *mtdbld_rate)>>4); + + if (dnlp_printk) + pr_info("Step C-1.y.2(after patch_blk_wht() ): special case:gmma_rate=%d low_alpha=%d hgh_alpha=%d mtdbld_rate=%d\n", + *gmma_rate, *low_alpha, + *hgh_alpha, *mtdbld_rate); + } + +} + + +/* function: based on luma_avg,luma_avg4 to calc blending coefs*/ +/* out: gmma_rate,low_alpha,hgh_alpha;*/ +/* mtdbld_rate; */ +static void dnlp_params_hist(unsigned int *gmma_rate, + unsigned int *low_alpha, unsigned int *hgh_alpha, + unsigned int *mtdbld_rate, + unsigned int luma_avg, unsigned int luma_avg4) +{ + static unsigned int pgmma0[4][7] = { + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0} + }; + int nTmp = 0; + int i = 0; + int trate = *gmma_rate; + int tlowa = *low_alpha; + int thgha = *hgh_alpha; + int tmrat = *mtdbld_rate; + static unsigned int xL[32]; /* for test */ + bool prt_flag = ((dnlp_printk>>2)&0x1); + + nTmp = (luma_avg > 31) ? luma_avg-31 : 31-luma_avg; + nTmp = (32 - nTmp + 2) >> 2; + + trate = trate + nTmp; + if (trate > 255) + trate = 255; + if (luma_avg4 <= 32) + tlowa = tlowa + (32 - luma_avg4); + + if (luma_avg4 >= 224) { + if (tlowa < (luma_avg4 - 224)) + tlowa = 0; + else + tlowa = tlowa - (luma_avg4 - 224); + } + + if (!dnlp_scn_chg) { + for (i = 0; i < 7; i++) { + trate += pgmma0[0][i]; + tlowa += pgmma0[1][i]; + thgha += pgmma0[2][i]; + tmrat += pgmma0[3][i]; + } + trate = ((trate + 4)>>3); + tlowa = ((tlowa + 4)>>3); + thgha = ((thgha + 4)>>3); + tmrat = ((tmrat + 4)>>3); + + for (i = 0; i < 6; i++) { + pgmma0[0][i] = pgmma0[0][i + 1]; + pgmma0[1][i] = pgmma0[1][i + 1]; + pgmma0[2][i] = pgmma0[2][i + 1]; + pgmma0[3][i] = pgmma0[3][i + 1]; + } + pgmma0[0][6] = trate; + pgmma0[1][6] = tlowa; + pgmma0[2][6] = thgha; + pgmma0[3][6] = tmrat; + } else + for (i = 0; i < 7; i++) { + pgmma0[0][i] = trate; + pgmma0[1][i] = tlowa; + pgmma0[2][i] = thgha; + pgmma0[3][i] = tmrat; + } + *gmma_rate = trate; + *low_alpha = tlowa; + *hgh_alpha = thgha; + *mtdbld_rate = tmrat; + + /* for debug only */ + for (i = 0; i < 31; i++) + xL[i] = xL[i+1]; + xL[31] = luma_avg4; + + if (prt_flag) { + pr_info("params_hist: gmma_rate=%d [%d %d %d %d %d %d %d],Tmp=%d luma_avg=%d (%d), alpha=[%d %d], mthd_rate=%d\n", + (*gmma_rate), pgmma0[0][0], pgmma0[0][1], + pgmma0[0][2], pgmma0[0][3], pgmma0[0][4], + pgmma0[0][5], pgmma0[0][6], nTmp, luma_avg, + luma_avg4, *low_alpha, *hgh_alpha, *mtdbld_rate); + i = 1; + pr_info("params_hist: low_alpha=%d [%d %d %d %d %d %d %d]\n", + (*low_alpha), pgmma0[i][0], pgmma0[i][1], + pgmma0[i][2], pgmma0[i][3], pgmma0[i][4], + pgmma0[i][5], pgmma0[i][6]); + i = 2; + pr_info("params_hist: hgh_alpha=%d [%d %d %d %d %d %d %d]\n", + (*hgh_alpha), pgmma0[i][0], pgmma0[i][1], + pgmma0[i][2], pgmma0[i][3], pgmma0[i][4], + pgmma0[i][5], pgmma0[i][6]); + i = 3; + pr_info("params_hist: mtdbld_rate=%d [%d %d %d %d %d %d %d]\n", + (*mtdbld_rate), pgmma0[i][0], pgmma0[i][1], + pgmma0[i][2], pgmma0[i][3], pgmma0[i][4], + pgmma0[i][5], pgmma0[i][6]); + + /* pr_info("xL = [%d %d %d %d %d %d %d %d ;\n */ + /* %d %d %d %d %d %d %d %d ;\n */ + /* %d %d %d %d %d %d %d %d ;\n */ + /* %d %d %d %d %d %d %d %d ]\n", */ + /* xL[0],xL[1],xL[2],xL[3], */ + /* xL[4],xL[5],xL[6],xL[7], */ + /* xL[8],xL[9],xL[10],xL[11], */ + /* xL[12],xL[13],xL[14],xL[15], */ + /* xL[16],xL[17],xL[18],xL[19], */ + /* xL[20],xL[21],xL[22],xL[23], */ + /* xL[24],xL[25],xL[26],xL[27], */ + /* xL[28],xL[29],xL[30],xL[31]); */ + + } +} + + +/* function: black bord detection, and histogram clipping*/ +/* in: hstSum,pre_0_gamma*/ +/* out: pre_0_gamma */ +static void dnlp_refine_bin0(int hstSum) +{ + static unsigned int tmp_sum[7]; + unsigned int nTmp = 0; + unsigned int nTmp0 = 0; + unsigned int nsum = 0; + int j = 0; + + nTmp = (hstSum * dnlp_alg_param.dnlp_bbd_ratio_low + 128) >> 8; + nTmp0 = pre_0_gamma[1] + pre_0_gamma[2]; + if (nTmp0 > nTmp) + nTmp = nTmp0; + + if (pre_0_gamma[0] > nTmp) { + if (pre_0_gamma[1] > nTmp) + nTmp = pre_0_gamma[1]; + if (pre_0_gamma[2] > nTmp) + nTmp = pre_0_gamma[2]; + + nsum = pre_0_gamma[0] - nTmp; + + nTmp = (hstSum * dnlp_alg_param.dnlp_bbd_ratio_hig + 128) >> 8; + if (nsum > nTmp) + nsum = nTmp; + } + + if (!dnlp_scn_chg) { + for (j = 0; j < 7; j++) + nsum += tmp_sum[j]; + nsum = ((nsum + 4) >> 3); + + for (j = 0; j < 6; j++) + tmp_sum[j] = tmp_sum[j + 1]; + tmp_sum[6] = nsum; + } else { + for (j = 0; j < 7; j++) + tmp_sum[j] = nsum; + } + + if (dnlp_printk & 0x1) + pr_info("Bin0 Refine: -%4d\n", nsum); + + if (nsum >= pre_0_gamma[0]) + pre_0_gamma[0] = 0; + else + pre_0_gamma[0] = pre_0_gamma[0] - nsum; +} + + +/*function: adaptive calc of coefs*/ +/* in : lmh_avg,dnlp_lowrange,dnlp_hghrange,*/ +/* &low_alpha,&hgh_alpha,&dnlp_pst_gmarat*/ +/* out:low_alpha,hgh_alph; (for gma_scurvet)*/ +/* dnlp_pst_gmarat; (for blk_gma_rat calc) */ +static void dnlp_adp_alpharate(unsigned int *lmh_avg, + unsigned int *low_alpha, unsigned int *hgh_alpha, + unsigned int *pst_gmarat, + unsigned int dnlp_lowrange, unsigned int dnlp_hghrange) +{ + int nTmp = 0; + int ndif = 0; + int nlap = 0; + int nbrt0 = 0; + int nbrt1 = 0; + bool prt_flag = ((dnlp_printk>>2)&0x1); + + if (prt_flag) + pr_info("Step C-1.y.1: adp_alpharateinput:lmh_avg= %3d %3d %3d %3d %3d, low_alpha=%2d, hgh_alpha=%2d\n", + lmh_avg[0], lmh_avg[1], lmh_avg[2], + lmh_avg[3], lmh_avg[4], *low_alpha, *hgh_alpha); + + if (dnlp_lowrange + lmh_avg[3] < 64) { /* decrease low alpha */ + nTmp = 64 - (dnlp_lowrange + lmh_avg[3]); + nTmp = (ve_dnlp_adpalpha_lrate * nTmp + 16) >> 5; + if (*low_alpha < nTmp) + *low_alpha = 0; + else + *low_alpha = *low_alpha - nTmp; + + if (prt_flag) + pr_info("Step C-1.y.1:out : low alpha-- (%3d) -> %2d\n", + nTmp, *low_alpha); + } else if (lmh_avg[3] > 64) { /* increase low alpha */ + ndif = lmh_avg[3] - 64; + nlap = (ve_dnlp_adpalpha_lrate * ndif + 16) >> 5; + if ((nlap + *low_alpha) > 64) + *low_alpha = 64; + else + *low_alpha += nlap; + + if (prt_flag) + pr_info("Step C-1.y.1:out :low alpha++ (%3d) -> %2d\n", + nlap, *low_alpha); + + if (lmh_avg[4] < 16) { + nbrt0 = ve_dnlp_pstgma_brghtrat1 * (16 - lmh_avg[4]); + nbrt0 = (nbrt0 + 8) >> 4; + } + nbrt1 = (ve_dnlp_pstgma_brghtrate * ndif + 16) >> 6; + + nTmp = nbrt0 + nbrt1; + + if ((*pst_gmarat + nTmp) > 64) + *pst_gmarat = 64; + else + *pst_gmarat += nTmp; + + if (prt_flag) + pr_info("Step C-1.y.1:out : pstgma(+%2d +%2d)(%2d)\n", + nbrt0, nbrt1, *pst_gmarat); + } + + if (lmh_avg[2] < 64 - dnlp_hghrange) { /* decrease hgh alpha */ + nTmp = 64 - dnlp_hghrange - lmh_avg[2]; + nTmp = (ve_dnlp_adpalpha_hrate * nTmp + 16) >> 5; + if (*hgh_alpha < nTmp) + *hgh_alpha = 0; + else + *hgh_alpha = *hgh_alpha - nTmp; + if (prt_flag) + pr_info("Step C-1.y.1:out: hgh alpha-- (%3d) -> %2d\n", + nTmp, *hgh_alpha); + } else if (lmh_avg[2] > 63) { /* increase hgh alpha */ + nTmp = lmh_avg[2] - 63; + nTmp = (ve_dnlp_adpalpha_hrate * nTmp + 16) >> 5; + if ((nTmp + *hgh_alpha) > 64) + *hgh_alpha = 64; + else + *hgh_alpha += nTmp; + + if (prt_flag) + pr_info("Step C-1.y.1: out: hgh alpha++ (%3d) -> %2d\n", + nTmp, *hgh_alpha); + } +} + + +static void dnlp_tgt_sort(void) +{ + int i = 0; + int j = 0; + unsigned char t = 0; + int chk = 0; + /* unsigned char ve_dnlp_tgt[64]; */ + for (j = 0; j < 63; j++) { + chk = 0; + for (i = 0; i < (63 - i); i++) { + if (ve_dnlp_tgt[i] > ve_dnlp_tgt[i+1]) { + t = ve_dnlp_tgt[i]; + ve_dnlp_tgt[i] = ve_dnlp_tgt[i+1]; + ve_dnlp_tgt[i+1] = t; + chk = chk+1; + } + } + if (chk == 0) + break; + } +} + + +/* in: vf (hist), h_sel*/ +/* out: hstSum,pre_0_gamma, *osamebin_num*/ +/*return: hstSum */ +static int load_histogram(int *osamebin_num, struct vframe_s *vf, + int h_sel, unsigned int nTstCnt) +{ + struct vframe_prop_s *p = &vf->prop; + int nT0; /* counter number of bins same to last frame */ + int hstSum, nT1, i, j; /* sum of pixels in histogram */ + + nT0 = 0; hstSum = 0; + for (i = 0; i < 64; i++) { + /* histogram stored for one frame delay */ + pre_1_gamma[i] = pre_0_gamma[i]; + if (h_sel) + pre_0_gamma[i] = (unsigned int)p->hist.vpp_gamma[i]; + else + pre_0_gamma[i] = (unsigned int)p->hist.gamma[i]; + + /* counter the same histogram */ + if (pre_1_gamma[i] == pre_0_gamma[i]) + nT0++; + else if (pre_1_gamma[i] > pre_0_gamma[i]) + nT1 = (pre_1_gamma[i] - pre_0_gamma[i]); + else + nT1 = (pre_0_gamma[i] - pre_1_gamma[i]); /* not use */ + + hstSum += pre_0_gamma[i]; + } + + if (dnlp_printk) + pr_info("\nRflsh%03d: %02d same bins hstSum(%d)\n", + nTstCnt, nT0, hstSum); + + /* output, same hist bin nums of this frame */ + *osamebin_num = nT0; + + if ((dnlp_printk >> 14) & 0x1) { + pr_info("\n#### load_histogram(): [\n"); + for (j = 0; j < 4; j++) { + i = j*16; + pr_info("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", + pre_0_gamma[i], pre_0_gamma[i+1], + pre_0_gamma[i+2], pre_0_gamma[i+3], + pre_0_gamma[i+4], pre_0_gamma[i+5], + pre_0_gamma[i+6], pre_0_gamma[i+7], + pre_0_gamma[i+8], pre_0_gamma[i+9], + pre_0_gamma[i+10], pre_0_gamma[i+11], + pre_0_gamma[i+12], pre_0_gamma[i+13], + pre_0_gamma[i+14], pre_0_gamma[i+15]); + } + pr_info(" ]\n"); + } + + return hstSum; +} + + +/* input: pre_0_gamma[] (iir filtered hist), raw_hst_sum;*/ +/* output: iir_hstSum, ihstBgn, ihstEnd, iRgnBgn, iRgnEnd */ +int get_hist_bgn_end(unsigned int *iRgnBgn, unsigned int *iRgnEnd, + unsigned int *ihstBgn, unsigned int *ihstEnd, + unsigned int ihst_sum) +{ + unsigned int i, iir_hstSum; + unsigned int hstBgn, hstEnd; + + /* detect the hstBgn and hstEnd */ + iir_hstSum = 0; hstBgn = 0; hstEnd = 0; + for (i = 0; i < 64; i++) { + if (pre_0_gamma[i] >= (ihst_sum>>8)) { + if (hstBgn == 0 && pre_0_gamma[0] <= (ihst_sum>>9)) + hstBgn = i; + } + if (pre_0_gamma[i] >= (ihst_sum>>8)) { + if (hstEnd != 64) + hstEnd = i+1; + } + clash_curve[i] = (i<<4); /* 0~1024 */ + + iir_hstSum += pre_0_gamma[i]; + } + clash_curve[64] = 1024; + + if (dnlp_alg_param.dnlp_limit_rng) { + /* i=ihstBgn, i= 59) + *iRgnEnd = hstEnd; + } + CrtTstDat[8] = *iRgnBgn; + CrtTstDat[9] = *iRgnEnd; + + /* outputs */ + *ihstBgn = hstBgn; *ihstEnd = hstEnd; + return iir_hstSum; +} + + +/*input: pre_0_gamma[] (iir filtered hist),iRgnBgn,iRgnEnd,ihstBgn,ihstEnd*/ +/* output: mMaxLst[], mMaxIdx[], *low_lsum, *low_bsum,*/ +/* *rgn_hstSum, *rgn_hstMax, *lsft_avg, *luma_avg4, *low_lavg4,*/ +/*max4_sum */ +unsigned int get_hist_max4_avgs(unsigned int *mMaxLst, unsigned int *mMaxIdx, + unsigned int *low_lsum, unsigned int *low_bsum, + unsigned int *rgn_lumSum, unsigned int *rgn_hstSum, + unsigned int *rgn_hstMax, unsigned int *lsft_avg, + unsigned int *luma_avg4, unsigned int *low_lavg4, + unsigned int *max4_sum, unsigned int iRgnBgn, unsigned int iRgnEnd, + unsigned int ihstBgn, unsigned int ihstEnd) +{ + int i, nT0, nT1; + unsigned int nTmp, nTmp0, sum, max, luma_sum; + + mMaxLst[0] = mMaxLst[1] = mMaxLst[2] = mMaxLst[3] = 0; + mMaxIdx[0] = mMaxIdx[1] = mMaxIdx[2] = mMaxIdx[3] = 0; + nT0 = 0; sum = max = luma_sum = 0; + for (i = iRgnBgn; i < iRgnEnd; i++) { + nTmp = pre_0_gamma[i]; + sum += nTmp; + + if (max < nTmp) + max = nTmp; + + /*lower extension [0-63]*/ + nTmp0 = nTmp*i; + luma_sum += nTmp0; + if (i == 31) { + *low_lsum = luma_sum;/*low luma sum, sum of lumas*/ + *low_bsum = sum;/*low bin sum, num of pixels*/ + } + + /*Get the maximum4*/ + for (nT0 = 0; nT0 < 4; nT0++) { + if (nTmp >= mMaxLst[nT0]) { + for (nT1 = 3; nT1 >= nT0+1; nT1--) { + mMaxLst[nT1] = mMaxLst[nT1-1]; + mMaxIdx[nT1] = mMaxIdx[nT1-1]; + } + mMaxLst[nT0] = nTmp; + mMaxIdx[nT0] = i; + break; + } + } + if ((dnlp_printk>>2) & 0x1) + pr_info("#StepA-0.6(get_hist_max4_avgs):i=%2d, luma_sum=%6d, sum=%6d, low_lsum=%6d, low_lsum=%6d\n", + i, luma_sum, sum, *low_lsum, *low_bsum); + } + + /*invalid histgram: freeze dnlp curve*/ + if ((*rgn_hstMax <= 55 || *rgn_hstSum == 0) + && (!dnlp_alg_param.dnlp_respond_flag)) { + if (dnlp_printk) + pr_info("WARNING: invalid hist @ step 0.6: [%d %d %d]\n", + (*rgn_hstMax), (*rgn_hstSum), + dnlp_alg_param.dnlp_respond_flag); + return -1; + } + + /* Filter to get the max4 bin */ + if (mMaxIdx[0] == 0) + nTmp = (mMaxIdx[1] * 2) + mMaxIdx[2] + mMaxIdx[3]; + else { + if (mMaxIdx[1] == 0) + nTmp = mMaxIdx[0] + mMaxIdx[2] + mMaxIdx[3]; + else if (mMaxIdx[2] == 0) + nTmp = mMaxIdx[0] + mMaxIdx[1] + mMaxIdx[3]; + else if (mMaxIdx[3] == 0) + nTmp = mMaxIdx[0] + mMaxIdx[1] + mMaxIdx[2]; + else + nTmp = mMaxIdx[1] + mMaxIdx[2] + mMaxIdx[3]; + + nTmp += mMaxIdx[0]; + } + /* outputs */ + *max4_sum = nTmp; /* maximum 4 bin's idx sum */ + + /* outputs */ + *rgn_lumSum = luma_sum;/* [iRgnBgn, iRgnEnd],not use ihstRgn data */ + *rgn_hstSum = sum; + *rgn_hstMax = max; + + + /* get the averages and output */ + nTmp = (luma_sum << (2 + dnlp_alg_param.dnlp_pavg_btsft)); + /* with (2 + ve_dnlp_pavg_btsft) precision */ + *lsft_avg = (nTmp + (sum >> 1)) / (sum+1); + *luma_avg4 = ((*lsft_avg) >> dnlp_alg_param.dnlp_pavg_btsft); + /* low range hist average binx4, equivalent to lmh_avg[0]???? */ + *low_lavg4 = 4*(*low_lsum)/((*low_bsum)+1); + if (dnlp_printk & 0x1) { + pr_info("step 0.6:nTmp=%d, btsft=%d, lsft_avg=%d, luma_avg4=%d; low_lavg4=4*(%d by %d)= %d", + nTmp, dnlp_alg_param.dnlp_pavg_btsft, (*lsft_avg), + (*luma_avg4), (*low_lsum), + (*low_bsum), (*low_lavg4)); + } + if ((*luma_avg4) < 0 || (*luma_avg4) > 256 + || luma_sum < 0 || (*lsft_avg) < 0) { + pr_info("ERROR 0.6b: :nTmp=%d, btsft=%d, lsft_avg=%d, luma_avg4=%d; low_lavg4=4*(%d by %d)= %d", + nTmp, dnlp_alg_param.dnlp_pavg_btsft, (*lsft_avg), + (*luma_avg4), (*low_lsum), + (*low_bsum), (*low_lavg4)); + } + + CrtTstDat[10] = *lsft_avg; + CrtTstDat[11] = *luma_avg4; + if (dnlp_printk & 0x1) { + pr_info("Step 0.60: #Bins: Pre-hist => Crt-Hist\n"); + for (i = 0; i < 64; i++) + pr_info("[%03d,%03d): %05d => %05d\n", + 4*i, 4*(i+1), + pre_1_gamma[i], pre_0_gamma[i]); + + pr_info("step 0.61:Max: %04d(%d) > %04d(%d) > %04d(%d) > %04d(%d) max=%d, max4_sum=%6d\n", + mMaxLst[0], mMaxIdx[0], mMaxLst[1], mMaxIdx[1], + mMaxLst[2], mMaxIdx[2], mMaxLst[3], mMaxIdx[3], max, *max4_sum); + pr_info(" ve_dnlp_luma_sum=%d, Rgn_BgnEnd= [%d %d], ihst_BgnEnd =[%d %d]\n", + ve_dnlp_luma_sum, iRgnBgn, + iRgnEnd, ihstBgn, ihstEnd); + + pr_info(" rgn_lumSum by rgn_hstSum =%d by %d => lsft_avg=%d luma_avg4= %d histMax=%d\n", + luma_sum, sum, *lsft_avg, *luma_avg4, *rgn_hstMax); + pr_info(" low_lsum by low_bsum =%d by %d => low_lavg4=%d\n", + *low_lsum, (*low_bsum), (*low_lavg4)); + } + + return 0; +} + + + +/*function: calc ihst variance */ +/*in : pre_0_gamma[i], rgn_hstSum,luma_avg4,iRgnBgn,iRgnEnd*/ +/*out : var*/ + +unsigned int cal_hist_var(unsigned int rgn_hstSum, unsigned int luma_avg4, + unsigned int iRgnBgn, unsigned int iRgnEnd) +{ + unsigned int i, dif, dif_sum, i4; + unsigned int var; + + dif_sum = 0; + for (i = iRgnBgn; i < iRgnEnd; i++) { + i4 = (i << 2); + /* luma_avg4:0~256 */ + dif = i4 > luma_avg4 ? (i4 - luma_avg4):(luma_avg4 - i4); + dif = (dif*dif) >> 4; + if ((dnlp_printk >> 13) & 0x1) + pr_info("@@@cal_hist_var():i4 = %d, luma_avg4 = %d, dif*dif = %4d, ", + i4, luma_avg4, dif); + + dif = dif * pre_0_gamma[i];/* num of i */ + dif_sum += dif; + + if ((dnlp_printk>>13) & 0x1) + pr_info("@@@cal_hist_var():(continue) pre_0_gamma[i] = %4d, dif_sum = %4d\n ", + pre_0_gamma[i], dif_sum); + } + var = dif_sum/((rgn_hstSum>>3)+1);/* mse */ + + if ((dnlp_printk>>14) & 0x1) + pr_info("@@@cal_hist_var(): var = %d(before clip)\n ", var); + + /* var = (var>2048)? 2048: var; */ + var = (var > 8192) ? 8192 : var; + /* typical histo <==> var <==> var/8 */ + /* 1-bin 0 0 */ + /* 3-bin 8 1 */ + /* 5-bin 16 2 */ + /* 7-bin 32 4 */ + /* 9-bin 52 7 */ + /* 11-bin 83 11 */ + /* 13-bin 112 15 */ + /* 16-bin 204 25 */ + /* 32-bin 748 93.5 */ + /* ramp 2500 325 */ + /* BW50% xx 1024 */ + + if ((dnlp_printk>>14) & 0x1) + pr_info("@@@cal_hist_var(): iRgn=[%d %d], luma_avg4= %d, rgn_hstSum = %d,=> var = %d(u8 %d)\n ", + iRgnBgn, iRgnEnd, luma_avg4, rgn_hstSum, var, var/8); + + return var; + +} + + +/* input: luma_avg (0~63)*/ + /* output: *auto_rng, *lowrange, *hghrange */ +void get_auto_range(unsigned int *auto_rng, unsigned int *lowrange, + unsigned int *hghrange, unsigned int luma_avg) +{ + unsigned int dnlp_auto_rng, dnlp_lowrange, dnlp_hghrange; + + /* auto_range */ + if (luma_avg < dnlp_alg_param.dnlp_auto_rng) + dnlp_auto_rng = luma_avg; + else if (luma_avg + dnlp_alg_param.dnlp_auto_rng > 64) + dnlp_auto_rng = 64 - luma_avg; + else + dnlp_auto_rng = dnlp_alg_param.dnlp_auto_rng; + if (dnlp_auto_rng < 2) + dnlp_auto_rng = 2; + else if (dnlp_auto_rng > 10) + dnlp_auto_rng = 10; + + /* lowrange and hghrange calcluation */ + if (dnlp_alg_param.dnlp_auto_rng > 0) { + if (luma_avg <= dnlp_auto_rng + 2) { + dnlp_lowrange = 2; + dnlp_hghrange = 64 - (luma_avg + dnlp_auto_rng); + } else if (luma_avg >= 61 - dnlp_auto_rng) { + dnlp_lowrange = luma_avg - dnlp_auto_rng; + dnlp_hghrange = 2; + } else { + dnlp_lowrange = luma_avg - dnlp_auto_rng; + dnlp_hghrange = (63 - (luma_avg + dnlp_auto_rng)); + } + } else { + dnlp_lowrange = dnlp_alg_param.dnlp_lowrange; + dnlp_hghrange = dnlp_alg_param.dnlp_hghrange; + } + if (dnlp_lowrange > 31) + dnlp_lowrange = 31; + else if (dnlp_lowrange < 2) + dnlp_lowrange = 2; + if (dnlp_hghrange > 31) + dnlp_hghrange = 31; + else if (dnlp_hghrange < 2) + dnlp_hghrange = 2; + + /* output */ + *auto_rng = dnlp_auto_rng; + *lowrange = dnlp_lowrange; + *hghrange = dnlp_hghrange; +} + + +/*function : calc for lmh_avg[5], further use in cal_bwext_param(),*/ + /*dnlp_adap_alpharate()*/ + /*input: pre_0_gamma (iir filtered version), dnlp_lowrange,*/ +/* dnlp_hghrange, *iRgnBgn, iRgnEnd */ + /*output: lmh_sum[3](not use), lmh_avg[5]*/ +void get_lmh_avg(unsigned int *lmh_sum, unsigned int *lmh_avg, + unsigned int dnlp_lowrange, unsigned int dnlp_hghrange, + unsigned int iRgnBgn, unsigned int iRgnEnd) +{ + unsigned int i, nTmp0; + + lmh_sum[0] = lmh_sum[1] = lmh_sum[2] = 0; /* jas_debug */ + for (i = iRgnBgn; i < iRgnEnd; i++) { + /* use iRgn([4,59]) ,not ihstRgn */ + nTmp0 = pre_0_gamma[i] * i; + + if (i < dnlp_lowrange) {/* low tone */ + lmh_sum[0] += pre_0_gamma[i]; + lmh_avg[0] += nTmp0; + lmh_avg[3] += pre_0_gamma[i] * (64 - i); + } else if (i > (63 - dnlp_hghrange)) { /* hgh tone */ + lmh_sum[2] += pre_0_gamma[i]; + lmh_avg[2] += nTmp0; + } else{ /* mid tone */ + lmh_sum[1] += pre_0_gamma[i]; + lmh_avg[1] += nTmp0; + } + } + + /* low/mid/high tone average */ + /* low tone avg in bins (0~63) */ + lmh_avg[0] = (lmh_avg[0] + (lmh_sum[0] >> 1)) / + (lmh_sum[0] + 1); + lmh_avg[3] = (lmh_avg[3] + (lmh_sum[0] >> 1)) / + (lmh_sum[0] + 1); + /* mid tone avg in bins (0~63) */ + lmh_avg[1] = (lmh_avg[1] + (lmh_sum[1] >> 1)) / + (lmh_sum[1] + 1); + /* hig tone avg in bins (0~63) */ + lmh_avg[2] = (lmh_avg[2] + (lmh_sum[2] >> 1)) / + (lmh_sum[2] + 1); +} + +/* function: get the blend coef between blk_gmma and clsh_scvbld */ +/* in: *dnlp_pstgma_ratio, dnlp_pst_gmarat */ +/*(return)output: blk_gma_rat[0~63], */ +void get_blk_gma_rat(unsigned int *blk_gma_rat, unsigned int *dnlp_pstgma_ratio, + unsigned int dnlp_pst_gmarat) +{ + unsigned int i, nT1; + + if (*dnlp_pstgma_ratio > dnlp_pst_gmarat) + *dnlp_pstgma_ratio = dnlp_pst_gmarat;/* */ + if (dnlp_printk & 0x1) + pr_info("\n ****** inside get_blk_gma_rat():\n "); + for (i = 0; i < 64; i++) { + nT1 = dnlp_pst_gmarat; + + if (i > ve_dnlp_pstgma_end) + nT1 = *dnlp_pstgma_ratio; + else if (ve_dnlp_pstgma_end > 0) { + nT1 = dnlp_pst_gmarat - (*dnlp_pstgma_ratio); + nT1 = nT1 * i + (ve_dnlp_pstgma_end >> 1); + nT1 = nT1 / (ve_dnlp_pstgma_end+1);/* can't be 0 */ + nT1 = dnlp_pst_gmarat - nT1; + } + + if (dnlp_alg_param.dnlp_limit_rng && (i <= 4)) { + nT1 = i * dnlp_pst_gmarat; + nT1 = ((nT1 + 2) >> 2); + } + + if (nT1 < 0) + nT1 = 0; + else if (nT1 > 64) + nT1 = 64; + + blk_gma_rat[i] = nT1; + + if (dnlp_printk & 0x1) + pr_info("%4d ", blk_gma_rat[i]); + } + + +} + + +/* dnlp saturation compensations */ +/* input: ve_dnlp_tgt[]; */ +/* output: ve_dnlp_add_cm(nTmp + 512), and delta saturation; */ +int dnlp_sat_compensation(void) +{ + int nT0, nT1, nTmp0, nTmp, i; + unsigned int pre_stur = 0; + + nT0 = 0; nT1 = 0; + for (i = 1; i < 64; i++) { + if (ve_dnlp_tgt[i] > 4*i) { + nT0 += (ve_dnlp_tgt[i] - 4*i) * (65 - i); + nT1 += (65 - i); + } + } + nTmp0 = nT0 * dnlp_alg_param.dnlp_satur_rat + (nT1 >> 1); + nTmp0 = nTmp0 / (nT1 + 1); + nTmp0 = ((nTmp0 + 4) >> 3); + + nTmp = (dnlp_alg_param.dnlp_satur_max << 3); + if (nTmp0 < nTmp) + nTmp = nTmp0; + + if (((dnlp_printk>>10)&0x1)) + pr_info("#sat_comp: pre(%3d) => %5d / %3d => %3d cur(%3d)\n", + pre_stur, nT0, nT1, nTmp0, nTmp); + + if (dnlp_alg_param.dnlp_set_saturtn == 0) { + if (nTmp != pre_stur) { + ve_dnlp_add_cm(nTmp + 512); + pre_stur = nTmp; + } + } else { + if (pre_stur != dnlp_alg_param.dnlp_set_saturtn) { + if (dnlp_alg_param.dnlp_set_saturtn < 512) + ve_dnlp_add_cm(dnlp_alg_param.dnlp_set_saturtn + + 512); + else + ve_dnlp_add_cm(dnlp_alg_param.dnlp_set_saturtn); + pre_stur = dnlp_alg_param.dnlp_set_saturtn; + } + } + + return nTmp; +} + + +/* function: final selection of the curves */ +/* input: ve_dnlp_tgt[], ve_dnlp_final_gain */ +/* output: ve_dnlp_tgt[], premap0[] */ +void curv_selection(void) +{ + int i, nTmp0; + static unsigned int pst_0_gamma[65]; + + bool prt_flg = ((dnlp_printk >> 10) & 0x1); + + if (!ve_dnlp_luma_sum) { + for (i = 0; i < 65; i++) + pst_0_gamma[i] = (i << 4); + } + + for (i = 0; i < 65; i++) { + premap0[i] = ve_dnlp_tgt[i]; + + if (dnlp_alg_param.dnlp_dbg_map == 1) + nTmp0 = gma_scurve0[i]; + else if (dnlp_alg_param.dnlp_dbg_map == 2) + nTmp0 = gma_scurve1[i]; + else if (dnlp_alg_param.dnlp_dbg_map == 3) + nTmp0 = gma_scurvet[i]; + else if (dnlp_alg_param.dnlp_dbg_map == 4) + nTmp0 = clash_curve[i]; + else if (dnlp_alg_param.dnlp_dbg_map == 5) + nTmp0 = clsh_scvbld[i]; + else if (dnlp_alg_param.dnlp_dbg_map == 6) + nTmp0 = blk_gma_crv[i]; + else if (dnlp_alg_param.dnlp_dbg_map == 7) + nTmp0 = blk_gma_bld[i]; + else if (dnlp_alg_param.dnlp_dbg_map == 8) + nTmp0 = (i<<4); /* 45 degree */ + else if (dnlp_alg_param.dnlp_dbg_map == 9) + nTmp0 = blkwht_ebld[i]; /* 1023 */ + else if (dnlp_alg_param.dnlp_dbg_map == 10) + nTmp0 = GmScurve[i]; + else + nTmp0 = blkwht_ebld[i]; + + /* add a gain here to finally change the DCE strength:*/ + /* final_gain normalized to 8 as 1 */ + nTmp0 = ((i)<<4) + + (((nTmp0-((i)<<4)) * + ((int)dnlp_alg_param.dnlp_final_gain) + 4)/8); + #if 0 + /* tiir filter */ + nTmp0 = dnlp_bld_lvl * nTmp0 + (RBASE >> 1); /* 1024 */ + nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pst_0_gamma[i]; + nTmp0 = (nTmp0 >> dnlp_alg_param.dnlp_mvreflsh); /* 0~4096 */ + + if (nTmp0 < 0) + nTmp0 = 0; + else if (nTmp0 > 1023) + nTmp0 = 1023; + + pst_0_gamma[i] = nTmp0; + #endif + + nTmp0 = ((nTmp0 + 2) >> 2); + + if (nTmp0 > 255) + nTmp0 = 255; + else if (nTmp0 < 0) + nTmp0 = 0; + + if (prt_flg) { + pr_info("curv_sel[%02d]: (s0 %4d s1 %4d) (s)%4d (c)%4d (cs)%4d (blk_gma)%4d-(blk_bld)%4d (blkwht_ebld)%4d => (final) %3d\n", + i, gma_scurve0[i], gma_scurve1[i], + gma_scurvet[i], clash_curve[i], + clsh_scvbld[i], blk_gma_crv[i], + blk_gma_bld[i], blkwht_ebld[i], nTmp0); + } + + ve_dnlp_tgt[i] = nTmp0; + } + + if (((!dnlp_scn_chg) && (!menu_chg_en)) && + ((dnlp_alg_param.dnlp_dbg_i2r >> 4) & 0x1)) { + for (i = 0; i < 65; i++) { + nTmp0 = dnlp_bld_lvl * ve_dnlp_tgt[i] + (RBASE >> 1); + nTmp0 = nTmp0 + (RBASE - dnlp_bld_lvl) * pst_0_gamma[i]; + nTmp0 = (nTmp0 >> dnlp_alg_param.dnlp_mvreflsh); + /*clip*/ + if (nTmp0 < 0) + nTmp0 = 0; + else if (nTmp0 > 255) + nTmp0 = 255; + + ve_dnlp_tgt[i] = nTmp0; + } + menu_chg_en = 0; + } + + for (i = 0; i < 65; i++) + pst_0_gamma[i] = ve_dnlp_tgt[i]; +} + +/* for draw curve */ + + +void ve_dnlp_calculate_tgtx_v3(struct vframe_s *vf) +{ + struct vframe_prop_s *p = &vf->prop; + + /* curve blending coef parms */ + /* 1- scurve0 + scurve1 = gma_scurvet */ + unsigned int gmma_rate = (unsigned int)ve_dnlp_gmma_rate; + /* gma_scurvet with 45 dgree in low luma */ + unsigned int low_alpha = (unsigned int)ve_dnlp_lowalpha_v3; + /* gma_scurvet with 45 dgree in high luma */ + unsigned int hgh_alpha = (unsigned int)ve_dnlp_hghalpha_v3; + /* 2- gma_scurvet + clahe_curve = clsh_scvbld */ + unsigned int mtdbld_rate = + (unsigned int)dnlp_alg_param.dnlp_mtdbld_rate; + + /* for calc blk_gma_rat */ + unsigned int dnlp_pst_gmarat = (unsigned int)ve_dnlp_pst_gmarat; + /* for calc blk_gma_rat, old (ve_dnlp_bkgert) */ + unsigned int dnlp_pstgma_ratio = (unsigned int)ve_dnlp_pstgma_ratio; + /* Black gamma rate: global -> auto local ??*/ + unsigned int blk_gma_rat[64]; + /* 3- blk_gma_crv + clsh_scvbld = blk_gma_bld */ + + /* clash, s curve begin & end */ + unsigned int clashBgn = (unsigned int)dnlp_alg_param.dnlp_clashBgn; + unsigned int clashEnd = (unsigned int)dnlp_alg_param.dnlp_clashEnd; + unsigned int sBgnBnd = (unsigned int)dnlp_alg_param.dnlp_sbgnbnd; + unsigned int sEndBnd = (unsigned int)dnlp_alg_param.dnlp_sendbnd; + + unsigned int ihstBgn, ihstEnd; /* hist begin,end */ + + /* hist auto range parms */ + unsigned int dnlp_lowrange = (unsigned int)dnlp_alg_param.dnlp_lowrange; + unsigned int dnlp_hghrange = (unsigned int)dnlp_alg_param.dnlp_hghrange; + unsigned int dnlp_auto_rng = 0; + + static unsigned int nTstCnt; + bool prt_flg = ((dnlp_printk) & 0x1); + + /*---- some intermediate variables ----*/ + unsigned int raw_hst_sum, iir_hstSum; + int i, nT0, smbin_num, nTmp0, dnlp_brightness, var, sat_compens; + + /* get_hist_max4_avgs () */ + /* only used in get_hist_max4_avgs */ + unsigned int rgn_lumSum, rgn_hstSum, rgn_hstMax; + unsigned int low_sum = 0; + unsigned int low_lsum; + + unsigned int lsft_avg = 0; /* luma shift average */ + /* luma average(64),luma average(256) */ + unsigned int luma_avg, luma_avg4; + unsigned int low_lavg4 = 0; /* low luma average */ + + unsigned int mMaxLst[4]; /* patch for black+white stripe */ + unsigned int mMaxIdx[4]; + + /* get_lmh_avg () */ + unsigned int lmh_avg[5] = {0, 0, 0, 0, 0}; + /* low mid hig range hist_sum for lmh_avg calculation */ + unsigned int lmh_sum[3] = {0, 0, 0}; + + /* get_clahe_curve() */ + unsigned int cluma_avg4; /* clahe luma avg4, not use */ + + /* black white extension params */ + int blk_wht_ext[2] = {0, 0}; /* u10 precision, */ + /*--------------------------------------------------*/ + + /* pre-define gamma curve,1.2 & 1.8 */ + + unsigned int rGm1p2[] = { + 0, 2, 4, 7, 9, 12, 15, 18, 21, 24, + 28, 31, 34, 38, 41, 45, 49, 52, 56, 60, + 63, 67, 71, 75, 79, 83, 87, 91, 95, 99, + 103, 107, 111, 116, 120, 124, 128, 133, + 137, 141, 146, 150, 154, 159, 163, 168, + 172, 177, 181, 186, 190, 195, 200, 204, + 209, 213, 218, 223, 227, 232, 237, 242, + 246, 251, 255}; + + + /* 2.0 for full range */ + unsigned int rGm1p8[] = { + 0, 0, 0, 1, 1, 2, 2, 3, 4, 5, + 6, 8, 9, 11, 12, 14, 16, 18, 20, 23, + 25, 28, 30, 33, 36, 39, 42, 46, 49, 53, + 56, 60, 64, 68, 72, 77, 81, 86, 90, 95, + 100, 105, 110, 116, 121, 127, 132, 138, + 144, 150, 156, 163, 169, 176, 182, 189, + 196, 203, 210, 218, 225, 233, 240, 248, 255}; + + + /* -------some pre-processing---------------------------// */ + + /* calc iir-coef params */ + if (dnlp_alg_param.dnlp_mvreflsh < 1) + dnlp_alg_param.dnlp_mvreflsh = 1; + RBASE = (1 << dnlp_alg_param.dnlp_mvreflsh); + + /* parameters refresh */ + dnlp3_param_refrsh(); + dnlp_scn_chg = 0; + + /* initalizations */ + if (low_alpha > 64) + low_alpha = 64; + if (hgh_alpha > 64) + hgh_alpha = 64; + if (clashBgn > 16) + clashBgn = 16; + if (clashEnd > 64) + clashEnd = 64; + if (clashEnd < 49) + clashEnd = 49; + for (i = 0; i < 28; i++) + PreTstDat[i] = CrtTstDat[i]; + + /* old historic luma sum*/ + /*sum_b = ve_dnlp_luma_sum;*/ + /* v3 historic luma sum */ + if (hist_sel) + ve_dnlp_luma_sum = p->hist.vpp_luma_sum; + else + ve_dnlp_luma_sum = p->hist.luma_sum; + + /* counter the calling function --for what ?? */ + nTstCnt++; + if (nTstCnt > 240) + nTstCnt = 0; + + /*--------------------------------------------------------*/ + + + /*------ STEP A: load histogram and do histogram */ + /* -pre-processing and detections ---*/ + /*step 0.0 load the histogram*/ + /* nTstCnt not use */ + raw_hst_sum = load_histogram(&smbin_num, vf, hist_sel, nTstCnt); + /*step 0.1 all the same histogram as last frame, freeze DNLP */ + if (smbin_num == 64 && + dnlp_alg_param.dnlp_smhist_ck && + (!dnlp_alg_param.dnlp_respond_flag)) { + if (dnlp_printk & 0x1) + pr_info("WARNING: invalid hist @ step 0.10\n"); + return; + } + /* v3 luma sum is 0,something is wrong,freeze dnlp curve*/ + if (!ve_dnlp_luma_sum) { + dnlp_scn_chg = 1; + if (dnlp_printk & 0x1) + pr_info("WARNING: invalid hist @ step 0.11\n"); + return; + } + + /*step 0.2 calc T-IIR blending coef base on historic avg_luma change */ + dnlp_bld_lvl = curve_rfrsh_chk(raw_hst_sum, RBASE); + if (dnlp_printk & 0x1) + pr_info("Step A-0.2(after curve_rfrsh_chk()): dnlp_bld_lvl = %d\n", + dnlp_bld_lvl); + + /*step 0.3 black bord detection,*/ + /*s and histogram clipping,*/ + /*schange the pre_0_gamma, TBD */ + dnlp_refine_bin0(raw_hst_sum); + + /*step 0.4 histogram and luma_sum IIR filters in time domain, */ + dnlp_inhist_tiir(); + + /*step 0.5 get the hist begin and end bins */ + iir_hstSum = get_hist_bgn_end(&dnlp_alg_param.dnlp_iRgnBgn, + &dnlp_alg_param.dnlp_iRgnEnd, + &ihstBgn, &ihstEnd, raw_hst_sum); + if (dnlp_printk & 0x1) + pr_info("Step A-0.5(after get_hist_bgn_end()): iRgnBgn = %d,iRgnEnd = %d,ihstBgn = %d,ihstEnd = %d\n", + dnlp_alg_param.dnlp_iRgnBgn, + dnlp_alg_param.dnlp_iRgnEnd, ihstBgn, ihstEnd); + + /*step 0.6 Get the maximum 4 bins and averages of the histogram*/ + if (get_hist_max4_avgs(&mMaxLst[0], + &mMaxIdx[0], &low_lsum, &low_sum, + &rgn_lumSum, &rgn_hstSum, &rgn_hstMax, + &lsft_avg, &luma_avg4, &low_lavg4, &lmh_avg[4], + dnlp_alg_param.dnlp_iRgnBgn, + dnlp_alg_param.dnlp_iRgnEnd, + ihstBgn, ihstEnd) < 0) + return; /* rgn_vehstSum ? */ + + luma_avg = (luma_avg4>>2); + + if (luma_avg4 < 0 || luma_avg4 > 256) + pr_info("ERROR 0.6: lsft_avg=%d luma_avg=%d (%d), low_lavg4=%d, BE[%d %d %d %d], max4[%d %d %d %d][%d %d %d %d],rgn[%d %d %d], low<%d %d>\n", + lsft_avg, luma_avg, luma_avg4, low_lavg4, + dnlp_alg_param.dnlp_iRgnBgn, + dnlp_alg_param.dnlp_iRgnEnd, + ihstBgn, ihstEnd, + mMaxLst[0], mMaxLst[1], mMaxLst[2], + mMaxLst[3], mMaxIdx[0], mMaxIdx[1], + mMaxIdx[2], mMaxIdx[3], rgn_lumSum, + rgn_hstSum, rgn_hstMax, low_lsum, low_sum); + + if (dnlp_printk) + pr_info("Step A- 0.6(after get_hist_max4_avgs()): lsft_avg=%d luma_avg=%d (%d), low_lavg4=%d, BE[%d %d %d %d], max4[%d %d %d %d][%d %d %d %d],rgn[%d %d %d], low<%d %d>\n", + lsft_avg, luma_avg, luma_avg4, low_lavg4, + dnlp_alg_param.dnlp_iRgnBgn, + dnlp_alg_param.dnlp_iRgnEnd, + ihstBgn, ihstEnd, + mMaxLst[0], mMaxLst[1], mMaxLst[2], + mMaxLst[3], mMaxIdx[0], mMaxIdx[1], + mMaxIdx[2], mMaxIdx[3], rgn_lumSum, + rgn_hstSum, rgn_hstMax, low_lsum, low_sum); + + /*step 0.7 IIR filter of lsft_avg in time domain,(for getting s0,s1)*/ + lsft_avg = cal_hst_shft_avg(lsft_avg); + if (ve_dnlp_scv_dbg != 0) { + nTmp0 = lsft_avg + 16 * ve_dnlp_scv_dbg; + lsft_avg = (nTmp0 < 0) ? 0 : nTmp0; + } + + if (dnlp_printk & 0x1) + pr_info("Step A-0.7(after cal_hst_shft_avg()): lsft_avg = %d\n", + lsft_avg); + + + /* Step 4.x.2 in Step B */ + /*step 0.8 calclulate adaptive brightness plus + *based on luma_avg4 and low_lavg4 + */ + dnlp_brightness = cal_brght_plus(luma_avg4, low_lavg4); + if (dnlp_printk) { + pr_info("step A-0.8(after cal_brght_plus()): [avg1]= luma_avg=(%02d %02d) lsft_avg=(%4d) gmma_rate=%d, low_sum=%6d, low_lavg4=%2d, dnlp_brightness=%d,\n", + luma_avg, luma_avg4, lsft_avg, gmma_rate, + low_sum, low_lavg4, dnlp_brightness); + + } + + /* ----------------------------------- */ + /*step 0.9 150918 for 32-step luma pattern*/ + if (dnlp_alg_param.dnlp_dbg_adjavg) + luma_avg4 = AdjHistAvg(luma_avg4, ihstEnd); + /* if (luma_avg4<0 || luma_avg4>256) + *pr_info("ERROR 0.8: lsft_avg=%d luma_avg=%d (%d), + * low_lavg4=%d, BE[%d %d %d %d]\n",lsft_avg, luma_avg, + * luma_avg4, low_lavg4,iRgnBgn, iRgnEnd, ihstBgn, ihstEnd); + */ + + /*step 0.a do IIR filter of luma_avg4 on time domain*/ + luma_avg4 = cal_hist_avg(luma_avg4); /* IIR filtered in time domain */ + /*for read in tool*/ + ro_luma_avg4 = luma_avg4; + luma_avg = (luma_avg4>>2); + if (dnlp_printk & 0x1) + pr_info("Step A-0.a(after AdjHistAvg(),cal_hist_avg()): luma_avg4 = %d(iir), luma_avg = %d\n", + luma_avg4, luma_avg); + /* if (luma_avg4<0 || luma_avg4>256) + *pr_info("ERROR 0.9: lsft_avg=%d luma_avg=%d (%d), + * low_lavg4=%d, BE[%d %d %d %d]\n",lsft_avg, + * luma_avg,luma_avg4, low_lavg4,iRgnBgn, + * iRgnEnd, ihstBgn, ihstEnd); + */ + + /* cal hist variance */ + var = cal_hist_var(rgn_hstSum, luma_avg4, + dnlp_alg_param.dnlp_iRgnBgn, dnlp_alg_param.dnlp_iRgnEnd); + + /*step 0.b auto range detection and lmh_avg calc for further steps*/ + get_auto_range(&dnlp_auto_rng, &dnlp_lowrange, + &dnlp_hghrange, luma_avg); + get_lmh_avg(&lmh_sum[0], &lmh_avg[0], dnlp_lowrange, + dnlp_hghrange, dnlp_alg_param.dnlp_iRgnBgn, + dnlp_alg_param.dnlp_iRgnEnd); + if (dnlp_printk) { + pr_info("step A- 0.b(after get_auto_range() & get_lmh_avg() ):\n auto_rgn=%d, dnlp_lowrange=%d, dnlp_hghrange=%d, lmh_sum=[%d %d %d], lmh_avg=[%d %d %d %d %d]\n", + dnlp_auto_rng, dnlp_lowrange, dnlp_hghrange, + lmh_sum[0], lmh_sum[1], lmh_sum[2], lmh_avg[0], + lmh_avg[1], lmh_avg[2], lmh_avg[3], lmh_avg[4]); + } + /* ----------------------------------------- */ + + /*-------------------------------------------*/ + + + /* -- Step B: prepare different curves--- */ + /* step 1.x.1 and 1.x.2 */ + GetGmCurves(gma_scurve0, rGm1p2, lsft_avg, sBgnBnd, sEndBnd); + GetGmCurves(gma_scurve1, rGm1p8, lsft_avg, sBgnBnd, sEndBnd); + + GetGmScurve_apl_var(GmScurve, luma_avg4, var, sBgnBnd, sEndBnd); + + /* Step 2.x: CLAHE curve calculations */ + get_clahe_curve(clash_curve, &cluma_avg4, pre_0_gamma, + var, clashBgn, clashEnd); + clahe_tiir(); /* iir filter on time domain */ + + /* step 3.x: get the blk_gma_crv down curve */ + GetGmBlkCvs(blk_gma_crv, rGm1p8, sBgnBnd, dnlp_alg_param.dnlp_iRgnEnd); + /* ve_dnlp_pst_gmarat decide up arch or down; */ + /*adap dnlp_pst_gmarat is later in step-C */ + + /* Step 4.x.1: BWext parameters calc */ + /* u10 */ + cal_bwext_param(blk_wht_ext, ihstBgn, ihstEnd, + rgn_hstSum, lmh_avg); + if (dnlp_printk & 0x1) + pr_info("Step B-params: blk_wht_ext =[%d %d], dnlp_brightness =%d, luma_avg4 = %d, iRgnBgnEnd =[%d, %d]\n", + blk_wht_ext[0], blk_wht_ext[1], dnlp_brightness, + luma_avg4, dnlp_alg_param.dnlp_iRgnBgn, + dnlp_alg_param.dnlp_iRgnEnd); + + /* for debug */ + CrtTstDat[20] = sBgnBnd; + CrtTstDat[21] = sEndBnd; + CrtTstDat[22] = lsft_avg; + CrtTstDat[23] = dnlp_alg_param.dnlp_iRgnEnd; + + /*----------------------------------------------------*/ + + + /* --- Step C: do the blending coefs calculations ----- */ + + /* step 2.y blending rate betwen gama_scurve and CLAHE*/ + mtdbld_rate = dnlp_adp_mtdrate(mtdbld_rate, luma_avg); + if (dnlp_printk & 0x1) + pr_info("Step C-2.y(after dnlp_adp_mtdrate()): mtdbld_rate = %d\n", + mtdbld_rate); + + /*step 1.y. blending rate of s0,s1; + *plus a intermediate varibles(dnlp_pst_gmarat) for calc blk_gma_rat + */ + /* post gamma rate: global -> auto local ??? */ + if (ve_dnlp_pst_gmarat > 64) + dnlp_pst_gmarat = ve_dnlp_pst_gmarat - 64; + else + dnlp_pst_gmarat = 64 - ve_dnlp_pst_gmarat; + dnlp_adp_alpharate(lmh_avg, &low_alpha, &hgh_alpha, + &dnlp_pst_gmarat, dnlp_lowrange, dnlp_hghrange); + + if (ve_dnlp_pst_gmarat < 64) /* no adp dnlp_pst_gmarat */ + dnlp_pst_gmarat = 64 - ve_dnlp_pst_gmarat; + + if (dnlp_printk) { + pr_info("Step C-1.y(after dnlp_adp_alpharate() ): mtdbld: %2d (%2d %2d) => %2d (%2d %2d), gmma_rate=%d\n", + dnlp_alg_param.dnlp_mtdbld_rate, ve_dnlp_lowalpha_v3, + ve_dnlp_hghalpha_v3, mtdbld_rate, + low_alpha, hgh_alpha, gmma_rate); + } + + /*step y -adap: patch for black+white stripe, + *may change gmma_rate,low_alpha, hgh_alpha, mtdbld_rate + */ + patch_blk_wht(&mMaxLst[0], &mMaxIdx[0], &gmma_rate, + &low_alpha, &hgh_alpha, &mtdbld_rate, iir_hstSum); + if (dnlp_printk & 0x1) + pr_info("Step C-y(adap:after patch_blk_wht()): mtdbld_rate = %d\n", + mtdbld_rate); + + /*step y --adap: do post processing of + *the coefs based on the luma_avgs + */ + dnlp_params_hist(&gmma_rate, &low_alpha, &hgh_alpha, + &mtdbld_rate, luma_avg, luma_avg4); + if (dnlp_printk & 0x1) + pr_info("Step C-y(adap:after dnlp_params_hist()): mtdbld_rate = %d\n", + mtdbld_rate); + + + /* step 3.y get the coef for blending of + *blk_gma_bld = blk_gma_crv + clsh_scvbld + */ + get_blk_gma_rat(&blk_gma_rat[0], &dnlp_pstgma_ratio, dnlp_pst_gmarat); + if (dnlp_printk & 0x1) { + pr_info("Step C,final-params: gmma_rate =%d, low_alpha =%d, hgh_alpha =%d, lsft_avg =%d; luma_avg=%d(%d), mtdbld_rate=%d\n", + gmma_rate, low_alpha, hgh_alpha, lsft_avg, + luma_avg, luma_avg4, mtdbld_rate); + pr_info("Step C-3.y:after get_blk_gma_rat(),blk_gma_rat[64]=\n "); + for (i = 0; i < 64; i++) + pr_info("%4d ", blk_gma_rat[i]); + } + + /*------------------------------------------------------*/ + + + /* -------------- Step D: Curves Blendings ------ */ + /* step 1.z: blend scurve0 and scurve1 to get the gma_scurvet */ + /* Step 1.x + 1.y */ + dnlp_gmma_cuvs(gmma_rate, low_alpha, hgh_alpha, lsft_avg); + + /*step 2.z: clsh_scvbld = clash_curve + gma_scurvet */ + /* clash + s-curve Step 1.z + 2.x,2.y, */ + dnlp_clsh_sbld(mtdbld_rate); + + /*step 3.z: blk_gma_bld = blk_gma_crv + clsh_scvbld */ + /* Step 2.z + 3.x,3.y */ + dnlp_blkgma_bld(blk_gma_rat); + + /*for read on tools*/ + ro_blk_wht_ext0 = blk_wht_ext[0]; + ro_blk_wht_ext1 = blk_wht_ext[1]; + ro_dnlp_brightness = dnlp_brightness; + + /*step 4.z: blkwht_ebld = blk_gma_bld + extension */ + /* Step 3.z + 4.x,4.y */ + dnlp_blkwht_bld(blkwht_ebld, blk_gma_bld, + blk_wht_ext, dnlp_brightness, + luma_avg4, luma_avg, + dnlp_alg_param.dnlp_iRgnBgn, + dnlp_alg_param.dnlp_iRgnEnd); + + /*------------------------------------------------------*/ + + + + /*-- Step E: final curve selection, boosting and sorting Blendings---*/ + /*Step E.1 selection of curve and apply the dnlp_final_gain*/ + curv_selection(); + + + /*Step E.2: sort the curve to avoid luma invert, 0~255 sort */ + dnlp_tgt_sort(); + + /*Step E.3: do the saturation compensation based on the dnlp_curve */ + sat_compens = dnlp_sat_compensation(); + + prt_flg = ((dnlp_printk >> 11) & 0x1); + + if (prt_flg) { + for (i = 0; i < 64; i++) { + nT0 = ve_dnlp_tgt[i] - 4*i; + pr_info("%02d: %03d(45_line)=>%03d(final_cur) (%3d(dif))\n", + i, 4*i, ve_dnlp_tgt[i], nT0); } + pr_info("\n"); + } + + if (dnlp_printk) { + pr_info("#Dbg:[iRgnBgn < luma_avg(luma_avg4) < iRgnEnd] dnlp_brightness=, sat_compens=\n"); + pr_info("#Dbg:[%02d < %02d (%03d) < %02d] dnlp_brightness=%03d, sat_compens=%d\n", + dnlp_alg_param.dnlp_iRgnBgn, luma_avg, + luma_avg4, dnlp_alg_param.dnlp_iRgnEnd, + dnlp_brightness, sat_compens); + } + + + /* debug to print the curves */ + nT0 = 0; + prt_flg = ((dnlp_printk >> 11) & 0x1); + if (prt_flg) { + for (i = 0; i < 64; i++) + nT0 += ((premap0[i] > ve_dnlp_tgt[i]) ? + (premap0[i] - ve_dnlp_tgt[i]) : + (ve_dnlp_tgt[i] - premap0[i])); + + pr_info("Step E.4: map dif= %d\n", nT0); + + if (nT0 > ve_dnlp_dbg_diflvl) { + /* print pre map & current final map */ + pr_info("# mtdbld_rate=%02d brht=%02d\n", + mtdbld_rate, dnlp_brightness); + /* pre ve_dnlp_tgt */ + pr_info("[index] pre_1_gamma => pre_0_gamma:(premap0 =>ve_dnlp_tgt[])\n"); + for (i = 0; i < 64; i++) + if (premap0[i] != ve_dnlp_tgt[i]) + pr_info("[%02d]%5d=>%5d:(%4d=>%4d)\n", + i, + pre_1_gamma[i], pre_0_gamma[i], + premap0[i], ve_dnlp_tgt[i]); + /* CrtTstDat print out */ + pr_info("[index] PreTstDat=>CrtTstDat\n"); + for (i = 0; i < 28; i++) + if (PreTstDat[i] != CrtTstDat[i]) + pr_info("[%02d] %5d => %5d\n", + i, PreTstDat[i], CrtTstDat[i]); + pr_info("\n"); + + if (ve_dnlp_ponce >= 2) + ve_dnlp_ponce--; + else + ve_dnlp_ponce = 1; + } + } + + prt_flg = ((dnlp_printk >> 11) & 0x1); + if (dnlp_alg_param.dnlp_dbg_map && prt_flg) + for (i = 0; i < 64; i++) + pr_info("[index %02d] %5d(pre_0_gamma)=>%5d(ve_dnlp_tgt[])\n", + i, pre_0_gamma[i], ve_dnlp_tgt[i]); + + /* print debug log once */ + if (ve_dnlp_ponce == 1 && dnlp_printk) + dnlp_printk = 0; + +} + + /* lpf[0] is always 0 & no need calculation */ +void ve_dnlp_calculate_lpf(void) +{ + ulong i = 0; + + for (i = 0; i < 64; i++) + ve_dnlp_lpf[i] = ve_dnlp_lpf[i] - + (ve_dnlp_lpf[i] >> ve_dnlp_rt) + ve_dnlp_tgt[i]; +} + +void ve_dnlp_calculate_reg(void) +{ + ulong i = 0, j = 0, cur = 0, data = 0, + offset = ve_dnlp_rt ? (1 << (ve_dnlp_rt - 1)) : 0; + for (i = 0; i < 16; i++) { + ve_dnlp_reg[i] = 0; + cur = i << 2; + for (j = 0; j < 4; j++) { + data = (ve_dnlp_lpf[cur + j] + offset) >> ve_dnlp_rt; + if (data > 255) + data = 255; + ve_dnlp_reg[i] |= data << (j << 3); + } + } +} + +void ve_set_v3_dnlp(struct ve_dnlp_curve_param_s *p) +{ + ulong i = 0; + /* get command parameters */ + /* general settings */ + if ((ve_en != p->param[ve_dnlp_enable]) || + (dnlp_sel != p->param[ve_dnlp_sel]) || + (dnlp_alg_param.dnlp_lowrange != + p->param[ve_dnlp_lowrange]) || + (dnlp_alg_param.dnlp_hghrange != + p->param[ve_dnlp_hghrange]) || + (dnlp_alg_param.dnlp_auto_rng != + p->param[ve_dnlp_auto_rng]) || + (dnlp_alg_param.dnlp_bbd_ratio_low != + p->param[ve_dnlp_bbd_ratio_low]) || + (dnlp_alg_param.dnlp_bbd_ratio_hig != + p->param[ve_dnlp_bbd_ratio_hig]) || + (dnlp_alg_param.dnlp_mvreflsh != + p->param[ve_dnlp_mvreflsh]) || + (dnlp_alg_param.dnlp_smhist_ck != + p->param[ve_dnlp_smhist_ck]) || + (dnlp_alg_param.dnlp_final_gain != + p->param[ve_dnlp_final_gain]) || + (dnlp_alg_param.dnlp_clahe_gain_neg != + p->param[ve_dnlp_clahe_gain_neg]) || + (dnlp_alg_param.dnlp_clahe_gain_pos != + p->param[ve_dnlp_clahe_gain_pos]) || + (dnlp_alg_param.dnlp_mtdbld_rate != + p->param[ve_dnlp_mtdbld_rate]) || + (dnlp_alg_param.dnlp_adpmtd_lbnd != + p->param[ve_dnlp_adpmtd_lbnd]) || + (dnlp_alg_param.dnlp_adpmtd_hbnd != + p->param[ve_dnlp_adpmtd_hbnd]) || + (dnlp_alg_param.dnlp_sbgnbnd != + p->param[ve_dnlp_sbgnbnd]) || + (dnlp_alg_param.dnlp_sendbnd != + p->param[ve_dnlp_sendbnd]) || + (dnlp_alg_param.dnlp_cliprate_v3 != + p->param[ve_dnlp_cliprate_v3]) || + (dnlp_alg_param.dnlp_cliprate_min != + p->param[ve_dnlp_cliprate_min]) || + (dnlp_alg_param.dnlp_adpcrat_lbnd != + p->param[ve_dnlp_adpcrat_lbnd]) || + (dnlp_alg_param.dnlp_adpcrat_hbnd != + p->param[ve_dnlp_adpcrat_hbnd]) || + (dnlp_alg_param.dnlp_clashBgn != + p->param[ve_dnlp_clashBgn]) || + (dnlp_alg_param.dnlp_clashEnd != + p->param[ve_dnlp_clashEnd]) || + (dnlp_alg_param.dnlp_blkext_rate != + p->param[ve_dnlp_blkext_rate]) || + (dnlp_alg_param.dnlp_whtext_rate != + p->param[ve_dnlp_whtext_rate]) || + (dnlp_alg_param.dnlp_blkext_ofst != + p->param[ve_dnlp_blkext_ofst]) || + (dnlp_alg_param.dnlp_whtext_ofst != + p->param[ve_dnlp_whtext_ofst]) || + (dnlp_alg_param.dnlp_bwext_div4x_min != + p->param[ve_dnlp_bwext_div4x_min]) || + (dnlp_alg_param.dnlp_blk_cctr != + p->param[ve_dnlp_blk_cctr]) || + (dnlp_alg_param.dnlp_brgt_ctrl != + p->param[ve_dnlp_brgt_ctrl]) || + (dnlp_alg_param.dnlp_brgt_range != + p->param[ve_dnlp_brgt_range]) || + (dnlp_alg_param.dnlp_brght_add != + p->param[ve_dnlp_brght_add]) || + (dnlp_alg_param.dnlp_brght_max != + p->param[ve_dnlp_brght_max]) || + (dnlp_alg_param.dnlp_satur_rat != + p->param[ve_dnlp_satur_rat]) || + (dnlp_alg_param.dnlp_satur_max != + p->param[ve_dnlp_satur_max]) || + (dnlp_alg_param.dnlp_scurv_low_th != + p->param[ve_dnlp_scurv_low_th]) || + (dnlp_alg_param.dnlp_scurv_mid1_th != + p->param[ve_dnlp_scurv_mid1_th]) || + (dnlp_alg_param.dnlp_scurv_mid2_th != + p->param[ve_dnlp_scurv_mid2_th]) || + (dnlp_alg_param.dnlp_scurv_hgh1_th != + p->param[ve_dnlp_scurv_hgh1_th]) || + (dnlp_alg_param.dnlp_scurv_hgh2_th != + p->param[ve_dnlp_scurv_hgh2_th]) || + (dnlp_alg_param.dnlp_mtdrate_adp_en != + p->param[ve_dnlp_mtdrate_adp_en])) + menu_chg_en = 1; + else + return; + + ve_en = p->param[ve_dnlp_enable]; + dnlp_sel = p->param[ve_dnlp_sel]; + + /* hist auto range parms */ + dnlp_alg_param.dnlp_lowrange = p->param[ve_dnlp_lowrange]; + dnlp_alg_param.dnlp_hghrange = p->param[ve_dnlp_hghrange]; + dnlp_alg_param.dnlp_auto_rng = p->param[ve_dnlp_auto_rng]; + + /* histogram refine parms (remove bb affects) */ + dnlp_alg_param.dnlp_bbd_ratio_low = p->param[ve_dnlp_bbd_ratio_low]; + dnlp_alg_param.dnlp_bbd_ratio_hig = p->param[ve_dnlp_bbd_ratio_hig]; + + /* calc iir-coef params */ + dnlp_alg_param.dnlp_mvreflsh = p->param[ve_dnlp_mvreflsh]; + dnlp_alg_param.dnlp_smhist_ck = p->param[ve_dnlp_smhist_ck]; + + /* gains to delta of curves (for strength of the DNLP) */ + dnlp_alg_param.dnlp_final_gain = p->param[ve_dnlp_final_gain]; + dnlp_alg_param.dnlp_clahe_gain_neg = p->param[ve_dnlp_clahe_gain_neg]; + dnlp_alg_param.dnlp_clahe_gain_pos = p->param[ve_dnlp_clahe_gain_pos]; + + /* coef of blending between gma_scurv and clahe curves */ + dnlp_alg_param.dnlp_mtdbld_rate = p->param[ve_dnlp_mtdbld_rate]; + dnlp_alg_param.dnlp_adpmtd_lbnd = p->param[ve_dnlp_adpmtd_lbnd]; + dnlp_alg_param.dnlp_adpmtd_hbnd = p->param[ve_dnlp_adpmtd_hbnd]; + + /* for gma_scurvs processing range */ + dnlp_alg_param.dnlp_sbgnbnd = p->param[ve_dnlp_sbgnbnd]; + dnlp_alg_param.dnlp_sendbnd = p->param[ve_dnlp_sendbnd]; + + /* curve- clahe */ + dnlp_alg_param.dnlp_cliprate_v3 = p->param[ve_dnlp_cliprate_v3]; + dnlp_alg_param.dnlp_cliprate_min = p->param[ve_dnlp_cliprate_min]; + dnlp_alg_param.dnlp_adpcrat_lbnd = p->param[ve_dnlp_adpcrat_lbnd]; + dnlp_alg_param.dnlp_adpcrat_hbnd = p->param[ve_dnlp_adpcrat_hbnd]; + + /* for clahe_curvs processing range */ + dnlp_alg_param.dnlp_clashBgn = p->param[ve_dnlp_clashBgn]; + dnlp_alg_param.dnlp_clashEnd = p->param[ve_dnlp_clashEnd]; + + /* black white extension control params */ + dnlp_alg_param.dnlp_blkext_rate = p->param[ve_dnlp_blkext_rate]; + dnlp_alg_param.dnlp_whtext_rate = p->param[ve_dnlp_whtext_rate]; + dnlp_alg_param.dnlp_blkext_ofst = p->param[ve_dnlp_blkext_ofst]; + dnlp_alg_param.dnlp_whtext_ofst = p->param[ve_dnlp_whtext_ofst]; + dnlp_alg_param.dnlp_bwext_div4x_min = p->param[ve_dnlp_bwext_div4x_min]; + + /* brightness_plus */ + dnlp_alg_param.dnlp_blk_cctr = p->param[ve_dnlp_blk_cctr]; + dnlp_alg_param.dnlp_brgt_ctrl = p->param[ve_dnlp_brgt_ctrl]; + dnlp_alg_param.dnlp_brgt_range = p->param[ve_dnlp_brgt_range]; + dnlp_alg_param.dnlp_brght_add = p->param[ve_dnlp_brght_add]; + dnlp_alg_param.dnlp_brght_max = p->param[ve_dnlp_brght_max]; + + /* adaptive saturation compensations */ + dnlp_alg_param.dnlp_satur_rat = p->param[ve_dnlp_satur_rat]; + dnlp_alg_param.dnlp_satur_max = p->param[ve_dnlp_satur_max]; + dnlp_alg_param.dnlp_scurv_low_th = p->param[ve_dnlp_scurv_low_th]; + dnlp_alg_param.dnlp_scurv_mid1_th = p->param[ve_dnlp_scurv_mid1_th]; + dnlp_alg_param.dnlp_scurv_mid2_th = p->param[ve_dnlp_scurv_mid2_th]; + dnlp_alg_param.dnlp_scurv_hgh1_th = p->param[ve_dnlp_scurv_hgh1_th]; + dnlp_alg_param.dnlp_scurv_hgh2_th = p->param[ve_dnlp_scurv_hgh2_th]; + dnlp_alg_param.dnlp_mtdrate_adp_en = + p->param[ve_dnlp_mtdrate_adp_en]; + /* TODO: ve_dnlp_set_saturtn = p->dnlp_set_saturtn; */ + + /*load static curve*/ + for (i = 0; i < 65; i++) { + dnlp_scurv_low[i] = p->ve_dnlp_scurv_low[i]; + dnlp_scurv_mid1[i] = p->ve_dnlp_scurv_mid1[i]; + dnlp_scurv_mid2[i] = p->ve_dnlp_scurv_mid2[i]; + dnlp_scurv_hgh1[i] = p->ve_dnlp_scurv_hgh1[i]; + dnlp_scurv_hgh2[i] = p->ve_dnlp_scurv_hgh2[i]; + } + /*load gain var*/ + for (i = 0; i < 49; i++) + gain_var_lut49[i] = p->ve_gain_var_lut49[i]; + /*load wext gain*/ + for (i = 0; i < 48; i++) + wext_gain[i] = p->ve_wext_gain[i]; + + if (ve_en) { + /* clear historic luma sum */ + ve_dnlp_luma_sum = 0; + /* init tgt & lpf */ + for (i = 0; i < 64; i++) { + ve_dnlp_tgt[i] = i << 2; + ve_dnlp_lpf[i] = ve_dnlp_tgt[i] << ve_dnlp_rt; + } + /* calculate dnlp reg data */ + ve_dnlp_calculate_reg(); + /* load dnlp reg data */ + ve_dnlp_load_reg(); + /* enable dnlp */ + ve_enable_dnlp(); + } else { + /* disable dnlp */ + ve_disable_dnlp(); + } + +} + diff --git a/drivers/amlogic/media/enhancement/amvecm/dnlp_cal.h b/drivers/amlogic/media/enhancement/amvecm/dnlp_cal.h new file mode 100644 index 000000000000..1e189581e544 --- /dev/null +++ b/drivers/amlogic/media/enhancement/amvecm/dnlp_cal.h @@ -0,0 +1,108 @@ + +#ifndef __AM_DNLP_CAL_H +#define __AM_DNLP_CAL_H + +struct dnlp_alg_param_s { + unsigned int dnlp_alg_enable; + unsigned int dnlp_respond; + unsigned int dnlp_sel; + unsigned int dnlp_respond_flag; + unsigned int dnlp_smhist_ck; + unsigned int dnlp_mvreflsh; + unsigned int dnlp_pavg_btsft; + unsigned int dnlp_dbg_i2r; + unsigned int dnlp_cuvbld_min; + unsigned int dnlp_cuvbld_max; + unsigned int dnlp_schg_sft; + unsigned int dnlp_bbd_ratio_low; + unsigned int dnlp_bbd_ratio_hig; + unsigned int dnlp_limit_rng; + unsigned int dnlp_range_det; + unsigned int dnlp_blk_cctr; + unsigned int dnlp_brgt_ctrl; + unsigned int dnlp_brgt_range; + unsigned int dnlp_brght_add; + unsigned int dnlp_brght_max; + unsigned int dnlp_dbg_adjavg; + unsigned int dnlp_auto_rng; + unsigned int dnlp_lowrange; + unsigned int dnlp_hghrange; + unsigned int dnlp_satur_rat; + unsigned int dnlp_satur_max; + unsigned int dnlp_set_saturtn; + unsigned int dnlp_sbgnbnd; + unsigned int dnlp_sendbnd; + unsigned int dnlp_clashBgn; + unsigned int dnlp_clashEnd; + unsigned int dnlp_var_th; + unsigned int dnlp_clahe_gain_neg; + unsigned int dnlp_clahe_gain_pos; + unsigned int dnlp_clahe_gain_delta; + unsigned int dnlp_mtdbld_rate; + unsigned int dnlp_adpmtd_lbnd; + unsigned int dnlp_adpmtd_hbnd; + unsigned int dnlp_blkext_ofst; + unsigned int dnlp_whtext_ofst; + unsigned int dnlp_blkext_rate; + unsigned int dnlp_whtext_rate; + unsigned int dnlp_bwext_div4x_min; + unsigned int dnlp_iRgnBgn; + unsigned int dnlp_iRgnEnd; + unsigned int dnlp_dbg_map; + unsigned int dnlp_final_gain; + unsigned int dnlp_cliprate_v3; + unsigned int dnlp_cliprate_min; + unsigned int dnlp_adpcrat_lbnd; + unsigned int dnlp_adpcrat_hbnd; + unsigned int dnlp_scurv_low_th; + unsigned int dnlp_scurv_mid1_th; + unsigned int dnlp_scurv_mid2_th; + unsigned int dnlp_scurv_hgh1_th; + unsigned int dnlp_scurv_hgh2_th; + unsigned int dnlp_mtdrate_adp_en; +}; + +struct dnlp_parse_cmd_s { + char *parse_string; + unsigned int *value; +}; + +extern struct ve_dnlp_table_s am_ve_new_dnlp; +extern struct ve_dnlp_curve_param_s dnlp_curve_param_load; +extern unsigned int ve_dnlp_rt; +extern unsigned char ve_dnlp_tgt[65]; +extern int GmScurve[65]; +extern int clash_curve[65]; +extern int clsh_scvbld[65]; +extern int blkwht_ebld[65]; +extern bool ve_en; +extern unsigned int ve_dnlp_rt; +extern unsigned int ve_dnlp_luma_sum; +extern ulong ve_dnlp_lpf[64]; +extern ulong ve_dnlp_reg[16]; +extern ulong ve_dnlp_reg_def[16]; +extern struct dnlp_parse_cmd_s dnlp_parse_cmd[]; + +extern int dnlp_scurv_low[65]; +extern int dnlp_scurv_mid1[65]; +extern int dnlp_scurv_mid2[65]; +extern int dnlp_scurv_hgh1[65]; +extern int dnlp_scurv_hgh2[65]; +extern int gain_var_lut49[49]; +extern int wext_gain[48]; + +extern int ro_luma_avg4; +extern int ro_var_d8; +extern int ro_scurv_gain; +extern int ro_blk_wht_ext0; +extern int ro_blk_wht_ext1; +extern int ro_dnlp_brightness; + +extern void ve_dnlp_calculate_tgtx_v3(struct vframe_s *vf); +extern void ve_set_v3_dnlp(struct ve_dnlp_curve_param_s *p); +extern void ve_dnlp_calculate_lpf(void); +extern void ve_dnlp_calculate_reg(void); +extern void dnlp_alg_param_init(void); +#endif + + diff --git a/include/linux/amlogic/media/amvecm/amvecm.h b/include/linux/amlogic/media/amvecm/amvecm.h index 44c80c8327f8..f7adfb63f7e8 100644 --- a/include/linux/amlogic/media/amvecm/amvecm.h +++ b/include/linux/amlogic/media/amvecm/amvecm.h @@ -125,11 +125,10 @@ enum pq_table_name_e { #define _VE_CM 'C' -#define AMVECM_IOC_VE_DNLP _IOW(_VE_CM, 0x21, struct ve_dnlp_s) #define AMVECM_IOC_G_HIST_AVG _IOW(_VE_CM, 0x22, struct ve_hist_s) #define AMVECM_IOC_VE_DNLP_EN _IO(_VE_CM, 0x23) #define AMVECM_IOC_VE_DNLP_DIS _IO(_VE_CM, 0x24) -#define AMVECM_IOC_VE_NEW_DNLP _IOW(_VE_CM, 0x25, struct ve_dnlp_table_s) +#define AMVECM_IOC_VE_NEW_DNLP _IOW(_VE_CM, 0x25, struct ve_dnlp_curve_param_s) #define AMVECM_IOC_G_HIST_BIN _IOW(_VE_CM, 0x26, struct vpp_hist_param_s) #define AMVECM_IOC_G_HDR_METADATA _IOW(_VE_CM, 0x27, struct hdr_metadata_info_s) diff --git a/include/linux/amlogic/media/amvecm/ve.h b/include/linux/amlogic/media/amvecm/ve.h index 4f0f274c4cab..c96aa531c196 100644 --- a/include/linux/amlogic/media/amvecm/ve.h +++ b/include/linux/amlogic/media/amvecm/ve.h @@ -66,107 +66,92 @@ struct ve_hist_s { int height; int ave; }; -struct ve_dnlp_table_s { - unsigned int en; - unsigned int method; - unsigned int cliprate; - unsigned int lowrange; - unsigned int hghrange; - unsigned int lowalpha; - unsigned int midalpha; - unsigned int hghalpha; - unsigned int adj_level; - unsigned int new_adj_level; - unsigned int new_mvreflsh; - unsigned int new_gmma_rate; - unsigned int new_lowalpha; - unsigned int new_hghalpha; - unsigned int new_sbgnbnd; - unsigned int new_sendbnd; - unsigned int new_clashBgn; - unsigned int new_clashEnd; - unsigned int new_cliprate; - unsigned int new_mtdbld_rate; - unsigned int new_dnlp_pst_gmarat; - unsigned int dnlp_sel; - unsigned int dnlp_blk_cctr;/*blk signal add brightness*/ - unsigned int dnlp_brgt_ctrl; - unsigned int dnlp_brgt_range; - unsigned int dnlp_brght_add; - unsigned int dnlp_brght_max; - unsigned int dnlp_almst_wht; - unsigned int dnlp_hghbin;/*1*/ - unsigned int dnlp_hghnum; - unsigned int dnlp_lowbin; - unsigned int dnlp_lownum; - unsigned int dnlp_bkgend; - unsigned int dnlp_bkgert; - unsigned int dnlp_blkext; - unsigned int dnlp_whtext; - unsigned int dnlp_bextmx; - unsigned int dnlp_wextmx; - unsigned int dnlp_smhist_ck; - unsigned int dnlp_glb_crate;/*12*/ - unsigned int dnlp_pstgma_brghtrate; - unsigned int dnlp_pstgma_brghtrat1; - unsigned int dnlp_wext_autorat; - unsigned int dnlp_cliprate_min; - unsigned int dnlp_adpcrat_lbnd; - unsigned int dnlp_adpcrat_hbnd; - unsigned int dnlp_adpmtd_lbnd; - unsigned int dnlp_adpmtd_hbnd; - unsigned int dnlp_set_bext; - unsigned int dnlp_set_wext; - unsigned int dnlp_satur_rat; - unsigned int dnlp_satur_max; - unsigned int blk_prct_rng; - unsigned int blk_prct_max; - unsigned int dnlp_lowrange; - unsigned int dnlp_hghrange; - unsigned int dnlp_auto_rng; - unsigned int dnlp_bin0_absmax; - unsigned int dnlp_bin0_sbtmax; - unsigned int dnlp_adpalpha_lrate; - unsigned int dnlp_adpalpha_hrate; - unsigned int dnlp_lrate00;/*0-64bin curve slope*/ - unsigned int dnlp_lrate02; - unsigned int dnlp_lrate04; - unsigned int dnlp_lrate06; - unsigned int dnlp_lrate08; - unsigned int dnlp_lrate10; - unsigned int dnlp_lrate12; - unsigned int dnlp_lrate14; - unsigned int dnlp_lrate16; - unsigned int dnlp_lrate18; - unsigned int dnlp_lrate20; - unsigned int dnlp_lrate22; - unsigned int dnlp_lrate24; - unsigned int dnlp_lrate26; - unsigned int dnlp_lrate28; - unsigned int dnlp_lrate30; - unsigned int dnlp_lrate32; - unsigned int dnlp_lrate34; - unsigned int dnlp_lrate36; - unsigned int dnlp_lrate38; - unsigned int dnlp_lrate40; - unsigned int dnlp_lrate42; - unsigned int dnlp_lrate44; - unsigned int dnlp_lrate46; - unsigned int dnlp_lrate48; - unsigned int dnlp_lrate50; - unsigned int dnlp_lrate52; - unsigned int dnlp_lrate54; - unsigned int dnlp_lrate56; - unsigned int dnlp_lrate58; - unsigned int dnlp_lrate60; - unsigned int dnlp_lrate62; -}; + struct vpp_hist_param_s { unsigned int vpp_hist_pow; unsigned int vpp_luma_sum; unsigned int vpp_pixel_sum; unsigned short vpp_histgram[64]; }; +struct ve_dnlp_curve_param_s { + unsigned int ve_dnlp_scurv_low[65]; + unsigned int ve_dnlp_scurv_mid1[65]; + unsigned int ve_dnlp_scurv_mid2[65]; + unsigned int ve_dnlp_scurv_hgh1[65]; + unsigned int ve_dnlp_scurv_hgh2[65]; + unsigned int ve_gain_var_lut49[49]; + unsigned int ve_wext_gain[48]; + unsigned int param[100]; +}; +enum dnlp_param_e { + ve_dnlp_enable = 0, + ve_dnlp_respond, + ve_dnlp_sel, + ve_dnlp_respond_flag, + ve_dnlp_smhist_ck, + ve_dnlp_mvreflsh, + ve_dnlp_pavg_btsft, + ve_dnlp_dbg_i2r, + ve_dnlp_cuvbld_min, + ve_dnlp_cuvbld_max, + ve_dnlp_schg_sft, + ve_dnlp_bbd_ratio_low, + ve_dnlp_bbd_ratio_hig, + ve_dnlp_limit_rng, + ve_dnlp_range_det, + ve_dnlp_blk_cctr, + ve_dnlp_brgt_ctrl, + ve_dnlp_brgt_range, + ve_dnlp_brght_add, + ve_dnlp_brght_max, + ve_dnlp_dbg_adjavg, + ve_dnlp_auto_rng, + ve_dnlp_lowrange, + ve_dnlp_hghrange, + ve_dnlp_satur_rat, + ve_dnlp_satur_max, + ve_dnlp_set_saturtn, + ve_dnlp_sbgnbnd, + ve_dnlp_sendbnd, + ve_dnlp_clashBgn, + ve_dnlp_clashEnd, + ve_dnlp_var_th, + ve_dnlp_clahe_gain_neg, + ve_dnlp_clahe_gain_pos, + ve_dnlp_clahe_gain_delta, + ve_dnlp_mtdbld_rate, + ve_dnlp_adpmtd_lbnd, + ve_dnlp_adpmtd_hbnd, + ve_dnlp_blkext_ofst, + ve_dnlp_whtext_ofst, + ve_dnlp_blkext_rate, + ve_dnlp_whtext_rate, + ve_dnlp_bwext_div4x_min, + ve_dnlp_iRgnBgn, + ve_dnlp_iRgnEnd, + ve_dnlp_dbg_map, + ve_dnlp_final_gain, + ve_dnlp_cliprate_v3, + ve_dnlp_cliprate_min, + ve_dnlp_adpcrat_lbnd, + ve_dnlp_adpcrat_hbnd, + ve_dnlp_scurv_low_th, + ve_dnlp_scurv_mid1_th, + ve_dnlp_scurv_mid2_th, + ve_dnlp_scurv_hgh1_th, + ve_dnlp_scurv_hgh2_th, + ve_dnlp_mtdrate_adp_en, + ve_dnlp_param_max, +}; +enum dnlp_curve_e { + ve_scurv_low = 1000, + ve_scurv_mid1, + ve_scurv_mid2, + ve_scurv_hgh1, + ve_scurv_hgh2, + ve_curv_var_lut49, + ve_curv_wext_gain, +}; #else struct ve_dnlp_s { unsigned char en;