FFmpeg 9.0
Loading...
Searching...
No Matches
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 */
53unsigned swscale_version(void);
54
55/**
56 * Return the libswscale build-time configuration.
57 */
58const char *swscale_configuration(void);
59
60/**
61 * Return the libswscale license.
62 */
63const 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 */
72
73/******************************
74 * Flags and quality settings *
75 ******************************/
76
77typedef 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 */
85 SWS_DITHER_MAX_ENUM = 0x7FFFFFFF, /* force size to 32 bits, not a valid dither type */
86} SwsDither;
87
88typedef enum SwsAlphaBlend {
92 SWS_ALPHA_BLEND_NB, /* not part of the ABI */
93 SWS_ALPHA_BLEND_MAX_ENUM = 0x7FFFFFFF, /* force size to 32 bits, not a valid blend mode */
95
96typedef enum SwsScaler {
98 SWS_SCALE_BILINEAR, ///< bilinear filtering
99 SWS_SCALE_BICUBIC, ///< 2-tap cubic BC-spline
100 SWS_SCALE_POINT, ///< nearest neighbor (point sampling)
101 SWS_SCALE_AREA, ///< area averaging
102 SWS_SCALE_GAUSSIAN, ///< 2-tap gaussian approximation
103 SWS_SCALE_SINC, ///< unwindowed sinc
104 SWS_SCALE_LANCZOS, ///< 3-tap sinc/sinc
105 SWS_SCALE_SPLINE, ///< unwindowned natural cubic spline
106 SWS_SCALE_NB, ///< not part of the ABI
107 SWS_SCALE_MAX_ENUM = 0x7FFFFFFF, ///< force size to 32 bits, not a valid filter type
108} SwsScaler;
109
110typedef enum SwsBackend {
111 /* Stable backends */
112 SWS_BACKEND_LEGACY = (1 << 0), ///< Legacy bespoke format-specific code
114
115 /* Unstable backends (auto-selected only if SWS_UNSTABLE is enabled) */
116 SWS_BACKEND_C = (1 << 1), ///< Template-based C reference implementation
117 SWS_BACKEND_MEMCPY = (1 << 2), ///< Fast path using libc memcpy() / memset()
118 SWS_BACKEND_X86 = (1 << 3), ///< Chained x86 SIMD kernels
119 SWS_BACKEND_AARCH64 = (1 << 4), ///< Chained AArch64 NEON kernels
120 SWS_BACKEND_SPIRV = (1 << 5), ///< Vulkan SPIR-V backend
126
128 SWS_BACKEND_MAX_ENUM = 0x7FFFFFFF, ///< force size to 32 bits, not a valid backend
129} SwsBackend;
130
131typedef enum SwsFlags {
132 /**
133 * Return an error on underspecified conversions. Without this flag,
134 * unspecified fields are defaulted to sensible values.
135 */
136 SWS_STRICT = 1 << 11,
137
138 /**
139 * Emit verbose log of scaling parameters.
140 */
141 SWS_PRINT_INFO = 1 << 12,
142
143 /**
144 * Perform full chroma upsampling when upscaling to RGB.
145 *
146 * For example, when converting 50x50 yuv420p to 100x100 rgba, setting this flag
147 * will scale the chroma plane from 25x25 to 100x100 (4:4:4), and then convert
148 * the 100x100 yuv444p image to rgba in the final output step.
149 *
150 * Without this flag, the chroma plane is instead scaled to 50x100 (4:2:2),
151 * with a single chroma sample being reused for both of the horizontally
152 * adjacent RGBA output pixels.
153 */
155
156 /**
157 * Perform full chroma interpolation when downscaling RGB sources.
158 *
159 * For example, when converting a 100x100 rgba source to 50x50 yuv444p, setting
160 * this flag will generate a 100x100 (4:4:4) chroma plane, which is then
161 * downscaled to the required 50x50.
162 *
163 * Without this flag, the chroma plane is instead generated at 50x100 (dropping
164 * every other pixel), before then being downscaled to the required 50x50
165 * resolution.
166 */
168
169 /**
170 * Force bit-exact output. This will prevent the use of platform-specific
171 * optimizations that may lead to slight difference in rounding, in favor
172 * of always maintaining exact bit output compatibility with the reference
173 * C code.
174 *
175 * Note: It is recommended to set both of these flags simultaneously.
176 */
178 SWS_BITEXACT = 1 << 19,
179
180 /**
181 * Allow/prefer using experimental new code paths. This may be faster,
182 * slower, or produce different output, with semantics subject to change
183 * at any point in time. For testing and debugging purposes only.
184 */
185 SWS_UNSTABLE = 1 << 20,
186
187 /**
188 * Deprecated flags.
189 */
190 SWS_DIRECT_BGR = 1 << 15, ///< This flag has no effect
191 SWS_ERROR_DIFFUSION = 1 << 23, ///< Set `SwsContext.dither` instead
192
193 /**
194 * Scaler selection options. Only one may be active at a time.
195 * Deprecated in favor of `SwsContext.scaler`.
196 */
197 SWS_FAST_BILINEAR = 1 << 0, ///< fast bilinear filtering
198 SWS_BILINEAR = 1 << 1, ///< bilinear filtering
199 SWS_BICUBIC = 1 << 2, ///< 2-tap cubic B-spline
200 SWS_X = 1 << 3, ///< experimental
201 SWS_POINT = 1 << 4, ///< nearest neighbor
202 SWS_AREA = 1 << 5, ///< area averaging
203 SWS_BICUBLIN = 1 << 6, ///< bicubic luma, bilinear chroma
204 SWS_GAUSS = 1 << 7, ///< gaussian approximation
205 SWS_SINC = 1 << 8, ///< unwindowed sinc
206 SWS_LANCZOS = 1 << 9, ///< 3-tap sinc/sinc
207 SWS_SPLINE = 1 << 10, ///< unwindowed natural cubic spline
208} SwsFlags;
209
210typedef enum SwsIntent {
211 SWS_INTENT_PERCEPTUAL = 0, ///< Perceptual tone mapping
212 SWS_INTENT_RELATIVE_COLORIMETRIC = 1, ///< Relative colorimetric clipping
213 SWS_INTENT_SATURATION = 2, ///< Saturation mapping
214 SWS_INTENT_ABSOLUTE_COLORIMETRIC = 3, ///< Absolute colorimetric clipping
215 SWS_INTENT_NB, ///< not part of the ABI
216} SwsIntent;
217
218/***********************************
219 * Context creation and management *
220 ***********************************/
221
222/**
223 * Main external API structure. New fields can be added to the end with
224 * minor version bumps. Removal, reordering and changes to existing fields
225 * require a major version bump. sizeof(SwsContext) is not part of the ABI.
226 */
227typedef struct SwsContext {
229
230 /**
231 * Private data of the user, can be used to carry app specific stuff.
232 */
233 void *opaque;
234
235 /**
236 * Bitmask of SWS_*. See `SwsFlags` for details.
237 */
238 unsigned flags;
239
240 /**
241 * Extra parameters for fine-tuning certain scalers.
242 */
243#define SWS_NUM_SCALER_PARAMS 2
245
246 /**
247 * How many threads to use for processing, or 0 for automatic selection.
248 */
250
251 /**
252 * Dither mode.
253 */
255
256 /**
257 * Alpha blending mode. See `SwsAlphaBlend` for details.
258 */
260
261 /**
262 * Use gamma correct scaling.
263 */
265
266 /**
267 * Deprecated frame property overrides, for the legacy API only.
268 *
269 * Ignored by sws_scale_frame() when used in dynamic mode, in which
270 * case all properties are instead taken from the frame directly.
271 */
272 int src_w, src_h; ///< Width and height of the source frame
273 int dst_w, dst_h; ///< Width and height of the destination frame
274 int src_format; ///< Source pixel format
275 int dst_format; ///< Destination pixel format
276 int src_range; ///< Source is full range
277 int dst_range; ///< Destination is full range
278 int src_v_chr_pos; ///< Source vertical chroma position in luma grid / 256
279 int src_h_chr_pos; ///< Source horizontal chroma position
280 int dst_v_chr_pos; ///< Destination vertical chroma position
281 int dst_h_chr_pos; ///< Destination horizontal chroma position
282
283 /**
284 * Desired ICC intent for color space conversions.
285 */
287
288 /**
289 * Scaling filter. If set to something other than SWS_SCALE_AUTO, this will
290 * override the filter implied by `SwsContext.flags`.
291 *
292 * Note: Does not affect the legacy (stateful) API.
293 */
295
296 /**
297 * Scaler used specifically for up/downsampling subsampled (chroma) planes.
298 * If set to something other than SWS_SCALE_AUTO, this will override the
299 * filter implied by `SwsContext.scaler`. Otherwise, the same filter
300 * will be used for both main scaling and chroma subsampling.
301 */
303
304 /**
305 * Bitmask of SWS_BACKEND_*. If non-zero, this will restrict the available
306 * backends to the specified set. If left as zero, a default set of
307 * backends will be selected automatically (based on SWS_UNSTABLE).
308 *
309 * Note: This is only relevant for the new API (sws_scale_frame()). The
310 * stateful legacy API always implies SWS_BACKEND_LEGACY.
311 */
313
314 /* Remember to add new fields to graph.c:opts_equal() */
315} SwsContext;
316
317/**
318 * Allocate an empty SwsContext and set its fields to default values.
319 */
321
322/**
323 * Free the context and everything associated with it, and write NULL
324 * to the provided pointer.
325 */
327
328/***************************
329 * Supported frame formats *
330 ***************************/
331
332/**
333 * Test if a given (software) pixel format is supported by any backend,
334 * excluding unstable backends.
335 *
336 * @param output If 0, test if compatible with the source/input frame;
337 * otherwise, with the destination/output frame.
338 * @param format The format to check.
339 *
340 * @return A positive integer if supported, 0 otherwise.
341 */
342int sws_test_format(enum AVPixelFormat format, int output);
343
344/**
345 * Test if a given hardware pixel format is supported by any backend,
346 * excluding unstable backends.
347 *
348 * @param format The hardware format to check, or AV_PIX_FMT_NONE.
349 *
350 * @return A positive integer if supported or AV_PIX_FMT_NONE, 0 otherwise.
351 */
353
354/**
355 * Test if a given color space is supported.
356 *
357 * @param output If 0, test if compatible with the source/input frame;
358 * otherwise, with the destination/output frame.
359 * @param colorspace The colorspace to check.
360 *
361 * @return A positive integer if supported, 0 otherwise.
362 */
363int sws_test_colorspace(enum AVColorSpace colorspace, int output);
364
365/**
366 * Test if a given set of color primaries is supported.
367 *
368 * @param output If 0, test if compatible with the source/input frame;
369 * otherwise, with the destination/output frame.
370 * @param primaries The color primaries to check.
371 *
372 * @return A positive integer if supported, 0 otherwise.
373 */
374int sws_test_primaries(enum AVColorPrimaries primaries, int output);
375
376/**
377 * Test if a given color transfer function is supported.
378 *
379 * @param output If 0, test if compatible with the source/input frame;
380 * otherwise, with the destination/output frame.
381 * @param trc The color transfer function to check.
382 *
383 * @return A positive integer if supported, 0 otherwise.
384 */
386
387/**
388 * Helper function to run all sws_test_* against a frame, as well as testing
389 * the basic frame properties for sanity. Ignores irrelevant properties - for
390 * example, AVColorSpace is not checked for RGB frames.
391 */
392int sws_test_frame(const AVFrame *frame, int output);
393
394/**
395 * Like `sws_scale_frame`, but without actually scaling. It will instead
396 * merely initialize internal state that *would* be required to perform the
397 * operation, as well as returning the correct error code for unsupported
398 * frame combinations.
399 *
400 * @param ctx The scaling context.
401 * @param dst The destination frame to consider.
402 * @param src The source frame to consider.
403 * @return 0 on success, a negative AVERROR code on failure.
404 */
405int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src);
406
407/********************
408 * Main scaling API *
409 ********************/
410
411/**
412 * Check if a given conversion is a noop. Returns a positive integer if
413 * no operation needs to be performed, 0 otherwise.
414 */
415int sws_is_noop(const AVFrame *dst, const AVFrame *src);
416
417/**
418 * Scale source data from `src` and write the output to `dst`.
419 *
420 * This function can be used directly on an allocated context, without setting
421 * up any frame properties or calling `sws_init_context()`. Such usage is fully
422 * dynamic and does not require reallocation if the frame properties change.
423 *
424 * Alternatively, this function can be called on a context that has been
425 * explicitly initialized. However, this is provided only for backwards
426 * compatibility. In this usage mode, all frame properties must be correctly
427 * set at init time, and may no longer change after initialization.
428 *
429 * @param ctx The scaling context.
430 * @param dst The destination frame. The data buffers may either be already
431 * allocated by the caller or left clear, in which case they will
432 * be allocated by the scaler. The latter may have performance
433 * advantages - e.g. in certain cases some (or all) output planes
434 * may be references to input planes, rather than copies.
435 * @param src The source frame. If the data buffers are set to NULL, then
436 * this function behaves identically to `sws_frame_setup`.
437 * @return >= 0 on success, a negative AVERROR code on failure.
438 */
439int sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src);
440
441/**
442 * Filter kernel cut-off value. Values below this (absolute) magnitude
443 * are cut off from the main filter kernel. Note that the window is
444 * always adjusted to the new filter radius, so there will never be
445 * any spectral leakage (for suitably windowed filters).
446 */
447#define SWS_MAX_REDUCE_CUTOFF 0.002
448
449/*************************
450 * Legacy (stateful) API *
451 *************************/
452
453#define SWS_SRC_V_CHR_DROP_MASK 0x30000
454#define SWS_SRC_V_CHR_DROP_SHIFT 16
455
456#define SWS_PARAM_DEFAULT 123456
457
458#define SWS_CS_ITU709 1
459#define SWS_CS_FCC 4
460#define SWS_CS_ITU601 5
461#define SWS_CS_ITU624 5
462#define SWS_CS_SMPTE170M 5
463#define SWS_CS_SMPTE240M 7
464#define SWS_CS_DEFAULT 5
465#define SWS_CS_BT2020 9
466
467/**
468 * Return a pointer to yuv<->rgb coefficients for the given colorspace
469 * suitable for sws_setColorspaceDetails().
470 *
471 * @param colorspace One of the SWS_CS_* macros. If invalid,
472 * SWS_CS_DEFAULT is used.
473 */
474const int *sws_getCoefficients(int colorspace);
475
476// when used for filters they must have an odd number of elements
477// coeffs cannot be shared between vectors
478typedef struct SwsVector {
479 double *coeff; ///< pointer to the list of coefficients
480 int length; ///< number of coefficients in the vector
481} SwsVector;
482
483// vectors can be shared
490
491/**
492 * Return a positive value if pix_fmt is a supported input format, 0
493 * otherwise.
494 */
496
497/**
498 * Return a positive value if pix_fmt is a supported output format, 0
499 * otherwise.
500 */
502
503/**
504 * @param[in] pix_fmt the pixel format
505 * @return a positive value if an endianness conversion for pix_fmt is
506 * supported, 0 otherwise.
507 */
509
510/**
511 * Initialize the swscaler context sws_context.
512 *
513 * This function is considered deprecated, and provided only for backwards
514 * compatibility with sws_scale() and sws_frame_start(). The preferred way to
515 * use libswscale is to set all frame properties correctly and call
516 * sws_scale_frame() directly, without explicitly initializing the context.
517 *
518 * @return zero or positive value on success, a negative value on
519 * error
520 */
522int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);
523
524/**
525 * Free the swscaler context swsContext.
526 * If swsContext is NULL, then does nothing.
527 */
528void sws_freeContext(SwsContext *swsContext);
529
530/**
531 * Allocate and return an SwsContext. You need it to perform
532 * scaling/conversion operations using sws_scale().
533 *
534 * @param srcW the width of the source image
535 * @param srcH the height of the source image
536 * @param srcFormat the source image format
537 * @param dstW the width of the destination image
538 * @param dstH the height of the destination image
539 * @param dstFormat the destination image format
540 * @param flags specify which algorithm and options to use for rescaling
541 * @param param extra parameters to tune the used scaler
542 * For SWS_BICUBIC param[0] and [1] tune the shape of the basis
543 * function, param[0] tunes f(1) and param[1] f´(1)
544 * For SWS_GAUSS param[0] tunes the exponent and thus cutoff
545 * frequency
546 * For SWS_LANCZOS param[0] tunes the width of the window function
547 * @return a pointer to an allocated context, or NULL in case of error
548 * @note this function is to be removed after a saner alternative is
549 * written
550 */
551SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,
552 int dstW, int dstH, enum AVPixelFormat dstFormat,
553 int flags, SwsFilter *srcFilter,
554 SwsFilter *dstFilter, const double *param);
555
556/**
557 * Scale the image slice in srcSlice and put the resulting scaled
558 * slice in the image in dst. A slice is a sequence of consecutive
559 * rows in an image. Requires a context that has previously been
560 * initialized with sws_init_context().
561 *
562 * Slices have to be provided in sequential order, either in
563 * top-bottom or bottom-top order. If slices are provided in
564 * non-sequential order the behavior of the function is undefined.
565 *
566 * @param c the scaling context previously created with
567 * sws_getContext()
568 * @param srcSlice the array containing the pointers to the planes of
569 * the source slice
570 * @param srcStride the array containing the strides for each plane of
571 * the source image
572 * @param srcSliceY the position in the source image of the slice to
573 * process, that is the number (counted starting from
574 * zero) in the image of the first row of the slice
575 * @param srcSliceH the height of the source slice, that is the number
576 * of rows in the slice
577 * @param dst the array containing the pointers to the planes of
578 * the destination image
579 * @param dstStride the array containing the strides for each plane of
580 * the destination image
581 * @return the height of the output slice
582 */
583int sws_scale(SwsContext *c, const uint8_t *const srcSlice[],
584 const int srcStride[], int srcSliceY, int srcSliceH,
585 uint8_t *const dst[], const int dstStride[]);
586
587/**
588 * Initialize the scaling process for a given pair of source/destination frames.
589 * Must be called before any calls to sws_send_slice() and sws_receive_slice().
590 * Requires a context that has previously been initialized with sws_init_context().
591 *
592 * This function will retain references to src and dst, so they must both use
593 * refcounted buffers (if allocated by the caller, in case of dst).
594 *
595 * @param c The scaling context
596 * @param dst The destination frame.
597 *
598 * The data buffers may either be already allocated by the caller or
599 * left clear, in which case they will be allocated by the scaler.
600 * The latter may have performance advantages - e.g. in certain cases
601 * some output planes may be references to input planes, rather than
602 * copies.
603 *
604 * Output data will be written into this frame in successful
605 * sws_receive_slice() calls.
606 * @param src The source frame. The data buffers must be allocated, but the
607 * frame data does not have to be ready at this point. Data
608 * availability is then signalled by sws_send_slice().
609 * @return 0 on success, a negative AVERROR code on failure
610 *
611 * @see sws_frame_end()
612 */
613int sws_frame_start(SwsContext *c, AVFrame *dst, const AVFrame *src);
614
615/**
616 * Finish the scaling process for a pair of source/destination frames previously
617 * submitted with sws_frame_start(). Must be called after all sws_send_slice()
618 * and sws_receive_slice() calls are done, before any new sws_frame_start()
619 * calls.
620 *
621 * @param c The scaling context
622 */
624
625/**
626 * Indicate that a horizontal slice of input data is available in the source
627 * frame previously provided to sws_frame_start(). The slices may be provided in
628 * any order, but may not overlap. For vertically subsampled pixel formats, the
629 * slices must be aligned according to subsampling.
630 *
631 * @param c The scaling context
632 * @param slice_start first row of the slice
633 * @param slice_height number of rows in the slice
634 *
635 * @return a non-negative number on success, a negative AVERROR code on failure.
636 */
637int sws_send_slice(SwsContext *c, unsigned int slice_start,
638 unsigned int slice_height);
639
640/**
641 * Request a horizontal slice of the output data to be written into the frame
642 * previously provided to sws_frame_start().
643 *
644 * @param c The scaling context
645 * @param slice_start first row of the slice; must be a multiple of
646 * sws_receive_slice_alignment()
647 * @param slice_height number of rows in the slice; must be a multiple of
648 * sws_receive_slice_alignment(), except for the last slice
649 * (i.e. when slice_start+slice_height is equal to output
650 * frame height)
651 *
652 * @return a non-negative number if the data was successfully written into the output
653 * AVERROR(EAGAIN) if more input data needs to be provided before the
654 * output can be produced
655 * another negative AVERROR code on other kinds of scaling failure
656 */
657int sws_receive_slice(SwsContext *c, unsigned int slice_start,
658 unsigned int slice_height);
659
660/**
661 * Get the alignment required for slices. Requires a context that has
662 * previously been initialized with sws_init_context().
663 *
664 * @param c The scaling context
665 * @return alignment required for output slices requested with sws_receive_slice().
666 * Slice offsets and sizes passed to sws_receive_slice() must be
667 * multiples of the value returned from this function.
668 */
670
671/**
672 * @param c the scaling context
673 * @param dstRange flag indicating the white-black range of the output (1=jpeg / 0=mpeg)
674 * @param srcRange flag indicating the white-black range of the input (1=jpeg / 0=mpeg)
675 * @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x]
676 * @param inv_table the yuv2rgb coefficients describing the input yuv space, normally ff_yuv2rgb_coeffs[x]
677 * @param brightness 16.16 fixed point brightness correction
678 * @param contrast 16.16 fixed point contrast correction
679 * @param saturation 16.16 fixed point saturation correction
680 *
681 * @return A negative error code on error, non negative otherwise.
682 * If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported.
683 */
684int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4],
685 int srcRange, const int table[4], int dstRange,
686 int brightness, int contrast, int saturation);
687
688/**
689 * @return A negative error code on error, non negative otherwise.
690 * If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported.
691 */
692int sws_getColorspaceDetails(SwsContext *c, int **inv_table,
693 int *srcRange, int **table, int *dstRange,
694 int *brightness, int *contrast, int *saturation);
695
696/**
697 * Allocate and return an uninitialized vector with length coefficients.
698 */
700
701/**
702 * Return a normalized Gaussian curve used to filter stuff
703 * quality = 3 is high quality, lower is lower quality.
704 */
705SwsVector *sws_getGaussianVec(double variance, double quality);
706
707/**
708 * Scale all the coefficients of a by the scalar value.
709 */
710void sws_scaleVec(SwsVector *a, double scalar);
711
712/**
713 * Scale all the coefficients of a so that their sum equals height.
714 */
716
718
719SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
720 float lumaSharpen, float chromaSharpen,
721 float chromaHShift, float chromaVShift,
722 int verbose);
724
725/**
726 * Check if context can be reused, otherwise reallocate a new one.
727 *
728 * If context is NULL, just calls sws_getContext() to get a new
729 * context. Otherwise, checks if the parameters are the ones already
730 * saved in context. If that is the case, returns the current
731 * context. Otherwise, frees context and gets a new context with
732 * the new parameters.
733 *
734 * Be warned that srcFilter and dstFilter are not checked, they
735 * are assumed to remain the same.
736 */
737SwsContext *sws_getCachedContext(SwsContext *context, int srcW, int srcH,
738 enum AVPixelFormat srcFormat, int dstW, int dstH,
739 enum AVPixelFormat dstFormat, int flags,
740 SwsFilter *srcFilter, SwsFilter *dstFilter,
741 const double *param);
742
743/**
744 * Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
745 *
746 * The output frame will have the same packed format as the palette.
747 *
748 * @param src source frame buffer
749 * @param dst destination frame buffer
750 * @param num_pixels number of pixels to convert
751 * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
752 */
753void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
754
755/**
756 * Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.
757 *
758 * With the palette format "ABCD", the destination frame ends up with the format "ABC".
759 *
760 * @param src source frame buffer
761 * @param dst destination frame buffer
762 * @param num_pixels number of pixels to convert
763 * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
764 */
765void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
766
767/**
768 * @}
769 */
770
771#endif /* SWSCALE_SWSCALE_H */
#define av_warn_unused_result
Definition attributes.h:91
Convenience header that includes libavutil's core.
static enum AVPixelFormat pix_fmt
static int height
static AVFrame * frame
reference-counted frame API
int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output)
Test if a given color transfer function is supported.
int sws_test_hw_format(enum AVPixelFormat format)
Test if a given hardware pixel format is supported by any backend, excluding unstable backends.
void sws_freeFilter(SwsFilter *filter)
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...
int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
int sws_test_colorspace(enum AVColorSpace colorspace, int output)
Test if a given color space is supported.
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.
int sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
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...
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.
int sws_test_primaries(enum AVColorPrimaries primaries, int output)
Test if a given set of color primaries is supported.
int sws_is_noop(const AVFrame *dst, const AVFrame *src)
Check if a given conversion is a noop.
void sws_freeVec(SwsVector *a)
const char * swscale_license(void)
Return the libswscale license.
SwsFilter * sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, float lumaSharpen, float chromaSharpen, float chromaHShift, float chromaVShift, int verbose)
int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt)
int sws_isSupportedOutput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported output format, 0 otherwise.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
unsigned int sws_receive_slice_alignment(const SwsContext *c)
Get the alignment required for slices.
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
SwsIntent
Definition swscale.h:210
SwsDither
Definition swscale.h:77
SwsVector * sws_allocVec(int length)
Allocate and return an uninitialized vector with length coefficients.
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality,...
SwsAlphaBlend
Definition swscale.h:88
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
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.
const AVClass * sws_get_class(void)
Get the AVClass for SwsContext.
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.
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 ...
SwsBackend
Definition swscale.h:110
const char * swscale_configuration(void)
Return the libswscale build-time configuration.
void sws_normalizeVec(SwsVector *a, double height)
Scale all the coefficients of a so that their sum equals height.
int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported input format, 0 otherwise.
int sws_test_format(enum AVPixelFormat format, int output)
Test if a given (software) pixel format is supported by any backend, excluding unstable backends.
int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src)
Like sws_scale_frame, but without actually scaling.
unsigned swscale_version(void)
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.
void sws_frame_end(SwsContext *c)
Finish the scaling process for a pair of source/destination frames previously submitted with sws_fram...
SwsScaler
Definition swscale.h:96
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
SwsFlags
Definition swscale.h:131
int sws_frame_start(SwsContext *c, AVFrame *dst, const AVFrame *src)
Initialize the scaling process for a given pair of source/destination frames.
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
@ SWS_INTENT_PERCEPTUAL
Perceptual tone mapping.
Definition swscale.h:211
@ SWS_INTENT_ABSOLUTE_COLORIMETRIC
Absolute colorimetric clipping.
Definition swscale.h:214
@ SWS_INTENT_RELATIVE_COLORIMETRIC
Relative colorimetric clipping.
Definition swscale.h:212
@ SWS_INTENT_SATURATION
Saturation mapping.
Definition swscale.h:213
@ SWS_INTENT_NB
not part of the ABI
Definition swscale.h:215
@ SWS_DITHER_NB
Definition swscale.h:84
@ SWS_DITHER_ED
Definition swscale.h:81
@ SWS_DITHER_A_DITHER
Definition swscale.h:82
@ SWS_DITHER_X_DITHER
Definition swscale.h:83
@ SWS_DITHER_AUTO
Definition swscale.h:79
@ SWS_DITHER_BAYER
Definition swscale.h:80
@ SWS_DITHER_MAX_ENUM
Definition swscale.h:85
@ SWS_DITHER_NONE
Definition swscale.h:78
@ SWS_ALPHA_BLEND_UNIFORM
Definition swscale.h:90
@ SWS_ALPHA_BLEND_MAX_ENUM
Definition swscale.h:93
@ SWS_ALPHA_BLEND_NB
Definition swscale.h:92
@ SWS_ALPHA_BLEND_CHECKERBOARD
Definition swscale.h:91
@ SWS_ALPHA_BLEND_NONE
Definition swscale.h:89
@ SWS_BACKEND_UNSTABLE
Definition swscale.h:121
@ SWS_BACKEND_LEGACY
Legacy bespoke format-specific code.
Definition swscale.h:112
@ SWS_BACKEND_MEMCPY
Fast path using libc memcpy() / memset().
Definition swscale.h:117
@ SWS_BACKEND_AARCH64
Chained AArch64 NEON kernels.
Definition swscale.h:119
@ SWS_BACKEND_X86
Chained x86 SIMD kernels.
Definition swscale.h:118
@ SWS_BACKEND_C
Template-based C reference implementation.
Definition swscale.h:116
@ SWS_BACKEND_STABLE
Definition swscale.h:113
@ SWS_BACKEND_MAX_ENUM
force size to 32 bits, not a valid backend
Definition swscale.h:128
@ SWS_BACKEND_ALL
Definition swscale.h:127
@ SWS_BACKEND_SPIRV
Vulkan SPIR-V backend.
Definition swscale.h:120
@ SWS_SCALE_SPLINE
unwindowned natural cubic spline
Definition swscale.h:105
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
Definition swscale.h:100
@ SWS_SCALE_NB
not part of the ABI
Definition swscale.h:106
@ SWS_SCALE_LANCZOS
3-tap sinc/sinc
Definition swscale.h:104
@ SWS_SCALE_BILINEAR
bilinear filtering
Definition swscale.h:98
@ SWS_SCALE_GAUSSIAN
2-tap gaussian approximation
Definition swscale.h:102
@ SWS_SCALE_BICUBIC
2-tap cubic BC-spline
Definition swscale.h:99
@ SWS_SCALE_AREA
area averaging
Definition swscale.h:101
@ SWS_SCALE_SINC
unwindowed sinc
Definition swscale.h:103
@ SWS_SCALE_AUTO
Definition swscale.h:97
@ SWS_SCALE_MAX_ENUM
force size to 32 bits, not a valid filter type
Definition swscale.h:107
@ SWS_PRINT_INFO
Emit verbose log of scaling parameters.
Definition swscale.h:141
@ SWS_SPLINE
unwindowed natural cubic spline
Definition swscale.h:207
@ SWS_BICUBIC
2-tap cubic B-spline
Definition swscale.h:199
@ SWS_BITEXACT
Definition swscale.h:178
@ SWS_STRICT
Return an error on underspecified conversions.
Definition swscale.h:136
@ SWS_AREA
area averaging
Definition swscale.h:202
@ SWS_BICUBLIN
bicubic luma, bilinear chroma
Definition swscale.h:203
@ SWS_ERROR_DIFFUSION
Set SwsContext.dither instead.
Definition swscale.h:191
@ SWS_BILINEAR
bilinear filtering
Definition swscale.h:198
@ SWS_UNSTABLE
Allow/prefer using experimental new code paths.
Definition swscale.h:185
@ SWS_FULL_CHR_H_INP
Perform full chroma interpolation when downscaling RGB sources.
Definition swscale.h:167
@ SWS_SINC
unwindowed sinc
Definition swscale.h:205
@ SWS_LANCZOS
3-tap sinc/sinc
Definition swscale.h:206
@ SWS_DIRECT_BGR
Deprecated flags.
Definition swscale.h:190
@ SWS_GAUSS
gaussian approximation
Definition swscale.h:204
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition swscale.h:197
@ SWS_ACCURATE_RND
Force bit-exact output.
Definition swscale.h:177
@ SWS_X
experimental
Definition swscale.h:200
@ SWS_POINT
nearest neighbor
Definition swscale.h:201
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition swscale.h:154
swscale version macros
swscale version macros
pixel format definitions
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:636
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:666
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:700
Describe the class of an AVClass context structure.
Definition log.h:76
This structure describes decoded (raw) audio or video data.
Definition frame.h:466
Main external API structure.
Definition swscale.h:227
int src_h
Width and height of the source frame.
Definition swscale.h:272
int dst_format
Destination pixel format.
Definition swscale.h:275
int intent
Desired ICC intent for color space conversions.
Definition swscale.h:286
int gamma_flag
Use gamma correct scaling.
Definition swscale.h:264
int threads
How many threads to use for processing, or 0 for automatic selection.
Definition swscale.h:249
SwsScaler scaler
Scaling filter.
Definition swscale.h:294
const AVClass * av_class
Definition swscale.h:228
int dst_h
Width and height of the destination frame.
Definition swscale.h:273
SwsAlphaBlend alpha_blend
Alpha blending mode.
Definition swscale.h:259
double scaler_params[SWS_NUM_SCALER_PARAMS]
Definition swscale.h:244
int dst_w
Definition swscale.h:273
SwsBackend backends
Bitmask of SWS_BACKEND_*.
Definition swscale.h:312
int dst_h_chr_pos
Destination horizontal chroma position.
Definition swscale.h:281
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition swscale.h:233
SwsScaler scaler_sub
Scaler used specifically for up/downsampling subsampled (chroma) planes.
Definition swscale.h:302
int src_w
Deprecated frame property overrides, for the legacy API only.
Definition swscale.h:272
int src_format
Source pixel format.
Definition swscale.h:274
int src_v_chr_pos
Source vertical chroma position in luma grid / 256.
Definition swscale.h:278
int dst_v_chr_pos
Destination vertical chroma position.
Definition swscale.h:280
SwsDither dither
Dither mode.
Definition swscale.h:254
int dst_range
Destination is full range.
Definition swscale.h:277
unsigned flags
Bitmask of SWS_*.
Definition swscale.h:238
int src_range
Source is full range.
Definition swscale.h:276
int src_h_chr_pos
Source horizontal chroma position.
Definition swscale.h:279
SwsVector * chrV
Definition swscale.h:488
SwsVector * lumH
Definition swscale.h:485
SwsVector * lumV
Definition swscale.h:486
SwsVector * chrH
Definition swscale.h:487
double * coeff
pointer to the list of coefficients
Definition swscale.h:479
int length
number of coefficients in the vector
Definition swscale.h:480
#define SWS_NUM_SCALER_PARAMS
Extra parameters for fine-tuning certain scalers.
Definition swscale.h:243