"Invalid filter" error is thrown when loading a PNG image.

Open
#21 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale

Research direction

Start in format/png/Tools.hx at decodeLine, then reproduce the failure by loading the linked PNG through the Heaps path. Trace the filter value and PNG decoding state to identify why it reaches the invalid-filter branch; done means the image loads without that error.

Written by the indexing model from the issue text.

Description

As we discussed in the mailing list, an "Invalid Filter" error is thrown when loading the PNG at the bottom of this post. The error is thrown by this piece of code :

https://github.com/HaxeFoundation/format/blob/master/format/png/Tools.hx

inline function decodeLine(y, f, getValue) {
    switch( f ) {
    case 0:
        for( x in 0...width ) {
            decode(getValue);
            bgra.set(w++,vb);
            bgra.set(w++,vg);
            bgra.set(w++,vr);
            bgra.set(w++,va);
        }
    case 1:
        var cr = 0, cg = 0, cb = 0, ca = 0;
        for( x in 0...width ) {
            decode(getValue);
            cb += vb;   bgra.set(w++,cb);
            cg += vg;   bgra.set(w++,cg);
            cr += vr;   bgra.set(w++,cr);
            ca += va;   bgra.set(w++,ca);
            bgra.set(w++, va);
        }
    case 2:
        var stride = y == 0 ? 0 : width * 4;
        for( x in 0...width ) {
            decode(getValue);
            bgra.set(w, vb + bgra.get(w - stride)); w++;
            bgra.set(w, vg + bgra.get(w - stride)); w++;
            bgra.set(w, vr + bgra.get(w - stride)); w++;
            bgra.set(w, va + bgra.get(w - stride)); w++;
        }
    case 3:
        var cr = 0, cg = 0, cb = 0, ca = 0;
        var stride = y == 0 ? 0 : width * 4;
        for( x in 0...width ) {
            decode(getValue);
            cb = (vb + ((cb + bgra.get(w - stride)) >> 1)) & 0xFF;  bgra.set(w++, cb);
            cg = (vg + ((cg + bgra.get(w - stride)) >> 1)) & 0xFF;  bgra.set(w++, cg);
            cr = (vr + ((cr + bgra.get(w - stride)) >> 1)) & 0xFF;  bgra.set(w++, cr);
            cr = (va + ((ca + bgra.get(w - stride)) >> 1)) & 0xFF;  bgra.set(w++, ca);
        }
    case 4:
        var stride = width * 4;
        var cr = 0, cg = 0, cb = 0, ca = 0;
        for( x in 0...width ) {
            decode(getValue);
            cb = (filter(bgra, x, y, stride, cb, w) + vb) & 0xFF; bgra.set(w++, cb);
            cg = (filter(bgra, x, y, stride, cg, w) + vg) & 0xFF; bgra.set(w++, cg);
            cr = (filter(bgra, x, y, stride, cr, w) + vr) & 0xFF; bgra.set(w++, cr);
            ca = (filter(bgra, x, y, stride, ca, w) + va) & 0xFF; bgra.set(w++, ca);
        }
    default:
        throw "Invalid filter "+f;
    }
}

The error occur when loading the PNG with Heaps.

ship

Dominant language
Haxe
Stars
141
Forks
65
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HaxeFoundation/format

All issues in HaxeFoundation/format

Similar issues

More Computer Graphics issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.