static int raw_decode(AVCodecContext *avctx,

                            void *data, int *data_size,

                            AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    int linesize_align = 4;

    RawVideoContext *context = avctx->priv_data;



    AVFrame   *frame   = data;

    AVPicture *picture = data;



    frame->pict_type        = avctx->coded_frame->pict_type;

    frame->interlaced_frame = avctx->coded_frame->interlaced_frame;

    frame->top_field_first = avctx->coded_frame->top_field_first;

    frame->reordered_opaque = avctx->reordered_opaque;

    frame->pkt_pts          = avctx->pkt->pts;

    frame->pkt_pos          = avctx->pkt->pos;



    if(context->tff>=0){

        frame->interlaced_frame = 1;

        frame->top_field_first  = context->tff;

    }



    if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))

        return -1;



    if (avctx->width <= 0 || avctx->height <= 0) {

        av_log(avctx, AV_LOG_ERROR, "w/h is invalid\n");

        return AVERROR(EINVAL);

    }



    //2bpp and 4bpp raw in avi and mov (yes this is ugly ...)

    if (context->buffer) {

        int i;

        uint8_t *dst = context->buffer;

        buf_size = context->length - 256*4;

        if (avctx->bits_per_coded_sample == 4){

            for(i=0; 2*i+1 < buf_size && i<avpkt->size; i++){

                dst[2*i+0]= buf[i]>>4;

                dst[2*i+1]= buf[i]&15;

            }

            linesize_align = 8;

        } else {

            for(i=0; 4*i+3 < buf_size && i<avpkt->size; i++){

                dst[4*i+0]= buf[i]>>6;

                dst[4*i+1]= buf[i]>>4&3;

                dst[4*i+2]= buf[i]>>2&3;

                dst[4*i+3]= buf[i]   &3;

            }

            linesize_align = 16;

        }

        buf= dst;

    }



    if(avctx->codec_tag == MKTAG('A', 'V', '1', 'x') ||

       avctx->codec_tag == MKTAG('A', 'V', 'u', 'p'))

        buf += buf_size - context->length;



    avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);

    if((avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length) ||

       (av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PSEUDOPAL)) {

        frame->data[1]= context->palette;

    }

    if (avctx->pix_fmt == PIX_FMT_PAL8) {

        const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);



        if (pal) {

            memcpy(frame->data[1], pal, AVPALETTE_SIZE);

            frame->palette_has_changed = 1;

        }

    }

    if((avctx->pix_fmt==PIX_FMT_BGR24    ||

        avctx->pix_fmt==PIX_FMT_GRAY8    ||

        avctx->pix_fmt==PIX_FMT_RGB555LE ||

        avctx->pix_fmt==PIX_FMT_RGB555BE ||

        avctx->pix_fmt==PIX_FMT_RGB565LE ||

        avctx->pix_fmt==PIX_FMT_MONOWHITE ||

        avctx->pix_fmt==PIX_FMT_PAL8) &&

        FFALIGN(frame->linesize[0], linesize_align)*avctx->height <= buf_size)

        frame->linesize[0] = FFALIGN(frame->linesize[0], linesize_align);



    if(context->flip)

        flip(avctx, picture);



    if (   avctx->codec_tag == MKTAG('Y', 'V', '1', '2')

        || avctx->codec_tag == MKTAG('Y', 'V', '1', '6')

        || avctx->codec_tag == MKTAG('Y', 'V', '2', '4')

        || avctx->codec_tag == MKTAG('Y', 'V', 'U', '9'))

        FFSWAP(uint8_t *, picture->data[1], picture->data[2]);



    if(avctx->codec_tag == AV_RL32("yuv2") &&

       avctx->pix_fmt   == PIX_FMT_YUYV422) {

        int x, y;

        uint8_t *line = picture->data[0];

        for(y = 0; y < avctx->height; y++) {

            for(x = 0; x < avctx->width; x++)

                line[2*x + 1] ^= 0x80;

            line += picture->linesize[0];

        }

    }



    *data_size = sizeof(AVPicture);

    return buf_size;

}

static int raw_decode(AVCodecContext *avctx,

                            void *data, int *data_size,

                            AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    int linesize_align = 4;

    RawVideoContext *context = avctx->priv_data;



    AVFrame   *frame   = data;

    AVPicture *picture = data;



    frame->pict_type        = avctx->coded_frame->pict_type;

    frame->interlaced_frame = avctx->coded_frame->interlaced_frame;

    frame->top_field_first = avctx->coded_frame->top_field_first;

    frame->reordered_opaque = avctx->reordered_opaque;

    frame->pkt_pts          = avctx->pkt->pts;

    frame->pkt_pos          = avctx->pkt->pos;



    if(context->tff>=0){

        frame->interlaced_frame = 1;

        frame->top_field_first  = context->tff;

    }



    if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))

        return -1;



    if (avctx->width <= 0 || avctx->height <= 0) {

        av_log(avctx, AV_LOG_ERROR, "w/h is invalid\n");

        return AVERROR(EINVAL);

    }



    

    if (context->buffer) {

        int i;

        uint8_t *dst = context->buffer;

        buf_size = context->length - 256*4;

        if (avctx->bits_per_coded_sample == 4){

            for(i=0; 2*i+1 < buf_size && i<avpkt->size; i++){

                dst[2*i+0]= buf[i]>>4;

                dst[2*i+1]= buf[i]&15;

            }

            linesize_align = 8;

        } else {

            for(i=0; 4*i+3 < buf_size && i<avpkt->size; i++){

                dst[4*i+0]= buf[i]>>6;

                dst[4*i+1]= buf[i]>>4&3;

                dst[4*i+2]= buf[i]>>2&3;

                dst[4*i+3]= buf[i]   &3;

            }

            linesize_align = 16;

        }

        buf= dst;

    }



    if(avctx->codec_tag == MKTAG('A', 'V', '1', 'x') ||

       avctx->codec_tag == MKTAG('A', 'V', 'u', 'p'))

        buf += buf_size - context->length;



    avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);

    if((avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length) ||

       (av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PSEUDOPAL)) {

        frame->data[1]= context->palette;

    }

    if (avctx->pix_fmt == PIX_FMT_PAL8) {

        const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);



        if (pal) {

            memcpy(frame->data[1], pal, AVPALETTE_SIZE);

            frame->palette_has_changed = 1;

        }

    }

    if((avctx->pix_fmt==PIX_FMT_BGR24    ||

        avctx->pix_fmt==PIX_FMT_GRAY8    ||

        avctx->pix_fmt==PIX_FMT_RGB555LE ||

        avctx->pix_fmt==PIX_FMT_RGB555BE ||

        avctx->pix_fmt==PIX_FMT_RGB565LE ||

        avctx->pix_fmt==PIX_FMT_MONOWHITE ||

        avctx->pix_fmt==PIX_FMT_PAL8) &&

        FFALIGN(frame->linesize[0], linesize_align)*avctx->height <= buf_size)

        frame->linesize[0] = FFALIGN(frame->linesize[0], linesize_align);



    if(context->flip)

        flip(avctx, picture);



    if (   avctx->codec_tag == MKTAG('Y', 'V', '1', '2')

        || avctx->codec_tag == MKTAG('Y', 'V', '1', '6')

        || avctx->codec_tag == MKTAG('Y', 'V', '2', '4')

        || avctx->codec_tag == MKTAG('Y', 'V', 'U', '9'))

        FFSWAP(uint8_t *, picture->data[1], picture->data[2]);



    if(avctx->codec_tag == AV_RL32("yuv2") &&

       avctx->pix_fmt   == PIX_FMT_YUYV422) {

        int x, y;

        uint8_t *line = picture->data[0];

        for(y = 0; y < avctx->height; y++) {

            for(x = 0; x < avctx->width; x++)

                line[2*x + 1] ^= 0x80;

            line += picture->linesize[0];

        }

    }



    *data_size = sizeof(AVPicture);

    return buf_size;

}

static int FUNC_0(AVCodecContext *VAR_0,

                            void *VAR_1, int *VAR_2,

                            AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5 = VAR_3->size;

    int VAR_6 = 4;

    RawVideoContext *context = VAR_0->priv_data;



    AVFrame   *frame   = VAR_1;

    AVPicture *picture = VAR_1;



    frame->pict_type        = VAR_0->coded_frame->pict_type;

    frame->interlaced_frame = VAR_0->coded_frame->interlaced_frame;

    frame->top_field_first = VAR_0->coded_frame->top_field_first;

    frame->reordered_opaque = VAR_0->reordered_opaque;

    frame->pkt_pts          = VAR_0->pkt->pts;

    frame->pkt_pos          = VAR_0->pkt->pos;



    if(context->tff>=0){

        frame->interlaced_frame = 1;

        frame->top_field_first  = context->tff;

    }



    if(VAR_5 < context->length - (VAR_0->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))

        return -1;



    if (VAR_0->width <= 0 || VAR_0->height <= 0) {

        av_log(VAR_0, AV_LOG_ERROR, "w/h is invalid\n");

        return AVERROR(EINVAL);

    }



    

    if (context->buffer) {

        int VAR_7;

        uint8_t *dst = context->buffer;

        VAR_5 = context->length - 256*4;

        if (VAR_0->bits_per_coded_sample == 4){

            for(VAR_7=0; 2*VAR_7+1 < VAR_5 && VAR_7<VAR_3->size; VAR_7++){

                dst[2*VAR_7+0]= VAR_4[VAR_7]>>4;

                dst[2*VAR_7+1]= VAR_4[VAR_7]&15;

            }

            VAR_6 = 8;

        } else {

            for(VAR_7=0; 4*VAR_7+3 < VAR_5 && VAR_7<VAR_3->size; VAR_7++){

                dst[4*VAR_7+0]= VAR_4[VAR_7]>>6;

                dst[4*VAR_7+1]= VAR_4[VAR_7]>>4&3;

                dst[4*VAR_7+2]= VAR_4[VAR_7]>>2&3;

                dst[4*VAR_7+3]= VAR_4[VAR_7]   &3;

            }

            VAR_6 = 16;

        }

        VAR_4= dst;

    }



    if(VAR_0->codec_tag == MKTAG('A', 'V', '1', 'VAR_9') ||

       VAR_0->codec_tag == MKTAG('A', 'V', 'u', 'p'))

        VAR_4 += VAR_5 - context->length;



    avpicture_fill(picture, VAR_4, VAR_0->pix_fmt, VAR_0->width, VAR_0->height);

    if((VAR_0->pix_fmt==PIX_FMT_PAL8 && VAR_5 < context->length) ||

       (av_pix_fmt_descriptors[VAR_0->pix_fmt].flags & PIX_FMT_PSEUDOPAL)) {

        frame->VAR_1[1]= context->palette;

    }

    if (VAR_0->pix_fmt == PIX_FMT_PAL8) {

        const uint8_t *VAR_8 = av_packet_get_side_data(VAR_3, AV_PKT_DATA_PALETTE, NULL);



        if (VAR_8) {

            memcpy(frame->VAR_1[1], VAR_8, AVPALETTE_SIZE);

            frame->palette_has_changed = 1;

        }

    }

    if((VAR_0->pix_fmt==PIX_FMT_BGR24    ||

        VAR_0->pix_fmt==PIX_FMT_GRAY8    ||

        VAR_0->pix_fmt==PIX_FMT_RGB555LE ||

        VAR_0->pix_fmt==PIX_FMT_RGB555BE ||

        VAR_0->pix_fmt==PIX_FMT_RGB565LE ||

        VAR_0->pix_fmt==PIX_FMT_MONOWHITE ||

        VAR_0->pix_fmt==PIX_FMT_PAL8) &&

        FFALIGN(frame->linesize[0], VAR_6)*VAR_0->height <= VAR_5)

        frame->linesize[0] = FFALIGN(frame->linesize[0], VAR_6);



    if(context->flip)

        flip(VAR_0, picture);



    if (   VAR_0->codec_tag == MKTAG('Y', 'V', '1', '2')

        || VAR_0->codec_tag == MKTAG('Y', 'V', '1', '6')

        || VAR_0->codec_tag == MKTAG('Y', 'V', '2', '4')

        || VAR_0->codec_tag == MKTAG('Y', 'V', 'U', '9'))

        FFSWAP(uint8_t *, picture->VAR_1[1], picture->VAR_1[2]);



    if(VAR_0->codec_tag == AV_RL32("yuv2") &&

       VAR_0->pix_fmt   == PIX_FMT_YUYV422) {

        int VAR_9, VAR_10;

        uint8_t *line = picture->VAR_1[0];

        for(VAR_10 = 0; VAR_10 < VAR_0->height; VAR_10++) {

            for(VAR_9 = 0; VAR_9 < VAR_0->width; VAR_9++)

                line[2*VAR_9 + 1] ^= 0x80;

            line += picture->linesize[0];

        }

    }



    *VAR_2 = sizeof(AVPicture);

    return VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5 = VAR_3->size; int VAR_6 = 4; RawVideoContext *context = VAR_0->priv_data; AVFrame   *frame   = VAR_1; AVPicture *picture = VAR_1; frame->pict_type        = VAR_0->coded_frame->pict_type; frame->interlaced_frame = VAR_0->coded_frame->interlaced_frame; frame->top_field_first = VAR_0->coded_frame->top_field_first; frame->reordered_opaque = VAR_0->reordered_opaque; frame->pkt_pts          = VAR_0->pkt->pts; frame->pkt_pos          = VAR_0->pkt->pos; if(context->tff>=0){ frame->interlaced_frame = 1; frame->top_field_first  = context->tff; } if(VAR_5 < context->length - (VAR_0->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))
return -1; if (VAR_0->width <= 0 || VAR_0->height <= 0) { av_log(VAR_0, AV_LOG_ERROR, "w/h is invalid\n"); return AVERROR(EINVAL); } if (context->buffer) { int VAR_7; uint8_t *dst = context->buffer; VAR_5 = context->length - 256*4; if (VAR_0->bits_per_coded_sample == 4){ for(VAR_7=0; 2*VAR_7+1 < VAR_5 && VAR_7<VAR_3->size; VAR_7++){ dst[2*VAR_7+0]= VAR_4[VAR_7]>>4; dst[2*VAR_7+1]= VAR_4[VAR_7]&15; } VAR_6 = 8; } else { for(VAR_7=0; 4*VAR_7+3 < VAR_5 && VAR_7<VAR_3->size; VAR_7++){ dst[4*VAR_7+0]= VAR_4[VAR_7]>>6; dst[4*VAR_7+1]= VAR_4[VAR_7]>>4&3; dst[4*VAR_7+2]= VAR_4[VAR_7]>>2&3; dst[4*VAR_7+3]= VAR_4[VAR_7]   &3; } VAR_6 = 16; } VAR_4= dst; } if(VAR_0->codec_tag == MKTAG('A', 'V', '1', 'VAR_9') ||
VAR_0->codec_tag == MKTAG('A', 'V', 'u', 'p'))
VAR_4 += VAR_5 - context->length; avpicture_fill(picture, VAR_4, VAR_0->pix_fmt, VAR_0->width, VAR_0->height); if((VAR_0->pix_fmt==PIX_FMT_PAL8 && VAR_5 < context->length) ||
(av_pix_fmt_descriptors[VAR_0->pix_fmt].flags & PIX_FMT_PSEUDOPAL)) { frame->VAR_1[1]= context->palette; } if (VAR_0->pix_fmt == PIX_FMT_PAL8) { const uint8_t *VAR_8 = av_packet_get_side_data(VAR_3, AV_PKT_DATA_PALETTE, NULL); if (VAR_8) { memcpy(frame->VAR_1[1], VAR_8, AVPALETTE_SIZE); frame->palette_has_changed = 1; } } if((VAR_0->pix_fmt==PIX_FMT_BGR24    ||
VAR_0->pix_fmt==PIX_FMT_GRAY8    ||
VAR_0->pix_fmt==PIX_FMT_RGB555LE ||
VAR_0->pix_fmt==PIX_FMT_RGB555BE ||
VAR_0->pix_fmt==PIX_FMT_RGB565LE ||
VAR_0->pix_fmt==PIX_FMT_MONOWHITE ||
VAR_0->pix_fmt==PIX_FMT_PAL8) &&
FFALIGN(frame->linesize[0], VAR_6)*VAR_0->height <= VAR_5)
frame->linesize[0] = FFALIGN(frame->linesize[0], VAR_6); if(context->flip)
flip(VAR_0, picture); if (   VAR_0->codec_tag == MKTAG('Y', 'V', '1', '2')
|| VAR_0->codec_tag == MKTAG('Y', 'V', '1', '6')
|| VAR_0->codec_tag == MKTAG('Y', 'V', '2', '4')
|| VAR_0->codec_tag == MKTAG('Y', 'V', 'U', '9'))
FFSWAP(uint8_t *, picture->VAR_1[1], picture->VAR_1[2]); if(VAR_0->codec_tag == AV_RL32("yuv2") &&
VAR_0->pix_fmt   == PIX_FMT_YUYV422) { int VAR_9, VAR_10; uint8_t *line = picture->VAR_1[0]; for(VAR_10 = 0; VAR_10 < VAR_0->height; VAR_10++) { for(VAR_9 = 0; VAR_9 < VAR_0->width; VAR_9++) line[2*VAR_9 + 1] ^= 0x80; line += picture->linesize[0]; } } *VAR_2 = sizeof(AVPicture); return VAR_5; }