swscale.h 24 KB

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