static int bitplane_decoding(BitPlane *bp, VC9Context *v)

{

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



    int imode, x, y, code, use_vertical_tile, tile_w, tile_h;

    uint8_t invert, *planep = bp->data;



    invert = get_bits(gb, 1);

    imode = get_vlc2(gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2);



    bp->is_raw = 0;

    switch (imode)

    {

    case IMODE_RAW:

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

        bp->is_raw = 1; //invert ignored

        return invert;

    case IMODE_DIFF2:

    case IMODE_NORM2:

        if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1);

        for(x=0; x<(bp->height*bp->width)>>1; x++){

            code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);

            *(++planep) = code&1; //lsb => left

            *(++planep) = (code>>1)&1; //msb => right

            //FIXME width->stride

        }

        break;

    case IMODE_DIFF6:

    case IMODE_NORM6:

        use_vertical_tile=  bp->height%3==0 &&  bp->width%3!=0;

        tile_w= use_vertical_tile ? 2 : 3;

        tile_h= use_vertical_tile ? 3 : 2;



        for(y=  bp->height%tile_h; y< bp->height; y+=tile_h){

            for(x=  bp->width%tile_w; x< bp->width; x+=tile_w){

#if VLC_NORM6_METH0D == 1

                code = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2);

                if(code<0){

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

                    return -1;

                }

#endif

#if VLC_NORM6_METH0D == 2 //Failure

                code = get_vlc2(gb, vc9_norm6_first_vlc.table, VC9_NORM6_FIRST_BITS, 2);

                if (code == 22)

                {

                    code = vc9_norm6_flc_val[get_bits(gb, 5)];

                }

                else if (code == 23)

                {

#  if TRACE

                    code = get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2);

                    assert(code>-1 && code<22);

                    code = vc9_norm6_second_val[code];

#  else

                    code = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2)];

#  endif

                }

#endif //VLC_NORM6_METH0D == 2

                //FIXME following is a pure guess and probably wrong

                //FIXME A bitplane (0 | !0), so could the shifts be avoided ?

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

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

                //FIXME Does branch prediction help here?

                if(use_vertical_tile){

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

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

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

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

                }else{

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

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

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

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

                }

            }

        }



        x=  bp->width % tile_w;

        decode_colskip(bp->data  ,             x, bp->height         , bp->stride, v);

        decode_rowskip(bp->data+x, bp->width - x, bp->height % tile_h, bp->stride, v);



        break;

    case IMODE_ROWSKIP:

        decode_rowskip(bp->data, bp->width, bp->height, bp->stride, v);

        break;

    case IMODE_COLSKIP: //Teh ugly

        decode_colskip(bp->data, bp->width, bp->height, bp->stride, v);

        break;

    default: break;

    }



    /* Applying diff operator */

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

    {

        planep = bp->data;

        planep[0] ^= invert;

        for (x=1; x<bp->width; x++)

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

        for (y=1; y<bp->height; y++)

        {

            planep += bp->stride;

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

            for (x=1; x<bp->width; x++)

            {

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

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

            }

        }

    }

    else if (invert)

    {

        planep = bp->data;

        for (x=0; x<bp->width*bp->height; x++) planep[x] = !planep[x]; //FIXME stride

    }

    return (imode<<1) + invert;

}

static int bitplane_decoding(BitPlane *bp, VC9Context *v)

{

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



    int imode, x, y, code, use_vertical_tile, tile_w, tile_h;

    uint8_t invert, *planep = bp->data;



    invert = get_bits(gb, 1);

    imode = get_vlc2(gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2);



    bp->is_raw = 0;

    switch (imode)

    {

    case IMODE_RAW:

        

        bp->is_raw = 1; 

        return invert;

    case IMODE_DIFF2:

    case IMODE_NORM2:

        if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1);

        for(x=0; x<(bp->height*bp->width)>>1; x++){

            code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);

            *(++planep) = code&1; 

            *(++planep) = (code>>1)&1; 

            

        }

        break;

    case IMODE_DIFF6:

    case IMODE_NORM6:

        use_vertical_tile=  bp->height%3==0 &&  bp->width%3!=0;

        tile_w= use_vertical_tile ? 2 : 3;

        tile_h= use_vertical_tile ? 3 : 2;



        for(y=  bp->height%tile_h; y< bp->height; y+=tile_h){

            for(x=  bp->width%tile_w; x< bp->width; x+=tile_w){

#if VLC_NORM6_METH0D == 1

                code = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2);

                if(code<0){

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

                    return -1;

                }

#endif

#if VLC_NORM6_METH0D == 2 

                code = get_vlc2(gb, vc9_norm6_first_vlc.table, VC9_NORM6_FIRST_BITS, 2);

                if (code == 22)

                {

                    code = vc9_norm6_flc_val[get_bits(gb, 5)];

                }

                else if (code == 23)

                {

#  if TRACE

                    code = get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2);

                    assert(code>-1 && code<22);

                    code = vc9_norm6_second_val[code];

#  else

                    code = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2)];

#  endif

                }

#endif 

                

                

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

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

                

                if(use_vertical_tile){

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

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

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

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

                }else{

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

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

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

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

                }

            }

        }



        x=  bp->width % tile_w;

        decode_colskip(bp->data  ,             x, bp->height         , bp->stride, v);

        decode_rowskip(bp->data+x, bp->width - x, bp->height % tile_h, bp->stride, v);



        break;

    case IMODE_ROWSKIP:

        decode_rowskip(bp->data, bp->width, bp->height, bp->stride, v);

        break;

    case IMODE_COLSKIP: 

        decode_colskip(bp->data, bp->width, bp->height, bp->stride, v);

        break;

    default: break;

    }



    

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

    {

        planep = bp->data;

        planep[0] ^= invert;

        for (x=1; x<bp->width; x++)

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

        for (y=1; y<bp->height; y++)

        {

            planep += bp->stride;

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

            for (x=1; x<bp->width; x++)

            {

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

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

            }

        }

    }

    else if (invert)

    {

        planep = bp->data;

        for (x=0; x<bp->width*bp->height; x++) planep[x] = !planep[x]; 

    }

    return (imode<<1) + invert;

}

#if VLC_NORM6_METH0D == 1 #endif #endif #if VLC_NORM6_METH0D == 1 #  endif #if VLC_NORM6_METH0D == 1 #endif #endif     GetBitContext *gb = &v->s.gb;     GetBitContext *gb = &v->s.gb;     int imode, x, y, code, use_vertical_tile, tile_w, tile_h;         if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1);         for(x=0; x<(bp->height*bp->width)>>1; x++){             code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); #if VLC_NORM6_METH0D == 1 #endif                 code = get_vlc2(gb, vc9_norm6_first_vlc.table, VC9_NORM6_FIRST_BITS, 2);                 if (code == 22)                     code = vc9_norm6_flc_val[get_bits(gb, 5)];                 else if (code == 23) #  if TRACE                     code = get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2);                     assert(code>-1 && code<22);                     code = vc9_norm6_second_val[code]; #  else                     code = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2)]; #  endif         decode_colskip(bp->data  ,             x, bp->height         , bp->stride, v);         decode_rowskip(bp->data+x, bp->width - x, bp->height % tile_h, bp->stride, v);         decode_rowskip(bp->data, bp->width, bp->height, bp->stride, v);         decode_colskip(bp->data, bp->width, bp->height, bp->stride, v); #if VLC_NORM6_METH0D == 1 #endif #endif
static int FUNC_0(BitPlane *VAR_0, VC9Context *VAR_1)

{

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



    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    uint8_t invert, *planep = VAR_0->data;



    invert = get_bits(gb, 1);

    VAR_2 = get_vlc2(gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2);



    VAR_0->is_raw = 0;

    switch (VAR_2)

    {

    case IMODE_RAW:

        

        VAR_0->is_raw = 1; 

        return invert;

    case IMODE_DIFF2:

    case IMODE_NORM2:

        if ((VAR_0->height*VAR_0->width) & 1) *(++planep) = get_bits(gb, 1);

        for(VAR_3=0; VAR_3<(VAR_0->height*VAR_0->width)>>1; VAR_3++){

            VAR_5 = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);

            *(++planep) = VAR_5&1; 

            *(++planep) = (VAR_5>>1)&1; 

            

        }

        break;

    case IMODE_DIFF6:

    case IMODE_NORM6:

        VAR_6=  VAR_0->height%3==0 &&  VAR_0->width%3!=0;

        VAR_7= VAR_6 ? 2 : 3;

        VAR_8= VAR_6 ? 3 : 2;



        for(VAR_4=  VAR_0->height%VAR_8; VAR_4< VAR_0->height; VAR_4+=VAR_8){

            for(VAR_3=  VAR_0->width%VAR_7; VAR_3< VAR_0->width; VAR_3+=VAR_7){

#if VLC_NORM6_METH0D == 1

                VAR_5 = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2);

                if(VAR_5<0){

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

                    return -1;

                }

#endif

#if VLC_NORM6_METH0D == 2 

                VAR_5 = get_vlc2(gb, vc9_norm6_first_vlc.table, VC9_NORM6_FIRST_BITS, 2);

                if (VAR_5 == 22)

                {

                    VAR_5 = vc9_norm6_flc_val[get_bits(gb, 5)];

                }

                else if (VAR_5 == 23)

                {

#  if TRACE

                    VAR_5 = get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2);

                    assert(VAR_5>-1 && VAR_5<22);

                    VAR_5 = vc9_norm6_second_val[VAR_5];

#  else

                    VAR_5 = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2)];

#  endif

                }

#endif 

                

                

                planep[VAR_3     + 0*VAR_0->stride]= (VAR_5>>0)&1;

                planep[VAR_3 + 1 + 0*VAR_0->stride]= (VAR_5>>1)&1;

                

                if(VAR_6){

                    planep[VAR_3 + 0 + 1*VAR_0->stride]= (VAR_5>>2)&1;

                    planep[VAR_3 + 1 + 1*VAR_0->stride]= (VAR_5>>3)&1;

                    planep[VAR_3 + 0 + 2*VAR_0->stride]= (VAR_5>>4)&1;

                    planep[VAR_3 + 1 + 2*VAR_0->stride]= (VAR_5>>5)&1;

                }else{

                    planep[VAR_3 + 2 + 0*VAR_0->stride]= (VAR_5>>2)&1;

                    planep[VAR_3 + 0 + 1*VAR_0->stride]= (VAR_5>>3)&1;

                    planep[VAR_3 + 1 + 1*VAR_0->stride]= (VAR_5>>4)&1;

                    planep[VAR_3 + 2 + 1*VAR_0->stride]= (VAR_5>>5)&1;

                }

            }

        }



        VAR_3=  VAR_0->width % VAR_7;

        decode_colskip(VAR_0->data  ,             VAR_3, VAR_0->height         , VAR_0->stride, VAR_1);

        decode_rowskip(VAR_0->data+VAR_3, VAR_0->width - VAR_3, VAR_0->height % VAR_8, VAR_0->stride, VAR_1);



        break;

    case IMODE_ROWSKIP:

        decode_rowskip(VAR_0->data, VAR_0->width, VAR_0->height, VAR_0->stride, VAR_1);

        break;

    case IMODE_COLSKIP: 

        decode_colskip(VAR_0->data, VAR_0->width, VAR_0->height, VAR_0->stride, VAR_1);

        break;

    default: break;

    }



    

    if (VAR_2 == IMODE_DIFF2 || VAR_2 == IMODE_DIFF6)

    {

        planep = VAR_0->data;

        planep[0] ^= invert;

        for (VAR_3=1; VAR_3<VAR_0->width; VAR_3++)

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

        for (VAR_4=1; VAR_4<VAR_0->height; VAR_4++)

        {

            planep += VAR_0->stride;

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

            for (VAR_3=1; VAR_3<VAR_0->width; VAR_3++)

            {

                if (planep[VAR_3-1] != planep[VAR_3-VAR_0->stride]) planep[VAR_3] ^= invert;

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

            }

        }

    }

    else if (invert)

    {

        planep = VAR_0->data;

        for (VAR_3=0; VAR_3<VAR_0->width*VAR_0->height; VAR_3++) planep[VAR_3] = !planep[VAR_3]; 

    }

    return (VAR_2<<1) + invert;

}

static int FUNC_0(BitPlane *VAR_0, VC9Context *VAR_1)
{ GetBitContext *gb = &VAR_1->s.gb; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; uint8_t invert, *planep = VAR_0->data; invert = get_bits(gb, 1); VAR_2 = get_vlc2(gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2); VAR_0->is_raw = 0; switch (VAR_2)
{ case IMODE_RAW:
VAR_0->is_raw = 1; return invert; case IMODE_DIFF2:
case IMODE_NORM2:
if ((VAR_0->height*VAR_0->width) & 1) *(++planep) = get_bits(gb, 1); for(VAR_3=0; VAR_3<(VAR_0->height*VAR_0->width)>>1; VAR_3++){ VAR_5 = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); *(++planep) = VAR_5&1; *(++planep) = (VAR_5>>1)&1; } break; case IMODE_DIFF6:
case IMODE_NORM6:
VAR_6=  VAR_0->height%3==0 &&  VAR_0->width%3!=0; VAR_7= VAR_6 ? 2 : 3; VAR_8= VAR_6 ? 3 : 2; for(VAR_4=  VAR_0->height%VAR_8; VAR_4< VAR_0->height; VAR_4+=VAR_8){ for(VAR_3=  VAR_0->width%VAR_7; VAR_3< VAR_0->width; VAR_3+=VAR_7){ #if VLC_NORM6_METH0D == 1
VAR_5 = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2); if(VAR_5<0){ av_log(VAR_1->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); return -1; } #endif
#if VLC_NORM6_METH0D == 2
VAR_5 = get_vlc2(gb, vc9_norm6_first_vlc.table, VC9_NORM6_FIRST_BITS, 2); if (VAR_5 == 22)
{ VAR_5 = vc9_norm6_flc_val[get_bits(gb, 5)]; } else if (VAR_5 == 23)
{ #  if TRACE
VAR_5 = get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2); assert(VAR_5>-1 && VAR_5<22); VAR_5 = vc9_norm6_second_val[VAR_5]; #  else
VAR_5 = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2)]; #  endif
} #endif
planep[VAR_3     + 0*VAR_0->stride]= (VAR_5>>0)&1; planep[VAR_3 + 1 + 0*VAR_0->stride]= (VAR_5>>1)&1; if(VAR_6){ planep[VAR_3 + 0 + 1*VAR_0->stride]= (VAR_5>>2)&1; planep[VAR_3 + 1 + 1*VAR_0->stride]= (VAR_5>>3)&1; planep[VAR_3 + 0 + 2*VAR_0->stride]= (VAR_5>>4)&1; planep[VAR_3 + 1 + 2*VAR_0->stride]= (VAR_5>>5)&1; }else{ planep[VAR_3 + 2 + 0*VAR_0->stride]= (VAR_5>>2)&1; planep[VAR_3 + 0 + 1*VAR_0->stride]= (VAR_5>>3)&1; planep[VAR_3 + 1 + 1*VAR_0->stride]= (VAR_5>>4)&1; planep[VAR_3 + 2 + 1*VAR_0->stride]= (VAR_5>>5)&1; } } } VAR_3=  VAR_0->width % VAR_7; decode_colskip(VAR_0->data  ,             VAR_3, VAR_0->height         , VAR_0->stride, VAR_1); decode_rowskip(VAR_0->data+VAR_3, VAR_0->width - VAR_3, VAR_0->height % VAR_8, VAR_0->stride, VAR_1); break; case IMODE_ROWSKIP:
decode_rowskip(VAR_0->data, VAR_0->width, VAR_0->height, VAR_0->stride, VAR_1); break; case IMODE_COLSKIP:
decode_colskip(VAR_0->data, VAR_0->width, VAR_0->height, VAR_0->stride, VAR_1); break; default: break; } if (VAR_2 == IMODE_DIFF2 || VAR_2 == IMODE_DIFF6)
{ planep = VAR_0->data; planep[0] ^= invert; for (VAR_3=1; VAR_3<VAR_0->width; VAR_3++) planep[VAR_3] ^= planep[VAR_3-1]; for (VAR_4=1; VAR_4<VAR_0->height; VAR_4++) { planep += VAR_0->stride; planep[0] ^= planep[-VAR_0->stride]; for (VAR_3=1; VAR_3<VAR_0->width; VAR_3++) { if (planep[VAR_3-1] != planep[VAR_3-VAR_0->stride]) planep[VAR_3] ^= invert; else                                     planep[VAR_3] ^= planep[VAR_3-1]; } } } else if (invert)
{ planep = VAR_0->data; for (VAR_3=0; VAR_3<VAR_0->width*VAR_0->height; VAR_3++) planep[VAR_3] = !planep[VAR_3]; } return (VAR_2<<1) + invert; }