Kruithne / wow.export

📦 Export Toolkit for World of Warcraft
MIT License
286 stars 53 forks source link

PNGWriter filter will always use None filter #427

Open KalopsiaTwilight opened 2 weeks ago

KalopsiaTwilight commented 2 weeks ago

In the file src/js/png-writer.js in the filter function (as far as I understand) there is some logic to use the smallest PNG byte output for a row:

for (let y = 0; y < height; y++) {
        let min = Infinity;

        for (let i = 0, len = FILTERS.length; i < len; i++) {
            let sum = FILTER_SUMS[i](data, dataOfs, byteWidth);
            if (sum < min) {
                selectedFilter = i;
                min = sum;
            }
        }

        raw[rawOfs] = selectedFilter;
        rawOfs++;

        FILTERS[selectedFilter](data, dataOfs, byteWidth, raw, rawOfs);
        rawOfs += byteWidth;
        dataOfs += byteWidth;
}

When I translated this code to Typescript, it helpfully pointed out that FILTERS does not actually have a length property, because it is an object with numbered keys and not an actual array. This means that FILTERS.length returns undefined and the selected filter will therefore always be 0.

As it turns out, this might be for the best because when I tried to run a version that does iterate over the functionsto selected the lowest sum, I got some strange artifacts in the PNG output that didn't happen when I just used the simple None filter. So there might be another filter that does not work as intended though this could also be an error on my side.

Just making this issue to have it noted somewhere.