/** * Convert the drm_color_lut to dc_gamma. The conversion depends on the size * of the lut - whether or not it's legacy. */ static void __drm_lut_to_dc_gamma(struct drm_color_lut *lut, struct dc_gamma *gamma, bool is_legacy) { uint32_t r, g, b; int i; if (is_legacy) { for (i = 0; i < MAX_COLOR_LEGACY_LUT_ENTRIES; i++) { r = drm_color_lut_extract(lut[i].red, 16); g = drm_color_lut_extract(lut[i].green, 16); b = drm_color_lut_extract(lut[i].blue, 16); gamma->entries.red[i] = dal_fixed31_32_from_int(r); gamma->entries.green[i] = dal_fixed31_32_from_int(g); gamma->entries.blue[i] = dal_fixed31_32_from_int(b); } return; } /* else */ for (i = 0; i < MAX_COLOR_LUT_ENTRIES; i++) { r = drm_color_lut_extract(lut[i].red, 16); g = drm_color_lut_extract(lut[i].green, 16); b = drm_color_lut_extract(lut[i].blue, 16); gamma->entries.red[i] = dal_fixed31_32_from_fraction(r, MAX_DRM_LUT_VALUE); gamma->entries.green[i] = dal_fixed31_32_from_fraction(g, MAX_DRM_LUT_VALUE); gamma->entries.blue[i] = dal_fixed31_32_from_fraction(b, MAX_DRM_LUT_VALUE); } }
uint16_t fixed_point_to_int_frac( struct fixed31_32 arg, uint8_t integer_bits, uint8_t fractional_bits) { int32_t numerator; int32_t divisor = 1 << fractional_bits; uint16_t result; uint16_t d = (uint16_t)dal_fixed31_32_floor( dal_fixed31_32_abs( arg)); if (d <= (uint16_t)(1 << integer_bits) - (1 / (uint16_t)divisor)) numerator = (uint16_t)dal_fixed31_32_floor( dal_fixed31_32_mul_int( arg, divisor)); else { numerator = dal_fixed31_32_floor( dal_fixed31_32_sub( dal_fixed31_32_from_int( 1LL << integer_bits), dal_fixed31_32_recip( dal_fixed31_32_from_int( divisor)))); } if (numerator >= 0) result = (uint16_t)numerator; else result = (uint16_t)( (1 << (integer_bits + fractional_bits + 1)) + numerator); if ((result != 0) && dal_fixed31_32_lt( arg, dal_fixed31_32_zero)) result |= 1 << (integer_bits + fractional_bits); return result; }
/* * initialize_color_float_adj_reference_values * This initialize display color adjust input from API to HW range for later * calculation use. This is shared by all the display color adjustment. * @param : * @return None */ static void initialize_color_float_adj_reference_values( const struct opp_grph_csc_adjustment *adjust, struct fixed31_32 *grph_cont, struct fixed31_32 *grph_sat, struct fixed31_32 *grph_bright, struct fixed31_32 *sin_grph_hue, struct fixed31_32 *cos_grph_hue) { /* Hue adjustment could be negative. -45 ~ +45 */ struct fixed31_32 hue = dal_fixed31_32_mul( dal_fixed31_32_from_fraction(adjust->grph_hue, 180), dal_fixed31_32_pi); *sin_grph_hue = dal_fixed31_32_sin(hue); *cos_grph_hue = dal_fixed31_32_cos(hue); if (adjust->adjust_divider) { *grph_cont = dal_fixed31_32_from_fraction( adjust->grph_cont, adjust->adjust_divider); *grph_sat = dal_fixed31_32_from_fraction( adjust->grph_sat, adjust->adjust_divider); *grph_bright = dal_fixed31_32_from_fraction( adjust->grph_bright, adjust->adjust_divider); } else { *grph_cont = dal_fixed31_32_from_int(adjust->grph_cont); *grph_sat = dal_fixed31_32_from_int(adjust->grph_sat); *grph_bright = dal_fixed31_32_from_int(adjust->grph_bright); } }
enum ds_return dal_grph_colors_group_get_color_gamut( struct grph_colors_group *grph_colors_adj, struct display_path *disp_path, const struct ds_gamut_reference_data *ref, struct ds_get_gamut_data *data) { enum ds_return ret; uint32_t display_index; struct adj_container *adj_container = NULL; struct adjustment_info *temperature_src = NULL; const struct display_characteristics *disp_char = NULL; struct color_characteristic color_charact = {{0 } }; struct gamut_data gamut_data; enum adjustment_id adj_id; struct fixed31_32 result; if (!disp_path) return DS_ERROR; display_index = dal_display_path_get_display_index( disp_path); adj_container = dal_ds_dispatch_get_adj_container_for_path( grph_colors_adj->ds, display_index); if (!adj_container) return DS_ERROR; if (!dal_hw_sequencer_is_support_custom_gamut_adj( grph_colors_adj->hws, disp_path, HW_GRAPHIC_SURFACE)) return DS_ERROR; dal_memset(&gamut_data, 0, sizeof(gamut_data)); if (!dal_ds_translate_gamut_reference( ref, &adj_id)) return DS_ERROR; if (adj_id == ADJ_ID_GAMUT_DESTINATION) { temperature_src = dal_adj_info_set_get_adj_info( &adj_container->adj_info_set, ADJ_ID_TEMPERATURE_SOURCE); if (temperature_src != NULL && temperature_src->adj_data.ranged.cur == COLOR_TEMPERATURE_SOURCE_EDID) { disp_char = dal_adj_container_get_disp_character( adj_container); if (!disp_char) return DS_ERROR; if (!dal_gamut_space_convert_edid_format_color_charact( disp_char->color_characteristics, &color_charact)) return DS_ERROR; gamut_data.option.bits.CUSTOM_GAMUT_SPACE = 1; gamut_data.option.bits.CUSTOM_WHITE_POINT = 1; result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.red_x); gamut_data.gamut.custom.red_x = dal_fixed31_32_floor(result); result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.red_y); gamut_data.gamut.custom.red_y = dal_fixed31_32_floor(result); result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.blue_x); gamut_data.gamut.custom.blue_x = dal_fixed31_32_floor(result); result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.blue_y); gamut_data.gamut.custom.blue_y = dal_fixed31_32_floor(result); result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.green_x); gamut_data.gamut.custom.green_x = dal_fixed31_32_floor(result); result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.green_y); gamut_data.gamut.custom.green_y = dal_fixed31_32_floor(result); result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.white_x); gamut_data.white_point.custom.white_x = dal_fixed31_32_floor(result); result = dal_fixed31_32_mul( dal_fixed31_32_from_int( (int64_t)GAMUT_DIVIDER), color_charact.white_y); gamut_data.white_point.custom.white_y = dal_fixed31_32_floor(result); ret = DS_SUCCESS; } } if (ret != DS_SUCCESS) if (!dal_adj_container_get_gamut( adj_container, adj_id, &gamut_data)) return DS_ERROR; if (!dal_ds_translate_internal_gamut_to_external_parameter( &gamut_data, &data->gamut)) return DS_ERROR; return ret; }