static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)

{

    GetBitContext *gb = &v->s.gb;



    int imode, x, y, code, offset;

    uint8_t invert, *planep = data;

    int width, height, stride;



    width  = v->s.mb_width;

    height = v->s.mb_height >> v->field_mode;

    stride = v->s.mb_stride;

    invert = get_bits1(gb);

    imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);



    *raw_flag = 0;

    switch (imode) {

    case IMODE_RAW:

        //Data is actually read in the MB layer (same for all tests == "raw")

        *raw_flag = 1; //invert ignored

        return invert;

    case IMODE_DIFF2:

    case IMODE_NORM2:

        if ((height * width) & 1) {

            *planep++ = get_bits1(gb);

            offset    = 1;

        }

        else

            offset = 0;

        // decode bitplane as one long line

        for (y = offset; y < height * width; y += 2) {

            code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);

            *planep++ = code & 1;

            offset++;

            if (offset == width) {

                offset  = 0;

                planep += stride - width;

            }

            *planep++ = code >> 1;

            offset++;

            if (offset == width) {

                offset  = 0;

                planep += stride - width;

            }

        }

        break;

    case IMODE_DIFF6:

    case IMODE_NORM6:

        if (!(height % 3) && (width % 3)) { // use 2x3 decoding

            for (y = 0; y < height; y += 3) {

                for (x = width & 1; x < width; x += 2) {

                    code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);

                    if (code < 0) {

                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");

                        return -1;

                    }

                    planep[x + 0]              = (code >> 0) & 1;

                    planep[x + 1]              = (code >> 1) & 1;

                    planep[x + 0 + stride]     = (code >> 2) & 1;

                    planep[x + 1 + stride]     = (code >> 3) & 1;

                    planep[x + 0 + stride * 2] = (code >> 4) & 1;

                    planep[x + 1 + stride * 2] = (code >> 5) & 1;

                }

                planep += stride * 3;

            }

            if (width & 1)

                decode_colskip(data, 1, height, stride, &v->s.gb);

        } else { // 3x2

            planep += (height & 1) * stride;

            for (y = height & 1; y < height; y += 2) {

                for (x = width % 3; x < width; x += 3) {

                    code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);

                    if (code < 0) {

                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");

                        return -1;

                    }

                    planep[x + 0]          = (code >> 0) & 1;

                    planep[x + 1]          = (code >> 1) & 1;

                    planep[x + 2]          = (code >> 2) & 1;

                    planep[x + 0 + stride] = (code >> 3) & 1;

                    planep[x + 1 + stride] = (code >> 4) & 1;

                    planep[x + 2 + stride] = (code >> 5) & 1;

                }

                planep += stride * 2;

            }

            x = width % 3;

            if (x)

                decode_colskip(data,             x, height, stride, &v->s.gb);

            if (height & 1)

                decode_rowskip(data + x, width - x,      1, stride, &v->s.gb);

        }

        break;

    case IMODE_ROWSKIP:

        decode_rowskip(data, width, height, stride, &v->s.gb);

        break;

    case IMODE_COLSKIP:

        decode_colskip(data, width, height, stride, &v->s.gb);

        break;

    default:

        break;

    }



    /* Applying diff operator */

    if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) {

        planep = data;

        planep[0] ^= invert;

        for (x = 1; x < width; x++)

            planep[x] ^= planep[x-1];

        for (y = 1; y < height; y++) {

            planep += stride;

            planep[0] ^= planep[-stride];

            for (x = 1; x < width; x++) {

                if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;

                else                                 planep[x] ^= planep[x-1];

            }

        }

    } else if (invert) {

        planep = data;

        for (x = 0; x < stride * height; x++)

            planep[x] = !planep[x]; //FIXME stride

    }

    return (imode << 1) + invert;

}

static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)

{

    GetBitContext *gb = &v->s.gb;



    int imode, x, y, code, offset;

    uint8_t invert, *planep = data;

    int width, height, stride;



    width  = v->s.mb_width;

    height = v->s.mb_height >> v->field_mode;

    stride = v->s.mb_stride;

    invert = get_bits1(gb);

    imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);



    *raw_flag = 0;

    switch (imode) {

    case IMODE_RAW:

        

        *raw_flag = 1; 

        return invert;

    case IMODE_DIFF2:

    case IMODE_NORM2:

        if ((height * width) & 1) {

            *planep++ = get_bits1(gb);

            offset    = 1;

        }

        else

            offset = 0;

        

        for (y = offset; y < height * width; y += 2) {

            code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);

            *planep++ = code & 1;

            offset++;

            if (offset == width) {

                offset  = 0;

                planep += stride - width;

            }

            *planep++ = code >> 1;

            offset++;

            if (offset == width) {

                offset  = 0;

                planep += stride - width;

            }

        }

        break;

    case IMODE_DIFF6:

    case IMODE_NORM6:

        if (!(height % 3) && (width % 3)) { 

            for (y = 0; y < height; y += 3) {

                for (x = width & 1; x < width; x += 2) {

                    code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);

                    if (code < 0) {

                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");

                        return -1;

                    }

                    planep[x + 0]              = (code >> 0) & 1;

                    planep[x + 1]              = (code >> 1) & 1;

                    planep[x + 0 + stride]     = (code >> 2) & 1;

                    planep[x + 1 + stride]     = (code >> 3) & 1;

                    planep[x + 0 + stride * 2] = (code >> 4) & 1;

                    planep[x + 1 + stride * 2] = (code >> 5) & 1;

                }

                planep += stride * 3;

            }

            if (width & 1)

                decode_colskip(data, 1, height, stride, &v->s.gb);

        } else { 

            planep += (height & 1) * stride;

            for (y = height & 1; y < height; y += 2) {

                for (x = width % 3; x < width; x += 3) {

                    code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);

                    if (code < 0) {

                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");

                        return -1;

                    }

                    planep[x + 0]          = (code >> 0) & 1;

                    planep[x + 1]          = (code >> 1) & 1;

                    planep[x + 2]          = (code >> 2) & 1;

                    planep[x + 0 + stride] = (code >> 3) & 1;

                    planep[x + 1 + stride] = (code >> 4) & 1;

                    planep[x + 2 + stride] = (code >> 5) & 1;

                }

                planep += stride * 2;

            }

            x = width % 3;

            if (x)

                decode_colskip(data,             x, height, stride, &v->s.gb);

            if (height & 1)

                decode_rowskip(data + x, width - x,      1, stride, &v->s.gb);

        }

        break;

    case IMODE_ROWSKIP:

        decode_rowskip(data, width, height, stride, &v->s.gb);

        break;

    case IMODE_COLSKIP:

        decode_colskip(data, width, height, stride, &v->s.gb);

        break;

    default:

        break;

    }



    

    if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) {

        planep = data;

        planep[0] ^= invert;

        for (x = 1; x < width; x++)

            planep[x] ^= planep[x-1];

        for (y = 1; y < height; y++) {

            planep += stride;

            planep[0] ^= planep[-stride];

            for (x = 1; x < width; x++) {

                if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;

                else                                 planep[x] ^= planep[x-1];

            }

        }

    } else if (invert) {

        planep = data;

        for (x = 0; x < stride * height; x++)

            planep[x] = !planep[x]; 

    }

    return (imode << 1) + invert;

}

            offset    = 1;             offset = 0;         for (y = offset; y < height * width; y += 2) {
static int FUNC_0(uint8_t* VAR_0, int *VAR_1, VC1Context *VAR_2)

{

    GetBitContext *gb = &VAR_2->s.gb;



    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;

    uint8_t invert, *planep = VAR_0;

    int VAR_8, VAR_9, VAR_10;



    VAR_8  = VAR_2->s.mb_width;

    VAR_9 = VAR_2->s.mb_height >> VAR_2->field_mode;

    VAR_10 = VAR_2->s.mb_stride;

    invert = get_bits1(gb);

    VAR_3 = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);



    *VAR_1 = 0;

    switch (VAR_3) {

    case IMODE_RAW:

        

        *VAR_1 = 1; 

        return invert;

    case IMODE_DIFF2:

    case IMODE_NORM2:

        if ((VAR_9 * VAR_8) & 1) {

            *planep++ = get_bits1(gb);

            VAR_7    = 1;

        }

        else

            VAR_7 = 0;

        

        for (VAR_5 = VAR_7; VAR_5 < VAR_9 * VAR_8; VAR_5 += 2) {

            VAR_6 = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);

            *planep++ = VAR_6 & 1;

            VAR_7++;

            if (VAR_7 == VAR_8) {

                VAR_7  = 0;

                planep += VAR_10 - VAR_8;

            }

            *planep++ = VAR_6 >> 1;

            VAR_7++;

            if (VAR_7 == VAR_8) {

                VAR_7  = 0;

                planep += VAR_10 - VAR_8;

            }

        }

        break;

    case IMODE_DIFF6:

    case IMODE_NORM6:

        if (!(VAR_9 % 3) && (VAR_8 % 3)) { 

            for (VAR_5 = 0; VAR_5 < VAR_9; VAR_5 += 3) {

                for (VAR_4 = VAR_8 & 1; VAR_4 < VAR_8; VAR_4 += 2) {

                    VAR_6 = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);

                    if (VAR_6 < 0) {

                        av_log(VAR_2->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");

                        return -1;

                    }

                    planep[VAR_4 + 0]              = (VAR_6 >> 0) & 1;

                    planep[VAR_4 + 1]              = (VAR_6 >> 1) & 1;

                    planep[VAR_4 + 0 + VAR_10]     = (VAR_6 >> 2) & 1;

                    planep[VAR_4 + 1 + VAR_10]     = (VAR_6 >> 3) & 1;

                    planep[VAR_4 + 0 + VAR_10 * 2] = (VAR_6 >> 4) & 1;

                    planep[VAR_4 + 1 + VAR_10 * 2] = (VAR_6 >> 5) & 1;

                }

                planep += VAR_10 * 3;

            }

            if (VAR_8 & 1)

                decode_colskip(VAR_0, 1, VAR_9, VAR_10, &VAR_2->s.gb);

        } else { 

            planep += (VAR_9 & 1) * VAR_10;

            for (VAR_5 = VAR_9 & 1; VAR_5 < VAR_9; VAR_5 += 2) {

                for (VAR_4 = VAR_8 % 3; VAR_4 < VAR_8; VAR_4 += 3) {

                    VAR_6 = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);

                    if (VAR_6 < 0) {

                        av_log(VAR_2->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");

                        return -1;

                    }

                    planep[VAR_4 + 0]          = (VAR_6 >> 0) & 1;

                    planep[VAR_4 + 1]          = (VAR_6 >> 1) & 1;

                    planep[VAR_4 + 2]          = (VAR_6 >> 2) & 1;

                    planep[VAR_4 + 0 + VAR_10] = (VAR_6 >> 3) & 1;

                    planep[VAR_4 + 1 + VAR_10] = (VAR_6 >> 4) & 1;

                    planep[VAR_4 + 2 + VAR_10] = (VAR_6 >> 5) & 1;

                }

                planep += VAR_10 * 2;

            }

            VAR_4 = VAR_8 % 3;

            if (VAR_4)

                decode_colskip(VAR_0,             VAR_4, VAR_9, VAR_10, &VAR_2->s.gb);

            if (VAR_9 & 1)

                decode_rowskip(VAR_0 + VAR_4, VAR_8 - VAR_4,      1, VAR_10, &VAR_2->s.gb);

        }

        break;

    case IMODE_ROWSKIP:

        decode_rowskip(VAR_0, VAR_8, VAR_9, VAR_10, &VAR_2->s.gb);

        break;

    case IMODE_COLSKIP:

        decode_colskip(VAR_0, VAR_8, VAR_9, VAR_10, &VAR_2->s.gb);

        break;

    default:

        break;

    }



    

    if (VAR_3 == IMODE_DIFF2 || VAR_3 == IMODE_DIFF6) {

        planep = VAR_0;

        planep[0] ^= invert;

        for (VAR_4 = 1; VAR_4 < VAR_8; VAR_4++)

            planep[VAR_4] ^= planep[VAR_4-1];

        for (VAR_5 = 1; VAR_5 < VAR_9; VAR_5++) {

            planep += VAR_10;

            planep[0] ^= planep[-VAR_10];

            for (VAR_4 = 1; VAR_4 < VAR_8; VAR_4++) {

                if (planep[VAR_4-1] != planep[VAR_4-VAR_10]) planep[VAR_4] ^= invert;

                else                                 planep[VAR_4] ^= planep[VAR_4-1];

            }

        }

    } else if (invert) {

        planep = VAR_0;

        for (VAR_4 = 0; VAR_4 < VAR_10 * VAR_9; VAR_4++)

            planep[VAR_4] = !planep[VAR_4]; 

    }

    return (VAR_3 << 1) + invert;

}

static int FUNC_0(uint8_t* VAR_0, int *VAR_1, VC1Context *VAR_2)
{ GetBitContext *gb = &VAR_2->s.gb; int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; uint8_t invert, *planep = VAR_0; int VAR_8, VAR_9, VAR_10; VAR_8  = VAR_2->s.mb_width; VAR_9 = VAR_2->s.mb_height >> VAR_2->field_mode; VAR_10 = VAR_2->s.mb_stride; invert = get_bits1(gb); VAR_3 = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1); *VAR_1 = 0; switch (VAR_3) { case IMODE_RAW:
*VAR_1 = 1; return invert; case IMODE_DIFF2:
case IMODE_NORM2:
if ((VAR_9 * VAR_8) & 1) { *planep++ = get_bits1(gb); VAR_7    = 1; } else
VAR_7 = 0; for (VAR_5 = VAR_7; VAR_5 < VAR_9 * VAR_8; VAR_5 += 2) { VAR_6 = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1); *planep++ = VAR_6 & 1; VAR_7++; if (VAR_7 == VAR_8) { VAR_7  = 0; planep += VAR_10 - VAR_8; } *planep++ = VAR_6 >> 1; VAR_7++; if (VAR_7 == VAR_8) { VAR_7  = 0; planep += VAR_10 - VAR_8; } } break; case IMODE_DIFF6:
case IMODE_NORM6:
if (!(VAR_9 % 3) && (VAR_8 % 3)) { for (VAR_5 = 0; VAR_5 < VAR_9; VAR_5 += 3) { for (VAR_4 = VAR_8 & 1; VAR_4 < VAR_8; VAR_4 += 2) { VAR_6 = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); if (VAR_6 < 0) { av_log(VAR_2->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); return -1; } planep[VAR_4 + 0]              = (VAR_6 >> 0) & 1; planep[VAR_4 + 1]              = (VAR_6 >> 1) & 1; planep[VAR_4 + 0 + VAR_10]     = (VAR_6 >> 2) & 1; planep[VAR_4 + 1 + VAR_10]     = (VAR_6 >> 3) & 1; planep[VAR_4 + 0 + VAR_10 * 2] = (VAR_6 >> 4) & 1; planep[VAR_4 + 1 + VAR_10 * 2] = (VAR_6 >> 5) & 1; } planep += VAR_10 * 3; } if (VAR_8 & 1)
decode_colskip(VAR_0, 1, VAR_9, VAR_10, &VAR_2->s.gb); } else { planep += (VAR_9 & 1) * VAR_10; for (VAR_5 = VAR_9 & 1; VAR_5 < VAR_9; VAR_5 += 2) { for (VAR_4 = VAR_8 % 3; VAR_4 < VAR_8; VAR_4 += 3) { VAR_6 = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); if (VAR_6 < 0) { av_log(VAR_2->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); return -1; } planep[VAR_4 + 0]          = (VAR_6 >> 0) & 1; planep[VAR_4 + 1]          = (VAR_6 >> 1) & 1; planep[VAR_4 + 2]          = (VAR_6 >> 2) & 1; planep[VAR_4 + 0 + VAR_10] = (VAR_6 >> 3) & 1; planep[VAR_4 + 1 + VAR_10] = (VAR_6 >> 4) & 1; planep[VAR_4 + 2 + VAR_10] = (VAR_6 >> 5) & 1; } planep += VAR_10 * 2; } VAR_4 = VAR_8 % 3; if (VAR_4)
decode_colskip(VAR_0,             VAR_4, VAR_9, VAR_10, &VAR_2->s.gb); if (VAR_9 & 1)
decode_rowskip(VAR_0 + VAR_4, VAR_8 - VAR_4,      1, VAR_10, &VAR_2->s.gb); } break; case IMODE_ROWSKIP:
decode_rowskip(VAR_0, VAR_8, VAR_9, VAR_10, &VAR_2->s.gb); break; case IMODE_COLSKIP:
decode_colskip(VAR_0, VAR_8, VAR_9, VAR_10, &VAR_2->s.gb); break; default:
break; } if (VAR_3 == IMODE_DIFF2 || VAR_3 == IMODE_DIFF6) { planep = VAR_0; planep[0] ^= invert; for (VAR_4 = 1; VAR_4 < VAR_8; VAR_4++) planep[VAR_4] ^= planep[VAR_4-1]; for (VAR_5 = 1; VAR_5 < VAR_9; VAR_5++) { planep += VAR_10; planep[0] ^= planep[-VAR_10]; for (VAR_4 = 1; VAR_4 < VAR_8; VAR_4++) { if (planep[VAR_4-1] != planep[VAR_4-VAR_10]) planep[VAR_4] ^= invert; else                                 planep[VAR_4] ^= planep[VAR_4-1]; } } } else if (invert) { planep = VAR_0; for (VAR_4 = 0; VAR_4 < VAR_10 * VAR_9; VAR_4++) planep[VAR_4] = !planep[VAR_4]; } return (VAR_3 << 1) + invert; }