00001
00024 #include "contributors.h"
00025
00026 #include <math.h>
00027
00028 #include "global.h"
00029 #include "mbuffer.h"
00030 #include "elements.h"
00031 #include "errorconcealment.h"
00032 #include "macroblock.h"
00033 #include "fmo.h"
00034 #include "cabac.h"
00035 #include "vlc.h"
00036 #include "image.h"
00037 #include "mb_access.h"
00038 #include "biaridecod.h"
00039 #include "block.h"
00040 #include "transform8x8.h"
00041 #include "transform.h"
00042 #include "mc_prediction.h"
00043 #include "quant.h"
00044 #include "intra4x4_pred.h"
00045 #include "intra8x8_pred.h"
00046 #include "intra16x16_pred.h"
00047
00048 #if TRACE
00049 #define TRACE_STRING(s) strncpy(currSE.tracestring, s, TRACESTRING_SIZE)
00050 #define TRACE_DECBITS(i) dectracebitcnt(1)
00051 #define TRACE_PRINTF(s) sprintf(type, "%s", s);
00052 #define TRACE_STRING_P(s) strncpy(currSE->tracestring, s, TRACESTRING_SIZE)
00053 #else
00054 #define TRACE_STRING(s)
00055 #define TRACE_DECBITS(i)
00056 #define TRACE_PRINTF(s)
00057 #define TRACE_STRING_P(s)
00058 #endif
00059
00061 static const byte SNGL_SCAN[16][2] =
00062 {
00063 {0,0},{1,0},{0,1},{0,2},
00064 {1,1},{2,0},{3,0},{2,1},
00065 {1,2},{0,3},{1,3},{2,2},
00066 {3,1},{3,2},{2,3},{3,3}
00067 };
00068
00070 static const byte FIELD_SCAN[16][2] =
00071 {
00072 {0,0},{0,1},{1,0},{0,2},
00073 {0,3},{1,1},{1,2},{1,3},
00074 {2,0},{2,1},{2,2},{2,3},
00075 {3,0},{3,1},{3,2},{3,3}
00076 };
00077
00079 static const int BLOCK_STEP[8][2]=
00080 {
00081 {0,0},{4,4},{4,2},{2,4},{2,2},{2,1},{1,2},{1,1}
00082 };
00083
00084 const byte QP_SCALE_CR[52]=
00085 {
00086 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,
00087 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,
00088 28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,
00089 37,38,38,38,39,39,39,39
00090
00091 };
00092
00094 const byte SNGL_SCAN8x8[64][2] = {
00095 {0,0}, {1,0}, {0,1}, {0,2}, {1,1}, {2,0}, {3,0}, {2,1}, {1,2}, {0,3}, {0,4}, {1,3}, {2,2}, {3,1}, {4,0}, {5,0},
00096 {4,1}, {3,2}, {2,3}, {1,4}, {0,5}, {0,6}, {1,5}, {2,4}, {3,3}, {4,2}, {5,1}, {6,0}, {7,0}, {6,1}, {5,2}, {4,3},
00097 {3,4}, {2,5}, {1,6}, {0,7}, {1,7}, {2,6}, {3,5}, {4,4}, {5,3}, {6,2}, {7,1}, {7,2}, {6,3}, {5,4}, {4,5}, {3,6},
00098 {2,7}, {3,7}, {4,6}, {5,5}, {6,4}, {7,3}, {7,4}, {6,5}, {5,6}, {4,7}, {5,7}, {6,6}, {7,5}, {7,6}, {6,7}, {7,7}
00099 };
00100
00101
00103 const byte FIELD_SCAN8x8[64][2] = {
00104 {0,0}, {0,1}, {0,2}, {1,0}, {1,1}, {0,3}, {0,4}, {1,2}, {2,0}, {1,3}, {0,5}, {0,6}, {0,7}, {1,4}, {2,1}, {3,0},
00105 {2,2}, {1,5}, {1,6}, {1,7}, {2,3}, {3,1}, {4,0}, {3,2}, {2,4}, {2,5}, {2,6}, {2,7}, {3,3}, {4,1}, {5,0}, {4,2},
00106 {3,4}, {3,5}, {3,6}, {3,7}, {4,3}, {5,1}, {6,0}, {5,2}, {4,4}, {4,5}, {4,6}, {4,7}, {5,3}, {6,1}, {6,2}, {5,4},
00107 {5,5}, {5,6}, {5,7}, {6,3}, {7,0}, {7,1}, {6,4}, {6,5}, {6,6}, {6,7}, {7,2}, {7,3}, {7,4}, {7,5}, {7,6}, {7,7}
00108 };
00109
00111 static const byte SCAN_YUV422[8][2] =
00112 {
00113 {0,0},{0,1},
00114 {1,0},{0,2},
00115 {0,3},{1,1},
00116 {1,2},{1,3}
00117 };
00118
00119 static unsigned char cbp_blk_chroma[8][4] =
00120 { {16, 17, 18, 19},
00121 {20, 21, 22, 23},
00122 {24, 25, 26, 27},
00123 {28, 29, 30, 31},
00124 {32, 33, 34, 35},
00125 {36, 37, 38, 39},
00126 {40, 41, 42, 43},
00127 {44, 45, 46, 47} };
00128
00130 const unsigned char subblk_offset_x[3][8][4] =
00131 {
00132 { {0, 4, 0, 4},
00133 {0, 4, 0, 4},
00134 {0, 0, 0, 0},
00135 {0, 0, 0, 0},
00136 {0, 0, 0, 0},
00137 {0, 0, 0, 0},
00138 {0, 0, 0, 0},
00139 {0, 0, 0, 0}, },
00140
00141 { {0, 4, 0, 4},
00142 {0, 4, 0, 4},
00143 {0, 4, 0, 4},
00144 {0, 4, 0, 4},
00145 {0, 0, 0, 0},
00146 {0, 0, 0, 0},
00147 {0, 0, 0, 0},
00148 {0, 0, 0, 0}, },
00149
00150 { {0, 4, 0, 4},
00151 {8,12, 8,12},
00152 {0, 4, 0, 4},
00153 {8,12, 8,12},
00154 {0, 4, 0, 4},
00155 {8,12, 8,12},
00156 {0, 4, 0, 4},
00157 {8,12, 8,12} }
00158 };
00159
00160 const unsigned char subblk_offset_y[3][8][4] =
00161 { { {0, 0, 4, 4},
00162 {0, 0, 4, 4},
00163 {0, 0, 0, 0},
00164 {0, 0, 0, 0},
00165 {0, 0, 0, 0},
00166 {0, 0, 0, 0},
00167 {0, 0, 0, 0},
00168 {0, 0, 0, 0}, },
00169
00170 { {0, 0, 4, 4},
00171 {8, 8,12,12},
00172 {0, 0, 4, 4},
00173 {8, 8,12,12},
00174 {0, 0, 0, 0},
00175 {0, 0, 0, 0},
00176 {0, 0, 0, 0},
00177 {0, 0, 0, 0} },
00178
00179 { {0, 0, 4, 4},
00180 {0, 0, 4, 4},
00181 {8, 8,12,12},
00182 {8, 8,12,12},
00183 {0, 0, 4, 4},
00184 {0, 0, 4, 4},
00185 {8, 8,12,12},
00186 {8, 8,12,12} }
00187 };
00188
00189 const unsigned char cofuv_blk_x[3][8][4] =
00190 { { {0, 1, 0, 1},
00191 {0, 1, 0, 1},
00192 {0, 0, 0, 0},
00193 {0, 0, 0, 0},
00194 {0, 0, 0, 0},
00195 {0, 0, 0, 0},
00196 {0, 0, 0, 0},
00197 {0, 0, 0, 0} },
00198
00199 { {0, 1, 0, 1},
00200 {0, 1, 0, 1},
00201 {0, 1, 0, 1},
00202 {0, 1, 0, 1},
00203 {0, 0, 0, 0},
00204 {0, 0, 0, 0},
00205 {0, 0, 0, 0},
00206 {0, 0, 0, 0} },
00207
00208 { {0, 1, 0, 1},
00209 {2, 3, 2, 3},
00210 {0, 1, 0, 1},
00211 {2, 3, 2, 3},
00212 {0, 1, 0, 1},
00213 {2, 3, 2, 3},
00214 {0, 1, 0, 1},
00215 {2, 3, 2, 3} }
00216 };
00217
00218 static const unsigned char cofuv_blk_y[3][8][4] =
00219 {
00220 { { 0, 0, 1, 1},
00221 { 0, 0, 1, 1},
00222 { 0, 0, 0, 0},
00223 { 0, 0, 0, 0},
00224 { 0, 0, 0, 0},
00225 { 0, 0, 0, 0},
00226 { 0, 0, 0, 0},
00227 { 0, 0, 0, 0} },
00228
00229 { { 0, 0, 1, 1},
00230 { 2, 2, 3, 3},
00231 { 0, 0, 1, 1},
00232 { 2, 2, 3, 3},
00233 { 0, 0, 0, 0},
00234 { 0, 0, 0, 0},
00235 { 0, 0, 0, 0},
00236 { 0, 0, 0, 0} },
00237
00238 { { 0, 0, 1, 1},
00239 { 0, 0, 1, 1},
00240 { 2, 2, 3, 3},
00241 { 2, 2, 3, 3},
00242 { 0, 0, 1, 1},
00243 { 0, 0, 1, 1},
00244 { 2, 2, 3, 3},
00245 { 2, 2, 3, 3}}
00246 };
00247
00248 void dectracebitcnt(int count);
00249
00250 extern int last_dquant;
00251 extern ColocatedParams *Co_located;
00252 extern ColocatedParams *Co_located_JV[MAX_PLANE];
00253
00254
00255 static void readMotionInfoFromNAL (ImageParameters *img, Slice *currSlice, Macroblock *currMB);
00256 static void read_ipred_modes (ImageParameters *img, Slice *currSlice, Macroblock *currMB);
00257 static void readCBPandCoeffsFromNAL(ImageParameters *img, Slice *currSlice, Macroblock *currMB);
00258 static void readIPCMcoeffsFromNAL (ImageParameters *img, struct datapartition *dP);
00259
00260
00261 static void (*interpret_mb_mode)(Macroblock *currMB);
00262
00269 int BType2CtxRef (int btype)
00270 {
00271 return (btype >= 4);
00272 }
00273
00280 static char (*readRefPictureIdx) (SyntaxElement *currSE, DataPartition *dP, char b8mode, int list);
00281
00288 static char readRefPictureIdx_VLC(SyntaxElement *currSE, DataPartition *dP, char b8mode, int list)
00289 {
00290 #if TRACE
00291 static char tstring[20];
00292 sprintf( tstring, "ref_idx_l%d", list);
00293 strncpy(currSE->tracestring, tstring, TRACESTRING_SIZE);
00294 #endif
00295 currSE->context = BType2CtxRef (b8mode);
00296 currSE->value2 = list;
00297 dP->readSyntaxElement (currSE,img,dP);
00298 return (char) currSE->value1;
00299 }
00300
00307 static char readRefPictureIdx_FLC(SyntaxElement *currSE, DataPartition *dP, char b8mode, int list)
00308 {
00309 #if TRACE
00310 static char tstring[20];
00311 sprintf( tstring, "ref_idx_l%d", list);
00312 strncpy(currSE->tracestring, tstring, TRACESTRING_SIZE);
00313 #endif
00314
00315 currSE->context = BType2CtxRef (b8mode);
00316 currSE->len = 1;
00317 readSyntaxElement_FLC(currSE, dP->bitstream);
00318 currSE->value1 = 1 - currSE->value1;
00319
00320 return (char) currSE->value1;
00321 }
00322
00329 static char readRefPictureIdx_Null(SyntaxElement *currSE, DataPartition *dP, char b8mode, int list)
00330 {
00331 return 0;
00332 }
00333
00340 static inline void prepareListforRefIdx ( SyntaxElement *currSE, DataPartition *dP, int num_ref_idx_active, int refidx_present)
00341 {
00342 readRefPictureIdx = readRefPictureIdx_Null;
00343 if(num_ref_idx_active > 1)
00344 {
00345 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
00346 {
00347 currSE->mapping = linfo_ue;
00348 if (refidx_present)
00349 {
00350 if (num_ref_idx_active == 2)
00351 readRefPictureIdx = readRefPictureIdx_FLC;
00352 else
00353 readRefPictureIdx = readRefPictureIdx_VLC;
00354 }
00355 }
00356 else
00357 {
00358 currSE->reading = readRefFrame_CABAC;
00359 if (refidx_present)
00360 readRefPictureIdx = readRefPictureIdx_VLC;
00361 }
00362 }
00363 }
00364
00365 void set_chroma_qp(ImageParameters *img, Macroblock* currMB)
00366 {
00367 int i;
00368 for (i=0; i<2; i++)
00369 {
00370 currMB->qpc[i] = iClip3 ( -img->bitdepth_chroma_qp_scale, 51, currMB->qp + dec_picture->chroma_qp_offset[i] );
00371 currMB->qpc[i] = currMB->qpc[i] < 0 ? currMB->qpc[i] : QP_SCALE_CR[currMB->qpc[i]];
00372 currMB->qp_scaled[i + 1] = currMB->qpc[i] + img->bitdepth_chroma_qp_scale;
00373 }
00374 }
00375
00382 void update_qp(ImageParameters *img, Macroblock *currMB, int qp)
00383 {
00384 currMB->qp = qp;
00385 currMB->qp_scaled[0] = qp + img->bitdepth_luma_qp_scale;
00386 set_chroma_qp(img, currMB);
00387 currMB->is_lossless = (Boolean) ((currMB->qp_scaled[0] == 0) && (img->lossless_qpprime_flag == 1));
00388 }
00389
00390 static void read_delta_quant(SyntaxElement *currSE, DataPartition *dP, Slice *currSlice, ImageParameters *img, Macroblock *currMB, byte *partMap, int type)
00391 {
00392 currSE->type = type;
00393
00394 dP = &(currSlice->partArr[partMap[currSE->type]]);
00395
00396 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
00397 {
00398 currSE->mapping = linfo_se;
00399 }
00400 else
00401 currSE->reading= readDquant_CABAC;
00402
00403 TRACE_STRING_P("mb_qp_delta");
00404
00405 dP->readSyntaxElement(currSE,img,dP);
00406 currMB->delta_quant = currSE->value1;
00407 if ((currMB->delta_quant < -(26 + img->bitdepth_luma_qp_scale/2)) || (currMB->delta_quant > (25 + img->bitdepth_luma_qp_scale/2)))
00408 error ("mb_qp_delta is out of range", 500);
00409
00410 img->qp = ((img->qp + currMB->delta_quant + 52 + 2*img->bitdepth_luma_qp_scale)%(52+img->bitdepth_luma_qp_scale)) -
00411 img->bitdepth_luma_qp_scale;
00412 update_qp(img, currMB, img->qp);
00413 }
00414
00421 static inline void readMBRefPictureIdx (SyntaxElement *currSE, DataPartition *dP, Macroblock *currMB, ImageParameters *img, char **cur_ref_idx, int list, int step_v0, int step_h0)
00422 {
00423 static int k, j, j0, i0;
00424 static char refframe;
00425
00426 for (j0 = 0; j0 < 4; j0 += step_v0)
00427 {
00428 img->subblock_y = j0 << 2;
00429 for (i0 = 0; i0 < 4; i0 += step_h0)
00430 {
00431 img->subblock_x = i0 << 2;
00432 k = 2 * (j0 >> 1) + (i0 >> 1);
00433
00434 if ((currMB->b8pdir[k] == list || currMB->b8pdir[k] == BI_PRED) && currMB->b8mode[k] != 0)
00435 {
00436 refframe = readRefPictureIdx(currSE, dP, currMB->b8mode[k], list);
00437
00438 for (j = j0; j < j0 + step_v0; j++)
00439 memset(&cur_ref_idx[j][img->block_x + i0], refframe, step_h0 * sizeof(char));
00440 }
00441 }
00442 }
00443 }
00444
00451 static inline void readMBMotionVectors (SyntaxElement *currSE, DataPartition *dP, Macroblock *currMB, ImageParameters *img, int list, int step_h0, int step_v0)
00452 {
00453 static int i, j, k, i4, j4, ii, jj, kk, i0, j0;
00454 static short curr_mvd[2], curr_mv[2], pred_mv[2];
00455 static short (*mvd)[4][2];
00456 static short ***mv;
00457 static int mv_mode, step_h, step_v;
00458 static char cur_ref_idx;
00459 PicMotionParams *motion = &dec_picture->motion;
00460 static PixelPos block_a, block_b, block_c, block_d;
00461
00462 for (j0=0; j0<4; j0+=step_v0)
00463 {
00464 for (i0=0; i0<4; i0+=step_h0)
00465 {
00466 kk = 2 * (j0 >> 1) + (i0 >> 1);
00467 if ((currMB->b8pdir[kk]== list || currMB->b8pdir[kk]== BI_PRED) && (currMB->b8mode[kk] !=0))
00468 {
00469 cur_ref_idx = motion->ref_idx[list][img->block_y+j0][img->block_x+i0];
00470 mv_mode = currMB->b8mode[kk];
00471 step_h = BLOCK_STEP [mv_mode][0];
00472 step_v = BLOCK_STEP [mv_mode][1];
00473
00474 for (j = j0; j < j0 + step_v0; j += step_v)
00475 {
00476 img->subblock_y = j << 2;
00477 j4 = img->block_y + j;
00478 mv = &motion->mv [list][j4];
00479 mvd = &currMB->mvd [list][j];
00480 for (i = i0; i < i0 + step_h0; i += step_h)
00481 {
00482 img->subblock_x = i << 2;
00483 i4 = img->block_x + i;
00484
00485 get_neighbors(currMB, &block_a, &block_b, &block_c, &block_d, BLOCK_SIZE * i, BLOCK_SIZE * j, 4 * step_h);
00486
00487
00488 GetMotionVectorPredictor (currMB, &block_a, &block_b, &block_c, pred_mv, cur_ref_idx, motion->ref_idx[list], motion->mv[list], BLOCK_SIZE * i, BLOCK_SIZE * j, 4*step_h, 4*step_v);
00489
00490 for (k=0; k < 2; k++)
00491 {
00492 #if TRACE
00493 static char tstring[20];
00494 sprintf( tstring, "mvd_l%d", list);
00495 strncpy(currSE->tracestring, tstring, TRACESTRING_SIZE);
00496 #endif
00497 currSE->value2 = (k << 1) + list;
00498 dP->readSyntaxElement(currSE,img,dP);
00499 curr_mvd[k] = (short) currSE->value1;
00500 curr_mv [k] = (short)(curr_mvd[k] + pred_mv[k]);
00501 }
00502
00503
00504 for(ii = i4; ii < i4 + step_h; ii++)
00505 {
00506 memcpy(&mv[0][ii][0], curr_mv, 2 * sizeof(short));
00507 }
00508
00509 for(jj = 1; jj < step_v; jj++)
00510 {
00511 memcpy(&mv[jj][i4][0], &mv[0][i4][0], 2 * step_h * sizeof(short));
00512 }
00513
00514
00515 for(ii = i; ii < i + step_h; ii++)
00516 {
00517 memcpy(&mvd[0][ii][0], curr_mvd, 2 * sizeof(short));
00518 }
00519
00520
00521 for(jj = 1; jj < step_v; jj++)
00522 {
00523 memcpy(&mvd[jj][i][0], &mvd[0][i][0], 2 * step_h * sizeof(short));
00524 }
00525 }
00526 }
00527 }
00528 }
00529 }
00530 }
00531
00532 void invScaleCoeff(ImageParameters *img, Macroblock *currMB, int level, int run, int qp_per, int i, int j, int i0, int j0, int coef_ctr, const byte (*pos_scan4x4)[2], int (*InvLevelScale4x4)[4])
00533 {
00534 if (level != 0)
00535 {
00536 coef_ctr += run + 1;
00537
00538 i0=pos_scan4x4[coef_ctr][0];
00539 j0=pos_scan4x4[coef_ctr][1];
00540
00541 currMB->cbp_blk[0] |= (int64)1 << ((j << 2) + i) ;
00542 img->cof[0][(j<<2) + j0][(i<<2) + i0]= rshift_rnd_sf((level * InvLevelScale4x4[j0][i0]) << qp_per, 4);
00543 }
00544 }
00545
00552 void start_macroblock(ImageParameters *img, Macroblock **currMB)
00553 {
00554 int mb_nr = img->current_mb_nr;
00555 *currMB = &img->mb_data[mb_nr];
00556
00557 (*currMB)->mbAddrX = mb_nr;
00558
00559
00560
00561
00562 if (img->MbaffFrameFlag)
00563 {
00564 img->mb_x = (mb_nr) % ((2*img->width) / MB_BLOCK_SIZE);
00565 img->mb_y = 2*((mb_nr) / ((2*img->width) / MB_BLOCK_SIZE));
00566
00567 img->mb_y += (img->mb_x & 0x01);
00568 img->mb_x >>= 1;
00569 }
00570 else
00571 {
00572 img->mb_x = PicPos[mb_nr][0];
00573 img->mb_y = PicPos[mb_nr][1];
00574 }
00575
00576
00577 img->block_y = img->mb_y * BLOCK_SIZE;
00578 img->block_y_aff = img->block_y;
00579 img->pix_y = img->mb_y * MB_BLOCK_SIZE;
00580 img->pix_c_y = img->mb_y * img->mb_cr_size_y;
00581
00582
00583 img->block_x = img->mb_x * BLOCK_SIZE;
00584 img->pix_x = img->mb_x * MB_BLOCK_SIZE;
00585 img->pix_c_x = img->mb_x * img->mb_cr_size_x;
00586
00587
00588
00589 (*currMB)->slice_nr = img->current_slice_nr;
00590
00591 if (img->current_slice_nr >= MAX_NUM_SLICES)
00592 {
00593 error ("Maximum number of supported slices exceeded. \nPlease recompile with increased value for MAX_NUM_SLICES", 200);
00594 }
00595
00596 dec_picture->slice_id[img->mb_y][img->mb_x] = (short) img->current_slice_nr;
00597 dec_picture->max_slice_id = (short) imax(img->current_slice_nr, dec_picture->max_slice_id);
00598
00599 CheckAvailabilityOfNeighbors(*currMB);
00600
00601
00602 update_qp(img, *currMB, img->qp);
00603 (*currMB)->mb_type = 0;
00604 (*currMB)->delta_quant = 0;
00605 (*currMB)->cbp = 0;
00606 memset((*currMB)->cbp_blk, 0, 3 * sizeof(int64));
00607 (*currMB)->c_ipred_mode = DC_PRED_8;
00608
00609 memset(&((*currMB)->mvd[0][0][0][0]),0, 2 * BLOCK_MULTIPLE * BLOCK_MULTIPLE * 2 * sizeof(short));
00610
00611 memset((*currMB)->cbp_bits, 0, 3 * sizeof(int64));
00612 memset((*currMB)->cbp_bits_8x8, 0, 3 * sizeof(int64));
00613
00614
00615 memset(&(img->mb_rres[0][0][0]), 0, 3 * MB_PIXELS * sizeof(int));
00616
00617
00618 (*currMB)->DFDisableIdc = img->currentSlice->DFDisableIdc;
00619 (*currMB)->DFAlphaC0Offset = img->currentSlice->DFAlphaC0Offset;
00620 (*currMB)->DFBetaOffset = img->currentSlice->DFBetaOffset;
00621 }
00622
00630 Boolean exit_macroblock(ImageParameters *img,int eos_bit)
00631 {
00636
00637
00638 img->num_dec_mb++;
00639
00640 if (img->num_dec_mb == img->PicSizeInMbs)
00641 {
00642 return TRUE;
00643 }
00644
00645 else
00646 {
00647
00648 img->current_mb_nr = FmoGetNextMBNr (img->current_mb_nr);
00649
00650 if (img->current_mb_nr == -1)
00651 {
00652 assert (nal_startcode_follows (img->currentSlice, eos_bit) == TRUE);
00653 return TRUE;
00654 }
00655
00656 if(nal_startcode_follows(img->currentSlice, eos_bit) == FALSE)
00657 return FALSE;
00658
00659 if(img->type == I_SLICE || img->type == SI_SLICE || active_pps->entropy_coding_mode_flag == CABAC)
00660 return TRUE;
00661 if(img->cod_counter <= 0)
00662 return TRUE;
00663 return FALSE;
00664 }
00665 }
00666
00673 static void interpret_mb_mode_P(Macroblock *currMB)
00674 {
00675 const int ICBPTAB[6] = {0,16,32,15,31,47};
00676 int mbmode = currMB->mb_type;
00677
00678 #define ZERO_P8x8 (mbmode==5)
00679 #define MODE_IS_P8x8 (mbmode==4 || mbmode==5)
00680 #define MODE_IS_I4x4 (mbmode==6)
00681 #define I16OFFSET (mbmode-7)
00682 #define MODE_IS_IPCM (mbmode==31)
00683
00684 if(mbmode <4)
00685 {
00686 currMB->mb_type = mbmode;
00687 memset(&currMB->b8mode[0],mbmode,4 * sizeof(char));
00688 memset(&currMB->b8pdir[0], 0, 4 * sizeof(char));
00689 }
00690 else if(MODE_IS_P8x8)
00691 {
00692 currMB->mb_type = P8x8;
00693 img->allrefzero = ZERO_P8x8;
00694 }
00695 else if(MODE_IS_I4x4)
00696 {
00697 currMB->mb_type = I4MB;
00698 memset(&currMB->b8mode[0],IBLOCK, 4 * sizeof(char));
00699 memset(&currMB->b8pdir[0], -1, 4 * sizeof(char));
00700 }
00701 else if(MODE_IS_IPCM)
00702 {
00703 currMB->mb_type = IPCM;
00704 currMB->cbp = -1;
00705 currMB->i16mode = 0;
00706
00707 memset(&currMB->b8mode[0], 0, 4 * sizeof(char));
00708 memset(&currMB->b8pdir[0],-1, 4 * sizeof(char));
00709 }
00710 else
00711 {
00712 currMB->mb_type = I16MB;
00713 currMB->cbp = ICBPTAB[(I16OFFSET)>>2];
00714 currMB->i16mode = (I16OFFSET) & 0x03;
00715 memset(&currMB->b8mode[0], 0, 4 * sizeof(char));
00716 memset(&currMB->b8pdir[0],-1, 4 * sizeof(char));
00717 }
00718 }
00719
00726 static void interpret_mb_mode_I(Macroblock *currMB)
00727 {
00728 static const int ICBPTAB[6] = {0,16,32,15,31,47};
00729 int mbmode = currMB->mb_type;
00730
00731 if (mbmode==0)
00732 {
00733 currMB->mb_type = I4MB;
00734 memset(&currMB->b8mode[0],IBLOCK,4 * sizeof(char));
00735 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00736 }
00737 else if(mbmode==25)
00738 {
00739 currMB->mb_type=IPCM;
00740 currMB->cbp= -1;
00741 currMB->i16mode = 0;
00742
00743 memset(&currMB->b8mode[0],0,4 * sizeof(char));
00744 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00745 }
00746 else
00747 {
00748 currMB->mb_type = I16MB;
00749 currMB->cbp= ICBPTAB[(mbmode-1)>>2];
00750 currMB->i16mode = (mbmode-1) & 0x03;
00751 memset(&currMB->b8mode[0], 0, 4 * sizeof(char));
00752 memset(&currMB->b8pdir[0],-1, 4 * sizeof(char));
00753 }
00754 }
00755
00762 static void interpret_mb_mode_B(Macroblock *currMB)
00763 {
00764 static const int offset2pdir16x16[12] = {0, 0, 1, 2, 0,0,0,0,0,0,0,0};
00765 static const int offset2pdir16x8[22][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{1,1},{0,0},{0,1},{0,0},{1,0},
00766 {0,0},{0,2},{0,0},{1,2},{0,0},{2,0},{0,0},{2,1},{0,0},{2,2},{0,0}};
00767 static const int offset2pdir8x16[22][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{1,1},{0,0},{0,1},{0,0},
00768 {1,0},{0,0},{0,2},{0,0},{1,2},{0,0},{2,0},{0,0},{2,1},{0,0},{2,2}};
00769
00770 const int ICBPTAB[6] = {0,16,32,15,31,47};
00771
00772 int i, mbmode;
00773 int mbtype = currMB->mb_type;
00774
00775
00776 if (mbtype==0)
00777 {
00778 mbmode=0;
00779 memset(&currMB->b8mode[0],0,4 * sizeof(char));
00780 memset(&currMB->b8pdir[0],2,4 * sizeof(char));
00781 }
00782 else if (mbtype==23)
00783 {
00784 mbmode=I4MB;
00785 memset(&currMB->b8mode[0],IBLOCK,4 * sizeof(char));
00786 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00787 }
00788 else if ((mbtype>23) && (mbtype<48) )
00789 {
00790 mbmode=I16MB;
00791 memset(&currMB->b8mode[0],0,4 * sizeof(char));
00792 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00793
00794 currMB->cbp = ICBPTAB[(mbtype-24)>>2];
00795 currMB->i16mode = (mbtype-24) & 0x03;
00796 }
00797 else if (mbtype==22)
00798 {
00799 mbmode=P8x8;
00800 }
00801 else if (mbtype<4)
00802 {
00803 mbmode=1;
00804 memset(&currMB->b8mode[0], 1,4 * sizeof(char));
00805 memset(&currMB->b8pdir[0],offset2pdir16x16[mbtype],4 * sizeof(char));
00806 }
00807 else if(mbtype==48)
00808 {
00809 mbmode=IPCM;
00810 memset(&currMB->b8mode[0], 0,4 * sizeof(char));
00811 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00812
00813 currMB->cbp= -1;
00814 currMB->i16mode = 0;
00815 }
00816
00817 else if ((mbtype&0x01)==0)
00818 {
00819 mbmode=2;
00820 memset(&currMB->b8mode[0], 2,4 * sizeof(char));
00821 for(i=0;i<4;i++)
00822 {
00823 currMB->b8pdir[i] = (char) offset2pdir16x8 [mbtype][i>>1];
00824 }
00825 }
00826 else
00827 {
00828 mbmode=3;
00829 memset(&currMB->b8mode[0], 3,4 * sizeof(char));
00830 for(i=0;i<4;i++)
00831 {
00832 currMB->b8pdir[i] = (char) offset2pdir8x16 [mbtype][i&0x01];
00833 }
00834 }
00835 currMB->mb_type = mbmode;
00836 }
00843 static void interpret_mb_mode_SI(Macroblock *currMB)
00844 {
00845 const int ICBPTAB[6] = {0,16,32,15,31,47};
00846 int mbmode = currMB->mb_type;
00847
00848 if (mbmode==0)
00849 {
00850 currMB->mb_type = SI4MB;
00851 memset(&currMB->b8mode[0],IBLOCK,4 * sizeof(char));
00852 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00853 img->siblock[img->mb_y][img->mb_x]=1;
00854 }
00855 else if (mbmode==1)
00856 {
00857 currMB->mb_type = I4MB;
00858 memset(&currMB->b8mode[0],IBLOCK,4 * sizeof(char));
00859 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00860 }
00861 else if(mbmode==26)
00862 {
00863 currMB->mb_type=IPCM;
00864 currMB->cbp= -1;
00865 currMB->i16mode = 0;
00866 memset(&currMB->b8mode[0],0,4 * sizeof(char));
00867 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00868 }
00869
00870 else
00871 {
00872 currMB->mb_type = I16MB;
00873 currMB->cbp= ICBPTAB[(mbmode-1)>>2];
00874 currMB->i16mode = (mbmode-2) & 0x03;
00875 memset(&currMB->b8mode[0],0,4 * sizeof(char));
00876 memset(&currMB->b8pdir[0],-1,4 * sizeof(char));
00877 }
00878 }
00879
00886 void set_interpret_mb_mode(int slice_type)
00887 {
00888 switch (slice_type)
00889 {
00890 case P_SLICE: case SP_SLICE:
00891 interpret_mb_mode = interpret_mb_mode_P;
00892 break;
00893 case B_SLICE:
00894 interpret_mb_mode = interpret_mb_mode_B;
00895 break;
00896 case I_SLICE:
00897 interpret_mb_mode = interpret_mb_mode_I;
00898 break;
00899 case SI_SLICE:
00900 interpret_mb_mode = interpret_mb_mode_SI;
00901 break;
00902 default:
00903 printf("Unsupported slice type\n");
00904 break;
00905 }
00906 }
00913 static void init_macroblock(ImageParameters *img)
00914 {
00915 int i, j, k;
00916 PicMotionParams *motion = &dec_picture->motion;
00917 for(j = img->block_y; j < img->block_y + BLOCK_SIZE; j++)
00918 memset(&img->ipredmode[j][img->block_x], DC_PRED, BLOCK_SIZE * sizeof(char));
00919
00920 for (k = LIST_0; k <= LIST_1; k++)
00921 {
00922
00923 for(j = img->block_y; j < img->block_y + BLOCK_SIZE; j++)
00924 {
00925 memset(&motion->mv[k][j][img->block_x][0], 0, 2 * BLOCK_SIZE * sizeof(short));
00926 }
00927
00928 for(j = img->block_y; j < img->block_y + BLOCK_SIZE; j++)
00929 {
00930 memset(&motion->ref_idx[k][j][img->block_x], -1, BLOCK_SIZE * sizeof(char));
00931 }
00932
00933 for(j = img->block_y; j < img->block_y + BLOCK_SIZE; j++)
00934 {
00935 for (i = img->block_x; i < img->block_x + BLOCK_SIZE;i++)
00936 {
00937 motion->ref_pic_id[k][j][i] = INT64_MIN;
00938 }
00939 }
00940 }
00941 }
00942
00943
00950 void SetB8Mode (ImageParameters* img, Macroblock* currMB, int value, int i)
00951 {
00952 static const char p_v2b8 [ 5] = {4, 5, 6, 7, IBLOCK};
00953 static const char p_v2pd [ 5] = {0, 0, 0, 0, -1};
00954 static const char b_v2b8 [14] = {0, 4, 4, 4, 5, 6, 5, 6, 5, 6, 7, 7, 7, IBLOCK};
00955 static const char b_v2pd [14] = {2, 0, 1, 2, 0, 0, 1, 1, 2, 2, 0, 1, 2, -1};
00956
00957 if (img->type==B_SLICE)
00958 {
00959 currMB->b8mode[i] = b_v2b8[value];
00960 currMB->b8pdir[i] = b_v2pd[value];
00961 }
00962 else
00963 {
00964 currMB->b8mode[i] = p_v2b8[value];
00965 currMB->b8pdir[i] = p_v2pd[value];
00966 }
00967 }
00968
00969
00970 void reset_coeffs(void)
00971 {
00972
00973
00974 memset(&img->cof[0][0][0], 0, 3 * MB_PIXELS * sizeof(int));
00975
00976
00977 if (active_pps->entropy_coding_mode_flag == UVLC)
00978 memset(&img->nz_coeff[img->current_mb_nr][0][0][0], 0, 3 * BLOCK_SIZE * BLOCK_SIZE * sizeof(byte));
00979 }
00980
00981 void field_flag_inference(Macroblock *currMB)
00982 {
00983 if (currMB->mbAvailA)
00984 {
00985 currMB->mb_field = img->mb_data[currMB->mbAddrA].mb_field;
00986 }
00987 else
00988 {
00989
00990 currMB->mb_field = currMB->mbAvailB ? img->mb_data[currMB->mbAddrB].mb_field : 0;
00991 }
00992 }
00993
00994
00995 void skip_macroblock(ImageParameters *img, Macroblock *currMB)
00996 {
00997 short pred_mv[2];
00998 int zeroMotionAbove;
00999 int zeroMotionLeft;
01000 static PixelPos mb_a, mb_b, mb_c, mb_d;
01001 int i, j;
01002 int a_mv_y = 0;
01003 int a_ref_idx = 0;
01004 int b_mv_y = 0;
01005 int b_ref_idx = 0;
01006 int img_block_y = img->block_y;
01007 int list_offset = ((img->MbaffFrameFlag)&&(currMB->mb_field))? (img->current_mb_nr & 0x01) ? 4 : 2 : 0;
01008 PicMotionParams *motion = &dec_picture->motion;
01009 static short *a_mv = NULL;
01010 static short *b_mv = NULL;
01011
01012 get_neighbors(currMB, &mb_a, &mb_b, &mb_c, &mb_d, 0, 0, MB_BLOCK_SIZE);
01013
01014 if (mb_a.available)
01015 {
01016 a_mv = motion->mv[LIST_0][mb_a.pos_y][mb_a.pos_x];
01017 a_mv_y = a_mv[1];
01018 a_ref_idx = motion->ref_idx[LIST_0][mb_a.pos_y][mb_a.pos_x];
01019
01020 if (currMB->mb_field && !img->mb_data[mb_a.mb_addr].mb_field)
01021 {
01022 a_mv_y /=2;
01023 a_ref_idx *=2;
01024 }
01025 if (!currMB->mb_field && img->mb_data[mb_a.mb_addr].mb_field)
01026 {
01027 a_mv_y *=2;
01028 a_ref_idx >>=1;
01029 }
01030 }
01031
01032 if (mb_b.available)
01033 {
01034 b_mv = motion->mv[LIST_0][mb_b.pos_y][mb_b.pos_x];
01035 b_mv_y = b_mv[1];
01036 b_ref_idx = motion->ref_idx[LIST_0][mb_b.pos_y][mb_b.pos_x];
01037
01038 if (currMB->mb_field && !img->mb_data[mb_b.mb_addr].mb_field)
01039 {
01040 b_mv_y /=2;
01041 b_ref_idx *=2;
01042 }
01043 if (!currMB->mb_field && img->mb_data[mb_b.mb_addr].mb_field)
01044 {
01045 b_mv_y *=2;
01046 b_ref_idx >>=1;
01047 }
01048 }
01049
01050 zeroMotionLeft = !mb_a.available ? 1 : a_ref_idx==0 && a_mv[0]==0 && a_mv_y==0 ? 1 : 0;
01051 zeroMotionAbove = !mb_b.available ? 1 : b_ref_idx==0 && b_mv[0]==0 && b_mv_y==0 ? 1 : 0;
01052
01053 currMB->cbp = 0;
01054 reset_coeffs();
01055
01056 if (zeroMotionAbove || zeroMotionLeft)
01057 {
01058 for(j = img_block_y; j < img_block_y + BLOCK_SIZE;j++)
01059 {
01060 memset(&motion->mv[LIST_0][j][img->block_x][0], 0, 2 * BLOCK_SIZE * sizeof(short));
01061 }
01062 }
01063 else
01064 {
01065 GetMotionVectorPredictor (currMB, &mb_a, &mb_b, &mb_c, pred_mv, 0, motion->ref_idx[LIST_0], motion->mv[LIST_0], 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
01066
01067
01068 for(i=img->block_x;i<img->block_x + BLOCK_SIZE;i++)
01069 memcpy(&motion->mv[LIST_0][img_block_y][i][0], &pred_mv[0], 2 * sizeof(short));
01070
01071
01072 for(j=img_block_y; j < img_block_y + BLOCK_SIZE - 1;j++)
01073 {
01074 memcpy(&motion->mv[LIST_0][j + 1][img->block_x][0], &motion->mv[LIST_0][j][img->block_x][0], 2 * BLOCK_SIZE * sizeof(short));
01075 }
01076 }
01077
01078
01079 for(j=img_block_y;j< img_block_y + BLOCK_SIZE;j++)
01080 {
01081 memset(&motion->ref_idx[LIST_0][j][img->block_x], 0, BLOCK_SIZE * sizeof(char));
01082 }
01083
01084
01085
01086 for(i=img->block_x;i<img->block_x + BLOCK_SIZE;i++)
01087 {
01088 motion->ref_pic_id[LIST_0][img_block_y][i] =
01089 dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][0];
01090 }
01091
01092 for(j=img_block_y;j< img_block_y + BLOCK_SIZE - 1;j++)
01093 {
01094 memcpy(&motion->ref_pic_id[LIST_0][j + 1][img->block_x], &motion->ref_pic_id[LIST_0][j][img->block_x], BLOCK_SIZE * sizeof(int64));
01095 }
01096 }
01097
01098 static void concealIPCMcoeffs(ImageParameters *img)
01099 {
01100 int i, j, k;
01101
01102 for(i=0;i<MB_BLOCK_SIZE;i++)
01103 {
01104 for(j=0;j<MB_BLOCK_SIZE;j++)
01105 {
01106 img->cof[0][i][j] = img->dc_pred_value_comp[0];
01107
01108 }
01109 }
01110
01111 if ((dec_picture->chroma_format_idc != YUV400) && !IS_INDEPENDENT(img))
01112 {
01113 for (k = 0; k < 2; k++)
01114 {
01115 for(i=0;i<img->mb_cr_size_y;i++)
01116 {
01117 for(j=0;j<img->mb_cr_size_x;j++)
01118 {
01119 img->cof[k][i][j] = img->dc_pred_value_comp[k];
01120
01121 }
01122 }
01123 }
01124 }
01125 }
01126
01127
01134 void read_one_macroblock(ImageParameters *img, Slice *currSlice, Macroblock *currMB)
01135 {
01136 int i;
01137
01138 SyntaxElement currSE;
01139 int mb_nr = img->current_mb_nr;
01140
01141 DataPartition *dP;
01142 byte *partMap = assignSE2partition[currSlice->dp_mode];
01143 Macroblock *topMB = NULL;
01144 int prevMbSkipped = 0;
01145 int check_bottom, read_bottom, read_top;
01146 PicMotionParams *motion = &dec_picture->motion;
01147
01148 if (img->MbaffFrameFlag)
01149 {
01150 if (mb_nr&0x01)
01151 {
01152 topMB= &img->mb_data[mb_nr-1];
01153 if(!(img->type == B_SLICE))
01154 prevMbSkipped = (topMB->mb_type == 0);
01155 else
01156 prevMbSkipped = topMB->skip_flag;
01157 }
01158 else
01159 prevMbSkipped = 0;
01160 }
01161
01162 currMB->mb_field = ((mb_nr&0x01) == 0)? 0 : img->mb_data[mb_nr-1].mb_field;
01163
01164 update_qp(img, currMB, img->qp);
01165 currSE.type = SE_MBTYPE;
01166
01167
01168 dP = &(currSlice->partArr[partMap[currSE.type]]);
01169
01170 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
01171 currSE.mapping = linfo_ue;
01172
01173 if(img->type == I_SLICE || img->type == SI_SLICE)
01174 {
01175
01176 if (img->MbaffFrameFlag && (mb_nr&0x01)==0)
01177 {
01178 TRACE_STRING("mb_field_decoding_flag");
01179 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
01180 {
01181 currSE.len = (int64) 1;
01182 readSyntaxElement_FLC(&currSE, dP->bitstream);
01183 }
01184 else
01185 {
01186 currSE.reading = readFieldModeInfo_CABAC;
01187 dP->readSyntaxElement(&currSE,img,dP);
01188 }
01189 currMB->mb_field = currSE.value1;
01190 }
01191
01192 if(active_pps->entropy_coding_mode_flag == CABAC)
01193 CheckAvailabilityOfNeighborsCABAC(currMB);
01194
01195
01196 TRACE_STRING("mb_type");
01197 currSE.reading = readMB_typeInfo_CABAC;
01198 dP->readSyntaxElement(&currSE,img,dP);
01199
01200 currMB->mb_type = currSE.value1;
01201 if(!dP->bitstream->ei_flag)
01202 currMB->ei_flag = 0;
01203 }
01204
01205 else if (active_pps->entropy_coding_mode_flag == CABAC)
01206 {
01207
01208 if (img->MbaffFrameFlag && ((mb_nr&0x01) == 0||prevMbSkipped))
01209 field_flag_inference(currMB);
01210
01211 CheckAvailabilityOfNeighborsCABAC(currMB);
01212 TRACE_STRING("mb_skip_flag");
01213 currSE.reading = readMB_skip_flagInfo_CABAC;
01214 dP->readSyntaxElement(&currSE,img,dP);
01215
01216 currMB->mb_type = currSE.value1;
01217 currMB->skip_flag = !(currSE.value1);
01218
01219 if (img->type==B_SLICE)
01220 currMB->cbp = currSE.value2;
01221
01222 if (!dP->bitstream->ei_flag)
01223 currMB->ei_flag = 0;
01224
01225 if ((img->type == B_SLICE) && currSE.value1 == 0 && currSE.value2 == 0)
01226 img->cod_counter=0;
01227
01228
01229 if (img->MbaffFrameFlag)
01230 {
01231 check_bottom=read_bottom=read_top=0;
01232 if ((mb_nr&0x01)==0)
01233 {
01234 check_bottom = currMB->skip_flag;
01235 read_top = !check_bottom;
01236 }
01237 else
01238 {
01239 read_bottom = (topMB->skip_flag && (!currMB->skip_flag));
01240 }
01241
01242 if (read_bottom || read_top)
01243 {
01244 TRACE_STRING("mb_field_decoding_flag");
01245 currSE.reading = readFieldModeInfo_CABAC;
01246 dP->readSyntaxElement(&currSE,img,dP);
01247 currMB->mb_field = currSE.value1;
01248 }
01249 if (check_bottom)
01250 check_next_mb_and_get_field_mode_CABAC(&currSE,img,dP);
01251 }
01252
01253 CheckAvailabilityOfNeighborsCABAC(currMB);
01254
01255
01256 if (currMB->mb_type != 0 )
01257 {
01258 currSE.reading = readMB_typeInfo_CABAC;
01259 TRACE_STRING("mb_type");
01260 dP->readSyntaxElement(&currSE,img,dP);
01261 currMB->mb_type = currSE.value1;
01262 if(!dP->bitstream->ei_flag)
01263 currMB->ei_flag = 0;
01264 }
01265 }
01266
01267 else
01268 {
01269 if(img->cod_counter == -1)
01270 {
01271 TRACE_STRING("mb_skip_run");
01272 dP->readSyntaxElement(&currSE,img,dP);
01273 img->cod_counter = currSE.value1;
01274 }
01275 if (img->cod_counter==0)
01276 {
01277
01278 if ((img->MbaffFrameFlag) && (((mb_nr&0x01)==0) || ((mb_nr&0x01) && prevMbSkipped)))
01279 {
01280 TRACE_STRING("mb_field_decoding_flag");
01281 currSE.len = (int64) 1;
01282 readSyntaxElement_FLC(&currSE, dP->bitstream);
01283 currMB->mb_field = currSE.value1;
01284 }
01285
01286
01287 TRACE_STRING("mb_type");
01288 dP->readSyntaxElement(&currSE,img,dP);
01289 if(img->type == P_SLICE || img->type == SP_SLICE)
01290 currSE.value1++;
01291 currMB->mb_type = currSE.value1;
01292 if(!dP->bitstream->ei_flag)
01293 currMB->ei_flag = 0;
01294 img->cod_counter--;
01295 currMB->skip_flag = 0;
01296 }
01297 else
01298 {
01299 img->cod_counter--;
01300 currMB->mb_type = 0;
01301 currMB->ei_flag = 0;
01302 currMB->skip_flag = 1;
01303
01304
01305 if(img->MbaffFrameFlag)
01306 {
01307 if(img->cod_counter == 0 && ((mb_nr&0x01) == 0))
01308 {
01309 TRACE_STRING("mb_field_decoding_flag (of coded bottom mb)");
01310 currSE.len = (int64) 1;
01311 readSyntaxElement_FLC(&currSE, dP->bitstream);
01312 dP->bitstream->frame_bitoffset--;
01313 TRACE_DECBITS(1);
01314 currMB->mb_field = currSE.value1;
01315 }
01316 else if (img->cod_counter > 0 && ((mb_nr & 0x01) == 0))
01317 {
01318
01319 if (mb_is_available(mb_nr - 2, currMB) && ((mb_nr % (img->PicWidthInMbs * 2))!=0))
01320 {
01321 currMB->mb_field = img->mb_data[mb_nr-2].mb_field;
01322 }
01323 else
01324 {
01325
01326 if (mb_is_available(mb_nr - 2*img->PicWidthInMbs, currMB))
01327 {
01328 currMB->mb_field = img->mb_data[mb_nr-2*img->PicWidthInMbs].mb_field;
01329 }
01330 else
01331 currMB->mb_field = 0;
01332 }
01333 }
01334 }
01335 }
01336 }
01337
01338 motion->mb_field[mb_nr] = (byte) currMB->mb_field;
01339
01340 img->block_y_aff = ((img->MbaffFrameFlag) && (currMB->mb_field)) ? (mb_nr&0x01) ? (img->block_y - 4)>>1 : img->block_y >> 1 : img->block_y;
01341 img->siblock[img->mb_y][img->mb_x]=0;
01342 interpret_mb_mode(currMB);
01343
01344 if(img->MbaffFrameFlag)
01345 {
01346 if(currMB->mb_field)
01347 {
01348 img->num_ref_idx_l0_active <<=1;
01349 img->num_ref_idx_l1_active <<=1;
01350 }
01351 }
01352
01353
01354 currMB->NoMbPartLessThan8x8Flag = (IS_DIRECT(currMB) && !(active_sps->direct_8x8_inference_flag))? 0: 1;
01355
01356
01357 if (currMB->mb_type == P8x8)
01358 {
01359 currSE.type = SE_MBTYPE;
01360 dP = &(currSlice->partArr[partMap[SE_MBTYPE]]);
01361
01362 if (active_pps->entropy_coding_mode_flag ==UVLC || dP->bitstream->ei_flag)
01363 currSE.mapping = linfo_ue;
01364 else
01365 currSE.reading = readB8_typeInfo_CABAC;
01366
01367 for (i = 0; i < 4; i++)
01368 {
01369 TRACE_STRING("sub_mb_type");
01370 dP->readSyntaxElement (&currSE, img, dP);
01371 SetB8Mode (img, currMB, currSE.value1, i);
01372
01373
01374 currMB->NoMbPartLessThan8x8Flag &= (currMB->b8mode[i]==0 && active_sps->direct_8x8_inference_flag) ||
01375 (currMB->b8mode[i]==4);
01376 }
01377
01378 init_macroblock (img);
01379 readMotionInfoFromNAL (img, currSlice, currMB);
01380 }
01381
01382
01383
01384
01385 if (currMB->mb_type == I4MB && img->Transform8x8Mode)
01386 {
01387 currSE.type = SE_HEADER;
01388 dP = &(currSlice->partArr[partMap[SE_HEADER]]);
01389 currSE.reading = readMB_transform_size_flag_CABAC;
01390 TRACE_STRING("transform_size_8x8_flag");
01391
01392
01393 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
01394 {
01395 currSE.len = (int64) 1;
01396 readSyntaxElement_FLC(&currSE, dP->bitstream);
01397 }
01398 else
01399 {
01400 dP->readSyntaxElement(&currSE,img,dP);
01401 }
01402
01403 currMB->luma_transform_size_8x8_flag = currSE.value1;
01404
01405 if (currMB->luma_transform_size_8x8_flag)
01406 {
01407 currMB->mb_type = I8MB;
01408 memset(&currMB->b8mode, I8MB, 4 * sizeof(char));
01409 memset(&currMB->b8pdir, -1, 4 * sizeof(char));
01410 }
01411 }
01412 else
01413 {
01414 currMB->luma_transform_size_8x8_flag = 0;
01415 }
01416
01417 if(active_pps->constrained_intra_pred_flag && (img->type == P_SLICE || img->type == B_SLICE))
01418 {
01419 if( !IS_INTRA(currMB) )
01420 {
01421 img->intra_block[mb_nr] = 0;
01422 }
01423 }
01424
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01442
01443
01444
01445 if (currMB->mb_type != P8x8)
01446 init_macroblock(img);
01447
01448 if (IS_DIRECT (currMB) && img->cod_counter >= 0)
01449 {
01450 currMB->cbp = 0;
01451 reset_coeffs();
01452
01453 if (active_pps->entropy_coding_mode_flag ==CABAC)
01454 img->cod_counter=-1;
01455 }
01456 else if (IS_SKIP (currMB))
01457 {
01458 skip_macroblock(img, currMB);
01459 }
01460 else if(currMB->mb_type != IPCM)
01461 {
01462
01463 if (IS_INTRA(currMB))
01464 read_ipred_modes(img, currSlice, currMB);
01465
01466
01467 if (IS_INTERMV (currMB) && (currMB->mb_type != P8x8))
01468 {
01469 readMotionInfoFromNAL (img, currSlice, currMB);
01470 }
01471
01472 readCBPandCoeffsFromNAL (img, currSlice, currMB);
01473 }
01474 else
01475 {
01476
01477
01478
01479
01480 if ( currSlice->dp_mode && currSlice->dpB_NotPresent )
01481 {
01482 concealIPCMcoeffs(img);
01483 }
01484 else
01485 {
01486 dP = &(currSlice->partArr[partMap[SE_LUM_DC_INTRA]]);
01487 readIPCMcoeffsFromNAL(img, dP);
01488 }
01489 }
01490
01491 return;
01492 }
01493
01494
01505 static void init_decoding_engine_IPCM(ImageParameters *img)
01506 {
01507 Slice *currSlice = img->currentSlice;
01508 Bitstream *currStream;
01509 int ByteStartPosition;
01510 int PartitionNumber;
01511 int i;
01512
01513 if(currSlice->dp_mode==PAR_DP_1)
01514 PartitionNumber=1;
01515 else if(currSlice->dp_mode==PAR_DP_3)
01516 PartitionNumber=3;
01517 else
01518 {
01519 printf("Partition Mode is not supported\n");
01520 exit(1);
01521 }
01522
01523 for(i=0;i<PartitionNumber;i++)
01524 {
01525 currStream = currSlice->partArr[i].bitstream;
01526 ByteStartPosition = currStream->read_len;
01527
01528 arideco_start_decoding (&currSlice->partArr[i].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len);
01529 }
01530 }
01531
01532
01533
01534
01546 static void readIPCMcoeffsFromNAL(ImageParameters *img, struct datapartition *dP)
01547 {
01548 SyntaxElement currSE;
01549 int i,j;
01550
01551
01552
01553 if(active_pps->entropy_coding_mode_flag == CABAC)
01554 {
01555 readIPCM_CABAC(dP);
01556 init_decoding_engine_IPCM(img);
01557 }
01558 else
01559 {
01560
01561
01562 if(((dP->bitstream->frame_bitoffset) & 0x07) != 0)
01563 {
01564 TRACE_STRING("pcm_alignment_zero_bit");
01565 currSE.len = (8 - ((dP->bitstream->frame_bitoffset) & 0x07));
01566 readSyntaxElement_FLC(&currSE, dP->bitstream);
01567 }
01568
01569
01570 currSE.len=img->bitdepth_luma;
01571 TRACE_STRING("pcm_sample_luma");
01572
01573 for(i=0;i<MB_BLOCK_SIZE;i++)
01574 {
01575 for(j=0;j<MB_BLOCK_SIZE;j++)
01576 {
01577 readSyntaxElement_FLC(&currSE, dP->bitstream);
01578 img->cof[0][i][j] = currSE.value1;
01579
01580 }
01581 }
01582 currSE.len=img->bitdepth_chroma;
01583 if ((dec_picture->chroma_format_idc != YUV400) && !IS_INDEPENDENT(img))
01584 {
01585 TRACE_STRING("pcm_sample_chroma (u)");
01586 for(i=0;i<img->mb_cr_size_y;i++)
01587 {
01588 for(j=0;j<img->mb_cr_size_x;j++)
01589 {
01590 readSyntaxElement_FLC(&currSE, dP->bitstream);
01591 img->cof[1][i][j] = currSE.value1;
01592
01593 }
01594 }
01595 TRACE_STRING("pcm_sample_chroma (v)");
01596 for(i=0;i<img->mb_cr_size_y;i++)
01597 {
01598 for(j=0;j<img->mb_cr_size_x;j++)
01599 {
01600 readSyntaxElement_FLC(&currSE, dP->bitstream);
01601 img->cof[2][i][j] = currSE.value1;
01602
01603 }
01604 }
01605 }
01606 }
01607 }
01608
01609
01619 static void read_ipred_modes(ImageParameters *img, Slice *currSlice, Macroblock *currMB)
01620 {
01621 int b8,i,j,bi,bj,bx,by,dec;
01622 SyntaxElement currSE;
01623 DataPartition *dP;
01624 byte *partMap = assignSE2partition[currSlice->dp_mode];
01625 int ts, ls;
01626 int mostProbableIntraPredMode;
01627 int upIntraPredMode;
01628 int leftIntraPredMode;
01629 char IntraChromaPredModeFlag = IS_INTRA(currMB);
01630 int bs_x, bs_y;
01631 int ii,jj;
01632
01633 PixelPos left_block, top_block;
01634
01635 currSE.type = SE_INTRAPREDMODE;
01636
01637 TRACE_STRING("intra4x4_pred_mode");
01638 dP = &(currSlice->partArr[partMap[currSE.type]]);
01639
01640 if (!(active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag))
01641 currSE.reading = readIntraPredMode_CABAC;
01642
01643 for(b8 = 0; b8 < 4; b8++)
01644 {
01645 if((currMB->b8mode[b8]==IBLOCK )||(currMB->b8mode[b8]==I8MB))
01646 {
01647 bs_x = bs_y = (currMB->b8mode[b8] == I8MB)?8:4;
01648
01649 IntraChromaPredModeFlag = 1;
01650
01651 ii = (bs_x>>2);
01652 jj = (bs_y>>2);
01653
01654 for(j=0;j<2;j+=jj)
01655 {
01656 by = (b8&2) + j;
01657 bj = img->block_y + by;
01658 for(i=0;i<2;i+=ii)
01659 {
01660 bx = ((b8&1)<<1) + i;
01661 bi = img->block_x + bx;
01662
01663 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
01664 readSyntaxElement_Intra4x4PredictionMode(&currSE,img,dP->bitstream);
01665 else
01666 {
01667 currSE.context=(b8<<2)+(j<<1) +i;
01668 dP->readSyntaxElement(&currSE,img,dP);
01669 }
01670
01671 get4x4Neighbour(currMB, (bx<<2) - 1, (by<<2), img->mb_size[IS_LUMA], &left_block);
01672 get4x4Neighbour(currMB, (bx<<2), (by<<2) - 1, img->mb_size[IS_LUMA], &top_block );
01673
01674
01675
01676 if (active_pps->constrained_intra_pred_flag)
01677 {
01678 left_block.available = left_block.available ? img->intra_block[left_block.mb_addr] : 0;
01679 top_block.available = top_block.available ? img->intra_block[top_block.mb_addr] : 0;
01680 }
01681
01682
01683 ts = ls = 0;
01684 if (currMB->mb_type == I4MB && img->type == SI_SLICE)
01685 {
01686 if (left_block.available)
01687 if (img->siblock [left_block.pos_y][left_block.pos_x])
01688 ls=1;
01689
01690 if (top_block.available)
01691 if (img->siblock [top_block.pos_y][top_block.pos_x])
01692 ts=1;
01693 }
01694
01695 upIntraPredMode = (top_block.available &&(ts == 0)) ? img->ipredmode[top_block.pos_y ][top_block.pos_x ] : -1;
01696 leftIntraPredMode = (left_block.available &&(ls == 0)) ? img->ipredmode[left_block.pos_y][left_block.pos_x] : -1;
01697
01698 mostProbableIntraPredMode = (upIntraPredMode < 0 || leftIntraPredMode < 0) ? DC_PRED : upIntraPredMode < leftIntraPredMode ? upIntraPredMode : leftIntraPredMode;
01699
01700 dec = (currSE.value1 == -1) ? mostProbableIntraPredMode : currSE.value1 + (currSE.value1 >= mostProbableIntraPredMode);
01701
01702
01703 for(jj = 0; jj < (bs_y >> 2); jj++)
01704 {
01705 memset(&(img->ipredmode[bj + jj][bi]), dec, (bs_x>>2) * sizeof(char));
01706 }
01707 }
01708 }
01709 }
01710 }
01711
01712 if (IntraChromaPredModeFlag && (dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444))
01713 {
01714 currSE.type = SE_INTRAPREDMODE;
01715 TRACE_STRING("intra_chroma_pred_mode");
01716 dP = &(currSlice->partArr[partMap[currSE.type]]);
01717
01718 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
01719 currSE.mapping = linfo_ue;
01720 else
01721 currSE.reading = readCIPredMode_CABAC;
01722
01723 dP->readSyntaxElement(&currSE,img,dP);
01724 currMB->c_ipred_mode = currSE.value1;
01725
01726 if (currMB->c_ipred_mode < DC_PRED_8 || currMB->c_ipred_mode > PLANE_8)
01727 {
01728 error("illegal chroma intra pred mode!\n", 600);
01729 }
01730 }
01731 }
01732
01733
01740 void get_neighbors(Macroblock *currMB,
01741 PixelPos *block_a,
01742 PixelPos *block_b,
01743 PixelPos *block_c,
01744 PixelPos *block_d,
01745 int mb_x,
01746 int mb_y,
01747 int blockshape_x
01748 )
01749 {
01750 int *mb_size = img->mb_size[IS_LUMA];
01751
01752 get4x4Neighbour(currMB, mb_x - 1, mb_y , mb_size, block_a);
01753 get4x4Neighbour(currMB, mb_x, mb_y - 1, mb_size, block_b);
01754 get4x4Neighbour(currMB, mb_x + blockshape_x, mb_y - 1, mb_size, block_c);
01755 get4x4Neighbour(currMB, mb_x - 1, mb_y - 1, mb_size, block_d);
01756
01757 if (mb_y > 0)
01758 {
01759 if (mb_x < 8)
01760 {
01761 if (mb_y == 8 )
01762 {
01763 if (blockshape_x == MB_BLOCK_SIZE)
01764 block_c->available = 0;
01765 }
01766 else if (mb_x+blockshape_x == 8)
01767 {
01768 block_c->available = 0;
01769 }
01770 }
01771 else if (mb_x + blockshape_x == MB_BLOCK_SIZE)
01772 {
01773 block_c->available = 0;
01774 }
01775 }
01776
01777 if (!block_c->available)
01778 {
01779 *block_c = *block_d;
01780 }
01781 }
01782
01783
01790 void GetMotionVectorPredictor (Macroblock *currMB,
01791 PixelPos *block_a,
01792 PixelPos *block_b,
01793 PixelPos *block_c,
01794 short pmv[2],
01795 char ref_frame,
01796 char **refPic,
01797 short ***tmp_mv,
01798 int mb_x,
01799 int mb_y,
01800 int blockshape_x,
01801 int blockshape_y)
01802 {
01803 int mv_a, mv_b, mv_c, pred_vec=0;
01804 int mvPredType, rFrameL, rFrameU, rFrameUR;
01805 int hv;
01806
01807 mvPredType = MVPRED_MEDIAN;
01808
01809 if (!img->MbaffFrameFlag)
01810 {
01811 rFrameL = block_a->available ? refPic[block_a->pos_y][block_a->pos_x] : -1;
01812 rFrameU = block_b->available ? refPic[block_b->pos_y][block_b->pos_x] : -1;
01813 rFrameUR = block_c->available ? refPic[block_c->pos_y][block_c->pos_x] : -1;
01814 }
01815 else
01816 {
01817 if (currMB->mb_field)
01818 {
01819 rFrameL = block_a->available
01820 ? (img->mb_data[block_a->mb_addr].mb_field
01821 ? refPic[block_a->pos_y][block_a->pos_x]
01822 : refPic[block_a->pos_y][block_a->pos_x] * 2) : -1;
01823 rFrameU = block_b->available
01824 ? (img->mb_data[block_b->mb_addr].mb_field
01825 ? refPic[block_b->pos_y][block_b->pos_x]
01826 : refPic[block_b->pos_y][block_b->pos_x] * 2) : -1;
01827 rFrameUR = block_c->available
01828 ? (img->mb_data[block_c->mb_addr].mb_field
01829 ? refPic[block_c->pos_y][block_c->pos_x]
01830 : refPic[block_c->pos_y][block_c->pos_x] * 2) : -1;
01831 }
01832 else
01833 {
01834 rFrameL = block_a->available
01835 ? (img->mb_data[block_a->mb_addr].mb_field
01836 ? refPic[block_a->pos_y][block_a->pos_x] >>1
01837 : refPic[block_a->pos_y][block_a->pos_x]) : -1;
01838 rFrameU = block_b->available
01839 ? (img->mb_data[block_b->mb_addr].mb_field
01840 ? refPic[block_b->pos_y][block_b->pos_x] >>1
01841 : refPic[block_b->pos_y][block_b->pos_x]) : -1;
01842 rFrameUR = block_c->available
01843 ? (img->mb_data[block_c->mb_addr].mb_field
01844 ? refPic[block_c->pos_y][block_c->pos_x] >>1
01845 : refPic[block_c->pos_y][block_c->pos_x]) : -1;
01846 }
01847 }
01848
01849
01850
01851
01852 if (rFrameL == ref_frame && rFrameU != ref_frame && rFrameUR != ref_frame)
01853 mvPredType = MVPRED_L;
01854 else if(rFrameL != ref_frame && rFrameU == ref_frame && rFrameUR != ref_frame)
01855 mvPredType = MVPRED_U;
01856 else if(rFrameL != ref_frame && rFrameU != ref_frame && rFrameUR == ref_frame)
01857 mvPredType = MVPRED_UR;
01858
01859 if(blockshape_x == 8 && blockshape_y == 16)
01860 {
01861 if(mb_x == 0)
01862 {
01863 if(rFrameL == ref_frame)
01864 mvPredType = MVPRED_L;
01865 }
01866 else
01867 {
01868 if( rFrameUR == ref_frame)
01869 mvPredType = MVPRED_UR;
01870 }
01871 }
01872 else if(blockshape_x == 16 && blockshape_y == 8)
01873 {
01874 if(mb_y == 0)
01875 {
01876 if(rFrameU == ref_frame)
01877 mvPredType = MVPRED_U;
01878 }
01879 else
01880 {
01881 if(rFrameL == ref_frame)
01882 mvPredType = MVPRED_L;
01883 }
01884 }
01885
01886 for (hv=0; hv < 2; hv++)
01887 {
01888 if (!img->MbaffFrameFlag || hv == 0)
01889 {
01890 mv_a = block_a->available ? tmp_mv[block_a->pos_y][block_a->pos_x][hv] : 0;
01891 mv_b = block_b->available ? tmp_mv[block_b->pos_y][block_b->pos_x][hv] : 0;
01892 mv_c = block_c->available ? tmp_mv[block_c->pos_y][block_c->pos_x][hv] : 0;
01893 }
01894 else
01895 {
01896 if (currMB->mb_field)
01897 {
01898 mv_a = block_a->available ? img->mb_data[block_a->mb_addr].mb_field
01899 ? tmp_mv[block_a->pos_y][block_a->pos_x][hv]
01900 : tmp_mv[block_a->pos_y][block_a->pos_x][hv] / 2
01901 : 0;
01902 mv_b = block_b->available ? img->mb_data[block_b->mb_addr].mb_field
01903 ? tmp_mv[block_b->pos_y][block_b->pos_x][hv]
01904 : tmp_mv[block_b->pos_y][block_b->pos_x][hv] / 2
01905 : 0;
01906 mv_c = block_c->available ? img->mb_data[block_c->mb_addr].mb_field
01907 ? tmp_mv[block_c->pos_y][block_c->pos_x][hv]
01908 : tmp_mv[block_c->pos_y][block_c->pos_x][hv] / 2
01909 : 0;
01910 }
01911 else
01912 {
01913 mv_a = block_a->available ? img->mb_data[block_a->mb_addr].mb_field
01914 ? tmp_mv[block_a->pos_y][block_a->pos_x][hv] * 2
01915 : tmp_mv[block_a->pos_y][block_a->pos_x][hv]
01916 : 0;
01917 mv_b = block_b->available ? img->mb_data[block_b->mb_addr].mb_field
01918 ? tmp_mv[block_b->pos_y][block_b->pos_x][hv] * 2
01919 : tmp_mv[block_b->pos_y][block_b->pos_x][hv]
01920 : 0;
01921 mv_c = block_c->available ? img->mb_data[block_c->mb_addr].mb_field
01922 ? tmp_mv[block_c->pos_y][block_c->pos_x][hv] * 2
01923 : tmp_mv[block_c->pos_y][block_c->pos_x][hv]
01924 : 0;
01925 }
01926 }
01927
01928 switch (mvPredType)
01929 {
01930 case MVPRED_MEDIAN:
01931 if(!(block_b->available || block_c->available))
01932 {
01933 pred_vec = mv_a;
01934 }
01935 else
01936 {
01937 pred_vec = mv_a + mv_b + mv_c - imin(mv_a, imin(mv_b, mv_c)) - imax(mv_a, imax(mv_b, mv_c));
01938 }
01939 break;
01940 case MVPRED_L:
01941 pred_vec = mv_a;
01942 break;
01943 case MVPRED_U:
01944 pred_vec = mv_b;
01945 break;
01946 case MVPRED_UR:
01947 pred_vec = mv_c;
01948 break;
01949 default:
01950 break;
01951 }
01952
01953 pmv[hv] = (short) pred_vec;
01954 }
01955 }
01956
01957
01964 static void readMotionInfoFromNAL (ImageParameters *img, Slice *currSlice, Macroblock *currMB)
01965 {
01966 int i,j,k;
01967 int mb_nr = img->current_mb_nr;
01968 SyntaxElement currSE;
01969 DataPartition *dP = NULL;
01970 byte *partMap = assignSE2partition[currSlice->dp_mode];
01971 int bslice = (img->type==B_SLICE);
01972 int partmode = ((currMB->mb_type == P8x8) ? 4 : currMB->mb_type);
01973 int step_h0 = BLOCK_STEP [partmode][0];
01974 int step_v0 = BLOCK_STEP [partmode][1];
01975
01976 int i0, j0, j6;
01977
01978 int j4, i4, ii;
01979 PicMotionParams *motion = &dec_picture->motion;
01980 MotionParams *colocated;
01981
01982 int mv_scale = 0;
01983
01984 int list_offset = ((img->MbaffFrameFlag)&&(currMB->mb_field))? (mb_nr&0x01) ? 4 : 2 : 0;
01985
01986
01987 if (bslice)
01988 {
01989 if ((img->MbaffFrameFlag) && (currMB->mb_field))
01990 {
01991 if(mb_nr&0x01)
01992 {
01993 colocated = &Co_located->bottom;
01994 }
01995 else
01996 {
01997 colocated = &Co_located->top;
01998 }
01999 }
02000 else
02001 {
02002 colocated = &Co_located->frame;
02003 }
02004
02005 if (currMB->mb_type == P8x8)
02006 {
02007 if (img->direct_spatial_mv_pred_flag)
02008 {
02009 char l0_rFrame, l1_rFrame;
02010 short pmvl0[2]={0,0}, pmvl1[2]={0,0};
02011
02012 prepare_direct_params(currMB, dec_picture, img, pmvl0, pmvl1, &l0_rFrame, &l1_rFrame);
02013
02014 for (k = 0; k < 4; k++)
02015 {
02016 if (currMB->b8mode[k] == 0)
02017 {
02018 i = img->block_x + 2 * (k & 0x01);
02019 for(j = 2 * (k >> 1); j < 2 * (k >> 1)+2;j++)
02020 {
02021 j6 = img->block_y_aff + j;
02022 j4 = img->block_y + j;
02023 for(i4 = i; i4 < i + 2; i4++)
02024 {
02025 if (l0_rFrame >= 0)
02026 {
02027 if (!l0_rFrame && ((!colocated->moving_block[j6][i4]) && (!listX[LIST_1 + list_offset][0]->is_long_term)))
02028 {
02029 motion->mv [LIST_0][j4][i4][0] = 0;
02030 motion->mv [LIST_0][j4][i4][1] = 0;
02031 motion->ref_idx[LIST_0][j4][i4] = 0;
02032 }
02033 else
02034 {
02035 motion->mv [LIST_0][j4][i4][0] = pmvl0[0];
02036 motion->mv [LIST_0][j4][i4][1] = pmvl0[1];
02037 motion->ref_idx[LIST_0][j4][i4] = l0_rFrame;
02038 }
02039 }
02040 else
02041 {
02042 motion->mv [LIST_0][j4][i4][0] = 0;
02043 motion->mv [LIST_0][j4][i4][1] = 0;
02044 motion->ref_idx[LIST_0][j4][i4] = -1;
02045 }
02046
02047 if (l1_rFrame >= 0)
02048 {
02049 if (l1_rFrame==0 && ((!colocated->moving_block[j6][i4])&& (!listX[LIST_1 + list_offset][0]->is_long_term)))
02050 {
02051 motion->mv [LIST_1][j4][i4][0] = 0;
02052 motion->mv [LIST_1][j4][i4][1] = 0;
02053 motion->ref_idx[LIST_1][j4][i4] = 0;
02054 }
02055 else
02056 {
02057 motion->mv [LIST_1][j4][i4][0] = pmvl1[0];
02058 motion->mv [LIST_1][j4][i4][1] = pmvl1[1];
02059 motion->ref_idx[LIST_1][j4][i4] = l1_rFrame;
02060 }
02061 }
02062 else
02063 {
02064 motion->mv [LIST_1][j4][i4][0] = 0;
02065 motion->mv [LIST_1][j4][i4][1] = 0;
02066 motion->ref_idx[LIST_1][j4][i4] = -1;
02067 }
02068
02069 if (l0_rFrame <0 && l1_rFrame <0)
02070 {
02071 motion->ref_idx[LIST_0][j4][i4] = 0;
02072 motion->ref_idx[LIST_1][j4][i4] = 0;
02073 }
02074 }
02075 }
02076 }
02077 }
02078 }
02079 else
02080 {
02081 for (k = 0; k < 4; k++)
02082 {
02083 if (currMB->b8mode[k] == 0)
02084 {
02085 for(j0 = 2 * (k >> 1); j0 < 2 * (k >> 1) + 2; j0 += step_v0)
02086 {
02087 for(i0 = img->block_x + 2*(k & 0x01); i0 < img->block_x + 2 * (k & 0x01)+2; i0 += step_h0)
02088 {
02089 int refList = colocated->ref_idx[LIST_0 ][img->block_y_aff + j0][i0]== -1 ? LIST_1 : LIST_0;
02090 int ref_idx = colocated->ref_idx[refList][img->block_y_aff + j0][i0];
02091 int mapped_idx = -1, iref;
02092
02093 if (ref_idx == -1)
02094 {
02095 for (j4 = img->block_y + j0; j4 < img->block_y + j0 + step_v0; j4++)
02096 {
02097 memset(&motion->ref_idx [LIST_0][j4][i0], 0, step_h0 * sizeof(char));
02098 memset(&motion->ref_idx [LIST_1][j4][i0], 0, step_h0 * sizeof(char));
02099 memset(&motion->mv [LIST_0][j4][i0][0], 0, 2 * step_h0 * sizeof(short));
02100 memset(&motion->mv [LIST_1][j4][i0][0], 0, 2 * step_h0 * sizeof(short));
02101 }
02102 }
02103 else
02104 {
02105 for (iref = 0; iref < imin(img->num_ref_idx_l0_active,listXsize[LIST_0 + list_offset]); iref++)
02106 {
02107 int curr_mb_field = ((img->MbaffFrameFlag)&&(currMB->mb_field));
02108
02109 if(img->structure==0 && curr_mb_field==0)
02110 {
02111
02112
02113
02114 if(listX[0][iref]->top_poc * 2 == colocated->ref_pic_id[refList][img->block_y_aff + j0][i0]
02115 || listX[0][iref]->bottom_poc * 2 == colocated->ref_pic_id[refList][img->block_y_aff + j0][i0])
02116 {
02117 mapped_idx=iref;
02118 break;
02119 }
02120 else
02121 mapped_idx=INVALIDINDEX;
02122 continue;
02123 }
02124 if (dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][iref]==colocated->ref_pic_id[refList][img->block_y_aff + j0][i0])
02125 {
02126 mapped_idx=iref;
02127 break;
02128 }
02129 else
02130 mapped_idx=INVALIDINDEX;
02131 }
02132
02133 if (INVALIDINDEX == mapped_idx)
02134 {
02135 error("temporal direct error: colocated block has ref that is unavailable",-1111);
02136 }
02137
02138 for (j = j0; j < j0 + step_v0; j++)
02139 {
02140 j4 = img->block_y + j;
02141 j6 = img->block_y_aff + j;
02142
02143 for (i4 = i0; i4 < i0 + step_h0; i4++)
02144 {
02145 mv_scale = img->mvscale[LIST_0 + list_offset][mapped_idx];
02146
02147 motion->ref_idx [LIST_0][j4][i4] = (char) mapped_idx;
02148 motion->ref_idx [LIST_1][j4][i4] = 0;
02149
02150 for (ii=0; ii < 2; ii++)
02151 {
02152 if (mv_scale == 9999 || listX[LIST_0+list_offset][mapped_idx]->is_long_term)
02153 {
02154 motion->mv [LIST_0][j4][i4][ii] = colocated->mv[refList][j6][i4][ii];
02155 motion->mv [LIST_1][j4][i4][ii] = 0;
02156 }
02157 else
02158 {
02159 motion->mv [LIST_0][j4][i4][ii] = (short) ((mv_scale * colocated->mv[refList][j6][i4][ii] + 128 ) >> 8);
02160 motion->mv [LIST_1][j4][i4][ii] = (short) (motion->mv[LIST_0][j4][i4][ii] - colocated->mv[refList][j6][i4][ii]);
02161 }
02162 }
02163 }
02164 }
02165 }
02166 }
02167 }
02168 }
02169 }
02170 }
02171 }
02172 }
02173
02174
02175 currSE.type = SE_REFFRAME;
02176 dP = &(currSlice->partArr[partMap[SE_REFFRAME]]);
02177
02178 prepareListforRefIdx (&currSE, dP, img->num_ref_idx_l0_active, (currMB->mb_type != P8x8) || bslice || (!img->allrefzero));
02179 readMBRefPictureIdx (&currSE, dP, currMB, img, &motion->ref_idx[LIST_0][img->block_y], LIST_0, step_v0, step_h0);
02180
02181
02182 prepareListforRefIdx (&currSE, dP, img->num_ref_idx_l1_active, (currMB->mb_type != P8x8) || bslice || (!img->allrefzero));
02183 readMBRefPictureIdx (&currSE, dP, currMB, img, &motion->ref_idx[LIST_1][img->block_y], LIST_1, step_v0, step_h0);
02184
02185
02186 currSE.type = SE_MVD;
02187 dP = &(currSlice->partArr[partMap[SE_MVD]]);
02188
02189 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
02190 currSE.mapping = linfo_se;
02191 else
02192 currSE.reading = readMVD_CABAC;
02193
02194
02195 readMBMotionVectors (&currSE, dP, currMB, img, LIST_0, step_h0, step_v0);
02196
02197 if (bslice)
02198 readMBMotionVectors (&currSE, dP, currMB, img, LIST_1, step_h0, step_v0);
02199
02200
02201
02202 for (k = LIST_0; k <= (bslice ? LIST_1: LIST_0); k++)
02203 {
02204 for(j4 = img->block_y; j4 < (img->block_y +4);j4++)
02205 {
02206 for(i4 = img->block_x; i4 < (img->block_x + 4);i4++)
02207 {
02208 if (motion->ref_idx[k][j4][i4]>=0)
02209 motion->ref_pic_id[k][j4][i4] = dec_picture->ref_pic_num[img->current_slice_nr][k + list_offset][(short)motion->ref_idx[k][j4][i4]];
02210 else
02211 motion->ref_pic_id[k][j4][i4] = INT64_MIN;
02212 }
02213 }
02214 }
02215 }
02216
02226 int predict_nnz(Macroblock *currMB, int block_type, ImageParameters *img, int i,int j)
02227 {
02228 PixelPos pix;
02229
02230 int pred_nnz = 0;
02231 int cnt = 0;
02232
02233
02234 get4x4Neighbour(currMB, i - 1, j, img->mb_size[IS_LUMA], &pix);
02235
02236 if (IS_INTRA(currMB) && pix.available && active_pps->constrained_intra_pred_flag && (img->currentSlice->dp_mode==PAR_DP_3))
02237 {
02238 pix.available &= img->intra_block[pix.mb_addr];
02239 if (!pix.available)
02240 cnt++;
02241 }
02242
02243 if (pix.available)
02244 {
02245 switch (block_type)
02246 {
02247 case LUMA:
02248 pred_nnz = img->nz_coeff [pix.mb_addr ][0][pix.y][pix.x];
02249 cnt++;
02250 break;
02251 case CB:
02252 pred_nnz = img->nz_coeff [pix.mb_addr ][1][pix.y][pix.x];
02253 cnt++;
02254 break;
02255 case CR:
02256 pred_nnz = img->nz_coeff [pix.mb_addr ][2][pix.y][pix.x];
02257 cnt++;
02258 break;
02259 default:
02260 error("writeCoeff4x4_CAVLC: Invalid block type", 600);
02261 break;
02262 }
02263 }
02264
02265
02266 get4x4Neighbour(currMB, i, j - 1, img->mb_size[IS_LUMA], &pix);
02267
02268 if (IS_INTRA(currMB) && pix.available && active_pps->constrained_intra_pred_flag && (img->currentSlice->dp_mode==PAR_DP_3))
02269 {
02270 pix.available &= img->intra_block[pix.mb_addr];
02271 if (!pix.available)
02272 cnt++;
02273 }
02274
02275 if (pix.available)
02276 {
02277 switch (block_type)
02278 {
02279 case LUMA:
02280 pred_nnz += img->nz_coeff [pix.mb_addr ][0][pix.y][pix.x];
02281 cnt++;
02282 break;
02283 case CB:
02284 pred_nnz += img->nz_coeff [pix.mb_addr ][1][pix.y][pix.x];
02285 cnt++;
02286 break;
02287 case CR:
02288 pred_nnz += img->nz_coeff [pix.mb_addr ][2][pix.y][pix.x];
02289 cnt++;
02290 break;
02291 default:
02292 error("writeCoeff4x4_CAVLC: Invalid block type", 600);
02293 break;
02294 }
02295 }
02296
02297 if (cnt==2)
02298 {
02299 pred_nnz++;
02300 pred_nnz>>=1;
02301 }
02302
02303 return pred_nnz;
02304 }
02305
02306
02316 int predict_nnz_chroma(Macroblock *currMB, ImageParameters *img, int i,int j)
02317 {
02318 PixelPos pix;
02319
02320 int pred_nnz = 0;
02321 int cnt = 0;
02322
02323 if (dec_picture->chroma_format_idc != YUV444)
02324 {
02325
02326
02327 get4x4Neighbour(currMB, ((i&0x01)<<2) - 1, j, img->mb_size[IS_CHROMA], &pix);
02328
02329 if (IS_INTRA(currMB) && pix.available && active_pps->constrained_intra_pred_flag && (img->currentSlice->dp_mode==PAR_DP_3))
02330 {
02331 pix.available &= img->intra_block[pix.mb_addr];
02332 if (!pix.available)
02333 cnt++;
02334 }
02335
02336 if (pix.available)
02337 {
02338 pred_nnz = img->nz_coeff [pix.mb_addr ][1][pix.y][2 * (i>>1) + pix.x];
02339 cnt++;
02340 }
02341
02342
02343 get4x4Neighbour(currMB, ((i&0x01)<<2), j - 1, img->mb_size[IS_CHROMA], &pix);
02344
02345 if (IS_INTRA(currMB) && pix.available && active_pps->constrained_intra_pred_flag && (img->currentSlice->dp_mode==PAR_DP_3))
02346 {
02347 pix.available &= img->intra_block[pix.mb_addr];
02348 if (!pix.available)
02349 cnt++;
02350 }
02351
02352 if (pix.available)
02353 {
02354 pred_nnz += img->nz_coeff [pix.mb_addr ][1][pix.y][2 * (i>>1) + pix.x];
02355 cnt++;
02356 }
02357
02358 if (cnt==2)
02359 {
02360 pred_nnz++;
02361 pred_nnz >>= 1;
02362 }
02363 }
02364
02365 return pred_nnz;
02366 }
02367
02368
02379 static void readCoeff4x4_CAVLC (Slice *currSlice, Macroblock *currMB, ImageParameters *img,
02380 int block_type,
02381 int i, int j, int levarr[16], int runarr[16],
02382 int *number_coefficients)
02383 {
02384 int mb_nr = img->current_mb_nr;
02385 SyntaxElement currSE;
02386 DataPartition *dP;
02387 byte *partMap = assignSE2partition[currSlice->dp_mode];
02388 static Bitstream *currStream;
02389
02390 int k, code, vlcnum;
02391 static int numcoeff, numtrailingones, numcoeff_vlc;
02392 static int level_two_or_higher;
02393 int numones, totzeros, abslevel, cdc=0, cac=0;
02394 int zerosleft, ntr, dptype = 0;
02395 int max_coeff_num = 0, nnz;
02396 static char type[15];
02397 static int incVlc[] = {0,3,6,12,24,48,32768};
02398
02399 numcoeff = 0;
02400
02401 switch (block_type)
02402 {
02403 case LUMA:
02404 max_coeff_num = 16;
02405 TRACE_PRINTF("Luma");
02406 dptype = IS_INTRA (currMB) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER;
02407 img->nz_coeff[mb_nr][0][j][i] = 0;
02408 break;
02409 case LUMA_INTRA16x16DC:
02410 max_coeff_num = 16;
02411 TRACE_PRINTF("Lum16DC");
02412 dptype = SE_LUM_DC_INTRA;
02413 img->nz_coeff[mb_nr][0][j][i] = 0;
02414 break;
02415 case LUMA_INTRA16x16AC:
02416 max_coeff_num = 15;
02417 TRACE_PRINTF("Lum16AC");
02418 dptype = SE_LUM_AC_INTRA;
02419 img->nz_coeff[mb_nr][0][j][i] = 0;
02420 break;
02421 case CB:
02422 max_coeff_num = 16;
02423 TRACE_PRINTF("Luma_add1");
02424 dptype = (IS_INTRA (currMB)) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER;
02425 img->nz_coeff[mb_nr][1][j][i] = 0;
02426 break;
02427 case CB_INTRA16x16DC:
02428 max_coeff_num = 16;
02429 TRACE_PRINTF("Luma_add1_16DC");
02430 dptype = SE_LUM_DC_INTRA;
02431 img->nz_coeff[mb_nr][1][j][i] = 0;
02432 break;
02433 case CB_INTRA16x16AC:
02434 max_coeff_num = 15;
02435 TRACE_PRINTF("Luma_add1_16AC");
02436 dptype = SE_LUM_AC_INTRA;
02437 img->nz_coeff[mb_nr][1][j][i] = 0;
02438 break;
02439 case CR:
02440 max_coeff_num = 16;
02441 TRACE_PRINTF("Luma_add2");
02442 dptype = (IS_INTRA (currMB)) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER;
02443 img->nz_coeff[mb_nr][2][j][i] = 0;
02444 break;
02445 case CR_INTRA16x16DC:
02446 max_coeff_num = 16;
02447 TRACE_PRINTF("Luma_add2_16DC");
02448 dptype = SE_LUM_DC_INTRA;
02449 img->nz_coeff[mb_nr][2][j][i] = 0;
02450 break;
02451 case CR_INTRA16x16AC:
02452 max_coeff_num = 15;
02453 TRACE_PRINTF("Luma_add1_16AC");
02454 dptype = SE_LUM_AC_INTRA;
02455 img->nz_coeff[mb_nr][2][j][i] = 0;
02456 break;
02457 case CHROMA_DC:
02458 max_coeff_num = img->num_cdc_coeff;
02459 cdc = 1;
02460 TRACE_PRINTF("ChrDC");
02461 dptype = IS_INTRA (currMB) ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER;
02462 img->nz_coeff[mb_nr][0][j][i] = 0;
02463 break;
02464 case CHROMA_AC:
02465 max_coeff_num = 15;
02466 cac = 1;
02467 TRACE_PRINTF("ChrDC");
02468 dptype = IS_INTRA (currMB) ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER;
02469 img->nz_coeff[mb_nr][0][j][i] = 0;
02470 break;
02471 default:
02472 error ("readCoeff4x4_CAVLC: invalid block type", 600);
02473 img->nz_coeff[mb_nr][0][j][i] = 0;
02474 break;
02475 }
02476
02477 currSE.type = dptype;
02478 dP = &(currSlice->partArr[partMap[dptype]]);
02479 currStream = dP->bitstream;
02480
02481 if (!cdc)
02482 {
02483
02484 if(block_type==LUMA || block_type==LUMA_INTRA16x16DC || block_type==LUMA_INTRA16x16AC ||block_type==CHROMA_AC)
02485 {
02486 nnz = (!cac) ? predict_nnz(currMB, LUMA, img, i<<2, j<<2) : predict_nnz_chroma(currMB, img, i, ((j-4)<<2));
02487 }
02488 else if (block_type==CB || block_type==CB_INTRA16x16DC || block_type==CB_INTRA16x16AC)
02489 {
02490 nnz = predict_nnz(currMB, CB, img, i<<2, j<<2);
02491 }
02492 else
02493 {
02494 nnz = predict_nnz(currMB, CR, img, i<<2, j<<2);
02495 }
02496
02497 if (nnz < 2)
02498 {
02499 numcoeff_vlc = 0;
02500 }
02501 else if (nnz < 4)
02502 {
02503 numcoeff_vlc = 1;
02504 }
02505 else if (nnz < 8)
02506 {
02507 numcoeff_vlc = 2;
02508 }
02509 else
02510 {
02511 numcoeff_vlc = 3;
02512 }
02513
02514 currSE.value1 = numcoeff_vlc;
02515
02516 readSyntaxElement_NumCoeffTrailingOnes(&currSE, currStream, type);
02517
02518 numcoeff = currSE.value1;
02519 numtrailingones = currSE.value2;
02520
02521 if(block_type==LUMA || block_type==LUMA_INTRA16x16DC || block_type==LUMA_INTRA16x16AC ||block_type==CHROMA_AC)
02522 img->nz_coeff[mb_nr][0][j][i] = numcoeff;
02523 else if (block_type==CB || block_type==CB_INTRA16x16DC || block_type==CB_INTRA16x16AC)
02524 img->nz_coeff[mb_nr][1][j][i] = numcoeff;
02525 else
02526 img->nz_coeff[mb_nr][2][j][i] = numcoeff;
02527 }
02528 else
02529 {
02530
02531 readSyntaxElement_NumCoeffTrailingOnesChromaDC(&currSE, currStream);
02532
02533 numcoeff = currSE.value1;
02534 numtrailingones = currSE.value2;
02535 }
02536
02537 memset(levarr, 0, max_coeff_num * sizeof(int));
02538 memset(runarr, 0, max_coeff_num * sizeof(int));
02539
02540 numones = numtrailingones;
02541 *number_coefficients = numcoeff;
02542
02543 if (numcoeff)
02544 {
02545 if (numtrailingones)
02546 {
02547 currSE.len = numtrailingones;
02548
02549 #if TRACE
02550 snprintf(currSE.tracestring,
02551 TRACESTRING_SIZE, "%s trailing ones sign (%d,%d)", type, i, j);
02552 #endif
02553
02554 readSyntaxElement_FLC (&currSE, currStream);
02555
02556 code = currSE.inf;
02557 ntr = numtrailingones;
02558 for (k = numcoeff - 1; k > numcoeff - 1 - numtrailingones; k--)
02559 {
02560 ntr --;
02561 levarr[k] = (code>>ntr)&1 ? -1 : 1;
02562 }
02563 }
02564
02565
02566 level_two_or_higher = (numcoeff > 3 && numtrailingones == 3)? 0 : 1;
02567 vlcnum = (numcoeff > 10 && numtrailingones < 3) ? 1 : 0;
02568
02569 for (k = numcoeff - 1 - numtrailingones; k >= 0; k--)
02570 {
02571
02572 #if TRACE
02573 snprintf(currSE.tracestring,
02574 TRACESTRING_SIZE, "%s lev (%d,%d) k=%d vlc=%d ", type, i, j, k, vlcnum);
02575 #endif
02576
02577 if (vlcnum == 0)
02578 readSyntaxElement_Level_VLC0(&currSE, currStream);
02579 else
02580 readSyntaxElement_Level_VLCN(&currSE, vlcnum, currStream);
02581
02582 if (level_two_or_higher)
02583 {
02584 currSE.inf += (currSE.inf > 0) ? 1 : -1;
02585 level_two_or_higher = 0;
02586 }
02587
02588 levarr[k] = currSE.inf;
02589 abslevel = iabs(levarr[k]);
02590 if (abslevel == 1)
02591 numones ++;
02592
02593
02594 if (abslevel > incVlc[vlcnum])
02595 vlcnum++;
02596
02597 if (k == numcoeff - 1 - numtrailingones && abslevel >3)
02598 vlcnum = 2;
02599 }
02600
02601 if (numcoeff < max_coeff_num)
02602 {
02603
02604 vlcnum = numcoeff - 1;
02605 currSE.value1 = vlcnum;
02606
02607 #if TRACE
02608 snprintf(currSE.tracestring,
02609 TRACESTRING_SIZE, "%s totalrun (%d,%d) vlc=%d ", type, i,j, vlcnum);
02610 #endif
02611 if (cdc)
02612 readSyntaxElement_TotalZerosChromaDC(&currSE, currStream);
02613 else
02614 readSyntaxElement_TotalZeros(&currSE, currStream);
02615
02616 totzeros = currSE.value1;
02617 }
02618 else
02619 {
02620 totzeros = 0;
02621 }
02622
02623
02624 zerosleft = totzeros;
02625 i = numcoeff - 1;
02626
02627 if (zerosleft > 0 && i > 0)
02628 {
02629 do
02630 {
02631
02632 vlcnum = imin(zerosleft - 1, RUNBEFORE_NUM_M1);
02633
02634 currSE.value1 = vlcnum;
02635 #if TRACE
02636 snprintf(currSE.tracestring,
02637 TRACESTRING_SIZE, "%s run (%d,%d) k=%d vlc=%d ",
02638 type, i, j, i, vlcnum);
02639 #endif
02640
02641 readSyntaxElement_Run(&currSE, currStream);
02642 runarr[i] = currSE.value1;
02643
02644 zerosleft -= runarr[i];
02645 i --;
02646 } while (zerosleft != 0 && i != 0);
02647 }
02648 runarr[i] = zerosleft;
02649 }
02650 }
02651
02659 static void readCompCoeff4x4SMB_CABAC (ImageParameters *img, Slice *currSlice, Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl, int block_y, int block_x, int start_scan, int64 *cbp_blk)
02660 {
02661 int i,j,k;
02662 int i0, j0;
02663 int level = 1;
02664 static DataPartition *dP;
02665 byte *partMap = assignSE2partition[currSlice->dp_mode];
02666
02667 const byte (*pos_scan4x4)[2] = ((img->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN;
02668 const byte *pos_scan_4x4 = pos_scan4x4[0];
02669 int **cof = img->cof[pl];
02670
02671 for (j = block_y; j < block_y + BLOCK_SIZE_8x8; j += 4)
02672 {
02673 img->subblock_y = j;
02674
02675 for (i = block_x; i < block_x + BLOCK_SIZE_8x8; i += 4)
02676 {
02677 img->subblock_x = i;
02678 pos_scan_4x4 = pos_scan4x4[start_scan];
02679 level = 1;
02680
02681 if (start_scan == 0)
02682 {
02683
02684
02685
02686
02687 currSE->type = (img->is_intra_block ? SE_LUM_DC_INTRA : SE_LUM_DC_INTER);
02688 dP = &(currSlice->partArr[partMap[currSE->type]]);
02689 if (dP->bitstream->ei_flag)
02690 currSE->mapping = linfo_levrun_inter;
02691 else
02692 currSE->reading = readRunLevel_CABAC;
02693
02694 #if TRACE
02695 if (pl == PLANE_Y)
02696 sprintf(currSE->tracestring, "Luma sng ");
02697 else if (pl == PLANE_U)
02698 sprintf(currSE->tracestring, "Cb sng ");
02699 else
02700 sprintf(currSE->tracestring, "Cr sng ");
02701 #endif
02702
02703 dP->readSyntaxElement(currSE,img,dP);
02704 level = currSE->value1;
02705
02706 if (level != 0)
02707 {
02708 pos_scan_4x4 += 2 * currSE->value2;
02709
02710 i0 = *pos_scan_4x4++;
02711 j0 = *pos_scan_4x4++;
02712
02713 *cbp_blk |= (int64) 1 << (j + (i >> 2)) ;
02714
02715 cof[j + j0][i + i0]= level;
02716
02717 }
02718 }
02719
02720 if (level != 0)
02721 {
02722
02723 currSE->type = (img->is_intra_block ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER);
02724 dP = &(currSlice->partArr[partMap[currSE->type]]);
02725
02726 if (dP->bitstream->ei_flag)
02727 currSE->mapping = linfo_levrun_inter;
02728 else
02729 currSE->reading = readRunLevel_CABAC;
02730
02731 for(k = 1; (k < 17) && (level != 0); k++)
02732 {
02733 #if TRACE
02734 if (pl == PLANE_Y)
02735 sprintf(currSE->tracestring, "Luma sng ");
02736 else if (pl == PLANE_U)
02737 sprintf(currSE->tracestring, "Cb sng ");
02738 else
02739 sprintf(currSE->tracestring, "Cr sng ");
02740 #endif
02741
02742 dP->readSyntaxElement(currSE, img, dP);
02743 level = currSE->value1;
02744
02745 if (level != 0)
02746 {
02747 pos_scan_4x4 += 2 * currSE->value2;
02748
02749 i0 = *pos_scan_4x4++;
02750 j0 = *pos_scan_4x4++;
02751
02752
02753 cof[j + j0][i + i0]= level;
02754
02755 }
02756 }
02757 }
02758 }
02759 }
02760 }
02761
02769 static void readCompCoeff4x4MB_CABAC (ImageParameters *img, Slice *currSlice, Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl, int intra, int (*InvLevelScale4x4)[4], int qp_per, int cbp)
02770 {
02771 int start_scan = IS_I16MB (currMB)? 1 : 0;
02772 int block_y, block_x;
02773 int i, j;
02774 int64 *cbp_blk = &currMB->cbp_blk[pl];
02775
02776 img->is_intra_block = intra;
02777
02778 if( pl == PLANE_Y || IS_INDEPENDENT(img) )
02779 currSE->context = (IS_I16MB(currMB) ? LUMA_16AC: LUMA_4x4);
02780 else if (pl == PLANE_U)
02781 currSE->context = (IS_I16MB(currMB) ? CB_16AC: CB_4x4);
02782 else
02783 currSE->context = (IS_I16MB(currMB) ? CR_16AC: CR_4x4);
02784
02785 if (currMB->is_lossless == FALSE)
02786 {
02787 for (block_y = 0; block_y < MB_BLOCK_SIZE; block_y += BLOCK_SIZE_8x8)
02788 {
02789 int **cof = &img->cof[pl][block_y];
02790 for (block_x = 0; block_x < MB_BLOCK_SIZE; block_x += BLOCK_SIZE_8x8)
02791 {
02792 if (cbp & (1 << ((block_y >> 2) + (block_x >> 3))))
02793 {
02794 readCompCoeff4x4SMB_CABAC (img, currSlice, currMB, currSE, pl, block_y, block_x, start_scan, cbp_blk);
02795
02796 if (start_scan == 0)
02797 {
02798 for (j = 0; j < BLOCK_SIZE_8x8; j++)
02799 {
02800 for (i = 0; i < BLOCK_SIZE_8x8; i++)
02801 {
02802 if (cof[j][block_x + i])
02803 cof[j][block_x + i]= rshift_rnd_sf((cof[j][block_x + i] * InvLevelScale4x4[j & 0x03][i & 0x03]) << qp_per, 4);
02804 }
02805 }
02806 }
02807 else
02808 {
02809 for (j = 0; j < BLOCK_SIZE_8x8; j++)
02810 {
02811 for (i = 0; i < BLOCK_SIZE_8x8; i++)
02812 {
02813 if (((i & 0x03) != 0 || (j & 0x03) != 0) && cof[j][block_x + i])
02814 {
02815 cof[j][block_x + i]= rshift_rnd_sf((cof[j][block_x + i] * InvLevelScale4x4[j & 0x03][i & 0x03]) << qp_per, 4);
02816 }
02817 }
02818 }
02819 }
02820 }
02821
02822 }
02823 }
02824 }
02825 else
02826 {
02827 for (block_y = 0; block_y < MB_BLOCK_SIZE; block_y += BLOCK_SIZE_8x8)
02828 {
02829 for (block_x = 0; block_x < MB_BLOCK_SIZE; block_x += BLOCK_SIZE_8x8)
02830 {
02831 if (cbp & (1 << ((block_y >> 2) + (block_x >> 3))))
02832 {
02833 readCompCoeff4x4SMB_CABAC (img, currSlice, currMB, currSE, pl, block_y, block_x, start_scan, cbp_blk);
02834 }
02835 }
02836 }
02837 }
02838 }
02839
02847 static void readCompCoeff8x8_CABAC (ImageParameters *img, Slice *currSlice, Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl, int b8)
02848 {
02849 if (currMB->cbp & (1<<b8))
02850 {
02851 int transform_pl = IS_INDEPENDENT(img) ? img->colour_plane_id : pl;
02852
02853 int **tcoeffs;
02854 int i,j,k;
02855 int level = 1;
02856
02857 DataPartition *dP;
02858 byte *partMap = assignSE2partition[currSlice->dp_mode];
02859 int boff_x, boff_y;
02860
02861 int64 cbp_mask = (int64) 51 << (4 * b8 - 2 * (b8 & 0x01));
02862 int64 *cur_cbp = &currMB->cbp_blk[pl];
02863
02864
02865 const byte (*pos_scan8x8) = ((img->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8[0] : FIELD_SCAN8x8[0];
02866
02867 int qp_per = qp_per_matrix[ currMB->qp_scaled[pl] ];
02868 int qp_rem = qp_rem_matrix[ currMB->qp_scaled[pl] ];
02869
02870 int (*InvLevelScale8x8)[8] = IS_INTRA(currMB)? InvLevelScale8x8_Intra[transform_pl][qp_rem] : InvLevelScale8x8_Inter[transform_pl][qp_rem];
02871
02872 img->is_intra_block = IS_INTRA(currMB);
02873
02874
02875 boff_x = (b8&0x01) << 3;
02876 boff_y = (b8 >> 1) << 3;
02877 tcoeffs = &img->mb_rres[pl][boff_y];
02878
02879 img->subblock_x = boff_x;
02880 img->subblock_y = boff_y;
02881
02882 if (pl==PLANE_Y || IS_INDEPENDENT(img))
02883 currSE->context = LUMA_8x8;
02884 else if (pl==PLANE_U)
02885 currSE->context = CB_8x8;
02886 else
02887 currSE->context = CR_8x8;
02888
02889 currSE->reading = readRunLevel_CABAC;
02890
02891 if(currMB->is_lossless == FALSE)
02892 {
02893
02894 currSE->type = ((img->is_intra_block == 1) ? SE_LUM_DC_INTRA : SE_LUM_DC_INTER );
02895 dP = &(currSlice->partArr[partMap[currSE->type]]);
02896
02897 #if TRACE
02898 if (pl==PLANE_Y)
02899 sprintf(currSE->tracestring, "Luma8x8 DC sng ");
02900 else if (pl==PLANE_U)
02901 sprintf(currSE->tracestring, "Cb 8x8 DC sng ");
02902 else
02903 sprintf(currSE->tracestring, "Cr 8x8 DC sng ");
02904 #endif
02905
02906 dP->readSyntaxElement(currSE,img,dP);
02907 level = currSE->value1;
02908
02909
02910 if (level != 0)
02911 {
02912 *cur_cbp |= cbp_mask;
02913
02914 pos_scan8x8 += 2 * (currSE->value2);
02915
02916 i = *pos_scan8x8++;
02917 j = *pos_scan8x8++;
02918
02919 tcoeffs[j][boff_x + i] = rshift_rnd_sf((level * InvLevelScale8x8[j][i]) << qp_per, 6);
02920
02921
02922 currSE->type = ((img->is_intra_block == 1) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER);
02923 dP = &(currSlice->partArr[partMap[currSE->type]]);
02924
02925 for(k = 1;(k < 65) && (level != 0);k++)
02926 {
02927 #if TRACE
02928 if (pl==PLANE_Y)
02929 sprintf(currSE->tracestring, "Luma8x8 sng ");
02930 else if (pl==PLANE_U)
02931 sprintf(currSE->tracestring, "Cb 8x8 sng ");
02932 else
02933 sprintf(currSE->tracestring, "Cr 8x8 sng ");
02934 #endif
02935
02936 dP->readSyntaxElement(currSE,img,dP);
02937 level = currSE->value1;
02938
02939
02940 if (level != 0)
02941 {
02942 pos_scan8x8 += 2 * (currSE->value2);
02943
02944 i = *pos_scan8x8++;
02945 j = *pos_scan8x8++;
02946
02947 tcoeffs[ j][boff_x + i] = rshift_rnd_sf((level * InvLevelScale8x8[j][i]) << qp_per, 6);
02948 }
02949 }
02950 }
02951 }
02952 else
02953 {
02954
02955 for(k=0; (k < 65) && (level != 0);k++)
02956 {
02957
02958
02959
02960
02961
02962
02963 currSE->type = ((img->is_intra_block == 1)
02964 ? (k==0 ? SE_LUM_DC_INTRA : SE_LUM_AC_INTRA)
02965 : (k==0 ? SE_LUM_DC_INTER : SE_LUM_AC_INTER));
02966
02967 #if TRACE
02968 if (pl==PLANE_Y)
02969 sprintf(currSE->tracestring, "Luma8x8 sng ");
02970 else if (pl==PLANE_U)
02971 sprintf(currSE->tracestring, "Cb 8x8 sng ");
02972 else
02973 sprintf(currSE->tracestring, "Cr 8x8 sng ");
02974 #endif
02975
02976 dP = &(currSlice->partArr[partMap[currSE->type]]);
02977 currSE->reading = readRunLevel_CABAC;
02978
02979 dP->readSyntaxElement(currSE,img,dP);
02980 level = currSE->value1;
02981
02982
02983 if (level != 0)
02984 {
02985 pos_scan8x8 += 2 * (currSE->value2);
02986
02987 i = *pos_scan8x8++;
02988 j = *pos_scan8x8++;
02989
02990 *cur_cbp |= cbp_mask;
02991
02992 tcoeffs[j][boff_x + i] = level;
02993 }
02994 }
02995 }
02996 }
02997 }
02998
02999
03007 static void readCompCoeff8x8MB_CABAC (ImageParameters *img, Slice *currSlice, Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl)
03008 {
03009
03010 readCompCoeff8x8_CABAC (img, currSlice, currMB, currSE, pl, 0);
03011 readCompCoeff8x8_CABAC (img, currSlice, currMB, currSE, pl, 1);
03012 readCompCoeff8x8_CABAC (img, currSlice, currMB, currSE, pl, 2);
03013 readCompCoeff8x8_CABAC (img, currSlice, currMB, currSE, pl, 3);
03014 }
03015
03023 static void readCompCoeff4x4MB_CAVLC (ImageParameters *img, Slice *currSlice, Macroblock *currMB, ColorPlane pl, int (*InvLevelScale4x4)[4], int qp_per, int cbp, byte **nzcoeff)
03024 {
03025 int block_y, block_x, b8;
03026 int i, j, k;
03027 int i0, j0;
03028 int levarr[16] = {0}, runarr[16] = {0}, numcoeff;
03029 const byte (*pos_scan4x4)[2] = ((img->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN;
03030 const byte *pos_scan_4x4 = pos_scan4x4[0];
03031 int start_scan = IS_I16MB(currMB) ? 1 : 0;
03032 int64 *cur_cbp = &currMB->cbp_blk[pl];
03033 int coef_ctr, cur_context;
03034
03035 if (IS_I16MB(currMB))
03036 {
03037 if (pl == PLANE_Y)
03038 cur_context = LUMA_INTRA16x16AC;
03039 else if (pl == PLANE_U)
03040 cur_context = CB_INTRA16x16AC;
03041 else
03042 cur_context = CR_INTRA16x16AC;
03043 }
03044 else
03045 {
03046 if (pl == PLANE_Y)
03047 cur_context = LUMA;
03048 else if (pl == PLANE_U)
03049 cur_context = CB;
03050 else
03051 cur_context = CR;
03052 }
03053
03054 if (currMB->is_lossless == FALSE)
03055 {
03056 for (block_y = 0; block_y < 4; block_y += 2)
03057 {
03058 for (block_x = 0; block_x < 4; block_x += 2)
03059 {
03060 b8 = (block_y + (block_x >> 1));
03061
03062 if (cbp & (1 << b8))
03063 {
03064 for (j=block_y << 2; j < (block_y + 2) << 2; j += BLOCK_SIZE)
03065 {
03066 for (i=block_x << 2; i < (block_x + 2) << 2; i += BLOCK_SIZE)
03067 {
03068 readCoeff4x4_CAVLC(currSlice, currMB, img, cur_context, i >> 2, j >> 2, levarr, runarr, &numcoeff);
03069 pos_scan_4x4 = pos_scan4x4[start_scan];
03070
03071 for (k = 0; k < numcoeff; k++)
03072 {
03073 if (levarr[k] != 0)
03074 {
03075 pos_scan_4x4 += (runarr[k] << 1);
03076
03077 i0 = *pos_scan_4x4++;
03078 j0 = *pos_scan_4x4++;
03079
03080
03081 *cur_cbp |= (int64) 1 << (j + (i >> 2));
03082
03083 img->cof[pl][j + j0][i + i0]= rshift_rnd_sf((levarr[k] * InvLevelScale4x4[j0][i0])<<qp_per, 4);
03084
03085 }
03086 }
03087 }
03088 }
03089 }
03090 else
03091 {
03092 for (j=block_y; j < block_y + 2; j++)
03093 {
03094 memset(&nzcoeff[j][block_x], 0, 2 * sizeof(byte));
03095 }
03096 }
03097 }
03098 }
03099 }
03100 else
03101 {
03102 for (block_y=0; block_y < 4; block_y += 2)
03103 {
03104 for (block_x=0; block_x < 4; block_x += 2)
03105 {
03106 b8 = 2*(block_y>>1) + (block_x>>1);
03107
03108 if (cbp & (1<<b8))
03109 {
03110 for (j=block_y; j < block_y+2; j++)
03111 {
03112 for (i=block_x; i < block_x+2; i++)
03113 {
03114 readCoeff4x4_CAVLC(currSlice, currMB, img, cur_context, i, j, levarr, runarr, &numcoeff);
03115
03116 coef_ctr = start_scan - 1;
03117
03118 for (k = 0; k < numcoeff; k++)
03119 {
03120 if (levarr[k] != 0)
03121 {
03122 coef_ctr += runarr[k]+1;
03123
03124 i0=pos_scan4x4[coef_ctr][0];
03125 j0=pos_scan4x4[coef_ctr][1];
03126
03127 *cur_cbp |= (int64) 1 << ((j<<2) + i);
03128 img->cof[pl][(j<<2) + j0][(i<<2) + i0]= levarr[k];
03129
03130 }
03131 }
03132 }
03133 }
03134 }
03135 else
03136 {
03137 for (j=block_y; j < block_y+2; j++)
03138 {
03139 memset(&nzcoeff[j][block_x], 0, 2 * sizeof(byte));
03140 }
03141 }
03142 }
03143 }
03144 }
03145 }
03146
03147
03155 static void readCompCoeff8x8MB_CAVLC (ImageParameters *img, Slice *currSlice, Macroblock *currMB, ColorPlane pl, int (*InvLevelScale8x8)[8], int qp_per, int cbp, byte **nzcoeff)
03156 {
03157 int block_y, block_x, b4, b8;
03158 int i, j, k;
03159 int i0, j0;
03160 int levarr[16] = {0}, runarr[16] = {0}, numcoeff;
03161 const byte (*pos_scan8x8)[2] = ((img->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8 : FIELD_SCAN8x8;
03162 int start_scan = IS_I16MB(currMB) ? 1 : 0;
03163 int64 *cur_cbp = &currMB->cbp_blk[pl];
03164 int coef_ctr, cur_context;
03165
03166 if (IS_I16MB(currMB))
03167 {
03168 if (pl == PLANE_Y)
03169 cur_context = LUMA_INTRA16x16AC;
03170 else if (pl == PLANE_U)
03171 cur_context = CB_INTRA16x16AC;
03172 else
03173 cur_context = CR_INTRA16x16AC;
03174 }
03175 else
03176 {
03177 if (pl == PLANE_Y)
03178 cur_context = LUMA;
03179 else if (pl == PLANE_U)
03180 cur_context = CB;
03181 else
03182 cur_context = CR;
03183 }
03184
03185 if (currMB->is_lossless == FALSE)
03186 {
03187
03188 for (block_y=0; block_y < 4; block_y += 2)
03189 {
03190 for (block_x=0; block_x < 4; block_x += 2)
03191 {
03192 b8 = block_y + (block_x>>1);
03193
03194 if (cbp & (1<<b8))
03195 {
03196 for (j=block_y; j < block_y+2; j++)
03197 {
03198 for (i=block_x; i < block_x+2; i++)
03199 {
03200 readCoeff4x4_CAVLC(currSlice, currMB, img, cur_context, i, j, levarr, runarr, &numcoeff);
03201
03202 coef_ctr = start_scan - 1;
03203
03204 for (k = 0; k < numcoeff; k++)
03205 {
03206 if (levarr[k] != 0)
03207 {
03208 coef_ctr += runarr[k]+1;
03209
03210
03211
03212 *cur_cbp |= 51 << ((block_y<<2) + block_x);
03213
03214 b4 = (coef_ctr << 2) + 2*(j - block_y)+(i - block_x);
03215
03216 i0 = pos_scan8x8[b4][0];
03217 j0 = pos_scan8x8[b4][1];
03218
03219 img->mb_rres[pl][block_y*4 +j0][block_x*4 +i0] = rshift_rnd_sf((levarr[k] * InvLevelScale8x8[j0][i0])<<qp_per, 6);
03220 }
03221 }
03222 }
03223 }
03224 }
03225 else
03226 {
03227 for (j=block_y; j < block_y+2; j++)
03228 {
03229 memset(&nzcoeff[j][block_x], 0, 2 * sizeof(byte));
03230 }
03231 }
03232 }
03233 }
03234 }
03235 else
03236 {
03237 for (block_y=0; block_y < 4; block_y += 2)
03238 {
03239 for (block_x=0; block_x < 4; block_x += 2)
03240 {
03241 b8 = 2*(block_y>>1) + (block_x>>1);
03242
03243 if (cbp & (1<<b8))
03244 {
03245 int iz, jz;
03246
03247 for (j=block_y; j < block_y+2; j++)
03248 {
03249 for (i=block_x; i < block_x+2; i++)
03250 {
03251
03252 readCoeff4x4_CAVLC(currSlice, currMB, img, cur_context, i, j, levarr, runarr, &numcoeff);
03253
03254 coef_ctr = start_scan - 1;
03255
03256 for (k = 0; k < numcoeff; k++)
03257 {
03258 if (levarr[k] != 0)
03259 {
03260 coef_ctr += runarr[k]+1;
03261
03262
03263
03264 *cur_cbp |= 51 << ((block_y<<2) + block_x);
03265
03266 b4 = 2*(j-block_y)+(i-block_x);
03267
03268 iz=pos_scan8x8[coef_ctr*4+b4][0];
03269 jz=pos_scan8x8[coef_ctr*4+b4][1];
03270
03271 img->mb_rres[pl][block_y*4 +jz][block_x*4 +iz] = levarr[k];
03272 }
03273 }
03274 }
03275 }
03276 }
03277 else
03278 {
03279 for (j=block_y; j < block_y+2; j++)
03280 {
03281 memset(&nzcoeff[j][block_x], 0, 2 * sizeof(byte));
03282 }
03283 }
03284 }
03285 }
03286 }
03287 }
03288
03297 static void check_dp_neighbors (Macroblock *currMB)
03298 {
03299 PixelPos up, left;
03300
03301 getNeighbour(currMB, -1, 0, img->mb_size[1], &left);
03302 getNeighbour(currMB, 0, -1, img->mb_size[1], &up);
03303
03304 if (IS_INTER (currMB) || (IS_INTRA (currMB) && !(active_pps->constrained_intra_pred_flag)) )
03305 {
03306 if (left.available)
03307 {
03308 currMB->dpl_flag |= img->mb_data[left.mb_addr].dpl_flag;
03309 }
03310 if (up.available)
03311 {
03312 currMB->dpl_flag |= img->mb_data[up.mb_addr].dpl_flag;
03313 }
03314 }
03315 }
03316
03317
03325 static void readCBPandCoeffsFromNAL(ImageParameters *img, Slice *currSlice, Macroblock *currMB)
03326 {
03327 int i,j,k;
03328 int level;
03329 int mb_nr = img->current_mb_nr;
03330 int cbp;
03331 SyntaxElement currSE;
03332 DataPartition *dP = NULL;
03333 byte *partMap = assignSE2partition[currSlice->dp_mode];
03334 int coef_ctr, i0, j0, b8;
03335 int ll;
03336 int levarr[16], runarr[16], numcoeff;
03337
03338 int qp_per, qp_rem;
03339 int smb = (img->type==SP_SLICE && currMB->mb_type!=I16MB ) || (((img->type==SP_SLICE) && IS_INTER (currMB)) || (img->type == SI_SLICE && currMB->mb_type == SI4MB));
03340
03341 int uv;
03342 int qp_per_uv[2];
03343 int qp_rem_uv[2];
03344
03345 int intra = IS_INTRA (currMB);
03346 int temp[4];
03347
03348 int b4;
03349 int yuv = dec_picture->chroma_format_idc - 1;
03350 int m6[4];
03351
03352 int need_transform_size_flag;
03353
03354 int (*InvLevelScale4x4)[4] = NULL;
03355 int (*InvLevelScale8x8)[8] = NULL;
03356
03357 const byte (*pos_scan4x4)[2] = ((img->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN;
03358 const byte *pos_scan_4x4 = pos_scan4x4[0];
03359
03360
03361
03362 if (dec_picture->chroma_format_idc != YUV400)
03363 {
03364 for (i=0; i<2; i++)
03365 {
03366 qp_per_uv[i] = qp_per_matrix[ currMB->qp_scaled[i + 1] ];
03367 qp_rem_uv[i] = qp_rem_matrix[ currMB->qp_scaled[i + 1] ];
03368 }
03369 }
03370
03371
03372 if (!IS_I16MB (currMB))
03373 {
03374
03375
03376 currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB)
03377 ? SE_CBP_INTRA
03378 : SE_CBP_INTER;
03379
03380 dP = &(currSlice->partArr[partMap[currSE.type]]);
03381
03382 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
03383 {
03384 currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB)
03385 ? linfo_cbp_intra
03386 : linfo_cbp_inter;
03387 }
03388 else
03389 {
03390 currSE.reading = readCBP_CABAC;
03391 }
03392
03393 TRACE_STRING("coded_block_pattern");
03394 dP->readSyntaxElement(&currSE, img, dP);
03395 currMB->cbp = cbp = currSE.value1;
03396
03397
03398
03399
03400 need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)||
03401 (IS_DIRECT(currMB) && active_sps->direct_8x8_inference_flag) ||
03402 (currMB->NoMbPartLessThan8x8Flag))
03403 && currMB->mb_type != I8MB && currMB->mb_type != I4MB
03404 && (currMB->cbp&15)
03405 && img->Transform8x8Mode);
03406
03407 if (need_transform_size_flag)
03408 {
03409 currSE.type = SE_HEADER;
03410 dP = &(currSlice->partArr[partMap[SE_HEADER]]);
03411 currSE.reading = readMB_transform_size_flag_CABAC;
03412 TRACE_STRING("transform_size_8x8_flag");
03413
03414
03415 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
03416 {
03417 currSE.len = 1;
03418 readSyntaxElement_FLC(&currSE, dP->bitstream);
03419 }
03420 else
03421 {
03422 dP->readSyntaxElement(&currSE,img,dP);
03423 }
03424 currMB->luma_transform_size_8x8_flag = currSE.value1;
03425 }
03426
03427
03428
03429
03430 if (cbp !=0)
03431 {
03432 read_delta_quant(&currSE, dP, currSlice, img, currMB, partMap, (IS_INTER (currMB)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA);
03433
03434 if (currSlice->dp_mode)
03435 {
03436 if (IS_INTER (currMB) && currSlice->dpC_NotPresent )
03437 currMB->dpl_flag = 1;
03438
03439 if( intra && currSlice->dpB_NotPresent )
03440 {
03441 currMB->ei_flag = 1;
03442 currMB->dpl_flag = 1;
03443 }
03444
03445
03446 check_dp_neighbors (currMB);
03447 if (currMB->dpl_flag)
03448 {
03449 cbp = 0;
03450 currMB->cbp = cbp;
03451 }
03452 }
03453 }
03454 }
03455 else
03456 {
03457 cbp = currMB->cbp;
03458 }
03459
03460 memset(&img->cof[0][0][0], 0, MB_PIXELS * sizeof(int));
03461
03462
03463 if (IS_I16MB (currMB))
03464 {
03465 read_delta_quant(&currSE, dP, currSlice, img, currMB, partMap, SE_DELTA_QUANT_INTRA);
03466
03467 for (j=0;j<BLOCK_SIZE;j++)
03468 memset(&img->ipredmode[img->block_y+j][img->block_x], DC_PRED, BLOCK_SIZE * sizeof(byte));
03469
03470 if (currSlice->dp_mode)
03471 {
03472 if (currSlice->dpB_NotPresent)
03473 {
03474 currMB->ei_flag = 1;
03475 currMB->dpl_flag = 1;
03476 }
03477 check_dp_neighbors (currMB);
03478 if (currMB->dpl_flag)
03479 {
03480 currMB->cbp = cbp = 0;
03481 }
03482 }
03483
03484 if (!currMB->dpl_flag)
03485 {
03486 pos_scan_4x4 = pos_scan4x4[0];
03487
03488 if (active_pps->entropy_coding_mode_flag == UVLC)
03489 {
03490 readCoeff4x4_CAVLC(currSlice, currMB, img, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff);
03491
03492 for(k = 0; k < numcoeff; k++)
03493 {
03494 if (levarr[k] != 0)
03495 {
03496 pos_scan_4x4 += 2 * runarr[k];
03497
03498 i0 = ((*pos_scan_4x4++) << 2);
03499 j0 = ((*pos_scan_4x4++) << 2);
03500
03501 img->cof[0][j0][i0] = levarr[k];
03502
03503 }
03504 }
03505 }
03506 else
03507 {
03508 currSE.type = SE_LUM_DC_INTRA;
03509 dP = &(currSlice->partArr[partMap[currSE.type]]);
03510
03511 currSE.context = LUMA_16DC;
03512 currSE.type = SE_LUM_DC_INTRA;
03513 img->is_intra_block = 1;
03514
03515 if (dP->bitstream->ei_flag)
03516 {
03517 currSE.mapping = linfo_levrun_inter;
03518 }
03519 else
03520 {
03521 currSE.reading = readRunLevel_CABAC;
03522 }
03523
03524 level = 1;
03525
03526 for(k = 0; (k < 17) && (level != 0); k++)
03527 {
03528 #if TRACE
03529 snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC luma 16x16 ");
03530 #endif
03531 dP->readSyntaxElement(&currSE, img, dP);
03532 level = currSE.value1;
03533
03534 if (level != 0)
03535 {
03536 pos_scan_4x4 += (2 * currSE.value2);
03537
03538 i0 = ((*pos_scan_4x4++) << 2);
03539 j0 = ((*pos_scan_4x4++) << 2);
03540
03541 img->cof[0][j0][i0] = level;
03542
03543 }
03544 }
03545 }
03546
03547 if(currMB->is_lossless == FALSE)
03548 itrans_2(img, currMB, (ColorPlane) img->colour_plane_id);
03549 }
03550 }
03551
03552 update_qp(img, currMB, img->qp);
03553
03554 qp_per = qp_per_matrix[ currMB->qp_scaled[img->colour_plane_id] ];
03555 qp_rem = qp_rem_matrix[ currMB->qp_scaled[img->colour_plane_id] ];
03556
03557
03558 if (dec_picture->chroma_format_idc != YUV400)
03559 {
03560 for(i=0; i < 2; i++)
03561 {
03562 qp_per_uv[i] = qp_per_matrix[ currMB->qp_scaled[i + 1] ];
03563 qp_rem_uv[i] = qp_rem_matrix[ currMB->qp_scaled[i + 1] ];
03564 }
03565 }
03566
03567 InvLevelScale4x4 = intra? InvLevelScale4x4_Intra[img->colour_plane_id][qp_rem] : InvLevelScale4x4_Inter[img->colour_plane_id][qp_rem];
03568 InvLevelScale8x8 = intra? InvLevelScale8x8_Intra[img->colour_plane_id][qp_rem] : InvLevelScale8x8_Inter[img->colour_plane_id][qp_rem];
03569
03570
03571 if (active_pps->entropy_coding_mode_flag == UVLC)
03572 {
03573 if (cbp)
03574 {
03575 if (!currMB->luma_transform_size_8x8_flag)
03576 {
03577 readCompCoeff4x4MB_CAVLC (img, currSlice, currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, img->nz_coeff[mb_nr][PLANE_Y]);
03578 }
03579 else
03580 {
03581 readCompCoeff8x8MB_CAVLC (img, currSlice, currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, img->nz_coeff[mb_nr][PLANE_Y]);
03582 }
03583 }
03584 else
03585 {
03586 memset(&img->nz_coeff[mb_nr][0][0][0], 0, BLOCK_SIZE * BLOCK_SIZE * sizeof(byte));
03587 }
03588 }
03589 else
03590 {
03591
03592
03593 if (cbp)
03594 {
03595 if(currMB->luma_transform_size_8x8_flag)
03596 {
03597
03598 readCompCoeff8x8MB_CABAC (img, currSlice, currMB, &currSE, PLANE_Y);
03599 }
03600 else
03601 {
03602 readCompCoeff4x4MB_CABAC (img, currSlice, currMB, &currSE, PLANE_Y, intra, InvLevelScale4x4, qp_per, cbp);
03603 }
03604 }
03605 }
03606
03607 if ( active_sps->chroma_format_idc==YUV444 && !IS_INDEPENDENT(img) )
03608 {
03609 for (uv = 0; uv < 2; uv++ )
03610 {
03611 memset(&img->cof[uv + 1][0][0], 0, MB_PIXELS * sizeof(int));
03612
03613
03614
03615 if (IS_I16MB (currMB))
03616 {
03617 for (j = 0; j < BLOCK_SIZE; j++)
03618 memset(&img->ipredmode[img->block_y + j][img->block_x], DC_PRED, BLOCK_SIZE * sizeof(byte));
03619
03620 if (active_pps->entropy_coding_mode_flag == UVLC)
03621 {
03622 if (uv == 0)
03623 readCoeff4x4_CAVLC(currSlice, currMB, img, CB_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff);
03624 else
03625 readCoeff4x4_CAVLC(currSlice, currMB, img, CR_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff);
03626
03627 coef_ctr=-1;
03628 level = 1;
03629
03630 for(k = 0; k < numcoeff; k++)
03631 {
03632 if (levarr[k] != 0)
03633 {
03634 coef_ctr += runarr[k] + 1;
03635
03636 i0 = pos_scan4x4[coef_ctr][0];
03637 j0 = pos_scan4x4[coef_ctr][1];
03638 img->cof[uv + 1][j0<<2][i0<<2] = levarr[k];
03639
03640 }
03641 }
03642 }
03643 else
03644 {
03645 currSE.type = SE_LUM_DC_INTRA;
03646 dP = &(currSlice->partArr[partMap[currSE.type]]);
03647
03648 if( IS_INDEPENDENT(img) )
03649 currSE.context = LUMA_16DC;
03650 else
03651 currSE.context = (uv==0) ? CB_16DC : CR_16DC;
03652
03653 img->is_intra_block = 1;
03654
03655 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
03656 {
03657 currSE.mapping = linfo_levrun_inter;
03658 }
03659 else
03660 {
03661 currSE.reading = readRunLevel_CABAC;
03662 }
03663
03664 coef_ctr = -1;
03665 level = 1;
03666
03667 for(k=0;(k<17) && (level!=0);k++)
03668 {
03669 #if TRACE
03670 if (uv == 0)
03671 snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC Cb 16x16 ");
03672 else
03673 snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC Cr 16x16 ");
03674 #endif
03675
03676 dP->readSyntaxElement(&currSE,img,dP);
03677 level = currSE.value1;
03678
03679 if (level != 0)
03680 {
03681 coef_ctr += currSE.value2 + 1;
03682
03683 i0 = pos_scan4x4[coef_ctr][0];
03684 j0 = pos_scan4x4[coef_ctr][1];
03685 img->cof[uv + 1][j0<<2][i0<<2] = level;
03686
03687 }
03688 }
03689 }
03690
03691 if(currMB->is_lossless == FALSE)
03692 {
03693 itrans_2(img, currMB, (ColorPlane) (uv + 1));
03694 }
03695 }
03696
03697 update_qp(img, currMB, img->qp);
03698
03699 qp_per = qp_per_matrix[ (img->qp + img->bitdepth_luma_qp_scale) ];
03700 qp_rem = qp_rem_matrix[ (img->qp + img->bitdepth_luma_qp_scale) ];
03701
03702
03703 qp_per_uv[uv] = qp_per_matrix[ (currMB->qpc[uv] + img->bitdepth_chroma_qp_scale) ];
03704 qp_rem_uv[uv] = qp_rem_matrix[ (currMB->qpc[uv] + img->bitdepth_chroma_qp_scale) ];
03705
03706 InvLevelScale4x4 = intra? InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]];
03707 InvLevelScale8x8 = intra? InvLevelScale8x8_Intra[uv + 1][qp_rem_uv[uv]] : InvLevelScale8x8_Inter[uv + 1][qp_rem_uv[uv]];
03708
03709 if (active_pps->entropy_coding_mode_flag == UVLC)
03710 {
03711 if (!currMB->luma_transform_size_8x8_flag)
03712 {
03713 readCompCoeff4x4MB_CAVLC (img, currSlice, currMB, (ColorPlane) (PLANE_U + uv), InvLevelScale4x4, qp_per_uv[uv], cbp, img->nz_coeff[mb_nr][PLANE_U + uv]);
03714 }
03715 else
03716 {
03717 readCompCoeff8x8MB_CAVLC (img, currSlice, currMB, (ColorPlane) (PLANE_U + uv), InvLevelScale8x8, qp_per_uv[uv], cbp, img->nz_coeff[mb_nr][PLANE_U + uv]);
03718 }
03719 }
03720 else
03721 {
03722 if (cbp)
03723 {
03724 if(currMB->luma_transform_size_8x8_flag)
03725 {
03726
03727 readCompCoeff8x8MB_CABAC (img, currSlice, currMB, &currSE, (ColorPlane) (PLANE_U + uv));
03728 }
03729 else
03730 {
03731 readCompCoeff4x4MB_CABAC (img, currSlice, currMB, &currSE, (ColorPlane) (PLANE_U + uv), intra, InvLevelScale4x4, qp_per_uv[uv], cbp);
03732 }
03733 }
03734 }
03735 }
03736 }
03737 else if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444))
03738 {
03739 memset(&img->cof[1][0][0], 0, 2 * MB_PIXELS * sizeof(int));
03740
03741
03742
03743
03744
03745 if(cbp>15)
03746 {
03747 if (dec_picture->chroma_format_idc == YUV420)
03748 {
03749 for (ll=0;ll<3;ll+=2)
03750 {
03751 uv = ll>>1;
03752
03753 InvLevelScale4x4 = intra ? InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]];
03754
03755 memset(&img->cofu[0], 0, 4 *sizeof(int));
03756 coef_ctr=-1;
03757
03758 if (active_pps->entropy_coding_mode_flag == UVLC)
03759 {
03760
03761 readCoeff4x4_CAVLC(currSlice, currMB, img, CHROMA_DC, 0, 0, levarr, runarr, &numcoeff);
03762
03763 for(k = 0; k < numcoeff; k++)
03764 {
03765 if (levarr[k] != 0)
03766 {
03767 currMB->cbp_blk[0] |= 0xf0000 << (ll<<1) ;
03768 coef_ctr += runarr[k] + 1;
03769 img->cofu[coef_ctr]=levarr[k];
03770 }
03771 }
03772 }
03773 else
03774 {
03775 level=1;
03776 img->is_intra_block = intra;
03777 img->is_v_block = ll;
03778 currSE.context = CHROMA_DC;
03779 currSE.type = (intra ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER);
03780
03781 dP = &(currSlice->partArr[partMap[currSE.type]]);
03782
03783 if (dP->bitstream->ei_flag)
03784 currSE.mapping = linfo_levrun_c2x2;
03785 else
03786 currSE.reading = readRunLevel_CABAC;
03787
03788 for(k = 0; (k < (img->num_cdc_coeff + 1))&&(level!=0);k++)
03789 {
03790 #if TRACE
03791 snprintf(currSE.tracestring, TRACESTRING_SIZE, "2x2 DC Chroma ");
03792 #endif
03793
03794 dP->readSyntaxElement(&currSE,img,dP);
03795 level = currSE.value1;
03796
03797 if (level != 0)
03798 {
03799 currMB->cbp_blk[0] |= 0xf0000 << (ll<<1) ;
03800 coef_ctr += currSE.value2 + 1;
03801
03802
03803
03804
03805
03806
03807
03808
03809
03810 assert (coef_ctr < img->num_cdc_coeff);
03811 img->cofu[coef_ctr]=level;
03812 }
03813 }
03814 }
03815
03816 if (smb || (currMB->is_lossless == TRUE))
03817 {
03818 img->cof[uv + 1][0][0] = img->cofu[0];
03819 img->cof[uv + 1][4][0] = img->cofu[1];
03820 img->cof[uv + 1][0][4] = img->cofu[2];
03821 img->cof[uv + 1][4][4] = img->cofu[3];
03822
03823
03824
03825
03826 }
03827 else
03828 {
03829 ihadamard2x2(img->cofu, temp);
03830
03831
03832
03833
03834
03835 img->cof[uv + 1][0][0] = (((temp[0] * InvLevelScale4x4[0][0])<<qp_per_uv[uv])>>5);
03836 img->cof[uv + 1][0][4] = (((temp[1] * InvLevelScale4x4[0][0])<<qp_per_uv[uv])>>5);
03837 img->cof[uv + 1][4][0] = (((temp[2] * InvLevelScale4x4[0][0])<<qp_per_uv[uv])>>5);
03838 img->cof[uv + 1][4][4] = (((temp[3] * InvLevelScale4x4[0][0])<<qp_per_uv[uv])>>5);
03839 }
03840 }
03841 }
03842 else if (dec_picture->chroma_format_idc == YUV422)
03843 {
03844 for (ll=0;ll<3;ll+=2)
03845 {
03846 int (*InvLevelScale4x4)[4] = NULL;
03847 uv = ll>>1;
03848 {
03849 int **imgcof = img->cof[uv + 1];
03850 int m3[2][4] = {{0,0,0,0},{0,0,0,0}};
03851 int m4[2][4] = {{0,0,0,0},{0,0,0,0}};
03852 int qp_per_uv_dc = qp_per_matrix[ (currMB->qpc[uv] + 3 + img->bitdepth_chroma_qp_scale) ];
03853 int qp_rem_uv_dc = qp_rem_matrix[ (currMB->qpc[uv] + 3 + img->bitdepth_chroma_qp_scale) ];
03854 if (intra)
03855 InvLevelScale4x4 = InvLevelScale4x4_Intra[uv + 1][qp_rem_uv_dc];
03856 else
03857 InvLevelScale4x4 = InvLevelScale4x4_Inter[uv + 1][qp_rem_uv_dc];
03858
03859
03860
03861 if (active_pps->entropy_coding_mode_flag == UVLC)
03862 {
03863 readCoeff4x4_CAVLC(currSlice, currMB, img, CHROMA_DC, 0, 0, levarr, runarr, &numcoeff);
03864 coef_ctr=-1;
03865 level=1;
03866 for(k = 0; k < numcoeff; k++)
03867 {
03868 if (levarr[k] != 0)
03869 {
03870 currMB->cbp_blk[0] |= ((int64)0xff0000) << (ll<<2);
03871 coef_ctr += runarr[k]+1;
03872 i0 = SCAN_YUV422[coef_ctr][0];
03873 j0 = SCAN_YUV422[coef_ctr][1];
03874
03875 m3[i0][j0]=levarr[k];
03876 }
03877 }
03878 }
03879 else
03880 {
03881 coef_ctr=-1;
03882 level=1;
03883 for(k=0;(k<9)&&(level!=0);k++)
03884 {
03885 currSE.context = CHROMA_DC_2x4;
03886 currSE.type = (IS_INTRA(currMB) ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER);
03887 img->is_intra_block = IS_INTRA(currMB);
03888 img->is_v_block = ll;
03889
03890 #if TRACE
03891 snprintf(currSE.tracestring, TRACESTRING_SIZE, "2x4 DC Chroma ");
03892 #endif
03893 dP = &(currSlice->partArr[partMap[currSE.type]]);
03894
03895 if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
03896 currSE.mapping = linfo_levrun_c2x2;
03897 else
03898 currSE.reading = readRunLevel_CABAC;
03899
03900 dP->readSyntaxElement(&currSE,img,dP);
03901
03902 level = currSE.value1;
03903
03904 if (level != 0)
03905 {
03906 currMB->cbp_blk[0] |= ((int64)0xff0000) << (ll<<2) ;
03907 coef_ctr += currSE.value2 + 1;
03908 assert (coef_ctr < img->num_cdc_coeff);
03909 i0=SCAN_YUV422[coef_ctr][0];
03910 j0=SCAN_YUV422[coef_ctr][1];
03911
03912 m3[i0][j0]=level;
03913 }
03914 }
03915 }
03916
03917
03918 if(currMB->is_lossless == FALSE)
03919 {
03920 m4[0][0] = m3[0][0] + m3[1][0];
03921 m4[0][1] = m3[0][1] + m3[1][1];
03922 m4[0][2] = m3[0][2] + m3[1][2];
03923 m4[0][3] = m3[0][3] + m3[1][3];
03924
03925 m4[1][0] = m3[0][0] - m3[1][0];
03926 m4[1][1] = m3[0][1] - m3[1][1];
03927 m4[1][2] = m3[0][2] - m3[1][2];
03928 m4[1][3] = m3[0][3] - m3[1][3];
03929
03930 for (i = 0; i < 2; i++)
03931 {
03932 m6[0] = m4[i][0] + m4[i][2];
03933 m6[1] = m4[i][0] - m4[i][2];
03934 m6[2] = m4[i][1] - m4[i][3];
03935 m6[3] = m4[i][1] + m4[i][3];
03936
03937 imgcof[ 0][i<<2] = m6[0] + m6[3];
03938 imgcof[ 4][i<<2] = m6[1] + m6[2];
03939 imgcof[ 8][i<<2] = m6[1] - m6[2];
03940 imgcof[12][i<<2] = m6[0] - m6[3];
03941 }
03942 }
03943 else
03944 {
03945 for(j=0;j<4;j++)
03946 {
03947 for(i=0;i<2;i++)
03948 {
03949 img->cof[uv + 1][j<<2][i<<2] = m3[i][j];
03950
03951 }
03952 }
03953 }
03954
03955 for(j = 0;j < img->mb_cr_size_y; j += BLOCK_SIZE)
03956 {
03957 for(i=0;i < img->mb_cr_size_x;i+=BLOCK_SIZE)
03958 {
03959 imgcof[j][i] = rshift_rnd_sf((imgcof[j][i] * InvLevelScale4x4[0][0]) << qp_per_uv_dc, 6);
03960 }
03961 }
03962 }
03963 }
03964 }
03965 }
03966
03967
03968
03969
03970 if (cbp<=31)
03971 {
03972 if (active_pps->entropy_coding_mode_flag == UVLC)
03973 memset(&img->nz_coeff [mb_nr ][1][0][0], 0, 2 * BLOCK_SIZE * BLOCK_SIZE * sizeof(byte));
03974 }
03975 else
03976 {
03977 if (active_pps->entropy_coding_mode_flag == UVLC)
03978 {
03979 if(currMB->is_lossless == FALSE)
03980 {
03981 for (b8=0; b8 < img->num_blk8x8_uv; b8++)
03982 {
03983 img->is_v_block = uv = (b8 > ((img->num_uv_blocks) - 1 ));
03984 InvLevelScale4x4 = intra ? InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]];
03985
03986 for (b4=0; b4 < 4; b4++)
03987 {
03988 i = cofuv_blk_x[yuv][b8][b4];
03989 j = cofuv_blk_y[yuv][b8][b4];
03990
03991 readCoeff4x4_CAVLC(currSlice, currMB, img, CHROMA_AC, i + 2*uv, j + 4, levarr, runarr, &numcoeff);
03992 coef_ctr = 0;
03993
03994 for(k = 0; k < numcoeff;k++)
03995 {
03996 if (levarr[k] != 0)
03997 {
03998 currMB->cbp_blk[0] |= ((int64)1) << cbp_blk_chroma[b8][b4];
03999 coef_ctr += runarr[k] + 1;
04000
04001 i0=pos_scan4x4[coef_ctr][0];
04002 j0=pos_scan4x4[coef_ctr][1];
04003
04004 img->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = rshift_rnd_sf((levarr[k] * InvLevelScale4x4[j0][i0])<<qp_per_uv[uv], 4);
04005
04006 }
04007 }
04008 }
04009 }
04010 }
04011 else
04012 {
04013 for (b8=0; b8 < img->num_blk8x8_uv; b8++)
04014 {
04015 img->is_v_block = uv = (b8 > ((img->num_uv_blocks) - 1 ));
04016
04017 for (b4=0; b4 < 4; b4++)
04018 {
04019 i = cofuv_blk_x[yuv][b8][b4];
04020 j = cofuv_blk_y[yuv][b8][b4];
04021
04022 readCoeff4x4_CAVLC(currSlice, currMB, img, CHROMA_AC, i, j, levarr, runarr, &numcoeff);
04023 coef_ctr=0;
04024
04025 for(k = 0; k < numcoeff;k++)
04026 {
04027 if (levarr[k] != 0)
04028 {
04029 currMB->cbp_blk[0] |= ((int64) 1) << cbp_blk_chroma[b8][b4];
04030 coef_ctr += runarr[k] + 1;
04031
04032 i0 = pos_scan4x4[coef_ctr][0];
04033 j0 = pos_scan4x4[coef_ctr][1];
04034
04035 img->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = levarr[k];
04036
04037 }
04038 }
04039 }
04040 }
04041 }
04042 }
04043 else
04044 {
04045 img->is_intra_block = IS_INTRA(currMB);
04046 currSE.context = CHROMA_AC;
04047 currSE.type = (img->is_intra_block ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER);
04048
04049 dP = &(currSlice->partArr[partMap[currSE.type]]);
04050
04051 if (dP->bitstream->ei_flag)
04052 currSE.mapping = linfo_levrun_inter;
04053 else
04054 currSE.reading = readRunLevel_CABAC;
04055
04056 if(currMB->is_lossless == FALSE)
04057 {
04058 for (b8=0; b8 < img->num_blk8x8_uv; b8++)
04059 {
04060 img->is_v_block = uv = (b8 > ((img->num_uv_blocks) - 1 ));
04061 InvLevelScale4x4 = intra ? InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]];
04062
04063 for (b4 = 0; b4 < 4; b4++)
04064 {
04065 i = cofuv_blk_x[yuv][b8][b4];
04066 j = cofuv_blk_y[yuv][b8][b4];
04067
04068 img->subblock_y = subblk_offset_y[yuv][b8][b4];
04069 img->subblock_x = subblk_offset_x[yuv][b8][b4];
04070
04071 pos_scan_4x4 = pos_scan4x4[1];
04072 level=1;
04073
04074 for(k = 0; (k < 16) && (level != 0);k++)
04075 {
04076 #if TRACE
04077 snprintf(currSE.tracestring, TRACESTRING_SIZE, "AC Chroma ");
04078 #endif
04079
04080 dP->readSyntaxElement(&currSE,img,dP);
04081 level = currSE.value1;
04082
04083 if (level != 0)
04084 {
04085 currMB->cbp_blk[0] |= ((int64)1) << cbp_blk_chroma[b8][b4];
04086 pos_scan_4x4 += (currSE.value2 << 1);
04087
04088 i0 = *pos_scan_4x4++;
04089 j0 = *pos_scan_4x4++;
04090
04091 img->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = rshift_rnd_sf((level * InvLevelScale4x4[j0][i0])<<qp_per_uv[uv], 4);
04092
04093 }
04094 }
04095 }
04096 }
04097 }
04098 else
04099 {
04100 for (b8=0; b8 < img->num_blk8x8_uv; b8++)
04101 {
04102 img->is_v_block = uv = (b8 > ((img->num_uv_blocks) - 1 ));
04103
04104 for (b4=0; b4 < 4; b4++)
04105 {
04106 i = cofuv_blk_x[yuv][b8][b4];
04107 j = cofuv_blk_y[yuv][b8][b4];
04108
04109 pos_scan_4x4 = pos_scan4x4[1];
04110 level=1;
04111
04112 img->subblock_y = subblk_offset_y[yuv][b8][b4];
04113 img->subblock_x = subblk_offset_x[yuv][b8][b4];
04114
04115 for(k=0;(k<16)&&(level!=0);k++)
04116 {
04117 #if TRACE
04118 snprintf(currSE.tracestring, TRACESTRING_SIZE, "AC Chroma ");
04119 #endif
04120 dP->readSyntaxElement(&currSE,img,dP);
04121 level = currSE.value1;
04122
04123 if (level != 0)
04124 {
04125 currMB->cbp_blk[0] |= ((int64)1) << cbp_blk_chroma[b8][b4];
04126 pos_scan_4x4 += (currSE.value2 << 1);
04127
04128 i0 = *pos_scan_4x4++;
04129 j0 = *pos_scan_4x4++;
04130
04131 img->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = level;
04132
04133 }
04134 }
04135 }
04136 }
04137 }
04138 }
04139 }
04140 }
04141 }
04142
04154 void decode_ipcm_mb(ImageParameters *img, Macroblock *currMB)
04155 {
04156 int i, j, k;
04157 int mb_nr = img->current_mb_nr;
04158
04159
04160
04161
04162 for(i = 0; i < MB_BLOCK_SIZE; i++)
04163 {
04164 for(j = 0;j < MB_BLOCK_SIZE ; j++)
04165 {
04166 dec_picture->imgY[img->pix_y+i][img->pix_x+j] = (imgpel) img->cof[0][i][j];
04167 }
04168 }
04169
04170 if ((dec_picture->chroma_format_idc != YUV400) && !IS_INDEPENDENT(img))
04171 {
04172 for (k = 0; k < 2; k++)
04173 {
04174 for(i = 0; i < img->mb_cr_size_y; i++)
04175 {
04176 for(j = 0;j < img->mb_cr_size_x; j++)
04177 {
04178 dec_picture->imgUV[k][img->pix_c_y+i][img->pix_c_x+j] = (imgpel) img->cof[k + 1][i][j];
04179 }
04180 }
04181 }
04182 }
04183
04184
04185 update_qp(img, currMB, 0);
04186
04187
04188
04189 memset(&img->nz_coeff[mb_nr][0][0][0], 16, 3 * BLOCK_SIZE * BLOCK_SIZE * sizeof(byte));
04190
04191
04192 currMB->skip_flag = 0;
04193
04194
04195 currMB->cbp_blk[0] = 0xFFFF;
04196
04197
04198 last_dquant = 0;
04199 }
04200
04208 int decode_one_component(ImageParameters *img, ColorPlane curr_plane, imgpel **currImg, Macroblock *currMB, StorablePicture *dec_picture, MotionParams *colocated, int list_offset)
04209 {
04210 int i=0, j=0,k,jj=0, j4=0,i4=0, j6;
04211 int refList;
04212 int uv;
04213 int ioff,joff;
04214 int block8x8;
04215 int j_pos, i_pos;
04216 PicMotionParams *motion = &dec_picture->motion;
04217
04218 static const byte decode_block_scan[16] = {0,1,4,5,2,3,6,7,8,9,12,13,10,11,14,15};
04219
04220 short ref_idx;
04221 int mv_mode, pred_dir;
04222
04223 int block_size_x, block_size_y;
04224
04225 int mv_scale;
04226 static imgpel **curComp;
04227 static imgpel **mpr;
04228
04229 int smb = ((img->type==SP_SLICE) && currMB->mb_type!=I16MB) || (img->type == SI_SLICE && currMB->mb_type == SI4MB);
04230
04231 char l0_rFrame = -1, l1_rFrame = -1;
04232
04233 short pmvl0[2]={0,0}, pmvl1[2]={0,0};
04234
04235 int direct_pdir=-1;
04236
04237 int curr_mb_field = ((img->MbaffFrameFlag)&&(currMB->mb_field));
04238
04239 int need_4x4_transform = (!currMB->luma_transform_size_8x8_flag);
04240 int yuv = dec_picture->chroma_format_idc - 1;
04241
04242
04243 ipmode_DPCM = NO_INTRA_PMODE;
04244
04245 if (IS_I16MB (currMB))
04246 {
04247 intrapred16x16(img, currMB, curr_plane, currMB->i16mode);
04248 ipmode_DPCM = currMB->i16mode;
04249
04250
04251 iMBtrans4x4(img, currMB, curr_plane, smb);
04252
04253
04254 if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444))
04255 {
04256 intra_cr_decoding(currMB, yuv, img, smb);
04257 }
04258 }
04259 else if (currMB->mb_type == I4MB)
04260 {
04261 itrans_4x4 = (currMB->is_lossless == FALSE) ? itrans4x4 : Inv_Residual_trans_4x4;
04262
04263 for (block8x8 = 0; block8x8 < 4; block8x8++)
04264 {
04265 for (k = block8x8 * 4; k < block8x8 * 4 + 4; k ++)
04266 {
04267 i = (decode_block_scan[k] & 3);
04268 j = ((decode_block_scan[k] >> 2) & 3);
04269
04270 ioff = (i << 2);
04271 joff = (j << 2);
04272 i4 = img->block_x + i;
04273 j4 = img->block_y + j;
04274 j_pos = j4 * BLOCK_SIZE;
04275 i_pos = i4 * BLOCK_SIZE;
04276
04277
04278
04279 if (intrapred(img, currMB, curr_plane, ioff,joff,i4,j4) == SEARCH_SYNC)
04280 return SEARCH_SYNC;
04281
04282
04283 itrans_4x4 (img, curr_plane, ioff, joff);
04284 for(jj = 0; jj < BLOCK_SIZE; jj++)
04285 {
04286 memcpy(&currImg[j_pos + jj][i_pos], &img->mb_rec[curr_plane][jj + joff][ioff], BLOCK_SIZE * sizeof(imgpel));
04287 }
04288 }
04289 }
04290
04291
04292 if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444))
04293 {
04294 intra_cr_decoding(currMB, yuv, img, smb);
04295 }
04296 }
04297 else if (currMB->mb_type == I8MB)
04298 {
04299 itrans_8x8 = (currMB->is_lossless == FALSE) ? itrans8x8 : Inv_Residual_trans_8x8;
04300
04301 for (block8x8 = 0; block8x8 < 4; block8x8++)
04302 {
04303
04304 ioff = 8 * (block8x8 & 0x01);
04305 joff = 8 * (block8x8 >> 1);
04306
04307
04308 intrapred8x8(img, currMB, curr_plane, block8x8);
04309
04310 itrans_8x8(img, currMB, curr_plane, ioff,joff);
04311
04312 for(jj = joff; jj < joff + 8;jj++)
04313 {
04314 memcpy(&currImg[img->pix_y + jj][img->pix_x + ioff], &img->mb_rec[curr_plane][jj][ioff], 8 * sizeof(imgpel));
04315 }
04316 }
04317
04318 if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444))
04319 {
04320 intra_cr_decoding(currMB, yuv, img, smb);
04321 }
04322 }
04323 else if ((img->type == P_SLICE) && (currMB->mb_type == PSKIP))
04324 {
04325 perform_mc(curr_plane, dec_picture, img, LIST_0, 0, 0, list_offset, MB_BLOCK_SIZE, MB_BLOCK_SIZE, curr_mb_field);
04326
04327 mpr = img->mb_pred[curr_plane];
04328 curComp = &currImg[img->pix_y];
04329
04330 for(j = 0; j < img->mb_size[0][1]; j++)
04331 {
04332 memcpy(&(curComp[j][img->pix_x]), &(mpr[j][0]), img->mb_size[0][0] * sizeof(imgpel));
04333 }
04334
04335 if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444))
04336 {
04337 for(uv=0;uv<2;uv++)
04338 {
04339 curComp = &dec_picture->imgUV[uv][img->pix_c_y];
04340
04341 mpr = img->mb_pred[uv + 1];
04342 for(jj = 0; jj < img->mb_size[1][1]; jj++)
04343 memcpy(&(curComp[jj][img->pix_c_x]), &(mpr[jj][0]), img->mb_size[1][0] * sizeof(imgpel));
04344 }
04345 }
04346 }
04347 else if (currMB->mb_type == P16x16)
04348 {
04349 perform_mc(curr_plane, dec_picture, img, currMB->b8pdir[0], 0, 0, list_offset, MB_BLOCK_SIZE, MB_BLOCK_SIZE, curr_mb_field);
04350 iTransform(img, currMB, curr_plane, need_4x4_transform, smb);
04351 }
04352 else if (currMB->mb_type == P16x8)
04353 {
04354 for (block8x8 = 0; block8x8 < 4; block8x8 += 2)
04355 {
04356 perform_mc(curr_plane, dec_picture, img, currMB->b8pdir[block8x8], 0, block8x8, list_offset, MB_BLOCK_SIZE, BLOCK_SIZE_8x8, curr_mb_field);
04357 }
04358 iTransform(img, currMB, curr_plane, need_4x4_transform, smb);
04359 }
04360 else if (currMB->mb_type == P8x16)
04361 {
04362 for (block8x8 = 0; block8x8 < 2; block8x8 ++)
04363 {
04364 perform_mc(curr_plane, dec_picture, img, currMB->b8pdir[block8x8], (block8x8<<1), 0, list_offset, BLOCK_SIZE_8x8, MB_BLOCK_SIZE, curr_mb_field);
04365 }
04366 iTransform(img, currMB, curr_plane, need_4x4_transform, smb);
04367 }
04368 else
04369 {
04370
04371 if (img->type==B_SLICE && img->direct_spatial_mv_pred_flag && (IS_DIRECT (currMB) ||
04372 ((currMB->mb_type == P8x8) && !(currMB->b8mode[0] && currMB->b8mode[1] && currMB->b8mode[2] && currMB->b8mode[3]))))
04373 prepare_direct_params(currMB, dec_picture, img, pmvl0, pmvl1, &l0_rFrame, &l1_rFrame);
04374
04375 for (block8x8=0; block8x8<4; block8x8++)
04376 {
04377 mv_mode = currMB->b8mode[block8x8];
04378 pred_dir = currMB->b8pdir[block8x8];
04379
04380
04381 if ( mv_mode != 0 )
04382 {
04383 int k_start = (block8x8 << 2);
04384 int k_inc = (mv_mode == SMB8x4) ? 2 : 1;
04385 int k_end = (mv_mode == SMB8x8) ? k_start + 1 : ((mv_mode == SMB4x4) ? k_start + 4 : k_start + k_inc + 1);
04386
04387 block_size_x = ( mv_mode == SMB8x4 || mv_mode == SMB8x8 ) ? SMB_BLOCK_SIZE : BLOCK_SIZE;
04388 block_size_y = ( mv_mode == SMB4x8 || mv_mode == SMB8x8 ) ? SMB_BLOCK_SIZE : BLOCK_SIZE;
04389
04390 for (k = k_start; k < k_end; k += k_inc)
04391 {
04392 i = (decode_block_scan[k] & 3);
04393 j = ((decode_block_scan[k] >> 2) & 3);
04394 perform_mc(curr_plane, dec_picture, img, pred_dir, i, j, list_offset, block_size_x, block_size_y, curr_mb_field);
04395 }
04396 }
04397 else
04398 {
04399 int k_start = (block8x8 << 2);
04400 int k_end = k_start;
04401
04402 if (active_sps->direct_8x8_inference_flag)
04403 {
04404 block_size_x = SMB_BLOCK_SIZE;
04405 block_size_y = SMB_BLOCK_SIZE;
04406 k_end ++;
04407 }
04408 else
04409 {
04410 block_size_x = BLOCK_SIZE;
04411 block_size_y = BLOCK_SIZE;
04412 k_end += BLOCK_MULTIPLE;
04413 }
04414
04415
04416
04417 if (img->direct_spatial_mv_pred_flag)
04418 {
04419 for (k = k_start; k < k_start + BLOCK_MULTIPLE; k ++)
04420 {
04421
04422 i = (decode_block_scan[k] & 3);
04423 j = ((decode_block_scan[k] >> 2) & 3);
04424
04425 ioff = (i << 2);
04426 i4 = img->block_x + i;
04427
04428 joff = (j << 2);
04429 j4 = img->block_y + j;
04430
04431 assert (pred_dir<=2);
04432
04433 j6 = img->block_y_aff + j;
04434
04435
04436
04437 if (l0_rFrame >=0)
04438 {
04439 if (!l0_rFrame && ((!colocated->moving_block[j6][i4]) && (!listX[LIST_1 + list_offset][0]->is_long_term)))
04440 {
04441 motion->mv [LIST_0][j4][i4][0] = 0;
04442 motion->mv [LIST_0][j4][i4][1] = 0;
04443 motion->ref_idx[LIST_0][j4][i4] = 0;
04444 }
04445 else
04446 {
04447 motion->mv [LIST_0][j4][i4][0] = pmvl0[0];
04448 motion->mv [LIST_0][j4][i4][1] = pmvl0[1];
04449 motion->ref_idx[LIST_0][j4][i4] = l0_rFrame;
04450 }
04451 }
04452 else
04453 {
04454 motion->ref_idx[LIST_0][j4][i4] = -1;
04455 motion->mv [LIST_0][j4][i4][0] = 0;
04456 motion->mv [LIST_0][j4][i4][1] = 0;
04457 }
04458
04459 if (l1_rFrame >=0)
04460 {
04461 if (l1_rFrame==0 && ((!colocated->moving_block[j6][i4]) && (!listX[LIST_1 + list_offset][0]->is_long_term)))
04462 {
04463
04464 motion->mv [LIST_1][j4][i4][0] = 0;
04465 motion->mv [LIST_1][j4][i4][1] = 0;
04466 motion->ref_idx[LIST_1][j4][i4] = l1_rFrame;
04467 }
04468 else
04469 {
04470 motion->mv [LIST_1][j4][i4][0] = pmvl1[0];
04471 motion->mv [LIST_1][j4][i4][1] = pmvl1[1];
04472 motion->ref_idx[LIST_1][j4][i4] = l1_rFrame;
04473 }
04474 }
04475 else
04476 {
04477 motion->mv [LIST_1][j4][i4][0] = 0;
04478 motion->mv [LIST_1][j4][i4][1] = 0;
04479 motion->ref_idx[LIST_1][j4][i4] = -1;
04480 }
04481
04482 if (l0_rFrame < 0 && l1_rFrame < 0)
04483 {
04484 motion->ref_idx[LIST_0][j4][i4] = 0;
04485 motion->ref_idx[LIST_1][j4][i4] = 0;
04486 }
04487
04488 if (motion->ref_idx[LIST_1][j4][i4]==-1)
04489 {
04490 direct_pdir = 0;
04491 ref_idx = (motion->ref_idx[LIST_0][j4][i4] != -1) ? motion->ref_idx[LIST_0][j4][i4] : 0;
04492 }
04493 else if (motion->ref_idx[LIST_0][j4][i4]==-1)
04494 {
04495 direct_pdir = 1;
04496 ref_idx = (motion->ref_idx[LIST_1][j4][i4] != -1) ? motion->ref_idx[LIST_1][j4][i4] : 0;
04497 }
04498 else
04499 direct_pdir = 2;
04500
04501 pred_dir = direct_pdir;
04502
04503 motion->ref_pic_id[LIST_0][j4][i4] = dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][(short)motion->ref_idx[LIST_0][j4][i4]];
04504 motion->ref_pic_id[LIST_1][j4][i4] = dec_picture->ref_pic_num[img->current_slice_nr][LIST_1 + list_offset][(short)motion->ref_idx[LIST_1][j4][i4]];
04505 }
04506 }
04507 else
04508 {
04509 for (k = k_start; k < k_start + BLOCK_MULTIPLE; k ++)
04510 {
04511
04512 i = (decode_block_scan[k] & 3);
04513 j = ((decode_block_scan[k] >> 2) & 3);
04514
04515 ioff = (i << 2);
04516 i4 = img->block_x + i;
04517
04518 joff = (j << 2);
04519 j4 = img->block_y + j;
04520
04521 assert (pred_dir<=2);
04522
04523 j6 = img->block_y_aff + j;
04524
04525 refList = (colocated->ref_idx[LIST_0][j6][i4]== -1 ? LIST_1 : LIST_0);
04526 ref_idx = colocated->ref_idx[refList][j6][i4];
04527
04528 if(ref_idx==-1)
04529 {
04530 memset( &motion->mv [LIST_0][j4][i4][0], 0, 2* sizeof(short));
04531 memset( &motion->mv [LIST_1][j4][i4][0], 0, 2* sizeof(short));
04532
04533 motion->ref_idx[LIST_0][j4][i4] = 0;
04534 motion->ref_idx[LIST_1][j4][i4] = 0;
04535 }
04536 else
04537 {
04538 int mapped_idx=0;
04539 int iref;
04540
04541 for (iref=0;iref<imin(img->num_ref_idx_l0_active,listXsize[LIST_0 + list_offset]);iref++)
04542 {
04543 if(img->structure==0 && curr_mb_field==0)
04544 {
04545
04546
04547
04548 if(listX[0][iref]->top_poc*2 == colocated->ref_pic_id[refList][j6][i4] || listX[0][iref]->bottom_poc*2 == colocated->ref_pic_id[refList][j6][i4])
04549 {
04550 mapped_idx=iref;
04551 break;
04552 }
04553 else
04554 mapped_idx=INVALIDINDEX;
04555 continue;
04556 }
04557
04558 if (dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][iref]==colocated->ref_pic_id[refList][j6][i4])
04559 {
04560 mapped_idx=iref;
04561 break;
04562 }
04563 else
04564 {
04565 mapped_idx=INVALIDINDEX;
04566 }
04567 }
04568 if (INVALIDINDEX == mapped_idx)
04569 {
04570 error("temporal direct error: colocated block has ref that is unavailable",-1111);
04571 }
04572
04573 mv_scale = img->mvscale[LIST_0 + list_offset][mapped_idx];
04574
04576 if (mv_scale == 9999 || listX[LIST_0+list_offset][mapped_idx]->is_long_term)
04577 {
04578 memcpy(&motion->mv [LIST_0][j4][i4][0], &colocated->mv[refList][j6][i4][0], 2 * sizeof(short));
04579 memset(&motion->mv [LIST_1][j4][i4][0], 0, 2 * sizeof(short));
04580 }
04581 else
04582 {
04583 motion->mv [LIST_0][j4][i4][0]=(mv_scale * colocated->mv[refList][j6][i4][0] + 128 ) >> 8;
04584 motion->mv [LIST_0][j4][i4][1]=(mv_scale * colocated->mv[refList][j6][i4][1] + 128 ) >> 8;
04585
04586 motion->mv [LIST_1][j4][i4][0]=motion->mv[LIST_0][j4][i4][0] - colocated->mv[refList][j6][i4][0] ;
04587 motion->mv [LIST_1][j4][i4][1]=motion->mv[LIST_0][j4][i4][1] - colocated->mv[refList][j6][i4][1] ;
04588 }
04589
04590 motion->ref_idx[LIST_0][j4][i4] = (char) mapped_idx;
04591 motion->ref_idx[LIST_1][j4][i4] = 0;
04592 }
04593
04594 motion->ref_pic_id[LIST_0][j4][i4] = dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][(short)motion->ref_idx[LIST_0][j4][i4]];
04595 motion->ref_pic_id[LIST_1][j4][i4] = dec_picture->ref_pic_num[img->current_slice_nr][LIST_1 + list_offset][(short)motion->ref_idx[LIST_1][j4][i4]];
04596 }
04597 }
04598
04599 for (k = k_start; k < k_end; k ++)
04600 {
04601 i = (decode_block_scan[k] & 3);
04602 j = ((decode_block_scan[k] >> 2) & 3);
04603 perform_mc(curr_plane, dec_picture, img, pred_dir, i, j, list_offset, block_size_x, block_size_y, curr_mb_field);
04604 }
04605 }
04606 }
04607
04608 iTransform(img, currMB, curr_plane, need_4x4_transform, smb);
04609 }
04610 return 1;
04611 }
04612
04620 int decode_one_macroblock(ImageParameters *img, Macroblock *currMB, StorablePicture *dec_picture)
04621 {
04622 int k,l;
04623 int uv;
04624 ColorPlane curr_plane = PLANE_Y;
04625
04626 int mb_nr = img->current_mb_nr;
04627 int curr_mb_field = ((img->MbaffFrameFlag) && (currMB->mb_field));
04628 int list_offset = 0;
04629
04630 MotionParams *colocated = &Co_located->frame;
04631
04632
04633 if(currMB->mb_type == IPCM)
04634 {
04635
04636 decode_ipcm_mb(img, currMB);
04637 return 0;
04638 }
04639
04640 img->max_mb_vmv_r = (img->structure != FRAME || (img->MbaffFrameFlag && currMB->mb_field)) ? img->max_vmv_r >> 1 : img->max_vmv_r;
04642
04643 if (curr_mb_field)
04644 {
04645 if(mb_nr&0x01)
04646 {
04647 list_offset = 4;
04648 colocated = &Co_located->bottom;
04649 }
04650 else
04651 {
04652 list_offset = 2;
04653 colocated = &Co_located->top;
04654 }
04655 }
04656
04657 if (!img->MbaffFrameFlag)
04658 {
04659 for (l = LIST_0 + list_offset; l <= (LIST_1 + list_offset); l++)
04660 {
04661 for(k = 0; k < listXsize[l]; k++)
04662 {
04663 listX[l][k]->chroma_vector_adjustment= 0;
04664 if(img->structure == TOP_FIELD && img->structure != listX[l][k]->structure)
04665 listX[l][k]->chroma_vector_adjustment = -2;
04666 if(img->structure == BOTTOM_FIELD && img->structure != listX[l][k]->structure)
04667 listX[l][k]->chroma_vector_adjustment = 2;
04668 }
04669 }
04670 }
04671 else
04672 {
04673 if (curr_mb_field)
04674 {
04675 for (l = LIST_0 + list_offset; l <= (LIST_1 + list_offset); l++)
04676 {
04677 for(k = 0; k < listXsize[l]; k++)
04678 {
04679 listX[l][k]->chroma_vector_adjustment= 0;
04680 if(mb_nr % 2 == 0 && listX[l][k]->structure == BOTTOM_FIELD)
04681 listX[l][k]->chroma_vector_adjustment = -2;
04682 if(mb_nr % 2 == 1 && listX[l][k]->structure == TOP_FIELD)
04683 listX[l][k]->chroma_vector_adjustment = 2;
04684 }
04685 }
04686 }
04687 else
04688 {
04689 for (l = LIST_0 + list_offset; l <= (LIST_1 + list_offset); l++)
04690 {
04691 for(k = 0; k < listXsize[l]; k++)
04692 {
04693 listX[l][k]->chroma_vector_adjustment= 0;
04694 }
04695 }
04696 }
04697 }
04698
04699
04700 decode_one_component(img, curr_plane, dec_picture->imgY, currMB, dec_picture, colocated, list_offset);
04701
04702 if ((active_sps->chroma_format_idc==YUV444)&&(!IS_INDEPENDENT(img)))
04703 {
04704 for (uv = 0; uv < 2; uv++ )
04705 {
04706 curr_plane = (ColorPlane) (uv + 1);
04707
04708 decode_one_component(img, curr_plane, dec_picture->imgUV[uv], currMB, dec_picture, colocated, list_offset);
04709 }
04710 }
04711 return 0;
04712 }
04713
04714
04722 void change_plane_JV( int nplane )
04723 {
04724 img->colour_plane_id = nplane;
04725 img->mb_data = img->mb_data_JV[nplane];
04726 dec_picture = dec_picture_JV[nplane];
04727 Co_located = Co_located_JV[nplane];
04728 }
04729
04737 void make_frame_picture_JV()
04738 {
04739 int uv, line;
04740 int nsize;
04741 int nplane;
04742 dec_picture = dec_picture_JV[0];
04743
04744
04745 for( nplane=0; nplane<MAX_PLANE; nplane++ )
04746 {
04747 copy_storable_param_JV( &dec_picture->JVmotion[nplane], &dec_picture_JV[nplane]->motion );
04748 }
04749
04750
04751 for( uv=0; uv<2; uv++ )
04752 {
04753 for( line=0; line<img->height; line++ )
04754 {
04755 nsize = sizeof(imgpel) * img->width;
04756 memcpy( dec_picture->imgUV[uv][line], dec_picture_JV[uv+1]->imgY[line], nsize );
04757 }
04758 free_storable_picture(dec_picture_JV[uv+1]);
04759 }
04760 }
04761
04762