📄 mp4eblck.c
字号:
/******************************************************************************// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright (c) 2003 Intel Corporation. All Rights Reserved.//// Description: Block encoding functions of MPEG-4 video encoder sample// code for Intel(R) Integrated Performance Primitives.// Functions List:// encode_block_intra_mpeg4()// encode_block_inter_mpeg4()// acdc_prediction_intra_mb_mpeg4()******************************************************************************/#include <memory.h>#include "sampmp4.h"/******************************************************************************//// Name: encode_block_intra_mpeg4//// Description: Quantize the DCT coefficients of the intra block and store// them into buffer. Meanwhile, the texture data are// reconstructed.//// Input Arguments: // src_block - Pointer to the pixels of current intra block.// blk_indx - Block index indicating the component type and position as// defined in subclause 6.1.3.8, Figure 6-5 of ISO/IEC// 14496-2.// cur_qp - Quantization parameter of the macroblock which the// current block belongs to.// step - Width of the source and reconstructed plane.// q_matrix - If the second inverse quantization method is used, it is// NULL; If the first inverse quantization method is used,// it points to the quantization weighting coefficients// buffer (for intra MB), whose first 64 elements are the// quantization weighting matrix in Q0, the second 64// elements are their reciprocals in Q21.//// Output Arguments: // dst_coeff - Pointer to the quantized DCT coefficients buffer.// rec_block - Pointer to the reconstructed texture.//// Returns:// SAMPLE_STATUS_NOERR - If succeeds.// SAMPLE_STATUS_ERR - If encoding fails.// *********************************************************************************/sample_status encode_block_intra_mpeg4(Ipp8u *src_block, Ipp8u *rec_block, Ipp16s *dst_coeff, int blk_indx, Ipp8u cur_qp, int step, const int *q_matrix){ Ipp8u q_matrix_8u[SAMPLE_VIDEO_BLOCK_SQUARE_SIZE]; Ipp16s dct_coef_buf[SAMPLE_VIDEO_BLOCK_SQUARE_SIZE + 8]; Ipp16s* dct_coef = (Ipp16s*)SAMPLE_ALIGN8(dct_coef_buf); int i; IppVideoComponent video_comp; sample_status ret_code; /* 1. DCT transform */ /* src_block, dct_coef must be 8 bytes aligned */ ret_code = ippiDCT8x8Fwd_Video_8u16s_C1R(src_block, step, dct_coef); if (ippStsNoErr != ret_code) { return SAMPLE_STATUS_ERR; } /* 2. Quantisation */ ret_code = ippiQuantIntra_MPEG4_16s_I(dct_coef, cur_qp, blk_indx, q_matrix); if (ippStsNoErr != ret_code) { return SAMPLE_STATUS_ERR; } else { memcpy((void*)dst_coeff, (void*)dct_coef, sizeof(Ipp16s) * 64); } /* 3. Inverse Quantisation */ video_comp = (Y_BLOCK4 >= blk_indx) ? IPP_VIDEO_LUMINANCE : IPP_VIDEO_CHROMINANCE; if (q_matrix) { for (i = 0; i < SAMPLE_VIDEO_BLOCK_SQUARE_SIZE; i++) { q_matrix_8u[i] = (Ipp8u)q_matrix[i]; } ret_code = ippiQuantInvIntra_MPEG4_16s_I(dct_coef, cur_qp, q_matrix_8u, video_comp); } else { ret_code = ippiQuantInvIntra_MPEG4_16s_I(dct_coef, cur_qp, NULL, video_comp); } if (ippStsNoErr != ret_code) { return SAMPLE_STATUS_ERR; } /* 4. IDCT */ /* dct_coef, rec_block must be 8 bytes aligned */ ret_code = ippiDCT8x8Inv_Video_16s8u_C1R(dct_coef, rec_block, step); if (ippStsNoErr != ret_code) { return SAMPLE_STATUS_ERR; } return SAMPLE_STATUS_NOERR;}/******************************************************************************//// Name: acdc_prediction_intra_mb_mpeg4//// Description: Implement the AC/DC coefficients prediction of the intra// macroblock //// Input Arguments: // src_dst_coeff - Pointer to the macroblock quantized DCT coefficient// buffer before AC/DC prediction.// coef_bufrow_y - Pointer to the y coefficient row buffer// coef_bufcol_y - Pointer to the y coefficient column buffer// coef_bufrow_cb - Pointer to the cb coefficient row buffer// coef_bufcol_cb - Pointer to the cb coefficient column buffer// coef_bufrow_cr - Pointer to the cr coefficient row buffer// coef_bufcol_cr - Pointer to the cr coefficient column buffer// cur_qp - Quantization parameter of the current macroblock.// qp_buf - Pointer to the quantization parameter buffer which// contains the quantization parameter of neighbouring// macroblocks.// Output Arguments:// src_dst_coeff - Pointer to the macroblock coefficient buffer after// AC/DC prediction. // ac_pred_flag - Pointer to the ac_pred_flag of the intra macroblock// pred_dir_buf - Pointer to the predict direction buffer for all six// blocks in the macroblock// coef_bufrow_y - Pointer to the updated y coefficient row buffer// coef_bufcol_y - Pointer to the updated y coefficient column buffer// coef_bufrow_cb - Pointer to the updated cb coefficient row buffer// coef_bufcol_cb - Pointer to the updated cb coefficient column buffer// coef_bufrow_cr - Pointer to the updated cr coefficient row buffer// coef_bufcol_cr - Pointer to the updated cr coefficient column buffer//// Returns:// SAMPLE_STATUS_NOERR - If succeeds.// *********************************************************************************/sample_status acdc_prediction_intra_mb_mpeg4(Ipp16s *src_dst_coeff, Ipp16s *coef_bufrow_y, Ipp16s *coef_bufcol_y, Ipp16s *coef_bufrow_cb, Ipp16s *coef_bufcol_cb, Ipp16s *coef_bufrow_cr, Ipp16s *coef_bufcol_cr, Ipp8u cur_qp, Ipp8u *qp_buf, int *ac_pred_flag, Ipp8u *pred_dir_buf){ Ipp8u pred_qp; Ipp16s tmp_coef, dc_coef, *coef, *coef_bufrow = NULL, *coef_bufcol = NULL; Ipp16s pred_buf[SAMPLE_VIDEO_BLOCK_SIZE * 6]; int dc_left, dc_top, dc_left_top; int dc_scaler_lum, dc_scaler_chr, dc_scaler = 0; int i, j, pred_dir, blk_indx, sum_err, level; /* Calculate dc_scaler */ /* Please refer to Table 7-1 ISC/IEC 14496-2:2001(E) */ if (5 > cur_qp) { dc_scaler_lum = 8; dc_scaler_chr = 8; } else if (9 > cur_qp) { dc_scaler_lum = cur_qp * 2; dc_scaler_chr = (cur_qp + 13) / 2; } else if (25 > cur_qp) { dc_scaler_lum = cur_qp + 8; dc_scaler_chr = (cur_qp + 13) / 2; } else { dc_scaler_lum = 2 * cur_qp - 16; dc_scaler_chr = cur_qp - 6; } sum_err = 0; for (blk_indx = Y_BLOCK1; blk_indx <= V_BLOCK; blk_indx ++) { switch (blk_indx) { case Y_BLOCK1: coef_bufrow = coef_bufrow_y; coef_bufcol = coef_bufcol_y; dc_scaler = dc_scaler_lum; break; case Y_BLOCK2: coef_bufrow = coef_bufrow_y + SAMPLE_VIDEO_BLOCK_SIZE; coef_bufcol = coef_bufcol_y; dc_scaler = dc_scaler_lum; break; case Y_BLOCK3: coef_bufrow = coef_bufrow_y; coef_bufcol = coef_bufcol_y + SAMPLE_VIDEO_BLOCK_SIZE; dc_scaler = dc_scaler_lum; break; case Y_BLOCK4: coef_bufrow = coef_bufrow_y + SAMPLE_VIDEO_BLOCK_SIZE; coef_bufcol = coef_bufcol_y + SAMPLE_VIDEO_BLOCK_SIZE; dc_scaler = dc_scaler_lum; break; case U_BLOCK: coef_bufrow = coef_bufrow_cb; coef_bufcol = coef_bufcol_cb; dc_scaler = dc_scaler_chr; break; case V_BLOCK: coef_bufrow = coef_bufrow_cr; coef_bufcol = coef_bufcol_cr; dc_scaler = dc_scaler_chr; break; } coef = src_dst_coeff + blk_indx * 64; /* 1. AC/DC precition direction */ dc_top = (0 > coef_bufrow[0]) ? 1024 : coef_bufrow[0]; dc_left = (0 > coef_bufrow[-8]) ? 1024 : coef_bufrow[-8]; dc_left_top = (0 > coef_bufcol[0]) ? 1024 : coef_bufcol[0]; pred_qp = cur_qp; if (ABS_MP4(dc_left_top - dc_left) < ABS_MP4(dc_left_top - dc_top)) { pred_dir = IPP_VIDEO_VERTICAL; if ((0 <= coef_bufrow[0]) && (Y_BLOCK3 != blk_indx) && (Y_BLOCK4 != blk_indx)) { /* the reference block is from the top macro block */ pred_qp = qp_buf[1]; } } else { pred_dir = IPP_VIDEO_HORIZONTAL; if ((0 <= coef_bufrow[-8]) && (Y_BLOCK2 != blk_indx) && (Y_BLOCK4 != blk_indx)) { /* the reference block is from the left macro block */ pred_qp = qp_buf[0]; } } /* 2. AC prediction precalculation */ if (IPP_VIDEO_VERTICAL == pred_dir && MPEG4_PRED_DISABLE != sum_err) { if (0 > coef_bufrow[0]) { pred_buf[blk_indx * 8] = 2; } else { pred_buf[blk_indx * 8] = 3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -