]> git.sesse.net Git - ffmpeg/blob - libswscale/swscale_internal.h
swscale: make yuv2interleavedX more asm-friendly
[ffmpeg] / libswscale / swscale_internal.h
1 /*
2  * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #ifndef SWSCALE_SWSCALE_INTERNAL_H
22 #define SWSCALE_SWSCALE_INTERNAL_H
23
24 #include "config.h"
25 #include "version.h"
26
27 #include "libavutil/avassert.h"
28 #include "libavutil/avutil.h"
29 #include "libavutil/common.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/log.h"
32 #include "libavutil/pixfmt.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/ppc/util_altivec.h"
35
36 #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long
37
38 #define YUVRGB_TABLE_HEADROOM 512
39 #define YUVRGB_TABLE_LUMA_HEADROOM 512
40
41 #define MAX_FILTER_SIZE SWS_MAX_FILTER_SIZE
42
43 #define DITHER1XBPP
44
45 #if HAVE_BIGENDIAN
46 #define ALT32_CORR (-1)
47 #else
48 #define ALT32_CORR   1
49 #endif
50
51 #if ARCH_X86_64
52 #   define APCK_PTR2  8
53 #   define APCK_COEF 16
54 #   define APCK_SIZE 24
55 #else
56 #   define APCK_PTR2  4
57 #   define APCK_COEF  8
58 #   define APCK_SIZE 16
59 #endif
60
61 #define RETCODE_USE_CASCADE -12345
62
63 struct SwsContext;
64
65 typedef enum SwsDither {
66     SWS_DITHER_NONE = 0,
67     SWS_DITHER_AUTO,
68     SWS_DITHER_BAYER,
69     SWS_DITHER_ED,
70     SWS_DITHER_A_DITHER,
71     SWS_DITHER_X_DITHER,
72     NB_SWS_DITHER,
73 } SwsDither;
74
75 typedef enum SwsAlphaBlend {
76     SWS_ALPHA_BLEND_NONE  = 0,
77     SWS_ALPHA_BLEND_UNIFORM,
78     SWS_ALPHA_BLEND_CHECKERBOARD,
79     SWS_ALPHA_BLEND_NB,
80 } SwsAlphaBlend;
81
82 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[],
83                        int srcStride[], int srcSliceY, int srcSliceH,
84                        uint8_t *dst[], int dstStride[]);
85
86 /**
87  * Write one line of horizontally scaled data to planar output
88  * without any additional vertical scaling (or point-scaling).
89  *
90  * @param src     scaled source data, 15 bits for 8-10-bit output,
91  *                19 bits for 16-bit output (in int32_t)
92  * @param dest    pointer to the output plane. For >8-bit
93  *                output, this is in uint16_t
94  * @param dstW    width of destination in pixels
95  * @param dither  ordered dither array of type int16_t and size 8
96  * @param offset  Dither offset
97  */
98 typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW,
99                                const uint8_t *dither, int offset);
100
101 /**
102  * Write one line of horizontally scaled data to planar output
103  * with multi-point vertical scaling between input pixels.
104  *
105  * @param filter        vertical luma/alpha scaling coefficients, 12 bits [0,4096]
106  * @param src           scaled luma (Y) or alpha (A) source data, 15 bits for
107  *                      8-10-bit output, 19 bits for 16-bit output (in int32_t)
108  * @param filterSize    number of vertical input lines to scale
109  * @param dest          pointer to output plane. For >8-bit
110  *                      output, this is in uint16_t
111  * @param dstW          width of destination pixels
112  * @param offset        Dither offset
113  */
114 typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize,
115                                const int16_t **src, uint8_t *dest, int dstW,
116                                const uint8_t *dither, int offset);
117
118 /**
119  * Write one line of horizontally scaled chroma to interleaved output
120  * with multi-point vertical scaling between input pixels.
121  *
122  * @param dstFormat     destination pixel format
123  * @param chrDither     ordered dither array of type uint8_t and size 8
124  * @param chrFilter     vertical chroma scaling coefficients, 12 bits [0,4096]
125  * @param chrUSrc       scaled chroma (U) source data, 15 bits for 8-10-bit
126  *                      output, 19 bits for 16-bit output (in int32_t)
127  * @param chrVSrc       scaled chroma (V) source data, 15 bits for 8-10-bit
128  *                      output, 19 bits for 16-bit output (in int32_t)
129  * @param chrFilterSize number of vertical chroma input lines to scale
130  * @param dest          pointer to the output plane. For >8-bit
131  *                      output, this is in uint16_t
132  * @param dstW          width of chroma planes
133  */
134 typedef void (*yuv2interleavedX_fn)(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
135                                     const int16_t *chrFilter,
136                                     int chrFilterSize,
137                                     const int16_t **chrUSrc,
138                                     const int16_t **chrVSrc,
139                                     uint8_t *dest, int dstW);
140
141 /**
142  * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
143  * output without any additional vertical scaling (or point-scaling). Note
144  * that this function may do chroma scaling, see the "uvalpha" argument.
145  *
146  * @param c       SWS scaling context
147  * @param lumSrc  scaled luma (Y) source data, 15 bits for 8-10-bit output,
148  *                19 bits for 16-bit output (in int32_t)
149  * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output,
150  *                19 bits for 16-bit output (in int32_t)
151  * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output,
152  *                19 bits for 16-bit output (in int32_t)
153  * @param alpSrc  scaled alpha (A) source data, 15 bits for 8-10-bit output,
154  *                19 bits for 16-bit output (in int32_t)
155  * @param dest    pointer to the output plane. For 16-bit output, this is
156  *                uint16_t
157  * @param dstW    width of lumSrc and alpSrc in pixels, number of pixels
158  *                to write into dest[]
159  * @param uvalpha chroma scaling coefficient for the second line of chroma
160  *                pixels, either 2048 or 0. If 0, one chroma input is used
161  *                for 2 output pixels (or if the SWS_FLAG_FULL_CHR_INT flag
162  *                is set, it generates 1 output pixel). If 2048, two chroma
163  *                input pixels should be averaged for 2 output pixels (this
164  *                only happens if SWS_FLAG_FULL_CHR_INT is not set)
165  * @param y       vertical line number for this output. This does not need
166  *                to be used to calculate the offset in the destination,
167  *                but can be used to generate comfort noise using dithering
168  *                for some output formats.
169  */
170 typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc,
171                                const int16_t *chrUSrc[2],
172                                const int16_t *chrVSrc[2],
173                                const int16_t *alpSrc, uint8_t *dest,
174                                int dstW, int uvalpha, int y);
175 /**
176  * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
177  * output by doing bilinear scaling between two input lines.
178  *
179  * @param c       SWS scaling context
180  * @param lumSrc  scaled luma (Y) source data, 15 bits for 8-10-bit output,
181  *                19 bits for 16-bit output (in int32_t)
182  * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output,
183  *                19 bits for 16-bit output (in int32_t)
184  * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output,
185  *                19 bits for 16-bit output (in int32_t)
186  * @param alpSrc  scaled alpha (A) source data, 15 bits for 8-10-bit output,
187  *                19 bits for 16-bit output (in int32_t)
188  * @param dest    pointer to the output plane. For 16-bit output, this is
189  *                uint16_t
190  * @param dstW    width of lumSrc and alpSrc in pixels, number of pixels
191  *                to write into dest[]
192  * @param yalpha  luma/alpha scaling coefficients for the second input line.
193  *                The first line's coefficients can be calculated by using
194  *                4096 - yalpha
195  * @param uvalpha chroma scaling coefficient for the second input line. The
196  *                first line's coefficients can be calculated by using
197  *                4096 - uvalpha
198  * @param y       vertical line number for this output. This does not need
199  *                to be used to calculate the offset in the destination,
200  *                but can be used to generate comfort noise using dithering
201  *                for some output formats.
202  */
203 typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2],
204                                const int16_t *chrUSrc[2],
205                                const int16_t *chrVSrc[2],
206                                const int16_t *alpSrc[2],
207                                uint8_t *dest,
208                                int dstW, int yalpha, int uvalpha, int y);
209 /**
210  * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
211  * output by doing multi-point vertical scaling between input pixels.
212  *
213  * @param c             SWS scaling context
214  * @param lumFilter     vertical luma/alpha scaling coefficients, 12 bits [0,4096]
215  * @param lumSrc        scaled luma (Y) source data, 15 bits for 8-10-bit output,
216  *                      19 bits for 16-bit output (in int32_t)
217  * @param lumFilterSize number of vertical luma/alpha input lines to scale
218  * @param chrFilter     vertical chroma scaling coefficients, 12 bits [0,4096]
219  * @param chrUSrc       scaled chroma (U) source data, 15 bits for 8-10-bit output,
220  *                      19 bits for 16-bit output (in int32_t)
221  * @param chrVSrc       scaled chroma (V) source data, 15 bits for 8-10-bit output,
222  *                      19 bits for 16-bit output (in int32_t)
223  * @param chrFilterSize number of vertical chroma input lines to scale
224  * @param alpSrc        scaled alpha (A) source data, 15 bits for 8-10-bit output,
225  *                      19 bits for 16-bit output (in int32_t)
226  * @param dest          pointer to the output plane. For 16-bit output, this is
227  *                      uint16_t
228  * @param dstW          width of lumSrc and alpSrc in pixels, number of pixels
229  *                      to write into dest[]
230  * @param y             vertical line number for this output. This does not need
231  *                      to be used to calculate the offset in the destination,
232  *                      but can be used to generate comfort noise using dithering
233  *                      or some output formats.
234  */
235 typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
236                                const int16_t **lumSrc, int lumFilterSize,
237                                const int16_t *chrFilter,
238                                const int16_t **chrUSrc,
239                                const int16_t **chrVSrc, int chrFilterSize,
240                                const int16_t **alpSrc, uint8_t *dest,
241                                int dstW, int y);
242
243 /**
244  * Write one line of horizontally scaled Y/U/V/A to YUV/RGB
245  * output by doing multi-point vertical scaling between input pixels.
246  *
247  * @param c             SWS scaling context
248  * @param lumFilter     vertical luma/alpha scaling coefficients, 12 bits [0,4096]
249  * @param lumSrc        scaled luma (Y) source data, 15 bits for 8-10-bit output,
250  *                      19 bits for 16-bit output (in int32_t)
251  * @param lumFilterSize number of vertical luma/alpha input lines to scale
252  * @param chrFilter     vertical chroma scaling coefficients, 12 bits [0,4096]
253  * @param chrUSrc       scaled chroma (U) source data, 15 bits for 8-10-bit output,
254  *                      19 bits for 16-bit output (in int32_t)
255  * @param chrVSrc       scaled chroma (V) source data, 15 bits for 8-10-bit output,
256  *                      19 bits for 16-bit output (in int32_t)
257  * @param chrFilterSize number of vertical chroma input lines to scale
258  * @param alpSrc        scaled alpha (A) source data, 15 bits for 8-10-bit output,
259  *                      19 bits for 16-bit output (in int32_t)
260  * @param dest          pointer to the output planes. For 16-bit output, this is
261  *                      uint16_t
262  * @param dstW          width of lumSrc and alpSrc in pixels, number of pixels
263  *                      to write into dest[]
264  * @param y             vertical line number for this output. This does not need
265  *                      to be used to calculate the offset in the destination,
266  *                      but can be used to generate comfort noise using dithering
267  *                      or some output formats.
268  */
269 typedef void (*yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter,
270                             const int16_t **lumSrc, int lumFilterSize,
271                             const int16_t *chrFilter,
272                             const int16_t **chrUSrc,
273                             const int16_t **chrVSrc, int chrFilterSize,
274                             const int16_t **alpSrc, uint8_t **dest,
275                             int dstW, int y);
276
277 struct SwsSlice;
278 struct SwsFilterDescriptor;
279
280 /* This struct should be aligned on at least a 32-byte boundary. */
281 typedef struct SwsContext {
282     /**
283      * info on struct for av_log
284      */
285     const AVClass *av_class;
286
287     /**
288      * Note that src, dst, srcStride, dstStride will be copied in the
289      * sws_scale() wrapper so they can be freely modified here.
290      */
291     SwsFunc swscale;
292     int srcW;                     ///< Width  of source      luma/alpha planes.
293     int srcH;                     ///< Height of source      luma/alpha planes.
294     int dstH;                     ///< Height of destination luma/alpha planes.
295     int chrSrcW;                  ///< Width  of source      chroma     planes.
296     int chrSrcH;                  ///< Height of source      chroma     planes.
297     int chrDstW;                  ///< Width  of destination chroma     planes.
298     int chrDstH;                  ///< Height of destination chroma     planes.
299     int lumXInc, chrXInc;
300     int lumYInc, chrYInc;
301     enum AVPixelFormat dstFormat; ///< Destination pixel format.
302     enum AVPixelFormat srcFormat; ///< Source      pixel format.
303     int dstFormatBpp;             ///< Number of bits per pixel of the destination pixel format.
304     int srcFormatBpp;             ///< Number of bits per pixel of the source      pixel format.
305     int dstBpc, srcBpc;
306     int chrSrcHSubSample;         ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source      image.
307     int chrSrcVSubSample;         ///< Binary logarithm of vertical   subsampling factor between luma/alpha and chroma planes in source      image.
308     int chrDstHSubSample;         ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image.
309     int chrDstVSubSample;         ///< Binary logarithm of vertical   subsampling factor between luma/alpha and chroma planes in destination image.
310     int vChrDrop;                 ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user.
311     int sliceDir;                 ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
312     double param[2];              ///< Input parameters for scaling algorithms that need them.
313
314     /* The cascaded_* fields allow spliting a scaler task into multiple
315      * sequential steps, this is for example used to limit the maximum
316      * downscaling factor that needs to be supported in one scaler.
317      */
318     struct SwsContext *cascaded_context[3];
319     int cascaded_tmpStride[4];
320     uint8_t *cascaded_tmp[4];
321     int cascaded1_tmpStride[4];
322     uint8_t *cascaded1_tmp[4];
323     int cascaded_mainindex;
324
325     double gamma_value;
326     int gamma_flag;
327     int is_internal_gamma;
328     uint16_t *gamma;
329     uint16_t *inv_gamma;
330
331     int numDesc;
332     int descIndex[2];
333     int numSlice;
334     struct SwsSlice *slice;
335     struct SwsFilterDescriptor *desc;
336
337     uint32_t pal_yuv[256];
338     uint32_t pal_rgb[256];
339
340     float uint2float_lut[256];
341
342     /**
343      * @name Scaled horizontal lines ring buffer.
344      * The horizontal scaler keeps just enough scaled lines in a ring buffer
345      * so they may be passed to the vertical scaler. The pointers to the
346      * allocated buffers for each line are duplicated in sequence in the ring
347      * buffer to simplify indexing and avoid wrapping around between lines
348      * inside the vertical scaler code. The wrapping is done before the
349      * vertical scaler is called.
350      */
351     //@{
352     int lastInLumBuf;             ///< Last scaled horizontal luma/alpha line from source in the ring buffer.
353     int lastInChrBuf;             ///< Last scaled horizontal chroma     line from source in the ring buffer.
354     //@}
355
356     uint8_t *formatConvBuffer;
357     int needAlpha;
358
359     /**
360      * @name Horizontal and vertical filters.
361      * To better understand the following fields, here is a pseudo-code of
362      * their usage in filtering a horizontal line:
363      * @code
364      * for (i = 0; i < width; i++) {
365      *     dst[i] = 0;
366      *     for (j = 0; j < filterSize; j++)
367      *         dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ];
368      *     dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point.
369      * }
370      * @endcode
371      */
372     //@{
373     int16_t *hLumFilter;          ///< Array of horizontal filter coefficients for luma/alpha planes.
374     int16_t *hChrFilter;          ///< Array of horizontal filter coefficients for chroma     planes.
375     int16_t *vLumFilter;          ///< Array of vertical   filter coefficients for luma/alpha planes.
376     int16_t *vChrFilter;          ///< Array of vertical   filter coefficients for chroma     planes.
377     int32_t *hLumFilterPos;       ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
378     int32_t *hChrFilterPos;       ///< Array of horizontal filter starting positions for each dst[i] for chroma     planes.
379     int32_t *vLumFilterPos;       ///< Array of vertical   filter starting positions for each dst[i] for luma/alpha planes.
380     int32_t *vChrFilterPos;       ///< Array of vertical   filter starting positions for each dst[i] for chroma     planes.
381     int hLumFilterSize;           ///< Horizontal filter size for luma/alpha pixels.
382     int hChrFilterSize;           ///< Horizontal filter size for chroma     pixels.
383     int vLumFilterSize;           ///< Vertical   filter size for luma/alpha pixels.
384     int vChrFilterSize;           ///< Vertical   filter size for chroma     pixels.
385     //@}
386
387     int lumMmxextFilterCodeSize;  ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for luma/alpha planes.
388     int chrMmxextFilterCodeSize;  ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for chroma planes.
389     uint8_t *lumMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for luma/alpha planes.
390     uint8_t *chrMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for chroma planes.
391
392     int canMMXEXTBeUsed;
393     int warned_unuseable_bilinear;
394
395     int dstY;                     ///< Last destination vertical line output from last slice.
396     int flags;                    ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
397     void *yuvTable;             // pointer to the yuv->rgb table start so it can be freed()
398     // alignment ensures the offset can be added in a single
399     // instruction on e.g. ARM
400     DECLARE_ALIGNED(16, int, table_gV)[256 + 2*YUVRGB_TABLE_HEADROOM];
401     uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM];
402     uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM];
403     uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM];
404     DECLARE_ALIGNED(16, int32_t, input_rgb2yuv_table)[16+40*4]; // This table can contain both C and SIMD formatted values, the C vales are always at the XY_IDX points
405 #define RY_IDX 0
406 #define GY_IDX 1
407 #define BY_IDX 2
408 #define RU_IDX 3
409 #define GU_IDX 4
410 #define BU_IDX 5
411 #define RV_IDX 6
412 #define GV_IDX 7
413 #define BV_IDX 8
414 #define RGB2YUV_SHIFT 15
415
416     int *dither_error[4];
417
418     //Colorspace stuff
419     int contrast, brightness, saturation;    // for sws_getColorspaceDetails
420     int srcColorspaceTable[4];
421     int dstColorspaceTable[4];
422     int srcRange;                 ///< 0 = MPG YUV range, 1 = JPG YUV range (source      image).
423     int dstRange;                 ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image).
424     int src0Alpha;
425     int dst0Alpha;
426     int srcXYZ;
427     int dstXYZ;
428     int src_h_chr_pos;
429     int dst_h_chr_pos;
430     int src_v_chr_pos;
431     int dst_v_chr_pos;
432     int yuv2rgb_y_offset;
433     int yuv2rgb_y_coeff;
434     int yuv2rgb_v2r_coeff;
435     int yuv2rgb_v2g_coeff;
436     int yuv2rgb_u2g_coeff;
437     int yuv2rgb_u2b_coeff;
438
439 #define RED_DITHER            "0*8"
440 #define GREEN_DITHER          "1*8"
441 #define BLUE_DITHER           "2*8"
442 #define Y_COEFF               "3*8"
443 #define VR_COEFF              "4*8"
444 #define UB_COEFF              "5*8"
445 #define VG_COEFF              "6*8"
446 #define UG_COEFF              "7*8"
447 #define Y_OFFSET              "8*8"
448 #define U_OFFSET              "9*8"
449 #define V_OFFSET              "10*8"
450 #define LUM_MMX_FILTER_OFFSET "11*8"
451 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)
452 #define DSTW_OFFSET           "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2"
453 #define ESP_OFFSET            "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+8"
454 #define VROUNDER_OFFSET       "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+16"
455 #define U_TEMP                "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+24"
456 #define V_TEMP                "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+32"
457 #define Y_TEMP                "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+40"
458 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+48"
459 #define UV_OFF_PX             "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+48"
460 #define UV_OFF_BYTE           "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+56"
461 #define DITHER16              "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+64"
462 #define DITHER32              "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+80"
463 #define DITHER32_INT          (11*8+4*4*MAX_FILTER_SIZE*3+80) // value equal to above, used for checking that the struct hasn't been changed by mistake
464
465     DECLARE_ALIGNED(8, uint64_t, redDither);
466     DECLARE_ALIGNED(8, uint64_t, greenDither);
467     DECLARE_ALIGNED(8, uint64_t, blueDither);
468
469     DECLARE_ALIGNED(8, uint64_t, yCoeff);
470     DECLARE_ALIGNED(8, uint64_t, vrCoeff);
471     DECLARE_ALIGNED(8, uint64_t, ubCoeff);
472     DECLARE_ALIGNED(8, uint64_t, vgCoeff);
473     DECLARE_ALIGNED(8, uint64_t, ugCoeff);
474     DECLARE_ALIGNED(8, uint64_t, yOffset);
475     DECLARE_ALIGNED(8, uint64_t, uOffset);
476     DECLARE_ALIGNED(8, uint64_t, vOffset);
477     int32_t lumMmxFilter[4 * MAX_FILTER_SIZE];
478     int32_t chrMmxFilter[4 * MAX_FILTER_SIZE];
479     int dstW;                     ///< Width  of destination luma/alpha planes.
480     DECLARE_ALIGNED(8, uint64_t, esp);
481     DECLARE_ALIGNED(8, uint64_t, vRounder);
482     DECLARE_ALIGNED(8, uint64_t, u_temp);
483     DECLARE_ALIGNED(8, uint64_t, v_temp);
484     DECLARE_ALIGNED(8, uint64_t, y_temp);
485     int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
486     // alignment of these values is not necessary, but merely here
487     // to maintain the same offset across x8632 and x86-64. Once we
488     // use proper offset macros in the asm, they can be removed.
489     DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes
490     DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes
491     DECLARE_ALIGNED(8, uint16_t, dither16)[8];
492     DECLARE_ALIGNED(8, uint32_t, dither32)[8];
493
494     const uint8_t *chrDither8, *lumDither8;
495
496 #if HAVE_ALTIVEC
497     vector signed short   CY;
498     vector signed short   CRV;
499     vector signed short   CBU;
500     vector signed short   CGU;
501     vector signed short   CGV;
502     vector signed short   OY;
503     vector unsigned short CSHIFT;
504     vector signed short  *vYCoeffsBank, *vCCoeffsBank;
505 #endif
506
507     int use_mmx_vfilter;
508
509 /* pre defined color-spaces gamma */
510 #define XYZ_GAMMA (2.6f)
511 #define RGB_GAMMA (2.2f)
512     int16_t *xyzgamma;
513     int16_t *rgbgamma;
514     int16_t *xyzgammainv;
515     int16_t *rgbgammainv;
516     int16_t xyz2rgb_matrix[3][4];
517     int16_t rgb2xyz_matrix[3][4];
518
519     /* function pointers for swscale() */
520     yuv2planar1_fn yuv2plane1;
521     yuv2planarX_fn yuv2planeX;
522     yuv2interleavedX_fn yuv2nv12cX;
523     yuv2packed1_fn yuv2packed1;
524     yuv2packed2_fn yuv2packed2;
525     yuv2packedX_fn yuv2packedX;
526     yuv2anyX_fn yuv2anyX;
527
528     /// Unscaled conversion of luma plane to YV12 for horizontal scaler.
529     void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
530                       int width, uint32_t *pal);
531     /// Unscaled conversion of alpha plane to YV12 for horizontal scaler.
532     void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
533                       int width, uint32_t *pal);
534     /// Unscaled conversion of chroma planes to YV12 for horizontal scaler.
535     void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
536                       const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
537                       int width, uint32_t *pal);
538
539     /**
540      * Functions to read planar input, such as planar RGB, and convert
541      * internally to Y/UV/A.
542      */
543     /** @{ */
544     void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv);
545     void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
546                           int width, int32_t *rgb2yuv);
547     void (*readAlpPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv);
548     /** @} */
549
550     /**
551      * Scale one horizontal line of input data using a bilinear filter
552      * to produce one line of output data. Compared to SwsContext->hScale(),
553      * please take note of the following caveats when using these:
554      * - Scaling is done using only 7 bits instead of 14-bit coefficients.
555      * - You can use no more than 5 input pixels to produce 4 output
556      *   pixels. Therefore, this filter should not be used for downscaling
557      *   by more than ~20% in width (because that equals more than 5/4th
558      *   downscaling and thus more than 5 pixels input per 4 pixels output).
559      * - In general, bilinear filters create artifacts during downscaling
560      *   (even when <20%), because one output pixel will span more than one
561      *   input pixel, and thus some pixels will need edges of both neighbor
562      *   pixels to interpolate the output pixel. Since you can use at most
563      *   two input pixels per output pixel in bilinear scaling, this is
564      *   impossible and thus downscaling by any size will create artifacts.
565      * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR
566      * in SwsContext->flags.
567      */
568     /** @{ */
569     void (*hyscale_fast)(struct SwsContext *c,
570                          int16_t *dst, int dstWidth,
571                          const uint8_t *src, int srcW, int xInc);
572     void (*hcscale_fast)(struct SwsContext *c,
573                          int16_t *dst1, int16_t *dst2, int dstWidth,
574                          const uint8_t *src1, const uint8_t *src2,
575                          int srcW, int xInc);
576     /** @} */
577
578     /**
579      * Scale one horizontal line of input data using a filter over the input
580      * lines, to produce one (differently sized) line of output data.
581      *
582      * @param dst        pointer to destination buffer for horizontally scaled
583      *                   data. If the number of bits per component of one
584      *                   destination pixel (SwsContext->dstBpc) is <= 10, data
585      *                   will be 15 bpc in 16 bits (int16_t) width. Else (i.e.
586      *                   SwsContext->dstBpc == 16), data will be 19bpc in
587      *                   32 bits (int32_t) width.
588      * @param dstW       width of destination image
589      * @param src        pointer to source data to be scaled. If the number of
590      *                   bits per component of a source pixel (SwsContext->srcBpc)
591      *                   is 8, this is 8bpc in 8 bits (uint8_t) width. Else
592      *                   (i.e. SwsContext->dstBpc > 8), this is native depth
593      *                   in 16 bits (uint16_t) width. In other words, for 9-bit
594      *                   YUV input, this is 9bpc, for 10-bit YUV input, this is
595      *                   10bpc, and for 16-bit RGB or YUV, this is 16bpc.
596      * @param filter     filter coefficients to be used per output pixel for
597      *                   scaling. This contains 14bpp filtering coefficients.
598      *                   Guaranteed to contain dstW * filterSize entries.
599      * @param filterPos  position of the first input pixel to be used for
600      *                   each output pixel during scaling. Guaranteed to
601      *                   contain dstW entries.
602      * @param filterSize the number of input coefficients to be used (and
603      *                   thus the number of input pixels to be used) for
604      *                   creating a single output pixel. Is aligned to 4
605      *                   (and input coefficients thus padded with zeroes)
606      *                   to simplify creating SIMD code.
607      */
608     /** @{ */
609     void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
610                     const uint8_t *src, const int16_t *filter,
611                     const int32_t *filterPos, int filterSize);
612     void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
613                     const uint8_t *src, const int16_t *filter,
614                     const int32_t *filterPos, int filterSize);
615     /** @} */
616
617     /// Color range conversion function for luma plane if needed.
618     void (*lumConvertRange)(int16_t *dst, int width);
619     /// Color range conversion function for chroma planes if needed.
620     void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
621
622     int needs_hcscale; ///< Set if there are chroma planes to be converted.
623
624     SwsDither dither;
625
626     SwsAlphaBlend alphablend;
627 } SwsContext;
628 //FIXME check init (where 0)
629
630 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
631 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
632                              int fullRange, int brightness,
633                              int contrast, int saturation);
634 void ff_yuv2rgb_init_tables_ppc(SwsContext *c, const int inv_table[4],
635                                 int brightness, int contrast, int saturation);
636
637 void ff_updateMMXDitherTables(SwsContext *c, int dstY);
638
639 av_cold void ff_sws_init_range_convert(SwsContext *c);
640
641 SwsFunc ff_yuv2rgb_init_x86(SwsContext *c);
642 SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c);
643
644 static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
645 {
646     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
647     av_assert0(desc);
648     return desc->comp[0].depth == 16;
649 }
650
651 static av_always_inline int is32BPS(enum AVPixelFormat pix_fmt)
652 {
653     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
654     av_assert0(desc);
655     return desc->comp[0].depth == 32;
656 }
657
658 static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
659 {
660     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
661     av_assert0(desc);
662     return desc->comp[0].depth >= 9 && desc->comp[0].depth <= 14;
663 }
664
665 static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
666 {
667     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
668     av_assert0(desc);
669     return desc->flags & AV_PIX_FMT_FLAG_BE;
670 }
671
672 static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
673 {
674     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
675     av_assert0(desc);
676     return !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
677 }
678
679 static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
680 {
681     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
682     av_assert0(desc);
683     return ((desc->flags & AV_PIX_FMT_FLAG_PLANAR) && isYUV(pix_fmt));
684 }
685
686 /*
687  * Identity semi-planar YUV formats. Specifically, those are YUV formats
688  * where the second and third components (U & V) are on the same plane.
689  */
690 static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
691 {
692     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
693     av_assert0(desc);
694     return (isPlanarYUV(pix_fmt) && desc->comp[1].plane == desc->comp[2].plane);
695 }
696
697 static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
698 {
699     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
700     av_assert0(desc);
701     return (desc->flags & AV_PIX_FMT_FLAG_RGB);
702 }
703
704 static av_always_inline int isGray(enum AVPixelFormat pix_fmt)
705 {
706     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
707     av_assert0(desc);
708     return !(desc->flags & AV_PIX_FMT_FLAG_PAL) &&
709            !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
710            desc->nb_components <= 2 &&
711            pix_fmt != AV_PIX_FMT_MONOBLACK &&
712            pix_fmt != AV_PIX_FMT_MONOWHITE;
713 }
714
715 static av_always_inline int isRGBinInt(enum AVPixelFormat pix_fmt)
716 {
717     return pix_fmt == AV_PIX_FMT_RGB48BE     ||
718            pix_fmt == AV_PIX_FMT_RGB48LE     ||
719            pix_fmt == AV_PIX_FMT_RGB32       ||
720            pix_fmt == AV_PIX_FMT_RGB32_1     ||
721            pix_fmt == AV_PIX_FMT_RGB24       ||
722            pix_fmt == AV_PIX_FMT_RGB565BE    ||
723            pix_fmt == AV_PIX_FMT_RGB565LE    ||
724            pix_fmt == AV_PIX_FMT_RGB555BE    ||
725            pix_fmt == AV_PIX_FMT_RGB555LE    ||
726            pix_fmt == AV_PIX_FMT_RGB444BE    ||
727            pix_fmt == AV_PIX_FMT_RGB444LE    ||
728            pix_fmt == AV_PIX_FMT_RGB8        ||
729            pix_fmt == AV_PIX_FMT_RGB4        ||
730            pix_fmt == AV_PIX_FMT_RGB4_BYTE   ||
731            pix_fmt == AV_PIX_FMT_RGBA64BE    ||
732            pix_fmt == AV_PIX_FMT_RGBA64LE    ||
733            pix_fmt == AV_PIX_FMT_MONOBLACK   ||
734            pix_fmt == AV_PIX_FMT_MONOWHITE;
735 }
736
737 static av_always_inline int isBGRinInt(enum AVPixelFormat pix_fmt)
738 {
739     return pix_fmt == AV_PIX_FMT_BGR48BE     ||
740            pix_fmt == AV_PIX_FMT_BGR48LE     ||
741            pix_fmt == AV_PIX_FMT_BGR32       ||
742            pix_fmt == AV_PIX_FMT_BGR32_1     ||
743            pix_fmt == AV_PIX_FMT_BGR24       ||
744            pix_fmt == AV_PIX_FMT_BGR565BE    ||
745            pix_fmt == AV_PIX_FMT_BGR565LE    ||
746            pix_fmt == AV_PIX_FMT_BGR555BE    ||
747            pix_fmt == AV_PIX_FMT_BGR555LE    ||
748            pix_fmt == AV_PIX_FMT_BGR444BE    ||
749            pix_fmt == AV_PIX_FMT_BGR444LE    ||
750            pix_fmt == AV_PIX_FMT_BGR8        ||
751            pix_fmt == AV_PIX_FMT_BGR4        ||
752            pix_fmt == AV_PIX_FMT_BGR4_BYTE   ||
753            pix_fmt == AV_PIX_FMT_BGRA64BE    ||
754            pix_fmt == AV_PIX_FMT_BGRA64LE    ||
755            pix_fmt == AV_PIX_FMT_MONOBLACK   ||
756            pix_fmt == AV_PIX_FMT_MONOWHITE;
757 }
758
759 static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
760 {
761     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
762     av_assert0(desc);
763     return !!(desc->flags & AV_PIX_FMT_FLAG_BAYER);
764 }
765
766 static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
767 {
768     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
769     av_assert0(desc);
770     return (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
771             pix_fmt == AV_PIX_FMT_MONOBLACK || pix_fmt == AV_PIX_FMT_MONOWHITE;
772 }
773
774 static av_always_inline int isFloat(enum AVPixelFormat pix_fmt)
775 {
776     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
777     av_assert0(desc);
778     return desc->flags & AV_PIX_FMT_FLAG_FLOAT;
779 }
780
781 static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
782 {
783     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
784     av_assert0(desc);
785     if (pix_fmt == AV_PIX_FMT_PAL8)
786         return 1;
787     return desc->flags & AV_PIX_FMT_FLAG_ALPHA;
788 }
789
790 static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
791 {
792     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
793     av_assert0(desc);
794     return (desc->nb_components >= 2 && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) ||
795             pix_fmt == AV_PIX_FMT_PAL8 ||
796             pix_fmt == AV_PIX_FMT_MONOBLACK || pix_fmt == AV_PIX_FMT_MONOWHITE;
797 }
798
799 static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
800 {
801     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
802     av_assert0(desc);
803     return (desc->nb_components >= 2 && (desc->flags & AV_PIX_FMT_FLAG_PLANAR));
804 }
805
806 static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
807 {
808     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
809     av_assert0(desc);
810     return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) == AV_PIX_FMT_FLAG_RGB);
811 }
812
813 static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
814 {
815     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
816     av_assert0(desc);
817     return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) ==
818             (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB));
819 }
820
821 static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
822 {
823     switch (pix_fmt) {
824     case AV_PIX_FMT_PAL8:
825     case AV_PIX_FMT_BGR4_BYTE:
826     case AV_PIX_FMT_BGR8:
827     case AV_PIX_FMT_GRAY8:
828     case AV_PIX_FMT_RGB4_BYTE:
829     case AV_PIX_FMT_RGB8:
830         return 1;
831     default:
832         return 0;
833     }
834 }
835
836 extern const uint64_t ff_dither4[2];
837 extern const uint64_t ff_dither8[2];
838
839 extern const uint8_t ff_dither_2x2_4[3][8];
840 extern const uint8_t ff_dither_2x2_8[3][8];
841 extern const uint8_t ff_dither_4x4_16[5][8];
842 extern const uint8_t ff_dither_8x8_32[9][8];
843 extern const uint8_t ff_dither_8x8_73[9][8];
844 extern const uint8_t ff_dither_8x8_128[9][8];
845 extern const uint8_t ff_dither_8x8_220[9][8];
846
847 extern const int32_t ff_yuv2rgb_coeffs[11][4];
848
849 extern const AVClass ff_sws_context_class;
850
851 /**
852  * Set c->swscale to an unscaled converter if one exists for the specific
853  * source and destination formats, bit depths, flags, etc.
854  */
855 void ff_get_unscaled_swscale(SwsContext *c);
856 void ff_get_unscaled_swscale_ppc(SwsContext *c);
857 void ff_get_unscaled_swscale_arm(SwsContext *c);
858 void ff_get_unscaled_swscale_aarch64(SwsContext *c);
859
860 /**
861  * Return function pointer to fastest main scaler path function depending
862  * on architecture and available optimizations.
863  */
864 SwsFunc ff_getSwsFunc(SwsContext *c);
865
866 void ff_sws_init_input_funcs(SwsContext *c);
867 void ff_sws_init_output_funcs(SwsContext *c,
868                               yuv2planar1_fn *yuv2plane1,
869                               yuv2planarX_fn *yuv2planeX,
870                               yuv2interleavedX_fn *yuv2nv12cX,
871                               yuv2packed1_fn *yuv2packed1,
872                               yuv2packed2_fn *yuv2packed2,
873                               yuv2packedX_fn *yuv2packedX,
874                               yuv2anyX_fn *yuv2anyX);
875 void ff_sws_init_swscale_ppc(SwsContext *c);
876 void ff_sws_init_swscale_vsx(SwsContext *c);
877 void ff_sws_init_swscale_x86(SwsContext *c);
878 void ff_sws_init_swscale_aarch64(SwsContext *c);
879 void ff_sws_init_swscale_arm(SwsContext *c);
880
881 void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
882                        const uint8_t *src, int srcW, int xInc);
883 void ff_hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
884                        int dstWidth, const uint8_t *src1,
885                        const uint8_t *src2, int srcW, int xInc);
886 int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode,
887                            int16_t *filter, int32_t *filterPos,
888                            int numSplits);
889 void ff_hyscale_fast_mmxext(SwsContext *c, int16_t *dst,
890                             int dstWidth, const uint8_t *src,
891                             int srcW, int xInc);
892 void ff_hcscale_fast_mmxext(SwsContext *c, int16_t *dst1, int16_t *dst2,
893                             int dstWidth, const uint8_t *src1,
894                             const uint8_t *src2, int srcW, int xInc);
895
896 /**
897  * Allocate and return an SwsContext.
898  * This is like sws_getContext() but does not perform the init step, allowing
899  * the user to set additional AVOptions.
900  *
901  * @see sws_getContext()
902  */
903 struct SwsContext *sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
904                                       int dstW, int dstH, enum AVPixelFormat dstFormat,
905                                       int flags, const double *param);
906
907 int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
908                           int srcStride[], int srcSliceY, int srcSliceH,
909                           uint8_t *dst[], int dstStride[]);
910
911 static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y,
912                                int alpha, int bits, const int big_endian)
913 {
914     int i, j;
915     uint8_t *ptr = plane + stride * y;
916     int v = alpha ? 0xFFFF>>(16-bits) : (1<<(bits-1));
917     for (i = 0; i < height; i++) {
918 #define FILL(wfunc) \
919         for (j = 0; j < width; j++) {\
920             wfunc(ptr+2*j, v);\
921         }
922         if (big_endian) {
923             FILL(AV_WB16);
924         } else {
925             FILL(AV_WL16);
926         }
927         ptr += stride;
928     }
929 #undef FILL
930 }
931
932 static inline void fillPlane32(uint8_t *plane, int stride, int width, int height, int y,
933                                int alpha, int bits, const int big_endian, int is_float)
934 {
935     int i, j;
936     uint8_t *ptr = plane + stride * y;
937     uint32_t v;
938     uint32_t onef32 = 0x3f800000;
939     if (is_float)
940         v = alpha ? onef32 : 0;
941     else
942         v = alpha ? 0xFFFFFFFF>>(32-bits) : (1<<(bits-1));
943
944     for (i = 0; i < height; i++) {
945 #define FILL(wfunc) \
946         for (j = 0; j < width; j++) {\
947             wfunc(ptr+4*j, v);\
948         }
949         if (big_endian) {
950             FILL(AV_WB32);
951         } else {
952             FILL(AV_WL32);
953         }
954         ptr += stride;
955     }
956 #undef FILL
957 }
958
959
960 #define MAX_SLICE_PLANES 4
961
962 /// Slice plane
963 typedef struct SwsPlane
964 {
965     int available_lines;    ///< max number of lines that can be hold by this plane
966     int sliceY;             ///< index of first line
967     int sliceH;             ///< number of lines
968     uint8_t **line;         ///< line buffer
969     uint8_t **tmp;          ///< Tmp line buffer used by mmx code
970 } SwsPlane;
971
972 /**
973  * Struct which defines a slice of an image to be scaled or an output for
974  * a scaled slice.
975  * A slice can also be used as intermediate ring buffer for scaling steps.
976  */
977 typedef struct SwsSlice
978 {
979     int width;              ///< Slice line width
980     int h_chr_sub_sample;   ///< horizontal chroma subsampling factor
981     int v_chr_sub_sample;   ///< vertical chroma subsampling factor
982     int is_ring;            ///< flag to identify if this slice is a ring buffer
983     int should_free_lines;  ///< flag to identify if there are dynamic allocated lines
984     enum AVPixelFormat fmt; ///< planes pixel format
985     SwsPlane plane[MAX_SLICE_PLANES];   ///< color planes
986 } SwsSlice;
987
988 /**
989  * Struct which holds all necessary data for processing a slice.
990  * A processing step can be a color conversion or horizontal/vertical scaling.
991  */
992 typedef struct SwsFilterDescriptor
993 {
994     SwsSlice *src;  ///< Source slice
995     SwsSlice *dst;  ///< Output slice
996
997     int alpha;      ///< Flag for processing alpha channel
998     void *instance; ///< Filter instance data
999
1000     /// Function for processing input slice sliceH lines starting from line sliceY
1001     int (*process)(SwsContext *c, struct SwsFilterDescriptor *desc, int sliceY, int sliceH);
1002 } SwsFilterDescriptor;
1003
1004 // warp input lines in the form (src + width*i + j) to slice format (line[i][j])
1005 // relative=true means first line src[x][0] otherwise first line is src[x][lum/crh Y]
1006 int ff_init_slice_from_src(SwsSlice * s, uint8_t *src[4], int stride[4], int srcW, int lumY, int lumH, int chrY, int chrH, int relative);
1007
1008 // Initialize scaler filter descriptor chain
1009 int ff_init_filters(SwsContext *c);
1010
1011 // Free all filter data
1012 int ff_free_filters(SwsContext *c);
1013
1014 /*
1015  function for applying ring buffer logic into slice s
1016  It checks if the slice can hold more @lum lines, if yes
1017  do nothing otherwise remove @lum least used lines.
1018  It applies the same procedure for @chr lines.
1019 */
1020 int ff_rotate_slice(SwsSlice *s, int lum, int chr);
1021
1022 /// initializes gamma conversion descriptor
1023 int ff_init_gamma_convert(SwsFilterDescriptor *desc, SwsSlice * src, uint16_t *table);
1024
1025 /// initializes lum pixel format conversion descriptor
1026 int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
1027
1028 /// initializes lum horizontal scaling descriptor
1029 int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
1030
1031 /// initializes chr pixel format conversion descriptor
1032 int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
1033
1034 /// initializes chr horizontal scaling descriptor
1035 int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
1036
1037 int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst);
1038
1039 /// initializes vertical scaling descriptors
1040 int ff_init_vscale(SwsContext *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst);
1041
1042 /// setup vertical scaler functions
1043 void ff_init_vscale_pfn(SwsContext *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX,
1044     yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2,
1045     yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx);
1046
1047 //number of extra lines to process
1048 #define MAX_LINES_AHEAD 4
1049
1050 #endif /* SWSCALE_SWSCALE_INTERNAL_H */