Mercurial > libavcodec.hg
comparison libpostproc/postprocess.c @ 1196:2e06398e4647 libavcodec
mpeg2 qscale flag
a few bugfixes for the C pp code
minor optimization
| author | michaelni |
|---|---|
| date | Fri, 18 Apr 2003 12:45:34 +0000 |
| parents | 57fe9c4e0c6e |
| children | d9cbc8ef5a33 |
comparison
equal
deleted
inserted
replaced
| 1195:f7522f310c7e | 1196:2e06398e4647 |
|---|---|
| 197 */ | 197 */ |
| 198 static inline int isHorizDC(uint8_t src[], int stride, PPContext *c) | 198 static inline int isHorizDC(uint8_t src[], int stride, PPContext *c) |
| 199 { | 199 { |
| 200 int numEq= 0; | 200 int numEq= 0; |
| 201 int y; | 201 int y; |
| 202 const int dcOffset= ((c->QP*c->ppMode.baseDcDiff)>>8) + 1; | 202 const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1; |
| 203 const int dcThreshold= dcOffset*2 + 1; | 203 const int dcThreshold= dcOffset*2 + 1; |
| 204 | |
| 204 for(y=0; y<BLOCK_SIZE; y++) | 205 for(y=0; y<BLOCK_SIZE; y++) |
| 205 { | 206 { |
| 206 if(((unsigned)(src[0] - src[1] + dcOffset)) < dcThreshold) numEq++; | 207 if(((unsigned)(src[0] - src[1] + dcOffset)) < dcThreshold) numEq++; |
| 207 if(((unsigned)(src[1] - src[2] + dcOffset)) < dcThreshold) numEq++; | 208 if(((unsigned)(src[1] - src[2] + dcOffset)) < dcThreshold) numEq++; |
| 208 if(((unsigned)(src[2] - src[3] + dcOffset)) < dcThreshold) numEq++; | 209 if(((unsigned)(src[2] - src[3] + dcOffset)) < dcThreshold) numEq++; |
| 219 * Check if the middle 8x8 Block in the given 8x16 block is flat | 220 * Check if the middle 8x8 Block in the given 8x16 block is flat |
| 220 */ | 221 */ |
| 221 static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c){ | 222 static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c){ |
| 222 int numEq= 0; | 223 int numEq= 0; |
| 223 int y; | 224 int y; |
| 224 const int dcOffset= ((c->QP*c->ppMode.baseDcDiff)>>8) + 1; | 225 const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1; |
| 225 const int dcThreshold= dcOffset*2 + 1; | 226 const int dcThreshold= dcOffset*2 + 1; |
| 227 | |
| 226 src+= stride*4; // src points to begin of the 8x8 Block | 228 src+= stride*4; // src points to begin of the 8x8 Block |
| 227 for(y=0; y<BLOCK_SIZE-1; y++) | 229 for(y=0; y<BLOCK_SIZE-1; y++) |
| 228 { | 230 { |
| 229 if(((unsigned)(src[0] - src[0+stride] + dcOffset)) < dcThreshold) numEq++; | 231 if(((unsigned)(src[0] - src[0+stride] + dcOffset)) < dcThreshold) numEq++; |
| 230 if(((unsigned)(src[1] - src[1+stride] + dcOffset)) < dcThreshold) numEq++; | 232 if(((unsigned)(src[1] - src[1+stride] + dcOffset)) < dcThreshold) numEq++; |
| 733 if(*p) free(*p); | 735 if(*p) free(*p); |
| 734 *p= memalign(alignment, size); | 736 *p= memalign(alignment, size); |
| 735 memset(*p, 0, size); | 737 memset(*p, 0, size); |
| 736 } | 738 } |
| 737 | 739 |
| 738 static void reallocBuffers(PPContext *c, int width, int height, int stride){ | 740 static void reallocBuffers(PPContext *c, int width, int height, int stride, int qpStride){ |
| 739 int mbWidth = (width+15)>>4; | 741 int mbWidth = (width+15)>>4; |
| 740 int mbHeight= (height+15)>>4; | 742 int mbHeight= (height+15)>>4; |
| 741 int i; | 743 int i; |
| 742 | 744 |
| 743 c->stride= stride; | 745 c->stride= stride; |
| 746 c->qpStride= qpStride; | |
| 744 | 747 |
| 745 reallocAlign((void **)&c->tempDst, 8, stride*24); | 748 reallocAlign((void **)&c->tempDst, 8, stride*24); |
| 746 reallocAlign((void **)&c->tempSrc, 8, stride*24); | 749 reallocAlign((void **)&c->tempSrc, 8, stride*24); |
| 747 reallocAlign((void **)&c->tempBlocks, 8, 2*16*8); | 750 reallocAlign((void **)&c->tempBlocks, 8, 2*16*8); |
| 748 reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t)); | 751 reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t)); |
| 755 reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024); | 758 reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024); |
| 756 reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size | 759 reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size |
| 757 } | 760 } |
| 758 | 761 |
| 759 reallocAlign((void **)&c->deintTemp, 8, 2*width+32); | 762 reallocAlign((void **)&c->deintTemp, 8, 2*width+32); |
| 760 reallocAlign((void **)&c->nonBQPTable, 8, mbWidth*mbHeight*sizeof(QP_STORE_T)); | 763 reallocAlign((void **)&c->nonBQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T)); |
| 764 reallocAlign((void **)&c->stdQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T)); | |
| 761 reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T)); | 765 reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T)); |
| 762 } | 766 } |
| 763 | 767 |
| 764 static void global_init(){ | 768 static void global_init(){ |
| 765 int i; | 769 int i; |
| 770 } | 774 } |
| 771 | 775 |
| 772 pp_context_t *pp_get_context(int width, int height, int cpuCaps){ | 776 pp_context_t *pp_get_context(int width, int height, int cpuCaps){ |
| 773 PPContext *c= memalign(32, sizeof(PPContext)); | 777 PPContext *c= memalign(32, sizeof(PPContext)); |
| 774 int stride= (width+15)&(~15); //assumed / will realloc if needed | 778 int stride= (width+15)&(~15); //assumed / will realloc if needed |
| 779 int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed | |
| 775 | 780 |
| 776 global_init(); | 781 global_init(); |
| 777 | 782 |
| 778 memset(c, 0, sizeof(PPContext)); | 783 memset(c, 0, sizeof(PPContext)); |
| 779 c->cpuCaps= cpuCaps; | 784 c->cpuCaps= cpuCaps; |
| 783 }else{ | 788 }else{ |
| 784 c->hChromaSubSample= 1; | 789 c->hChromaSubSample= 1; |
| 785 c->vChromaSubSample= 1; | 790 c->vChromaSubSample= 1; |
| 786 } | 791 } |
| 787 | 792 |
| 788 reallocBuffers(c, width, height, stride); | 793 reallocBuffers(c, width, height, stride, qpStride); |
| 789 | 794 |
| 790 c->frameNum=-1; | 795 c->frameNum=-1; |
| 791 | 796 |
| 792 return c; | 797 return c; |
| 793 } | 798 } |
| 802 free(c->tempBlocks); | 807 free(c->tempBlocks); |
| 803 free(c->yHistogram); | 808 free(c->yHistogram); |
| 804 free(c->tempDst); | 809 free(c->tempDst); |
| 805 free(c->tempSrc); | 810 free(c->tempSrc); |
| 806 free(c->deintTemp); | 811 free(c->deintTemp); |
| 812 free(c->stdQPTable); | |
| 807 free(c->nonBQPTable); | 813 free(c->nonBQPTable); |
| 808 free(c->forcedQPTable); | 814 free(c->forcedQPTable); |
| 809 | 815 |
| 810 memset(c, 0, sizeof(PPContext)); | 816 memset(c, 0, sizeof(PPContext)); |
| 811 | 817 |
| 821 int mbWidth = (width+15)>>4; | 827 int mbWidth = (width+15)>>4; |
| 822 int mbHeight= (height+15)>>4; | 828 int mbHeight= (height+15)>>4; |
| 823 PPMode *mode = (PPMode*)vm; | 829 PPMode *mode = (PPMode*)vm; |
| 824 PPContext *c = (PPContext*)vc; | 830 PPContext *c = (PPContext*)vc; |
| 825 int minStride= MAX(srcStride[0], dstStride[0]); | 831 int minStride= MAX(srcStride[0], dstStride[0]); |
| 826 | 832 |
| 827 if(c->stride < minStride) | 833 if(c->stride < minStride || c->qpStride < QPStride) |
| 828 reallocBuffers(c, width, height, minStride); | 834 reallocBuffers(c, width, height, |
| 835 MAX(minStride, c->stride), | |
| 836 MAX(c->qpStride, QPStride)); | |
| 829 | 837 |
| 830 if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) | 838 if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) |
| 831 { | 839 { |
| 832 int i; | 840 int i; |
| 833 QP_store= c->forcedQPTable; | 841 QP_store= c->forcedQPTable; |
| 835 if(mode->lumMode & FORCE_QUANT) | 843 if(mode->lumMode & FORCE_QUANT) |
| 836 for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant; | 844 for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant; |
| 837 else | 845 else |
| 838 for(i=0; i<mbWidth; i++) QP_store[i]= 1; | 846 for(i=0; i<mbWidth; i++) QP_store[i]= 1; |
| 839 } | 847 } |
| 848 //printf("pict_type:%d\n", pict_type); | |
| 849 | |
| 850 if(pict_type & PP_PICT_TYPE_QP2){ | |
| 851 int i; | |
| 852 const int count= mbHeight * QPStride; | |
| 853 for(i=0; i<(count>>2); i++){ | |
| 854 ((uint32_t*)c->stdQPTable)[i] = (((uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F; | |
| 855 } | |
| 856 for(i<<=2; i<count; i++){ | |
| 857 c->stdQPTable[i] = QP_store[i]>>1; | |
| 858 } | |
| 859 QP_store= c->stdQPTable; | |
| 860 } | |
| 861 | |
| 840 if(0){ | 862 if(0){ |
| 841 int x,y; | 863 int x,y; |
| 842 for(y=0; y<mbHeight; y++){ | 864 for(y=0; y<mbHeight; y++){ |
| 843 for(x=0; x<mbWidth; x++){ | 865 for(x=0; x<mbWidth; x++){ |
| 844 printf("%2d ", QP_store[x + y*QPStride]); | 866 printf("%2d ", QP_store[x + y*QPStride]); |
| 845 } | 867 } |
| 846 printf("\n"); | 868 printf("\n"); |
| 847 } | 869 } |
| 848 printf("\n"); | 870 printf("\n"); |
| 849 } | 871 } |
| 850 //printf("pict_type:%d\n", pict_type); | 872 |
| 851 | 873 if((pict_type&7)!=3) |
| 852 if(pict_type!=3) | 874 { |
| 853 { | 875 int i; |
| 854 int x,y; | 876 const int count= mbHeight * QPStride; |
| 855 for(y=0; y<mbHeight; y++){ | 877 for(i=0; i<(count>>2); i++){ |
| 856 for(x=0; x<mbWidth; x++){ | 878 ((uint32_t*)c->nonBQPTable)[i] = ((uint32_t*)QP_store)[i] & 0x1F1F1F1F; |
| 857 int qscale= QP_store[x + y*QPStride]; | 879 } |
| 858 if(qscale&~31) | 880 for(i<<=2; i<count; i++){ |
| 859 qscale=31; | 881 c->nonBQPTable[i] = QP_store[i] & 0x1F; |
| 860 c->nonBQPTable[y*mbWidth + x]= qscale; | |
| 861 } | |
| 862 } | 882 } |
| 863 } | 883 } |
| 864 | 884 |
| 865 if(verbose>2) | 885 if(verbose>2) |
| 866 { | 886 { |
