-
-/**
- * initialise predictors for motion vectors and intra prediction
- */
-static inline void init_mb(AVSContext *h) {
- int i;
-
- /* copy predictors from top line (MB B and C) into cache */
- for(i=0;i<3;i++) {
- h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
- h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
- }
- h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
- h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
- /* clear top predictors if MB B is not available */
- if(!(h->flags & B_AVAIL)) {
- h->mv[MV_FWD_B2] = ff_cavs_un_mv;
- h->mv[MV_FWD_B3] = ff_cavs_un_mv;
- h->mv[MV_BWD_B2] = ff_cavs_un_mv;
- h->mv[MV_BWD_B3] = ff_cavs_un_mv;
- h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
- h->flags &= ~(C_AVAIL|D_AVAIL);
- } else if(h->mbx) {
- h->flags |= D_AVAIL;
- }
- if(h->mbx == h->mb_width-1) //MB C not available
- h->flags &= ~C_AVAIL;
- /* clear top-right predictors if MB C is not available */
- if(!(h->flags & C_AVAIL)) {
- h->mv[MV_FWD_C2] = ff_cavs_un_mv;
- h->mv[MV_BWD_C2] = ff_cavs_un_mv;
- }
- /* clear top-left predictors if MB D is not available */
- if(!(h->flags & D_AVAIL)) {
- h->mv[MV_FWD_D3] = ff_cavs_un_mv;
- h->mv[MV_BWD_D3] = ff_cavs_un_mv;
- }
- /* set pointer for co-located macroblock type */
- h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx];
-}
-
-static inline void check_for_slice(AVSContext *h);
-
-/**
- * save predictors for later macroblocks and increase
- * macroblock address
- * @returns 0 if end of frame is reached, 1 otherwise
- */
-static inline int next_mb(AVSContext *h) {
- int i;
-
- h->flags |= A_AVAIL;
- h->cy += 16;
- h->cu += 8;
- h->cv += 8;
- /* copy mvs as predictors to the left */
- for(i=0;i<=20;i+=4)
- h->mv[i] = h->mv[i+2];
- /* copy bottom mvs from cache to top line */
- h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
- h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
- h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
- h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
- /* next MB address */
- h->mbx++;
- if(h->mbx == h->mb_width) { //new mb line
- h->flags = B_AVAIL|C_AVAIL;
- /* clear left pred_modes */
- h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
- /* clear left mv predictors */
- for(i=0;i<=20;i+=4)
- h->mv[i] = ff_cavs_un_mv;
- h->mbx = 0;
- h->mby++;
- /* re-calculate sample pointers */
- h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
- h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
- h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
- if(h->mby == h->mb_height) { //frame end
- return 0;
- } else {
- //check_for_slice(h);
+static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
+ DCTELEM *dst, int mul, int shift, int coeff_num) {
+ int round = 1 << (shift - 1);
+ int pos = -1;
+ const uint8_t *scantab = h->scantable.permutated;
+
+ /* inverse scan and dequantization */
+ while(--coeff_num >= 0){
+ pos += run_buf[coeff_num];
+ if(pos > 63) {
+ av_log(h->s.avctx, AV_LOG_ERROR,
+ "position out of block bounds at pic %d MB(%d,%d)\n",
+ h->picture.poc, h->mbx, h->mby);
+ return -1;