Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. diff --git a/encoder/macroblock.c b/encoder/macroblock.c
  2. index f1b66ac..2e9e174 100755
  3. --- a/encoder/macroblock.c
  4. +++ b/encoder/macroblock.c
  5. @@ -273,7 +273,8 @@ static void x262_mb_encode_i_block( x264_t *h, int idx, int i_qp )
  6. pixel *p_src;
  7. pixel *p_dst;
  8. ALIGNED_ARRAY_16( dctcoef, dct8x8,[64] );
  9. - int nz, half_range, cur_dc_predictor, dc_diff;
  10. + int nz, cur_dc_predictor, dc_mult, dc_diff, size;
  11. + dctcoef dcb;
  12. // TODO decimation
  13.  
  14. if( idx < 4 )
  15. @@ -291,7 +292,29 @@ static void x262_mb_encode_i_block( x264_t *h, int idx, int i_qp )
  16.  
  17. h->dctf.sub8x8_dct8( dct8x8, p_src, p_dst );
  18.  
  19. - nz = 1; // TODO quantisation
  20. + // quantize dc
  21. + dcb = dct8x8[0];
  22. + dc_mult = 8 >> h->param.i_intra_dc_precision;
  23. + dcb = (dcb + (dc_mult >> 1)) / dc_mult;
  24. +
  25. + if( idx < 4 )
  26. + cur_dc_predictor = idx == 0 ? h->mb.i_intra_dc_predictor[3] : h->mb.i_intra_dc_predictor[idx-1];
  27. + else
  28. + cur_dc_predictor = h->mb.i_intra_dc_predictor[idx];
  29. + dc_diff = dcb - cur_dc_predictor;
  30. +
  31. + if( dc_diff < 0 )
  32. + {
  33. + size = LOG2_16( -2*dc_diff );
  34. + dc_diff--;
  35. + }
  36. + else
  37. + size = LOG2_16( 2*dc_diff );
  38. +
  39. + // TODO quantisation of rest of coeffs
  40. + //nz = h->quantf.quant_8x8_mpeg2( dct8x8, x262_cqm_intra, x262_qscale[h->mb.i_qp] );
  41. +
  42. + nz = 1;
  43. if( nz )
  44. {
  45. if( idx < 4 )
  46. @@ -299,25 +322,15 @@ static void x262_mb_encode_i_block( x264_t *h, int idx, int i_qp )
  47. else
  48. h->mb.i_cbp_chroma |= 1<<(5-idx);
  49. h->zigzagf.scan_8x8( h->dct.mpeg2_8x8[idx], dct8x8 );
  50. + h->dct.mpeg2_8x8[idx][0] = dcb;
  51. //h->quantf.dequant_8x8( dct8x8[idx], h->dequant8_mf[CQM_8IY], i_qp );
  52. - h->dctf.add8x8_idct8( p_dst, dct8x8 );
  53. + //h->dctf.add8x8_idct8( p_dst, dct8x8 );
  54. }
  55.  
  56. - if( idx < 4 )
  57. - cur_dc_predictor = idx == 0 ? h->mb.i_intra_dc_predictor[4] : h->mb.i_intra_dc_predictor[idx-1];
  58. - else
  59. - cur_dc_predictor = h->mb.i_intra_dc_predictor[idx];
  60. -
  61. - /* update intra_dc_predictor */
  62. - h->mb.i_dct_dc_size[idx] = 32 - x264_clz( abs( h->dct.mpeg2_8x8[idx][0] ) );
  63. - dc_diff = h->mb.i_dct_dc_diff[idx] = h->dct.mpeg2_8x8[idx][0] - cur_dc_predictor;
  64. - if( h->mb.i_dct_dc_size[idx] )
  65. - {
  66. - half_range = 1 << ( h->mb.i_dct_dc_size[idx] - 1 );
  67. - if( h->mb.i_dct_dc_diff[idx] < half_range )
  68. - h->mb.i_dct_dc_diff[idx] = ( h->mb.i_dct_dc_diff[idx] + ( half_range << 1 ) ) - 1;
  69. - h->mb.i_intra_dc_predictor[idx] += dc_diff;
  70. - }
  71. + /* store dc_diff and update intra_dc_predictor */
  72. + h->mb.i_dct_dc_size[idx] = size;
  73. + h->mb.i_dct_dc_diff[idx] = dc_diff & ((1<<size)-1);
  74. + h->mb.i_intra_dc_predictor[idx] = dcb;
  75. }
  76.  
  77. static inline int idct_dequant_round_2x2_dc( dctcoef ref[4], dctcoef dct[4], int dequant_mf[6][16], int i_qp )
  78. @@ -712,7 +725,7 @@ void x264_macroblock_encode( x264_t *h )
  79. for( int i = 0; i < 4; i++ )
  80. {
  81. pixel *p_dst = &h->mb.pic.p_fdec[0][8 * (i&1) + 8 * (i>>1) * FDEC_STRIDE];
  82. - h->predict_mpeg2_8x8( p_dst, h->mb.i_intra_dc_predictor[i] );
  83. + h->predict_mpeg2_8x8( p_dst, 0 );
  84. x262_mb_encode_i_block( h, i, i_qp );
  85. }
  86. else
  87. @@ -945,8 +958,8 @@ void x264_macroblock_encode( x264_t *h )
  88. x264_predict_lossless_8x8_chroma( h, i_mode );
  89. else if( h->param.b_mpeg2 )
  90. {
  91. - h->predict_mpeg2_8x8( h->mb.pic.p_fdec[1], h->mb.i_intra_dc_predictor[4] );
  92. - h->predict_mpeg2_8x8( h->mb.pic.p_fdec[2], h->mb.i_intra_dc_predictor[5] );
  93. + h->predict_mpeg2_8x8( h->mb.pic.p_fdec[1], 0 );
  94. + h->predict_mpeg2_8x8( h->mb.pic.p_fdec[2], 0 );
  95.  
  96. for( int i = 4; i < 6; i++ )
  97. x262_mb_encode_i_block( h, i, i_qp ); /* encode intra block */
  98. @@ -964,9 +977,7 @@ void x264_macroblock_encode( x264_t *h )
  99. // TODO inter MPEG-2
  100. }
  101. else
  102. - {
  103. x264_mb_encode_8x8_chroma( h, !IS_INTRA( h->mb.i_type ), h->mb.i_chroma_qp );
  104. - }
  105.  
  106. /* store cbp */ // FIXME do we need to make this into mpeg-2 cbp
  107. int cbp = h->mb.i_cbp_chroma << 4 | h->mb.i_cbp_luma;
  108. diff --git a/encoder/mpeg2vlc.c b/encoder/mpeg2vlc.c
  109. index f78b565..f8f8d97 100755
  110. --- a/encoder/mpeg2vlc.c
  111. +++ b/encoder/mpeg2vlc.c
  112. @@ -38,18 +38,19 @@ void x262_macroblock_write_vlc( x264_t *h )
  113. {
  114. bs_t *s = &h->out.bs;
  115. const int i_mb_type = h->mb.i_type;
  116. - int cbp;
  117. + int cbp, i_total;
  118.  
  119. #if RDO_SKIP_BS
  120. s->i_bits_encoded = 0;
  121. #else
  122. const int i_mb_pos_start = bs_pos( s );
  123. - int i_mb_pos_tex;
  124. + int i_mb_pos_tex = 0;
  125. #endif
  126.  
  127. // macroblock modes
  128. if( i_mb_type == I_16x16 )
  129. - bs_write_vlc( s, x262_i_mb_type[h->sh.i_type][!!h->mb.i_quant_scale_code] );
  130. + //bs_write_vlc( s, x262_i_mb_type[h->sh.i_type][!!h->mb.i_qp] );
  131. + bs_write_vlc( s, x262_i_mb_type[h->sh.i_type][0] ); // FIXME no quant
  132. else if( i_mb_type == P_8x8 )
  133. {
  134.  
  135. @@ -60,8 +61,8 @@ void x262_macroblock_write_vlc( x264_t *h )
  136.  
  137. }
  138.  
  139. - if( h->mb.i_quant_scale_code )
  140. - bs_write( s, 5, h->mb.i_quant_scale_code );
  141. + if( h->mb.i_qp )
  142. + //bs_write( s, 5, h->mb.i_qp ); // quantizer_scale_code
  143.  
  144. // forward mvs
  145.  
  146. @@ -72,10 +73,11 @@ void x262_macroblock_write_vlc( x264_t *h )
  147. h->stat.frame.i_mv_bits += i_mb_pos_tex - i_mb_pos_start;
  148. #endif
  149.  
  150. - cbp = h->mb.i_cbp_luma << 2;
  151. + cbp = h->mb.i_cbp_luma << 2 | h->mb.i_cbp_chroma;
  152.  
  153. - // coded block pattern (TODO: handle others and chroma)
  154. - if( i_mb_type == I_16x16 )
  155. + // coded block pattern (TODO: handle others)
  156. +
  157. + if( i_mb_type != I_16x16 && cbp )
  158. bs_write_vlc( s, x262_cbp[cbp] ); // coded_block_pattern_420
  159.  
  160. for( int i = 0; i < 6; i++ )
  161. @@ -83,17 +85,32 @@ void x262_macroblock_write_vlc( x264_t *h )
  162. // block()
  163. if( i_mb_type == I_16x16 )
  164. {
  165. -
  166. + if( i < 4 )
  167. + {
  168. + // DC coefficient
  169. + bs_write_vlc( s, x262_dc_luma_code[h->mb.i_dct_dc_size[i]] );
  170. + if( h->mb.i_dct_dc_size[i] )
  171. + bs_write( s, h->mb.i_dct_dc_size[i], h->mb.i_dct_dc_diff[i] );
  172. + h->dct.mpeg2_8x8[i][0] = 0;
  173. +
  174. + }
  175. + else
  176. + {
  177. +
  178. + bs_write_vlc( s, x262_dc_chroma_code[h->mb.i_dct_dc_size[i]] );
  179. + if( h->mb.i_dct_dc_size[i] )
  180. + bs_write( s, h->mb.i_dct_dc_size[i], h->mb.i_dct_dc_diff[i] );
  181. + }
  182. + bs_write_vlc( s, dct_vlcs[h->param.b_alt_intra_vlc][0][0] ); // end of block
  183. + }
  184. + else if( (cbp & (1<<(5-i))) )
  185. + {
  186. }
  187. - else if( !(cbp & (1<<(5-i))) )
  188. + else
  189. continue;
  190. -
  191. - // end of block
  192. }
  193.  
  194. #if !RDO_SKIP_BS
  195. h->stat.frame.i_tex_bits += bs_pos(s) - i_mb_pos_tex;
  196. #endif
  197. -
  198. -
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement