void print() { printf("Y buckets:\n"); bucket0.print(); printf("\nI buckets:\n"); for (auto b : bucket1) b.print(); printf("\nQ buckets:\n "); for (auto bs : bucket2) { for (auto b : bs) b.print(); printf("\n ");} if (ranges->numPlanes() > 3) { printf("Alpha buckets:\n"); bucket3.print(); } }
bool exists(const int p, const prevPlanes &pp) const { if (p>0 && (pp[0] < min0 || pp[0] > ranges->max(0))) return false; if (p>1 && (pp[1] < min1 || pp[1] > ranges->max(1))) return false; ColorVal rmin, rmax; ColorVal v=pp[p]; ranges->snap(p,pp,rmin,rmax,v); if (v != pp[p]) return false; // bucket empty because of original range constraints const ColorBucket b = findBucket(p,pp); //if (b.min > b.max) return false; if (b.snapColor_slow(pp[p]) != pp[p]) return false; return true; }
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]; } } }
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]; } } }