static int decode_0(PAFVideoDecContext *c, uint8_t *pkt, uint8_t code)

{

    uint32_t opcode_size, offset;

    uint8_t *dst, *dend, mask = 0, color = 0;

    const uint8_t *src, *send, *opcodes;

    int i, j, op = 0;



    i = bytestream2_get_byte(&c->gb);

    if (i) {

        if (code & 0x10) {

            int align;



            align = bytestream2_tell(&c->gb) & 3;

            if (align)

                bytestream2_skip(&c->gb, 4 - align);

        }

        do {

            int page, val, x, y;

            val    = bytestream2_get_be16(&c->gb);

            page   = val >> 14;

            x      = (val & 0x7F) * 2;

            y      = ((val >> 7) & 0x7F) * 2;

            dst    = c->frame[page] + x + y * c->width;

            dend   = c->frame[page] + c->frame_size;

            offset = (x & 0x7F) * 2;

            j      = bytestream2_get_le16(&c->gb) + offset;

            do {

                offset++;

                if (dst + 3 * c->width + 4 > dend)

                    return AVERROR_INVALIDDATA;

                read4x4block(c, dst, c->width);

                if ((offset & 0x3F) == 0)

                    dst += c->width * 3;

                dst += 4;

            } while (offset < j);

        } while (--i);

    }



    dst  = c->frame[c->current_frame];

    dend = c->frame[c->current_frame] + c->frame_size;

    do {

        set_src_position(c, &src, &send);

        if ((src + 3 * c->width + 4 > send) ||

            (dst + 3 * c->width + 4 > dend))

            return AVERROR_INVALIDDATA;

        copy_block4(dst, src, c->width, c->width, 4);

        i++;

        if ((i & 0x3F) == 0)

            dst += c->width * 3;

        dst += 4;

    } while (i < c->video_size / 16);



    opcode_size = bytestream2_get_le16(&c->gb);

    bytestream2_skip(&c->gb, 2);



    if (bytestream2_get_bytes_left(&c->gb) < opcode_size)

        return AVERROR_INVALIDDATA;



    opcodes = pkt + bytestream2_tell(&c->gb);

    bytestream2_skipu(&c->gb, opcode_size);



    dst = c->frame[c->current_frame];



    for (i = 0; i < c->height; i += 4, dst += c->width * 3)

        for (j = 0; j < c->width; j += 4, dst += 4) {

            int opcode, k = 0;

            if (op > opcode_size)

                return AVERROR_INVALIDDATA;

            if (j & 4) {

                opcode = opcodes[op] & 15;

                op++;

            } else {

                opcode = opcodes[op] >> 4;

            }



            while (block_sequences[opcode][k]) {

                offset = c->width * 2;

                code   = block_sequences[opcode][k++];



                switch (code) {

                case 2:

                    offset = 0;

                case 3:

                    color = bytestream2_get_byte(&c->gb);

                case 4:

                    mask = bytestream2_get_byte(&c->gb);

                    copy_color_mask(dst + offset, c->width, mask, color);

                    break;

                case 5:

                    offset = 0;

                case 6:

                    set_src_position(c, &src, &send);

                case 7:

                    if (src + offset + c->width + 4 > send)

                        return AVERROR_INVALIDDATA;

                    mask = bytestream2_get_byte(&c->gb);

                    copy_src_mask(dst + offset, c->width, mask, src + offset);

                    break;

                }

            }

        }



    return 0;

}

static int decode_0(PAFVideoDecContext *c, uint8_t *pkt, uint8_t code)

{

    uint32_t opcode_size, offset;

    uint8_t *dst, *dend, mask = 0, color = 0;

    const uint8_t *src, *send, *opcodes;

    int i, j, op = 0;



    i = bytestream2_get_byte(&c->gb);

    if (i) {

        if (code & 0x10) {

            int align;



            align = bytestream2_tell(&c->gb) & 3;

            if (align)

                bytestream2_skip(&c->gb, 4 - align);

        }

        do {

            int page, val, x, y;

            val    = bytestream2_get_be16(&c->gb);

            page   = val >> 14;

            x      = (val & 0x7F) * 2;

            y      = ((val >> 7) & 0x7F) * 2;

            dst    = c->frame[page] + x + y * c->width;

            dend   = c->frame[page] + c->frame_size;

            offset = (x & 0x7F) * 2;

            j      = bytestream2_get_le16(&c->gb) + offset;

            do {

                offset++;

                if (dst + 3 * c->width + 4 > dend)

                    return AVERROR_INVALIDDATA;

                read4x4block(c, dst, c->width);

                if ((offset & 0x3F) == 0)

                    dst += c->width * 3;

                dst += 4;

            } while (offset < j);

        } while (--i);

    }



    dst  = c->frame[c->current_frame];

    dend = c->frame[c->current_frame] + c->frame_size;

    do {

        set_src_position(c, &src, &send);

        if ((src + 3 * c->width + 4 > send) ||

            (dst + 3 * c->width + 4 > dend))

            return AVERROR_INVALIDDATA;

        copy_block4(dst, src, c->width, c->width, 4);

        i++;

        if ((i & 0x3F) == 0)

            dst += c->width * 3;

        dst += 4;

    } while (i < c->video_size / 16);



    opcode_size = bytestream2_get_le16(&c->gb);

    bytestream2_skip(&c->gb, 2);



    if (bytestream2_get_bytes_left(&c->gb) < opcode_size)

        return AVERROR_INVALIDDATA;



    opcodes = pkt + bytestream2_tell(&c->gb);

    bytestream2_skipu(&c->gb, opcode_size);



    dst = c->frame[c->current_frame];



    for (i = 0; i < c->height; i += 4, dst += c->width * 3)

        for (j = 0; j < c->width; j += 4, dst += 4) {

            int opcode, k = 0;

            if (op > opcode_size)

                return AVERROR_INVALIDDATA;

            if (j & 4) {

                opcode = opcodes[op] & 15;

                op++;

            } else {

                opcode = opcodes[op] >> 4;

            }



            while (block_sequences[opcode][k]) {

                offset = c->width * 2;

                code   = block_sequences[opcode][k++];



                switch (code) {

                case 2:

                    offset = 0;

                case 3:

                    color = bytestream2_get_byte(&c->gb);

                case 4:

                    mask = bytestream2_get_byte(&c->gb);

                    copy_color_mask(dst + offset, c->width, mask, color);

                    break;

                case 5:

                    offset = 0;

                case 6:

                    set_src_position(c, &src, &send);

                case 7:

                    if (src + offset + c->width + 4 > send)

                        return AVERROR_INVALIDDATA;

                    mask = bytestream2_get_byte(&c->gb);

                    copy_src_mask(dst + offset, c->width, mask, src + offset);

                    break;

                }

            }

        }



    return 0;

}

            (dst + 3 * c->width + 4 > dend))
static int FUNC_0(PAFVideoDecContext *VAR_0, uint8_t *VAR_1, uint8_t VAR_2)

{

    uint32_t opcode_size, offset;

    uint8_t *dst, *dend, mask = 0, color = 0;

    const uint8_t *VAR_3, *send, *opcodes;

    int VAR_4, VAR_5, VAR_6 = 0;



    VAR_4 = bytestream2_get_byte(&VAR_0->gb);

    if (VAR_4) {

        if (VAR_2 & 0x10) {

            int VAR_7;



            VAR_7 = bytestream2_tell(&VAR_0->gb) & 3;

            if (VAR_7)

                bytestream2_skip(&VAR_0->gb, 4 - VAR_7);

        }

        do {

            int VAR_8, VAR_9, VAR_10, VAR_11;

            VAR_9    = bytestream2_get_be16(&VAR_0->gb);

            VAR_8   = VAR_9 >> 14;

            VAR_10      = (VAR_9 & 0x7F) * 2;

            VAR_11      = ((VAR_9 >> 7) & 0x7F) * 2;

            dst    = VAR_0->frame[VAR_8] + VAR_10 + VAR_11 * VAR_0->width;

            dend   = VAR_0->frame[VAR_8] + VAR_0->frame_size;

            offset = (VAR_10 & 0x7F) * 2;

            VAR_5      = bytestream2_get_le16(&VAR_0->gb) + offset;

            do {

                offset++;

                if (dst + 3 * VAR_0->width + 4 > dend)

                    return AVERROR_INVALIDDATA;

                read4x4block(VAR_0, dst, VAR_0->width);

                if ((offset & 0x3F) == 0)

                    dst += VAR_0->width * 3;

                dst += 4;

            } while (offset < VAR_5);

        } while (--VAR_4);

    }



    dst  = VAR_0->frame[VAR_0->current_frame];

    dend = VAR_0->frame[VAR_0->current_frame] + VAR_0->frame_size;

    do {

        set_src_position(VAR_0, &VAR_3, &send);

        if ((VAR_3 + 3 * VAR_0->width + 4 > send) ||

            (dst + 3 * VAR_0->width + 4 > dend))

            return AVERROR_INVALIDDATA;

        copy_block4(dst, VAR_3, VAR_0->width, VAR_0->width, 4);

        VAR_4++;

        if ((VAR_4 & 0x3F) == 0)

            dst += VAR_0->width * 3;

        dst += 4;

    } while (VAR_4 < VAR_0->video_size / 16);



    opcode_size = bytestream2_get_le16(&VAR_0->gb);

    bytestream2_skip(&VAR_0->gb, 2);



    if (bytestream2_get_bytes_left(&VAR_0->gb) < opcode_size)

        return AVERROR_INVALIDDATA;



    opcodes = VAR_1 + bytestream2_tell(&VAR_0->gb);

    bytestream2_skipu(&VAR_0->gb, opcode_size);



    dst = VAR_0->frame[VAR_0->current_frame];



    for (VAR_4 = 0; VAR_4 < VAR_0->height; VAR_4 += 4, dst += VAR_0->width * 3)

        for (VAR_5 = 0; VAR_5 < VAR_0->width; VAR_5 += 4, dst += 4) {

            int opcode, k = 0;

            if (VAR_6 > opcode_size)

                return AVERROR_INVALIDDATA;

            if (VAR_5 & 4) {

                opcode = opcodes[VAR_6] & 15;

                VAR_6++;

            } else {

                opcode = opcodes[VAR_6] >> 4;

            }



            while (block_sequences[opcode][k]) {

                offset = VAR_0->width * 2;

                VAR_2   = block_sequences[opcode][k++];



                switch (VAR_2) {

                case 2:

                    offset = 0;

                case 3:

                    color = bytestream2_get_byte(&VAR_0->gb);

                case 4:

                    mask = bytestream2_get_byte(&VAR_0->gb);

                    copy_color_mask(dst + offset, VAR_0->width, mask, color);

                    break;

                case 5:

                    offset = 0;

                case 6:

                    set_src_position(VAR_0, &VAR_3, &send);

                case 7:

                    if (VAR_3 + offset + VAR_0->width + 4 > send)

                        return AVERROR_INVALIDDATA;

                    mask = bytestream2_get_byte(&VAR_0->gb);

                    copy_src_mask(dst + offset, VAR_0->width, mask, VAR_3 + offset);

                    break;

                }

            }

        }



    return 0;

}

static int FUNC_0(PAFVideoDecContext *VAR_0, uint8_t *VAR_1, uint8_t VAR_2)
{ uint32_t opcode_size, offset; uint8_t *dst, *dend, mask = 0, color = 0; const uint8_t *VAR_3, *send, *opcodes; int VAR_4, VAR_5, VAR_6 = 0; VAR_4 = bytestream2_get_byte(&VAR_0->gb); if (VAR_4) { if (VAR_2 & 0x10) { int VAR_7; VAR_7 = bytestream2_tell(&VAR_0->gb) & 3; if (VAR_7)
bytestream2_skip(&VAR_0->gb, 4 - VAR_7); } do { int VAR_8, VAR_9, VAR_10, VAR_11; VAR_9    = bytestream2_get_be16(&VAR_0->gb); VAR_8   = VAR_9 >> 14; VAR_10      = (VAR_9 & 0x7F) * 2; VAR_11      = ((VAR_9 >> 7) & 0x7F) * 2; dst    = VAR_0->frame[VAR_8] + VAR_10 + VAR_11 * VAR_0->width; dend   = VAR_0->frame[VAR_8] + VAR_0->frame_size; offset = (VAR_10 & 0x7F) * 2; VAR_5      = bytestream2_get_le16(&VAR_0->gb) + offset; do { offset++; if (dst + 3 * VAR_0->width + 4 > dend)
return AVERROR_INVALIDDATA; read4x4block(VAR_0, dst, VAR_0->width); if ((offset & 0x3F) == 0)
dst += VAR_0->width * 3; dst += 4; } while (offset < VAR_5); } while (--VAR_4); } dst  = VAR_0->frame[VAR_0->current_frame]; dend = VAR_0->frame[VAR_0->current_frame] + VAR_0->frame_size; do { set_src_position(VAR_0, &VAR_3, &send); if ((VAR_3 + 3 * VAR_0->width + 4 > send) ||
(dst + 3 * VAR_0->width + 4 > dend))
return AVERROR_INVALIDDATA; copy_block4(dst, VAR_3, VAR_0->width, VAR_0->width, 4); VAR_4++; if ((VAR_4 & 0x3F) == 0)
dst += VAR_0->width * 3; dst += 4; } while (VAR_4 < VAR_0->video_size / 16); opcode_size = bytestream2_get_le16(&VAR_0->gb); bytestream2_skip(&VAR_0->gb, 2); if (bytestream2_get_bytes_left(&VAR_0->gb) < opcode_size)
return AVERROR_INVALIDDATA; opcodes = VAR_1 + bytestream2_tell(&VAR_0->gb); bytestream2_skipu(&VAR_0->gb, opcode_size); dst = VAR_0->frame[VAR_0->current_frame]; for (VAR_4 = 0; VAR_4 < VAR_0->height; VAR_4 += 4, dst += VAR_0->width * 3) for (VAR_5 = 0; VAR_5 < VAR_0->width; VAR_5 += 4, dst += 4) { int opcode, k = 0; if (VAR_6 > opcode_size)
return AVERROR_INVALIDDATA; if (VAR_5 & 4) { opcode = opcodes[VAR_6] & 15; VAR_6++; } else { opcode = opcodes[VAR_6] >> 4; } while (block_sequences[opcode][k]) { offset = VAR_0->width * 2; VAR_2   = block_sequences[opcode][k++]; switch (VAR_2) { case 2:
offset = 0; case 3:
color = bytestream2_get_byte(&VAR_0->gb); case 4:
mask = bytestream2_get_byte(&VAR_0->gb); copy_color_mask(dst + offset, VAR_0->width, mask, color); break; case 5:
offset = 0; case 6:
set_src_position(VAR_0, &VAR_3, &send); case 7:
if (VAR_3 + offset + VAR_0->width + 4 > send)
return AVERROR_INVALIDDATA; mask = bytestream2_get_byte(&VAR_0->gb); copy_src_mask(dst + offset, VAR_0->width, mask, VAR_3 + offset); break; } } } return 0; }