static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)

{

    XanContext *s = avctx->priv_data;

    uint8_t *U, *V;

    int val, uval, vval;

    int i, j;

    const uint8_t *src, *src_end;

    const uint8_t *table;

    int mode, offset, dec_size;



    if (!chroma_off)

        return 0;

    if (chroma_off + 4 >= bytestream2_get_bytes_left(&s->gb)) {

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

        return -1;

    }

    bytestream2_seek(&s->gb, chroma_off + 4, SEEK_SET);

    mode   = bytestream2_get_le16(&s->gb);

    table  = s->gb.buffer;

    offset = bytestream2_get_le16(&s->gb) * 2;



    if (offset >= bytestream2_get_bytes_left(&s->gb)) {

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

        return -1;

    }



    bytestream2_skip(&s->gb, offset);

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

    dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size);

    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, unsigned chroma_off)

{

    XanContext *s = avctx->priv_data;

    uint8_t *U, *V;

    int val, uval, vval;

    int i, j;

    const uint8_t *src, *src_end;

    const uint8_t *table;

    int mode, offset, dec_size;



    if (!chroma_off)

        return 0;

    if (chroma_off + 4 >= bytestream2_get_bytes_left(&s->gb)) {

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

        return -1;

    }

    bytestream2_seek(&s->gb, chroma_off + 4, SEEK_SET);

    mode   = bytestream2_get_le16(&s->gb);

    table  = s->gb.buffer;

    offset = bytestream2_get_le16(&s->gb) * 2;



    if (offset >= bytestream2_get_bytes_left(&s->gb)) {

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

        return -1;

    }



    bytestream2_skip(&s->gb, offset);

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

    dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size);

    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;

}

    int mode, offset, dec_size;     mode   = bytestream2_get_le16(&s->gb);     table  = s->gb.buffer;     offset = bytestream2_get_le16(&s->gb) * 2;                 if (val) {                 if (val) {
static int FUNC_0(AVCodecContext *VAR_0, unsigned VAR_1)

{

    XanContext *s = VAR_0->priv_data;

    uint8_t *U, *V;

    int VAR_2, VAR_3, VAR_4;

    int VAR_5, VAR_6;

    const uint8_t *VAR_7, *src_end;

    const uint8_t *VAR_8;

    int VAR_9, VAR_10, VAR_11;



    if (!VAR_1)

        return 0;

    if (VAR_1 + 4 >= bytestream2_get_bytes_left(&s->gb)) {

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

        return -1;

    }

    bytestream2_seek(&s->gb, VAR_1 + 4, SEEK_SET);

    VAR_9   = bytestream2_get_le16(&s->gb);

    VAR_8  = s->gb.buffer;

    VAR_10 = bytestream2_get_le16(&s->gb) * 2;



    if (VAR_10 >= bytestream2_get_bytes_left(&s->gb)) {

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

        return -1;

    }



    bytestream2_skip(&s->gb, VAR_10);

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

    VAR_11 = xan_unpack(s, s->scratch_buffer, s->buffer_size);

    if (VAR_11 < 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_7     = s->scratch_buffer;

    src_end = VAR_7 + VAR_11;

    if (VAR_9) {

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

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

                VAR_2 = *VAR_7++;

                if (VAR_2) {

                    VAR_2  = AV_RL16(VAR_8 + (VAR_2 << 1));

                    VAR_3 = (VAR_2 >> 3) & 0xF8;

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

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

                    V[VAR_5] = VAR_4 | (VAR_4 >> 5);

                }

                if (VAR_7 == 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_6 = 0; VAR_6 < VAR_0->height >> 2; VAR_6++) {

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

                VAR_2 = *VAR_7++;

                if (VAR_2) {

                    VAR_2  = AV_RL16(VAR_8 + (VAR_2 << 1));

                    VAR_3 = (VAR_2 >> 3) & 0xF8;

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

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

                    V[VAR_5] = V[VAR_5+1] = V2[VAR_5] = V2[VAR_5+1] = VAR_4 | (VAR_4 >> 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, unsigned VAR_1)
{ XanContext *s = VAR_0->priv_data; uint8_t *U, *V; int VAR_2, VAR_3, VAR_4; int VAR_5, VAR_6; const uint8_t *VAR_7, *src_end; const uint8_t *VAR_8; int VAR_9, VAR_10, VAR_11; if (!VAR_1)
return 0; if (VAR_1 + 4 >= bytestream2_get_bytes_left(&s->gb)) { av_log(VAR_0, AV_LOG_ERROR, "Invalid chroma block position\n"); return -1; } bytestream2_seek(&s->gb, VAR_1 + 4, SEEK_SET); VAR_9   = bytestream2_get_le16(&s->gb); VAR_8  = s->gb.buffer; VAR_10 = bytestream2_get_le16(&s->gb) * 2; if (VAR_10 >= bytestream2_get_bytes_left(&s->gb)) { av_log(VAR_0, AV_LOG_ERROR, "Invalid chroma block VAR_10\n"); return -1; } bytestream2_skip(&s->gb, VAR_10); memset(s->scratch_buffer, 0, s->buffer_size); VAR_11 = xan_unpack(s, s->scratch_buffer, s->buffer_size); if (VAR_11 < 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_7     = s->scratch_buffer; src_end = VAR_7 + VAR_11; if (VAR_9) { for (VAR_6 = 0; VAR_6 < VAR_0->height >> 1; VAR_6++) { for (VAR_5 = 0; VAR_5 < VAR_0->width >> 1; VAR_5++) { VAR_2 = *VAR_7++; if (VAR_2) { VAR_2  = AV_RL16(VAR_8 + (VAR_2 << 1)); VAR_3 = (VAR_2 >> 3) & 0xF8; VAR_4 = (VAR_2 >> 8) & 0xF8; U[VAR_5] = VAR_3 | (VAR_3 >> 5); V[VAR_5] = VAR_4 | (VAR_4 >> 5); } if (VAR_7 == 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_6 = 0; VAR_6 < VAR_0->height >> 2; VAR_6++) { for (VAR_5 = 0; VAR_5 < VAR_0->width >> 1; VAR_5 += 2) { VAR_2 = *VAR_7++; if (VAR_2) { VAR_2  = AV_RL16(VAR_8 + (VAR_2 << 1)); VAR_3 = (VAR_2 >> 3) & 0xF8; VAR_4 = (VAR_2 >> 8) & 0xF8; U[VAR_5] = U[VAR_5+1] = U2[VAR_5] = U2[VAR_5+1] = VAR_3 | (VAR_3 >> 5); V[VAR_5] = V[VAR_5+1] = V2[VAR_5] = V2[VAR_5+1] = VAR_4 | (VAR_4 >> 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; }