static int decode_init(AVCodecContext *avctx)

{

    HYuvContext *s = avctx->priv_data;

    int width, height;



    s->avctx= avctx;

    s->flags= avctx->flags;

        

    dsputil_init(&s->dsp, avctx);

    memset(s->vlc, 0, 3*sizeof(VLC));

    

    width= s->width= avctx->width;

    height= s->height= avctx->height;

    avctx->coded_frame= &s->picture;



s->bgr32=1;

    assert(width && height);

//if(avctx->extradata)

//  printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size);

    if(avctx->extradata_size){

        if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12)

            s->version=1; // do such files exist at all?

        else

            s->version=2;

    }else

        s->version=0;

    

    if(s->version==2){

        int method;



        method= ((uint8_t*)avctx->extradata)[0];

        s->decorrelate= method&64 ? 1 : 0;

        s->predictor= method&63;

        s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1];

        if(s->bitstream_bpp==0) 

            s->bitstream_bpp= avctx->bits_per_sample&~7;

        s->context= ((uint8_t*)avctx->extradata)[2] & 0x40 ? 1 : 0;

            

        if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0)

            return -1;

    }else{

        switch(avctx->bits_per_sample&7){

        case 1:

            s->predictor= LEFT;

            s->decorrelate= 0;

            break;

        case 2:

            s->predictor= LEFT;

            s->decorrelate= 1;

            break;

        case 3:

            s->predictor= PLANE;

            s->decorrelate= avctx->bits_per_sample >= 24;

            break;

        case 4:

            s->predictor= MEDIAN;

            s->decorrelate= 0;

            break;

        default:

            s->predictor= LEFT; //OLD

            s->decorrelate= 0;

            break;

        }

        s->bitstream_bpp= avctx->bits_per_sample & ~7;

        s->context= 0;

        

        if(read_old_huffman_tables(s) < 0)

            return -1;

    }

    

    if(((uint8_t*)avctx->extradata)[2] & 0x20)

	s->interlaced= ((uint8_t*)avctx->extradata)[2] & 0x10 ? 1 : 0;

    else

	s->interlaced= height > 288;

    

    switch(s->bitstream_bpp){

    case 12:

        avctx->pix_fmt = PIX_FMT_YUV420P;

        break;

    case 16:

        if(s->yuy2){

            avctx->pix_fmt = PIX_FMT_YUV422;

        }else{

            avctx->pix_fmt = PIX_FMT_YUV422P;

        }

        break;

    case 24:

    case 32:

        if(s->bgr32){

            avctx->pix_fmt = PIX_FMT_RGBA32;

        }else{

            avctx->pix_fmt = PIX_FMT_BGR24;

        }

        break;

    default:

        assert(0);

    }

    

//    av_log(NULL, AV_LOG_DEBUG, "pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);



    return 0;

}

static int decode_init(AVCodecContext *avctx)

{

    HYuvContext *s = avctx->priv_data;

    int width, height;



    s->avctx= avctx;

    s->flags= avctx->flags;

        

    dsputil_init(&s->dsp, avctx);

    memset(s->vlc, 0, 3*sizeof(VLC));

    

    width= s->width= avctx->width;

    height= s->height= avctx->height;

    avctx->coded_frame= &s->picture;



s->bgr32=1;

    assert(width && height);





    if(avctx->extradata_size){

        if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12)

            s->version=1; 

        else

            s->version=2;

    }else

        s->version=0;

    

    if(s->version==2){

        int method;



        method= ((uint8_t*)avctx->extradata)[0];

        s->decorrelate= method&64 ? 1 : 0;

        s->predictor= method&63;

        s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1];

        if(s->bitstream_bpp==0) 

            s->bitstream_bpp= avctx->bits_per_sample&~7;

        s->context= ((uint8_t*)avctx->extradata)[2] & 0x40 ? 1 : 0;

            

        if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0)

            return -1;

    }else{

        switch(avctx->bits_per_sample&7){

        case 1:

            s->predictor= LEFT;

            s->decorrelate= 0;

            break;

        case 2:

            s->predictor= LEFT;

            s->decorrelate= 1;

            break;

        case 3:

            s->predictor= PLANE;

            s->decorrelate= avctx->bits_per_sample >= 24;

            break;

        case 4:

            s->predictor= MEDIAN;

            s->decorrelate= 0;

            break;

        default:

            s->predictor= LEFT; 

            s->decorrelate= 0;

            break;

        }

        s->bitstream_bpp= avctx->bits_per_sample & ~7;

        s->context= 0;

        

        if(read_old_huffman_tables(s) < 0)

            return -1;

    }

    

    if(((uint8_t*)avctx->extradata)[2] & 0x20)

	s->interlaced= ((uint8_t*)avctx->extradata)[2] & 0x10 ? 1 : 0;

    else

	s->interlaced= height > 288;

    

    switch(s->bitstream_bpp){

    case 12:

        avctx->pix_fmt = PIX_FMT_YUV420P;

        break;

    case 16:

        if(s->yuy2){

            avctx->pix_fmt = PIX_FMT_YUV422;

        }else{

            avctx->pix_fmt = PIX_FMT_YUV422P;

        }

        break;

    case 24:

    case 32:

        if(s->bgr32){

            avctx->pix_fmt = PIX_FMT_RGBA32;

        }else{

            avctx->pix_fmt = PIX_FMT_BGR24;

        }

        break;

    default:

        assert(0);

    }

    





    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0)

{

    HYuvContext *s = VAR_0->priv_data;

    int VAR_1, VAR_2;



    s->VAR_0= VAR_0;

    s->flags= VAR_0->flags;

        

    dsputil_init(&s->dsp, VAR_0);

    memset(s->vlc, 0, 3*sizeof(VLC));

    

    VAR_1= s->VAR_1= VAR_0->VAR_1;

    VAR_2= s->VAR_2= VAR_0->VAR_2;

    VAR_0->coded_frame= &s->picture;



s->bgr32=1;

    assert(VAR_1 && VAR_2);





    if(VAR_0->extradata_size){

        if((VAR_0->bits_per_sample&7) && VAR_0->bits_per_sample != 12)

            s->version=1; 

        else

            s->version=2;

    }else

        s->version=0;

    

    if(s->version==2){

        int VAR_3;



        VAR_3= ((uint8_t*)VAR_0->extradata)[0];

        s->decorrelate= VAR_3&64 ? 1 : 0;

        s->predictor= VAR_3&63;

        s->bitstream_bpp= ((uint8_t*)VAR_0->extradata)[1];

        if(s->bitstream_bpp==0) 

            s->bitstream_bpp= VAR_0->bits_per_sample&~7;

        s->context= ((uint8_t*)VAR_0->extradata)[2] & 0x40 ? 1 : 0;

            

        if(read_huffman_tables(s, ((uint8_t*)VAR_0->extradata)+4, VAR_0->extradata_size) < 0)

            return -1;

    }else{

        switch(VAR_0->bits_per_sample&7){

        case 1:

            s->predictor= LEFT;

            s->decorrelate= 0;

            break;

        case 2:

            s->predictor= LEFT;

            s->decorrelate= 1;

            break;

        case 3:

            s->predictor= PLANE;

            s->decorrelate= VAR_0->bits_per_sample >= 24;

            break;

        case 4:

            s->predictor= MEDIAN;

            s->decorrelate= 0;

            break;

        default:

            s->predictor= LEFT; 

            s->decorrelate= 0;

            break;

        }

        s->bitstream_bpp= VAR_0->bits_per_sample & ~7;

        s->context= 0;

        

        if(read_old_huffman_tables(s) < 0)

            return -1;

    }

    

    if(((uint8_t*)VAR_0->extradata)[2] & 0x20)

	s->interlaced= ((uint8_t*)VAR_0->extradata)[2] & 0x10 ? 1 : 0;

    else

	s->interlaced= VAR_2 > 288;

    

    switch(s->bitstream_bpp){

    case 12:

        VAR_0->pix_fmt = PIX_FMT_YUV420P;

        break;

    case 16:

        if(s->yuy2){

            VAR_0->pix_fmt = PIX_FMT_YUV422;

        }else{

            VAR_0->pix_fmt = PIX_FMT_YUV422P;

        }

        break;

    case 24:

    case 32:

        if(s->bgr32){

            VAR_0->pix_fmt = PIX_FMT_RGBA32;

        }else{

            VAR_0->pix_fmt = PIX_FMT_BGR24;

        }

        break;

    default:

        assert(0);

    }

    





    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0)
{ HYuvContext *s = VAR_0->priv_data; int VAR_1, VAR_2; s->VAR_0= VAR_0; s->flags= VAR_0->flags; dsputil_init(&s->dsp, VAR_0); memset(s->vlc, 0, 3*sizeof(VLC)); VAR_1= s->VAR_1= VAR_0->VAR_1; VAR_2= s->VAR_2= VAR_0->VAR_2; VAR_0->coded_frame= &s->picture; s->bgr32=1; assert(VAR_1 && VAR_2); if(VAR_0->extradata_size){ if((VAR_0->bits_per_sample&7) && VAR_0->bits_per_sample != 12)
s->version=1; else
s->version=2; }else s->version=0; if(s->version==2){ int VAR_3; VAR_3= ((uint8_t*)VAR_0->extradata)[0]; s->decorrelate= VAR_3&64 ? 1 : 0; s->predictor= VAR_3&63; s->bitstream_bpp= ((uint8_t*)VAR_0->extradata)[1]; if(s->bitstream_bpp==0)
s->bitstream_bpp= VAR_0->bits_per_sample&~7; s->context= ((uint8_t*)VAR_0->extradata)[2] & 0x40 ? 1 : 0; if(read_huffman_tables(s, ((uint8_t*)VAR_0->extradata)+4, VAR_0->extradata_size) < 0)
return -1; }else{ switch(VAR_0->bits_per_sample&7){ case 1:
s->predictor= LEFT; s->decorrelate= 0; break; case 2:
s->predictor= LEFT; s->decorrelate= 1; break; case 3:
s->predictor= PLANE; s->decorrelate= VAR_0->bits_per_sample >= 24; break; case 4:
s->predictor= MEDIAN; s->decorrelate= 0; break; default:
s->predictor= LEFT; s->decorrelate= 0; break; } s->bitstream_bpp= VAR_0->bits_per_sample & ~7; s->context= 0; if(read_old_huffman_tables(s) < 0)
return -1; } if(((uint8_t*)VAR_0->extradata)[2] & 0x20)
s->interlaced= ((uint8_t*)VAR_0->extradata)[2] & 0x10 ? 1 : 0; else
s->interlaced= VAR_2 > 288; switch(s->bitstream_bpp){ case 12:
VAR_0->pix_fmt = PIX_FMT_YUV420P; break; case 16:
if(s->yuy2){ VAR_0->pix_fmt = PIX_FMT_YUV422; }else{ VAR_0->pix_fmt = PIX_FMT_YUV422P; } break; case 24:
case 32:
if(s->bgr32){ VAR_0->pix_fmt = PIX_FMT_RGBA32; }else{ VAR_0->pix_fmt = PIX_FMT_BGR24; } break; default:
assert(0); } return 0; }