00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <math.h>
00019 #include <limits.h>
00020
00021 #include "global.h"
00022
00023 #include "image.h"
00024 #include "mb_access.h"
00025 #include "elements.h"
00026 #include "vlc.h"
00027 #include "transform8x8.h"
00028 #include "transform.h"
00029 #include "macroblock.h"
00030 #include "symbol.h"
00031 #include "mc_prediction.h"
00032 #include "quant8x8.h"
00033 #include "rdoq.h"
00034 #include "q_matrix.h"
00035 #include "q_offsets.h"
00036 #include "rdopt.h"
00037
00038 static int diff64[64];
00039 extern imgpel ***rec8x8;
00040
00041
00042 const byte SNGL_SCAN8x8[64][2] = {
00043 {0,0}, {1,0}, {0,1}, {0,2}, {1,1}, {2,0}, {3,0}, {2,1},
00044 {1,2}, {0,3}, {0,4}, {1,3}, {2,2}, {3,1}, {4,0}, {5,0},
00045 {4,1}, {3,2}, {2,3}, {1,4}, {0,5}, {0,6}, {1,5}, {2,4},
00046 {3,3}, {4,2}, {5,1}, {6,0}, {7,0}, {6,1}, {5,2}, {4,3},
00047 {3,4}, {2,5}, {1,6}, {0,7}, {1,7}, {2,6}, {3,5}, {4,4},
00048 {5,3}, {6,2}, {7,1}, {7,2}, {6,3}, {5,4}, {4,5}, {3,6},
00049 {2,7}, {3,7}, {4,6}, {5,5}, {6,4}, {7,3}, {7,4}, {6,5},
00050 {5,6}, {4,7}, {5,7}, {6,6}, {7,5}, {7,6}, {6,7}, {7,7}
00051 };
00052
00053
00054
00055 const byte FIELD_SCAN8x8[64][2] = {
00056 {0,0}, {0,1}, {0,2}, {1,0}, {1,1}, {0,3}, {0,4}, {1,2},
00057 {2,0}, {1,3}, {0,5}, {0,6}, {0,7}, {1,4}, {2,1}, {3,0},
00058 {2,2}, {1,5}, {1,6}, {1,7}, {2,3}, {3,1}, {4,0}, {3,2},
00059 {2,4}, {2,5}, {2,6}, {2,7}, {3,3}, {4,1}, {5,0}, {4,2},
00060 {3,4}, {3,5}, {3,6}, {3,7}, {4,3}, {5,1}, {6,0}, {5,2},
00061 {4,4}, {4,5}, {4,6}, {4,7}, {5,3}, {6,1}, {6,2}, {5,4},
00062 {5,5}, {5,6}, {5,7}, {6,3}, {7,0}, {7,1}, {6,4}, {6,5},
00063 {6,6}, {6,7}, {7,2}, {7,3}, {7,4}, {7,5}, {7,6}, {7,7}
00064 };
00065
00066
00067
00068 static const byte COEFF_COST8x8[2][64] =
00069 {
00070 {3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,
00071 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
00072 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
00073 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00074 {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
00075 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
00076 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
00077 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}
00078 };
00079
00080 static int **levelscale = NULL, **leveloffset = NULL;
00081 static int **invlevelscale = NULL;
00082 static int **fadjust8x8 = NULL;
00083
00084
00085 #define P_Z (PredPel[0])
00086 #define P_A (PredPel[1])
00087 #define P_B (PredPel[2])
00088 #define P_C (PredPel[3])
00089 #define P_D (PredPel[4])
00090 #define P_E (PredPel[5])
00091 #define P_F (PredPel[6])
00092 #define P_G (PredPel[7])
00093 #define P_H (PredPel[8])
00094 #define P_I (PredPel[9])
00095 #define P_J (PredPel[10])
00096 #define P_K (PredPel[11])
00097 #define P_L (PredPel[12])
00098 #define P_M (PredPel[13])
00099 #define P_N (PredPel[14])
00100 #define P_O (PredPel[15])
00101 #define P_P (PredPel[16])
00102 #define P_Q (PredPel[17])
00103 #define P_R (PredPel[18])
00104 #define P_S (PredPel[19])
00105 #define P_T (PredPel[20])
00106 #define P_U (PredPel[21])
00107 #define P_V (PredPel[22])
00108 #define P_W (PredPel[23])
00109 #define P_X (PredPel[24])
00110
00111
00112
00113
00114
00115
00116
00117
00118 void copy_8x8block(imgpel **oblock, imgpel **iblock, int o_xoffset, int i_xoffset)
00119 {
00120 int y;
00121 for (y = 0; y < BLOCK_SIZE_8x8; y++)
00122 {
00123 memcpy(&oblock[y][o_xoffset],&iblock[y][i_xoffset], BLOCK_SIZE_8x8 * sizeof(imgpel));
00124 }
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 int Residual_DPCM_8x8(int ipmode, int **ores, int **rres,int block_y, int block_x)
00138 {
00139 int i,j;
00140 int temp[8][8];
00141
00142 if(ipmode==VERT_PRED)
00143 {
00144
00145 for (j=0; j<8; j++)
00146 temp[0][j] = ores[block_y][block_x+j];
00147
00148 for (i=1; i<8; i++)
00149 for (j=0; j<8; j++)
00150 temp[i][j] = ores[block_y+i][block_x+j] - ores[block_y+i-1][block_x+j];
00151
00152 for (i = 0; i < 8; i++)
00153 for (j = 0; j < 8; j++)
00154 rres[block_y+i][block_x+j] = temp[i][j];
00155 }
00156 else
00157 {
00158 for (i=0; i<8; i++)
00159 temp[i][0] = ores[block_y + i][block_x];
00160
00161 for (i=0; i<8; i++)
00162 for (j=1; j<8; j++)
00163 temp[i][j] = ores[block_y+i][block_x+j] - ores[block_y+i][block_x+j-1];
00164
00165 for (i=0; i<8; i++)
00166 for (j=0; j<8; j++)
00167 rres[block_y+i][block_x+j] = temp[i][j];
00168 }
00169 return 0;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 int Inv_Residual_DPCM_8x8(int **m7, int block_y, int block_x)
00183 {
00184 int i;
00185 int temp[8][8];
00186
00187 if(ipmode_DPCM==VERT_PRED)
00188 {
00189 for(i=0; i<8; i++)
00190 {
00191 temp[0][i] = m7[block_y+0][block_x+i];
00192 temp[1][i] = temp[0][i] + m7[block_y+1][block_x+i];
00193 temp[2][i] = temp[1][i] + m7[block_y+2][block_x+i];
00194 temp[3][i] = temp[2][i] + m7[block_y+3][block_x+i];
00195 temp[4][i] = temp[3][i] + m7[block_y+4][block_x+i];
00196 temp[5][i] = temp[4][i] + m7[block_y+5][block_x+i];
00197 temp[6][i] = temp[5][i] + m7[block_y+6][block_x+i];
00198 temp[7][i] = temp[6][i] + m7[block_y+7][block_x+i];
00199 }
00200 for(i=0; i<8; i++)
00201 {
00202 m7[block_y+1][block_x+i] = temp[1][i];
00203 m7[block_y+2][block_x+i] = temp[2][i];
00204 m7[block_y+3][block_x+i] = temp[3][i];
00205 m7[block_y+4][block_x+i] = temp[4][i];
00206 m7[block_y+5][block_x+i] = temp[5][i];
00207 m7[block_y+6][block_x+i] = temp[6][i];
00208 m7[block_y+7][block_x+i] = temp[7][i];
00209 }
00210 }
00211 else
00212 {
00213 for(i=0; i<8; i++)
00214 {
00215 temp[i][0] = m7[block_y+i][block_x+0];
00216 temp[i][1] = temp[i][0] + m7[block_y+i][block_x+1];
00217 temp[i][2] = temp[i][1] + m7[block_y+i][block_x+2];
00218 temp[i][3] = temp[i][2] + m7[block_y+i][block_x+3];
00219 temp[i][4] = temp[i][3] + m7[block_y+i][block_x+4];
00220 temp[i][5] = temp[i][4] + m7[block_y+i][block_x+5];
00221 temp[i][6] = temp[i][5] + m7[block_y+i][block_x+6];
00222 temp[i][7] = temp[i][6] + m7[block_y+i][block_x+7];
00223 }
00224 for(i=0; i<8; i++)
00225 {
00226 m7[block_y+i][block_x+1] = temp[i][1];
00227 m7[block_y+i][block_x+2] = temp[i][2];
00228 m7[block_y+i][block_x+3] = temp[i][3];
00229 m7[block_y+i][block_x+4] = temp[i][4];
00230 m7[block_y+i][block_x+5] = temp[i][5];
00231 m7[block_y+i][block_x+6] = temp[i][6];
00232 m7[block_y+i][block_x+7] = temp[i][7];
00233 }
00234 }
00235 return 0;
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245 int Mode_Decision_for_Intra8x8Macroblock (Slice *currSlice, Macroblock *currMB, double lambda, double *min_cost)
00246 {
00247 int cur_cbp = 0, b8;
00248 double cost8x8;
00249 int cr_cbp[3] = { 0, 0, 0};
00250
00251 *min_cost = (int)floor(6.0 * lambda + 0.4999);
00252
00253 if (img->P444_joined == 0)
00254 {
00255 for (b8=0; b8<4; b8++)
00256 {
00257 if (Mode_Decision_for_8x8IntraBlocks (currSlice, currMB, b8, lambda, &cost8x8, cr_cbp))
00258 {
00259 cur_cbp |= (1<<b8);
00260 }
00261 *min_cost += cost8x8;
00262 }
00263 }
00264 else
00265 {
00266 int k;
00267 cmp_cbp[1] = cmp_cbp[2] = 0;
00268
00269 for (b8=0; b8<4; b8++)
00270 {
00271 if (Mode_Decision_for_8x8IntraBlocks (currSlice, currMB, b8, lambda, &cost8x8, cr_cbp))
00272 {
00273 cur_cbp |= (1<<b8);
00274 }
00275 *min_cost += cost8x8;
00276
00277 for (k = 1; k < 3; k++)
00278 {
00279 if (cr_cbp[k])
00280 {
00281 cmp_cbp[k] |= (1<<b8);
00282 cur_cbp |= cmp_cbp[k];
00283 cmp_cbp[k] = cur_cbp;
00284 }
00285 }
00286 }
00287 }
00288
00289 return cur_cbp;
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299 int Mode_Decision_for_8x8IntraBlocks_JM_Low (Slice *currSlice, Macroblock *currMB, int b8, double lambda, double *min_cost, int cr_cbp[3])
00300 {
00301 int ipmode, best_ipmode = 0, i, j, dummy;
00302 double cost;
00303 int nonzero = 0;
00304 int block_x = (b8 & 0x01) << 3;
00305 int block_y = (b8 >> 1) << 3;
00306 int pic_pix_x = img->pix_x + block_x;
00307 int pic_pix_y = img->pix_y + block_y;
00308 int pic_opix_x = img->opix_x + block_x;
00309 int pic_opix_y = img->opix_y + block_y;
00310 int pic_block_x = pic_pix_x >> 2;
00311 int pic_block_y = pic_pix_y >> 2;
00312 imgpel *img_org, *img_prd;
00313 int *residual;
00314 int left_available, up_available, all_available;
00315 int **mb_ores = img->mb_ores[0];
00316 imgpel **mb_pred = img->mb_pred[0];
00317 int *mb_size = img->mb_size[IS_LUMA];
00318
00319 char upMode;
00320 char leftMode;
00321 int mostProbableMode;
00322
00323 PixelPos left_block;
00324 PixelPos top_block;
00325
00326 get4x4Neighbour(currMB, block_x - 1, block_y , mb_size, &left_block);
00327 get4x4Neighbour(currMB, block_x, block_y - 1, mb_size, &top_block );
00328
00329 if (params->UseConstrainedIntraPred)
00330 {
00331 top_block.available = top_block.available ? img->intra_block [top_block.mb_addr] : 0;
00332 left_block.available = left_block.available ? img->intra_block [left_block.mb_addr] : 0;
00333 }
00334
00335 if(b8 >> 1)
00336 upMode = top_block.available ? img->ipredmode8x8[top_block.pos_y ][top_block.pos_x ] : -1;
00337 else
00338 upMode = top_block.available ? img->ipredmode [top_block.pos_y ][top_block.pos_x ] : -1;
00339 if(b8 & 0x01)
00340 leftMode = left_block.available ? img->ipredmode8x8[left_block.pos_y][left_block.pos_x] : -1;
00341 else
00342 leftMode = left_block.available ? img->ipredmode[left_block.pos_y][left_block.pos_x] : -1;
00343
00344 mostProbableMode = (upMode < 0 || leftMode < 0) ? DC_PRED : upMode < leftMode ? upMode : leftMode;
00345
00346 *min_cost = INT_MAX;
00347
00348 ipmode_DPCM = NO_INTRA_PMODE;
00349
00350
00351 intrapred_8x8 (currMB, PLANE_Y, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
00352
00353 if(img->P444_joined)
00354 {
00355 select_plane(PLANE_U);
00356 intrapred_8x8(currMB, PLANE_U, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
00357 select_plane(PLANE_V);
00358 intrapred_8x8(currMB, PLANE_V, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
00359 select_plane(PLANE_Y);
00360 }
00361
00362
00363 for (ipmode = 0; ipmode < NO_INTRA_PMODE; ipmode++)
00364 {
00365 if( (ipmode==DC_PRED) ||
00366 ((ipmode==VERT_PRED||ipmode==VERT_LEFT_PRED||ipmode==DIAG_DOWN_LEFT_PRED) && up_available ) ||
00367 ((ipmode==HOR_PRED||ipmode==HOR_UP_PRED) && left_available ) ||
00368 (all_available) )
00369 {
00370 cost = (ipmode == mostProbableMode) ? 0 : (int)floor(4 * lambda );
00371 compute_comp_cost8x8(&pImgOrg[0][pic_opix_y], img->mpr_8x8[0][ipmode], pic_opix_x, &cost);
00372
00373 if(img->P444_joined)
00374 {
00375 int m;
00376 for (m = PLANE_U; m <= PLANE_V; m++)
00377 compute_comp_cost8x8(&pImgOrg[m][pic_opix_y], img->mpr_8x8[m][ipmode], pic_opix_x, &cost);
00378 }
00379
00380 if (cost < *min_cost)
00381 {
00382 best_ipmode = ipmode;
00383 *min_cost = cost;
00384 }
00385 }
00386 }
00387
00388
00389 img->ipredmode8x8[pic_block_y][pic_block_x] = (char) best_ipmode;
00390 ipmode_DPCM = best_ipmode;
00391
00392 if(img->P444_joined)
00393 {
00394 ColorPlane k;
00395 CbCr_predmode_8x8[b8] = best_ipmode;
00396 for (k = PLANE_U; k <= PLANE_V; k++)
00397 {
00398 cr_cbp[k] = 0;
00399 select_plane(k);
00400 for (j=0; j<8; j++)
00401 {
00402 for (i=0; i<8; i++)
00403 {
00404 img->mb_pred[k][block_y+j][block_x+i] = img->mpr_8x8[k][best_ipmode][j][i];
00405 img->mb_ores[k][block_y+j][block_x+i] = pImgOrg[k][img->pix_y+block_y+j][img->pix_x+block_x+i] - img->mpr_8x8[k][best_ipmode][j][i];
00406 }
00407 }
00408 ipmode_DPCM=best_ipmode;
00409
00410 if (pDCT_8x8(currMB, k, b8, &dummy, 1))
00411 cr_cbp[k] = 1;
00412 }
00413 select_plane(PLANE_Y);
00414 }
00415
00416 currMB->intra_pred_modes8x8[4*b8] = (mostProbableMode == best_ipmode)
00417 ? -1
00418 : (best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1);
00419
00420 for(j = img->mb_y*4+(b8 >> 1)*2; j < img->mb_y*4+(b8 >> 1)*2 + 2; j++)
00421 memset(&img->ipredmode8x8[j][img->mb_x*4+(b8 & 0x01)*2], best_ipmode, 2 * sizeof(char));
00422
00423
00424 for (j = block_y; j < block_y + 8; j++)
00425 {
00426 memcpy(&mb_pred[j][block_x],img->mpr_8x8[0][best_ipmode][j - block_y], 8 * sizeof(imgpel));
00427 img_org = &pCurImg[img->opix_y+j][pic_opix_x];
00428 img_prd = &mb_pred[j][block_x];
00429 residual = &mb_ores[j][block_x];
00430 for (i=0; i<8; i++)
00431 {
00432 *residual++ = *img_org++ - *img_prd++;
00433 }
00434 }
00435
00436 ipmode_DPCM = best_ipmode;
00437 nonzero = pDCT_8x8 (currMB, PLANE_Y, b8, &dummy, 1);
00438 return nonzero;
00439 }
00440
00441
00442
00443
00444
00445
00446
00447
00448 int Mode_Decision_for_8x8IntraBlocks_JM_High (Slice *currSlice, Macroblock *currMB, int b8, double lambda, double *min_cost, int cr_cbp[3])
00449 {
00450 int ipmode, best_ipmode = 0, i, j, k, dummy;
00451 int c_nz, nonzero = 0;
00452 double rdcost = 0.0;
00453 int block_x = (b8 & 0x01) << 3;
00454 int block_y = (b8 >> 1) << 3;
00455 int pic_pix_x = img->pix_x + block_x;
00456 int pic_pix_y = img->pix_y + block_y;
00457 int pic_opix_x = img->opix_x + block_x;
00458 int pic_opix_y = img->opix_y + block_y;
00459 int pic_block_x = pic_pix_x >> 2;
00460 int pic_block_y = pic_pix_y >> 2;
00461 double min_rdcost = 1e30;
00462 imgpel *img_org, *img_prd;
00463 int *residual;
00464 int uv, c_nzCbCr[3];
00465 int left_available, up_available, all_available;
00466 int **mb_ores = img->mb_ores[0];
00467 imgpel **mb_pred = img->mb_pred[0];
00468 int *mb_size = img->mb_size[IS_LUMA];
00469
00470 char upMode;
00471 char leftMode;
00472 int mostProbableMode;
00473
00474 PixelPos left_block, top_block;
00475
00476 get4x4Neighbour(currMB, block_x - 1, block_y , mb_size, &left_block);
00477 get4x4Neighbour(currMB, block_x, block_y - 1, mb_size, &top_block );
00478
00479 if (params->UseConstrainedIntraPred)
00480 {
00481 top_block.available = top_block.available ? img->intra_block [top_block.mb_addr] : 0;
00482 left_block.available = left_block.available ? img->intra_block [left_block.mb_addr] : 0;
00483 }
00484
00485 if(b8 >> 1)
00486 upMode = top_block.available ? img->ipredmode8x8[top_block.pos_y ][top_block.pos_x ] : -1;
00487 else
00488 upMode = top_block.available ? img->ipredmode [top_block.pos_y ][top_block.pos_x ] : -1;
00489
00490 if(b8 & 0x01)
00491 leftMode = left_block.available ? img->ipredmode8x8[left_block.pos_y][left_block.pos_x] : -1;
00492 else
00493 leftMode = left_block.available ? img->ipredmode[left_block.pos_y][left_block.pos_x] : -1;
00494
00495 mostProbableMode = (upMode < 0 || leftMode < 0) ? DC_PRED : upMode < leftMode ? upMode : leftMode;
00496
00497 *min_cost = INT_MAX;
00498
00499 ipmode_DPCM = NO_INTRA_PMODE;
00500
00501
00502 intrapred_8x8 (currMB, PLANE_Y, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
00503
00504 if(img->P444_joined)
00505 {
00506 select_plane(PLANE_U);
00507 intrapred_8x8(currMB, PLANE_U, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
00508 select_plane(PLANE_V);
00509 intrapred_8x8(currMB, PLANE_V, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
00510 select_plane(PLANE_Y);
00511 }
00512
00513
00514 for (ipmode = 0; ipmode < NO_INTRA_PMODE; ipmode++)
00515 {
00516 if( (ipmode==DC_PRED) ||
00517 ((ipmode==VERT_PRED||ipmode==VERT_LEFT_PRED||ipmode==DIAG_DOWN_LEFT_PRED) && up_available ) ||
00518 ((ipmode==HOR_PRED||ipmode==HOR_UP_PRED) && left_available ) ||
00519 (all_available) )
00520 {
00521
00522 for (j=block_y; j < block_y + 8; j++)
00523 {
00524 memcpy(&mb_pred[j][block_x],img->mpr_8x8[0][ipmode][j - block_y], 8 * sizeof(imgpel));
00525 img_org = &pCurImg[img->opix_y+j][pic_opix_x];
00526 img_prd = &mb_pred[j][block_x];
00527 residual = &mb_ores[j][block_x];
00528 for (i=0; i<8; i++)
00529 {
00530 *residual++ = *img_org++ - *img_prd++;
00531 }
00532 }
00533
00534 if(img->P444_joined)
00535 {
00536 for (k = PLANE_U; k <= PLANE_V; k++)
00537 {
00538 for (j=0; j<8; j++)
00539 {
00540 memcpy(&img->mb_pred[k][block_y+j][block_x],img->mpr_8x8[k][ipmode][j], 8 * sizeof(imgpel));
00541 for (i=0; i<8; i++)
00542 {
00543 img->mb_ores[k][block_y+j][block_x+i] = (int) (pImgOrg[k][pic_opix_y+j][pic_opix_x+i] - img->mpr_8x8[k][ipmode][j][i]);
00544
00545 }
00546 }
00547 }
00548 }
00549
00550 ipmode_DPCM=ipmode;
00551
00552
00553
00554
00555
00556 if ((rdcost = RDCost_for_8x8IntraBlocks (currSlice, currMB, &c_nz, b8, ipmode, lambda, min_rdcost, mostProbableMode, c_nzCbCr)) < min_rdcost)
00557 {
00558
00559 memcpy(coefAC8x8[b8][0][0][0],img->cofAC[b8][0][0], 4 * 2 * 65 * sizeof(int));
00560
00561
00562
00563 copy_8x8block(rec8x8[PLANE_Y], &enc_picture->imgY[pic_pix_y], 0, pic_pix_x);
00564
00565 if (img->AdaptiveRounding)
00566 {
00567 for (j = block_y; j < block_y + 8; j++)
00568 memcpy(&img->ARCofAdj8x8[0][DUMMY][j][block_x],&img->ARCofAdj8x8[0][I8MB][j][block_x], 8 * sizeof(int));
00569
00570 if (img->P444_joined)
00571 {
00572 for (j = block_y; j < block_y + 8; j++)
00573 {
00574 memcpy(&img->ARCofAdj8x8[1][DUMMY][j][block_x],&img->ARCofAdj8x8[1][I8MB][j][block_x], 8 * sizeof(int));
00575 memcpy(&img->ARCofAdj8x8[2][DUMMY][j][block_x],&img->ARCofAdj8x8[2][I8MB][j][block_x], 8 * sizeof(int));
00576 }
00577 }
00578 }
00579
00580 if (img->P444_joined)
00581 {
00582
00583 for (uv=0; uv < 2; uv++)
00584 {
00585 memcpy(coefAC8x8[b8][uv + 1][0][0],img->cofAC[4+b8+4*uv][0][0], 2 * 4 * 65 * sizeof(int));
00586
00587 cr_cbp[uv + 1] = c_nzCbCr[uv + 1];
00588
00589 copy_8x8block(rec8x8[uv + 1], &enc_picture->imgUV[uv][pic_pix_y], 0, pic_pix_x);
00590 }
00591 }
00592
00593
00594 nonzero = c_nz;
00595
00596
00597 *min_cost = rdcost;
00598 min_rdcost = rdcost;
00599 best_ipmode = ipmode;
00600 }
00601 reset_coding_state_cs_cm(currSlice, currMB);
00602 }
00603 }
00604
00605
00606 img->ipredmode8x8[pic_block_y][pic_block_x] = (char) best_ipmode;
00607 ipmode_DPCM = best_ipmode;
00608
00609 if(img->P444_joined)
00610 {
00611 ColorPlane k;
00612 CbCr_predmode_8x8[b8] = best_ipmode;
00613 for (k = PLANE_U; k <= PLANE_V; k++)
00614 {
00615 cr_cbp[k] = 0;
00616 select_plane(k);
00617 for (j=0; j<8; j++)
00618 {
00619 for (i=0; i<8; i++)
00620 {
00621 img->mb_pred[k][block_y+j][block_x+i] = img->mpr_8x8[k][best_ipmode][j][i];
00622 img->mb_ores[k][block_y+j][block_x+i] = pImgOrg[k][img->pix_y+block_y+j][img->pix_x+block_x+i] - img->mpr_8x8[k][best_ipmode][j][i];
00623 }
00624 }
00625 ipmode_DPCM = best_ipmode;
00626
00627 if (pDCT_8x8(currMB, k, b8, &dummy, 1))
00628 cr_cbp[k] = 1;
00629 }
00630 select_plane(PLANE_Y);
00631 }
00632
00633 currMB->intra_pred_modes8x8[4*b8] = (mostProbableMode == best_ipmode)
00634 ? -1
00635 : (best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1);
00636
00637 for(j = img->mb_y*4+(b8 >> 1)*2; j < img->mb_y*4+(b8 >> 1)*2 + 2; j++)
00638 memset(&img->ipredmode8x8[j][img->mb_x*4+(b8 & 0x01)*2], best_ipmode, 2 * sizeof(char));
00639
00640
00641 memcpy(img->cofAC[b8][0][0],coefAC8x8[b8][0][0][0], 4 * 2 * 65 * sizeof(int));
00642
00643
00644 if (img->AdaptiveRounding)
00645 {
00646 for (j=block_y; j< block_y + 8; j++)
00647 memcpy(&img->ARCofAdj8x8[0][I8MB][j][block_x], &img->ARCofAdj8x8[0][DUMMY][j][block_x], 8 * sizeof(int));
00648
00649 if (img->P444_joined)
00650 {
00651 for (j=0; j<8; j++)
00652 {
00653 memcpy(&img->ARCofAdj8x8[1][I8MB][block_y + j][block_x], &img->ARCofAdj8x8[1][DUMMY][block_y + j][block_x], 8 * sizeof(int));
00654 memcpy(&img->ARCofAdj8x8[2][I8MB][block_y + j][block_x], &img->ARCofAdj8x8[2][DUMMY][block_y + j][block_x], 8 * sizeof(int));
00655 }
00656 }
00657 }
00658
00659
00660 copy_8x8block(&enc_picture->imgY[pic_pix_y], rec8x8[0], pic_pix_x, 0);
00661 copy_8x8block(&mb_pred[block_y], img->mpr_8x8[0][best_ipmode], block_x, 0);
00662
00663 if (img->P444_joined)
00664 {
00665
00666 memcpy(img->cofAC[4+b8+4*0][0][0], coefAC8x8[b8][1][0][0], 4 * 2 * 65 * sizeof(int));
00667 memcpy(img->cofAC[4+b8+4*1][0][0], coefAC8x8[b8][2][0][0], 4 * 2 * 65 * sizeof(int));
00668
00669
00670 copy_8x8block(&enc_picture->imgUV[0][pic_pix_y], rec8x8[1], pic_pix_x, 0);
00671 copy_8x8block(&enc_picture->imgUV[1][pic_pix_y], rec8x8[2], pic_pix_x, 0);
00672 copy_8x8block(&img->mb_pred[1][block_y], img->mpr_8x8[1][best_ipmode], block_x, 0);
00673 copy_8x8block(&img->mb_pred[2][block_y], img->mpr_8x8[2][best_ipmode], block_x, 0);
00674 }
00675
00676 return nonzero;
00677 }
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693 static inline void get_diag_down_left(imgpel **cur_pred, imgpel *PredPel)
00694 {
00695 cur_pred[0][0] = (imgpel) ((P_A + P_C + (P_B << 1) + 2) >> 2);
00696 cur_pred[0][1] =
00697 cur_pred[1][0] = (imgpel) ((P_B + P_D + (P_C << 1) + 2) >> 2);
00698 cur_pred[0][2] =
00699 cur_pred[1][1] =
00700 cur_pred[2][0] = (imgpel) ((P_C + P_E + (P_D << 1) + 2) >> 2);
00701 cur_pred[0][3] =
00702 cur_pred[1][2] =
00703 cur_pred[2][1] =
00704 cur_pred[3][0] = (imgpel) ((P_D + P_F + (P_E << 1) + 2) >> 2);
00705 cur_pred[0][4] =
00706 cur_pred[1][3] =
00707 cur_pred[2][2] =
00708 cur_pred[3][1] =
00709 cur_pred[4][0] = (imgpel) ((P_E + P_G + (P_F << 1) + 2) >> 2);
00710 cur_pred[0][5] =
00711 cur_pred[1][4] =
00712 cur_pred[2][3] =
00713 cur_pred[3][2] =
00714 cur_pred[4][1] =
00715 cur_pred[5][0] = (imgpel) ((P_F + P_H + (P_G << 1) + 2) >> 2);
00716 cur_pred[0][6] =
00717 cur_pred[1][5] =
00718 cur_pred[2][4] =
00719 cur_pred[3][3] =
00720 cur_pred[4][2] =
00721 cur_pred[5][1] =
00722 cur_pred[6][0] = (imgpel) ((P_G + P_I + (P_H << 1) + 2) >> 2);
00723 cur_pred[0][7] =
00724 cur_pred[1][6] =
00725 cur_pred[2][5] =
00726 cur_pred[3][4] =
00727 cur_pred[4][3] =
00728 cur_pred[5][2] =
00729 cur_pred[6][1] =
00730 cur_pred[7][0] = (imgpel) ((P_H + P_J + (P_I << 1) + 2) >> 2);
00731 cur_pred[1][7] =
00732 cur_pred[2][6] =
00733 cur_pred[3][5] =
00734 cur_pred[4][4] =
00735 cur_pred[5][3] =
00736 cur_pred[6][2] =
00737 cur_pred[7][1] = (imgpel) ((P_I + P_K + (P_J << 1) + 2) >> 2);
00738 cur_pred[2][7] =
00739 cur_pred[3][6] =
00740 cur_pred[4][5] =
00741 cur_pred[5][4] =
00742 cur_pred[6][3] =
00743 cur_pred[7][2] = (imgpel) ((P_J + P_L + (P_K << 1) + 2) >> 2);
00744 cur_pred[3][7] =
00745 cur_pred[4][6] =
00746 cur_pred[5][5] =
00747 cur_pred[6][4] =
00748 cur_pred[7][3] = (imgpel) ((P_K + P_M + (P_L << 1) + 2) >> 2);
00749 cur_pred[4][7] =
00750 cur_pred[5][6] =
00751 cur_pred[6][5] =
00752 cur_pred[7][4] = (imgpel) ((P_L + P_N + (P_M << 1) + 2) >> 2);
00753 cur_pred[5][7] =
00754 cur_pred[6][6] =
00755 cur_pred[7][5] = (imgpel) ((P_M + P_O + (P_N << 1) + 2) >> 2);
00756 cur_pred[6][7] =
00757 cur_pred[7][6] = (imgpel) ((P_N + P_P + (P_O << 1) + 2) >> 2);
00758 cur_pred[7][7] = (imgpel) ((P_O + P_P + (P_P << 1) + 2) >> 2);
00759 }
00760
00761 static inline void get_vert_left(imgpel **cur_pred, imgpel *PredPel)
00762 {
00763 cur_pred[0][0] = (imgpel) ((P_A + P_B + 1) >> 1);
00764 cur_pred[0][1] =
00765 cur_pred[2][0] = (imgpel) ((P_B + P_C + 1) >> 1);
00766 cur_pred[0][2] =
00767 cur_pred[2][1] =
00768 cur_pred[4][0] = (imgpel) ((P_C + P_D + 1) >> 1);
00769 cur_pred[0][3] =
00770 cur_pred[2][2] =
00771 cur_pred[4][1] =
00772 cur_pred[6][0] = (imgpel) ((P_D + P_E + 1) >> 1);
00773 cur_pred[0][4] =
00774 cur_pred[2][3] =
00775 cur_pred[4][2] =
00776 cur_pred[6][1] = (imgpel) ((P_E + P_F + 1) >> 1);
00777 cur_pred[0][5] =
00778 cur_pred[2][4] =
00779 cur_pred[4][3] =
00780 cur_pred[6][2] = (imgpel) ((P_F + P_G + 1) >> 1);
00781 cur_pred[0][6] =
00782 cur_pred[2][5] =
00783 cur_pred[4][4] =
00784 cur_pred[6][3] = (imgpel) ((P_G + P_H + 1) >> 1);
00785 cur_pred[0][7] =
00786 cur_pred[2][6] =
00787 cur_pred[4][5] =
00788 cur_pred[6][4] = (imgpel) ((P_H + P_I + 1) >> 1);
00789 cur_pred[2][7] =
00790 cur_pred[4][6] =
00791 cur_pred[6][5] = (imgpel) ((P_I + P_J + 1) >> 1);
00792 cur_pred[4][7] =
00793 cur_pred[6][6] = (imgpel) ((P_J + P_K + 1) >> 1);
00794 cur_pred[6][7] = (imgpel) ((P_K + P_L + 1) >> 1);
00795 cur_pred[1][0] = (imgpel) ((P_A + P_C + 2*P_B + 2) >> 2);
00796 cur_pred[1][1] =
00797 cur_pred[3][0] = (imgpel) ((P_B + P_D + 2*P_C + 2) >> 2);
00798 cur_pred[1][2] =
00799 cur_pred[3][1] =
00800 cur_pred[5][0] = (imgpel) ((P_C + P_E + 2*P_D + 2) >> 2);
00801 cur_pred[1][3] =
00802 cur_pred[3][2] =
00803 cur_pred[5][1] =
00804 cur_pred[7][0] = (imgpel) ((P_D + P_F + 2*P_E + 2) >> 2);
00805 cur_pred[1][4] =
00806 cur_pred[3][3] =
00807 cur_pred[5][2] =
00808 cur_pred[7][1] = (imgpel) ((P_E + P_G + 2*P_F + 2) >> 2);
00809 cur_pred[1][5] =
00810 cur_pred[3][4] =
00811 cur_pred[5][3] =
00812 cur_pred[7][2] = (imgpel) ((P_F + P_H + 2*P_G + 2) >> 2);
00813 cur_pred[1][6] =
00814 cur_pred[3][5] =
00815 cur_pred[5][4] =
00816 cur_pred[7][3] = (imgpel) ((P_G + P_I + 2*P_H + 2) >> 2);
00817 cur_pred[1][7] =
00818 cur_pred[3][6] =
00819 cur_pred[5][5] =
00820 cur_pred[7][4] = (imgpel) ((P_H + P_J + 2*P_I + 2) >> 2);
00821 cur_pred[3][7] =
00822 cur_pred[5][6] =
00823 cur_pred[7][5] = (imgpel) ((P_I + P_K + 2*P_J + 2) >> 2);
00824 cur_pred[5][7] =
00825 cur_pred[7][6] = (imgpel) ((P_J + P_L + 2*P_K + 2) >> 2);
00826 cur_pred[7][7] = (imgpel) ((P_K + P_M + 2*P_L + 2) >> 2);
00827 }
00828
00829 static inline void get_diag_down_right(imgpel **cur_pred, imgpel *PredPel)
00830 {
00831 cur_pred[7][0] = (imgpel) ((P_X + P_V + (P_W << 1) + 2) >> 2);
00832 cur_pred[6][0] =
00833 cur_pred[7][1] = (imgpel) ((P_W + P_U + (P_V << 1) + 2) >> 2);
00834 cur_pred[5][0] =
00835 cur_pred[6][1] =
00836 cur_pred[7][2] = (imgpel) ((P_V + P_T + (P_U << 1) + 2) >> 2);
00837 cur_pred[4][0] =
00838 cur_pred[5][1] =
00839 cur_pred[6][2] =
00840 cur_pred[7][3] = (imgpel) ((P_U + P_S + (P_T << 1) + 2) >> 2);
00841 cur_pred[3][0] =
00842 cur_pred[4][1] =
00843 cur_pred[5][2] =
00844 cur_pred[6][3] =
00845 cur_pred[7][4] = (imgpel) ((P_T + P_R + (P_S << 1) + 2) >> 2);
00846 cur_pred[2][0] =
00847 cur_pred[3][1] =
00848 cur_pred[4][2] =
00849 cur_pred[5][3] =
00850 cur_pred[6][4] =
00851 cur_pred[7][5] = (imgpel) ((P_S + P_Q + (P_R << 1) + 2) >> 2);
00852 cur_pred[1][0] =
00853 cur_pred[2][1] =
00854 cur_pred[3][2] =
00855 cur_pred[4][3] =
00856 cur_pred[5][4] =
00857 cur_pred[6][5] =
00858 cur_pred[7][6] = (imgpel) ((P_R + P_Z + (P_Q << 1) + 2) >> 2);
00859 cur_pred[0][0] =
00860 cur_pred[1][1] =
00861 cur_pred[2][2] =
00862 cur_pred[3][3] =
00863 cur_pred[4][4] =
00864 cur_pred[5][5] =
00865 cur_pred[6][6] =
00866 cur_pred[7][7] = (imgpel) ((P_Q + P_A + (P_Z << 1) + 2) >> 2);
00867 cur_pred[0][1] =
00868 cur_pred[1][2] =
00869 cur_pred[2][3] =
00870 cur_pred[3][4] =
00871 cur_pred[4][5] =
00872 cur_pred[5][6] =
00873 cur_pred[6][7] = (imgpel) ((P_Z + P_B + (P_A << 1) + 2) >> 2);
00874 cur_pred[0][2] =
00875 cur_pred[1][3] =
00876 cur_pred[2][4] =
00877 cur_pred[3][5] =
00878 cur_pred[4][6] =
00879 cur_pred[5][7] = (imgpel) ((P_A + P_C + (P_B << 1) + 2) >> 2);
00880 cur_pred[0][3] =
00881 cur_pred[1][4] =
00882 cur_pred[2][5] =
00883 cur_pred[3][6] =
00884 cur_pred[4][7] = (imgpel) ((P_B + P_D + (P_C << 1) + 2) >> 2);
00885 cur_pred[0][4] =
00886 cur_pred[1][5] =
00887 cur_pred[2][6] =
00888 cur_pred[3][7] = (imgpel) ((P_C + P_E + (P_D << 1) + 2) >> 2);
00889 cur_pred[0][5] =
00890 cur_pred[1][6] =
00891 cur_pred[2][7] = (imgpel) ((P_D + P_F + (P_E << 1) + 2) >> 2);
00892 cur_pred[0][6] =
00893 cur_pred[1][7] = (imgpel) ((P_E + P_G + (P_F << 1) + 2) >> 2);
00894 cur_pred[0][7] = (imgpel) ((P_F + P_H + (P_G << 1) + 2) >> 2);
00895 }
00896
00897 static inline void get_vert_right(imgpel **cur_pred, imgpel *PredPel)
00898 {
00899 cur_pred[0][0] =
00900 cur_pred[2][1] =
00901 cur_pred[4][2] =
00902 cur_pred[6][3] = (imgpel) ((P_Z + P_A + 1) >> 1);
00903 cur_pred[0][1] =
00904 cur_pred[2][2] =
00905 cur_pred[4][3] =
00906 cur_pred[6][4] = (imgpel) ((P_A + P_B + 1) >> 1);
00907 cur_pred[0][2] =
00908 cur_pred[2][3] =
00909 cur_pred[4][4] =
00910 cur_pred[6][5] = (imgpel) ((P_B + P_C + 1) >> 1);
00911 cur_pred[0][3] =
00912 cur_pred[2][4] =
00913 cur_pred[4][5] =
00914 cur_pred[6][6] = (imgpel) ((P_C + P_D + 1) >> 1);
00915 cur_pred[0][4] =
00916 cur_pred[2][5] =
00917 cur_pred[4][6] =
00918 cur_pred[6][7] = (imgpel) ((P_D + P_E + 1) >> 1);
00919 cur_pred[0][5] =
00920 cur_pred[2][6] =
00921 cur_pred[4][7] = (imgpel) ((P_E + P_F + 1) >> 1);
00922 cur_pred[0][6] =
00923 cur_pred[2][7] = (imgpel) ((P_F + P_G + 1) >> 1);
00924 cur_pred[0][7] = (imgpel) ((P_G + P_H + 1) >> 1);
00925 cur_pred[1][0] =
00926 cur_pred[3][1] =
00927 cur_pred[5][2] =
00928 cur_pred[7][3] = (imgpel) ((P_Q + P_A + (P_Z << 1) + 2) >> 2);
00929 cur_pred[1][1] =
00930 cur_pred[3][2] =
00931 cur_pred[5][3] =
00932 cur_pred[7][4] = (imgpel) ((P_Z + P_B + (P_A << 1) + 2) >> 2);
00933 cur_pred[1][2] =
00934 cur_pred[3][3] =
00935 cur_pred[5][4] =
00936 cur_pred[7][5] = (imgpel) ((P_A + P_C + (P_B << 1) + 2) >> 2);
00937 cur_pred[1][3] =
00938 cur_pred[3][4] =
00939 cur_pred[5][5] =
00940 cur_pred[7][6] = (imgpel) ((P_B + P_D + (P_C << 1) + 2) >> 2);
00941 cur_pred[1][4] =
00942 cur_pred[3][5] =
00943 cur_pred[5][6] =
00944 cur_pred[7][7] = (imgpel) ((P_C + P_E + (P_D << 1) + 2) >> 2);
00945 cur_pred[1][5] =
00946 cur_pred[3][6] =
00947 cur_pred[5][7] = (imgpel) ((P_D + P_F + (P_E << 1) + 2) >> 2);
00948 cur_pred[1][6] =
00949 cur_pred[3][7] = (imgpel) ((P_E + P_G + (P_F << 1) + 2) >> 2);
00950 cur_pred[1][7] = (imgpel) ((P_F + P_H + (P_G << 1) + 2) >> 2);
00951 cur_pred[2][0] =
00952 cur_pred[4][1] =
00953 cur_pred[6][2] = (imgpel) ((P_R + P_Z + (P_Q << 1) + 2) >> 2);
00954 cur_pred[3][0] =
00955 cur_pred[5][1] =
00956 cur_pred[7][2] = (imgpel) ((P_S + P_Q + (P_R << 1) + 2) >> 2);
00957 cur_pred[4][0] =
00958 cur_pred[6][1] = (imgpel) ((P_T + P_R + (P_S << 1) + 2) >> 2);
00959 cur_pred[5][0] =
00960 cur_pred[7][1] = (imgpel) ((P_U + P_S + (P_T << 1) + 2) >> 2);
00961 cur_pred[6][0] = (imgpel) ((P_V + P_T + (P_U << 1) + 2) >> 2);
00962 cur_pred[7][0] = (imgpel) ((P_W + P_U + (P_V << 1) + 2) >> 2);
00963 }
00964
00965 static inline void get_hor_down(imgpel **cur_pred, imgpel *PredPel)
00966 {
00967 cur_pred[0][0] =
00968 cur_pred[1][2] =
00969 cur_pred[2][4] =
00970 cur_pred[3][6] = (imgpel) ((P_Q + P_Z + 1) >> 1);
00971 cur_pred[1][0] =
00972 cur_pred[2][2] =
00973 cur_pred[3][4] =
00974 cur_pred[4][6] = (imgpel) ((P_R + P_Q + 1) >> 1);
00975 cur_pred[2][0] =
00976 cur_pred[3][2] =
00977 cur_pred[4][4] =
00978 cur_pred[5][6] = (imgpel) ((P_S + P_R + 1) >> 1);
00979 cur_pred[3][0] =
00980 cur_pred[4][2] =
00981 cur_pred[5][4] =
00982 cur_pred[6][6] = (imgpel) ((P_T + P_S + 1) >> 1);
00983 cur_pred[4][0] =
00984 cur_pred[5][2] =
00985 cur_pred[6][4] =
00986 cur_pred[7][6] = (imgpel) ((P_U + P_T + 1) >> 1);
00987 cur_pred[5][0] =
00988 cur_pred[6][2] =
00989 cur_pred[7][4] = (imgpel) ((P_V + P_U + 1) >> 1);
00990 cur_pred[6][0] =
00991 cur_pred[7][2] = (imgpel) ((P_W + P_V + 1) >> 1);
00992 cur_pred[7][0] = (imgpel) ((P_X + P_W + 1) >> 1);
00993 cur_pred[0][1] =
00994 cur_pred[1][3] =
00995 cur_pred[2][5] =
00996 cur_pred[3][7] = (imgpel) ((P_Q + P_A + (P_Z << 1) + 2) >> 2);
00997 cur_pred[1][1] =
00998 cur_pred[2][3] =
00999 cur_pred[3][5] =
01000 cur_pred[4][7] = (imgpel) ((P_Z + P_R + (P_Q << 1) + 2) >> 2);
01001 cur_pred[2][1] =
01002 cur_pred[3][3] =
01003 cur_pred[4][5] =
01004 cur_pred[5][7] = (imgpel) ((P_Q + P_S + (P_R << 1) + 2) >> 2);
01005 cur_pred[3][1] =
01006 cur_pred[4][3] =
01007 cur_pred[5][5] =
01008 cur_pred[6][7] = (imgpel) ((P_R + P_T + (P_S << 1) + 2) >> 2);
01009 cur_pred[4][1] =
01010 cur_pred[5][3] =
01011 cur_pred[6][5] =
01012 cur_pred[7][7] = (imgpel) ((P_S + P_U + (P_T << 1) + 2) >> 2);
01013 cur_pred[5][1] =
01014 cur_pred[6][3] =
01015 cur_pred[7][5] = (imgpel) ((P_T + P_V + (P_U << 1) + 2) >> 2);
01016 cur_pred[6][1] =
01017 cur_pred[7][3] = (imgpel) ((P_U + P_W + (P_V << 1) + 2) >> 2);
01018 cur_pred[7][1] = (imgpel) ((P_V + P_X + (P_W << 1) + 2) >> 2);
01019 cur_pred[0][2] =
01020 cur_pred[1][4] =
01021 cur_pred[2][6] = (imgpel) ((P_Z + P_B + (P_A << 1) + 2) >> 2);
01022 cur_pred[0][3] =
01023 cur_pred[1][5] =
01024 cur_pred[2][7] = (imgpel) ((P_A + P_C + (P_B << 1) + 2) >> 2);
01025 cur_pred[0][4] =
01026 cur_pred[1][6] = (imgpel) ((P_B + P_D + (P_C << 1) + 2) >> 2);
01027 cur_pred[0][5] =
01028 cur_pred[1][7] = (imgpel) ((P_C + P_E + (P_D << 1) + 2) >> 2);
01029 cur_pred[0][6] = (imgpel) ((P_D + P_F + (P_E << 1) + 2) >> 2);
01030 cur_pred[0][7] = (imgpel) ((P_E + P_G + (P_F << 1) + 2) >> 2);
01031 }
01032
01033 static inline void get_hor_up(imgpel **cur_pred, imgpel *PredPel)
01034 {
01035 cur_pred[0][0] = (imgpel) ((P_Q + P_R + 1) >> 1);
01036 cur_pred[1][0] =
01037 cur_pred[0][2] = (imgpel) ((P_R + P_S + 1) >> 1);
01038 cur_pred[2][0] =
01039 cur_pred[1][2] =
01040 cur_pred[0][4] = (imgpel) ((P_S + P_T + 1) >> 1);
01041 cur_pred[3][0] =
01042 cur_pred[2][2] =
01043 cur_pred[1][4] =
01044 cur_pred[0][6] = (imgpel) ((P_T + P_U + 1) >> 1);
01045 cur_pred[4][0] =
01046 cur_pred[3][2] =
01047 cur_pred[2][4] =
01048 cur_pred[1][6] = (imgpel) ((P_U + P_V + 1) >> 1);
01049 cur_pred[5][0] =
01050 cur_pred[4][2] =
01051 cur_pred[3][4] =
01052 cur_pred[2][6] = (imgpel) ((P_V + P_W + 1) >> 1);
01053 cur_pred[6][0] =
01054 cur_pred[5][2] =
01055 cur_pred[4][4] =
01056 cur_pred[3][6] = (imgpel) ((P_W + P_X + 1) >> 1);
01057 cur_pred[4][6] =
01058 cur_pred[4][7] =
01059 cur_pred[5][4] =
01060 cur_pred[5][5] =
01061 cur_pred[5][6] =
01062 cur_pred[5][7] =
01063 cur_pred[6][2] =
01064 cur_pred[6][3] =
01065 cur_pred[6][4] =
01066 cur_pred[6][5] =
01067 cur_pred[6][6] =
01068 cur_pred[6][7] =
01069 cur_pred[7][0] =
01070 cur_pred[7][1] =
01071 cur_pred[7][2] =
01072 cur_pred[7][3] =
01073 cur_pred[7][4] =
01074 cur_pred[7][5] =
01075 cur_pred[7][6] =
01076 cur_pred[7][7] = (imgpel) P_X;
01077 cur_pred[6][1] =
01078 cur_pred[5][3] =
01079 cur_pred[4][5] =
01080 cur_pred[3][7] = (imgpel) ((P_W + P_X + (P_X << 1) + 2) >> 2);
01081 cur_pred[5][1] =
01082 cur_pred[4][3] =
01083 cur_pred[3][5] =
01084 cur_pred[2][7] = (imgpel) ((P_X + P_V + (P_W << 1) + 2) >> 2);
01085 cur_pred[4][1] =
01086 cur_pred[3][3] =
01087 cur_pred[2][5] =
01088 cur_pred[1][7] = (imgpel) ((P_W + P_U + (P_V << 1) + 2) >> 2);
01089 cur_pred[3][1] =
01090 cur_pred[2][3] =
01091 cur_pred[1][5] =
01092 cur_pred[0][7] = (imgpel) ((P_V + P_T + (P_U << 1) + 2) >> 2);
01093 cur_pred[2][1] =
01094 cur_pred[1][3] =
01095 cur_pred[0][5] = (imgpel) ((P_U + P_S + (P_T << 1) + 2) >> 2);
01096 cur_pred[1][1] =
01097 cur_pred[0][3] = (imgpel) ((P_T + P_R + (P_S << 1) + 2) >> 2);
01098 cur_pred[0][1] = (imgpel) ((P_S + P_Q + (P_R << 1) + 2) >> 2);
01099 }
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117 void intrapred_8x8(Macroblock *currMB, ColorPlane pl, int img_x,int img_y, int *left_available, int *up_available, int *all_available)
01118 {
01119 int i,j;
01120 int s0;
01121 static imgpel PredPel[25];
01122 imgpel **img_enc = enc_picture->p_curr_img;
01123 imgpel *img_pel;
01124 static imgpel **cur_pred;
01125 imgpel ***curr_mpr_8x8 = img->mpr_8x8[pl];
01126 unsigned int dc_pred_value = img->dc_pred_value;
01127 int *mb_size = img->mb_size[IS_LUMA];
01128
01129 int ioff = (img_x & 15);
01130 int joff = (img_y & 15);
01131
01132 PixelPos pix_a[8];
01133 PixelPos pix_b, pix_c, pix_d;
01134
01135 int block_available_up;
01136 int block_available_left;
01137 int block_available_up_left;
01138 int block_available_up_right;
01139
01140 for (i=0;i<8;i++)
01141 {
01142 getNeighbour(currMB, ioff - 1, joff + i , mb_size, &pix_a[i]);
01143 }
01144
01145 getNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b);
01146 getNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c);
01147 getNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d);
01148
01149 pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8);
01150
01151 if (params->UseConstrainedIntraPred)
01152 {
01153 for (i=0, block_available_left=1; i<8;i++)
01154 block_available_left &= pix_a[i].available ? img->intra_block[pix_a[i].mb_addr]: 0;
01155
01156 block_available_up = pix_b.available ? img->intra_block [pix_b.mb_addr] : 0;
01157 block_available_up_right = pix_c.available ? img->intra_block [pix_c.mb_addr] : 0;
01158 block_available_up_left = pix_d.available ? img->intra_block [pix_d.mb_addr] : 0;
01159 }
01160 else
01161 {
01162 block_available_left = pix_a[0].available;
01163 block_available_up = pix_b.available;
01164 block_available_up_right = pix_c.available;
01165 block_available_up_left = pix_d.available;
01166 }
01167
01168 *left_available = block_available_left;
01169 *up_available = block_available_up;
01170 *all_available = block_available_up && block_available_left && block_available_up_left;
01171
01172
01173 if (block_available_up)
01174 {
01175 img_pel = &img_enc[pix_b.pos_y][pix_b.pos_x];
01176 P_A = *(img_pel++);
01177 P_B = *(img_pel++);
01178 P_C = *(img_pel++);
01179 P_D = *(img_pel++);
01180 P_E = *(img_pel++);
01181 P_F = *(img_pel++);
01182 P_G = *(img_pel++);
01183 P_H = *(img_pel);
01184 }
01185 else
01186 {
01187 P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = dc_pred_value;
01188 }
01189
01190 if (block_available_up_right)
01191 {
01192 img_pel = &img_enc[pix_c.pos_y][pix_c.pos_x];
01193 P_I = *(img_pel++);
01194 P_J = *(img_pel++);
01195 P_K = *(img_pel++);
01196 P_L = *(img_pel++);
01197 P_M = *(img_pel++);
01198 P_N = *(img_pel++);
01199 P_O = *(img_pel++);
01200 P_P = *(img_pel);
01201
01202 }
01203 else
01204 {
01205 P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H;
01206 }
01207
01208 if (block_available_left)
01209 {
01210 P_Q = img_enc[pix_a[0].pos_y][pix_a[0].pos_x];
01211 P_R = img_enc[pix_a[1].pos_y][pix_a[1].pos_x];
01212 P_S = img_enc[pix_a[2].pos_y][pix_a[2].pos_x];
01213 P_T = img_enc[pix_a[3].pos_y][pix_a[3].pos_x];
01214 P_U = img_enc[pix_a[4].pos_y][pix_a[4].pos_x];
01215 P_V = img_enc[pix_a[5].pos_y][pix_a[5].pos_x];
01216 P_W = img_enc[pix_a[6].pos_y][pix_a[6].pos_x];
01217 P_X = img_enc[pix_a[7].pos_y][pix_a[7].pos_x];
01218 }
01219 else
01220 {
01221 P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = dc_pred_value;
01222 }
01223
01224 if (block_available_up_left)
01225 {
01226 P_Z = img_enc[pix_d.pos_y][pix_d.pos_x];
01227 }
01228 else
01229 {
01230 P_Z = dc_pred_value;
01231 }
01232
01233 for(i=0;i<9;i++)
01234 curr_mpr_8x8[i][0][0]=-1;
01235
01236 LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left);
01237
01238
01239
01240
01241 s0 = 0;
01242 if (block_available_up && block_available_left)
01243 {
01244
01245 s0 = rshift_rnd_sf((P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X), 4);
01246 }
01247 else if (!block_available_up && block_available_left)
01248 {
01249
01250 s0 = rshift_rnd_sf((P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X), 3);
01251 }
01252 else if (block_available_up && !block_available_left)
01253 {
01254
01255 s0 = rshift_rnd_sf((P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H), 3);
01256 }
01257 else
01258 {
01259
01260 s0 = dc_pred_value;
01261 }
01262
01263
01264 cur_pred = curr_mpr_8x8[DC_PRED];
01265
01266 for (i=0; i < BLOCK_SIZE_8x8; i++)
01267 {
01268 cur_pred[0][i] = (imgpel) s0;
01269 }
01270
01271 for (j=0; j < BLOCK_SIZE_8x8 - 1; j++)
01272 {
01273 memcpy (cur_pred[j + 1], cur_pred[j], BLOCK_SIZE_8x8 * sizeof(imgpel));
01274 }
01275
01276
01277
01278
01279
01280 if(block_available_up)
01281 {
01282 cur_pred = curr_mpr_8x8[VERT_PRED];
01283 for (j=0; j < BLOCK_SIZE_8x8; j++)
01284 memcpy(cur_pred[j], &P_A, BLOCK_SIZE_8x8 * sizeof(imgpel));
01285 }
01286
01287 if(block_available_left)
01288 {
01289 cur_pred = curr_mpr_8x8[HOR_PRED];
01290 for (i=0; i < BLOCK_SIZE_8x8; i++)
01291 {
01292 cur_pred[i][0] =
01293 cur_pred[i][1] =
01294 cur_pred[i][2] =
01295 cur_pred[i][3] =
01296 cur_pred[i][4] =
01297 cur_pred[i][5] =
01298 cur_pred[i][6] =
01299 cur_pred[i][7] = (imgpel) (&P_Q)[i];
01300 }
01301 }
01302
01303
01304
01305
01306 if (block_available_up)
01307 {
01308
01309 get_diag_down_left(curr_mpr_8x8[DIAG_DOWN_LEFT_PRED], PredPel);
01310
01311
01312
01313
01314 get_vert_left(curr_mpr_8x8[VERT_LEFT_PRED], PredPel);
01315 }
01316
01317
01318
01319
01320 if (block_available_up && block_available_left && block_available_up_left)
01321 {
01322
01323 get_diag_down_right(curr_mpr_8x8[DIAG_DOWN_RIGHT_PRED], PredPel);
01324
01325
01326
01327
01328 get_vert_right(curr_mpr_8x8[VERT_RIGHT_PRED], PredPel);
01329
01330
01331
01332
01333 get_hor_down(curr_mpr_8x8[HOR_DOWN_PRED], PredPel);
01334 }
01335
01336
01337
01338
01339 if (block_available_left)
01340 {
01341 get_hor_up(curr_mpr_8x8[HOR_UP_PRED], PredPel);
01342 }
01343 }
01344
01345
01346
01347
01348
01349
01350
01351 void LowPassForIntra8x8Pred(imgpel *PredPel, int block_up_left, int block_up, int block_left)
01352 {
01353 int i;
01354 static imgpel LoopArray[25];
01355
01356 memcpy(LoopArray,PredPel, 25 * sizeof(imgpel));
01357
01358 if(block_up)
01359 {
01360 if(block_up_left)
01361 {
01362 LoopArray[1] = ((PredPel[0] + (PredPel[1]<<1) + PredPel[2] + 2)>>2);
01363 }
01364 else
01365 LoopArray[1] = ((PredPel[1] + (PredPel[1]<<1) + PredPel[2] + 2)>>2);
01366
01367
01368 for(i = 2; i <16; i++)
01369 {
01370 LoopArray[i] = ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2);
01371 }
01372 LoopArray[16] = ((P_P + (P_P<<1) + P_O + 2)>>2);
01373 }
01374
01375 if(block_up_left)
01376 {
01377 if(block_up && block_left)
01378 {
01379 LoopArray[0] = ((P_Q + (P_Z<<1) + P_A +2)>>2);
01380 }
01381 else
01382 {
01383 if(block_up)
01384 LoopArray[0] = ((P_Z + (P_Z<<1) + P_A +2)>>2);
01385 else
01386 if(block_left)
01387 LoopArray[0] = ((P_Z + (P_Z<<1) + P_Q +2)>>2);
01388 }
01389 }
01390
01391 if(block_left)
01392 {
01393 if(block_up_left)
01394 LoopArray[17] = ((P_Z + (P_Q<<1) + P_R + 2)>>2);
01395 else
01396 LoopArray[17] = ((P_Q + (P_Q<<1) + P_R + 2)>>2);
01397
01398 for(i = 18; i <24; i++)
01399 {
01400 LoopArray[i] = ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2);
01401 }
01402 LoopArray[24] = ((P_W + (P_X<<1) + P_X + 2) >> 2);
01403 }
01404
01405 memcpy(PredPel, LoopArray, 25 * sizeof(imgpel));
01406 }
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416 double RDCost_for_8x8IntraBlocks(Slice *currSlice, Macroblock *currMB, int *nonzero, int b8, int ipmode, double lambda, double min_rdcost, int mostProbableMode, int c_nzCbCr[3])
01417 {
01418 double rdcost = 0.0;
01419 int dummy = 0;
01420 int rate;
01421 int64 distortion = 0;
01422 int block_x = (b8 & 0x01) << 3;
01423 int block_y = (b8 >> 1) << 3;
01424 int pic_pix_x = img->pix_x + block_x;
01425 int pic_pix_y = img->pix_y + block_y;
01426 int pic_opix_y = img->opix_y + block_y;
01427
01428 SyntaxElement se;
01429 const int *partMap = assignSE2partition[params->partition_mode];
01430 DataPartition *dataPart;
01431
01432 if(img->P444_joined == 0)
01433 {
01434
01435 *nonzero = pDCT_8x8 (currMB, PLANE_Y, b8, &dummy, 1);
01436
01437
01438 distortion += compute_SSE(&pCurImg[pic_opix_y], &enc_picture->imgY[pic_pix_y], pic_pix_x, pic_pix_x, 8, 8);
01439
01440 ipmode_DPCM = NO_INTRA_PMODE;
01441
01442
01443 se.value1 = (mostProbableMode == ipmode) ? -1 : ipmode < mostProbableMode ? ipmode : ipmode-1;
01444
01445
01446 se.context = b8;
01447 se.type = SE_INTRAPREDMODE;
01448
01449
01450 if (img->type!=B_SLICE)
01451 dataPart = &(currSlice->partArr[partMap[SE_INTRAPREDMODE]]);
01452 else
01453 dataPart = &(currSlice->partArr[partMap[SE_BFRAME]]);
01454
01455
01456 writeIntraPredMode (&se, dataPart);
01457
01458 rate = se.len;
01459
01460
01461
01462 if (currSlice->symbol_mode == CAVLC)
01463 {
01464 rate += writeCoeff4x4_CAVLC (currSlice, currMB, LUMA, b8, 0, 0);
01465 rate += writeCoeff4x4_CAVLC (currSlice, currMB, LUMA, b8, 1, 0);
01466 rate += writeCoeff4x4_CAVLC (currSlice, currMB, LUMA, b8, 2, 0);
01467 rate += writeCoeff4x4_CAVLC (currSlice, currMB, LUMA, b8, 3, 0);
01468 }
01469 else
01470 {
01471 rate += writeCoeff8x8_CABAC (currSlice, currMB, PLANE_Y, b8, 1);
01472 }
01473 }
01474 else
01475 {
01476 ColorPlane k;
01477
01478 *nonzero = pDCT_8x8 (currMB, PLANE_Y, b8, &dummy, 1);
01479
01480
01481 distortion += compute_SSE(&pCurImg[pic_opix_y], &enc_picture->imgY[pic_pix_y], pic_pix_x, pic_pix_x, 8, 8);
01482
01483 for (k = PLANE_U; k <= PLANE_V; k++)
01484 {
01485 select_plane(k);
01486 c_nzCbCr[k ]= pDCT_8x8(currMB, k, b8, &dummy,1);
01487 distortion += compute_SSE(&pImgOrg[k][pic_opix_y], &enc_picture->p_curr_img[pic_pix_y], pic_pix_x, pic_pix_x, 8, 8);
01488 }
01489 ipmode_DPCM = NO_INTRA_PMODE;
01490 select_plane(PLANE_Y);
01491
01492
01493 se.value1 = (mostProbableMode == ipmode) ? -1 : ipmode < mostProbableMode ? ipmode : ipmode-1;
01494
01495
01496 se.context = b8;
01497 se.type = SE_INTRAPREDMODE;
01498
01499
01500 if (img->type!=B_SLICE)
01501 dataPart = &(currSlice->partArr[partMap[SE_INTRAPREDMODE]]);
01502 else
01503 dataPart = &(currSlice->partArr[partMap[SE_BFRAME]]);
01504
01505
01506 writeIntraPredMode (&se, dataPart);
01507 rate = se.len;
01508
01509
01510
01511 if (currSlice->symbol_mode == CAVLC)
01512 {
01513 int b4;
01514 for(b4=0; b4<4; b4++)
01515 {
01516 rate += writeCoeff4x4_CAVLC (currSlice, currMB, LUMA, b8, b4, 0);
01517 rate += writeCoeff4x4_CAVLC (currSlice, currMB, CB, b8, b4, 0);
01518 rate += writeCoeff4x4_CAVLC (currSlice, currMB, CR, b8, b4, 0);
01519 }
01520 }
01521 else
01522 {
01523 rate += writeCoeff8x8_CABAC (currSlice, currMB, PLANE_Y, b8, 1);
01524 rate += writeCoeff8x8_CABAC (currSlice, currMB, PLANE_U, b8, 1);
01525 rate += writeCoeff8x8_CABAC (currSlice, currMB, PLANE_V, b8, 1);
01526 }
01527 }
01528 rdcost = (double)distortion + lambda*(double)rate;
01529
01530 return rdcost;
01531 }
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548 int dct_8x8(Macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra)
01549 {
01550 int nonzero = FALSE;
01551
01552 int block_x = 8*(b8 & 0x01);
01553 int block_y = 8*(b8 >> 1);
01554 int pl_off = b8+ (pl<<2);
01555 int* ACLevel = img->cofAC[pl_off][0][0];
01556 int* ACRun = img->cofAC[pl_off][0][1];
01557 imgpel **img_enc = enc_picture->p_curr_img;
01558 imgpel **mb_pred = img->mb_pred[pl];
01559 int **mb_ores = img->mb_ores[pl];
01560 int **mb_rres = img->mb_rres[pl];
01561
01562 int max_imgpel_value = img->max_imgpel_value;
01563 int qp = currMB->qp_scaled[pl];
01564 const byte (*pos_scan)[2] = currMB->is_field_mode ? FIELD_SCAN8x8 : SNGL_SCAN8x8;
01565
01566 int qp_rem = qp_rem_matrix[qp];
01567
01568
01569 levelscale = LevelScale8x8Comp [pl][intra][qp_rem];
01570 invlevelscale = InvLevelScale8x8Comp[pl][intra][qp_rem];
01571 leveloffset = LevelOffset8x8Comp [pl][intra][qp];
01572
01573 fadjust8x8 = img->AdaptiveRounding ? (&img->ARCofAdj8x8[pl][currMB->ar_mode][block_y]) :NULL;
01574
01575
01576 forward8x8(mb_ores, mb_rres, block_y, block_x);
01577
01578
01579 nonzero = quant_8x8(&mb_rres[block_y], block_y, block_x, qp, ACLevel, ACRun, fadjust8x8,
01580 levelscale, invlevelscale, leveloffset, coeff_cost, pos_scan, COEFF_COST8x8[params->disthres]);
01581
01582 if (nonzero)
01583 {
01584
01585 inverse8x8(mb_rres, mb_rres, block_y, block_x);
01586
01587
01588 SampleReconstruct (img_enc, mb_pred, mb_rres, block_y, block_x, img->pix_y, img->pix_x + block_x, BLOCK_SIZE_8x8, BLOCK_SIZE_8x8, max_imgpel_value, DQ_BITS_8);
01589 }
01590 else
01591 {
01592 copy_8x8block(&img_enc[img->pix_y + block_y], &mb_pred[block_y], img->pix_x + block_x, block_x);
01593 }
01594
01595
01596 return nonzero;
01597 }
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614 int dct_8x8_cavlc(Macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra)
01615 {
01616 int nonzero = FALSE;
01617
01618 int block_x = 8*(b8 & 0x01);
01619 int block_y = 8*(b8 >> 1);
01620 int pl_off = b8+ (pl<<2);
01621 imgpel **img_enc = enc_picture->p_curr_img;
01622 imgpel **mb_pred = img->mb_pred[pl];
01623 int **mb_ores = img->mb_ores[pl];
01624 int **mb_rres = img->mb_rres[pl];
01625
01626 int max_imgpel_value = img->max_imgpel_value;
01627
01628 int qp = currMB->qp_scaled[pl];
01629 const byte (*pos_scan)[2] = currMB->is_field_mode ? FIELD_SCAN8x8 : SNGL_SCAN8x8;
01630
01631 int qp_rem = qp_rem_matrix[qp];
01632
01633 levelscale = LevelScale8x8Comp [pl][intra][qp_rem];
01634 invlevelscale = InvLevelScale8x8Comp[pl][intra][qp_rem];
01635 leveloffset = LevelOffset8x8Comp [pl][intra][qp];
01636
01637 fadjust8x8 = img->AdaptiveRounding ? (&img->ARCofAdj8x8[pl][currMB->ar_mode][block_y]) :NULL;
01638
01639
01640 forward8x8(mb_ores, mb_rres, block_y, block_x);
01641
01642
01643 nonzero = quant_8x8cavlc(&mb_rres[block_y], block_y, block_x, qp, img->cofAC[pl_off], fadjust8x8,
01644 levelscale, invlevelscale, leveloffset, coeff_cost, pos_scan, COEFF_COST8x8[params->disthres]);
01645
01646 if (nonzero)
01647 {
01648
01649 inverse8x8(mb_rres, mb_rres, block_y, block_x);
01650
01651
01652 SampleReconstruct (img_enc, mb_pred, mb_rres, block_y, block_x, img->pix_y, img->pix_x + block_x, BLOCK_SIZE_8x8, BLOCK_SIZE_8x8, max_imgpel_value, DQ_BITS_8);
01653 }
01654 else
01655 {
01656 copy_8x8block(&img_enc[img->pix_y + block_y], &mb_pred[block_y], img->pix_x + block_x, block_x);
01657 }
01658
01659
01660 return nonzero;
01661 }
01662
01663 int dct_8x8_ls(Macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra)
01664 {
01665 int i,j,coeff_ctr;
01666 int scan_pos = 0,run = -1;
01667 int nonzero = FALSE;
01668
01669 int block_x = 8*(b8 & 0x01);
01670 int block_y = 8*(b8 >> 1);
01671 int pl_off = b8 + (pl<<2);
01672 int* ACLevel = img->cofAC[pl_off][0][0];
01673 int* ACRun = img->cofAC[pl_off][0][1];
01674 imgpel **img_enc = enc_picture->p_curr_img;
01675 imgpel **mb_pred = img->mb_pred[pl];
01676 int **mb_ores = img->mb_ores[pl];
01677 int **mb_rres = img->mb_rres[pl];
01678
01679 int scan_poss[4] = { 0 }, runs[4] = { -1, -1, -1, -1 };
01680 int MCcoeff = 0;
01681 int *m7;
01682 int is_cavlc = (img->currentSlice->symbol_mode == CAVLC);
01683
01684 const byte (*pos_scan)[2] = currMB->is_field_mode ? FIELD_SCAN8x8 : SNGL_SCAN8x8;
01685
01686 int **fadjust8x8 = img->AdaptiveRounding ? (&img->ARCofAdj8x8[pl][currMB->ar_mode][block_y]) :NULL;
01687
01688 runs[0]=runs[1]=runs[2]=runs[3]=-1;
01689 scan_poss[0] = scan_poss[1] = scan_poss[2] = scan_poss[3] = 0;
01690
01691 if( (ipmode_DPCM < 2)&&(intra))
01692 {
01693 Residual_DPCM_8x8(ipmode_DPCM, mb_ores, mb_rres, block_y, block_x);
01694 }
01695
01696 for (coeff_ctr=0; coeff_ctr < 64; coeff_ctr++)
01697 {
01698 i=pos_scan[coeff_ctr][0];
01699 j=pos_scan[coeff_ctr][1];
01700
01701 run++;
01702
01703 if (currMB->luma_transform_size_8x8_flag && is_cavlc)
01704 {
01705 MCcoeff = (coeff_ctr & 3);
01706 runs[MCcoeff]++;
01707 }
01708
01709 m7 = &mb_rres[block_y + j][block_x + i];
01710
01711 if (img->AdaptiveRounding)
01712 {
01713 fadjust8x8[j][block_x+i] = 0;
01714 }
01715
01716 if (*m7 != 0)
01717 {
01718 nonzero = TRUE;
01719
01720 if (currMB->luma_transform_size_8x8_flag && is_cavlc)
01721 {
01722 *m7 = iClip3(-CAVLC_LEVEL_LIMIT, CAVLC_LEVEL_LIMIT, *m7);
01723 *coeff_cost += MAX_VALUE;
01724
01725 img->cofAC[pl_off][MCcoeff][0][scan_poss[MCcoeff] ] = *m7;
01726 img->cofAC[pl_off][MCcoeff][1][scan_poss[MCcoeff]++] = runs[MCcoeff];
01727 ++scan_pos;
01728 runs[MCcoeff]=-1;
01729 }
01730 else
01731 {
01732 *coeff_cost += MAX_VALUE;
01733 ACLevel[scan_pos ] = *m7;
01734 ACRun [scan_pos++] = run;
01735 run=-1;
01736 }
01737 }
01738 }
01739
01740 if (!currMB->luma_transform_size_8x8_flag || !is_cavlc)
01741 ACLevel[scan_pos] = 0;
01742 else
01743 {
01744 for(i=0; i<4; i++)
01745 img->cofAC[pl_off][i][0][scan_poss[i]] = 0;
01746 }
01747
01748 if( (ipmode_DPCM < 2) && (intra))
01749 {
01750 Inv_Residual_DPCM_8x8(mb_rres, block_y, block_x);
01751 }
01752
01753 for( j=block_y; j<block_y + BLOCK_SIZE_8x8; j++)
01754 {
01755 for( i=block_x; i< block_x + BLOCK_SIZE_8x8; i++)
01756 {
01757 mb_rres[j][i] += (int) mb_pred[j][i];
01758 img_enc[img->pix_y + j][img->pix_x + i]= (imgpel) mb_rres[j][i];
01759 }
01760 }
01761
01762
01763 return nonzero;
01764 }
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781 void compute_comp_cost8x8(imgpel **cur_img, imgpel **mpr8x8, int pic_opix_x, double *cost)
01782 {
01783 int i, j;
01784 int *diff = &diff64[0];
01785 imgpel *cimg, *cmpr;
01786
01787 for (j=0; j<8; j++)
01788 {
01789
01790
01791 cimg = &cur_img[j][pic_opix_x];
01792 cmpr = &mpr8x8[j][0];
01793 for (i=0; i<8; i++)
01794 {
01795 *diff++ = *cimg++ - *cmpr++;
01796 }
01797
01798 }
01799 *cost += distortion8x8 (diff64);
01800 }
01801