/*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/log.h"33#include "libavutil/pixfmt.h"34#include "version.h"3536/**37* @defgroup libsws Color conversion and scaling38* @{39*40* Return the LIBSWSCALE_VERSION_INT constant.41*/42unsigned swscale_version(void);4344/**45* Return the libswscale build-time configuration.46*/47const char *swscale_configuration(void);4849/**50* Return the libswscale license.51*/52const char *swscale_license(void);5354/* values for the flags, the stuff on the command line is different */55#define SWS_FAST_BILINEAR 156#define SWS_BILINEAR 257#define SWS_BICUBIC 458#define SWS_X 859#define SWS_POINT 0x1060#define SWS_AREA 0x2061#define SWS_BICUBLIN 0x4062#define SWS_GAUSS 0x8063#define SWS_SINC 0x10064#define SWS_LANCZOS 0x20065#define SWS_SPLINE 0x4006667#define SWS_SRC_V_CHR_DROP_MASK 0x3000068#define SWS_SRC_V_CHR_DROP_SHIFT 166970#define SWS_PARAM_DEFAULT 1234567172#define SWS_PRINT_INFO 0x10007374//the following 3 flags are not completely implemented75//internal chrominace subsampling info76#define SWS_FULL_CHR_H_INT 0x200077//input subsampling info78#define SWS_FULL_CHR_H_INP 0x400079#define SWS_DIRECT_BGR 0x800080#define SWS_ACCURATE_RND 0x4000081#define SWS_BITEXACT 0x8000082#define SWS_ERROR_DIFFUSION 0x8000008384#define SWS_MAX_REDUCE_CUTOFF 0.0028586#define SWS_CS_ITU709 187#define SWS_CS_FCC 488#define SWS_CS_ITU601 589#define SWS_CS_ITU624 590#define SWS_CS_SMPTE170M 591#define SWS_CS_SMPTE240M 792#define SWS_CS_DEFAULT 59394/**95* Return a pointer to yuv<->rgb coefficients for the given colorspace96* suitable for sws_setColorspaceDetails().97*98* @param colorspace One of the SWS_CS_* macros. If invalid,99* SWS_CS_DEFAULT is used.100*/101const int *sws_getCoefficients(int colorspace);102103// when used for filters they must have an odd number of elements104// coeffs cannot be shared between vectors105typedef struct SwsVector {106double *coeff; ///< pointer to the list of coefficients107int length; ///< number of coefficients in the vector108} SwsVector;109110// vectors can be shared111typedef struct SwsFilter {112SwsVector *lumH;113SwsVector *lumV;114SwsVector *chrH;115SwsVector *chrV;116} SwsFilter;117118struct SwsContext;119120/**121* Return a positive value if pix_fmt is a supported input format, 0122* otherwise.123*/124int sws_isSupportedInput(enum AVPixelFormat pix_fmt);125126/**127* Return a positive value if pix_fmt is a supported output format, 0128* otherwise.129*/130int sws_isSupportedOutput(enum AVPixelFormat pix_fmt);131132/**133* @param[in] pix_fmt the pixel format134* @return a positive value if an endianness conversion for pix_fmt is135* supported, 0 otherwise.136*/137int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt);138139/**140* Allocate an empty SwsContext. This must be filled and passed to141* sws_init_context(). For filling see AVOptions, options.c and142* sws_setColorspaceDetails().143*/144struct SwsContext *sws_alloc_context(void);145146/**147* Initialize the swscaler context sws_context.148*149* @return zero or positive value on success, a negative value on150* error151*/152av_warn_unused_result153int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);154155/**156* Free the swscaler context swsContext.157* If swsContext is NULL, then does nothing.158*/159void sws_freeContext(struct SwsContext *swsContext);160161/**162* Allocate and return an SwsContext. You need it to perform163* scaling/conversion operations using sws_scale().164*165* @param srcW the width of the source image166* @param srcH the height of the source image167* @param srcFormat the source image format168* @param dstW the width of the destination image169* @param dstH the height of the destination image170* @param dstFormat the destination image format171* @param flags specify which algorithm and options to use for rescaling172* @param param extra parameters to tune the used scaler173* For SWS_BICUBIC param[0] and [1] tune the shape of the basis174* function, param[0] tunes f(1) and param[1] f´(1)175* For SWS_GAUSS param[0] tunes the exponent and thus cutoff176* frequency177* For SWS_LANCZOS param[0] tunes the width of the window function178* @return a pointer to an allocated context, or NULL in case of error179* @note this function is to be removed after a saner alternative is180* written181*/182struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,183int dstW, int dstH, enum AVPixelFormat dstFormat,184int flags, SwsFilter *srcFilter,185SwsFilter *dstFilter, const double *param);186187/**188* Scale the image slice in srcSlice and put the resulting scaled189* slice in the image in dst. A slice is a sequence of consecutive190* rows in an image.191*192* Slices have to be provided in sequential order, either in193* top-bottom or bottom-top order. If slices are provided in194* non-sequential order the behavior of the function is undefined.195*196* @param c the scaling context previously created with197* sws_getContext()198* @param srcSlice the array containing the pointers to the planes of199* the source slice200* @param srcStride the array containing the strides for each plane of201* the source image202* @param srcSliceY the position in the source image of the slice to203* process, that is the number (counted starting from204* zero) in the image of the first row of the slice205* @param srcSliceH the height of the source slice, that is the number206* of rows in the slice207* @param dst the array containing the pointers to the planes of208* the destination image209* @param dstStride the array containing the strides for each plane of210* the destination image211* @return the height of the output slice212*/213int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],214const int srcStride[], int srcSliceY, int srcSliceH,215uint8_t *const dst[], const int dstStride[]);216217/**218* @param dstRange flag indicating the while-black range of the output (1=jpeg / 0=mpeg)219* @param srcRange flag indicating the while-black range of the input (1=jpeg / 0=mpeg)220* @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x]221* @param inv_table the yuv2rgb coefficients describing the input yuv space, normally ff_yuv2rgb_coeffs[x]222* @param brightness 16.16 fixed point brightness correction223* @param contrast 16.16 fixed point contrast correction224* @param saturation 16.16 fixed point saturation correction225* @return -1 if not supported226*/227int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],228int srcRange, const int table[4], int dstRange,229int brightness, int contrast, int saturation);230231/**232* @return -1 if not supported233*/234int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,235int *srcRange, int **table, int *dstRange,236int *brightness, int *contrast, int *saturation);237238/**239* Allocate and return an uninitialized vector with length coefficients.240*/241SwsVector *sws_allocVec(int length);242243/**244* Return a normalized Gaussian curve used to filter stuff245* quality = 3 is high quality, lower is lower quality.246*/247SwsVector *sws_getGaussianVec(double variance, double quality);248249/**250* Allocate and return a vector with length coefficients, all251* with the same value c.252*/253SwsVector *sws_getConstVec(double c, int length);254255/**256* Allocate and return a vector with just one coefficient, with257* value 1.0.258*/259SwsVector *sws_getIdentityVec(void);260261/**262* Scale all the coefficients of a by the scalar value.263*/264void sws_scaleVec(SwsVector *a, double scalar);265266/**267* Scale all the coefficients of a so that their sum equals height.268*/269void sws_normalizeVec(SwsVector *a, double height);270void sws_convVec(SwsVector *a, SwsVector *b);271void sws_addVec(SwsVector *a, SwsVector *b);272void sws_subVec(SwsVector *a, SwsVector *b);273void sws_shiftVec(SwsVector *a, int shift);274275/**276* Allocate and return a clone of the vector a, that is a vector277* with the same coefficients as a.278*/279SwsVector *sws_cloneVec(SwsVector *a);280281/**282* Print with av_log() a textual representation of the vector a283* if log_level <= av_log_level.284*/285void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level);286287void sws_freeVec(SwsVector *a);288289SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,290float lumaSharpen, float chromaSharpen,291float chromaHShift, float chromaVShift,292int verbose);293void sws_freeFilter(SwsFilter *filter);294295/**296* Check if context can be reused, otherwise reallocate a new one.297*298* If context is NULL, just calls sws_getContext() to get a new299* context. Otherwise, checks if the parameters are the ones already300* saved in context. If that is the case, returns the current301* context. Otherwise, frees context and gets a new context with302* the new parameters.303*304* Be warned that srcFilter and dstFilter are not checked, they305* are assumed to remain the same.306*/307struct SwsContext *sws_getCachedContext(struct SwsContext *context,308int srcW, int srcH, enum AVPixelFormat srcFormat,309int dstW, int dstH, enum AVPixelFormat dstFormat,310int flags, SwsFilter *srcFilter,311SwsFilter *dstFilter, const double *param);312313/**314* Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.315*316* The output frame will have the same packed format as the palette.317*318* @param src source frame buffer319* @param dst destination frame buffer320* @param num_pixels number of pixels to convert321* @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src322*/323void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);324325/**326* Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.327*328* With the palette format "ABCD", the destination frame ends up with the format "ABC".329*330* @param src source frame buffer331* @param dst destination frame buffer332* @param num_pixels number of pixels to convert333* @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src334*/335void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);336337/**338* Get the AVClass for swsContext. It can be used in combination with339* AV_OPT_SEARCH_FAKE_OBJ for examining options.340*341* @see av_opt_find().342*/343const AVClass *sws_get_class(void);344345/**346* @}347*/348349#endif /* SWSCALE_SWSCALE_H */350351352