xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/display/modules/color/color_gamma.h (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: color_gamma.h,v 1.2 2021/12/18 23:45:07 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2016 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: AMD
25  *
26  */
27 
28 #ifndef COLOR_MOD_COLOR_GAMMA_H_
29 #define COLOR_MOD_COLOR_GAMMA_H_
30 
31 struct dc_transfer_func;
32 struct dc_gamma;
33 struct dc_transfer_func_distributed_points;
34 struct dc_rgb_fixed;
35 enum dc_transfer_func_predefined;
36 
37 /* For SetRegamma ADL interface support
38  * Must match escape type
39  */
40 union regamma_flags {
41 	unsigned int raw;
42 	struct {
43 		unsigned int gammaRampArray       :1;    // RegammaRamp is in use
44 		unsigned int gammaFromEdid        :1;    //gamma from edid is in use
45 		unsigned int gammaFromEdidEx      :1;    //gamma from edid is in use , but only for Display Id 1.2
46 		unsigned int gammaFromUser        :1;    //user custom gamma is used
47 		unsigned int coeffFromUser        :1;    //coeff. A0-A3 from user is in use
48 		unsigned int coeffFromEdid        :1;    //coeff. A0-A3 from edid is in use
49 		unsigned int applyDegamma         :1;    //flag for additional degamma correction in driver
50 		unsigned int gammaPredefinedSRGB  :1;    //flag for SRGB gamma
51 		unsigned int gammaPredefinedPQ    :1;    //flag for PQ gamma
52 		unsigned int gammaPredefinedPQ2084Interim :1;    //flag for PQ gamma, lower max nits
53 		unsigned int gammaPredefined36    :1;    //flag for 3.6 gamma
54 		unsigned int gammaPredefinedReset :1;    //flag to return to previous gamma
55 	} bits;
56 };
57 
58 struct regamma_ramp {
59 	unsigned short gamma[256*3];  // gamma ramp packed  in same way as OS windows ,r , g & b
60 };
61 
62 struct regamma_coeff {
63 	int    gamma[3];
64 	int    A0[3];
65 	int    A1[3];
66 	int    A2[3];
67 	int    A3[3];
68 };
69 
70 struct regamma_lut {
71 	union regamma_flags flags;
72 	union {
73 		struct regamma_ramp ramp;
74 		struct regamma_coeff coeff;
75 	};
76 };
77 
78 struct freesync_hdr_tf_params {
79 	unsigned int sdr_white_level;
80 	unsigned int min_content; // luminance in 1/10000 nits
81 	unsigned int max_content; // luminance in nits
82 	unsigned int min_display; // luminance in 1/10000 nits
83 	unsigned int max_display; // luminance in nits
84 	unsigned int skip_tm; // skip tm
85 };
86 
87 struct translate_from_linear_space_args {
88 	struct fixed31_32 arg;
89 	struct fixed31_32 a0;
90 	struct fixed31_32 a1;
91 	struct fixed31_32 a2;
92 	struct fixed31_32 a3;
93 	struct fixed31_32 gamma;
94 };
95 
96 void setup_x_points_distribution(void);
97 void log_x_points_distribution(struct dal_logger *logger);
98 void precompute_pq(void);
99 void precompute_de_pq(void);
100 
101 bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf,
102 		const struct dc_gamma *ramp, bool mapUserRamp, bool canRomBeUsed,
103 		const struct freesync_hdr_tf_params *fs_params);
104 
105 bool mod_color_calculate_degamma_params(struct dc_transfer_func *output_tf,
106 		const struct dc_gamma *ramp, bool mapUserRamp);
107 
108 bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
109 				struct dc_transfer_func_distributed_points *points);
110 
111 bool calculate_user_regamma_coeff(struct dc_transfer_func *output_tf,
112 		const struct regamma_lut *regamma);
113 
114 bool calculate_user_regamma_ramp(struct dc_transfer_func *output_tf,
115 		const struct regamma_lut *regamma);
116 
117 
118 #endif /* COLOR_MOD_COLOR_GAMMA_H_ */
119