00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "global.h"
00017 #include "mbuffer.h"
00018 #include "mb_access.h"
00019 #include "macroblock.h"
00020 #include "errdo.h"
00021 #include "block.h"
00022 #include "errdo_mc_prediction.h"
00023
00024 static const int COEF[6] = { 1, -5, 20, 20, -5, 1 };
00025
00026
00027
00028
00029
00030
00031 static inline void mc_prediction(imgpel** mb_pred,
00032 int ver_block_size,
00033 int hor_block_size,
00034 int ioff,
00035 imgpel block[MB_BLOCK_SIZE][MB_BLOCK_SIZE])
00036 {
00037 int jj;
00038
00039 if (hor_block_size == MB_BLOCK_SIZE)
00040 {
00041 memcpy(&(mb_pred[0][ioff]), &(block[0][0]), hor_block_size * ver_block_size * sizeof(imgpel));
00042 }
00043 else
00044 {
00045 for(jj = 0; jj < ver_block_size; jj++)
00046 {
00047 memcpy(&(mb_pred[jj][ioff]), &(block[jj][0]), hor_block_size * sizeof(imgpel));
00048 }
00049 }
00050 }
00051
00052
00053
00054
00055
00056
00057
00058 static inline void weighted_mc_prediction(imgpel** mb_pred,
00059 int ver_block_size,
00060 int hor_block_size,
00061 int ioff,
00062 imgpel block[MB_BLOCK_SIZE][MB_BLOCK_SIZE],
00063 int wp_scale,
00064 int wp_offset,
00065 int weight_denom,
00066 int color_clip)
00067 {
00068 int ii, jj;
00069 imgpel *mpr, *b0;
00070
00071 for(jj=0;jj<ver_block_size;jj++)
00072 {
00073 mpr = &mb_pred[jj][ioff];
00074 b0 = block[jj];
00075 for(ii=0;ii<hor_block_size;ii++)
00076 *(mpr++) = (imgpel) iClip1(color_clip, (rshift_rnd((wp_scale * *(b0++)), weight_denom) + wp_offset ));
00077 }
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087 static inline void bi_prediction(imgpel** mb_pred,
00088 imgpel block_l0[MB_BLOCK_SIZE][MB_BLOCK_SIZE],
00089 imgpel block_l1[MB_BLOCK_SIZE][MB_BLOCK_SIZE],
00090 int ver_block_size,
00091 int hor_block_size,
00092 int ioff)
00093 {
00094 int ii, jj;
00095 imgpel *mpr, *b0, *b1;
00096
00097 for(jj = 0;jj < ver_block_size;jj++)
00098 {
00099 mpr = &mb_pred[jj][ioff];
00100 b0 = block_l0[jj];
00101 b1 = block_l1[jj];
00102 for(ii = 0; ii < hor_block_size;ii++)
00103 *(mpr++) = (imgpel) rshift_rnd_sf((*(b0++) + *(b1++)), 1);
00104 }
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 static inline void weighted_bi_prediction(imgpel** mb_pred,
00114 imgpel block_l0[MB_BLOCK_SIZE][MB_BLOCK_SIZE],
00115 imgpel block_l1[MB_BLOCK_SIZE][MB_BLOCK_SIZE],
00116 int ver_block_size,
00117 int hor_block_size,
00118 int ioff,
00119 int wp_scale_l0,
00120 int wp_scale_l1,
00121 int wp_offset,
00122 int weight_denom,
00123 int color_clip)
00124 {
00125 int ii, jj;
00126 imgpel *mpr, *b0, *b1;
00127
00128 for(jj = 0; jj < ver_block_size; jj++)
00129 {
00130 mpr = &mb_pred[jj][ioff];
00131 b0 = block_l0[jj];
00132 b1 = block_l1[jj];
00133
00134 for(ii=0;ii<hor_block_size;ii++)
00135 *(mpr++) = (imgpel) iClip1(color_clip, (rshift_rnd((wp_scale_l0 * *(b0++) + wp_scale_l1 * *(b1++)), weight_denom) + wp_offset));
00136 }
00137 }
00138
00139 void get_block_luma(Macroblock *currMB, int decoder, ColorPlane pl, StorablePicture* dec_picture, StorablePicture *curr_ref, int x_pos, int y_pos, int hor_block_size, int ver_block_size, imgpel block[MB_BLOCK_SIZE][MB_BLOCK_SIZE])
00140 {
00141 ImageParameters *p_Img = currMB->p_Img;
00142 InputParameters *p_Inp = currMB->p_Inp;
00143
00144 int tmp_res[21][21];
00145 int *tmp_line;
00146 imgpel *p0, *p1, *p2, *p3, *p4, *p5;
00147 int *x0, *x1, *x2, *x3, *x4, *x5;
00148
00149 imgpel **cur_imgY, *cur_lineY;
00150 int ipos_m2, ipos_m1, ipos, ipos_p1, ipos_p2, ipos_p3;
00151 imgpel *orig_line;
00152 int tmp_pos;
00153
00154 int dx = (x_pos & 3), dy = (y_pos & 3);
00155 int i, j, jj;
00156 int shift_x = dec_picture->size_x;
00157 int maxold_x = dec_picture->size_x - 1;
00158 int maxold_y = (dec_picture->motion.mb_field[p_Img->current_mb_nr]) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y - 1;
00159 int result;
00160 int pres_x;
00161 int max_imgpel_value = p_Img->max_pel_value_comp[pl];
00162
00163 if( IS_INDEPENDENT(p_Inp) )
00164 {
00165 cur_imgY = curr_ref->p_dec_img[(short) p_Img->colour_plane_id][decoder];
00166 }
00167 else
00168 {
00169 cur_imgY = curr_ref->p_dec_img[pl][decoder];
00170 }
00171
00172 x_pos = x_pos >> 2;
00173 y_pos = y_pos >> 2;
00174
00175 if ( (y_pos > 1) && (y_pos < maxold_y - 2 - ver_block_size) && (x_pos > 1) && (x_pos < maxold_x - 2 - hor_block_size))
00176 {
00177 cur_imgY = &cur_imgY[ y_pos];
00178 if (dx == 0 && dy == 0)
00179 {
00180 for (j = 0; j < ver_block_size; j++)
00181 {
00182 memcpy(&(block[j][0]), &(cur_imgY[j][x_pos]), hor_block_size * sizeof(imgpel));
00183 }
00184 }
00185 else
00186 {
00187
00188 if (dy == 0)
00189 {
00190 for (j = 0; j < ver_block_size; j++)
00191 {
00192 p0 = &cur_imgY[j][x_pos - 2];
00193 p1 = p0 + 1;
00194 p2 = p1 + 1;
00195 p3 = p2 + 1;
00196 p4 = p3 + 1;
00197 p5 = p4 + 1;
00198 orig_line = block[j];
00199
00200 for (i = 0; i < hor_block_size; i++)
00201 {
00202 result = (*(p0++) + *(p5++)) * COEF[0]
00203 + (*(p1++) + *(p4++)) * COEF[1]
00204 + (*(p2++) + *(p3++)) * COEF[2];
00205
00206 *orig_line++ = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5));
00207 }
00208 }
00209
00210 if ((dx&1) == 1)
00211 {
00212 for (j = 0; j < ver_block_size; j++)
00213 {
00214 cur_lineY = &(cur_imgY[j][x_pos + (dx >> 1)]);
00215 orig_line = block[j];
00216 for (i = 0; i < hor_block_size; i++)
00217 {
00218 *orig_line = (imgpel) ((*orig_line + *(cur_lineY++) + 1 ) >> 1);
00219 orig_line++;
00220 }
00221 }
00222 }
00223 }
00224 else if (dx == 0)
00225 {
00226 p0 = &(cur_imgY[ - 2][x_pos]);
00227 for (j = 0; j < ver_block_size; j++)
00228 {
00229 p1 = p0 + shift_x;
00230 p2 = p1 + shift_x;
00231 p3 = p2 + shift_x;
00232 p4 = p3 + shift_x;
00233 p5 = p4 + shift_x;
00234 orig_line = block[j];
00235
00236 for (i = 0; i < hor_block_size; i++)
00237 {
00238 result = (*(p0++) + *(p5++)) * COEF[0]
00239 + (*(p1++) + *(p4++)) * COEF[1]
00240 + (*(p2++) + *(p3++)) * COEF[2];
00241
00242 *orig_line++ = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5));
00243 }
00244 p0 = p1 - hor_block_size;
00245 }
00246
00247 if ((dy&1) == 1)
00248 {
00249 jj = (dy >> 1);
00250 for (j = 0; j < ver_block_size; j++)
00251 {
00252 cur_lineY = &(cur_imgY[jj++][x_pos]);
00253 orig_line = block[j];
00254 for (i = 0; i < hor_block_size; i++)
00255 {
00256 *orig_line = (imgpel) ((*orig_line + *(cur_lineY++) + 1 ) >> 1);
00257 orig_line++;
00258 }
00259 }
00260 }
00261 }
00262 else if (dx == 2)
00263 {
00264 jj = - 2;
00265 for (j = 0; j < ver_block_size + 5; j++)
00266 {
00267 p0 = &cur_imgY[jj++][x_pos - 2];
00268 p1 = p0 + 1;
00269 p2 = p1 + 1;
00270 p3 = p2 + 1;
00271 p4 = p3 + 1;
00272 p5 = p4 + 1;
00273 orig_line = block[j];
00274 tmp_line = tmp_res[j];
00275
00276 for (i = 0; i < hor_block_size; i++)
00277 {
00278 *(tmp_line++) = (*(p0++) + *(p5++)) * COEF[0]
00279 + (*(p1++) + *(p4++)) * COEF[1]
00280 + (*(p2++) + *(p3++)) * COEF[2];
00281 }
00282 }
00283
00284 for (j = 0; j < ver_block_size; j++)
00285 {
00286 x0 = tmp_res[j ];
00287 x1 = tmp_res[j + 1];
00288 x2 = tmp_res[j + 2];
00289 x3 = tmp_res[j + 3];
00290 x4 = tmp_res[j + 4];
00291 x5 = tmp_res[j + 5];
00292 orig_line = block[j];
00293
00294 for (i = 0; i < hor_block_size; i++)
00295 {
00296 result = (*x0++ + *x5++) * COEF[0]
00297 + (*x1++ + *x4++) * COEF[1]
00298 + (*x2++ + *x3++) * COEF[2];
00299
00300 *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result+512)>>10));
00301 }
00302 }
00303
00304 if ((dy&1) == 1)
00305 {
00306 jj = 2 + (dy>>1);
00307 for (j = 0; j < ver_block_size; j++)
00308 {
00309 tmp_line = tmp_res[jj++];
00310 orig_line = block[j];
00311 for (i = 0; i < hor_block_size; i++)
00312 {
00313 *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + 1 )>> 1);
00314 orig_line++;
00315 }
00316 }
00317 }
00318 }
00319 else if (dy == 2)
00320 {
00321 p0 = &(cur_imgY[ -2][x_pos - 2]);
00322 for (j = 0; j < ver_block_size; j++)
00323 {
00324 p1 = p0 + shift_x;
00325 p2 = p1 + shift_x;
00326 p3 = p2 + shift_x;
00327 p4 = p3 + shift_x;
00328 p5 = p4 + shift_x;
00329 tmp_line = tmp_res[j];
00330
00331 for (i = 0; i < hor_block_size + 5; i++)
00332 {
00333 *(tmp_line++) = (*(p0++) + *(p5++)) * COEF[0]
00334 + (*(p1++) + *(p4++)) * COEF[1]
00335 + (*(p2++) + *(p3++)) * COEF[2];
00336 }
00337 p0 = p1 - (hor_block_size + 5);
00338 }
00339
00340 for (j = 0; j < ver_block_size; j++)
00341 {
00342 orig_line = block[j];
00343 x0 = tmp_res[j];
00344 x1 = x0 + 1;
00345 x2 = x1 + 1;
00346 x3 = x2 + 1;
00347 x4 = x3 + 1;
00348 x5 = x4 + 1;
00349
00350 for (i = 0; i < hor_block_size; i++)
00351 {
00352 result = (*(x0++) + *(x5++)) * COEF[0]
00353 + (*(x1++) + *(x4++)) * COEF[1]
00354 + (*(x2++) + *(x3++)) * COEF[2];
00355
00356 *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 512)>>10));
00357 }
00358 }
00359
00360 if ((dx&1) == 1)
00361 {
00362 for (j = 0; j < ver_block_size; j++)
00363 {
00364 tmp_line = &tmp_res[j][2 + (dx>>1)];
00365 orig_line = block[j];
00366 for (i = 0; i < hor_block_size; i++)
00367 {
00368 *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16)>>5))+1)>>1);
00369 orig_line ++;
00370 }
00371 }
00372 }
00373 }
00374 else
00375 {
00376 jj = (dy == 1 ? 0 : 1);
00377
00378 for (j = 0; j < ver_block_size; j++)
00379 {
00380 p0 = &cur_imgY[jj++][x_pos - 2];
00381 p1 = p0 + 1;
00382 p2 = p1 + 1;
00383 p3 = p2 + 1;
00384 p4 = p3 + 1;
00385 p5 = p4 + 1;
00386
00387 orig_line = block[j];
00388
00389 for (i = 0; i < hor_block_size; i++)
00390 {
00391 result = (*(p0++) + *(p5++)) * COEF[0]
00392 + (*(p1++) + *(p4++)) * COEF[1]
00393 + (*(p2++) + *(p3++)) * COEF[2];
00394
00395 *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5));
00396 }
00397 }
00398
00399 p0 = &(cur_imgY[-2][(dx == 1 ? x_pos : x_pos + 1)]);
00400 for (j = 0; j < ver_block_size; j++)
00401 {
00402 p1 = p0 + shift_x;
00403 p2 = p1 + shift_x;
00404 p3 = p2 + shift_x;
00405 p4 = p3 + shift_x;
00406 p5 = p4 + shift_x;
00407 orig_line = block[j];
00408
00409 for (i = 0; i < hor_block_size; i++)
00410 {
00411 result = (*(p0++) + *(p5++)) * COEF[0]
00412 + (*(p1++) + *(p4++)) * COEF[1]
00413 + (*(p2++) + *(p3++)) * COEF[2];
00414
00415 *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> 1);
00416 orig_line++;
00417 }
00418 p0 = p1 - hor_block_size ;
00419 }
00420 }
00421 }
00422 }
00423 else
00424 {
00425 if (dx == 0 && dy == 0)
00426 {
00427 for (j = 0; j < ver_block_size; j++)
00428 {
00429 cur_lineY = cur_imgY[iClip3(0, maxold_y, y_pos + j)];
00430 orig_line = block[j];
00431 for (i = 0; i < hor_block_size; i++)
00432 {
00433 *(orig_line++) = cur_lineY[iClip3(0, maxold_x, x_pos + i )];
00434 }
00435 }
00436 }
00437 else
00438 {
00439
00440 if (dy == 0)
00441 {
00442 tmp_pos = x_pos - 2;
00443 for (i = 0; i < hor_block_size; i++)
00444 {
00445 ipos_m2 = iClip3(0, maxold_x, tmp_pos++);
00446 ipos_m1 = iClip3(0, maxold_x, tmp_pos++);
00447 ipos = iClip3(0, maxold_x, tmp_pos++);
00448 ipos_p1 = iClip3(0, maxold_x, tmp_pos++);
00449 ipos_p2 = iClip3(0, maxold_x, tmp_pos++);
00450 ipos_p3 = iClip3(0, maxold_x, tmp_pos );
00451 tmp_pos -= 4;
00452
00453 for (j = 0; j < ver_block_size; j++)
00454 {
00455 cur_lineY = cur_imgY[iClip3(0,maxold_y,y_pos+j)];
00456
00457 result = (cur_lineY[ipos_m2] + cur_lineY[ipos_p3]) * COEF[0];
00458 result += (cur_lineY[ipos_m1] + cur_lineY[ipos_p2]) * COEF[1];
00459 result += (cur_lineY[ipos ] + cur_lineY[ipos_p1]) * COEF[2];
00460
00461 block[j][i] = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5));
00462 }
00463 }
00464
00465 if ((dx&1) == 1)
00466 {
00467 for (j = 0; j < ver_block_size; j++)
00468 {
00469 cur_lineY = cur_imgY[iClip3(0,maxold_y,y_pos+j)];
00470 orig_line = block[j];
00471 for (i = 0; i < hor_block_size; i++)
00472 {
00473 *orig_line = (imgpel) ((*orig_line + cur_lineY[iClip3(0, maxold_x, x_pos + i + (dx >> 1))] + 1 ) >> 1);
00474 orig_line++;
00475 }
00476 }
00477 }
00478 }
00479 else if (dx == 0)
00480 {
00481 tmp_pos = y_pos - 2;
00482 for (j = 0; j < ver_block_size; j++)
00483 {
00484 p0 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00485 p1 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00486 p2 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00487 p3 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00488 p4 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00489 p5 = cur_imgY[iClip3(0, maxold_y, tmp_pos )];
00490
00491 tmp_pos -= 4;
00492 orig_line = block[j];
00493
00494 for (i = 0; i < hor_block_size; i++)
00495 {
00496 pres_x = iClip3(0,maxold_x,x_pos+i);
00497
00498 result = (p0[pres_x] + p5[pres_x]) * COEF[0];
00499 result += (p1[pres_x] + p4[pres_x]) * COEF[1];
00500 result += (p2[pres_x] + p3[pres_x]) * COEF[2];
00501 *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result+16)>>5));
00502 }
00503 }
00504
00505 if ((dy&1) == 1)
00506 {
00507 for (j = 0; j < ver_block_size; j++)
00508 {
00509 cur_lineY = cur_imgY[iClip3(0,maxold_y,y_pos+j+(dy>>1))];
00510 orig_line = block[j];
00511 for (i = 0; i < hor_block_size; i++)
00512 {
00513 *orig_line = (imgpel) ((*orig_line + cur_lineY[iClip3(0, maxold_x, x_pos + i)] + 1 ) >> 1);
00514 orig_line++;
00515 }
00516 }
00517 }
00518 }
00519 else if (dx == 2)
00520 {
00521 tmp_pos = x_pos - 2;
00522 for (i = 0; i < hor_block_size; i++)
00523 {
00524 ipos_m2 = iClip3(0, maxold_x, tmp_pos++);
00525 ipos_m1 = iClip3(0, maxold_x, tmp_pos++);
00526 ipos = iClip3(0, maxold_x, tmp_pos++);
00527 ipos_p1 = iClip3(0, maxold_x, tmp_pos++);
00528 ipos_p2 = iClip3(0, maxold_x, tmp_pos++);
00529 ipos_p3 = iClip3(0, maxold_x, tmp_pos );
00530 tmp_pos -= 4;
00531
00532 for (j = 0; j < ver_block_size + 5; j++)
00533 {
00534 cur_lineY = cur_imgY[iClip3(0,maxold_y,y_pos + j - 2)];
00535
00536 tmp_res[j][i] = (cur_lineY[ipos_m2] + cur_lineY[ipos_p3]) * COEF[0];
00537 tmp_res[j][i] += (cur_lineY[ipos_m1] + cur_lineY[ipos_p2]) * COEF[1];
00538 tmp_res[j][i] += (cur_lineY[ipos ] + cur_lineY[ipos_p1]) * COEF[2];
00539 }
00540 }
00541
00542 for (j = 0; j < ver_block_size; j++)
00543 {
00544 x0 = tmp_res[j ];
00545 x1 = tmp_res[j + 1];
00546 x2 = tmp_res[j + 2];
00547 x3 = tmp_res[j + 3];
00548 x4 = tmp_res[j + 4];
00549 x5 = tmp_res[j + 5];
00550 orig_line = block[j];
00551
00552 for (i = 0; i < hor_block_size; i++)
00553 {
00554 result = (*x0++ + *x5++) * COEF[0]
00555 + (*x1++ + *x4++) * COEF[1]
00556 + (*x2++ + *x3++) * COEF[2];
00557
00558 *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result+512)>>10));
00559 }
00560 }
00561
00562 if ((dy&1) == 1)
00563 {
00564 for (j = 0; j < ver_block_size; j++)
00565 {
00566 tmp_line = tmp_res[j + 2 + (dy>>1)];
00567 orig_line = block[j];
00568 for (i = 0; i < hor_block_size; i++)
00569 {
00570 *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + 1 )>>1);
00571 orig_line++;
00572 }
00573 }
00574 }
00575 }
00576 else if (dy == 2)
00577 {
00578
00579 tmp_pos = y_pos - 2;
00580 for (j = 0; j < ver_block_size; j++)
00581 {
00582 p0 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00583 p1 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00584 p2 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00585 p3 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00586 p4 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00587 p5 = cur_imgY[iClip3(0, maxold_y, tmp_pos )];
00588
00589 tmp_pos -= 4;
00590
00591 for (i = 0; i < hor_block_size + 5; i++)
00592 {
00593 pres_x = iClip3(0,maxold_x, x_pos + i - 2);
00594 result = (p0[pres_x] + p5[pres_x])*COEF[0]
00595 + (p1[pres_x] + p4[pres_x])*COEF[1]
00596 + (p2[pres_x] + p3[pres_x])*COEF[2];
00597 tmp_res[j][i] = result;
00598 }
00599 }
00600
00601 for (j = 0; j < ver_block_size; j++)
00602 {
00603 orig_line = block[j];
00604 tmp_line = tmp_res[j];
00605 x0 = tmp_res[j];
00606 x1 = x0 + 1;
00607 x2 = x1 + 1;
00608 x3 = x2 + 1;
00609 x4 = x3 + 1;
00610 x5 = x4 + 1;
00611
00612 for (i = 0; i < hor_block_size; i++)
00613 {
00614 result = (*(x0++) + *(x5++)) * COEF[0]
00615 + (*(x1++) + *(x4++)) * COEF[1]
00616 + (*(x2++) + *(x3++)) * COEF[2];
00617
00618 *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 512)>>10));
00619 }
00620 }
00621
00622 if ((dx&1) == 1)
00623 {
00624 for (j = 0; j < ver_block_size; j++)
00625 {
00626 tmp_line = &tmp_res[j][2 + (dx>>1)];
00627 orig_line = block[j];
00628 for (i = 0; i < hor_block_size; i++)
00629 {
00630 *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16)>>5)) + 1)>> 1);
00631 orig_line++;
00632 }
00633 }
00634 }
00635 }
00636 else
00637 {
00638 tmp_pos = x_pos - 2;
00639 for (i = 0; i < hor_block_size; i++)
00640 {
00641 ipos_m2 = iClip3(0, maxold_x, tmp_pos++);
00642 ipos_m1 = iClip3(0, maxold_x, tmp_pos++);
00643 ipos = iClip3(0, maxold_x, tmp_pos++);
00644 ipos_p1 = iClip3(0, maxold_x, tmp_pos++);
00645 ipos_p2 = iClip3(0, maxold_x, tmp_pos++);
00646 ipos_p3 = iClip3(0, maxold_x, tmp_pos );
00647 tmp_pos -= 4;
00648
00649 for (j = 0; j < ver_block_size; j++)
00650 {
00651 cur_lineY = cur_imgY[iClip3(0,maxold_y,(dy == 1 ? y_pos+j : y_pos+j+1))];
00652
00653 result = (cur_lineY[ipos_m2] + cur_lineY[ipos_p3]) * COEF[0];
00654 result += (cur_lineY[ipos_m1] + cur_lineY[ipos_p2]) * COEF[1];
00655 result += (cur_lineY[ipos ] + cur_lineY[ipos_p1]) * COEF[2];
00656
00657 block[j][i] = (imgpel) iClip1(max_imgpel_value, ((result+16)>>5));
00658 }
00659 }
00660
00661 tmp_pos = y_pos - 2;
00662 for (j = 0; j < ver_block_size; j++)
00663 {
00664 p0 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00665 p1 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00666 p2 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00667 p3 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00668 p4 = cur_imgY[iClip3(0, maxold_y, tmp_pos++)];
00669 p5 = cur_imgY[iClip3(0, maxold_y, tmp_pos )];
00670
00671 tmp_pos -= 4;
00672 orig_line = block[j];
00673
00674 for (i = 0; i < hor_block_size; i++)
00675 {
00676 pres_x = dx == 1 ? x_pos+i : x_pos+i+1;
00677 pres_x = iClip3(0, maxold_x, pres_x);
00678
00679 result = (p0[pres_x] + p5[pres_x]) * COEF[0];
00680 result += (p1[pres_x] + p4[pres_x]) * COEF[1];
00681 result += (p2[pres_x] + p3[pres_x]) * COEF[2];
00682
00683 *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((result+16)>>5)) + 1 ) >> 1);
00684 orig_line++;
00685 }
00686 }
00687 }
00688 }
00689 }
00690 }
00691
00692 void get_block_chroma(Macroblock *currMB, int decoder, int uv, StorablePicture* dec_picture, StorablePicture *curr_ref, int x_pos, int y_pos, int hor_block_size, int ver_block_size, imgpel block[MB_BLOCK_SIZE][MB_BLOCK_SIZE])
00693 {
00694 ImageParameters *p_Img = currMB->p_Img;
00695 int subpel_x = p_Img->mb_cr_size_x == 8 ? 7 : 3;
00696 int subpel_y = p_Img->mb_cr_size_y == 8 ? 7 : 3;
00697 int shiftpel_x = p_Img->mb_cr_size_x == 8 ? 3 : 2;
00698 int shiftpel_y = p_Img->mb_cr_size_y == 8 ? 3 : 2;
00699 int total_scale = shiftpel_x + shiftpel_y;
00700
00701 int dx = (x_pos & subpel_x);
00702 int dy = (y_pos & subpel_y);
00703 int dxcur = (subpel_x + 1 - dx);
00704 int dycur = (subpel_y + 1 - dy);
00705
00706 int w00 = dxcur * dycur;
00707 int w01 = dxcur * dy;
00708 int w10 = dx * dycur;
00709 int w11 = dx * dy;
00710
00711 int i, j;
00712 int maxold_x = dec_picture->size_x_cr - 1;
00713 int maxold_y = (dec_picture->motion.mb_field[p_Img->current_mb_nr]) ? (dec_picture->size_y_cr >> 1) - 1 : dec_picture->size_y_cr - 1;
00714 int result;
00715
00716 imgpel **cur_img, *blk_line;
00717 imgpel *cur_line, *cur_line_p1;
00718 int tmp_pos;
00719 int ipos, ipos_p1;
00720 int max_imgpel_value = p_Img->max_pel_value_comp[uv + 1];
00721
00722 #if 0
00723 if (curr_ref == no_reference_picture && p_Img->framepoc < p_Img->recovery_poc)
00724 {
00725 printf("list[ref_frame] is equal to 'no reference picture' before RAP\n");
00726
00727
00728 for (j = 0; j < ver_block_size; j++)
00729 for (i = 0; i < hor_block_size; i++)
00730 block[j][i] = 128;
00731 return;
00732 }
00733 #endif
00734
00735 cur_img = curr_ref->p_dec_img[uv+1][decoder];
00736
00737 x_pos = x_pos >> shiftpel_x;
00738 y_pos = y_pos >> shiftpel_y;
00739
00740 if ((y_pos >= 0) && (y_pos < maxold_y - ver_block_size) && (x_pos >= 0) && (x_pos < maxold_x - hor_block_size))
00741 {
00742 if (dx == 0 && dy == 0)
00743 {
00744 for (j = 0; j < ver_block_size; j++)
00745 {
00746 memcpy(&(block[j][0]), &(cur_img[ y_pos + j ][x_pos]), hor_block_size * sizeof(imgpel));
00747 }
00748 }
00749 else if (dx == 0)
00750 {
00751 for (j = 0; j < ver_block_size; j++)
00752 {
00753 cur_line = &cur_img[y_pos + j ][x_pos];
00754 cur_line_p1 = &cur_img[y_pos + j + 1][x_pos];
00755 blk_line = block[j];
00756
00757 for (i = 0; i < hor_block_size; i++)
00758 {
00759 result = (w00 * *cur_line++ + w01 * *cur_line_p1++);
00760 *(blk_line++) = (imgpel) iClip1(max_imgpel_value, rshift_rnd_sf(result, total_scale));
00761 }
00762 }
00763 }
00764 else if (dy == 0)
00765 {
00766 for (j = 0; j < ver_block_size; j++)
00767 {
00768 cur_line = &cur_img[y_pos + j][x_pos];
00769 cur_line_p1 = cur_line + 1;
00770 blk_line = block[j];
00771
00772 for (i = 0; i < hor_block_size; i++)
00773 {
00774 result = (w00 * *cur_line++ + w10 * *cur_line_p1++);
00775 *(blk_line++) = (imgpel) iClip1(max_imgpel_value, rshift_rnd_sf(result, total_scale));
00776 }
00777 }
00778 }
00779 else
00780 {
00781 for (j = 0; j < ver_block_size; j++)
00782 {
00783 cur_line = &cur_img[y_pos + j ][x_pos];
00784 cur_line_p1 = &cur_img[y_pos + j + 1][x_pos];
00785 blk_line = block[j];
00786
00787 for (i = 0; i < hor_block_size; i++)
00788 {
00789 result = (w00 * *(cur_line++) + w01 * *(cur_line_p1++));
00790 result += (w10 * *(cur_line ) + w11 * *(cur_line_p1 ));
00791 *(blk_line++) = (imgpel) iClip1(max_imgpel_value, rshift_rnd_sf(result, total_scale));
00792 }
00793 }
00794 }
00795 }
00796 else
00797 {
00798 if (dx == 0 && dy == 0)
00799 {
00800 for (j = 0; j < ver_block_size; j++)
00801 {
00802 cur_line = cur_img[iClip3(0, maxold_y, y_pos + j)];
00803 blk_line = block[j];
00804 for (i = 0; i < hor_block_size; i++)
00805 {
00806 *(blk_line++) = cur_line[iClip3(0, maxold_x, x_pos + i )];
00807 }
00808 }
00809 }
00810 else if (dx == 0)
00811 {
00812 for (j = 0; j < ver_block_size; j++)
00813 {
00814 cur_line = cur_img[iClip3(0, maxold_y, y_pos + j)];
00815 cur_line_p1 = cur_img[iClip3(0, maxold_y, y_pos + j + 1)];
00816 tmp_pos = x_pos;
00817 blk_line = block[j];
00818
00819 for (i = 0; i < hor_block_size; i++)
00820 {
00821 ipos = iClip3(0, maxold_x, tmp_pos++);
00822
00823 result = (w00 * cur_line[ipos] + w01 * cur_line_p1[ipos]);
00824 *(blk_line++) = (imgpel) iClip1(max_imgpel_value, rshift_rnd_sf(result, total_scale));
00825 }
00826 }
00827 }
00828 else if (dy == 0)
00829 {
00830 for (j = 0; j < ver_block_size; j++)
00831 {
00832 cur_line = cur_img[iClip3(0, maxold_y, y_pos + j)];
00833 tmp_pos = x_pos;
00834 blk_line = block[j];
00835
00836 for (i = 0; i < hor_block_size; i++)
00837 {
00838 ipos = iClip3(0, maxold_x, tmp_pos++);
00839 ipos_p1 = iClip3(0, maxold_x, tmp_pos );
00840
00841 result = (w00 * cur_line[ipos ] + w10 * cur_line[ipos_p1]);
00842 *(blk_line++) = (imgpel)iClip1(max_imgpel_value, rshift_rnd_sf(result, total_scale));
00843 }
00844 }
00845 }
00846 else
00847 {
00848 for (j = 0; j < ver_block_size; j++)
00849 {
00850 cur_line = cur_img[iClip3(0, maxold_y, y_pos + j)];
00851 cur_line_p1 = cur_img[iClip3(0, maxold_y, y_pos + j + 1)];
00852 tmp_pos = x_pos;
00853 blk_line = block[j];
00854
00855 for (i = 0; i < hor_block_size; i++)
00856 {
00857 ipos = iClip3(0, maxold_x, tmp_pos++);
00858 ipos_p1 = iClip3(0, maxold_x, tmp_pos );
00859
00860 result = (
00861 w00 * cur_line [ipos ] +
00862 w10 * cur_line [ipos_p1] +
00863 w01 * cur_line_p1[ipos ] +
00864 w11 * cur_line_p1[ipos_p1]);
00865 *(blk_line++) = (imgpel) iClip1(max_imgpel_value, rshift_rnd_sf(result, total_scale));
00866 }
00867 }
00868 }
00869 }
00870 }
00871
00872 #if 0
00873 void intra_cr_decoding(Macroblock *currMB, int yuv, int smb)
00874 {
00875 ImageParameters *p_Img = currMB->p_Img;
00876 imgpel **curUV, *cur_img;
00877 int (*m7UV)[16], *m7;
00878 int uv;
00879 int b8,b4;
00880 int ioff, joff, ii, jj;
00881
00882 for(uv = 0; uv < 2; uv++)
00883 {
00884 Boolean lossless_qpprime = (Boolean) ((p_Img->lossless_qpprime_flag == 1) &&((p_Img->qp + dec_picture->chroma_qp_offset[uv] + p_Img->bitdepth_chroma_qp_scale) == 0));
00885 itrans_4x4 = (!lossless_qpprime) ? itrans4x4 : itrans4x4_ls;
00886
00887 curUV = dec_picture->imgUV[uv];
00888 m7UV = p_Img->currentSlice->mb_rres[uv+1];
00889 intrapred_chroma(currMB, uv);
00890
00891 if (!smb && (currMB->cbp >> 4))
00892 {
00893 for (b8 = 0; b8 < (p_Img->num_uv_blocks); b8++)
00894 {
00895 for(b4 = 0; b4 < 4; b4++)
00896 {
00897 joff = subblk_offset_y[yuv][b8][b4];
00898 ioff = subblk_offset_x[yuv][b8][b4];
00899
00900 itrans_4x4(p_Img, (ColorPlane) (uv + 1), ioff, joff);
00901
00902 for(jj=joff; jj<joff + 4;jj++)
00903 {
00904 cur_img = &curUV[currMB->pix_c_y + jj][currMB->pix_c_x + ioff];
00905 m7 = &m7UV[jj][ioff];
00906
00907 for(ii=0; ii<4;ii++)
00908 {
00909 *cur_img++ = (imgpel) *m7++;
00910 }
00911 }
00912 }
00913 }
00914 }
00915 else if ((currMB->cbp >> 4) == 0)
00916 {
00917 for (b8 = 0; b8 < (p_Img->num_uv_blocks); b8++)
00918 {
00919 for(b4 = 0; b4 < 4; b4++)
00920 {
00921 joff = subblk_offset_y[yuv][b8][b4];
00922 ioff = subblk_offset_x[yuv][b8][b4];
00923
00924 for(jj = joff; jj < 4 + joff;jj++)
00925 memcpy(&(curUV[currMB->pix_c_y + jj][currMB->pix_c_x + ioff]), &(p_Img->currentSlice->mb_pred[uv + 1][jj][ioff]), BLOCK_SIZE * sizeof(imgpel));
00926 }
00927 }
00928 }
00929 else
00930 {
00931 itrans_sp_cr(p_Img, uv);
00932
00933 for (joff = 0; joff < 8; joff += 4)
00934 {
00935 for(ioff = 0; ioff < 8;ioff+=4)
00936 {
00937 itrans_4x4(p_Img, (ColorPlane) (uv + 1), ioff, joff);
00938
00939 for(jj = joff; jj < joff + 4; jj++)
00940 for(ii = ioff; ii < ioff + 4; ii++)
00941 {
00942 curUV[currMB->pix_c_y+jj][ii + currMB->pix_c_x] = (imgpel) p_Img->currentSlice->mb_rres[uv+1][jj][ii];
00943 }
00944 }
00945 }
00946 }
00947 }
00948 }
00949
00950 void prepare_direct_params(Macroblock *currMB, StorablePicture *dec_picture, short pmvl0[2], short pmvl1[2],char *l0_rFrame, char *l1_rFrame)
00951 {
00952 ImageParameters *p_Img = currMB->p_Img;
00953 char l0_rFrameL, l0_rFrameU, l0_rFrameUR;
00954 char l1_rFrameL, l1_rFrameU, l1_rFrameUR;
00955 PicMotionParams *motion = &dec_picture->motion;
00956
00957 PixelPos mb[4];
00958
00959 get_neighbors(currMB, mb, 0, 0, 16);
00960
00961 if (!p_Img->MbaffFrameFlag)
00962 {
00963 l0_rFrameL = (char) (mb[0].available ? motion->ref_idx[LIST_0][mb[0].pos_y][mb[0].pos_x] : -1);
00964 l0_rFrameU = (char) (mb[1].available ? motion->ref_idx[LIST_0][mb[1].pos_y][mb[1].pos_x] : -1);
00965 l0_rFrameUR = (char) (mb[2].available ? motion->ref_idx[LIST_0][mb[2].pos_y][mb[2].pos_x] : -1);
00966
00967 l1_rFrameL = (char) (mb[0].available ? motion->ref_idx[LIST_1][mb[0].pos_y][mb[0].pos_x] : -1);
00968 l1_rFrameU = (char) (mb[1].available ? motion->ref_idx[LIST_1][mb[1].pos_y][mb[1].pos_x] : -1);
00969 l1_rFrameUR = (char) (mb[2].available ? motion->ref_idx[LIST_1][mb[2].pos_y][mb[2].pos_x] : -1);
00970 }
00971 else
00972 {
00973 if (currMB->mb_field)
00974 {
00975 l0_rFrameL = (char) (mb[0].available
00976 ? p_Img->mb_data[mb[0].mb_addr].mb_field || motion->ref_idx[LIST_0][mb[0].pos_y][mb[0].pos_x] < 0
00977 ? motion->ref_idx[LIST_0][mb[0].pos_y][mb[0].pos_x]
00978 : motion->ref_idx[LIST_0][mb[0].pos_y][mb[0].pos_x] * 2: -1);
00979
00980 l0_rFrameU = (char) (mb[1].available
00981 ? p_Img->mb_data[mb[1].mb_addr].mb_field || motion->ref_idx[LIST_0][mb[1].pos_y][mb[1].pos_x] < 0
00982 ? motion->ref_idx[LIST_0][mb[1].pos_y][mb[1].pos_x]
00983 : motion->ref_idx[LIST_0][mb[1].pos_y][mb[1].pos_x] * 2: -1);
00984
00985 l0_rFrameUR = (char) (mb[2].available
00986 ? p_Img->mb_data[mb[2].mb_addr].mb_field || motion->ref_idx[LIST_0][mb[2].pos_y][mb[2].pos_x] < 0
00987 ? motion->ref_idx[LIST_0][mb[2].pos_y][mb[2].pos_x]
00988 : motion->ref_idx[LIST_0][mb[2].pos_y][mb[2].pos_x] * 2: -1);
00989
00990 l1_rFrameL = (char) (mb[0].available
00991 ? p_Img->mb_data[mb[0].mb_addr].mb_field || motion->ref_idx[LIST_1][mb[0].pos_y][mb[0].pos_x] < 0
00992 ? motion->ref_idx[LIST_1][mb[0].pos_y][mb[0].pos_x]
00993 : motion->ref_idx[LIST_1][mb[0].pos_y][mb[0].pos_x] * 2: -1);
00994
00995 l1_rFrameU = (char) (mb[1].available
00996 ? p_Img->mb_data[mb[1].mb_addr].mb_field || motion->ref_idx[LIST_1][mb[1].pos_y][mb[1].pos_x] < 0
00997 ? motion->ref_idx[LIST_1][mb[1].pos_y][mb[1].pos_x]
00998 : motion->ref_idx[LIST_1][mb[1].pos_y][mb[1].pos_x] * 2: -1);
00999
01000 l1_rFrameUR = (char) (mb[2].available
01001 ? p_Img->mb_data[mb[2].mb_addr].mb_field || motion->ref_idx[LIST_1][mb[2].pos_y][mb[2].pos_x] < 0
01002 ? motion->ref_idx[LIST_1][mb[2].pos_y][mb[2].pos_x]
01003 : motion->ref_idx[LIST_1][mb[2].pos_y][mb[2].pos_x] * 2: -1);
01004 }
01005 else
01006 {
01007 l0_rFrameL = (char) (mb[0].available
01008 ? p_Img->mb_data[mb[0].mb_addr].mb_field || motion->ref_idx[LIST_0][mb[0].pos_y][mb[0].pos_x] < 0
01009 ? motion->ref_idx[LIST_0][mb[0].pos_y][mb[0].pos_x] >> 1
01010 : motion->ref_idx[LIST_0][mb[0].pos_y][mb[0].pos_x]: -1);
01011
01012 l0_rFrameU = (char) (mb[1].available
01013 ? p_Img->mb_data[mb[1].mb_addr].mb_field || motion->ref_idx[LIST_0][mb[1].pos_y][mb[1].pos_x] < 0
01014 ? motion->ref_idx[LIST_0][mb[1].pos_y][mb[1].pos_x] >> 1
01015 : motion->ref_idx[LIST_0][mb[1].pos_y][mb[1].pos_x] : -1);
01016
01017 l0_rFrameUR = (char) (mb[2].available
01018 ? p_Img->mb_data[mb[2].mb_addr].mb_field || motion->ref_idx[LIST_0][mb[2].pos_y][mb[2].pos_x] < 0
01019 ? motion->ref_idx[LIST_0][mb[2].pos_y][mb[2].pos_x] >> 1
01020 : motion->ref_idx[LIST_0][mb[2].pos_y][mb[2].pos_x] : -1);
01021
01022 l1_rFrameL = (char) (mb[0].available
01023 ? p_Img->mb_data[mb[0].mb_addr].mb_field || motion->ref_idx[LIST_1][mb[0].pos_y][mb[0].pos_x] < 0
01024 ? motion->ref_idx[LIST_1][mb[0].pos_y][mb[0].pos_x] >> 1
01025 : motion->ref_idx[LIST_1][mb[0].pos_y][mb[0].pos_x] : -1);
01026
01027 l1_rFrameU = (char) (mb[1].available
01028 ? p_Img->mb_data[mb[1].mb_addr].mb_field || motion->ref_idx[LIST_1][mb[1].pos_y][mb[1].pos_x] < 0
01029 ? motion->ref_idx[LIST_1][mb[1].pos_y][mb[1].pos_x] >> 1
01030 : motion->ref_idx[LIST_1][mb[1].pos_y][mb[1].pos_x] : -1);
01031
01032 l1_rFrameUR = (char) (mb[2].available
01033 ? p_Img->mb_data[mb[2].mb_addr].mb_field || motion->ref_idx[LIST_1][mb[2].pos_y][mb[2].pos_x] < 0
01034 ? motion->ref_idx[LIST_1][mb[2].pos_y][mb[2].pos_x] >> 1
01035 : motion->ref_idx[LIST_1][mb[2].pos_y][mb[2].pos_x] : -1);
01036 }
01037 }
01038
01039 *l0_rFrame = (char) ((l0_rFrameL >= 0 && l0_rFrameU >= 0) ? imin(l0_rFrameL,l0_rFrameU) : imax(l0_rFrameL,l0_rFrameU));
01040 *l0_rFrame = (char) ((*l0_rFrame >= 0 && l0_rFrameUR >= 0) ? imin(*l0_rFrame,l0_rFrameUR): imax(*l0_rFrame,l0_rFrameUR));
01041
01042 *l1_rFrame = (char) ((l1_rFrameL >= 0 && l1_rFrameU >= 0) ? imin(l1_rFrameL,l1_rFrameU) : imax(l1_rFrameL,l1_rFrameU));
01043 *l1_rFrame = (char) ((*l1_rFrame >= 0 && l1_rFrameUR >= 0) ? imin(*l1_rFrame,l1_rFrameUR): imax(*l1_rFrame,l1_rFrameUR));
01044
01045 if (*l0_rFrame >=0)
01046 currMB->GetMVPredictor(currMB, mb, pmvl0, *l0_rFrame, motion->ref_idx[LIST_0], motion->mv[LIST_0], 0, 0, 16, 16);
01047
01048 if (*l1_rFrame >=0)
01049 currMB->GetMVPredictor (currMB, mb, pmvl1, *l1_rFrame, motion->ref_idx[LIST_1], motion->mv[LIST_1], 0, 0, 16, 16);
01050 }
01051
01052
01053 void check_motion_vector_range(ImageParameters *p_Img, short mv_x, short mv_y)
01054 {
01055 if (mv_x > 8191 || mv_x < -8192)
01056 {
01057 fprintf(stderr,"ERROR! Horizontal motion vector %d is out of allowed range {-8192, 8191} in picture %d, macroblock %d\n", mv_x, p_Img->number, p_Img->current_mb_nr);
01058 error("invalid stream: too big horizontal motion vector", 500);
01059 }
01060
01061 if (mv_y > (p_Img->max_mb_vmv_r - 1) || mv_y < (-p_Img->max_mb_vmv_r))
01062 {
01063 fprintf(stderr,"ERROR! Vertical motion vector %d is out of allowed range {%d, %d} in picture %d, macroblock %d\n", mv_y, (-p_Img->max_mb_vmv_r), (p_Img->max_mb_vmv_r - 1), p_Img->number, p_Img->current_mb_nr);
01064 error("invalid stream: too big vertical motion vector", 500);
01065 }
01066 }
01067 #endif
01068
01069 void perform_mc(Macroblock* currMB, int decoder, ColorPlane pl, StorablePicture *dec_picture, int pred_dir, int l0_mode, int l1_mode, char*** ref_idx_buf, int i, int j, int block_size_x, int block_size_y, short bipred_me)
01070 {
01071 imgpel tmp_block_l0[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
01072 imgpel tmp_block_l1[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
01073
01074 Slice *currSlice = currMB->p_slice;
01075 ImageParameters *p_Img = currMB->p_Img;
01076
01077 int vec1_x=0, vec1_y=0;
01078 int vec2_x=0, vec2_y=0;
01079
01080 int alpha_l0, alpha_l1, wp_off;
01081 int max_imgpel_value = p_Img->max_pel_value_comp[pl];
01082 int apply_weights = ( (p_Img->active_pps->weighted_pred_flag && (currSlice->slice_type== P_SLICE || currSlice->slice_type == SP_SLICE)) ||
01083 (p_Img->active_pps->weighted_bipred_idc && (currSlice->slice_type== B_SLICE)));
01084 static const int mv_mul = 16;
01085
01086 int i4 = currMB->block_x + i;
01087 int j4 = currMB->block_y + j;
01088 int ioff = (i << 2);
01089 int joff = (j << 2);
01090
01091 assert (pred_dir<=2);
01092
01093 if (pred_dir != 2)
01094 {
01095
01096 short ref_idx = ref_idx_buf[pred_dir][j4][i4];
01097 short ref_idx_wp = ref_idx;
01098 short ***mv_array = currSlice->all_mv[pred_dir][ref_idx][l0_mode];
01099 StorablePicture **list = p_Img->listX[currMB->list_offset + pred_dir];
01100
01101 vec1_x = i4 * mv_mul + mv_array[j][i][0];
01102
01103 vec1_y = j4 * mv_mul + mv_array[j][i][1];
01104
01105 get_block_luma (currMB, decoder, pl, dec_picture, list[ref_idx], vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0);
01106
01107 if (apply_weights)
01108 {
01109 if (currMB->mb_field)
01110 {
01111 ref_idx_wp >>=1;
01112 }
01113 alpha_l0 = currSlice->wp_weight[pred_dir][ref_idx_wp][0];
01114 wp_off = currSlice->wp_offset[pred_dir][ref_idx_wp][0];
01115
01116 weighted_mc_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], block_size_y, block_size_x, ioff, tmp_block_l0, alpha_l0, wp_off, currSlice->luma_log_weight_denom, max_imgpel_value);
01117 }
01118 else
01119 {
01120 mc_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], block_size_y, block_size_x, ioff, tmp_block_l0);
01121 }
01122
01123 #if 0
01124 if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444) )
01125 {
01126 int uv;
01127
01128 int ioff_cr = (p_Img->mb_cr_size_x == MB_BLOCK_SIZE) ? ioff : ioff >> 1;
01129 int joff_cr = (p_Img->mb_cr_size_y == MB_BLOCK_SIZE) ? joff : joff >> 1;
01130 int block_size_x_cr = p_Img->mb_cr_size_x == MB_BLOCK_SIZE ? block_size_x : block_size_x >> 1;
01131 int block_size_y_cr = p_Img->mb_cr_size_y == MB_BLOCK_SIZE ? block_size_y : block_size_y >> 1;
01132
01133 vec1_y_cr = vec1_y + ((active_sps->chroma_format_idc == 1)? list[ref_idx]->chroma_vector_adjustment : 0);
01134
01135 for(uv=0;uv<2;uv++)
01136 {
01137 get_block_chroma (currMB, uv, list[ref_idx], vec1_x, vec1_y_cr, block_size_x_cr, block_size_y_cr, tmp_block_l0);
01138
01139 if (p_Img->apply_weights)
01140 {
01141 alpha_l0 = p_Img->wp_weight[pred_dir][ref_idx_wp][uv + 1];
01142 wp_offset = p_Img->wp_offset[pred_dir][ref_idx_wp][uv + 1];
01143
01144 weighted_mc_prediction(&currSlice->mb_pred[uv + 1][joff_cr], block_size_y_cr, block_size_x_cr, ioff_cr, tmp_block_l0, alpha_l0, wp_offset, p_Img->chroma_log2_weight_denom, p_Img->max_pel_value_comp[uv + 1]);
01145 }
01146 else
01147 {
01148 mc_prediction(&currSlice->mb_pred[uv + 1][joff_cr], block_size_y_cr, block_size_x_cr, ioff_cr, tmp_block_l0);
01149 }
01150 }
01151 }
01152 #endif
01153 }
01154 else
01155 {
01156
01157 short l0_ref = ref_idx_buf[LIST_0][j4][i4];
01158 short l1_ref = ref_idx_buf[LIST_1][j4][i4];
01159
01160 short ***l0_mv_array = (bipred_me ? currSlice->bipred_mv[bipred_me-1][LIST_0][l0_ref][l0_mode]:currSlice->all_mv[LIST_0][l0_ref][l0_mode]);
01161 short ***l1_mv_array = (bipred_me ? currSlice->bipred_mv[bipred_me-1][LIST_1][l1_ref][l1_mode]:currSlice->all_mv[LIST_1][l1_ref][l1_mode]);
01162
01163 vec1_x = i4 * mv_mul + l0_mv_array[j][i][0];
01164 vec2_x = i4 * mv_mul + l1_mv_array[j][i][0];
01165
01166 vec1_y = j4 * mv_mul + l0_mv_array[j][i][1];
01167 vec2_y = j4 * mv_mul + l1_mv_array[j][i][1];
01168
01169 get_block_luma (currMB, decoder, pl, dec_picture, p_Img->listX[LIST_0 + currMB->list_offset][l0_ref], vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0);
01170 get_block_luma (currMB, decoder, pl, dec_picture, p_Img->listX[LIST_1 + currMB->list_offset][l1_ref], vec2_x, vec2_y, block_size_x, block_size_y, tmp_block_l1);
01171
01172 if(apply_weights)
01173 {
01174 int wt_list_offset = (p_Img->active_pps->weighted_bipred_idc==2)? currMB->list_offset : 0;
01175
01176
01177
01178 if (currMB->mb_field)
01179 {
01180 l0_ref >>=1;
01181 l1_ref >>=1;
01182 }
01183
01184 alpha_l0 = currSlice->wbp_weight[LIST_0 + wt_list_offset][l0_ref][l1_ref][0];
01185 alpha_l1 = currSlice->wbp_weight[LIST_1 + wt_list_offset][l0_ref][l1_ref][0];
01186 wp_off = ((currSlice->wp_offset [LIST_0 + wt_list_offset][l0_ref][0] + currSlice->wp_offset[LIST_1 + wt_list_offset][l1_ref][0] + 1) >>1);
01187
01188 weighted_bi_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], tmp_block_l0, tmp_block_l1, block_size_y, block_size_x, ioff, alpha_l0, alpha_l1, wp_off, (currSlice->luma_log_weight_denom + 1), max_imgpel_value);
01189 }
01190 else
01191 {
01192 bi_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], tmp_block_l0, tmp_block_l1, block_size_y, block_size_x, ioff);
01193 }
01194 #if 0
01195 if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444) )
01196 {
01197 int uv;
01198
01199 int ioff_cr = p_Img->mb_cr_size_x == MB_BLOCK_SIZE ? ioff : ioff >> 1;
01200 int joff_cr = p_Img->mb_cr_size_y == MB_BLOCK_SIZE ? joff : joff >> 1;
01201 int block_size_x_cr = p_Img->mb_cr_size_x == MB_BLOCK_SIZE ? block_size_x : block_size_x >> 1;
01202 int block_size_y_cr = p_Img->mb_cr_size_y == MB_BLOCK_SIZE ? block_size_y : block_size_y >> 1;
01203
01204 vec1_y_cr = vec1_y + ((active_sps->chroma_format_idc == 1)? p_Img->listX[LIST_0 + list_offset][l0_refframe]->chroma_vector_adjustment : 0);
01205 vec2_y_cr = vec2_y + ((active_sps->chroma_format_idc == 1)? p_Img->listX[LIST_1 + list_offset][l1_refframe]->chroma_vector_adjustment : 0);
01206
01207 for(uv=0;uv<2;uv++)
01208 {
01209 get_block_chroma (currMB, uv, p_Img->listX[LIST_0 + list_offset][l0_refframe], vec1_x, vec1_y_cr, block_size_x_cr, block_size_y_cr, tmp_block_l0);
01210 get_block_chroma (currMB, uv, p_Img->listX[LIST_1 + list_offset][l1_refframe], vec2_x, vec2_y_cr, block_size_x_cr, block_size_y_cr, tmp_block_l1);
01211
01212 if(p_Img->apply_weights)
01213 {
01214 int wt_list_offset = (active_pps->weighted_bipred_idc==2)? list_offset : 0;
01215
01216 alpha_l0 = p_Img->wbp_weight[LIST_0 + wt_list_offset][l0_ref_idx][l1_ref_idx][uv + 1];
01217 alpha_l1 = p_Img->wbp_weight[LIST_1 + wt_list_offset][l0_ref_idx][l1_ref_idx][uv + 1];
01218 wp_offset = ((p_Img->wp_offset [LIST_0 + wt_list_offset][l0_ref_idx][uv + 1] + p_Img->wp_offset[LIST_1 + wt_list_offset][l1_ref_idx][uv + 1] + 1) >>1);
01219
01220 weighted_bi_prediction(&currSlice->mb_pred[uv+1][joff_cr], tmp_block_l0, tmp_block_l1, block_size_y_cr, block_size_x_cr, ioff_cr, alpha_l0, alpha_l1, wp_offset, (p_Img->chroma_log2_weight_denom + 1), p_Img->max_pel_value_comp[uv + 1]);
01221 }
01222 else
01223 {
01224 bi_prediction(&p_Img->currentSlice->mb_pred[uv + 1][joff_cr], tmp_block_l0, tmp_block_l1, block_size_y_cr, block_size_x_cr, ioff_cr);
01225 }
01226 }
01227 }
01228 #endif
01229 }
01230 }
01231
01232 void perform_mc_concealment(Macroblock* currMB, int decoder, ColorPlane pl, StorablePicture *dec_picture, int pred_dir, int l0_mode, int l1_mode, char*** ref_idx_buf, int i, int j, int block_size_x, int block_size_y)
01233 {
01234 imgpel tmp_block_l0[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
01235 imgpel tmp_block_l1[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
01236
01237 Slice *currSlice = currMB->p_slice;
01238 ImageParameters *p_Img = currMB->p_Img;
01239
01240 int vec1_x=0, vec1_y=0;
01241 int vec2_x=0, vec2_y=0;
01242
01243 int alpha_l0, alpha_l1, wp_off;
01244 int max_imgpel_value = p_Img->max_pel_value_comp[pl];
01245 int apply_weights = ( (p_Img->active_pps->weighted_pred_flag && (currSlice->slice_type == P_SLICE || currSlice->slice_type == SP_SLICE)) ||
01246 (p_Img->active_pps->weighted_bipred_idc && (currSlice->slice_type== B_SLICE)));
01247 static const int mv_mul = 16;
01248
01249 int i4 = currMB->block_x + i;
01250 int j4 = currMB->block_y + j;
01251 int ioff = (i << 2);
01252 int joff = (j << 2);
01253
01254 assert (pred_dir<=2);
01255
01256 if (pred_dir != 2)
01257 {
01258
01259 short ref_idx = ref_idx_buf[pred_dir][j4][i4];
01260 short ref_idx_wp = ref_idx;
01261 short ***mv_array = dec_picture->motion.mv[pred_dir];
01262 StorablePicture **list = p_Img->listX[currMB->list_offset + pred_dir];
01263
01264 vec1_x = i4 * mv_mul + mv_array[j4][i4][0];
01265
01266 vec1_y = j4 * mv_mul + mv_array[j4][i4][1];
01267
01268 get_block_luma (currMB, decoder, pl, dec_picture, list[ref_idx], vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0);
01269
01270 if (apply_weights)
01271 {
01272 if (currMB->mb_field)
01273 {
01274 ref_idx_wp >>=1;
01275 }
01276 alpha_l0 = p_Img->currentSlice->wp_weight[pred_dir][ref_idx_wp][0];
01277 wp_off = p_Img->currentSlice->wp_offset[pred_dir][ref_idx_wp][0];
01278
01279 weighted_mc_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], block_size_y, block_size_x, ioff, tmp_block_l0, alpha_l0, wp_off, p_Img->currentSlice->luma_log_weight_denom, max_imgpel_value);
01280 }
01281 else
01282 {
01283 mc_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], block_size_y, block_size_x, ioff, tmp_block_l0);
01284 }
01285 }
01286 else
01287 {
01288
01289 short l0_ref = ref_idx_buf[LIST_0][j4][i4];
01290 short l1_ref = ref_idx_buf[LIST_1][j4][i4];
01291
01292 short ***l0_mv_array = dec_picture->motion.mv[LIST_0];
01293 short ***l1_mv_array = dec_picture->motion.mv[LIST_1];
01294
01295 vec1_x = i4 * mv_mul + l0_mv_array[j4][i4][0];
01296 vec2_x = i4 * mv_mul + l1_mv_array[j4][i4][0];
01297
01298 vec1_y = j4 * mv_mul + l0_mv_array[j4][i4][1];
01299 vec2_y = j4 * mv_mul + l1_mv_array[j4][i4][1];
01300
01301 get_block_luma (currMB, decoder, pl, dec_picture, p_Img->listX[LIST_0 + currMB->list_offset][l0_ref], vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0);
01302 get_block_luma (currMB, decoder, pl, dec_picture, p_Img->listX[LIST_1 + currMB->list_offset][l1_ref], vec2_x, vec2_y, block_size_x, block_size_y, tmp_block_l1);
01303
01304 if(apply_weights)
01305 {
01306 int wt_list_offset = (p_Img->active_pps->weighted_bipred_idc==2)? currMB->list_offset : 0;
01307
01308
01309
01310 if (currMB->mb_field)
01311 {
01312 l0_ref >>=1;
01313 l1_ref >>=1;
01314 }
01315
01316 alpha_l0 = p_Img->currentSlice->wbp_weight[LIST_0 + wt_list_offset][l0_ref][l1_ref][0];
01317 alpha_l1 = p_Img->currentSlice->wbp_weight[LIST_1 + wt_list_offset][l0_ref][l1_ref][0];
01318 wp_off = ((p_Img->currentSlice->wp_offset [LIST_0 + wt_list_offset][l0_ref][0] + p_Img->currentSlice->wp_offset[LIST_1 + wt_list_offset][l1_ref][0] + 1) >>1);
01319
01320 weighted_bi_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], tmp_block_l0, tmp_block_l1, block_size_y, block_size_x, ioff, alpha_l0, alpha_l1, wp_off, (p_Img->currentSlice->luma_log_weight_denom + 1), max_imgpel_value);
01321 }
01322 else
01323 {
01324 bi_prediction(&p_Img->p_decs->dec_mb_pred[decoder][joff], tmp_block_l0, tmp_block_l1, block_size_y, block_size_x, ioff);
01325 }
01326 }
01327 }