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_INTERNAL_H yading@11: #define SWSCALE_SWSCALE_INTERNAL_H yading@11: yading@11: #include "config.h" yading@11: yading@11: #if HAVE_ALTIVEC_H yading@11: #include yading@11: #endif yading@11: yading@11: #include "libavutil/avassert.h" yading@11: #include "libavutil/avutil.h" yading@11: #include "libavutil/common.h" yading@11: #include "libavutil/intreadwrite.h" yading@11: #include "libavutil/log.h" yading@11: #include "libavutil/pixfmt.h" yading@11: #include "libavutil/pixdesc.h" yading@11: yading@11: #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long yading@11: yading@11: #define YUVRGB_TABLE_HEADROOM 128 yading@11: yading@11: #define MAX_FILTER_SIZE 256 yading@11: yading@11: #define DITHER1XBPP yading@11: yading@11: #if HAVE_BIGENDIAN yading@11: #define ALT32_CORR (-1) yading@11: #else yading@11: #define ALT32_CORR 1 yading@11: #endif yading@11: yading@11: #if ARCH_X86_64 yading@11: # define APCK_PTR2 8 yading@11: # define APCK_COEF 16 yading@11: # define APCK_SIZE 24 yading@11: #else yading@11: # define APCK_PTR2 4 yading@11: # define APCK_COEF 8 yading@11: # define APCK_SIZE 16 yading@11: #endif yading@11: yading@11: struct SwsContext; yading@11: yading@11: typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[], yading@11: int srcStride[], int srcSliceY, int srcSliceH, yading@11: uint8_t *dst[], int dstStride[]); yading@11: yading@11: /** yading@11: * Write one line of horizontally scaled data to planar output yading@11: * without any additional vertical scaling (or point-scaling). yading@11: * yading@11: * @param src scaled source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param dest pointer to the output plane. For >8bit yading@11: * output, this is in uint16_t yading@11: * @param dstW width of destination in pixels yading@11: * @param dither ordered dither array of type int16_t and size 8 yading@11: * @param offset Dither offset yading@11: */ yading@11: typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, yading@11: const uint8_t *dither, int offset); yading@11: yading@11: /** yading@11: * Write one line of horizontally scaled data to planar output yading@11: * with multi-point vertical scaling between input pixels. yading@11: * yading@11: * @param filter vertical luma/alpha scaling coefficients, 12bit [0,4096] yading@11: * @param src scaled luma (Y) or alpha (A) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param filterSize number of vertical input lines to scale yading@11: * @param dest pointer to output plane. For >8bit yading@11: * output, this is in uint16_t yading@11: * @param dstW width of destination pixels yading@11: * @param offset Dither offset yading@11: */ yading@11: typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize, yading@11: const int16_t **src, uint8_t *dest, int dstW, yading@11: const uint8_t *dither, int offset); yading@11: yading@11: /** yading@11: * Write one line of horizontally scaled chroma to interleaved output yading@11: * with multi-point vertical scaling between input pixels. yading@11: * yading@11: * @param c SWS scaling context yading@11: * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096] yading@11: * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrFilterSize number of vertical chroma input lines to scale yading@11: * @param dest pointer to the output plane. For >8bit yading@11: * output, this is in uint16_t yading@11: * @param dstW width of chroma planes yading@11: */ yading@11: typedef void (*yuv2interleavedX_fn)(struct SwsContext *c, yading@11: const int16_t *chrFilter, yading@11: int chrFilterSize, yading@11: const int16_t **chrUSrc, yading@11: const int16_t **chrVSrc, yading@11: uint8_t *dest, int dstW); yading@11: yading@11: /** yading@11: * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB yading@11: * output without any additional vertical scaling (or point-scaling). Note yading@11: * that this function may do chroma scaling, see the "uvalpha" argument. yading@11: * yading@11: * @param c SWS scaling context yading@11: * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param dest pointer to the output plane. For 16bit output, this is yading@11: * uint16_t yading@11: * @param dstW width of lumSrc and alpSrc in pixels, number of pixels yading@11: * to write into dest[] yading@11: * @param uvalpha chroma scaling coefficient for the second line of chroma yading@11: * pixels, either 2048 or 0. If 0, one chroma input is used yading@11: * for 2 output pixels (or if the SWS_FLAG_FULL_CHR_INT flag yading@11: * is set, it generates 1 output pixel). If 2048, two chroma yading@11: * input pixels should be averaged for 2 output pixels (this yading@11: * only happens if SWS_FLAG_FULL_CHR_INT is not set) yading@11: * @param y vertical line number for this output. This does not need yading@11: * to be used to calculate the offset in the destination, yading@11: * but can be used to generate comfort noise using dithering yading@11: * for some output formats. yading@11: */ yading@11: typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc, yading@11: const int16_t *chrUSrc[2], yading@11: const int16_t *chrVSrc[2], yading@11: const int16_t *alpSrc, uint8_t *dest, yading@11: int dstW, int uvalpha, int y); yading@11: /** yading@11: * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB yading@11: * output by doing bilinear scaling between two input lines. yading@11: * yading@11: * @param c SWS scaling context yading@11: * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param dest pointer to the output plane. For 16bit output, this is yading@11: * uint16_t yading@11: * @param dstW width of lumSrc and alpSrc in pixels, number of pixels yading@11: * to write into dest[] yading@11: * @param yalpha luma/alpha scaling coefficients for the second input line. yading@11: * The first line's coefficients can be calculated by using yading@11: * 4096 - yalpha yading@11: * @param uvalpha chroma scaling coefficient for the second input line. The yading@11: * first line's coefficients can be calculated by using yading@11: * 4096 - uvalpha yading@11: * @param y vertical line number for this output. This does not need yading@11: * to be used to calculate the offset in the destination, yading@11: * but can be used to generate comfort noise using dithering yading@11: * for some output formats. yading@11: */ yading@11: typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2], yading@11: const int16_t *chrUSrc[2], yading@11: const int16_t *chrVSrc[2], yading@11: const int16_t *alpSrc[2], yading@11: uint8_t *dest, yading@11: int dstW, int yalpha, int uvalpha, int y); yading@11: /** yading@11: * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB yading@11: * output by doing multi-point vertical scaling between input pixels. yading@11: * yading@11: * @param c SWS scaling context yading@11: * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096] yading@11: * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param lumFilterSize number of vertical luma/alpha input lines to scale yading@11: * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096] yading@11: * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrFilterSize number of vertical chroma input lines to scale yading@11: * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param dest pointer to the output plane. For 16bit output, this is yading@11: * uint16_t yading@11: * @param dstW width of lumSrc and alpSrc in pixels, number of pixels yading@11: * to write into dest[] yading@11: * @param y vertical line number for this output. This does not need yading@11: * to be used to calculate the offset in the destination, yading@11: * but can be used to generate comfort noise using dithering yading@11: * or some output formats. yading@11: */ yading@11: typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter, yading@11: const int16_t **lumSrc, int lumFilterSize, yading@11: const int16_t *chrFilter, yading@11: const int16_t **chrUSrc, yading@11: const int16_t **chrVSrc, int chrFilterSize, yading@11: const int16_t **alpSrc, uint8_t *dest, yading@11: int dstW, int y); yading@11: yading@11: /** yading@11: * Write one line of horizontally scaled Y/U/V/A to YUV/RGB yading@11: * output by doing multi-point vertical scaling between input pixels. yading@11: * yading@11: * @param c SWS scaling context yading@11: * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096] yading@11: * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param lumFilterSize number of vertical luma/alpha input lines to scale yading@11: * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096] yading@11: * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param chrFilterSize number of vertical chroma input lines to scale yading@11: * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output, yading@11: * 19-bit for 16bit output (in int32_t) yading@11: * @param dest pointer to the output planes. For 16bit output, this is yading@11: * uint16_t yading@11: * @param dstW width of lumSrc and alpSrc in pixels, number of pixels yading@11: * to write into dest[] yading@11: * @param y vertical line number for this output. This does not need yading@11: * to be used to calculate the offset in the destination, yading@11: * but can be used to generate comfort noise using dithering yading@11: * or some output formats. yading@11: */ yading@11: typedef void (*yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter, yading@11: const int16_t **lumSrc, int lumFilterSize, yading@11: const int16_t *chrFilter, yading@11: const int16_t **chrUSrc, yading@11: const int16_t **chrVSrc, int chrFilterSize, yading@11: const int16_t **alpSrc, uint8_t **dest, yading@11: int dstW, int y); yading@11: yading@11: /* This struct should be aligned on at least a 32-byte boundary. */ yading@11: typedef struct SwsContext { yading@11: /** yading@11: * info on struct for av_log yading@11: */ yading@11: const AVClass *av_class; yading@11: yading@11: /** yading@11: * Note that src, dst, srcStride, dstStride will be copied in the yading@11: * sws_scale() wrapper so they can be freely modified here. yading@11: */ yading@11: SwsFunc swScale; yading@11: int srcW; ///< Width of source luma/alpha planes. yading@11: int srcH; ///< Height of source luma/alpha planes. yading@11: int dstH; ///< Height of destination luma/alpha planes. yading@11: int chrSrcW; ///< Width of source chroma planes. yading@11: int chrSrcH; ///< Height of source chroma planes. yading@11: int chrDstW; ///< Width of destination chroma planes. yading@11: int chrDstH; ///< Height of destination chroma planes. yading@11: int lumXInc, chrXInc; yading@11: int lumYInc, chrYInc; yading@11: enum AVPixelFormat dstFormat; ///< Destination pixel format. yading@11: enum AVPixelFormat srcFormat; ///< Source pixel format. yading@11: int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format. yading@11: int srcFormatBpp; ///< Number of bits per pixel of the source pixel format. yading@11: int dstBpc, srcBpc; yading@11: int chrSrcHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source image. yading@11: int chrSrcVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image. yading@11: int chrDstHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image. yading@11: int chrDstVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination image. yading@11: int vChrDrop; ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user. yading@11: int sliceDir; ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top). yading@11: double param[2]; ///< Input parameters for scaling algorithms that need them. yading@11: yading@11: uint32_t pal_yuv[256]; yading@11: uint32_t pal_rgb[256]; yading@11: yading@11: /** yading@11: * @name Scaled horizontal lines ring buffer. yading@11: * The horizontal scaler keeps just enough scaled lines in a ring buffer yading@11: * so they may be passed to the vertical scaler. The pointers to the yading@11: * allocated buffers for each line are duplicated in sequence in the ring yading@11: * buffer to simplify indexing and avoid wrapping around between lines yading@11: * inside the vertical scaler code. The wrapping is done before the yading@11: * vertical scaler is called. yading@11: */ yading@11: //@{ yading@11: int16_t **lumPixBuf; ///< Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler. yading@11: int16_t **chrUPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler. yading@11: int16_t **chrVPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler. yading@11: int16_t **alpPixBuf; ///< Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler. yading@11: int vLumBufSize; ///< Number of vertical luma/alpha lines allocated in the ring buffer. yading@11: int vChrBufSize; ///< Number of vertical chroma lines allocated in the ring buffer. yading@11: int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer. yading@11: int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer. yading@11: int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source. yading@11: int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source. yading@11: //@} yading@11: yading@11: uint8_t *formatConvBuffer; yading@11: yading@11: /** yading@11: * @name Horizontal and vertical filters. yading@11: * To better understand the following fields, here is a pseudo-code of yading@11: * their usage in filtering a horizontal line: yading@11: * @code yading@11: * for (i = 0; i < width; i++) { yading@11: * dst[i] = 0; yading@11: * for (j = 0; j < filterSize; j++) yading@11: * dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ]; yading@11: * dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point. yading@11: * } yading@11: * @endcode yading@11: */ yading@11: //@{ yading@11: int16_t *hLumFilter; ///< Array of horizontal filter coefficients for luma/alpha planes. yading@11: int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes. yading@11: int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes. yading@11: int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes. yading@11: int32_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes. yading@11: int32_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes. yading@11: int32_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes. yading@11: int32_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes. yading@11: int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels. yading@11: int hChrFilterSize; ///< Horizontal filter size for chroma pixels. yading@11: int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels. yading@11: int vChrFilterSize; ///< Vertical filter size for chroma pixels. yading@11: //@} yading@11: yading@11: int lumMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for luma/alpha planes. yading@11: int chrMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for chroma planes. yading@11: uint8_t *lumMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for luma/alpha planes. yading@11: uint8_t *chrMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for chroma planes. yading@11: yading@11: int canMMXEXTBeUsed; yading@11: yading@11: int dstY; ///< Last destination vertical line output from last slice. yading@11: int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc... yading@11: void *yuvTable; // pointer to the yuv->rgb table start so it can be freed() yading@11: uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM]; yading@11: uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM]; yading@11: int table_gV[256 + 2*YUVRGB_TABLE_HEADROOM]; yading@11: uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM]; yading@11: DECLARE_ALIGNED(16, int32_t, input_rgb2yuv_table)[16+40*4]; // This table can contain both C and SIMD formatted values, teh C vales are always at the XY_IDX points yading@11: #define RY_IDX 0 yading@11: #define GY_IDX 1 yading@11: #define BY_IDX 2 yading@11: #define RU_IDX 3 yading@11: #define GU_IDX 4 yading@11: #define BU_IDX 5 yading@11: #define RV_IDX 6 yading@11: #define GV_IDX 7 yading@11: #define BV_IDX 8 yading@11: #define RGB2YUV_SHIFT 15 yading@11: yading@11: int *dither_error[4]; yading@11: yading@11: //Colorspace stuff yading@11: int contrast, brightness, saturation; // for sws_getColorspaceDetails yading@11: int srcColorspaceTable[4]; yading@11: int dstColorspaceTable[4]; yading@11: int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image). yading@11: int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image). yading@11: int src0Alpha; yading@11: int dst0Alpha; yading@11: int yuv2rgb_y_offset; yading@11: int yuv2rgb_y_coeff; yading@11: int yuv2rgb_v2r_coeff; yading@11: int yuv2rgb_v2g_coeff; yading@11: int yuv2rgb_u2g_coeff; yading@11: int yuv2rgb_u2b_coeff; yading@11: yading@11: #define RED_DITHER "0*8" yading@11: #define GREEN_DITHER "1*8" yading@11: #define BLUE_DITHER "2*8" yading@11: #define Y_COEFF "3*8" yading@11: #define VR_COEFF "4*8" yading@11: #define UB_COEFF "5*8" yading@11: #define VG_COEFF "6*8" yading@11: #define UG_COEFF "7*8" yading@11: #define Y_OFFSET "8*8" yading@11: #define U_OFFSET "9*8" yading@11: #define V_OFFSET "10*8" yading@11: #define LUM_MMX_FILTER_OFFSET "11*8" yading@11: #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256" yading@11: #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM yading@11: #define ESP_OFFSET "11*8+4*4*256*2+8" yading@11: #define VROUNDER_OFFSET "11*8+4*4*256*2+16" yading@11: #define U_TEMP "11*8+4*4*256*2+24" yading@11: #define V_TEMP "11*8+4*4*256*2+32" yading@11: #define Y_TEMP "11*8+4*4*256*2+40" yading@11: #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48" yading@11: #define UV_OFF_PX "11*8+4*4*256*3+48" yading@11: #define UV_OFF_BYTE "11*8+4*4*256*3+56" yading@11: #define DITHER16 "11*8+4*4*256*3+64" yading@11: #define DITHER32 "11*8+4*4*256*3+80" yading@11: yading@11: DECLARE_ALIGNED(8, uint64_t, redDither); yading@11: DECLARE_ALIGNED(8, uint64_t, greenDither); yading@11: DECLARE_ALIGNED(8, uint64_t, blueDither); yading@11: yading@11: DECLARE_ALIGNED(8, uint64_t, yCoeff); yading@11: DECLARE_ALIGNED(8, uint64_t, vrCoeff); yading@11: DECLARE_ALIGNED(8, uint64_t, ubCoeff); yading@11: DECLARE_ALIGNED(8, uint64_t, vgCoeff); yading@11: DECLARE_ALIGNED(8, uint64_t, ugCoeff); yading@11: DECLARE_ALIGNED(8, uint64_t, yOffset); yading@11: DECLARE_ALIGNED(8, uint64_t, uOffset); yading@11: DECLARE_ALIGNED(8, uint64_t, vOffset); yading@11: int32_t lumMmxFilter[4 * MAX_FILTER_SIZE]; yading@11: int32_t chrMmxFilter[4 * MAX_FILTER_SIZE]; yading@11: int dstW; ///< Width of destination luma/alpha planes. yading@11: DECLARE_ALIGNED(8, uint64_t, esp); yading@11: DECLARE_ALIGNED(8, uint64_t, vRounder); yading@11: DECLARE_ALIGNED(8, uint64_t, u_temp); yading@11: DECLARE_ALIGNED(8, uint64_t, v_temp); yading@11: DECLARE_ALIGNED(8, uint64_t, y_temp); yading@11: int32_t alpMmxFilter[4 * MAX_FILTER_SIZE]; yading@11: // alignment of these values is not necessary, but merely here yading@11: // to maintain the same offset across x8632 and x86-64. Once we yading@11: // use proper offset macros in the asm, they can be removed. yading@11: DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes yading@11: DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes yading@11: DECLARE_ALIGNED(8, uint16_t, dither16)[8]; yading@11: DECLARE_ALIGNED(8, uint32_t, dither32)[8]; yading@11: yading@11: const uint8_t *chrDither8, *lumDither8; yading@11: yading@11: #if HAVE_ALTIVEC yading@11: vector signed short CY; yading@11: vector signed short CRV; yading@11: vector signed short CBU; yading@11: vector signed short CGU; yading@11: vector signed short CGV; yading@11: vector signed short OY; yading@11: vector unsigned short CSHIFT; yading@11: vector signed short *vYCoeffsBank, *vCCoeffsBank; yading@11: #endif yading@11: yading@11: #if ARCH_BFIN yading@11: DECLARE_ALIGNED(4, uint32_t, oy); yading@11: DECLARE_ALIGNED(4, uint32_t, oc); yading@11: DECLARE_ALIGNED(4, uint32_t, zero); yading@11: DECLARE_ALIGNED(4, uint32_t, cy); yading@11: DECLARE_ALIGNED(4, uint32_t, crv); yading@11: DECLARE_ALIGNED(4, uint32_t, rmask); yading@11: DECLARE_ALIGNED(4, uint32_t, cbu); yading@11: DECLARE_ALIGNED(4, uint32_t, bmask); yading@11: DECLARE_ALIGNED(4, uint32_t, cgu); yading@11: DECLARE_ALIGNED(4, uint32_t, cgv); yading@11: DECLARE_ALIGNED(4, uint32_t, gmask); yading@11: #endif yading@11: yading@11: #if HAVE_VIS yading@11: DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10]; yading@11: #endif yading@11: int use_mmx_vfilter; yading@11: yading@11: /* function pointers for swScale() */ yading@11: yuv2planar1_fn yuv2plane1; yading@11: yuv2planarX_fn yuv2planeX; yading@11: yuv2interleavedX_fn yuv2nv12cX; yading@11: yuv2packed1_fn yuv2packed1; yading@11: yuv2packed2_fn yuv2packed2; yading@11: yuv2packedX_fn yuv2packedX; yading@11: yuv2anyX_fn yuv2anyX; yading@11: yading@11: /// Unscaled conversion of luma plane to YV12 for horizontal scaler. yading@11: void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, yading@11: int width, uint32_t *pal); yading@11: /// Unscaled conversion of alpha plane to YV12 for horizontal scaler. yading@11: void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, yading@11: int width, uint32_t *pal); yading@11: /// Unscaled conversion of chroma planes to YV12 for horizontal scaler. yading@11: void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV, yading@11: const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, yading@11: int width, uint32_t *pal); yading@11: yading@11: /** yading@11: * Functions to read planar input, such as planar RGB, and convert yading@11: * internally to Y/UV. yading@11: */ yading@11: /** @{ */ yading@11: void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv); yading@11: void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], yading@11: int width, int32_t *rgb2yuv); yading@11: /** @} */ yading@11: yading@11: /** yading@11: * Scale one horizontal line of input data using a bilinear filter yading@11: * to produce one line of output data. Compared to SwsContext->hScale(), yading@11: * please take note of the following caveats when using these: yading@11: * - Scaling is done using only 7bit instead of 14bit coefficients. yading@11: * - You can use no more than 5 input pixels to produce 4 output yading@11: * pixels. Therefore, this filter should not be used for downscaling yading@11: * by more than ~20% in width (because that equals more than 5/4th yading@11: * downscaling and thus more than 5 pixels input per 4 pixels output). yading@11: * - In general, bilinear filters create artifacts during downscaling yading@11: * (even when <20%), because one output pixel will span more than one yading@11: * input pixel, and thus some pixels will need edges of both neighbor yading@11: * pixels to interpolate the output pixel. Since you can use at most yading@11: * two input pixels per output pixel in bilinear scaling, this is yading@11: * impossible and thus downscaling by any size will create artifacts. yading@11: * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR yading@11: * in SwsContext->flags. yading@11: */ yading@11: /** @{ */ yading@11: void (*hyscale_fast)(struct SwsContext *c, yading@11: int16_t *dst, int dstWidth, yading@11: const uint8_t *src, int srcW, int xInc); yading@11: void (*hcscale_fast)(struct SwsContext *c, yading@11: int16_t *dst1, int16_t *dst2, int dstWidth, yading@11: const uint8_t *src1, const uint8_t *src2, yading@11: int srcW, int xInc); yading@11: /** @} */ yading@11: yading@11: /** yading@11: * Scale one horizontal line of input data using a filter over the input yading@11: * lines, to produce one (differently sized) line of output data. yading@11: * yading@11: * @param dst pointer to destination buffer for horizontally scaled yading@11: * data. If the number of bits per component of one yading@11: * destination pixel (SwsContext->dstBpc) is <= 10, data yading@11: * will be 15bpc in 16bits (int16_t) width. Else (i.e. yading@11: * SwsContext->dstBpc == 16), data will be 19bpc in yading@11: * 32bits (int32_t) width. yading@11: * @param dstW width of destination image yading@11: * @param src pointer to source data to be scaled. If the number of yading@11: * bits per component of a source pixel (SwsContext->srcBpc) yading@11: * is 8, this is 8bpc in 8bits (uint8_t) width. Else yading@11: * (i.e. SwsContext->dstBpc > 8), this is native depth yading@11: * in 16bits (uint16_t) width. In other words, for 9-bit yading@11: * YUV input, this is 9bpc, for 10-bit YUV input, this is yading@11: * 10bpc, and for 16-bit RGB or YUV, this is 16bpc. yading@11: * @param filter filter coefficients to be used per output pixel for yading@11: * scaling. This contains 14bpp filtering coefficients. yading@11: * Guaranteed to contain dstW * filterSize entries. yading@11: * @param filterPos position of the first input pixel to be used for yading@11: * each output pixel during scaling. Guaranteed to yading@11: * contain dstW entries. yading@11: * @param filterSize the number of input coefficients to be used (and yading@11: * thus the number of input pixels to be used) for yading@11: * creating a single output pixel. Is aligned to 4 yading@11: * (and input coefficients thus padded with zeroes) yading@11: * to simplify creating SIMD code. yading@11: */ yading@11: /** @{ */ yading@11: void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW, yading@11: const uint8_t *src, const int16_t *filter, yading@11: const int32_t *filterPos, int filterSize); yading@11: void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW, yading@11: const uint8_t *src, const int16_t *filter, yading@11: const int32_t *filterPos, int filterSize); yading@11: /** @} */ yading@11: yading@11: /// Color range conversion function for luma plane if needed. yading@11: void (*lumConvertRange)(int16_t *dst, int width); yading@11: /// Color range conversion function for chroma planes if needed. yading@11: void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width); yading@11: yading@11: int needs_hcscale; ///< Set if there are chroma planes to be converted. yading@11: } SwsContext; yading@11: //FIXME check init (where 0) yading@11: yading@11: SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c); yading@11: int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], yading@11: int fullRange, int brightness, yading@11: int contrast, int saturation); yading@11: yading@11: void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], yading@11: int brightness, int contrast, int saturation); yading@11: void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, yading@11: int lastInLumBuf, int lastInChrBuf); yading@11: yading@11: SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c); yading@11: SwsFunc ff_yuv2rgb_init_vis(SwsContext *c); yading@11: SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c); yading@11: SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c); yading@11: void ff_bfin_get_unscaled_swscale(SwsContext *c); yading@11: yading@11: #if FF_API_SWS_FORMAT_NAME yading@11: /** yading@11: * @deprecated Use av_get_pix_fmt_name() instead. yading@11: */ yading@11: attribute_deprecated yading@11: const char *sws_format_name(enum AVPixelFormat format); yading@11: #endif yading@11: yading@11: static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return desc->comp[0].depth_minus1 == 15; yading@11: } yading@11: yading@11: static av_always_inline int is9_OR_10BPS(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return desc->comp[0].depth_minus1 >= 8 && desc->comp[0].depth_minus1 <= 13; yading@11: } yading@11: yading@11: #define isNBPS(x) is9_OR_10BPS(x) yading@11: yading@11: static av_always_inline int isBE(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return desc->flags & PIX_FMT_BE; yading@11: } yading@11: yading@11: static av_always_inline int isYUV(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return !(desc->flags & PIX_FMT_RGB) && desc->nb_components >= 2; yading@11: } yading@11: yading@11: static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return ((desc->flags & PIX_FMT_PLANAR) && isYUV(pix_fmt)); yading@11: } yading@11: yading@11: static av_always_inline int isRGB(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return (desc->flags & PIX_FMT_RGB); yading@11: } yading@11: yading@11: #if 0 // FIXME yading@11: #define isGray(x) \ yading@11: (!(av_pix_fmt_desc_get(x)->flags & PIX_FMT_PAL) && \ yading@11: av_pix_fmt_desc_get(x)->nb_components <= 2) yading@11: #else yading@11: #define isGray(x) \ yading@11: ((x) == AV_PIX_FMT_GRAY8 || \ yading@11: (x) == AV_PIX_FMT_Y400A || \ yading@11: (x) == AV_PIX_FMT_GRAY16BE || \ yading@11: (x) == AV_PIX_FMT_GRAY16LE) yading@11: #endif yading@11: yading@11: #define isRGBinInt(x) \ yading@11: ( \ yading@11: (x) == AV_PIX_FMT_RGB48BE || \ yading@11: (x) == AV_PIX_FMT_RGB48LE || \ yading@11: (x) == AV_PIX_FMT_RGBA64BE || \ yading@11: (x) == AV_PIX_FMT_RGBA64LE || \ yading@11: (x) == AV_PIX_FMT_RGB32 || \ yading@11: (x) == AV_PIX_FMT_RGB32_1 || \ yading@11: (x) == AV_PIX_FMT_RGB24 || \ yading@11: (x) == AV_PIX_FMT_RGB565BE || \ yading@11: (x) == AV_PIX_FMT_RGB565LE || \ yading@11: (x) == AV_PIX_FMT_RGB555BE || \ yading@11: (x) == AV_PIX_FMT_RGB555LE || \ yading@11: (x) == AV_PIX_FMT_RGB444BE || \ yading@11: (x) == AV_PIX_FMT_RGB444LE || \ yading@11: (x) == AV_PIX_FMT_RGB8 || \ yading@11: (x) == AV_PIX_FMT_RGB4 || \ yading@11: (x) == AV_PIX_FMT_RGB4_BYTE || \ yading@11: (x) == AV_PIX_FMT_MONOBLACK || \ yading@11: (x) == AV_PIX_FMT_MONOWHITE \ yading@11: ) yading@11: #define isBGRinInt(x) \ yading@11: ( \ yading@11: (x) == AV_PIX_FMT_BGR48BE || \ yading@11: (x) == AV_PIX_FMT_BGR48LE || \ yading@11: (x) == AV_PIX_FMT_BGRA64BE || \ yading@11: (x) == AV_PIX_FMT_BGRA64LE || \ yading@11: (x) == AV_PIX_FMT_BGR32 || \ yading@11: (x) == AV_PIX_FMT_BGR32_1 || \ yading@11: (x) == AV_PIX_FMT_BGR24 || \ yading@11: (x) == AV_PIX_FMT_BGR565BE || \ yading@11: (x) == AV_PIX_FMT_BGR565LE || \ yading@11: (x) == AV_PIX_FMT_BGR555BE || \ yading@11: (x) == AV_PIX_FMT_BGR555LE || \ yading@11: (x) == AV_PIX_FMT_BGR444BE || \ yading@11: (x) == AV_PIX_FMT_BGR444LE || \ yading@11: (x) == AV_PIX_FMT_BGR8 || \ yading@11: (x) == AV_PIX_FMT_BGR4 || \ yading@11: (x) == AV_PIX_FMT_BGR4_BYTE || \ yading@11: (x) == AV_PIX_FMT_MONOBLACK || \ yading@11: (x) == AV_PIX_FMT_MONOWHITE \ yading@11: ) yading@11: yading@11: #define isRGBinBytes(x) ( \ yading@11: (x) == AV_PIX_FMT_RGB48BE \ yading@11: || (x) == AV_PIX_FMT_RGB48LE \ yading@11: || (x) == AV_PIX_FMT_RGBA64BE \ yading@11: || (x) == AV_PIX_FMT_RGBA64LE \ yading@11: || (x) == AV_PIX_FMT_RGBA \ yading@11: || (x) == AV_PIX_FMT_ARGB \ yading@11: || (x) == AV_PIX_FMT_RGB24 \ yading@11: ) yading@11: #define isBGRinBytes(x) ( \ yading@11: (x) == AV_PIX_FMT_BGR48BE \ yading@11: || (x) == AV_PIX_FMT_BGR48LE \ yading@11: || (x) == AV_PIX_FMT_BGRA64BE \ yading@11: || (x) == AV_PIX_FMT_BGRA64LE \ yading@11: || (x) == AV_PIX_FMT_BGRA \ yading@11: || (x) == AV_PIX_FMT_ABGR \ yading@11: || (x) == AV_PIX_FMT_BGR24 \ yading@11: ) yading@11: yading@11: #define isAnyRGB(x) \ yading@11: ( \ yading@11: isRGBinInt(x) || \ yading@11: isBGRinInt(x) || \ yading@11: isRGB(x) || \ yading@11: (x)==AV_PIX_FMT_GBRP9LE || \ yading@11: (x)==AV_PIX_FMT_GBRP9BE || \ yading@11: (x)==AV_PIX_FMT_GBRP10LE || \ yading@11: (x)==AV_PIX_FMT_GBRP10BE || \ yading@11: (x)==AV_PIX_FMT_GBRP12LE || \ yading@11: (x)==AV_PIX_FMT_GBRP12BE || \ yading@11: (x)==AV_PIX_FMT_GBRP14LE || \ yading@11: (x)==AV_PIX_FMT_GBRP14BE || \ yading@11: (x)==AV_PIX_FMT_GBR24P \ yading@11: ) yading@11: yading@11: static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return desc->flags & PIX_FMT_ALPHA; yading@11: } yading@11: yading@11: #if 1 yading@11: #define isPacked(x) ( \ yading@11: (x)==AV_PIX_FMT_PAL8 \ yading@11: || (x)==AV_PIX_FMT_YUYV422 \ yading@11: || (x)==AV_PIX_FMT_UYVY422 \ yading@11: || (x)==AV_PIX_FMT_Y400A \ yading@11: || isRGBinInt(x) \ yading@11: || isBGRinInt(x) \ yading@11: ) yading@11: #else yading@11: static av_always_inline int isPacked(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return ((desc->nb_components >= 2 && !(desc->flags & PIX_FMT_PLANAR)) || yading@11: pix_fmt == AV_PIX_FMT_PAL8); yading@11: } yading@11: yading@11: #endif yading@11: static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return (desc->nb_components >= 2 && (desc->flags & PIX_FMT_PLANAR)); yading@11: } yading@11: yading@11: static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return ((desc->flags & (PIX_FMT_PLANAR | PIX_FMT_RGB)) == PIX_FMT_RGB); yading@11: } yading@11: yading@11: static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return ((desc->flags & (PIX_FMT_PLANAR | PIX_FMT_RGB)) == yading@11: (PIX_FMT_PLANAR | PIX_FMT_RGB)); yading@11: } yading@11: yading@11: static av_always_inline int usePal(enum AVPixelFormat pix_fmt) yading@11: { yading@11: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); yading@11: av_assert0(desc); yading@11: return (desc->flags & PIX_FMT_PAL) || (desc->flags & PIX_FMT_PSEUDOPAL); yading@11: } yading@11: yading@11: extern const uint64_t ff_dither4[2]; yading@11: extern const uint64_t ff_dither8[2]; yading@11: extern const uint8_t dithers[8][8][8]; yading@11: extern const uint16_t dither_scale[15][16]; yading@11: yading@11: yading@11: extern const AVClass sws_context_class; yading@11: yading@11: /** yading@11: * Set c->swScale to an unscaled converter if one exists for the specific yading@11: * source and destination formats, bit depths, flags, etc. yading@11: */ yading@11: void ff_get_unscaled_swscale(SwsContext *c); yading@11: yading@11: void ff_swscale_get_unscaled_altivec(SwsContext *c); yading@11: yading@11: /** yading@11: * Return function pointer to fastest main scaler path function depending yading@11: * on architecture and available optimizations. yading@11: */ yading@11: SwsFunc ff_getSwsFunc(SwsContext *c); yading@11: yading@11: void ff_sws_init_input_funcs(SwsContext *c); yading@11: void ff_sws_init_output_funcs(SwsContext *c, yading@11: yuv2planar1_fn *yuv2plane1, yading@11: yuv2planarX_fn *yuv2planeX, yading@11: yuv2interleavedX_fn *yuv2nv12cX, yading@11: yuv2packed1_fn *yuv2packed1, yading@11: yuv2packed2_fn *yuv2packed2, yading@11: yuv2packedX_fn *yuv2packedX, yading@11: yuv2anyX_fn *yuv2anyX); yading@11: void ff_sws_init_swScale_altivec(SwsContext *c); yading@11: void ff_sws_init_swScale_mmx(SwsContext *c); yading@11: yading@11: static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, yading@11: int alpha, int bits, const int big_endian) yading@11: { yading@11: int i, j; yading@11: uint8_t *ptr = plane + stride * y; yading@11: int v = alpha ? 0xFFFF>>(15-bits) : (1<