1 module ffmpeg.libswscale.swscale;
2 import std.stdint;
3 import ffmpeg.libavutil.avutil;
4 
5 @nogc nothrow extern(C):
6 
7 /**
8 * @defgroup libsws Color conversion and scaling
9 * @{
10 *
11 * Return the LIBSWSCALE_VERSION_INT constant.
12 */
13 uint swscale_version();
14 
15 /**
16 * Return the libswscale build-time configuration.
17 */
18 char* swscale_configuration();
19 
20 /**
21 * Return the libswscale license.
22 */
23 char* swscale_license();
24 
25 /* values for the flags, the stuff on the command line is different */
26 enum SWS_FAST_BILINEAR =   1;
27 enum SWS_BILINEAR      =    2;
28 enum SWS_BICUBIC     =      4;
29 enum SWS_X          =       8;
30 enum SWS_POINT      =    0x10;
31 enum SWS_AREA       =    0x20;
32 enum SWS_BICUBLIN   =    0x40;
33 enum SWS_GAUSS     =     0x80;
34 enum SWS_SINC      =    0x100;
35 enum SWS_LANCZOS  =     0x200;
36 enum SWS_SPLINE     =   0x400;
37 
38 enum SWS_SRC_V_CHR_DROP_MASK  =   0x30000;
39 enum SWS_SRC_V_CHR_DROP_SHIFT  =  16;
40 
41 enum SWS_PARAM_DEFAULT     =      123_456;
42 
43 enum SWS_PRINT_INFO         =     0x1000;
44 
45 //the following 3 flags are not completely implemented
46 //internal chrominace subsampling info
47 enum SWS_FULL_CHR_H_INT  =  0x2000;
48 //input subsampling info
49 enum SWS_FULL_CHR_H_INP  =  0x4000;
50 enum SWS_DIRECT_BGR      =  0x8000;
51 enum SWS_ACCURATE_RND   =   0x40000;
52 enum SWS_BITEXACT        =  0x80000;
53 enum SWS_ERROR_DIFFUSION = 0x800000;
54 
55 enum SWS_MAX_REDUCE_CUTOFF = 0.002;
56 
57 enum SWS_CS_ITU709   =      1;
58 enum SWS_CS_FCC       =     4;
59 enum SWS_CS_ITU601   =      5;
60 enum SWS_CS_ITU624     =    5;
61 enum SWS_CS_SMPTE170M  =    5;
62 enum SWS_CS_SMPTE240M  =    7;
63 enum SWS_CS_DEFAULT     =   5;
64 
65 /**
66 * Return a pointer to yuv<->rgb coefficients for the given colorspace
67 * suitable for sws_setColorspaceDetails().
68 *
69 * @param colorspace One of the SWS_CS_* macros. If invalid,
70 * SWS_CS_DEFAULT is used.
71 */
72 int *sws_getCoefficients(int colorspace);
73 
74 // when used for filters they must have an odd number of elements
75 // coeffs cannot be shared between vectors
76 struct SwsVector {
77     double *coeff;              ///< pointer to the list of coefficients
78     int length;                 ///< number of coefficients in the vector
79 }
80 
81 // vectors can be shared
82 struct SwsFilter {
83     SwsVector *lumH;
84     SwsVector *lumV;
85     SwsVector *chrH;
86     SwsVector *chrV;
87 }
88 
89 struct SwsContext{}
90 /**
91 * Return a positive value if pix_fmt is a supported input format, 0
92 * otherwise.
93 */
94 int sws_isSupportedInput(const AVPixelFormat pix_fmt);
95 
96 /**
97 * Return a positive value if pix_fmt is a supported output format, 0
98 * otherwise.
99 */
100 int sws_isSupportedOutput(const AVPixelFormat pix_fmt);
101 
102 /**
103 * @param[in]  pix_fmt the pixel format
104 * @return a positive value if an endianness conversion for pix_fmt is
105 * supported, 0 otherwise.
106 */
107 int sws_isSupportedEndiannessConversion(const AVPixelFormat pix_fmt);
108 
109 /**
110 * Allocate an empty SwsContext. This must be filled and passed to
111 * sws_init_context(). For filling see AVOptions, options.c and
112 * sws_setColorspaceDetails().
113 */
114 SwsContext *sws_alloc_context();
115 
116 /**
117 * Initialize the swscaler context sws_context.
118 *
119 * @return zero or positive value on success, a negative value on
120 * error
121 */
122 int sws_init_context( SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);
123 
124 /**
125 * Free the swscaler context swsContext.
126 * If swsContext is NULL, then does nothing.
127 */
128 void sws_freeContext( SwsContext *swsContext);
129 
130 /**
131 * Allocate and return an SwsContext. You need it to perform
132 * scaling/conversion operations using sws_scale().
133 *
134 * @param srcW the width of the source image
135 * @param srcH the height of the source image
136 * @param srcFormat the source image format
137 * @param dstW the width of the destination image
138 * @param dstH the height of the destination image
139 * @param dstFormat the destination image format
140 * @param flags specify which algorithm and options to use for rescaling
141 * @return a pointer to an allocated context, or NULL in case of error
142 * @note this function is to be removed after a saner alternative is
143 *       written
144 */
145 SwsContext *sws_getContext(int srcW, int srcH, const AVPixelFormat srcFormat,
146                                   int dstW, int dstH, const AVPixelFormat dstFormat,
147                                   int flags, SwsFilter *srcFilter,
148                                   SwsFilter *dstFilter, const double *param);
149 
150 /**
151 * Scale the image slice in srcSlice and put the resulting scaled
152 * slice in the image in dst. A slice is a sequence of consecutive
153 * rows in an image.
154 *
155 * Slices have to be provided in sequential order, either in
156 * top-bottom or bottom-top order. If slices are provided in
157 * non-sequential order the behavior of the function is undefined.
158 *
159 * @param c         the scaling context previously created with
160 *                  sws_getContext()
161 * @param srcSlice  the array containing the pointers to the planes of
162 *                  the source slice
163 * @param srcStride the array containing the strides for each plane of
164 *                  the source image
165 * @param srcSliceY the position in the source image of the slice to
166 *                  process, that is the number (counted starting from
167 *                  zero) in the image of the first row of the slice
168 * @param srcSliceH the height of the source slice, that is the number
169 *                  of rows in the slice
170 * @param dst       the array containing the pointers to the planes of
171 *                  the destination image
172 * @param dstStride the array containing the strides for each plane of
173 *                  the destination image
174 * @return          the height of the output slice
175 */
176 int sws_scale(SwsContext *c, const uint8_t **srcSlice,
177               const int *srcStride, int srcSliceY, int srcSliceH,
178               const uint8_t **dst, const int *dstStride);
179 
180 /**
181 * @param dstRange flag indicating the while-black range of the output (1=jpeg / 0=mpeg)
182 * @param srcRange flag indicating the while-black range of the input (1=jpeg / 0=mpeg)
183 * @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x]
184 * @param inv_table the yuv2rgb coefficients describing the input yuv space, normally ff_yuv2rgb_coeffs[x]
185 * @param brightness 16.16 fixed point brightness correction
186 * @param contrast 16.16 fixed point contrast correction
187 * @param saturation 16.16 fixed point saturation correction
188 * @return -1 if not supported
189 */
190 int sws_setColorspaceDetails( SwsContext *c, const int [4]inv_table,
191                              int srcRange, const int [4]table, int dstRange,
192                              int brightness, int contrast, int saturation);
193 
194 /**
195 * @return -1 if not supported
196 */
197 int sws_getColorspaceDetails( SwsContext *c, int **inv_table,
198                              int *srcRange, int **table, int *dstRange,
199                              int *brightness, int *contrast, int *saturation);
200 
201 /**
202 * Allocate and return an uninitialized vector with length coefficients.
203 */
204 SwsVector *sws_allocVec(int length);
205 
206 /**
207 * Return a normalized Gaussian curve used to filter stuff
208 * quality = 3 is high quality, lower is lower quality.
209 */
210 SwsVector *sws_getGaussianVec(double variance, double quality);
211 
212 /**
213 * Allocate and return a vector with length coefficients, all
214 * with the same value c.
215 */
216 SwsVector *sws_getConstVec(double c, int length);
217 
218 /**
219 * Allocate and return a vector with just one coefficient, with
220 * value 1.0.
221 */
222 SwsVector *sws_getIdentityVec();
223 
224 /**
225 * Scale all the coefficients of a by the scalar value.
226 */
227 void sws_scaleVec(SwsVector *a, double scalar);
228 
229 /**
230 * Scale all the coefficients of a so that their sum equals height.
231 */
232 void sws_normalizeVec(SwsVector *a, double height);
233 void sws_convVec(SwsVector *a, SwsVector *b);
234 void sws_addVec(SwsVector *a, SwsVector *b);
235 void sws_subVec(SwsVector *a, SwsVector *b);
236 void sws_shiftVec(SwsVector *a, int shift);
237 
238 /**
239 * Allocate and return a clone of the vector a, that is a vector
240 * with the same coefficients as a.
241 */
242 SwsVector *sws_cloneVec(SwsVector *a);
243 
244 /**
245 * Print with av_log() a textual representation of the vector a
246 * if log_level <= av_log_level.
247 */
248 void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level);
249 
250 void sws_freeVec(SwsVector *a);
251 
252 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
253                                 float lumaSharpen, float chromaSharpen,
254                                 float chromaHShift, float chromaVShift,
255                                 int verbose);
256 void sws_freeFilter(SwsFilter *filter);
257 
258 /**
259 * Check if context can be reused, otherwise reallocate a new one.
260 *
261 * If context is NULL, just calls sws_getContext() to get a new
262 * context. Otherwise, checks if the parameters are the ones already
263 * saved in context. If that is the case, returns the current
264 * context. Otherwise, frees context and gets a new context with
265 * the new parameters.
266 *
267 * Be warned that srcFilter and dstFilter are not checked, they
268 * are assumed to remain the same.
269 */
270  SwsContext *sws_getCachedContext( SwsContext *context,
271                                         int srcW, int srcH, const AVPixelFormat srcFormat,
272                                         int dstW, int dstH, const AVPixelFormat dstFormat,
273                                         int flags, SwsFilter *srcFilter,
274                                         SwsFilter *dstFilter, const double *param);
275 
276 /**
277 * Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
278 *
279 * The output frame will have the same packed format as the palette.
280 *
281 * @param src        source frame buffer
282 * @param dst        destination frame buffer
283 * @param num_pixels number of pixels to convert
284 * @param palette    array with [256] entries, which must match color arrangement (RGB or BGR) of src
285 */
286 void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
287 
288 /**
289 * Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.
290 *
291 * With the palette format "ABCD", the destination frame ends up with the format "ABC".
292 *
293 * @param src        source frame buffer
294 * @param dst        destination frame buffer
295 * @param num_pixels number of pixels to convert
296 * @param palette    array with [256] entries, which must match color arrangement (RGB or BGR) of src
297 */
298 void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
299 
300 /**
301 * Get the AVClass for swsContext. It can be used in combination with
302 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
303 *
304 * @see av_opt_find().
305 */
306 AVClass *sws_get_class();
307 
308 /**
309 * @}
310 */