comparison postproc/yuv2rgb.c @ 6453:7f06ef0d58a6

8bpp bugfixes (brightness, contrast ...) 4bpp
author michael
date Mon, 17 Jun 2002 01:48:31 +0000
parents dae4143c636b
children f0b64210ce97
comparison
equal deleted inserted replaced
6452:dae4143c636b 6453:7f06ef0d58a6
85 85
86 uint64_t __attribute__((aligned(8))) dither8[2]={ 86 uint64_t __attribute__((aligned(8))) dither8[2]={
87 0x0602060206020602LL, 87 0x0602060206020602LL,
88 0x0004000400040004LL,}; 88 0x0004000400040004LL,};
89 89
90 uint8_t __attribute__((aligned(8))) dither32[4][8]={ 90 uint8_t __attribute__((aligned(8))) dither_4x4_32[4][8]={
91 { 0,16, 6,22, 0,16, 6,22}, 91 { 0,16, 6,22, 0,16, 6,22},
92 {28, 8,24,14,28, 8,24,14}, 92 {28, 8,24,14,28, 8,24,14},
93 { 4,20, 2,18, 4,20, 2,18}, 93 { 4,20, 2,18, 4,20, 2,18},
94 {26,12,30,10,26,12,30,10}, 94 {26,12,30,10,26,12,30,10},
95 }; 95 };
96 96
97 uint8_t __attribute__((aligned(8))) dither64[4][8]={ 97 uint8_t __attribute__((aligned(8))) dither_4x4_64[4][8]={
98 { 8,40, 4,36, 8,40, 4,36,}, 98 { 8,40, 4,36, 8,40, 4,36,},
99 {52,24,60,20,52,24,60,20,}, 99 {52,24,60,20,52,24,60,20,},
100 {00,32,12,44,00,32,12,44,}, 100 {00,32,12,44,00,32,12,44,},
101 {56,16,48,28,56,16,48,28,}, 101 {56,16,48,28,56,16,48,28,},
102 };
103
104 uint8_t __attribute__((aligned(8))) dither_8x8_64[8][8]={
105 { 0, 48, 12, 60, 3, 51, 15, 63, },
106 { 32, 16, 44, 28, 35, 19, 47, 31, },
107 { 8, 56, 4, 52, 11, 59, 7, 55, },
108 { 40, 24, 36, 20, 43, 27, 39, 23, },
109 { 2, 50, 14, 62, 1, 49, 13, 61, },
110 { 34, 18, 46, 30, 33, 17, 45, 29, },
111 { 10, 58, 6, 54, 9, 57, 5, 53, },
112 { 42, 26, 38, 22, 41, 25, 37, 21, },
113 };
114
115 uint8_t __attribute__((aligned(8))) dither_8x8_128[8][8]={
116 { 68, 36, 92, 60, 66, 34, 90, 58, },
117 { 20, 116, 12, 108, 18, 114, 10, 106, },
118 { 84, 52, 76, 44, 82, 50, 74, 42, },
119 { 0, 96, 24, 120, 6, 102, 30, 126, },
120 { 64, 32, 88, 56, 70, 38, 94, 62, },
121 { 16, 112, 8, 104, 22, 118, 14, 110, },
122 { 80, 48, 72, 40, 86, 54, 78, 46, },
123 { 4, 100, 28, 124, 2, 98, 26, 122, },
102 }; 124 };
103 125
104 #undef HAVE_MMX 126 #undef HAVE_MMX
105 #undef ARCH_X86 127 #undef ARCH_X86
106 128
445 dst_1 += 8; 467 dst_1 += 8;
446 dst_2 += 8; 468 dst_2 += 8;
447 } 469 }
448 } 470 }
449 471
450 // This is exactly the same code as yuv2rgb_c_32 except for the types of
451 // r, g, b, dst_1, dst_2 472 // r, g, b, dst_1, dst_2
452 static void yuv2rgb_c_8_ordered_dither (uint8_t * py_1, uint8_t * py_2, 473 static void yuv2rgb_c_8_ordered_dither (uint8_t * py_1, uint8_t * py_2,
453 uint8_t * pu, uint8_t * pv, 474 uint8_t * pu, uint8_t * pv,
454 void * _dst_1, void * _dst_2, int h_size, int v_pos) 475 void * _dst_1, void * _dst_2, int h_size, int v_pos)
455 { 476 {
460 h_size >>= 3; 481 h_size >>= 3;
461 dst_1 = _dst_1; 482 dst_1 = _dst_1;
462 dst_2 = _dst_2; 483 dst_2 = _dst_2;
463 484
464 while (h_size--) { 485 while (h_size--) {
465 uint8_t *d32= dither32[v_pos&3]; 486 uint8_t *d32= dither_4x4_32[v_pos&3];
466 uint8_t *d64= dither64[v_pos&3]; 487 uint8_t *d64= dither_4x4_64[v_pos&3];
467 488
468 #define DST1a(i) \ 489 #define DST1a(i) \
469 Y = py_1[2*i]; \ 490 Y = py_1[2*i]; \
470 dst_1[2*i] = r[Y+d32[0]] + g[Y+d32[0]] + b[Y+d64[0]]; \ 491 dst_1[2*i] = r[Y+d32[0]] + g[Y+d32[0]] + b[Y+d64[0]]; \
471 Y = py_1[2*i+1]; \ 492 Y = py_1[2*i+1]; \
511 py_2 += 8; 532 py_2 += 8;
512 dst_1 += 8; 533 dst_1 += 8;
513 dst_2 += 8; 534 dst_2 += 8;
514 } 535 }
515 } 536 }
537
538
539 // This is exactly the same code as yuv2rgb_c_32 except for the types of
540 // r, g, b, dst_1, dst_2
541 static void yuv2rgb_c_4 (uint8_t * py_1, uint8_t * py_2,
542 uint8_t * pu, uint8_t * pv,
543 void * _dst_1, void * _dst_2, int h_size, int v_pos)
544 {
545 int U, V, Y, out;
546 uint8_t * r, * g, * b;
547 uint8_t * dst_1, * dst_2;
548
549 h_size >>= 3;
550 dst_1 = _dst_1;
551 dst_2 = _dst_2;
552
553 while (h_size--) {
554 RGB(0);
555 DST1(0);
556 DST2(0);
557
558 RGB(1);
559 DST2(1);
560 DST1(1);
561
562 RGB(2);
563 DST1(2);
564 DST2(2);
565
566 RGB(3);
567 DST2(3);
568 DST1(3);
569
570 pu += 4;
571 pv += 4;
572 py_1 += 8;
573 py_2 += 8;
574 dst_1 += 8;
575 dst_2 += 8;
576 }
577 }
578
579 static void yuv2rgb_c_4_ordered_dither (uint8_t * py_1, uint8_t * py_2,
580 uint8_t * pu, uint8_t * pv,
581 void * _dst_1, void * _dst_2, int h_size, int v_pos)
582 {
583 int U, V, Y;
584 uint8_t * r, * g, * b;
585 uint8_t * dst_1, * dst_2;
586
587 h_size >>= 3;
588 dst_1 = _dst_1;
589 dst_2 = _dst_2;
590
591 while (h_size--) {
592 uint8_t *d64= dither_8x8_64 [v_pos&7];
593 uint8_t *d128=dither_8x8_128[v_pos&7];
594
595 #define DST1bpp4(i,o) \
596 Y = py_1[2*i]; \
597 dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
598 Y = py_1[2*i+1]; \
599 dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
600
601 #define DST2bpp4(i,o) \
602 Y = py_2[2*i]; \
603 dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
604 Y = py_2[2*i+1]; \
605 dst_2[2*i+1] = r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]];
606
607
608 RGB(0);
609 DST1bpp4(0,0);
610 DST2bpp4(0,0);
611
612 RGB(1);
613 DST2bpp4(1,2);
614 DST1bpp4(1,2);
615
616 RGB(2);
617 DST1bpp4(2,4);
618 DST2bpp4(2,4);
619
620 RGB(3);
621 DST2bpp4(3,6);
622 DST1bpp4(3,6);
623
624 pu += 4;
625 pv += 4;
626 py_1 += 8;
627 py_2 += 8;
628 dst_1 += 8;
629 dst_2 += 8;
630 }
631 }
632
516 633
517 static int div_round (int dividend, int divisor) 634 static int div_round (int dividend, int divisor)
518 { 635 {
519 if (dividend > 0) 636 if (dividend > 0)
520 return (dividend + (divisor>>1)) / divisor; 637 return (dividend + (divisor>>1)) / divisor;
528 uint8_t table_Y[1024]; 645 uint8_t table_Y[1024];
529 uint32_t *table_32 = 0; 646 uint32_t *table_32 = 0;
530 uint16_t *table_16 = 0; 647 uint16_t *table_16 = 0;
531 uint8_t *table_8 = 0; 648 uint8_t *table_8 = 0;
532 uint8_t *table_332 = 0; 649 uint8_t *table_332 = 0;
650 uint8_t *table_121 = 0;
651 uint8_t *table_1 = 0;
533 int entry_size = 0; 652 int entry_size = 0;
534 void *table_r = 0, *table_g = 0, *table_b = 0; 653 void *table_r = 0, *table_g = 0, *table_b = 0;
535 654
536 int crv = Inverse_Table_6_9[matrix_coefficients][0]; 655 int crv = Inverse_Table_6_9[matrix_coefficients][0];
537 int cbu = Inverse_Table_6_9[matrix_coefficients][1]; 656 int cbu = Inverse_Table_6_9[matrix_coefficients][1];
621 table_r = table_332 + 197; 740 table_r = table_332 + 197;
622 table_b = table_332 + 197 + 685; 741 table_b = table_332 + 197 + 685;
623 table_g = table_332 + 197 + 2*682; 742 table_g = table_332 + 197 + 2*682;
624 743
625 for (i = -197; i < 256+197; i++) { 744 for (i = -197; i < 256+197; i++) {
626 int j = table_Y[i+384] >> 5; 745 int j = (table_Y[i+384] - 16) >> 5;
746 if(j<0) j=0;
627 747
628 if (mode == MODE_RGB) 748 if (mode == MODE_RGB)
629 j <<= 5; 749 j <<= 5;
630 750
631 ((uint8_t *)table_r)[i] = j; 751 ((uint8_t *)table_r)[i] = j;
632 } 752 }
633 for (i = -132; i < 256+132; i++) { 753 for (i = -132; i < 256+132; i++) {
634 int j = table_Y[i+384] >> 5; 754 int j = (table_Y[i+384] - 16) >> 5;
755 if(j<0) j=0;
635 756
636 if (mode == MODE_BGR) 757 if (mode == MODE_BGR)
637 j <<= 1; 758 j <<= 1;
638 759
639 ((uint8_t *)table_g)[i] = j << 2; 760 ((uint8_t *)table_g)[i] = j << 2;
640 } 761 }
641 for (i = -232; i < 256+232; i++) { 762 for (i = -232; i < 256+232; i++) {
642 int j = table_Y[i+384] >> 6; 763 int j = (table_Y[i+384] - 32) >> 6;
764 if(j<0) j=0;
643 765
644 if (mode == MODE_BGR) 766 if (mode == MODE_BGR)
645 j <<= 6; 767 j <<= 6;
768
769 ((uint8_t *)table_b)[i] = j;
770 }
771 break;
772 case 4:
773 yuv2rgb_c_internal = yuv2rgb_c_4_ordered_dither; //yuv2rgb_c_4;
774
775 table_121 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
776
777 entry_size = sizeof (uint8_t);
778 table_r = table_121 + 197;
779 table_b = table_121 + 197 + 685;
780 table_g = table_121 + 197 + 2*682;
781
782 for (i = -197; i < 256+197; i++) {
783 int j = (table_Y[i+384] - 64) >> 7;
784 if(j<0) j=0;
785
786 if (mode == MODE_RGB)
787 j <<= 3;
788
789 ((uint8_t *)table_r)[i] = j;
790 }
791 for (i = -132; i < 256+132; i++) {
792 int j = (table_Y[i+384] - 32) >> 6;
793 if(j<0) j=0;
794
795 ((uint8_t *)table_g)[i] = j << 1;
796 }
797 for (i = -232; i < 256+232; i++) {
798 int j =(table_Y[i+384] - 64) >> 7;
799 if(j<0) j=0;
800
801 if (mode == MODE_BGR)
802 j <<= 3;
646 803
647 ((uint8_t *)table_b)[i] = j; 804 ((uint8_t *)table_b)[i] = j;
648 } 805 }
649 break; 806 break;
650 807