comparison postprocess.c @ 29:2e855f3f4e0b libpostproc

printf --> av_log with some help from Oded
author diego
date Wed, 11 Oct 2006 00:18:33 +0000
parents c83a71c1729d
children 81ad3274583c
comparison
equal deleted inserted replaced
28:b55400a067f0 29:2e855f3f4e0b
116 static uint64_t __attribute__((aligned(8))) attribute_used b80= 0x8080808080808080LL; 116 static uint64_t __attribute__((aligned(8))) attribute_used b80= 0x8080808080808080LL;
117 #endif 117 #endif
118 118
119 static uint8_t clip_table[3*256]; 119 static uint8_t clip_table[3*256];
120 static uint8_t * const clip_tab= clip_table + 256; 120 static uint8_t * const clip_tab= clip_table + 256;
121
122 static const int verbose= 0;
123 121
124 static const int attribute_used deringThreshold= 20; 122 static const int attribute_used deringThreshold= 20;
125 123
126 124
127 static struct PPFilter filters[]= 125 static struct PPFilter filters[]=
771 ppMode->maxClippedThreshold= 0.01; 769 ppMode->maxClippedThreshold= 0.01;
772 ppMode->error=0; 770 ppMode->error=0;
773 771
774 strncpy(temp, name, GET_MODE_BUFFER_SIZE); 772 strncpy(temp, name, GET_MODE_BUFFER_SIZE);
775 773
776 if(verbose>1) printf("pp: %s\n", name); 774 av_log(NULL, AV_LOG_DEBUG, "pp: %s\n", name);
777 775
778 for(;;){ 776 for(;;){
779 char *filterName; 777 char *filterName;
780 int q= 1000000; //PP_QUALITY_MAX; 778 int q= 1000000; //PP_QUALITY_MAX;
781 int chrom=-1; 779 int chrom=-1;
789 787
790 filterToken= strtok(p, filterDelimiters); 788 filterToken= strtok(p, filterDelimiters);
791 if(filterToken == NULL) break; 789 if(filterToken == NULL) break;
792 p+= strlen(filterToken) + 1; // p points to next filterToken 790 p+= strlen(filterToken) + 1; // p points to next filterToken
793 filterName= strtok(filterToken, optionDelimiters); 791 filterName= strtok(filterToken, optionDelimiters);
794 if(verbose>1) printf("pp: %s::%s\n", filterToken, filterName); 792 av_log(NULL, AV_LOG_DEBUG, "pp: %s::%s\n", filterToken, filterName);
795 793
796 if(*filterName == '-') 794 if(*filterName == '-')
797 { 795 {
798 enable=0; 796 enable=0;
799 filterName++; 797 filterName++;
801 799
802 for(;;){ //for all options 800 for(;;){ //for all options
803 option= strtok(NULL, optionDelimiters); 801 option= strtok(NULL, optionDelimiters);
804 if(option == NULL) break; 802 if(option == NULL) break;
805 803
806 if(verbose>1) printf("pp: option: %s\n", option); 804 av_log(NULL, AV_LOG_DEBUG, "pp: option: %s\n", option);
807 if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality; 805 if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
808 else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0; 806 else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
809 else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1; 807 else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
810 else if(!strcmp("noluma", option) || !strcmp("n", option)) luma=0; 808 else if(!strcmp("noluma", option) || !strcmp("n", option)) luma=0;
811 else 809 else
842 } 840 }
843 } 841 }
844 842
845 for(i=0; filters[i].shortName!=NULL; i++) 843 for(i=0; filters[i].shortName!=NULL; i++)
846 { 844 {
847 // printf("Compareing %s, %s, %s\n", filters[i].shortName,filters[i].longName, filterName);
848 if( !strcmp(filters[i].longName, filterName) 845 if( !strcmp(filters[i].longName, filterName)
849 || !strcmp(filters[i].shortName, filterName)) 846 || !strcmp(filters[i].shortName, filterName))
850 { 847 {
851 ppMode->lumMode &= ~filters[i].mask; 848 ppMode->lumMode &= ~filters[i].mask;
852 ppMode->chromMode &= ~filters[i].mask; 849 ppMode->chromMode &= ~filters[i].mask;
929 } 926 }
930 if(!filterNameOk) ppMode->error++; 927 if(!filterNameOk) ppMode->error++;
931 ppMode->error += numOfUnknownOptions; 928 ppMode->error += numOfUnknownOptions;
932 } 929 }
933 930
934 if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode); 931 av_log(NULL, AV_LOG_DEBUG, "pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
935 if(ppMode->error) 932 if(ppMode->error)
936 { 933 {
937 fprintf(stderr, "%d errors in postprocess string \"%s\"\n", ppMode->error, name); 934 av_log(NULL, AV_LOG_ERROR, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
938 av_free(ppMode); 935 av_free(ppMode);
939 return NULL; 936 return NULL;
940 } 937 }
941 return ppMode; 938 return ppMode;
942 } 939 }
984 for(i=256; i<512; i++) 981 for(i=256; i<512; i++)
985 clip_table[i]= i; 982 clip_table[i]= i;
986 memset(clip_table+512, 0, 256); 983 memset(clip_table+512, 0, 256);
987 } 984 }
988 985
986 static const char * context_to_name(void * ptr) {
987 return "postproc";
988 }
989
990 static AVClass av_codec_context_class = { "Postproc", context_to_name, NULL };
991
989 pp_context_t *pp_get_context(int width, int height, int cpuCaps){ 992 pp_context_t *pp_get_context(int width, int height, int cpuCaps){
990 PPContext *c= av_malloc(sizeof(PPContext)); 993 PPContext *c= av_malloc(sizeof(PPContext));
991 int stride= (width+15)&(~15); //assumed / will realloc if needed 994 int stride= (width+15)&(~15); //assumed / will realloc if needed
992 int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed 995 int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
993 996
994 global_init(); 997 global_init();
995 998
996 memset(c, 0, sizeof(PPContext)); 999 memset(c, 0, sizeof(PPContext));
1000 c->av_class = &av_codec_context_class;
997 c->cpuCaps= cpuCaps; 1001 c->cpuCaps= cpuCaps;
998 if(cpuCaps&PP_FORMAT){ 1002 if(cpuCaps&PP_FORMAT){
999 c->hChromaSubSample= cpuCaps&0x3; 1003 c->hChromaSubSample= cpuCaps&0x3;
1000 c->vChromaSubSample= (cpuCaps>>4)&0x3; 1004 c->vChromaSubSample= (cpuCaps>>4)&0x3;
1001 }else{ 1005 }else{
1058 if(mode->lumMode & FORCE_QUANT) 1062 if(mode->lumMode & FORCE_QUANT)
1059 for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant; 1063 for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant;
1060 else 1064 else
1061 for(i=0; i<mbWidth; i++) QP_store[i]= 1; 1065 for(i=0; i<mbWidth; i++) QP_store[i]= 1;
1062 } 1066 }
1063 //printf("pict_type:%d\n", pict_type);
1064 1067
1065 if(pict_type & PP_PICT_TYPE_QP2){ 1068 if(pict_type & PP_PICT_TYPE_QP2){
1066 int i; 1069 int i;
1067 const int count= mbHeight * absQPStride; 1070 const int count= mbHeight * absQPStride;
1068 for(i=0; i<(count>>2); i++){ 1071 for(i=0; i<(count>>2); i++){
1077 1080
1078 if(0){ 1081 if(0){
1079 int x,y; 1082 int x,y;
1080 for(y=0; y<mbHeight; y++){ 1083 for(y=0; y<mbHeight; y++){
1081 for(x=0; x<mbWidth; x++){ 1084 for(x=0; x<mbWidth; x++){
1082 printf("%2d ", QP_store[x + y*QPStride]); 1085 av_log(c, AV_LOG_INFO, "%2d ", QP_store[x + y*QPStride]);
1083 } 1086 }
1084 printf("\n"); 1087 av_log(c, AV_LOG_INFO, "\n");
1085 } 1088 }
1086 printf("\n"); 1089 av_log(c, AV_LOG_INFO, "\n");
1087 } 1090 }
1088 1091
1089 if((pict_type&7)!=3) 1092 if((pict_type&7)!=3)
1090 { 1093 {
1091 if (QPStride >= 0) { 1094 if (QPStride >= 0) {
1105 } 1108 }
1106 } 1109 }
1107 } 1110 }
1108 } 1111 }
1109 1112
1110 if(verbose>2) 1113 av_log(c, AV_LOG_DEBUG, "using npp filters 0x%X/0x%X\n",
1111 { 1114 mode->lumMode, mode->chromMode);
1112 printf("using npp filters 0x%X/0x%X\n", mode->lumMode, mode->chromMode);
1113 }
1114 1115
1115 postProcess(src[0], srcStride[0], dst[0], dstStride[0], 1116 postProcess(src[0], srcStride[0], dst[0], dstStride[0],
1116 width, height, QP_store, QPStride, 0, mode, c); 1117 width, height, QP_store, QPStride, 0, mode, c);
1117 1118
1118 width = (width )>>c->hChromaSubSample; 1119 width = (width )>>c->hChromaSubSample;