Mercurial > mplayer.hg
comparison postproc/yuv2rgb_altivec.c @ 13564:992960f68af0
postproc/yuv2rgb_altivec.c compile fix
yuv2rgb_altivec_init_tables does initialize the SwsContext vectors.
missing vec_splat.
patch by (Luca Barbato <lu_zero at gentoo dot org>) and (Romain Dolbeau <dolbeau at irisa dot fr>)
author | michael |
---|---|
date | Tue, 05 Oct 2004 19:11:00 +0000 |
parents | ec86a77cb6f4 |
children | 08cac43f1e38 |
comparison
equal
deleted
inserted
replaced
13563:9b55ea3879ef | 13564:992960f68af0 |
---|---|
117 a67b 89cA BdCD eEFf | 117 a67b 89cA BdCD eEFf |
118 | 118 |
119 */ | 119 */ |
120 static | 120 static |
121 const vector unsigned char | 121 const vector unsigned char |
122 perm_rgb_0 = (vector unsigned char)(0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05, | 122 perm_rgb_0 = (const vector unsigned char)AVV(0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05, |
123 0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a), | 123 0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a), |
124 perm_rgb_1 = (vector unsigned char)(0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17, | 124 perm_rgb_1 = (const vector unsigned char)AVV(0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17, |
125 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f), | 125 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f), |
126 perm_rgb_2 = (vector unsigned char)(0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, | 126 perm_rgb_2 = (const vector unsigned char)AVV(0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, |
127 0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05), | 127 0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05), |
128 perm_rgb_3 = (vector unsigned char)(0x1a,0x06,0x07,0x1b,0x08,0x09,0x1c,0x0a, | 128 perm_rgb_3 = (const vector unsigned char)AVV(0x1a,0x06,0x07,0x1b,0x08,0x09,0x1c,0x0a, |
129 0x0b,0x1d,0x0c,0x0d,0x1e,0x0e,0x0f,0x1f); | 129 0x0b,0x1d,0x0c,0x0d,0x1e,0x0e,0x0f,0x1f); |
130 | 130 |
131 #define vec_merge3(x2,x1,x0,y0,y1,y2) \ | 131 #define vec_merge3(x2,x1,x0,y0,y1,y2) \ |
132 do { \ | 132 do { \ |
133 typeof(x0) o0,o2,o3; \ | 133 typeof(x0) o0,o2,o3; \ |
196 | 196 |
197 | 197 |
198 | 198 |
199 #define vec_unh(x) \ | 199 #define vec_unh(x) \ |
200 (vector signed short) \ | 200 (vector signed short) \ |
201 vec_perm(x,(typeof(x))(0),\ | 201 vec_perm(x,(typeof(x))AVV(0),\ |
202 (vector unsigned char)(0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\ | 202 (vector unsigned char)AVV(0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\ |
203 0x10,0x04,0x10,0x05,0x10,0x06,0x10,0x07)) | 203 0x10,0x04,0x10,0x05,0x10,0x06,0x10,0x07)) |
204 #define vec_unl(x) \ | 204 #define vec_unl(x) \ |
205 (vector signed short) \ | 205 (vector signed short) \ |
206 vec_perm(x,(typeof(x))(0),\ | 206 vec_perm(x,(typeof(x))AVV(0),\ |
207 (vector unsigned char)(0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\ | 207 (vector unsigned char)AVV(0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\ |
208 0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F)) | 208 0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F)) |
209 | 209 |
210 #define vec_clip(x) \ | 210 #define vec_clip(x) \ |
211 vec_max (vec_min (x, (typeof(x))(255)), (typeof(x))(0)) | 211 vec_max (vec_min (x, (typeof(x))AVV(235)), (typeof(x))AVV(16)) |
212 | 212 |
213 #define vec_packclp_a(x,y) \ | 213 #define vec_packclp_a(x,y) \ |
214 (vector unsigned char)vec_pack (vec_clip (x), vec_clip (y)) | 214 (vector unsigned char)vec_pack (vec_clip (x), vec_clip (y)) |
215 | 215 |
216 #define vec_packclp(x,y) \ | 216 #define vec_packclp(x,y) \ |
217 (vector unsigned char)vec_packs \ | 217 (vector unsigned char)vec_packs \ |
218 ((vector unsigned short)vec_max (x,(vector signed short) (0)), \ | 218 ((vector unsigned short)vec_max (x,(vector signed short) AVV(0)), \ |
219 (vector unsigned short)vec_max (y,(vector signed short) (0))) | 219 (vector unsigned short)vec_max (y,(vector signed short) AVV(0))) |
220 | 220 |
221 //#define out_pixels(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))(0)),a,a,a,ptr) | 221 //#define out_pixels(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),a,a,a,ptr) |
222 | 222 |
223 | 223 |
224 static inline void cvtyuvtoRGB (SwsContext *c, | 224 static inline void cvtyuvtoRGB (SwsContext *c, |
225 vector signed short Y, vector signed short U, vector signed short V, | 225 vector signed short Y, vector signed short U, vector signed short V, |
226 vector signed short *R, vector signed short *G, vector signed short *B) | 226 vector signed short *R, vector signed short *G, vector signed short *B) |
227 { | 227 { |
228 vector signed short vx,ux,uvx; | 228 vector signed short vx,ux,uvx; |
229 | 229 |
230 Y = vec_mradds (Y, c->CY, c->OY); | 230 Y = vec_mradds (Y, c->CY, c->OY); |
231 | 231 U = vec_sub (U,(vector signed short) |
232 U = vec_sub (U,(vector signed short)(128)); | 232 vec_splat((vector signed short)AVV(128),0)); |
233 V = vec_sub (V,(vector signed short)(128)); | 233 V = vec_sub (V,(vector signed short) |
234 vec_splat((vector signed short)AVV(128),0)); | |
234 | 235 |
235 // ux = (CBU*(u<<c->CSHIFT)+0x4000)>>15; | 236 // ux = (CBU*(u<<c->CSHIFT)+0x4000)>>15; |
236 ux = vec_sl (U, c->CSHIFT); | 237 ux = vec_sl (U, c->CSHIFT); |
237 *B = vec_mradds (ux, c->CBU, Y); | 238 *B = vec_mradds (ux, c->CBU, Y); |
238 | 239 |
322 u = (vector signed char)vec_perm (uivP[0], uivP[1], align_perm); \ | 323 u = (vector signed char)vec_perm (uivP[0], uivP[1], align_perm); \ |
323 \ | 324 \ |
324 align_perm = vec_lvsl (0, vi); \ | 325 align_perm = vec_lvsl (0, vi); \ |
325 v = (vector signed char)vec_perm (vivP[0], vivP[1], align_perm); \ | 326 v = (vector signed char)vec_perm (vivP[0], vivP[1], align_perm); \ |
326 \ | 327 \ |
327 u = (vector signed char)vec_sub (u, (vector signed char)(128)); \ | 328 u = (vector signed char) \ |
328 v = (vector signed char)vec_sub (v, (vector signed char)(128)); \ | 329 vec_sub (u,(vector signed char) \ |
330 vec_splat((vector signed char)AVV(128),0));\ | |
331 v = (vector signed char) \ | |
332 vec_sub (v,(vector signed char) \ | |
333 vec_splat((vector signed char)AVV(128),0));\ | |
334 \ | |
329 U = vec_unpackh (u); \ | 335 U = vec_unpackh (u); \ |
330 V = vec_unpackh (v); \ | 336 V = vec_unpackh (v); \ |
331 \ | 337 \ |
332 \ | 338 \ |
333 Y0 = vec_unh (y0); \ | 339 Y0 = vec_unh (y0); \ |
340 Y2 = vec_mradds (Y2, lCY, lOY); \ | 346 Y2 = vec_mradds (Y2, lCY, lOY); \ |
341 Y3 = vec_mradds (Y3, lCY, lOY); \ | 347 Y3 = vec_mradds (Y3, lCY, lOY); \ |
342 \ | 348 \ |
343 /* ux = (CBU*(u<<CSHIFT)+0x4000)>>15 */ \ | 349 /* ux = (CBU*(u<<CSHIFT)+0x4000)>>15 */ \ |
344 ux = vec_sl (U, lCSHIFT); \ | 350 ux = vec_sl (U, lCSHIFT); \ |
345 ux = vec_mradds (ux, lCBU, (vector signed short)(0)); \ | 351 ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0)); \ |
346 ux0 = vec_mergeh (ux,ux); \ | 352 ux0 = vec_mergeh (ux,ux); \ |
347 ux1 = vec_mergel (ux,ux); \ | 353 ux1 = vec_mergel (ux,ux); \ |
348 \ | 354 \ |
349 /* vx = (CRV*(v<<CSHIFT)+0x4000)>>15; */ \ | 355 /* vx = (CRV*(v<<CSHIFT)+0x4000)>>15; */ \ |
350 vx = vec_sl (V, lCSHIFT); \ | 356 vx = vec_sl (V, lCSHIFT); \ |
351 vx = vec_mradds (vx, lCRV, (vector signed short)(0)); \ | 357 vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0)); \ |
352 vx0 = vec_mergeh (vx,vx); \ | 358 vx0 = vec_mergeh (vx,vx); \ |
353 vx1 = vec_mergel (vx,vx); \ | 359 vx1 = vec_mergel (vx,vx); \ |
354 \ | 360 \ |
355 /* uvx = ((CGU*u) + (CGV*v))>>15 */ \ | 361 /* uvx = ((CGU*u) + (CGV*v))>>15 */ \ |
356 uvx = vec_mradds (U, lCGU, (vector signed short)(0)); \ | 362 uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0)); \ |
357 uvx = vec_mradds (V, lCGV, uvx); \ | 363 uvx = vec_mradds (V, lCGV, uvx); \ |
358 uvx0 = vec_mergeh (uvx,uvx); \ | 364 uvx0 = vec_mergeh (uvx,uvx); \ |
359 uvx1 = vec_mergel (uvx,uvx); \ | 365 uvx1 = vec_mergel (uvx,uvx); \ |
360 \ | 366 \ |
361 R0 = vec_add (Y0,vx0); \ | 367 R0 = vec_add (Y0,vx0); \ |
401 } \ | 407 } \ |
402 return srcSliceH; \ | 408 return srcSliceH; \ |
403 } | 409 } |
404 | 410 |
405 | 411 |
406 #define out_abgr(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))(0)),c,b,a,ptr) | 412 #define out_abgr(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),c,b,a,ptr) |
407 #define out_bgra(a,b,c,ptr) vec_mstrgb32(typeof(a),c,b,a,((typeof (a))(0)),ptr) | 413 #define out_bgra(a,b,c,ptr) vec_mstrgb32(typeof(a),c,b,a,((typeof (a))AVV(0)),ptr) |
408 #define out_rgba(a,b,c,ptr) vec_mstrgb32(typeof(a),a,b,c,((typeof (a))(0)),ptr) | 414 #define out_rgba(a,b,c,ptr) vec_mstrgb32(typeof(a),a,b,c,((typeof (a))AVV(0)),ptr) |
409 #define out_argb(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))(0)),a,b,c,ptr) | 415 #define out_argb(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),a,b,c,ptr) |
410 #define out_rgb24(a,b,c,ptr) vec_mstrgb24(a,b,c,ptr) | 416 #define out_rgb24(a,b,c,ptr) vec_mstrgb24(a,b,c,ptr) |
411 #define out_bgr24(a,b,c,ptr) vec_mstrgb24(c,b,a,ptr) | 417 #define out_bgr24(a,b,c,ptr) vec_mstbgr24(c,b,a,ptr) |
412 | 418 |
413 DEFCSP420_CVT (yuv2_abgr32, out_abgr) | 419 DEFCSP420_CVT (yuv2_abgr32, out_abgr) |
420 #if 1 | |
414 DEFCSP420_CVT (yuv2_bgra32, out_argb) | 421 DEFCSP420_CVT (yuv2_bgra32, out_argb) |
422 #else | |
423 static int altivec_yuv2_bgra32 (SwsContext *c, | |
424 unsigned char **in, int *instrides, | |
425 int srcSliceY, int srcSliceH, | |
426 unsigned char **oplanes, int *outstrides) | |
427 { | |
428 int w = c->srcW; | |
429 int h = srcSliceH; | |
430 int i,j; | |
431 int instrides_scl[3]; | |
432 vector unsigned char y0,y1; | |
433 | |
434 vector signed char u,v; | |
435 | |
436 vector signed short Y0,Y1,Y2,Y3; | |
437 vector signed short U,V; | |
438 vector signed short vx,ux,uvx; | |
439 vector signed short vx0,ux0,uvx0; | |
440 vector signed short vx1,ux1,uvx1; | |
441 vector signed short R0,G0,B0; | |
442 vector signed short R1,G1,B1; | |
443 vector unsigned char R,G,B; | |
444 | |
445 vector unsigned char *uivP, *vivP; | |
446 vector unsigned char align_perm; | |
447 | |
448 vector signed short | |
449 lCY = c->CY, | |
450 lOY = c->OY, | |
451 lCRV = c->CRV, | |
452 lCBU = c->CBU, | |
453 lCGU = c->CGU, | |
454 lCGV = c->CGV; | |
455 | |
456 vector unsigned short lCSHIFT = c->CSHIFT; | |
457 | |
458 ubyte *y1i = in[0]; | |
459 ubyte *y2i = in[0]+w; | |
460 ubyte *ui = in[1]; | |
461 ubyte *vi = in[2]; | |
462 | |
463 vector unsigned char *oute | |
464 = (vector unsigned char *) | |
465 (oplanes[0]+srcSliceY*outstrides[0]); | |
466 vector unsigned char *outo | |
467 = (vector unsigned char *) | |
468 (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); | |
469 | |
470 | |
471 instrides_scl[0] = instrides[0]; | |
472 instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ | |
473 instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ | |
474 | |
475 | |
476 for (i=0;i<h/2;i++) { | |
477 vec_dstst (outo, (0x02000002|(((w*3+32)/32)<<16)), 0); | |
478 vec_dstst (oute, (0x02000002|(((w*3+32)/32)<<16)), 1); | |
479 | |
480 for (j=0;j<w/16;j++) { | |
481 | |
482 y0 = vec_ldl (0,y1i); | |
483 y1 = vec_ldl (0,y2i); | |
484 uivP = (vector unsigned char *)ui; | |
485 vivP = (vector unsigned char *)vi; | |
486 | |
487 align_perm = vec_lvsl (0, ui); | |
488 u = (vector signed char)vec_perm (uivP[0], uivP[1], align_perm); | |
489 | |
490 align_perm = vec_lvsl (0, vi); | |
491 v = (vector signed char)vec_perm (vivP[0], vivP[1], align_perm); | |
492 u = (vector signed char) | |
493 vec_sub (u,(vector signed char) | |
494 vec_splat((vector signed char)AVV(128),0)); | |
495 | |
496 v = (vector signed char) | |
497 vec_sub (v, (vector signed char) | |
498 vec_splat((vector signed char)AVV(128),0)); | |
499 | |
500 U = vec_unpackh (u); | |
501 V = vec_unpackh (v); | |
502 | |
503 | |
504 Y0 = vec_unh (y0); | |
505 Y1 = vec_unl (y0); | |
506 Y2 = vec_unh (y1); | |
507 Y3 = vec_unl (y1); | |
508 | |
509 Y0 = vec_mradds (Y0, lCY, lOY); | |
510 Y1 = vec_mradds (Y1, lCY, lOY); | |
511 Y2 = vec_mradds (Y2, lCY, lOY); | |
512 Y3 = vec_mradds (Y3, lCY, lOY); | |
513 | |
514 /* ux = (CBU*(u<<CSHIFT)+0x4000)>>15 */ | |
515 ux = vec_sl (U, lCSHIFT); | |
516 ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0)); | |
517 ux0 = vec_mergeh (ux,ux); | |
518 ux1 = vec_mergel (ux,ux); | |
519 | |
520 /* vx = (CRV*(v<<CSHIFT)+0x4000)>>15; */ | |
521 vx = vec_sl (V, lCSHIFT); | |
522 vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0)); | |
523 vx0 = vec_mergeh (vx,vx); | |
524 vx1 = vec_mergel (vx,vx); | |
525 /* uvx = ((CGU*u) + (CGV*v))>>15 */ | |
526 uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0)); | |
527 uvx = vec_mradds (V, lCGV, uvx); | |
528 uvx0 = vec_mergeh (uvx,uvx); | |
529 uvx1 = vec_mergel (uvx,uvx); | |
530 R0 = vec_add (Y0,vx0); | |
531 G0 = vec_add (Y0,uvx0); | |
532 B0 = vec_add (Y0,ux0); | |
533 R1 = vec_add (Y1,vx1); | |
534 G1 = vec_add (Y1,uvx1); | |
535 B1 = vec_add (Y1,ux1); | |
536 R = vec_packclp (R0,R1); | |
537 G = vec_packclp (G0,G1); | |
538 B = vec_packclp (B0,B1); | |
539 | |
540 out_argb(R,G,B,oute); | |
541 R0 = vec_add (Y2,vx0); | |
542 G0 = vec_add (Y2,uvx0); | |
543 B0 = vec_add (Y2,ux0); | |
544 R1 = vec_add (Y3,vx1); | |
545 G1 = vec_add (Y3,uvx1); | |
546 B1 = vec_add (Y3,ux1); | |
547 R = vec_packclp (R0,R1); | |
548 G = vec_packclp (G0,G1); | |
549 B = vec_packclp (B0,B1); | |
550 | |
551 out_argb(R,G,B,outo); | |
552 y1i += 16; | |
553 y2i += 16; | |
554 ui += 8; | |
555 vi += 8; | |
556 | |
557 } | |
558 | |
559 outo += (outstrides[0])>>4; | |
560 oute += (outstrides[0])>>4; | |
561 | |
562 ui += instrides_scl[1]; | |
563 vi += instrides_scl[2]; | |
564 y1i += instrides_scl[0]; | |
565 y2i += instrides_scl[0]; | |
566 } | |
567 return srcSliceH; | |
568 } | |
569 | |
570 #endif | |
571 | |
572 | |
415 DEFCSP420_CVT (yuv2_rgba32, out_rgba) | 573 DEFCSP420_CVT (yuv2_rgba32, out_rgba) |
416 DEFCSP420_CVT (yuv2_argb32, out_argb) | 574 DEFCSP420_CVT (yuv2_argb32, out_argb) |
417 DEFCSP420_CVT (yuv2_rgb24, out_rgb24) | 575 DEFCSP420_CVT (yuv2_rgb24, out_rgb24) |
418 DEFCSP420_CVT (yuv2_bgr24, out_bgr24) | 576 DEFCSP420_CVT (yuv2_bgr24, out_bgr24) |
419 | 577 |
420 | 578 |
421 // uyvy|uyvy|uyvy|uyvy | 579 // uyvy|uyvy|uyvy|uyvy |
422 // 0123 4567 89ab cdef | 580 // 0123 4567 89ab cdef |
423 static | 581 static |
424 const vector unsigned char | 582 const vector unsigned char |
425 demux_u = (vector unsigned char)(0x10,0x00,0x10,0x00, | 583 demux_u = (const vector unsigned char)AVV(0x10,0x00,0x10,0x00, |
426 0x10,0x04,0x10,0x04, | 584 0x10,0x04,0x10,0x04, |
427 0x10,0x08,0x10,0x08, | 585 0x10,0x08,0x10,0x08, |
428 0x10,0x0c,0x10,0x0c), | 586 0x10,0x0c,0x10,0x0c), |
429 demux_v = (vector unsigned char)(0x10,0x02,0x10,0x02, | 587 demux_v = (const vector unsigned char)AVV(0x10,0x02,0x10,0x02, |
430 0x10,0x06,0x10,0x06, | 588 0x10,0x06,0x10,0x06, |
431 0x10,0x0A,0x10,0x0A, | 589 0x10,0x0A,0x10,0x0A, |
432 0x10,0x0E,0x10,0x0E), | 590 0x10,0x0E,0x10,0x0E), |
433 demux_y = (vector unsigned char)(0x10,0x01,0x10,0x03, | 591 demux_y = (const vector unsigned char)AVV(0x10,0x01,0x10,0x03, |
434 0x10,0x05,0x10,0x07, | 592 0x10,0x05,0x10,0x07, |
435 0x10,0x09,0x10,0x0B, | 593 0x10,0x09,0x10,0x0B, |
436 0x10,0x0D,0x10,0x0F); | 594 0x10,0x0D,0x10,0x0F); |
437 | 595 |
438 /* | 596 /* |
459 | 617 |
460 for (i=0;i<h;i++) { | 618 for (i=0;i<h;i++) { |
461 for (j=0;j<w/16;j++) { | 619 for (j=0;j<w/16;j++) { |
462 uyvy = vec_ld (0, img); | 620 uyvy = vec_ld (0, img); |
463 U = (vector signed short) | 621 U = (vector signed short) |
464 vec_perm (uyvy, (vector unsigned char)(0), demux_u); | 622 vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u); |
465 | 623 |
466 V = (vector signed short) | 624 V = (vector signed short) |
467 vec_perm (uyvy, (vector unsigned char)(0), demux_v); | 625 vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v); |
468 | 626 |
469 Y = (vector signed short) | 627 Y = (vector signed short) |
470 vec_perm (uyvy, (vector unsigned char)(0), demux_y); | 628 vec_perm (uyvy, (vector unsigned char)AVV(0), demux_y); |
471 | 629 |
472 cvtyuvtoRGB (c, Y,U,V,&R0,&G0,&B0); | 630 cvtyuvtoRGB (c, Y,U,V,&R0,&G0,&B0); |
473 | 631 |
474 uyvy = vec_ld (16, img); | 632 uyvy = vec_ld (16, img); |
475 U = (vector signed short) | 633 U = (vector signed short) |
476 vec_perm (uyvy, (vector unsigned char)(0), demux_u); | 634 vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u); |
477 | 635 |
478 V = (vector signed short) | 636 V = (vector signed short) |
479 vec_perm (uyvy, (vector unsigned char)(0), demux_v); | 637 vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v); |
480 | 638 |
481 Y = (vector signed short) | 639 Y = (vector signed short) |
482 vec_perm (uyvy, (vector unsigned char)(0), demux_y); | 640 vec_perm (uyvy, (vector unsigned char)AVV(0), demux_y); |
483 | 641 |
484 cvtyuvtoRGB (c, Y,U,V,&R1,&G1,&B1); | 642 cvtyuvtoRGB (c, Y,U,V,&R1,&G1,&B1); |
485 | 643 |
486 R = vec_packclp (R0,R1); | 644 R = vec_packclp (R0,R1); |
487 G = vec_packclp (G0,G1); | 645 G = vec_packclp (G0,G1); |
562 | 720 |
563 } | 721 } |
564 return NULL; | 722 return NULL; |
565 } | 723 } |
566 | 724 |
567 void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4]) | 725 static uint16_t roundToInt16(int64_t f){ |
726 int r= (f + (1<<15))>>16; | |
727 if(r<-0x7FFF) return 0x8000; | |
728 else if(r> 0x7FFF) return 0x7FFF; | |
729 else return r; | |
730 } | |
731 | |
732 void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation) | |
568 { | 733 { |
569 vector signed short CY, CRV, CBU, CGU, CGV, OY, Y0; | 734 union { |
570 int64_t crv __attribute__ ((aligned(16))) = inv_table[0]; | 735 signed short tmp[8] __attribute__ ((aligned(16))); |
571 int64_t cbu __attribute__ ((aligned(16))) = inv_table[1]; | 736 vector signed short vec; |
572 int64_t cgu __attribute__ ((aligned(16))) = inv_table[2]; | 737 } buf; |
573 int64_t cgv __attribute__ ((aligned(16))) = inv_table[3]; | 738 |
574 int64_t cy = (1<<16)-1; | 739 buf.tmp[0] = ( (0xffffLL) * contrast>>8 )>>9; //cy |
575 int64_t oy = 0; | 740 buf.tmp[1] = -256*brightness; //oy |
576 short tmp __attribute__ ((aligned(16))); | 741 buf.tmp[2] = (inv_table[0]>>3) *(contrast>>16)*(saturation>>16); //crv |
577 | 742 buf.tmp[3] = (inv_table[1]>>3) *(contrast>>16)*(saturation>>16); //cbu |
578 if ((c->flags & SWS_CPU_CAPS_ALTIVEC) == 0) | 743 buf.tmp[4] = -((inv_table[2]>>1)*(contrast>>16)*(saturation>>16)); //cgu |
579 return; | 744 buf.tmp[5] = -((inv_table[3]>>1)*(contrast>>16)*(saturation>>16)); //cgv |
580 | 745 |
581 cy = (cy *c->contrast )>>17; | 746 |
582 crv= (crv*c->contrast * c->saturation)>>32; | 747 c->CSHIFT = (vector unsigned short)vec_splat((vector unsigned short)AVV(2),0); |
583 cbu= (cbu*c->contrast * c->saturation)>>32; | 748 c->CY = vec_splat ((vector signed short)buf.vec, 0); |
584 cgu= (cgu*c->contrast * c->saturation)>>32; | 749 c->OY = vec_splat ((vector signed short)buf.vec, 1); |
585 cgv= (cgv*c->contrast * c->saturation)>>32; | 750 c->CRV = vec_splat ((vector signed short)buf.vec, 2); |
586 | 751 c->CBU = vec_splat ((vector signed short)buf.vec, 3); |
587 oy -= 256*c->brightness; | 752 c->CGU = vec_splat ((vector signed short)buf.vec, 4); |
588 | 753 c->CGV = vec_splat ((vector signed short)buf.vec, 5); |
589 tmp = cy; | |
590 CY = vec_lde (0, &tmp); | |
591 CY = vec_splat (CY, 0); | |
592 | |
593 tmp = oy; | |
594 OY = vec_lde (0, &tmp); | |
595 OY = vec_splat (OY, 0); | |
596 | |
597 tmp = crv>>3; | |
598 CRV = vec_lde (0, &tmp); | |
599 CRV = vec_splat (CRV, 0); | |
600 tmp = cbu>>3; | |
601 CBU = vec_lde (0, &tmp); | |
602 CBU = vec_splat (CBU, 0); | |
603 | |
604 tmp = -(cgu>>1); | |
605 CGU = vec_lde (0, &tmp); | |
606 CGU = vec_splat (CGU, 0); | |
607 tmp = -(cgv>>1); | |
608 CGV = vec_lde (0, &tmp); | |
609 CGV = vec_splat (CGV, 0); | |
610 | |
611 c->CSHIFT = (vector unsigned short)(2); | |
612 c->CY = CY; | |
613 c->OY = OY; | |
614 c->CRV = CRV; | |
615 c->CBU = CBU; | |
616 c->CGU = CGU; | |
617 c->CGV = CGV; | |
618 | |
619 #if 0 | 754 #if 0 |
620 printf ("cy: %hvx\n", CY); | 755 { |
621 printf ("oy: %hvx\n", OY); | 756 int i; |
622 printf ("crv: %hvx\n", CRV); | 757 char *v[6]={"cy","oy","crv","cbu","cgu","cgv"}; |
623 printf ("cbu: %hvx\n", CBU); | 758 for (i=0; i<6;i++) |
624 printf ("cgv: %hvx\n", CGV); | 759 printf("%s %d ", v[i],buf.tmp[i] ); |
625 printf ("cgu: %hvx\n", CGU); | 760 printf("\n"); |
761 } | |
626 #endif | 762 #endif |
627 | |
628 return; | 763 return; |
629 } | 764 } |
630 | 765 |
631 | 766 |
632 void | 767 void |
635 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, | 770 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, |
636 uint8_t *dest, int dstW, int dstY) | 771 uint8_t *dest, int dstW, int dstY) |
637 { | 772 { |
638 int i,j; | 773 int i,j; |
639 short tmp __attribute__((aligned (16))); | 774 short tmp __attribute__((aligned (16))); |
640 short *p; | 775 int16_t *p; |
641 short *f; | 776 short *f; |
642 vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V; | 777 vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V; |
643 vector signed short R0,G0,B0,R1,G1,B1; | 778 vector signed short R0,G0,B0,R1,G1,B1; |
644 | 779 |
645 vector unsigned char R,G,B,pels[3]; | 780 vector unsigned char R,G,B,pels[3]; |
646 vector unsigned char *out,*nout; | 781 vector unsigned char *out,*nout; |
647 vector signed short RND = (vector signed short)(1<<3); | 782 |
648 vector unsigned short SCL = (vector unsigned short)(4); | 783 vector signed short RND = vec_splat((vector signed short)AVV(1<<3),0); |
784 vector unsigned short SCL = vec_splat((vector unsigned short)AVV(4),0); | |
649 unsigned long scratch[16] __attribute__ ((aligned (16))); | 785 unsigned long scratch[16] __attribute__ ((aligned (16))); |
650 | 786 |
651 vector signed short *vYCoeffsBank, *vCCoeffsBank; | 787 vector signed short *vYCoeffsBank, *vCCoeffsBank; |
652 | 788 |
653 vector signed short *YCoeffs, *CCoeffs; | 789 vector signed short *YCoeffs, *CCoeffs; |