static int xface_encode_frame(AVCodecContext *avctx, AVPacket *pkt,

                              const AVFrame *frame, int *got_packet)

{

    XFaceContext *xface = avctx->priv_data;

    ProbRangesQueue pq = {{ 0 }, 0};

    uint8_t bitmap_copy[XFACE_PIXELS];

    BigInt b = {0};

    int i, j, k, ret = 0;

    const uint8_t *buf;

    uint8_t *p;

    char intbuf[XFACE_MAX_DIGITS];



    if (avctx->width || avctx->height) {

        if (avctx->width != XFACE_WIDTH || avctx->height != XFACE_HEIGHT) {

            av_log(avctx, AV_LOG_ERROR,

                   "Size value %dx%d not supported, only accepts a size of %dx%d\n",

                   avctx->width, avctx->height, XFACE_WIDTH, XFACE_HEIGHT);

            return AVERROR(EINVAL);

        }

    }

    avctx->width  = XFACE_WIDTH;

    avctx->height = XFACE_HEIGHT;



    /* convert image from MONOWHITE to 1=black 0=white bitmap */

    buf = frame->data[0];

    for (i = 0, j = 0; i < XFACE_PIXELS; ) {

        for (k = 0; k < 8; k++)

            xface->bitmap[i++] = (buf[j]>>(7-k))&1;

        if (++j == XFACE_WIDTH/8) {

            buf += frame->linesize[0];

            j = 0;

        }

    }



    /* create a copy of bitmap */

    memcpy(bitmap_copy, xface->bitmap, XFACE_PIXELS);

    ff_xface_generate_face(xface->bitmap, bitmap_copy);



    encode_block(xface->bitmap,                         16, 16, 0, &pq);

    encode_block(xface->bitmap + 16,                    16, 16, 0, &pq);

    encode_block(xface->bitmap + 32,                    16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16,      16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16 + 16, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16 + 32, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32,      16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32 + 16, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32 + 32, 16, 16, 0, &pq);



    while (pq.prob_ranges_idx > 0)

        push_integer(&b, pq.prob_ranges[--pq.prob_ranges_idx]);



    /* write the inverted big integer in b to intbuf */

    i = 0;

    while (b.nb_words) {

        uint8_t r;

        ff_big_div(&b, XFACE_PRINTS, &r);

        intbuf[i++] = r + XFACE_FIRST_PRINT;

    }



    if ((ret = ff_alloc_packet2(avctx, pkt, i+2)) < 0)

        return ret;



    /* revert the number, and close the buffer */

    p = pkt->data;

    while (--i >= 0)

        *(p++) = intbuf[i];

    *(p++) = '\n';

    *(p++) = 0;



    pkt->flags |= AV_PKT_FLAG_KEY;

    *got_packet = 1;



    return 0;

}

static int xface_encode_frame(AVCodecContext *avctx, AVPacket *pkt,

                              const AVFrame *frame, int *got_packet)

{

    XFaceContext *xface = avctx->priv_data;

    ProbRangesQueue pq = {{ 0 }, 0};

    uint8_t bitmap_copy[XFACE_PIXELS];

    BigInt b = {0};

    int i, j, k, ret = 0;

    const uint8_t *buf;

    uint8_t *p;

    char intbuf[XFACE_MAX_DIGITS];



    if (avctx->width || avctx->height) {

        if (avctx->width != XFACE_WIDTH || avctx->height != XFACE_HEIGHT) {

            av_log(avctx, AV_LOG_ERROR,

                   "Size value %dx%d not supported, only accepts a size of %dx%d\n",

                   avctx->width, avctx->height, XFACE_WIDTH, XFACE_HEIGHT);

            return AVERROR(EINVAL);

        }

    }

    avctx->width  = XFACE_WIDTH;

    avctx->height = XFACE_HEIGHT;



    

    buf = frame->data[0];

    for (i = 0, j = 0; i < XFACE_PIXELS; ) {

        for (k = 0; k < 8; k++)

            xface->bitmap[i++] = (buf[j]>>(7-k))&1;

        if (++j == XFACE_WIDTH/8) {

            buf += frame->linesize[0];

            j = 0;

        }

    }



    

    memcpy(bitmap_copy, xface->bitmap, XFACE_PIXELS);

    ff_xface_generate_face(xface->bitmap, bitmap_copy);



    encode_block(xface->bitmap,                         16, 16, 0, &pq);

    encode_block(xface->bitmap + 16,                    16, 16, 0, &pq);

    encode_block(xface->bitmap + 32,                    16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16,      16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16 + 16, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16 + 32, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32,      16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32 + 16, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32 + 32, 16, 16, 0, &pq);



    while (pq.prob_ranges_idx > 0)

        push_integer(&b, pq.prob_ranges[--pq.prob_ranges_idx]);



    

    i = 0;

    while (b.nb_words) {

        uint8_t r;

        ff_big_div(&b, XFACE_PRINTS, &r);

        intbuf[i++] = r + XFACE_FIRST_PRINT;

    }



    if ((ret = ff_alloc_packet2(avctx, pkt, i+2)) < 0)

        return ret;



    

    p = pkt->data;

    while (--i >= 0)

        *(p++) = intbuf[i];

    *(p++) = '\n';

    *(p++) = 0;



    pkt->flags |= AV_PKT_FLAG_KEY;

    *got_packet = 1;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,

                              const AVFrame *VAR_2, int *VAR_3)

{

    XFaceContext *xface = VAR_0->priv_data;

    ProbRangesQueue pq = {{ 0 }, 0};

    uint8_t bitmap_copy[XFACE_PIXELS];

    BigInt b = {0};

    int VAR_4, VAR_5, VAR_6, VAR_7 = 0;

    const uint8_t *VAR_8;

    uint8_t *p;

    char VAR_9[XFACE_MAX_DIGITS];



    if (VAR_0->width || VAR_0->height) {

        if (VAR_0->width != XFACE_WIDTH || VAR_0->height != XFACE_HEIGHT) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "Size value %dx%d not supported, only accepts a size of %dx%d\n",

                   VAR_0->width, VAR_0->height, XFACE_WIDTH, XFACE_HEIGHT);

            return AVERROR(EINVAL);

        }

    }

    VAR_0->width  = XFACE_WIDTH;

    VAR_0->height = XFACE_HEIGHT;



    

    VAR_8 = VAR_2->data[0];

    for (VAR_4 = 0, VAR_5 = 0; VAR_4 < XFACE_PIXELS; ) {

        for (VAR_6 = 0; VAR_6 < 8; VAR_6++)

            xface->bitmap[VAR_4++] = (VAR_8[VAR_5]>>(7-VAR_6))&1;

        if (++VAR_5 == XFACE_WIDTH/8) {

            VAR_8 += VAR_2->linesize[0];

            VAR_5 = 0;

        }

    }



    

    memcpy(bitmap_copy, xface->bitmap, XFACE_PIXELS);

    ff_xface_generate_face(xface->bitmap, bitmap_copy);



    encode_block(xface->bitmap,                         16, 16, 0, &pq);

    encode_block(xface->bitmap + 16,                    16, 16, 0, &pq);

    encode_block(xface->bitmap + 32,                    16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16,      16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16 + 16, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 16 + 32, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32,      16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32 + 16, 16, 16, 0, &pq);

    encode_block(xface->bitmap + XFACE_WIDTH * 32 + 32, 16, 16, 0, &pq);



    while (pq.prob_ranges_idx > 0)

        push_integer(&b, pq.prob_ranges[--pq.prob_ranges_idx]);



    

    VAR_4 = 0;

    while (b.nb_words) {

        uint8_t r;

        ff_big_div(&b, XFACE_PRINTS, &r);

        VAR_9[VAR_4++] = r + XFACE_FIRST_PRINT;

    }



    if ((VAR_7 = ff_alloc_packet2(VAR_0, VAR_1, VAR_4+2)) < 0)

        return VAR_7;



    

    p = VAR_1->data;

    while (--VAR_4 >= 0)

        *(p++) = VAR_9[VAR_4];

    *(p++) = '\n';

    *(p++) = 0;



    VAR_1->flags |= AV_PKT_FLAG_KEY;

    *VAR_3 = 1;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ XFaceContext *xface = VAR_0->priv_data; ProbRangesQueue pq = {{ 0 }, 0}; uint8_t bitmap_copy[XFACE_PIXELS]; BigInt b = {0}; int VAR_4, VAR_5, VAR_6, VAR_7 = 0; const uint8_t *VAR_8; uint8_t *p; char VAR_9[XFACE_MAX_DIGITS]; if (VAR_0->width || VAR_0->height) { if (VAR_0->width != XFACE_WIDTH || VAR_0->height != XFACE_HEIGHT) { av_log(VAR_0, AV_LOG_ERROR,
"Size value %dx%d not supported, only accepts a size of %dx%d\n",
VAR_0->width, VAR_0->height, XFACE_WIDTH, XFACE_HEIGHT); return AVERROR(EINVAL); } } VAR_0->width  = XFACE_WIDTH; VAR_0->height = XFACE_HEIGHT; VAR_8 = VAR_2->data[0]; for (VAR_4 = 0, VAR_5 = 0; VAR_4 < XFACE_PIXELS; ) { for (VAR_6 = 0; VAR_6 < 8; VAR_6++) xface->bitmap[VAR_4++] = (VAR_8[VAR_5]>>(7-VAR_6))&1; if (++VAR_5 == XFACE_WIDTH/8) { VAR_8 += VAR_2->linesize[0]; VAR_5 = 0; } } memcpy(bitmap_copy, xface->bitmap, XFACE_PIXELS); ff_xface_generate_face(xface->bitmap, bitmap_copy); encode_block(xface->bitmap,                         16, 16, 0, &pq); encode_block(xface->bitmap + 16,                    16, 16, 0, &pq); encode_block(xface->bitmap + 32,                    16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 16,      16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 16 + 16, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 16 + 32, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 32,      16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 32 + 16, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 32 + 32, 16, 16, 0, &pq); while (pq.prob_ranges_idx > 0)
push_integer(&b, pq.prob_ranges[--pq.prob_ranges_idx]); VAR_4 = 0; while (b.nb_words) { uint8_t r; ff_big_div(&b, XFACE_PRINTS, &r); VAR_9[VAR_4++] = r + XFACE_FIRST_PRINT; } if ((VAR_7 = ff_alloc_packet2(VAR_0, VAR_1, VAR_4+2)) < 0)
return VAR_7; p = VAR_1->data; while (--VAR_4 >= 0)
*(p++) = VAR_9[VAR_4]; *(p++) = '\n'; *(p++) = 0; VAR_1->flags |= AV_PKT_FLAG_KEY; *VAR_3 = 1; return 0; }