Exemplo n.º 1
0
    void save_bucket(const ColorBucket &b, SimpleSymbolCoder<FLIFBitChanceMeta, RacOut<IO>, 18> &coder, const ColorRanges *srcRanges, const int plane, const prevPlanes &pixelL, const prevPlanes &pixelU) const {
        if (plane<3)
        for (int p=0; p<plane; p++) {
                if (!cb->exists(p,pixelL,pixelU)) {
                        if (!b.empty()) {printf("\nBucket does not exist but is not empty!\n"); assert(false);}
                        return;
                }
        }
        ColorVal smin,smax;
        minmax(srcRanges,plane,pixelL,pixelU,smin,smax);

        if (b.min > b.max) {
                coder.write_int(0, 1, 0);  // empty bucket
                return;
        } else coder.write_int(0, 1, 1);  // non-empty bucket
        if (smin==smax) { return;}


        coder.write_int(smin, smax, b.min);
        coder.write_int(b.min, smax, b.max);
        if (b.min == b.max) return;  // singleton bucket
        if (b.min + 1  == b.max) return; // bucket contains two consecutive values
        coder.write_int(0, 1, b.discrete);
        if (b.discrete) {
           assert((int)b.values.size() < b.max-b.min+1); // no discrete buckets that are completely full
           coder.write_int(2, std::min((int)max_per_colorbucket[plane],b.max-b.min), b.values.size());
           ColorVal v=b.min;
           int nb = b.values.size();
           for (int p=1; p < nb - 1; p++) {
               coder.write_int(v+1, b.max+1-nb+p, b.values[p]);
               v = b.values[p];
           }
        }
    }
Exemplo n.º 2
0
    const ColorBucket load_bucket(SimpleSymbolCoder<FLIFBitChanceMeta, RacIn<IO>, 18> &coder, const ColorRanges *srcRanges, const int plane, const prevPlanes &pixelL, const prevPlanes &pixelU) const {
        ColorBucket b;
        if (plane<3)
        for (int p=0; p<plane; p++) {
                if (!cb->exists(p,pixelL,pixelU)) return b;
        }
//        SimpleBitCoder<FLIFBitChanceMeta, RacIn> bcoder(rac);

        ColorVal smin,smax;
        minmax(srcRanges,plane,pixelL,pixelU,smin,smax);

        int exists = coder.read_int(0, 1);
        if (exists == 0) {
           return b; // empty bucket
        }
        if (smin == smax) {b.min = b.max = smin; b.discrete=false; return b;}
        b.min = coder.read_int(smin, smax);
        b.max = coder.read_int(b.min, smax);
        if (b.min == b.max) { b.discrete=false; return b; }
        if (b.min + 1 == b.max) { b.discrete=false; return b; }
        b.discrete = coder.read_int(0,1);
        if (b.discrete) {
           int nb = coder.read_int(2, std::min((int)max_per_colorbucket[plane],b.max-b.min));
           b.values.push_back(b.min);
           ColorVal v=b.min;
             for (int p=1; p < nb-1; p++) {
               b.values.push_back(coder.read_int(v+1, b.max+1-nb+p));
               v = b.values[p];
             }
           if (b.min < b.max) b.values.push_back(b.max);
        }
        return b;
    }
Exemplo n.º 3
0
    void save_bucket(const ColorBucket &b, SimpleSymbolCoder<FLIFBitChanceMeta, RacOut<IO>, 24> &coder, const ColorRanges *srcRanges, const int plane, const prevPlanes &pixelL, const prevPlanes &pixelU) const {
        if (plane<3)
        for (int p=0; p<plane; p++) {
                if (!cb->exists(p,pixelL,pixelU)) {
                        if (!b.empty()) {printf("\nBucket does not exist but is not empty!\n"); assert(false);}
                        return;
                }
        }
//        SimpleBitCoder<FLIFBitChanceMeta, RacOut> bcoder(rac);
//        if (b.min > b.max) printf("SHOULD NOT HAPPEN!\n");

        ColorVal smin,smax;
        minmax(srcRanges,plane,pixelL,pixelU,smin,smax);
        if (smin==smax) { return;}

//        b.printshort();
//        b.print();

        if (b.min > b.max) {
                coder.write_int(0, 1, 0);  // empty bucket
                return;
        } else coder.write_int(0, 1, 1);  // non-empty bucket


        coder.write_int(smin, smax, b.min);
        coder.write_int(b.min, smax, b.max);
        if (b.min == b.max) return;  // singleton bucket
        if (b.min + 1  == b.max) return; // bucket contains two consecutive values
        coder.write_int(0, 1, b.discrete);
        if (b.discrete) {
           coder.write_int(2, max_per_colorbucket[plane], b.values.size());
           ColorVal v=b.min;
/*           if (b.values.size() > 10) {
             v++;
             bcoder.set( 0x1000 * (b.values.size()-2) / (b.max-b.min-1) );
             for (unsigned int p=1; p < b.values.size() - 1; p++) {
               while (v<b.values[p]) { bcoder.write(0); v++; }
               bcoder.write(1); v++;
             }
           } else   */
             for (unsigned int p=1; p < b.values.size() - 1; p++) {
               coder.write_int(v+1, b.max-1, b.values[p]);
//               coder.write_int(0, b.max-v-2, b.values[p]-v-1);
               v = b.values[p];
             }
        }
    }
Exemplo n.º 4
0
    ColorBucket load_bucket(SimpleSymbolCoder<FLIFBitChanceMeta, RacIn<IO>, 24> &coder, const ColorRanges *srcRanges, const int plane, const prevPlanes &pixelL, const prevPlanes &pixelU) {
        ColorBucket b;
        if (plane<3)
        for (int p=0; p<plane; p++) {
                if (!cb->exists(p,pixelL,pixelU)) return b;
        }
//        SimpleBitCoder<FLIFBitChanceMeta, RacIn> bcoder(rac);

        ColorVal smin,smax;
        minmax(srcRanges,plane,pixelL,pixelU,smin,smax);
        if (smin == smax) {b.min = b.max = smin; b.discrete=false; return b;}

        int exists = coder.read_int(0, 1);
        if (exists == 0) {
           return b; // empty bucket
        }
        b.min = coder.read_int(smin, smax);
        b.max = coder.read_int(b.min, smax);
        if (b.min == b.max) { b.discrete=false; return b; }
        if (b.min + 1 == b.max) { b.discrete=false; return b; }
        b.discrete = coder.read_int(0,1);
        if (b.discrete) {
           int nb = coder.read_int(2, max_per_colorbucket[plane]);
           b.values.push_back(b.min);
           ColorVal v=b.min;
/*           if (nb > 10) {
             v++;
             bcoder.set( 0x1000 * (nb-2) / (b.max-b.min-1) );
             for (int p=1; p < nb - 1; p++) {
               while (bcoder.read() == 0) { v++; }
               b.values.push_back(v); v++;
             }
           } else */
             for (int p=1; p < nb-1; p++) {
               b.values.push_back(coder.read_int(v+1, b.max-1));
//               b.values.push_back(v+1+coder.read_int(0, b.max-v-2));
//               printf("val %i\n",b.values[p]);
               v = b.values[p];
             }
           if (b.min < b.max) b.values.push_back(b.max);
        }
//        b.print();
        return b;
    }