annotate ffmpeg/libswscale/swscale_internal.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
yading@11 3 *
yading@11 4 * This file is part of FFmpeg.
yading@11 5 *
yading@11 6 * FFmpeg is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * FFmpeg is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with FFmpeg; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 #ifndef SWSCALE_SWSCALE_INTERNAL_H
yading@11 22 #define SWSCALE_SWSCALE_INTERNAL_H
yading@11 23
yading@11 24 #include "config.h"
yading@11 25
yading@11 26 #if HAVE_ALTIVEC_H
yading@11 27 #include <altivec.h>
yading@11 28 #endif
yading@11 29
yading@11 30 #include "libavutil/avassert.h"
yading@11 31 #include "libavutil/avutil.h"
yading@11 32 #include "libavutil/common.h"
yading@11 33 #include "libavutil/intreadwrite.h"
yading@11 34 #include "libavutil/log.h"
yading@11 35 #include "libavutil/pixfmt.h"
yading@11 36 #include "libavutil/pixdesc.h"
yading@11 37
yading@11 38 #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long
yading@11 39
yading@11 40 #define YUVRGB_TABLE_HEADROOM 128
yading@11 41
yading@11 42 #define MAX_FILTER_SIZE 256
yading@11 43
yading@11 44 #define DITHER1XBPP
yading@11 45
yading@11 46 #if HAVE_BIGENDIAN
yading@11 47 #define ALT32_CORR (-1)
yading@11 48 #else
yading@11 49 #define ALT32_CORR 1
yading@11 50 #endif
yading@11 51
yading@11 52 #if ARCH_X86_64
yading@11 53 # define APCK_PTR2 8
yading@11 54 # define APCK_COEF 16
yading@11 55 # define APCK_SIZE 24
yading@11 56 #else
yading@11 57 # define APCK_PTR2 4
yading@11 58 # define APCK_COEF 8
yading@11 59 # define APCK_SIZE 16
yading@11 60 #endif
yading@11 61
yading@11 62 struct SwsContext;
yading@11 63
yading@11 64 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[],
yading@11 65 int srcStride[], int srcSliceY, int srcSliceH,
yading@11 66 uint8_t *dst[], int dstStride[]);
yading@11 67
yading@11 68 /**
yading@11 69 * Write one line of horizontally scaled data to planar output
yading@11 70 * without any additional vertical scaling (or point-scaling).
yading@11 71 *
yading@11 72 * @param src scaled source data, 15bit for 8-10bit output,
yading@11 73 * 19-bit for 16bit output (in int32_t)
yading@11 74 * @param dest pointer to the output plane. For >8bit
yading@11 75 * output, this is in uint16_t
yading@11 76 * @param dstW width of destination in pixels
yading@11 77 * @param dither ordered dither array of type int16_t and size 8
yading@11 78 * @param offset Dither offset
yading@11 79 */
yading@11 80 typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW,
yading@11 81 const uint8_t *dither, int offset);
yading@11 82
yading@11 83 /**
yading@11 84 * Write one line of horizontally scaled data to planar output
yading@11 85 * with multi-point vertical scaling between input pixels.
yading@11 86 *
yading@11 87 * @param filter vertical luma/alpha scaling coefficients, 12bit [0,4096]
yading@11 88 * @param src scaled luma (Y) or alpha (A) source data, 15bit for 8-10bit output,
yading@11 89 * 19-bit for 16bit output (in int32_t)
yading@11 90 * @param filterSize number of vertical input lines to scale
yading@11 91 * @param dest pointer to output plane. For >8bit
yading@11 92 * output, this is in uint16_t
yading@11 93 * @param dstW width of destination pixels
yading@11 94 * @param offset Dither offset
yading@11 95 */
yading@11 96 typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize,
yading@11 97 const int16_t **src, uint8_t *dest, int dstW,
yading@11 98 const uint8_t *dither, int offset);
yading@11 99
yading@11 100 /**
yading@11 101 * Write one line of horizontally scaled chroma to interleaved output
yading@11 102 * with multi-point vertical scaling between input pixels.
yading@11 103 *
yading@11 104 * @param c SWS scaling context
yading@11 105 * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
yading@11 106 * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
yading@11 107 * 19-bit for 16bit output (in int32_t)
yading@11 108 * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
yading@11 109 * 19-bit for 16bit output (in int32_t)
yading@11 110 * @param chrFilterSize number of vertical chroma input lines to scale
yading@11 111 * @param dest pointer to the output plane. For >8bit
yading@11 112 * output, this is in uint16_t
yading@11 113 * @param dstW width of chroma planes
yading@11 114 */
yading@11 115 typedef void (*yuv2interleavedX_fn)(struct SwsContext *c,
yading@11 116 const int16_t *chrFilter,
yading@11 117 int chrFilterSize,
yading@11 118 const int16_t **chrUSrc,
yading@11 119 const int16_t **chrVSrc,
yading@11 120 uint8_t *dest, int dstW);
yading@11 121
yading@11 122 /**
yading@11 123 * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
yading@11 124 * output without any additional vertical scaling (or point-scaling). Note
yading@11 125 * that this function may do chroma scaling, see the "uvalpha" argument.
yading@11 126 *
yading@11 127 * @param c SWS scaling context
yading@11 128 * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
yading@11 129 * 19-bit for 16bit output (in int32_t)
yading@11 130 * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
yading@11 131 * 19-bit for 16bit output (in int32_t)
yading@11 132 * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
yading@11 133 * 19-bit for 16bit output (in int32_t)
yading@11 134 * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
yading@11 135 * 19-bit for 16bit output (in int32_t)
yading@11 136 * @param dest pointer to the output plane. For 16bit output, this is
yading@11 137 * uint16_t
yading@11 138 * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
yading@11 139 * to write into dest[]
yading@11 140 * @param uvalpha chroma scaling coefficient for the second line of chroma
yading@11 141 * pixels, either 2048 or 0. If 0, one chroma input is used
yading@11 142 * for 2 output pixels (or if the SWS_FLAG_FULL_CHR_INT flag
yading@11 143 * is set, it generates 1 output pixel). If 2048, two chroma
yading@11 144 * input pixels should be averaged for 2 output pixels (this
yading@11 145 * only happens if SWS_FLAG_FULL_CHR_INT is not set)
yading@11 146 * @param y vertical line number for this output. This does not need
yading@11 147 * to be used to calculate the offset in the destination,
yading@11 148 * but can be used to generate comfort noise using dithering
yading@11 149 * for some output formats.
yading@11 150 */
yading@11 151 typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc,
yading@11 152 const int16_t *chrUSrc[2],
yading@11 153 const int16_t *chrVSrc[2],
yading@11 154 const int16_t *alpSrc, uint8_t *dest,
yading@11 155 int dstW, int uvalpha, int y);
yading@11 156 /**
yading@11 157 * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
yading@11 158 * output by doing bilinear scaling between two input lines.
yading@11 159 *
yading@11 160 * @param c SWS scaling context
yading@11 161 * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
yading@11 162 * 19-bit for 16bit output (in int32_t)
yading@11 163 * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
yading@11 164 * 19-bit for 16bit output (in int32_t)
yading@11 165 * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
yading@11 166 * 19-bit for 16bit output (in int32_t)
yading@11 167 * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
yading@11 168 * 19-bit for 16bit output (in int32_t)
yading@11 169 * @param dest pointer to the output plane. For 16bit output, this is
yading@11 170 * uint16_t
yading@11 171 * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
yading@11 172 * to write into dest[]
yading@11 173 * @param yalpha luma/alpha scaling coefficients for the second input line.
yading@11 174 * The first line's coefficients can be calculated by using
yading@11 175 * 4096 - yalpha
yading@11 176 * @param uvalpha chroma scaling coefficient for the second input line. The
yading@11 177 * first line's coefficients can be calculated by using
yading@11 178 * 4096 - uvalpha
yading@11 179 * @param y vertical line number for this output. This does not need
yading@11 180 * to be used to calculate the offset in the destination,
yading@11 181 * but can be used to generate comfort noise using dithering
yading@11 182 * for some output formats.
yading@11 183 */
yading@11 184 typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2],
yading@11 185 const int16_t *chrUSrc[2],
yading@11 186 const int16_t *chrVSrc[2],
yading@11 187 const int16_t *alpSrc[2],
yading@11 188 uint8_t *dest,
yading@11 189 int dstW, int yalpha, int uvalpha, int y);
yading@11 190 /**
yading@11 191 * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
yading@11 192 * output by doing multi-point vertical scaling between input pixels.
yading@11 193 *
yading@11 194 * @param c SWS scaling context
yading@11 195 * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096]
yading@11 196 * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
yading@11 197 * 19-bit for 16bit output (in int32_t)
yading@11 198 * @param lumFilterSize number of vertical luma/alpha input lines to scale
yading@11 199 * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
yading@11 200 * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
yading@11 201 * 19-bit for 16bit output (in int32_t)
yading@11 202 * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
yading@11 203 * 19-bit for 16bit output (in int32_t)
yading@11 204 * @param chrFilterSize number of vertical chroma input lines to scale
yading@11 205 * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
yading@11 206 * 19-bit for 16bit output (in int32_t)
yading@11 207 * @param dest pointer to the output plane. For 16bit output, this is
yading@11 208 * uint16_t
yading@11 209 * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
yading@11 210 * to write into dest[]
yading@11 211 * @param y vertical line number for this output. This does not need
yading@11 212 * to be used to calculate the offset in the destination,
yading@11 213 * but can be used to generate comfort noise using dithering
yading@11 214 * or some output formats.
yading@11 215 */
yading@11 216 typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
yading@11 217 const int16_t **lumSrc, int lumFilterSize,
yading@11 218 const int16_t *chrFilter,
yading@11 219 const int16_t **chrUSrc,
yading@11 220 const int16_t **chrVSrc, int chrFilterSize,
yading@11 221 const int16_t **alpSrc, uint8_t *dest,
yading@11 222 int dstW, int y);
yading@11 223
yading@11 224 /**
yading@11 225 * Write one line of horizontally scaled Y/U/V/A to YUV/RGB
yading@11 226 * output by doing multi-point vertical scaling between input pixels.
yading@11 227 *
yading@11 228 * @param c SWS scaling context
yading@11 229 * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096]
yading@11 230 * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
yading@11 231 * 19-bit for 16bit output (in int32_t)
yading@11 232 * @param lumFilterSize number of vertical luma/alpha input lines to scale
yading@11 233 * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
yading@11 234 * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
yading@11 235 * 19-bit for 16bit output (in int32_t)
yading@11 236 * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
yading@11 237 * 19-bit for 16bit output (in int32_t)
yading@11 238 * @param chrFilterSize number of vertical chroma input lines to scale
yading@11 239 * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
yading@11 240 * 19-bit for 16bit output (in int32_t)
yading@11 241 * @param dest pointer to the output planes. For 16bit output, this is
yading@11 242 * uint16_t
yading@11 243 * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
yading@11 244 * to write into dest[]
yading@11 245 * @param y vertical line number for this output. This does not need
yading@11 246 * to be used to calculate the offset in the destination,
yading@11 247 * but can be used to generate comfort noise using dithering
yading@11 248 * or some output formats.
yading@11 249 */
yading@11 250 typedef void (*yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter,
yading@11 251 const int16_t **lumSrc, int lumFilterSize,
yading@11 252 const int16_t *chrFilter,
yading@11 253 const int16_t **chrUSrc,
yading@11 254 const int16_t **chrVSrc, int chrFilterSize,
yading@11 255 const int16_t **alpSrc, uint8_t **dest,
yading@11 256 int dstW, int y);
yading@11 257
yading@11 258 /* This struct should be aligned on at least a 32-byte boundary. */
yading@11 259 typedef struct SwsContext {
yading@11 260 /**
yading@11 261 * info on struct for av_log
yading@11 262 */
yading@11 263 const AVClass *av_class;
yading@11 264
yading@11 265 /**
yading@11 266 * Note that src, dst, srcStride, dstStride will be copied in the
yading@11 267 * sws_scale() wrapper so they can be freely modified here.
yading@11 268 */
yading@11 269 SwsFunc swScale;
yading@11 270 int srcW; ///< Width of source luma/alpha planes.
yading@11 271 int srcH; ///< Height of source luma/alpha planes.
yading@11 272 int dstH; ///< Height of destination luma/alpha planes.
yading@11 273 int chrSrcW; ///< Width of source chroma planes.
yading@11 274 int chrSrcH; ///< Height of source chroma planes.
yading@11 275 int chrDstW; ///< Width of destination chroma planes.
yading@11 276 int chrDstH; ///< Height of destination chroma planes.
yading@11 277 int lumXInc, chrXInc;
yading@11 278 int lumYInc, chrYInc;
yading@11 279 enum AVPixelFormat dstFormat; ///< Destination pixel format.
yading@11 280 enum AVPixelFormat srcFormat; ///< Source pixel format.
yading@11 281 int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format.
yading@11 282 int srcFormatBpp; ///< Number of bits per pixel of the source pixel format.
yading@11 283 int dstBpc, srcBpc;
yading@11 284 int chrSrcHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source image.
yading@11 285 int chrSrcVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image.
yading@11 286 int chrDstHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image.
yading@11 287 int chrDstVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination image.
yading@11 288 int vChrDrop; ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user.
yading@11 289 int sliceDir; ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
yading@11 290 double param[2]; ///< Input parameters for scaling algorithms that need them.
yading@11 291
yading@11 292 uint32_t pal_yuv[256];
yading@11 293 uint32_t pal_rgb[256];
yading@11 294
yading@11 295 /**
yading@11 296 * @name Scaled horizontal lines ring buffer.
yading@11 297 * The horizontal scaler keeps just enough scaled lines in a ring buffer
yading@11 298 * so they may be passed to the vertical scaler. The pointers to the
yading@11 299 * allocated buffers for each line are duplicated in sequence in the ring
yading@11 300 * buffer to simplify indexing and avoid wrapping around between lines
yading@11 301 * inside the vertical scaler code. The wrapping is done before the
yading@11 302 * vertical scaler is called.
yading@11 303 */
yading@11 304 //@{
yading@11 305 int16_t **lumPixBuf; ///< Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler.
yading@11 306 int16_t **chrUPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
yading@11 307 int16_t **chrVPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
yading@11 308 int16_t **alpPixBuf; ///< Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler.
yading@11 309 int vLumBufSize; ///< Number of vertical luma/alpha lines allocated in the ring buffer.
yading@11 310 int vChrBufSize; ///< Number of vertical chroma lines allocated in the ring buffer.
yading@11 311 int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer.
yading@11 312 int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer.
yading@11 313 int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source.
yading@11 314 int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source.
yading@11 315 //@}
yading@11 316
yading@11 317 uint8_t *formatConvBuffer;
yading@11 318
yading@11 319 /**
yading@11 320 * @name Horizontal and vertical filters.
yading@11 321 * To better understand the following fields, here is a pseudo-code of
yading@11 322 * their usage in filtering a horizontal line:
yading@11 323 * @code
yading@11 324 * for (i = 0; i < width; i++) {
yading@11 325 * dst[i] = 0;
yading@11 326 * for (j = 0; j < filterSize; j++)
yading@11 327 * dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ];
yading@11 328 * dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point.
yading@11 329 * }
yading@11 330 * @endcode
yading@11 331 */
yading@11 332 //@{
yading@11 333 int16_t *hLumFilter; ///< Array of horizontal filter coefficients for luma/alpha planes.
yading@11 334 int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes.
yading@11 335 int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes.
yading@11 336 int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes.
yading@11 337 int32_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
yading@11 338 int32_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes.
yading@11 339 int32_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes.
yading@11 340 int32_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes.
yading@11 341 int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels.
yading@11 342 int hChrFilterSize; ///< Horizontal filter size for chroma pixels.
yading@11 343 int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels.
yading@11 344 int vChrFilterSize; ///< Vertical filter size for chroma pixels.
yading@11 345 //@}
yading@11 346
yading@11 347 int lumMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for luma/alpha planes.
yading@11 348 int chrMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for chroma planes.
yading@11 349 uint8_t *lumMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for luma/alpha planes.
yading@11 350 uint8_t *chrMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for chroma planes.
yading@11 351
yading@11 352 int canMMXEXTBeUsed;
yading@11 353
yading@11 354 int dstY; ///< Last destination vertical line output from last slice.
yading@11 355 int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
yading@11 356 void *yuvTable; // pointer to the yuv->rgb table start so it can be freed()
yading@11 357 uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM];
yading@11 358 uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM];
yading@11 359 int table_gV[256 + 2*YUVRGB_TABLE_HEADROOM];
yading@11 360 uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM];
yading@11 361 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 362 #define RY_IDX 0
yading@11 363 #define GY_IDX 1
yading@11 364 #define BY_IDX 2
yading@11 365 #define RU_IDX 3
yading@11 366 #define GU_IDX 4
yading@11 367 #define BU_IDX 5
yading@11 368 #define RV_IDX 6
yading@11 369 #define GV_IDX 7
yading@11 370 #define BV_IDX 8
yading@11 371 #define RGB2YUV_SHIFT 15
yading@11 372
yading@11 373 int *dither_error[4];
yading@11 374
yading@11 375 //Colorspace stuff
yading@11 376 int contrast, brightness, saturation; // for sws_getColorspaceDetails
yading@11 377 int srcColorspaceTable[4];
yading@11 378 int dstColorspaceTable[4];
yading@11 379 int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image).
yading@11 380 int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image).
yading@11 381 int src0Alpha;
yading@11 382 int dst0Alpha;
yading@11 383 int yuv2rgb_y_offset;
yading@11 384 int yuv2rgb_y_coeff;
yading@11 385 int yuv2rgb_v2r_coeff;
yading@11 386 int yuv2rgb_v2g_coeff;
yading@11 387 int yuv2rgb_u2g_coeff;
yading@11 388 int yuv2rgb_u2b_coeff;
yading@11 389
yading@11 390 #define RED_DITHER "0*8"
yading@11 391 #define GREEN_DITHER "1*8"
yading@11 392 #define BLUE_DITHER "2*8"
yading@11 393 #define Y_COEFF "3*8"
yading@11 394 #define VR_COEFF "4*8"
yading@11 395 #define UB_COEFF "5*8"
yading@11 396 #define VG_COEFF "6*8"
yading@11 397 #define UG_COEFF "7*8"
yading@11 398 #define Y_OFFSET "8*8"
yading@11 399 #define U_OFFSET "9*8"
yading@11 400 #define V_OFFSET "10*8"
yading@11 401 #define LUM_MMX_FILTER_OFFSET "11*8"
yading@11 402 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
yading@11 403 #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
yading@11 404 #define ESP_OFFSET "11*8+4*4*256*2+8"
yading@11 405 #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
yading@11 406 #define U_TEMP "11*8+4*4*256*2+24"
yading@11 407 #define V_TEMP "11*8+4*4*256*2+32"
yading@11 408 #define Y_TEMP "11*8+4*4*256*2+40"
yading@11 409 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
yading@11 410 #define UV_OFF_PX "11*8+4*4*256*3+48"
yading@11 411 #define UV_OFF_BYTE "11*8+4*4*256*3+56"
yading@11 412 #define DITHER16 "11*8+4*4*256*3+64"
yading@11 413 #define DITHER32 "11*8+4*4*256*3+80"
yading@11 414
yading@11 415 DECLARE_ALIGNED(8, uint64_t, redDither);
yading@11 416 DECLARE_ALIGNED(8, uint64_t, greenDither);
yading@11 417 DECLARE_ALIGNED(8, uint64_t, blueDither);
yading@11 418
yading@11 419 DECLARE_ALIGNED(8, uint64_t, yCoeff);
yading@11 420 DECLARE_ALIGNED(8, uint64_t, vrCoeff);
yading@11 421 DECLARE_ALIGNED(8, uint64_t, ubCoeff);
yading@11 422 DECLARE_ALIGNED(8, uint64_t, vgCoeff);
yading@11 423 DECLARE_ALIGNED(8, uint64_t, ugCoeff);
yading@11 424 DECLARE_ALIGNED(8, uint64_t, yOffset);
yading@11 425 DECLARE_ALIGNED(8, uint64_t, uOffset);
yading@11 426 DECLARE_ALIGNED(8, uint64_t, vOffset);
yading@11 427 int32_t lumMmxFilter[4 * MAX_FILTER_SIZE];
yading@11 428 int32_t chrMmxFilter[4 * MAX_FILTER_SIZE];
yading@11 429 int dstW; ///< Width of destination luma/alpha planes.
yading@11 430 DECLARE_ALIGNED(8, uint64_t, esp);
yading@11 431 DECLARE_ALIGNED(8, uint64_t, vRounder);
yading@11 432 DECLARE_ALIGNED(8, uint64_t, u_temp);
yading@11 433 DECLARE_ALIGNED(8, uint64_t, v_temp);
yading@11 434 DECLARE_ALIGNED(8, uint64_t, y_temp);
yading@11 435 int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
yading@11 436 // alignment of these values is not necessary, but merely here
yading@11 437 // to maintain the same offset across x8632 and x86-64. Once we
yading@11 438 // use proper offset macros in the asm, they can be removed.
yading@11 439 DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes
yading@11 440 DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes
yading@11 441 DECLARE_ALIGNED(8, uint16_t, dither16)[8];
yading@11 442 DECLARE_ALIGNED(8, uint32_t, dither32)[8];
yading@11 443
yading@11 444 const uint8_t *chrDither8, *lumDither8;
yading@11 445
yading@11 446 #if HAVE_ALTIVEC
yading@11 447 vector signed short CY;
yading@11 448 vector signed short CRV;
yading@11 449 vector signed short CBU;
yading@11 450 vector signed short CGU;
yading@11 451 vector signed short CGV;
yading@11 452 vector signed short OY;
yading@11 453 vector unsigned short CSHIFT;
yading@11 454 vector signed short *vYCoeffsBank, *vCCoeffsBank;
yading@11 455 #endif
yading@11 456
yading@11 457 #if ARCH_BFIN
yading@11 458 DECLARE_ALIGNED(4, uint32_t, oy);
yading@11 459 DECLARE_ALIGNED(4, uint32_t, oc);
yading@11 460 DECLARE_ALIGNED(4, uint32_t, zero);
yading@11 461 DECLARE_ALIGNED(4, uint32_t, cy);
yading@11 462 DECLARE_ALIGNED(4, uint32_t, crv);
yading@11 463 DECLARE_ALIGNED(4, uint32_t, rmask);
yading@11 464 DECLARE_ALIGNED(4, uint32_t, cbu);
yading@11 465 DECLARE_ALIGNED(4, uint32_t, bmask);
yading@11 466 DECLARE_ALIGNED(4, uint32_t, cgu);
yading@11 467 DECLARE_ALIGNED(4, uint32_t, cgv);
yading@11 468 DECLARE_ALIGNED(4, uint32_t, gmask);
yading@11 469 #endif
yading@11 470
yading@11 471 #if HAVE_VIS
yading@11 472 DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
yading@11 473 #endif
yading@11 474 int use_mmx_vfilter;
yading@11 475
yading@11 476 /* function pointers for swScale() */
yading@11 477 yuv2planar1_fn yuv2plane1;
yading@11 478 yuv2planarX_fn yuv2planeX;
yading@11 479 yuv2interleavedX_fn yuv2nv12cX;
yading@11 480 yuv2packed1_fn yuv2packed1;
yading@11 481 yuv2packed2_fn yuv2packed2;
yading@11 482 yuv2packedX_fn yuv2packedX;
yading@11 483 yuv2anyX_fn yuv2anyX;
yading@11 484
yading@11 485 /// Unscaled conversion of luma plane to YV12 for horizontal scaler.
yading@11 486 void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
yading@11 487 int width, uint32_t *pal);
yading@11 488 /// Unscaled conversion of alpha plane to YV12 for horizontal scaler.
yading@11 489 void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
yading@11 490 int width, uint32_t *pal);
yading@11 491 /// Unscaled conversion of chroma planes to YV12 for horizontal scaler.
yading@11 492 void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
yading@11 493 const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
yading@11 494 int width, uint32_t *pal);
yading@11 495
yading@11 496 /**
yading@11 497 * Functions to read planar input, such as planar RGB, and convert
yading@11 498 * internally to Y/UV.
yading@11 499 */
yading@11 500 /** @{ */
yading@11 501 void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv);
yading@11 502 void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
yading@11 503 int width, int32_t *rgb2yuv);
yading@11 504 /** @} */
yading@11 505
yading@11 506 /**
yading@11 507 * Scale one horizontal line of input data using a bilinear filter
yading@11 508 * to produce one line of output data. Compared to SwsContext->hScale(),
yading@11 509 * please take note of the following caveats when using these:
yading@11 510 * - Scaling is done using only 7bit instead of 14bit coefficients.
yading@11 511 * - You can use no more than 5 input pixels to produce 4 output
yading@11 512 * pixels. Therefore, this filter should not be used for downscaling
yading@11 513 * by more than ~20% in width (because that equals more than 5/4th
yading@11 514 * downscaling and thus more than 5 pixels input per 4 pixels output).
yading@11 515 * - In general, bilinear filters create artifacts during downscaling
yading@11 516 * (even when <20%), because one output pixel will span more than one
yading@11 517 * input pixel, and thus some pixels will need edges of both neighbor
yading@11 518 * pixels to interpolate the output pixel. Since you can use at most
yading@11 519 * two input pixels per output pixel in bilinear scaling, this is
yading@11 520 * impossible and thus downscaling by any size will create artifacts.
yading@11 521 * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR
yading@11 522 * in SwsContext->flags.
yading@11 523 */
yading@11 524 /** @{ */
yading@11 525 void (*hyscale_fast)(struct SwsContext *c,
yading@11 526 int16_t *dst, int dstWidth,
yading@11 527 const uint8_t *src, int srcW, int xInc);
yading@11 528 void (*hcscale_fast)(struct SwsContext *c,
yading@11 529 int16_t *dst1, int16_t *dst2, int dstWidth,
yading@11 530 const uint8_t *src1, const uint8_t *src2,
yading@11 531 int srcW, int xInc);
yading@11 532 /** @} */
yading@11 533
yading@11 534 /**
yading@11 535 * Scale one horizontal line of input data using a filter over the input
yading@11 536 * lines, to produce one (differently sized) line of output data.
yading@11 537 *
yading@11 538 * @param dst pointer to destination buffer for horizontally scaled
yading@11 539 * data. If the number of bits per component of one
yading@11 540 * destination pixel (SwsContext->dstBpc) is <= 10, data
yading@11 541 * will be 15bpc in 16bits (int16_t) width. Else (i.e.
yading@11 542 * SwsContext->dstBpc == 16), data will be 19bpc in
yading@11 543 * 32bits (int32_t) width.
yading@11 544 * @param dstW width of destination image
yading@11 545 * @param src pointer to source data to be scaled. If the number of
yading@11 546 * bits per component of a source pixel (SwsContext->srcBpc)
yading@11 547 * is 8, this is 8bpc in 8bits (uint8_t) width. Else
yading@11 548 * (i.e. SwsContext->dstBpc > 8), this is native depth
yading@11 549 * in 16bits (uint16_t) width. In other words, for 9-bit
yading@11 550 * YUV input, this is 9bpc, for 10-bit YUV input, this is
yading@11 551 * 10bpc, and for 16-bit RGB or YUV, this is 16bpc.
yading@11 552 * @param filter filter coefficients to be used per output pixel for
yading@11 553 * scaling. This contains 14bpp filtering coefficients.
yading@11 554 * Guaranteed to contain dstW * filterSize entries.
yading@11 555 * @param filterPos position of the first input pixel to be used for
yading@11 556 * each output pixel during scaling. Guaranteed to
yading@11 557 * contain dstW entries.
yading@11 558 * @param filterSize the number of input coefficients to be used (and
yading@11 559 * thus the number of input pixels to be used) for
yading@11 560 * creating a single output pixel. Is aligned to 4
yading@11 561 * (and input coefficients thus padded with zeroes)
yading@11 562 * to simplify creating SIMD code.
yading@11 563 */
yading@11 564 /** @{ */
yading@11 565 void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
yading@11 566 const uint8_t *src, const int16_t *filter,
yading@11 567 const int32_t *filterPos, int filterSize);
yading@11 568 void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
yading@11 569 const uint8_t *src, const int16_t *filter,
yading@11 570 const int32_t *filterPos, int filterSize);
yading@11 571 /** @} */
yading@11 572
yading@11 573 /// Color range conversion function for luma plane if needed.
yading@11 574 void (*lumConvertRange)(int16_t *dst, int width);
yading@11 575 /// Color range conversion function for chroma planes if needed.
yading@11 576 void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
yading@11 577
yading@11 578 int needs_hcscale; ///< Set if there are chroma planes to be converted.
yading@11 579 } SwsContext;
yading@11 580 //FIXME check init (where 0)
yading@11 581
yading@11 582 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
yading@11 583 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
yading@11 584 int fullRange, int brightness,
yading@11 585 int contrast, int saturation);
yading@11 586
yading@11 587 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
yading@11 588 int brightness, int contrast, int saturation);
yading@11 589 void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
yading@11 590 int lastInLumBuf, int lastInChrBuf);
yading@11 591
yading@11 592 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
yading@11 593 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
yading@11 594 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
yading@11 595 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
yading@11 596 void ff_bfin_get_unscaled_swscale(SwsContext *c);
yading@11 597
yading@11 598 #if FF_API_SWS_FORMAT_NAME
yading@11 599 /**
yading@11 600 * @deprecated Use av_get_pix_fmt_name() instead.
yading@11 601 */
yading@11 602 attribute_deprecated
yading@11 603 const char *sws_format_name(enum AVPixelFormat format);
yading@11 604 #endif
yading@11 605
yading@11 606 static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
yading@11 607 {
yading@11 608 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 609 av_assert0(desc);
yading@11 610 return desc->comp[0].depth_minus1 == 15;
yading@11 611 }
yading@11 612
yading@11 613 static av_always_inline int is9_OR_10BPS(enum AVPixelFormat pix_fmt)
yading@11 614 {
yading@11 615 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 616 av_assert0(desc);
yading@11 617 return desc->comp[0].depth_minus1 >= 8 && desc->comp[0].depth_minus1 <= 13;
yading@11 618 }
yading@11 619
yading@11 620 #define isNBPS(x) is9_OR_10BPS(x)
yading@11 621
yading@11 622 static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
yading@11 623 {
yading@11 624 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 625 av_assert0(desc);
yading@11 626 return desc->flags & PIX_FMT_BE;
yading@11 627 }
yading@11 628
yading@11 629 static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
yading@11 630 {
yading@11 631 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 632 av_assert0(desc);
yading@11 633 return !(desc->flags & PIX_FMT_RGB) && desc->nb_components >= 2;
yading@11 634 }
yading@11 635
yading@11 636 static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
yading@11 637 {
yading@11 638 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 639 av_assert0(desc);
yading@11 640 return ((desc->flags & PIX_FMT_PLANAR) && isYUV(pix_fmt));
yading@11 641 }
yading@11 642
yading@11 643 static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
yading@11 644 {
yading@11 645 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 646 av_assert0(desc);
yading@11 647 return (desc->flags & PIX_FMT_RGB);
yading@11 648 }
yading@11 649
yading@11 650 #if 0 // FIXME
yading@11 651 #define isGray(x) \
yading@11 652 (!(av_pix_fmt_desc_get(x)->flags & PIX_FMT_PAL) && \
yading@11 653 av_pix_fmt_desc_get(x)->nb_components <= 2)
yading@11 654 #else
yading@11 655 #define isGray(x) \
yading@11 656 ((x) == AV_PIX_FMT_GRAY8 || \
yading@11 657 (x) == AV_PIX_FMT_Y400A || \
yading@11 658 (x) == AV_PIX_FMT_GRAY16BE || \
yading@11 659 (x) == AV_PIX_FMT_GRAY16LE)
yading@11 660 #endif
yading@11 661
yading@11 662 #define isRGBinInt(x) \
yading@11 663 ( \
yading@11 664 (x) == AV_PIX_FMT_RGB48BE || \
yading@11 665 (x) == AV_PIX_FMT_RGB48LE || \
yading@11 666 (x) == AV_PIX_FMT_RGBA64BE || \
yading@11 667 (x) == AV_PIX_FMT_RGBA64LE || \
yading@11 668 (x) == AV_PIX_FMT_RGB32 || \
yading@11 669 (x) == AV_PIX_FMT_RGB32_1 || \
yading@11 670 (x) == AV_PIX_FMT_RGB24 || \
yading@11 671 (x) == AV_PIX_FMT_RGB565BE || \
yading@11 672 (x) == AV_PIX_FMT_RGB565LE || \
yading@11 673 (x) == AV_PIX_FMT_RGB555BE || \
yading@11 674 (x) == AV_PIX_FMT_RGB555LE || \
yading@11 675 (x) == AV_PIX_FMT_RGB444BE || \
yading@11 676 (x) == AV_PIX_FMT_RGB444LE || \
yading@11 677 (x) == AV_PIX_FMT_RGB8 || \
yading@11 678 (x) == AV_PIX_FMT_RGB4 || \
yading@11 679 (x) == AV_PIX_FMT_RGB4_BYTE || \
yading@11 680 (x) == AV_PIX_FMT_MONOBLACK || \
yading@11 681 (x) == AV_PIX_FMT_MONOWHITE \
yading@11 682 )
yading@11 683 #define isBGRinInt(x) \
yading@11 684 ( \
yading@11 685 (x) == AV_PIX_FMT_BGR48BE || \
yading@11 686 (x) == AV_PIX_FMT_BGR48LE || \
yading@11 687 (x) == AV_PIX_FMT_BGRA64BE || \
yading@11 688 (x) == AV_PIX_FMT_BGRA64LE || \
yading@11 689 (x) == AV_PIX_FMT_BGR32 || \
yading@11 690 (x) == AV_PIX_FMT_BGR32_1 || \
yading@11 691 (x) == AV_PIX_FMT_BGR24 || \
yading@11 692 (x) == AV_PIX_FMT_BGR565BE || \
yading@11 693 (x) == AV_PIX_FMT_BGR565LE || \
yading@11 694 (x) == AV_PIX_FMT_BGR555BE || \
yading@11 695 (x) == AV_PIX_FMT_BGR555LE || \
yading@11 696 (x) == AV_PIX_FMT_BGR444BE || \
yading@11 697 (x) == AV_PIX_FMT_BGR444LE || \
yading@11 698 (x) == AV_PIX_FMT_BGR8 || \
yading@11 699 (x) == AV_PIX_FMT_BGR4 || \
yading@11 700 (x) == AV_PIX_FMT_BGR4_BYTE || \
yading@11 701 (x) == AV_PIX_FMT_MONOBLACK || \
yading@11 702 (x) == AV_PIX_FMT_MONOWHITE \
yading@11 703 )
yading@11 704
yading@11 705 #define isRGBinBytes(x) ( \
yading@11 706 (x) == AV_PIX_FMT_RGB48BE \
yading@11 707 || (x) == AV_PIX_FMT_RGB48LE \
yading@11 708 || (x) == AV_PIX_FMT_RGBA64BE \
yading@11 709 || (x) == AV_PIX_FMT_RGBA64LE \
yading@11 710 || (x) == AV_PIX_FMT_RGBA \
yading@11 711 || (x) == AV_PIX_FMT_ARGB \
yading@11 712 || (x) == AV_PIX_FMT_RGB24 \
yading@11 713 )
yading@11 714 #define isBGRinBytes(x) ( \
yading@11 715 (x) == AV_PIX_FMT_BGR48BE \
yading@11 716 || (x) == AV_PIX_FMT_BGR48LE \
yading@11 717 || (x) == AV_PIX_FMT_BGRA64BE \
yading@11 718 || (x) == AV_PIX_FMT_BGRA64LE \
yading@11 719 || (x) == AV_PIX_FMT_BGRA \
yading@11 720 || (x) == AV_PIX_FMT_ABGR \
yading@11 721 || (x) == AV_PIX_FMT_BGR24 \
yading@11 722 )
yading@11 723
yading@11 724 #define isAnyRGB(x) \
yading@11 725 ( \
yading@11 726 isRGBinInt(x) || \
yading@11 727 isBGRinInt(x) || \
yading@11 728 isRGB(x) || \
yading@11 729 (x)==AV_PIX_FMT_GBRP9LE || \
yading@11 730 (x)==AV_PIX_FMT_GBRP9BE || \
yading@11 731 (x)==AV_PIX_FMT_GBRP10LE || \
yading@11 732 (x)==AV_PIX_FMT_GBRP10BE || \
yading@11 733 (x)==AV_PIX_FMT_GBRP12LE || \
yading@11 734 (x)==AV_PIX_FMT_GBRP12BE || \
yading@11 735 (x)==AV_PIX_FMT_GBRP14LE || \
yading@11 736 (x)==AV_PIX_FMT_GBRP14BE || \
yading@11 737 (x)==AV_PIX_FMT_GBR24P \
yading@11 738 )
yading@11 739
yading@11 740 static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
yading@11 741 {
yading@11 742 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 743 av_assert0(desc);
yading@11 744 return desc->flags & PIX_FMT_ALPHA;
yading@11 745 }
yading@11 746
yading@11 747 #if 1
yading@11 748 #define isPacked(x) ( \
yading@11 749 (x)==AV_PIX_FMT_PAL8 \
yading@11 750 || (x)==AV_PIX_FMT_YUYV422 \
yading@11 751 || (x)==AV_PIX_FMT_UYVY422 \
yading@11 752 || (x)==AV_PIX_FMT_Y400A \
yading@11 753 || isRGBinInt(x) \
yading@11 754 || isBGRinInt(x) \
yading@11 755 )
yading@11 756 #else
yading@11 757 static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
yading@11 758 {
yading@11 759 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 760 av_assert0(desc);
yading@11 761 return ((desc->nb_components >= 2 && !(desc->flags & PIX_FMT_PLANAR)) ||
yading@11 762 pix_fmt == AV_PIX_FMT_PAL8);
yading@11 763 }
yading@11 764
yading@11 765 #endif
yading@11 766 static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
yading@11 767 {
yading@11 768 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 769 av_assert0(desc);
yading@11 770 return (desc->nb_components >= 2 && (desc->flags & PIX_FMT_PLANAR));
yading@11 771 }
yading@11 772
yading@11 773 static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
yading@11 774 {
yading@11 775 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 776 av_assert0(desc);
yading@11 777 return ((desc->flags & (PIX_FMT_PLANAR | PIX_FMT_RGB)) == PIX_FMT_RGB);
yading@11 778 }
yading@11 779
yading@11 780 static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
yading@11 781 {
yading@11 782 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 783 av_assert0(desc);
yading@11 784 return ((desc->flags & (PIX_FMT_PLANAR | PIX_FMT_RGB)) ==
yading@11 785 (PIX_FMT_PLANAR | PIX_FMT_RGB));
yading@11 786 }
yading@11 787
yading@11 788 static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
yading@11 789 {
yading@11 790 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
yading@11 791 av_assert0(desc);
yading@11 792 return (desc->flags & PIX_FMT_PAL) || (desc->flags & PIX_FMT_PSEUDOPAL);
yading@11 793 }
yading@11 794
yading@11 795 extern const uint64_t ff_dither4[2];
yading@11 796 extern const uint64_t ff_dither8[2];
yading@11 797 extern const uint8_t dithers[8][8][8];
yading@11 798 extern const uint16_t dither_scale[15][16];
yading@11 799
yading@11 800
yading@11 801 extern const AVClass sws_context_class;
yading@11 802
yading@11 803 /**
yading@11 804 * Set c->swScale to an unscaled converter if one exists for the specific
yading@11 805 * source and destination formats, bit depths, flags, etc.
yading@11 806 */
yading@11 807 void ff_get_unscaled_swscale(SwsContext *c);
yading@11 808
yading@11 809 void ff_swscale_get_unscaled_altivec(SwsContext *c);
yading@11 810
yading@11 811 /**
yading@11 812 * Return function pointer to fastest main scaler path function depending
yading@11 813 * on architecture and available optimizations.
yading@11 814 */
yading@11 815 SwsFunc ff_getSwsFunc(SwsContext *c);
yading@11 816
yading@11 817 void ff_sws_init_input_funcs(SwsContext *c);
yading@11 818 void ff_sws_init_output_funcs(SwsContext *c,
yading@11 819 yuv2planar1_fn *yuv2plane1,
yading@11 820 yuv2planarX_fn *yuv2planeX,
yading@11 821 yuv2interleavedX_fn *yuv2nv12cX,
yading@11 822 yuv2packed1_fn *yuv2packed1,
yading@11 823 yuv2packed2_fn *yuv2packed2,
yading@11 824 yuv2packedX_fn *yuv2packedX,
yading@11 825 yuv2anyX_fn *yuv2anyX);
yading@11 826 void ff_sws_init_swScale_altivec(SwsContext *c);
yading@11 827 void ff_sws_init_swScale_mmx(SwsContext *c);
yading@11 828
yading@11 829 static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y,
yading@11 830 int alpha, int bits, const int big_endian)
yading@11 831 {
yading@11 832 int i, j;
yading@11 833 uint8_t *ptr = plane + stride * y;
yading@11 834 int v = alpha ? 0xFFFF>>(15-bits) : (1<<bits);
yading@11 835 for (i = 0; i < height; i++) {
yading@11 836 #define FILL(wfunc) \
yading@11 837 for (j = 0; j < width; j++) {\
yading@11 838 wfunc(ptr+2*j, v);\
yading@11 839 }
yading@11 840 if (big_endian) {
yading@11 841 FILL(AV_WB16);
yading@11 842 } else {
yading@11 843 FILL(AV_WL16);
yading@11 844 }
yading@11 845 ptr += stride;
yading@11 846 }
yading@11 847 }
yading@11 848
yading@11 849 #endif /* SWSCALE_SWSCALE_INTERNAL_H */