Mercurial > libavcodec.hg
comparison libpostproc/postprocess.c @ 937:04fd733c5e4b libavcodec
buffer alloc cleanup / 10l
| author | michael |
|---|---|
| date | Sun, 29 Dec 2002 00:57:23 +0000 |
| parents | ee8bb36d2e60 |
| children | 8a95bda80fdc |
comparison
equal
deleted
inserted
replaced
| 936:caa77cd960c0 | 937:04fd733c5e4b |
|---|---|
| 712 | 712 |
| 713 void pp_free_mode(pp_mode_t *mode){ | 713 void pp_free_mode(pp_mode_t *mode){ |
| 714 if(mode) free(mode); | 714 if(mode) free(mode); |
| 715 } | 715 } |
| 716 | 716 |
| 717 static void reallocAlign(void **p, int alignment, int size){ | |
| 718 if(*p) free(*p); | |
| 719 *p= memalign(alignment, size); | |
| 720 memset(*p, 0, size); | |
| 721 } | |
| 722 | |
| 723 static void reallocBuffers(PPContext *c, int width, int height, int stride){ | |
| 724 int mbWidth = (width+15)>>4; | |
| 725 int mbHeight= (height+15)>>4; | |
| 726 int i; | |
| 727 | |
| 728 c->stride= stride; | |
| 729 | |
| 730 reallocAlign((void **)&c->tempDst, 8, stride*24); | |
| 731 reallocAlign((void **)&c->tempSrc, 8, stride*24); | |
| 732 reallocAlign((void **)&c->tempBlocks, 8, 2*16*8); | |
| 733 reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t)); | |
| 734 for(i=0; i<256; i++) | |
| 735 c->yHistogram[i]= width*height/64*15/256; | |
| 736 | |
| 737 for(i=0; i<3; i++) | |
| 738 { | |
| 739 //Note:the +17*1024 is just there so i dont have to worry about r/w over te end | |
| 740 reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024); | |
| 741 reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size | |
| 742 } | |
| 743 | |
| 744 reallocAlign((void **)&c->deintTemp, 8, width+16); | |
| 745 reallocAlign((void **)&c->nonBQPTable, 8, mbWidth*mbHeight*sizeof(QP_STORE_T)); | |
| 746 reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T)); | |
| 747 } | |
| 748 | |
| 717 pp_context_t *pp_get_context(int width, int height, int cpuCaps){ | 749 pp_context_t *pp_get_context(int width, int height, int cpuCaps){ |
| 718 PPContext *c= memalign(32, sizeof(PPContext)); | 750 PPContext *c= memalign(32, sizeof(PPContext)); |
| 719 int i; | 751 int i; |
| 720 int mbWidth = (width+15)>>4; | 752 int stride= (width+15)&(~15); //assumed / will realloc if needed |
| 721 int mbHeight= (height+15)>>4; | 753 |
| 722 | 754 memset(c, 0, sizeof(PPContext)); |
| 723 c->cpuCaps= cpuCaps; | 755 c->cpuCaps= cpuCaps; |
| 724 | 756 |
| 725 c->tempBlocks= (uint8_t*)memalign(8, 2*16*8); | 757 reallocBuffers(c, width, height, stride); |
| 726 c->yHistogram= (uint64_t*)memalign(8, 256*sizeof(uint64_t)); | 758 |
| 727 for(i=0; i<256; i++) | |
| 728 c->yHistogram[i]= width*height/64*15/256; | |
| 729 | |
| 730 for(i=0; i<3; i++) | |
| 731 { | |
| 732 //Note:the +17*1024 is just there so i dont have to worry about r/w over te end | |
| 733 c->tempBlured[i]= (uint8_t*)memalign(8, ((width+7)&(~7))*2*((height+7)&(~7)) + 17*1024); //FIXME dstStride instead of width | |
| 734 c->tempBluredPast[i]= (uint32_t*)memalign(8, 256*((height+7)&(~7))/2 + 17*1024); | |
| 735 | |
| 736 memset(c->tempBlured[i], 0, ((width+7)&(~7))*2*((height+7)&(~7)) + 17*1024); | |
| 737 memset(c->tempBluredPast[i], 0, 256*((height+7)&(~7))/2 + 17*1024); | |
| 738 } | |
| 739 | |
| 740 c->tempDst= (uint8_t*)memalign(8, 1024*24); | |
| 741 c->tempSrc= (uint8_t*)memalign(8, 1024*24); | |
| 742 c->tempDstBlock= (uint8_t*)memalign(8, 1024*24); | |
| 743 c->tempSrcBlock= (uint8_t*)memalign(8, 1024*24); | |
| 744 c->deintTemp= (uint8_t*)memalign(8, width+16); | |
| 745 c->nonBQPTable= (QP_STORE_T*)memalign(8, mbWidth*mbHeight*sizeof(QP_STORE_T)); | |
| 746 memset(c->nonBQPTable, 0, mbWidth*mbHeight*sizeof(QP_STORE_T)); | |
| 747 | |
| 748 c->frameNum=-1; | 759 c->frameNum=-1; |
| 749 | 760 |
| 750 return c; | 761 return c; |
| 751 } | 762 } |
| 752 | 763 |
| 759 | 770 |
| 760 free(c->tempBlocks); | 771 free(c->tempBlocks); |
| 761 free(c->yHistogram); | 772 free(c->yHistogram); |
| 762 free(c->tempDst); | 773 free(c->tempDst); |
| 763 free(c->tempSrc); | 774 free(c->tempSrc); |
| 764 free(c->tempDstBlock); | |
| 765 free(c->tempSrcBlock); | |
| 766 free(c->deintTemp); | 775 free(c->deintTemp); |
| 767 free(c->nonBQPTable); | 776 free(c->nonBQPTable); |
| 768 | 777 free(c->forcedQPTable); |
| 778 | |
| 779 memset(c, 0, sizeof(PPContext)); | |
| 780 | |
| 769 free(c); | 781 free(c); |
| 770 } | 782 } |
| 771 | 783 |
| 772 void pp_postprocess(uint8_t * src[3], int srcStride[3], | 784 void pp_postprocess(uint8_t * src[3], int srcStride[3], |
| 773 uint8_t * dst[3], int dstStride[3], | 785 uint8_t * dst[3], int dstStride[3], |
| 775 QP_STORE_T *QP_store, int QPStride, | 787 QP_STORE_T *QP_store, int QPStride, |
| 776 pp_mode_t *vm, void *vc, int pict_type) | 788 pp_mode_t *vm, void *vc, int pict_type) |
| 777 { | 789 { |
| 778 int mbWidth = (width+15)>>4; | 790 int mbWidth = (width+15)>>4; |
| 779 int mbHeight= (height+15)>>4; | 791 int mbHeight= (height+15)>>4; |
| 780 QP_STORE_T quantArray[2048/8]; | |
| 781 PPMode *mode = (PPMode*)vm; | 792 PPMode *mode = (PPMode*)vm; |
| 782 PPContext *c = (PPContext*)vc; | 793 PPContext *c = (PPContext*)vc; |
| 794 int minStride= MAX(srcStride[0], dstStride[0]); | |
| 795 | |
| 796 if(c->stride < minStride) | |
| 797 reallocBuffers(c, width, height, minStride); | |
| 798 | |
| 783 | 799 |
| 784 if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) | 800 if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) |
| 785 { | 801 { |
| 786 int i; | 802 int i; |
| 787 QP_store= quantArray; | 803 QP_store= c->forcedQPTable; |
| 788 QPStride= 0; | 804 QPStride= 0; |
| 789 if(mode->lumMode & FORCE_QUANT) | 805 if(mode->lumMode & FORCE_QUANT) |
| 790 for(i=0; i<2048/8; i++) quantArray[i]= mode->forcedQuant; | 806 for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant; |
| 791 else | 807 else |
| 792 for(i=0; i<2048/8; i++) quantArray[i]= 1; | 808 for(i=0; i<mbWidth; i++) QP_store[i]= 1; |
| 793 } | 809 } |
| 794 if(0){ | 810 if(0){ |
| 795 int x,y; | 811 int x,y; |
| 796 for(y=0; y<mbHeight; y++){ | 812 for(y=0; y<mbHeight; y++){ |
| 797 for(x=0; x<mbWidth; x++){ | 813 for(x=0; x<mbWidth; x++){ |
