📄 ep_picture.c
字号:
free(pred); free(prev_recon); free(base_recon); FreeImage(pr_edge); FreeImage(nr_edge); free(pi); free(bi); for (j = 0; j < (lines>>4)+1; j++) for (i = 0; i < (pels>>4)+2; i++) for (k = 0; k < 7; k++) free(MV[k][j][i]); if (advanced_intra_coding) { free(store_coeff); free(store_rcoeff); } if (advanced_temporarily_off) { overlapping_MC = ON; adv_pred = ON; use_4mv = ON; advanced_temporarily_off = NO; } return;}/*********************************************************************** * * Name: Predict_EP * Description: Predicts macroblock in EP frame prediction * * Input: pointers to current frame, previous recon. previous * interpolated, base recon, base interpolated, * pos. in image, MV data, and MB prediction type. * Returns: pointer to differential MB data after prediction * Side effects: * * Date: 971001 Author: Michael Gallant ---mikeg@ee.ubc.ca * ***********************************************************************/MB_Structure *Predict_EP( PictImage *curr_image, PictImage *prev_recon, unsigned char *prev_ipol, PictImage *base_recon, unsigned char *base_ipol, MB_Structure *pred_macroblock, int x, int y, MotionVector *MV[7][MBR+1][MBC+2], int *prediction_type, int *mode, int RTYPE){ int curr[16][16]; MB_Structure *forward_pred = (MB_Structure *) malloc (sizeof (MB_Structure)); MB_Structure *bidir_pred = (MB_Structure *) malloc (sizeof (MB_Structure)); MB_Structure *upward_pred = (MB_Structure *) malloc (sizeof (MB_Structure)); MB_Structure *pred_error = (MB_Structure *) malloc (sizeof (MB_Structure)); MotionVector *forward_MV; MotionVector ZERO = {0,0,0,0,0}; int SADbidir, SADforw, SADup, SADmin; int dx, dy, xmb, ymb, i, j; xmb = x / MB_SIZE + 1; ymb = y / MB_SIZE + 1; forward_MV = MV[0][ymb][xmb]; /* Find MB in current image */ FindMB (x, y, curr_image->lum, curr); /* Forward prediction. */ FindPred (x, y, forward_MV, prev_ipol, &forward_pred->lum[0][0], 16, 0); FindPred (x, y, &ZERO, base_ipol, &upward_pred->lum[0][0], 16, 0); for (j = 0; j < MB_SIZE; j++) { for (i = 0; i < MB_SIZE; i++) { /* Bidirectional prediction. */ bidir_pred->lum[j][i] = (forward_pred->lum[j][i] + upward_pred->lum[j][i]) / 2; } } SADforw = SAD_MB_integer (&curr[0][0], &forward_pred->lum[0][0], 16, INT_MAX); SADbidir = SAD_MB_integer (&curr[0][0], &bidir_pred->lum[0][0], 16, INT_MAX); SADbidir += 100; SADup = SAD_MB_integer (&curr[0][0], &upward_pred->lum[0][0], 16, INT_MAX); SADup -= 50; /* Prediction direction decision. */ if ((SADup <= SADforw) && (SADup <= SADbidir)) { *prediction_type = EP_UPWARD_PREDICTION; SADmin = SADup; } else if ((SADforw < SADup) && (SADforw <= SADbidir)) { *prediction_type = EP_FORWARD_PREDICTION; SADmin = SADforw; } else { *prediction_type = EP_BIDIRECTIONAL_PREDICTION; SADmin = SADbidir; } *(mode) = ChooseMode( curr_image->lum, x, y, SADmin); if (MODE_INTRA == *(mode) || MODE_INTRA_Q == *(mode)) { *prediction_type = EP_INTRA_PREDICTION; } switch (*prediction_type) { case EP_FORWARD_PREDICTION: /* Translate MV to chrominance-resolution (downsampled). */ dx = 2 * forward_MV->x + forward_MV->x_half; dy = 2 * forward_MV->y + forward_MV->y_half; dx = (dx % 4 == 0 ? dx >> 1 : (dx >> 1) | 1); dy = (dy % 4 == 0 ? dy >> 1 : (dy >> 1) | 1); /* Predict B as if P. */ DoPredChrom_P (x, y, dx, dy, curr_image, prev_recon, forward_pred, pred_error, RTYPE); for (j = 0; j < MB_SIZE; j++) { for (i = 0; i < MB_SIZE; i++) { pred_error->lum[j][i] = *(curr_image->lum + x + i + (y + j) * pels) - forward_pred->lum[j][i]; pred_macroblock->lum[j][i] = forward_pred->lum[j][i]; } } for (j = 0; j < MB_SIZE >> 1; j++) { for (i = 0; i < MB_SIZE >> 1; i++) { pred_macroblock->Cr[j][i] = forward_pred->Cr[j][i]; pred_macroblock->Cb[j][i] = forward_pred->Cb[j][i]; } } forward_MV->Mode = MODE_INTER; break; case EP_UPWARD_PREDICTION: /* Predict B as if P. */ DoPredChrom_P (x, y, 0, 0, curr_image, base_recon, upward_pred, pred_error, RTYPE); for (j = 0; j < MB_SIZE; j++) { for (i = 0; i < MB_SIZE; i++) { pred_error->lum[j][i] = *(curr_image->lum + x + i + (y + j) * pels) - upward_pred->lum[j][i]; pred_macroblock->lum[j][i] = upward_pred->lum[j][i]; } } for (j = 0; j < MB_SIZE >> 1; j++) { for (i = 0; i < MB_SIZE >> 1; i++) { pred_macroblock->Cr[j][i] = upward_pred->Cr[j][i]; pred_macroblock->Cb[j][i] = upward_pred->Cb[j][i]; } } forward_MV->Mode = MODE_INTER; /* Set forward MV data to 0 for future MV prediction. */ forward_MV->x = forward_MV->x_half = 0; forward_MV->y = forward_MV->y_half = 0; break; case EP_BIDIRECTIONAL_PREDICTION: /* Translate MV to chrominance-resolution (downsampled). */ dx = 2 * forward_MV->x + forward_MV->x_half; dy = 2 * forward_MV->y + forward_MV->y_half; dx = (dx % 4 == 0 ? dx >> 1 : (dx >> 1) | 1); dy = (dy % 4 == 0 ? dy >> 1 : (dy >> 1) | 1); DoPredChrom_P (x, y, dx, dy, curr_image, prev_recon, forward_pred, pred_error, RTYPE); /* Zero MV for upward prediction */ DoPredChrom_P (x, y, 0, 0, curr_image, base_recon, upward_pred, pred_error, RTYPE); for (j = 0; j < MB_SIZE; j++) { for (i = 0; i < MB_SIZE; i++) { pred_error->lum[j][i] = *(curr_image->lum + x + i + (y + j) * pels) - bidir_pred->lum[j][i]; pred_macroblock->lum[j][i] = bidir_pred->lum[j][i]; } } for (j = 0; j < MB_SIZE >> 1; j++) { for (i = 0; i < MB_SIZE >> 1; i++) { pred_macroblock->Cr[j][i] = (forward_pred->Cr[j][i] + upward_pred->Cr[j][i]) / 2; pred_macroblock->Cb[j][i] = (forward_pred->Cb[j][i] + upward_pred->Cb[j][i]) / 2; pred_error->Cr[j][i] = *(curr_image->Cr + (x>>1) + i + ((y>>1) + j) * cpels) - pred_macroblock->Cr[j][i]; pred_error->Cb[j][i] = *(curr_image->Cb + (x>>1) + i + ((y>>1) + j) * cpels) - pred_macroblock->Cb[j][i]; } } forward_MV->Mode = MODE_INTER; break; case EP_INTRA_PREDICTION: /* Set forward MV data to 0 for future MV prediction. */ forward_MV->x = forward_MV->x_half = 0; forward_MV->y = forward_MV->y_half = 0; forward_MV->Mode = MODE_INTRA; break; default: fprintf (stderr, "Illegal scalable prediction type in MB_Predict_EP (pred.c)\n"); exit (-1); } free (forward_pred); free (bidir_pred); free (upward_pred); return pred_error;}/********************************************************************** * * Name: MB_Recon_EP * Description: Reconstructs EP MB * * Input: pointers to decoded residual, previous recon, previous * interpolated, base recon, base interpolated, * pos. in image, MV data, and MB prediction type. * Returns: pointer to reconstructed MB data after motion compensation * Side effects: allocates memory to MB_structure * * Date: 971101 Author: Michael Gallant --- mikeg@ee.ubc.ca * ***********************************************************************/MB_Structure *MB_Recon_EP( PictImage *prev_recon, unsigned char *prev_ipol, MB_Structure *diff, PictImage *base_recon, unsigned char *base_ipol, int x_curr, int y_curr, MotionVector *MV[7][MBR+1][MBC+2], int prediction_type, int RTYPE){ MB_Structure *forward = (MB_Structure *) malloc (sizeof (MB_Structure)); MB_Structure *upward = (MB_Structure *) malloc (sizeof (MB_Structure)); MB_Structure *recon_data = (MB_Structure *) malloc (sizeof (MB_Structure)); MotionVector *forward_MV; MotionVector ZERO = {0,0,0,0,0}; int dxf, dyf; int i, j; switch (prediction_type) { case EP_FORWARD_PREDICTION: forward_MV = MV[0][y_curr / MB_SIZE + 1][x_curr / MB_SIZE + 1]; if (forward_MV->Mode == MODE_INTER || forward_MV->Mode == MODE_INTER_Q) { /* Inter 16x16 */ ReconLumBlock_P (x_curr, y_curr, forward_MV, prev_ipol, &diff->lum[0][0], 16, 0); dxf = 2 * forward_MV->x + forward_MV->x_half; dyf = 2 * forward_MV->y + forward_MV->y_half; dxf = (dxf % 4 == 0 ? dxf >> 1 : (dxf >> 1) | 1); dyf = (dyf % 4 == 0 ? dyf >> 1 : (dyf >> 1) | 1); ReconChromBlock_P (x_curr, y_curr, dxf, dyf, prev_recon, diff, RTYPE); } break; case EP_UPWARD_PREDICTION: /* Inter 16x16 */ ReconLumBlock_P (x_curr, y_curr, &ZERO, base_ipol, &diff->lum[0][0], 16, 0); ReconChromBlock_P (x_curr, y_curr, 0, 0, base_recon, diff, RTYPE); break; case EP_BIDIRECTIONAL_PREDICTION: forward_MV = MV[0][y_curr / MB_SIZE + 1][x_curr / MB_SIZE + 1]; if ((forward_MV->Mode == MODE_INTER || forward_MV->Mode == MODE_INTER_Q)) { /* Forward prediction. */ FindPred (x_curr, y_curr, forward_MV, prev_ipol, &forward->lum[0][0], 16, 0); /* Backward prediction. */ FindPred (x_curr, y_curr, &ZERO, base_ipol, &upward->lum[0][0], 16, 0); for (j = 0; j < MB_SIZE; j++) { for (i = 0; i < MB_SIZE; i++) { diff->lum[j][i] += (forward->lum[j][i] + upward->lum[j][i]) / 2; } } dxf = 2 * forward_MV->x + forward_MV->x_half; dyf = 2 * forward_MV->y + forward_MV->y_half; dxf = (dxf % 4 == 0 ? dxf >> 1 : (dxf >> 1) | 1); dyf = (dyf % 4 == 0 ? dyf >> 1 : (dyf >> 1) | 1); FindChromBlock_P (x_curr, y_curr, dxf, dyf, prev_recon, forward, RTYPE); FindChromBlock_P (x_curr, y_curr, 0, 0, base_recon, upward, RTYPE); for (j = 0; j < MB_SIZE / 2; j++) { for (i = 0; i < MB_SIZE / 2; i++) { diff->Cr[j][i] += (forward->Cr[j][i] + upward->Cr[j][i]) / 2; diff->Cb[j][i] += (forward->Cb[j][i] + upward->Cb[j][i]) / 2; } } } break; case EP_INTRA_PREDICTION: break; default: fprintf (stderr, "Illegal scalable prediction type in MB_Recon_EP (pred.c)\n"); exit (-1); break; } memcpy (recon_data, diff, sizeof (MB_Structure)); free (forward); free (upward); return recon_data;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -