static int decode_hextile(VmncContext *c, uint8_t *dst, const uint8_t *src,

                          int ssize, int w, int h, int stride)

{

    int i, j, k;

    int bg = 0, fg = 0, rects, color, flags, xy, wh;

    const int bpp = c->bpp2;

    uint8_t *dst2;

    int bw = 16, bh = 16;

    const uint8_t *ssrc = src;



    for (j = 0; j < h; j += 16) {

        dst2 = dst;

        bw   = 16;

        if (j + 16 > h)

            bh = h - j;

        for (i = 0; i < w; i += 16, dst2 += 16 * bpp) {

            if (src - ssrc >= ssize) {

                av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                return -1;

            }

            if (i + 16 > w)

                bw = w - i;

            flags = *src++;

            if (flags & HT_RAW) {

                if (src - ssrc > ssize - bw * bh * bpp) {

                    av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                    return -1;

                }

                paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);

                src += bw * bh * bpp;

            } else {

                if (flags & HT_BKG) {

                    bg = vmnc_get_pixel(src, bpp, c->bigendian);

                    src += bpp;

                }

                if (flags & HT_FG) {

                    fg = vmnc_get_pixel(src, bpp, c->bigendian);

                    src += bpp;

                }

                rects = 0;

                if (flags & HT_SUB)

                    rects = *src++;

                color = !!(flags & HT_CLR);



                paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);



                if (src - ssrc > ssize - rects * (color * bpp + 2)) {

                    av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                    return -1;

                }

                for (k = 0; k < rects; k++) {

                    if (color) {

                        fg = vmnc_get_pixel(src, bpp, c->bigendian);

                        src += bpp;

                    }

                    xy = *src++;

                    wh = *src++;

                    paint_rect(dst2, xy >> 4, xy & 0xF, (wh >> 4) + 1,

                               (wh & 0xF) + 1, fg, bpp, stride);

                }

            }

        }

        dst += stride * 16;

    }

    return src - ssrc;

}

static int decode_hextile(VmncContext *c, uint8_t *dst, const uint8_t *src,

                          int ssize, int w, int h, int stride)

{

    int i, j, k;

    int bg = 0, fg = 0, rects, color, flags, xy, wh;

    const int bpp = c->bpp2;

    uint8_t *dst2;

    int bw = 16, bh = 16;

    const uint8_t *ssrc = src;



    for (j = 0; j < h; j += 16) {

        dst2 = dst;

        bw   = 16;

        if (j + 16 > h)

            bh = h - j;

        for (i = 0; i < w; i += 16, dst2 += 16 * bpp) {

            if (src - ssrc >= ssize) {

                av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                return -1;

            }

            if (i + 16 > w)

                bw = w - i;

            flags = *src++;

            if (flags & HT_RAW) {

                if (src - ssrc > ssize - bw * bh * bpp) {

                    av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                    return -1;

                }

                paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);

                src += bw * bh * bpp;

            } else {

                if (flags & HT_BKG) {

                    bg = vmnc_get_pixel(src, bpp, c->bigendian);

                    src += bpp;

                }

                if (flags & HT_FG) {

                    fg = vmnc_get_pixel(src, bpp, c->bigendian);

                    src += bpp;

                }

                rects = 0;

                if (flags & HT_SUB)

                    rects = *src++;

                color = !!(flags & HT_CLR);



                paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);



                if (src - ssrc > ssize - rects * (color * bpp + 2)) {

                    av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                    return -1;

                }

                for (k = 0; k < rects; k++) {

                    if (color) {

                        fg = vmnc_get_pixel(src, bpp, c->bigendian);

                        src += bpp;

                    }

                    xy = *src++;

                    wh = *src++;

                    paint_rect(dst2, xy >> 4, xy & 0xF, (wh >> 4) + 1,

                               (wh & 0xF) + 1, fg, bpp, stride);

                }

            }

        }

        dst += stride * 16;

    }

    return src - ssrc;

}

static int decode_hextile(VmncContext *c, uint8_t *dst, const uint8_t *src,                           int ssize, int w, int h, int stride)     const uint8_t *ssrc = src;             if (src - ssrc >= ssize) {             flags = *src++;                 if (src - ssrc > ssize - bw * bh * bpp) {                 paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);                 src += bw * bh * bpp;                 if (flags & HT_BKG) {                     bg = vmnc_get_pixel(src, bpp, c->bigendian);                     src += bpp;                 if (flags & HT_FG) {                     fg = vmnc_get_pixel(src, bpp, c->bigendian);                     src += bpp;                     rects = *src++;                 if (src - ssrc > ssize - rects * (color * bpp + 2)) {                     if (color) {                         fg = vmnc_get_pixel(src, bpp, c->bigendian);                         src += bpp;                     xy = *src++;                     wh = *src++;                     paint_rect(dst2, xy >> 4, xy & 0xF, (wh >> 4) + 1,                                (wh & 0xF) + 1, fg, bpp, stride);     return src - ssrc;
static int FUNC_0(VmncContext *VAR_0, uint8_t *VAR_1, const uint8_t *VAR_2,

                          int VAR_3, int VAR_4, int VAR_5, int VAR_6)

{

    int VAR_7, VAR_8, VAR_9;

    int VAR_10 = 0, VAR_11 = 0, VAR_12, VAR_13, VAR_14, VAR_15, VAR_16;

    const int VAR_17 = VAR_0->bpp2;

    uint8_t *dst2;

    int VAR_18 = 16, VAR_19 = 16;

    const uint8_t *VAR_20 = VAR_2;



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

        dst2 = VAR_1;

        VAR_18   = 16;

        if (VAR_8 + 16 > VAR_5)

            VAR_19 = VAR_5 - VAR_8;

        for (VAR_7 = 0; VAR_7 < VAR_4; VAR_7 += 16, dst2 += 16 * VAR_17) {

            if (VAR_2 - VAR_20 >= VAR_3) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                return -1;

            }

            if (VAR_7 + 16 > VAR_4)

                VAR_18 = VAR_4 - VAR_7;

            VAR_14 = *VAR_2++;

            if (VAR_14 & HT_RAW) {

                if (VAR_2 - VAR_20 > VAR_3 - VAR_18 * VAR_19 * VAR_17) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                    return -1;

                }

                paint_raw(dst2, VAR_18, VAR_19, VAR_2, VAR_17, VAR_0->bigendian, VAR_6);

                VAR_2 += VAR_18 * VAR_19 * VAR_17;

            } else {

                if (VAR_14 & HT_BKG) {

                    VAR_10 = vmnc_get_pixel(VAR_2, VAR_17, VAR_0->bigendian);

                    VAR_2 += VAR_17;

                }

                if (VAR_14 & HT_FG) {

                    VAR_11 = vmnc_get_pixel(VAR_2, VAR_17, VAR_0->bigendian);

                    VAR_2 += VAR_17;

                }

                VAR_12 = 0;

                if (VAR_14 & HT_SUB)

                    VAR_12 = *VAR_2++;

                VAR_13 = !!(VAR_14 & HT_CLR);



                paint_rect(dst2, 0, 0, VAR_18, VAR_19, VAR_10, VAR_17, VAR_6);



                if (VAR_2 - VAR_20 > VAR_3 - VAR_12 * (VAR_13 * VAR_17 + 2)) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Premature end of data!\n");

                    return -1;

                }

                for (VAR_9 = 0; VAR_9 < VAR_12; VAR_9++) {

                    if (VAR_13) {

                        VAR_11 = vmnc_get_pixel(VAR_2, VAR_17, VAR_0->bigendian);

                        VAR_2 += VAR_17;

                    }

                    VAR_15 = *VAR_2++;

                    VAR_16 = *VAR_2++;

                    paint_rect(dst2, VAR_15 >> 4, VAR_15 & 0xF, (VAR_16 >> 4) + 1,

                               (VAR_16 & 0xF) + 1, VAR_11, VAR_17, VAR_6);

                }

            }

        }

        VAR_1 += VAR_6 * 16;

    }

    return VAR_2 - VAR_20;

}

static int FUNC_0(VmncContext *VAR_0, uint8_t *VAR_1, const uint8_t *VAR_2,
int VAR_3, int VAR_4, int VAR_5, int VAR_6)
{ int VAR_7, VAR_8, VAR_9; int VAR_10 = 0, VAR_11 = 0, VAR_12, VAR_13, VAR_14, VAR_15, VAR_16; const int VAR_17 = VAR_0->bpp2; uint8_t *dst2; int VAR_18 = 16, VAR_19 = 16; const uint8_t *VAR_20 = VAR_2; for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8 += 16) { dst2 = VAR_1; VAR_18   = 16; if (VAR_8 + 16 > VAR_5)
VAR_19 = VAR_5 - VAR_8; for (VAR_7 = 0; VAR_7 < VAR_4; VAR_7 += 16, dst2 += 16 * VAR_17) { if (VAR_2 - VAR_20 >= VAR_3) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Premature end of data!\n"); return -1; } if (VAR_7 + 16 > VAR_4)
VAR_18 = VAR_4 - VAR_7; VAR_14 = *VAR_2++; if (VAR_14 & HT_RAW) { if (VAR_2 - VAR_20 > VAR_3 - VAR_18 * VAR_19 * VAR_17) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Premature end of data!\n"); return -1; } paint_raw(dst2, VAR_18, VAR_19, VAR_2, VAR_17, VAR_0->bigendian, VAR_6); VAR_2 += VAR_18 * VAR_19 * VAR_17; } else { if (VAR_14 & HT_BKG) { VAR_10 = vmnc_get_pixel(VAR_2, VAR_17, VAR_0->bigendian); VAR_2 += VAR_17; } if (VAR_14 & HT_FG) { VAR_11 = vmnc_get_pixel(VAR_2, VAR_17, VAR_0->bigendian); VAR_2 += VAR_17; } VAR_12 = 0; if (VAR_14 & HT_SUB)
VAR_12 = *VAR_2++; VAR_13 = !!(VAR_14 & HT_CLR); paint_rect(dst2, 0, 0, VAR_18, VAR_19, VAR_10, VAR_17, VAR_6); if (VAR_2 - VAR_20 > VAR_3 - VAR_12 * (VAR_13 * VAR_17 + 2)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Premature end of data!\n"); return -1; } for (VAR_9 = 0; VAR_9 < VAR_12; VAR_9++) { if (VAR_13) { VAR_11 = vmnc_get_pixel(VAR_2, VAR_17, VAR_0->bigendian); VAR_2 += VAR_17; } VAR_15 = *VAR_2++; VAR_16 = *VAR_2++; paint_rect(dst2, VAR_15 >> 4, VAR_15 & 0xF, (VAR_16 >> 4) + 1,
(VAR_16 & 0xF) + 1, VAR_11, VAR_17, VAR_6); } } } VAR_1 += VAR_6 * 16; } return VAR_2 - VAR_20; }