jariz / vibrant.js

Extract prominent colors from an image. JS port of Android's Palette.
http://jariz.github.io/vibrant.js/
MIT License
4.61k stars 236 forks source link

[bug] global variable "index" #20

Closed LoeiFy closed 6 years ago

LoeiFy commented 9 years ago

hello, i find vibrant.js will set a global variable index

https://github.com/jariz/vibrant.js/blob/master/dist/Vibrant.js#L143

i think this can fix it

// https://github.com/jariz/vibrant.js/blob/master/dist/Vibrant.js#L134-L152
        count: function(force) {
            var vbox = this,
                histo = vbox.histo;
            if (!vbox._count_set || force) {
                var npix = 0,
                    i, j, k, index;  // add index here
                for (i = vbox.r1; i <= vbox.r2; i++) {
                    for (j = vbox.g1; j <= vbox.g2; j++) {
                        for (k = vbox.b1; k <= vbox.b2; k++) {
                            index = getColorIndex(i, j, k);
                            npix += (histo[index] || 0);
                        }
                    }
                }
                vbox._count = npix;
                vbox._count_set = true;
            }
            return vbox._count;
        },

sorry that i don not know coffee js

kamiranoff commented 8 years ago

Thanks. I reproduced the same bug. it works with your fix for me now.

jariz commented 8 years ago

Would be cool if somebody submitted a PR On Oct 24, 2015 22:26, "Kevin Amiranoff" notifications@github.com wrote:

Thanks. I reproduced the same bug. it works with your fix for me now.

— Reply to this email directly or view it on GitHub https://github.com/jariz/vibrant.js/issues/20#issuecomment-150847828.

jonathanzong commented 8 years ago

Realized it's actually a bug in the quantize dependency, not vibrant.js.

akfish commented 6 years ago

Fixed in node-vibrant