@@ -500,6 +500,15 @@ struct isharp_1D_lut_pregen filter_isharp_1D_lut_pregen[NUM_SHARPNESS_SETUPS] =
500500 },
501501};
502502
503+ struct scale_ratio_to_sharpness_level_adj sharpness_level_adj [NUM_SHARPNESS_ADJ_LEVELS ] = {
504+ {1125 , 1000 , 0 },
505+ {11 , 10 , 1 },
506+ {1075 , 1000 , 2 },
507+ {105 , 100 , 3 },
508+ {1025 , 1000 , 4 },
509+ {1 , 1 , 5 },
510+ };
511+
503512const uint32_t * spl_get_filter_isharp_1D_lut_0 (void )
504513{
505514 return filter_isharp_1D_lut_0 ;
@@ -541,35 +550,99 @@ uint16_t *spl_get_filter_isharp_bs_3tap_64p(void)
541550 return filter_isharp_bs_3tap_64p_s1_12 ;
542551}
543552
544- static unsigned int spl_calculate_sharpness_level (int discrete_sharpness_level , enum system_setup setup ,
545- struct spl_sharpness_range sharpness_range )
553+ static unsigned int spl_calculate_sharpness_level_adj (struct spl_fixed31_32 ratio )
554+ {
555+ int j ;
556+ struct spl_fixed31_32 ratio_level ;
557+ struct scale_ratio_to_sharpness_level_adj * lookup_ptr ;
558+ unsigned int sharpness_level_down_adj ;
559+
560+ /*
561+ * Adjust sharpness level based on current scaling ratio
562+ *
563+ * We have 5 discrete scaling ratios which we will use to adjust the
564+ * sharpness level down by 1 as we pass each ratio. The ratios
565+ * are
566+ *
567+ * 1.125 upscale and higher - no adj
568+ * 1.100 - under 1.125 - adj level down 1
569+ * 1.075 - under 1.100 - adj level down 2
570+ * 1.050 - under 1.075 - adj level down 3
571+ * 1.025 - under 1.050 - adj level down 4
572+ * 1.000 - under 1.025 - adj level down 5
573+ *
574+ */
575+ j = 0 ;
576+ sharpness_level_down_adj = 0 ;
577+ lookup_ptr = sharpness_level_adj ;
578+ while (j < NUM_SHARPNESS_ADJ_LEVELS ) {
579+ ratio_level = spl_fixpt_from_fraction (lookup_ptr -> ratio_numer ,
580+ lookup_ptr -> ratio_denom );
581+ if (ratio .value >= ratio_level .value ) {
582+ sharpness_level_down_adj = lookup_ptr -> level_down_adj ;
583+ break ;
584+ }
585+ lookup_ptr ++ ;
586+ j ++ ;
587+ }
588+ return sharpness_level_down_adj ;
589+ }
590+
591+ static unsigned int spl_calculate_sharpness_level (struct spl_fixed31_32 ratio ,
592+ int discrete_sharpness_level , enum system_setup setup ,
593+ struct spl_sharpness_range sharpness_range ,
594+ enum scale_to_sharpness_policy scale_to_sharpness_policy )
546595{
547596 unsigned int sharpness_level = 0 ;
597+ unsigned int sharpness_level_down_adj = 0 ;
548598
549599 int min_sharpness , max_sharpness , mid_sharpness ;
550600
601+ /*
602+ * Adjust sharpness level if policy requires we adjust it based on
603+ * scale ratio. Based on scale ratio, we may adjust the sharpness
604+ * level down by a certain number of steps. We will not select
605+ * a sharpness value of 0 so the lowest sharpness level will be
606+ * 0 or 1 depending on what the min_sharpness is
607+ *
608+ * If the policy is no required, this code maybe removed at a later
609+ * date
610+ */
551611 switch (setup ) {
552612
553613 case HDR_L :
554614 min_sharpness = sharpness_range .hdr_rgb_min ;
555615 max_sharpness = sharpness_range .hdr_rgb_max ;
556616 mid_sharpness = sharpness_range .hdr_rgb_mid ;
617+ if (scale_to_sharpness_policy == SCALE_TO_SHARPNESS_ADJ_ALL )
618+ sharpness_level_down_adj = spl_calculate_sharpness_level_adj (ratio );
557619 break ;
558620 case HDR_NL :
559621 /* currently no use case, use Non-linear SDR values for now */
560622 case SDR_NL :
561623 min_sharpness = sharpness_range .sdr_yuv_min ;
562624 max_sharpness = sharpness_range .sdr_yuv_max ;
563625 mid_sharpness = sharpness_range .sdr_yuv_mid ;
626+ if (scale_to_sharpness_policy >= SCALE_TO_SHARPNESS_ADJ_YUV )
627+ sharpness_level_down_adj = spl_calculate_sharpness_level_adj (ratio );
564628 break ;
565629 case SDR_L :
566630 default :
567631 min_sharpness = sharpness_range .sdr_rgb_min ;
568632 max_sharpness = sharpness_range .sdr_rgb_max ;
569633 mid_sharpness = sharpness_range .sdr_rgb_mid ;
634+ if (scale_to_sharpness_policy == SCALE_TO_SHARPNESS_ADJ_ALL )
635+ sharpness_level_down_adj = spl_calculate_sharpness_level_adj (ratio );
570636 break ;
571637 }
572638
639+ if ((min_sharpness == 0 ) && (sharpness_level_down_adj >= discrete_sharpness_level ))
640+ discrete_sharpness_level = 1 ;
641+ else if (sharpness_level_down_adj >= discrete_sharpness_level )
642+ discrete_sharpness_level = 0 ;
643+ else
644+ discrete_sharpness_level -= sharpness_level_down_adj ;
645+
573646 int lower_half_step_size = (mid_sharpness - min_sharpness ) / 5 ;
574647 int upper_half_step_size = (max_sharpness - mid_sharpness ) / 5 ;
575648
@@ -584,7 +657,7 @@ static unsigned int spl_calculate_sharpness_level(int discrete_sharpness_level,
584657}
585658
586659void spl_build_isharp_1dlut_from_reference_curve (struct spl_fixed31_32 ratio , enum system_setup setup ,
587- struct adaptive_sharpness sharpness )
660+ struct adaptive_sharpness sharpness , enum scale_to_sharpness_policy scale_to_sharpness_policy )
588661{
589662 uint8_t * byte_ptr_1dlut_src , * byte_ptr_1dlut_dst ;
590663 struct spl_fixed31_32 sharp_base , sharp_calc , sharp_level ;
@@ -594,8 +667,9 @@ void spl_build_isharp_1dlut_from_reference_curve(struct spl_fixed31_32 ratio, en
594667 uint32_t filter_pregen_store [ISHARP_LUT_TABLE_SIZE ];
595668
596669 /* Custom sharpnessX1000 value */
597- unsigned int sharpnessX1000 = spl_calculate_sharpness_level (sharpness .sharpness_level ,
598- setup , sharpness .sharpness_range );
670+ unsigned int sharpnessX1000 = spl_calculate_sharpness_level (ratio ,
671+ sharpness .sharpness_level , setup ,
672+ sharpness .sharpness_range , scale_to_sharpness_policy );
599673 sharp_level = spl_fixpt_from_fraction (sharpnessX1000 , 1000 );
600674
601675 /*
@@ -606,7 +680,6 @@ void spl_build_isharp_1dlut_from_reference_curve(struct spl_fixed31_32 ratio, en
606680 (filter_isharp_1D_lut_pregen [setup ].sharpness_denom == 1000 ))
607681 return ;
608682
609-
610683 /*
611684 * Calculate LUT_128_gained with this equation:
612685 *
0 commit comments