static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, int * posts, float * floor, int samples) {

    int range = 255 / fc->multiplier + 1;

    int coded[fc->values]; // first 2 values are unused

    int i, counter;

    int lx, ly;



    put_bits(pb, 1, 1); // non zero

    put_bits(pb, ilog(range - 1), posts[0]);

    put_bits(pb, ilog(range - 1), posts[1]);



    for (i = 2; i < fc->values; i++) {

        int predicted = render_point(fc->list[fc->list[i].low].x,

                                     posts[fc->list[i].low],

                                     fc->list[fc->list[i].high].x,

                                     posts[fc->list[i].high],

                                     fc->list[i].x);

        int highroom = range - predicted;

        int lowroom = predicted;

        int room = FFMIN(highroom, lowroom);

        if (predicted == posts[i]) {

            coded[i] = 0; // must be used later as flag!

            continue;

        } else {

            if (!coded[fc->list[i].low]) coded[fc->list[i].low] = -1;

            if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1;

        }

        if (posts[i] > predicted) {

            if (posts[i] - predicted > room) coded[i] = posts[i] - predicted + lowroom;

            else coded[i] = (posts[i] - predicted) << 1;

        } else {

            if (predicted - posts[i] > room) coded[i] = predicted - posts[i] + highroom - 1;

            else coded[i] = ((predicted - posts[i]) << 1) - 1;

        }

    }



    counter = 2;

    for (i = 0; i < fc->partitions; i++) {

        floor_class_t * c = &fc->classes[fc->partition_to_class[i]];

        int k, cval = 0, csub = 1<<c->subclass;

        if (c->subclass) {

            codebook_t * book = &venc->codebooks[c->masterbook];

            int cshift = 0;

            for (k = 0; k < c->dim; k++) {

                int l;

                for (l = 0; l < csub; l++) {

                    int maxval = 1;

                    if (c->books[l] != -1) maxval = venc->codebooks[c->books[l]].nentries;

                    // coded could be -1, but this still works, cause thats 0

                    if (coded[counter + k] < maxval) break;

                }

                assert(l != csub);

                cval |= l << cshift;

                cshift += c->subclass;

            }

            assert(cval < book->nentries);

            put_bits(pb, book->entries[cval].len, book->entries[cval].codeword);

        }

        for (k = 0; k < c->dim; k++) {

            int book = c->books[cval & (csub-1)];

            int entry = coded[counter++];

            cval >>= c->subclass;

            if (book == -1) continue;

            if (entry == -1) entry = 0;

            assert(entry < venc->codebooks[book].nentries);

            assert(entry >= 0);

            put_bits(pb, venc->codebooks[book].entries[entry].len, venc->codebooks[book].entries[entry].codeword);

        }

    }



    lx = 0;

    ly = posts[0] * fc->multiplier; // sorted 0 is still 0

    coded[0] = coded[1] = 1;

    for (i = 1; i < fc->values; i++) {

        int pos = fc->list[i].sort;

        if (coded[pos]) {

            render_line(lx, ly, fc->list[pos].x, posts[pos] * fc->multiplier, floor, samples);

            lx = fc->list[pos].x;

            ly = posts[pos] * fc->multiplier;

        }

        if (lx >= samples) break;

    }

    if (lx < samples) render_line(lx, ly, samples, ly, floor, samples);

}

static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, int * posts, float * floor, int samples) {

    int range = 255 / fc->multiplier + 1;

    int coded[fc->values]; 

    int i, counter;

    int lx, ly;



    put_bits(pb, 1, 1); 

    put_bits(pb, ilog(range - 1), posts[0]);

    put_bits(pb, ilog(range - 1), posts[1]);



    for (i = 2; i < fc->values; i++) {

        int predicted = render_point(fc->list[fc->list[i].low].x,

                                     posts[fc->list[i].low],

                                     fc->list[fc->list[i].high].x,

                                     posts[fc->list[i].high],

                                     fc->list[i].x);

        int highroom = range - predicted;

        int lowroom = predicted;

        int room = FFMIN(highroom, lowroom);

        if (predicted == posts[i]) {

            coded[i] = 0; 

            continue;

        } else {

            if (!coded[fc->list[i].low]) coded[fc->list[i].low] = -1;

            if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1;

        }

        if (posts[i] > predicted) {

            if (posts[i] - predicted > room) coded[i] = posts[i] - predicted + lowroom;

            else coded[i] = (posts[i] - predicted) << 1;

        } else {

            if (predicted - posts[i] > room) coded[i] = predicted - posts[i] + highroom - 1;

            else coded[i] = ((predicted - posts[i]) << 1) - 1;

        }

    }



    counter = 2;

    for (i = 0; i < fc->partitions; i++) {

        floor_class_t * c = &fc->classes[fc->partition_to_class[i]];

        int k, cval = 0, csub = 1<<c->subclass;

        if (c->subclass) {

            codebook_t * book = &venc->codebooks[c->masterbook];

            int cshift = 0;

            for (k = 0; k < c->dim; k++) {

                int l;

                for (l = 0; l < csub; l++) {

                    int maxval = 1;

                    if (c->books[l] != -1) maxval = venc->codebooks[c->books[l]].nentries;

                    

                    if (coded[counter + k] < maxval) break;

                }

                assert(l != csub);

                cval |= l << cshift;

                cshift += c->subclass;

            }

            assert(cval < book->nentries);

            put_bits(pb, book->entries[cval].len, book->entries[cval].codeword);

        }

        for (k = 0; k < c->dim; k++) {

            int book = c->books[cval & (csub-1)];

            int entry = coded[counter++];

            cval >>= c->subclass;

            if (book == -1) continue;

            if (entry == -1) entry = 0;

            assert(entry < venc->codebooks[book].nentries);

            assert(entry >= 0);

            put_bits(pb, venc->codebooks[book].entries[entry].len, venc->codebooks[book].entries[entry].codeword);

        }

    }



    lx = 0;

    ly = posts[0] * fc->multiplier; 

    coded[0] = coded[1] = 1;

    for (i = 1; i < fc->values; i++) {

        int pos = fc->list[i].sort;

        if (coded[pos]) {

            render_line(lx, ly, fc->list[pos].x, posts[pos] * fc->multiplier, floor, samples);

            lx = fc->list[pos].x;

            ly = posts[pos] * fc->multiplier;

        }

        if (lx >= samples) break;

    }

    if (lx < samples) render_line(lx, ly, samples, ly, floor, samples);

}

static void FUNC_0(venc_context_t * VAR_0, floor_t * VAR_1, PutBitContext * VAR_2, int * VAR_3, float * VAR_4, int VAR_5) {

    int VAR_6 = 255 / VAR_1->multiplier + 1;

    int VAR_7[VAR_1->values]; 

    int VAR_8, VAR_9;

    int VAR_10, VAR_11;



    put_bits(VAR_2, 1, 1); 

    put_bits(VAR_2, ilog(VAR_6 - 1), VAR_3[0]);

    put_bits(VAR_2, ilog(VAR_6 - 1), VAR_3[1]);



    for (VAR_8 = 2; VAR_8 < VAR_1->values; VAR_8++) {

        int predicted = render_point(VAR_1->list[VAR_1->list[VAR_8].low].x,

                                     VAR_3[VAR_1->list[VAR_8].low],

                                     VAR_1->list[VAR_1->list[VAR_8].high].x,

                                     VAR_3[VAR_1->list[VAR_8].high],

                                     VAR_1->list[VAR_8].x);

        int highroom = VAR_6 - predicted;

        int lowroom = predicted;

        int room = FFMIN(highroom, lowroom);

        if (predicted == VAR_3[VAR_8]) {

            VAR_7[VAR_8] = 0; 

            continue;

        } else {

            if (!VAR_7[VAR_1->list[VAR_8].low]) VAR_7[VAR_1->list[VAR_8].low] = -1;

            if (!VAR_7[VAR_1->list[VAR_8].high]) VAR_7[VAR_1->list[VAR_8].high] = -1;

        }

        if (VAR_3[VAR_8] > predicted) {

            if (VAR_3[VAR_8] - predicted > room) VAR_7[VAR_8] = VAR_3[VAR_8] - predicted + lowroom;

            else VAR_7[VAR_8] = (VAR_3[VAR_8] - predicted) << 1;

        } else {

            if (predicted - VAR_3[VAR_8] > room) VAR_7[VAR_8] = predicted - VAR_3[VAR_8] + highroom - 1;

            else VAR_7[VAR_8] = ((predicted - VAR_3[VAR_8]) << 1) - 1;

        }

    }



    VAR_9 = 2;

    for (VAR_8 = 0; VAR_8 < VAR_1->partitions; VAR_8++) {

        floor_class_t * c = &VAR_1->classes[VAR_1->partition_to_class[VAR_8]];

        int k, cval = 0, csub = 1<<c->subclass;

        if (c->subclass) {

            codebook_t * book = &VAR_0->codebooks[c->masterbook];

            int cshift = 0;

            for (k = 0; k < c->dim; k++) {

                int l;

                for (l = 0; l < csub; l++) {

                    int maxval = 1;

                    if (c->books[l] != -1) maxval = VAR_0->codebooks[c->books[l]].nentries;

                    

                    if (VAR_7[VAR_9 + k] < maxval) break;

                }

                assert(l != csub);

                cval |= l << cshift;

                cshift += c->subclass;

            }

            assert(cval < book->nentries);

            put_bits(VAR_2, book->entries[cval].len, book->entries[cval].codeword);

        }

        for (k = 0; k < c->dim; k++) {

            int book = c->books[cval & (csub-1)];

            int entry = VAR_7[VAR_9++];

            cval >>= c->subclass;

            if (book == -1) continue;

            if (entry == -1) entry = 0;

            assert(entry < VAR_0->codebooks[book].nentries);

            assert(entry >= 0);

            put_bits(VAR_2, VAR_0->codebooks[book].entries[entry].len, VAR_0->codebooks[book].entries[entry].codeword);

        }

    }



    VAR_10 = 0;

    VAR_11 = VAR_3[0] * VAR_1->multiplier; 

    VAR_7[0] = VAR_7[1] = 1;

    for (VAR_8 = 1; VAR_8 < VAR_1->values; VAR_8++) {

        int pos = VAR_1->list[VAR_8].sort;

        if (VAR_7[pos]) {

            render_line(VAR_10, VAR_11, VAR_1->list[pos].x, VAR_3[pos] * VAR_1->multiplier, VAR_4, VAR_5);

            VAR_10 = VAR_1->list[pos].x;

            VAR_11 = VAR_3[pos] * VAR_1->multiplier;

        }

        if (VAR_10 >= VAR_5) break;

    }

    if (VAR_10 < VAR_5) render_line(VAR_10, VAR_11, VAR_5, VAR_11, VAR_4, VAR_5);

}

static void FUNC_0(venc_context_t * VAR_0, floor_t * VAR_1, PutBitContext * VAR_2, int * VAR_3, float * VAR_4, int VAR_5) { int VAR_6 = 255 / VAR_1->multiplier + 1; int VAR_7[VAR_1->values]; int VAR_8, VAR_9; int VAR_10, VAR_11; put_bits(VAR_2, 1, 1); put_bits(VAR_2, ilog(VAR_6 - 1), VAR_3[0]); put_bits(VAR_2, ilog(VAR_6 - 1), VAR_3[1]); for (VAR_8 = 2; VAR_8 < VAR_1->values; VAR_8++) { int predicted = render_point(VAR_1->list[VAR_1->list[VAR_8].low].x,
VAR_3[VAR_1->list[VAR_8].low],
VAR_1->list[VAR_1->list[VAR_8].high].x,
VAR_3[VAR_1->list[VAR_8].high],
VAR_1->list[VAR_8].x); int highroom = VAR_6 - predicted; int lowroom = predicted; int room = FFMIN(highroom, lowroom); if (predicted == VAR_3[VAR_8]) { VAR_7[VAR_8] = 0; continue; } else { if (!VAR_7[VAR_1->list[VAR_8].low]) VAR_7[VAR_1->list[VAR_8].low] = -1; if (!VAR_7[VAR_1->list[VAR_8].high]) VAR_7[VAR_1->list[VAR_8].high] = -1; } if (VAR_3[VAR_8] > predicted) { if (VAR_3[VAR_8] - predicted > room) VAR_7[VAR_8] = VAR_3[VAR_8] - predicted + lowroom; else VAR_7[VAR_8] = (VAR_3[VAR_8] - predicted) << 1; } else { if (predicted - VAR_3[VAR_8] > room) VAR_7[VAR_8] = predicted - VAR_3[VAR_8] + highroom - 1; else VAR_7[VAR_8] = ((predicted - VAR_3[VAR_8]) << 1) - 1; } } VAR_9 = 2; for (VAR_8 = 0; VAR_8 < VAR_1->partitions; VAR_8++) { floor_class_t * c = &VAR_1->classes[VAR_1->partition_to_class[VAR_8]]; int k, cval = 0, csub = 1<<c->subclass; if (c->subclass) { codebook_t * book = &VAR_0->codebooks[c->masterbook]; int cshift = 0; for (k = 0; k < c->dim; k++) { int l; for (l = 0; l < csub; l++) { int maxval = 1; if (c->books[l] != -1) maxval = VAR_0->codebooks[c->books[l]].nentries; if (VAR_7[VAR_9 + k] < maxval) break; } assert(l != csub); cval |= l << cshift; cshift += c->subclass; } assert(cval < book->nentries); put_bits(VAR_2, book->entries[cval].len, book->entries[cval].codeword); } for (k = 0; k < c->dim; k++) { int book = c->books[cval & (csub-1)]; int entry = VAR_7[VAR_9++]; cval >>= c->subclass; if (book == -1) continue; if (entry == -1) entry = 0; assert(entry < VAR_0->codebooks[book].nentries); assert(entry >= 0); put_bits(VAR_2, VAR_0->codebooks[book].entries[entry].len, VAR_0->codebooks[book].entries[entry].codeword); } } VAR_10 = 0; VAR_11 = VAR_3[0] * VAR_1->multiplier; VAR_7[0] = VAR_7[1] = 1; for (VAR_8 = 1; VAR_8 < VAR_1->values; VAR_8++) { int pos = VAR_1->list[VAR_8].sort; if (VAR_7[pos]) { render_line(VAR_10, VAR_11, VAR_1->list[pos].x, VAR_3[pos] * VAR_1->multiplier, VAR_4, VAR_5); VAR_10 = VAR_1->list[pos].x; VAR_11 = VAR_3[pos] * VAR_1->multiplier; } if (VAR_10 >= VAR_5) break; } if (VAR_10 < VAR_5) render_line(VAR_10, VAR_11, VAR_5, VAR_11, VAR_4, VAR_5); }