?? p_picture.c
字號:
/* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); FindChromBlock_P (x, y, dx, dy, prev_image, pred, 0); /* chroma vectors are sum of B luma vectors divided and rounded */ xvec = yvec = 0; for (k = 1; k <= 4; k++) { mvx = 2 * f[k]->x + f[k]->x_half; mvy = 2 * f[k]->y + f[k]->y_half; xvec += bdx == 0 ? (TRB - TRD) * mvx / TRD : TRB * mvx / TRD + bdx - mvx; yvec += bdy == 0 ? (TRB - TRD) * mvy / TRD : TRB * mvy / TRD + bdy - mvy; } /* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); FindBiDirChrPredPB (recon_P, dx, dy, pred); } else { xvec = 4 * (TRB * (2 * f[0]->x + f[0]->x_half) / TRD + bdx); yvec = 4 * (TRB * (2 * f[0]->y + f[0]->y_half) / TRD + bdy); /* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); /* chroma vectors */ FindChromBlock_P (x, y, dx, dy, prev_image, pred, 0); mvx = 2 * f[0]->x + f[0]->x_half; xvec = bdx == 0 ? (TRB - TRD) * mvx / TRD : TRB * mvx / TRD + bdx - mvx; xvec *= 4; mvy = 2 * f[0]->y + f[0]->y_half; yvec = bdy == 0 ? (TRB - TRD) * mvy / TRD : TRB * mvy / TRD + bdy - mvy; yvec *= 4; /* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); FindBiDirChrPredPB (recon_P, dx, dy, pred); } /* Do the actual prediction */ for (j = 0; j < MB_SIZE; j++) for (i = 0; i < MB_SIZE; i++) { p_err->lum[j][i] = *(curr_image->lum + x + i + (y + j) * pels) - pred->lum[j][i]; pred_macroblock->lum[j][i] = pred->lum[j][i]; } xx = x >> 1; yy = y >> 1; for (j = 0; j < MB_SIZE >> 1; j++) for (i = 0; i < MB_SIZE >> 1; i++) { p_err->Cr[j][i] = *(curr_image->Cr + xx + i + (yy + j) * cpels) - pred->Cr[j][i]; p_err->Cb[j][i] = *(curr_image->Cb + xx + i + (yy + j) * cpels) - pred->Cb[j][i]; pred_macroblock->Cr[j][i] = pred->Cr[j][i]; pred_macroblock->Cb[j][i] = pred->Cb[j][i]; } } /* store PB-deltas */ MV[6][y / MB_SIZE + 1][x / MB_SIZE + 1]->x = bdx; /* is in half pel format */ MV[6][y / MB_SIZE + 1][x / MB_SIZE + 1]->y = bdy; MV[6][y / MB_SIZE + 1][x / MB_SIZE + 1]->x_half = 0; MV[6][y / MB_SIZE + 1][x / MB_SIZE + 1]->y_half = 0; free (pred); free (frw_pred); return p_err;}/*********************************************************************** * * Name: MB_Recon_B * Description: Reconstructs the B macroblock in PB-frame * prediction * * Input: pointers previous recon. frame, pred. diff., * pos. in image, MV-data, reconstructed macroblock * from image ahead * Returns: pointer to reconstructed MB data * Side effects: allocates memory to MB_structure * * Date: 950114 Author: Karl.Lillevold@nta.no * ***********************************************************************/MB_Structure *MB_Recon_B (PictImage * prev_image, MB_Structure * diff, unsigned char *prev_ipol, int x, int y, MotionVector * MV[5][MBR + 1][MBC + 2], MB_Structure * recon_P, int TRD, int TRB){ int i, j, k; int dx, dy, bdx, bdy, mvx, mvy, xvec, yvec; MB_Structure *recon_B = (MB_Structure *) malloc (sizeof (MB_Structure)); MB_Structure *pred = (MB_Structure *) malloc (sizeof (MB_Structure)); MotionVector *f[5]; for (k = 0; k <= 4; k++) f[k] = MV[k][y / MB_SIZE + 1][x / MB_SIZE + 1]; bdx = MV[6][y / MB_SIZE + 1][x / MB_SIZE + 1]->x; bdy = MV[6][y / MB_SIZE + 1][x / MB_SIZE + 1]->y; if (f[0]->Mode == MODE_INTER4V || f[0]->Mode == MODE_INTER4V_Q) { /* Mode INTER4V */ /* Find forward prediction */ /* Luma */ FindForwLumPredPB (prev_ipol, x, y, f[1], &pred->lum[0][0], TRD, TRB, bdx, bdy, 8, 0); FindForwLumPredPB (prev_ipol, x, y, f[2], &pred->lum[0][8], TRD, TRB, bdx, bdy, 8, 1); FindForwLumPredPB (prev_ipol, x, y, f[3], &pred->lum[8][0], TRD, TRB, bdx, bdy, 8, 2); FindForwLumPredPB (prev_ipol, x, y, f[4], &pred->lum[8][8], TRD, TRB, bdx, bdy, 8, 3); /* chroma vectors are sum of B luma vectors divided and rounded */ xvec = yvec = 0; for (k = 1; k <= 4; k++) { xvec += TRB * (2 * f[k]->x + f[k]->x_half) / TRD + bdx; yvec += TRB * (2 * f[k]->y + f[k]->y_half) / TRD + bdy; } /* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); FindChromBlock_P (x, y, dx, dy, prev_image, pred, 0); /* Find bidirectional prediction */ FindBiDirLumPredPB (&recon_P->lum[0][0], f[1], &pred->lum[0][0], TRD, TRB, bdx, bdy, 0, 0); FindBiDirLumPredPB (&recon_P->lum[0][8], f[2], &pred->lum[0][8], TRD, TRB, bdx, bdy, 1, 0); FindBiDirLumPredPB (&recon_P->lum[8][0], f[3], &pred->lum[8][0], TRD, TRB, bdx, bdy, 0, 1); FindBiDirLumPredPB (&recon_P->lum[8][8], f[4], &pred->lum[8][8], TRD, TRB, bdx, bdy, 1, 1); /* chroma vectors are sum of B luma vectors divided and rounded */ xvec = yvec = 0; for (k = 1; k <= 4; k++) { mvx = 2 * f[k]->x + f[k]->x_half; mvy = 2 * f[k]->y + f[k]->y_half; xvec += bdx == 0 ? (TRB - TRD) * mvx / TRD : TRB * mvx / TRD + bdx - mvx; yvec += bdy == 0 ? (TRB - TRD) * mvy / TRD : TRB * mvy / TRD + bdy - mvy; } /* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); FindBiDirChrPredPB (recon_P, dx, dy, pred); } else { /* Mode INTER or INTER_Q */ /* Find forward prediction */ FindForwLumPredPB (prev_ipol, x, y, f[0], &pred->lum[0][0], TRD, TRB, bdx, bdy, 16, 0); xvec = 4 * (TRB * (2 * f[0]->x + f[0]->x_half) / TRD + bdx); yvec = 4 * (TRB * (2 * f[0]->y + f[0]->y_half) / TRD + bdy); /* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); FindChromBlock_P (x, y, dx, dy, prev_image, pred, 0); /* Find bidirectional prediction */ FindBiDirLumPredPB (&recon_P->lum[0][0], f[0], &pred->lum[0][0], TRD, TRB, bdx, bdy, 0, 0); FindBiDirLumPredPB (&recon_P->lum[0][8], f[0], &pred->lum[0][8], TRD, TRB, bdx, bdy, 1, 0); FindBiDirLumPredPB (&recon_P->lum[8][0], f[0], &pred->lum[8][0], TRD, TRB, bdx, bdy, 0, 1); FindBiDirLumPredPB (&recon_P->lum[8][8], f[0], &pred->lum[8][8], TRD, TRB, bdx, bdy, 1, 1); /* chroma vectors */ mvx = 2 * f[0]->x + f[0]->x_half; xvec = bdx == 0 ? (TRB - TRD) * mvx / TRD : TRB * mvx / TRD + bdx - mvx; xvec *= 4; mvy = 2 * f[0]->y + f[0]->y_half; yvec = bdy == 0 ? (TRB - TRD) * mvy / TRD : TRB * mvy / TRD + bdy - mvy; yvec *= 4; /* round values according to TABLE 16/H.263 */ dx = sign (xvec) * (roundtab[abs (xvec) % 16] + (abs (xvec) / 16) * 2); dy = sign (yvec) * (roundtab[abs (yvec) % 16] + (abs (yvec) / 16) * 2); FindBiDirChrPredPB (recon_P, dx, dy, pred); } /* Reconstruction */ for (j = 0; j < MB_SIZE; j++) for (i = 0; i < MB_SIZE; i++) recon_B->lum[j][i] = pred->lum[j][i] + diff->lum[j][i]; for (j = 0; j < MB_SIZE >> 1; j++) for (i = 0; i < MB_SIZE >> 1; i++) { recon_B->Cr[j][i] = pred->Cr[j][i] + diff->Cr[j][i]; recon_B->Cb[j][i] = pred->Cb[j][i] + diff->Cb[j][i]; } free (pred); return recon_B;}/********************************************************************** * * Name: FindForwLumPredPB * Description: Finds the forward luma prediction in PB-frame * pred. * * Input: pointer to prev. recon. frame, current positon, * MV structure and pred. structure to fill * * Date: 950114 Author: Karl.Lillevold@nta.no * ***********************************************************************/void FindForwLumPredPB (unsigned char *prev_ipol, int x_curr, int y_curr, MotionVector * fr, int *pred, int TRD, int TRB, int bdx, int bdy, int bs, int comp){ int i, j; int xvec, yvec, lx; lx = (mv_outside_frame ? pels + (long_vectors ? 64 : 32) : pels); /* Luma */ xvec = (TRB) * (2 * fr->x + fr->x_half) / TRD + bdx; yvec = (TRB) * (2 * fr->y + fr->y_half) / TRD + bdy; x_curr += ((comp & 1) << 3); y_curr += ((comp & 2) << 2); for (j = 0; j < bs; j++) { for (i = 0; i < bs; i++) { *(pred + i + j * 16) = *(prev_ipol + (i + x_curr) * 2 + xvec + ((j + y_curr) * 2 + yvec) * lx * 2); } } return;}/********************************************************************** * * Name: FindBiDirLumPredPB * Description: Finds the bi-dir. luma prediction in PB-frame * prediction * * Input: pointer to future recon. data, current positon, * MV structure and pred. structure to fill * * Date: 950115 Author: Karl.Lillevold@nta.no * ***********************************************************************/void FindBiDirLumPredPB (int *recon_P, MotionVector * fr, int *pred, int TRD, int TRB, int bdx, int bdy, int nh, int nv){ int xstart, xstop, ystart, ystop; int xvec, yvec, mvx, mvy; mvx = 2 * fr->x + fr->x_half; mvy = 2 * fr->y + fr->y_half; xvec = (bdx == 0 ? (TRB - TRD) * mvx / TRD : TRB * mvx / TRD + bdx - mvx); yvec = (bdy == 0 ? (TRB - TRD) * mvy / TRD : TRB * mvy / TRD + bdy - mvy); /* Luma */ FindBiDirLimits (xvec, &xstart, &xstop, nh); FindBiDirLimits (yvec, &ystart, &ystop, nv); BiDirPredBlock (xstart, xstop, ystart, ystop, xvec, yvec, recon_P, pred, 16); return;}/********************************************************************** * * Name: FindBiDirChrPredPB * Description: Finds the bi-dir. chroma prediction in PB-frame * prediction * * Input: pointer to future recon. data, current positon, * MV structure and pred. structure to fill * * Date: 950115 Author: Karl.Lillevold@nta.no * ***********************************************************************/void FindBiDirChrPredPB (MB_Structure * recon_P, int dx, int dy, MB_Structure * pred){ int xstart, xstop, ystart, ystop; FindBiDirChromaLimits (dx, &xstart, &xstop); FindBiDirChromaLimits (dy, &ystart, &ystop); BiDirPredBlock (xstart, xstop, ystart, ystop, dx, dy, &recon_P->Cb[0][0], &pred->Cb[0][0], 8); BiDirPredBlock (xstart, xstop, ystart, ystop, dx, dy, &recon_P->Cr[0][0], &pred->Cr[0][0], 8); return;}void FindBiDirLimits (int vec, int *start, int *stop, int nhv){ /* limits taken from C loop in section G5 in H.263 */ *start = mmax (0, (-vec + 1) / 2 - nhv * 8); *stop = mmin (7, 15 - (vec + 1) / 2 - nhv * 8); return;}void FindBiDirChromaLimits (int vec, int *start, int *stop){ /* limits taken from C loop in section G5 in H.263 */ *start = mmax (0, (-vec + 1) / 2); *stop = mmin (7, 7 - (vec + 1) / 2); return;}void BiDirPredBlock (int xstart, int xstop, int ystart, int ystop, int xvec, int yvec, int *recon, int *pred, int bl){ int i, j, pel; int xint, yint; int xh, yh; xint = xvec >> 1; xh = xvec - 2 * xint; yint = yvec >> 1; yh = yvec - 2 * yint; if (!xh && !yh) { for (j = ystart; j <= ystop; j++) { for (i = xstart; i <= xstop; i++) { pel = *(recon + (j + yint) * bl + i + xint); *(pred + j * bl + i) = (mmin (255, mmax (0, pel)) + *(pred + j * bl + i)) >> 1; } } } else if (!xh && yh) { for (j = ystart; j <= ystop; j++) { for (i = xstart; i <= xstop; i++) { pel = (*(recon + (j + yint) * bl + i + xint) + *(recon + (j + yint + yh) * bl + i + xint) + 1) >> 1; *(pred + j * bl + i) = (pel + *(pred + j * bl + i)) >> 1; } } } else if (xh && !yh) { for (j = ystart; j <= ystop; j++) { for (i = xstart; i <= xstop; i++) { pel = (*(recon + (j + yint) * bl + i + xint) + *(recon + (j + yint) * bl + i + xint + xh) + 1) >> 1; *(pred + j * bl + i) = (pel + *(pred + j * bl + i)) >> 1; } } } else { /* xh && yh */ for (j = ystart; j <= ystop; j++) { for (i = xstart; i <= xstop; i++) { pel = (*(recon + (j + yint) * bl + i + xint) + *(recon + (j + yint + yh) * bl + i + xint) + *(recon + (j + yint) * bl + i + xint + xh) + *(recon + (j + yint + yh) * bl + i + xint + xh) + 2) >> 2; *(pred + j * bl + i) = (pel + *(pred + j * bl + i)) >> 1; } } } return;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -