static void decode_delta_j(uint8_t *dst,

                           const uint8_t *buf, const uint8_t *buf_end,

                           int w, int h, int bpp, int dst_size)

{

    int32_t pitch;

    uint8_t *end = dst + dst_size, *ptr;

    uint32_t type, flag, cols, groups, rows, bytes;

    uint32_t offset;

    int planepitch_byte = (w + 7) / 8;

    int planepitch = ((w + 15) / 16) * 2;

    int kludge_j, b, g, r, d;

    GetByteContext gb;



    pitch = planepitch * bpp;

    kludge_j = w < 320 ? (320 - w) / 8 / 2 : 0;



    bytestream2_init(&gb, buf, buf_end - buf);



    while (bytestream2_get_bytes_left(&gb) >= 2) {

        type = bytestream2_get_be16(&gb);



        switch (type) {

        case 0:

            return;

        case 1:

            flag   = bytestream2_get_be16(&gb);

            cols   = bytestream2_get_be16(&gb);

            groups = bytestream2_get_be16(&gb);



            for (g = 0; g < groups; g++) {

                offset = bytestream2_get_be16(&gb);



                if (kludge_j)

                    offset = ((offset / (320 / 8)) * pitch) + (offset % (320 / 8)) - kludge_j;

                else

                    offset = ((offset / planepitch_byte) * pitch) + (offset % planepitch_byte);



                ptr = dst + offset;

                if (ptr >= end)

                    return;



                for (b = 0; b < cols; b++) {

                    for (d = 0; d < bpp; d++) {

                        uint8_t value = bytestream2_get_byte(&gb);



                        if (flag)

                            ptr[0] ^= value;

                        else

                            ptr[0]  = value;



                        ptr += planepitch;

                        if (ptr >= end)

                            return;

                    }

                }

                if ((cols * bpp) & 1)

                    bytestream2_skip(&gb, 1);

            }

            break;

        case 2:

            flag   = bytestream2_get_be16(&gb);

            rows   = bytestream2_get_be16(&gb);

            bytes  = bytestream2_get_be16(&gb);

            groups = bytestream2_get_be16(&gb);



            for (g = 0; g < groups; g++) {

                offset = bytestream2_get_be16(&gb);



                if (kludge_j)

                    offset = ((offset / (320 / 8)) * pitch) + (offset % (320/ 8)) - kludge_j;

                else

                    offset = ((offset / planepitch_byte) * pitch) + (offset % planepitch_byte);



                for (r = 0; r < rows; r++) {

                    for (d = 0; d < bpp; d++) {

                        ptr = dst + offset + (r * pitch) + d * planepitch;

                        if (ptr >= end)

                            return;



                        for (b = 0; b < bytes; b++) {

                            uint8_t value = bytestream2_get_byte(&gb);



                            if (flag)

                                ptr[0] ^= value;

                            else

                                ptr[0]  = value;



                            ptr++;

                            if (ptr >= end)

                                return;

                        }

                    }

                }

                if ((rows * bytes * bpp) & 1)

                    bytestream2_skip(&gb, 1);

            }

            break;

        default:

            return;

        }

    }

}

static void decode_delta_j(uint8_t *dst,

                           const uint8_t *buf, const uint8_t *buf_end,

                           int w, int h, int bpp, int dst_size)

{

    int32_t pitch;

    uint8_t *end = dst + dst_size, *ptr;

    uint32_t type, flag, cols, groups, rows, bytes;

    uint32_t offset;

    int planepitch_byte = (w + 7) / 8;

    int planepitch = ((w + 15) / 16) * 2;

    int kludge_j, b, g, r, d;

    GetByteContext gb;



    pitch = planepitch * bpp;

    kludge_j = w < 320 ? (320 - w) / 8 / 2 : 0;



    bytestream2_init(&gb, buf, buf_end - buf);



    while (bytestream2_get_bytes_left(&gb) >= 2) {

        type = bytestream2_get_be16(&gb);



        switch (type) {

        case 0:

            return;

        case 1:

            flag   = bytestream2_get_be16(&gb);

            cols   = bytestream2_get_be16(&gb);

            groups = bytestream2_get_be16(&gb);



            for (g = 0; g < groups; g++) {

                offset = bytestream2_get_be16(&gb);



                if (kludge_j)

                    offset = ((offset / (320 / 8)) * pitch) + (offset % (320 / 8)) - kludge_j;

                else

                    offset = ((offset / planepitch_byte) * pitch) + (offset % planepitch_byte);



                ptr = dst + offset;

                if (ptr >= end)

                    return;



                for (b = 0; b < cols; b++) {

                    for (d = 0; d < bpp; d++) {

                        uint8_t value = bytestream2_get_byte(&gb);



                        if (flag)

                            ptr[0] ^= value;

                        else

                            ptr[0]  = value;



                        ptr += planepitch;

                        if (ptr >= end)

                            return;

                    }

                }

                if ((cols * bpp) & 1)

                    bytestream2_skip(&gb, 1);

            }

            break;

        case 2:

            flag   = bytestream2_get_be16(&gb);

            rows   = bytestream2_get_be16(&gb);

            bytes  = bytestream2_get_be16(&gb);

            groups = bytestream2_get_be16(&gb);



            for (g = 0; g < groups; g++) {

                offset = bytestream2_get_be16(&gb);



                if (kludge_j)

                    offset = ((offset / (320 / 8)) * pitch) + (offset % (320/ 8)) - kludge_j;

                else

                    offset = ((offset / planepitch_byte) * pitch) + (offset % planepitch_byte);



                for (r = 0; r < rows; r++) {

                    for (d = 0; d < bpp; d++) {

                        ptr = dst + offset + (r * pitch) + d * planepitch;

                        if (ptr >= end)

                            return;



                        for (b = 0; b < bytes; b++) {

                            uint8_t value = bytestream2_get_byte(&gb);



                            if (flag)

                                ptr[0] ^= value;

                            else

                                ptr[0]  = value;



                            ptr++;

                            if (ptr >= end)

                                return;

                        }

                    }

                }

                if ((rows * bytes * bpp) & 1)

                    bytestream2_skip(&gb, 1);

            }

            break;

        default:

            return;

        }

    }

}

    uint8_t *end = dst + dst_size, *ptr;                 ptr = dst + offset;                 if (ptr >= end)                         ptr += planepitch;                         if (ptr >= end)                         ptr = dst + offset + (r * pitch) + d * planepitch;                         if (ptr >= end)                             ptr++;                             if (ptr >= end)
static void FUNC_0(uint8_t *VAR_0,

                           const uint8_t *VAR_1, const uint8_t *VAR_2,

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

{

    int32_t pitch;

    uint8_t *end = VAR_0 + VAR_6, *ptr;

    uint32_t type, flag, cols, groups, rows, bytes;

    uint32_t offset;

    int VAR_7 = (VAR_3 + 7) / 8;

    int VAR_8 = ((VAR_3 + 15) / 16) * 2;

    int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;

    GetByteContext gb;



    pitch = VAR_8 * VAR_5;

    VAR_9 = VAR_3 < 320 ? (320 - VAR_3) / 8 / 2 : 0;



    bytestream2_init(&gb, VAR_1, VAR_2 - VAR_1);



    while (bytestream2_get_bytes_left(&gb) >= 2) {

        type = bytestream2_get_be16(&gb);



        switch (type) {

        case 0:

            return;

        case 1:

            flag   = bytestream2_get_be16(&gb);

            cols   = bytestream2_get_be16(&gb);

            groups = bytestream2_get_be16(&gb);



            for (VAR_11 = 0; VAR_11 < groups; VAR_11++) {

                offset = bytestream2_get_be16(&gb);



                if (VAR_9)

                    offset = ((offset / (320 / 8)) * pitch) + (offset % (320 / 8)) - VAR_9;

                else

                    offset = ((offset / VAR_7) * pitch) + (offset % VAR_7);



                ptr = VAR_0 + offset;

                if (ptr >= end)

                    return;



                for (VAR_10 = 0; VAR_10 < cols; VAR_10++) {

                    for (VAR_13 = 0; VAR_13 < VAR_5; VAR_13++) {

                        uint8_t value = bytestream2_get_byte(&gb);



                        if (flag)

                            ptr[0] ^= value;

                        else

                            ptr[0]  = value;



                        ptr += VAR_8;

                        if (ptr >= end)

                            return;

                    }

                }

                if ((cols * VAR_5) & 1)

                    bytestream2_skip(&gb, 1);

            }

            break;

        case 2:

            flag   = bytestream2_get_be16(&gb);

            rows   = bytestream2_get_be16(&gb);

            bytes  = bytestream2_get_be16(&gb);

            groups = bytestream2_get_be16(&gb);



            for (VAR_11 = 0; VAR_11 < groups; VAR_11++) {

                offset = bytestream2_get_be16(&gb);



                if (VAR_9)

                    offset = ((offset / (320 / 8)) * pitch) + (offset % (320/ 8)) - VAR_9;

                else

                    offset = ((offset / VAR_7) * pitch) + (offset % VAR_7);



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

                    for (VAR_13 = 0; VAR_13 < VAR_5; VAR_13++) {

                        ptr = VAR_0 + offset + (VAR_12 * pitch) + VAR_13 * VAR_8;

                        if (ptr >= end)

                            return;



                        for (VAR_10 = 0; VAR_10 < bytes; VAR_10++) {

                            uint8_t value = bytestream2_get_byte(&gb);



                            if (flag)

                                ptr[0] ^= value;

                            else

                                ptr[0]  = value;



                            ptr++;

                            if (ptr >= end)

                                return;

                        }

                    }

                }

                if ((rows * bytes * VAR_5) & 1)

                    bytestream2_skip(&gb, 1);

            }

            break;

        default:

            return;

        }

    }

}

static void FUNC_0(uint8_t *VAR_0,
const uint8_t *VAR_1, const uint8_t *VAR_2,
int VAR_3, int VAR_4, int VAR_5, int VAR_6)
{ int32_t pitch; uint8_t *end = VAR_0 + VAR_6, *ptr; uint32_t type, flag, cols, groups, rows, bytes; uint32_t offset; int VAR_7 = (VAR_3 + 7) / 8; int VAR_8 = ((VAR_3 + 15) / 16) * 2; int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; GetByteContext gb; pitch = VAR_8 * VAR_5; VAR_9 = VAR_3 < 320 ? (320 - VAR_3) / 8 / 2 : 0; bytestream2_init(&gb, VAR_1, VAR_2 - VAR_1); while (bytestream2_get_bytes_left(&gb) >= 2) { type = bytestream2_get_be16(&gb); switch (type) { case 0:
return; case 1:
flag   = bytestream2_get_be16(&gb); cols   = bytestream2_get_be16(&gb); groups = bytestream2_get_be16(&gb); for (VAR_11 = 0; VAR_11 < groups; VAR_11++) { offset = bytestream2_get_be16(&gb); if (VAR_9)
offset = ((offset / (320 / 8)) * pitch) + (offset % (320 / 8)) - VAR_9; else
offset = ((offset / VAR_7) * pitch) + (offset % VAR_7); ptr = VAR_0 + offset; if (ptr >= end)
return; for (VAR_10 = 0; VAR_10 < cols; VAR_10++) { for (VAR_13 = 0; VAR_13 < VAR_5; VAR_13++) { uint8_t value = bytestream2_get_byte(&gb); if (flag)
ptr[0] ^= value; else
ptr[0]  = value; ptr += VAR_8; if (ptr >= end)
return; } } if ((cols * VAR_5) & 1)
bytestream2_skip(&gb, 1); } break; case 2:
flag   = bytestream2_get_be16(&gb); rows   = bytestream2_get_be16(&gb); bytes  = bytestream2_get_be16(&gb); groups = bytestream2_get_be16(&gb); for (VAR_11 = 0; VAR_11 < groups; VAR_11++) { offset = bytestream2_get_be16(&gb); if (VAR_9)
offset = ((offset / (320 / 8)) * pitch) + (offset % (320/ 8)) - VAR_9; else
offset = ((offset / VAR_7) * pitch) + (offset % VAR_7); for (VAR_12 = 0; VAR_12 < rows; VAR_12++) { for (VAR_13 = 0; VAR_13 < VAR_5; VAR_13++) { ptr = VAR_0 + offset + (VAR_12 * pitch) + VAR_13 * VAR_8; if (ptr >= end)
return; for (VAR_10 = 0; VAR_10 < bytes; VAR_10++) { uint8_t value = bytestream2_get_byte(&gb); if (flag)
ptr[0] ^= value; else
ptr[0]  = value; ptr++; if (ptr >= end)
return; } } } if ((rows * bytes * VAR_5) & 1)
bytestream2_skip(&gb, 1); } break; default:
return; } } }