Beispiel #1
0
    const ColorRanges* meta(Images&, const ColorRanges *srcRanges) {
//        cb->print();
        // in the I buckets, some discrete buckets may have become continuous to keep the colorbucket info small
        // this means some Q buckets are empty, which means that some values from the I buckets can be eliminated
        really_used = true;
        prevPlanes pixelL,pixelU;
        pixelL.push_back(cb->min0);
        pixelU.push_back(cb->min0+CB0b-1);
        pixelL.push_back(cb->min1);
        pixelU.push_back(cb->min1+CB1-1);
        for (auto bv : cb->bucket2) {
                pixelL[1] = cb->min1;
                pixelU[1] = cb->min1+CB1-1;
                for (auto b : bv) {
                        if (b.empty()) {
                                for (ColorVal c=pixelL[1]; c<=pixelU[1]; c++) {
                                  cb->findBucket(1,pixelL).removeColor(c);
                                  cb->findBucket(1,pixelU).removeColor(c);
                                }
                        }
                        pixelL[1] += CB1; pixelU[1] += CB1;
                }
                pixelL[0] += CB0b; pixelU[0] += CB0b;
        }
        cb->bucket0.prepare_snapvalues();
        cb->bucket3.prepare_snapvalues();
        for (auto& b : cb->bucket1) b.prepare_snapvalues();
        for (auto& bv : cb->bucket2) for (auto& b : bv) b.prepare_snapvalues();

        return new ColorRangesCB(srcRanges, cb);
    }
    bool process(const ColorRanges *srcRanges, const Images &images) {
            std::vector<ColorVal> pixel(images[0].numPlanes());
            // fill buckets
            for (const Image& image : images)
            for (uint32_t r=0; r<image.rows(); r++) {
                for (uint32_t c=0; c<image.cols(); c++) {
                  int p;
                  for (p=0; p<image.numPlanes(); p++) {
                    ColorVal v = image(p,r,c);
                    pixel[p] = v;
                  }
                  if (image.alpha_zero_special && p>3 && pixel[3]==0) { cb->findBucket(3, pixel).addColor(0,max_per_colorbucket[3]); continue;}
                  cb->addColor(pixel);
                }
            }

            cb->bucket0.simplify_lossless();
            cb->bucket3.simplify_lossless();
            for (auto& b : cb->bucket1) b.simplify_lossless();
            for (auto& bv : cb->bucket2) for (auto& b : bv) b.simplify_lossless();


        // TODO: IMPROVE THESE HEURISTICS!
        // TAKE IMAGE SIZE INTO ACCOUNT!
        // CONSIDER RELATIVE AREA OF BUCKETS / BOUNDS!

//            printf("Filled color buckets with %i discrete colors + %i continous buckets\n",totaldiscretecolors,totalcontinuousbuckets);

            int64_t total_pixels = (int64_t) images.size() * images[0].rows() * images[0].cols();
            v_printf(7,", [D=%i,C=%i,P=%i]",totaldiscretecolors,totalcontinuousbuckets,(int) (total_pixels/100));
            if (totaldiscretecolors < total_pixels/200 && totalcontinuousbuckets < total_pixels/50) return true;
            if (totaldiscretecolors < total_pixels/100 && totalcontinuousbuckets < total_pixels/200) return true;
            if (totaldiscretecolors < total_pixels/40 && totalcontinuousbuckets < total_pixels/500) return true;

            // simplify buckets
            for (int factor = 95; factor >= 35; factor -= 10) {
                for (auto& b : cb->bucket1) b.simplify(factor);
                for (auto& bv : cb->bucket2) for (auto& b : bv) b.simplify(factor-20);
                v_printf(8,"->[D=%i,C=%i]",totaldiscretecolors,totalcontinuousbuckets);
                if (totaldiscretecolors < total_pixels/200 && totalcontinuousbuckets < total_pixels/100) return true;
            }
            return false;
    }
Beispiel #3
0
 ColorBucket bucket(const int p, const prevPlanes &pp) const { return buckets->findBucket(p,pp); }