static int kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int src_size, int w, int h)

{

    BitBuf bb;

    int res, val;

    int i, j;

    int bx, by;

    int l0x, l1x, l0y, l1y;

    int mx, my;

    const uint8_t *src_end = src + src_size;



    kmvc_init_getbits(bb, src);



    for (by = 0; by < h; by += 8)

        for (bx = 0; bx < w; bx += 8) {

            kmvc_getbit(bb, src, src_end, res);

            if (!res) {         // fill whole 8x8 block

                if (src >= src_end) {

                    av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                    return AVERROR_INVALIDDATA;

                }

                val = *src++;

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

                    BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;

            } else {            // handle four 4x4 subblocks

                for (i = 0; i < 4; i++) {

                    l0x = bx + (i & 1) * 4;

                    l0y = by + (i & 2) * 2;

                    kmvc_getbit(bb, src, src_end, res);

                    if (!res) {

                        kmvc_getbit(bb, src, src_end, res);

                        if (!res) {     // fill whole 4x4 block

                            if (src >= src_end) {

                                av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                return AVERROR_INVALIDDATA;

                            }

                            val = *src++;

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

                                BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;

                        } else {        // copy block from already decoded place

                            if (src >= src_end) {

                                av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                return AVERROR_INVALIDDATA;

                            }

                            val = *src++;

                            mx = val & 0xF;

                            my = val >> 4;

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

                                BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =

                                    BLK(ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);

                        }

                    } else {    // descend to 2x2 sub-sub-blocks

                        for (j = 0; j < 4; j++) {

                            l1x = l0x + (j & 1) * 2;

                            l1y = l0y + (j & 2);

                            kmvc_getbit(bb, src, src_end, res);

                            if (!res) {

                                kmvc_getbit(bb, src, src_end, res);

                                if (!res) {     // fill whole 2x2 block

                                    if (src >= src_end) {

                                        av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                        return AVERROR_INVALIDDATA;

                                    }

                                    val = *src++;

                                    BLK(ctx->cur, l1x, l1y) = val;

                                    BLK(ctx->cur, l1x + 1, l1y) = val;

                                    BLK(ctx->cur, l1x, l1y + 1) = val;

                                    BLK(ctx->cur, l1x + 1, l1y + 1) = val;

                                } else {        // copy block from already decoded place

                                    if (src >= src_end) {

                                        av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                        return AVERROR_INVALIDDATA;

                                    }

                                    val = *src++;

                                    mx = val & 0xF;

                                    my = val >> 4;

                                    BLK(ctx->cur, l1x, l1y) = BLK(ctx->cur, l1x - mx, l1y - my);

                                    BLK(ctx->cur, l1x + 1, l1y) =

                                        BLK(ctx->cur, l1x + 1 - mx, l1y - my);

                                    BLK(ctx->cur, l1x, l1y + 1) =

                                        BLK(ctx->cur, l1x - mx, l1y + 1 - my);

                                    BLK(ctx->cur, l1x + 1, l1y + 1) =

                                        BLK(ctx->cur, l1x + 1 - mx, l1y + 1 - my);

                                }

                            } else {    // read values for block

                                BLK(ctx->cur, l1x, l1y) = *src++;

                                BLK(ctx->cur, l1x + 1, l1y) = *src++;

                                BLK(ctx->cur, l1x, l1y + 1) = *src++;

                                BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;

                            }

                        }

                    }

                }

            }

        }



    return 0;

}

static int kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int src_size, int w, int h)

{

    BitBuf bb;

    int res, val;

    int i, j;

    int bx, by;

    int l0x, l1x, l0y, l1y;

    int mx, my;

    const uint8_t *src_end = src + src_size;



    kmvc_init_getbits(bb, src);



    for (by = 0; by < h; by += 8)

        for (bx = 0; bx < w; bx += 8) {

            kmvc_getbit(bb, src, src_end, res);

            if (!res) {         

                if (src >= src_end) {

                    av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                    return AVERROR_INVALIDDATA;

                }

                val = *src++;

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

                    BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;

            } else {            

                for (i = 0; i < 4; i++) {

                    l0x = bx + (i & 1) * 4;

                    l0y = by + (i & 2) * 2;

                    kmvc_getbit(bb, src, src_end, res);

                    if (!res) {

                        kmvc_getbit(bb, src, src_end, res);

                        if (!res) {     

                            if (src >= src_end) {

                                av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                return AVERROR_INVALIDDATA;

                            }

                            val = *src++;

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

                                BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;

                        } else {        

                            if (src >= src_end) {

                                av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                return AVERROR_INVALIDDATA;

                            }

                            val = *src++;

                            mx = val & 0xF;

                            my = val >> 4;

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

                                BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =

                                    BLK(ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);

                        }

                    } else {    

                        for (j = 0; j < 4; j++) {

                            l1x = l0x + (j & 1) * 2;

                            l1y = l0y + (j & 2);

                            kmvc_getbit(bb, src, src_end, res);

                            if (!res) {

                                kmvc_getbit(bb, src, src_end, res);

                                if (!res) {     

                                    if (src >= src_end) {

                                        av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                        return AVERROR_INVALIDDATA;

                                    }

                                    val = *src++;

                                    BLK(ctx->cur, l1x, l1y) = val;

                                    BLK(ctx->cur, l1x + 1, l1y) = val;

                                    BLK(ctx->cur, l1x, l1y + 1) = val;

                                    BLK(ctx->cur, l1x + 1, l1y + 1) = val;

                                } else {        

                                    if (src >= src_end) {

                                        av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");

                                        return AVERROR_INVALIDDATA;

                                    }

                                    val = *src++;

                                    mx = val & 0xF;

                                    my = val >> 4;

                                    BLK(ctx->cur, l1x, l1y) = BLK(ctx->cur, l1x - mx, l1y - my);

                                    BLK(ctx->cur, l1x + 1, l1y) =

                                        BLK(ctx->cur, l1x + 1 - mx, l1y - my);

                                    BLK(ctx->cur, l1x, l1y + 1) =

                                        BLK(ctx->cur, l1x - mx, l1y + 1 - my);

                                    BLK(ctx->cur, l1x + 1, l1y + 1) =

                                        BLK(ctx->cur, l1x + 1 - mx, l1y + 1 - my);

                                }

                            } else {    

                                BLK(ctx->cur, l1x, l1y) = *src++;

                                BLK(ctx->cur, l1x + 1, l1y) = *src++;

                                BLK(ctx->cur, l1x, l1y + 1) = *src++;

                                BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;

                            }

                        }

                    }

                }

            }

        }



    return 0;

}

static int kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int src_size, int w, int h)     const uint8_t *src_end = src + src_size;     kmvc_init_getbits(bb, src);             kmvc_getbit(bb, src, src_end, res);                 if (src >= src_end) {                     av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                     return AVERROR_INVALIDDATA;                 val = *src++;                     kmvc_getbit(bb, src, src_end, res);                         kmvc_getbit(bb, src, src_end, res);                             if (src >= src_end) {                                 av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                 return AVERROR_INVALIDDATA;                             val = *src++;                             if (src >= src_end) {                                 av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                 return AVERROR_INVALIDDATA;                             val = *src++;                             kmvc_getbit(bb, src, src_end, res);                                 kmvc_getbit(bb, src, src_end, res);                                     if (src >= src_end) {                                         av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                         return AVERROR_INVALIDDATA;                                     val = *src++;                                     if (src >= src_end) {                                         av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                         return AVERROR_INVALIDDATA;                                     val = *src++;                                 BLK(ctx->cur, l1x, l1y) = *src++;                                 BLK(ctx->cur, l1x + 1, l1y) = *src++;                                 BLK(ctx->cur, l1x, l1y + 1) = *src++;                                 BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;     const uint8_t *src_end = src + src_size;     kmvc_init_getbits(bb, src);             kmvc_getbit(bb, src, src_end, res);                     kmvc_getbit(bb, src, src_end, res);                         kmvc_getbit(bb, src, src_end, res);                             if (src >= src_end) {                                 av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                 return AVERROR_INVALIDDATA;                             val = *src++;                             if (src >= src_end) {                                 av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                 return AVERROR_INVALIDDATA;                             val = *src++;                             kmvc_getbit(bb, src, src_end, res);                                 kmvc_getbit(bb, src, src_end, res);                                     if (src >= src_end) {                                         av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                         return AVERROR_INVALIDDATA;                                     val = *src++;                                     if (src >= src_end) {                                         av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n");                                         return AVERROR_INVALIDDATA;                                     val = *src++;                                 BLK(ctx->cur, l1x, l1y) = *src++;                                 BLK(ctx->cur, l1x + 1, l1y) = *src++;                                 BLK(ctx->cur, l1x, l1y + 1) = *src++;                                 BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;
static int FUNC_0(KmvcContext * VAR_0, const uint8_t * VAR_1, int VAR_2, int VAR_3, int VAR_4)

{

    BitBuf bb;

    int VAR_5, VAR_6;

    int VAR_7, VAR_8;

    int VAR_9, VAR_10;

    int VAR_11, VAR_12, VAR_13, VAR_14;

    int VAR_15, VAR_16;

    const uint8_t *VAR_17 = VAR_1 + VAR_2;



    kmvc_init_getbits(bb, VAR_1);



    for (VAR_10 = 0; VAR_10 < VAR_4; VAR_10 += 8)

        for (VAR_9 = 0; VAR_9 < VAR_3; VAR_9 += 8) {

            kmvc_getbit(bb, VAR_1, VAR_17, VAR_5);

            if (!VAR_5) {         

                if (VAR_1 >= VAR_17) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n");

                    return AVERROR_INVALIDDATA;

                }

                VAR_6 = *VAR_1++;

                for (VAR_7 = 0; VAR_7 < 64; VAR_7++)

                    BLK(VAR_0->cur, VAR_9 + (VAR_7 & 0x7), VAR_10 + (VAR_7 >> 3)) = VAR_6;

            } else {            

                for (VAR_7 = 0; VAR_7 < 4; VAR_7++) {

                    VAR_11 = VAR_9 + (VAR_7 & 1) * 4;

                    VAR_13 = VAR_10 + (VAR_7 & 2) * 2;

                    kmvc_getbit(bb, VAR_1, VAR_17, VAR_5);

                    if (!VAR_5) {

                        kmvc_getbit(bb, VAR_1, VAR_17, VAR_5);

                        if (!VAR_5) {     

                            if (VAR_1 >= VAR_17) {

                                av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n");

                                return AVERROR_INVALIDDATA;

                            }

                            VAR_6 = *VAR_1++;

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

                                BLK(VAR_0->cur, VAR_11 + (VAR_8 & 3), VAR_13 + (VAR_8 >> 2)) = VAR_6;

                        } else {        

                            if (VAR_1 >= VAR_17) {

                                av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n");

                                return AVERROR_INVALIDDATA;

                            }

                            VAR_6 = *VAR_1++;

                            VAR_15 = VAR_6 & 0xF;

                            VAR_16 = VAR_6 >> 4;

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

                                BLK(VAR_0->cur, VAR_11 + (VAR_8 & 3), VAR_13 + (VAR_8 >> 2)) =

                                    BLK(VAR_0->cur, VAR_11 + (VAR_8 & 3) - VAR_15, VAR_13 + (VAR_8 >> 2) - VAR_16);

                        }

                    } else {    

                        for (VAR_8 = 0; VAR_8 < 4; VAR_8++) {

                            VAR_12 = VAR_11 + (VAR_8 & 1) * 2;

                            VAR_14 = VAR_13 + (VAR_8 & 2);

                            kmvc_getbit(bb, VAR_1, VAR_17, VAR_5);

                            if (!VAR_5) {

                                kmvc_getbit(bb, VAR_1, VAR_17, VAR_5);

                                if (!VAR_5) {     

                                    if (VAR_1 >= VAR_17) {

                                        av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n");

                                        return AVERROR_INVALIDDATA;

                                    }

                                    VAR_6 = *VAR_1++;

                                    BLK(VAR_0->cur, VAR_12, VAR_14) = VAR_6;

                                    BLK(VAR_0->cur, VAR_12 + 1, VAR_14) = VAR_6;

                                    BLK(VAR_0->cur, VAR_12, VAR_14 + 1) = VAR_6;

                                    BLK(VAR_0->cur, VAR_12 + 1, VAR_14 + 1) = VAR_6;

                                } else {        

                                    if (VAR_1 >= VAR_17) {

                                        av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n");

                                        return AVERROR_INVALIDDATA;

                                    }

                                    VAR_6 = *VAR_1++;

                                    VAR_15 = VAR_6 & 0xF;

                                    VAR_16 = VAR_6 >> 4;

                                    BLK(VAR_0->cur, VAR_12, VAR_14) = BLK(VAR_0->cur, VAR_12 - VAR_15, VAR_14 - VAR_16);

                                    BLK(VAR_0->cur, VAR_12 + 1, VAR_14) =

                                        BLK(VAR_0->cur, VAR_12 + 1 - VAR_15, VAR_14 - VAR_16);

                                    BLK(VAR_0->cur, VAR_12, VAR_14 + 1) =

                                        BLK(VAR_0->cur, VAR_12 - VAR_15, VAR_14 + 1 - VAR_16);

                                    BLK(VAR_0->cur, VAR_12 + 1, VAR_14 + 1) =

                                        BLK(VAR_0->cur, VAR_12 + 1 - VAR_15, VAR_14 + 1 - VAR_16);

                                }

                            } else {    

                                BLK(VAR_0->cur, VAR_12, VAR_14) = *VAR_1++;

                                BLK(VAR_0->cur, VAR_12 + 1, VAR_14) = *VAR_1++;

                                BLK(VAR_0->cur, VAR_12, VAR_14 + 1) = *VAR_1++;

                                BLK(VAR_0->cur, VAR_12 + 1, VAR_14 + 1) = *VAR_1++;

                            }

                        }

                    }

                }

            }

        }



    return 0;

}

static int FUNC_0(KmvcContext * VAR_0, const uint8_t * VAR_1, int VAR_2, int VAR_3, int VAR_4)
{ BitBuf bb; int VAR_5, VAR_6; int VAR_7, VAR_8; int VAR_9, VAR_10; int VAR_11, VAR_12, VAR_13, VAR_14; int VAR_15, VAR_16; const uint8_t *VAR_17 = VAR_1 + VAR_2; kmvc_init_getbits(bb, VAR_1); for (VAR_10 = 0; VAR_10 < VAR_4; VAR_10 += 8) for (VAR_9 = 0; VAR_9 < VAR_3; VAR_9 += 8) { kmvc_getbit(bb, VAR_1, VAR_17, VAR_5); if (!VAR_5) { if (VAR_1 >= VAR_17) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n"); return AVERROR_INVALIDDATA; } VAR_6 = *VAR_1++; for (VAR_7 = 0; VAR_7 < 64; VAR_7++) BLK(VAR_0->cur, VAR_9 + (VAR_7 & 0x7), VAR_10 + (VAR_7 >> 3)) = VAR_6; } else { for (VAR_7 = 0; VAR_7 < 4; VAR_7++) { VAR_11 = VAR_9 + (VAR_7 & 1) * 4; VAR_13 = VAR_10 + (VAR_7 & 2) * 2; kmvc_getbit(bb, VAR_1, VAR_17, VAR_5); if (!VAR_5) { kmvc_getbit(bb, VAR_1, VAR_17, VAR_5); if (!VAR_5) { if (VAR_1 >= VAR_17) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n"); return AVERROR_INVALIDDATA; } VAR_6 = *VAR_1++; for (VAR_8 = 0; VAR_8 < 16; VAR_8++) BLK(VAR_0->cur, VAR_11 + (VAR_8 & 3), VAR_13 + (VAR_8 >> 2)) = VAR_6; } else { if (VAR_1 >= VAR_17) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n"); return AVERROR_INVALIDDATA; } VAR_6 = *VAR_1++; VAR_15 = VAR_6 & 0xF; VAR_16 = VAR_6 >> 4; for (VAR_8 = 0; VAR_8 < 16; VAR_8++) BLK(VAR_0->cur, VAR_11 + (VAR_8 & 3), VAR_13 + (VAR_8 >> 2)) =
BLK(VAR_0->cur, VAR_11 + (VAR_8 & 3) - VAR_15, VAR_13 + (VAR_8 >> 2) - VAR_16); } } else { for (VAR_8 = 0; VAR_8 < 4; VAR_8++) { VAR_12 = VAR_11 + (VAR_8 & 1) * 2; VAR_14 = VAR_13 + (VAR_8 & 2); kmvc_getbit(bb, VAR_1, VAR_17, VAR_5); if (!VAR_5) { kmvc_getbit(bb, VAR_1, VAR_17, VAR_5); if (!VAR_5) { if (VAR_1 >= VAR_17) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n"); return AVERROR_INVALIDDATA; } VAR_6 = *VAR_1++; BLK(VAR_0->cur, VAR_12, VAR_14) = VAR_6; BLK(VAR_0->cur, VAR_12 + 1, VAR_14) = VAR_6; BLK(VAR_0->cur, VAR_12, VAR_14 + 1) = VAR_6; BLK(VAR_0->cur, VAR_12 + 1, VAR_14 + 1) = VAR_6; } else { if (VAR_1 >= VAR_17) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Data overrun\n"); return AVERROR_INVALIDDATA; } VAR_6 = *VAR_1++; VAR_15 = VAR_6 & 0xF; VAR_16 = VAR_6 >> 4; BLK(VAR_0->cur, VAR_12, VAR_14) = BLK(VAR_0->cur, VAR_12 - VAR_15, VAR_14 - VAR_16); BLK(VAR_0->cur, VAR_12 + 1, VAR_14) =
BLK(VAR_0->cur, VAR_12 + 1 - VAR_15, VAR_14 - VAR_16); BLK(VAR_0->cur, VAR_12, VAR_14 + 1) =
BLK(VAR_0->cur, VAR_12 - VAR_15, VAR_14 + 1 - VAR_16); BLK(VAR_0->cur, VAR_12 + 1, VAR_14 + 1) =
BLK(VAR_0->cur, VAR_12 + 1 - VAR_15, VAR_14 + 1 - VAR_16); } } else { BLK(VAR_0->cur, VAR_12, VAR_14) = *VAR_1++; BLK(VAR_0->cur, VAR_12 + 1, VAR_14) = *VAR_1++; BLK(VAR_0->cur, VAR_12, VAR_14 + 1) = *VAR_1++; BLK(VAR_0->cur, VAR_12 + 1, VAR_14 + 1) = *VAR_1++; } } } } } } return 0; }