comparison libpostproc/postprocess.c @ 829:c39e14fc2392 libavcodec

cleanup
author michael
date Sat, 02 Nov 2002 13:58:14 +0000
parents 6d225a8f0ff0
children 0a1fbae9f6e1
comparison
equal deleted inserted replaced
828:ace3ccd18dd2 829:c39e14fc2392
75 //#undef HAVE_MMX 75 //#undef HAVE_MMX
76 //#undef ARCH_X86 76 //#undef ARCH_X86
77 //#define DEBUG_BRIGHTNESS 77 //#define DEBUG_BRIGHTNESS
78 #include "../libvo/fastmemcpy.h" 78 #include "../libvo/fastmemcpy.h"
79 #include "postprocess.h" 79 #include "postprocess.h"
80 #include "postprocess_internal.h"
80 #include "../mangle.h" 81 #include "../mangle.h"
81 82
82 #define MIN(a,b) ((a) > (b) ? (b) : (a)) 83 #define MIN(a,b) ((a) > (b) ? (b) : (a))
83 #define MAX(a,b) ((a) < (b) ? (b) : (a)) 84 #define MAX(a,b) ((a) < (b) ? (b) : (a))
84 #define ABS(a) ((a) > 0 ? (a) : (-(a))) 85 #define ABS(a) ((a) > 0 ? (a) : (-(a)))
102 103
103 static int verbose= 0; 104 static int verbose= 0;
104 105
105 static const int deringThreshold= 20; 106 static const int deringThreshold= 20;
106 107
107 struct PPFilter{
108 char *shortName;
109 char *longName;
110 int chromDefault; // is chrominance filtering on by default if this filter is manually activated
111 int minLumQuality; // minimum quality to turn luminance filtering on
112 int minChromQuality; // minimum quality to turn chrominance filtering on
113 int mask; // Bitmask to turn this filter on
114 };
115
116 typedef struct PPContext{
117 uint8_t *tempBlocks; //used for the horizontal code
118
119 /* we need 64bit here otherwise weŽll going to have a problem
120 after watching a black picture for 5 hours*/
121 uint64_t *yHistogram;
122
123 uint64_t __attribute__((aligned(8))) packedYOffset;
124 uint64_t __attribute__((aligned(8))) packedYScale;
125
126 /* Temporal noise reducing buffers */
127 uint8_t *tempBlured[3];
128 int32_t *tempBluredPast[3];
129
130 /* Temporary buffers for handling the last row(s) */
131 uint8_t *tempDst;
132 uint8_t *tempSrc;
133
134 /* Temporary buffers for handling the last block */
135 uint8_t *tempDstBlock;
136 uint8_t *tempSrcBlock;
137 uint8_t *deintTemp;
138
139 uint64_t __attribute__((aligned(8))) pQPb;
140 uint64_t __attribute__((aligned(8))) pQPb2;
141
142 uint64_t __attribute__((aligned(8))) mmxDcOffset[32];
143 uint64_t __attribute__((aligned(8))) mmxDcThreshold[32];
144
145 QP_STORE_T *nonBQPTable;
146
147 int QP;
148 int nonBQP;
149
150 int frameNum;
151
152 int cpuCaps;
153
154 PPMode ppMode;
155 } PPContext;
156 108
157 static struct PPFilter filters[]= 109 static struct PPFilter filters[]=
158 { 110 {
159 {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK}, 111 {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK},
160 {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK}, 112 {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK},
487 #endif 439 #endif
488 440
489 // minor note: the HAVE_xyz is messed up after that line so dont use it 441 // minor note: the HAVE_xyz is messed up after that line so dont use it
490 442
491 static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, 443 static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
492 QP_STORE_T QPs[], int QPStride, int isColor, PPMode *ppMode, pp_context_t *vc) 444 QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc)
493 { 445 {
494 PPContext *c= (PPContext *)vc; 446 PPContext *c= (PPContext *)vc;
447 PPMode *ppMode= (PPMode *)vm;
495 c->ppMode= *ppMode; //FIXME 448 c->ppMode= *ppMode; //FIXME
496 449
497 // useing ifs here as they are faster than function pointers allthough the 450 // useing ifs here as they are faster than function pointers allthough the
498 // difference wouldnt be messureable here but its much better because 451 // difference wouldnt be messureable here but its much better because
499 // someone might exchange the cpu whithout restarting mplayer ;) 452 // someone might exchange the cpu whithout restarting mplayer ;)
568 /** 521 /**
569 * returns a PPMode struct which will have a non 0 error variable if an error occured 522 * returns a PPMode struct which will have a non 0 error variable if an error occured
570 * name is the string after "-pp" on the command line 523 * name is the string after "-pp" on the command line
571 * quality is a number from 0 to GET_PP_QUALITY_MAX 524 * quality is a number from 0 to GET_PP_QUALITY_MAX
572 */ 525 */
573 struct PPMode pp_get_mode_by_name_and_quality(char *name, int quality) 526 pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality)
574 { 527 {
575 char temp[GET_MODE_BUFFER_SIZE]; 528 char temp[GET_MODE_BUFFER_SIZE];
576 char *p= temp; 529 char *p= temp;
577 char *filterDelimiters= ",/"; 530 char *filterDelimiters= ",/";
578 char *optionDelimiters= ":"; 531 char *optionDelimiters= ":";
579 struct PPMode ppMode; 532 struct PPMode *ppMode;
580 char *filterToken; 533 char *filterToken;
581 534
582 ppMode.lumMode= 0; 535 ppMode= memalign(8, sizeof(PPMode));
583 ppMode.chromMode= 0; 536
584 ppMode.maxTmpNoise[0]= 700; 537 ppMode->lumMode= 0;
585 ppMode.maxTmpNoise[1]= 1500; 538 ppMode->chromMode= 0;
586 ppMode.maxTmpNoise[2]= 3000; 539 ppMode->maxTmpNoise[0]= 700;
587 ppMode.maxAllowedY= 234; 540 ppMode->maxTmpNoise[1]= 1500;
588 ppMode.minAllowedY= 16; 541 ppMode->maxTmpNoise[2]= 3000;
589 ppMode.baseDcDiff= 256/4; 542 ppMode->maxAllowedY= 234;
590 ppMode.flatnessThreshold=40; 543 ppMode->minAllowedY= 16;
591 ppMode.flatnessThreshold= 56-16; 544 ppMode->baseDcDiff= 256/4;
592 ppMode.maxClippedThreshold= 0.01; 545 ppMode->flatnessThreshold=40;
593 ppMode.error=0; 546 ppMode->flatnessThreshold= 56-16;
547 ppMode->maxClippedThreshold= 0.01;
548 ppMode->error=0;
594 549
595 strncpy(temp, name, GET_MODE_BUFFER_SIZE); 550 strncpy(temp, name, GET_MODE_BUFFER_SIZE);
596 551
597 if(verbose>1) printf("pp: %s\n", name); 552 if(verbose>1) printf("pp: %s\n", name);
598 553
650 605
651 plen= strlen(p); 606 plen= strlen(p);
652 spaceLeft= p - temp + plen; 607 spaceLeft= p - temp + plen;
653 if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE) 608 if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE)
654 { 609 {
655 ppMode.error++; 610 ppMode->error++;
656 break; 611 break;
657 } 612 }
658 memmove(p + newlen, p, plen+1); 613 memmove(p + newlen, p, plen+1);
659 memcpy(p, replaceTable[2*i + 1], newlen); 614 memcpy(p, replaceTable[2*i + 1], newlen);
660 filterNameOk=1; 615 filterNameOk=1;
665 { 620 {
666 // printf("Compareing %s, %s, %s\n", filters[i].shortName,filters[i].longName, filterName); 621 // printf("Compareing %s, %s, %s\n", filters[i].shortName,filters[i].longName, filterName);
667 if( !strcmp(filters[i].longName, filterName) 622 if( !strcmp(filters[i].longName, filterName)
668 || !strcmp(filters[i].shortName, filterName)) 623 || !strcmp(filters[i].shortName, filterName))
669 { 624 {
670 ppMode.lumMode &= ~filters[i].mask; 625 ppMode->lumMode &= ~filters[i].mask;
671 ppMode.chromMode &= ~filters[i].mask; 626 ppMode->chromMode &= ~filters[i].mask;
672 627
673 filterNameOk=1; 628 filterNameOk=1;
674 if(!enable) break; // user wants to disable it 629 if(!enable) break; // user wants to disable it
675 630
676 if(q >= filters[i].minLumQuality) 631 if(q >= filters[i].minLumQuality)
677 ppMode.lumMode|= filters[i].mask; 632 ppMode->lumMode|= filters[i].mask;
678 if(chrom==1 || (chrom==-1 && filters[i].chromDefault)) 633 if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
679 if(q >= filters[i].minChromQuality) 634 if(q >= filters[i].minChromQuality)
680 ppMode.chromMode|= filters[i].mask; 635 ppMode->chromMode|= filters[i].mask;
681 636
682 if(filters[i].mask == LEVEL_FIX) 637 if(filters[i].mask == LEVEL_FIX)
683 { 638 {
684 int o; 639 int o;
685 ppMode.minAllowedY= 16; 640 ppMode->minAllowedY= 16;
686 ppMode.maxAllowedY= 234; 641 ppMode->maxAllowedY= 234;
687 for(o=0; options[o]!=NULL; o++) 642 for(o=0; options[o]!=NULL; o++)
688 { 643 {
689 if( !strcmp(options[o],"fullyrange") 644 if( !strcmp(options[o],"fullyrange")
690 ||!strcmp(options[o],"f")) 645 ||!strcmp(options[o],"f"))
691 { 646 {
692 ppMode.minAllowedY= 0; 647 ppMode->minAllowedY= 0;
693 ppMode.maxAllowedY= 255; 648 ppMode->maxAllowedY= 255;
694 numOfUnknownOptions--; 649 numOfUnknownOptions--;
695 } 650 }
696 } 651 }
697 } 652 }
698 else if(filters[i].mask == TEMP_NOISE_FILTER) 653 else if(filters[i].mask == TEMP_NOISE_FILTER)
701 int numOfNoises=0; 656 int numOfNoises=0;
702 657
703 for(o=0; options[o]!=NULL; o++) 658 for(o=0; options[o]!=NULL; o++)
704 { 659 {
705 char *tail; 660 char *tail;
706 ppMode.maxTmpNoise[numOfNoises]= 661 ppMode->maxTmpNoise[numOfNoises]=
707 strtol(options[o], &tail, 0); 662 strtol(options[o], &tail, 0);
708 if(tail!=options[o]) 663 if(tail!=options[o])
709 { 664 {
710 numOfNoises++; 665 numOfNoises++;
711 numOfUnknownOptions--; 666 numOfUnknownOptions--;
722 char *tail; 677 char *tail;
723 int val= strtol(options[o], &tail, 0); 678 int val= strtol(options[o], &tail, 0);
724 if(tail==options[o]) break; 679 if(tail==options[o]) break;
725 680
726 numOfUnknownOptions--; 681 numOfUnknownOptions--;
727 if(o==0) ppMode.baseDcDiff= val; 682 if(o==0) ppMode->baseDcDiff= val;
728 else ppMode.flatnessThreshold= val; 683 else ppMode->flatnessThreshold= val;
729 } 684 }
730 } 685 }
731 else if(filters[i].mask == FORCE_QUANT) 686 else if(filters[i].mask == FORCE_QUANT)
732 { 687 {
733 int o; 688 int o;
734 ppMode.forcedQuant= 15; 689 ppMode->forcedQuant= 15;
735 690
736 for(o=0; options[o]!=NULL && o<1; o++) 691 for(o=0; options[o]!=NULL && o<1; o++)
737 { 692 {
738 char *tail; 693 char *tail;
739 int val= strtol(options[o], &tail, 0); 694 int val= strtol(options[o], &tail, 0);
740 if(tail==options[o]) break; 695 if(tail==options[o]) break;
741 696
742 numOfUnknownOptions--; 697 numOfUnknownOptions--;
743 ppMode.forcedQuant= val; 698 ppMode->forcedQuant= val;
744 } 699 }
745 } 700 }
746 } 701 }
747 } 702 }
748 if(!filterNameOk) ppMode.error++; 703 if(!filterNameOk) ppMode->error++;
749 ppMode.error += numOfUnknownOptions; 704 ppMode->error += numOfUnknownOptions;
750 } 705 }
751 706
752 if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode.lumMode, ppMode.chromMode); 707 if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
708 if(ppMode->error)
709 {
710 fprintf(stderr, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
711 free(ppMode);
712 return NULL;
713 }
753 return ppMode; 714 return ppMode;
754 } 715 }
755 716
756 void *pp_get_context(int width, int height, int cpuCaps){ 717 void pp_free_mode(pp_mode_t *mode){
718 if(mode) free(mode);
719 }
720
721 pp_context_t *pp_get_context(int width, int height, int cpuCaps){
757 PPContext *c= memalign(32, sizeof(PPContext)); 722 PPContext *c= memalign(32, sizeof(PPContext));
758 int i; 723 int i;
759 int mbWidth = (width+15)>>4; 724 int mbWidth = (width+15)>>4;
760 int mbHeight= (height+15)>>4; 725 int mbHeight= (height+15)>>4;
761 726
810 775
811 void pp_postprocess(uint8_t * src[3], int srcStride[3], 776 void pp_postprocess(uint8_t * src[3], int srcStride[3],
812 uint8_t * dst[3], int dstStride[3], 777 uint8_t * dst[3], int dstStride[3],
813 int width, int height, 778 int width, int height,
814 QP_STORE_T *QP_store, int QPStride, 779 QP_STORE_T *QP_store, int QPStride,
815 PPMode *mode, void *vc, int pict_type) 780 pp_mode_t *vm, void *vc, int pict_type)
816 { 781 {
817 int mbWidth = (width+15)>>4; 782 int mbWidth = (width+15)>>4;
818 int mbHeight= (height+15)>>4; 783 int mbHeight= (height+15)>>4;
819 QP_STORE_T quantArray[2048/8]; 784 QP_STORE_T quantArray[2048/8];
785 PPMode *mode = (PPMode*)vm;
820 PPContext *c = (PPContext*)vc; 786 PPContext *c = (PPContext*)vc;
821 787
822 if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) 788 if(QP_store==NULL || (mode->lumMode & FORCE_QUANT))
823 { 789 {
824 int i; 790 int i;