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