~ubuntu-branches/ubuntu/lucid/ffmpeg/lucid-security

« back to all changes in this revision

Viewing changes to libswscale/swscale.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-03-13 09:18:28 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090313091828-n4ktby5eca487uhv
Tags: 3:0.svn20090303-1ubuntu1+unstripped1
merge from ubuntu.jaunty branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
#define RV ( (int)(0.500*224/255*(1<<RGB2YUV_SHIFT)+0.5))
175
175
#define RU (-(int)(0.169*224/255*(1<<RGB2YUV_SHIFT)+0.5))
176
176
 
177
 
extern const int32_t Inverse_Table_6_9[8][4];
 
177
extern const int32_t ff_yuv2rgb_coeffs[8][4];
178
178
 
179
179
static const double rgb2yuv_table[8][9]={
180
180
    {0.7152, 0.0722, 0.2126, -0.386, 0.5, -0.115, -0.454, -0.046, 0.5},
922
922
    switch(c->dstFormat){
923
923
    case PIX_FMT_ARGB:
924
924
        dest++;
925
 
        aidx= 0;
 
925
        aidx= -1;
926
926
    case PIX_FMT_RGB24:
927
927
        aidx--;
928
928
    case PIX_FMT_RGBA:
929
929
        YSCALE_YUV_2_RGBX_FULL_C(1<<21)
930
 
            dest[aidx]= 0;
 
930
            dest[aidx]= 255;
931
931
            dest[0]= R>>22;
932
932
            dest[1]= G>>22;
933
933
            dest[2]= B>>22;
936
936
        break;
937
937
    case PIX_FMT_ABGR:
938
938
        dest++;
939
 
        aidx= 0;
 
939
        aidx= -1;
940
940
    case PIX_FMT_BGR24:
941
941
        aidx--;
942
942
    case PIX_FMT_BGRA:
943
943
        YSCALE_YUV_2_RGBX_FULL_C(1<<21)
944
 
            dest[aidx]= 0;
 
944
            dest[aidx]= 255;
945
945
            dest[0]= B>>22;
946
946
            dest[1]= G>>22;
947
947
            dest[2]= R>>22;
2076
2076
}
2077
2077
 
2078
2078
/**
2079
 
 * @param inv_table the yuv2rgb coefficients, normally Inverse_Table_6_9[x]
 
2079
 * @param inv_table the yuv2rgb coefficients, normally ff_yuv2rgb_coeffs[x]
2080
2080
 * @param fullRange if 1 then the luma range is 0..255 if 0 it is 16..235
2081
2081
 * @return -1 if not supported
2082
2082
 */
2133
2133
    c->yuv2rgb_u2g_coeff= (int16_t)roundToInt16(cgu<<13);
2134
2134
    c->yuv2rgb_u2b_coeff= (int16_t)roundToInt16(cbu<<13);
2135
2135
 
2136
 
    yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation);
 
2136
    sws_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation);
2137
2137
    //FIXME factorize
2138
2138
 
2139
2139
#ifdef COMPILE_ALTIVEC
2140
2140
    if (c->flags & SWS_CPU_CAPS_ALTIVEC)
2141
 
        yuv2rgb_altivec_init_tables (c, inv_table, brightness, contrast, saturation);
 
2141
        sws_yuv2rgb_altivec_init_tables (c, inv_table, brightness, contrast, saturation);
2142
2142
#endif
2143
2143
    return 0;
2144
2144
}
2321
2321
    c->chrDstW= -((-dstW) >> c->chrDstHSubSample);
2322
2322
    c->chrDstH= -((-dstH) >> c->chrDstVSubSample);
2323
2323
 
2324
 
    sws_setColorspaceDetails(c, Inverse_Table_6_9[SWS_CS_DEFAULT], srcRange, Inverse_Table_6_9[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16);
 
2324
    sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16);
2325
2325
 
2326
2326
    /* unscaled special cases */
2327
2327
    if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isBGR(dstFormat) || isRGB(dstFormat)))
2328
2328
    {
2329
2329
        /* yv12_to_nv12 */
2330
 
        if (srcFormat == PIX_FMT_YUV420P && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21))
 
2330
        if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21))
2331
2331
        {
2332
2332
            c->swScale= PlanarToNV12Wrapper;
2333
2333
        }
2334
 
#if CONFIG_GPL
2335
2334
        /* yuv2bgr */
2336
 
        if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P) && (isBGR(dstFormat) || isRGB(dstFormat))
 
2335
        if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P || srcFormat==PIX_FMT_YUVA420P) && (isBGR(dstFormat) || isRGB(dstFormat))
2337
2336
            && !(flags & SWS_ACCURATE_RND) && !(dstH&1))
2338
2337
        {
2339
 
            c->swScale= yuv2rgb_get_func_ptr(c);
 
2338
            c->swScale= sws_yuv2rgb_get_func_ptr(c);
2340
2339
        }
2341
 
#endif
2342
2340
 
2343
2341
        if (srcFormat==PIX_FMT_YUV410P && dstFormat==PIX_FMT_YUV420P && !(flags & SWS_BITEXACT))
2344
2342
        {
2385
2383
        /* LQ converters if -sws 0 or -sws 4*/
2386
2384
        if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)){
2387
2385
            /* yv12_to_yuy2 */
2388
 
            if (srcFormat == PIX_FMT_YUV420P)
 
2386
            if (srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P)
2389
2387
            {
2390
2388
                if (dstFormat == PIX_FMT_YUYV422)
2391
2389
                    c->swScale= PlanarToYuy2Wrapper;
2396
2394
 
2397
2395
#ifdef COMPILE_ALTIVEC
2398
2396
        if ((c->flags & SWS_CPU_CAPS_ALTIVEC) &&
 
2397
            !(c->flags & SWS_BITEXACT) &&
2399
2398
            srcFormat == PIX_FMT_YUV420P) {
2400
2399
          // unscaled YV12 -> packed YUV, we want speed
2401
2400
          if (dstFormat == PIX_FMT_YUYV422)
2407
2406
 
2408
2407
        /* simple copy */
2409
2408
        if (  srcFormat == dstFormat
 
2409
            || (srcFormat == PIX_FMT_YUVA420P && dstFormat == PIX_FMT_YUV420P)
2410
2410
            || (isPlanarYUV(srcFormat) && isGray(dstFormat))
2411
2411
            || (isPlanarYUV(dstFormat) && isGray(srcFormat)))
2412
2412
        {
2820
2820
    }
2821
2821
}
2822
2822
 
2823
 
/**
2824
 
 * swscale wrapper, so we don't need to export the SwsContext.
2825
 
 */
 
2823
#if LIBSWSCALE_VERSION_MAJOR < 1
2826
2824
int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2827
2825
                      int srcSliceH, uint8_t* dst[], int dstStride[]){
2828
2826
    return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
2829
2827
}
 
2828
#endif
2830
2829
 
2831
2830
SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
2832
2831
                                float lumaSharpen, float chromaSharpen,
2880
2879
    sws_normalizeVec(filter->lumH, 1.0);
2881
2880
    sws_normalizeVec(filter->lumV, 1.0);
2882
2881
 
2883
 
    if (verbose) sws_printVec(filter->chrH);
2884
 
    if (verbose) sws_printVec(filter->lumH);
 
2882
    if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
 
2883
    if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
2885
2884
 
2886
2885
    return filter;
2887
2886
}
2888
2887
 
2889
 
/**
2890
 
 * Returns a normalized Gaussian curve used to filter stuff
2891
 
 * quality=3 is high quality, lower is lower quality.
2892
 
 */
2893
2888
SwsVector *sws_getGaussianVec(double variance, double quality){
2894
2889
    const int length= (int)(variance*quality + 0.5) | 1;
2895
2890
    int i;
3072
3067
    return vec;
3073
3068
}
3074
3069
 
3075
 
void sws_printVec(SwsVector *a){
 
3070
void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level){
3076
3071
    int i;
3077
3072
    double max=0;
3078
3073
    double min=0;
3089
3084
    for (i=0; i<a->length; i++)
3090
3085
    {
3091
3086
        int x= (int)((a->coeff[i]-min)*60.0/range +0.5);
3092
 
        av_log(NULL, AV_LOG_DEBUG, "%1.3f ", a->coeff[i]);
3093
 
        for (;x>0; x--) av_log(NULL, AV_LOG_DEBUG, " ");
3094
 
        av_log(NULL, AV_LOG_DEBUG, "|\n");
 
3087
        av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]);
 
3088
        for (;x>0; x--) av_log(log_ctx, log_level, " ");
 
3089
        av_log(log_ctx, log_level, "|\n");
3095
3090
    }
3096
3091
}
3097
3092
 
 
3093
#if LIBSWSCALE_VERSION_MAJOR < 1
 
3094
void sws_printVec(SwsVector *a){
 
3095
    sws_printVec2(a, NULL, AV_LOG_DEBUG);
 
3096
}
 
3097
#endif
 
3098
 
3098
3099
void sws_freeVec(SwsVector *a){
3099
3100
    if (!a) return;
3100
3101
    av_freep(&a->coeff);
3166
3167
    av_free(c);
3167
3168
}
3168
3169
 
3169
 
/**
3170
 
 * Checks if context is valid or reallocs a new one instead.
3171
 
 * If context is NULL, just calls sws_getContext() to get a new one.
3172
 
 * Otherwise, checks if the parameters are the ones already saved in context.
3173
 
 * If that is the case, returns the current context.
3174
 
 * Otherwise, frees context and gets a new one.
3175
 
 *
3176
 
 * Be warned that srcFilter, dstFilter are not checked, they are
3177
 
 * asumed to remain valid.
3178
 
 */
3179
3170
struct SwsContext *sws_getCachedContext(struct SwsContext *context,
3180
3171
                                        int srcW, int srcH, enum PixelFormat srcFormat,
3181
3172
                                        int dstW, int dstH, enum PixelFormat dstFormat, int flags,