~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to postproc/swscale.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:47:54 UTC
  • Revision ID: siretart@tauware.de-20060708084754-c3ff228cc9c2d8de
upgrade to pre8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1166
1166
        }
1167
1167
 
1168
1168
        // Note the +1 is for the MMXscaler which reads over the end
1169
 
        *outFilter= (int16_t*)memalign(8, *outFilterSize*(dstW+1)*sizeof(int16_t));
 
1169
        /* align at 16 for AltiVec (needed by hScale_altivec_real) */
 
1170
        *outFilter= (int16_t*)memalign(16, *outFilterSize*(dstW+1)*sizeof(int16_t));
1170
1171
        memset(*outFilter, 0, *outFilterSize*(dstW+1)*sizeof(int16_t));
1171
1172
 
1172
1173
        /* Normalize & Store in outFilter */
1374
1375
}
1375
1376
#endif // ARCH_X86 || ARCH_X86_64
1376
1377
 
1377
 
static void globalInit(){
 
1378
static void globalInit(void){
1378
1379
    // generating tables:
1379
1380
    int i;
1380
1381
    for(i=0; i<768; i++){
2109
2110
                                c->chrSrcH, c->chrDstH, filterAlign, (1<<12)-4,
2110
2111
                                (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
2111
2112
                                srcFilter->chrV, dstFilter->chrV, c->param);
 
2113
 
 
2114
#ifdef HAVE_ALTIVEC
 
2115
                c->vYCoeffsBank = memalign (16, sizeof (vector signed short)*c->vLumFilterSize*c->dstH);
 
2116
                c->vCCoeffsBank = memalign (16, sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH);
 
2117
 
 
2118
                for (i=0;i<c->vLumFilterSize*c->dstH;i++) {
 
2119
                  int j;
 
2120
                  short *p = (short *)&c->vYCoeffsBank[i];
 
2121
                  for (j=0;j<8;j++)
 
2122
                    p[j] = c->vLumFilter[i];
 
2123
                }
 
2124
 
 
2125
                for (i=0;i<c->vChrFilterSize*c->chrDstH;i++) {
 
2126
                  int j;
 
2127
                  short *p = (short *)&c->vCCoeffsBank[i];
 
2128
                  for (j=0;j<8;j++)
 
2129
                    p[j] = c->vChrFilter[i];
 
2130
                }
 
2131
#endif
2112
2132
        }
2113
2133
 
2114
2134
        // Calculate Buffer Sizes so that they won't run out while handling these damn slices
2132
2152
        c->lumPixBuf= (int16_t**)memalign(4, c->vLumBufSize*2*sizeof(int16_t*));
2133
2153
        c->chrPixBuf= (int16_t**)memalign(4, c->vChrBufSize*2*sizeof(int16_t*));
2134
2154
        //Note we need at least one pixel more at the end because of the mmx code (just in case someone wanna replace the 4000/8000)
 
2155
        /* align at 16 bytes for AltiVec */
2135
2156
        for(i=0; i<c->vLumBufSize; i++)
2136
 
                c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= (uint16_t*)memalign(8, 4000);
 
2157
                c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= (uint16_t*)memalign(16, 4000);
2137
2158
        for(i=0; i<c->vChrBufSize; i++)
2138
 
                c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= (uint16_t*)memalign(8, 8000);
 
2159
                c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= (uint16_t*)memalign(16, 8000);
2139
2160
 
2140
2161
        //try to avoid drawing green stuff between the right end and the stride end
2141
2162
        for(i=0; i<c->vLumBufSize; i++) memset(c->lumPixBuf[i], 0, 4000);
2346
2367
        }
2347
2368
 
2348
2369
        if(chromaSharpen!=0.0){
2349
 
                SwsVector *g= sws_getConstVec(-1.0, 3);
2350
 
                SwsVector *id= sws_getConstVec(10.0/chromaSharpen, 1);
2351
 
                g->coeff[1]=2.0;
2352
 
                sws_addVec(id, g);
2353
 
                sws_convVec(filter->chrH, id);
2354
 
                sws_convVec(filter->chrV, id);
2355
 
                sws_freeVec(g);
 
2370
                SwsVector *id= sws_getIdentityVec();
 
2371
                sws_scaleVec(filter->chrH, -chromaSharpen);
 
2372
                sws_scaleVec(filter->chrV, -chromaSharpen);
 
2373
                sws_addVec(filter->chrH, id);
 
2374
                sws_addVec(filter->chrV, id);
2356
2375
                sws_freeVec(id);
2357
2376
        }
2358
2377
 
2359
2378
        if(lumaSharpen!=0.0){
2360
 
                SwsVector *g= sws_getConstVec(-1.0, 3);
2361
 
                SwsVector *id= sws_getConstVec(10.0/lumaSharpen, 1);
2362
 
                g->coeff[1]=2.0;
2363
 
                sws_addVec(id, g);
2364
 
                sws_convVec(filter->lumH, id);
2365
 
                sws_convVec(filter->lumV, id);
2366
 
                sws_freeVec(g);
 
2379
                SwsVector *id= sws_getIdentityVec();
 
2380
                sws_scaleVec(filter->lumH, -lumaSharpen);
 
2381
                sws_scaleVec(filter->lumV, -lumaSharpen);
 
2382
                sws_addVec(filter->lumH, id);
 
2383
                sws_addVec(filter->lumV, id);
2367
2384
                sws_freeVec(id);
2368
2385
        }
2369
2386
 
2425
2442
 
2426
2443
 
2427
2444
SwsVector *sws_getIdentityVec(void){
2428
 
        double *coeff= memalign(sizeof(double), sizeof(double));
2429
 
        SwsVector *vec= malloc(sizeof(SwsVector));
2430
 
        coeff[0]= 1.0;
2431
 
 
2432
 
        vec->coeff= coeff;
2433
 
        vec->length= 1;
2434
 
 
2435
 
        return vec;
 
2445
        return sws_getConstVec(1.0, 1);
2436
2446
}
2437
2447
 
2438
 
void sws_normalizeVec(SwsVector *a, double height){
 
2448
double sws_dcVec(SwsVector *a){
2439
2449
        int i;
2440
 
        double sum=0;
2441
 
        double inv;
 
2450
        double sum=0;
2442
2451
 
2443
2452
        for(i=0; i<a->length; i++)
2444
2453
                sum+= a->coeff[i];
2445
2454
 
2446
 
        inv= height/sum;
2447
 
 
2448
 
        for(i=0; i<a->length; i++)
2449
 
                a->coeff[i]*= inv;
 
2455
        return sum;
2450
2456
}
2451
2457
 
2452
2458
void sws_scaleVec(SwsVector *a, double scalar){
2456
2462
                a->coeff[i]*= scalar;
2457
2463
}
2458
2464
 
 
2465
void sws_normalizeVec(SwsVector *a, double height){
 
2466
        sws_scaleVec(a, height/sws_dcVec(a));
 
2467
}
 
2468
 
2459
2469
static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b){
2460
2470
        int length= a->length + b->length - 1;
2461
2471
        double *coeff= memalign(sizeof(double), length*sizeof(double));
2653
2663
        c->hLumFilter = NULL;
2654
2664
        if(c->hChrFilter) free(c->hChrFilter);
2655
2665
        c->hChrFilter = NULL;
 
2666
#ifdef HAVE_ALTIVEC
 
2667
        if(c->vYCoeffsBank) free(c->vYCoeffsBank);
 
2668
        c->vYCoeffsBank = NULL;
 
2669
        if(c->vCCoeffsBank) free(c->vCCoeffsBank);
 
2670
        c->vCCoeffsBank = NULL;
 
2671
#endif
2656
2672
 
2657
2673
        if(c->vLumFilterPos) free(c->vLumFilterPos);
2658
2674
        c->vLumFilterPos = NULL;