h.264 scanning process for transform coefficients
生活随笔
收集整理的這篇文章主要介紹了
h.264 scanning process for transform coefficients
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
宏塊在經過變換、量化后,得到大小為4x4或者8x8的矩陣,矩陣中的數據被稱為transform coefficient levels。這些level在后面會被用于熵編碼,因此我們需要把矩陣按照一定順序進行掃描,得到數字序列。
?
掃描順序在幀與場會有所不同
4x4塊矩陣的掃描順序如下
??????????????
Zig-zag scan(Frame)????????????????????????? Field scan???????????
?
8x8塊矩陣的掃描順序如下
???????????
?
Zig-zag scan(Frame)??????? ????????????????????????? Field scan???????????
?
在實際的代碼處理上(JM),對變換系數的掃描過程是包含在量化過程中的,因為對矩陣內的元素的量化也是逐個進行的,因此就可以按照對變換系數掃描的順序取出矩陣內的元素進行量化,后續就能直接對這些transform coefficient level序列進行熵編碼。
int quant_4x4_normal(Macroblock *currMB, int **tblock, struct quant_methods *q_method) { VideoParameters *p_Vid = currMB->p_Vid;QuantParameters *p_Quant = p_Vid->p_Quant;Slice *currSlice = currMB->p_Slice;Boolean is_cavlc = (Boolean) (currSlice->symbol_mode == CAVLC);int block_x = q_method->block_x;int qp = q_method->qp;int* ACL = &q_method->ACLevel[0];int* ACR = &q_method->ACRun[0]; LevelQuantParams **q_params_4x4 = q_method->q_params;const byte (*pos_scan)[2] = q_method->pos_scan;const byte *c_cost = q_method->c_cost;int *coeff_cost = q_method->coeff_cost;LevelQuantParams *q_params = NULL;int i,j, coeff_ctr;int *m7;int scaled_coeff;int level, run = 0;int nonzero = FALSE;int qp_per = p_Quant->qp_per_matrix[qp];int q_bits = Q_BITS + qp_per;const byte *p_scan = &pos_scan[0][0];// Quantization// 4x4 block matrix has 16 coefficientsfor (coeff_ctr = 0; coeff_ctr < 16; ++coeff_ctr){//scanning positions (Zig-zag scan or Field scan)i = *p_scan++; // horizontal positionj = *p_scan++; // vertical position//block_x,block_y here is the position of a block on a Macroblock with the unit of pixelm7 = &tblock[j][block_x + i];if (*m7 != 0){q_params = &q_params_4x4[j][i];scaled_coeff = iabs (*m7) * q_params->ScaleComp;level = (scaled_coeff + q_params->OffsetComp) >> q_bits;if (level != 0){if (is_cavlc)level = imin(level, CAVLC_LEVEL_LIMIT);*coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];level = isignab(level, *m7);*m7 = rshift_rnd_sf(((level * q_params->InvScaleComp) << qp_per), 4);// inverse scale can be alternative performed as follows to ensure 16bit// arithmetic is satisfied.// *m7 = (qp_per<4) ? rshift_rnd_sf((level*q_params->InvScaleComp),4-qp_per) : (level*q_params->InvScaleComp)<<(qp_per-4);*ACL++ = level;*ACR++ = run;// reset zero level counterrun = 0;nonzero = TRUE;}else{*m7 = 0;++run;}}else{++run;}}*ACL = 0;return nonzero; }轉載于:https://www.cnblogs.com/TaigaCon/p/5245108.html
總結
以上是生活随笔為你收集整理的h.264 scanning process for transform coefficients的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tomcat的优化技巧
- 下一篇: 前端性能优化之DOM(三)