void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,

                                    ScanTable *intra_scantable,

                                    uint16_t intra_matrix[64])

{

    int chroma_h_shift, chroma_v_shift;

    const int lossless = avctx->codec_id != AV_CODEC_ID_MJPEG;

    int hsample[3], vsample[3];



    av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,

                                     &chroma_v_shift);



    if (avctx->codec->id == AV_CODEC_ID_LJPEG &&

        avctx->pix_fmt   == AV_PIX_FMT_BGR24) {

        vsample[0] = hsample[0] =

        vsample[1] = hsample[1] =

        vsample[2] = hsample[2] = 1;

    } else {

        vsample[0] = 2;

        vsample[1] = 2 >> chroma_v_shift;

        vsample[2] = 2 >> chroma_v_shift;

        hsample[0] = 2;

        hsample[1] = 2 >> chroma_h_shift;

        hsample[2] = 2 >> chroma_h_shift;

    }



    put_marker(pb, SOI);



    jpeg_put_comments(avctx, pb);



    jpeg_table_header(pb, intra_scantable, intra_matrix);



    switch (avctx->codec_id) {

    case AV_CODEC_ID_MJPEG:  put_marker(pb, SOF0 ); break;

    case AV_CODEC_ID_LJPEG:  put_marker(pb, SOF3 ); break;

    default: assert(0);

    }



    put_bits(pb, 16, 17);

    if (lossless && avctx->pix_fmt == AV_PIX_FMT_BGR24)

        put_bits(pb, 8, 9); /* 9 bits/component RCT */

    else

        put_bits(pb, 8, 8); /* 8 bits/component */

    put_bits(pb, 16, avctx->height);

    put_bits(pb, 16, avctx->width);

    put_bits(pb, 8, 3); /* 3 components */



    /* Y component */

    put_bits(pb, 8, 1); /* component number */

    put_bits(pb, 4, hsample[0]); /* H factor */

    put_bits(pb, 4, vsample[0]); /* V factor */

    put_bits(pb, 8, 0); /* select matrix */



    /* Cb component */

    put_bits(pb, 8, 2); /* component number */

    put_bits(pb, 4, hsample[1]); /* H factor */

    put_bits(pb, 4, vsample[1]); /* V factor */

    put_bits(pb, 8, 0); /* select matrix */



    /* Cr component */

    put_bits(pb, 8, 3); /* component number */

    put_bits(pb, 4, hsample[2]); /* H factor */

    put_bits(pb, 4, vsample[2]); /* V factor */

    put_bits(pb, 8, 0); /* select matrix */



    /* scan header */

    put_marker(pb, SOS);

    put_bits(pb, 16, 12); /* length */

    put_bits(pb, 8, 3); /* 3 components */



    /* Y component */

    put_bits(pb, 8, 1); /* index */

    put_bits(pb, 4, 0); /* DC huffman table index */

    put_bits(pb, 4, 0); /* AC huffman table index */



    /* Cb component */

    put_bits(pb, 8, 2); /* index */

    put_bits(pb, 4, 1); /* DC huffman table index */

    put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */



    /* Cr component */

    put_bits(pb, 8, 3); /* index */

    put_bits(pb, 4, 1); /* DC huffman table index */

    put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */



    put_bits(pb, 8, lossless ? avctx->prediction_method + 1 : 0); /* Ss (not used) */



    switch (avctx->codec_id) {

    case AV_CODEC_ID_MJPEG:  put_bits(pb, 8, 63); break; /* Se (not used) */

    case AV_CODEC_ID_LJPEG:  put_bits(pb, 8,  0); break; /* not used */

    default: assert(0);

    }



    put_bits(pb, 8, 0); /* Ah/Al (not used) */

}

void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,

                                    ScanTable *intra_scantable,

                                    uint16_t intra_matrix[64])

{

    int chroma_h_shift, chroma_v_shift;

    const int lossless = avctx->codec_id != AV_CODEC_ID_MJPEG;

    int hsample[3], vsample[3];



    av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,

                                     &chroma_v_shift);



    if (avctx->codec->id == AV_CODEC_ID_LJPEG &&

        avctx->pix_fmt   == AV_PIX_FMT_BGR24) {

        vsample[0] = hsample[0] =

        vsample[1] = hsample[1] =

        vsample[2] = hsample[2] = 1;

    } else {

        vsample[0] = 2;

        vsample[1] = 2 >> chroma_v_shift;

        vsample[2] = 2 >> chroma_v_shift;

        hsample[0] = 2;

        hsample[1] = 2 >> chroma_h_shift;

        hsample[2] = 2 >> chroma_h_shift;

    }



    put_marker(pb, SOI);



    jpeg_put_comments(avctx, pb);



    jpeg_table_header(pb, intra_scantable, intra_matrix);



    switch (avctx->codec_id) {

    case AV_CODEC_ID_MJPEG:  put_marker(pb, SOF0 ); break;

    case AV_CODEC_ID_LJPEG:  put_marker(pb, SOF3 ); break;

    default: assert(0);

    }



    put_bits(pb, 16, 17);

    if (lossless && avctx->pix_fmt == AV_PIX_FMT_BGR24)

        put_bits(pb, 8, 9); 

    else

        put_bits(pb, 8, 8); 

    put_bits(pb, 16, avctx->height);

    put_bits(pb, 16, avctx->width);

    put_bits(pb, 8, 3); 



    

    put_bits(pb, 8, 1); 

    put_bits(pb, 4, hsample[0]); 

    put_bits(pb, 4, vsample[0]); 

    put_bits(pb, 8, 0); 



    

    put_bits(pb, 8, 2); 

    put_bits(pb, 4, hsample[1]); 

    put_bits(pb, 4, vsample[1]); 

    put_bits(pb, 8, 0); 



    

    put_bits(pb, 8, 3); 

    put_bits(pb, 4, hsample[2]); 

    put_bits(pb, 4, vsample[2]); 

    put_bits(pb, 8, 0); 



    

    put_marker(pb, SOS);

    put_bits(pb, 16, 12); 

    put_bits(pb, 8, 3); 



    

    put_bits(pb, 8, 1); 

    put_bits(pb, 4, 0); 

    put_bits(pb, 4, 0); 



    

    put_bits(pb, 8, 2); 

    put_bits(pb, 4, 1); 

    put_bits(pb, 4, lossless ? 0 : 1); 



    

    put_bits(pb, 8, 3); 

    put_bits(pb, 4, 1); 

    put_bits(pb, 4, lossless ? 0 : 1); 



    put_bits(pb, 8, lossless ? avctx->prediction_method + 1 : 0); 



    switch (avctx->codec_id) {

    case AV_CODEC_ID_MJPEG:  put_bits(pb, 8, 63); break; 

    case AV_CODEC_ID_LJPEG:  put_bits(pb, 8,  0); break; 

    default: assert(0);

    }



    put_bits(pb, 8, 0); 

}

void FUNC_0(AVCodecContext *VAR_0, PutBitContext *VAR_1,

                                    ScanTable *VAR_2,

                                    uint16_t VAR_3[64])

{

    int VAR_4, VAR_5;

    const int VAR_6 = VAR_0->codec_id != AV_CODEC_ID_MJPEG;

    int VAR_7[3], VAR_8[3];



    av_pix_fmt_get_chroma_sub_sample(VAR_0->pix_fmt, &VAR_4,

                                     &VAR_5);



    if (VAR_0->codec->id == AV_CODEC_ID_LJPEG &&

        VAR_0->pix_fmt   == AV_PIX_FMT_BGR24) {

        VAR_8[0] = VAR_7[0] =

        VAR_8[1] = VAR_7[1] =

        VAR_8[2] = VAR_7[2] = 1;

    } else {

        VAR_8[0] = 2;

        VAR_8[1] = 2 >> VAR_5;

        VAR_8[2] = 2 >> VAR_5;

        VAR_7[0] = 2;

        VAR_7[1] = 2 >> VAR_4;

        VAR_7[2] = 2 >> VAR_4;

    }



    put_marker(VAR_1, SOI);



    jpeg_put_comments(VAR_0, VAR_1);



    jpeg_table_header(VAR_1, VAR_2, VAR_3);



    switch (VAR_0->codec_id) {

    case AV_CODEC_ID_MJPEG:  put_marker(VAR_1, SOF0 ); break;

    case AV_CODEC_ID_LJPEG:  put_marker(VAR_1, SOF3 ); break;

    default: assert(0);

    }



    put_bits(VAR_1, 16, 17);

    if (VAR_6 && VAR_0->pix_fmt == AV_PIX_FMT_BGR24)

        put_bits(VAR_1, 8, 9); 

    else

        put_bits(VAR_1, 8, 8); 

    put_bits(VAR_1, 16, VAR_0->height);

    put_bits(VAR_1, 16, VAR_0->width);

    put_bits(VAR_1, 8, 3); 



    

    put_bits(VAR_1, 8, 1); 

    put_bits(VAR_1, 4, VAR_7[0]); 

    put_bits(VAR_1, 4, VAR_8[0]); 

    put_bits(VAR_1, 8, 0); 



    

    put_bits(VAR_1, 8, 2); 

    put_bits(VAR_1, 4, VAR_7[1]); 

    put_bits(VAR_1, 4, VAR_8[1]); 

    put_bits(VAR_1, 8, 0); 



    

    put_bits(VAR_1, 8, 3); 

    put_bits(VAR_1, 4, VAR_7[2]); 

    put_bits(VAR_1, 4, VAR_8[2]); 

    put_bits(VAR_1, 8, 0); 



    

    put_marker(VAR_1, SOS);

    put_bits(VAR_1, 16, 12); 

    put_bits(VAR_1, 8, 3); 



    

    put_bits(VAR_1, 8, 1); 

    put_bits(VAR_1, 4, 0); 

    put_bits(VAR_1, 4, 0); 



    

    put_bits(VAR_1, 8, 2); 

    put_bits(VAR_1, 4, 1); 

    put_bits(VAR_1, 4, VAR_6 ? 0 : 1); 



    

    put_bits(VAR_1, 8, 3); 

    put_bits(VAR_1, 4, 1); 

    put_bits(VAR_1, 4, VAR_6 ? 0 : 1); 



    put_bits(VAR_1, 8, VAR_6 ? VAR_0->prediction_method + 1 : 0); 



    switch (VAR_0->codec_id) {

    case AV_CODEC_ID_MJPEG:  put_bits(VAR_1, 8, 63); break; 

    case AV_CODEC_ID_LJPEG:  put_bits(VAR_1, 8,  0); break; 

    default: assert(0);

    }



    put_bits(VAR_1, 8, 0); 

}

void FUNC_0(AVCodecContext *VAR_0, PutBitContext *VAR_1,
ScanTable *VAR_2,
uint16_t VAR_3[64])
{ int VAR_4, VAR_5; const int VAR_6 = VAR_0->codec_id != AV_CODEC_ID_MJPEG; int VAR_7[3], VAR_8[3]; av_pix_fmt_get_chroma_sub_sample(VAR_0->pix_fmt, &VAR_4,
&VAR_5); if (VAR_0->codec->id == AV_CODEC_ID_LJPEG &&
VAR_0->pix_fmt   == AV_PIX_FMT_BGR24) { VAR_8[0] = VAR_7[0] =
VAR_8[1] = VAR_7[1] =
VAR_8[2] = VAR_7[2] = 1; } else { VAR_8[0] = 2; VAR_8[1] = 2 >> VAR_5; VAR_8[2] = 2 >> VAR_5; VAR_7[0] = 2; VAR_7[1] = 2 >> VAR_4; VAR_7[2] = 2 >> VAR_4; } put_marker(VAR_1, SOI); jpeg_put_comments(VAR_0, VAR_1); jpeg_table_header(VAR_1, VAR_2, VAR_3); switch (VAR_0->codec_id) { case AV_CODEC_ID_MJPEG:  put_marker(VAR_1, SOF0 ); break; case AV_CODEC_ID_LJPEG:  put_marker(VAR_1, SOF3 ); break; default: assert(0); } put_bits(VAR_1, 16, 17); if (VAR_6 && VAR_0->pix_fmt == AV_PIX_FMT_BGR24)
put_bits(VAR_1, 8, 9); else
put_bits(VAR_1, 8, 8); put_bits(VAR_1, 16, VAR_0->height); put_bits(VAR_1, 16, VAR_0->width); put_bits(VAR_1, 8, 3); put_bits(VAR_1, 8, 1); put_bits(VAR_1, 4, VAR_7[0]); put_bits(VAR_1, 4, VAR_8[0]); put_bits(VAR_1, 8, 0); put_bits(VAR_1, 8, 2); put_bits(VAR_1, 4, VAR_7[1]); put_bits(VAR_1, 4, VAR_8[1]); put_bits(VAR_1, 8, 0); put_bits(VAR_1, 8, 3); put_bits(VAR_1, 4, VAR_7[2]); put_bits(VAR_1, 4, VAR_8[2]); put_bits(VAR_1, 8, 0); put_marker(VAR_1, SOS); put_bits(VAR_1, 16, 12); put_bits(VAR_1, 8, 3); put_bits(VAR_1, 8, 1); put_bits(VAR_1, 4, 0); put_bits(VAR_1, 4, 0); put_bits(VAR_1, 8, 2); put_bits(VAR_1, 4, 1); put_bits(VAR_1, 4, VAR_6 ? 0 : 1); put_bits(VAR_1, 8, 3); put_bits(VAR_1, 4, 1); put_bits(VAR_1, 4, VAR_6 ? 0 : 1); put_bits(VAR_1, 8, VAR_6 ? VAR_0->prediction_method + 1 : 0); switch (VAR_0->codec_id) { case AV_CODEC_ID_MJPEG:  put_bits(VAR_1, 8, 63); break; case AV_CODEC_ID_LJPEG:  put_bits(VAR_1, 8,  0); break; default: assert(0); } put_bits(VAR_1, 8, 0); }