2 * Copyright 2016 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef COLOR_MOD_COLOR_GAMMA_H_
27 #define COLOR_MOD_COLOR_GAMMA_H_
29 #include "color_table.h"
31 struct dc_transfer_func;
33 struct dc_transfer_func_distributed_points;
36 enum dc_transfer_func_predefined;
38 /* For SetRegamma ADL interface support
39 * Must match escape type
44 unsigned int gammaRampArray :1; // RegammaRamp is in use
45 unsigned int gammaFromEdid :1; //gamma from edid is in use
46 unsigned int gammaFromEdidEx :1; //gamma from edid is in use , but only for Display Id 1.2
47 unsigned int gammaFromUser :1; //user custom gamma is used
48 unsigned int coeffFromUser :1; //coeff. A0-A3 from user is in use
49 unsigned int coeffFromEdid :1; //coeff. A0-A3 from edid is in use
50 unsigned int applyDegamma :1; //flag for additional degamma correction in driver
51 unsigned int gammaPredefinedSRGB :1; //flag for SRGB gamma
52 unsigned int gammaPredefinedPQ :1; //flag for PQ gamma
53 unsigned int gammaPredefinedPQ2084Interim :1; //flag for PQ gamma, lower max nits
54 unsigned int gammaPredefined36 :1; //flag for 3.6 gamma
55 unsigned int gammaPredefinedReset :1; //flag to return to previous gamma
60 unsigned short gamma[256*3]; // gamma ramp packed in same way as OS windows ,r , g & b
63 struct regamma_coeff {
72 union regamma_flags flags;
74 struct regamma_ramp ramp;
75 struct regamma_coeff coeff;
79 struct freesync_hdr_tf_params {
80 unsigned int sdr_white_level;
81 unsigned int min_content; // luminance in 1/10000 nits
82 unsigned int max_content; // luminance in nits
83 unsigned int min_display; // luminance in 1/10000 nits
84 unsigned int max_display; // luminance in nits
85 unsigned int skip_tm; // skip tm
88 struct calculate_buffer {
90 struct fixed31_32 buffer[NUM_PTS_IN_REGION];
91 struct fixed31_32 gamma_of_2;
94 struct translate_from_linear_space_args {
95 struct fixed31_32 arg;
100 struct fixed31_32 gamma;
101 struct calculate_buffer *cal_buffer;
104 void setup_x_points_distribution(void);
105 void log_x_points_distribution(struct dal_logger *logger);
106 void precompute_pq(void);
107 void precompute_de_pq(void);
109 bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf,
110 const struct dc_gamma *ramp, bool mapUserRamp, bool canRomBeUsed,
111 const struct freesync_hdr_tf_params *fs_params,
112 struct calculate_buffer *cal_buffer);
114 bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps,
115 struct dc_transfer_func *output_tf,
116 const struct dc_gamma *ramp, bool mapUserRamp);
118 bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
119 struct dc_transfer_func_distributed_points *points);
121 bool calculate_user_regamma_coeff(struct dc_transfer_func *output_tf,
122 const struct regamma_lut *regamma,
123 struct calculate_buffer *cal_buffer,
124 const struct dc_gamma *ramp);
126 bool calculate_user_regamma_ramp(struct dc_transfer_func *output_tf,
127 const struct regamma_lut *regamma,
128 struct calculate_buffer *cal_buffer,
129 const struct dc_gamma *ramp);
132 #endif /* COLOR_MOD_COLOR_GAMMA_H_ */