Revision 5cebb24b postproc/swscale.c

View differences:

postproc/swscale.c
60 60
more intelligent missalignment avoidance for the horizontal scaler
61 61
dither in C
62 62
change the distance of the u & v buffer
63
Move static / global vars into a struct so multiple scalers can be used
64 63
write special vertical cubic upscale version
65 64
Optimize C code (yv12 / minmax)
66 65
*/
......
144 143
//global sws_flags from the command line
145 144
int sws_flags=0;
146 145

  
146
//global srcFilter
147
SwsFilter src_filter= {NULL, NULL, NULL, NULL};
148

  
149
float sws_lum_gblur= 0.0;
150
float sws_chr_gblur= 0.0;
151
int sws_chr_vshift= 0;
152
int sws_chr_hshift= 0;
153

  
147 154
/* cpuCaps combined from cpudetect and whats actually compiled in
148 155
   (if there is no support for something compiled in it wont appear here) */
149 156
static CpuCaps cpuCaps;
......
151 158
void (*swScale)(SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
152 159
             int srcSliceH, uint8_t* dst[], int dstStride[])=NULL;
153 160

  
161
static SwsVector *getConvVec(SwsVector *a, SwsVector *b);
162

  
154 163
#ifdef CAN_COMPILE_X86_ASM
155 164
void in_asm_used_var_warning_killer()
156 165
{
......
454 463
	int flags=0;
455 464
	static int firstTime=1;
456 465
	int dstStride3[3]= {dstStride, dstStride>>1, dstStride>>1};
457
	static SwsFilter srcFilter={NULL, NULL, NULL, NULL};
458 466

  
459 467
	if(firstTime)
460 468
	{
461 469
		flags= SWS_PRINT_INFO;
462 470
		firstTime=0;
463
{/*
464
		SwsVector *g= getGaussianVec(1.7, 2);
465
		SwsVector *id= getIdentityVec();
466
		scaleVec(g, 0.2);
467 471

  
472
		if(src_filter.lumH) free(src_filter.lumH);
473
		if(src_filter.lumV) free(src_filter.lumV);
474
		if(src_filter.chrH) free(src_filter.chrH);
475
		if(src_filter.chrV) free(src_filter.chrV);
476

  
477
		if(sws_lum_gblur!=0.0){
478
			src_filter.lumH= getGaussianVec(sws_lum_gblur, 3.0);
479
			src_filter.lumV= getGaussianVec(sws_lum_gblur, 3.0);
480
		}else{
481
			src_filter.lumH= getIdentityVec();
482
			src_filter.lumV= getIdentityVec();
483
		}
468 484

  
469
//		srcFilter.chrH= diffVec(id, g);
470
//		srcFilter.chrH= shiftVec(id, 20);
471
		srcFilter.chrH= g;
472
//		freeVec(g);
473
		freeVec(id);
485
		if(sws_chr_gblur!=0.0){
486
			src_filter.chrH= getGaussianVec(sws_chr_gblur, 3.0);
487
			src_filter.chrV= getGaussianVec(sws_chr_gblur, 3.0);
488
		}else{
489
			src_filter.chrH= getIdentityVec();
490
			src_filter.chrV= getIdentityVec();
491
		}
492

  
493
		if(sws_chr_hshift)
494
			shiftVec(src_filter.chrH, sws_chr_hshift);
474 495

  
475
		normalizeVec(srcFilter.chrH, 1.0);
476
		printVec(srcFilter.chrH);
496
		if(sws_chr_vshift)
497
			shiftVec(src_filter.chrV, sws_chr_vshift);
477 498

  
478
		srcFilter.lumV= srcFilter.lumH= srcFilter.chrV= srcFilter.chrH;
479
		srcFilter.lumH = srcFilter.lumV = NULL;
480
//		srcFilter.chrH = srcFilter.chrV = NULL;
481
*/}
482 499
	}
483 500

  
484 501
	switch(dstbpp)
......
501 518
		default:flags|= SWS_BILINEAR; break;
502 519
	}
503 520

  
504
	if(!context) context=getSwsContext(srcW, srcH, IMGFMT_YV12, dstW, dstH, dstFormat, flags, &srcFilter, NULL);
521
	if(!context) context=getSwsContext(srcW, srcH, IMGFMT_YV12, dstW, dstH, dstFormat, flags, &src_filter, NULL);
505 522

  
506 523

  
507 524
	swScale(context, src, srcStride, srcSliceY, srcSliceH, dst, dstStride3);
......
660 677
		scaleFilter.coeff= filter + i*filterSize;
661 678
		scaleFilter.length= filterSize;
662 679

  
663
		if(srcFilter) outVec= convVec(srcFilter, &scaleFilter);
680
		if(srcFilter) outVec= getConvVec(srcFilter, &scaleFilter);
664 681
		else	      outVec= &scaleFilter;
665 682

  
666 683
		ASSERT(outVec->length == filter2Size)
......
945 962
	int i;
946 963
	SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};
947 964

  
965
#ifdef ARCH_X86
966
	if(gCpuCaps.hasMMX)
967
		asm volatile("emms\n\t"::: "memory");
968
#endif
969

  
948 970
	if(swScale==NULL) globalInit();
949 971

  
950 972
	/* sanity check */
......
1243 1265
		a->coeff[i]*= scalar;
1244 1266
}
1245 1267

  
1246
SwsVector *convVec(SwsVector *a, SwsVector *b){
1268
static SwsVector *getConvVec(SwsVector *a, SwsVector *b){
1247 1269
	int length= a->length + b->length - 1;
1248 1270
	double *coeff= memalign(sizeof(double), length*sizeof(double));
1249 1271
	int i, j;
......
1265 1287
	return vec;
1266 1288
}
1267 1289

  
1268
SwsVector *sumVec(SwsVector *a, SwsVector *b){
1290
static SwsVector *sumVec(SwsVector *a, SwsVector *b){
1269 1291
	int length= MAX(a->length, b->length);
1270 1292
	double *coeff= memalign(sizeof(double), length*sizeof(double));
1271 1293
	int i;
......
1282 1304
	return vec;
1283 1305
}
1284 1306

  
1285
SwsVector *diffVec(SwsVector *a, SwsVector *b){
1307
static SwsVector *diffVec(SwsVector *a, SwsVector *b){
1286 1308
	int length= MAX(a->length, b->length);
1287 1309
	double *coeff= memalign(sizeof(double), length*sizeof(double));
1288 1310
	int i;
......
1300 1322
}
1301 1323

  
1302 1324
/* shift left / or right if "shift" is negative */
1303
SwsVector *shiftVec(SwsVector *a, int shift){
1325
static SwsVector *getShiftedVec(SwsVector *a, int shift){
1304 1326
	int length= a->length + ABS(shift)*2;
1305 1327
	double *coeff= memalign(sizeof(double), length*sizeof(double));
1306 1328
	int i, j;
......
1319 1341
	return vec;
1320 1342
}
1321 1343

  
1344
void shiftVec(SwsVector *a, int shift){
1345
	SwsVector *shifted= getShiftedVec(a, shift);
1346
	free(a->coeff);
1347
	a->coeff= shifted->coeff;
1348
	a->length= shifted->length;
1349
	free(shifted);
1350
}
1351

  
1352
void addVec(SwsVector *a, SwsVector *b){
1353
	SwsVector *sum= sumVec(a, b);
1354
	free(a->coeff);
1355
	a->coeff= sum->coeff;
1356
	a->length= sum->length;
1357
	free(sum);
1358
}
1359

  
1360
void subVec(SwsVector *a, SwsVector *b){
1361
	SwsVector *diff= diffVec(a, b);
1362
	free(a->coeff);
1363
	a->coeff= diff->coeff;
1364
	a->length= diff->length;
1365
	free(diff);
1366
}
1367

  
1368
void convVec(SwsVector *a, SwsVector *b){
1369
	SwsVector *conv= getConvVec(a, b);
1370
	free(a->coeff);
1371
	a->coeff= conv->coeff;
1372
	a->length= conv->length;
1373
	free(conv);
1374
}
1375

  
1376
SwsVector *cloneVec(SwsVector *a){
1377
	double *coeff= memalign(sizeof(double), a->length*sizeof(double));
1378
	int i;
1379
	SwsVector *vec= malloc(sizeof(SwsVector));
1380

  
1381
	vec->coeff= coeff;
1382
	vec->length= a->length;
1383

  
1384
	for(i=0; i<a->length; i++) coeff[i]= a->coeff[i];
1385

  
1386
	return vec;
1387
}
1388

  
1322 1389
void printVec(SwsVector *a){
1323 1390
	int i;
1324 1391
	double max=0;

Also available in: Unified diff