static int decompress_p(AVCodecContext *avctx,

                        uint32_t *dst, int linesize,

                        uint32_t *prev, int plinesize)

{

    SCPRContext *s = avctx->priv_data;

    GetByteContext *gb = &s->gb;

    int ret, temp, min, max, x, y, cx = 0, cx1 = 0;

    int backstep = linesize - avctx->width;

    const int cxshift = s->cxshift;



    if (bytestream2_get_byte(gb) == 0)

        return 0;

    bytestream2_skip(gb, 1);

    init_rangecoder(&s->rc, gb);



    ret  = decode_value(s, s->range_model, 256, 1, &min);

    ret |= decode_value(s, s->range_model, 256, 1, &temp);

    min += temp << 8;

    ret |= decode_value(s, s->range_model, 256, 1, &max);

    ret |= decode_value(s, s->range_model, 256, 1, &temp);

    if (ret < 0)

        return ret;



    max += temp << 8;

    memset(s->blocks, 0, sizeof(*s->blocks) * s->nbcount);



    while (min <= max) {

        int fill, count;



        ret  = decode_value(s, s->fill_model,  5,   10, &fill);

        ret |= decode_value(s, s->count_model, 256, 20, &count);

        if (ret < 0)

            return ret;



        while (min < s->nbcount && count-- > 0) {

            s->blocks[min++] = fill;

        }

    }



    for (y = 0; y < s->nby; y++) {

        for (x = 0; x < s->nbx; x++) {

            int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;



            if (s->blocks[y * s->nbx + x] == 0)

                continue;



            if (((s->blocks[y * s->nbx + x] - 1) & 1) > 0) {

                ret  = decode_value(s, s->sxy_model[0], 16, 100, &sx1);

                ret |= decode_value(s, s->sxy_model[1], 16, 100, &sy1);

                ret |= decode_value(s, s->sxy_model[2], 16, 100, &sx2);

                ret |= decode_value(s, s->sxy_model[3], 16, 100, &sy2);

                if (ret < 0)

                    return ret;



                sx2++;

                sy2++;

            }

            if (((s->blocks[y * s->nbx + x] - 1) & 2) > 0) {

                int i, j, by = y * 16, bx = x * 16;

                int mvx, mvy;



                ret  = decode_value(s, s->mv_model[0], 512, 100, &mvx);

                ret |= decode_value(s, s->mv_model[1], 512, 100, &mvy);

                if (ret < 0)

                    return ret;



                mvx -= 256;

                mvy -= 256;



                if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||

                    by + mvy + sy1 >= avctx->height || bx + mvx + sx1 >= avctx->width)

                    return AVERROR_INVALIDDATA;



                for (i = 0; i < sy2 - sy1 && (by + sy1 + i) < avctx->height && (by + mvy + sy1 + i) < avctx->height; i++) {

                    for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->width && (bx + mvx + sx1 + j) < avctx->width; j++) {

                        dst[(by + i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j];

                    }

                }

            } else {

                int run, r, g, b, z, bx = x * 16 + sx1, by = y * 16 + sy1;

                unsigned clr, ptype = 0;



                for (; by < y * 16 + sy2 && by < avctx->height;) {

                    ret = decode_value(s, s->op_model[ptype], 6, 1000, &ptype);

                    if (ptype == 0) {

                        ret = decode_unit(s, &s->pixel_model[0][cx + cx1], 400, &r);

                        if (ret < 0)

                            return ret;



                        cx1 = (cx << 6) & 0xFC0;

                        cx = r >> cxshift;

                        ret = decode_unit(s, &s->pixel_model[1][cx + cx1], 400, &g);

                        if (ret < 0)

                            return ret;



                        cx1 = (cx << 6) & 0xFC0;

                        cx = g >> cxshift;

                        ret = decode_unit(s, &s->pixel_model[2][cx + cx1], 400, &b);

                        if (ret < 0)

                            return ret;



                        clr = (b << 16) + (g << 8) + r;

                    }

                    if (ptype > 5)

                        return AVERROR_INVALIDDATA;

                    ret = decode_value(s, s->run_model[ptype], 256, 400, &run);

                    if (ret < 0)

                        return ret;



                    switch (ptype) {

                    case 0:

                        while (run-- > 0) {

                            if (by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 1:

                        while (run-- > 0) {

                            if (bx == 0) {

                                if (by < 1)

                                    return AVERROR_INVALIDDATA;

                                z = backstep;

                            } else {

                                z = 0;

                            }



                            if (by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            clr = dst[by * linesize + bx - 1 - z];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 2:

                        while (run-- > 0) {

                            if (by < 1 || by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            clr = dst[(by - 1) * linesize + bx];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 3:

                        while (run-- > 0) {

                            if (by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            clr = prev[by * plinesize + bx];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 4:

                        while (run-- > 0) {

                            uint8_t *odst = (uint8_t *)dst;



                            if (by < 1 || by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            if (bx == 0) {

                                z = backstep;

                            } else {

                                z = 0;

                            }



                            r = odst[((by - 1) * linesize + bx) * 4] +

                                odst[(by * linesize + bx - 1 - z) * 4] -

                                odst[((by - 1) * linesize + bx - 1 - z) * 4];

                            g = odst[((by - 1) * linesize + bx) * 4 + 1] +

                                odst[(by * linesize + bx - 1 - z) * 4 + 1] -

                                odst[((by - 1) * linesize + bx - 1 - z) * 4 + 1];

                            b = odst[((by - 1) * linesize + bx) * 4 + 2] +

                                odst[(by * linesize + bx - 1 - z) * 4 + 2] -

                                odst[((by - 1) * linesize + bx - 1 - z) * 4 + 2];

                            clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF);

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 5:

                        while (run-- > 0) {

                            if (by < 1 || by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            if (bx == 0) {

                                z = backstep;

                            } else {

                                z = 0;

                            }



                            clr = dst[(by - 1) * linesize + bx - 1 - z];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    }



                    if (avctx->bits_per_coded_sample == 16) {

                        cx1 = (clr & 0x3F00) >> 2;

                        cx = (clr & 0xFFFFFF) >> 16;

                    } else {

                        cx1 = (clr & 0xFC00) >> 4;

                        cx = (clr & 0xFFFFFF) >> 18;

                    }

                }

            }

        }

    }



    return 0;

}

static int decompress_p(AVCodecContext *avctx,

                        uint32_t *dst, int linesize,

                        uint32_t *prev, int plinesize)

{

    SCPRContext *s = avctx->priv_data;

    GetByteContext *gb = &s->gb;

    int ret, temp, min, max, x, y, cx = 0, cx1 = 0;

    int backstep = linesize - avctx->width;

    const int cxshift = s->cxshift;



    if (bytestream2_get_byte(gb) == 0)

        return 0;

    bytestream2_skip(gb, 1);

    init_rangecoder(&s->rc, gb);



    ret  = decode_value(s, s->range_model, 256, 1, &min);

    ret |= decode_value(s, s->range_model, 256, 1, &temp);

    min += temp << 8;

    ret |= decode_value(s, s->range_model, 256, 1, &max);

    ret |= decode_value(s, s->range_model, 256, 1, &temp);

    if (ret < 0)

        return ret;



    max += temp << 8;

    memset(s->blocks, 0, sizeof(*s->blocks) * s->nbcount);



    while (min <= max) {

        int fill, count;



        ret  = decode_value(s, s->fill_model,  5,   10, &fill);

        ret |= decode_value(s, s->count_model, 256, 20, &count);

        if (ret < 0)

            return ret;



        while (min < s->nbcount && count-- > 0) {

            s->blocks[min++] = fill;

        }

    }



    for (y = 0; y < s->nby; y++) {

        for (x = 0; x < s->nbx; x++) {

            int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;



            if (s->blocks[y * s->nbx + x] == 0)

                continue;



            if (((s->blocks[y * s->nbx + x] - 1) & 1) > 0) {

                ret  = decode_value(s, s->sxy_model[0], 16, 100, &sx1);

                ret |= decode_value(s, s->sxy_model[1], 16, 100, &sy1);

                ret |= decode_value(s, s->sxy_model[2], 16, 100, &sx2);

                ret |= decode_value(s, s->sxy_model[3], 16, 100, &sy2);

                if (ret < 0)

                    return ret;



                sx2++;

                sy2++;

            }

            if (((s->blocks[y * s->nbx + x] - 1) & 2) > 0) {

                int i, j, by = y * 16, bx = x * 16;

                int mvx, mvy;



                ret  = decode_value(s, s->mv_model[0], 512, 100, &mvx);

                ret |= decode_value(s, s->mv_model[1], 512, 100, &mvy);

                if (ret < 0)

                    return ret;



                mvx -= 256;

                mvy -= 256;



                if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||

                    by + mvy + sy1 >= avctx->height || bx + mvx + sx1 >= avctx->width)

                    return AVERROR_INVALIDDATA;



                for (i = 0; i < sy2 - sy1 && (by + sy1 + i) < avctx->height && (by + mvy + sy1 + i) < avctx->height; i++) {

                    for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->width && (bx + mvx + sx1 + j) < avctx->width; j++) {

                        dst[(by + i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j];

                    }

                }

            } else {

                int run, r, g, b, z, bx = x * 16 + sx1, by = y * 16 + sy1;

                unsigned clr, ptype = 0;



                for (; by < y * 16 + sy2 && by < avctx->height;) {

                    ret = decode_value(s, s->op_model[ptype], 6, 1000, &ptype);

                    if (ptype == 0) {

                        ret = decode_unit(s, &s->pixel_model[0][cx + cx1], 400, &r);

                        if (ret < 0)

                            return ret;



                        cx1 = (cx << 6) & 0xFC0;

                        cx = r >> cxshift;

                        ret = decode_unit(s, &s->pixel_model[1][cx + cx1], 400, &g);

                        if (ret < 0)

                            return ret;



                        cx1 = (cx << 6) & 0xFC0;

                        cx = g >> cxshift;

                        ret = decode_unit(s, &s->pixel_model[2][cx + cx1], 400, &b);

                        if (ret < 0)

                            return ret;



                        clr = (b << 16) + (g << 8) + r;

                    }

                    if (ptype > 5)

                        return AVERROR_INVALIDDATA;

                    ret = decode_value(s, s->run_model[ptype], 256, 400, &run);

                    if (ret < 0)

                        return ret;



                    switch (ptype) {

                    case 0:

                        while (run-- > 0) {

                            if (by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 1:

                        while (run-- > 0) {

                            if (bx == 0) {

                                if (by < 1)

                                    return AVERROR_INVALIDDATA;

                                z = backstep;

                            } else {

                                z = 0;

                            }



                            if (by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            clr = dst[by * linesize + bx - 1 - z];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 2:

                        while (run-- > 0) {

                            if (by < 1 || by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            clr = dst[(by - 1) * linesize + bx];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 3:

                        while (run-- > 0) {

                            if (by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            clr = prev[by * plinesize + bx];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 4:

                        while (run-- > 0) {

                            uint8_t *odst = (uint8_t *)dst;



                            if (by < 1 || by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            if (bx == 0) {

                                z = backstep;

                            } else {

                                z = 0;

                            }



                            r = odst[((by - 1) * linesize + bx) * 4] +

                                odst[(by * linesize + bx - 1 - z) * 4] -

                                odst[((by - 1) * linesize + bx - 1 - z) * 4];

                            g = odst[((by - 1) * linesize + bx) * 4 + 1] +

                                odst[(by * linesize + bx - 1 - z) * 4 + 1] -

                                odst[((by - 1) * linesize + bx - 1 - z) * 4 + 1];

                            b = odst[((by - 1) * linesize + bx) * 4 + 2] +

                                odst[(by * linesize + bx - 1 - z) * 4 + 2] -

                                odst[((by - 1) * linesize + bx - 1 - z) * 4 + 2];

                            clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF);

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 5:

                        while (run-- > 0) {

                            if (by < 1 || by >= avctx->height)

                                return AVERROR_INVALIDDATA;



                            if (bx == 0) {

                                z = backstep;

                            } else {

                                z = 0;

                            }



                            clr = dst[(by - 1) * linesize + bx - 1 - z];

                            dst[by * linesize + bx] = clr;

                            bx++;

                            if (bx >= x * 16 + sx2 || bx >= avctx->width) {

                                bx = x * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    }



                    if (avctx->bits_per_coded_sample == 16) {

                        cx1 = (clr & 0x3F00) >> 2;

                        cx = (clr & 0xFFFFFF) >> 16;

                    } else {

                        cx1 = (clr & 0xFC00) >> 4;

                        cx = (clr & 0xFFFFFF) >> 18;

                    }

                }

            }

        }

    }



    return 0;

}

                        cx = (clr & 0xFFFFFF) >> 16;
static int FUNC_0(AVCodecContext *VAR_0,

                        uint32_t *VAR_1, int VAR_2,

                        uint32_t *VAR_3, int VAR_4)

{

    SCPRContext *s = VAR_0->priv_data;

    GetByteContext *gb = &s->gb;

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11 = 0, VAR_12 = 0;

    int VAR_13 = VAR_2 - VAR_0->width;

    const int VAR_14 = s->VAR_14;



    if (bytestream2_get_byte(gb) == 0)

        return 0;

    bytestream2_skip(gb, 1);

    init_rangecoder(&s->rc, gb);



    VAR_5  = decode_value(s, s->range_model, 256, 1, &VAR_7);

    VAR_5 |= decode_value(s, s->range_model, 256, 1, &VAR_6);

    VAR_7 += VAR_6 << 8;

    VAR_5 |= decode_value(s, s->range_model, 256, 1, &VAR_8);

    VAR_5 |= decode_value(s, s->range_model, 256, 1, &VAR_6);

    if (VAR_5 < 0)

        return VAR_5;



    VAR_8 += VAR_6 << 8;

    memset(s->blocks, 0, sizeof(*s->blocks) * s->nbcount);



    while (VAR_7 <= VAR_8) {

        int VAR_15, VAR_16;



        VAR_5  = decode_value(s, s->fill_model,  5,   10, &VAR_15);

        VAR_5 |= decode_value(s, s->count_model, 256, 20, &VAR_16);

        if (VAR_5 < 0)

            return VAR_5;



        while (VAR_7 < s->nbcount && VAR_16-- > 0) {

            s->blocks[VAR_7++] = VAR_15;

        }

    }



    for (VAR_10 = 0; VAR_10 < s->nby; VAR_10++) {

        for (VAR_9 = 0; VAR_9 < s->nbx; VAR_9++) {

            int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;



            if (s->blocks[VAR_10 * s->nbx + VAR_9] == 0)

                continue;



            if (((s->blocks[VAR_10 * s->nbx + VAR_9] - 1) & 1) > 0) {

                VAR_5  = decode_value(s, s->sxy_model[0], 16, 100, &sx1);

                VAR_5 |= decode_value(s, s->sxy_model[1], 16, 100, &sy1);

                VAR_5 |= decode_value(s, s->sxy_model[2], 16, 100, &sx2);

                VAR_5 |= decode_value(s, s->sxy_model[3], 16, 100, &sy2);

                if (VAR_5 < 0)

                    return VAR_5;



                sx2++;

                sy2++;

            }

            if (((s->blocks[VAR_10 * s->nbx + VAR_9] - 1) & 2) > 0) {

                int i, j, by = VAR_10 * 16, bx = VAR_9 * 16;

                int mvx, mvy;



                VAR_5  = decode_value(s, s->mv_model[0], 512, 100, &mvx);

                VAR_5 |= decode_value(s, s->mv_model[1], 512, 100, &mvy);

                if (VAR_5 < 0)

                    return VAR_5;



                mvx -= 256;

                mvy -= 256;



                if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||

                    by + mvy + sy1 >= VAR_0->height || bx + mvx + sx1 >= VAR_0->width)

                    return AVERROR_INVALIDDATA;



                for (i = 0; i < sy2 - sy1 && (by + sy1 + i) < VAR_0->height && (by + mvy + sy1 + i) < VAR_0->height; i++) {

                    for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < VAR_0->width && (bx + mvx + sx1 + j) < VAR_0->width; j++) {

                        VAR_1[(by + i + sy1) * VAR_2 + bx + sx1 + j] = VAR_3[(by + mvy + sy1 + i) * VAR_4 + bx + sx1 + mvx + j];

                    }

                }

            } else {

                int run, r, g, b, z, bx = VAR_9 * 16 + sx1, by = VAR_10 * 16 + sy1;

                unsigned clr, ptype = 0;



                for (; by < VAR_10 * 16 + sy2 && by < VAR_0->height;) {

                    VAR_5 = decode_value(s, s->op_model[ptype], 6, 1000, &ptype);

                    if (ptype == 0) {

                        VAR_5 = decode_unit(s, &s->pixel_model[0][VAR_11 + VAR_12], 400, &r);

                        if (VAR_5 < 0)

                            return VAR_5;



                        VAR_12 = (VAR_11 << 6) & 0xFC0;

                        VAR_11 = r >> VAR_14;

                        VAR_5 = decode_unit(s, &s->pixel_model[1][VAR_11 + VAR_12], 400, &g);

                        if (VAR_5 < 0)

                            return VAR_5;



                        VAR_12 = (VAR_11 << 6) & 0xFC0;

                        VAR_11 = g >> VAR_14;

                        VAR_5 = decode_unit(s, &s->pixel_model[2][VAR_11 + VAR_12], 400, &b);

                        if (VAR_5 < 0)

                            return VAR_5;



                        clr = (b << 16) + (g << 8) + r;

                    }

                    if (ptype > 5)

                        return AVERROR_INVALIDDATA;

                    VAR_5 = decode_value(s, s->run_model[ptype], 256, 400, &run);

                    if (VAR_5 < 0)

                        return VAR_5;



                    switch (ptype) {

                    case 0:

                        while (run-- > 0) {

                            if (by >= VAR_0->height)

                                return AVERROR_INVALIDDATA;



                            VAR_1[by * VAR_2 + bx] = clr;

                            bx++;

                            if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) {

                                bx = VAR_9 * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 1:

                        while (run-- > 0) {

                            if (bx == 0) {

                                if (by < 1)

                                    return AVERROR_INVALIDDATA;

                                z = VAR_13;

                            } else {

                                z = 0;

                            }



                            if (by >= VAR_0->height)

                                return AVERROR_INVALIDDATA;



                            clr = VAR_1[by * VAR_2 + bx - 1 - z];

                            VAR_1[by * VAR_2 + bx] = clr;

                            bx++;

                            if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) {

                                bx = VAR_9 * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 2:

                        while (run-- > 0) {

                            if (by < 1 || by >= VAR_0->height)

                                return AVERROR_INVALIDDATA;



                            clr = VAR_1[(by - 1) * VAR_2 + bx];

                            VAR_1[by * VAR_2 + bx] = clr;

                            bx++;

                            if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) {

                                bx = VAR_9 * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 3:

                        while (run-- > 0) {

                            if (by >= VAR_0->height)

                                return AVERROR_INVALIDDATA;



                            clr = VAR_3[by * VAR_4 + bx];

                            VAR_1[by * VAR_2 + bx] = clr;

                            bx++;

                            if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) {

                                bx = VAR_9 * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 4:

                        while (run-- > 0) {

                            uint8_t *odst = (uint8_t *)VAR_1;



                            if (by < 1 || by >= VAR_0->height)

                                return AVERROR_INVALIDDATA;



                            if (bx == 0) {

                                z = VAR_13;

                            } else {

                                z = 0;

                            }



                            r = odst[((by - 1) * VAR_2 + bx) * 4] +

                                odst[(by * VAR_2 + bx - 1 - z) * 4] -

                                odst[((by - 1) * VAR_2 + bx - 1 - z) * 4];

                            g = odst[((by - 1) * VAR_2 + bx) * 4 + 1] +

                                odst[(by * VAR_2 + bx - 1 - z) * 4 + 1] -

                                odst[((by - 1) * VAR_2 + bx - 1 - z) * 4 + 1];

                            b = odst[((by - 1) * VAR_2 + bx) * 4 + 2] +

                                odst[(by * VAR_2 + bx - 1 - z) * 4 + 2] -

                                odst[((by - 1) * VAR_2 + bx - 1 - z) * 4 + 2];

                            clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF);

                            VAR_1[by * VAR_2 + bx] = clr;

                            bx++;

                            if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) {

                                bx = VAR_9 * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    case 5:

                        while (run-- > 0) {

                            if (by < 1 || by >= VAR_0->height)

                                return AVERROR_INVALIDDATA;



                            if (bx == 0) {

                                z = VAR_13;

                            } else {

                                z = 0;

                            }



                            clr = VAR_1[(by - 1) * VAR_2 + bx - 1 - z];

                            VAR_1[by * VAR_2 + bx] = clr;

                            bx++;

                            if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) {

                                bx = VAR_9 * 16 + sx1;

                                by++;

                            }

                        }

                        break;

                    }



                    if (VAR_0->bits_per_coded_sample == 16) {

                        VAR_12 = (clr & 0x3F00) >> 2;

                        VAR_11 = (clr & 0xFFFFFF) >> 16;

                    } else {

                        VAR_12 = (clr & 0xFC00) >> 4;

                        VAR_11 = (clr & 0xFFFFFF) >> 18;

                    }

                }

            }

        }

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0,
uint32_t *VAR_1, int VAR_2,
uint32_t *VAR_3, int VAR_4)
{ SCPRContext *s = VAR_0->priv_data; GetByteContext *gb = &s->gb; int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11 = 0, VAR_12 = 0; int VAR_13 = VAR_2 - VAR_0->width; const int VAR_14 = s->VAR_14; if (bytestream2_get_byte(gb) == 0)
return 0; bytestream2_skip(gb, 1); init_rangecoder(&s->rc, gb); VAR_5  = decode_value(s, s->range_model, 256, 1, &VAR_7); VAR_5 |= decode_value(s, s->range_model, 256, 1, &VAR_6); VAR_7 += VAR_6 << 8; VAR_5 |= decode_value(s, s->range_model, 256, 1, &VAR_8); VAR_5 |= decode_value(s, s->range_model, 256, 1, &VAR_6); if (VAR_5 < 0)
return VAR_5; VAR_8 += VAR_6 << 8; memset(s->blocks, 0, sizeof(*s->blocks) * s->nbcount); while (VAR_7 <= VAR_8) { int VAR_15, VAR_16; VAR_5  = decode_value(s, s->fill_model,  5,   10, &VAR_15); VAR_5 |= decode_value(s, s->count_model, 256, 20, &VAR_16); if (VAR_5 < 0)
return VAR_5; while (VAR_7 < s->nbcount && VAR_16-- > 0) { s->blocks[VAR_7++] = VAR_15; } } for (VAR_10 = 0; VAR_10 < s->nby; VAR_10++) { for (VAR_9 = 0; VAR_9 < s->nbx; VAR_9++) { int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16; if (s->blocks[VAR_10 * s->nbx + VAR_9] == 0)
continue; if (((s->blocks[VAR_10 * s->nbx + VAR_9] - 1) & 1) > 0) { VAR_5  = decode_value(s, s->sxy_model[0], 16, 100, &sx1); VAR_5 |= decode_value(s, s->sxy_model[1], 16, 100, &sy1); VAR_5 |= decode_value(s, s->sxy_model[2], 16, 100, &sx2); VAR_5 |= decode_value(s, s->sxy_model[3], 16, 100, &sy2); if (VAR_5 < 0)
return VAR_5; sx2++; sy2++; } if (((s->blocks[VAR_10 * s->nbx + VAR_9] - 1) & 2) > 0) { int i, j, by = VAR_10 * 16, bx = VAR_9 * 16; int mvx, mvy; VAR_5  = decode_value(s, s->mv_model[0], 512, 100, &mvx); VAR_5 |= decode_value(s, s->mv_model[1], 512, 100, &mvy); if (VAR_5 < 0)
return VAR_5; mvx -= 256; mvy -= 256; if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
by + mvy + sy1 >= VAR_0->height || bx + mvx + sx1 >= VAR_0->width)
return AVERROR_INVALIDDATA; for (i = 0; i < sy2 - sy1 && (by + sy1 + i) < VAR_0->height && (by + mvy + sy1 + i) < VAR_0->height; i++) { for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < VAR_0->width && (bx + mvx + sx1 + j) < VAR_0->width; j++) { VAR_1[(by + i + sy1) * VAR_2 + bx + sx1 + j] = VAR_3[(by + mvy + sy1 + i) * VAR_4 + bx + sx1 + mvx + j]; } } } else { int run, r, g, b, z, bx = VAR_9 * 16 + sx1, by = VAR_10 * 16 + sy1; unsigned clr, ptype = 0; for (; by < VAR_10 * 16 + sy2 && by < VAR_0->height;) { VAR_5 = decode_value(s, s->op_model[ptype], 6, 1000, &ptype); if (ptype == 0) { VAR_5 = decode_unit(s, &s->pixel_model[0][VAR_11 + VAR_12], 400, &r); if (VAR_5 < 0)
return VAR_5; VAR_12 = (VAR_11 << 6) & 0xFC0; VAR_11 = r >> VAR_14; VAR_5 = decode_unit(s, &s->pixel_model[1][VAR_11 + VAR_12], 400, &g); if (VAR_5 < 0)
return VAR_5; VAR_12 = (VAR_11 << 6) & 0xFC0; VAR_11 = g >> VAR_14; VAR_5 = decode_unit(s, &s->pixel_model[2][VAR_11 + VAR_12], 400, &b); if (VAR_5 < 0)
return VAR_5; clr = (b << 16) + (g << 8) + r; } if (ptype > 5)
return AVERROR_INVALIDDATA; VAR_5 = decode_value(s, s->run_model[ptype], 256, 400, &run); if (VAR_5 < 0)
return VAR_5; switch (ptype) { case 0:
while (run-- > 0) { if (by >= VAR_0->height)
return AVERROR_INVALIDDATA; VAR_1[by * VAR_2 + bx] = clr; bx++; if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) { bx = VAR_9 * 16 + sx1; by++; } } break; case 1:
while (run-- > 0) { if (bx == 0) { if (by < 1)
return AVERROR_INVALIDDATA; z = VAR_13; } else { z = 0; } if (by >= VAR_0->height)
return AVERROR_INVALIDDATA; clr = VAR_1[by * VAR_2 + bx - 1 - z]; VAR_1[by * VAR_2 + bx] = clr; bx++; if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) { bx = VAR_9 * 16 + sx1; by++; } } break; case 2:
while (run-- > 0) { if (by < 1 || by >= VAR_0->height)
return AVERROR_INVALIDDATA; clr = VAR_1[(by - 1) * VAR_2 + bx]; VAR_1[by * VAR_2 + bx] = clr; bx++; if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) { bx = VAR_9 * 16 + sx1; by++; } } break; case 3:
while (run-- > 0) { if (by >= VAR_0->height)
return AVERROR_INVALIDDATA; clr = VAR_3[by * VAR_4 + bx]; VAR_1[by * VAR_2 + bx] = clr; bx++; if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) { bx = VAR_9 * 16 + sx1; by++; } } break; case 4:
while (run-- > 0) { uint8_t *odst = (uint8_t *)VAR_1; if (by < 1 || by >= VAR_0->height)
return AVERROR_INVALIDDATA; if (bx == 0) { z = VAR_13; } else { z = 0; } r = odst[((by - 1) * VAR_2 + bx) * 4] +
odst[(by * VAR_2 + bx - 1 - z) * 4] -
odst[((by - 1) * VAR_2 + bx - 1 - z) * 4]; g = odst[((by - 1) * VAR_2 + bx) * 4 + 1] +
odst[(by * VAR_2 + bx - 1 - z) * 4 + 1] -
odst[((by - 1) * VAR_2 + bx - 1 - z) * 4 + 1]; b = odst[((by - 1) * VAR_2 + bx) * 4 + 2] +
odst[(by * VAR_2 + bx - 1 - z) * 4 + 2] -
odst[((by - 1) * VAR_2 + bx - 1 - z) * 4 + 2]; clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF); VAR_1[by * VAR_2 + bx] = clr; bx++; if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) { bx = VAR_9 * 16 + sx1; by++; } } break; case 5:
while (run-- > 0) { if (by < 1 || by >= VAR_0->height)
return AVERROR_INVALIDDATA; if (bx == 0) { z = VAR_13; } else { z = 0; } clr = VAR_1[(by - 1) * VAR_2 + bx - 1 - z]; VAR_1[by * VAR_2 + bx] = clr; bx++; if (bx >= VAR_9 * 16 + sx2 || bx >= VAR_0->width) { bx = VAR_9 * 16 + sx1; by++; } } break; } if (VAR_0->bits_per_coded_sample == 16) { VAR_12 = (clr & 0x3F00) >> 2; VAR_11 = (clr & 0xFFFFFF) >> 16; } else { VAR_12 = (clr & 0xFC00) >> 4; VAR_11 = (clr & 0xFFFFFF) >> 18; } } } } } return 0; }