VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_chroma_probe.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_chroma_probe.h: chroma conversion probing
3 *****************************************************************************
4 * Copyright (C) 2025 VLC authors and VideoLAN
5 *
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.
10 *
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.
15 *
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 *****************************************************************************/
20
21#ifndef VLC_CHROMA_PROBE_H
22#define VLC_CHROMA_PROBE_H 1
23
24#include <vlc_common.h>
25#include <vlc_vector.h>
26
27/**
28 * \defgroup chroma_probe Chroma conversion probing
29 * \ingroup filter
30 * @{
31 * \file
32 * Chroma conversion probing
33 *
34 * \defgroup chroma_probe_api Chroma probing API
35 * \ingroup chroma_probe
36 *
37 * @{
38 */
39
40#define VLC_CHROMA_CONV_MAX_INDIRECT_STEPS 1
41#define VLC_CHROMA_CONV_CHAIN_COUNT_MAX (2 /* in + out */ + VLC_CHROMA_CONV_MAX_INDIRECT_STEPS)
43/**
44 * Chroma conversion result structure
45 */
48 /**
49 * Array of chromas used to achieve the conversion
50 *
51 * 'chain[0]' is always equals to the 'in' argument of the
52 * vlc_chroma_conv_Probe() function.
53 *
54 * if the out argument of the vlc_chroma_conv_Probe() is valid,
55 * chain[chain_count - 1] is equals to 'out'
56 */
59 /** Number of chromas in the chain */
60 size_t chain_count;
62 /**
63 * Cost of the full conversion, lower is better.
64 */
65 unsigned cost;
67 /**
68 * Quality of the conversion, higher is better.
69 *
70 * A quality of 100 means there are no quality loss: same color size and
71 * same vlc_chroma_subtype (or same YUV subsampling for video).
72 */
73 unsigned quality;
74};
75
76/** Only accept YUV output chromas (the input chroma can be RGB) */
77#define VLC_CHROMA_CONV_FLAG_ONLY_YUV 0x1
78/** Only accept RGB output chromas (the input chroma can be YUV) */
79#define VLC_CHROMA_CONV_FLAG_ONLY_RGB 0x2
80/** Sort results by cost instead of quality */
81#define VLC_CHROMA_CONV_FLAG_SORT_COST 0x4
83/**
84 * Probe possible chroma conversions
85
86 * Results are sorted by quality, unless VLC_CHROMA_CONV_FLAG_SORT_COST is
87 * specified in flags.
88
89 * @param in the input chroma to convert from, must be valid
90 * @param out the output chroma to convert to, if 0, the function will find all
91 * possible conversion from in to x
92 * @param width video width, used for finer cost calculation, can be 0
93 * @param height video height, used for finer cost calculation, can be 0
94 * @param max_indirect_steps maximum number of indirect conversion steps, must
95 * be lower or equal to @ref VLC_CHROMA_CONV_MAX_INDIRECT_STEPS, if in and out
96 * chromas are CPU chromas, the steps will be automatically lowered to 0
97 * @param flags bitwise flags, cf. VLC_CHROMA_CONV_FLAG_*
98 * @param count pointer to the number of results, must be valid
99 * @return a pointer to an array of results, must be released with free(), can
100 * be NULL
101 */
104 unsigned width, unsigned height,
105 unsigned max_indirect_steps, int flags, size_t *count);
106
107/**
108 * Get a string representing the result
109 *
110 * @param res pointer to a valid result
111 * @return a string or NULL, must be released with free()
112 */
113VLC_API char *
115
116/**
117 * @}
118 *
119 * \defgroup chroma_probe_module Chroma probing module implementation
120 * \ingroup chroma_probe
121 *
122 * @{
123 */
124
125/**
126 * Chroma conversion entry structure
127 */
130 /** Cost factor, 0.25 for GPU<->GPU conversions, 0.75 for SIMD, 1 for CPU */
131 float cost_factor;
132 /** input chroma */
134 /** output chroma */
139/**
140 * Module probe function signature
141 *
142 * @param vec pointer to an allocated vector
143 * @return a VLC error code
144 */
145typedef void (*vlc_chroma_conv_probe)(vlc_chroma_conv_vec *vec);
147#define set_callback_chroma_conv_probe(activate) \
148 { \
149 vlc_chroma_conv_probe activate__ = activate; \
150 (void) activate__; \
151 set_callback(activate) \
152 } \
153 set_capability("chroma probe", 100)
154
155/**
156 * Helper that add a chroma conversion
157 *
158 * Must be called inside vlc_chroma_conv_probe()
159 *
160 * @param vec pointer to the vector of chromas
161 * @param cost_factor cf. vlc_chroma_conv_entry.cost_factor
162 * @param in cf. vlc_chroma_conv_entry.in
163 * @param out cf. vlc_chroma_conv_entry.out
164 * @param twoway if true, 'out' can also be converted to 'in'
165 */
166static inline void
167vlc_chroma_conv_add(vlc_chroma_conv_vec *vec, float cost_factor,
168 vlc_fourcc_t in, vlc_fourcc_t out, bool twoway)
169{
170 {
171 const struct vlc_chroma_conv_entry entry = {
173 };
175 }
176
177 if (twoway)
178 {
179 const struct vlc_chroma_conv_entry entry = {
181 };
183 }
184}
185
186/**
187 * Helper that add an array of out chroma conversions
188 *
189 * Must be called inside vlc_chroma_conv_probe()
190 *
191 * @param vec pointer to the vector of chromas
192 * @param cost_factor cf. vlc_chroma_conv_entry.cost_factor
193 * @param in cf. vlc_chroma_conv_entry.in
194 * @param out_array a list of out chromas
195 * @param out_count number of elements in the out_array
196 */
197static inline void
200 const vlc_fourcc_t *out_array, size_t out_count)
201{
202 for (size_t i = 0; i < out_count; i++)
203 {
204 const struct vlc_chroma_conv_entry entry = {
205 cost_factor, in, out_array[i],
206 };
208 }
209}
210
211/**
212 * Helper that add a list of out chroma conversions
213 */
214#define vlc_chroma_conv_add_in_outlist(vec, cost_factor, in, ...) do { \
215 static const vlc_fourcc_t out_array[] = { __VA_ARGS__ }; \
216 size_t count = ARRAY_SIZE(out_array); \
217 vlc_chroma_conv_add_in_outarray(vec, cost_factor, in, out_array, count); \
218} while(0)
219
220/**
221 * Helper that add an array of in chroma conversions
222 *
223 * Must be called inside vlc_chroma_conv_probe()
224 *
225 * @param vec pointer to the vector of chromas
226 * @param cost_factor cf. vlc_chroma_conv_entry.cost_factor
227 * @param out cf. vlc_chroma_conv_entry.out
228 * @param in_array a list of out chromas
229 * @param in_count number of elements in the in_array
230 */
231static inline void
234 const vlc_fourcc_t *in_array, size_t in_count)
235{
236 for (size_t i = 0; i < in_count; i++)
237 {
238 const struct vlc_chroma_conv_entry entry = {
239 cost_factor, in_array[i], out,
240 };
242 }
243}
244
245/**
246 * Helper that add a list of in chroma conversions
247 */
248#define vlc_chroma_conv_add_out_inlist(vec, cost_factor, out, ...) do { \
249 static const vlc_fourcc_t in_array[] = { __VA_ARGS__ }; \
250 size_t count = ARRAY_SIZE(in_array); \
251 vlc_chroma_conv_add_out_inarray(vec, cost_factor, out, in_array, count); \
252} while(0)
253
254/**
255 * @}
256 * @}
257 */
258
259#endif /* VLC_CHROMA_PROBE_H */
size_t count
Definition core.c:403
#define VLC_API
Definition fourcc_gen.c:31
uint32_t vlc_fourcc_t
Definition fourcc_gen.c:33
struct vlc_chroma_conv_result * vlc_chroma_conv_Probe(vlc_fourcc_t in, vlc_fourcc_t out, unsigned width, unsigned height, unsigned max_indirect_steps, int flags, size_t *count)
Probe possible chroma conversions.
Definition chroma_probe.c:348
#define VLC_CHROMA_CONV_CHAIN_COUNT_MAX
Definition vlc_chroma_probe.h:42
char * vlc_chroma_conv_result_ToString(const struct vlc_chroma_conv_result *res)
Get a string representing the result.
Definition chroma_probe.c:459
static void vlc_chroma_conv_add_out_inarray(vlc_chroma_conv_vec *vec, float cost_factor, vlc_fourcc_t out, const vlc_fourcc_t *in_array, size_t in_count)
Helper that add an array of in chroma conversions.
Definition vlc_chroma_probe.h:233
static void vlc_chroma_conv_add_in_outarray(vlc_chroma_conv_vec *vec, float cost_factor, vlc_fourcc_t in, const vlc_fourcc_t *out_array, size_t out_count)
Helper that add an array of out chroma conversions.
Definition vlc_chroma_probe.h:199
void(* vlc_chroma_conv_probe)(vlc_chroma_conv_vec *vec)
Module probe function signature.
Definition vlc_chroma_probe.h:146
static void vlc_chroma_conv_add(vlc_chroma_conv_vec *vec, float cost_factor, vlc_fourcc_t in, vlc_fourcc_t out, bool twoway)
Helper that add a chroma conversion.
Definition vlc_chroma_probe.h:168
#define vlc_vector_push(pv, item)
Push an item at the end of the vector.
Definition vlc_vector.h:314
#define VLC_VECTOR(type)
Vector struct body.
Definition vlc_vector.h:66
Definition fourcc_gen.c:52
Chroma conversion entry structure.
Definition vlc_chroma_probe.h:130
vlc_fourcc_t out
output chroma
Definition vlc_chroma_probe.h:136
float cost_factor
Cost factor, 0.25 for GPU<->GPU conversions, 0.75 for SIMD, 1 for CPU.
Definition vlc_chroma_probe.h:132
vlc_fourcc_t in
input chroma
Definition vlc_chroma_probe.h:134
Chroma conversion result structure.
Definition vlc_chroma_probe.h:48
size_t chain_count
Number of chromas in the chain.
Definition vlc_chroma_probe.h:61
unsigned cost
Cost of the full conversion, lower is better.
Definition vlc_chroma_probe.h:66
vlc_fourcc_t chain[(2+1)]
Array of chromas used to achieve the conversion.
Definition vlc_chroma_probe.h:58
unsigned quality
Quality of the conversion, higher is better.
Definition vlc_chroma_probe.h:74
Definition vlc_chroma_probe.h:138
This file is a collection of common definitions and types.
This provides convenience helpers for vectors.