static int xan_decode_chroma(AVCodecContext *avctx, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    XanContext *s = avctx->priv_data;

    uint8_t *U, *V;

    unsigned chroma_off;

    int val, uval, vval;

    int i, j;

    const uint8_t *src, *src_end;

    const uint8_t *table;

    int mode, offset, dec_size;



    chroma_off = AV_RL32(buf + 4);

    if (!chroma_off)

        return 0;

    if (chroma_off + 10 >= avpkt->size) {

        av_log(avctx, AV_LOG_ERROR, "Invalid chroma block position\n");

        return -1;

    }

    src    = avpkt->data + 4 + chroma_off;

    table  = src + 2;

    mode   = bytestream_get_le16(&src);

    offset = bytestream_get_le16(&src) * 2;



    if (src - avpkt->data >= avpkt->size - offset) {

        av_log(avctx, AV_LOG_ERROR, "Invalid chroma block offset\n");

        return -1;

    }



    memset(s->scratch_buffer, 0, s->buffer_size);

    dec_size = xan_unpack(s->scratch_buffer, s->buffer_size, src + offset,

                          avpkt->size - offset - (src - avpkt->data));

    if (dec_size < 0) {

        av_log(avctx, AV_LOG_ERROR, "Chroma unpacking failed\n");

        return -1;

    }



    U = s->pic.data[1];

    V = s->pic.data[2];

    src     = s->scratch_buffer;

    src_end = src + dec_size;

    if (mode) {

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

            for (i = 0; i < avctx->width >> 1; i++) {

                val = *src++;

                if (val) {

                    val  = AV_RL16(table + (val << 1));

                    uval = (val >> 3) & 0xF8;

                    vval = (val >> 8) & 0xF8;

                    U[i] = uval | (uval >> 5);

                    V[i] = vval | (vval >> 5);

                }

                if (src == src_end)

                    return 0;

            }

            U += s->pic.linesize[1];

            V += s->pic.linesize[2];

        }

    } else {

        uint8_t *U2 = U + s->pic.linesize[1];

        uint8_t *V2 = V + s->pic.linesize[2];



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

            for (i = 0; i < avctx->width >> 1; i += 2) {

                val = *src++;

                if (val) {

                    val  = AV_RL16(table + (val << 1));

                    uval = (val >> 3) & 0xF8;

                    vval = (val >> 8) & 0xF8;

                    U[i] = U[i+1] = U2[i] = U2[i+1] = uval | (uval >> 5);

                    V[i] = V[i+1] = V2[i] = V2[i+1] = vval | (vval >> 5);

                }

            }

            U  += s->pic.linesize[1] * 2;

            V  += s->pic.linesize[2] * 2;

            U2 += s->pic.linesize[1] * 2;

            V2 += s->pic.linesize[2] * 2;

        }

    }



    return 0;

}

static int xan_decode_chroma(AVCodecContext *avctx, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    XanContext *s = avctx->priv_data;

    uint8_t *U, *V;

    unsigned chroma_off;

    int val, uval, vval;

    int i, j;

    const uint8_t *src, *src_end;

    const uint8_t *table;

    int mode, offset, dec_size;



    chroma_off = AV_RL32(buf + 4);

    if (!chroma_off)

        return 0;

    if (chroma_off + 10 >= avpkt->size) {

        av_log(avctx, AV_LOG_ERROR, "Invalid chroma block position\n");

        return -1;

    }

    src    = avpkt->data + 4 + chroma_off;

    table  = src + 2;

    mode   = bytestream_get_le16(&src);

    offset = bytestream_get_le16(&src) * 2;



    if (src - avpkt->data >= avpkt->size - offset) {

        av_log(avctx, AV_LOG_ERROR, "Invalid chroma block offset\n");

        return -1;

    }



    memset(s->scratch_buffer, 0, s->buffer_size);

    dec_size = xan_unpack(s->scratch_buffer, s->buffer_size, src + offset,

                          avpkt->size - offset - (src - avpkt->data));

    if (dec_size < 0) {

        av_log(avctx, AV_LOG_ERROR, "Chroma unpacking failed\n");

        return -1;

    }



    U = s->pic.data[1];

    V = s->pic.data[2];

    src     = s->scratch_buffer;

    src_end = src + dec_size;

    if (mode) {

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

            for (i = 0; i < avctx->width >> 1; i++) {

                val = *src++;

                if (val) {

                    val  = AV_RL16(table + (val << 1));

                    uval = (val >> 3) & 0xF8;

                    vval = (val >> 8) & 0xF8;

                    U[i] = uval | (uval >> 5);

                    V[i] = vval | (vval >> 5);

                }

                if (src == src_end)

                    return 0;

            }

            U += s->pic.linesize[1];

            V += s->pic.linesize[2];

        }

    } else {

        uint8_t *U2 = U + s->pic.linesize[1];

        uint8_t *V2 = V + s->pic.linesize[2];



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

            for (i = 0; i < avctx->width >> 1; i += 2) {

                val = *src++;

                if (val) {

                    val  = AV_RL16(table + (val << 1));

                    uval = (val >> 3) & 0xF8;

                    vval = (val >> 8) & 0xF8;

                    U[i] = U[i+1] = U2[i] = U2[i+1] = uval | (uval >> 5);

                    V[i] = V[i+1] = V2[i] = V2[i+1] = vval | (vval >> 5);

                }

            }

            U  += s->pic.linesize[1] * 2;

            V  += s->pic.linesize[2] * 2;

            U2 += s->pic.linesize[1] * 2;

            V2 += s->pic.linesize[2] * 2;

        }

    }



    return 0;

}

                if (src == src_end)                     return 0;
static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1)

{

    const uint8_t *VAR_2 = VAR_1->data;

    XanContext *s = VAR_0->priv_data;

    uint8_t *U, *V;

    unsigned VAR_3;

    int VAR_4, VAR_5, VAR_6;

    int VAR_7, VAR_8;

    const uint8_t *VAR_9, *src_end;

    const uint8_t *VAR_10;

    int VAR_11, VAR_12, VAR_13;



    VAR_3 = AV_RL32(VAR_2 + 4);

    if (!VAR_3)

        return 0;

    if (VAR_3 + 10 >= VAR_1->size) {

        av_log(VAR_0, AV_LOG_ERROR, "Invalid chroma block position\n");

        return -1;

    }

    VAR_9    = VAR_1->data + 4 + VAR_3;

    VAR_10  = VAR_9 + 2;

    VAR_11   = bytestream_get_le16(&VAR_9);

    VAR_12 = bytestream_get_le16(&VAR_9) * 2;



    if (VAR_9 - VAR_1->data >= VAR_1->size - VAR_12) {

        av_log(VAR_0, AV_LOG_ERROR, "Invalid chroma block VAR_12\n");

        return -1;

    }



    memset(s->scratch_buffer, 0, s->buffer_size);

    VAR_13 = xan_unpack(s->scratch_buffer, s->buffer_size, VAR_9 + VAR_12,

                          VAR_1->size - VAR_12 - (VAR_9 - VAR_1->data));

    if (VAR_13 < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Chroma unpacking failed\n");

        return -1;

    }



    U = s->pic.data[1];

    V = s->pic.data[2];

    VAR_9     = s->scratch_buffer;

    src_end = VAR_9 + VAR_13;

    if (VAR_11) {

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

            for (VAR_7 = 0; VAR_7 < VAR_0->width >> 1; VAR_7++) {

                VAR_4 = *VAR_9++;

                if (VAR_4) {

                    VAR_4  = AV_RL16(VAR_10 + (VAR_4 << 1));

                    VAR_5 = (VAR_4 >> 3) & 0xF8;

                    VAR_6 = (VAR_4 >> 8) & 0xF8;

                    U[VAR_7] = VAR_5 | (VAR_5 >> 5);

                    V[VAR_7] = VAR_6 | (VAR_6 >> 5);

                }

                if (VAR_9 == src_end)

                    return 0;

            }

            U += s->pic.linesize[1];

            V += s->pic.linesize[2];

        }

    } else {

        uint8_t *U2 = U + s->pic.linesize[1];

        uint8_t *V2 = V + s->pic.linesize[2];



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

            for (VAR_7 = 0; VAR_7 < VAR_0->width >> 1; VAR_7 += 2) {

                VAR_4 = *VAR_9++;

                if (VAR_4) {

                    VAR_4  = AV_RL16(VAR_10 + (VAR_4 << 1));

                    VAR_5 = (VAR_4 >> 3) & 0xF8;

                    VAR_6 = (VAR_4 >> 8) & 0xF8;

                    U[VAR_7] = U[VAR_7+1] = U2[VAR_7] = U2[VAR_7+1] = VAR_5 | (VAR_5 >> 5);

                    V[VAR_7] = V[VAR_7+1] = V2[VAR_7] = V2[VAR_7+1] = VAR_6 | (VAR_6 >> 5);

                }

            }

            U  += s->pic.linesize[1] * 2;

            V  += s->pic.linesize[2] * 2;

            U2 += s->pic.linesize[1] * 2;

            V2 += s->pic.linesize[2] * 2;

        }

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1)
{ const uint8_t *VAR_2 = VAR_1->data; XanContext *s = VAR_0->priv_data; uint8_t *U, *V; unsigned VAR_3; int VAR_4, VAR_5, VAR_6; int VAR_7, VAR_8; const uint8_t *VAR_9, *src_end; const uint8_t *VAR_10; int VAR_11, VAR_12, VAR_13; VAR_3 = AV_RL32(VAR_2 + 4); if (!VAR_3)
return 0; if (VAR_3 + 10 >= VAR_1->size) { av_log(VAR_0, AV_LOG_ERROR, "Invalid chroma block position\n"); return -1; } VAR_9    = VAR_1->data + 4 + VAR_3; VAR_10  = VAR_9 + 2; VAR_11   = bytestream_get_le16(&VAR_9); VAR_12 = bytestream_get_le16(&VAR_9) * 2; if (VAR_9 - VAR_1->data >= VAR_1->size - VAR_12) { av_log(VAR_0, AV_LOG_ERROR, "Invalid chroma block VAR_12\n"); return -1; } memset(s->scratch_buffer, 0, s->buffer_size); VAR_13 = xan_unpack(s->scratch_buffer, s->buffer_size, VAR_9 + VAR_12,
VAR_1->size - VAR_12 - (VAR_9 - VAR_1->data)); if (VAR_13 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Chroma unpacking failed\n"); return -1; } U = s->pic.data[1]; V = s->pic.data[2]; VAR_9     = s->scratch_buffer; src_end = VAR_9 + VAR_13; if (VAR_11) { for (VAR_8 = 0; VAR_8 < VAR_0->height >> 1; VAR_8++) { for (VAR_7 = 0; VAR_7 < VAR_0->width >> 1; VAR_7++) { VAR_4 = *VAR_9++; if (VAR_4) { VAR_4  = AV_RL16(VAR_10 + (VAR_4 << 1)); VAR_5 = (VAR_4 >> 3) & 0xF8; VAR_6 = (VAR_4 >> 8) & 0xF8; U[VAR_7] = VAR_5 | (VAR_5 >> 5); V[VAR_7] = VAR_6 | (VAR_6 >> 5); } if (VAR_9 == src_end)
return 0; } U += s->pic.linesize[1]; V += s->pic.linesize[2]; } } else { uint8_t *U2 = U + s->pic.linesize[1]; uint8_t *V2 = V + s->pic.linesize[2]; for (VAR_8 = 0; VAR_8 < VAR_0->height >> 2; VAR_8++) { for (VAR_7 = 0; VAR_7 < VAR_0->width >> 1; VAR_7 += 2) { VAR_4 = *VAR_9++; if (VAR_4) { VAR_4  = AV_RL16(VAR_10 + (VAR_4 << 1)); VAR_5 = (VAR_4 >> 3) & 0xF8; VAR_6 = (VAR_4 >> 8) & 0xF8; U[VAR_7] = U[VAR_7+1] = U2[VAR_7] = U2[VAR_7+1] = VAR_5 | (VAR_5 >> 5); V[VAR_7] = V[VAR_7+1] = V2[VAR_7] = V2[VAR_7+1] = VAR_6 | (VAR_6 >> 5); } } U  += s->pic.linesize[1] * 2; V  += s->pic.linesize[2] * 2; U2 += s->pic.linesize[1] * 2; V2 += s->pic.linesize[2] * 2; } } return 0; }