Mercurial > libavcodec.hg
comparison mpegvideo.c @ 1716:da5d64a0fa02 libavcodec
cleanup
| author | michael |
|---|---|
| date | Fri, 02 Jan 2004 03:02:34 +0000 |
| parents | 88a2c6cc45f4 |
| children | fdd1bc71da55 |
comparison
equal
deleted
inserted
replaced
| 1715:88a2c6cc45f4 | 1716:da5d64a0fa02 |
|---|---|
| 4756 // length[UNI_AC_ENC_INDEX(0, 65)]= 2; | 4756 // length[UNI_AC_ENC_INDEX(0, 65)]= 2; |
| 4757 } | 4757 } |
| 4758 | 4758 |
| 4759 for(i=0; i<=last_non_zero - start_i; i++){ | 4759 for(i=0; i<=last_non_zero - start_i; i++){ |
| 4760 int level_index, run, j; | 4760 int level_index, run, j; |
| 4761 const int dct_coeff= block[ scantable[i + start_i] ]; | 4761 const int dct_coeff= ABS(block[ scantable[i + start_i] ]); |
| 4762 const int zero_distoration= dct_coeff*dct_coeff; | 4762 const int zero_distoration= dct_coeff*dct_coeff; |
| 4763 int best_score=256*256*256*120; | 4763 int best_score=256*256*256*120; |
| 4764 | 4764 |
| 4765 for(level_index=0; level_index < coeff_count[i]; level_index++){ | 4765 for(level_index=0; level_index < coeff_count[i]; level_index++){ |
| 4766 int distoration; | 4766 int distoration; |
| 4767 int level= coeff[level_index][i]; | 4767 int level= coeff[level_index][i]; |
| 4768 const int alevel= ABS(level); | |
| 4768 int unquant_coeff; | 4769 int unquant_coeff; |
| 4769 | 4770 |
| 4770 assert(level); | 4771 assert(level); |
| 4771 | 4772 |
| 4772 if(s->out_format == FMT_H263){ | 4773 if(s->out_format == FMT_H263){ |
| 4773 if(level>0){ | 4774 unquant_coeff= alevel*qmul + qadd; |
| 4774 unquant_coeff= level*qmul + qadd; | |
| 4775 }else{ | |
| 4776 unquant_coeff= level*qmul - qadd; | |
| 4777 } | |
| 4778 }else{ //MPEG1 | 4775 }else{ //MPEG1 |
| 4779 j= s->dsp.idct_permutation[ scantable[i + start_i] ]; //FIXME optimize | 4776 j= s->dsp.idct_permutation[ scantable[i + start_i] ]; //FIXME optimize |
| 4780 if(s->mb_intra){ | 4777 if(s->mb_intra){ |
| 4781 if (level < 0) { | 4778 unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3; |
| 4782 unquant_coeff = (int)((-level) * qscale * s->intra_matrix[j]) >> 3; | |
| 4783 unquant_coeff = -((unquant_coeff - 1) | 1); | |
| 4784 } else { | |
| 4785 unquant_coeff = (int)( level * qscale * s->intra_matrix[j]) >> 3; | |
| 4786 unquant_coeff = (unquant_coeff - 1) | 1; | 4779 unquant_coeff = (unquant_coeff - 1) | 1; |
| 4787 } | |
| 4788 }else{ | 4780 }else{ |
| 4789 if (level < 0) { | 4781 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; |
| 4790 unquant_coeff = ((((-level) << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; | |
| 4791 unquant_coeff = -((unquant_coeff - 1) | 1); | |
| 4792 } else { | |
| 4793 unquant_coeff = ((( level << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; | |
| 4794 unquant_coeff = (unquant_coeff - 1) | 1; | 4782 unquant_coeff = (unquant_coeff - 1) | 1; |
| 4795 } | |
| 4796 } | 4783 } |
| 4797 unquant_coeff<<= 3; | 4784 unquant_coeff<<= 3; |
| 4798 } | 4785 } |
| 4799 | 4786 |
| 4800 distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration; | 4787 distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration; |
| 4878 } | 4865 } |
| 4879 } | 4866 } |
| 4880 | 4867 |
| 4881 s->coded_score[n] = last_score; | 4868 s->coded_score[n] = last_score; |
| 4882 | 4869 |
| 4883 dc= block[0]; | 4870 dc= ABS(block[0]); |
| 4884 last_non_zero= last_i - 1 + start_i; | 4871 last_non_zero= last_i - 1 + start_i; |
| 4885 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); | 4872 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); |
| 4886 | 4873 |
| 4887 if(last_non_zero < start_i) | 4874 if(last_non_zero < start_i) |
| 4888 return last_non_zero; | 4875 return last_non_zero; |
| 4891 int best_level= 0; | 4878 int best_level= 0; |
| 4892 int best_score= dc * dc; | 4879 int best_score= dc * dc; |
| 4893 | 4880 |
| 4894 for(i=0; i<coeff_count[0]; i++){ | 4881 for(i=0; i<coeff_count[0]; i++){ |
| 4895 int level= coeff[i][0]; | 4882 int level= coeff[i][0]; |
| 4896 int unquant_coeff, score, distoration; | 4883 int alevel= ABS(level); |
| 4884 int unquant_coeff, score, distortion; | |
| 4897 | 4885 |
| 4898 if(s->out_format == FMT_H263){ | 4886 if(s->out_format == FMT_H263){ |
| 4899 if(level>0){ | 4887 unquant_coeff= (alevel*qmul + qadd)>>3; |
| 4900 unquant_coeff= (level*qmul + qadd)>>3; | |
| 4901 }else{ | |
| 4902 unquant_coeff= (level*qmul - qadd)>>3; | |
| 4903 } | |
| 4904 }else{ //MPEG1 | 4888 }else{ //MPEG1 |
| 4905 if (level < 0) { | 4889 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4; |
| 4906 unquant_coeff = ((((-level) << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4; | 4890 unquant_coeff = (unquant_coeff - 1) | 1; |
| 4907 unquant_coeff = -((unquant_coeff - 1) | 1); | |
| 4908 } else { | |
| 4909 unquant_coeff = ((( level << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4; | |
| 4910 unquant_coeff = (unquant_coeff - 1) | 1; | |
| 4911 } | |
| 4912 } | 4891 } |
| 4913 unquant_coeff = (unquant_coeff + 4) >> 3; | 4892 unquant_coeff = (unquant_coeff + 4) >> 3; |
| 4914 unquant_coeff<<= 3 + 3; | 4893 unquant_coeff<<= 3 + 3; |
| 4915 | 4894 |
| 4916 distoration= (unquant_coeff - dc) * (unquant_coeff - dc); | 4895 distortion= (unquant_coeff - dc) * (unquant_coeff - dc); |
| 4917 level+=64; | 4896 level+=64; |
| 4918 if((level&(~127)) == 0) | 4897 if((level&(~127)) == 0) score= distortion + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda; |
| 4919 score= distoration + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda; | 4898 else score= distortion + esc_length*lambda; |
| 4920 else | |
| 4921 score= distoration + esc_length*lambda; | |
| 4922 | 4899 |
| 4923 if(score < best_score){ | 4900 if(score < best_score){ |
| 4924 best_score= score; | 4901 best_score= score; |
| 4925 best_level= level - 64; | 4902 best_level= level - 64; |
| 4926 } | 4903 } |
