static int decode_format80(VqaContext *s, int src_size,

    unsigned char *dest, int dest_size, int check_size) {



    int dest_index = 0;

    int count, opcode, start;

    int src_pos;

    unsigned char color;

    int i;



    start = bytestream2_tell(&s->gb);

    while (bytestream2_tell(&s->gb) - start < src_size) {

        opcode = bytestream2_get_byte(&s->gb);

        av_dlog(s->avctx, "opcode %02X: ", opcode);



        /* 0x80 means that frame is finished */

        if (opcode == 0x80)

            break;



        if (dest_index >= dest_size) {

            av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\n",

                dest_index, dest_size);

            return AVERROR_INVALIDDATA;

        }



        if (opcode == 0xFF) {



            count   = bytestream2_get_le16(&s->gb);

            src_pos = bytestream2_get_le16(&s->gb);

            av_dlog(s->avctx, "(1) copy %X bytes from absolute pos %X\n", count, src_pos);

            CHECK_COUNT();

            CHECK_COPY(src_pos);

            for (i = 0; i < count; i++)

                dest[dest_index + i] = dest[src_pos + i];

            dest_index += count;



        } else if (opcode == 0xFE) {



            count = bytestream2_get_le16(&s->gb);

            color = bytestream2_get_byte(&s->gb);

            av_dlog(s->avctx, "(2) set %X bytes to %02X\n", count, color);

            CHECK_COUNT();

            memset(&dest[dest_index], color, count);

            dest_index += count;



        } else if ((opcode & 0xC0) == 0xC0) {



            count = (opcode & 0x3F) + 3;

            src_pos = bytestream2_get_le16(&s->gb);

            av_dlog(s->avctx, "(3) copy %X bytes from absolute pos %X\n", count, src_pos);

            CHECK_COUNT();

            CHECK_COPY(src_pos);

            for (i = 0; i < count; i++)

                dest[dest_index + i] = dest[src_pos + i];

            dest_index += count;



        } else if (opcode > 0x80) {



            count = opcode & 0x3F;

            av_dlog(s->avctx, "(4) copy %X bytes from source to dest\n", count);

            CHECK_COUNT();

            bytestream2_get_buffer(&s->gb, &dest[dest_index], count);

            dest_index += count;



        } else {



            count = ((opcode & 0x70) >> 4) + 3;

            src_pos = bytestream2_get_byte(&s->gb) | ((opcode & 0x0F) << 8);

            av_dlog(s->avctx, "(5) copy %X bytes from relpos %X\n", count, src_pos);

            CHECK_COUNT();

            CHECK_COPY(dest_index - src_pos);

            for (i = 0; i < count; i++)

                dest[dest_index + i] = dest[dest_index - src_pos + i];

            dest_index += count;

        }

    }



    /* validate that the entire destination buffer was filled; this is

     * important for decoding frame maps since each vector needs to have a

     * codebook entry; it is not important for compressed codebooks because

     * not every entry needs to be filled */

    if (check_size)

        if (dest_index < dest_size)

            av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",

                dest_index, dest_size);



    return 0; // let's display what we decoded anyway

}

static int decode_format80(VqaContext *s, int src_size,

    unsigned char *dest, int dest_size, int check_size) {



    int dest_index = 0;

    int count, opcode, start;

    int src_pos;

    unsigned char color;

    int i;



    start = bytestream2_tell(&s->gb);

    while (bytestream2_tell(&s->gb) - start < src_size) {

        opcode = bytestream2_get_byte(&s->gb);

        av_dlog(s->avctx, "opcode %02X: ", opcode);



        

        if (opcode == 0x80)

            break;



        if (dest_index >= dest_size) {

            av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\n",

                dest_index, dest_size);

            return AVERROR_INVALIDDATA;

        }



        if (opcode == 0xFF) {



            count   = bytestream2_get_le16(&s->gb);

            src_pos = bytestream2_get_le16(&s->gb);

            av_dlog(s->avctx, "(1) copy %X bytes from absolute pos %X\n", count, src_pos);

            CHECK_COUNT();

            CHECK_COPY(src_pos);

            for (i = 0; i < count; i++)

                dest[dest_index + i] = dest[src_pos + i];

            dest_index += count;



        } else if (opcode == 0xFE) {



            count = bytestream2_get_le16(&s->gb);

            color = bytestream2_get_byte(&s->gb);

            av_dlog(s->avctx, "(2) set %X bytes to %02X\n", count, color);

            CHECK_COUNT();

            memset(&dest[dest_index], color, count);

            dest_index += count;



        } else if ((opcode & 0xC0) == 0xC0) {



            count = (opcode & 0x3F) + 3;

            src_pos = bytestream2_get_le16(&s->gb);

            av_dlog(s->avctx, "(3) copy %X bytes from absolute pos %X\n", count, src_pos);

            CHECK_COUNT();

            CHECK_COPY(src_pos);

            for (i = 0; i < count; i++)

                dest[dest_index + i] = dest[src_pos + i];

            dest_index += count;



        } else if (opcode > 0x80) {



            count = opcode & 0x3F;

            av_dlog(s->avctx, "(4) copy %X bytes from source to dest\n", count);

            CHECK_COUNT();

            bytestream2_get_buffer(&s->gb, &dest[dest_index], count);

            dest_index += count;



        } else {



            count = ((opcode & 0x70) >> 4) + 3;

            src_pos = bytestream2_get_byte(&s->gb) | ((opcode & 0x0F) << 8);

            av_dlog(s->avctx, "(5) copy %X bytes from relpos %X\n", count, src_pos);

            CHECK_COUNT();

            CHECK_COPY(dest_index - src_pos);

            for (i = 0; i < count; i++)

                dest[dest_index + i] = dest[dest_index - src_pos + i];

            dest_index += count;

        }

    }



    







    if (check_size)

        if (dest_index < dest_size)

            av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",

                dest_index, dest_size);



    return 0; 

}

        if (dest_index < dest_size)
static int FUNC_0(VqaContext *VAR_0, int VAR_1,

    unsigned char *VAR_2, int VAR_3, int VAR_4) {



    int VAR_5 = 0;

    int VAR_6, VAR_7, VAR_8;

    int VAR_9;

    unsigned char VAR_10;

    int VAR_11;



    VAR_8 = bytestream2_tell(&VAR_0->gb);

    while (bytestream2_tell(&VAR_0->gb) - VAR_8 < VAR_1) {

        VAR_7 = bytestream2_get_byte(&VAR_0->gb);

        av_dlog(VAR_0->avctx, "VAR_7 %02X: ", VAR_7);



        

        if (VAR_7 == 0x80)

            break;



        if (VAR_5 >= VAR_3) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "FUNC_0 problem: VAR_5 (%d) exceeded VAR_3 (%d)\n",

                VAR_5, VAR_3);

            return AVERROR_INVALIDDATA;

        }



        if (VAR_7 == 0xFF) {



            VAR_6   = bytestream2_get_le16(&VAR_0->gb);

            VAR_9 = bytestream2_get_le16(&VAR_0->gb);

            av_dlog(VAR_0->avctx, "(1) copy %X bytes from absolute pos %X\n", VAR_6, VAR_9);

            CHECK_COUNT();

            CHECK_COPY(VAR_9);

            for (VAR_11 = 0; VAR_11 < VAR_6; VAR_11++)

                VAR_2[VAR_5 + VAR_11] = VAR_2[VAR_9 + VAR_11];

            VAR_5 += VAR_6;



        } else if (VAR_7 == 0xFE) {



            VAR_6 = bytestream2_get_le16(&VAR_0->gb);

            VAR_10 = bytestream2_get_byte(&VAR_0->gb);

            av_dlog(VAR_0->avctx, "(2) set %X bytes to %02X\n", VAR_6, VAR_10);

            CHECK_COUNT();

            memset(&VAR_2[VAR_5], VAR_10, VAR_6);

            VAR_5 += VAR_6;



        } else if ((VAR_7 & 0xC0) == 0xC0) {



            VAR_6 = (VAR_7 & 0x3F) + 3;

            VAR_9 = bytestream2_get_le16(&VAR_0->gb);

            av_dlog(VAR_0->avctx, "(3) copy %X bytes from absolute pos %X\n", VAR_6, VAR_9);

            CHECK_COUNT();

            CHECK_COPY(VAR_9);

            for (VAR_11 = 0; VAR_11 < VAR_6; VAR_11++)

                VAR_2[VAR_5 + VAR_11] = VAR_2[VAR_9 + VAR_11];

            VAR_5 += VAR_6;



        } else if (VAR_7 > 0x80) {



            VAR_6 = VAR_7 & 0x3F;

            av_dlog(VAR_0->avctx, "(4) copy %X bytes from source to VAR_2\n", VAR_6);

            CHECK_COUNT();

            bytestream2_get_buffer(&VAR_0->gb, &VAR_2[VAR_5], VAR_6);

            VAR_5 += VAR_6;



        } else {



            VAR_6 = ((VAR_7 & 0x70) >> 4) + 3;

            VAR_9 = bytestream2_get_byte(&VAR_0->gb) | ((VAR_7 & 0x0F) << 8);

            av_dlog(VAR_0->avctx, "(5) copy %X bytes from relpos %X\n", VAR_6, VAR_9);

            CHECK_COUNT();

            CHECK_COPY(VAR_5 - VAR_9);

            for (VAR_11 = 0; VAR_11 < VAR_6; VAR_11++)

                VAR_2[VAR_5 + VAR_11] = VAR_2[VAR_5 - VAR_9 + VAR_11];

            VAR_5 += VAR_6;

        }

    }



    







    if (VAR_4)

        if (VAR_5 < VAR_3)

            av_log(VAR_0->avctx, AV_LOG_ERROR, "FUNC_0 problem: decode finished with VAR_5 (%d) < VAR_3 (%d)\n",

                VAR_5, VAR_3);



    return 0; 

}

static int FUNC_0(VqaContext *VAR_0, int VAR_1,
unsigned char *VAR_2, int VAR_3, int VAR_4) { int VAR_5 = 0; int VAR_6, VAR_7, VAR_8; int VAR_9; unsigned char VAR_10; int VAR_11; VAR_8 = bytestream2_tell(&VAR_0->gb); while (bytestream2_tell(&VAR_0->gb) - VAR_8 < VAR_1) { VAR_7 = bytestream2_get_byte(&VAR_0->gb); av_dlog(VAR_0->avctx, "VAR_7 %02X: ", VAR_7); if (VAR_7 == 0x80)
break; if (VAR_5 >= VAR_3) { av_log(VAR_0->avctx, AV_LOG_ERROR, "FUNC_0 problem: VAR_5 (%d) exceeded VAR_3 (%d)\n",
VAR_5, VAR_3); return AVERROR_INVALIDDATA; } if (VAR_7 == 0xFF) { VAR_6   = bytestream2_get_le16(&VAR_0->gb); VAR_9 = bytestream2_get_le16(&VAR_0->gb); av_dlog(VAR_0->avctx, "(1) copy %X bytes from absolute pos %X\n", VAR_6, VAR_9); CHECK_COUNT(); CHECK_COPY(VAR_9); for (VAR_11 = 0; VAR_11 < VAR_6; VAR_11++) VAR_2[VAR_5 + VAR_11] = VAR_2[VAR_9 + VAR_11]; VAR_5 += VAR_6; } else if (VAR_7 == 0xFE) { VAR_6 = bytestream2_get_le16(&VAR_0->gb); VAR_10 = bytestream2_get_byte(&VAR_0->gb); av_dlog(VAR_0->avctx, "(2) set %X bytes to %02X\n", VAR_6, VAR_10); CHECK_COUNT(); memset(&VAR_2[VAR_5], VAR_10, VAR_6); VAR_5 += VAR_6; } else if ((VAR_7 & 0xC0) == 0xC0) { VAR_6 = (VAR_7 & 0x3F) + 3; VAR_9 = bytestream2_get_le16(&VAR_0->gb); av_dlog(VAR_0->avctx, "(3) copy %X bytes from absolute pos %X\n", VAR_6, VAR_9); CHECK_COUNT(); CHECK_COPY(VAR_9); for (VAR_11 = 0; VAR_11 < VAR_6; VAR_11++) VAR_2[VAR_5 + VAR_11] = VAR_2[VAR_9 + VAR_11]; VAR_5 += VAR_6; } else if (VAR_7 > 0x80) { VAR_6 = VAR_7 & 0x3F; av_dlog(VAR_0->avctx, "(4) copy %X bytes from source to VAR_2\n", VAR_6); CHECK_COUNT(); bytestream2_get_buffer(&VAR_0->gb, &VAR_2[VAR_5], VAR_6); VAR_5 += VAR_6; } else { VAR_6 = ((VAR_7 & 0x70) >> 4) + 3; VAR_9 = bytestream2_get_byte(&VAR_0->gb) | ((VAR_7 & 0x0F) << 8); av_dlog(VAR_0->avctx, "(5) copy %X bytes from relpos %X\n", VAR_6, VAR_9); CHECK_COUNT(); CHECK_COPY(VAR_5 - VAR_9); for (VAR_11 = 0; VAR_11 < VAR_6; VAR_11++) VAR_2[VAR_5 + VAR_11] = VAR_2[VAR_5 - VAR_9 + VAR_11]; VAR_5 += VAR_6; } } if (VAR_4)
if (VAR_5 < VAR_3)
av_log(VAR_0->avctx, AV_LOG_ERROR, "FUNC_0 problem: decode finished with VAR_5 (%d) < VAR_3 (%d)\n",
VAR_5, VAR_3); return 0; }