OSDN Git Service

Merge remote-tracking branch 'qatar/master'
[coroid/ffmpeg_saccubus.git] / libswscale / swscale_internal.h
1 /*
2  * Copyright (C) 2001-2003 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
26 #if HAVE_ALTIVEC_H
27 #include <altivec.h>
28 #endif
29
30 #include "libavutil/avutil.h"
31
32 #define STR(s)         AV_TOSTRING(s) //AV_STRINGIFY is too long
33
34 #define FAST_BGR2YV12 //use 7-bit instead of 15-bit coefficients
35
36 #define MAX_FILTER_SIZE 256
37
38 #define DITHER1XBPP
39
40 #if HAVE_BIGENDIAN
41 #define ALT32_CORR (-1)
42 #else
43 #define ALT32_CORR   1
44 #endif
45
46 #if ARCH_X86_64
47 #   define APCK_PTR2 8
48 #   define APCK_COEF 16
49 #   define APCK_SIZE 24
50 #else
51 #   define APCK_PTR2 4
52 #   define APCK_COEF 8
53 #   define APCK_SIZE 16
54 #endif
55
56 struct SwsContext;
57
58 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[],
59                        int srcStride[], int srcSliceY, int srcSliceH,
60                        uint8_t* dst[], int dstStride[]);
61
62 typedef void (*yuv2planar1_fn) (struct SwsContext *c,
63                                 const int16_t *lumSrc, const int16_t *chrUSrc,
64                                 const int16_t *chrVSrc, const int16_t *alpSrc,
65                                 uint8_t *dest,
66                                 uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
67                                 int dstW, int chrDstW, const uint8_t *lumDither, const uint8_t *chrDither);
68 typedef void (*yuv2planarX_fn) (struct SwsContext *c,
69                                 const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
70                                 const int16_t *chrFilter, const int16_t **chrUSrc,
71                                 const int16_t **chrVSrc, int chrFilterSize,
72                                 const int16_t **alpSrc,
73                                 uint8_t *dest,
74                                 uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
75                                 int dstW, int chrDstW, const uint8_t *lumDither, const uint8_t *chrDither);
76 typedef void (*yuv2packed1_fn) (struct SwsContext *c,
77                                 const uint16_t *buf0,
78                                 const uint16_t *ubuf0, const uint16_t *ubuf1,
79                                 const uint16_t *vbuf0, const uint16_t *vbuf1,
80                                 const uint16_t *abuf0,
81                                 uint8_t *dest,
82                                 int dstW, int uvalpha, int dstFormat, int flags, int y);
83 typedef void (*yuv2packed2_fn) (struct SwsContext *c,
84                                 const uint16_t *buf0, const uint16_t *buf1,
85                                 const uint16_t *ubuf0, const uint16_t *ubuf1,
86                                 const uint16_t *vbuf0, const uint16_t *vbuf1,
87                                 const uint16_t *abuf0, const uint16_t *abuf1,
88                                 uint8_t *dest,
89                                 int dstW, int yalpha, int uvalpha, int y);
90 typedef void (*yuv2packedX_fn) (struct SwsContext *c,
91                                 const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
92                                 const int16_t *chrFilter, const int16_t **chrUSrc,
93                                 const int16_t **chrVSrc, int chrFilterSize,
94                                 const int16_t **alpSrc, uint8_t *dest,
95                                 int dstW, int dstY);
96
97 /* This struct should be aligned on at least a 32-byte boundary. */
98 typedef struct SwsContext {
99     /**
100      * info on struct for av_log
101      */
102     const AVClass *av_class;
103
104     /**
105      * Note that src, dst, srcStride, dstStride will be copied in the
106      * sws_scale() wrapper so they can be freely modified here.
107      */
108     SwsFunc swScale;
109     int srcW;                     ///< Width  of source      luma/alpha planes.
110     int srcH;                     ///< Height of source      luma/alpha planes.
111     int dstH;                     ///< Height of destination luma/alpha planes.
112     int chrSrcW;                  ///< Width  of source      chroma     planes.
113     int chrSrcH;                  ///< Height of source      chroma     planes.
114     int chrDstW;                  ///< Width  of destination chroma     planes.
115     int chrDstH;                  ///< Height of destination chroma     planes.
116     int lumXInc, chrXInc;
117     int lumYInc, chrYInc;
118     enum PixelFormat dstFormat;   ///< Destination pixel format.
119     enum PixelFormat srcFormat;   ///< Source      pixel format.
120     int dstFormatBpp;             ///< Number of bits per pixel of the destination pixel format.
121     int srcFormatBpp;             ///< Number of bits per pixel of the source      pixel format.
122     int chrSrcHSubSample;         ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source      image.
123     int chrSrcVSubSample;         ///< Binary logarithm of vertical   subsampling factor between luma/alpha and chroma planes in source      image.
124     int chrDstHSubSample;         ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image.
125     int chrDstVSubSample;         ///< Binary logarithm of vertical   subsampling factor between luma/alpha and chroma planes in destination image.
126     int vChrDrop;                 ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user.
127     int sliceDir;                 ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
128     double param[2];              ///< Input parameters for scaling algorithms that need them.
129
130     uint32_t pal_yuv[256];
131     uint32_t pal_rgb[256];
132
133     /**
134      * @name Scaled horizontal lines ring buffer.
135      * The horizontal scaler keeps just enough scaled lines in a ring buffer
136      * so they may be passed to the vertical scaler. The pointers to the
137      * allocated buffers for each line are duplicated in sequence in the ring
138      * buffer to simplify indexing and avoid wrapping around between lines
139      * inside the vertical scaler code. The wrapping is done before the
140      * vertical scaler is called.
141      */
142     //@{
143     int16_t **lumPixBuf;          ///< Ring buffer for scaled horizontal luma   plane lines to be fed to the vertical scaler.
144     int16_t **chrUPixBuf;         ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
145     int16_t **chrVPixBuf;         ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
146     int16_t **alpPixBuf;          ///< Ring buffer for scaled horizontal alpha  plane lines to be fed to the vertical scaler.
147     int       vLumBufSize;        ///< Number of vertical luma/alpha lines allocated in the ring buffer.
148     int       vChrBufSize;        ///< Number of vertical chroma     lines allocated in the ring buffer.
149     int       lastInLumBuf;       ///< Last scaled horizontal luma/alpha line from source in the ring buffer.
150     int       lastInChrBuf;       ///< Last scaled horizontal chroma     line from source in the ring buffer.
151     int       lumBufIndex;        ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source.
152     int       chrBufIndex;        ///< Index in ring buffer of the last scaled horizontal chroma     line from source.
153     //@}
154
155     uint8_t *formatConvBuffer;
156
157     /**
158      * @name Horizontal and vertical filters.
159      * To better understand the following fields, here is a pseudo-code of
160      * their usage in filtering a horizontal line:
161      * @code
162      * for (i = 0; i < width; i++) {
163      *     dst[i] = 0;
164      *     for (j = 0; j < filterSize; j++)
165      *         dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ];
166      *     dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point.
167      * }
168      * @endcode
169      */
170     //@{
171     int16_t *hLumFilter;          ///< Array of horizontal filter coefficients for luma/alpha planes.
172     int16_t *hChrFilter;          ///< Array of horizontal filter coefficients for chroma     planes.
173     int16_t *vLumFilter;          ///< Array of vertical   filter coefficients for luma/alpha planes.
174     int16_t *vChrFilter;          ///< Array of vertical   filter coefficients for chroma     planes.
175     int16_t *hLumFilterPos;       ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
176     int16_t *hChrFilterPos;       ///< Array of horizontal filter starting positions for each dst[i] for chroma     planes.
177     int16_t *vLumFilterPos;       ///< Array of vertical   filter starting positions for each dst[i] for luma/alpha planes.
178     int16_t *vChrFilterPos;       ///< Array of vertical   filter starting positions for each dst[i] for chroma     planes.
179     int      hLumFilterSize;      ///< Horizontal filter size for luma/alpha pixels.
180     int      hChrFilterSize;      ///< Horizontal filter size for chroma     pixels.
181     int      vLumFilterSize;      ///< Vertical   filter size for luma/alpha pixels.
182     int      vChrFilterSize;      ///< Vertical   filter size for chroma     pixels.
183     //@}
184
185     int lumMmx2FilterCodeSize;    ///< Runtime-generated MMX2 horizontal fast bilinear scaler code size for luma/alpha planes.
186     int chrMmx2FilterCodeSize;    ///< Runtime-generated MMX2 horizontal fast bilinear scaler code size for chroma     planes.
187     uint8_t *lumMmx2FilterCode;   ///< Runtime-generated MMX2 horizontal fast bilinear scaler code for luma/alpha planes.
188     uint8_t *chrMmx2FilterCode;   ///< Runtime-generated MMX2 horizontal fast bilinear scaler code for chroma     planes.
189
190     int canMMX2BeUsed;
191
192     int dstY;                     ///< Last destination vertical line output from last slice.
193     int flags;                    ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
194     void * yuvTable;            // pointer to the yuv->rgb table start so it can be freed()
195     uint8_t * table_rV[256];
196     uint8_t * table_gU[256];
197     int    table_gV[256];
198     uint8_t * table_bU[256];
199
200     //Colorspace stuff
201     int contrast, brightness, saturation;    // for sws_getColorspaceDetails
202     int srcColorspaceTable[4];
203     int dstColorspaceTable[4];
204     int srcRange;                 ///< 0 = MPG YUV range, 1 = JPG YUV range (source      image).
205     int dstRange;                 ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image).
206     int yuv2rgb_y_offset;
207     int yuv2rgb_y_coeff;
208     int yuv2rgb_v2r_coeff;
209     int yuv2rgb_v2g_coeff;
210     int yuv2rgb_u2g_coeff;
211     int yuv2rgb_u2b_coeff;
212
213 #define RED_DITHER            "0*8"
214 #define GREEN_DITHER          "1*8"
215 #define BLUE_DITHER           "2*8"
216 #define Y_COEFF               "3*8"
217 #define VR_COEFF              "4*8"
218 #define UB_COEFF              "5*8"
219 #define VG_COEFF              "6*8"
220 #define UG_COEFF              "7*8"
221 #define Y_OFFSET              "8*8"
222 #define U_OFFSET              "9*8"
223 #define V_OFFSET              "10*8"
224 #define LUM_MMX_FILTER_OFFSET "11*8"
225 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
226 #define DSTW_OFFSET           "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
227 #define ESP_OFFSET            "11*8+4*4*256*2+8"
228 #define VROUNDER_OFFSET       "11*8+4*4*256*2+16"
229 #define U_TEMP                "11*8+4*4*256*2+24"
230 #define V_TEMP                "11*8+4*4*256*2+32"
231 #define Y_TEMP                "11*8+4*4*256*2+40"
232 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
233 #define UV_OFF                "11*8+4*4*256*3+48"
234 #define UV_OFFx2              "11*8+4*4*256*3+56"
235 #define DITHER16              "11*8+4*4*256*3+64"
236 #define DITHER32              "11*8+4*4*256*3+64+16"
237
238     DECLARE_ALIGNED(8, uint64_t, redDither);
239     DECLARE_ALIGNED(8, uint64_t, greenDither);
240     DECLARE_ALIGNED(8, uint64_t, blueDither);
241
242     DECLARE_ALIGNED(8, uint64_t, yCoeff);
243     DECLARE_ALIGNED(8, uint64_t, vrCoeff);
244     DECLARE_ALIGNED(8, uint64_t, ubCoeff);
245     DECLARE_ALIGNED(8, uint64_t, vgCoeff);
246     DECLARE_ALIGNED(8, uint64_t, ugCoeff);
247     DECLARE_ALIGNED(8, uint64_t, yOffset);
248     DECLARE_ALIGNED(8, uint64_t, uOffset);
249     DECLARE_ALIGNED(8, uint64_t, vOffset);
250     int32_t  lumMmxFilter[4*MAX_FILTER_SIZE];
251     int32_t  chrMmxFilter[4*MAX_FILTER_SIZE];
252     int dstW;                     ///< Width  of destination luma/alpha planes.
253     DECLARE_ALIGNED(8, uint64_t, esp);
254     DECLARE_ALIGNED(8, uint64_t, vRounder);
255     DECLARE_ALIGNED(8, uint64_t, u_temp);
256     DECLARE_ALIGNED(8, uint64_t, v_temp);
257     DECLARE_ALIGNED(8, uint64_t, y_temp);
258     int32_t  alpMmxFilter[4*MAX_FILTER_SIZE];
259     DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes
260     DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes
261     uint16_t dither16[8];
262     uint32_t dither32[8];
263
264 #if HAVE_ALTIVEC
265     vector signed short   CY;
266     vector signed short   CRV;
267     vector signed short   CBU;
268     vector signed short   CGU;
269     vector signed short   CGV;
270     vector signed short   OY;
271     vector unsigned short CSHIFT;
272     vector signed short   *vYCoeffsBank, *vCCoeffsBank;
273 #endif
274
275 #if ARCH_BFIN
276     DECLARE_ALIGNED(4, uint32_t, oy);
277     DECLARE_ALIGNED(4, uint32_t, oc);
278     DECLARE_ALIGNED(4, uint32_t, zero);
279     DECLARE_ALIGNED(4, uint32_t, cy);
280     DECLARE_ALIGNED(4, uint32_t, crv);
281     DECLARE_ALIGNED(4, uint32_t, rmask);
282     DECLARE_ALIGNED(4, uint32_t, cbu);
283     DECLARE_ALIGNED(4, uint32_t, bmask);
284     DECLARE_ALIGNED(4, uint32_t, cgu);
285     DECLARE_ALIGNED(4, uint32_t, cgv);
286     DECLARE_ALIGNED(4, uint32_t, gmask);
287 #endif
288
289 #if HAVE_VIS
290     DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
291 #endif
292
293     /* function pointers for swScale() */
294     yuv2planar1_fn yuv2yuv1;
295     yuv2planarX_fn yuv2yuvX;
296     yuv2packed1_fn yuv2packed1;
297     yuv2packed2_fn yuv2packed2;
298     yuv2packedX_fn yuv2packedX;
299
300     void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
301                       int width, uint32_t *pal); ///< Unscaled conversion of luma plane to YV12 for horizontal scaler.
302     void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
303                       int width, uint32_t *pal); ///< Unscaled conversion of alpha plane to YV12 for horizontal scaler.
304     void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
305                       const uint8_t *src1, const uint8_t *src2,
306                       int width, uint32_t *pal); ///< Unscaled conversion of chroma planes to YV12 for horizontal scaler.
307     void (*hyscale_fast)(struct SwsContext *c,
308                          int16_t *dst, int dstWidth,
309                          const uint8_t *src, int srcW, int xInc);
310     void (*hcscale_fast)(struct SwsContext *c,
311                          int16_t *dst1, int16_t *dst2, int dstWidth,
312                          const uint8_t *src1, const uint8_t *src2,
313                          int srcW, int xInc);
314
315     void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW,
316                    int xInc, const int16_t *filter, const int16_t *filterPos,
317                    int filterSize);
318
319     void (*hScale16)(int16_t *dst, int dstW, const uint16_t *src, int srcW,
320                    int xInc, const int16_t *filter, const int16_t *filterPos,
321                    long filterSize, int shift);
322
323     void (*lumConvertRange)(int16_t *dst, int width); ///< Color range conversion function for luma plane if needed.
324     void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width); ///< Color range conversion function for chroma planes if needed.
325
326     int needs_hcscale; ///< Set if there are chroma planes to be converted.
327
328 } SwsContext;
329 //FIXME check init (where 0)
330
331 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
332 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
333                              int fullRange, int brightness,
334                              int contrast, int saturation);
335
336 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
337                                     int brightness, int contrast, int saturation);
338 void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
339                            int lastInLumBuf, int lastInChrBuf);
340
341 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
342 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
343 SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
344 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
345 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
346 void ff_bfin_get_unscaled_swscale(SwsContext *c);
347
348 #if FF_API_SWS_FORMAT_NAME
349 /**
350  * @deprecated Use av_get_pix_fmt_name() instead.
351  */
352 attribute_deprecated
353 const char *sws_format_name(enum PixelFormat format);
354 #endif
355
356 //FIXME replace this with something faster
357 #define is16BPS(x)      (           \
358            (x)==PIX_FMT_GRAY16BE    \
359         || (x)==PIX_FMT_GRAY16LE    \
360         || (x)==PIX_FMT_BGR48BE     \
361         || (x)==PIX_FMT_BGR48LE     \
362         || (x)==PIX_FMT_RGB48BE     \
363         || (x)==PIX_FMT_RGB48LE     \
364         || (x)==PIX_FMT_YUV420P16LE \
365         || (x)==PIX_FMT_YUV422P16LE \
366         || (x)==PIX_FMT_YUV444P16LE \
367         || (x)==PIX_FMT_YUV420P16BE \
368         || (x)==PIX_FMT_YUV422P16BE \
369         || (x)==PIX_FMT_YUV444P16BE \
370     )
371 #define isNBPS(x)       (           \
372            (x)==PIX_FMT_YUV420P9LE  \
373         || (x)==PIX_FMT_YUV420P9BE  \
374         || (x)==PIX_FMT_YUV444P9BE  \
375         || (x)==PIX_FMT_YUV444P9LE  \
376         || (x)==PIX_FMT_YUV422P10BE \
377         || (x)==PIX_FMT_YUV422P10LE \
378         || (x)==PIX_FMT_YUV444P10BE \
379         || (x)==PIX_FMT_YUV444P10LE \
380         || (x)==PIX_FMT_YUV420P10LE \
381         || (x)==PIX_FMT_YUV420P10BE \
382         || (x)==PIX_FMT_YUV422P10LE \
383         || (x)==PIX_FMT_YUV422P10BE \
384     )
385 #define is9_OR_10BPS isNBPS //for ronald
386 #define isBE(x) ((x)&1)
387 #define isPlanar8YUV(x) (           \
388            (x)==PIX_FMT_YUV410P     \
389         || (x)==PIX_FMT_YUV420P     \
390         || (x)==PIX_FMT_YUVA420P    \
391         || (x)==PIX_FMT_YUV411P     \
392         || (x)==PIX_FMT_YUV422P     \
393         || (x)==PIX_FMT_YUV444P     \
394         || (x)==PIX_FMT_YUV440P     \
395         || (x)==PIX_FMT_NV12        \
396         || (x)==PIX_FMT_NV21        \
397     )
398 #define isPlanarYUV(x)  (           \
399         isPlanar8YUV(x)             \
400         || (x)==PIX_FMT_YUV420P9LE  \
401         || (x)==PIX_FMT_YUV444P9LE  \
402         || (x)==PIX_FMT_YUV420P10LE \
403         || (x)==PIX_FMT_YUV422P10LE \
404         || (x)==PIX_FMT_YUV444P10LE \
405         || (x)==PIX_FMT_YUV420P16LE \
406         || (x)==PIX_FMT_YUV422P10LE \
407         || (x)==PIX_FMT_YUV422P16LE \
408         || (x)==PIX_FMT_YUV444P16LE \
409         || (x)==PIX_FMT_YUV420P9BE  \
410         || (x)==PIX_FMT_YUV444P9BE  \
411         || (x)==PIX_FMT_YUV420P10BE \
412         || (x)==PIX_FMT_YUV422P10BE \
413         || (x)==PIX_FMT_YUV444P10BE \
414         || (x)==PIX_FMT_YUV420P16BE \
415         || (x)==PIX_FMT_YUV422P10BE \
416         || (x)==PIX_FMT_YUV422P16BE \
417         || (x)==PIX_FMT_YUV444P16BE \
418     )
419 #define isYUV(x)        (           \
420            (x)==PIX_FMT_UYVY422     \
421         || (x)==PIX_FMT_YUYV422     \
422         || isPlanarYUV(x)           \
423     )
424 #define isGray(x)       (           \
425            (x)==PIX_FMT_GRAY8       \
426         || (x)==PIX_FMT_GRAY8A      \
427         || (x)==PIX_FMT_GRAY16BE    \
428         || (x)==PIX_FMT_GRAY16LE    \
429     )
430 #define isGray16(x)     (           \
431            (x)==PIX_FMT_GRAY16BE    \
432         || (x)==PIX_FMT_GRAY16LE    \
433     )
434 #define isRGBinInt(x)   (           \
435            (x)==PIX_FMT_RGB48BE     \
436         || (x)==PIX_FMT_RGB48LE     \
437         || (x)==PIX_FMT_RGB32       \
438         || (x)==PIX_FMT_RGB32_1     \
439         || (x)==PIX_FMT_RGB24       \
440         || (x)==PIX_FMT_RGB565BE    \
441         || (x)==PIX_FMT_RGB565LE    \
442         || (x)==PIX_FMT_RGB555BE    \
443         || (x)==PIX_FMT_RGB555LE    \
444         || (x)==PIX_FMT_RGB444BE    \
445         || (x)==PIX_FMT_RGB444LE    \
446         || (x)==PIX_FMT_RGB8        \
447         || (x)==PIX_FMT_RGB4        \
448         || (x)==PIX_FMT_RGB4_BYTE   \
449         || (x)==PIX_FMT_MONOBLACK   \
450         || (x)==PIX_FMT_MONOWHITE   \
451     )
452 #define isBGRinInt(x)   (           \
453            (x)==PIX_FMT_BGR48BE     \
454         || (x)==PIX_FMT_BGR48LE     \
455         || (x)==PIX_FMT_BGR32       \
456         || (x)==PIX_FMT_BGR32_1     \
457         || (x)==PIX_FMT_BGR24       \
458         || (x)==PIX_FMT_BGR565BE    \
459         || (x)==PIX_FMT_BGR565LE    \
460         || (x)==PIX_FMT_BGR555BE    \
461         || (x)==PIX_FMT_BGR555LE    \
462         || (x)==PIX_FMT_BGR444BE    \
463         || (x)==PIX_FMT_BGR444LE    \
464         || (x)==PIX_FMT_BGR8        \
465         || (x)==PIX_FMT_BGR4        \
466         || (x)==PIX_FMT_BGR4_BYTE   \
467         || (x)==PIX_FMT_MONOBLACK   \
468         || (x)==PIX_FMT_MONOWHITE   \
469     )
470 #define isRGBinBytes(x) (           \
471            (x)==PIX_FMT_RGB48BE     \
472         || (x)==PIX_FMT_RGB48LE     \
473         || (x)==PIX_FMT_RGBA        \
474         || (x)==PIX_FMT_ARGB        \
475         || (x)==PIX_FMT_RGB24       \
476     )
477 #define isBGRinBytes(x) (           \
478            (x)==PIX_FMT_BGR48BE     \
479         || (x)==PIX_FMT_BGR48LE     \
480         || (x)==PIX_FMT_BGRA        \
481         || (x)==PIX_FMT_ABGR        \
482         || (x)==PIX_FMT_BGR24       \
483     )
484 #define isAnyRGB(x)     (           \
485             isRGBinInt(x)           \
486         ||  isBGRinInt(x)           \
487     )
488 #define isALPHA(x)      (           \
489            (x)==PIX_FMT_BGR32       \
490         || (x)==PIX_FMT_BGR32_1     \
491         || (x)==PIX_FMT_RGB32       \
492         || (x)==PIX_FMT_RGB32_1     \
493         || (x)==PIX_FMT_PAL8        \
494         || (x)==PIX_FMT_GRAY8A      \
495         || (x)==PIX_FMT_YUVA420P    \
496     )
497 #define isPacked(x)         (       \
498            (x)==PIX_FMT_PAL8        \
499         || (x)==PIX_FMT_YUYV422     \
500         || (x)==PIX_FMT_UYVY422     \
501         || (x)==PIX_FMT_Y400A       \
502         || isAnyRGB(x)              \
503     )
504 #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_GRAY8A)
505
506 extern const uint64_t ff_dither4[2];
507 extern const uint64_t ff_dither8[2];
508 extern const uint8_t dithers[8][8][8];
509 extern const uint16_t dither_scale[15][16];
510
511
512 extern const AVClass sws_context_class;
513
514 /**
515  * Sets c->swScale to an unscaled converter if one exists for the specific
516  * source and destination formats, bit depths, flags, etc.
517  */
518 void ff_get_unscaled_swscale(SwsContext *c);
519
520 void ff_swscale_get_unscaled_altivec(SwsContext *c);
521
522 /**
523  * Returns function pointer to fastest main scaler path function depending
524  * on architecture and available optimizations.
525  */
526 SwsFunc ff_getSwsFunc(SwsContext *c);
527
528 void ff_sws_init_swScale_altivec(SwsContext *c);
529 void ff_sws_init_swScale_mmx(SwsContext *c);
530
531 #endif /* SWSCALE_SWSCALE_INTERNAL_H */