• 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-2011 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 #include "libavutil/log.h"
00032 #include "libavutil/pixfmt.h"
00033 #include "libavutil/pixdesc.h"
00034 
00035 #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long
00036 
00037 #define YUVRGB_TABLE_HEADROOM 128
00038 
00039 #define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients
00040 
00041 #define MAX_FILTER_SIZE 256
00042 
00043 #define DITHER1XBPP
00044 
00045 #if HAVE_BIGENDIAN
00046 #define ALT32_CORR (-1)
00047 #else
00048 #define ALT32_CORR   1
00049 #endif
00050 
00051 #if ARCH_X86_64
00052 #   define APCK_PTR2  8
00053 #   define APCK_COEF 16
00054 #   define APCK_SIZE 24
00055 #else
00056 #   define APCK_PTR2  4
00057 #   define APCK_COEF  8
00058 #   define APCK_SIZE 16
00059 #endif
00060 
00061 struct SwsContext;
00062 
00063 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[],
00064                        int srcStride[], int srcSliceY, int srcSliceH,
00065                        uint8_t *dst[], int dstStride[]);
00066 
00079 typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW,
00080                                const uint8_t *dither, int offset);
00081 
00095 typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize,
00096                                const int16_t **src, uint8_t *dest, int dstW,
00097                                const uint8_t *dither, int offset);
00098 
00114 typedef void (*yuv2interleavedX_fn)(struct SwsContext *c,
00115                                     const int16_t *chrFilter,
00116                                     int chrFilterSize,
00117                                     const int16_t **chrUSrc,
00118                                     const int16_t **chrVSrc,
00119                                     uint8_t *dest, int dstW);
00120 
00150 typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc,
00151                                const int16_t *chrUSrc[2],
00152                                const int16_t *chrVSrc[2],
00153                                const int16_t *alpSrc, uint8_t *dest,
00154                                int dstW, int uvalpha, int y);
00183 typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2],
00184                                const int16_t *chrUSrc[2],
00185                                const int16_t *chrVSrc[2],
00186                                const int16_t *alpSrc[2],
00187                                uint8_t *dest,
00188                                int dstW, int yalpha, int uvalpha, int y);
00215 typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
00216                                const int16_t **lumSrc, int lumFilterSize,
00217                                const int16_t *chrFilter,
00218                                const int16_t **chrUSrc,
00219                                const int16_t **chrVSrc, int chrFilterSize,
00220                                const int16_t **alpSrc, uint8_t *dest,
00221                                int dstW, int y);
00222 
00223 /* This struct should be aligned on at least a 32-byte boundary. */
00224 typedef struct SwsContext {
00228     const AVClass *av_class;
00229 
00234     SwsFunc swScale;
00235     int srcW;                     
00236     int srcH;                     
00237     int dstH;                     
00238     int chrSrcW;                  
00239     int chrSrcH;                  
00240     int chrDstW;                  
00241     int chrDstH;                  
00242     int lumXInc, chrXInc;
00243     int lumYInc, chrYInc;
00244     enum PixelFormat dstFormat;   
00245     enum PixelFormat srcFormat;   
00246     int dstFormatBpp;             
00247     int srcFormatBpp;             
00248     int dstBpc, srcBpc;
00249     int chrSrcHSubSample;         
00250     int chrSrcVSubSample;         
00251     int chrDstHSubSample;         
00252     int chrDstVSubSample;         
00253     int vChrDrop;                 
00254     int sliceDir;                 
00255     double param[2];              
00256 
00257     uint32_t pal_yuv[256];
00258     uint32_t pal_rgb[256];
00259 
00270     int16_t **lumPixBuf;          
00271     int16_t **chrUPixBuf;         
00272     int16_t **chrVPixBuf;         
00273     int16_t **alpPixBuf;          
00274     int vLumBufSize;              
00275     int vChrBufSize;              
00276     int lastInLumBuf;             
00277     int lastInChrBuf;             
00278     int lumBufIndex;              
00279     int chrBufIndex;              
00280 
00281 
00282     uint8_t *formatConvBuffer;
00283 
00298     int16_t *hLumFilter;          
00299     int16_t *hChrFilter;          
00300     int16_t *vLumFilter;          
00301     int16_t *vChrFilter;          
00302     int32_t *hLumFilterPos;       
00303     int32_t *hChrFilterPos;       
00304     int32_t *vLumFilterPos;       
00305     int32_t *vChrFilterPos;       
00306     int hLumFilterSize;           
00307     int hChrFilterSize;           
00308     int vLumFilterSize;           
00309     int vChrFilterSize;           
00310 
00311 
00312     int lumMmx2FilterCodeSize;    
00313     int chrMmx2FilterCodeSize;    
00314     uint8_t *lumMmx2FilterCode;   
00315     uint8_t *chrMmx2FilterCode;   
00316 
00317     int canMMX2BeUsed;
00318 
00319     int dstY;                     
00320     int flags;                    
00321     void *yuvTable;             // pointer to the yuv->rgb table start so it can be freed()
00322     uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM];
00323     uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM];
00324     int table_gV[256 + 2*YUVRGB_TABLE_HEADROOM];
00325     uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM];
00326 
00327     //Colorspace stuff
00328     int contrast, brightness, saturation;    // for sws_getColorspaceDetails
00329     int srcColorspaceTable[4];
00330     int dstColorspaceTable[4];
00331     int srcRange;                 
00332     int dstRange;                 
00333     int src0Alpha;
00334     int dst0Alpha;
00335     int yuv2rgb_y_offset;
00336     int yuv2rgb_y_coeff;
00337     int yuv2rgb_v2r_coeff;
00338     int yuv2rgb_v2g_coeff;
00339     int yuv2rgb_u2g_coeff;
00340     int yuv2rgb_u2b_coeff;
00341 
00342 #define RED_DITHER            "0*8"
00343 #define GREEN_DITHER          "1*8"
00344 #define BLUE_DITHER           "2*8"
00345 #define Y_COEFF               "3*8"
00346 #define VR_COEFF              "4*8"
00347 #define UB_COEFF              "5*8"
00348 #define VG_COEFF              "6*8"
00349 #define UG_COEFF              "7*8"
00350 #define Y_OFFSET              "8*8"
00351 #define U_OFFSET              "9*8"
00352 #define V_OFFSET              "10*8"
00353 #define LUM_MMX_FILTER_OFFSET "11*8"
00354 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
00355 #define DSTW_OFFSET           "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
00356 #define ESP_OFFSET            "11*8+4*4*256*2+8"
00357 #define VROUNDER_OFFSET       "11*8+4*4*256*2+16"
00358 #define U_TEMP                "11*8+4*4*256*2+24"
00359 #define V_TEMP                "11*8+4*4*256*2+32"
00360 #define Y_TEMP                "11*8+4*4*256*2+40"
00361 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
00362 #define UV_OFF_PX             "11*8+4*4*256*3+48"
00363 #define UV_OFF_BYTE           "11*8+4*4*256*3+56"
00364 #define DITHER16              "11*8+4*4*256*3+64"
00365 #define DITHER32              "11*8+4*4*256*3+80"
00366 
00367     DECLARE_ALIGNED(8, uint64_t, redDither);
00368     DECLARE_ALIGNED(8, uint64_t, greenDither);
00369     DECLARE_ALIGNED(8, uint64_t, blueDither);
00370 
00371     DECLARE_ALIGNED(8, uint64_t, yCoeff);
00372     DECLARE_ALIGNED(8, uint64_t, vrCoeff);
00373     DECLARE_ALIGNED(8, uint64_t, ubCoeff);
00374     DECLARE_ALIGNED(8, uint64_t, vgCoeff);
00375     DECLARE_ALIGNED(8, uint64_t, ugCoeff);
00376     DECLARE_ALIGNED(8, uint64_t, yOffset);
00377     DECLARE_ALIGNED(8, uint64_t, uOffset);
00378     DECLARE_ALIGNED(8, uint64_t, vOffset);
00379     int32_t lumMmxFilter[4 * MAX_FILTER_SIZE];
00380     int32_t chrMmxFilter[4 * MAX_FILTER_SIZE];
00381     int dstW;                     
00382     DECLARE_ALIGNED(8, uint64_t, esp);
00383     DECLARE_ALIGNED(8, uint64_t, vRounder);
00384     DECLARE_ALIGNED(8, uint64_t, u_temp);
00385     DECLARE_ALIGNED(8, uint64_t, v_temp);
00386     DECLARE_ALIGNED(8, uint64_t, y_temp);
00387     int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
00388     // alignment of these values is not necessary, but merely here
00389     // to maintain the same offset across x8632 and x86-64. Once we
00390     // use proper offset macros in the asm, they can be removed.
00391     DECLARE_ALIGNED(8, ptrdiff_t, uv_off); 
00392     DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); 
00393     DECLARE_ALIGNED(8, uint16_t, dither16)[8];
00394     DECLARE_ALIGNED(8, uint32_t, dither32)[8];
00395 
00396     const uint8_t *chrDither8, *lumDither8;
00397 
00398 #if HAVE_ALTIVEC
00399     vector signed short   CY;
00400     vector signed short   CRV;
00401     vector signed short   CBU;
00402     vector signed short   CGU;
00403     vector signed short   CGV;
00404     vector signed short   OY;
00405     vector unsigned short CSHIFT;
00406     vector signed short  *vYCoeffsBank, *vCCoeffsBank;
00407 #endif
00408 
00409 #if ARCH_BFIN
00410     DECLARE_ALIGNED(4, uint32_t, oy);
00411     DECLARE_ALIGNED(4, uint32_t, oc);
00412     DECLARE_ALIGNED(4, uint32_t, zero);
00413     DECLARE_ALIGNED(4, uint32_t, cy);
00414     DECLARE_ALIGNED(4, uint32_t, crv);
00415     DECLARE_ALIGNED(4, uint32_t, rmask);
00416     DECLARE_ALIGNED(4, uint32_t, cbu);
00417     DECLARE_ALIGNED(4, uint32_t, bmask);
00418     DECLARE_ALIGNED(4, uint32_t, cgu);
00419     DECLARE_ALIGNED(4, uint32_t, cgv);
00420     DECLARE_ALIGNED(4, uint32_t, gmask);
00421 #endif
00422 
00423 #if HAVE_VIS
00424     DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
00425 #endif
00426     int use_mmx_vfilter;
00427 
00428     /* function pointers for swScale() */
00429     yuv2planar1_fn yuv2plane1;
00430     yuv2planarX_fn yuv2planeX;
00431     yuv2interleavedX_fn yuv2nv12cX;
00432     yuv2packed1_fn yuv2packed1;
00433     yuv2packed2_fn yuv2packed2;
00434     yuv2packedX_fn yuv2packedX;
00435 
00437     void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
00438                       int width, uint32_t *pal);
00440     void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
00441                       int width, uint32_t *pal);
00443     void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
00444                       const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
00445                       int width, uint32_t *pal);
00446 
00452     void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width);
00453     void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
00454                           int width);
00476     void (*hyscale_fast)(struct SwsContext *c,
00477                          int16_t *dst, int dstWidth,
00478                          const uint8_t *src, int srcW, int xInc);
00479     void (*hcscale_fast)(struct SwsContext *c,
00480                          int16_t *dst1, int16_t *dst2, int dstWidth,
00481                          const uint8_t *src1, const uint8_t *src2,
00482                          int srcW, int xInc);
00516     void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
00517                     const uint8_t *src, const int16_t *filter,
00518                     const int32_t *filterPos, int filterSize);
00519     void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
00520                     const uint8_t *src, const int16_t *filter,
00521                     const int32_t *filterPos, int filterSize);
00524 
00525     void (*lumConvertRange)(int16_t *dst, int width);
00527     void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
00528 
00529     int needs_hcscale; 
00530 } SwsContext;
00531 //FIXME check init (where 0)
00532 
00533 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
00534 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
00535                              int fullRange, int brightness,
00536                              int contrast, int saturation);
00537 
00538 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
00539                                     int brightness, int contrast, int saturation);
00540 void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
00541                            int lastInLumBuf, int lastInChrBuf);
00542 
00543 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
00544 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
00545 SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
00546 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
00547 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
00548 void ff_bfin_get_unscaled_swscale(SwsContext *c);
00549 
00550 #if FF_API_SWS_FORMAT_NAME
00551 
00554 attribute_deprecated
00555 const char *sws_format_name(enum PixelFormat format);
00556 #endif
00557 
00558 #define is16BPS(x) \
00559     (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 15)
00560 
00561 #define is9_OR_10BPS(x) \
00562     (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 8 || \
00563      av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 9)
00564 
00565 #define isNBPS(x) is9_OR_10BPS(x)
00566 
00567 #define isBE(x) \
00568     (av_pix_fmt_descriptors[x].flags & PIX_FMT_BE)
00569 
00570 #define isYUV(x) \
00571     (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB) && \
00572      av_pix_fmt_descriptors[x].nb_components >= 2)
00573 
00574 #define isPlanarYUV(x) \
00575     ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR) && \
00576      isYUV(x))
00577 
00578 #define isRGB(x) \
00579     (av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB)
00580 #if 0 // FIXME
00581 #define isGray(x) \
00582     (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) && \
00583      av_pix_fmt_descriptors[x].nb_components <= 2)
00584 #else
00585 #define isGray(x)                      \
00586     ((x) == PIX_FMT_GRAY8       ||     \
00587      (x) == PIX_FMT_Y400A       ||     \
00588      (x) == PIX_FMT_GRAY16BE    ||     \
00589      (x) == PIX_FMT_GRAY16LE)
00590 #endif
00591 
00592 #define isRGBinInt(x) \
00593     (           \
00594         (x)==PIX_FMT_RGB48BE   ||   \
00595         (x)==PIX_FMT_RGB48LE   ||   \
00596         (x)==PIX_FMT_RGBA64BE  ||   \
00597         (x)==PIX_FMT_RGBA64LE  ||   \
00598         (x)==PIX_FMT_RGB32     ||   \
00599         (x)==PIX_FMT_RGB32_1   ||   \
00600         (x)==PIX_FMT_RGB24     ||   \
00601         (x)==PIX_FMT_RGB565BE  ||   \
00602         (x)==PIX_FMT_RGB565LE  ||   \
00603         (x)==PIX_FMT_RGB555BE  ||   \
00604         (x)==PIX_FMT_RGB555LE  ||   \
00605         (x)==PIX_FMT_RGB444BE  ||   \
00606         (x)==PIX_FMT_RGB444LE  ||   \
00607         (x)==PIX_FMT_RGB8      ||   \
00608         (x)==PIX_FMT_RGB4      ||   \
00609         (x)==PIX_FMT_RGB4_BYTE ||   \
00610         (x)==PIX_FMT_MONOBLACK ||   \
00611         (x)==PIX_FMT_MONOWHITE   \
00612     )
00613 #define isBGRinInt(x) \
00614     (           \
00615          (x)==PIX_FMT_BGR48BE  ||   \
00616          (x)==PIX_FMT_BGR48LE  ||   \
00617          (x)==PIX_FMT_BGRA64BE ||   \
00618          (x)==PIX_FMT_BGRA64LE ||   \
00619          (x)==PIX_FMT_BGR32    ||   \
00620          (x)==PIX_FMT_BGR32_1  ||   \
00621          (x)==PIX_FMT_BGR24    ||   \
00622          (x)==PIX_FMT_BGR565BE ||   \
00623          (x)==PIX_FMT_BGR565LE ||   \
00624          (x)==PIX_FMT_BGR555BE ||   \
00625          (x)==PIX_FMT_BGR555LE ||   \
00626          (x)==PIX_FMT_BGR444BE ||   \
00627          (x)==PIX_FMT_BGR444LE ||   \
00628          (x)==PIX_FMT_BGR8     ||   \
00629          (x)==PIX_FMT_BGR4     ||   \
00630          (x)==PIX_FMT_BGR4_BYTE||   \
00631          (x)==PIX_FMT_MONOBLACK||   \
00632          (x)==PIX_FMT_MONOWHITE   \
00633     )
00634 
00635 #define isRGBinBytes(x) (           \
00636            (x)==PIX_FMT_RGB48BE     \
00637         || (x)==PIX_FMT_RGB48LE     \
00638         || (x)==PIX_FMT_RGBA64BE    \
00639         || (x)==PIX_FMT_RGBA64LE    \
00640         || (x)==PIX_FMT_RGBA        \
00641         || (x)==PIX_FMT_ARGB        \
00642         || (x)==PIX_FMT_RGB24       \
00643     )
00644 #define isBGRinBytes(x) (           \
00645            (x)==PIX_FMT_BGR48BE     \
00646         || (x)==PIX_FMT_BGR48LE     \
00647         || (x)==PIX_FMT_BGRA64BE    \
00648         || (x)==PIX_FMT_BGRA64LE    \
00649         || (x)==PIX_FMT_BGRA        \
00650         || (x)==PIX_FMT_ABGR        \
00651         || (x)==PIX_FMT_BGR24       \
00652     )
00653 
00654 #define isAnyRGB(x) \
00655     (           \
00656           isRGBinInt(x)       ||    \
00657           isBGRinInt(x)       ||    \
00658           (x)==PIX_FMT_GBR24P     \
00659     )
00660 
00661 #define isALPHA(x) \
00662     (av_pix_fmt_descriptors[x].nb_components == 2 || \
00663      av_pix_fmt_descriptors[x].nb_components == 4)
00664 
00665 #if 1
00666 #define isPacked(x)         (       \
00667            (x)==PIX_FMT_PAL8        \
00668         || (x)==PIX_FMT_YUYV422     \
00669         || (x)==PIX_FMT_UYVY422     \
00670         || (x)==PIX_FMT_Y400A       \
00671         ||  isRGBinInt(x)           \
00672         ||  isBGRinInt(x)           \
00673     )
00674 #else
00675 #define isPacked(x)                                            \
00676     ((av_pix_fmt_descriptors[x].nb_components >= 2         &&  \
00677       !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) ||  \
00678      (x) == PIX_FMT_PAL8)
00679 
00680 #endif
00681 #define isPlanar(x) \
00682     (av_pix_fmt_descriptors[x].nb_components >= 2          &&  \
00683      (av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
00684 
00685 #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A)
00686 
00687 extern const uint64_t ff_dither4[2];
00688 extern const uint64_t ff_dither8[2];
00689 extern const uint8_t dithers[8][8][8];
00690 extern const uint16_t dither_scale[15][16];
00691 
00692 
00693 extern const AVClass sws_context_class;
00694 
00699 void ff_get_unscaled_swscale(SwsContext *c);
00700 
00701 void ff_swscale_get_unscaled_altivec(SwsContext *c);
00702 
00707 SwsFunc ff_getSwsFunc(SwsContext *c);
00708 
00709 void ff_sws_init_swScale_altivec(SwsContext *c);
00710 void ff_sws_init_swScale_mmx(SwsContext *c);
00711 
00712 #endif /* SWSCALE_SWSCALE_INTERNAL_H */
Generated on Fri Feb 1 2013 14:34:57 for FFmpeg by doxygen 1.7.1