Path: blob/master/dep/ffmpeg/include/libswscale/swscale.h
4216 views
/*1* Copyright (C) 2001-2011 Michael Niedermayer <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#ifndef SWSCALE_SWSCALE_H21#define SWSCALE_SWSCALE_H2223/**24* @file25* @ingroup libsws26* external API header27*/2829#include <stdint.h>3031#include "libavutil/avutil.h"32#include "libavutil/frame.h"33#include "libavutil/log.h"34#include "libavutil/pixfmt.h"35#include "version_major.h"36#ifndef HAVE_AV_CONFIG_H37/* When included as part of the ffmpeg build, only include the major version38* to avoid unnecessary rebuilds. When included externally, keep including39* the full version information. */40#include "version.h"41#endif4243/**44* @defgroup libsws libswscale45* Color conversion and scaling library.46*47* @{48*49* Return the LIBSWSCALE_VERSION_INT constant.50*/51unsigned swscale_version(void);5253/**54* Return the libswscale build-time configuration.55*/56const char *swscale_configuration(void);5758/**59* Return the libswscale license.60*/61const char *swscale_license(void);6263/* values for the flags, the stuff on the command line is different */64#define SWS_FAST_BILINEAR 165#define SWS_BILINEAR 266#define SWS_BICUBIC 467#define SWS_X 868#define SWS_POINT 0x1069#define SWS_AREA 0x2070#define SWS_BICUBLIN 0x4071#define SWS_GAUSS 0x8072#define SWS_SINC 0x10073#define SWS_LANCZOS 0x20074#define SWS_SPLINE 0x4007576#define SWS_SRC_V_CHR_DROP_MASK 0x3000077#define SWS_SRC_V_CHR_DROP_SHIFT 167879#define SWS_PARAM_DEFAULT 1234568081#define SWS_PRINT_INFO 0x10008283//the following 3 flags are not completely implemented8485/**86* Perform full chroma upsampling when upscaling to RGB.87*88* For example, when converting 50x50 yuv420p to 100x100 rgba, setting this flag89* will scale the chroma plane from 25x25 to 100x100 (4:4:4), and then convert90* the 100x100 yuv444p image to rgba in the final output step.91*92* Without this flag, the chroma plane is instead scaled to 50x100 (4:2:2),93* with a single chroma sample being re-used for both of the horizontally94* adjacent RGBA output pixels.95*/96#define SWS_FULL_CHR_H_INT 0x20009798/**99* Perform full chroma interpolation when downscaling RGB sources.100*101* For example, when converting a 100x100 rgba source to 50x50 yuv444p, setting102* this flag will generate a 100x100 (4:4:4) chroma plane, which is then103* downscaled to the required 50x50.104*105* Without this flag, the chroma plane is instead generated at 50x100 (dropping106* every other pixel), before then being downscaled to the required 50x50107* resolution.108*/109#define SWS_FULL_CHR_H_INP 0x4000110111#define SWS_DIRECT_BGR 0x8000112113#define SWS_ACCURATE_RND 0x40000114#define SWS_BITEXACT 0x80000115#define SWS_ERROR_DIFFUSION 0x800000116117#define SWS_MAX_REDUCE_CUTOFF 0.002118119#define SWS_CS_ITU709 1120#define SWS_CS_FCC 4121#define SWS_CS_ITU601 5122#define SWS_CS_ITU624 5123#define SWS_CS_SMPTE170M 5124#define SWS_CS_SMPTE240M 7125#define SWS_CS_DEFAULT 5126#define SWS_CS_BT2020 9127128/**129* Return a pointer to yuv<->rgb coefficients for the given colorspace130* suitable for sws_setColorspaceDetails().131*132* @param colorspace One of the SWS_CS_* macros. If invalid,133* SWS_CS_DEFAULT is used.134*/135const int *sws_getCoefficients(int colorspace);136137// when used for filters they must have an odd number of elements138// coeffs cannot be shared between vectors139typedef struct SwsVector {140double *coeff; ///< pointer to the list of coefficients141int length; ///< number of coefficients in the vector142} SwsVector;143144// vectors can be shared145typedef struct SwsFilter {146SwsVector *lumH;147SwsVector *lumV;148SwsVector *chrH;149SwsVector *chrV;150} SwsFilter;151152struct SwsContext;153154/**155* Return a positive value if pix_fmt is a supported input format, 0156* otherwise.157*/158int sws_isSupportedInput(enum AVPixelFormat pix_fmt);159160/**161* Return a positive value if pix_fmt is a supported output format, 0162* otherwise.163*/164int sws_isSupportedOutput(enum AVPixelFormat pix_fmt);165166/**167* @param[in] pix_fmt the pixel format168* @return a positive value if an endianness conversion for pix_fmt is169* supported, 0 otherwise.170*/171int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt);172173/**174* Allocate an empty SwsContext. This must be filled and passed to175* sws_init_context(). For filling see AVOptions, options.c and176* sws_setColorspaceDetails().177*/178struct SwsContext *sws_alloc_context(void);179180/**181* Initialize the swscaler context sws_context.182*183* @return zero or positive value on success, a negative value on184* error185*/186av_warn_unused_result187int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);188189/**190* Free the swscaler context swsContext.191* If swsContext is NULL, then does nothing.192*/193void sws_freeContext(struct SwsContext *swsContext);194195/**196* Allocate and return an SwsContext. You need it to perform197* scaling/conversion operations using sws_scale().198*199* @param srcW the width of the source image200* @param srcH the height of the source image201* @param srcFormat the source image format202* @param dstW the width of the destination image203* @param dstH the height of the destination image204* @param dstFormat the destination image format205* @param flags specify which algorithm and options to use for rescaling206* @param param extra parameters to tune the used scaler207* For SWS_BICUBIC param[0] and [1] tune the shape of the basis208* function, param[0] tunes f(1) and param[1] f´(1)209* For SWS_GAUSS param[0] tunes the exponent and thus cutoff210* frequency211* For SWS_LANCZOS param[0] tunes the width of the window function212* @return a pointer to an allocated context, or NULL in case of error213* @note this function is to be removed after a saner alternative is214* written215*/216struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,217int dstW, int dstH, enum AVPixelFormat dstFormat,218int flags, SwsFilter *srcFilter,219SwsFilter *dstFilter, const double *param);220221/**222* Scale the image slice in srcSlice and put the resulting scaled223* slice in the image in dst. A slice is a sequence of consecutive224* rows in an image.225*226* Slices have to be provided in sequential order, either in227* top-bottom or bottom-top order. If slices are provided in228* non-sequential order the behavior of the function is undefined.229*230* @param c the scaling context previously created with231* sws_getContext()232* @param srcSlice the array containing the pointers to the planes of233* the source slice234* @param srcStride the array containing the strides for each plane of235* the source image236* @param srcSliceY the position in the source image of the slice to237* process, that is the number (counted starting from238* zero) in the image of the first row of the slice239* @param srcSliceH the height of the source slice, that is the number240* of rows in the slice241* @param dst the array containing the pointers to the planes of242* the destination image243* @param dstStride the array containing the strides for each plane of244* the destination image245* @return the height of the output slice246*/247int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],248const int srcStride[], int srcSliceY, int srcSliceH,249uint8_t *const dst[], const int dstStride[]);250251/**252* Scale source data from src and write the output to dst.253*254* This is merely a convenience wrapper around255* - sws_frame_start()256* - sws_send_slice(0, src->height)257* - sws_receive_slice(0, dst->height)258* - sws_frame_end()259*260* @param c The scaling context261* @param dst The destination frame. See documentation for sws_frame_start() for262* more details.263* @param src The source frame.264*265* @return 0 on success, a negative AVERROR code on failure266*/267int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src);268269/**270* Initialize the scaling process for a given pair of source/destination frames.271* Must be called before any calls to sws_send_slice() and sws_receive_slice().272*273* This function will retain references to src and dst, so they must both use274* refcounted buffers (if allocated by the caller, in case of dst).275*276* @param c The scaling context277* @param dst The destination frame.278*279* The data buffers may either be already allocated by the caller or280* left clear, in which case they will be allocated by the scaler.281* The latter may have performance advantages - e.g. in certain cases282* some output planes may be references to input planes, rather than283* copies.284*285* Output data will be written into this frame in successful286* sws_receive_slice() calls.287* @param src The source frame. The data buffers must be allocated, but the288* frame data does not have to be ready at this point. Data289* availability is then signalled by sws_send_slice().290* @return 0 on success, a negative AVERROR code on failure291*292* @see sws_frame_end()293*/294int sws_frame_start(struct SwsContext *c, AVFrame *dst, const AVFrame *src);295296/**297* Finish the scaling process for a pair of source/destination frames previously298* submitted with sws_frame_start(). Must be called after all sws_send_slice()299* and sws_receive_slice() calls are done, before any new sws_frame_start()300* calls.301*302* @param c The scaling context303*/304void sws_frame_end(struct SwsContext *c);305306/**307* Indicate that a horizontal slice of input data is available in the source308* frame previously provided to sws_frame_start(). The slices may be provided in309* any order, but may not overlap. For vertically subsampled pixel formats, the310* slices must be aligned according to subsampling.311*312* @param c The scaling context313* @param slice_start first row of the slice314* @param slice_height number of rows in the slice315*316* @return a non-negative number on success, a negative AVERROR code on failure.317*/318int sws_send_slice(struct SwsContext *c, unsigned int slice_start,319unsigned int slice_height);320321/**322* Request a horizontal slice of the output data to be written into the frame323* previously provided to sws_frame_start().324*325* @param c The scaling context326* @param slice_start first row of the slice; must be a multiple of327* sws_receive_slice_alignment()328* @param slice_height number of rows in the slice; must be a multiple of329* sws_receive_slice_alignment(), except for the last slice330* (i.e. when slice_start+slice_height is equal to output331* frame height)332*333* @return a non-negative number if the data was successfully written into the output334* AVERROR(EAGAIN) if more input data needs to be provided before the335* output can be produced336* another negative AVERROR code on other kinds of scaling failure337*/338int sws_receive_slice(struct SwsContext *c, unsigned int slice_start,339unsigned int slice_height);340341/**342* Get the alignment required for slices343*344* @param c The scaling context345* @return alignment required for output slices requested with sws_receive_slice().346* Slice offsets and sizes passed to sws_receive_slice() must be347* multiples of the value returned from this function.348*/349unsigned int sws_receive_slice_alignment(const struct SwsContext *c);350351/**352* @param c the scaling context353* @param dstRange flag indicating the while-black range of the output (1=jpeg / 0=mpeg)354* @param srcRange flag indicating the while-black range of the input (1=jpeg / 0=mpeg)355* @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x]356* @param inv_table the yuv2rgb coefficients describing the input yuv space, normally ff_yuv2rgb_coeffs[x]357* @param brightness 16.16 fixed point brightness correction358* @param contrast 16.16 fixed point contrast correction359* @param saturation 16.16 fixed point saturation correction360*361* @return A negative error code on error, non negative otherwise.362* If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported.363*/364int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],365int srcRange, const int table[4], int dstRange,366int brightness, int contrast, int saturation);367368/**369* @return A negative error code on error, non negative otherwise.370* If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported.371*/372int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,373int *srcRange, int **table, int *dstRange,374int *brightness, int *contrast, int *saturation);375376/**377* Allocate and return an uninitialized vector with length coefficients.378*/379SwsVector *sws_allocVec(int length);380381/**382* Return a normalized Gaussian curve used to filter stuff383* quality = 3 is high quality, lower is lower quality.384*/385SwsVector *sws_getGaussianVec(double variance, double quality);386387/**388* Scale all the coefficients of a by the scalar value.389*/390void sws_scaleVec(SwsVector *a, double scalar);391392/**393* Scale all the coefficients of a so that their sum equals height.394*/395void sws_normalizeVec(SwsVector *a, double height);396397void sws_freeVec(SwsVector *a);398399SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,400float lumaSharpen, float chromaSharpen,401float chromaHShift, float chromaVShift,402int verbose);403void sws_freeFilter(SwsFilter *filter);404405/**406* Check if context can be reused, otherwise reallocate a new one.407*408* If context is NULL, just calls sws_getContext() to get a new409* context. Otherwise, checks if the parameters are the ones already410* saved in context. If that is the case, returns the current411* context. Otherwise, frees context and gets a new context with412* the new parameters.413*414* Be warned that srcFilter and dstFilter are not checked, they415* are assumed to remain the same.416*/417struct SwsContext *sws_getCachedContext(struct SwsContext *context,418int srcW, int srcH, enum AVPixelFormat srcFormat,419int dstW, int dstH, enum AVPixelFormat dstFormat,420int flags, SwsFilter *srcFilter,421SwsFilter *dstFilter, const double *param);422423/**424* Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.425*426* The output frame will have the same packed format as the palette.427*428* @param src source frame buffer429* @param dst destination frame buffer430* @param num_pixels number of pixels to convert431* @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src432*/433void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);434435/**436* Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.437*438* With the palette format "ABCD", the destination frame ends up with the format "ABC".439*440* @param src source frame buffer441* @param dst destination frame buffer442* @param num_pixels number of pixels to convert443* @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src444*/445void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);446447/**448* Get the AVClass for swsContext. It can be used in combination with449* AV_OPT_SEARCH_FAKE_OBJ for examining options.450*451* @see av_opt_find().452*/453const AVClass *sws_get_class(void);454455/**456* @}457*/458459#endif /* SWSCALE_SWSCALE_H */460461462