vout: libplacebo: add PL_COLOR_PRIM_DISPLAY_P3
[vlc.git] / modules / video_output / placebo_utils.h
blob1b216adb09c947b21e4b8c2830b48bf3b6684031
1 /*****************************************************************************
2 * placebo_utils.h: Definition of various libplacebo helpers
3 *****************************************************************************
4 * Copyright (C) 2018 Niklas Haas
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifndef VLC_PLACEBO_UTILS_H
22 #define VLC_PLACEBO_UTILS_H 1
24 #include <vlc_common.h>
25 #include <vlc_picture.h>
27 #include <libplacebo/colorspace.h>
28 #include <libplacebo/shaders/colorspace.h>
29 #include <libplacebo/utils/upload.h>
31 // Create a libplacebo context, hooked up to the log system; or NULL on OOM
32 VLC_API struct pl_context *vlc_placebo_Create(vlc_object_t *);
34 // Turn a video_format_t into the equivalent libplacebo values
35 VLC_API struct pl_color_space vlc_placebo_ColorSpace(const video_format_t *);
36 VLC_API struct pl_color_repr vlc_placebo_ColorRepr(const video_format_t *);
37 VLC_API enum pl_chroma_location vlc_placebo_ChromaLoc(const video_format_t *);
39 // Fill a pl_plane_data array with various data. Returns the number of planes,
40 // or 0 if the format is unsupported by the libplacebo API. If `buf` is set,
41 // then all addresses of the picture_t must lie within `buf`'s mapped memory.
42 VLC_API int vlc_placebo_PlaneFormat(const video_format_t *, struct pl_plane_data[4]);
43 VLC_API int vlc_placebo_PlaneData(const picture_t *, struct pl_plane_data[4],
44 const struct pl_buf *buf);
46 // See if a given FourCC is physically supported by a given GPU
47 VLC_API bool vlc_placebo_FormatSupported(const struct pl_gpu *, vlc_fourcc_t);
49 // Shared options strings/structs for libplacebo options
51 #define RENDER_INTENT_TEXT "Rendering intent for color conversion"
52 #define RENDER_INTENT_LONGTEXT "The mapping type used to convert between color spaces."
54 static const int intent_values[] = {
55 PL_INTENT_PERCEPTUAL,
56 PL_INTENT_RELATIVE_COLORIMETRIC,
57 PL_INTENT_SATURATION,
58 PL_INTENT_ABSOLUTE_COLORIMETRIC,
61 static const char * const intent_text[] = {
62 "Perceptual",
63 "Relative colorimetric",
64 "Absolute colorimetric",
65 "Saturation",
68 #define PRIM_TEXT "Display primaries"
69 #define PRIM_LONGTEXT "The primaries associated with the output display"
71 static const int prim_values[] = {
72 PL_COLOR_PRIM_UNKNOWN,
73 PL_COLOR_PRIM_BT_601_525,
74 PL_COLOR_PRIM_BT_601_625,
75 PL_COLOR_PRIM_BT_709,
76 PL_COLOR_PRIM_BT_470M,
77 PL_COLOR_PRIM_BT_2020,
78 PL_COLOR_PRIM_APPLE,
79 PL_COLOR_PRIM_ADOBE,
80 PL_COLOR_PRIM_PRO_PHOTO,
81 PL_COLOR_PRIM_CIE_1931,
82 PL_COLOR_PRIM_DCI_P3,
83 PL_COLOR_PRIM_V_GAMUT,
84 PL_COLOR_PRIM_S_GAMUT,
85 PL_COLOR_PRIM_DISPLAY_P3,
88 static const char * const prim_text[] = {
89 "Automatic / Unknown primaries",
90 "ITU-R Rec. BT.601 (525-line = NTSC, SMPTE-C)",
91 "ITU-R Rec. BT.601 (625-line = PAL, SECAM)",
92 "ITU-R Rec. BT.709 (HD), also sRGB",
93 "ITU-R Rec. BT.470 M",
94 "ITU-R Rec. BT.2020 (UltraHD)",
95 "Apple RGB",
96 "Adobe RGB (1998)",
97 "ProPhoto RGB (ROMM)",
98 "CIE 1931 RGB primaries",
99 "DCI-P3 (Digital Cinema)",
100 "Panasonic V-Gamut (VARICAM)",
101 "Sony S-Gamut",
102 "Display-P3 (Digital Cinema with D65)",
105 #define TRC_TEXT "Display gamma / transfer function"
106 #define TRC_LONGTEXT "The gamma/transfer function associated with the output display"
108 static const int trc_values[] = {
109 PL_COLOR_TRC_UNKNOWN,
110 PL_COLOR_TRC_BT_1886,
111 PL_COLOR_TRC_SRGB,
112 PL_COLOR_TRC_LINEAR,
113 PL_COLOR_TRC_GAMMA18,
114 PL_COLOR_TRC_GAMMA22,
115 PL_COLOR_TRC_GAMMA28,
116 PL_COLOR_TRC_PRO_PHOTO,
117 PL_COLOR_TRC_PQ,
118 PL_COLOR_TRC_HLG,
119 PL_COLOR_TRC_V_LOG,
120 PL_COLOR_TRC_S_LOG1,
121 PL_COLOR_TRC_S_LOG2,
124 static const char * const trc_text[] = {
125 "Automatic / Unknown gamma",
126 "ITU-R Rec. BT.1886 (CRT emulation + OOTF)",
127 "IEC 61966-2-4 sRGB (CRT emulation)",
128 "Linear light content",
129 "Pure power gamma 1.8",
130 "Pure power gamma 2.2",
131 "Pure power gamma 2.8",
132 "ProPhoto RGB (ROMM)",
133 "ITU-R BT.2100 PQ (perceptual quantizer), aka SMPTE ST2084",
134 "ITU-R BT.2100 HLG (hybrid log-gamma), aka ARIB STD-B67",
135 "Panasonic V-Log (VARICAM)",
136 "Sony S-Log1",
137 "Sony S-Log2",
141 #define TONEMAPPING_TEXT "Tone-mapping algorithm"
142 #define TONEMAPPING_LONGTEXT "Algorithm to use when converting from wide gamut to standard gamut, or from HDR to SDR."
144 static const int tone_values[] = {
145 PL_TONE_MAPPING_HABLE,
146 PL_TONE_MAPPING_MOBIUS,
147 PL_TONE_MAPPING_REINHARD,
148 PL_TONE_MAPPING_GAMMA,
149 PL_TONE_MAPPING_LINEAR,
150 PL_TONE_MAPPING_CLIP,
153 static const char * const tone_text[] = {
154 "Hable (filmic mapping, recommended)",
155 "Mobius (linear + knee)",
156 "Reinhard (simple non-linear)",
157 "Gamma-Power law",
158 "Linear stretch (peak to peak)",
159 "Hard clip out-of-gamut",
162 #define TONEMAP_PARAM_TEXT "Tone-mapping parameter"
163 #define TONEMAP_PARAM_LONGTEXT "This parameter can be used to tune the tone-mapping curve. Specifics depend on the curve used. If left as 0, the curve's preferred default is used."
165 #define TONEMAP_DESAT_TEXT "Tone-mapping desaturation coefficient"
166 #define TONEMAP_DESAT_LONGTEXT "How strongly to desaturate bright spectral colors towards white. 0.0 disables this behavior."
168 #define GAMUT_WARN_TEXT "Highlight clipped pixels"
169 #define GAMUT_WARN_LONGTEXT "Debugging tool to indicate which pixels were clipped as part of the tone mapping process."
171 #define PEAK_FRAMES_TEXT "HDR peak detection buffer size"
172 #define PEAK_FRAMES_LONGTEXT "How many input frames to consider when determining the brightness of HDR signals. Higher values result in a slower/smoother response to brightness level changes. Setting this to 0 disables peak detection entirely."
174 #define TARGET_AVG_TEXT "Target peak brightness average"
175 #define TARGET_AVG_LONGTEXT "If the source frame has an average brightness exceeding this number, the frame will be automatically darkened to compensate. This feature only works when peak detection is enabled."
177 #define SCENE_THRESHOLD_TEXT "HDR peak scene change threshold"
178 #define SCENE_THRESHOLD_LONGTEXT "When using HDR peak detection, this sets a threshold for sudden brightness changes that should be considered as scene changes. This will result in the detected peak being immediately updated to the new value, rather than gradually being adjusted. Setting this to 0 disables this feature."
180 #define DITHER_TEXT "Dithering algorithm"
181 #define DITHER_LONGTEXT "The algorithm to use when dithering to a lower bit depth."
183 static const int dither_values[] = {
184 -1, // no dithering
185 PL_DITHER_BLUE_NOISE,
186 PL_DITHER_ORDERED_FIXED,
187 PL_DITHER_ORDERED_LUT,
188 PL_DITHER_WHITE_NOISE,
191 static const char * const dither_text[] = {
192 "Disabled",
193 "Blue noise (high quality)",
194 "Bayer matrix (ordered dither), 16x16 fixed size (fast)",
195 "Bayer matrix (ordered dither), any size",
196 "White noise (fast but low quality)",
199 #define DITHER_SIZE_TEXT "Dither LUT size (log 2)"
200 #define DITHER_SIZE_LONGTEXT "Controls the size of the dither matrix, as a power of two (e.g. the default of 6 corresponds to a 64x64 matrix). Does not affect all algorithms."
202 #define TEMPORAL_DITHER_TEXT "Temporal dithering"
203 #define TEMPORAL_DITHER_LONGTEXT "Enables perturbing the dither matrix across frames. This reduces the persistence of dithering artifacts, but can cause flickering on some (cheap) LCD screens."
205 #define DITHER_DEPTH_TEXT "Dither depth override (0 = auto)"
206 #define DITHER_DEPTH_LONGTEXT "Overrides the detected framebuffer depth. Useful to dither to lower bit depths than otherwise required."
208 enum {
209 SCALE_BUILTIN = 0,
210 SCALE_SPLINE16,
211 SCALE_SPLINE36,
212 SCALE_SPLINE64,
213 SCALE_MITCHELL,
214 SCALE_BICUBIC,
215 SCALE_EWA_LANCZOS,
216 SCALE_NEAREST,
217 SCALE_BILINEAR,
218 SCALE_GAUSSIAN,
219 SCALE_LANCZOS,
220 SCALE_GINSENG,
221 SCALE_EWA_GINSENG,
222 SCALE_EWA_HANN,
223 SCALE_HAASNSOFT,
224 SCALE_CATMULL_ROM,
225 SCALE_ROBIDOUX,
226 SCALE_ROBIDOUXSHARP,
227 SCALE_EWA_ROBIDOUX,
228 SCALE_EWA_ROBIDOUXSHARP,
229 SCALE_SINC,
230 SCALE_EWA_JINC,
231 SCALE_CUSTOM,
234 static const int scale_values[] = {
235 SCALE_BUILTIN,
236 SCALE_SPLINE16,
237 SCALE_SPLINE36,
238 SCALE_SPLINE64,
239 SCALE_MITCHELL,
240 SCALE_BICUBIC,
241 SCALE_EWA_LANCZOS,
242 SCALE_NEAREST,
243 SCALE_BILINEAR,
244 SCALE_GAUSSIAN,
245 SCALE_LANCZOS,
246 SCALE_GINSENG,
247 SCALE_EWA_GINSENG,
248 SCALE_EWA_HANN,
249 SCALE_HAASNSOFT,
250 SCALE_CATMULL_ROM,
251 SCALE_ROBIDOUX,
252 SCALE_ROBIDOUXSHARP,
253 SCALE_EWA_ROBIDOUX,
254 SCALE_EWA_ROBIDOUXSHARP,
255 SCALE_SINC,
256 SCALE_EWA_JINC,
257 SCALE_CUSTOM,
260 static const char * const scale_text[] = {
261 "Built-in / fixed function (fast)",
262 "Spline 2 taps",
263 "Spline 3 taps (recommended upscaler)",
264 "Spline 4 taps",
265 "Mitchell-Netravali (recommended downscaler)",
266 "Bicubic",
267 "Jinc / EWA Lanczos 3 taps (high quality, slow)",
268 "Nearest neighbour",
269 "Bilinear",
270 "Gaussian",
271 "Lanczos 3 taps",
272 "Ginseng 3 taps",
273 "EWA Ginseng",
274 "EWA Hann",
275 "HaasnSoft (blurred EWA Hann)",
276 "Catmull-Rom",
277 "Robidoux",
278 "RobidouxSharp",
279 "EWA Robidoux",
280 "EWA RobidouxSharp",
281 "Unwindowed sinc (clipped)",
282 "Unwindowed EWA Jinc (clipped)",
283 "Custom (see below)",
286 static const struct pl_filter_config *scale_config[] = {
287 [SCALE_BUILTIN] = NULL,
288 [SCALE_SPLINE16] = &pl_filter_spline16,
289 [SCALE_SPLINE36] = &pl_filter_spline36,
290 [SCALE_SPLINE64] = &pl_filter_spline64,
291 [SCALE_NEAREST] = &pl_filter_box,
292 [SCALE_BILINEAR] = &pl_filter_triangle,
293 [SCALE_GAUSSIAN] = &pl_filter_gaussian,
294 [SCALE_SINC] = &pl_filter_sinc,
295 [SCALE_LANCZOS] = &pl_filter_lanczos,
296 [SCALE_GINSENG] = &pl_filter_ginseng,
297 [SCALE_EWA_JINC] = &pl_filter_ewa_jinc,
298 [SCALE_EWA_LANCZOS] = &pl_filter_ewa_lanczos,
299 [SCALE_EWA_GINSENG] = &pl_filter_ewa_ginseng,
300 [SCALE_EWA_HANN] = &pl_filter_ewa_hann,
301 [SCALE_HAASNSOFT] = &pl_filter_haasnsoft,
302 [SCALE_BICUBIC] = &pl_filter_bicubic,
303 [SCALE_CATMULL_ROM] = &pl_filter_catmull_rom,
304 [SCALE_MITCHELL] = &pl_filter_mitchell,
305 [SCALE_ROBIDOUX] = &pl_filter_robidoux,
306 [SCALE_ROBIDOUXSHARP] = &pl_filter_robidouxsharp,
307 [SCALE_EWA_ROBIDOUX] = &pl_filter_robidoux,
308 [SCALE_EWA_ROBIDOUXSHARP] = &pl_filter_robidouxsharp,
309 [SCALE_CUSTOM] = NULL,
312 #define UPSCALER_PRESET_TEXT "Upscaler preset"
313 #define DOWNSCALER_PRESET_TEXT "Downscaler preset"
314 #define SCALER_PRESET_LONGTEXT "Choose from one of the built-in scaler presets. If set to custom, you can choose your own combination of kernel/window functions."
316 #define LUT_ENTRIES_TEXT "Scaler LUT size"
317 #define LUT_ENTRIES_LONGTEXT "Size of the LUT texture used for up/downscalers that require one. Reducing this may boost performance at the cost of quality."
319 #define ANTIRING_TEXT "Anti-ringing strength"
320 #define ANTIRING_LONGTEXT "Enables anti-ringing for non-polar filters. A value of 1.0 completely removes ringing, a value of 0.0 is a no-op."
322 enum {
323 FILTER_NONE = 0,
324 FILTER_BOX,
325 FILTER_TRIANGLE,
326 FILTER_HANN,
327 FILTER_HAMMING,
328 FILTER_WELCH,
329 FILTER_KAISER,
330 FILTER_BLACKMAN,
331 FILTER_GAUSSIAN,
332 FILTER_SINC,
333 FILTER_JINC,
334 FILTER_SPHINX,
335 FILTER_BCSPLINE,
336 FILTER_CATMULL_ROM,
337 FILTER_MITCHELL,
338 FILTER_ROBIDOUX,
339 FILTER_ROBIDOUXSHARP,
340 FILTER_BICUBIC,
341 FILTER_SPLINE16,
342 FILTER_SPLINE36,
343 FILTER_SPLINE64,
346 static const int filter_values[] = {
347 FILTER_NONE,
348 FILTER_BOX,
349 FILTER_TRIANGLE,
350 FILTER_HANN,
351 FILTER_HAMMING,
352 FILTER_WELCH,
353 FILTER_KAISER,
354 FILTER_BLACKMAN,
355 FILTER_GAUSSIAN,
356 FILTER_SINC,
357 FILTER_JINC,
358 FILTER_SPHINX,
359 FILTER_BCSPLINE,
360 FILTER_CATMULL_ROM,
361 FILTER_MITCHELL,
362 FILTER_ROBIDOUX,
363 FILTER_ROBIDOUXSHARP,
364 FILTER_BICUBIC,
365 FILTER_SPLINE16,
366 FILTER_SPLINE36,
367 FILTER_SPLINE64,
370 static const char * const filter_text[] = {
371 "None",
372 "Box / Nearest",
373 "Triangle / Linear",
374 "Hann",
375 "Hamming",
376 "Welch",
377 "Kaiser",
378 "Blackman",
379 "Gaussian",
380 "Sinc",
381 "Jinc",
382 "Sphinx",
383 "BC spline",
384 "Catmull-Rom",
385 "Mitchell-Netravali",
386 "Robidoux",
387 "RobidouxSharp",
388 "Bicubic",
389 "Spline16",
390 "Spline36",
391 "Spline64",
394 static const struct pl_filter_function *filter_fun[] = {
395 [FILTER_NONE] = NULL,
396 [FILTER_BOX] = &pl_filter_function_box,
397 [FILTER_TRIANGLE] = &pl_filter_function_triangle,
398 [FILTER_HANN] = &pl_filter_function_hann,
399 [FILTER_HAMMING] = &pl_filter_function_hamming,
400 [FILTER_WELCH] = &pl_filter_function_welch,
401 [FILTER_KAISER] = &pl_filter_function_kaiser,
402 [FILTER_BLACKMAN] = &pl_filter_function_blackman,
403 [FILTER_GAUSSIAN] = &pl_filter_function_gaussian,
404 [FILTER_SINC] = &pl_filter_function_sinc,
405 [FILTER_JINC] = &pl_filter_function_jinc,
406 [FILTER_SPHINX] = &pl_filter_function_sphinx,
407 [FILTER_BCSPLINE] = &pl_filter_function_bcspline,
408 [FILTER_CATMULL_ROM] = &pl_filter_function_catmull_rom,
409 [FILTER_MITCHELL] = &pl_filter_function_mitchell,
410 [FILTER_ROBIDOUX] = &pl_filter_function_robidoux,
411 [FILTER_ROBIDOUXSHARP] = &pl_filter_function_robidouxsharp,
412 [FILTER_BICUBIC] = &pl_filter_function_bicubic,
413 [FILTER_SPLINE16] = &pl_filter_function_spline16,
414 [FILTER_SPLINE36] = &pl_filter_function_spline36,
415 [FILTER_SPLINE64] = &pl_filter_function_spline64,
418 #define KERNEL_TEXT "Kernel function"
419 #define KERNEL_LONGTEXT "Main function defining the filter kernel."
421 #define WINDOW_TEXT "Window function"
422 #define WINDOW_LONGTEXT "Window the kernel by an additional function. (Optional)"
424 #define CLAMP_TEXT "Clamping coefficient"
425 #define CLAMP_LONGTEXT "If 1.0, clamp the kernel to only allow non-negative coefficients. If 0.0, no clamping is performed. Values in between are linear."
427 #define BLUR_TEXT "Blur/Sharpen coefficient"
428 #define BLUR_LONGTEXT "If 1.0, no change is performed. Values below 1.0 sharpen/narrow the kernel, values above 1.0 blur/widen the kernel. Avoid setting too low values!"
430 #define TAPER_TEXT "Taper width"
431 #define TAPER_LONGTEXT "Taper the kernel - all inputs within the range [0, taper] will return 1.0, and the rest of the kernel is squished into (taper, radius]."
433 #define POLAR_TEXT "Use as EWA / Polar filter"
434 #define POLAR_LONGTEXT "EWA/Polar filters are much slower but higher quality. Not all functions are good candidates. It's recommended to use jinc as the kernel."
436 #define DEBAND_TEXT "Enable debanding"
437 #define DEBAND_LONGTEXT "Turns on the debanding step. This algorithm can be further tuned with the iterations and grain options."
439 #define DEBAND_ITER_TEXT "Debanding iterations"
440 #define DEBAND_ITER_LONGTEXT "The number of debanding steps to perform per sample. Each step reduces a bit more banding, but takes time to compute. Note that the strength of each step falls off very quickly, so high numbers (>4) are practically useless. A value of 0 is a no-op."
442 #define DEBAND_THRESH_TEXT "Gradient threshold"
443 #define DEBAND_THRESH_LONGTEXT "The debanding filter's cut-off threshold. Higher numbers increase the debanding strength dramatically, but progressively diminish image details."
445 #define DEBAND_RADIUS_TEXT "Search radius"
446 #define DEBAND_RADIUS_LONGTEXT "The debanding filter's initial radius. The radius increases linearly for each iteration. A higher radius will find more gradients, but a lower radius will smooth more aggressively."
448 #define DEBAND_GRAIN_TEXT "Grain strength"
449 #define DEBAND_GRAIN_LONGTEXT "Add some extra noise to the image. This significantly helps cover up remaining quantization artifacts. Higher numbers add more noise."
451 #define SIGMOID_TEXT "Use sigmoidization when upscaling"
452 #define SIGMOID_LONGTEXT "If true, sigmoidizes the signal before upscaling. This helps prevent ringing artifacts. Not always in effect, even if enabled."
454 #define SIGMOID_CENTER_TEXT "Sigmoid center"
455 #define SIGMOID_CENTER_LONGTEXT "The center (bias) of the sigmoid curve."
457 #define SIGMOID_SLOPE_TEXT "Sigmoid slope"
458 #define SIGMOID_SLOPE_LONGTEXT "The slope (steepness) of the sigmoid curve."
460 #define POLAR_CUTOFF_TEXT "Cut-off value for polar samplers"
461 #define POLAR_CUTOFF_LONGTEXT "As a micro-optimization, all samples with a weight below this value will be ignored. This reduces the need to perform unnecessary work that doesn't noticeably change the resulting image. Setting it to a value of 0.0 disables this optimization."
463 #define SKIP_AA_TEXT "Disable anti-aliasing when downscaling"
464 #define SKIP_AA_LONGTEXT "This will result in moiré artifacts and nasty, jagged pixels when downscaling, except for some very limited special cases (e.g. bilinear downsampling to exactly 0.5x). Significantly speeds up downscaling with high downscaling ratios."
466 #define OVERLAY_DIRECT_TEXT "Force GPU built-in sampling for overlay textures"
467 #define OVERLAY_DIRECT_LONGTEXT "Normally, the configured up/downscalers will be used when overlay textures (such as subtitles) need to be scaled up or down. Enabling this option overrides this behavior and forces overlay textures to go through the GPU's built-in sampling instead (typically bilinear)."
469 #define DISABLE_LINEAR_TEXT "Don't linearize before scaling"
470 #define DISABLE_LINEAR_LONGTEXT "Normally, the image is converted to linear light before scaling (under certain conditions). Enabling this option disables this behavior."
472 #define FORCE_GENERAL_TEXT "Force the use of general-purpose scalers"
473 #define FORCE_GENERAL_LONGTEXT "Normally, certain special scalers will be replaced by faster versions instead of going through the general scaler architecture. Enabling this option disables these optimizations."
475 #endif // VLC_PLACEBO_UTILS_H