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