yading@11: /* yading@11: * Copyright (C) 2001-2011 Michael Niedermayer yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef SWSCALE_SWSCALE_H yading@11: #define SWSCALE_SWSCALE_H yading@11: yading@11: /** yading@11: * @file yading@11: * @ingroup lsws yading@11: * external API header yading@11: */ yading@11: yading@11: /** yading@11: * @defgroup lsws Libswscale yading@11: * @{ yading@11: */ yading@11: yading@11: #include yading@11: yading@11: #include "libavutil/avutil.h" yading@11: #include "libavutil/log.h" yading@11: #include "libavutil/pixfmt.h" yading@11: #include "version.h" yading@11: yading@11: /** yading@11: * Return the LIBSWSCALE_VERSION_INT constant. yading@11: */ yading@11: unsigned swscale_version(void); yading@11: yading@11: /** yading@11: * Return the libswscale build-time configuration. yading@11: */ yading@11: const char *swscale_configuration(void); yading@11: yading@11: /** yading@11: * Return the libswscale license. yading@11: */ yading@11: const char *swscale_license(void); yading@11: yading@11: /* values for the flags, the stuff on the command line is different */ yading@11: #define SWS_FAST_BILINEAR 1 yading@11: #define SWS_BILINEAR 2 yading@11: #define SWS_BICUBIC 4 yading@11: #define SWS_X 8 yading@11: #define SWS_POINT 0x10 yading@11: #define SWS_AREA 0x20 yading@11: #define SWS_BICUBLIN 0x40 yading@11: #define SWS_GAUSS 0x80 yading@11: #define SWS_SINC 0x100 yading@11: #define SWS_LANCZOS 0x200 yading@11: #define SWS_SPLINE 0x400 yading@11: yading@11: #define SWS_SRC_V_CHR_DROP_MASK 0x30000 yading@11: #define SWS_SRC_V_CHR_DROP_SHIFT 16 yading@11: yading@11: #define SWS_PARAM_DEFAULT 123456 yading@11: yading@11: #define SWS_PRINT_INFO 0x1000 yading@11: yading@11: //the following 3 flags are not completely implemented yading@11: //internal chrominace subsampling info yading@11: #define SWS_FULL_CHR_H_INT 0x2000 yading@11: //input subsampling info yading@11: #define SWS_FULL_CHR_H_INP 0x4000 yading@11: #define SWS_DIRECT_BGR 0x8000 yading@11: #define SWS_ACCURATE_RND 0x40000 yading@11: #define SWS_BITEXACT 0x80000 yading@11: #define SWS_ERROR_DIFFUSION 0x800000 yading@11: yading@11: #if FF_API_SWS_CPU_CAPS yading@11: /** yading@11: * CPU caps are autodetected now, those flags yading@11: * are only provided for API compatibility. yading@11: */ yading@11: #define SWS_CPU_CAPS_MMX 0x80000000 yading@11: #define SWS_CPU_CAPS_MMXEXT 0x20000000 yading@11: #define SWS_CPU_CAPS_MMX2 0x20000000 yading@11: #define SWS_CPU_CAPS_3DNOW 0x40000000 yading@11: #define SWS_CPU_CAPS_ALTIVEC 0x10000000 yading@11: #define SWS_CPU_CAPS_BFIN 0x01000000 yading@11: #define SWS_CPU_CAPS_SSE2 0x02000000 yading@11: #endif yading@11: yading@11: #define SWS_MAX_REDUCE_CUTOFF 0.002 yading@11: yading@11: #define SWS_CS_ITU709 1 yading@11: #define SWS_CS_FCC 4 yading@11: #define SWS_CS_ITU601 5 yading@11: #define SWS_CS_ITU624 5 yading@11: #define SWS_CS_SMPTE170M 5 yading@11: #define SWS_CS_SMPTE240M 7 yading@11: #define SWS_CS_DEFAULT 5 yading@11: yading@11: /** yading@11: * Return a pointer to yuv<->rgb coefficients for the given colorspace yading@11: * suitable for sws_setColorspaceDetails(). yading@11: * yading@11: * @param colorspace One of the SWS_CS_* macros. If invalid, yading@11: * SWS_CS_DEFAULT is used. yading@11: */ yading@11: const int *sws_getCoefficients(int colorspace); yading@11: yading@11: // when used for filters they must have an odd number of elements yading@11: // coeffs cannot be shared between vectors yading@11: typedef struct SwsVector { yading@11: double *coeff; ///< pointer to the list of coefficients yading@11: int length; ///< number of coefficients in the vector yading@11: } SwsVector; yading@11: yading@11: // vectors can be shared yading@11: typedef struct SwsFilter { yading@11: SwsVector *lumH; yading@11: SwsVector *lumV; yading@11: SwsVector *chrH; yading@11: SwsVector *chrV; yading@11: } SwsFilter; yading@11: yading@11: struct SwsContext; yading@11: yading@11: /** yading@11: * Return a positive value if pix_fmt is a supported input format, 0 yading@11: * otherwise. yading@11: */ yading@11: int sws_isSupportedInput(enum AVPixelFormat pix_fmt); yading@11: yading@11: /** yading@11: * Return a positive value if pix_fmt is a supported output format, 0 yading@11: * otherwise. yading@11: */ yading@11: int sws_isSupportedOutput(enum AVPixelFormat pix_fmt); yading@11: yading@11: /** yading@11: * Allocate an empty SwsContext. This must be filled and passed to yading@11: * sws_init_context(). For filling see AVOptions, options.c and yading@11: * sws_setColorspaceDetails(). yading@11: */ yading@11: struct SwsContext *sws_alloc_context(void); yading@11: yading@11: /** yading@11: * Initialize the swscaler context sws_context. yading@11: * yading@11: * @return zero or positive value on success, a negative value on yading@11: * error yading@11: */ yading@11: int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter); yading@11: yading@11: /** yading@11: * Free the swscaler context swsContext. yading@11: * If swsContext is NULL, then does nothing. yading@11: */ yading@11: void sws_freeContext(struct SwsContext *swsContext); yading@11: yading@11: #if FF_API_SWS_GETCONTEXT yading@11: /** yading@11: * Allocate and return an SwsContext. You need it to perform yading@11: * scaling/conversion operations using sws_scale(). yading@11: * yading@11: * @param srcW the width of the source image yading@11: * @param srcH the height of the source image yading@11: * @param srcFormat the source image format yading@11: * @param dstW the width of the destination image yading@11: * @param dstH the height of the destination image yading@11: * @param dstFormat the destination image format yading@11: * @param flags specify which algorithm and options to use for rescaling yading@11: * @return a pointer to an allocated context, or NULL in case of error yading@11: * @note this function is to be removed after a saner alternative is yading@11: * written yading@11: * @deprecated Use sws_getCachedContext() instead. yading@11: */ yading@11: struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, yading@11: int dstW, int dstH, enum AVPixelFormat dstFormat, yading@11: int flags, SwsFilter *srcFilter, yading@11: SwsFilter *dstFilter, const double *param); yading@11: #endif yading@11: yading@11: /** yading@11: * Scale the image slice in srcSlice and put the resulting scaled yading@11: * slice in the image in dst. A slice is a sequence of consecutive yading@11: * rows in an image. yading@11: * yading@11: * Slices have to be provided in sequential order, either in yading@11: * top-bottom or bottom-top order. If slices are provided in yading@11: * non-sequential order the behavior of the function is undefined. yading@11: * yading@11: * @param c the scaling context previously created with yading@11: * sws_getContext() yading@11: * @param srcSlice the array containing the pointers to the planes of yading@11: * the source slice yading@11: * @param srcStride the array containing the strides for each plane of yading@11: * the source image yading@11: * @param srcSliceY the position in the source image of the slice to yading@11: * process, that is the number (counted starting from yading@11: * zero) in the image of the first row of the slice yading@11: * @param srcSliceH the height of the source slice, that is the number yading@11: * of rows in the slice yading@11: * @param dst the array containing the pointers to the planes of yading@11: * the destination image yading@11: * @param dstStride the array containing the strides for each plane of yading@11: * the destination image yading@11: * @return the height of the output slice yading@11: */ yading@11: int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], yading@11: const int srcStride[], int srcSliceY, int srcSliceH, yading@11: uint8_t *const dst[], const int dstStride[]); yading@11: yading@11: /** yading@11: * @param dstRange flag indicating the while-black range of the output (1=jpeg / 0=mpeg) yading@11: * @param srcRange flag indicating the while-black range of the input (1=jpeg / 0=mpeg) yading@11: * @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x] yading@11: * @param inv_table the yuv2rgb coefficients describing the input yuv space, normally ff_yuv2rgb_coeffs[x] yading@11: * @param brightness 16.16 fixed point brightness correction yading@11: * @param contrast 16.16 fixed point contrast correction yading@11: * @param saturation 16.16 fixed point saturation correction yading@11: * @return -1 if not supported yading@11: */ yading@11: int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], yading@11: int srcRange, const int table[4], int dstRange, yading@11: int brightness, int contrast, int saturation); yading@11: yading@11: /** yading@11: * @return -1 if not supported yading@11: */ yading@11: int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, yading@11: int *srcRange, int **table, int *dstRange, yading@11: int *brightness, int *contrast, int *saturation); yading@11: yading@11: /** yading@11: * Allocate and return an uninitialized vector with length coefficients. yading@11: */ yading@11: SwsVector *sws_allocVec(int length); yading@11: yading@11: /** yading@11: * Return a normalized Gaussian curve used to filter stuff yading@11: * quality = 3 is high quality, lower is lower quality. yading@11: */ yading@11: SwsVector *sws_getGaussianVec(double variance, double quality); yading@11: yading@11: /** yading@11: * Allocate and return a vector with length coefficients, all yading@11: * with the same value c. yading@11: */ yading@11: SwsVector *sws_getConstVec(double c, int length); yading@11: yading@11: /** yading@11: * Allocate and return a vector with just one coefficient, with yading@11: * value 1.0. yading@11: */ yading@11: SwsVector *sws_getIdentityVec(void); yading@11: yading@11: /** yading@11: * Scale all the coefficients of a by the scalar value. yading@11: */ yading@11: void sws_scaleVec(SwsVector *a, double scalar); yading@11: yading@11: /** yading@11: * Scale all the coefficients of a so that their sum equals height. yading@11: */ yading@11: void sws_normalizeVec(SwsVector *a, double height); yading@11: void sws_convVec(SwsVector *a, SwsVector *b); yading@11: void sws_addVec(SwsVector *a, SwsVector *b); yading@11: void sws_subVec(SwsVector *a, SwsVector *b); yading@11: void sws_shiftVec(SwsVector *a, int shift); yading@11: yading@11: /** yading@11: * Allocate and return a clone of the vector a, that is a vector yading@11: * with the same coefficients as a. yading@11: */ yading@11: SwsVector *sws_cloneVec(SwsVector *a); yading@11: yading@11: /** yading@11: * Print with av_log() a textual representation of the vector a yading@11: * if log_level <= av_log_level. yading@11: */ yading@11: void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level); yading@11: yading@11: void sws_freeVec(SwsVector *a); yading@11: yading@11: SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, yading@11: float lumaSharpen, float chromaSharpen, yading@11: float chromaHShift, float chromaVShift, yading@11: int verbose); yading@11: void sws_freeFilter(SwsFilter *filter); yading@11: yading@11: /** yading@11: * Check if context can be reused, otherwise reallocate a new one. yading@11: * yading@11: * If context is NULL, just calls sws_getContext() to get a new yading@11: * context. Otherwise, checks if the parameters are the ones already yading@11: * saved in context. If that is the case, returns the current yading@11: * context. Otherwise, frees context and gets a new context with yading@11: * the new parameters. yading@11: * yading@11: * Be warned that srcFilter and dstFilter are not checked, they yading@11: * are assumed to remain the same. yading@11: */ yading@11: struct SwsContext *sws_getCachedContext(struct SwsContext *context, yading@11: int srcW, int srcH, enum AVPixelFormat srcFormat, yading@11: int dstW, int dstH, enum AVPixelFormat dstFormat, yading@11: int flags, SwsFilter *srcFilter, yading@11: SwsFilter *dstFilter, const double *param); yading@11: yading@11: /** yading@11: * Convert an 8-bit paletted frame into a frame with a color depth of 32 bits. yading@11: * yading@11: * The output frame will have the same packed format as the palette. yading@11: * yading@11: * @param src source frame buffer yading@11: * @param dst destination frame buffer yading@11: * @param num_pixels number of pixels to convert yading@11: * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src yading@11: */ yading@11: void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette); yading@11: yading@11: /** yading@11: * Convert an 8-bit paletted frame into a frame with a color depth of 24 bits. yading@11: * yading@11: * With the palette format "ABCD", the destination frame ends up with the format "ABC". yading@11: * yading@11: * @param src source frame buffer yading@11: * @param dst destination frame buffer yading@11: * @param num_pixels number of pixels to convert yading@11: * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src yading@11: */ yading@11: void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette); yading@11: yading@11: /** yading@11: * Get the AVClass for swsContext. It can be used in combination with yading@11: * AV_OPT_SEARCH_FAKE_OBJ for examining options. yading@11: * yading@11: * @see av_opt_find(). yading@11: */ yading@11: const AVClass *sws_get_class(void); yading@11: yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: #endif /* SWSCALE_SWSCALE_H */