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