static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst,

                            int pitch, const uint8_t *table)

{

    int i;

    int j;

    int out = 0;



    if (width & 1)

        return AVERROR_INVALIDDATA;



    /* first line contain absolute values, other lines contain deltas */

    while (out < width) {

        int c = ir2_get_code(&ctx->gb);

        if (c >= 0x80) { /* we have a run */

            c -= 0x7F;

            if (out + c*2 > width)

                return AVERROR_INVALIDDATA;

            for (i = 0; i < c * 2; i++)

                dst[out++] = 0x80;

        } else { /* copy two values from table */

            dst[out++] = table[c * 2];

            dst[out++] = table[(c * 2) + 1];

        }

    }

    dst += pitch;



    for (j = 1; j < height; j++) {

        out = 0;

        if (get_bits_left(&ctx->gb) <= 0)

            return AVERROR_INVALIDDATA;

        while (out < width) {

            int c = ir2_get_code(&ctx->gb);

            if (c >= 0x80) { /* we have a skip */

                c -= 0x7F;

                if (out + c*2 > width)

                    return AVERROR_INVALIDDATA;

                for (i = 0; i < c * 2; i++) {

                    dst[out] = dst[out - pitch];

                    out++;

                }

            } else { /* add two deltas from table */

                int t    = dst[out - pitch] + (table[c * 2] - 128);

                t        = av_clip_uint8(t);

                dst[out] = t;

                out++;

                t        = dst[out - pitch] + (table[(c * 2) + 1] - 128);

                t        = av_clip_uint8(t);

                dst[out] = t;

                out++;

            }

        }

        dst += pitch;

    }

    return 0;

}

static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst,

                            int pitch, const uint8_t *table)

{

    int i;

    int j;

    int out = 0;



    if (width & 1)

        return AVERROR_INVALIDDATA;



    

    while (out < width) {

        int c = ir2_get_code(&ctx->gb);

        if (c >= 0x80) { 

            c -= 0x7F;

            if (out + c*2 > width)

                return AVERROR_INVALIDDATA;

            for (i = 0; i < c * 2; i++)

                dst[out++] = 0x80;

        } else { 

            dst[out++] = table[c * 2];

            dst[out++] = table[(c * 2) + 1];

        }

    }

    dst += pitch;



    for (j = 1; j < height; j++) {

        out = 0;

        if (get_bits_left(&ctx->gb) <= 0)

            return AVERROR_INVALIDDATA;

        while (out < width) {

            int c = ir2_get_code(&ctx->gb);

            if (c >= 0x80) { 

                c -= 0x7F;

                if (out + c*2 > width)

                    return AVERROR_INVALIDDATA;

                for (i = 0; i < c * 2; i++) {

                    dst[out] = dst[out - pitch];

                    out++;

                }

            } else { 

                int t    = dst[out - pitch] + (table[c * 2] - 128);

                t        = av_clip_uint8(t);

                dst[out] = t;

                out++;

                t        = dst[out - pitch] + (table[(c * 2) + 1] - 128);

                t        = av_clip_uint8(t);

                dst[out] = t;

                out++;

            }

        }

        dst += pitch;

    }

    return 0;

}

                int t    = dst[out - pitch] + (table[c * 2] - 128);
static int FUNC_0(Ir2Context *VAR_0, int VAR_1, int VAR_2, uint8_t *VAR_3,

                            int VAR_4, const uint8_t *VAR_5)

{

    int VAR_6;

    int VAR_7;

    int VAR_8 = 0;



    if (VAR_1 & 1)

        return AVERROR_INVALIDDATA;



    

    while (VAR_8 < VAR_1) {

        int VAR_10 = ir2_get_code(&VAR_0->gb);

        if (VAR_10 >= 0x80) { 

            VAR_10 -= 0x7F;

            if (VAR_8 + VAR_10*2 > VAR_1)

                return AVERROR_INVALIDDATA;

            for (VAR_6 = 0; VAR_6 < VAR_10 * 2; VAR_6++)

                VAR_3[VAR_8++] = 0x80;

        } else { 

            VAR_3[VAR_8++] = VAR_5[VAR_10 * 2];

            VAR_3[VAR_8++] = VAR_5[(VAR_10 * 2) + 1];

        }

    }

    VAR_3 += VAR_4;



    for (VAR_7 = 1; VAR_7 < VAR_2; VAR_7++) {

        VAR_8 = 0;

        if (get_bits_left(&VAR_0->gb) <= 0)

            return AVERROR_INVALIDDATA;

        while (VAR_8 < VAR_1) {

            int VAR_10 = ir2_get_code(&VAR_0->gb);

            if (VAR_10 >= 0x80) { 

                VAR_10 -= 0x7F;

                if (VAR_8 + VAR_10*2 > VAR_1)

                    return AVERROR_INVALIDDATA;

                for (VAR_6 = 0; VAR_6 < VAR_10 * 2; VAR_6++) {

                    VAR_3[VAR_8] = VAR_3[VAR_8 - VAR_4];

                    VAR_8++;

                }

            } else { 

                int VAR_10    = VAR_3[VAR_8 - VAR_4] + (VAR_5[VAR_10 * 2] - 128);

                VAR_10        = av_clip_uint8(VAR_10);

                VAR_3[VAR_8] = VAR_10;

                VAR_8++;

                VAR_10        = VAR_3[VAR_8 - VAR_4] + (VAR_5[(VAR_10 * 2) + 1] - 128);

                VAR_10        = av_clip_uint8(VAR_10);

                VAR_3[VAR_8] = VAR_10;

                VAR_8++;

            }

        }

        VAR_3 += VAR_4;

    }

    return 0;

}

static int FUNC_0(Ir2Context *VAR_0, int VAR_1, int VAR_2, uint8_t *VAR_3,
int VAR_4, const uint8_t *VAR_5)
{ int VAR_6; int VAR_7; int VAR_8 = 0; if (VAR_1 & 1)
return AVERROR_INVALIDDATA; while (VAR_8 < VAR_1) { int VAR_10 = ir2_get_code(&VAR_0->gb); if (VAR_10 >= 0x80) { VAR_10 -= 0x7F; if (VAR_8 + VAR_10*2 > VAR_1)
return AVERROR_INVALIDDATA; for (VAR_6 = 0; VAR_6 < VAR_10 * 2; VAR_6++) VAR_3[VAR_8++] = 0x80; } else { VAR_3[VAR_8++] = VAR_5[VAR_10 * 2]; VAR_3[VAR_8++] = VAR_5[(VAR_10 * 2) + 1]; } } VAR_3 += VAR_4; for (VAR_7 = 1; VAR_7 < VAR_2; VAR_7++) { VAR_8 = 0; if (get_bits_left(&VAR_0->gb) <= 0)
return AVERROR_INVALIDDATA; while (VAR_8 < VAR_1) { int VAR_10 = ir2_get_code(&VAR_0->gb); if (VAR_10 >= 0x80) { VAR_10 -= 0x7F; if (VAR_8 + VAR_10*2 > VAR_1)
return AVERROR_INVALIDDATA; for (VAR_6 = 0; VAR_6 < VAR_10 * 2; VAR_6++) { VAR_3[VAR_8] = VAR_3[VAR_8 - VAR_4]; VAR_8++; } } else { int VAR_10    = VAR_3[VAR_8 - VAR_4] + (VAR_5[VAR_10 * 2] - 128); VAR_10        = av_clip_uint8(VAR_10); VAR_3[VAR_8] = VAR_10; VAR_8++; VAR_10        = VAR_3[VAR_8 - VAR_4] + (VAR_5[(VAR_10 * 2) + 1] - 128); VAR_10        = av_clip_uint8(VAR_10); VAR_3[VAR_8] = VAR_10; VAR_8++; } } VAR_3 += VAR_4; } return 0; }