• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libswscale/swscale_internal.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #ifndef SWSCALE_SWSCALE_INTERNAL_H
00022 #define SWSCALE_SWSCALE_INTERNAL_H
00023 
00024 #include "config.h"
00025 
00026 #if HAVE_ALTIVEC_H
00027 #include <altivec.h>
00028 #endif
00029 
00030 #include "libavutil/avutil.h"
00031 
00032 #define STR(s)         AV_TOSTRING(s) //AV_STRINGIFY is too long
00033 
00034 #define MAX_FILTER_SIZE 256
00035 
00036 #if ARCH_X86
00037 #define VOFW 5120
00038 #else
00039 #define VOFW 2048 // faster on PPC and not tested on others
00040 #endif
00041 
00042 #define VOF  (VOFW*2)
00043 
00044 #if HAVE_BIGENDIAN
00045 #define ALT32_CORR (-1)
00046 #else
00047 #define ALT32_CORR   1
00048 #endif
00049 
00050 #if ARCH_X86_64
00051 #   define APCK_PTR2 8
00052 #   define APCK_COEF 16
00053 #   define APCK_SIZE 24
00054 #else
00055 #   define APCK_PTR2 4
00056 #   define APCK_COEF 8
00057 #   define APCK_SIZE 16
00058 #endif
00059 
00060 struct SwsContext;
00061 
00062 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[],
00063                        int srcStride[], int srcSliceY, int srcSliceH,
00064                        uint8_t* dst[], int dstStride[]);
00065 
00066 /* This struct should be aligned on at least a 32-byte boundary. */
00067 typedef struct SwsContext {
00071     const AVClass *av_class;
00072 
00077     SwsFunc swScale;
00078     int srcW;                     
00079     int srcH;                     
00080     int dstH;                     
00081     int chrSrcW;                  
00082     int chrSrcH;                  
00083     int chrDstW;                  
00084     int chrDstH;                  
00085     int lumXInc, chrXInc;
00086     int lumYInc, chrYInc;
00087     enum PixelFormat dstFormat;   
00088     enum PixelFormat srcFormat;   
00089     int dstFormatBpp;             
00090     int srcFormatBpp;             
00091     int chrSrcHSubSample;         
00092     int chrSrcVSubSample;         
00093     int chrDstHSubSample;         
00094     int chrDstVSubSample;         
00095     int vChrDrop;                 
00096     int sliceDir;                 
00097     double param[2];              
00098 
00099     uint32_t pal_yuv[256];
00100     uint32_t pal_rgb[256];
00101 
00112     int16_t **lumPixBuf;          
00113     int16_t **chrPixBuf;          
00114     int16_t **alpPixBuf;          
00115     int       vLumBufSize;        
00116     int       vChrBufSize;        
00117     int       lastInLumBuf;       
00118     int       lastInChrBuf;       
00119     int       lumBufIndex;        
00120     int       chrBufIndex;        
00121 
00122 
00123     uint8_t formatConvBuffer[VOF]; //FIXME dynamic allocation, but we have to change a lot of code for this to be useful
00124 
00139     int16_t *hLumFilter;          
00140     int16_t *hChrFilter;          
00141     int16_t *vLumFilter;          
00142     int16_t *vChrFilter;          
00143     int16_t *hLumFilterPos;       
00144     int16_t *hChrFilterPos;       
00145     int16_t *vLumFilterPos;       
00146     int16_t *vChrFilterPos;       
00147     int      hLumFilterSize;      
00148     int      hChrFilterSize;      
00149     int      vLumFilterSize;      
00150     int      vChrFilterSize;      
00151 
00152 
00153     int lumMmx2FilterCodeSize;    
00154     int chrMmx2FilterCodeSize;    
00155     uint8_t *lumMmx2FilterCode;   
00156     uint8_t *chrMmx2FilterCode;   
00157 
00158     int canMMX2BeUsed;
00159 
00160     int dstY;                     
00161     int flags;                    
00162     void * yuvTable;            // pointer to the yuv->rgb table start so it can be freed()
00163     uint8_t * table_rV[256];
00164     uint8_t * table_gU[256];
00165     int    table_gV[256];
00166     uint8_t * table_bU[256];
00167 
00168     //Colorspace stuff
00169     int contrast, brightness, saturation;    // for sws_getColorspaceDetails
00170     int srcColorspaceTable[4];
00171     int dstColorspaceTable[4];
00172     int srcRange;                 
00173     int dstRange;                 
00174     int yuv2rgb_y_offset;
00175     int yuv2rgb_y_coeff;
00176     int yuv2rgb_v2r_coeff;
00177     int yuv2rgb_v2g_coeff;
00178     int yuv2rgb_u2g_coeff;
00179     int yuv2rgb_u2b_coeff;
00180 
00181 #define RED_DITHER            "0*8"
00182 #define GREEN_DITHER          "1*8"
00183 #define BLUE_DITHER           "2*8"
00184 #define Y_COEFF               "3*8"
00185 #define VR_COEFF              "4*8"
00186 #define UB_COEFF              "5*8"
00187 #define VG_COEFF              "6*8"
00188 #define UG_COEFF              "7*8"
00189 #define Y_OFFSET              "8*8"
00190 #define U_OFFSET              "9*8"
00191 #define V_OFFSET              "10*8"
00192 #define LUM_MMX_FILTER_OFFSET "11*8"
00193 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
00194 #define DSTW_OFFSET           "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
00195 #define ESP_OFFSET            "11*8+4*4*256*2+8"
00196 #define VROUNDER_OFFSET       "11*8+4*4*256*2+16"
00197 #define U_TEMP                "11*8+4*4*256*2+24"
00198 #define V_TEMP                "11*8+4*4*256*2+32"
00199 #define Y_TEMP                "11*8+4*4*256*2+40"
00200 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
00201 
00202     DECLARE_ALIGNED(8, uint64_t, redDither);
00203     DECLARE_ALIGNED(8, uint64_t, greenDither);
00204     DECLARE_ALIGNED(8, uint64_t, blueDither);
00205 
00206     DECLARE_ALIGNED(8, uint64_t, yCoeff);
00207     DECLARE_ALIGNED(8, uint64_t, vrCoeff);
00208     DECLARE_ALIGNED(8, uint64_t, ubCoeff);
00209     DECLARE_ALIGNED(8, uint64_t, vgCoeff);
00210     DECLARE_ALIGNED(8, uint64_t, ugCoeff);
00211     DECLARE_ALIGNED(8, uint64_t, yOffset);
00212     DECLARE_ALIGNED(8, uint64_t, uOffset);
00213     DECLARE_ALIGNED(8, uint64_t, vOffset);
00214     int32_t  lumMmxFilter[4*MAX_FILTER_SIZE];
00215     int32_t  chrMmxFilter[4*MAX_FILTER_SIZE];
00216     int dstW;                     
00217     DECLARE_ALIGNED(8, uint64_t, esp);
00218     DECLARE_ALIGNED(8, uint64_t, vRounder);
00219     DECLARE_ALIGNED(8, uint64_t, u_temp);
00220     DECLARE_ALIGNED(8, uint64_t, v_temp);
00221     DECLARE_ALIGNED(8, uint64_t, y_temp);
00222     int32_t  alpMmxFilter[4*MAX_FILTER_SIZE];
00223 
00224 #if HAVE_ALTIVEC
00225     vector signed short   CY;
00226     vector signed short   CRV;
00227     vector signed short   CBU;
00228     vector signed short   CGU;
00229     vector signed short   CGV;
00230     vector signed short   OY;
00231     vector unsigned short CSHIFT;
00232     vector signed short   *vYCoeffsBank, *vCCoeffsBank;
00233 #endif
00234 
00235 #if ARCH_BFIN
00236     DECLARE_ALIGNED(4, uint32_t, oy);
00237     DECLARE_ALIGNED(4, uint32_t, oc);
00238     DECLARE_ALIGNED(4, uint32_t, zero);
00239     DECLARE_ALIGNED(4, uint32_t, cy);
00240     DECLARE_ALIGNED(4, uint32_t, crv);
00241     DECLARE_ALIGNED(4, uint32_t, rmask);
00242     DECLARE_ALIGNED(4, uint32_t, cbu);
00243     DECLARE_ALIGNED(4, uint32_t, bmask);
00244     DECLARE_ALIGNED(4, uint32_t, cgu);
00245     DECLARE_ALIGNED(4, uint32_t, cgv);
00246     DECLARE_ALIGNED(4, uint32_t, gmask);
00247 #endif
00248 
00249 #if HAVE_VIS
00250     DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
00251 #endif
00252 
00253     /* function pointers for swScale() */
00254     void (*yuv2nv12X  )(struct SwsContext *c,
00255                         const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
00256                         const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
00257                         uint8_t *dest, uint8_t *uDest,
00258                         int dstW, int chrDstW, int dstFormat);
00259     void (*yuv2yuv1   )(struct SwsContext *c,
00260                         const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc,
00261                         uint8_t *dest,
00262                         uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
00263                         long dstW, long chrDstW);
00264     void (*yuv2yuvX   )(struct SwsContext *c,
00265                         const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
00266                         const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
00267                         const int16_t **alpSrc,
00268                         uint8_t *dest,
00269                         uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
00270                         long dstW, long chrDstW);
00271     void (*yuv2packed1)(struct SwsContext *c,
00272                         const uint16_t *buf0,
00273                         const uint16_t *uvbuf0, const uint16_t *uvbuf1,
00274                         const uint16_t *abuf0,
00275                         uint8_t *dest,
00276                         int dstW, int uvalpha, int dstFormat, int flags, int y);
00277     void (*yuv2packed2)(struct SwsContext *c,
00278                         const uint16_t *buf0, const uint16_t *buf1,
00279                         const uint16_t *uvbuf0, const uint16_t *uvbuf1,
00280                         const uint16_t *abuf0, const uint16_t *abuf1,
00281                         uint8_t *dest,
00282                         int dstW, int yalpha, int uvalpha, int y);
00283     void (*yuv2packedX)(struct SwsContext *c,
00284                         const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
00285                         const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
00286                         const int16_t **alpSrc, uint8_t *dest,
00287                         long dstW, long dstY);
00288 
00289     void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
00290                       long width, uint32_t *pal); 
00291     void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
00292                       long width, uint32_t *pal); 
00293     void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
00294                       const uint8_t *src1, const uint8_t *src2,
00295                       long width, uint32_t *pal); 
00296     void (*hyscale_fast)(struct SwsContext *c,
00297                          int16_t *dst, long dstWidth,
00298                          const uint8_t *src, int srcW, int xInc);
00299     void (*hcscale_fast)(struct SwsContext *c,
00300                          int16_t *dst, long dstWidth,
00301                          const uint8_t *src1, const uint8_t *src2,
00302                          int srcW, int xInc);
00303 
00304     void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW,
00305                    int xInc, const int16_t *filter, const int16_t *filterPos,
00306                    long filterSize);
00307 
00308     void (*lumConvertRange)(uint16_t *dst, int width); 
00309     void (*chrConvertRange)(uint16_t *dst, int width); 
00310 
00311     int lumSrcOffset; 
00312     int chrSrcOffset; 
00313     int alpSrcOffset; 
00314 
00315     int needs_hcscale; 
00316 
00317 } SwsContext;
00318 //FIXME check init (where 0)
00319 
00320 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
00321 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
00322                              int fullRange, int brightness,
00323                              int contrast, int saturation);
00324 
00325 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
00326                                     int brightness, int contrast, int saturation);
00327 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
00328 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
00329 SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
00330 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
00331 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
00332 void ff_bfin_get_unscaled_swscale(SwsContext *c);
00333 void ff_yuv2packedX_altivec(SwsContext *c,
00334                             const int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
00335                             const int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
00336                             uint8_t *dest, int dstW, int dstY);
00337 
00338 const char *sws_format_name(enum PixelFormat format);
00339 
00340 //FIXME replace this with something faster
00341 #define is16BPS(x)      (           \
00342            (x)==PIX_FMT_GRAY16BE    \
00343         || (x)==PIX_FMT_GRAY16LE    \
00344         || (x)==PIX_FMT_RGB48BE     \
00345         || (x)==PIX_FMT_RGB48LE     \
00346         || (x)==PIX_FMT_YUV420P16LE   \
00347         || (x)==PIX_FMT_YUV422P16LE   \
00348         || (x)==PIX_FMT_YUV444P16LE   \
00349         || (x)==PIX_FMT_YUV420P16BE   \
00350         || (x)==PIX_FMT_YUV422P16BE   \
00351         || (x)==PIX_FMT_YUV444P16BE   \
00352     )
00353 #define isBE(x) ((x)&1)
00354 #define isPlanar8YUV(x) (           \
00355            (x)==PIX_FMT_YUV410P     \
00356         || (x)==PIX_FMT_YUV420P     \
00357         || (x)==PIX_FMT_YUVA420P    \
00358         || (x)==PIX_FMT_YUV411P     \
00359         || (x)==PIX_FMT_YUV422P     \
00360         || (x)==PIX_FMT_YUV444P     \
00361         || (x)==PIX_FMT_YUV440P     \
00362         || (x)==PIX_FMT_NV12        \
00363         || (x)==PIX_FMT_NV21        \
00364     )
00365 #define isPlanarYUV(x)  (           \
00366         isPlanar8YUV(x)             \
00367         || (x)==PIX_FMT_YUV420P16LE   \
00368         || (x)==PIX_FMT_YUV422P16LE   \
00369         || (x)==PIX_FMT_YUV444P16LE   \
00370         || (x)==PIX_FMT_YUV420P16BE   \
00371         || (x)==PIX_FMT_YUV422P16BE   \
00372         || (x)==PIX_FMT_YUV444P16BE   \
00373     )
00374 #define isYUV(x)        (           \
00375            (x)==PIX_FMT_UYVY422     \
00376         || (x)==PIX_FMT_YUYV422     \
00377         || isPlanarYUV(x)           \
00378     )
00379 #define isGray(x)       (           \
00380            (x)==PIX_FMT_GRAY8       \
00381         || (x)==PIX_FMT_GRAY16BE    \
00382         || (x)==PIX_FMT_GRAY16LE    \
00383     )
00384 #define isGray16(x)     (           \
00385            (x)==PIX_FMT_GRAY16BE    \
00386         || (x)==PIX_FMT_GRAY16LE    \
00387     )
00388 #define isRGBinInt(x)   (           \
00389            (x)==PIX_FMT_RGB48BE     \
00390         || (x)==PIX_FMT_RGB48LE     \
00391         || (x)==PIX_FMT_RGB32       \
00392         || (x)==PIX_FMT_RGB32_1     \
00393         || (x)==PIX_FMT_RGB24       \
00394         || (x)==PIX_FMT_RGB565BE    \
00395         || (x)==PIX_FMT_RGB565LE    \
00396         || (x)==PIX_FMT_RGB555BE    \
00397         || (x)==PIX_FMT_RGB555LE    \
00398         || (x)==PIX_FMT_RGB444BE    \
00399         || (x)==PIX_FMT_RGB444LE    \
00400         || (x)==PIX_FMT_RGB8        \
00401         || (x)==PIX_FMT_RGB4        \
00402         || (x)==PIX_FMT_RGB4_BYTE   \
00403         || (x)==PIX_FMT_MONOBLACK   \
00404         || (x)==PIX_FMT_MONOWHITE   \
00405     )
00406 #define isBGRinInt(x)   (           \
00407            (x)==PIX_FMT_BGR32       \
00408         || (x)==PIX_FMT_BGR32_1     \
00409         || (x)==PIX_FMT_BGR24       \
00410         || (x)==PIX_FMT_BGR565BE    \
00411         || (x)==PIX_FMT_BGR565LE    \
00412         || (x)==PIX_FMT_BGR555BE    \
00413         || (x)==PIX_FMT_BGR555LE    \
00414         || (x)==PIX_FMT_BGR444BE    \
00415         || (x)==PIX_FMT_BGR444LE    \
00416         || (x)==PIX_FMT_BGR8        \
00417         || (x)==PIX_FMT_BGR4        \
00418         || (x)==PIX_FMT_BGR4_BYTE   \
00419         || (x)==PIX_FMT_MONOBLACK   \
00420         || (x)==PIX_FMT_MONOWHITE   \
00421     )
00422 #define isRGBinBytes(x) (           \
00423            (x)==PIX_FMT_RGB48BE     \
00424         || (x)==PIX_FMT_RGB48LE     \
00425         || (x)==PIX_FMT_RGBA        \
00426         || (x)==PIX_FMT_ARGB        \
00427         || (x)==PIX_FMT_RGB24       \
00428     )
00429 #define isBGRinBytes(x) (           \
00430            (x)==PIX_FMT_BGRA        \
00431         || (x)==PIX_FMT_ABGR        \
00432         || (x)==PIX_FMT_BGR24       \
00433     )
00434 #define isAnyRGB(x)     (           \
00435             isRGBinInt(x)           \
00436         ||  isBGRinInt(x)           \
00437     )
00438 #define isALPHA(x)      (           \
00439            (x)==PIX_FMT_BGR32       \
00440         || (x)==PIX_FMT_BGR32_1     \
00441         || (x)==PIX_FMT_RGB32       \
00442         || (x)==PIX_FMT_RGB32_1     \
00443         || (x)==PIX_FMT_YUVA420P    \
00444     )
00445 #define usePal(x) (av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL)
00446 
00447 extern const uint64_t ff_dither4[2];
00448 extern const uint64_t ff_dither8[2];
00449 
00450 extern const AVClass sws_context_class;
00451 
00456 void ff_get_unscaled_swscale(SwsContext *c);
00457 
00461 int ff_hardcodedcpuflags(void);
00462 
00467 SwsFunc ff_getSwsFunc(SwsContext *c);
00468 
00469 #endif /* SWSCALE_SWSCALE_INTERNAL_H */

Generated on Fri Sep 16 2011 17:17:52 for FFmpeg by  doxygen 1.7.1