FFmpeg
swscale.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Niklas Haas
3  * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef SWSCALE_SWSCALE_H
23 #define SWSCALE_SWSCALE_H
24 
25 /**
26  * @file
27  * @ingroup libsws
28  * external API header
29  */
30 
31 #include <stdint.h>
32 
33 #include "libavutil/avutil.h"
34 #include "libavutil/frame.h"
35 #include "libavutil/log.h"
36 #include "libavutil/pixfmt.h"
37 #include "version_major.h"
38 #ifndef HAVE_AV_CONFIG_H
39 /* When included as part of the ffmpeg build, only include the major version
40  * to avoid unnecessary rebuilds. When included externally, keep including
41  * the full version information. */
42 #include "version.h"
43 #endif
44 
45 /**
46  * @defgroup libsws libswscale
47  * Color conversion and scaling library.
48  *
49  * @{
50  *
51  * Return the LIBSWSCALE_VERSION_INT constant.
52  */
53 unsigned swscale_version(void);
54 
55 /**
56  * Return the libswscale build-time configuration.
57  */
58 const char *swscale_configuration(void);
59 
60 /**
61  * Return the libswscale license.
62  */
63 const char *swscale_license(void);
64 
65 /**
66  * Get the AVClass for SwsContext. It can be used in combination with
67  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
68  *
69  * @see av_opt_find().
70  */
71 const AVClass *sws_get_class(void);
72 
73 /******************************
74  * Flags and quality settings *
75  ******************************/
76 
77 typedef enum SwsDither {
78  SWS_DITHER_NONE = 0, /* disable dithering */
79  SWS_DITHER_AUTO, /* auto-select from preset */
80  SWS_DITHER_BAYER, /* ordered dither matrix */
81  SWS_DITHER_ED, /* error diffusion */
82  SWS_DITHER_A_DITHER, /* arithmetic addition */
83  SWS_DITHER_X_DITHER, /* arithmetic xor */
84  SWS_DITHER_NB, /* not part of the ABI */
86 
87 typedef enum SwsAlphaBlend {
91  SWS_ALPHA_BLEND_NB, /* not part of the ABI */
93 
94 typedef enum SwsFlags {
95  /**
96  * Scaler selection options. Only one may be active at a time.
97  */
98  SWS_FAST_BILINEAR = 1 << 0, ///< fast bilinear filtering
99  SWS_BILINEAR = 1 << 1, ///< bilinear filtering
100  SWS_BICUBIC = 1 << 2, ///< 2-tap cubic B-spline
101  SWS_X = 1 << 3, ///< experimental
102  SWS_POINT = 1 << 4, ///< nearest neighbor
103  SWS_AREA = 1 << 5, ///< area averaging
104  SWS_BICUBLIN = 1 << 6, ///< bicubic luma, bilinear chroma
105  SWS_GAUSS = 1 << 7, ///< gaussian approximation
106  SWS_SINC = 1 << 8, ///< unwindowed sinc
107  SWS_LANCZOS = 1 << 9, ///< 3-tap sinc/sinc
108  SWS_SPLINE = 1 << 10, ///< cubic Keys spline
109 
110  /**
111  * Return an error on underspecified conversions. Without this flag,
112  * unspecified fields are defaulted to sensible values.
113  */
114  SWS_STRICT = 1 << 11,
115 
116  /**
117  * Emit verbose log of scaling parameters.
118  */
119  SWS_PRINT_INFO = 1 << 12,
120 
121  /**
122  * Perform full chroma upsampling when upscaling to RGB.
123  *
124  * For example, when converting 50x50 yuv420p to 100x100 rgba, setting this flag
125  * will scale the chroma plane from 25x25 to 100x100 (4:4:4), and then convert
126  * the 100x100 yuv444p image to rgba in the final output step.
127  *
128  * Without this flag, the chroma plane is instead scaled to 50x100 (4:2:2),
129  * with a single chroma sample being re-used for both of the horizontally
130  * adjacent RGBA output pixels.
131  */
133 
134  /**
135  * Perform full chroma interpolation when downscaling RGB sources.
136  *
137  * For example, when converting a 100x100 rgba source to 50x50 yuv444p, setting
138  * this flag will generate a 100x100 (4:4:4) chroma plane, which is then
139  * downscaled to the required 50x50.
140  *
141  * Without this flag, the chroma plane is instead generated at 50x100 (dropping
142  * every other pixel), before then being downscaled to the required 50x50
143  * resolution.
144  */
146 
147  /**
148  * Force bit-exact output. This will prevent the use of platform-specific
149  * optimizations that may lead to slight difference in rounding, in favor
150  * of always maintaining exact bit output compatibility with the reference
151  * C code.
152  *
153  * Note: It is recommended to set both of these flags simultaneously.
154  */
155  SWS_ACCURATE_RND = 1 << 18,
156  SWS_BITEXACT = 1 << 19,
157 
158  /**
159  * Deprecated flags.
160  */
161  SWS_DIRECT_BGR = 1 << 15, ///< This flag has no effect
162  SWS_ERROR_DIFFUSION = 1 << 23, ///< Set `SwsContext.dither` instead
163 } SwsFlags;
164 
165 /***********************************
166  * Context creation and management *
167  ***********************************/
168 
169 /**
170  * Main external API structure. New fields can be added to the end with
171  * minor version bumps. Removal, reordering and changes to existing fields
172  * require a major version bump. sizeof(SwsContext) is not part of the ABI.
173  */
174 typedef struct SwsContext {
175  const AVClass *av_class;
176 
177  /**
178  * Private data of the user, can be used to carry app specific stuff.
179  */
180  void *opaque;
181 
182  /**
183  * Bitmask of SWS_*. See `SwsFlags` for details.
184  */
185  unsigned flags;
186 
187  /**
188  * Extra parameters for fine-tuning certain scalers.
189  */
190  double scaler_params[2];
191 
192  /**
193  * How many threads to use for processing, or 0 for automatic selection.
194  */
195  int threads;
196 
197  /**
198  * Dither mode.
199  */
201 
202  /**
203  * Alpha blending mode. See `SwsAlphaBlend` for details.
204  */
206 
207  /**
208  * Use gamma correct scaling.
209  */
210  int gamma_flag;
211 
212  /**
213  * Deprecated frame property overrides, for the legacy API only.
214  *
215  * Ignored by sws_scale_frame() when used in dynamic mode, in which
216  * case all properties are instead taken from the frame directly.
217  */
218  int src_w, src_h; ///< Width and height of the source frame
219  int dst_w, dst_h; ///< Width and height of the destination frame
220  int src_format; ///< Source pixel format
221  int dst_format; ///< Destination pixel format
222  int src_range; ///< Source is full range
223  int dst_range; ///< Destination is full range
224  int src_v_chr_pos; ///< Source vertical chroma position in luma grid / 256
225  int src_h_chr_pos; ///< Source horizontal chroma position
226  int dst_v_chr_pos; ///< Destination vertical chroma position
227  int dst_h_chr_pos; ///< Destination horizontal chroma position
228 
229  /* Remember to add new fields to graph.c:opts_equal() */
230 } SwsContext;
231 
232 /**
233  * Allocate an empty SwsContext and set its fields to default values.
234  */
236 
237 /**
238  * Free the context and everything associated with it, and write NULL
239  * to the provided pointer.
240  */
242 
243 /***************************
244  * Supported frame formats *
245  ***************************/
246 
247 /**
248  * Test if a given pixel format is supported.
249  *
250  * @param output If 0, test if compatible with the source/input frame;
251  * otherwise, with the destination/output frame.
252  * @param format The format to check.
253  *
254  * @return A positive integer if supported, 0 otherwise.
255  */
257 
258 /**
259  * Test if a given color space is supported.
260  *
261  * @param output If 0, test if compatible with the source/input frame;
262  * otherwise, with the destination/output frame.
263  * @param colorspace The colorspace to check.
264  *
265  * @return A positive integer if supported, 0 otherwise.
266  */
267 int sws_test_colorspace(enum AVColorSpace colorspace, int output);
268 
269 /**
270  * Test if a given set of color primaries is supported.
271  *
272  * @param output If 0, test if compatible with the source/input frame;
273  * otherwise, with the destination/output frame.
274  * @param primaries The color primaries to check.
275  *
276  * @return A positive integer if supported, 0 otherwise.
277  */
279 
280 /**
281  * Test if a given color transfer function is supported.
282  *
283  * @param output If 0, test if compatible with the source/input frame;
284  * otherwise, with the destination/output frame.
285  * @param trc The color transfer function to check.
286  *
287  * @return A positive integer if supported, 0 otherwise.
288  */
290 
291 /**
292  * Helper function to run all sws_test_* against a frame, as well as testing
293  * the basic frame properties for sanity. Ignores irrelevant properties - for
294  * example, AVColorSpace is not checked for RGB frames.
295  */
296 int sws_test_frame(const AVFrame *frame, int output);
297 
298 /**
299  * Like `sws_scale_frame`, but without actually scaling. It will instead
300  * merely initialize internal state that *would* be required to perform the
301  * operation, as well as returning the correct error code for unsupported
302  * frame combinations.
303  *
304  * @param ctx The scaling context.
305  * @param dst The destination frame to consider.
306  * @param src The source frame to consider.
307  * @return 0 on success, a negative AVERROR code on failure.
308  */
309 int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src);
310 
311 /********************
312  * Main scaling API *
313  ********************/
314 
315 /**
316  * Check if a given conversion is a noop. Returns a positive integer if
317  * no operation needs to be performed, 0 otherwise.
318  */
319 int sws_is_noop(const AVFrame *dst, const AVFrame *src);
320 
321 /**
322  * Scale source data from `src` and write the output to `dst`.
323  *
324  * This function can be used directly on an allocated context, without setting
325  * up any frame properties or calling `sws_init_context()`. Such usage is fully
326  * dynamic and does not require reallocation if the frame properties change.
327  *
328  * Alternatively, this function can be called on a context that has been
329  * explicitly initialized. However, this is provided only for backwards
330  * compatibility. In this usage mode, all frame properties must be correctly
331  * set at init time, and may no longer change after initialization.
332  *
333  * @param ctx The scaling context.
334  * @param dst The destination frame. The data buffers may either be already
335  * allocated by the caller or left clear, in which case they will
336  * be allocated by the scaler. The latter may have performance
337  * advantages - e.g. in certain cases some (or all) output planes
338  * may be references to input planes, rather than copies.
339  * @param src The source frame. If the data buffers are set to NULL, then
340  * this function behaves identically to `sws_frame_setup`.
341  * @return 0 on success, a negative AVERROR code on failure.
342  */
344 
345 /*************************
346  * Legacy (stateful) API *
347  *************************/
348 
349 #define SWS_SRC_V_CHR_DROP_MASK 0x30000
350 #define SWS_SRC_V_CHR_DROP_SHIFT 16
351 
352 #define SWS_PARAM_DEFAULT 123456
353 
354 #define SWS_MAX_REDUCE_CUTOFF 0.002
355 
356 #define SWS_CS_ITU709 1
357 #define SWS_CS_FCC 4
358 #define SWS_CS_ITU601 5
359 #define SWS_CS_ITU624 5
360 #define SWS_CS_SMPTE170M 5
361 #define SWS_CS_SMPTE240M 7
362 #define SWS_CS_DEFAULT 5
363 #define SWS_CS_BT2020 9
364 
365 /**
366  * Return a pointer to yuv<->rgb coefficients for the given colorspace
367  * suitable for sws_setColorspaceDetails().
368  *
369  * @param colorspace One of the SWS_CS_* macros. If invalid,
370  * SWS_CS_DEFAULT is used.
371  */
372 const int *sws_getCoefficients(int colorspace);
373 
374 // when used for filters they must have an odd number of elements
375 // coeffs cannot be shared between vectors
376 typedef struct SwsVector {
377  double *coeff; ///< pointer to the list of coefficients
378  int length; ///< number of coefficients in the vector
379 } SwsVector;
380 
381 // vectors can be shared
382 typedef struct SwsFilter {
387 } SwsFilter;
388 
389 /**
390  * Return a positive value if pix_fmt is a supported input format, 0
391  * otherwise.
392  */
394 
395 /**
396  * Return a positive value if pix_fmt is a supported output format, 0
397  * otherwise.
398  */
400 
401 /**
402  * @param[in] pix_fmt the pixel format
403  * @return a positive value if an endianness conversion for pix_fmt is
404  * supported, 0 otherwise.
405  */
407 
408 /**
409  * Initialize the swscaler context sws_context.
410  *
411  * This function is considered deprecated, and provided only for backwards
412  * compatibility with sws_scale() and sws_start_frame(). The preferred way to
413  * use libswscale is to set all frame properties correctly and call
414  * sws_scale_frame() directly, without explicitly initializing the context.
415  *
416  * @return zero or positive value on success, a negative value on
417  * error
418  */
420 int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);
421 
422 /**
423  * Free the swscaler context swsContext.
424  * If swsContext is NULL, then does nothing.
425  */
426 void sws_freeContext(SwsContext *swsContext);
427 
428 /**
429  * Allocate and return an SwsContext. You need it to perform
430  * scaling/conversion operations using sws_scale().
431  *
432  * @param srcW the width of the source image
433  * @param srcH the height of the source image
434  * @param srcFormat the source image format
435  * @param dstW the width of the destination image
436  * @param dstH the height of the destination image
437  * @param dstFormat the destination image format
438  * @param flags specify which algorithm and options to use for rescaling
439  * @param param extra parameters to tune the used scaler
440  * For SWS_BICUBIC param[0] and [1] tune the shape of the basis
441  * function, param[0] tunes f(1) and param[1] f´(1)
442  * For SWS_GAUSS param[0] tunes the exponent and thus cutoff
443  * frequency
444  * For SWS_LANCZOS param[0] tunes the width of the window function
445  * @return a pointer to an allocated context, or NULL in case of error
446  * @note this function is to be removed after a saner alternative is
447  * written
448  */
449 SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,
450  int dstW, int dstH, enum AVPixelFormat dstFormat,
451  int flags, SwsFilter *srcFilter,
452  SwsFilter *dstFilter, const double *param);
453 
454 /**
455  * Scale the image slice in srcSlice and put the resulting scaled
456  * slice in the image in dst. A slice is a sequence of consecutive
457  * rows in an image. Requires a context that has been previously
458  * been initialized with sws_init_context().
459  *
460  * Slices have to be provided in sequential order, either in
461  * top-bottom or bottom-top order. If slices are provided in
462  * non-sequential order the behavior of the function is undefined.
463  *
464  * @param c the scaling context previously created with
465  * sws_getContext()
466  * @param srcSlice the array containing the pointers to the planes of
467  * the source slice
468  * @param srcStride the array containing the strides for each plane of
469  * the source image
470  * @param srcSliceY the position in the source image of the slice to
471  * process, that is the number (counted starting from
472  * zero) in the image of the first row of the slice
473  * @param srcSliceH the height of the source slice, that is the number
474  * of rows in the slice
475  * @param dst the array containing the pointers to the planes of
476  * the destination image
477  * @param dstStride the array containing the strides for each plane of
478  * the destination image
479  * @return the height of the output slice
480  */
481 int sws_scale(SwsContext *c, const uint8_t *const srcSlice[],
482  const int srcStride[], int srcSliceY, int srcSliceH,
483  uint8_t *const dst[], const int dstStride[]);
484 
485 /**
486  * Initialize the scaling process for a given pair of source/destination frames.
487  * Must be called before any calls to sws_send_slice() and sws_receive_slice().
488  * Requires a context that has been previously been initialized with
489  * sws_init_context().
490  *
491  * This function will retain references to src and dst, so they must both use
492  * refcounted buffers (if allocated by the caller, in case of dst).
493  *
494  * @param c The scaling context
495  * @param dst The destination frame.
496  *
497  * The data buffers may either be already allocated by the caller or
498  * left clear, in which case they will be allocated by the scaler.
499  * The latter may have performance advantages - e.g. in certain cases
500  * some output planes may be references to input planes, rather than
501  * copies.
502  *
503  * Output data will be written into this frame in successful
504  * sws_receive_slice() calls.
505  * @param src The source frame. The data buffers must be allocated, but the
506  * frame data does not have to be ready at this point. Data
507  * availability is then signalled by sws_send_slice().
508  * @return 0 on success, a negative AVERROR code on failure
509  *
510  * @see sws_frame_end()
511  */
513 
514 /**
515  * Finish the scaling process for a pair of source/destination frames previously
516  * submitted with sws_frame_start(). Must be called after all sws_send_slice()
517  * and sws_receive_slice() calls are done, before any new sws_frame_start()
518  * calls.
519  *
520  * @param c The scaling context
521  */
522 void sws_frame_end(SwsContext *c);
523 
524 /**
525  * Indicate that a horizontal slice of input data is available in the source
526  * frame previously provided to sws_frame_start(). The slices may be provided in
527  * any order, but may not overlap. For vertically subsampled pixel formats, the
528  * slices must be aligned according to subsampling.
529  *
530  * @param c The scaling context
531  * @param slice_start first row of the slice
532  * @param slice_height number of rows in the slice
533  *
534  * @return a non-negative number on success, a negative AVERROR code on failure.
535  */
536 int sws_send_slice(SwsContext *c, unsigned int slice_start,
537  unsigned int slice_height);
538 
539 /**
540  * Request a horizontal slice of the output data to be written into the frame
541  * previously provided to sws_frame_start().
542  *
543  * @param c The scaling context
544  * @param slice_start first row of the slice; must be a multiple of
545  * sws_receive_slice_alignment()
546  * @param slice_height number of rows in the slice; must be a multiple of
547  * sws_receive_slice_alignment(), except for the last slice
548  * (i.e. when slice_start+slice_height is equal to output
549  * frame height)
550  *
551  * @return a non-negative number if the data was successfully written into the output
552  * AVERROR(EAGAIN) if more input data needs to be provided before the
553  * output can be produced
554  * another negative AVERROR code on other kinds of scaling failure
555  */
556 int sws_receive_slice(SwsContext *c, unsigned int slice_start,
557  unsigned int slice_height);
558 
559 /**
560  * Get the alignment required for slices. Requires a context that has been
561  * previously been initialized with sws_init_context().
562  *
563  * @param c The scaling context
564  * @return alignment required for output slices requested with sws_receive_slice().
565  * Slice offsets and sizes passed to sws_receive_slice() must be
566  * multiples of the value returned from this function.
567  */
568 unsigned int sws_receive_slice_alignment(const SwsContext *c);
569 
570 /**
571  * @param c the scaling context
572  * @param dstRange flag indicating the while-black range of the output (1=jpeg / 0=mpeg)
573  * @param srcRange flag indicating the while-black range of the input (1=jpeg / 0=mpeg)
574  * @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x]
575  * @param inv_table the yuv2rgb coefficients describing the input yuv space, normally ff_yuv2rgb_coeffs[x]
576  * @param brightness 16.16 fixed point brightness correction
577  * @param contrast 16.16 fixed point contrast correction
578  * @param saturation 16.16 fixed point saturation correction
579  *
580  * @return A negative error code on error, non negative otherwise.
581  * If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported.
582  */
583 int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4],
584  int srcRange, const int table[4], int dstRange,
585  int brightness, int contrast, int saturation);
586 
587 /**
588  * @return A negative error code on error, non negative otherwise.
589  * If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported.
590  */
591 int sws_getColorspaceDetails(SwsContext *c, int **inv_table,
592  int *srcRange, int **table, int *dstRange,
593  int *brightness, int *contrast, int *saturation);
594 
595 /**
596  * Allocate and return an uninitialized vector with length coefficients.
597  */
598 SwsVector *sws_allocVec(int length);
599 
600 /**
601  * Return a normalized Gaussian curve used to filter stuff
602  * quality = 3 is high quality, lower is lower quality.
603  */
604 SwsVector *sws_getGaussianVec(double variance, double quality);
605 
606 /**
607  * Scale all the coefficients of a by the scalar value.
608  */
609 void sws_scaleVec(SwsVector *a, double scalar);
610 
611 /**
612  * Scale all the coefficients of a so that their sum equals height.
613  */
614 void sws_normalizeVec(SwsVector *a, double height);
615 
616 void sws_freeVec(SwsVector *a);
617 
618 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
619  float lumaSharpen, float chromaSharpen,
620  float chromaHShift, float chromaVShift,
621  int verbose);
623 
624 /**
625  * Check if context can be reused, otherwise reallocate a new one.
626  *
627  * If context is NULL, just calls sws_getContext() to get a new
628  * context. Otherwise, checks if the parameters are the ones already
629  * saved in context. If that is the case, returns the current
630  * context. Otherwise, frees context and gets a new context with
631  * the new parameters.
632  *
633  * Be warned that srcFilter and dstFilter are not checked, they
634  * are assumed to remain the same.
635  */
636 SwsContext *sws_getCachedContext(SwsContext *context, int srcW, int srcH,
637  enum AVPixelFormat srcFormat, int dstW, int dstH,
638  enum AVPixelFormat dstFormat, int flags,
639  SwsFilter *srcFilter, SwsFilter *dstFilter,
640  const double *param);
641 
642 /**
643  * Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
644  *
645  * The output frame will have the same packed format as the palette.
646  *
647  * @param src source frame buffer
648  * @param dst destination frame buffer
649  * @param num_pixels number of pixels to convert
650  * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
651  */
652 void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
653 
654 /**
655  * Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.
656  *
657  * With the palette format "ABCD", the destination frame ends up with the format "ABC".
658  *
659  * @param src source frame buffer
660  * @param dst destination frame buffer
661  * @param num_pixels number of pixels to convert
662  * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
663  */
664 void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
665 
666 /**
667  * @}
668  */
669 
670 #endif /* SWSCALE_SWSCALE_H */
sws_setColorspaceDetails
int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
Definition: utils.c:1046
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
SWS_DITHER_AUTO
@ SWS_DITHER_AUTO
Definition: swscale.h:81
version_major.h
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:611
SwsContext::src_w
int src_w
Deprecated frame property overrides, for the legacy API only.
Definition: swscale.h:220
SWS_ALPHA_BLEND_CHECKERBOARD
@ SWS_ALPHA_BLEND_CHECKERBOARD
Definition: swscale.h:90
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
sws_freeContext
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:2447
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
SWS_DITHER_NONE
@ SWS_DITHER_NONE
Definition: swscale.h:80
SWS_BILINEAR
@ SWS_BILINEAR
bilinear filtering
Definition: swscale.h:99
sws_test_primaries
int sws_test_primaries(enum AVColorPrimaries primaries, int output)
Test if a given set of color primaries is supported.
Definition: utils.c:2733
SWS_BITEXACT
@ SWS_BITEXACT
Definition: swscale.h:156
table
static const uint16_t table[]
Definition: prosumer.c:203
SwsContext::av_class
const AVClass * av_class
Definition: swscale.h:177
SwsContext::flags
unsigned flags
Bitmask of SWS_*.
Definition: swscale.h:187
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
sws_receive_slice
int sws_receive_slice(SwsContext *c, unsigned int slice_start, unsigned int slice_height)
Request a horizontal slice of the output data to be written into the frame previously provided to sws...
Definition: swscale.c:1167
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:586
sws_convertPalette8ToPacked24
void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.
Definition: swscale_unscaled.c:2613
SWS_BICUBLIN
@ SWS_BICUBLIN
bicubic luma, bilinear chroma
Definition: swscale.h:104
SWS_ALPHA_BLEND_NONE
@ SWS_ALPHA_BLEND_NONE
Definition: swscale.h:88
quality
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
Definition: rate_distortion.txt:12
sws_freeVec
void sws_freeVec(SwsVector *a)
Definition: utils.c:2343
SWS_FAST_BILINEAR
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition: swscale.h:98
primaries
enum AVColorPrimaries primaries
Definition: mediacodec_wrapper.c:2612
SWS_FULL_CHR_H_INP
@ SWS_FULL_CHR_H_INP
Perform full chroma interpolation when downscaling RGB sources.
Definition: swscale.h:145
SwsContext::src_v_chr_pos
int src_v_chr_pos
Source vertical chroma position in luma grid / 256.
Definition: swscale.h:226
SwsDither
SwsDither
Definition: swscale.h:77
sws_getCachedContext
SwsContext * sws_getCachedContext(SwsContext *context, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Check if context can be reused, otherwise reallocate a new one.
Definition: utils.c:2536
swscale_license
const char * swscale_license(void)
Return the libswscale license.
Definition: version.c:38
sws_init_context
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition: utils.c:2082
sws_frame_setup
int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src)
Like sws_scale_frame, but without actually scaling.
Definition: swscale.c:1343
SWS_ALPHA_BLEND_NB
@ SWS_ALPHA_BLEND_NB
Definition: swscale.h:91
sws_get_class
const AVClass * sws_get_class(void)
Get the AVClass for SwsContext.
Definition: options.c:99
SWS_DITHER_X_DITHER
@ SWS_DITHER_X_DITHER
Definition: swscale.h:85
SWS_AREA
@ SWS_AREA
area averaging
Definition: swscale.h:103
SwsContext::dither
SwsDither dither
Dither mode.
Definition: swscale.h:202
SwsFlags
SwsFlags
Definition: swscale.h:94
SwsContext::threads
int threads
How many threads to use for processing, or 0 for automatic selection.
Definition: swscale.h:197
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
SwsVector::length
int length
number of coefficients in the vector
Definition: swscale.h:378
sws_allocVec
SwsVector * sws_allocVec(int length)
Allocate and return an uninitialized vector with length coefficients.
Definition: utils.c:2153
SWS_DITHER_BAYER
@ SWS_DITHER_BAYER
Definition: swscale.h:82
sws_test_colorspace
int sws_test_colorspace(enum AVColorSpace colorspace, int output)
Test if a given color space is supported.
Definition: utils.c:2716
ctx
AVFormatContext * ctx
Definition: movenc.c:49
sws_getGaussianVec
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality,...
Definition: utils.c:2170
sws_frame_end
void sws_frame_end(SwsContext *c)
Finish the scaling process for a pair of source/destination frames previously submitted with sws_fram...
Definition: swscale.c:1106
context
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
SWS_DIRECT_BGR
@ SWS_DIRECT_BGR
Deprecated flags.
Definition: swscale.h:161
SWS_BICUBIC
@ SWS_BICUBIC
2-tap cubic B-spline
Definition: swscale.h:100
SwsContext::gamma_flag
int gamma_flag
Use gamma correct scaling.
Definition: swscale.h:212
sws_is_noop
int sws_is_noop(const AVFrame *dst, const AVFrame *src)
Check if a given conversion is a noop.
Definition: utils.c:2779
sws_getDefaultFilter
SwsFilter * sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, float lumaSharpen, float chromaSharpen, float chromaHShift, float chromaVShift, int verbose)
Definition: utils.c:2364
sws_test_format
int sws_test_format(enum AVPixelFormat format, int output)
Test if a given pixel format is supported.
Definition: utils.c:2711
SwsContext::src_range
int src_range
Source is full range.
Definition: swscale.h:224
SwsVector::coeff
double * coeff
pointer to the list of coefficients
Definition: swscale.h:377
SwsContext::dst_h_chr_pos
int dst_h_chr_pos
Destination horizontal chroma position.
Definition: swscale.h:229
sws_scaleVec
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
Definition: utils.c:2236
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
SwsFilter::chrV
SwsVector * chrV
Definition: swscale.h:386
height
#define height
Definition: dsp.h:85
sws_alloc_context
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition: utils.c:1227
SwsVector
Definition: swscale.h:376
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
SwsContext::opaque
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: swscale.h:182
SWS_POINT
@ SWS_POINT
nearest neighbor
Definition: swscale.h:102
SWS_ALPHA_BLEND_UNIFORM
@ SWS_ALPHA_BLEND_UNIFORM
Definition: swscale.h:89
SwsContext::alpha_blend
SwsAlphaBlend alpha_blend
Alpha blending mode.
Definition: swscale.h:207
SWS_SPLINE
@ SWS_SPLINE
cubic Keys spline
Definition: swscale.h:108
SwsContext::src_h
int src_h
Width and height of the source frame.
Definition: swscale.h:220
frame.h
sws_getColorspaceDetails
int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
Definition: utils.c:1202
SwsFilter
Definition: swscale.h:382
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
SwsFilter::lumV
SwsVector * lumV
Definition: swscale.h:384
sws_test_transfer
int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output)
Test if a given color transfer function is supported.
Definition: utils.c:2739
SWS_DITHER_NB
@ SWS_DITHER_NB
Definition: swscale.h:86
swscale_configuration
const char * swscale_configuration(void)
Return the libswscale build-time configuration.
Definition: version.c:33
sws_isSupportedInput
int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported input format, 0 otherwise.
Definition: utils.c:373
SwsContext::dst_format
int dst_format
Destination pixel format.
Definition: swscale.h:223
av_warn_unused_result
#define av_warn_unused_result
Definition: attributes.h:64
sws_isSupportedEndiannessConversion
int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt)
Definition: utils.c:385
sws_send_slice
int sws_send_slice(SwsContext *c, unsigned int slice_start, unsigned int slice_height)
Indicate that a horizontal slice of input data is available in the source frame previously provided t...
Definition: swscale.c:1145
log.h
SWS_X
@ SWS_X
experimental
Definition: swscale.h:101
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:640
sws_isSupportedOutput
int sws_isSupportedOutput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported output format, 0 otherwise.
Definition: utils.c:379
sws_test_frame
int sws_test_frame(const AVFrame *frame, int output)
Helper function to run all sws_test_* against a frame, as well as testing the basic frame properties ...
Definition: utils.c:2766
SwsContext::dst_h
int dst_h
Width and height of the destination frame.
Definition: swscale.h:221
sws_freeFilter
void sws_freeFilter(SwsFilter *filter)
Definition: utils.c:2352
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: dec.c:738
SWS_DITHER_ED
@ SWS_DITHER_ED
Definition: swscale.h:83
sws_receive_slice_alignment
unsigned int sws_receive_slice_alignment(const SwsContext *c)
Get the alignment required for slices.
Definition: swscale.c:1158
pixfmt.h
sws_frame_start
int sws_frame_start(SwsContext *c, AVFrame *dst, const AVFrame *src)
Initialize the scaling process for a given pair of source/destination frames.
Definition: swscale.c:1114
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
verbose
int verbose
Definition: checkasm.c:404
SWS_FULL_CHR_H_INT
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition: swscale.h:132
sws_getContext
SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:2116
SWS_DITHER_A_DITHER
@ SWS_DITHER_A_DITHER
Definition: swscale.h:84
SwsAlphaBlend
SwsAlphaBlend
Definition: swscale.h:87
SwsContext::scaler_params
double scaler_params[2]
Extra parameters for fine-tuning certain scalers.
Definition: swscale.h:192
sws_scale
int sws_scale(SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst.
Definition: swscale.c:1427
SWS_PRINT_INFO
@ SWS_PRINT_INFO
Emit verbose log of scaling parameters.
Definition: swscale.h:119
SWS_ERROR_DIFFUSION
@ SWS_ERROR_DIFFUSION
Set SwsContext.dither instead.
Definition: swscale.h:162
SWS_GAUSS
@ SWS_GAUSS
gaussian approximation
Definition: swscale.h:105
SWS_STRICT
@ SWS_STRICT
Return an error on underspecified conversions.
Definition: swscale.h:114
avutil.h
sws_getCoefficients
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
Definition: yuv2rgb.c:61
SwsContext::dst_w
int dst_w
Definition: swscale.h:221
SwsContext::src_format
int src_format
Source pixel format.
Definition: swscale.h:222
swscale_version
unsigned swscale_version(void)
Definition: version.c:27
SwsContext::dst_range
int dst_range
Destination is full range.
Definition: swscale.h:225
SwsFilter::lumH
SwsVector * lumH
Definition: swscale.h:383
sws_free_context
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
Definition: utils.c:2526
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
SwsContext::src_h_chr_pos
int src_h_chr_pos
Source horizontal chroma position.
Definition: swscale.h:227
sws_scale_frame
int sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
Definition: swscale.c:1267
SWS_ACCURATE_RND
@ SWS_ACCURATE_RND
Force bit-exact output.
Definition: swscale.h:155
SWS_LANCZOS
@ SWS_LANCZOS
3-tap sinc/sinc
Definition: swscale.h:107
sws_convertPalette8ToPacked32
void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
Definition: swscale_unscaled.c:2603
SwsContext::dst_v_chr_pos
int dst_v_chr_pos
Destination vertical chroma position.
Definition: swscale.h:228
SWS_SINC
@ SWS_SINC
unwindowed sinc
Definition: swscale.h:106
SwsContext
Main external API structure.
Definition: swscale.h:174
SwsFilter::chrH
SwsVector * chrH
Definition: swscale.h:385
sws_normalizeVec
void sws_normalizeVec(SwsVector *a, double height)
Scale all the coefficients of a so that their sum equals height.
Definition: utils.c:2244
src
#define src
Definition: vp8dsp.c:248