jariz / vibrant.js

Extract prominent colors from an image. JS port of Android's Palette.

Home Page:http://jariz.github.io/vibrant.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] global variable "index"

LoeiFy opened this issue · comments

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

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

commented

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
#20 (comment).

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