static int xan_decode_frame_type0(AVCodecContext *avctx)

{

    XanContext *s = avctx->priv_data;

    uint8_t *ybuf, *prev_buf, *src = s->scratch_buffer;

    unsigned  chroma_off, corr_off;

    int cur, last;

    int i, j;

    int ret;



    chroma_off = bytestream2_get_le32(&s->gb);

    corr_off   = bytestream2_get_le32(&s->gb);



    if ((ret = xan_decode_chroma(avctx, chroma_off)) != 0)

        return ret;



    if (corr_off >= (s->gb.buffer_end - s->gb.buffer_start)) {

        av_log(avctx, AV_LOG_WARNING, "Ignoring invalid correction block position\n");

        corr_off = 0;

    }

    bytestream2_seek(&s->gb, 12, SEEK_SET);

    ret = xan_unpack_luma(s, src, s->buffer_size >> 1);

    if (ret) {

        av_log(avctx, AV_LOG_ERROR, "Luma decoding failed\n");

        return ret;

    }



    ybuf = s->y_buffer;

    last = *src++;

    ybuf[0] = last << 1;

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

        cur = (last + *src++) & 0x1F;

        ybuf[j]   = last + cur;

        ybuf[j+1] = cur << 1;

        last = cur;

    }

    ybuf[j]  = last << 1;

    prev_buf = ybuf;

    ybuf += avctx->width;



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

        last = ((prev_buf[0] >> 1) + *src++) & 0x1F;

        ybuf[0] = last << 1;

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

            cur = ((prev_buf[j + 1] >> 1) + *src++) & 0x1F;

            ybuf[j]   = last + cur;

            ybuf[j+1] = cur << 1;

            last = cur;

        }

        ybuf[j] = last << 1;

        prev_buf = ybuf;

        ybuf += avctx->width;

    }



    if (corr_off) {

        int dec_size;



        bytestream2_seek(&s->gb, 8 + corr_off, SEEK_SET);

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

        if (dec_size < 0)

            dec_size = 0;

        for (i = 0; i < dec_size; i++)

            s->y_buffer[i*2+1] = (s->y_buffer[i*2+1] + (s->scratch_buffer[i] << 1)) & 0x3F;

    }



    src  = s->y_buffer;

    ybuf = s->pic.data[0];

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

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

            ybuf[i] = (src[i] << 2) | (src[i] >> 3);

        src  += avctx->width;

        ybuf += s->pic.linesize[0];

    }



    return 0;

}

static int xan_decode_frame_type0(AVCodecContext *avctx)

{

    XanContext *s = avctx->priv_data;

    uint8_t *ybuf, *prev_buf, *src = s->scratch_buffer;

    unsigned  chroma_off, corr_off;

    int cur, last;

    int i, j;

    int ret;



    chroma_off = bytestream2_get_le32(&s->gb);

    corr_off   = bytestream2_get_le32(&s->gb);



    if ((ret = xan_decode_chroma(avctx, chroma_off)) != 0)

        return ret;



    if (corr_off >= (s->gb.buffer_end - s->gb.buffer_start)) {

        av_log(avctx, AV_LOG_WARNING, "Ignoring invalid correction block position\n");

        corr_off = 0;

    }

    bytestream2_seek(&s->gb, 12, SEEK_SET);

    ret = xan_unpack_luma(s, src, s->buffer_size >> 1);

    if (ret) {

        av_log(avctx, AV_LOG_ERROR, "Luma decoding failed\n");

        return ret;

    }



    ybuf = s->y_buffer;

    last = *src++;

    ybuf[0] = last << 1;

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

        cur = (last + *src++) & 0x1F;

        ybuf[j]   = last + cur;

        ybuf[j+1] = cur << 1;

        last = cur;

    }

    ybuf[j]  = last << 1;

    prev_buf = ybuf;

    ybuf += avctx->width;



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

        last = ((prev_buf[0] >> 1) + *src++) & 0x1F;

        ybuf[0] = last << 1;

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

            cur = ((prev_buf[j + 1] >> 1) + *src++) & 0x1F;

            ybuf[j]   = last + cur;

            ybuf[j+1] = cur << 1;

            last = cur;

        }

        ybuf[j] = last << 1;

        prev_buf = ybuf;

        ybuf += avctx->width;

    }



    if (corr_off) {

        int dec_size;



        bytestream2_seek(&s->gb, 8 + corr_off, SEEK_SET);

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

        if (dec_size < 0)

            dec_size = 0;

        for (i = 0; i < dec_size; i++)

            s->y_buffer[i*2+1] = (s->y_buffer[i*2+1] + (s->scratch_buffer[i] << 1)) & 0x3F;

    }



    src  = s->y_buffer;

    ybuf = s->pic.data[0];

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

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

            ybuf[i] = (src[i] << 2) | (src[i] >> 3);

        src  += avctx->width;

        ybuf += s->pic.linesize[0];

    }



    return 0;

}

        dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size);
static int FUNC_0(AVCodecContext *VAR_0)

{

    XanContext *s = VAR_0->priv_data;

    uint8_t *ybuf, *prev_buf, *src = s->scratch_buffer;

    unsigned  VAR_1, VAR_2;

    int VAR_3, VAR_4;

    int VAR_5, VAR_6;

    int VAR_7;



    VAR_1 = bytestream2_get_le32(&s->gb);

    VAR_2   = bytestream2_get_le32(&s->gb);



    if ((VAR_7 = xan_decode_chroma(VAR_0, VAR_1)) != 0)

        return VAR_7;



    if (VAR_2 >= (s->gb.buffer_end - s->gb.buffer_start)) {

        av_log(VAR_0, AV_LOG_WARNING, "Ignoring invalid correction block position\n");

        VAR_2 = 0;

    }

    bytestream2_seek(&s->gb, 12, SEEK_SET);

    VAR_7 = xan_unpack_luma(s, src, s->buffer_size >> 1);

    if (VAR_7) {

        av_log(VAR_0, AV_LOG_ERROR, "Luma decoding failed\n");

        return VAR_7;

    }



    ybuf = s->y_buffer;

    VAR_4 = *src++;

    ybuf[0] = VAR_4 << 1;

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

        VAR_3 = (VAR_4 + *src++) & 0x1F;

        ybuf[VAR_6]   = VAR_4 + VAR_3;

        ybuf[VAR_6+1] = VAR_3 << 1;

        VAR_4 = VAR_3;

    }

    ybuf[VAR_6]  = VAR_4 << 1;

    prev_buf = ybuf;

    ybuf += VAR_0->width;



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

        VAR_4 = ((prev_buf[0] >> 1) + *src++) & 0x1F;

        ybuf[0] = VAR_4 << 1;

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

            VAR_3 = ((prev_buf[VAR_6 + 1] >> 1) + *src++) & 0x1F;

            ybuf[VAR_6]   = VAR_4 + VAR_3;

            ybuf[VAR_6+1] = VAR_3 << 1;

            VAR_4 = VAR_3;

        }

        ybuf[VAR_6] = VAR_4 << 1;

        prev_buf = ybuf;

        ybuf += VAR_0->width;

    }



    if (VAR_2) {

        int VAR_8;



        bytestream2_seek(&s->gb, 8 + VAR_2, SEEK_SET);

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

        if (VAR_8 < 0)

            VAR_8 = 0;

        for (VAR_5 = 0; VAR_5 < VAR_8; VAR_5++)

            s->y_buffer[VAR_5*2+1] = (s->y_buffer[VAR_5*2+1] + (s->scratch_buffer[VAR_5] << 1)) & 0x3F;

    }



    src  = s->y_buffer;

    ybuf = s->pic.data[0];

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

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

            ybuf[VAR_5] = (src[VAR_5] << 2) | (src[VAR_5] >> 3);

        src  += VAR_0->width;

        ybuf += s->pic.linesize[0];

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0)
{ XanContext *s = VAR_0->priv_data; uint8_t *ybuf, *prev_buf, *src = s->scratch_buffer; unsigned  VAR_1, VAR_2; int VAR_3, VAR_4; int VAR_5, VAR_6; int VAR_7; VAR_1 = bytestream2_get_le32(&s->gb); VAR_2   = bytestream2_get_le32(&s->gb); if ((VAR_7 = xan_decode_chroma(VAR_0, VAR_1)) != 0)
return VAR_7; if (VAR_2 >= (s->gb.buffer_end - s->gb.buffer_start)) { av_log(VAR_0, AV_LOG_WARNING, "Ignoring invalid correction block position\n"); VAR_2 = 0; } bytestream2_seek(&s->gb, 12, SEEK_SET); VAR_7 = xan_unpack_luma(s, src, s->buffer_size >> 1); if (VAR_7) { av_log(VAR_0, AV_LOG_ERROR, "Luma decoding failed\n"); return VAR_7; } ybuf = s->y_buffer; VAR_4 = *src++; ybuf[0] = VAR_4 << 1; for (VAR_6 = 1; VAR_6 < VAR_0->width - 1; VAR_6 += 2) { VAR_3 = (VAR_4 + *src++) & 0x1F; ybuf[VAR_6]   = VAR_4 + VAR_3; ybuf[VAR_6+1] = VAR_3 << 1; VAR_4 = VAR_3; } ybuf[VAR_6]  = VAR_4 << 1; prev_buf = ybuf; ybuf += VAR_0->width; for (VAR_5 = 1; VAR_5 < VAR_0->height; VAR_5++) { VAR_4 = ((prev_buf[0] >> 1) + *src++) & 0x1F; ybuf[0] = VAR_4 << 1; for (VAR_6 = 1; VAR_6 < VAR_0->width - 1; VAR_6 += 2) { VAR_3 = ((prev_buf[VAR_6 + 1] >> 1) + *src++) & 0x1F; ybuf[VAR_6]   = VAR_4 + VAR_3; ybuf[VAR_6+1] = VAR_3 << 1; VAR_4 = VAR_3; } ybuf[VAR_6] = VAR_4 << 1; prev_buf = ybuf; ybuf += VAR_0->width; } if (VAR_2) { int VAR_8; bytestream2_seek(&s->gb, 8 + VAR_2, SEEK_SET); VAR_8 = xan_unpack(s, s->scratch_buffer, s->buffer_size); if (VAR_8 < 0)
VAR_8 = 0; for (VAR_5 = 0; VAR_5 < VAR_8; VAR_5++) s->y_buffer[VAR_5*2+1] = (s->y_buffer[VAR_5*2+1] + (s->scratch_buffer[VAR_5] << 1)) & 0x3F; } src  = s->y_buffer; ybuf = s->pic.data[0]; for (VAR_6 = 0; VAR_6 < VAR_0->height; VAR_6++) { for (VAR_5 = 0; VAR_5 < VAR_0->width; VAR_5++) ybuf[VAR_5] = (src[VAR_5] << 2) | (src[VAR_5] >> 3); src  += VAR_0->width; ybuf += s->pic.linesize[0]; } return 0; }