static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
{
    MpegEncContext *s = &v->s;
    DSPContext *dsp = &v->s.dsp;
    uint8_t *srcY;
    int dxy, mx, my, src_x, src_y;
    int off;
    int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0;
    int v_edge_pos = s->v_edge_pos >> v->field_mode;
    if ((!v->field_mode ||
         (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&
        !v->s.last_picture.f.data[0])
    mx = s->mv[dir][n][0];
    my = s->mv[dir][n][1];
    if (!dir) {
        if (v->field_mode) {
            if ((v->cur_field_type != v->ref_field_type[dir]) && v->second_field)
                srcY = s->current_picture.f.data[0];
            else
                srcY = s->last_picture.f.data[0];
        } else
            srcY = s->last_picture.f.data[0];
    } else
        srcY = s->next_picture.f.data[0];
    if (v->field_mode) {
        if (v->cur_field_type != v->ref_field_type[dir])
            my = my - 2 + 4 * v->cur_field_type;
    }
    if (s->pict_type == AV_PICTURE_TYPE_P && n == 3 && v->field_mode) {
        int same_count = 0, opp_count = 0, k;
        int chosen_mv[2][4][2], f;
        int tx, ty;
        for (k = 0; k < 4; k++) {
            f = v->mv_f[0][s->block_index[k] + v->blocks_off];
            chosen_mv[f][f ? opp_count : same_count][0] = s->mv[0][k][0];
            chosen_mv[f][f ? opp_count : same_count][1] = s->mv[0][k][1];
            opp_count  += f;
            same_count += 1 - f;
        }
        f = opp_count > same_count;
        switch (f ? opp_count : same_count) {
        case 4:
            tx = median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
                         chosen_mv[f][2][0], chosen_mv[f][3][0]);
            ty = median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
                         chosen_mv[f][2][1], chosen_mv[f][3][1]);
            break;
        case 3:
            tx = mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
            ty = mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
            break;
        case 2:
            tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
            ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
            break;
        default:
            av_assert2(0);
        }
        s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
        s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
        for (k = 0; k < 4; k++)
            v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
    }
    if (v->fcm == ILACE_FRAME) {  // not sure if needed for other types of picture
        int qx, qy;
        int width  = s->avctx->coded_width;
        int height = s->avctx->coded_height >> 1;
        qx = (s->mb_x * 16) + (mx >> 2);
        qy = (s->mb_y *  8) + (my >> 3);
        if (qx < -17)
            mx -= 4 * (qx + 17);
        else if (qx > width)
            mx -= 4 * (qx - width);
        if (qy < -18)
            my -= 8 * (qy + 18);
        else if (qy > height + 1)
            my -= 8 * (qy - height - 1);
    }
    if ((v->fcm == ILACE_FRAME) && fieldmv)
        off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;
    else
        off = s->linesize * 4 * (n & 2) + (n & 1) * 8;
    if (v->field_mode && v->second_field)
        off += s->current_picture_ptr->f.linesize[0];
    src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2);
    if (!fieldmv)
        src_y = s->mb_y * 16 + (n & 2) * 4 + (my >> 2);
    else
        src_y = s->mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
    if (v->profile != PROFILE_ADVANCED) {
        src_x = av_clip(src_x, -16, s->mb_width  * 16);
        src_y = av_clip(src_y, -16, s->mb_height * 16);
    } else {
        src_x = av_clip(src_x, -17, s->avctx->coded_width);
        if (v->fcm == ILACE_FRAME) {
            if (src_y & 1)
                src_y = av_clip(src_y, -17, s->avctx->coded_height + 1);
            else
                src_y = av_clip(src_y, -18, s->avctx->coded_height);
        } else {
            src_y = av_clip(src_y, -18, s->avctx->coded_height + 1);
        }
    }
    srcY += src_y * s->linesize + src_x;
    if (v->field_mode && v->ref_field_type[dir])
        srcY += s->current_picture_ptr->f.linesize[0];
    if (fieldmv && !(src_y & 1))
        v_edge_pos--;
    if (fieldmv && (src_y & 1) && src_y < 4)
        src_y--;
    if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
        || s->h_edge_pos < 13 || v_edge_pos < 23
        || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2
        || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) {
        srcY -= s->mspel * (1 + (s->linesize << fieldmv));
        /* check emulate edge stride and offset */
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
                                9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv,
                                src_x - s->mspel, src_y - (s->mspel << fieldmv),
                                s->h_edge_pos, v_edge_pos);
        srcY = s->edge_emu_buffer;
        /* if we deal with range reduction we need to scale source blocks */
        if (v->rangeredfrm) {
            int i, j;
            uint8_t *src;
            src = srcY;
            for (j = 0; j < 9 + s->mspel * 2; j++) {
                for (i = 0; i < 9 + s->mspel * 2; i++)
                    src[i] = ((src[i] - 128) >> 1) + 128;
                src += s->linesize << fieldmv;
            }
        }
        /* if we deal with intensity compensation we need to scale source blocks */
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
            int i, j;
            uint8_t *src;
            src = srcY;
            for (j = 0; j < 9 + s->mspel * 2; j++) {
                for (i = 0; i < 9 + s->mspel * 2; i++)
                    src[i] = v->luty[src[i]];
                src += s->linesize << fieldmv;
            }
        }
        srcY += s->mspel * (1 + (s->linesize << fieldmv));
    }
    if (s->mspel) {
        dxy = ((my & 3) << 2) | (mx & 3);
        v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);
    } else { // hpel mc - always used for luma
        dxy = (my & 2) | ((mx & 2) >> 1);
        if (!v->rnd)
            dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
        else
            dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
    }
}
static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
{
    MpegEncContext *s = &v->s;
    DSPContext *dsp = &v->s.dsp;
    uint8_t *srcY;
    int dxy, mx, my, src_x, src_y;
    int off;
    int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0;
    int v_edge_pos = s->v_edge_pos >> v->field_mode;
    if ((!v->field_mode ||
         (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&
        !v->s.last_picture.f.data[0])
    mx = s->mv[dir][n][0];
    my = s->mv[dir][n][1];
    if (!dir) {
        if (v->field_mode) {
            if ((v->cur_field_type != v->ref_field_type[dir]) && v->second_field)
                srcY = s->current_picture.f.data[0];
            else
                srcY = s->last_picture.f.data[0];
        } else
            srcY = s->last_picture.f.data[0];
    } else
        srcY = s->next_picture.f.data[0];
    if (v->field_mode) {
        if (v->cur_field_type != v->ref_field_type[dir])
            my = my - 2 + 4 * v->cur_field_type;
    }
    if (s->pict_type == AV_PICTURE_TYPE_P && n == 3 && v->field_mode) {
        int same_count = 0, opp_count = 0, k;
        int chosen_mv[2][4][2], f;
        int tx, ty;
        for (k = 0; k < 4; k++) {
            f = v->mv_f[0][s->block_index[k] + v->blocks_off];
            chosen_mv[f][f ? opp_count : same_count][0] = s->mv[0][k][0];
            chosen_mv[f][f ? opp_count : same_count][1] = s->mv[0][k][1];
            opp_count  += f;
            same_count += 1 - f;
        }
        f = opp_count > same_count;
        switch (f ? opp_count : same_count) {
        case 4:
            tx = median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
                         chosen_mv[f][2][0], chosen_mv[f][3][0]);
            ty = median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
                         chosen_mv[f][2][1], chosen_mv[f][3][1]);
            break;
        case 3:
            tx = mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
            ty = mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
            break;
        case 2:
            tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
            ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
            break;
        default:
            av_assert2(0);
        }
        s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
        s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
        for (k = 0; k < 4; k++)
            v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
    }
    if (v->fcm == ILACE_FRAME) {  
        int qx, qy;
        int width  = s->avctx->coded_width;
        int height = s->avctx->coded_height >> 1;
        qx = (s->mb_x * 16) + (mx >> 2);
        qy = (s->mb_y *  8) + (my >> 3);
        if (qx < -17)
            mx -= 4 * (qx + 17);
        else if (qx > width)
            mx -= 4 * (qx - width);
        if (qy < -18)
            my -= 8 * (qy + 18);
        else if (qy > height + 1)
            my -= 8 * (qy - height - 1);
    }
    if ((v->fcm == ILACE_FRAME) && fieldmv)
        off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;
    else
        off = s->linesize * 4 * (n & 2) + (n & 1) * 8;
    if (v->field_mode && v->second_field)
        off += s->current_picture_ptr->f.linesize[0];
    src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2);
    if (!fieldmv)
        src_y = s->mb_y * 16 + (n & 2) * 4 + (my >> 2);
    else
        src_y = s->mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
    if (v->profile != PROFILE_ADVANCED) {
        src_x = av_clip(src_x, -16, s->mb_width  * 16);
        src_y = av_clip(src_y, -16, s->mb_height * 16);
    } else {
        src_x = av_clip(src_x, -17, s->avctx->coded_width);
        if (v->fcm == ILACE_FRAME) {
            if (src_y & 1)
                src_y = av_clip(src_y, -17, s->avctx->coded_height + 1);
            else
                src_y = av_clip(src_y, -18, s->avctx->coded_height);
        } else {
            src_y = av_clip(src_y, -18, s->avctx->coded_height + 1);
        }
    }
    srcY += src_y * s->linesize + src_x;
    if (v->field_mode && v->ref_field_type[dir])
        srcY += s->current_picture_ptr->f.linesize[0];
    if (fieldmv && !(src_y & 1))
        v_edge_pos--;
    if (fieldmv && (src_y & 1) && src_y < 4)
        src_y--;
    if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
        || s->h_edge_pos < 13 || v_edge_pos < 23
        || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2
        || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) {
        srcY -= s->mspel * (1 + (s->linesize << fieldmv));
        
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
                                9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv,
                                src_x - s->mspel, src_y - (s->mspel << fieldmv),
                                s->h_edge_pos, v_edge_pos);
        srcY = s->edge_emu_buffer;
        
        if (v->rangeredfrm) {
            int i, j;
            uint8_t *src;
            src = srcY;
            for (j = 0; j < 9 + s->mspel * 2; j++) {
                for (i = 0; i < 9 + s->mspel * 2; i++)
                    src[i] = ((src[i] - 128) >> 1) + 128;
                src += s->linesize << fieldmv;
            }
        }
        
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
            int i, j;
            uint8_t *src;
            src = srcY;
            for (j = 0; j < 9 + s->mspel * 2; j++) {
                for (i = 0; i < 9 + s->mspel * 2; i++)
                    src[i] = v->luty[src[i]];
                src += s->linesize << fieldmv;
            }
        }
        srcY += s->mspel * (1 + (s->linesize << fieldmv));
    }
    if (s->mspel) {
        dxy = ((my & 3) << 2) | (mx & 3);
        v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);
    } else { 
        dxy = (my & 2) | ((mx & 2) >> 1);
        if (!v->rnd)
            dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
        else
            dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
    }
}
static void FUNC_0(VC1Context *VAR_0, int VAR_1, int VAR_2)
{
    MpegEncContext *s = &VAR_0->s;
    DSPContext *dsp = &VAR_0->s.dsp;
    uint8_t *srcY;
    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;
    int VAR_8;
    int VAR_9 = (VAR_0->fcm == ILACE_FRAME) ? VAR_0->blk_mv_type[s->block_index[VAR_1]] : 0;
    int VAR_10 = s->VAR_10 >> VAR_0->field_mode;
    if ((!VAR_0->field_mode ||
         (VAR_0->ref_field_type[VAR_2] == 1 && VAR_0->cur_field_type == 1)) &&
        !VAR_0->s.last_picture.VAR_15.data[0])
    VAR_4 = s->mv[VAR_2][VAR_1][0];
    VAR_5 = s->mv[VAR_2][VAR_1][1];
    if (!VAR_2) {
        if (VAR_0->field_mode) {
            if ((VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2]) && VAR_0->second_field)
                srcY = s->current_picture.VAR_15.data[0];
            else
                srcY = s->last_picture.VAR_15.data[0];
        } else
            srcY = s->last_picture.VAR_15.data[0];
    } else
        srcY = s->next_picture.VAR_15.data[0];
    if (VAR_0->field_mode) {
        if (VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2])
            VAR_5 = VAR_5 - 2 + 4 * VAR_0->cur_field_type;
    }
    if (s->pict_type == AV_PICTURE_TYPE_P && VAR_1 == 3 && VAR_0->field_mode) {
        int VAR_11 = 0, VAR_12 = 0, VAR_13;
        int VAR_14[2][4][2], VAR_15;
        int VAR_16, VAR_17;
        for (VAR_13 = 0; VAR_13 < 4; VAR_13++) {
            VAR_15 = VAR_0->mv_f[0][s->block_index[VAR_13] + VAR_0->blocks_off];
            VAR_14[VAR_15][VAR_15 ? VAR_12 : VAR_11][0] = s->mv[0][VAR_13][0];
            VAR_14[VAR_15][VAR_15 ? VAR_12 : VAR_11][1] = s->mv[0][VAR_13][1];
            VAR_12  += VAR_15;
            VAR_11 += 1 - VAR_15;
        }
        VAR_15 = VAR_12 > VAR_11;
        switch (VAR_15 ? VAR_12 : VAR_11) {
        case 4:
            VAR_16 = median4(VAR_14[VAR_15][0][0], VAR_14[VAR_15][1][0],
                         VAR_14[VAR_15][2][0], VAR_14[VAR_15][3][0]);
            VAR_17 = median4(VAR_14[VAR_15][0][1], VAR_14[VAR_15][1][1],
                         VAR_14[VAR_15][2][1], VAR_14[VAR_15][3][1]);
            break;
        case 3:
            VAR_16 = mid_pred(VAR_14[VAR_15][0][0], VAR_14[VAR_15][1][0], VAR_14[VAR_15][2][0]);
            VAR_17 = mid_pred(VAR_14[VAR_15][0][1], VAR_14[VAR_15][1][1], VAR_14[VAR_15][2][1]);
            break;
        case 2:
            VAR_16 = (VAR_14[VAR_15][0][0] + VAR_14[VAR_15][1][0]) / 2;
            VAR_17 = (VAR_14[VAR_15][0][1] + VAR_14[VAR_15][1][1]) / 2;
            break;
        default:
            av_assert2(0);
        }
        s->current_picture.VAR_15.motion_val[1][s->block_index[0] + VAR_0->blocks_off][0] = VAR_16;
        s->current_picture.VAR_15.motion_val[1][s->block_index[0] + VAR_0->blocks_off][1] = VAR_17;
        for (VAR_13 = 0; VAR_13 < 4; VAR_13++)
            VAR_0->mv_f[1][s->block_index[VAR_13] + VAR_0->blocks_off] = VAR_15;
    }
    if (VAR_0->fcm == ILACE_FRAME) {  
        int VAR_18, VAR_19;
        int VAR_20  = s->avctx->coded_width;
        int VAR_21 = s->avctx->coded_height >> 1;
        VAR_18 = (s->mb_x * 16) + (VAR_4 >> 2);
        VAR_19 = (s->mb_y *  8) + (VAR_5 >> 3);
        if (VAR_18 < -17)
            VAR_4 -= 4 * (VAR_18 + 17);
        else if (VAR_18 > VAR_20)
            VAR_4 -= 4 * (VAR_18 - VAR_20);
        if (VAR_19 < -18)
            VAR_5 -= 8 * (VAR_19 + 18);
        else if (VAR_19 > VAR_21 + 1)
            VAR_5 -= 8 * (VAR_19 - VAR_21 - 1);
    }
    if ((VAR_0->fcm == ILACE_FRAME) && VAR_9)
        VAR_8 = ((VAR_1 > 1) ? s->linesize : 0) + (VAR_1 & 1) * 8;
    else
        VAR_8 = s->linesize * 4 * (VAR_1 & 2) + (VAR_1 & 1) * 8;
    if (VAR_0->field_mode && VAR_0->second_field)
        VAR_8 += s->current_picture_ptr->VAR_15.linesize[0];
    VAR_6 = s->mb_x * 16 + (VAR_1 & 1) * 8 + (VAR_4 >> 2);
    if (!VAR_9)
        VAR_7 = s->mb_y * 16 + (VAR_1 & 2) * 4 + (VAR_5 >> 2);
    else
        VAR_7 = s->mb_y * 16 + ((VAR_1 > 1) ? 1 : 0) + (VAR_5 >> 2);
    if (VAR_0->profile != PROFILE_ADVANCED) {
        VAR_6 = av_clip(VAR_6, -16, s->mb_width  * 16);
        VAR_7 = av_clip(VAR_7, -16, s->mb_height * 16);
    } else {
        VAR_6 = av_clip(VAR_6, -17, s->avctx->coded_width);
        if (VAR_0->fcm == ILACE_FRAME) {
            if (VAR_7 & 1)
                VAR_7 = av_clip(VAR_7, -17, s->avctx->coded_height + 1);
            else
                VAR_7 = av_clip(VAR_7, -18, s->avctx->coded_height);
        } else {
            VAR_7 = av_clip(VAR_7, -18, s->avctx->coded_height + 1);
        }
    }
    srcY += VAR_7 * s->linesize + VAR_6;
    if (VAR_0->field_mode && VAR_0->ref_field_type[VAR_2])
        srcY += s->current_picture_ptr->VAR_15.linesize[0];
    if (VAR_9 && !(VAR_7 & 1))
        VAR_10--;
    if (VAR_9 && (VAR_7 & 1) && VAR_7 < 4)
        VAR_7--;
    if (VAR_0->rangeredfrm || (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP)
        || s->h_edge_pos < 13 || VAR_10 < 23
        || (unsigned)(VAR_6 - s->mspel) > s->h_edge_pos - (VAR_4 & 3) - 8 - s->mspel * 2
        || (unsigned)(VAR_7 - (s->mspel << VAR_9)) > VAR_10 - (VAR_5 & 3) - ((8 + s->mspel * 2) << VAR_9)) {
        srcY -= s->mspel * (1 + (s->linesize << VAR_9));
        
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
                                9 + s->mspel * 2, (9 + s->mspel * 2) << VAR_9,
                                VAR_6 - s->mspel, VAR_7 - (s->mspel << VAR_9),
                                s->h_edge_pos, VAR_10);
        srcY = s->edge_emu_buffer;
        
        if (VAR_0->rangeredfrm) {
            int VAR_24, VAR_24;
            uint8_t *src;
            src = srcY;
            for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++) {
                for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++)
                    src[VAR_24] = ((src[VAR_24] - 128) >> 1) + 128;
                src += s->linesize << VAR_9;
            }
        }
        
        if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) {
            int VAR_24, VAR_24;
            uint8_t *src;
            src = srcY;
            for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++) {
                for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++)
                    src[VAR_24] = VAR_0->luty[src[VAR_24]];
                src += s->linesize << VAR_9;
            }
        }
        srcY += s->mspel * (1 + (s->linesize << VAR_9));
    }
    if (s->mspel) {
        VAR_3 = ((VAR_5 & 3) << 2) | (VAR_4 & 3);
        VAR_0->vc1dsp.put_vc1_mspel_pixels_tab[VAR_3](s->dest[0] + VAR_8, srcY, s->linesize << VAR_9, VAR_0->rnd);
    } else { 
        VAR_3 = (VAR_5 & 2) | ((VAR_4 & 2) >> 1);
        if (!VAR_0->rnd)
            dsp->put_pixels_tab[1][VAR_3](s->dest[0] + VAR_8, srcY, s->linesize, 8);
        else
            dsp->put_no_rnd_pixels_tab[1][VAR_3](s->dest[0] + VAR_8, srcY, s->linesize, 8);
    }
}
static void FUNC_0(VC1Context *VAR_0, int VAR_1, int VAR_2)
{ MpegEncContext *s = &VAR_0->s; DSPContext *dsp = &VAR_0->s.dsp; uint8_t *srcY; int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; int VAR_8; int VAR_9 = (VAR_0->fcm == ILACE_FRAME) ? VAR_0->blk_mv_type[s->block_index[VAR_1]] : 0; int VAR_10 = s->VAR_10 >> VAR_0->field_mode; if ((!VAR_0->field_mode ||
(VAR_0->ref_field_type[VAR_2] == 1 && VAR_0->cur_field_type == 1)) &&
!VAR_0->s.last_picture.VAR_15.data[0])
VAR_4 = s->mv[VAR_2][VAR_1][0]; VAR_5 = s->mv[VAR_2][VAR_1][1]; if (!VAR_2) { if (VAR_0->field_mode) { if ((VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2]) && VAR_0->second_field)
srcY = s->current_picture.VAR_15.data[0]; else
srcY = s->last_picture.VAR_15.data[0]; } else srcY = s->last_picture.VAR_15.data[0]; } else srcY = s->next_picture.VAR_15.data[0]; if (VAR_0->field_mode) { if (VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2])
VAR_5 = VAR_5 - 2 + 4 * VAR_0->cur_field_type; } if (s->pict_type == AV_PICTURE_TYPE_P && VAR_1 == 3 && VAR_0->field_mode) { int VAR_11 = 0, VAR_12 = 0, VAR_13; int VAR_14[2][4][2], VAR_15; int VAR_16, VAR_17; for (VAR_13 = 0; VAR_13 < 4; VAR_13++) { VAR_15 = VAR_0->mv_f[0][s->block_index[VAR_13] + VAR_0->blocks_off]; VAR_14[VAR_15][VAR_15 ? VAR_12 : VAR_11][0] = s->mv[0][VAR_13][0]; VAR_14[VAR_15][VAR_15 ? VAR_12 : VAR_11][1] = s->mv[0][VAR_13][1]; VAR_12  += VAR_15; VAR_11 += 1 - VAR_15; } VAR_15 = VAR_12 > VAR_11; switch (VAR_15 ? VAR_12 : VAR_11) { case 4:
VAR_16 = median4(VAR_14[VAR_15][0][0], VAR_14[VAR_15][1][0],
VAR_14[VAR_15][2][0], VAR_14[VAR_15][3][0]); VAR_17 = median4(VAR_14[VAR_15][0][1], VAR_14[VAR_15][1][1],
VAR_14[VAR_15][2][1], VAR_14[VAR_15][3][1]); break; case 3:
VAR_16 = mid_pred(VAR_14[VAR_15][0][0], VAR_14[VAR_15][1][0], VAR_14[VAR_15][2][0]); VAR_17 = mid_pred(VAR_14[VAR_15][0][1], VAR_14[VAR_15][1][1], VAR_14[VAR_15][2][1]); break; case 2:
VAR_16 = (VAR_14[VAR_15][0][0] + VAR_14[VAR_15][1][0]) / 2; VAR_17 = (VAR_14[VAR_15][0][1] + VAR_14[VAR_15][1][1]) / 2; break; default:
av_assert2(0); } s->current_picture.VAR_15.motion_val[1][s->block_index[0] + VAR_0->blocks_off][0] = VAR_16; s->current_picture.VAR_15.motion_val[1][s->block_index[0] + VAR_0->blocks_off][1] = VAR_17; for (VAR_13 = 0; VAR_13 < 4; VAR_13++) VAR_0->mv_f[1][s->block_index[VAR_13] + VAR_0->blocks_off] = VAR_15; } if (VAR_0->fcm == ILACE_FRAME) { int VAR_18, VAR_19; int VAR_20  = s->avctx->coded_width; int VAR_21 = s->avctx->coded_height >> 1; VAR_18 = (s->mb_x * 16) + (VAR_4 >> 2); VAR_19 = (s->mb_y *  8) + (VAR_5 >> 3); if (VAR_18 < -17)
VAR_4 -= 4 * (VAR_18 + 17); else if (VAR_18 > VAR_20)
VAR_4 -= 4 * (VAR_18 - VAR_20); if (VAR_19 < -18)
VAR_5 -= 8 * (VAR_19 + 18); else if (VAR_19 > VAR_21 + 1)
VAR_5 -= 8 * (VAR_19 - VAR_21 - 1); } if ((VAR_0->fcm == ILACE_FRAME) && VAR_9)
VAR_8 = ((VAR_1 > 1) ? s->linesize : 0) + (VAR_1 & 1) * 8; else
VAR_8 = s->linesize * 4 * (VAR_1 & 2) + (VAR_1 & 1) * 8; if (VAR_0->field_mode && VAR_0->second_field)
VAR_8 += s->current_picture_ptr->VAR_15.linesize[0]; VAR_6 = s->mb_x * 16 + (VAR_1 & 1) * 8 + (VAR_4 >> 2); if (!VAR_9)
VAR_7 = s->mb_y * 16 + (VAR_1 & 2) * 4 + (VAR_5 >> 2); else
VAR_7 = s->mb_y * 16 + ((VAR_1 > 1) ? 1 : 0) + (VAR_5 >> 2); if (VAR_0->profile != PROFILE_ADVANCED) { VAR_6 = av_clip(VAR_6, -16, s->mb_width  * 16); VAR_7 = av_clip(VAR_7, -16, s->mb_height * 16); } else { VAR_6 = av_clip(VAR_6, -17, s->avctx->coded_width); if (VAR_0->fcm == ILACE_FRAME) { if (VAR_7 & 1)
VAR_7 = av_clip(VAR_7, -17, s->avctx->coded_height + 1); else
VAR_7 = av_clip(VAR_7, -18, s->avctx->coded_height); } else { VAR_7 = av_clip(VAR_7, -18, s->avctx->coded_height + 1); } } srcY += VAR_7 * s->linesize + VAR_6; if (VAR_0->field_mode && VAR_0->ref_field_type[VAR_2])
srcY += s->current_picture_ptr->VAR_15.linesize[0]; if (VAR_9 && !(VAR_7 & 1))
VAR_10--; if (VAR_9 && (VAR_7 & 1) && VAR_7 < 4)
VAR_7--; if (VAR_0->rangeredfrm || (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP)
|| s->h_edge_pos < 13 || VAR_10 < 23
|| (unsigned)(VAR_6 - s->mspel) > s->h_edge_pos - (VAR_4 & 3) - 8 - s->mspel * 2
|| (unsigned)(VAR_7 - (s->mspel << VAR_9)) > VAR_10 - (VAR_5 & 3) - ((8 + s->mspel * 2) << VAR_9)) { srcY -= s->mspel * (1 + (s->linesize << VAR_9)); s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
9 + s->mspel * 2, (9 + s->mspel * 2) << VAR_9,
VAR_6 - s->mspel, VAR_7 - (s->mspel << VAR_9),
s->h_edge_pos, VAR_10); srcY = s->edge_emu_buffer; if (VAR_0->rangeredfrm) { int VAR_24, VAR_24; uint8_t *src; src = srcY; for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++) { for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++) src[VAR_24] = ((src[VAR_24] - 128) >> 1) + 128; src += s->linesize << VAR_9; } } if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) { int VAR_24, VAR_24; uint8_t *src; src = srcY; for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++) { for (VAR_24 = 0; VAR_24 < 9 + s->mspel * 2; VAR_24++) src[VAR_24] = VAR_0->luty[src[VAR_24]]; src += s->linesize << VAR_9; } } srcY += s->mspel * (1 + (s->linesize << VAR_9)); } if (s->mspel) { VAR_3 = ((VAR_5 & 3) << 2) | (VAR_4 & 3); VAR_0->vc1dsp.put_vc1_mspel_pixels_tab[VAR_3](s->dest[0] + VAR_8, srcY, s->linesize << VAR_9, VAR_0->rnd); } else { VAR_3 = (VAR_5 & 2) | ((VAR_4 & 2) >> 1); if (!VAR_0->rnd)
dsp->put_pixels_tab[1][VAR_3](s->dest[0] + VAR_8, srcY, s->linesize, 8); else
dsp->put_no_rnd_pixels_tab[1][VAR_3](s->dest[0] + VAR_8, srcY, s->linesize, 8); } }