1 /* Copyright 2022 Advanced Micro Devices, Inc. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a 4 * copy of this software and associated documentation files (the "Software"), 5 * to deal in the Software without restriction, including without limitation 6 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 * and/or sell copies of the Software, and to permit persons to whom the 8 * Software is furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 19 * OTHER DEALINGS IN THE SOFTWARE. 20 * 21 * Authors: AMD 22 * 23 */ 24 25 #pragma once 26 27 #include "vpe_types.h" 28 #include "fixed31_32.h" 29 #include "hw_shared.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #define SDR_VIDEO_WHITE_POINT 100 // nits 36 #define SDR_WHITE_POINT 80 // nits 37 #define HDR_PEAK_WHITE 10000 38 #define CCCS_NORM HDR_PEAK_WHITE/SDR_WHITE_POINT 39 #define STUDIO_RANGE_FOOT_ROOM_10_BIT vpe_fixpt_from_fraction(64, 1023) 40 #define STUDIO_RANGE_SCALE_10_BIT vpe_fixpt_from_fraction(940 - 64, 1023) 41 #define STUDIO_RANGE_FOOT_ROOM_8_BIT vpe_fixpt_from_fraction(16, 255) 42 #define STUDIO_RANGE_SCALE_8_BIT vpe_fixpt_from_fraction(235 - 16, 255) 43 44 struct vpe_priv; 45 struct stream_ctx; 46 47 enum color_depth { 48 COLOR_DEPTH_UNDEFINED, 49 COLOR_DEPTH_666, 50 COLOR_DEPTH_888, 51 COLOR_DEPTH_101010, 52 COLOR_DEPTH_121212, 53 COLOR_DEPTH_141414, 54 COLOR_DEPTH_161616, 55 COLOR_DEPTH_999, 56 COLOR_DEPTH_111111, 57 COLOR_DEPTH_COUNT 58 }; 59 60 /* 61 * Special comment for TRANSFER_FUNC_LINEAR_0_125, 62 Inside of the pipeline, vpe operates in 0 - 1 nominal range. 63 For degamma operations, 0_125 refers to input normalization and for regam, 0_125 refers to output normalization. 64 */ 65 enum color_transfer_func { 66 TRANSFER_FUNC_UNKNOWN, 67 TRANSFER_FUNC_SRGB, 68 TRANSFER_FUNC_BT709, 69 TRANSFER_FUNC_BT1886, 70 TRANSFER_FUNC_PQ2084, 71 TRANSFER_FUNC_LINEAR_0_1, 72 TRANSFER_FUNC_LINEAR_0_125, 73 TRANSFER_FUNC_NORMALIZED_PQ, 74 TRANSFER_FUNC_HLG 75 }; 76 77 enum dither_option { 78 DITHER_OPTION_DEFAULT, 79 DITHER_OPTION_DISABLE, 80 DITHER_OPTION_FM6, 81 DITHER_OPTION_FM8, 82 DITHER_OPTION_FM10, 83 DITHER_OPTION_SPATIAL6_FRAME_RANDOM, 84 DITHER_OPTION_SPATIAL8_FRAME_RANDOM, 85 DITHER_OPTION_SPATIAL10_FRAME_RANDOM, 86 DITHER_OPTION_SPATIAL6, 87 DITHER_OPTION_SPATIAL8, 88 DITHER_OPTION_SPATIAL10, 89 DITHER_OPTION_TRUN6, 90 DITHER_OPTION_TRUN8, 91 DITHER_OPTION_TRUN10, 92 DITHER_OPTION_TRUN10_SPATIAL8, 93 DITHER_OPTION_TRUN10_SPATIAL6, 94 DITHER_OPTION_TRUN10_FM8, 95 DITHER_OPTION_TRUN10_FM6, 96 DITHER_OPTION_TRUN10_SPATIAL8_FM6, 97 DITHER_OPTION_SPATIAL10_FM8, 98 DITHER_OPTION_SPATIAL10_FM6, 99 DITHER_OPTION_TRUN8_SPATIAL6, 100 DITHER_OPTION_TRUN8_FM6, 101 DITHER_OPTION_SPATIAL8_FM6, 102 DITHER_OPTION_MAX = DITHER_OPTION_SPATIAL8_FM6, 103 DITHER_OPTION_INVALID 104 }; 105 106 enum color_space { 107 COLOR_SPACE_UNKNOWN, 108 COLOR_SPACE_SRGB, 109 COLOR_SPACE_SRGB_LIMITED, 110 COLOR_SPACE_MSREF_SCRGB, 111 COLOR_SPACE_YCBCR601, 112 COLOR_SPACE_YCBCR709, 113 COLOR_SPACE_JFIF, 114 COLOR_SPACE_YCBCR601_LIMITED, 115 COLOR_SPACE_YCBCR709_LIMITED, 116 COLOR_SPACE_2020_RGB_FULLRANGE, 117 COLOR_SPACE_2020_RGB_LIMITEDRANGE, 118 COLOR_SPACE_2020_YCBCR, 119 COLOR_SPACE_2020_YCBCR_LIMITED, 120 COLOR_SPACE_MAX, 121 }; 122 123 enum transfer_func_type { 124 TF_TYPE_PREDEFINED, 125 TF_TYPE_DISTRIBUTED_POINTS, 126 TF_TYPE_BYPASS, 127 TF_TYPE_HWPWL 128 }; 129 130 enum cm_type { 131 CM_DEGAM, 132 CM_REGAM, 133 }; 134 135 enum { 136 TRANSFER_FUNC_POINTS = 1025 137 }; 138 139 typedef struct fixed31_32 white_point_gain; 140 141 struct transfer_func_distributed_points { 142 struct fixed31_32 red[TRANSFER_FUNC_POINTS]; 143 struct fixed31_32 green[TRANSFER_FUNC_POINTS]; 144 struct fixed31_32 blue[TRANSFER_FUNC_POINTS]; 145 146 uint16_t end_exponent; 147 uint16_t x_point_at_y1_red; 148 uint16_t x_point_at_y1_green; 149 uint16_t x_point_at_y1_blue; 150 }; 151 152 struct transfer_func { 153 enum transfer_func_type type; 154 enum color_transfer_func tf; 155 enum cm_type cm_gamma_type; 156 struct fixed31_32 start_base; //Used to clamp curve start 157 158 /* FP16 1.0 reference level in nits, default is 80 nits, only for PQ*/ 159 uint32_t sdr_ref_white_level; 160 union { 161 struct pwl_params pwl; 162 struct transfer_func_distributed_points tf_pts; 163 }; 164 bool use_pre_calculated_table; 165 }; 166 167 enum color_white_point_type { 168 color_white_point_type_unknown, 169 color_white_point_type_5000k_horizon, 170 color_white_point_type_6500k_noon, 171 color_white_point_type_7500k_north_sky, 172 color_white_point_type_9300k, 173 color_white_point_type_custom_coordinates 174 }; 175 176 struct color_space_coordinates { 177 unsigned int redX; 178 unsigned int redY; 179 unsigned int greenX; 180 unsigned int greenY; 181 unsigned int blueX; 182 unsigned int blueY; 183 unsigned int whiteX; 184 unsigned int whiteY; 185 }; 186 187 enum predefined_gamut_type { 188 gamut_type_bt709, 189 gamut_type_bt601, 190 gamut_type_adobe_rgb, 191 gamut_type_srgb, 192 gamut_type_bt2020, 193 gamut_type_dcip3, 194 gamut_type_unknown, 195 }; 196 197 enum predefined_white_point_type { 198 white_point_type_5000k_horizon, 199 white_point_type_6500k_noon, 200 white_point_type_7500k_north_sky, 201 white_point_type_9300k, 202 white_point_type_unknown, 203 }; 204 205 struct colorspace_transform { 206 struct fixed31_32 matrix[12]; 207 bool enable_remap; 208 }; 209 210 struct color_gamut_data { 211 enum color_space color_space; 212 enum color_white_point_type white_point; 213 struct color_space_coordinates gamut; 214 }; 215 216 union vpe_3dlut_state { 217 struct { 218 uint32_t initialized : 1; /*if 3dlut is went through color module for initialization */ 219 uint32_t reserved : 15; 220 } bits; 221 uint32_t raw; 222 }; 223 224 struct vpe_3dlut { 225 // struct kref refcount; 226 struct tetrahedral_params lut_3d; 227 struct fixed31_32 hdr_multiplier; 228 union vpe_3dlut_state state; 229 }; 230 231 enum vpe_status vpe_color_update_color_space_and_tf( 232 struct vpe_priv *vpe_priv, const struct vpe_build_param *param); 233 234 enum vpe_status vpe_color_update_movable_cm( 235 struct vpe_priv *vpe_priv, const struct vpe_build_param *param); 236 237 void vpe_color_get_color_space_and_tf( 238 const struct vpe_color_space *vcs, enum color_space *cs, enum color_transfer_func *tf); 239 240 bool vpe_use_csc_adjust(const struct vpe_color_adjust *adjustments); 241 242 bool vpe_is_rgb_equal(const struct pwl_result_data *rgb, uint32_t num); 243 244 bool vpe_is_HDR(enum color_transfer_func tf); 245 246 void vpe_convert_full_range_color_enum(enum color_space *cs); 247 248 enum vpe_status vpe_color_update_whitepoint( 249 const struct vpe_priv *vpe_priv, const struct vpe_build_param *param); 250 251 enum vpe_status vpe_color_tm_update_hdr_mult(uint16_t shaper_in_exp_max, uint32_t peak_white, 252 struct fixed31_32 *hdr_multiplier, bool enable_3dlut); 253 254 enum vpe_status vpe_color_update_shaper( 255 uint16_t shaper_in_exp_max, struct transfer_func *shaper_func, bool enable_3dlut); 256 257 enum vpe_status vpe_color_build_tm_cs(const struct vpe_tonemap_params *tm_params, 258 struct vpe_surface_info surface_info, struct vpe_color_space *vcs); 259 260 #ifdef __cplusplus 261 } 262 #endif 263